summaryrefslogtreecommitdiff
path: root/src/sm_rp_trans.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/sm_rp_trans.erl')
-rw-r--r--src/sm_rp_trans.erl128
1 files changed, 67 insertions, 61 deletions
diff --git a/src/sm_rp_trans.erl b/src/sm_rp_trans.erl
index 775f4d0..7f022ce 100644
--- a/src/sm_rp_trans.erl
+++ b/src/sm_rp_trans.erl
@@ -36,24 +36,24 @@
% gen_statem callbacks
-export([
- init/1,
- terminate/3,
- code_change/4,
- callback_mode/0
- ]).
+ init/1,
+ terminate/3,
+ code_change/4,
+ callback_mode/0
+]).
% State functions (section 6.2.2)
-export([
- smr_st_idle/3,
- smr_st_wait_rx_ack/3,
- smr_st_wait_tx_ack/3
- ]).
+ smr_st_idle/3,
+ smr_st_wait_rx_ack/3,
+ smr_st_wait_tx_ack/3
+]).
% API functions
-export([
- start_link/2,
- start/2
- ]).
+ start_link/2,
+ start/2
+]).
% 3GPP TS 24.011, chapter 10: Timers
-define(GSM411_TMR_TR1N, 40 * 1000).
@@ -66,90 +66,96 @@
%% API functions
start_link(Interface, Core) ->
- gen_statem:start_link(?MODULE, [Interface, Core], []).
+ gen_statem:start_link(?MODULE, [Interface, Core], []).
start(Interface, Core) ->
- gen_statem:start(?MODULE, [Interface, Core], []).
+ gen_statem:start(?MODULE, [Interface, Core], []).
%% gen_statem callbacks
init([Interface, Core]) ->
- {ok, smr_st_idle, #smr_state{iface = Interface, core = Core, data = nope}}.
+ {ok, smr_st_idle, #smr_state{iface = Interface, core = Core, data = nope}}.
% Define a separate handler function for each state
callback_mode() ->
- state_functions.
+ 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}, State) ->
- {next_state, smr_st_wait_tx_ack,
- State#smr_state{data = Data},
- [{reply, From, ok}, {state_timeout, ?GSM411_TMR_TR2N, wait_tx_ack}]};
+ {next_state, smr_st_wait_tx_ack, 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}, State) ->
- {next_state, smr_st_wait_tx_ack,
- State#smr_state{data = Data},
- [{reply, From, ok}, {state_timeout, ?GSM411_TMR_TR2N, wait_tx_ack}]};
+ {next_state, smr_st_wait_tx_ack, 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}, State) ->
- gen_server:cast(State#smr_state.iface, {smsc_ev_mt_fwd_sm_req, Data}),
- {next_state, smr_st_wait_rx_ack,
- State#smr_state{data = Data},
- [{reply, From, ok}, {state_timeout, ?GSM411_TMR_TR1N, wait_rx_ack}]};
+ gen_server:cast(State#smr_state.iface, {smsc_ev_mt_fwd_sm_req, Data}),
+ {next_state, smr_st_wait_rx_ack, 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) ->
- io:format("Event ~p (~p) unhandled in state IDLE~n",
- [EventContent, EventType]),
- {keep_state, State}.
+ io:format(
+ "Event ~p (~p) unhandled in state IDLE~n",
+ [EventContent, EventType]
+ ),
+ {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, 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};
+ 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}, 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};
+ 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) ->
- % 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"),
- {stop, timeout, 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"),
+ {stop, timeout, S};
smr_st_wait_tx_ack(EventType, EventContent, State) ->
- io:format("Event ~p (~p) unhandled in state WAIT_TX_ACK~n",
- [EventContent, EventType]),
- {keep_state, State}.
+ io:format(
+ "Event ~p (~p) unhandled in state WAIT_TX_ACK~n",
+ [EventContent, EventType]
+ ),
+ {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) ->
- {stop, normal, 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) ->
- {stop, normal, S};
+ {stop, normal, S};
% Timeout waiting for RP-ACK / RP-ERROR
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"),
- {stop, timeout, 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"),
+ {stop, timeout, S};
smr_st_wait_rx_ack(EventType, EventContent, State) ->
- io:format("Event ~p (~p) unhandled in state WAIT_RX_ACK~n",
- [EventContent, EventType]),
- {keep_state, State}.
+ io:format(
+ "Event ~p (~p) unhandled in state WAIT_RX_ACK~n",
+ [EventContent, EventType]
+ ),
+ {keep_state, State}.
terminate(Reason, StateName, _State) ->
- io:format("Terminating in state ~p (reason ~p)~n", [StateName, Reason]),
- ok.
+ io:format("Terminating in state ~p (reason ~p)~n", [StateName, Reason]),
+ ok.
code_change(_OldVsn, StateName, State, _Extra) ->
- {ok, StateName, State}.
+ {ok, StateName, State}.