Wireshark 4.7.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 <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/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;
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
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;
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;
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};
117
118/* Conversation Structure
119 * there is one such structure for each device/endpoint conversation */
121 uint8_t descriptor_transfer_type; /* transfer type lifted from the configuration descriptor */
122 uint16_t max_packet_size; /* max packet size from configuration descriptor */
123
124 uint16_t interfaceClass; /* Interface Descriptor - class */
125 uint16_t interfaceSubclass; /* Interface Descriptor - subclass */
126 uint16_t interfaceProtocol; /* Interface Descriptor - protocol */
127 uint8_t interfaceNum; /* Most recent interface number */
128
129 uint16_t deviceVendor; /* Device Descriptor - USB Vendor ID */
130 uint32_t deviceProduct; /* Device Descriptor - USB Product ID - MSBs only for encoding unknown */
131 uint16_t deviceVersion; /* Device Descriptor - USB device version number BCD */
132 uint8_t iSerialNumber; /* Device Descriptor - iSerialNumber (0 if no serial number available) */
133 wmem_tree_t *transactions;
134
135 void *class_data; /* private class/id decode data */
136 enum usb_conv_class_data_type class_data_type;
137
138 wmem_array_t *alt_settings;
139};
140
141/* URB data lifetime is limited to packet scope */
143 uint16_t bus_id;
144 uint16_t device_address;
145 uint8_t endpoint;
146 int direction;
147 uint8_t transfer_type; /* transfer type from URB */
148 uint32_t device_protocol;
149 bool is_request;
150 bool is_setup;
151 uint8_t setup_requesttype;
152 usb_speed_t speed;
153
154 usb_trans_info_t *usb_trans_info; /* pointer to the current transaction */
155
156 usb_conv_info_t *conv;
157};
158
159/* This is what a tap will tap */
160typedef struct _usb_tap_data_t {
161 uint8_t urb_type;
162 uint8_t transfer_type;
163 urb_info_t *urb;
164 usb_trans_info_t *trans_info;
166
167
168/* the value for "no endpoint" that's used usb_addr_t, e.g. for the address of the host */
169#define NO_ENDPOINT 0xffffffff
170/* the 8bit version of NO_ENDPOINT, it's used in usb_conv_info_t
171 0xff would be an invalid endpoint number (reserved bits are 1) */
172#define NO_ENDPOINT8 ((uint8_t)(NO_ENDPOINT& UINT8_MAX))
173
174/*
175 * Values from the Linux USB pseudo-header.
176 */
177
178/*
179 * event_type values
180 */
181#define URB_SUBMIT 'S'
182#define URB_COMPLETE 'C'
183#define URB_ERROR 'E'
184
185/*
186 * URB transfer_type values
187 */
188#define URB_ISOCHRONOUS 0x0
189#define URB_INTERRUPT 0x1
190#define URB_CONTROL 0x2
191#define URB_BULK 0x3
192#define URB_UNKNOWN 0xFF
193
194#define URB_TRANSFER_IN 0x80 /* to host */
195
196
197/* http://www.usb.org/developers/defined_class */
198#define IF_CLASS_DEVICE 0x00
199#define IF_CLASS_AUDIO 0x01
200#define IF_CLASS_COMMUNICATIONS 0x02
201#define IF_CLASS_HID 0x03
202#define IF_CLASS_PHYSICAL 0x05
203#define IF_CLASS_IMAGE 0x06
204#define IF_CLASS_PRINTER 0x07
205#define IF_CLASS_MASS_STORAGE 0x08
206#define IF_CLASS_HUB 0x09
207#define IF_CLASS_CDC_DATA 0x0a
208#define IF_CLASS_SMART_CARD 0x0b
209#define IF_CLASS_CONTENT_SECURITY 0x0d
210#define IF_CLASS_VIDEO 0x0e
211#define IF_CLASS_PERSONAL_HEALTHCARE 0x0f
212#define IF_CLASS_AUDIO_VIDEO 0x10
213#define IF_CLASS_BILLBOARD 0x11
214#define IF_CLASS_USB_C_BRIDGE 0x12
215#define IF_CLASS_BULK_DISPLAY_PROTO 0x13
216#define IF_CLASS_MCTP_USB_EP 0x14
217#define IF_CLASS_I3C 0x3c
218#define IF_CLASS_DIAGNOSTIC_DEVICE 0xdc
219#define IF_CLASS_WIRELESS_CONTROLLER 0xe0
220#define IF_CLASS_MISCELLANEOUS 0xef
221#define IF_CLASS_APPLICATION_SPECIFIC 0xfe
222#define IF_CLASS_VENDOR_SPECIFIC 0xff
223
224#define IF_CLASS_UNKNOWN 0xffff
225#define IF_SUBCLASS_UNKNOWN 0xffff
226#define IF_PROTOCOL_UNKNOWN 0xffff
227#define DEV_VENDOR_UNKNOWN 0x0000 /* this id is unassigned */
228#define DEV_PRODUCT_UNKNOWN 0xfffffff /* 0x0000 and 0xffff are used values by vendors, so MSBs encode unknown */
229#define DEV_VERSION_UNKNOWN 0xffff
230
231#define IF_SUBCLASS_MISC_U3V 0x05
232
233#define IF_SUBCLASS_APP_DFU 0x01
234
235#define IF_PROTOCOL_DFU_RUNTIME 0x01
236#define IF_PROTOCOL_DFU_MODE 0x02
237
238/* Key to be used with "usb.control", "usb.bulk" and/or "usb.interrupt"
239 * dissector tables when the dissector only applies to specific triple.
240 * Use class code directly if the code is not shared with other specifications.
241 *
242 * MSB (bit 31) is arbitrarily chosen to ensure class registered dissectors
243 * won't clash with protocol key.
244 */
245#define USB_PROTOCOL_KEY(class, subclass, protocol) \
246 (1u << 31 | (class & 0xff) << 16 | (subclass & 0xff) << 8 | (protocol & 0xff))
247
248/* bmRequestType values */
249#define USB_DIR_OUT 0 /* to device */
250#define USB_DIR_IN 0x80 /* to host */
251
252#define USB_TYPE_MASK (0x03 << 5)
253#define USB_TYPE(type) (((type) & USB_TYPE_MASK) >> 5)
254#define RQT_SETUP_TYPE_STANDARD 0
255#define RQT_SETUP_TYPE_CLASS 1
256#define RQT_SETUP_TYPE_VENDOR 2
257
258#define USB_RECIPIENT_MASK 0x1F
259#define USB_RECIPIENT(type) ((type) & USB_RECIPIENT_MASK)
260#define RQT_SETUP_RECIPIENT_DEVICE 0
261#define RQT_SETUP_RECIPIENT_INTERFACE 1
262#define RQT_SETUP_RECIPIENT_ENDPOINT 2
263#define RQT_SETUP_RECIPIENT_OTHER 3
264
265/* Endpoint descriptor bmAttributes */
266#define ENDPOINT_TYPE(ep_attrib) ((ep_attrib) & 0x03)
267#define ENDPOINT_TYPE_CONTROL 0
268#define ENDPOINT_TYPE_ISOCHRONOUS 1
269#define ENDPOINT_TYPE_BULK 2
270#define ENDPOINT_TYPE_INTERRUPT 3
271#define ENDPOINT_TYPE_NOT_SET 255
272
273/* wMaxPacketSize */
274#define USB_MPS_EP_SIZE(max_packet_size) ((max_packet_size) & 0x07FF)
275#define USB_MPS_ADDNL(max_packet_size) (((max_packet_size) & 0x1800) >> 11)
276#define USB_MPS(ep_size, addnl) (((addnl) << 11) | (ep_size))
277#define USB_MPS_TPL(max_packet_size) \
278 ((USB_MPS_ADDNL(max_packet_size) + 1) * USB_MPS_EP_SIZE(max_packet_size))
279
280#define USB_SETUP_GET_STATUS 0
281#define USB_SETUP_CLEAR_FEATURE 1
282#define USB_SETUP_SET_FEATURE 3
283#define USB_SETUP_SET_ADDRESS 5
284#define USB_SETUP_GET_DESCRIPTOR 6
285#define USB_SETUP_SET_DESCRIPTOR 7
286#define USB_SETUP_GET_CONFIGURATION 8
287#define USB_SETUP_SET_CONFIGURATION 9
288#define USB_SETUP_GET_INTERFACE 10
289#define USB_SETUP_SET_INTERFACE 11
290#define USB_SETUP_SYNCH_FRAME 12
291#define USB_SETUP_SET_SEL 48
292#define USB_SETUP_SET_ISOCH_DELAY 49
293
294/* transfer_flags */
295#define URB_SHORT_NOT_OK 0x00000001 /* report short reads as errors */
296#define URB_ISO_ASAP 0x00000002 /* iso-only; use the first unexpired
297 * slot in the schedule */
298#define URB_NO_TRANSFER_DMA_MAP 0x00000004 /* urb->transfer_dma valid on submit */
299#define URB_NO_FSBR 0x00000020 /* UHCI-specific */
300#define URB_ZERO_PACKET 0x00000040 /* Finish bulk OUT with short packet */
301#define URB_NO_INTERRUPT 0x00000080 /* HINT: no non-error interrupt
302 * needed */
303#define URB_FREE_BUFFER 0x00000100 /* Free transfer buffer with the URB */
304
305/* The following flags are used internally by usbcore and HCDs */
306#define URB_DIR_IN 0x00000200 /* Transfer from device to host */
307#define URB_DIR_OUT 0
308#define URB_DIR_MASK URB_DIR_IN
309
310#define URB_DMA_MAP_SINGLE 0x00010000 /* Non-scatter-gather mapping */
311#define URB_DMA_MAP_PAGE 0x00020000 /* HCD-unsupported S-G */
312#define URB_DMA_MAP_SG 0x00040000 /* HCD-supported S-G */
313#define URB_MAP_LOCAL 0x00080000 /* HCD-local-memory mapping */
314#define URB_SETUP_MAP_SINGLE 0x00100000 /* Setup packet DMA mapped */
315#define URB_SETUP_MAP_LOCAL 0x00200000 /* HCD-local setup packet */
316#define URB_DMA_SG_COMBINED 0x00400000 /* S-G entries were combined */
317#define URB_ALIGNED_TEMP_BUFFER 0x00800000 /* Temp buffer was alloc'd */
318
319
320/* 9.6.6 */
321extern const true_false_string tfs_endpoint_direction;
322
323extern value_string_ext usb_class_vals_ext;
324extern value_string_ext usb_langid_vals_ext;
325extern value_string_ext ext_usb_audio_subclass_vals;
326extern value_string_ext ext_usb_massstorage_subclass_vals;
327extern value_string_ext ext_usb_com_subclass_vals;
328extern value_string_ext usb_massstorage_protocol_vals_ext;
329
330
331usb_conv_info_t *get_usb_iface_conv_info(packet_info *pinfo, uint8_t interface_num);
332usb_conv_info_t *get_existing_usb_ep_conv_info(packet_info *pinfo, uint16_t bus_id,
333 uint16_t device_address, int endpoint);
334
335proto_item * dissect_usb_descriptor_header(proto_tree *tree,
336 tvbuff_t *tvb, int offset,
337 value_string_ext *type_val_str);
338
339void dissect_usb_endpoint_address(proto_tree *tree, tvbuff_t *tvb, int offset);
340
341unsigned int
342sanitize_usb_max_packet_size(uint8_t ep_type, usb_speed_t speed,
343 unsigned int max_packet_size);
344
345int
346dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
347 tvbuff_t *tvb, int offset,
348 urb_info_t *urb,
349 uint8_t *out_ep_type, usb_speed_t speed);
350
351int
352dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
353 tvbuff_t *tvb, int offset,
354 urb_info_t *urb _U_);
355
356int
357dissect_urb_transfer_flags(tvbuff_t *tvb, int offset, proto_tree* tree, int hf, int endian);
358
359struct mausb_header;
360
361void
362dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent,
363 usb_header_t header_type, void *extra_data);
364
365void usb_lpm_besl_str(char *buf, uint32_t value);
366
367#endif
368
369/*
370 * Editor modelines - https://www.wireshark.org/tools/modelines.html
371 *
372 * Local variables:
373 * c-basic-offset: 4
374 * tab-width: 8
375 * indent-tabs-mode: nil
376 * End:
377 *
378 * vi: set shiftwidth=4 tabstop=8 expandtab:
379 * :indentSize=4:tabSize=8:noTabs=true:
380 */
Represents the metadata and indexing information for a single captured frame.
Definition packet_info.h:43
Definition proto.h:909
Definition packet-usb.h:142
Definition packet-usb.h:20
Definition packet-usb.h:120
Definition packet-usb.h:61
Definition packet-usb.h:160
Definition packet-usb.h:78
Definition packet-usb.h:71
Extended metadata for a value_string array.
Definition value_string.h:325
Definition wmem_array.c:29
Internal representation of a wmem balanced tree.
Definition wmem_tree-int.h:81
Definition packet-mausb.h:18
Definition nstime.h:26
Definition tfs.h:24
Core tvbuff (testy virtual buffer) structure representing a region of packet data,...
Definition tvbuff-int.h:95