summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-01-16 21:39:48 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-16 21:39:48 +0100
commit092443629b7de87f4cd2d0fc0de13da3e5a50203 (patch)
tree0df02d5c54dbbd4f18282d32b25dbbb7bfd2c6dc
parent429456f13f59ed5ecf996caa59e76ee9bdd9bb24 (diff)
MTP3: fix encoding of bit/byte ordering in routing label
-rw-r--r--src/mtp3_codec.erl9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mtp3_codec.erl b/src/mtp3_codec.erl
index ae86cdd..cbb9052 100644
--- a/src/mtp3_codec.erl
+++ b/src/mtp3_codec.erl
@@ -28,7 +28,10 @@
% Parse standard routing label according to Section 2.2 of ITU-T Q.704
parse_mtp3_routing_label(_, LabelBin) when is_binary(LabelBin) ->
- <<Sls:4/big, Opc:14/big, Dpc:14/big, Remain/binary>> = LabelBin,
+ % we need to swap the four bytes and then parse the fields
+ <<Label32:32/little, Remain/binary>> = LabelBin,
+ LabelRev = <<Label32:32/big>>,
+ <<Sls:4/big, Dpc:14/big, Opc:14/big>> = LabelRev,
{ok, #mtp3_routing_label{sig_link_sel = Sls, origin_pc = Opc, dest_pc = Dpc}, Remain}.
parse_mtp3_msg(DataBin) when is_binary(DataBin) ->
@@ -43,7 +46,9 @@ encode_mtp3_routing_label(#mtp3_routing_label{sig_link_sel = Sls, origin_pc = Op
dest_pc = DpcIn}) ->
Opc = osmo_util:pointcode2int(OpcIn),
Dpc = osmo_util:pointcode2int(DpcIn),
- <<Sls:4/big, Opc:14/big, Dpc:14/big>>.
+ % we need to swap the four bytes after encoding the fields
+ <<Label32:32/little>> = <<Sls:4/big, Dpc:14/big, Opc:14/big>>,
+ <<Label32:32/big>>.
encode_mtp3_msg(#mtp3_msg{network_ind = NetInd, service_ind = ServiceInd,
routing_label = RoutLbl, payload = Payload}) ->