diff options
author | Michael Mann <mmann78@netscape.net> | 2016-07-10 23:47:28 -0400 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-07-21 12:35:22 +0000 |
commit | ad6fc87d64de30cdcdca18168a117d2ec24591da (patch) | |
tree | b5df109654ae6806db7544933f8bf1a848a02ae7 /plugins/irda/packet-sir.c | |
parent | 1e19f55f0c44b850bc6304be28d5b272a3553204 (diff) | |
download | wireshark-ad6fc87d64de30cdcdca18168a117d2ec24591da.tar.gz |
Add proto_tree_add_checksum.
This is an attempt to standardize display/handling of checksum fields for all dissectors.
The main target is for dissectors that do validation, but dissectors that just report the
checksum were also included just to make them easier to find in the future.
Bug: 10620
Bug: 12058
Ping-Bug: 8859
Change-Id: Ia8abd86e42eaf8ed50de6b173409e914b17993bf
Reviewed-on: https://code.wireshark.org/review/16380
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Jeff Morriss <jeff.morriss.ws@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'plugins/irda/packet-sir.c')
-rw-r--r-- | plugins/irda/packet-sir.c | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/plugins/irda/packet-sir.c b/plugins/irda/packet-sir.c index 98ee323390..11188a47bf 100644 --- a/plugins/irda/packet-sir.c +++ b/plugins/irda/packet-sir.c @@ -56,10 +56,20 @@ static int hf_sir_bof = -1; /* static int hf_sir_ce = -1; */ static int hf_sir_eof = -1; static int hf_sir_fcs = -1; -static int hf_sir_fcs_bad = -1; +static int hf_sir_fcs_status = -1; static int hf_sir_length = -1; static int hf_sir_preamble = -1; +/* 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" }, + { PROTO_CHECKSUM_E_GOOD, "Good" }, + { PROTO_CHECKSUM_E_UNVERIFIED, "Unverified" }, + { PROTO_CHECKSUM_E_NOT_PRESENT, "Not present" }, + + { 0, NULL } +}; + /** Unescapes the data. */ static tvbuff_t * @@ -94,29 +104,13 @@ unescape_data(tvbuff_t *tvb, packet_info *pinfo) static tvbuff_t * checksum_data(tvbuff_t *tvb, proto_tree *tree) { - proto_item *hidden_item; int len = tvb_reported_length(tvb) - 2; if (len < 0) return tvb; - if (tree) { - guint16 actual_fcs = tvb_get_letohs(tvb, len); - guint16 calculated_fcs = crc16_ccitt_tvb(tvb, len); - if (calculated_fcs == actual_fcs) { - proto_tree_add_uint_format(tree, hf_sir_fcs, - tvb, len, 2, actual_fcs, - "Frame check sequence: 0x%04x (correct)", - actual_fcs); - } else { - hidden_item = proto_tree_add_boolean(tree, - hf_sir_fcs_bad, tvb, len, 2, TRUE); - PROTO_ITEM_SET_HIDDEN(hidden_item); - proto_tree_add_uint_format(tree, hf_sir_fcs, - tvb, len, 2, actual_fcs, - "Frame check sequence: 0x%04x " - "(incorrect, should be 0x%04x)", - actual_fcs, calculated_fcs); - } - } + + proto_tree_add_checksum(tree, tvb, len, hf_sir_fcs, hf_sir_fcs_status, NULL, NULL, crc16_ccitt_tvb(tvb, len), + ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY); + return tvb_new_subset_length(tvb, 0, len); } @@ -209,9 +203,9 @@ proto_register_irsir(void) { "Frame check sequence", "sir.fcs", FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }}, - { &hf_sir_fcs_bad, - { "Bad frame check sequence", "sir.fcs_bad", - FT_BOOLEAN, BASE_NONE, NULL, 0x0, + { &hf_sir_fcs_status, + { "Frame check sequence Status", "sir.fcs.status", + FT_UINT8, BASE_NONE, VALS(plugin_proto_checksum_vals), 0x0, NULL, HFILL }}, { &hf_sir_length, { "Length", "sir.length", |