osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-s1gw/+/37039?usp=email )
Change subject: Decode S1AP PDUs and log them while forwarding ......................................................................
Decode S1AP PDUs and log them while forwarding
Change-Id: Iac1db3dbbf9b72fbd301b4c4133df3cb8c85cf89 --- A src/s1ap_proxy.erl M src/sctp_proxy.erl 2 files changed, 44 insertions(+), 2 deletions(-)
Approvals: osmith: Looks good to me, approved; Verified
diff --git a/src/s1ap_proxy.erl b/src/s1ap_proxy.erl new file mode 100644 index 0000000..62701ef --- /dev/null +++ b/src/s1ap_proxy.erl @@ -0,0 +1,31 @@ +-module(s1ap_proxy). + +-export([handle_pdu/1]). + +%% ------------------------------------------------------------------ +%% public API +%% ------------------------------------------------------------------ + +%% Process an S1AP PDU +handle_pdu(Data) -> + case decode_pdu(Data) of + {ok, Pdu} -> + logger:info("S1AP PDU: ~p", [Pdu]), + Data; + {error, {asn1, Error}} -> + logger:error("S1AP PDU decoding failed: ~p", [Error]), + Data + end. + + +%% ------------------------------------------------------------------ +%% private API +%% ------------------------------------------------------------------ + +%% Decode an S1AP PDU +-spec decode_pdu(binary()) -> {ok, tuple()} | + {error, {asn1, tuple()}}. +decode_pdu(Data) -> + 'S1AP-PDU-Descriptions':decode('S1AP-PDU', Data). + +%% vim:set ts=4 sw=4 et: diff --git a/src/sctp_proxy.erl b/src/sctp_proxy.erl index e09720c..2cc6165 100644 --- a/src/sctp_proxy.erl +++ b/src/sctp_proxy.erl @@ -121,7 +121,8 @@ {[#sctp_sndrcvinfo{assoc_id = Aid}], Data}}, S) -> logger:info("MME connection (id=~p, ~p:~p) Rx ~p", [Aid, MmeAddr, MmePort, Data]), - sctp_server:send_data(maps:get(enb_aid, S), Data), + sctp_server:send_data(maps:get(enb_aid, S), + s1ap_proxy:handle_pdu(Data)), {keep_state, S};
%% Catch-all for other kinds of SCTP events @@ -160,7 +161,8 @@
%% Send a single message to the MME sctp_send(#{sock := Sock, mme_aid := Aid}, Data) -> - sctp_client:send_data({Sock, Aid}, Data). + sctp_client:send_data({Sock, Aid}, + s1ap_proxy:handle_pdu(Data)).
%% Send pending messages to the MME