From 6cf416140345bdf8f1d1fb9cfdf7be95779cafdf Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Mon, 19 Aug 2019 23:28:39 +0200 Subject: [PATCH] ipa_proto.erl: fix IPA IDENTITY REQUEST handling --- src/ipa_proto.erl | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/ipa_proto.erl b/src/ipa_proto.erl index 9a3f3d0..8904072 100644 --- a/src/ipa_proto.erl +++ b/src/ipa_proto.erl @@ -93,7 +93,8 @@ controlling_process(Socket, StreamID, NewPid) -> % unblock the socket from further processing unblock(Socket) -> - send_ccm_id_get(Socket), + % FIXME: why are we sending it here?!? + % send_ccm_id_get(Socket), call_sync_sock(Socket, {ipa_unblock, Socket}). @@ -260,15 +261,43 @@ loop(S, StreamMap) -> ok end. +% Length-Tag-Value +gen_ccm_ltv_str(Tag, String) -> + Len = string:len(String) + 1 + 1, + BinString = list_to_binary(String), + << 16#00, Len, Tag, BinString/binary, 16#00 >>. + +% Parse Length-Tag list from the Request +gen_ccm_id_resp(Response, << >>) -> Response; +gen_ccm_id_resp(Response, LTList) -> + << _Len, Tag, Rest/binary >> = LTList, + case Tag of + % Unit ID + 16#08 -> + LTV = gen_ccm_ltv_str(Tag, "0/0/0"), + gen_ccm_id_resp(<< Response/binary, LTV/binary >>, Rest); + % Serial number, Unit name + % FIXME: hard-coded values! + 16#00 -> + LTV = gen_ccm_ltv_str(Tag, "EUSE-OsmoSMSC-00-00-00-00-00-00"), + gen_ccm_id_resp(<< Response/binary, LTV/binary >>, Rest); + 16#01 -> + LTV = gen_ccm_ltv_str(Tag, "EUSE-OsmoSMSC-00-00-00-00-00-00"), + gen_ccm_id_resp(<< Response/binary, LTV/binary >>, Rest); + _ -> + % HACK: for anything else, just use "00:00:00:00:00:00" + LTV = gen_ccm_ltv_str(Tag, "00:00:00:00:00:00"), + gen_ccm_id_resp(<< Response/binary, LTV/binary >>, Rest) + end. + % Respond with PONG to PING process_ccm_msg(Socket, StreamID, ?IPAC_MSGT_PING, _) -> io:format("Socket ~p Stream ~p: PING -> PONG~n", [Socket, StreamID]), send(Socket, StreamID, <>); -% Simply respond to ID_ACK with ID_ACK -process_ccm_msg(Socket, StreamID, ?IPAC_MSGT_ID_ACK, _) -> - io:format("Socket ~p Stream ~p: ID_ACK -> ID_ACK~n", [Socket, StreamID]), - send(Socket, StreamID, <>); -% Simply respond to ID_RESP with ID_ACK +process_ccm_msg(Socket, StreamID, ?IPAC_MSGT_ID_GET, Params) -> + io:format("Socket ~p Stream ~p: ID_GET -> ID_RESP~n", [Socket, StreamID]), + Response = gen_ccm_id_resp(<>, list_to_binary(Params)), + send(Socket, StreamID, Response); process_ccm_msg(Socket, StreamID, ?IPAC_MSGT_ID_RESP, _) -> io:format("Socket ~p Stream ~p: ID_RESP -> ID_ACK~n", [Socket, StreamID]), send(Socket, StreamID, <>);