2006-10-18 09:10:14 +00:00
|
|
|
/* packet-usb.h
|
|
|
|
*
|
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2006-10-18 09:10:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __PACKET_USB_H__
|
|
|
|
#define __PACKET_USB_H__
|
|
|
|
|
2013-09-02 14:31:22 +00:00
|
|
|
#include <epan/value_string.h>
|
2013-07-31 01:06:50 +00:00
|
|
|
#include <epan/wmem/wmem.h>
|
2014-06-03 23:22:43 +00:00
|
|
|
#include <epan/conversation.h>
|
2013-07-31 01:06:50 +00:00
|
|
|
|
2007-01-08 14:32:10 +00:00
|
|
|
typedef struct _usb_address_t {
|
|
|
|
guint32 device;
|
|
|
|
guint32 endpoint;
|
2014-07-03 21:05:24 +00:00
|
|
|
guint16 bus_id;
|
2007-01-08 14:32:10 +00:00
|
|
|
} usb_address_t;
|
2007-03-25 11:15:09 +00:00
|
|
|
#define USB_ADDR_LEN (sizeof(usb_address_t))
|
2007-01-08 14:32:10 +00:00
|
|
|
|
2012-03-21 08:40:19 +00:00
|
|
|
/* Flag used to mark usb_address_t.endpoint as an interface
|
|
|
|
* address instead of the normal endpoint address.
|
|
|
|
*/
|
|
|
|
#define INTERFACE_PORT 0x80000000
|
|
|
|
|
2007-01-08 14:32:10 +00:00
|
|
|
|
2006-10-22 11:49:23 +00:00
|
|
|
typedef struct _usb_conv_info_t usb_conv_info_t;
|
2006-10-18 09:10:14 +00:00
|
|
|
|
2014-03-25 21:51:05 +00:00
|
|
|
/* header flags */
|
|
|
|
#define USB_HEADER_IS_LINUX (1 << 0)
|
|
|
|
#define USB_HEADER_IS_64_BYTES (1 << 1)
|
|
|
|
#define USB_HEADER_IS_USBPCAP (1 << 2)
|
2014-08-25 22:02:10 +00:00
|
|
|
#define USB_HEADER_IS_MAUSB (1 << 3)
|
2014-03-25 21:51:05 +00:00
|
|
|
|
2006-10-18 09:10:14 +00:00
|
|
|
/* there is one such structure for each request/response */
|
|
|
|
typedef struct _usb_trans_info_t {
|
|
|
|
guint32 request_in;
|
|
|
|
guint32 response_in;
|
2007-03-25 05:20:56 +00:00
|
|
|
nstime_t req_time;
|
2014-03-25 21:51:05 +00:00
|
|
|
guint8 header_info;
|
2012-03-21 08:40:19 +00:00
|
|
|
|
|
|
|
/* Valid only for SETUP transactions */
|
|
|
|
struct _usb_setup {
|
|
|
|
guint8 requesttype;
|
|
|
|
guint8 request;
|
|
|
|
guint16 wValue;
|
|
|
|
guint16 wIndex;
|
2013-02-15 17:32:34 +00:00
|
|
|
guint16 wLength;
|
2012-03-21 08:40:19 +00:00
|
|
|
} setup;
|
|
|
|
|
|
|
|
/* Valid only during GET DESCRIPTOR transactions */
|
2006-10-18 09:10:14 +00:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
guint8 type;
|
|
|
|
guint8 index;
|
|
|
|
} get_descriptor;
|
2006-11-07 08:33:24 +00:00
|
|
|
} u;
|
2006-10-18 09:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* used to pass the interface class from the
|
|
|
|
* interface descriptor onto the endpoint
|
|
|
|
* descriptors so that we can create a
|
|
|
|
* conversation with the appropriate class
|
|
|
|
* once we know the endpoint.
|
2012-03-21 08:40:19 +00:00
|
|
|
* Valid only during GET CONFIGURATION response.
|
2006-10-18 09:10:14 +00:00
|
|
|
*/
|
|
|
|
usb_conv_info_t *interface_info;
|
|
|
|
} usb_trans_info_t;
|
|
|
|
|
2013-10-13 19:56:52 +00:00
|
|
|
/* Conversation Structure
|
2013-03-07 23:57:43 +00:00
|
|
|
* there is one such structure for each device/endpoint conversation */
|
2006-10-22 11:49:23 +00:00
|
|
|
struct _usb_conv_info_t {
|
2013-11-12 13:46:51 +00:00
|
|
|
guint16 bus_id;
|
2014-04-08 16:11:21 +00:00
|
|
|
guint16 device_address;
|
2013-11-12 13:46:51 +00:00
|
|
|
guint8 endpoint;
|
|
|
|
gint direction;
|
2013-12-23 18:54:46 +00:00
|
|
|
guint8 transfer_type;
|
|
|
|
guint32 device_protocol;
|
|
|
|
gboolean is_request;
|
|
|
|
gboolean is_setup;
|
|
|
|
guint8 setup_requesttype;
|
2013-11-12 13:46:51 +00:00
|
|
|
|
2013-03-07 23:57:43 +00:00
|
|
|
guint16 interfaceClass; /* Interface Descriptor - class */
|
|
|
|
guint16 interfaceSubclass; /* Interface Descriptor - subclass */
|
|
|
|
guint16 interfaceProtocol; /* Interface Descriptor - protocol */
|
|
|
|
guint8 interfaceNum; /* Most recent interface number */
|
2013-11-12 13:46:51 +00:00
|
|
|
|
2013-03-07 23:57:43 +00:00
|
|
|
guint16 deviceVendor; /* Device Descriptor - USB Vendor ID */
|
|
|
|
guint32 deviceProduct; /* Device Descriptor - USB Product ID - MSBs only for encoding unknown */
|
2013-07-31 01:06:50 +00:00
|
|
|
wmem_tree_t *transactions;
|
2006-10-22 11:49:23 +00:00
|
|
|
usb_trans_info_t *usb_trans_info; /* pointer to the current transaction */
|
2013-11-12 13:46:51 +00:00
|
|
|
|
2007-03-25 22:53:35 +00:00
|
|
|
void *class_data; /* private class/id decode data */
|
2006-10-22 11:49:23 +00:00
|
|
|
};
|
|
|
|
|
2007-03-25 09:55:49 +00:00
|
|
|
/* This is what a tap will tap */
|
|
|
|
typedef struct _usb_tap_data_t {
|
|
|
|
guint8 urb_type;
|
|
|
|
guint8 transfer_type;
|
|
|
|
usb_conv_info_t *conv_info;
|
|
|
|
usb_trans_info_t *trans_info;
|
|
|
|
} usb_tap_data_t;
|
2006-10-18 11:24:03 +00:00
|
|
|
|
2012-11-29 13:59:36 +00:00
|
|
|
|
2014-08-20 11:49:51 +00:00
|
|
|
/* the value for "no endpoint" that's used usb_addr_t, e.g. for the address of the host */
|
|
|
|
#define NO_ENDPOINT 0xffffffff
|
|
|
|
/* the 8bit version of NO_ENDPOINT, it's used in usb_conv_info_t
|
|
|
|
0xff would be an invalid endpoint number (reserved bits are 1) */
|
|
|
|
#define NO_ENDPOINT8 ((guint8)(NO_ENDPOINT& G_MAXUINT8))
|
2006-10-18 11:24:03 +00:00
|
|
|
|
2010-05-16 03:19:40 +00:00
|
|
|
/*
|
|
|
|
* Values from the Linux USB pseudo-header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* event_type values
|
|
|
|
*/
|
|
|
|
#define URB_SUBMIT 'S'
|
|
|
|
#define URB_COMPLETE 'C'
|
|
|
|
#define URB_ERROR 'E'
|
|
|
|
|
|
|
|
/*
|
2014-07-31 07:59:29 +00:00
|
|
|
* URB transfer_type values
|
2010-05-16 03:19:40 +00:00
|
|
|
*/
|
|
|
|
#define URB_ISOCHRONOUS 0x0
|
|
|
|
#define URB_INTERRUPT 0x1
|
|
|
|
#define URB_CONTROL 0x2
|
|
|
|
#define URB_BULK 0x3
|
2014-08-19 19:33:18 +00:00
|
|
|
#define URB_UNKNOWN 0xFF
|
2010-05-16 03:19:40 +00:00
|
|
|
|
|
|
|
#define URB_TRANSFER_IN 0x80 /* to host */
|
2006-10-18 11:24:03 +00:00
|
|
|
|
2012-11-29 13:29:50 +00:00
|
|
|
|
|
|
|
/* http://www.usb.org/developers/defined_class */
|
|
|
|
#define IF_CLASS_DEVICE 0x00
|
|
|
|
#define IF_CLASS_AUDIO 0x01
|
|
|
|
#define IF_CLASS_COMMUNICATIONS 0x02
|
|
|
|
#define IF_CLASS_HID 0x03
|
|
|
|
#define IF_CLASS_PHYSICAL 0x05
|
|
|
|
#define IF_CLASS_IMAGE 0x06
|
|
|
|
#define IF_CLASS_PRINTER 0x07
|
|
|
|
#define IF_CLASS_MASS_STORAGE 0x08
|
|
|
|
#define IF_CLASS_HUB 0x09
|
|
|
|
#define IF_CLASS_CDC_DATA 0x0a
|
|
|
|
#define IF_CLASS_SMART_CARD 0x0b
|
|
|
|
#define IF_CLASS_CONTENT_SECURITY 0x0d
|
|
|
|
#define IF_CLASS_VIDEO 0x0e
|
|
|
|
#define IF_CLASS_PERSONAL_HEALTHCARE 0x0f
|
|
|
|
#define IF_CLASS_AUDIO_VIDEO 0x10
|
|
|
|
#define IF_CLASS_DIAGNOSTIC_DEVICE 0xdc
|
|
|
|
#define IF_CLASS_WIRELESS_CONTROLLER 0xe0
|
|
|
|
#define IF_CLASS_MISCELLANEOUS 0xef
|
|
|
|
#define IF_CLASS_APPLICATION_SPECIFIC 0xfe
|
|
|
|
#define IF_CLASS_VENDOR_SPECIFIC 0xff
|
|
|
|
|
|
|
|
#define IF_CLASS_UNKNOWN 0xffff
|
|
|
|
#define IF_SUBCLASS_UNKNOWN 0xffff
|
2013-03-07 23:57:43 +00:00
|
|
|
#define IF_PROTOCOL_UNKNOWN 0xffff
|
|
|
|
#define DEV_VENDOR_UNKNOWN 0x0000 /* this id is unassigned */
|
|
|
|
#define DEV_PRODUCT_UNKNOWN 0xfffffff /* 0x0000 and 0xffff are used values by vendors, so MSBs encode unknown */
|
2009-10-29 21:32:21 +00:00
|
|
|
|
|
|
|
/* bmRequestType values */
|
|
|
|
#define USB_DIR_OUT 0 /* to device */
|
|
|
|
#define USB_DIR_IN 0x80 /* to host */
|
|
|
|
|
|
|
|
#define USB_TYPE_MASK (0x03 << 5)
|
2010-04-21 20:51:22 +00:00
|
|
|
#define USB_TYPE(type) (((type) & USB_TYPE_MASK) >> 5)
|
2009-10-29 21:32:21 +00:00
|
|
|
#define RQT_SETUP_TYPE_STANDARD 0
|
|
|
|
#define RQT_SETUP_TYPE_CLASS 1
|
|
|
|
#define RQT_SETUP_TYPE_VENDOR 2
|
|
|
|
|
2012-03-21 08:40:19 +00:00
|
|
|
#define USB_RECIPIENT_MASK 0x1F
|
|
|
|
#define USB_RECIPIENT(type) ((type) & USB_RECIPIENT_MASK)
|
2009-10-29 21:32:21 +00:00
|
|
|
#define RQT_SETUP_RECIPIENT_DEVICE 0
|
|
|
|
#define RQT_SETUP_RECIPIENT_INTERFACE 1
|
|
|
|
#define RQT_SETUP_RECIPIENT_ENDPOINT 2
|
|
|
|
#define RQT_SETUP_RECIPIENT_OTHER 3
|
|
|
|
|
2012-04-27 08:44:36 +00:00
|
|
|
/* Endpoint descriptor bmAttributes */
|
|
|
|
#define ENDPOINT_TYPE(ep_attrib) ((ep_attrib) & 0x03)
|
|
|
|
#define ENDPOINT_TYPE_CONTROL 0
|
|
|
|
#define ENDPOINT_TYPE_ISOCHRONOUS 1
|
|
|
|
#define ENDPOINT_TYPE_BULK 2
|
|
|
|
#define ENDPOINT_TYPE_INTERRUPT 3
|
|
|
|
|
2014-09-15 21:26:05 +00:00
|
|
|
/* 9.6.6 */
|
|
|
|
extern const true_false_string tfs_endpoint_direction;
|
|
|
|
|
2014-06-06 00:01:46 +00:00
|
|
|
usb_conv_info_t *
|
|
|
|
get_usb_conv_info(conversation_t *conversation);
|
|
|
|
|
2014-06-03 23:22:43 +00:00
|
|
|
conversation_t *
|
|
|
|
get_usb_conversation(packet_info *pinfo,
|
|
|
|
address *src_addr, address *dst_addr,
|
|
|
|
guint32 src_endpoint, guint32 dst_endpoint);
|
|
|
|
|
2013-03-01 22:57:13 +00:00
|
|
|
usb_conv_info_t *get_usb_iface_conv_info(packet_info *pinfo, guint8 interface_num);
|
|
|
|
|
2013-12-14 03:44:12 +00:00
|
|
|
proto_item * dissect_usb_descriptor_header(proto_tree *tree,
|
|
|
|
tvbuff_t *tvb, int offset,
|
|
|
|
value_string_ext *type_val_str);
|
2012-03-10 16:09:28 +00:00
|
|
|
void dissect_usb_endpoint_address(proto_tree *tree, tvbuff_t *tvb, int offset);
|
|
|
|
|
2014-02-06 00:03:15 +00:00
|
|
|
int
|
|
|
|
dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
|
|
|
|
tvbuff_t *tvb, int offset,
|
2014-08-20 12:32:40 +00:00
|
|
|
usb_conv_info_t *usb_conv_info);
|
2014-02-06 00:03:15 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
|
|
|
|
tvbuff_t *tvb, int offset,
|
|
|
|
usb_conv_info_t *usb_conv_info _U_);
|
2014-06-03 23:22:43 +00:00
|
|
|
|
2014-07-07 18:38:45 +00:00
|
|
|
int
|
|
|
|
dissect_usb_setup_response(packet_info *pinfo, proto_tree *tree,
|
2014-11-08 11:12:36 +00:00
|
|
|
tvbuff_t *tvb, int offset,
|
2014-07-07 18:38:45 +00:00
|
|
|
guint8 urb_type, usb_conv_info_t *usb_conv_info);
|
|
|
|
|
2014-06-06 00:01:46 +00:00
|
|
|
int
|
2014-08-25 22:02:10 +00:00
|
|
|
dissect_usb_setup_request(packet_info *pinfo, proto_tree *tree,
|
2014-11-08 10:58:33 +00:00
|
|
|
tvbuff_t *tvb, int offset,
|
2014-08-25 22:02:10 +00:00
|
|
|
guint8 urb_type, usb_conv_info_t *usb_conv_info,
|
|
|
|
guint8 header_info);
|
2014-06-06 00:01:46 +00:00
|
|
|
|
2014-07-07 18:38:45 +00:00
|
|
|
|
2014-06-03 23:22:43 +00:00
|
|
|
void
|
2014-12-17 15:12:41 +00:00
|
|
|
usb_set_addr(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, guint16 bus_id, guint16 device_address,
|
2014-07-03 21:05:24 +00:00
|
|
|
int endpoint, gboolean req);
|
2014-06-03 23:22:43 +00:00
|
|
|
|
2014-06-06 00:01:46 +00:00
|
|
|
usb_trans_info_t
|
|
|
|
*usb_get_trans_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
|
|
|
|
guint8 header_info, usb_conv_info_t *usb_conv_info);
|
|
|
|
|
|
|
|
|
2006-10-18 09:10:14 +00:00
|
|
|
#endif
|