Harald Welte | 67b003d | 2011-10-10 21:43:27 +0200 | [diff] [blame^] | 1 | % SS7 service handler for dumping MTP3 payload (testing) |
| 2 | |
| 3 | % (C) 2010-2011 by Harald Welte <laforge@gnumonks.org> |
| 4 | % |
| 5 | % All Rights Reserved |
| 6 | % |
| 7 | % This program is free software; you can redistribute it and/or modify |
| 8 | % it under the terms of the GNU Affero General Public License as |
| 9 | % published by the Free Software Foundation; either version 3 of the |
| 10 | % License, or (at your option) any later version. |
| 11 | % |
| 12 | % This program is distributed in the hope that it will be useful, |
| 13 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | % GNU General Public License for more details. |
| 16 | % |
| 17 | % You should have received a copy of the GNU Affero General Public |
| 18 | % License |
| 19 | % along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | |
| 21 | -module(ss7_service_dump). |
| 22 | -behaviour(gen_fsm). |
| 23 | -export([start_link/1, init/1, idle/2]). |
| 24 | |
| 25 | -include_lib("osmo_ss7/include/osmo_util.hrl"). |
| 26 | -include_lib("osmo_ss7/include/mtp3.hrl"). |
| 27 | -include_lib("osmo_ss7/include/isup.hrl"). |
| 28 | -include_lib("osmo_ss7/include/sccp.hrl"). |
| 29 | |
| 30 | -record(loop_dat, { |
| 31 | ssns |
| 32 | }). |
| 33 | |
| 34 | start_link(Ssns) -> |
| 35 | gen_fsm:start_link(ss7_service_dump, [Ssns], []). |
| 36 | |
| 37 | init(Ssn) when is_integer(Ssn) -> |
| 38 | init([Ssn]); |
| 39 | init(Ssns) when is_list(Ssns) -> |
| 40 | bind_services(Ssns), |
| 41 | {ok, idle, #loop_dat{ssns = Ssns}}. |
| 42 | |
| 43 | bind_services([]) -> |
| 44 | ok; |
| 45 | bind_services([Head|Tail]) -> |
| 46 | ok = ss7_links:bind_service(Head, "ss7_service_dump"), |
| 47 | bind_services(Tail). |
| 48 | |
| 49 | parse_mtp3(#mtp3_msg{service_ind = ?MTP3_SERV_SCCP, payload = Payload}) -> |
| 50 | sccp_codec:parse_sccp_msg(Payload); |
| 51 | parse_mtp3(#mtp3_msg{service_ind = ?MTP3_SERV_ISUP, payload = Payload}) -> |
| 52 | isup_codec:parse_isup_msg(Payload). |
| 53 | |
| 54 | idle(#primitive{subsystem = 'MTP', gen_name = 'TRANSFER', |
| 55 | spec_name = indication, parameters = Mtp3Msg}, LoopDat) -> |
| 56 | io:format("ss7_service_dump in: ~p~n", [Mtp3Msg]), |
| 57 | try parse_mtp3(Mtp3Msg) of |
| 58 | Parsed -> |
| 59 | io:format("ss7_service_dump out: ~p~n", [Parsed]) |
| 60 | catch |
| 61 | _ -> |
| 62 | io:format("ss7_service_dump parser error~n") |
| 63 | end, |
| 64 | {next_state, idle, LoopDat}. |