user_message_reference/tag values not decoding properly
archseer opened this issue · 2 comments
archseer commented
This deliver_sm packet has a user_message_reference
optional value.
└─ λ xxd raw.bin
00000000: 0000 004a 0000 0005 0000 0000 2710 150e ...J........'...
00000010: 0001 0131 3231 3233 3435 3637 3839 0001 ...12123456789..
00000020: 0131 3233 3435 3637 3839 3031 0000 0000 .12345678901....
00000030: 0000 0000 0300 0d4d 6f72 6520 6d65 7373 .......More mess
00000040: 6167 6573 0204 0002 004d ages.....M
But when decoding, it's returned as 516
(0x0204 = user_message_reference) in the optional
map, instead of decoded properly.
iex(13)> v = File.read!("raw.bin")
<<0, 0, 0, 74, 0, 0, 0, 5, 0, 0, 0, 0, 39, 16, 21, 14, 0, 1, 1, 49, 50, 49, 50,
51, 52, 53, 54, 55, 56, 57, 0, 1, 1, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48,
49, 0, 0, 0, 0, 0, 0, ...>>
iex(14)> SMPPEX.Protocol.parse(v)
{:ok,
{:pdu,
%SMPPEX.Pdu{command_id: 5, command_status: 0,
mandatory: %{data_coding: 3, dest_addr_npi: 1, dest_addr_ton: 1,
destination_addr: "12345678901", esm_class: 0, priority_flag: 0,
protocol_id: 0, registered_delivery: 0, replace_if_present_flag: 0,
schedule_delivery_time: "", service_type: "",
short_message: "More messages", sm_default_msg_id: 0, sm_length: 13,
source_addr: "12123456789", source_addr_npi: 1, source_addr_ton: 1,
validity_period: ""}, optional: %{516 => 77},
ref: #Reference<0.0.262145.195893>, sequence_number: 655365390}}, ""}
Meanwhile, Wireshark does correctly parse it:
archseer commented
Ah unless that is by design? The TLV parser doesn't seem to use the tag ID. It was just surprising since all the other keys were atoms.
savonarola commented
Hello!
Although parsed optional fields are stored by ids, one can still access them by name:
iex(1)> pdu = %SMPPEX.Pdu{command_id: 5, command_status: 0,
...(1)> mandatory: %{data_coding: 3, dest_addr_npi: 1, dest_addr_ton: 1,
...(1)> destination_addr: "12345678901", esm_class: 0, priority_flag: 0,
...(1)> protocol_id: 0, registered_delivery: 0, replace_if_present_flag: 0,
...(1)> schedule_delivery_time: "", service_type: "",
...(1)> short_message: "More messages", sm_default_msg_id: 0, sm_length: 13,
...(1)> source_addr: "12123456789", source_addr_npi: 1, source_addr_ton: 1,
...(1)> validity_period: ""}, optional: %{516 => 77}
...(1)> }
%SMPPEX.Pdu{command_id: 5, command_status: 0,
mandatory: %{data_coding: 3, dest_addr_npi: 1, dest_addr_ton: 1,
destination_addr: "12345678901", esm_class: 0, priority_flag: 0,
protocol_id: 0, registered_delivery: 0, replace_if_present_flag: 0,
schedule_delivery_time: "", service_type: "", short_message: "More messages",
sm_default_msg_id: 0, sm_length: 13, source_addr: "12123456789",
source_addr_npi: 1, source_addr_ton: 1, validity_period: ""},
optional: %{516 => 77}, ref: nil, sequence_number: 0}
iex(2)> SMPPEX.Pdu.optional_field(pdu, :user_message_reference)
77