summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2020-01-23 16:29:37 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2020-01-23 16:29:37 +0700
commit663b6268d2f9181c2c6284461b8482f064f6e47c (patch)
treec99650f20ca469c86c3b12072df6359f28ec6ded /src
parenta27329a499c567ae7a2496c836ed6d88b3e14292 (diff)
WIP WIP WIP
Diffstat (limited to 'src')
-rw-r--r--src/osmo_gsup_if.erl66
-rw-r--r--src/osmo_smsc_app.erl3
-rw-r--r--src/sm_rp_trans.erl67
3 files changed, 90 insertions, 46 deletions
diff --git a/src/osmo_gsup_if.erl b/src/osmo_gsup_if.erl
index ca5cc5a..7b95376 100644
--- a/src/osmo_gsup_if.erl
+++ b/src/osmo_gsup_if.erl
@@ -40,12 +40,14 @@
-define(IPAC_PROTO_EXT_GSUP, {osmo, 5}).
+-record(smr_data, {imsi, msg_ref, orig_addr, dest_addr, tpdu}).
-record(gsupc_state, {
+ core,
socket,
ipa_pid
}).
--export([start_link/3]).
+-export([start_link/2]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2]).
-export([code_change/3, terminate/2]).
@@ -54,21 +56,21 @@
%% our exported API
%% ------------------------------------------------------------------
-start_link(ServerAddr, ServerPort, Options) ->
- gen_server:start_link(?MODULE, [ServerAddr, ServerPort, Options], [{debug, [trace]}]).
+start_link(Core, HLRAddr) ->
+ gen_server:start_link(?MODULE, [Core, HLRAddr], [{debug, [trace]}]).
%% ------------------------------------------------------------------
%% gen_server Function Definitions
%% ------------------------------------------------------------------
-init([Address, Port, Options]) ->
+init([Core, {Address, Port, Options}]) ->
ipa_proto:init(),
% register the GSUP codec with the IPA core; ignore result as we mgiht be doing this multiple times
ipa_proto:register_codec(?IPAC_PROTO_EXT_GSUP, fun gsup_protocol:encode/1, fun gsup_protocol:decode/1),
{ok, {Socket, IpaPid}} = ipa_proto:connect(Address, Port, Options),
true = ipa_proto:register_stream(Socket, ?IPAC_PROTO_EXT_GSUP, {process_id, self()}),
ipa_proto:unblock(Socket),
- {ok, #gsupc_state{socket=Socket, ipa_pid=IpaPid}}.
+ {ok, #gsupc_state{core = Core, socket = Socket, ipa_pid = IpaPid}}.
-define(IPA_GSUP_STREAM_ID, {osmo, 16#05}).
-define(GSUP_MSG_CLS_SM, 16#02).
@@ -84,22 +86,27 @@ gen_sm_response(GSUPMsg, MsgType) ->
% IPA/GSUP messages from OsmoHLR
handle_cast({ipa, ?IPA_GSUP_STREAM_ID, GSUPMsg}, State) ->
% Obtain mandatory IEs
- #{imsi := IMSI, sm_rp_mr := RPRef} = GSUPMsg,
+ #{imsi := IMSI, sm_rp_mr := MR} = GSUPMsg,
% Parse depending on a message type
case GSUPMsg of
% MO RP-DATA / RP-SMMA
- #{message_type := mo_forward_sm_req, sm_rp_ui := TPDU} ->
- Response = gen_sm_response(GSUPMsg, mo_forward_sm_res),
- ipa_proto:send(State#gsupc_state.socket, ?IPA_GSUP_STREAM_ID, Response);
+ #{message_type := mo_forward_sm_req, sm_rp_da := DA, sm_rp_oa := OA, sm_rp_ui := TPDU} ->
+ io:format("(IMSI:~p, MR:~p) Rx MT-forwardSM Request~n", [IMSI, MR]),
+ gen_server:cast(State#gsupc_state.core,
+ {smsc_ev_mo_fwd_sm_req, IMSI, MR, DA, OA, TPDU});
#{message_type := ready_for_sm_req} ->
Response = gen_sm_response(GSUPMsg, ready_for_sm_res),
ipa_proto:send(State#gsupc_state.socket, ?IPA_GSUP_STREAM_ID, Response);
% MT RP-ACK
- #{message_type := mt_forward_sm_res, sm_rp_mr := MR} ->
- io:format("(IMSI:~p, MR:~p) Rx MT-forwardSM Result~n", [IMSI, MR]);
+ #{message_type := mt_forward_sm_res} ->
+ io:format("(IMSI:~p, MR:~p) Rx MT-forwardSM Result~n", [IMSI, MR]),
+ gen_server:cast(State#gsupc_state.core,
+ {smsc_ev_mt_fwd_sm_ack, IMSI, MR});
% MT RP-ERROR
- #{message_type := mt_forward_sm_err, sm_rp_mr := MR, sm_rp_cause := Cause} ->
- io:format("(IMSI:~p, MR:~p) Rx MT-forwardSM Error: cause=~p~n", [IMSI, MR, Cause]);
+ #{message_type := mt_forward_sm_err, sm_rp_cause := Cause} ->
+ io:format("(IMSI:~p, MR:~p) Rx MT-forwardSM Error: cause=~p~n", [IMSI, MR, Cause]),
+ gen_server:cast(State#gsupc_state.core,
+ {smsc_ev_mt_fwd_sm_err, IMSI, MR, Cause});
_ ->
error_logger:error_report(["unknown GSUP message",
{module, ?MODULE},
@@ -108,6 +115,39 @@ handle_cast({ipa, ?IPA_GSUP_STREAM_ID, GSUPMsg}, State) ->
end,
{noreply, State};
+% IPA/GSUP messages from the SMSC
+handle_cast({smsc_ev_mt_fwd_sm_req, Data}, State) ->
+ #smr_data{imsi = IMSI, msg_ref = MR,
+ orig_addr = OA, dest_addr = DA,
+ tpdu = TPDU} = Data,
+ ipa_proto:send(State#gsupc_state.socket, ?IPA_GSUP_STREAM_ID,
+ #{message_class => ?GSUP_MSG_CLS_SM, message_type => mt_forward_sm_req,
+ imsi => IMSI, sm_rp_mr => MR,
+ sm_rp_da => DA, sm_rp_oa => OA,
+ sm_rp_ui => TPDU,
+ % FIXME: this must be configurable
+ source_name => << "EUSE-OsmoSMSC-00-00-00-00-00-00", 0 >>,
+ destination_name => << "MSC-00-00-00-00-00-00", 0 >> }),
+ {noreply, State};
+
+handle_cast({smr_ev_fwd_mo_sm_ack, IMSI, MR}, State) ->
+ ipa_proto:send(State#gsupc_state.socket, ?IPA_GSUP_STREAM_ID,
+ #{message_class => ?GSUP_MSG_CLS_SM, message_type => mo_forward_sm_res,
+ imsi => IMSI, sm_rp_mr => MR,
+ % FIXME: this must be configurable
+ source_name => << "EUSE-OsmoSMSC-00-00-00-00-00-00", 0 >>,
+ destination_name => << "MSC-00-00-00-00-00-00", 0 >> }),
+ {noreply, State};
+
+handle_cast({smr_ev_fwd_mo_sm_err, IMSI, MR, Cause}, State) ->
+ ipa_proto:send(State#gsupc_state.socket, ?IPA_GSUP_STREAM_ID,
+ #{message_class => ?GSUP_MSG_CLS_SM, message_type => mo_forward_sm_err,
+ imsi => IMSI, sm_rp_mr => MR, sm_rp_cause => Cause,
+ % FIXME: this must be configurable
+ source_name => << "EUSE-OsmoSMSC-00-00-00-00-00-00", 0 >>,
+ destination_name => << "MSC-00-00-00-00-00-00", 0 >> }),
+ {noreply, State};
+
% All unsupported IPA messages
handle_cast({ipa, StreamID, GSUPMsg}, State) ->
error_logger:error_report(["unknown IPA message",
diff --git a/src/osmo_smsc_app.erl b/src/osmo_smsc_app.erl
index 39c218b..4b78fff 100644
--- a/src/osmo_smsc_app.erl
+++ b/src/osmo_smsc_app.erl
@@ -4,8 +4,7 @@
-export([start/2, stop/1]).
start(_StartType, _StartArgs) ->
- % FIXME / TODO!
- {ok, _} = osmo_gsup_if:start_link("127.0.0.1", 4222, []).
+ {ok, _} = osmo_smsc_core:start_link().
stop(_State) ->
ok.
diff --git a/src/sm_rp_trans.erl b/src/sm_rp_trans.erl
index 175677e..775f4d0 100644
--- a/src/sm_rp_trans.erl
+++ b/src/sm_rp_trans.erl
@@ -51,8 +51,8 @@
% API functions
-export([
- start_link/0,
- start/0
+ start_link/2,
+ start/2
]).
% 3GPP TS 24.011, chapter 10: Timers
@@ -60,43 +60,41 @@
-define(GSM411_TMR_TRAN, 30 * 1000).
-define(GSM411_TMR_TR2N, 15 * 1000).
--record(smr_data, {msg_ref, orig_addr, dest_addr, tpdu}).
--record(smr_state, {sender, receiver, data}).
+-record(smr_data, {imsi, msg_ref, orig_addr, dest_addr, tpdu}).
+-record(smr_state, {iface, core, data}).
%% API functions
-start_link() ->
- gen_statem:start_link(?MODULE, [], []).
+start_link(Interface, Core) ->
+ gen_statem:start_link(?MODULE, [Interface, Core], []).
-start() ->
- gen_statem:start(?MODULE, [], []).
+start(Interface, Core) ->
+ gen_statem:start(?MODULE, [Interface, Core], []).
%% gen_statem callbacks
-init([]) ->
- {ok, smr_st_idle, #smr_state{sender = nil, receiver = nil, data = nil}}.
+init([Interface, Core]) ->
+ {ok, smr_st_idle, #smr_state{iface = Interface, core = Core, data = nope}}.
% Define a separate handler function for each state
callback_mode() ->
state_functions.
% Rx MO RP-DATA from the MSC, forward to the SMSC
-smr_st_idle({call, From}, {smr_ev_fwd_mo_sm_req, Data}, _) ->
- % TODO: store OA/DA/TPDU to the database
+smr_st_idle({call, From}, {smr_ev_fwd_mo_sm_req, Data}, State) ->
{next_state, smr_st_wait_tx_ack,
- #smr_state{sender = From, data = Data},
+ State#smr_state{data = Data},
[{reply, From, ok}, {state_timeout, ?GSM411_TMR_TR2N, wait_tx_ack}]};
% Rx MO RP-SMMA from the MSC, notify the SMSC
-smr_st_idle({call, From}, {smr_ev_fwd_mo_smma_req, Data}, _) ->
- % TODO: notify the SMSC that subscriber is online / has memory
+smr_st_idle({call, From}, {smr_ev_fwd_mo_smma_req, Data}, State) ->
{next_state, smr_st_wait_tx_ack,
- #smr_state{sender = From, data = Data},
+ State#smr_state{data = Data},
[{reply, From, ok}, {state_timeout, ?GSM411_TMR_TR2N, wait_tx_ack}]};
% Rx MT RP-DATA from the SMSC, forward to the MSC
-smr_st_idle({call, From}, {smr_ev_fwd_mt_sm_req, Data}, _) ->
- % TODO: route MT SMS towards the MSC (MSISDN lookup)
+smr_st_idle({call, From}, {smr_ev_fwd_mt_sm_req, Data}, State) ->
+ gen_server:cast(State#smr_state.iface, {smsc_ev_mt_fwd_sm_req, Data}),
{next_state, smr_st_wait_rx_ack,
- #smr_state{sender = From, data = Data},
+ State#smr_state{data = Data},
[{reply, From, ok}, {state_timeout, ?GSM411_TMR_TR1N, wait_rx_ack}]};
% Trap for unhandled events
smr_st_idle(EventType, EventContent, State) ->
@@ -105,17 +103,24 @@ smr_st_idle(EventType, EventContent, State) ->
{keep_state, State}.
% Rx MO RP-ACK from the SMSC, forward to the MSC
-smr_st_wait_tx_ack({call, From}, smr_ev_fwd_mo_sm_ack, S = #smr_state{sender = _Pid}) ->
- % TODO: actually send ACK to the MSC
- % FIXME: should we respond?!?
- {stop, normal, S};
+smr_st_wait_tx_ack({call, From}, smr_ev_fwd_mo_sm_ack, State) ->
+ SMRData = State#smr_state.data, MR = SMRData#smr_data.msg_ref,
+ gen_server:cast(State#smr_state.iface,
+ {smsc_ev_mo_fwd_sm_ack,
+ SMRData#smr_data.imsi,
+ SMRData#smr_data.msg_ref}),
+ {stop, normal, State};
% Rx MO RP-ERROR from the SMSC, forward to the MSC
-smr_st_wait_tx_ack({call, From}, {smr_ev_fwd_mo_sm_err, _Cause}, S = #smr_state{sender = _Pid}) ->
- % TODO: actually send ERROR to the MSC
- % FIXME: should we respond?!?
- {stop, normal, S};
+smr_st_wait_tx_ack({call, From}, {smr_ev_fwd_mo_sm_err, Cause}, State) ->
+ SMRData = State#smr_state.data,
+ gen_server:cast(State#smr_state.iface,
+ {smsc_ev_mo_fwd_sm_err,
+ SMRData#smr_data.imsi,
+ SMRData#smr_data.msg_ref,
+ Cause}),
+ {stop, normal, State};
% Timeout waiting for RP-ACK / RP-ERROR
-smr_st_wait_tx_ack(state_timeout, wait_tx_ack, S = #smr_state{sender = _Pid}) ->
+smr_st_wait_tx_ack(state_timeout, wait_tx_ack, S) ->
% TODO: we probably want to try again here
% TODO: notify the MSC/MS about that
io:format("Timeout waiting for RP-ACK / RP-ERROR for MO SMS~n"),
@@ -126,13 +131,13 @@ smr_st_wait_tx_ack(EventType, EventContent, State) ->
{keep_state, State}.
% Rx MT RP-ACK from the MSC, forward to the SMSC
-smr_st_wait_rx_ack({call, From}, smr_ev_fwd_mt_sm_ack, S = #smr_state{sender = _Pid}) ->
+smr_st_wait_rx_ack({call, From}, smr_ev_fwd_mt_sm_ack, S) ->
{stop, normal, S};
% Rx MT RP-ERROR from the MSC, forward to the SMSC
-smr_st_wait_rx_ack({call, From}, {smr_ev_fwd_mt_sm_err, _Cause}, S = #smr_state{sender = _Pid}) ->
+smr_st_wait_rx_ack({call, From}, {smr_ev_fwd_mt_sm_err, _Cause}, S) ->
{stop, normal, S};
% Timeout waiting for RP-ACK / RP-ERROR
-smr_st_wait_rx_ack(state_timeout, wait_rx_ack, S = #smr_state{sender = _Pid}) ->
+smr_st_wait_rx_ack(state_timeout, wait_rx_ack, S) ->
% TODO: we probably want to try again here
% TODO: notify the SMSC about that
io:format("Timeout waiting for RP-ACK / RP-ERROR for MT SMS~n"),