diff options
author | Harald Welte <laforge@gnumonks.org> | 2012-01-16 20:03:37 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2012-01-16 20:03:37 +0100 |
commit | 429456f13f59ed5ecf996caa59e76ee9bdd9bb24 (patch) | |
tree | aa282df99c43e1fdc3961a0e95e7b4b9787691c4 | |
parent | b668988e25d8edc98a73c4fde0f4a7a7133f5938 (diff) |
MTP3: parsing of mgmt messages
-rw-r--r-- | include/mtp3.hrl | 9 | ||||
-rw-r--r-- | src/mtp3_codec.erl | 15 |
2 files changed, 19 insertions, 5 deletions
diff --git a/include/mtp3.hrl b/include/mtp3.hrl index 6c0833d..22f4603 100644 --- a/include/mtp3.hrl +++ b/include/mtp3.hrl @@ -21,4 +21,13 @@ payload }). +-record(mtp3mg_msg, { + h0, + h1, + payload + }). + +-define(MTP3MG_H0_TEST, 1). +-define(MTP3MG_H1_SLTM, 1). +-define(MTP3MG_H1_SLTA, 2). diff --git a/src/mtp3_codec.erl b/src/mtp3_codec.erl index 0fca990..ae86cdd 100644 --- a/src/mtp3_codec.erl +++ b/src/mtp3_codec.erl @@ -48,19 +48,24 @@ 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), - PayloadBin = payload_to_binary(Payload), + PayloadBin = payload_to_binary(ServiceInd, Payload), <<NetInd:2, 0:2, ServiceInd:4, RoutLblBin/binary, PayloadBin/binary>>. -decode_payload(?MTP3_SERV_MGMT, Payload) -> +decode_payload(?MTP3_SERV_MTN, Payload) -> <<H0:4, H1:4, _:4, Len:4, TP/binary>> = Payload, - #mtp3mg_msg{h0 = H0, h1 = H1, test_pattern = TP}; + #mtp3mg_msg{h0 = H0, h1 = H1, payload = TP}; +decode_payload(?MTP3_SERV_MGMT, Payload) -> + <<H0:4, H1:4, Remain/binary>> = Payload, + #mtp3mg_msg{h0 = H0, h1 = H1, payload = Payload}; decode_payload(_, Payload) -> Payload. -payload_to_binary(#mtp3mg_msg{h0=H0, h1=H1, test_pattern=TP}) -> +payload_to_binary(?MTP3_SERV_MTN, #mtp3mg_msg{h0=H0, h1=H1, payload=TP}) -> Len = byte_size(TP), <<H0:4, H1:4, 0:4, Len:4, TP/binary>>; -payload_to_binary(Whatever) -> +payload_to_binary(?MTP3_SERV_MGMT, #mtp3mg_msg{h0=H0, h1=H1, payload=Payload}) -> + <<H0:4, H1:4, Payload/binary>>; +payload_to_binary(_, Whatever) -> Whatever. |