From 8b0e9c66728f6a39bbe3ada1029e13ad1378013a Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Thu, 21 Jul 2016 10:21:25 -0400 Subject: Follow up for proto_tree_add_checksum. Fill in the "gaps" so that all dissectors that verify checksums have both a status and expert info field. Also address comments from original proto_tree_add_checksum patch that didn't make it. Ping-Bug: 8859 Change-Id: I2e6640108fd6bb218cb959fe9e4ba98a13e43a2f Reviewed-on: https://code.wireshark.org/review/16590 Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- plugins/irda/packet-sir.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'plugins/irda/packet-sir.c') diff --git a/plugins/irda/packet-sir.c b/plugins/irda/packet-sir.c index 13534a7c5f..ff7ded56fb 100644 --- a/plugins/irda/packet-sir.c +++ b/plugins/irda/packet-sir.c @@ -25,6 +25,7 @@ #include "config.h" #include +#include #include /** Serial infrared port. */ @@ -60,6 +61,8 @@ static int hf_sir_fcs_status = -1; static int hf_sir_length = -1; static int hf_sir_preamble = -1; +static expert_field ei_sir_fcs = EI_INIT; + /* Copied and renamed from proto.c because global value_strings don't work for plugins */ static const value_string plugin_proto_checksum_vals[] = { { PROTO_CHECKSUM_E_BAD, "Bad" }, @@ -101,13 +104,13 @@ unescape_data(tvbuff_t *tvb, packet_info *pinfo) /** Checksums the data. */ static tvbuff_t * -checksum_data(tvbuff_t *tvb, proto_tree *tree) +checksum_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { int len = tvb_reported_length(tvb) - 2; if (len < 0) return tvb; - proto_tree_add_checksum(tree, tvb, len, hf_sir_fcs, hf_sir_fcs_status, NULL, NULL, crc16_ccitt_tvb(tvb, len), + proto_tree_add_checksum(tree, tvb, len, hf_sir_fcs, hf_sir_fcs_status, &ei_sir_fcs, pinfo, crc16_ccitt_tvb(tvb, len), ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY); return tvb_new_subset_length(tvb, 0, len); @@ -153,11 +156,11 @@ dissect_sir(tvbuff_t *tvb, packet_info *pinfo, proto_tree *root, void* data _U_) bof_offset, 1, ENC_BIG_ENDIAN); proto_tree_add_uint(tree, hf_sir_length, next_tvb, 0, data_len, data_len); - next_tvb = checksum_data(next_tvb, tree); + next_tvb = checksum_data(next_tvb, pinfo, tree); proto_tree_add_item(tree, hf_sir_eof, tvb, eof_offset, 1, ENC_BIG_ENDIAN); } else { - next_tvb = checksum_data(next_tvb, NULL); + next_tvb = checksum_data(next_tvb, pinfo, NULL); } call_dissector(irda_handle, next_tvb, pinfo, root); } @@ -216,12 +219,18 @@ proto_register_irsir(void) NULL, HFILL }} }; - proto_sir = proto_register_protocol( - "Serial Infrared", "SIR", "sir"); + static ei_register_info ei[] = { + { &ei_sir_fcs, { "sir.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }}, + }; + + expert_module_t* expert_sir; + + proto_sir = proto_register_protocol("Serial Infrared", "SIR", "sir"); register_dissector("sir", dissect_sir, proto_sir); proto_register_subtree_array(ett, array_length(ett)); - proto_register_field_array( - proto_sir, hf_sir, array_length(hf_sir)); + proto_register_field_array( proto_sir, hf_sir, array_length(hf_sir)); + expert_sir = expert_register_protocol(proto_sir); + expert_register_field_array(expert_sir, ei, array_length(ei)); } /* -- cgit v1.2.1