diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ipa_proto.erl | 2 | ||||
| -rw-r--r-- | src/osmo_gsup_if.erl | 97 |
2 files changed, 71 insertions, 28 deletions
diff --git a/src/ipa_proto.erl b/src/ipa_proto.erl index 3bd5754..662d60e 100644 --- a/src/ipa_proto.erl +++ b/src/ipa_proto.erl @@ -133,7 +133,7 @@ deliver_rx_ipa_msg(Socket, StreamID, StreamMap, DataBin) -> DataDec = try_decode(StreamID, DataBin), case ets:lookup(StreamMap, {Socket, StreamID}) of [{_,{process_id, Pid}}] -> - Pid ! {ipa, Socket, StreamID, DataDec}; + gen_server:cast(Pid, {ipa, StreamID, DataDec}); [{_,{callback_fn, Fn, Args}}] -> Fn(Socket, StreamID, DataDec, Args); [] -> diff --git a/src/osmo_gsup_if.erl b/src/osmo_gsup_if.erl index 748771e..ca5cc5a 100644 --- a/src/osmo_gsup_if.erl +++ b/src/osmo_gsup_if.erl @@ -70,33 +70,76 @@ init([Address, Port, Options]) -> ipa_proto:unblock(Socket), {ok, #gsupc_state{socket=Socket, ipa_pid=IpaPid}}. - -% send a given GSUP message and synchronously wait for message type ExpRes or ExpErr -handle_call({transceive_gsup, GsupMsgTx, ExpRes, ExpErr}, _From, State) -> - Socket = State#gsupc_state.socket, - {ok, Imsi} = maps:find(imsi, GsupMsgTx), - ipa_proto:send(Socket, ?IPAC_PROTO_EXT_GSUP, GsupMsgTx), - % selective receive for only those GSUP responses we expect - receive - {ipa, Socket, ?IPAC_PROTO_EXT_GSUP, GsupMsgRx = #{message_type := ExpRes, imsi := Imsi}} -> - {reply, GsupMsgRx, State}; - - {ipa, Socket, ?IPAC_PROTO_EXT_GSUP, GsupMsgRx = #{message_type := ExpErr, imsi := Imsi}} -> - {reply, GsupMsgRx, State} - after 5000 -> - {reply, timeout, State} - end. - -handle_cast(Info, S) -> - error_logger:error_report(["unknown handle_cast", {module, ?MODULE}, {info, Info}, {state, S}]), - {noreply, S}. - -handle_info(Info, S) -> - error_logger:error_report(["unknown handle_info", {module, ?MODULE}, {info, Info}, {state, S}]), - {noreply, S}. - -terminate(Reason, _S) -> - lager:info("terminating ~p with reason ~p~n", [?MODULE, Reason]). +-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)}. + +% IPA/GSUP messages from OsmoHLR +handle_cast({ipa, ?IPA_GSUP_STREAM_ID, GSUPMsg}, State) -> + % Obtain mandatory IEs + #{imsi := IMSI, sm_rp_mr := RPRef} = 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 := 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]); + % 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]); + _ -> + error_logger:error_report(["unknown GSUP message", + {module, ?MODULE}, + {message, GSUPMsg}, + {state, State}]) + end, + {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}; + +handle_cast(Info, 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}. + +handle_info(Info, 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]). code_change(_OldVsn, State, _Extra) -> {ok, State}. |
