Add ENC_APN_STR to handle APN strings

This commit is contained in:
AndersBroman 2021-05-20 09:27:53 +00:00
parent 34ae07e180
commit 754cce9531
5 changed files with 28 additions and 58 deletions

View File

@ -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 }},
};

View File

@ -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;
const guint8 *apn = NULL;
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);
}
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);
}

View File

@ -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);
}

View File

@ -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:
*

View File

@ -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;
}