summaryrefslogtreecommitdiffstats
path: root/src/mtp3_hmdt.erl
blob: ebac4bac977e7e0b8c70f38cba05a283e4040aa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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.