From 52a5b964920b5c470b19e4b3a37443b8f5fea405 Mon Sep 17 00:00:00 2001 From: Thomas Schneider Date: Sat, 31 Oct 2026 19:03:43 +0100 Subject: Add and apply erlfmt --- src/osmo_smsc_core.erl | 213 +++++++++++++++++++++++++++---------------------- 1 file changed, 118 insertions(+), 95 deletions(-) (limited to 'src/osmo_smsc_core.erl') diff --git a/src/osmo_smsc_core.erl b/src/osmo_smsc_core.erl index ecc47f0..200704b 100644 --- a/src/osmo_smsc_core.erl +++ b/src/osmo_smsc_core.erl @@ -45,132 +45,155 @@ -record(osmo_smsc_state, {interface, map}). sm_tpdu_submit2deliver(TPDUSubmit) -> - << Hdr:1/binary, MR, Tail/binary>> = TPDUSubmit, - << RP:1, UDHI:1, SRR:1, VPF:2, RD:1, MTI:2 >> = Hdr, - - % FIXME: make sure we've got SUBMIT - ?GSM411_TP_MTI_SUBMIT = MTI, - - << DANum, _:1, ODAToN:3, ODANPI:4, DATail/binary >> = Tail, - DALen = (DANum div 2) + (DANum rem 2), % Convert number of digits to number of bits - << DA:DALen/binary, PID, DCS, VPTail/binary >> = DATail, - - % VP is optional and may be either 1 octet or 7 octet long - case VPF of - 16#00 -> - << VP:0/binary, UDL, UD/binary >> = VPTail; - 16#02 -> - << VP:8, UDL, UD/binary >> = VPTail; - _ -> - << VP:56, UDL, UD/binary >> = VPTail - end, - - io:format("Rx SM-TPDU SUBMIT: RD=~p, VPF=~p, SRR=~p, UDHI=~p, RP=~p | " - "MR=~p, PID=~p, DCS=~p, DA len=~p~n", - [RD, VPF, SRR, UDHI, RP, MR, PID, DCS, DALen]), - - % SMS-DELIVER: no Return-Path, no Status-Report, no More-Messages - << 0:1, UDHI:1, 0:1, 0:1, 0:1, 1:1, 0:2, - % FIXME: hard-coded originating address (989108987294) - 16#0c, 16#91, 16#89, 16#19, 16#80, 16#89, 16#27, 16#49, - PID, DCS, - % FIXME: hard-coded Service-Centre-Timestamp - 16#71, 16#90, 16#71, 16#21, 16#70, 16#92, 16#41, - UDL, UD/binary >>. + <> = TPDUSubmit, + <> = Hdr, + + % FIXME: make sure we've got SUBMIT + ?GSM411_TP_MTI_SUBMIT = MTI, + + <> = Tail, + % Convert number of digits to number of bits + DALen = (DANum div 2) + (DANum rem 2), + <> = DATail, + + % VP is optional and may be either 1 octet or 7 octet long + case VPF of + 16#00 -> + <> = VPTail; + 16#02 -> + <> = VPTail; + _ -> + <> = VPTail + end, + + io:format( + "Rx SM-TPDU SUBMIT: RD=~p, VPF=~p, SRR=~p, UDHI=~p, RP=~p | " + "MR=~p, PID=~p, DCS=~p, DA len=~p~n", + [RD, VPF, SRR, UDHI, RP, MR, PID, DCS, DALen] + ), + + % SMS-DELIVER: no Return-Path, no Status-Report, no More-Messages + <<0:1, UDHI:1, 0:1, 0:1, 0:1, 1:1, 0:2, + % FIXME: hard-coded originating address (989108987294) + 16#0c, 16#91, 16#89, 16#19, 16#80, 16#89, 16#27, 16#49, PID, DCS, + % FIXME: hard-coded Service-Centre-Timestamp + 16#71, 16#90, 16#71, 16#21, 16#70, 16#92, 16#41, UDL, UD/binary>>. %% ------------------------------------------------------------------ %% our exported API %% ------------------------------------------------------------------ start() -> - gen_server:start(?MODULE, [], [{debug, [trace]}]). + gen_server:start(?MODULE, [], [{debug, [trace]}]). start_link() -> - gen_server:start_link(?MODULE, [], [{debug, [trace]}]). + gen_server:start_link(?MODULE, [], [{debug, [trace]}]). %% ------------------------------------------------------------------ %% gen_server Function Definitions %% ------------------------------------------------------------------ init([]) -> - % FIXME: IPA/GSUP is the only supported interface for now - {ok, Pid} = osmo_gsup_if:start_link(self(), {"127.0.0.1", 4222, []}), - {ok, #osmo_smsc_state{interface = Pid, map = #{}}}. + % FIXME: IPA/GSUP is the only supported interface for now + {ok, Pid} = osmo_gsup_if:start_link(self(), {"127.0.0.1", 4222, []}), + {ok, #osmo_smsc_state{interface = Pid, map = #{}}}. % Events coming from the external interfaces (IPA/GSUP, MAP, ...) handle_cast({smsc_ev_mo_fwd_sm_req, IMSI, MR, DA, OA, TPDU}, State) -> - {Interface, Core} = {State#osmo_smsc_state.interface, self()}, - {ok, MOFsm} = sm_rp_trans:start(Interface, Core), - {ok, MTFsm} = sm_rp_trans:start(Interface, Core), - - % FIXME: check if we already have Key = {IMSI, MR} - Mapping = maps:put({IMSI, MR}, {MOFsm, MTFsm}, - State#osmo_smsc_state.map), - - % HACK: we do not (yet) have the database, so here we forward the SMS immediately - ok = gen_statem:call(MOFsm, {smr_ev_fwd_mo_sm_req, #smr_data{ - imsi = IMSI, msg_ref = MR, - orig_addr = OA, dest_addr = DA, - tpdu = TPDU}}), - ok = gen_statem:call(MTFsm, {smr_ev_fwd_mt_sm_req, #smr_data{ - imsi = IMSI, msg_ref = 16#ff, orig_addr = DA, - dest_addr = OA, % FIXME: extract from TPDU! - tpdu = sm_tpdu_submit2deliver(TPDU)}}), - - {noreply, State#osmo_smsc_state{map = Mapping}}; - + {Interface, Core} = {State#osmo_smsc_state.interface, self()}, + {ok, MOFsm} = sm_rp_trans:start(Interface, Core), + {ok, MTFsm} = sm_rp_trans:start(Interface, Core), + + % FIXME: check if we already have Key = {IMSI, MR} + Mapping = maps:put( + {IMSI, MR}, + {MOFsm, MTFsm}, + State#osmo_smsc_state.map + ), + + % HACK: we do not (yet) have the database, so here we forward the SMS immediately + ok = gen_statem:call( + MOFsm, + {smr_ev_fwd_mo_sm_req, #smr_data{ + imsi = IMSI, + msg_ref = MR, + orig_addr = OA, + dest_addr = DA, + tpdu = TPDU + }} + ), + ok = gen_statem:call( + MTFsm, + {smr_ev_fwd_mt_sm_req, #smr_data{ + imsi = IMSI, + msg_ref = 16#ff, + orig_addr = DA, + % FIXME: extract from TPDU! + dest_addr = OA, + tpdu = sm_tpdu_submit2deliver(TPDU) + }} + ), + + {noreply, State#osmo_smsc_state{map = Mapping}}; handle_cast({smsc_ev_mt_fwd_sm_ack, IMSI, MR}, State) -> - {MOFsm, MTFsm} = maps:get({IMSI, MR}, State#osmo_smsc_state.map), - ok = gen_statem:call(MTFsm, smr_ev_fwd_mt_sm_ack), - ok = gen_statem:call(MOFsm, smr_ev_fwd_mo_sm_ack), - {noreply, State}; - + {MOFsm, MTFsm} = maps:get({IMSI, MR}, State#osmo_smsc_state.map), + ok = gen_statem:call(MTFsm, smr_ev_fwd_mt_sm_ack), + ok = gen_statem:call(MOFsm, smr_ev_fwd_mo_sm_ack), + {noreply, State}; handle_cast({smsc_ev_mt_fwd_sm_err, IMSI, MR, Cause}, State) -> - {MOFsm, MTFsm} = maps:get({IMSI, MR}, State#osmo_smsc_state.map), - ok = gen_statem:call(MTFsm, {smr_ev_fwd_mt_sm_err, Cause}), - ok = gen_statem:call(MOFsm, {smr_ev_fwd_mo_sm_err, Cause}), - {noreply, State}; - + {MOFsm, MTFsm} = maps:get({IMSI, MR}, State#osmo_smsc_state.map), + ok = gen_statem:call(MTFsm, {smr_ev_fwd_mt_sm_err, Cause}), + ok = gen_statem:call(MOFsm, {smr_ev_fwd_mo_sm_err, Cause}), + {noreply, State}; % Events coming from SMR state machines % TODO: remove mappings on termination % FIXME: we need IMSI! handle_cast({smr_ev_fwd_mo_sm_req, {IMSI, MR, OA, DA, TPDU}}, State) -> - {_MOFsm, MTFsm} = maps:get({IMSI, MR}, State#osmo_smsc_state.map), - ok = gen_statem:call(MTFsm, {smsc_ev_mt_fwd_sm_req, #smr_data{ - msg_ref = 16#ff, orig_addr = DA, - dest_addr = OA, % FIXME: extract from TPDU! - tpdu = sm_tpdu_submit2deliver(TPDU)}}), - {noreply, State}; - + {_MOFsm, MTFsm} = maps:get({IMSI, MR}, State#osmo_smsc_state.map), + ok = gen_statem:call( + MTFsm, + {smsc_ev_mt_fwd_sm_req, #smr_data{ + msg_ref = 16#ff, + orig_addr = DA, + % FIXME: extract from TPDU! + dest_addr = OA, + tpdu = sm_tpdu_submit2deliver(TPDU) + }} + ), + {noreply, State}; handle_cast({smr_ev_mt_fwd_sm_ack, IMSI, MR}, State) -> - {noreply, State}; - + {noreply, State}; handle_cast({smr_ev_mt_fwd_sm_err, IMSI, MR, Cause}, State) -> - {noreply, State}; - + {noreply, State}; handle_cast(Message, State) -> - error_logger:error_report(["unknown gen_server:cast()", - {module, ?MODULE}, - {message, Message}, - {state, State}]), - {noreply, State}. + error_logger:error_report([ + "unknown gen_server:cast()", + {module, ?MODULE}, + {message, Message}, + {state, State} + ]), + {noreply, State}. handle_call(Message, _From, State) -> - error_logger:error_report(["unknown gen_server:call()", - {module, ?MODULE}, - {message, Message}, - {state, State}]), - {reply, unknown_call, State}. + error_logger:error_report([ + "unknown gen_server:call()", + {module, ?MODULE}, + {message, Message}, + {state, State} + ]), + {reply, unknown_call, State}. handle_info(Info, State) -> - error_logger:error_report(["unknown handle_info", - {module, ?MODULE}, - {info, Info}, - {state, State}]), - {noreply, State}. + error_logger:error_report([ + "unknown handle_info", + {module, ?MODULE}, + {info, Info}, + {state, State} + ]), + {noreply, State}. terminate(Reason, _State) -> - io:format("Terminating ~p with reason ~p~n", [?MODULE, Reason]). + io:format("Terminating ~p with reason ~p~n", [?MODULE, Reason]). code_change(_OldVsn, State, _Extra) -> - {ok, State}. + {ok, State}. -- cgit v1.2.3