<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/erlang/osmo_ss7/+/19807">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Add IPA CCM protocol encoder/decoder<br><br>This uses the new 'codec' infrastructure of our Erlang IPA<br>implementation to decode/encode the IPA CCM messages.<br><br>Change-Id: I9575145acbb6e3aff57f8bd97d327cbcd81b3665<br>---<br>A src/ipa_proto_ccm.erl<br>1 file changed, 119 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/ipa_proto_ccm.erl b/src/ipa_proto_ccm.erl</span><br><span>new file mode 100644</span><br><span>index 0000000..cfd3863</span><br><span>--- /dev/null</span><br><span>+++ b/src/ipa_proto_ccm.erl</span><br><span>@@ -0,0 +1,119 @@</span><br><span style="color: hsl(120, 100%, 40%);">+% ip.access IPA CCM protocol </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+% (C) 2019 by Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+%</span><br><span style="color: hsl(120, 100%, 40%);">+% All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+%</span><br><span style="color: hsl(120, 100%, 40%);">+% This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+% it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+% the Free Software Foundation; either version 2 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+% (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+%</span><br><span style="color: hsl(120, 100%, 40%);">+% This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+% but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+% GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+%</span><br><span style="color: hsl(120, 100%, 40%);">+% You should have received a copy of the GNU General Public License along</span><br><span style="color: hsl(120, 100%, 40%);">+% with this program; if not, write to the Free Software Foundation, Inc.,</span><br><span style="color: hsl(120, 100%, 40%);">+% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+-module(ipa_proto_ccm).</span><br><span style="color: hsl(120, 100%, 40%);">+-author('Harald Welte <laforge@gnumonks.org>').</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+-export([decode/1, encode/1]).</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+-define(TESTMSG, <<5,0,7,8,48,47,48,47,48,0,0,19,7,48,48,58,48,48,58,48,48,58,48,48,58,48,48,58,</span><br><span style="color: hsl(120, 100%, 40%);">+  48,48,0,0,19,2,48,48,58,48,48,58,48,48,58,48,48,58,48,48,58,48,48,0,0,19,3,</span><br><span style="color: hsl(120, 100%, 40%);">+  48,48,58,48,48,58,48,48,58,48,48,58,48,48,58,48,48,0,0,19,4,48,48,58,48,48,</span><br><span style="color: hsl(120, 100%, 40%);">+  58,48,48,58,48,48,58,48,48,58,48,48,0,0,24,5,111,115,109,111,45,109,115,99,</span><br><span style="color: hsl(120, 100%, 40%);">+  45,49,46,51,46,49,46,49,49,45,52,50,55,50,0,0,23,1,77,83,67,45,48,48,45,48,</span><br><span style="color: hsl(120, 100%, 40%);">+  48,45,48,48,45,48,48,45,48,48,45,48,48,0,0,23,0,77,83,67,45,48,48,45,48,48,</span><br><span style="color: hsl(120, 100%, 40%);">+  45,48,48,45,48,48,45,48,48,45,48,48,0>>).</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(0) -> ping;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(1) -> pong;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(4) -> id_req;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(5) -> id_resp;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(6) -> id_ack;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(7) -> id_nack;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(8) -> proxy_req;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(9) -> proxy_ack;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(10) -> proxy_nack;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_msgt(Int) when is_integer(Int) -> Int.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(ping) -> 0;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(pong) -> 1;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(id_req) -> 4;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(id_resp) -> 5;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(id_ack) -> 6;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(id_nack) -> 7;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(proxy_req) -> 8;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(proxy_ack) -> 9;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(proxy_nack) -> 10;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_msgt(Int) when is_integer(Int) -> Int.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(0) -> serial_nr;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(1) -> unit_name;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(2) -> location;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(3) -> unit_type;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(4) -> equip_vers;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(5) -> sw_version;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(6) -> ip_address;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(7) -> mac_address;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(8) -> unit_id;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_idtag(Int) when is_integer(Int) -> Int.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(serial_nr) -> 0;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(unit_name) -> 1;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(location) -> 2;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(unit_type) -> 3;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(equip_vers) -> 4;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(sw_version) -> 5;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(ip_address) -> 6;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(mac_address) -> 7;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(unit_id) -> 8;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_idtag(Int) when is_integer(Int) -> Int.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+decode(Bin) when is_binary(Bin) -></span><br><span style="color: hsl(120, 100%, 40%);">+   <<MsgType:8, IeList/binary>> = Bin,</span><br><span style="color: hsl(120, 100%, 40%);">+       {decode_msgt(MsgType), decode_ies(IeList, [])}.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+decode_ies(<<>>, IeList) when is_list(IeList) -></span><br><span style="color: hsl(120, 100%, 40%);">+    IeList;</span><br><span style="color: hsl(120, 100%, 40%);">+decode_ies(<<1:8, IdTag:8, Remain/binary>>, IeList) when is_list(IeList) -></span><br><span style="color: hsl(120, 100%, 40%);">+   decode_ies(Remain, IeList ++ [{id, IdTag}]);</span><br><span style="color: hsl(120, 100%, 40%);">+decode_ies(<<0:8, Len:8, TypeValue:Len/binary, Remain/binary>>, IeList) when is_list(IeList) -></span><br><span style="color: hsl(120, 100%, 40%);">+  <<Type:8, Value/binary>> = TypeValue,</span><br><span style="color: hsl(120, 100%, 40%);">+     ValueList = binary_to_list(Value),</span><br><span style="color: hsl(120, 100%, 40%);">+    case lists:last(ValueList) of</span><br><span style="color: hsl(120, 100%, 40%);">+         0 -> ValueStripped = lists:droplast(ValueList);</span><br><span style="color: hsl(120, 100%, 40%);">+            _ -> ValueStripped = ValueList</span><br><span style="color: hsl(120, 100%, 40%);">+     end,</span><br><span style="color: hsl(120, 100%, 40%);">+  decode_ies(Remain, IeList ++ [{string, decode_idtag(Type), ValueStripped}]).</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+encode_ie({id, IdTag}) -></span><br><span style="color: hsl(120, 100%, 40%);">+        <<1:8, IdTag:8>>;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_ie({string, Type, Value}) -></span><br><span style="color: hsl(120, 100%, 40%);">+ case lists:last(Value) of</span><br><span style="color: hsl(120, 100%, 40%);">+             0 -> ValueTerminated = Value;</span><br><span style="color: hsl(120, 100%, 40%);">+              _ -> ValueTerminated = lists:append(Value, [0])</span><br><span style="color: hsl(120, 100%, 40%);">+    end,</span><br><span style="color: hsl(120, 100%, 40%);">+  ValueBin = list_to_binary(ValueTerminated),</span><br><span style="color: hsl(120, 100%, 40%);">+   Type2 = encode_idtag(Type),</span><br><span style="color: hsl(120, 100%, 40%);">+   TypeValue = <<Type2:8, ValueBin/binary>>,</span><br><span style="color: hsl(120, 100%, 40%);">+ Len = byte_size(TypeValue),</span><br><span style="color: hsl(120, 100%, 40%);">+   <<0:8, Len:8, TypeValue/binary>>.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+encode_ies(IeList) when is_list(IeList) -></span><br><span style="color: hsl(120, 100%, 40%);">+        encode_ies(IeList, <<>>).</span><br><span style="color: hsl(120, 100%, 40%);">+encode_ies([], Bin) -> Bin;</span><br><span style="color: hsl(120, 100%, 40%);">+encode_ies([Head|Tail], Bin) -></span><br><span style="color: hsl(120, 100%, 40%);">+     IeBin = encode_ie(Head),</span><br><span style="color: hsl(120, 100%, 40%);">+      encode_ies(Tail, <<Bin/binary, IeBin/binary>>).</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+encode({MsgType, IeList}) -></span><br><span style="color: hsl(120, 100%, 40%);">+        MsgtInt = encode_msgt(MsgType),</span><br><span style="color: hsl(120, 100%, 40%);">+       IesBin = encode_ies(IeList),</span><br><span style="color: hsl(120, 100%, 40%);">+  <<MsgtInt:8, IesBin/binary>>.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/erlang/osmo_ss7/+/19807">change 19807</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/erlang/osmo_ss7/+/19807"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: erlang/osmo_ss7 </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I9575145acbb6e3aff57f8bd97d327cbcd81b3665 </div>
<div style="display:none"> Gerrit-Change-Number: 19807 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>