summaryrefslogtreecommitdiffstats
path: root/src/mtp3_codec.erl
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2012-01-16 15:59:27 +0100
committerHarald Welte <laforge@gnumonks.org>2012-01-16 15:59:27 +0100
commit642a68b017aa3dfdc2a57164843ffeda05490729 (patch)
treeafbfc10e96ac5f2199adb566b2749f4fc1e78806 /src/mtp3_codec.erl
parentd9c318fdca63c418436727e6dc19e45064df16b1 (diff)
mtp3: add encoder/decoder for MTP3MG
Diffstat (limited to 'src/mtp3_codec.erl')
-rw-r--r--src/mtp3_codec.erl19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/mtp3_codec.erl b/src/mtp3_codec.erl
index df5b6b1..0fca990 100644
--- a/src/mtp3_codec.erl
+++ b/src/mtp3_codec.erl
@@ -34,8 +34,9 @@ parse_mtp3_routing_label(_, LabelBin) when is_binary(LabelBin) ->
parse_mtp3_msg(DataBin) when is_binary(DataBin) ->
<<NetInd:2, 0:2, ServiceInd:4, Remain/binary>> = DataBin,
{ok, RoutLbl, Payload} = parse_mtp3_routing_label(ServiceInd, Remain),
+ PayloadDec = decode_payload(ServiceInd, Payload),
#mtp3_msg{network_ind = NetInd, service_ind = ServiceInd, routing_label = RoutLbl,
- payload = Payload}.
+ payload = PayloadDec}.
encode_mtp3_routing_label(#mtp3_routing_label{sig_link_sel = Sls, origin_pc = OpcIn,
@@ -47,5 +48,19 @@ encode_mtp3_routing_label(#mtp3_routing_label{sig_link_sel = Sls, origin_pc = Op
encode_mtp3_msg(#mtp3_msg{network_ind = NetInd, service_ind = ServiceInd,
routing_label = RoutLbl, payload = Payload}) ->
RoutLblBin = encode_mtp3_routing_label(RoutLbl),
- <<NetInd:2, 0:2, ServiceInd:4, RoutLblBin/binary, Payload/binary>>.
+ PayloadBin = payload_to_binary(Payload),
+ <<NetInd:2, 0:2, ServiceInd:4, RoutLblBin/binary, PayloadBin/binary>>.
+
+
+decode_payload(?MTP3_SERV_MGMT, Payload) ->
+ <<H0:4, H1:4, _:4, Len:4, TP/binary>> = Payload,
+ #mtp3mg_msg{h0 = H0, h1 = H1, test_pattern = TP};
+decode_payload(_, Payload) ->
+ Payload.
+
+payload_to_binary(#mtp3mg_msg{h0=H0, h1=H1, test_pattern=TP}) ->
+ Len = byte_size(TP),
+ <<H0:4, H1:4, 0:4, Len:4, TP/binary>>;
+payload_to_binary(Whatever) ->
+ Whatever.