From add2157701a41faf34f33419623d6349ec7dadbe Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 15 Aug 2019 22:25:51 +0200 Subject: Rename gsup_client.erl to osmo_gsup_if.erl Later on we may introduce more interfaces (MAP and SMPP) to communicate with the external entities, so let's introduce and follow a common naming scheme: "*_if.erl". --- src/gsup_client.erl | 101 -------------------------------------------------- src/osmo_gsup_if.erl | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 101 deletions(-) delete mode 100644 src/gsup_client.erl create mode 100644 src/osmo_gsup_if.erl diff --git a/src/gsup_client.erl b/src/gsup_client.erl deleted file mode 100644 index 05eddb1..0000000 --- a/src/gsup_client.erl +++ /dev/null @@ -1,101 +0,0 @@ -% simple, blocking/synchronous GSUP client - -% (C) 2019 by Harald Welte -% -% All Rights Reserved -% -% This program is free software; you can redistribute it and/or modify -% it under the terms of the GNU Affero General Public License as -% published by the Free Software Foundation; either version 3 of the -% License, or (at your option) any later version. -% -% This program is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU Affero General Public License -% along with this program. If not, see . -% -% Additional Permission under GNU AGPL version 3 section 7: -% -% If you modify this Program, or any covered work, by linking or -% combining it with runtime libraries of Erlang/OTP as released by -% Ericsson on http://www.erlang.org (or a modified version of these -% libraries), containing parts covered by the terms of the Erlang Public -% License (http://www.erlang.org/EPLICENSE), the licensors of this -% Program grant you additional permission to convey the resulting work -% without the need to license the runtime libraries of Erlang/OTP under -% the GNU Affero General Public License. Corresponding Source for a -% non-source form of such a combination shall include the source code -% for the parts of the runtime libraries of Erlang/OTP used as well as -% that of the covered work. - --module(gsup_client). - --behaviour(gen_server). - --include_lib("osmo_gsup/include/gsup_protocol.hrl"). - --define(IPAC_PROTO_EXT_GSUP, {osmo, 5}). - --record(gsupc_state, { - socket, - ipa_pid - }). - --export([start_link/3]). - --export([init/1, handle_call/3, handle_cast/2, handle_info/2]). --export([code_change/3, terminate/2]). - -%% ------------------------------------------------------------------ -%% our exported API -%% ------------------------------------------------------------------ - -start_link(ServerAddr, ServerPort, Options) -> - gen_server:start_link(?MODULE, [ServerAddr, ServerPort, Options], [{debug, [trace]}]). - -%% ------------------------------------------------------------------ -%% gen_server Function Definitions -%% ------------------------------------------------------------------ - -init([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}}. - - -% 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]). - -code_change(_OldVsn, State, _Extra) -> - {ok, State}. diff --git a/src/osmo_gsup_if.erl b/src/osmo_gsup_if.erl new file mode 100644 index 0000000..748771e --- /dev/null +++ b/src/osmo_gsup_if.erl @@ -0,0 +1,102 @@ +% Osmocom GSUP (Generic Subscriber Update Protocol) interface. +% Simple, blocking / synchronous GSUP client (SMSC -> OsmoHLR). +% +% (C) 2019 by Harald Welte +% +% All Rights Reserved +% +% This program is free software; you can redistribute it and/or modify +% it under the terms of the GNU Affero General Public License as +% published by the Free Software Foundation; either version 3 of the +% License, or (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU Affero General Public License +% along with this program. If not, see . +% +% Additional Permission under GNU AGPL version 3 section 7: +% +% If you modify this Program, or any covered work, by linking or +% combining it with runtime libraries of Erlang/OTP as released by +% Ericsson on http://www.erlang.org (or a modified version of these +% libraries), containing parts covered by the terms of the Erlang Public +% License (http://www.erlang.org/EPLICENSE), the licensors of this +% Program grant you additional permission to convey the resulting work +% without the need to license the runtime libraries of Erlang/OTP under +% the GNU Affero General Public License. Corresponding Source for a +% non-source form of such a combination shall include the source code +% for the parts of the runtime libraries of Erlang/OTP used as well as +% that of the covered work. + +-module(osmo_gsup_if). + +-behaviour(gen_server). + +-include_lib("osmo_gsup/include/gsup_protocol.hrl"). + +-define(IPAC_PROTO_EXT_GSUP, {osmo, 5}). + +-record(gsupc_state, { + socket, + ipa_pid + }). + +-export([start_link/3]). + +-export([init/1, handle_call/3, handle_cast/2, handle_info/2]). +-export([code_change/3, terminate/2]). + +%% ------------------------------------------------------------------ +%% our exported API +%% ------------------------------------------------------------------ + +start_link(ServerAddr, ServerPort, Options) -> + gen_server:start_link(?MODULE, [ServerAddr, ServerPort, Options], [{debug, [trace]}]). + +%% ------------------------------------------------------------------ +%% gen_server Function Definitions +%% ------------------------------------------------------------------ + +init([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}}. + + +% 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]). + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. -- cgit v1.2.3