summaryrefslogtreecommitdiffstats
path: root/src/mtp3_hmdt.erl
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-01-16 22:22:17 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-16 22:22:17 +0100
commit26bdef27ddc68be80e838e25a3b6f764719e8f87 (patch)
tree3e1194754a25d5783333c45a64315c035b9a17d8 /src/mtp3_hmdt.erl
parentf14ef9ffd758430de676c85ee6b91f7748fcd69c (diff)
Commit current state of working MTP3-in-M2PA
The current implementation can successfully establish M2PA with Cisco ITP.
Diffstat (limited to 'src/mtp3_hmdt.erl')
-rw-r--r--src/mtp3_hmdt.erl102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/mtp3_hmdt.erl b/src/mtp3_hmdt.erl
new file mode 100644
index 0000000..ebac4ba
--- /dev/null
+++ b/src/mtp3_hmdt.erl
@@ -0,0 +1,102 @@
+% MTP3 Message handling; message distribution (HMDT) according to Q.704
+
+% (C) 2011-2012 by Harald Welte <laforge@gnumonks.org>
+%
+% All Rights Reserved
+%
+% This program is free software; you can redistribute it and/or modify
+% it under the terms of the GNU Affero General Public License as
+% published by the Free Software Foundation; either version 3 of the
+% License, or (at your option) any later version.
+%
+% This program is distributed in the hope that it will be useful,
+% but WITHOUT ANY WARRANTY; without even the implied warranty of
+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+% GNU General Public License for more details.
+%
+% You should have received a copy of the GNU Affero General Public License
+% along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+-module(mtp3_hmdt).
+-author('Harald Welte <laforge@gnumonks.org>').
+-behaviour(gen_fsm).
+
+-include("mtp3.hrl").
+
+% gen_fsm exports
+-export([init/1, terminate/3, code_change/4, handle_event/3, handle_info/3]).
+
+% individual FSM states
+-export([idle/2, own_sp_restart/2]).
+
+-record(hmdt_state, {
+ sltc_pid
+ }).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% gen_fsm callbacks
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+init([Sltc]) when is_pid(Sltc) ->
+ HmdtState = #hmdt_state{sltc_pid = Sltc},
+ {ok, idle, HmdtState}.
+
+terminate(Reason, State, _LoopDat) ->
+ io:format("Terminating ~p in State ~p (Reason: ~p)~n",
+ [?MODULE, State, Reason]),
+ ok.
+
+code_change(_OldVsn, StateName, LoopDat, _Extra) ->
+ {ok, StateName, LoopDat}.
+
+handle_event(Event, State, LoopDat) ->
+ io:format("Unknown Event ~p in state ~p~n", [Event, State]),
+ {next_state, State, LoopDat}.
+
+handle_info(Info, State, LoopDat) ->
+ io:format("Unknown Info ~p in state ~p~n", [Info, State]),
+ {next_state, State, LoopDat}.
+
+% See Figure 2 of Q.707
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% STATE: idle
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+idle(M=#mtp3_msg{service_ind=Sio}, LoopDat) ->
+ handle_mtp3(Sio, M, LoopDat),
+ {next_state, idle, LoopDat};
+
+idle(restart_begins, LoopDat) ->
+ {next_state, own_sp_restart, LoopDat}.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% STATE: own_sp_restart
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+own_sp_restart(M=#mtp3_msg{service_ind=Sio}, LoopDat) when
+ Sio == ?MTP3_SERV_MGMT; Sio == ?MTP3_SERV_MTN ->
+ handle_mtp3(Sio, M, LoopDat),
+ {next_state, own_sp_restart, LoopDat};
+
+own_sp_restart(restart_ends, LoopDat) ->
+ {next_state, idle, LoopDat}.
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% helper functions
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+handle_mtp3(?MTP3_SERV_MTN, Mtp3, LoopDat) ->
+ io:format("SIO ~p HMDT -> SLTC~n", [?MTP3_SERV_MTN]),
+ gen_fsm:send_event(LoopDat#hmdt_state.sltc_pid, Mtp3);
+handle_mtp3(?MTP3_SERV_MGMT, Mtp3, LoopDat) ->
+ io:format("SIO ~p HMDT -> NULL~n", [?MTP3_SERV_MGMT]),
+ % FIXME: distinguish between SRM, SLM and STM
+ ok;
+handle_mtp3(Sio, Mtp3, LoopDat) ->
+ io:format("SIO ~p HMDT -> ss7_links~n", [Sio]),
+ % deliver to subsystem
+ ss7_links:mtp3_rx(Mtp3),
+ % FIXME: Send UPU! ?
+ ok.