diff options
author | Tomasz Moń <desowin@gmail.com> | 2019-07-19 17:43:20 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2019-07-25 08:58:13 +0000 |
commit | dd5f2bd054710910788656e068ad8853089c84c5 (patch) | |
tree | 310b4d2361be39e018cb0e05d534dac3fad3cc51 /epan | |
parent | 53fdec477da233d7161990616f174deedad524b8 (diff) |
USBLL: Verify DATA packets CRC-16
Ping-Bug: 15908
Change-Id: Idda280545665184aca40c694ea6d639c9317307a
Reviewed-on: https://code.wireshark.org/review/34016
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/crc16-tvb.c | 10 | ||||
-rw-r--r-- | epan/crc16-tvb.h | 7 | ||||
-rw-r--r-- | epan/dissectors/packet-usbll.c | 13 |
3 files changed, 29 insertions, 1 deletions
diff --git a/epan/crc16-tvb.c b/epan/crc16-tvb.c index 85b92a3ce7..85b6337d4e 100644 --- a/epan/crc16-tvb.c +++ b/epan/crc16-tvb.c @@ -96,6 +96,16 @@ guint16 crc16_iso14443a_tvb_offset(tvbuff_t *tvb, guint offset, guint len) return crc16_iso14443a(buf, len); } +guint16 crc16_usb_tvb_offset(tvbuff_t *tvb, guint offset, guint len) +{ + const guint8 *buf; + + tvb_ensure_bytes_exist(tvb, offset, len); /* len == -1 not allowed */ + buf = tvb_get_ptr(tvb, offset, len); + + return crc16_usb(buf, len); +} + guint16 crc16_plain_tvb_offset(tvbuff_t *tvb, guint offset, guint len) { guint16 crc = crc16_plain_init(); diff --git a/epan/crc16-tvb.h b/epan/crc16-tvb.h index 203ca23652..454cfbc992 100644 --- a/epan/crc16-tvb.h +++ b/epan/crc16-tvb.h @@ -72,6 +72,13 @@ WS_DLL_PUBLIC guint16 crc16_ccitt_tvb_offset_seed(tvbuff_t *tvb, guint offset, @return The calculated CRC_A. */ WS_DLL_PUBLIC guint16 crc16_iso14443a_tvb_offset(tvbuff_t *tvb, guint offset, guint len); +/** Compute the 16bit CRC value of a tv buffer as defined in USB Standard. + @param tvb The tv buffer containing the data. + @param offset The offset into the tv buffer. + @param len The number of bytes to include in the computation. + @return The calculated CRC. */ +WS_DLL_PUBLIC guint16 crc16_usb_tvb_offset(tvbuff_t *tvb, guint offset, guint len); + /** Compute the "plain" CRC16 checksum of a tv buffer using the following * parameters: * Width = 16 diff --git a/epan/dissectors/packet-usbll.c b/epan/dissectors/packet-usbll.c index d9a42e20ad..ce99b983c9 100644 --- a/epan/dissectors/packet-usbll.c +++ b/epan/dissectors/packet-usbll.c @@ -16,6 +16,7 @@ #include "config.h" #include <epan/packet.h> #include <epan/expert.h> +#include <epan/crc16-tvb.h> static int proto_usbll = -1; @@ -26,6 +27,7 @@ static int hf_usbll_endp = -1; static int hf_usbll_crc5 = -1; static int hf_usbll_data = -1; static int hf_usbll_data_crc = -1; +static int hf_usbll_data_crc_status = -1; static int hf_usbll_sof_framenum = -1; static int hf_usbll_split_hub_addr = -1; static int hf_usbll_split_sc = -1; @@ -40,6 +42,7 @@ static int ett_usbll = -1; static expert_field ei_invalid_pid = EI_INIT; static expert_field ei_undecoded = EI_INIT; +static expert_field ei_wrong_crc16 = EI_INIT; static dissector_handle_t usbll_handle; @@ -174,7 +177,10 @@ dissect_usbll_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, proto_tree_add_item(tree, hf_usbll_data, tvb, offset, data_size, ENC_NA); offset += data_size; } - proto_tree_add_item(tree, hf_usbll_data_crc, tvb, offset, 2, ENC_LITTLE_ENDIAN); + proto_tree_add_checksum(tree, tvb, offset, + hf_usbll_data_crc, hf_usbll_data_crc_status, &ei_wrong_crc16, pinfo, + crc16_usb_tvb_offset(tvb, 1, offset - 1), + ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY); offset += 2; break; } @@ -278,6 +284,10 @@ proto_register_usbll(void) { "CRC", "usbll.crc16", FT_UINT16, BASE_HEX, NULL, 0x0000, NULL, HFILL }}, + { &hf_usbll_data_crc_status, + { "CRC Status", "usbll.crc16.status", + FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0, + NULL, HFILL }}, { &hf_usbll_sof_framenum, { "Frame Number", "usbll.frame_num", FT_UINT16, BASE_DEC, NULL, 0x07FF, @@ -320,6 +330,7 @@ proto_register_usbll(void) static ei_register_info ei[] = { { &ei_invalid_pid, { "usbll.invalid_pid", PI_MALFORMED, PI_ERROR, "Invalid USB Packet ID", EXPFILL }}, { &ei_undecoded, { "usbll.undecoded", PI_UNDECODED, PI_WARN, "Not dissected yet (report to wireshark.org)", EXPFILL }}, + { &ei_wrong_crc16, { "usbll.crc16.wrong", PI_PROTOCOL, PI_WARN, "Wrong CRC", EXPFILL }}, }; static gint *ett[] = { |