diff options
author | Anders Broman <anders.broman@ericsson.com> | 2020-12-10 13:14:21 +0100 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2020-12-10 16:02:10 +0100 |
commit | 9a46fabf5299fb0b634dfc0f6368d8201e847d73 (patch) | |
tree | 8a3cd1a11130d56cb10182fddfddaabc79d5cf12 /epan | |
parent | 37f11e9a364c4b3684db52c3f4ad4773034a90a0 (diff) |
Introduce ENC_BCD_ODD_NUM_DIG in order to handle odd number of digits
Diffstat (limited to 'epan')
-rw-r--r-- | epan/dissectors/packet-e212.c | 9 | ||||
-rw-r--r-- | epan/dissectors/packet-nas_5gs.c | 15 | ||||
-rw-r--r-- | epan/dissectors/packet-nas_eps.c | 18 | ||||
-rw-r--r-- | epan/proto.h | 8 | ||||
-rw-r--r-- | epan/tvbuff.c | 26 | ||||
-rw-r--r-- | epan/tvbuff.h | 5 |
6 files changed, 45 insertions, 36 deletions
diff --git a/epan/dissectors/packet-e212.c b/epan/dissectors/packet-e212.c index cb96611204..b979c6d292 100644 --- a/epan/dissectors/packet-e212.c +++ b/epan/dissectors/packet-e212.c @@ -3468,14 +3468,17 @@ dissect_e212_imsi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offse { proto_item *item; proto_tree *subtree; - const gchar *imsi_str; + const guint8 *imsi_str; /* Fetch the BCD encoded digits from tvb indicated half byte, formating the digits according to * a default digit set of 0-9 returning "?" for overdecadic digits a pointer to the wmem * allocated string will be returned. */ - imsi_str = tvb_bcd_dig_to_wmem_packet_str( tvb, offset, length, NULL, skip_first); - item = proto_tree_add_string(tree, hf_E212_imsi, tvb, offset, length, imsi_str); + if (skip_first) { + item = proto_tree_add_item_ret_string(tree, hf_E212_imsi, tvb, offset, length, ENC_BCD_DIGITS_0_9 | ENC_BCD_SKIP_FIRST, wmem_packet_scope(), &imsi_str); + } else { + item = proto_tree_add_item_ret_string(tree, hf_E212_imsi, tvb, offset, length, ENC_BCD_DIGITS_0_9, wmem_packet_scope(), &imsi_str); + } if (!is_imsi_string_valid(imsi_str)) { expert_add_info(pinfo, item, &ei_E212_imsi_malformed); } diff --git a/epan/dissectors/packet-nas_5gs.c b/epan/dissectors/packet-nas_5gs.c index 8e2c0d9c87..d44cddc97c 100644 --- a/epan/dissectors/packet-nas_5gs.c +++ b/epan/dissectors/packet-nas_5gs.c @@ -954,7 +954,7 @@ de_nas_5gs_mm_5gs_mobile_id(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint8 oct, type_id, supi_fmt; guint32 scheme_id, fiveg_tmsi; tvbuff_t * new_tvb; - const char *digit_str, *route_id_str; + const char *route_id_str; proto_item* ti; static int * const flags_spare_tid[] = { @@ -1076,9 +1076,7 @@ de_nas_5gs_mm_5gs_mobile_id(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, case 3: /* IMEI */ proto_tree_add_bitmask_list(tree, tvb, offset, 1, flags_odd_even_tid, ENC_BIG_ENDIAN); - new_tvb = tvb_new_subset_length(tvb, offset, len); - digit_str = tvb_bcd_dig_to_wmem_packet_str(new_tvb, 0, -1, NULL, TRUE); - proto_tree_add_string(tree, hf_nas_5gs_mm_imei, new_tvb, 0, -1, digit_str); + proto_tree_add_item(tree, hf_nas_5gs_mm_imei, tvb, offset, len, ENC_BCD_DIGITS_0_9 | ENC_BCD_SKIP_FIRST); break; case 4: /*5G-S-TMSI*/ @@ -1097,9 +1095,8 @@ de_nas_5gs_mm_5gs_mobile_id(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, case 5: /* IMEISV */ proto_tree_add_bitmask_list(tree, tvb, offset, 1, flags_odd_even_tid, ENC_BIG_ENDIAN); - new_tvb = tvb_new_subset_length(tvb, offset, len); - digit_str = tvb_bcd_dig_to_wmem_packet_str(new_tvb, 0, -1, NULL, TRUE); - proto_tree_add_string(tree, hf_nas_5gs_mm_imeisv, new_tvb, 0, -1, digit_str); + /* XXXX Do we need the odd/even bit?*/ + proto_tree_add_item(tree, hf_nas_5gs_mm_imeisv, tvb, offset, len, ENC_BCD_DIGITS_0_9 | ENC_BCD_SKIP_FIRST); break; case 6: /* MAC address */ @@ -3475,12 +3472,10 @@ de_nas_5gs_mm_ue_radio_cap_id(tvbuff_t* tvb, proto_tree* tree, packet_info* pinf gchar* add_string _U_, int string_len _U_) { int curr_offset; - const char* digit_str; curr_offset = offset; - digit_str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, len, NULL, FALSE); - proto_tree_add_string(tree, hf_nas_5gs_mm_ue_radio_cap_id, tvb, 0, -1, digit_str); + proto_tree_add_item(tree, hf_nas_5gs_mm_ue_radio_cap_id, tvb, curr_offset, len, ENC_BCD_DIGITS_0_9); return len; } diff --git a/epan/dissectors/packet-nas_eps.c b/epan/dissectors/packet-nas_eps.c index 715b15f0a0..e3c8530020 100644 --- a/epan/dissectors/packet-nas_eps.c +++ b/epan/dissectors/packet-nas_eps.c @@ -1343,8 +1343,6 @@ de_emm_eps_mid(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, { guint32 curr_offset; guint8 octet; - const char *digit_str; - tvbuff_t *new_tvb; proto_item* ti; curr_offset = offset; @@ -1356,14 +1354,11 @@ de_emm_eps_mid(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, switch (octet&0x7) { case 1: /* IMSI */ - new_tvb = tvb_new_subset_length(tvb, curr_offset, len); - dissect_e212_imsi(new_tvb, pinfo, tree, 0, len, TRUE); + dissect_e212_imsi(tvb, pinfo, tree, curr_offset, len, TRUE); break; case 3: /* IMEI */ - new_tvb = tvb_new_subset_length(tvb, curr_offset, len); - digit_str = tvb_bcd_dig_to_wmem_packet_str(new_tvb, 0, len, NULL, TRUE); - proto_tree_add_string(tree, hf_nas_eps_emm_imei, new_tvb, 0, -1, digit_str); + proto_tree_add_item(tree, hf_nas_eps_emm_imei, tvb, curr_offset, len, ENC_BCD_DIGITS_0_9 | ENC_BCD_SKIP_FIRST); break; case 6: /* GUTI */ @@ -3701,22 +3696,19 @@ de_esm_remote_ue_context_list(tvbuff_t *tvb, proto_tree *tree, packet_info *pinf break; case 3: { - const gchar *msisdn_str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, user_id_len, NULL, TRUE); - proto_tree_add_string(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_msisdn, tvb, curr_offset, user_id_len, msisdn_str); + proto_tree_add_item(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_msisdn, tvb, curr_offset, user_id_len, ENC_BCD_DIGITS_0_9 | ENC_BCD_SKIP_FIRST); curr_offset += user_id_len; } break; case 4: { - const gchar *imei_str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, user_id_len, NULL, TRUE); - proto_tree_add_string(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_imei, tvb, curr_offset, user_id_len, imei_str); + proto_tree_add_item(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_imei, tvb, curr_offset, user_id_len, ENC_BCD_DIGITS_0_9 | ENC_BCD_SKIP_FIRST); curr_offset += user_id_len; } break; case 5: { - const gchar *imeisv_str = tvb_bcd_dig_to_wmem_packet_str(tvb, curr_offset, user_id_len, NULL, TRUE); - proto_tree_add_string(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_imeisv, tvb, curr_offset, user_id_len, imeisv_str); + proto_tree_add_item(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_imeisv, tvb, curr_offset, user_id_len, ENC_BCD_DIGITS_0_9 | ENC_BCD_SKIP_FIRST); curr_offset += user_id_len; } break; diff --git a/epan/proto.h b/epan/proto.h index 2a51071562..335e014789 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -515,7 +515,13 @@ void proto_report_dissector_bug(const char *format, ...) /* a convenience macro for the above */ #define ENC_SEP_MASK 0x001F0000 -/* +/* Encodings for BCD strings + * Depending if the BCD string has even or odd number of digits + * we may need to strip of the last digit/High nibble + */ +#define ENC_BCD_ODD_NUM_DIG 0x00010000 +#define ENC_BCD_SKIP_FIRST 0x00020000 + /* * Encodings for time values. * * Historically FT_TIMEs were only timespecs; the only question was whether diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 6efe933ae2..1c80ad79cb 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -2873,6 +2873,7 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, const gint length, const guint encoding) { guint8 *strptr; + gboolean odd, skip_first; DISSECTOR_ASSERT(tvb && tvb->initialized); @@ -3053,7 +3054,9 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, /* * Packed BCD, with digits 0-9. */ - strptr = tvb_get_bcd_string(scope, tvb, offset, length, &Dgt0_9_bcd, FALSE); + odd = (encoding & ENC_BCD_ODD_NUM_DIG) >> 16; + skip_first = (encoding & ENC_BCD_SKIP_FIRST) >> 17; + strptr = tvb_get_bcd_string(scope, tvb, offset, length, &Dgt0_9_bcd, skip_first, odd); break; case ENC_KEYPAD_ABC_TBCD: @@ -3061,7 +3064,9 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, * Keypad-with-a/b/c "telephony BCD" - packed BCD, with * digits 0-9 and symbols *, #, a, b, and c. */ - strptr = tvb_get_bcd_string(scope, tvb, offset, length, &Dgt_keypad_abc_tbcd, FALSE); + odd = (encoding & ENC_BCD_ODD_NUM_DIG) >> 16; + skip_first = (encoding & ENC_BCD_SKIP_FIRST) >> 17; + strptr = tvb_get_bcd_string(scope, tvb, offset, length, &Dgt_keypad_abc_tbcd, skip_first, odd); break; case ENC_KEYPAD_BC_TBCD: @@ -3069,7 +3074,9 @@ tvb_get_string_enc(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, * Keypad-with-B/C "telephony BCD" - packed BCD, with * digits 0-9 and symbols B, C, *, and #. */ - strptr = tvb_get_bcd_string(scope, tvb, offset, length, &Dgt_ansi_tbcd, FALSE); + odd = (encoding & ENC_BCD_ODD_NUM_DIG) >> 16; + skip_first = (encoding & ENC_BCD_SKIP_FIRST) >> 17; + strptr = tvb_get_bcd_string(scope, tvb, offset, length, &Dgt_ansi_tbcd, skip_first, odd); break; case ENC_3GPP_TS_23_038_7BITS_UNPACKED: @@ -4130,10 +4137,11 @@ tvb_bytes_to_str_punct(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset * byte), formating the digits into characters according to the * input digit set, and return a pointer to a UTF-8 string, allocated * using the wmem scope. A high-order nibble of 0xf is considered a - * 'filler' and will end the conversion. + * 'filler' and will end the conversion. Similarrily if odd is set thje last + * high nibble will be omitted. */ gchar * -tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint len, const dgt_set_t *dgt, gboolean skip_first) +tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint len, const dgt_set_t *dgt, gboolean skip_first, gboolean odd) { const guint8 *ptr; int i = 0; @@ -4185,7 +4193,10 @@ tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gi */ break; } - + if ((len == 1) && (odd == TRUE )){ + /* Last octet, skipp last high nibble incase of odd number digits*/ + break; + } digit_str[i] = dgt->out[octet & 0x0f]; i++; @@ -4196,13 +4207,14 @@ tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gi return digit_str; } +/* XXXX Fix me - needs odd indicator added */ const gchar * tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, const gint offset, const gint len, const dgt_set_t *dgt, gboolean skip_first) { if (!dgt) dgt = &Dgt0_9_bcd; - return tvb_get_bcd_string(wmem_packet_scope(), tvb, offset, len, dgt, skip_first); + return tvb_get_bcd_string(wmem_packet_scope(), tvb, offset, len, dgt, skip_first, FALSE); } /* diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 3d06d09290..01ca3fcb24 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -951,11 +951,12 @@ WS_DLL_PUBLIC const gchar *tvb_bcd_dig_to_wmem_packet_str(tvbuff_t *tvb, * byte), formating the digits into characters according to the * input digit set, and return a pointer to a UTF-8 string, allocated * using the wmem scope. A high-order nibble of 0xf is considered a - * 'filler' and will end the conversion. + * 'filler' and will end the conversion. If odd is set the high order + * nibble in the last octet will be skipped */ WS_DLL_PUBLIC gchar *tvb_get_bcd_string(wmem_allocator_t *scope, tvbuff_t *tvb, const gint offset, gint len, const dgt_set_t *dgt, - gboolean skip_first); + gboolean skip_first, gboolean odd); /** Locate a sub-tvbuff within another tvbuff, starting at position * 'haystack_offset'. Returns the index of the beginning of 'needle' within |