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 | % |
Harald Welte | f8bf032 | 2012-04-16 13:10:47 +0200 | [diff] [blame^] | 17 | % You should have received a copy of the GNU Affero General Public License |
Harald Welte | 67b003d | 2011-10-10 21:43:27 +0200 | [diff] [blame] | 18 | % along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | f8bf032 | 2012-04-16 13:10:47 +0200 | [diff] [blame^] | 19 | % |
| 20 | % Additional Permission under GNU AGPL version 3 section 7: |
| 21 | % |
| 22 | % If you modify this Program, or any covered work, by linking or |
| 23 | % combining it with runtime libraries of Erlang/OTP as released by |
| 24 | % Ericsson on http://www.erlang.org (or a modified version of these |
| 25 | % libraries), containing parts covered by the terms of the Erlang Public |
| 26 | % License (http://www.erlang.org/EPLICENSE), the licensors of this |
| 27 | % Program grant you additional permission to convey the resulting work |
| 28 | % without the need to license the runtime libraries of Erlang/OTP under |
| 29 | % the GNU Affero General Public License. Corresponding Source for a |
| 30 | % non-source form of such a combination shall include the source code |
| 31 | % for the parts of the runtime libraries of Erlang/OTP used as well as |
| 32 | % that of the covered work. |
| 33 | |
Harald Welte | 67b003d | 2011-10-10 21:43:27 +0200 | [diff] [blame] | 34 | |
| 35 | -module(ss7_service_dump). |
| 36 | -behaviour(gen_fsm). |
| 37 | -export([start_link/1, init/1, idle/2]). |
| 38 | |
| 39 | -include_lib("osmo_ss7/include/osmo_util.hrl"). |
| 40 | -include_lib("osmo_ss7/include/mtp3.hrl"). |
| 41 | -include_lib("osmo_ss7/include/isup.hrl"). |
| 42 | -include_lib("osmo_ss7/include/sccp.hrl"). |
| 43 | |
| 44 | -record(loop_dat, { |
| 45 | ssns |
| 46 | }). |
| 47 | |
| 48 | start_link(Ssns) -> |
| 49 | gen_fsm:start_link(ss7_service_dump, [Ssns], []). |
| 50 | |
| 51 | init(Ssn) when is_integer(Ssn) -> |
| 52 | init([Ssn]); |
| 53 | init(Ssns) when is_list(Ssns) -> |
| 54 | bind_services(Ssns), |
| 55 | {ok, idle, #loop_dat{ssns = Ssns}}. |
| 56 | |
| 57 | bind_services([]) -> |
| 58 | ok; |
| 59 | bind_services([Head|Tail]) -> |
| 60 | ok = ss7_links:bind_service(Head, "ss7_service_dump"), |
| 61 | bind_services(Tail). |
| 62 | |
| 63 | parse_mtp3(#mtp3_msg{service_ind = ?MTP3_SERV_SCCP, payload = Payload}) -> |
| 64 | sccp_codec:parse_sccp_msg(Payload); |
| 65 | parse_mtp3(#mtp3_msg{service_ind = ?MTP3_SERV_ISUP, payload = Payload}) -> |
| 66 | isup_codec:parse_isup_msg(Payload). |
| 67 | |
| 68 | idle(#primitive{subsystem = 'MTP', gen_name = 'TRANSFER', |
| 69 | spec_name = indication, parameters = Mtp3Msg}, LoopDat) -> |
| 70 | io:format("ss7_service_dump in: ~p~n", [Mtp3Msg]), |
| 71 | try parse_mtp3(Mtp3Msg) of |
| 72 | Parsed -> |
| 73 | io:format("ss7_service_dump out: ~p~n", [Parsed]) |
| 74 | catch |
| 75 | _ -> |
| 76 | io:format("ss7_service_dump parser error~n") |
| 77 | end, |
| 78 | {next_state, idle, LoopDat}. |