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_gsup_if.erl | 246 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 144 insertions(+), 102 deletions(-) (limited to 'src/osmo_gsup_if.erl') diff --git a/src/osmo_gsup_if.erl b/src/osmo_gsup_if.erl index 7b95376..943d70c 100644 --- a/src/osmo_gsup_if.erl +++ b/src/osmo_gsup_if.erl @@ -38,14 +38,14 @@ -include_lib("osmo_gsup/include/gsup_protocol.hrl"). --define(IPAC_PROTO_EXT_GSUP, {osmo, 5}). +-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 - }). + core, + socket, + ipa_pid +}). -export([start_link/2]). @@ -57,129 +57,171 @@ %% ------------------------------------------------------------------ start_link(Core, HLRAddr) -> - gen_server:start_link(?MODULE, [Core, HLRAddr], [{debug, [trace]}]). + gen_server:start_link(?MODULE, [Core, HLRAddr], [{debug, [trace]}]). %% ------------------------------------------------------------------ %% gen_server Function Definitions %% ------------------------------------------------------------------ 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{core = Core, socket = Socket, ipa_pid = IpaPid}}. + 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{core = Core, socket = Socket, ipa_pid = IpaPid}}. -define(IPA_GSUP_STREAM_ID, {osmo, 16#05}). -define(GSUP_MSG_CLS_SM, 16#02). gen_sm_response(GSUPMsg, MsgType) -> - #{message_class => ?GSUP_MSG_CLS_SM, - message_type => MsgType, - imsi => maps:get(imsi, GSUPMsg), - sm_rp_mr => maps:get(sm_rp_mr, GSUPMsg), - source_name => << "EUSE-OsmoSMSC-00-00-00-00-00-00", 0 >>, - destination_name => maps:get(source_name, GSUPMsg)}. + #{ + message_class => ?GSUP_MSG_CLS_SM, + message_type => MsgType, + imsi => maps:get(imsi, GSUPMsg), + sm_rp_mr => maps:get(sm_rp_mr, GSUPMsg), + source_name => <<"EUSE-OsmoSMSC-00-00-00-00-00-00", 0>>, + destination_name => maps:get(source_name, GSUPMsg) + }. % IPA/GSUP messages from OsmoHLR handle_cast({ipa, ?IPA_GSUP_STREAM_ID, GSUPMsg}, State) -> - % Obtain mandatory IEs - #{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_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} -> - 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_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}, - {message, GSUPMsg}, - {state, State}]) - end, - {noreply, State}; - + % Obtain mandatory IEs + #{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_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} -> + 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_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}, + {message, GSUPMsg}, + {state, 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}; - + #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}; - + 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}; - + 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", - {module, ?MODULE}, - {stream_id, StreamID}, - {message, GSUPMsg}, - {state, State}]), - {noreply, State}; - + error_logger:error_report([ + "unknown IPA message", + {module, ?MODULE}, + {stream_id, StreamID}, + {message, GSUPMsg}, + {state, State} + ]), + {noreply, State}; handle_cast(Info, State) -> - error_logger:error_report(["unknown gen_server:cast()", - {module, ?MODULE}, - {info, Info}, - {state, State}]), - {noreply, State}. + error_logger:error_report([ + "unknown gen_server:cast()", + {module, ?MODULE}, + {info, Info}, + {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_msg, State}. + error_logger:error_report([ + "unknown gen_server:call()", + {module, ?MODULE}, + {message, Message}, + {state, State} + ]), + {reply, unknown_msg, 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