Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
packet-usb.h
1 /* packet-usb.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef __PACKET_USB_H__
11 #define __PACKET_USB_H__
12 
13 #include <epan/value_string.h>
14 #include <epan/wmem/wmem.h>
15 #include <epan/conversation.h>
16 
17 typedef struct _usb_address_t {
18  guint32 device;
19  guint32 endpoint;
20  guint16 bus_id;
22 #define USB_ADDR_LEN (sizeof(usb_address_t))
23 
24 /* Flag used to mark usb_address_t.endpoint as an interface
25  * address instead of the normal endpoint address.
26  */
27 #define INTERFACE_PORT 0x80000000
28 
29 
30 typedef struct _usb_conv_info_t usb_conv_info_t;
31 
32 /* header type */
33 typedef enum {
34  USB_HEADER_LINUX_48_BYTES,
35  USB_HEADER_LINUX_64_BYTES,
36  USB_HEADER_USBPCAP,
37  USB_HEADER_MAUSB,
38  USB_HEADER_USBIP,
39  USB_HEADER_DARWIN
40 } usb_header_t;
41 
42 #define USB_HEADER_IS_LINUX(type) \
43  ((type) == USB_HEADER_LINUX_48_BYTES || (type) == USB_HEADER_LINUX_64_BYTES)
44 
45 /* there is one such structure for each request/response */
46 typedef struct _usb_trans_info_t {
47  guint32 request_in;
48  guint32 response_in;
49  nstime_t req_time;
50  usb_header_t header_type;
51 
52  /* Valid only for SETUP transactions */
53  struct _usb_setup {
54  guint8 requesttype;
55  guint8 request;
56  guint16 wValue;
57  guint16 wIndex;
58  guint16 wLength;
59  } setup;
60 
61  /* Valid only during GET DESCRIPTOR transactions */
62  union {
63  struct {
64  guint8 type;
65  guint8 usb_index;
66  } get_descriptor;
67  } u;
68 
69 
70  /* used to pass the interface class from the
71  * interface descriptor onto the endpoint
72  * descriptors so that we can create a
73  * conversation with the appropriate class
74  * once we know the endpoint.
75  * Valid only during GET CONFIGURATION response.
76  */
77  usb_conv_info_t *interface_info;
78 
79  guint64 usb_id;
81 
82 enum usb_conv_class_data_type {USB_CONV_UNKNOWN = 0, USB_CONV_U3V, USB_CONV_AUDIO, USB_CONV_VIDEO, USB_CONV_MASS_STORAGE};
83 
84 /* Conversation Structure
85  * there is one such structure for each device/endpoint conversation */
87  guint16 bus_id;
88  guint16 device_address;
89  guint8 endpoint;
90  gint direction;
91  guint8 transfer_type;
92  guint32 device_protocol;
93  gboolean is_request;
94  gboolean is_setup;
95  guint8 setup_requesttype;
96 
97  guint16 interfaceClass; /* Interface Descriptor - class */
98  guint16 interfaceSubclass; /* Interface Descriptor - subclass */
99  guint16 interfaceProtocol; /* Interface Descriptor - protocol */
100  guint8 interfaceNum; /* Most recent interface number */
101 
102  guint16 deviceVendor; /* Device Descriptor - USB Vendor ID */
103  guint32 deviceProduct; /* Device Descriptor - USB Product ID - MSBs only for encoding unknown */
104  wmem_tree_t *transactions;
105  usb_trans_info_t *usb_trans_info; /* pointer to the current transaction */
106 
107  void *class_data; /* private class/id decode data */
108  enum usb_conv_class_data_type class_data_type;
109 
110  wmem_array_t *alt_settings;
111 };
112 
113 /* This is what a tap will tap */
114 typedef struct _usb_tap_data_t {
115  guint8 urb_type;
116  guint8 transfer_type;
117  usb_conv_info_t *conv_info;
118  usb_trans_info_t *trans_info;
120 
121 
122 /* the value for "no endpoint" that's used usb_addr_t, e.g. for the address of the host */
123 #define NO_ENDPOINT 0xffffffff
124 /* the 8bit version of NO_ENDPOINT, it's used in usb_conv_info_t
125  0xff would be an invalid endpoint number (reserved bits are 1) */
126 #define NO_ENDPOINT8 ((guint8)(NO_ENDPOINT& G_MAXUINT8))
127 
128 /*
129  * Values from the Linux USB pseudo-header.
130  */
131 
132 /*
133  * event_type values
134  */
135 #define URB_SUBMIT 'S'
136 #define URB_COMPLETE 'C'
137 #define URB_ERROR 'E'
138 
139 /*
140  * URB transfer_type values
141  */
142 #define URB_ISOCHRONOUS 0x0
143 #define URB_INTERRUPT 0x1
144 #define URB_CONTROL 0x2
145 #define URB_BULK 0x3
146 #define URB_UNKNOWN 0xFF
147 
148 #define URB_TRANSFER_IN 0x80 /* to host */
149 
150 
151 /* http://www.usb.org/developers/defined_class */
152 #define IF_CLASS_DEVICE 0x00
153 #define IF_CLASS_AUDIO 0x01
154 #define IF_CLASS_COMMUNICATIONS 0x02
155 #define IF_CLASS_HID 0x03
156 #define IF_CLASS_PHYSICAL 0x05
157 #define IF_CLASS_IMAGE 0x06
158 #define IF_CLASS_PRINTER 0x07
159 #define IF_CLASS_MASS_STORAGE 0x08
160 #define IF_CLASS_HUB 0x09
161 #define IF_CLASS_CDC_DATA 0x0a
162 #define IF_CLASS_SMART_CARD 0x0b
163 #define IF_CLASS_CONTENT_SECURITY 0x0d
164 #define IF_CLASS_VIDEO 0x0e
165 #define IF_CLASS_PERSONAL_HEALTHCARE 0x0f
166 #define IF_CLASS_AUDIO_VIDEO 0x10
167 #define IF_CLASS_DIAGNOSTIC_DEVICE 0xdc
168 #define IF_CLASS_WIRELESS_CONTROLLER 0xe0
169 #define IF_CLASS_MISCELLANEOUS 0xef
170 #define IF_CLASS_APPLICATION_SPECIFIC 0xfe
171 #define IF_CLASS_VENDOR_SPECIFIC 0xff
172 
173 #define IF_CLASS_UNKNOWN 0xffff
174 #define IF_SUBCLASS_UNKNOWN 0xffff
175 #define IF_PROTOCOL_UNKNOWN 0xffff
176 #define DEV_VENDOR_UNKNOWN 0x0000 /* this id is unassigned */
177 #define DEV_PRODUCT_UNKNOWN 0xfffffff /* 0x0000 and 0xffff are used values by vendors, so MSBs encode unknown */
178 
179 #define IF_SUBCLASS_MISC_U3V 0x05
180 
181 /* bmRequestType values */
182 #define USB_DIR_OUT 0 /* to device */
183 #define USB_DIR_IN 0x80 /* to host */
184 
185 #define USB_TYPE_MASK (0x03 << 5)
186 #define USB_TYPE(type) (((type) & USB_TYPE_MASK) >> 5)
187 #define RQT_SETUP_TYPE_STANDARD 0
188 #define RQT_SETUP_TYPE_CLASS 1
189 #define RQT_SETUP_TYPE_VENDOR 2
190 
191 #define USB_RECIPIENT_MASK 0x1F
192 #define USB_RECIPIENT(type) ((type) & USB_RECIPIENT_MASK)
193 #define RQT_SETUP_RECIPIENT_DEVICE 0
194 #define RQT_SETUP_RECIPIENT_INTERFACE 1
195 #define RQT_SETUP_RECIPIENT_ENDPOINT 2
196 #define RQT_SETUP_RECIPIENT_OTHER 3
197 
198 /* Endpoint descriptor bmAttributes */
199 #define ENDPOINT_TYPE(ep_attrib) ((ep_attrib) & 0x03)
200 #define ENDPOINT_TYPE_CONTROL 0
201 #define ENDPOINT_TYPE_ISOCHRONOUS 1
202 #define ENDPOINT_TYPE_BULK 2
203 #define ENDPOINT_TYPE_INTERRUPT 3
204 
205 
206 #define USB_SETUP_GET_STATUS 0
207 #define USB_SETUP_CLEAR_FEATURE 1
208 #define USB_SETUP_SET_FEATURE 3
209 #define USB_SETUP_SET_ADDRESS 5
210 #define USB_SETUP_GET_DESCRIPTOR 6
211 #define USB_SETUP_SET_DESCRIPTOR 7
212 #define USB_SETUP_GET_CONFIGURATION 8
213 #define USB_SETUP_SET_CONFIGURATION 9
214 #define USB_SETUP_GET_INTERFACE 10
215 #define USB_SETUP_SET_INTERFACE 11
216 #define USB_SETUP_SYNCH_FRAME 12
217 #define USB_SETUP_SET_SEL 48
218 #define USB_SETUP_SET_ISOCH_DELAY 49
219 
220 
221 /* 9.6.6 */
222 extern const true_false_string tfs_endpoint_direction;
223 
224 extern value_string_ext usb_class_vals_ext;
225 
226 usb_conv_info_t *get_usb_iface_conv_info(packet_info *pinfo, guint8 interface_num);
227 
228 proto_item * dissect_usb_descriptor_header(proto_tree *tree,
229  tvbuff_t *tvb, int offset,
230  value_string_ext *type_val_str);
231 
232 void dissect_usb_endpoint_address(proto_tree *tree, tvbuff_t *tvb, int offset);
233 
234 int
235 dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
236  tvbuff_t *tvb, int offset,
237  usb_conv_info_t *usb_conv_info);
238 
239 int
240 dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
241  tvbuff_t *tvb, int offset,
242  usb_conv_info_t *usb_conv_info _U_);
243 
244 struct mausb_header;
245 
246 void
247 dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent,
248  usb_header_t header_type, void *extra_data);
249 
250 #endif
251 
252 /*
253  * Editor modelines - http://www.wireshark.org/tools/modelines.html
254  *
255  * Local variables:
256  * c-basic-offset: 4
257  * tab-width: 8
258  * indent-tabs-mode: nil
259  * End:
260  *
261  * vi: set shiftwidth=4 tabstop=8 expandtab:
262  * :indentSize=4:tabSize=8:noTabs=true:
263  */
Definition: tfs.h:26
Definition: wmem_tree-int.h:47
Definition: packet_info.h:44
Definition: packet-usb.h:17
Definition: wmem_array.c:27
Definition: packet-usb.h:53
Definition: packet-usb.h:46
Definition: tvbuff-int.h:35
Definition: nstime.h:27
Definition: packet-mausb.h:18
Definition: packet-usb.h:114
Definition: conversation.c:27
Definition: packet-usb.h:86
Definition: value_string.h:164
Definition: proto.h:759