blob: 751be9df72f74603f8dd932391611afd0e3105eb [file] [log] [blame]
Harald Welte9ebf3162012-01-20 02:02:25 +01001% M3UA ASP xua_asp_fsm callback
2
3% (C) 2011-2012 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 License
18% along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Weltef8bf0322012-04-16 13:10:47 +020019%
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.
Harald Welte9ebf3162012-01-20 02:02:25 +010033
34-module(m3ua_asp).
35-author('Harald Welte <laforge@gnumonks.org>').
36-behaviour(xua_asp_fsm).
37
38-include("osmo_util.hrl").
39-include("m3ua.hrl").
40
41-export([init/1]).
42
43-export([gen_xua_msg/3, asp_down/3, asp_inactive/3, asp_active/3]).
44
45init([]) ->
46 {ok, we_have_no_state}.
47
48gen_xua_msg(MsgClass, MsgType, Params) ->
49 #m3ua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType, payload = Params}.
50
51asp_down(#m3ua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
52 LoopDat, Mld) when MsgClass == ?M3UA_MSGC_ASPSM; MsgClass == ?M3UA_MSGC_ASPTM ->
53 % convert from M3UA to xua_msg and call into master module
54 xua_asp_fsm:asp_down({xua_msg, MsgClass, MsgType}, Mld);
55asp_down(M3uaMsg, LoopDat, Mld) when is_record(M3uaMsg, m3ua_msg) ->
56 rx_m3ua(M3uaMsg, asp_down, Mld).
57
58asp_inactive(#m3ua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
59 LoopDat, Mld) when MsgClass == ?M3UA_MSGC_ASPSM; MsgClass == ?M3UA_MSGC_ASPTM ->
60 % convert from M3UA to xua_msg and call into master module
61 xua_asp_fsm:asp_inactive({xua_msg, MsgClass, MsgType}, Mld);
62asp_inactive(M3uaMsg, LoopDat, Mld) when is_record(M3uaMsg, m3ua_msg) ->
63 rx_m3ua(M3uaMsg, asp_inactive, Mld).
64
65asp_active(#m3ua_msg{version = 1, msg_class = MsgClass, msg_type = MsgType},
66 LoopDat, Mld) when MsgClass == ?M3UA_MSGC_ASPSM; MsgClass == ?M3UA_MSGC_ASPTM ->
67 % convert from M3UA to xua_msg and call into master module
68 xua_asp_fsm:asp_active({xua_msg, MsgClass, MsgType}, Mld);
69asp_active(M3uaMsg, LoopDat, Mld) when is_record(M3uaMsg, m3ua_msg) ->
70 rx_m3ua(M3uaMsg, asp_active, Mld).
71
72
73
74
75
76rx_m3ua(Msg = #m3ua_msg{version = 1, msg_class = ?M3UA_MSGC_MGMT,
77 msg_type = ?M3UA_MSGT_MGMT_NTFY}, State, LoopDat) ->
78 xua_asp_fsm:send_prim_to_user(LoopDat, osmo_util:make_prim('M','NOTIFY',indication,[Msg])),
79 {next_state, State, LoopDat};
80
81rx_m3ua(Msg = #m3ua_msg{version = 1, msg_class = ?M3UA_MSGC_ASPSM,
82 msg_type = ?M3UA_MSGT_ASPSM_BEAT}, State, LoopDat) ->
83 % Send BEAT_ACK using the same payload as the BEAT msg
84 xua_asp_fsm:send_sctp_to_peer(LoopDat, Msg#m3ua_msg{msg_type = ?M3UA_MSGT_ASPSM_BEAT_ACK}),
85 {next_state, State, LoopDat};
86
87rx_m3ua(Msg = #m3ua_msg{version = 1, msg_class = ?M3UA_MSGC_MGMT,
88 msg_type = ?M3UA_MSGT_MGMT_ERR}, State, LoopDat) ->
89 xua_asp_fsm:send_prim_to_user(LoopDat, osmo_util:make_prim('M','ERROR',indication,[Msg])),
90 {next_state, State, LoopDat};
91
92rx_m3ua(Msg = #m3ua_msg{version = 1, msg_class = ?M3UA_MSGC_SSNM,
93 msg_type = MsgType, payload = Params}, State, LoopDat) ->
94 % transform to classic MTP primitive and send up to the user
95 Mtp = map_ssnm_to_mtp_prim(MsgType),
96 xua_asp_fsm:send_prim_to_user(LoopDat, Mtp),
97 {next_state, State, LoopDat};
98
99rx_m3ua(Msg = #m3ua_msg{}, State, LoopDat) ->
100 io:format("M3UA Unknown messge ~p in state ~p~n", [Msg, State]),
101 {next_state, State, LoopDat}.
102
103% Transform the M3UA SSNM messages into classic MTP primitives
104map_ssnm_to_mtp_prim(MsgType) ->
105 Mtp = #primitive{subsystem = 'MTP', spec_name = indication},
106 case MsgType of
107 ?M3UA_MSGT_SSNM_DUNA -> Mtp#primitive{gen_name = 'PAUSE'};
108 ?M3UA_MSGT_SSNM_DAVA -> Mtp#primitive{gen_name = 'RESUME'};
109 ?M3UA_MSGT_SSNM_SCON -> Mtp#primitive{gen_name = 'STATUS'};
110 ?M3UA_MSGT_SSNM_DUPU -> Mtp#primitive{gen_name = 'STATUS'}
111 end.