aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndersBroman <a.broman58@gmail.com>2021-05-20 09:27:53 +0000
committerAndersBroman <a.broman58@gmail.com>2021-05-20 09:27:53 +0000
commit754cce9531ed22494a35a6707dcb29d601946ec7 (patch)
tree27d8fb2763c742c951187884b0e20ff3bb32f33a
parent34ae07e180266431d49e7899a561cd7360f7ee5b (diff)
Add ENC_APN_STR to handle APN strings
-rw-r--r--epan/dissectors/packet-gsm_a_gm.c23
-rw-r--r--epan/dissectors/packet-gtpv2.c42
-rw-r--r--epan/dissectors/packet-pfcp.c2
-rw-r--r--epan/proto.h1
-rw-r--r--epan/tvbuff.c18
5 files changed, 28 insertions, 58 deletions
diff --git a/epan/dissectors/packet-gsm_a_gm.c b/epan/dissectors/packet-gsm_a_gm.c
index a89e97de9c..97b221fb9d 100644
--- a/epan/dissectors/packet-gsm_a_gm.c
+++ b/epan/dissectors/packet-gsm_a_gm.c
@@ -604,7 +604,6 @@ static gint ett_sm_pco = -1;
static expert_field ei_gsm_a_gm_extraneous_data = EI_INIT;
static expert_field ei_gsm_a_gm_not_enough_data = EI_INIT;
static expert_field ei_gsm_a_gm_undecoded = EI_INIT;
-static expert_field ei_gsm_a_gm_apn_too_long = EI_INIT;
static expert_field ei_gsm_a_gm_missing_mandatory_element = EI_INIT;
static dissector_handle_t rrc_irat_ho_info_handle;
@@ -4392,29 +4391,10 @@ guint16
de_sm_apn(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 offset, guint len, gchar *add_string _U_, int string_len _U_)
{
guint32 curr_offset;
- guint curr_len;
- guint8 *str;
- proto_item *pi;
curr_offset = offset;
- str = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, len, ENC_ASCII|ENC_NA);
-
- curr_len = 0;
- while (curr_len < len)
- {
- guint step = str[curr_len];
- str[curr_len] = '.';
- curr_len += step+1;
- }
-
- /* Highlight bytes including the first length byte */
- if (str[0]) {
- pi = proto_tree_add_string(tree, hf_gsm_a_gm_apn, tvb, curr_offset, len, str+1);
- if (len > 100) {
- expert_add_info(pinfo, pi, &ei_gsm_a_gm_apn_too_long);
- }
- }
+ proto_tree_add_item(tree, hf_gsm_a_gm_apn, tvb, curr_offset, len, ENC_APN_STR | ENC_NA);
curr_offset += len;
EXTRANEOUS_DATA_CHECK(len, curr_offset - offset, pinfo, &ei_gsm_a_gm_extraneous_data);
@@ -9642,7 +9622,6 @@ proto_register_gsm_a_gm(void)
{ &ei_gsm_a_gm_extraneous_data, { "gsm_a.gm.extraneous_data", PI_PROTOCOL, PI_NOTE, "Extraneous Data, dissector bug or later version spec (report to wireshark.org)", EXPFILL }},
{ &ei_gsm_a_gm_not_enough_data, { "gsm_a.gm.not_enough_data", PI_PROTOCOL, PI_WARN, "Not enough data", EXPFILL }},
{ &ei_gsm_a_gm_undecoded, { "gsm_a.gm.undecoded", PI_UNDECODED, PI_WARN, "Not decoded", EXPFILL }},
- { &ei_gsm_a_gm_apn_too_long, { "gsm_a.gm.apn_to_long", PI_PROTOCOL, PI_ERROR, "APN encoding has more than 100 octets", EXPFILL }},
{ &ei_gsm_a_gm_missing_mandatory_element, { "gsm_a.gm.missing_mandatory_element", PI_PROTOCOL, PI_ERROR, "Missing Mandatory element, rest of dissection is suspect", EXPFILL }},
};
diff --git a/epan/dissectors/packet-gtpv2.c b/epan/dissectors/packet-gtpv2.c
index a8022775f7..d399a37561 100644
--- a/epan/dissectors/packet-gtpv2.c
+++ b/epan/dissectors/packet-gtpv2.c
@@ -2200,29 +2200,12 @@ dissect_gtpv2_mm_ctx_for_cs_to_ps_srvcc(tvbuff_t *tvb, packet_info *pinfo _U_, p
static void
dissect_gtpv2_apn(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, proto_item *item, guint16 length, guint8 message_type _U_, guint8 instance _U_, session_args_t * args _U_)
{
- int offset = 0;
- guint8 *apn = NULL;
- int name_len, tmp;
-
- if (length > 0) {
- proto_item *pi;
-
- name_len = tvb_get_guint8(tvb, offset);
- apn = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 1, length - 1, ENC_ASCII);
- for (;;) {
- if (name_len >= length - 1)
- break;
- tmp = name_len;
- name_len = name_len + apn[tmp] + 1;
- apn[tmp] = '.';
- }
- pi = proto_tree_add_string(tree, hf_gtpv2_apn, tvb, offset, length, apn);
- if (length > 100)
- expert_add_info(pinfo, pi, &ei_gtpv2_apn_too_long);
- }
+ const guint8 *apn = NULL;
- if (apn)
+ proto_tree_add_item_ret_string(tree, hf_gtpv2_apn, tvb, 0, length, ENC_APN_STR | ENC_NA, wmem_packet_scope(), &apn);
+ if (apn) {
proto_item_append_text(item, "%s", apn);
+ }
}
@@ -7368,8 +7351,7 @@ dissect_gtpv2_apn_and_relative_capacity(tvbuff_t *tvb, packet_info *pinfo _U_, p
{
int offset = 0;
guint8 oct, apn_length;
- guint8 *apn = NULL;
- int name_len, tmp;
+ const guint8 *apn = NULL;
oct = tvb_get_guint8(tvb, offset);
proto_tree_add_item(tree, hf_gtpv2_relative_capacity, tvb, offset, 1, ENC_BIG_ENDIAN);
@@ -7381,18 +7363,8 @@ dissect_gtpv2_apn_and_relative_capacity(tvbuff_t *tvb, packet_info *pinfo _U_, p
offset += 1;
if (apn_length > 0) {
- proto_item *pi;
-
- name_len = tvb_get_guint8(tvb, offset);
- apn = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 1, apn_length - 1, ENC_ASCII);
- for (;;) {
- if (name_len >= apn_length - 1)
- break;
- tmp = name_len;
- name_len = name_len + apn[tmp] + 1;
- apn[tmp] = '.';
- }
- pi = proto_tree_add_string(tree, hf_gtpv2_apn, tvb, offset, apn_length, apn);
+ proto_item* pi;
+ pi = proto_tree_add_item_ret_string(tree, hf_gtpv2_apn, tvb, offset, apn_length, ENC_APN_STR | ENC_NA, wmem_packet_scope(), &apn);
if (apn_length > 100)
expert_add_info(pinfo, pi, &ei_gtpv2_apn_too_long);
}
diff --git a/epan/dissectors/packet-pfcp.c b/epan/dissectors/packet-pfcp.c
index 6ef8e5ffe7..05ae0fe1b4 100644
--- a/epan/dissectors/packet-pfcp.c
+++ b/epan/dissectors/packet-pfcp.c
@@ -6109,7 +6109,7 @@ dissect_pfcp_apn_dnn(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, pr
/* NOTE: The APN/DNN field is not encoded as a dotted string as commonly used in documentation. */
const guint8* string_value;
- proto_tree_add_item_ret_string(tree, hf_pfcp_apn_dnn, tvb, offset, length, ENC_ASCII | ENC_NA, wmem_packet_scope(), &string_value);
+ proto_tree_add_item_ret_string(tree, hf_pfcp_apn_dnn, tvb, offset, length, ENC_APN_STR | ENC_NA, wmem_packet_scope(), &string_value);
proto_item_append_text(item, "%s", string_value);
}
diff --git a/epan/proto.h b/epan/proto.h
index b893db9c65..77e24617f7 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -426,6 +426,7 @@ void proto_report_dissector_bug(const char *format, ...)
#define ENC_ETSI_TS_102_221_ANNEX_A 0x0000004E /* ETSI TS 102 221 Annex A */
#define ENC_GB18030 0x00000050
#define ENC_EUC_KR 0x00000052
+#define ENC_APN_STR 0x00000054 /* The encoding the APN/DNN field follows 3GPP TS 23.003 [2] clause 9.1.*/
/*
* TODO:
*
diff --git a/epan/tvbuff.c b/epan/tvbuff.c
index fce3cb8c2d..0c26a2f9f0 100644
--- a/epan/tvbuff.c
+++ b/epan/tvbuff.c
@@ -1630,6 +1630,7 @@ validate_single_byte_ascii_encoding(const guint encoding)
case ENC_KEYPAD_ABC_TBCD:
case ENC_KEYPAD_BC_TBCD:
case ENC_ETSI_TS_102_221_ANNEX_A:
+ case ENC_APN_STR:
REPORT_DISSECTOR_BUG("Invalid string encoding type passed to tvb_get_string_XXX");
break;
default:
@@ -3092,6 +3093,23 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset,
case ENC_EUC_KR:
strptr = tvb_get_euc_kr_string(scope, tvb, offset, length);
break;
+ case ENC_APN_STR:
+ {
+ int name_len, tmp;
+
+ if (length > 0) {
+ name_len = tvb_get_guint8(tvb, offset);
+ strptr = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 1, length - 1, ENC_ASCII);
+ for (;;) {
+ if (name_len >= length - 1)
+ break;
+ tmp = name_len;
+ name_len = name_len + strptr[tmp] + 1;
+ strptr[tmp] = '.';
+ }
+ }
+ }
+ break;
}
return strptr;
}