2 * Routines for GSM A Interface RP dissection - SMS GSM layer 3
4 * Copyright 2003, Michael Lum <mlum [AT] telostech.com>
5 * In association with Telos Technology Inc.
10 * Point-to-Point (PP) Short Message Service (SMS)
11 * support on mobile radio interface
12 * (3GPP TS 24.011 version 4.1.1 Release 4)
14 * Wireshark - Network traffic analyzer
15 * By Gerald Combs <gerald@wireshark.org>
16 * Copyright 1998 Gerald Combs
18 * SPDX-License-Identifier: GPL-2.0-or-later
23 #include <epan/packet.h>
24 #include <epan/expert.h>
25 #include <epan/proto_data.h>
27 #include <wsutil/wsjson.h>
28 #include <wsutil/array.h>
30 #include "packet-gsm_a_common.h"
31 #include "packet-media-type.h"
33 void proto_register_gsm_a_rp(void);
34 void proto_reg_handoff_gsm_a_rp(void);
36 /* PROTOTYPES/FORWARDS */
38 static const value_string gsm_rp_msg_strings
[] = {
39 { 0x00, "RP-DATA (MS to Network)" },
40 { 0x01, "RP-DATA (Network to MS)" },
41 { 0x02, "RP-ACK (MS to Network)" },
42 { 0x03, "RP-ACK (Network to MS)" },
43 { 0x04, "RP-ERROR (MS to Network)" },
44 { 0x05, "RP-ERROR (Network to MS)" },
45 { 0x06, "RP-SMMA (MS to Network)" },
51 /* Short Message Service Information Elements [5] 8.2 */
52 DE_RP_MESSAGE_REF
, /* RP-Message Reference */
53 DE_RP_ORIG_ADDR
, /* RP-Originator Address */
54 DE_RP_DEST_ADDR
, /* RP-Destination Address */
55 DE_RP_USER_DATA
, /* RP-User Data */
56 DE_RP_CAUSE
, /* RP-Cause */
61 static const value_string gsm_rp_elem_strings
[] = {
62 /* Short Message Service RP Information Elements [5] 8.2 */
63 { DE_RP_MESSAGE_REF
, "RP-Message Reference" },
64 { DE_RP_ORIG_ADDR
, "RP-Originator Address" },
65 { DE_RP_DEST_ADDR
, "RP-Destination Address" },
66 { DE_RP_USER_DATA
, "RP-User Data" },
67 { DE_RP_CAUSE
, "RP-Cause" },
70 value_string_ext gsm_rp_elem_strings_ext
= VALUE_STRING_EXT_INIT(gsm_rp_elem_strings
);
72 /* Initialize the protocol and registered fields */
73 static int proto_a_rp
;
75 static int hf_gsm_a_rp_msg_type
;
76 int hf_gsm_a_rp_elem_id
;
77 /* Generated from convert_proto_tree_add_text.pl */
78 static int hf_gsm_a_rp_tpdu
;
79 static int hf_gsm_a_rp_extension
;
80 static int hf_gsm_a_rp_diagnostic_field
;
81 static int hf_gsm_a_rp_cause
;
82 static int hf_gsm_a_rp_message_elements
;
83 static int hf_gsm_a_rp_rp_message_reference
;
85 /* Initialize the subtree pointers */
86 static int ett_rp_msg
;
88 static expert_field ei_gsm_a_rp_extraneous_data
;
89 static expert_field ei_gsm_a_rp_missing_mandatory_element
;
91 static dissector_handle_t gsm_sms_handle
; /* SMS TPDU */
92 static dissector_handle_t gsm_a_dtap_handle
;
94 static int proto_json
;
96 static proto_tree
*g_tree
;
98 #define NUM_GSM_RP_ELEM array_length(gsm_rp_elem_strings)
99 int ett_gsm_rp_elem
[NUM_GSM_RP_ELEM
];
105 de_rp_message_ref(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo _U_
, uint32_t offset
, unsigned len _U_
, char *add_string _U_
, int string_len _U_
)
107 uint32_t curr_offset
;
109 curr_offset
= offset
;
111 proto_tree_add_item(tree
, hf_gsm_a_rp_rp_message_reference
, tvb
, curr_offset
, 1, ENC_BIG_ENDIAN
);
115 /* no length check possible */
117 return curr_offset
- offset
;
124 de_rp_orig_addr(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo _U_
, uint32_t offset
, unsigned len
, char *add_string
, int string_len
)
126 return de_cld_party_bcd_num(tvb
, tree
, pinfo
, offset
, len
, add_string
, string_len
);
133 de_rp_dest_addr(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo _U_
, uint32_t offset
, unsigned len
, char *add_string
, int string_len
)
135 return de_cld_party_bcd_num(tvb
, tree
, pinfo
, offset
, len
, add_string
, string_len
);
142 de_rp_user_data(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
, char *add_string _U_
, int string_len _U_
)
144 uint32_t curr_offset
;
147 curr_offset
= offset
;
149 proto_tree_add_bytes_format(tree
, hf_gsm_a_rp_tpdu
, tvb
, curr_offset
, len
, NULL
, "TPDU (not displayed)");
152 * dissect the embedded TPDU message
154 tpdu_tvb
= tvb_new_subset_length(tvb
, curr_offset
, len
);
156 call_dissector_only(gsm_sms_handle
, tpdu_tvb
, pinfo
, g_tree
, NULL
);
160 EXTRANEOUS_DATA_CHECK(len
, curr_offset
- offset
, pinfo
, &ei_gsm_a_rp_extraneous_data
);
162 return curr_offset
- offset
;
168 static const value_string gsm_rp_cause_vals
[] = {
169 { 1, "Unassigned (unallocated) number" },
170 { 8, "Operator determined barring" },
171 { 10, "Call barred" },
173 { 21, "Short message transfer rejected" },
174 { 22, "Memory capacity exceeded" },
175 { 27, "Destination out of order" },
176 { 28, "Unidentified subscriber" },
177 { 29, "Facility rejected" },
178 { 30, "Unknown subscriber" },
179 { 38, "Network out of order" },
180 { 41, "Temporary failure" },
181 { 42, "Congestion" },
182 { 47, "Resources unavailable, unspecified" },
183 { 50, "Requested facility not subscribed" },
184 { 69, "Requested facility not implemented" },
185 { 81, "Invalid short message transfer reference value" },
186 { 95, "Semantically incorrect message" },
187 { 96, "Invalid mandatory information" },
188 { 97, "Message type non-existent or not implemented" },
189 { 98, "Message not compatible with short message protocol state" },
190 { 99, "Information element non-existent or not implemented" },
191 { 111, "Protocol error, unspecified" },
192 { 127, "Interworking, unspecified" },
196 static value_string_ext gsm_rp_cause_vals_ext
= VALUE_STRING_EXT_INIT(gsm_rp_cause_vals
);
198 static const true_false_string tfs_extended_no_extension
= { "Extended", "No extension"};
201 de_rp_cause(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo _U_
, uint32_t offset
, unsigned len
, char *add_string
, int string_len
)
204 uint32_t curr_offset
;
206 curr_offset
= offset
;
208 oct
= tvb_get_uint8(tvb
, curr_offset
);
210 proto_tree_add_item(tree
, hf_gsm_a_rp_extension
, tvb
, curr_offset
, 1, ENC_NA
);
211 proto_tree_add_item(tree
, hf_gsm_a_rp_cause
, tvb
, curr_offset
, 1, ENC_BIG_ENDIAN
);
216 snprintf(add_string
, string_len
, " - (%u) %s", oct
& 0x7f, val_to_str_ext_const(oct
& 0x7f, &gsm_rp_cause_vals_ext
, "Reserved"));
218 NO_MORE_DATA_CHECK(len
);
220 proto_tree_add_item(tree
, hf_gsm_a_rp_diagnostic_field
, tvb
, curr_offset
, len
- (curr_offset
- offset
), ENC_NA
);
222 curr_offset
+= len
- (curr_offset
- offset
);
224 EXTRANEOUS_DATA_CHECK(len
, curr_offset
- offset
, pinfo
, &ei_gsm_a_rp_extraneous_data
);
226 return curr_offset
- offset
;
229 uint16_t (*rp_elem_fcn
[])(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
, char *add_string
, int string_len
) = {
230 /* Short Message Service Information Elements [5] 8.2 */
231 de_rp_message_ref
, /* RP-Message Reference */
232 de_rp_orig_addr
, /* RP-Originator Address */
233 de_rp_dest_addr
, /* RP-Destination Address */
234 de_rp_user_data
, /* RP-User Data */
235 de_rp_cause
, /* RP-Cause */
239 /* MESSAGE FUNCTIONS */
245 rp_data_n_ms(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
)
247 uint32_t curr_offset
;
251 curr_offset
= offset
;
254 pinfo
->p2p_dir
= P2P_DIR_SENT
;
256 ELEM_MAND_V(GSM_A_PDU_TYPE_RP
, DE_RP_MESSAGE_REF
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
258 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_ORIG_ADDR
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
260 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_DEST_ADDR
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
262 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_USER_DATA
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
264 EXTRANEOUS_DATA_CHECK(curr_len
, 0, pinfo
, &ei_gsm_a_rp_extraneous_data
);
271 rp_data_ms_n(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
)
273 uint32_t curr_offset
;
277 curr_offset
= offset
;
280 pinfo
->p2p_dir
= P2P_DIR_RECV
;
282 ELEM_MAND_V(GSM_A_PDU_TYPE_RP
, DE_RP_MESSAGE_REF
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
284 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_ORIG_ADDR
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
286 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_DEST_ADDR
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
288 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_USER_DATA
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
290 EXTRANEOUS_DATA_CHECK(curr_len
, 0, pinfo
, &ei_gsm_a_rp_extraneous_data
);
297 rp_smma(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo _U_
, uint32_t offset
, unsigned len
)
299 uint32_t curr_offset
;
303 curr_offset
= offset
;
306 ELEM_MAND_V(GSM_A_PDU_TYPE_RP
, DE_RP_MESSAGE_REF
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
308 EXTRANEOUS_DATA_CHECK(curr_len
, 0, pinfo
, &ei_gsm_a_rp_extraneous_data
);
315 rp_ack_n_ms(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
)
317 uint32_t curr_offset
;
321 curr_offset
= offset
;
324 pinfo
->p2p_dir
= P2P_DIR_SENT
;
326 ELEM_MAND_V(GSM_A_PDU_TYPE_RP
, DE_RP_MESSAGE_REF
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
328 ELEM_OPT_TLV(0x41, GSM_A_PDU_TYPE_RP
, DE_RP_USER_DATA
, NULL
);
330 EXTRANEOUS_DATA_CHECK(curr_len
, 0, pinfo
, &ei_gsm_a_rp_extraneous_data
);
337 rp_ack_ms_n(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
)
339 uint32_t curr_offset
;
343 curr_offset
= offset
;
346 pinfo
->p2p_dir
= P2P_DIR_RECV
;
348 ELEM_MAND_V(GSM_A_PDU_TYPE_RP
, DE_RP_MESSAGE_REF
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
350 ELEM_OPT_TLV(0x41, GSM_A_PDU_TYPE_RP
, DE_RP_USER_DATA
, NULL
);
352 EXTRANEOUS_DATA_CHECK(curr_len
, 0, pinfo
, &ei_gsm_a_rp_extraneous_data
);
359 rp_error_n_ms(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
)
361 uint32_t curr_offset
;
365 curr_offset
= offset
;
368 pinfo
->p2p_dir
= P2P_DIR_SENT
;
370 ELEM_MAND_V(GSM_A_PDU_TYPE_RP
, DE_RP_MESSAGE_REF
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
372 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_CAUSE
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
374 ELEM_OPT_TLV(0x41, GSM_A_PDU_TYPE_RP
, DE_RP_USER_DATA
, NULL
);
376 EXTRANEOUS_DATA_CHECK(curr_len
, 0, pinfo
, &ei_gsm_a_rp_extraneous_data
);
383 rp_error_ms_n(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo
, uint32_t offset
, unsigned len
)
385 uint32_t curr_offset
;
389 curr_offset
= offset
;
392 pinfo
->p2p_dir
= P2P_DIR_RECV
;
394 ELEM_MAND_V(GSM_A_PDU_TYPE_RP
, DE_RP_MESSAGE_REF
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
396 ELEM_MAND_LV(GSM_A_PDU_TYPE_RP
, DE_RP_CAUSE
, NULL
, ei_gsm_a_rp_missing_mandatory_element
);
398 ELEM_OPT_TLV(0x41, GSM_A_PDU_TYPE_RP
, DE_RP_USER_DATA
, NULL
);
400 EXTRANEOUS_DATA_CHECK(curr_len
, 0, pinfo
, &ei_gsm_a_rp_extraneous_data
);
403 #define NUM_GSM_RP_MSG array_length(gsm_rp_msg_strings)
404 static int ett_gsm_rp_msg
[NUM_GSM_RP_MSG
];
405 static void (*rp_msg_fcn
[])(tvbuff_t
*tvb
, proto_tree
*tree
, packet_info
*pinfo _U_
, uint32_t offset
, unsigned len
) = {
406 rp_data_ms_n
, /* RP-DATA (MS to Network) */
407 rp_data_n_ms
, /* RP-DATA (Network to MS) */
408 rp_ack_ms_n
, /* RP-ACK (MS to Network) */
409 rp_ack_n_ms
, /* RP-ACK (Network to MS) */
410 rp_error_ms_n
, /* RP-ERROR (MS to Network) */
411 rp_error_n_ms
, /* RP-ERROR (Network to MS) */
412 rp_smma
, /* RP-SMMA (MS to Network) */
416 /* GENERIC DISSECTOR FUNCTIONS */
419 dissect_rp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
422 uint32_t offset
, saved_offset
;
425 proto_item
*rp_item
= NULL
;
426 proto_tree
*rp_tree
= NULL
;
429 col_append_str(pinfo
->cinfo
, COL_INFO
, "(RP) ");
432 saved_offset
= offset
;
436 len
= tvb_reported_length(tvb
);
439 * add RP message name
441 oct
= tvb_get_uint8(tvb
, offset
++);
443 str
= try_val_to_str_idx((uint32_t) oct
, gsm_rp_msg_strings
, &idx
);
446 * create the protocol tree
451 proto_tree_add_protocol_format(tree
, proto_a_rp
, tvb
, 0, len
,
452 "GSM A-I/F RP - Unknown RP Message Type (0x%02x)",
455 rp_tree
= proto_item_add_subtree(rp_item
, ett_rp_msg
);
460 proto_tree_add_protocol_format(tree
, proto_a_rp
, tvb
, 0, -1,
464 rp_tree
= proto_item_add_subtree(rp_item
, ett_gsm_rp_msg
[idx
]);
466 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s ", str
);
470 * add RP message name
472 proto_tree_add_uint_format(rp_tree
, hf_gsm_a_rp_msg_type
,
473 tvb
, saved_offset
, 1, oct
, "Message Type %s", str
? str
: "(Unknown)");
475 if (str
== NULL
) return offset
;
477 if (offset
>=len
) return offset
;
482 if (rp_msg_fcn
[idx
] == NULL
)
484 proto_tree_add_item(rp_tree
, hf_gsm_a_rp_message_elements
, tvb
, offset
, len
- offset
, ENC_NA
);
488 (*rp_msg_fcn
[idx
])(tvb
, rp_tree
, pinfo
, offset
, len
- offset
);
490 return tvb_captured_length(tvb
);
494 dissect_nf_media_type(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, media_content_info_t
*content_info
)
498 jsmntok_t
*tokens
, *cur_tok
;
500 const char *content_id
;
502 if (!gsm_a_dtap_handle
|| !content_info
|| content_info
->type
> MEDIA_CONTAINER_HTTP_OTHERS
|| !content_info
->content_id
)
504 json_tvb
= (tvbuff_t
*)p_get_proto_data(pinfo
->pool
, pinfo
, proto_json
, 0);
507 json_data
= tvb_get_string_enc(pinfo
->pool
, json_tvb
, 0, tvb_reported_length(json_tvb
), ENC_UTF_8
|ENC_NA
);
508 ret
= json_parse(json_data
, NULL
, 0);
511 tokens
= wmem_alloc_array(pinfo
->pool
, jsmntok_t
, ret
);
512 if (json_parse(json_data
, tokens
, ret
) <= 0)
514 cur_tok
= json_get_object(json_data
, tokens
, "smsPayload");
517 content_id
= json_get_string(json_data
, cur_tok
, "contentId");
518 if (content_id
&& !strcmp(content_id
, content_info
->content_id
))
519 return call_dissector_only(gsm_a_dtap_handle
, tvb
, pinfo
, tree
, NULL
);
525 dissect_rp_media_type(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
528 media_content_info_t
*content_info
= (media_content_info_t
*)data
;
530 ret
= dissect_nf_media_type(tvb
, pinfo
, tree
, content_info
);
532 ret
= dissect_rp(tvb
, pinfo
, tree
, NULL
);
536 /* Register the protocol with Wireshark */
538 proto_register_gsm_a_rp(void)
541 unsigned last_offset
;
543 /* Setup list of header fields */
545 static hf_register_info hf
[] = {
546 { &hf_gsm_a_rp_msg_type
,
547 { "RP Message Type", "gsm_a.rp.msg_type",
548 FT_UINT8
, BASE_HEX
, VALS(gsm_rp_msg_strings
), 0x0,
551 { &hf_gsm_a_rp_elem_id
,
552 { "Element ID", "gsm_a.rp.elem_id",
553 FT_UINT8
, BASE_HEX
, NULL
, 0,
557 /* Generated from convert_proto_tree_add_text.pl */
558 { &hf_gsm_a_rp_rp_message_reference
, { "RP-Message Reference", "gsm_a.rp.rp_message_reference", FT_UINT8
, BASE_HEX_DEC
, NULL
, 0x0, NULL
, HFILL
}},
559 { &hf_gsm_a_rp_tpdu
, { "TPDU", "gsm_a.rp.tpdu", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
560 { &hf_gsm_a_rp_extension
, { "Extension", "gsm_a.rp.extension", FT_BOOLEAN
, 8, TFS(&tfs_extended_no_extension
), 0x80, NULL
, HFILL
}},
561 { &hf_gsm_a_rp_cause
, { "Cause", "gsm_a.rp.cause", FT_UINT8
, BASE_DEC
|BASE_EXT_STRING
, &gsm_rp_cause_vals_ext
, 0x7F, NULL
, HFILL
}},
562 { &hf_gsm_a_rp_diagnostic_field
, { "Diagnostic field", "gsm_a.rp.diagnostic_field", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
563 { &hf_gsm_a_rp_message_elements
, { "Message Elements", "gsm_a.rp.message_elements", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}},
566 static ei_register_info ei
[] = {
567 { &ei_gsm_a_rp_extraneous_data
, { "gsm_a.rp.extraneous_data", PI_PROTOCOL
, PI_NOTE
, "Extraneous Data, dissector bug or later version spec(report to wireshark.org)", EXPFILL
}},
568 { &ei_gsm_a_rp_missing_mandatory_element
, { "gsm_a.rp.missing_mandatory_element", PI_PROTOCOL
, PI_ERROR
, "Missing Mandatory element, rest of dissection is suspect", EXPFILL
}},
571 expert_module_t
* expert_gsm_a_rp
;
573 /* Setup protocol subtree array */
574 #define NUM_INDIVIDUAL_ELEMS 1
575 int *ett
[NUM_INDIVIDUAL_ELEMS
+
579 ett
[0] = &ett_rp_msg
;
581 last_offset
= NUM_INDIVIDUAL_ELEMS
;
583 for (i
=0; i
< NUM_GSM_RP_MSG
; i
++, last_offset
++)
585 ett
[last_offset
] = &ett_gsm_rp_msg
[i
];
588 for (i
=0; i
< NUM_GSM_RP_ELEM
; i
++, last_offset
++)
590 ett
[last_offset
] = &ett_gsm_rp_elem
[i
];
593 /* Register the protocol name and description */
595 proto_a_rp
= proto_register_protocol("GSM A-I/F RP", "GSM RP", "gsm_a.rp");
597 proto_register_field_array(proto_a_rp
, hf
, array_length(hf
));
598 proto_register_subtree_array(ett
, array_length(ett
));
599 expert_gsm_a_rp
= expert_register_protocol(proto_a_rp
);
600 expert_register_field_array(expert_gsm_a_rp
, ei
, array_length(ei
));
602 register_dissector("gsm_a_rp", dissect_rp
, proto_a_rp
);
606 proto_reg_handoff_gsm_a_rp(void)
608 dissector_handle_t gsm_a_rp_handle
;
610 gsm_a_rp_handle
= create_dissector_handle(dissect_rp_media_type
, proto_a_rp
);
611 /* Dissect messages embedded in SIP */
612 dissector_add_string("media_type","application/vnd.3gpp.sms", gsm_a_rp_handle
);
613 gsm_sms_handle
= find_dissector_add_dependency("gsm_sms", proto_a_rp
);
614 gsm_a_dtap_handle
= find_dissector_add_dependency("gsm_a_dtap", proto_a_rp
);
615 proto_json
= proto_get_id_by_filter_name("json");
619 * Editor modelines - https://www.wireshark.org/tools/modelines.html
624 * indent-tabs-mode: t
627 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
628 * :indentSize=8:tabSize=8:noTabs=false: