proto_tree_add_item_ret_(u)int/proto_tree_add_bitmask_with_flags_ret_uint64: return real value

Apply mask and bit shift on the returned value.

Change-Id: I00aebc854756f01a25199a259d6d5252abea4349
Reviewed-on: https://code.wireshark.org/review/17958
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Pascal Quantin 2016-09-27 23:57:29 +02:00 committed by Anders Broman
parent f8b32e5b4e
commit 152e245804
13 changed files with 49 additions and 40 deletions

View File

@ -669,7 +669,7 @@ fp_info *fpinf ;
subtree = proto_item_add_subtree(actx->created_item, ett_rrc_ims_info);
proto_tree_add_item_ret_uint(subtree, hf_rrc_ims_info_atgw_trans_det_cont_type, imsInformation_tvb, curr_offset, 1, ENC_BIG_ENDIAN, &atgw_trans_det_cont);
curr_offset++;
switch (atgw_trans_det_cont & 0x03) {
switch (atgw_trans_det_cont) {
case 0:
proto_tree_add_item(subtree, hf_rrc_ims_info_atgw_udp_port, imsInformation_tvb, curr_offset, 2, ENC_BIG_ENDIAN);
curr_offset+=2;

View File

@ -2270,7 +2270,7 @@ dissect_cpf(enip_request_key_t *request_key, int command, tvbuff_t *tvb,
* it to the list of information structures later before dissection.
*/
request_key = wmem_new0(wmem_packet_scope(), enip_request_key_t);
request_key->requesttype = (ucmm_request & 0x8000) ? ENIP_RESPONSE_PACKET : ENIP_REQUEST_PACKET;
request_key->requesttype = ucmm_request ? ENIP_RESPONSE_PACKET : ENIP_REQUEST_PACKET;
request_key->type = EPDT_UNKNOWN;
/* UCMM over UDP doesn't have a session handle, so use conversation

View File

@ -137,7 +137,6 @@ dissect_abis_pgsl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat
proto_tree_add_item(pgsl_tree, hf_pgsl_version, tvb, offset, 1, ENC_NA);
proto_tree_add_item_ret_uint(pgsl_tree, hf_pgsl_msg_disc, tvb, offset, 1, ENC_NA, &msg_disc);
msg_disc &= 0xF;
offset++;
col_append_str(pinfo->cinfo, COL_INFO, val_to_str(msg_disc, pgsl_msg_disc_vals, "Unknown (%u)"));
@ -187,7 +186,6 @@ dissect_abis_pgsl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat
/* Codec Status */
proto_tree_add_item(pgsl_tree, hf_pgsl_codec_delay, tvb, offset, 1, ENC_NA);
proto_tree_add_item_ret_uint(pgsl_tree, hf_pgsl_codec_cs, tvb, offset, 1, ENC_NA, &cs);
cs &= 0x1f;
proto_tree_add_item(pgsl_tree, hf_pgsl_codec_rxlev, tvb, offset+1, 1, ENC_NA);
if (cs <= 4) {
/* GPRS */

View File

@ -96,7 +96,7 @@ dissect_abis_tfp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
proto_item *ti;
proto_tree *tfp_tree;
int offset = 0;
guint32 slot_rate, frame_bits, hdr2, atsr, seq_nr;
guint32 slot_rate, frame_bits, atsr, seq_nr;
guint8 ftype;
tvbuff_t *next_tvb;
@ -105,12 +105,9 @@ dissect_abis_tfp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
ti = proto_tree_add_item(tree, proto_abis_tfp, tvb, 0, -1, ENC_NA);
tfp_tree = proto_item_add_subtree(ti, ett_tfp);
proto_tree_add_item_ret_uint(tfp_tree, hf_tfp_hdr_atsr, tvb, offset, 2, ENC_BIG_ENDIAN, &hdr2);
proto_tree_add_item(tfp_tree, hf_tfp_hdr_slot_rate, tvb, offset, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(tfp_tree, hf_tfp_hdr_seq_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
atsr = hdr2 >> 13;
slot_rate = (hdr2 >> 11) & 3;
seq_nr = (hdr2 >> 6) & 0x1f;
proto_tree_add_item_ret_uint(tfp_tree, hf_tfp_hdr_atsr, tvb, offset, 2, ENC_BIG_ENDIAN, &atsr);
proto_tree_add_item_ret_uint(tfp_tree, hf_tfp_hdr_slot_rate, tvb, offset, 2, ENC_BIG_ENDIAN, &slot_rate);
proto_tree_add_item_ret_uint(tfp_tree, hf_tfp_hdr_seq_nr, tvb, offset, 2, ENC_BIG_ENDIAN, &seq_nr);
proto_tree_add_item(tfp_tree, hf_tfp_hdr_delay_info, tvb, offset+1, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(tfp_tree, hf_tfp_hdr_p, tvb, offset+1, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(tfp_tree, hf_tfp_hdr_s, tvb, offset+2, 1, ENC_NA);

View File

@ -3972,7 +3972,7 @@ dissect_gtpv2_mm_context_eps_qq(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tre
proto_tree_add_item(tree, hf_gtpv2_mm_context_old_kasme, tvb, offset, 32, ENC_NA);
offset += 32;
/* (s+33) to (s+64) old NH */
if ((dword & 1) == 1) {
if (dword) {
proto_tree_add_item(tree, hf_gtpv2_mm_context_old_nh, tvb, offset, 32, ENC_NA);
offset += 32;
}

View File

@ -1064,7 +1064,6 @@ static int dissect_1722_aaf (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
{
proto_tree_add_item(ti_aaf_tree, hf_1722_aaf_nominal_sample_rate, tvb, offset, 2, ENC_BIG_ENDIAN);
ti_channels_per_frame = proto_tree_add_item_ret_uint(ti_aaf_tree, hf_1722_aaf_channels_per_frame, tvb, offset, 2, ENC_BIG_ENDIAN, &channels_per_frame);
channels_per_frame &= IEEE_1722_CHANNEL_PER_FRAME_MASK;
if (channels_per_frame == 0)
{
expert_add_info(pinfo, ti_channels_per_frame, &ei_aaf_channels_per_frame);

View File

@ -4823,7 +4823,7 @@ static void dissect_ulsch_or_dlsch(tvbuff_t *tvb, packet_info *pinfo, proto_tree
it = proto_tree_add_item_ret_uint(slbsr_tree, hf_mac_lte_control_sidelink_reserved,
tvb, curr_offset, 1, ENC_BIG_ENDIAN, &reserved);
if (reserved & 0x0f) {
if (reserved) {
if (lcids[n] == SIDELINK_BSR) {
expert_add_info_format(pinfo, it, &ei_mac_lte_reserved_not_zero,
"Sidelink BSR Reserved bits not zero");
@ -5517,7 +5517,7 @@ static void dissect_ulsch_or_dlsch(tvbuff_t *tvb, packet_info *pinfo, proto_tree
dpr_tree = proto_item_add_subtree(dpr_ti, ett_mac_lte_data_vol_power_headroom);
dpr_ti = proto_tree_add_item_ret_uint(dpr_tree, hf_mac_lte_data_vol_power_headroom_reserved,
tvb, offset, 1, ENC_BIG_ENDIAN, &reserved);
if (reserved & 0xc0) {
if (reserved) {
expert_add_info_format(pinfo, dpr_ti, &ei_mac_lte_reserved_not_zero,
"Data Volume and Power Headroom Report Reserved bits not zero");
}
@ -6245,7 +6245,7 @@ static void dissect_slsch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
ti = proto_tree_add_item_ret_uint(pdu_subheader_tree, hf_mac_lte_slsch_reserved,
tvb, offset, 1, ENC_BIG_ENDIAN, &reserved);
offset++;
if (reserved & 0x0f) {
if (reserved) {
expert_add_info_format(pinfo, ti, &ei_mac_lte_reserved_not_zero,
"SL-SCH header Reserved bits not zero");
}
@ -6274,8 +6274,9 @@ static void dissect_slsch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
ett_mac_lte_slsch_subheader);
/* Check 1st 2 reserved bits */
ti = proto_tree_add_item_ret_uint(pdu_subheader_tree, hf_mac_lte_slsch_reserved2,
tvb, offset, 1, ENC_BIG_ENDIAN, &first_byte);
ti = proto_tree_add_item(pdu_subheader_tree, hf_mac_lte_slsch_reserved2,
tvb, offset, 1, ENC_BIG_ENDIAN);
first_byte = tvb_get_guint8(tvb, offset);
if ((first_byte & 0xc0) != 0) {
expert_add_info_format(pinfo, ti, &ei_mac_lte_reserved_not_zero,
"SL-SCH header Reserved bits not zero");
@ -6333,7 +6334,7 @@ static void dissect_slsch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
tvb, offset, 1, ENC_BIG_ENDIAN, &format);
/* Now read length field itself */
if (format & 0x80) {
if (format) {
/* >= 128 - use 15 bits */
proto_tree_add_bits_ret_val(pdu_subheader_tree, hf_mac_lte_slsch_length,
tvb, offset*8 + 1, 15, &length, ENC_BIG_ENDIAN);

View File

@ -2977,7 +2977,7 @@ de_esm_remote_ue_context_list(tvbuff_t *tvb, proto_tree *tree, packet_info *pinf
curr_offset ++;
proto_tree_add_item(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_odd_even_indic, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item_ret_uint(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_user_id_type, tvb, curr_offset, 1, ENC_BIG_ENDIAN, &user_id_type);
switch (user_id_type & 0x07) {
switch (user_id_type) {
case 1:
proto_tree_add_bits_item(subtree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 4, ENC_BIG_ENDIAN);
curr_offset++;
@ -3017,7 +3017,7 @@ de_esm_remote_ue_context_list(tvbuff_t *tvb, proto_tree *tree, packet_info *pinf
proto_tree_add_bits_item(subtree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 5, ENC_BIG_ENDIAN);
proto_tree_add_item_ret_uint(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_address_type, tvb, curr_offset, 1, ENC_BIG_ENDIAN, &remote_address_type);
curr_offset++;
switch (remote_address_type & 0x07) {
switch (remote_address_type) {
case 1:
proto_tree_add_item(subtree, hf_nas_eps_esm_remote_ue_context_list_ue_context_ipv4, tvb, curr_offset, 4, ENC_BIG_ENDIAN);
curr_offset += 4;
@ -3055,7 +3055,7 @@ de_esm_pkmf_address(tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo _U_,
proto_tree_add_bits_item(tree, hf_nas_eps_spare_bits, tvb, curr_offset<<3, 5, ENC_BIG_ENDIAN);
proto_tree_add_item_ret_uint(tree, hf_nas_eps_esm_pkmf_address_type, tvb, curr_offset, 1, ENC_BIG_ENDIAN, &pkmf_address_type);
curr_offset++;
switch (pkmf_address_type & 0x07) {
switch (pkmf_address_type) {
case 1:
proto_tree_add_item(tree, hf_nas_eps_esm_pkmf_ipv4, tvb, curr_offset, 4, ENC_BIG_ENDIAN);
break;

View File

@ -2063,7 +2063,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* First-Missing-Sequence SN */
proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_fms, tvb,
offset, 2, ENC_BIG_ENDIAN, &fms);
fms &= 0x0fff;
offset += 2;
/* HRW */
@ -2074,7 +2073,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* NMP */
proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_nmp, tvb,
offset, 2, ENC_BIG_ENDIAN, &nmp);
nmp &= 0x0fff;
offset += 2;
} else if (p_pdcp_info->seqnum_length == PDCP_SN_LENGTH_15_BITS) {
proto_item *ti;
@ -2083,7 +2081,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* 5 reserved bits */
ti = proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_reserved4, tvb,
offset, 2, ENC_BIG_ENDIAN, &reserved_value);
reserved_value = (reserved_value & 0x0f80) >> 7;
offset++;
/* Complain if not 0 */
if (reserved_value != 0) {
@ -2095,14 +2092,13 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* First-Missing-Sequence SN */
proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_fms2, tvb,
offset, 2, ENC_BIG_ENDIAN, &fms);
fms &= 0x7fff;
offset += 2;
/* 1 reserved bit */
ti = proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_reserved7, tvb,
offset, 1, ENC_BIG_ENDIAN, &reserved_value);
/* Complain if not 0 */
if (reserved_value & 0x80) {
if (reserved_value) {
expert_add_info_format(pinfo, ti, &ei_pdcp_lte_reserved_bits_not_zero,
"Reserved bits have value 0x1 - should be 0x0");
}
@ -2116,7 +2112,7 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
ti = proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_reserved7, tvb,
offset, 1, ENC_BIG_ENDIAN, &reserved_value);
/* Complain if not 0 */
if (reserved_value & 0x80) {
if (reserved_value) {
expert_add_info_format(pinfo, ti, &ei_pdcp_lte_reserved_bits_not_zero,
"Reserved bits have value 0x1 - should be 0x0");
}
@ -2124,7 +2120,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* NMP */
proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_nmp2, tvb,
offset, 2, ENC_BIG_ENDIAN, &nmp);
nmp &= 0x7fff;
offset += 2;
} else {
proto_item *ti;
@ -2133,7 +2128,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* 2 reserved bits */
ti = proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_reserved6,
tvb, offset, 1, ENC_BIG_ENDIAN, &reserved_value);
reserved_value = (reserved_value & 0x0c) >> 2;
/* Complain if not 0 */
if (reserved_value != 0) {
expert_add_info_format(pinfo, ti, &ei_pdcp_lte_reserved_bits_not_zero,
@ -2144,7 +2138,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* First-Missing-Sequence SN */
proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_fms3, tvb,
offset, 3, ENC_BIG_ENDIAN, &fms);
fms &= 0x03ffff;
offset += 3;
/* HRW */
@ -2155,7 +2148,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* 4 reserved bits */
ti = proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_reserved8,
tvb, offset, 1, ENC_BIG_ENDIAN, &reserved_value);
reserved_value = (reserved_value & 0x3c) >> 2;
/* Complain if not 0 */
if (reserved_value != 0) {
expert_add_info_format(pinfo, ti, &ei_pdcp_lte_reserved_bits_not_zero,
@ -2166,7 +2158,6 @@ static int dissect_pdcp_lte(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
/* NMP */
proto_tree_add_item_ret_uint(pdcp_tree, hf_pdcp_lte_nmp3, tvb,
offset, 3, ENC_BIG_ENDIAN, &nmp);
nmp &= 0x03ffff;
offset += 3;
}

View File

@ -96604,7 +96604,7 @@ dissect_rrc_T_ims_Information(tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *act
subtree = proto_item_add_subtree(actx->created_item, ett_rrc_ims_info);
proto_tree_add_item_ret_uint(subtree, hf_rrc_ims_info_atgw_trans_det_cont_type, imsInformation_tvb, curr_offset, 1, ENC_BIG_ENDIAN, &atgw_trans_det_cont);
curr_offset++;
switch (atgw_trans_det_cont & 0x03) {
switch (atgw_trans_det_cont) {
case 0:
proto_tree_add_item(subtree, hf_rrc_ims_info_atgw_udp_port, imsInformation_tvb, curr_offset, 2, ENC_BIG_ENDIAN);
curr_offset+=2;

View File

@ -3125,7 +3125,6 @@ dissct_rsl_ipaccess_msg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int
case RSL_IE_IPAC_SPEECH_MODE:
proto_tree_add_item_ret_uint(ie_tree, hf_rsl_speech_mode_s, tvb,
offset, len, ENC_BIG_ENDIAN, &rtp_codec);
rtp_codec &= 0x0f;
conv = find_or_create_conversation(pinfo);
dyn_pl_info = (struct dyn_pl_info_t *)conversation_get_proto_data(conv, proto_rsl);
if (!dyn_pl_info) {

View File

@ -2324,8 +2324,18 @@ proto_tree_add_item_ret_int(proto_tree *tree, int hfindex, tvbuff_t *tvb,
/* I believe it's ok if this is called with a NULL tree */
value = get_int_value(tree, tvb, start, length, encoding);
if (retval)
if (retval) {
gint no_of_bits;
*retval = value;
if (hfinfo->bitmask) {
/* Mask out irrelevant portions */
*retval &= (guint32)(hfinfo->bitmask);
/* Shift bits */
*retval >>= hfinfo_bitshift(hfinfo);
}
no_of_bits = ws_count_ones(hfinfo->bitmask);
*retval = ws_sign_ext32(*retval, no_of_bits);
}
CHECK_FOR_NULL_TREE(tree);
@ -2376,8 +2386,15 @@ proto_tree_add_item_ret_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb,
/* XXX - modify if we ever support EBCDIC FT_CHAR */
value = get_uint_value(tree, tvb, start, length, encoding);
if (retval)
if (retval) {
*retval = value;
if (hfinfo->bitmask) {
/* Mask out irrelevant portions */
*retval &= (guint32)(hfinfo->bitmask);
/* Shift bits */
*retval >>= hfinfo_bitshift(hfinfo);
}
}
CHECK_FOR_NULL_TREE(tree);
@ -9531,6 +9548,13 @@ proto_tree_add_bitmask_with_flags_ret_uint64(proto_tree *parent_tree, tvbuff_t *
}
*retval = value;
if (hf->bitmask) {
/* Mask out irrelevant portions */
*retval &= hf->bitmask;
/* Shift bits */
*retval >>= hfinfo_bitshift(hf);
}
return item;
}

View File

@ -1055,7 +1055,7 @@ Integers of 8, 16, 24 and 32 bits can be retrieved with these functions.
@param length length of data in tvb (for strings can be -1 for remaining)
@param encoding data encoding (e.g, ENC_LITTLE_ENDIAN, ENC_BIG_ENDIAN, ENC_ASCII|ENC_STRING, etc.)
@param[out] retval points to a gint32 or guint32 which will be set to the value
@return the newly created item, and *retval is set to the decoded value
@return the newly created item, and *retval is set to the decoded value masked/shifted according to bitmask
*/
WS_DLL_PUBLIC proto_item *
proto_tree_add_item_ret_int(proto_tree *tree, int hfindex, tvbuff_t *tvb,
@ -2461,7 +2461,7 @@ proto_tree_add_bitmask(proto_tree *tree, tvbuff_t *tvb, const guint offset,
matched string displayed on the expansion line.
@param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
@param[out] retval points to a guint64 which will be set
@return the newly created item, and *retval is set to the decoded value
@return the newly created item, and *retval is set to the decoded value masked/shifted according to bitmask
*/
WS_DLL_PUBLIC proto_item *
proto_tree_add_bitmask_ret_uint64(proto_tree *tree, tvbuff_t *tvb, const guint offset,
@ -2520,7 +2520,7 @@ proto_tree_add_bitmask_with_flags(proto_tree *tree, tvbuff_t *tvb, const guint o
@param encoding big or little endian byte representation (ENC_BIG_ENDIAN/ENC_LITTLE_ENDIAN/ENC_HOST_ENDIAN)
@param flags bitmask field using BMT_NO_* flags to determine behavior
@param[out] retval points to a guint64 which will be set
@return the newly created item, and *retval is set to the decoded value
@return the newly created item, and *retval is set to the decoded value masked/shifted according to bitmask
*/
WS_DLL_PUBLIC proto_item *
proto_tree_add_bitmask_with_flags_ret_uint64(proto_tree *tree, tvbuff_t *tvb, const guint offset,