diff options
-rw-r--r-- | epan/CMakeLists.txt | 1 | ||||
-rw-r--r-- | epan/dissectors/Makefile.common | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-ubertooth.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-usb-dfu.c | 607 | ||||
-rw-r--r-- | epan/dissectors/packet-usb.c | 120 |
5 files changed, 670 insertions, 63 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt index 2e59071e1f..1ecaad13c6 100644 --- a/epan/CMakeLists.txt +++ b/epan/CMakeLists.txt @@ -1261,6 +1261,7 @@ set(DISSECTOR_SRC dissectors/packet-usb-audio.c dissectors/packet-usb-ccid.c dissectors/packet-usb-com.c + dissectors/packet-usb-dfu.c dissectors/packet-usb-hid.c dissectors/packet-usb-hub.c dissectors/packet-usb-masstorage.c diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common index 960c5b3bc6..0145dd56ee 100644 --- a/epan/dissectors/Makefile.common +++ b/epan/dissectors/Makefile.common @@ -1181,6 +1181,7 @@ DISSECTOR_SRC = \ packet-usb-audio.c \ packet-usb-ccid.c \ packet-usb-com.c \ + packet-usb-dfu.c \ packet-usb-hid.c \ packet-usb-hub.c \ packet-usb-masstorage.c \ diff --git a/epan/dissectors/packet-ubertooth.c b/epan/dissectors/packet-ubertooth.c index 1d1d732e09..c142d4dfcd 100644 --- a/epan/dissectors/packet-ubertooth.c +++ b/epan/dissectors/packet-ubertooth.c @@ -684,6 +684,8 @@ dissect_ubertooth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat wmem_tree_insert32_array(command_info, key, command_data); } + pinfo->p2p_dir = p2p_dir_save; + return offset; } @@ -703,6 +705,8 @@ dissect_ubertooth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat proto_tree_add_expert(main_tree, pinfo, &ei_unknown_data, tvb, offset, tvb_length_remaining(tvb, offset)); + pinfo->p2p_dir = p2p_dir_save; + return tvb_length(tvb); } diff --git a/epan/dissectors/packet-usb-dfu.c b/epan/dissectors/packet-usb-dfu.c new file mode 100644 index 0000000000..902a5479f9 --- /dev/null +++ b/epan/dissectors/packet-usb-dfu.c @@ -0,0 +1,607 @@ +/* packet-usbdfu.c + * Routines for USB DFU dissection + * + * Copyright 2014, Michal Labedzki for Tieto Corporation + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <epan/packet.h> +#include <epan/prefs.h> +#include <epan/expert.h> +#include <epan/wmem/wmem.h> + +#include "packet-usb.h" + +static int proto_usb_dfu = -1; + +static gint hf_setup_command = -1; +static gint hf_setup_unused = -1; +static gint hf_setup_interface = -1; +static gint hf_setup_length = -1; +static gint hf_setup_timeout = -1; +static gint hf_setup_block_number = -1; +static gint hf_response = -1; +static gint hf_command_in_frame = -1; +static gint hf_state = -1; +static gint hf_status = -1; +static gint hf_poll_timeout = -1; +static gint hf_iString = -1; +static gint hf_data = -1; +static gint hf_usb_dfu_descriptor = -1; +static gint hf_usb_dfu_descriptor_bmAttributes_reserved = -1; +static gint hf_usb_dfu_descriptor_bmAttributes_WillDetach = -1; +static gint hf_usb_dfu_descriptor_bmAttributes_ManifestationTolerant = -1; +static gint hf_usb_dfu_descriptor_bmAttributes_CanUpload = -1; +static gint hf_usb_dfu_descriptor_bmAttributes_CanDownload = -1; +static gint hf_usb_dfu_descriptor_wDetachTimeOut = -1; +static gint hf_usb_dfu_descriptor_wTransferSize = -1; +static gint hf_usb_dfu_descriptor_bcdDFUVersion = -1; + +static gint ett_usb_dfu = -1; +static gint ett_usb_dfu_descriptor = -1; +static gint ett_command = -1; + +static expert_field ei_unexpected_response = EI_INIT; +static expert_field ei_unknown_data = EI_INIT; +static expert_field ei_unexpected_data = EI_INIT; +static expert_field ei_descriptor_invalid_length = EI_INIT; +static expert_field ei_invalid_command_for_request_type = EI_INIT; + +static dissector_handle_t usb_dfu_handle; + +static wmem_tree_t *command_info = NULL; + +typedef struct _command_data { + guint32 bus_id; + guint32 device_address; + + guint16 interface; + guint8 command; + guint32 command_frame_number; + gint32 block_number; +} command_data_t; + + +static const value_string command_vals[] = { + { 0x00, "Detach" }, + { 0x01, "Download" }, + { 0x02, "Upload" }, + { 0x03, "Get Status" }, + { 0x04, "Clear Status" }, + { 0x05, "Get State" }, + { 0x06, "Abort" }, + { 0x00, NULL } +}; +static value_string_ext(command_vals_ext) = VALUE_STRING_EXT_INIT(command_vals); + +static const value_string state_vals[] = { + { 0, "appIdle" }, + { 1, "appDetach" }, + { 2, "dfuIdle" }, + { 3, "dfuDownloadSync" }, + { 4, "dfuDownloadBusy" }, + { 5, "dfuDownloadIdle" }, + { 6, "dfuManifestSync" }, + { 7, "dfuManifest" }, + { 8, "dfuManifestWaitReset" }, + { 9, "dfuUploadIdle" }, + { 10, "dfuError" }, + { 0x00, NULL } +}; +static value_string_ext(state_vals_ext) = VALUE_STRING_EXT_INIT(state_vals); + +static const value_string status_vals[] = { + { 0x00, "OK" }, + { 0x01, "errTarget" }, + { 0x02, "errFile" }, + { 0x03, "errWrite" }, + { 0x04, "errErase" }, + { 0x05, "errCheckErased" }, + { 0x06, "errProg" }, + { 0x07, "errVerify" }, + { 0x08, "errAddress" }, + { 0x09, "errNotDone" }, + { 0x0A, "errFirmware" }, + { 0x0B, "errVendor" }, + { 0x0C, "errUsbReset" }, + { 0x0D, "errPowerOnReset" }, + { 0x0E, "errUnknown" }, + { 0x0F, "errStalledPkt" }, + { 0x00, NULL } +}; +static value_string_ext(status_vals_ext) = VALUE_STRING_EXT_INIT(status_vals); + +static const value_string descriptor_type_vals[] = { + { 0x21, "DFU FUNCTIONAL" }, + { 0x00, NULL } +}; +static value_string_ext(descriptor_type_vals_ext) = VALUE_STRING_EXT_INIT(descriptor_type_vals); + +void proto_register_usb_dfu(void); +void proto_reg_handoff_usb_dfu(void); + + +static gint +dissect_usb_dfu_descriptor(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +{ + proto_item *main_item; + proto_tree *main_tree; + proto_item *length_item; + gint offset = 0; + guint8 descriptor_length; + guint8 descriptor_type; + usb_conv_info_t *usb_conv_info = (usb_conv_info_t *) data; + + if (!usb_conv_info) return offset; + + if (!(usb_conv_info->interfaceClass == IF_CLASS_APPLICATION_SPECIFIC && + usb_conv_info->interfaceSubclass == 0x01)) return offset; + + descriptor_length = tvb_get_guint8(tvb, offset); + descriptor_type = tvb_get_guint8(tvb, offset + 1); + + switch (descriptor_type) { + case 0x21: + main_item = proto_tree_add_item(tree, hf_usb_dfu_descriptor, tvb, offset, -1, ENC_NA); + main_tree = proto_item_add_subtree(main_item, ett_usb_dfu_descriptor); + + proto_item_append_text(main_item, ": %s", val_to_str_ext_const(descriptor_type, &descriptor_type_vals_ext, "Unknown")); + + length_item = dissect_usb_descriptor_header(main_tree, tvb, offset, &descriptor_type_vals_ext); + if (descriptor_length != 7 && descriptor_length != 9) + expert_add_info(pinfo, length_item, &ei_descriptor_invalid_length); + offset += 2; + + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_bmAttributes_reserved, tvb, offset, 1, ENC_NA); + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_bmAttributes_WillDetach, tvb, offset, 1, ENC_NA); + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_bmAttributes_ManifestationTolerant, tvb, offset, 1, ENC_NA); + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_bmAttributes_CanUpload, tvb, offset, 1, ENC_NA); + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_bmAttributes_CanDownload, tvb, offset, 1, ENC_NA); + offset += 1; + + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_wDetachTimeOut, tvb, offset, 2, ENC_LITTLE_ENDIAN); + offset += 2; + + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_wTransferSize, tvb, offset, 2, ENC_LITTLE_ENDIAN); + offset += 2; + + if (descriptor_length > 7) { + proto_tree_add_item(main_tree, hf_usb_dfu_descriptor_bcdDFUVersion, tvb, offset, 2, ENC_LITTLE_ENDIAN); + offset += 2; + } + + break; + } + + return offset; +} + +static gint +dissect_usb_dfu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data) +{ + proto_item *main_item; + proto_tree *main_tree; + proto_item *command_item; + proto_item *sub_item; + proto_tree *command_tree; + gint offset = 0; + gint p2p_dir_save; + guint8 command; + gint16 command_response = -1; + command_data_t *command_data = NULL; + wmem_tree_t *wmem_tree; + wmem_tree_key_t key[5]; + guint32 bus_id; + guint32 device_address; + guint32 k_bus_id; + guint32 k_device_address; + guint32 k_frame_number; + gint32 block_number = -1; + usb_conv_info_t *usb_conv_info = (usb_conv_info_t *)data; + + if (!usb_conv_info) return offset; + + bus_id = usb_conv_info->bus_id; + device_address = usb_conv_info->device_address; + + k_bus_id = bus_id; + k_device_address = device_address; + k_frame_number = pinfo->fd->num; + + key[0].length = 1; + key[0].key = &k_bus_id; + key[1].length = 1; + key[1].key = &k_device_address; + + main_item = proto_tree_add_item(tree, proto_usb_dfu, tvb, offset, -1, ENC_NA); + main_tree = proto_item_add_subtree(main_item, ett_usb_dfu); + + col_set_str(pinfo->cinfo, COL_PROTOCOL, "USB DFU"); + + p2p_dir_save = pinfo->p2p_dir; + pinfo->p2p_dir = (usb_conv_info->is_request) ? P2P_DIR_SENT : P2P_DIR_RECV; + + switch (pinfo->p2p_dir) { + + case P2P_DIR_SENT: + col_set_str(pinfo->cinfo, COL_INFO, "Sent "); + break; + + case P2P_DIR_RECV: + col_set_str(pinfo->cinfo, COL_INFO, "Rcvd "); + break; + + default: + col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction "); + break; + } + + if (usb_conv_info->is_setup) { + guint16 interface; + + command_item = proto_tree_add_item(main_tree, hf_setup_command, tvb, offset, 1, ENC_NA); + command = tvb_get_guint8(tvb, offset); + + if (!((usb_conv_info->setup_requesttype == 0x21 && (command == 0x00 || command == 0x01 || command == 0x04 || command == 0x06)) || + (usb_conv_info->setup_requesttype == 0xa1 && (command == 0x02 || command == 0x03 || command == 0x05)))) + expert_add_info(pinfo, command_item, &ei_invalid_command_for_request_type); + offset += 1; + + col_append_fstr(pinfo->cinfo, COL_INFO, "Command: %s", + val_to_str_ext_const(command, &command_vals_ext, "Unknown")); + + if (command == 0x00) { /* Detach */ + proto_tree_add_item(main_tree, hf_setup_timeout, tvb, offset, 2, ENC_LITTLE_ENDIAN); + col_append_fstr(pinfo->cinfo, COL_INFO, " Timeout=%u", tvb_get_letohs(tvb, offset)); + } else if (command == 0x01 || command == 0x02) { /* Download || Upload */ + proto_tree_add_item(main_tree, hf_setup_block_number, tvb, offset, 2, ENC_LITTLE_ENDIAN); + col_append_fstr(pinfo->cinfo, COL_INFO, " Block Number=%u", tvb_get_letohs(tvb, offset)); + block_number = tvb_get_letohs(tvb, offset); + } else { + proto_tree_add_item(main_tree, hf_setup_unused, tvb, offset, 2, ENC_LITTLE_ENDIAN); + } + offset += 2; + + proto_tree_add_item(main_tree, hf_setup_interface, tvb, offset, 2, ENC_LITTLE_ENDIAN); + interface = tvb_get_letohs(tvb, offset); + offset += 2; + + proto_tree_add_item(main_tree, hf_setup_length, tvb, offset, 2, ENC_LITTLE_ENDIAN); + offset += 2; + + if (command == 0x01) { /* Download */ + proto_tree_add_item(main_tree, hf_data, tvb, offset, -1, ENC_NA); + offset = tvb_length(tvb); + } + + if (tvb_length_remaining(tvb, offset) > 0) { + proto_tree_add_expert(main_tree, pinfo, &ei_unexpected_data, tvb, offset, tvb_length_remaining(tvb, offset)); + offset = tvb_length(tvb); + } + + /* Save request info (command_data) */ + if (!pinfo->fd->flags.visited && command != 21) { + key[2].length = 1; + key[2].key = &k_frame_number; + key[3].length = 0; + key[3].key = NULL; + + command_data = wmem_new(wmem_file_scope(), command_data_t); + command_data->bus_id = bus_id; + command_data->device_address = device_address; + + command_data->command = command; + command_data->interface = interface; + command_data->command_frame_number = pinfo->fd->num; + command_data->block_number = block_number; + + wmem_tree_insert32_array(command_info, key, command_data); + } + + pinfo->p2p_dir = p2p_dir_save; + + return offset; + } + + /* Get request info (command_data) */ + key[2].length = 0; + key[2].key = NULL; + + wmem_tree = (wmem_tree_t *) wmem_tree_lookup32_array(command_info, key); + if (wmem_tree) { + command_data = (command_data_t *) wmem_tree_lookup32_le(wmem_tree, pinfo->fd->num); + if (command_data) { + command_response = command_data->command; + block_number = command_data->block_number; + } + } + + if (!command_data) { + col_append_str(pinfo->cinfo, COL_INFO, "Response: Unknown"); + + proto_tree_add_expert(main_tree, pinfo, &ei_unknown_data, tvb, offset, tvb_length_remaining(tvb, offset)); + + pinfo->p2p_dir = p2p_dir_save; + + return tvb_length(tvb); + } + + col_append_fstr(pinfo->cinfo, COL_INFO, "Response: %s", + val_to_str_ext_const(command_response, &command_vals_ext, "Unknown")); + + command_item = proto_tree_add_uint(main_tree, hf_response, tvb, offset, 0, command_response); + command_tree = proto_item_add_subtree(command_item, ett_command); + PROTO_ITEM_SET_GENERATED(command_item); + + if (command_data) { + command_item = proto_tree_add_uint(main_tree, hf_setup_interface, tvb, offset, 0, command_data->interface); + PROTO_ITEM_SET_GENERATED(command_item); + + command_item = proto_tree_add_uint(main_tree, hf_command_in_frame, tvb, offset, 0, command_data->command_frame_number); + PROTO_ITEM_SET_GENERATED(command_item); + } + + switch (command_response) { + case 0x02: /* Upload */ + if (block_number != -1) { + sub_item = proto_tree_add_uint(main_tree, hf_setup_block_number, tvb, offset, 0, block_number); + PROTO_ITEM_SET_GENERATED(sub_item); + col_append_fstr(pinfo->cinfo, COL_INFO, " Block Number=%u", block_number); + } + + proto_tree_add_item(main_tree, hf_data, tvb, offset, -1, ENC_NA); + offset = tvb_length(tvb); + + break; + case 0x03: /* Get Status */ + col_append_fstr(pinfo->cinfo, COL_INFO, " = Status: %s, PollTimeout: %u ms, State: %s", + val_to_str_ext_const(tvb_get_guint8(tvb, offset), &status_vals_ext, "Unknown"), + tvb_get_letoh24(tvb, offset + 1), + val_to_str_ext_const(tvb_get_guint8(tvb, offset + 4), &state_vals_ext, "Unknown")); + + proto_tree_add_item(main_tree, hf_status, tvb, offset, 1, ENC_NA); + offset += 1; + + proto_tree_add_item(main_tree, hf_poll_timeout, tvb, offset, 3, ENC_LITTLE_ENDIAN); + offset += 3; + + proto_tree_add_item(main_tree, hf_state, tvb, offset, 1, ENC_NA); + offset += 1; + + proto_tree_add_item(main_tree, hf_iString, tvb, offset, 1, ENC_NA); + offset += 1; + + break; + case 0x05: /* Get State */ + proto_tree_add_item(main_tree, hf_state, tvb, offset, 1, ENC_NA); + + col_append_fstr(pinfo->cinfo, COL_INFO, " = %s", + val_to_str_ext_const(tvb_get_guint8(tvb, offset), &state_vals_ext, "Unknown")); + + offset += 1; + + break; + case 0x00: /* Detach */ + case 0x01: /* Download */ + case 0x04: /* Clear Status */ + case 0x06: /* Abort */ + default: + proto_tree_add_expert(command_tree, pinfo, &ei_unexpected_response, tvb, offset, 0); + if (tvb_length_remaining(tvb, offset) > 0) { + proto_tree_add_expert(main_tree, pinfo, &ei_unknown_data, tvb, offset, -1); + offset = tvb_length(tvb); + } + } + + pinfo->p2p_dir = p2p_dir_save; + + return offset; +} + +void +proto_register_usb_dfu(void) +{ + module_t *module; + expert_module_t *expert_module; + + static hf_register_info hf[] = { + + { &hf_setup_command, + { "Command", "usbdfu.command", + FT_UINT8, BASE_DEC | BASE_EXT_STRING, &command_vals_ext, 0x0, + NULL, HFILL } + }, + { &hf_response, + { "Response", "usbdfu.response", + FT_UINT8, BASE_DEC | BASE_EXT_STRING, &command_vals_ext, 0x0, + NULL, HFILL } + }, + { &hf_command_in_frame, + { "Command Frame", "usbdfu.command_frame", + FT_FRAMENUM, BASE_NONE, NULL, 0x0, + NULL, HFILL } + }, + { &hf_setup_unused, + { "Unused", "usbdfu.unused", + FT_UINT16, BASE_HEX, NULL, 0x0, + NULL, HFILL } + }, + { &hf_setup_interface, + { "Interface", "usbdfu.interface", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_setup_length, + { "Length", "usbdfu.length", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_setup_block_number, + { "Block Number", "usbdfu.block_number", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_setup_timeout, + { "Timeout", "usbdfu.timeout", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_state, + { "State", "usbdfu.state", + FT_UINT8, BASE_DEC | BASE_EXT_STRING, &state_vals_ext, 0x0, + NULL, HFILL } + }, + { &hf_status, + { "Status", "usbdfu.status", + FT_UINT8, BASE_HEX | BASE_EXT_STRING, &status_vals_ext, 0x0, + NULL, HFILL } + }, + { &hf_iString, + { "iString", "usbdfu.iString", + FT_INT8, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_poll_timeout, + { "Poll Timeout", "usbdfu.poll_timeout", + FT_UINT24, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_data, + { "Data", "usbdfu.data", + FT_NONE, BASE_NONE, NULL, 0x0, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor, + { "DFU Descriptor", "usbdfu.descriptor", + FT_NONE, BASE_NONE, NULL, 0x0, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_bmAttributes_reserved, + { "Reserved", "usbdfu.descriptor.bmAttributes.reserved", + FT_UINT8, BASE_HEX, NULL, 0xF0, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_bmAttributes_WillDetach, + { "Will Detach", "usbdfu.descriptor.bmAttributes.WillDetach", + FT_BOOLEAN, 8, NULL, 0x08, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_bmAttributes_ManifestationTolerant, + { "Manifestation Tolerant", "usbdfu.descriptor.bmAttributes.ManifestationTolerant", + FT_BOOLEAN, 8, NULL, 0x04, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_bmAttributes_CanUpload, + { "Can Upload", "usbdfu.descriptor.bmAttributes.CanUpload", + FT_BOOLEAN, 8, NULL, 0x02, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_bmAttributes_CanDownload, + { "Can Download", "usbdfu.descriptor.bmAttributes.CanDownload", + FT_BOOLEAN, 8, NULL, 0x01, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_wDetachTimeOut, + { "wDetachTimeOut", "usbdfu.descriptor.wDetachTimeOut", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_wTransferSize, + { "wTransferSize", "usbdfu.descriptor.wTransferSize", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL } + }, + { &hf_usb_dfu_descriptor_bcdDFUVersion, + { "bcdDFUVersion", "usbdfu.descriptor.bcdDFUVersion", + FT_UINT16, BASE_HEX, NULL, 0x0, + NULL, HFILL } + } + }; + + static ei_register_info ei[] = { + { &ei_unexpected_response, { "usb_dfu.unexpected_response", PI_PROTOCOL, PI_ERROR, "Unexpected response for this command", EXPFILL }}, + { &ei_unknown_data, { "usb_dfu.unknown_data", PI_PROTOCOL, PI_NOTE, "Unknown data", EXPFILL }}, + { &ei_unexpected_data, { "usb_dfu.unexpected_data", PI_PROTOCOL, PI_WARN, "Unexpected data", EXPFILL }}, + { &ei_invalid_command_for_request_type, { "usb_dfu.invalid_command_for_request_type", PI_PROTOCOL, PI_WARN, "Invalid command for this Request Type", EXPFILL }}, + { &ei_descriptor_invalid_length, { "usb_dfu.descriptor.invalid_length", PI_PROTOCOL, PI_WARN, "Invalid Length", EXPFILL }}, + }; + + static gint *ett[] = { + &ett_usb_dfu, + &ett_usb_dfu_descriptor, + &ett_command + }; + + command_info = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope()); + + proto_usb_dfu = proto_register_protocol("USB Device Firmware Upgrade ", "USB DFU", "usbdfu"); + proto_register_field_array(proto_usb_dfu, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + usb_dfu_handle = new_register_dissector("usb_dfu", dissect_usb_dfu, proto_usb_dfu); + + expert_module = expert_register_protocol(proto_usb_dfu); + expert_register_field_array(expert_module, ei, array_length(ei)); + + module = prefs_register_protocol(proto_usb_dfu, NULL); + prefs_register_static_text_preference(module, "version", + "USB DFU Specification 1.1", + "Version of protocol supported by this dissector."); +} + +void +proto_reg_handoff_usb_dfu(void) +{ + dissector_handle_t usf_dfu_descriptor_handle; + + usf_dfu_descriptor_handle = new_create_dissector_handle(dissect_usb_dfu_descriptor, proto_usb_dfu); + dissector_add_uint("usb.descriptor", IF_CLASS_APPLICATION_SPECIFIC, usf_dfu_descriptor_handle); + + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x1db5, usb_dfu_handle); /* IDBG in DFU mode */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6001, usb_dfu_handle); /* Ubertooth Zero DFU */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6003, usb_dfu_handle); /* Ubertooth One DFU */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x600f, usb_dfu_handle); /* Paparazzi Lisa/M (DFU) */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6011, usb_dfu_handle); /* LeoLipo (DFU) */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6017, usb_dfu_handle); /* Black Magic Debug Probe (DFU) */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6044, usb_dfu_handle); /* Open Source USB CANBUS converter (DFU Mode) */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6064, usb_dfu_handle); /* CPC FPGA (DFU) */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6069, usb_dfu_handle); /* xser (DFU mode) */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6082, usb_dfu_handle); /* Facecandy *USB DFU loader */ + dissector_add_uint("usb.product", (0x1d50 << 16) | 0x6084, usb_dfu_handle); /* arcin arcade controller (USB DFU loader) */ + + dissector_add_handle("usb.device", usb_dfu_handle); + dissector_add_handle("usb.protocol", usb_dfu_handle); +} + +/* + * Editor modelines - http://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/epan/dissectors/packet-usb.c b/epan/dissectors/packet-usb.c index 7496e2681d..87334ac9b0 100644 --- a/epan/dissectors/packet-usb.c +++ b/epan/dissectors/packet-usb.c @@ -2446,8 +2446,8 @@ static const value_string bmrequesttype_recipient_vals[] = { }; static gint -try_dissect_next_protocol(proto_tree *parent, tvbuff_t *next_tvb, gint offset, packet_info *pinfo, - usb_conv_info_t *usb_conv_info, gint type, guint16 bus_id, guint8 device_address, +try_dissect_next_protocol(proto_tree *tree, proto_tree *parent, tvbuff_t *next_tvb, gint offset, packet_info *pinfo, + usb_conv_info_t *usb_conv_info, gint type, gint type_2, guint8 urb_type, guint16 bus_id, guint8 device_address, device_product_data_t *device_product_data, device_protocol_data_t *device_protocol_data) { wmem_tree_key_t key[4]; @@ -2498,9 +2498,59 @@ try_dissect_next_protocol(proto_tree *parent, tvbuff_t *next_tvb, gint offset, p heur_subdissector_list = heur_interrupt_subdissector_list; usb_dissector_table = usb_interrupt_dissector_table; break; - case URB_CONTROL: + case URB_CONTROL: { + usb_trans_info_t *usb_trans_info = usb_conv_info->usb_trans_info; + gboolean is_request = usb_conv_info->is_request; + heur_subdissector_list = heur_control_subdissector_list; usb_dissector_table = usb_control_dissector_table; + + /* Make sure we have the proper conversation */ + if (usb_trans_info && ((is_request && usb_conv_info->is_setup && type_2 == RQT_SETUP_TYPE_CLASS) || + (!is_request && USB_TYPE(usb_trans_info->setup.requesttype) == RQT_SETUP_TYPE_CLASS))) { + usb_tap_data_t *tap_data; + proto_item *sub_item; + + if (USB_RECIPIENT(usb_trans_info->setup.requesttype) == RQT_SETUP_RECIPIENT_INTERFACE) { + guint8 interface_num = usb_trans_info->setup.wIndex & 0xff; + + usb_conv_info = get_usb_iface_conv_info(pinfo, interface_num); + usb_conv_info->usb_trans_info = usb_trans_info; + } else if (USB_RECIPIENT(usb_trans_info->setup.requesttype) == RQT_SETUP_RECIPIENT_ENDPOINT) { + static address endpoint_addr; + gint endpoint; + static usb_address_t src_addr, dst_addr; /* has to be static due to SET_ADDRESS */ + guint32 src_endpoint, dst_endpoint; + conversation_t *conversation; + + endpoint = usb_trans_info->setup.wIndex & 0x0f; + + if (is_request) { + dst_addr.endpoint = dst_endpoint = GUINT32_TO_LE(endpoint); + SET_ADDRESS(&endpoint_addr, AT_USB, USB_ADDR_LEN, (char *)&dst_addr); + + conversation = get_usb_conversation(pinfo, &pinfo->src, &endpoint_addr, pinfo->srcport, dst_endpoint); + } else { + src_addr.endpoint = src_endpoint = GUINT32_TO_LE(endpoint); + SET_ADDRESS(&endpoint_addr, AT_USB, USB_ADDR_LEN, (char *)&src_addr); + + conversation = get_usb_conversation(pinfo, &endpoint_addr, &pinfo->dst, src_endpoint, pinfo->destport); + } + + usb_conv_info = get_usb_conv_info(conversation); + usb_conv_info->usb_trans_info = usb_trans_info; + } + + tap_data = wmem_new(wmem_packet_scope(), usb_tap_data_t); + tap_data->urb_type = urb_type; + tap_data->transfer_type = (guint8)type; + tap_data->conv_info = usb_conv_info; + tap_data->trans_info = usb_trans_info; + tap_queue_packet(usb_tap, pinfo, tap_data); + sub_item = proto_tree_add_uint(tree, hf_usb_bInterfaceClass, next_tvb, 0, 0, usb_conv_info->interfaceClass); + PROTO_ITEM_SET_GENERATED(sub_item); + } + } break; default: heur_subdissector_list = NULL; @@ -2701,6 +2751,7 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, gint offset = 0; gint new_offset; int type, endpoint, endpoint_with_dir; + gint type_2 = 0; guint8 urb_type, usbpcap_control_stage = 0; guint8 setup_flag; guint16 hdr_len; @@ -2921,7 +2972,6 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, usb_setup_dissector dissector; proto_item *ti = NULL; proto_tree *setup_tree = NULL; - int type_2 = 0; if (is_request) { if (setup_flag == 0) { @@ -2981,33 +3031,6 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, offset += 2; } break; - - case RQT_SETUP_TYPE_CLASS: - /* Make sure we have the proper conversation */ - if (USB_RECIPIENT(usb_trans_info->setup.requesttype) == RQT_SETUP_RECIPIENT_INTERFACE) { - guint8 interface_num = usb_trans_info->setup.wIndex & 0xff; - usb_conv_info = get_usb_iface_conv_info(pinfo, interface_num); - usb_conv_info->usb_trans_info = usb_trans_info; - } else if (USB_RECIPIENT(usb_trans_info->setup.requesttype) == RQT_SETUP_RECIPIENT_ENDPOINT) { - static address endpoint_addr; - endpoint = usb_trans_info->setup.wIndex & 0x0f; - - dst_addr.endpoint = dst_endpoint = GUINT32_TO_LE(endpoint); - SET_ADDRESS(&endpoint_addr, AT_USB, USB_ADDR_LEN, (char *)&dst_addr); - - conversation = get_usb_conversation(pinfo, &pinfo->src, &endpoint_addr, pinfo->srcport, dst_endpoint); - usb_conv_info = get_usb_conv_info(conversation); - usb_conv_info->usb_trans_info = usb_trans_info; - } - - tap_data->conv_info = usb_conv_info; - tap_data->trans_info = usb_trans_info; - tap_queue_packet(usb_tap, pinfo, tap_data); - - ti = proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, 0, 0, usb_conv_info->interfaceClass); - PROTO_ITEM_SET_GENERATED(ti); - - /* NOTE: No break */ default: /* To dissector found - display generic fields */ proto_tree_add_item(setup_tree, hf_usb_request_unknown_class, tvb, offset, 1, ENC_LITTLE_ENDIAN); @@ -3056,7 +3079,7 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, next_tvb = tvb_new_subset_remaining(tvb, offset - 7); } - offset = try_dissect_next_protocol(parent, next_tvb, offset, pinfo, usb_conv_info, type, bus_id, device_address, NULL, NULL); + offset = try_dissect_next_protocol(tree, parent, next_tvb, offset, pinfo, usb_conv_info, type, type_2, urb_type, bus_id, device_address, NULL, NULL); } } else { /* this is a response */ @@ -3067,33 +3090,6 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, offset += 8; } - /* Make sure we have the proper conversation */ - if (usb_trans_info) { - if (USB_TYPE(usb_trans_info->setup.requesttype) == RQT_SETUP_TYPE_CLASS) { - if (USB_RECIPIENT(usb_trans_info->setup.requesttype) == RQT_SETUP_RECIPIENT_INTERFACE) { - guint8 interface_num = usb_trans_info->setup.wIndex & 0xff; - usb_conv_info = get_usb_iface_conv_info(pinfo, interface_num); - usb_conv_info->usb_trans_info = usb_trans_info; - } else if (USB_RECIPIENT(usb_trans_info->setup.requesttype) == RQT_SETUP_RECIPIENT_ENDPOINT) { - static address endpoint_addr; - endpoint = usb_trans_info->setup.wIndex & 0x0f; - - src_addr.endpoint = src_endpoint = GUINT32_TO_LE(endpoint); - SET_ADDRESS(&endpoint_addr, AT_USB, USB_ADDR_LEN, (char *)&src_addr); - - conversation = get_usb_conversation(pinfo, &endpoint_addr, &pinfo->dst, src_endpoint, pinfo->destport); - usb_conv_info = get_usb_conv_info(conversation); - usb_conv_info->usb_trans_info = usb_trans_info; - } - } - } - - tap_data->conv_info = usb_conv_info; - tap_data->trans_info = usb_trans_info; - tap_queue_packet(usb_tap, pinfo, tap_data); - ti = proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, 0, 0, usb_conv_info->interfaceClass); - PROTO_ITEM_SET_GENERATED(ti); - /* * If this has a 64-byte header, process the extra 16 bytes of * pseudo-header information. @@ -3149,7 +3145,7 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, /* Try to find a non-standard specific dissector */ if (tvb_reported_length_remaining(tvb, offset) != 0) { next_tvb = tvb_new_subset_remaining(tvb, offset); - new_offset = try_dissect_next_protocol(parent, next_tvb, offset, pinfo, usb_conv_info, type, bus_id, device_address, NULL, NULL); + new_offset = try_dissect_next_protocol(tree, parent, next_tvb, offset, pinfo, usb_conv_info, type, type_2, urb_type, bus_id, device_address, NULL, NULL); if (new_offset > offset) offset = new_offset; } @@ -3188,7 +3184,6 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, if (setup_flag == 0) { proto_item *ti; proto_tree *setup_tree; - int type_2; /* Dissect the setup header - it's applicable */ @@ -3380,7 +3375,6 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, if (setup_flag == 0) { proto_item *ti; proto_tree *setup_tree; - int type_2; /* Dissect the setup header - it's applicable */ @@ -3455,7 +3449,7 @@ dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, if (tvb_length_remaining(tvb, offset) > 0) { next_tvb = tvb_new_subset_remaining(tvb, offset); - offset = try_dissect_next_protocol(parent, next_tvb, offset, pinfo, usb_conv_info, type, bus_id, device_address, device_product_data, device_protocol_data); + offset = try_dissect_next_protocol(tree, parent, next_tvb, offset, pinfo, usb_conv_info, type, type_2, urb_type, bus_id, device_address, device_product_data, device_protocol_data); } if (tvb_length_remaining(tvb, offset) > 0) { |