Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
packet-usb.h
1/* packet-usb.h
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <[email protected]>
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/packet_info.h>
14#include <epan/proto.h>
15#include <epan/tvbuff.h>
16#include <wsutil/value_string.h>
17#include <epan/tfs.h>
18#include <wsutil/nstime.h>
19
20typedef struct _usb_address_t {
21 uint32_t device;
22 uint32_t endpoint;
23 uint16_t bus_id;
24} usb_address_t;
25#define USB_ADDR_LEN (sizeof(usb_address_t))
26
27/* Flag used to mark usb_address_t.endpoint as an interface
28 * address instead of the normal endpoint address.
29 */
30#define INTERFACE_PORT 0x80000000
31
32
33typedef struct _usb_conv_info_t usb_conv_info_t;
34typedef struct _urb_info_t urb_info_t;
35
36/* Wireshark specific (i.e. numeric values are arbitrary) enum representing
37 * USB device speed.
38 */
39typedef enum {
40 USB_SPEED_UNKNOWN, /* Unknown, skip speed specific processing */
41 USB_SPEED_LOW,
42 USB_SPEED_FULL,
43 USB_SPEED_HIGH,
44} usb_speed_t;
45
46/* header type */
47typedef enum {
48 USB_HEADER_LINUX_48_BYTES,
49 USB_HEADER_LINUX_64_BYTES,
50 USB_HEADER_USBPCAP,
51 USB_HEADER_MAUSB,
52 USB_HEADER_USBIP,
53 USB_HEADER_DARWIN,
54 USB_HEADER_PSEUDO_URB,
55 USB_HEADER_FREEBSD,
56} usb_header_t;
57
58#define USB_HEADER_IS_LINUX(type) \
59 ((type) == USB_HEADER_LINUX_48_BYTES || (type) == USB_HEADER_LINUX_64_BYTES)
60
61typedef struct _usb_pseudo_urb_t {
62 bool from_host;
63 uint8_t transfer_type;
64 uint8_t device_address;
65 uint8_t endpoint;
66 uint16_t bus_id;
67 usb_speed_t speed;
68} usb_pseudo_urb_t;
69
70/* there is one such structure for each request/response */
71typedef struct _usb_trans_info_t {
72 uint32_t request_in;
73 uint32_t response_in;
74 nstime_t req_time;
75 usb_header_t header_type;
76
77 /* Valid only for SETUP transactions */
78 struct _usb_setup {
79 uint8_t requesttype;
80 uint8_t request;
81 uint16_t wValue;
82 uint16_t wIndex;
83 uint16_t wLength;
84 } setup;
85
86 /* Valid only during GET DESCRIPTOR transactions */
87 union {
88 struct {
89 uint8_t type;
90 uint8_t usb_index;
91 } get_descriptor;
92 } u;
93
94
95 /* used to pass the interface class from the
96 * interface descriptor onto the endpoint
97 * descriptors so that we can create a
98 * conversation with the appropriate class
99 * once we know the endpoint.
100 * Valid only during GET CONFIGURATION response.
101 */
102 uint8_t interface_endpoint;
103 usb_conv_info_t *interface_info;
104
105 uint64_t usb_id;
106} usb_trans_info_t;
107
108enum usb_conv_class_data_type {
109 USB_CONV_UNKNOWN = 0,
110 USB_CONV_U3V,
111 USB_CONV_AUDIO,
112 USB_CONV_VIDEO,
113 USB_CONV_MASS_STORAGE_BOT,
114 USB_CONV_MASS_STORAGE_UASP,
115 USB_CONV_CDC_DATA,
116 USB_CONV_PTP,
117};
118
119/* Conversation Structure
120 * there is one such structure for each device/endpoint conversation */
122 uint8_t descriptor_transfer_type; /* transfer type lifted from the configuration descriptor */
123 uint16_t max_packet_size; /* max packet size from configuration descriptor */
124
125 uint16_t interfaceClass; /* Interface Descriptor - class */
126 uint16_t interfaceSubclass; /* Interface Descriptor - subclass */
127 uint16_t interfaceProtocol; /* Interface Descriptor - protocol */
128 uint8_t interfaceNum; /* Most recent interface number */
129
130 uint16_t deviceVendor; /* Device Descriptor - USB Vendor ID */
131 uint32_t deviceProduct; /* Device Descriptor - USB Product ID - MSBs only for encoding unknown */
132 uint16_t deviceVersion; /* Device Descriptor - USB device version number BCD */
133 uint8_t iSerialNumber; /* Device Descriptor - iSerialNumber (0 if no serial number available) */
134 wmem_tree_t *transactions;
135
136 void *class_data; /* private class/id decode data */
137 enum usb_conv_class_data_type class_data_type;
138 uint32_t config_desc_frame_num; /* configuration descriptor frame number (0 = none) */
139
140 wmem_array_t *alt_settings;
141};
142
143/* URB data lifetime is limited to packet scope */
145 uint16_t bus_id;
146 uint16_t device_address;
147 uint8_t endpoint;
148 int direction;
149 uint8_t transfer_type; /* transfer type from URB */
150 uint32_t device_protocol;
151 bool is_request;
152 bool is_setup;
153 uint8_t setup_requesttype;
154 usb_speed_t speed;
155
156 usb_trans_info_t *usb_trans_info; /* pointer to the current transaction */
157
158 usb_conv_info_t *conv;
159};
160
161/* This is what a tap will tap */
162typedef struct _usb_tap_data_t {
163 uint8_t urb_type;
164 uint8_t transfer_type;
165 urb_info_t *urb;
166 usb_trans_info_t *trans_info;
167} usb_tap_data_t;
168
169
170/* the value for "no endpoint" that's used usb_addr_t, e.g. for the address of the host */
171#define NO_ENDPOINT 0xffffffff
172/* the 8bit version of NO_ENDPOINT, it's used in usb_conv_info_t
173 0xff would be an invalid endpoint number (reserved bits are 1) */
174#define NO_ENDPOINT8 ((uint8_t)(NO_ENDPOINT& UINT8_MAX))
175
176/*
177 * Values from the Linux USB pseudo-header.
178 */
179
180/*
181 * event_type values
182 */
183#define URB_SUBMIT 'S'
184#define URB_COMPLETE 'C'
185#define URB_ERROR 'E'
186
187/*
188 * URB transfer_type values
189 */
190#define URB_ISOCHRONOUS 0x0
191#define URB_INTERRUPT 0x1
192#define URB_CONTROL 0x2
193#define URB_BULK 0x3
194#define URB_UNKNOWN 0xFF
195
196#define URB_TRANSFER_IN 0x80 /* to host */
197
198
199/* http://www.usb.org/developers/defined_class */
200#define IF_CLASS_DEVICE 0x00
201#define IF_CLASS_AUDIO 0x01
202#define IF_CLASS_COMMUNICATIONS 0x02
203#define IF_CLASS_HID 0x03
204#define IF_CLASS_PHYSICAL 0x05
205#define IF_CLASS_IMAGE 0x06
206#define IF_CLASS_PRINTER 0x07
207#define IF_CLASS_MASS_STORAGE 0x08
208#define IF_CLASS_HUB 0x09
209#define IF_CLASS_CDC_DATA 0x0a
210#define IF_CLASS_SMART_CARD 0x0b
211#define IF_CLASS_CONTENT_SECURITY 0x0d
212#define IF_CLASS_VIDEO 0x0e
213#define IF_CLASS_PERSONAL_HEALTHCARE 0x0f
214#define IF_CLASS_AUDIO_VIDEO 0x10
215#define IF_CLASS_BILLBOARD 0x11
216#define IF_CLASS_USB_C_BRIDGE 0x12
217#define IF_CLASS_BULK_DISPLAY_PROTO 0x13
218#define IF_CLASS_MCTP_USB_EP 0x14
219#define IF_CLASS_I3C 0x3c
220#define IF_CLASS_DIAGNOSTIC_DEVICE 0xdc
221#define IF_CLASS_WIRELESS_CONTROLLER 0xe0
222#define IF_CLASS_MISCELLANEOUS 0xef
223#define IF_CLASS_APPLICATION_SPECIFIC 0xfe
224#define IF_CLASS_VENDOR_SPECIFIC 0xff
225
226#define IF_CLASS_UNKNOWN 0xffff
227#define IF_SUBCLASS_UNKNOWN 0xffff
228#define IF_PROTOCOL_UNKNOWN 0xffff
229#define DEV_VENDOR_UNKNOWN 0x0000 /* this id is unassigned */
230#define DEV_PRODUCT_UNKNOWN 0xfffffff /* 0x0000 and 0xffff are used values by vendors, so MSBs encode unknown */
231#define DEV_VERSION_UNKNOWN 0xffff
232
233#define IF_SUBCLASS_MISC_U3V 0x05
234
235#define IF_SUBCLASS_APP_DFU 0x01
236
237#define IF_PROTOCOL_DFU_RUNTIME 0x01
238#define IF_PROTOCOL_DFU_MODE 0x02
239
240/* Key to be used with "usb.control", "usb.bulk" and/or "usb.interrupt"
241 * dissector tables when the dissector only applies to specific triple.
242 * Use class code directly if the code is not shared with other specifications.
243 *
244 * MSB (bit 31) is arbitrarily chosen to ensure class registered dissectors
245 * won't clash with protocol key.
246 */
247#define USB_PROTOCOL_KEY(class, subclass, protocol) \
248 (1u << 31 | (class & 0xff) << 16 | (subclass & 0xff) << 8 | (protocol & 0xff))
249
250/* bmRequestType values */
251#define USB_DIR_OUT 0 /* to device */
252#define USB_DIR_IN 0x80 /* to host */
253
254#define USB_TYPE_MASK (0x03 << 5)
255#define USB_TYPE(type) (((type) & USB_TYPE_MASK) >> 5)
256#define RQT_SETUP_TYPE_STANDARD 0
257#define RQT_SETUP_TYPE_CLASS 1
258#define RQT_SETUP_TYPE_VENDOR 2
259
260#define USB_RECIPIENT_MASK 0x1F
261#define USB_RECIPIENT(type) ((type) & USB_RECIPIENT_MASK)
262#define RQT_SETUP_RECIPIENT_DEVICE 0
263#define RQT_SETUP_RECIPIENT_INTERFACE 1
264#define RQT_SETUP_RECIPIENT_ENDPOINT 2
265#define RQT_SETUP_RECIPIENT_OTHER 3
266
267/* Endpoint descriptor bmAttributes */
268#define ENDPOINT_TYPE(ep_attrib) ((ep_attrib) & 0x03)
269#define ENDPOINT_TYPE_CONTROL 0
270#define ENDPOINT_TYPE_ISOCHRONOUS 1
271#define ENDPOINT_TYPE_BULK 2
272#define ENDPOINT_TYPE_INTERRUPT 3
273#define ENDPOINT_TYPE_NOT_SET 255
274
275/* wMaxPacketSize */
276#define USB_MPS_EP_SIZE(max_packet_size) ((max_packet_size) & 0x07FF)
277#define USB_MPS_ADDNL(max_packet_size) (((max_packet_size) & 0x1800) >> 11)
278#define USB_MPS(ep_size, addnl) (((addnl) << 11) | (ep_size))
279#define USB_MPS_TPL(max_packet_size) \
280 ((USB_MPS_ADDNL(max_packet_size) + 1) * USB_MPS_EP_SIZE(max_packet_size))
281
282#define USB_SETUP_GET_STATUS 0
283#define USB_SETUP_CLEAR_FEATURE 1
284#define USB_SETUP_SET_FEATURE 3
285#define USB_SETUP_SET_ADDRESS 5
286#define USB_SETUP_GET_DESCRIPTOR 6
287#define USB_SETUP_SET_DESCRIPTOR 7
288#define USB_SETUP_GET_CONFIGURATION 8
289#define USB_SETUP_SET_CONFIGURATION 9
290#define USB_SETUP_GET_INTERFACE 10
291#define USB_SETUP_SET_INTERFACE 11
292#define USB_SETUP_SYNCH_FRAME 12
293#define USB_SETUP_SET_SEL 48
294#define USB_SETUP_SET_ISOCH_DELAY 49
295
296/* transfer_flags */
297#define URB_SHORT_NOT_OK 0x00000001 /* report short reads as errors */
298#define URB_ISO_ASAP 0x00000002 /* iso-only; use the first unexpired
299 * slot in the schedule */
300#define URB_NO_TRANSFER_DMA_MAP 0x00000004 /* urb->transfer_dma valid on submit */
301#define URB_NO_FSBR 0x00000020 /* UHCI-specific */
302#define URB_ZERO_PACKET 0x00000040 /* Finish bulk OUT with short packet */
303#define URB_NO_INTERRUPT 0x00000080 /* HINT: no non-error interrupt
304 * needed */
305#define URB_FREE_BUFFER 0x00000100 /* Free transfer buffer with the URB */
306
307/* The following flags are used internally by usbcore and HCDs */
308#define URB_DIR_IN 0x00000200 /* Transfer from device to host */
309#define URB_DIR_OUT 0
310#define URB_DIR_MASK URB_DIR_IN
311
312#define URB_DMA_MAP_SINGLE 0x00010000 /* Non-scatter-gather mapping */
313#define URB_DMA_MAP_PAGE 0x00020000 /* HCD-unsupported S-G */
314#define URB_DMA_MAP_SG 0x00040000 /* HCD-supported S-G */
315#define URB_MAP_LOCAL 0x00080000 /* HCD-local-memory mapping */
316#define URB_SETUP_MAP_SINGLE 0x00100000 /* Setup packet DMA mapped */
317#define URB_SETUP_MAP_LOCAL 0x00200000 /* HCD-local setup packet */
318#define URB_DMA_SG_COMBINED 0x00400000 /* S-G entries were combined */
319#define URB_ALIGNED_TEMP_BUFFER 0x00800000 /* Temp buffer was alloc'd */
320
321
322/* 9.6.6 */
323extern const true_false_string tfs_endpoint_direction;
324
325extern value_string_ext usb_class_vals_ext;
326extern value_string_ext usb_langid_vals_ext;
327extern value_string_ext ext_usb_audio_subclass_vals;
328extern value_string_ext ext_usb_massstorage_subclass_vals;
329extern value_string_ext ext_usb_com_subclass_vals;
330extern value_string_ext usb_massstorage_protocol_vals_ext;
331
332
333usb_conv_info_t *get_usb_iface_conv_info(packet_info *pinfo, uint8_t interface_num);
334usb_conv_info_t *get_existing_usb_ep_conv_info(packet_info *pinfo, uint16_t bus_id,
335 uint16_t device_address, int endpoint);
336
337proto_item * dissect_usb_descriptor_header(proto_tree *tree,
338 tvbuff_t *tvb, int offset,
339 value_string_ext *type_val_str);
340
341void dissect_usb_endpoint_address(proto_tree *tree, tvbuff_t *tvb, int offset);
342
343unsigned int
344sanitize_usb_max_packet_size(uint8_t ep_type, usb_speed_t speed,
345 unsigned int max_packet_size);
346
347int
348dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
349 tvbuff_t *tvb, int offset,
350 urb_info_t *urb,
351 uint8_t *out_ep_type, usb_speed_t speed);
352
353int
354dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
355 tvbuff_t *tvb, int offset,
356 urb_info_t *urb _U_);
357
358int
359dissect_urb_transfer_flags(tvbuff_t *tvb, int offset, proto_tree* tree, int hf, int endian);
360
361struct mausb_header;
362
363void
364dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent,
365 usb_header_t header_type, void *extra_data);
366
367void usb_lpm_besl_str(char *buf, uint32_t value);
368
369#endif
370
371/*
372 * Editor modelines - https://www.wireshark.org/tools/modelines.html
373 *
374 * Local variables:
375 * c-basic-offset: 4
376 * tab-width: 8
377 * indent-tabs-mode: nil
378 * End:
379 *
380 * vi: set shiftwidth=4 tabstop=8 expandtab:
381 * :indentSize=4:tabSize=8:noTabs=true:
382 */
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
proto_node proto_item
Definition proto.h:927
struct _wmem_array_t wmem_array_t
Opaque type representing a dynamically resizable array in the wmem system.
Definition wmem_array.h:42
struct _wmem_tree_t wmem_tree_t
Opaque type representing a red-black tree in the wmem system.
Definition wmem_tree.h:49
Definition packet-usb.h:144
Definition packet-usb.h:20
Definition packet-usb.h:121
Definition packet-usb.h:61
Definition packet-usb.h:162
Definition packet-usb.h:78
Definition packet-usb.h:71
Definition packet-mausb.h:18
Definition nstime.h:26
Definition tfs.h:24