diff options
author | Guy Harris <gharris@sonic.net> | 2020-09-28 13:16:17 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2020-09-28 22:30:35 +0000 |
commit | c597927da829f9f9aab3e175347f85649e103a45 (patch) | |
tree | f4a73d564337356ba549c55cc6cd3ed49c50ce90 /epan/dissectors | |
parent | b7c0dc3cb1725fc2d4bb5f6545e7f7ebf014030b (diff) |
Add some more string encodings.
Add an encoding for "unpacked" 3GPP TS 23.038 7-bit strings, in which
each code position is in a byte of its own, rather than with the code
positions packed into 7 bits. Rename the packed encoding to explicitly
indicate that it's packed.
Add an encoding for ETSI TS 102 221 Annex A strings.
Use the new encodings.
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/packet-ansi_637.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-cell_broadcast.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-etsi_card_app_toolkit.c | 90 | ||||
-rw-r--r-- | epan/dissectors/packet-gmr1_rr.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-gsm_a_dtap.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-gsm_sms.c | 42 | ||||
-rw-r--r-- | epan/dissectors/packet-mbim.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-nas_eps.c | 2 |
8 files changed, 37 insertions, 107 deletions
diff --git a/epan/dissectors/packet-ansi_637.c b/epan/dissectors/packet-ansi_637.c index c6a84a6827..97a760e5ed 100644 --- a/epan/dissectors/packet-ansi_637.c +++ b/epan/dissectors/packet-ansi_637.c @@ -451,7 +451,7 @@ text_decoder(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset offset = 0; bit = fill_bits; - proto_tree_add_ts_23_038_7bits_item(tree, hf_index, tvb_out, (offset << 3) + bit, num_fields); + proto_tree_add_ts_23_038_7bits_packed_item(tree, hf_index, tvb_out, (offset << 3) + bit, num_fields); break; case 0x10: /* KSC5601 (Korean) */ diff --git a/epan/dissectors/packet-cell_broadcast.c b/epan/dissectors/packet-cell_broadcast.c index afd86f8040..6914be47d1 100644 --- a/epan/dissectors/packet-cell_broadcast.c +++ b/epan/dissectors/packet-cell_broadcast.c @@ -240,7 +240,7 @@ tvbuff_t * dissect_cbs_data(guint8 sms_encoding, tvbuff_t *tvb, proto_tree *tree switch(sms_encoding){ case SMS_ENCODING_7BIT: case SMS_ENCODING_7BIT_LANG: - text = tvb_get_ts_23_038_7bits_string(pinfo->pool, tvb, offset<<3, (length*8)/7); + text = tvb_get_ts_23_038_7bits_string_packed(pinfo->pool, tvb, offset<<3, (length*8)/7); tvb_out = tvb_new_child_real_data(tvb, text, (guint)strlen(text), (guint)strlen(text)); add_new_data_source(pinfo, tvb_out, "unpacked 7 bit data"); break; diff --git a/epan/dissectors/packet-etsi_card_app_toolkit.c b/epan/dissectors/packet-etsi_card_app_toolkit.c index 5da5e75526..1c0f97e8bb 100644 --- a/epan/dissectors/packet-etsi_card_app_toolkit.c +++ b/epan/dissectors/packet-etsi_card_app_toolkit.c @@ -997,89 +997,25 @@ typedef struct { cat_nmr_type nmr_type; } cat_transaction_t; +/* + * ETSI TS 102 221 Annex A. + */ static void dissect_cat_efadn_coding(tvbuff_t *tvb, proto_tree *tree, guint32 pos, guint32 len, int hf_entry) { if (len) { - guint32 i; - guint8 first_byte = tvb_get_guint8(tvb, pos); + if ((first_byte & 0x80) == 0) { - wmem_strbuf_t *strbuf = wmem_strbuf_sized_new(wmem_packet_scope(), len+1, 0); - for (i = 0; i < len; i++) { - guint8 gsm_chars[2]; - gsm_chars[0] = tvb_get_guint8(tvb, pos+i); - if (gsm_chars[0] == 0x1b) { - /* Escape character */ - guint8 second_byte; - i++; - second_byte = tvb_get_guint8(tvb, pos+i); - gsm_chars[0] |= second_byte << 7; - gsm_chars[1] = second_byte >> 1; - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 2)); - } else { - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 1)); - } - } - proto_tree_add_string(tree, hf_entry, tvb, pos, len, wmem_strbuf_finalize(strbuf)); - } else if (first_byte == 0x80) { - proto_tree_add_item(tree, hf_entry, tvb, pos+1, len-1, ENC_UCS_2|ENC_BIG_ENDIAN); - } else if (first_byte == 0x81) { - guint8 string_len = tvb_get_guint8(tvb, pos+1); - guint16 ucs2_base = tvb_get_guint8(tvb, pos+2) << 7; - wmem_strbuf_t *strbuf = wmem_strbuf_sized_new(wmem_packet_scope(), 2*string_len+1, 0); - for (i = 0; i < string_len; i++) { - guint8 byte = tvb_get_guint8(tvb, pos+3+i); - if ((byte & 0x80) == 0) { - guint8 gsm_chars[2]; - gsm_chars[0] = byte; - if (gsm_chars[0] == 0x1b) { - /* Escape character */ - guint8 second_byte; - i++; - second_byte = tvb_get_guint8(tvb, pos+3+i); - gsm_chars[0] |= second_byte << 7; - gsm_chars[1] = second_byte >> 1; - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 2)); - } else { - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 1)); - } - } else { - guint8 ucs2_char[2]; - ucs2_char[0] = ucs2_base >> 8; - ucs2_char[1] = (ucs2_base & 0xff) + (byte & 0x7f); - wmem_strbuf_append(strbuf, get_ucs_2_string(wmem_packet_scope(), ucs2_char, 2, ENC_BIG_ENDIAN)); - } - } - proto_tree_add_string(tree, hf_entry, tvb, pos, len, wmem_strbuf_finalize(strbuf)); - } else if (first_byte == 0x82) { - guint8 string_len = tvb_get_guint8(tvb, pos+1); - guint16 ucs2_base = tvb_get_ntohs(tvb, pos+2); - wmem_strbuf_t *strbuf = wmem_strbuf_sized_new(wmem_packet_scope(), 2*string_len+1, 0); - for (i = 0; i < string_len; i++) { - guint8 byte = tvb_get_guint8(tvb, pos+4+i); - if ((byte & 0x80) == 0) { - guint8 gsm_chars[2]; - gsm_chars[0] = byte; - if (gsm_chars[0] == 0x1b) { - /* Escape character */ - guint8 second_byte; - i++; - second_byte = tvb_get_guint8(tvb, pos+4+i); - gsm_chars[0] |= second_byte << 7; - gsm_chars[1] = second_byte >> 1; - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 2)); - } else { - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 1)); - } - } else { - guint8 ucs2_char[2]; - ucs2_char[0] = ucs2_base >> 8; - ucs2_char[1] = (ucs2_base & 0xff) + (byte & 0x7f); - wmem_strbuf_append(strbuf, get_ucs_2_string(wmem_packet_scope(), ucs2_char, 2, ENC_BIG_ENDIAN)); - } - } - proto_tree_add_string(tree, hf_entry, tvb, pos, len, wmem_strbuf_finalize(strbuf)); + /* + * Unpacked GSM alphabet. + */ + proto_tree_add_item(tree, hf_entry, tvb, pos, len, ENC_3GPP_TS_23_038_7BITS_UNPACKED|ENC_NA); + } else { + /* + * Annex A. + */ + proto_tree_add_item(tree, hf_entry, tvb, pos, len, ENC_ETSI_TS_102_221_ANNEX_A); } } } diff --git a/epan/dissectors/packet-gmr1_rr.c b/epan/dissectors/packet-gmr1_rr.c index 52fb29a5d7..00df109157 100644 --- a/epan/dissectors/packet-gmr1_rr.c +++ b/epan/dissectors/packet-gmr1_rr.c @@ -652,7 +652,7 @@ GMR1_IE_FUNC(gmr1_ie_rr_pos_display) txt_packed_tvb = tvb_new_real_data(txt_packed, 11, 11); /* Unpack text */ - txt_unpacked = tvb_get_ts_23_038_7bits_string(wmem_packet_scope(), txt_packed_tvb, 0, 12); + txt_unpacked = tvb_get_ts_23_038_7bits_string_packed(wmem_packet_scope(), txt_packed_tvb, 0, 12); tvb_free(txt_packed_tvb); /* Display it */ diff --git a/epan/dissectors/packet-gsm_a_dtap.c b/epan/dissectors/packet-gsm_a_dtap.c index cb7dd3a0b0..706b069e0f 100644 --- a/epan/dissectors/packet-gsm_a_dtap.c +++ b/epan/dissectors/packet-gsm_a_dtap.c @@ -938,7 +938,7 @@ de_network_name(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo, guint32 off { expert_add_info(pinfo, item, &ei_gsm_a_dtap_text_string_not_multiple_of_7); } - proto_tree_add_ts_23_038_7bits_item(tree, hf_gsm_a_dtap_text_string, tvb, curr_offset<<3, num_text_bits/7); + proto_tree_add_ts_23_038_7bits_packed_item(tree, hf_gsm_a_dtap_text_string, tvb, curr_offset<<3, num_text_bits/7); break; case 1: proto_tree_add_item(tree, hf_gsm_a_dtap_text_string, tvb, curr_offset, len - 1, ENC_UCS_2|ENC_BIG_ENDIAN); diff --git a/epan/dissectors/packet-gsm_sms.c b/epan/dissectors/packet-gsm_sms.c index 922f1b2d30..e82976e25d 100644 --- a/epan/dissectors/packet-gsm_sms.c +++ b/epan/dissectors/packet-gsm_sms.c @@ -645,7 +645,7 @@ dis_field_addr(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, guint32 *off { case 0x05: /* "Alphanumeric (coded according to 3GPP TS 23.038 GSM 7-bit default alphabet)" */ addrlength = (addrlength << 2) / 7; - addrstr = tvb_get_ts_23_038_7bits_string(wmem_packet_scope(), tvb, offset << 3, + addrstr = tvb_get_ts_23_038_7bits_string_packed(wmem_packet_scope(), tvb, offset << 3, (addrlength > MAX_ADDR_SIZE) ? MAX_ADDR_SIZE : addrlength); break; default: @@ -2131,29 +2131,23 @@ dis_field_ud(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset { if (data && data->stk_packing_required) { - /* STK requires SMS packing by the terminal */ - /* Per 3GPP 31.111 chapter 6.4.10: */ - /* It shall use the SMS default 7-bit coded alphabet */ - /* as defined in TS 23.038 with bit 8 set to 0 */ + /* + * STK requires SMS packing by the terminal; this means + * that the string here is *not* packet 7 bits per + * character, but is unpacked, with each character in + * an octet, with the expectation that the recipient + * will pack it before sending it on the network. + * + * Per 3GPP 31.111 chapter 6.4.10: + * It shall use the SMS default 7-bit coded alphabet + * as defined in TS 23.038 with bit 8 set to 0 + * + * I.e., bit 8 of each octet should be 0. + */ if(!(reassembled && pinfo->num == reassembled_in)) { - wmem_strbuf_t *strbuf = wmem_strbuf_sized_new(wmem_packet_scope(), length+1, 0); - for (i = 0; i < length; i++) { - guint8 gsm_chars[2]; - gsm_chars[0] = tvb_get_guint8(tvb, offset+i); - if (gsm_chars[0] == 0x1b) { - /* Escape character */ - guint8 second_byte; - i++; - second_byte = tvb_get_guint8(tvb, offset+i); - gsm_chars[0] |= second_byte << 7; - gsm_chars[1] = second_byte >> 1; - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 2)); - } else { - wmem_strbuf_append(strbuf, get_ts_23_038_7bits_string(wmem_packet_scope(), gsm_chars, 0, 1)); - } - } - proto_tree_add_string(subtree, hf_gsm_sms_text, tvb, offset, length, wmem_strbuf_finalize(strbuf)); + proto_tree_add_item(subtree, hf_gsm_sms_text, tvb, offset, + length, ENC_3GPP_TS_23_038_7BITS_UNPACKED); } else { @@ -2181,7 +2175,7 @@ dis_field_ud(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset if(!(reassembled && pinfo->num == reassembled_in)) { /* Show unassembled SMS */ - proto_tree_add_ts_23_038_7bits_item(subtree, hf_gsm_sms_text, tvb, (offset<<3)+fill_bits, + proto_tree_add_ts_23_038_7bits_packed_item(subtree, hf_gsm_sms_text, tvb, (offset<<3)+fill_bits, (udl > SMS_MAX_MESSAGE_SIZE ? SMS_MAX_MESSAGE_SIZE : udl)); } else @@ -2202,7 +2196,7 @@ dis_field_ud(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset &frag_params_key); if (p_frag_params) { - proto_tree_add_ts_23_038_7bits_item(subtree, hf_gsm_sms_text, sm_tvb, + proto_tree_add_ts_23_038_7bits_packed_item(subtree, hf_gsm_sms_text, sm_tvb, (total_sms_len<<3)+p_frag_params->fill_bits, (p_frag_params->udl > SMS_MAX_MESSAGE_SIZE ? SMS_MAX_MESSAGE_SIZE : p_frag_params->udl)); diff --git a/epan/dissectors/packet-mbim.c b/epan/dissectors/packet-mbim.c index 22841f05c1..7ac2249f82 100644 --- a/epan/dissectors/packet-mbim.c +++ b/epan/dissectors/packet-mbim.c @@ -3833,7 +3833,7 @@ static void mbim_decode_sms_cdma_text(tvbuff_t *tvb, proto_tree *tree, const int proto_tree_add_item(tree, hfindex, tvb, offset, size_in_bytes, ENC_ISO_8859_1|ENC_NA); break; case MBIM_ENCODING_GSM_7BIT: - proto_tree_add_ts_23_038_7bits_item(tree, hfindex, tvb, (offset << 3), size_in_chars); + proto_tree_add_ts_23_038_7bits_packed_item(tree, hfindex, tvb, (offset << 3), size_in_chars); break; default: break; diff --git a/epan/dissectors/packet-nas_eps.c b/epan/dissectors/packet-nas_eps.c index 712ceb1f66..496b1d604c 100644 --- a/epan/dissectors/packet-nas_eps.c +++ b/epan/dissectors/packet-nas_eps.c @@ -2356,7 +2356,7 @@ de_emm_ext_emerg_num_list(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U tvb, curr_offset, 1, ENC_NA, &length); curr_offset++; if (length > 0) { - proto_tree_add_ts_23_038_7bits_item(sub_tree, hf_eps_emm_ext_emerg_num_list_sub_serv_field, + proto_tree_add_ts_23_038_7bits_packed_item(sub_tree, hf_eps_emm_ext_emerg_num_list_sub_serv_field, tvb, curr_offset<<3, (length<<3)/7); curr_offset += length; } |