Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-usb.c
Line
Count
Source
1
/* packet-usb.c
2
 *
3
 * USB basic dissector
4
 * By Paolo Abeni <paolo.abeni@email.it>
5
 * Ronnie Sahlberg 2006
6
 *
7
 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
8
 *
9
 * https://github.com/torvalds/linux/blob/master/Documentation/usb/usbmon.rst
10
 *
11
 * http://desowin.org/usbpcap/captureformat.html
12
 *
13
 * SPDX-License-Identifier: GPL-2.0-or-later
14
 */
15
16
17
#include "config.h"
18
19
#include <epan/packet.h>
20
#include <epan/exceptions.h>
21
#include <epan/addr_resolv.h>
22
#include <epan/address_types.h>
23
#include <epan/conversation_table.h>
24
#include <epan/expert.h>
25
#include <epan/prefs.h>
26
#include <epan/decode_as.h>
27
#include <epan/proto_data.h>
28
#include <epan/unit_strings.h>
29
#include <wsutil/pint.h>
30
#include <wsutil/ws_roundup.h>
31
32
#include "packet-usb.h"
33
#include "packet-mausb.h"
34
#include "packet-usbip.h"
35
#include "packet-netmon.h"
36
37
/* dissector handles */
38
static dissector_handle_t  linux_usb_handle;
39
static dissector_handle_t  linux_usb_mmapped_handle;
40
static dissector_handle_t  win32_usb_handle;
41
static dissector_handle_t  freebsd_usb_handle;
42
static dissector_handle_t  darwin_usb_handle;
43
static dissector_handle_t  netmon_usb_port_handle;
44
45
/* protocols and header fields */
46
static int proto_usb;
47
static int proto_usbport;
48
49
/* USB pseudoheader fields, both FreeBSD and Linux */
50
static int hf_usb_totlen;
51
static int hf_usb_busunit;
52
static int hf_usb_address;
53
static int hf_usb_mode;
54
static int hf_usb_freebsd_urb_type;
55
static int hf_usb_freebsd_transfer_type;
56
static int hf_usb_xferflags;
57
static int hf_usb_xferflags_force_short_xfer;
58
static int hf_usb_xferflags_short_xfer_ok;
59
static int hf_usb_xferflags_short_frames_ok;
60
static int hf_usb_xferflags_pipe_bof;
61
static int hf_usb_xferflags_proxy_buffer;
62
static int hf_usb_xferflags_ext_buffer;
63
static int hf_usb_xferflags_manual_status;
64
static int hf_usb_xferflags_no_pipe_ok;
65
static int hf_usb_xferflags_stall_pipe;
66
static int hf_usb_xferstatus;
67
static int hf_usb_xferstatus_open;
68
static int hf_usb_xferstatus_transferring;
69
static int hf_usb_xferstatus_did_dma_delay;
70
static int hf_usb_xferstatus_did_close;
71
static int hf_usb_xferstatus_draining;
72
static int hf_usb_xferstatus_started;
73
static int hf_usb_xferstatus_bw_reclaimed;
74
static int hf_usb_xferstatus_control_xfr;
75
static int hf_usb_xferstatus_control_hdr;
76
static int hf_usb_xferstatus_control_act;
77
static int hf_usb_xferstatus_control_stall;
78
static int hf_usb_xferstatus_short_frames_ok;
79
static int hf_usb_xferstatus_short_xfer_ok;
80
static int hf_usb_xferstatus_bdma_enable;
81
static int hf_usb_xferstatus_bdma_no_post_sync;
82
static int hf_usb_xferstatus_bdma_setup;
83
static int hf_usb_xferstatus_isochronous_xfr;
84
static int hf_usb_xferstatus_curr_dma_set;
85
static int hf_usb_xferstatus_can_cancel_immed;
86
static int hf_usb_xferstatus_doing_callback;
87
static int hf_usb_error;
88
static int hf_usb_interval;
89
static int hf_usb_nframes;
90
static int hf_usb_packet_size;
91
static int hf_usb_packet_count;
92
static int hf_usb_speed;
93
static int hf_usb_frame_length;
94
static int hf_usb_frame_flags;
95
static int hf_usb_frame_flags_read;
96
static int hf_usb_frame_flags_data_follows;
97
static int hf_usb_frame_data;
98
static int hf_usb_urb_id;
99
static int hf_usb_linux_urb_type;
100
static int hf_usb_linux_transfer_type;
101
static int hf_usb_endpoint_address;
102
static int hf_usb_endpoint_direction;
103
static int hf_usb_endpoint_number;
104
static int hf_usb_device_address;
105
static int hf_usb_bus_id;
106
static int hf_usb_setup_flag;
107
static int hf_usb_data_flag;
108
static int hf_usb_urb_ts_sec;
109
static int hf_usb_urb_ts_usec;
110
static int hf_usb_urb_status;
111
static int hf_usb_urb_len;
112
static int hf_usb_urb_data_len;
113
static int hf_usb_urb_unused_setup_header;
114
static int hf_usb_urb_interval;
115
static int hf_usb_urb_start_frame;
116
static int hf_usb_urb_copy_of_transfer_flags;
117
118
/* transfer_flags */
119
static int hf_short_not_ok;
120
static int hf_iso_asap;
121
static int hf_no_transfer_dma_map;
122
static int hf_no_fsbr;
123
static int hf_zero_packet;
124
static int hf_no_interrupt;
125
static int hf_free_buffer;
126
static int hf_dir_in;
127
static int hf_dma_map_single;
128
static int hf_dma_map_page;
129
static int hf_dma_map_sg;
130
static int hf_map_local;
131
static int hf_setup_map_single;
132
static int hf_setup_map_local;
133
static int hf_dma_sg_combined;
134
static int hf_aligned_temp_buffer;
135
136
static int * const transfer_flags_fields[] = {
137
    &hf_short_not_ok,
138
    &hf_iso_asap,
139
    &hf_no_transfer_dma_map,
140
    &hf_no_fsbr,
141
    &hf_zero_packet,
142
    &hf_no_interrupt,
143
    &hf_free_buffer,
144
    &hf_dir_in,
145
    &hf_dma_map_single,
146
    &hf_dma_map_page,
147
    &hf_dma_map_sg,
148
    &hf_map_local,
149
    &hf_setup_map_single,
150
    &hf_setup_map_local,
151
    &hf_dma_sg_combined,
152
    &hf_aligned_temp_buffer,
153
    NULL
154
};
155
156
/* Win32 USBPcap pseudoheader fields */
157
static int hf_usb_win32_header_len;
158
static int hf_usb_irp_id;
159
static int hf_usb_usbd_status;
160
static int hf_usb_function;
161
static int hf_usb_info;
162
static int hf_usb_usbpcap_info_reserved;
163
static int hf_usb_usbpcap_info_direction;
164
static int hf_usb_win32_device_address;
165
static int hf_usb_win32_transfer_type;
166
/* hf_usb_bus_id, hf_usb_endpoint_address, hf_usb_endpoint_direction,
167
 * hf_usb_endpoint_number are common with
168
 * FreeBSD and Linux pseudoheaders */
169
static int hf_usb_win32_data_len;
170
static int hf_usb_win32_control_stage;
171
static int hf_usb_win32_iso_start_frame;
172
static int hf_usb_win32_iso_num_packets;
173
static int hf_usb_win32_iso_error_count;
174
static int hf_usb_win32_iso_offset;
175
static int hf_usb_win32_iso_length;
176
static int hf_usb_win32_iso_status;
177
178
static int hf_usb_request;
179
static int hf_usb_request_unknown_class;
180
static int hf_usb_value;
181
static int hf_usb_index;
182
static int hf_usb_length;
183
/* static int hf_usb_data_len; */
184
static int hf_usb_capdata;
185
static int hf_usb_device_wFeatureSelector;
186
static int hf_usb_interface_wFeatureSelector;
187
static int hf_usb_endpoint_wFeatureSelector;
188
static int hf_usb_wInterface;
189
static int hf_usb_wEndpoint;
190
static int hf_usb_wStatus;
191
static int hf_usb_wFrameNumber;
192
193
static int hf_usb_iso_error_count;
194
static int hf_usb_iso_numdesc;
195
static int hf_usb_iso_status;
196
static int hf_usb_iso_off;
197
static int hf_usb_iso_len;
198
static int hf_usb_iso_actual_len;
199
static int hf_usb_iso_pad;
200
static int hf_usb_iso_data;
201
202
static int hf_usb_bmRequestType;
203
static int hf_usb_control_response_generic;
204
static int hf_usb_bmRequestType_direction;
205
static int hf_usb_bmRequestType_type;
206
static int hf_usb_bmRequestType_recipient;
207
static int hf_usb_bDescriptorType;
208
static int hf_usb_get_descriptor_resp_generic;
209
static int hf_usb_descriptor_index;
210
static int hf_usb_language_id;
211
static int hf_usb_bLength;
212
static int hf_usb_bcdUSB;
213
static int hf_usb_bDeviceClass;
214
static int hf_usb_bDeviceSubClass;
215
static int hf_usb_bDeviceProtocol;
216
static int hf_usb_bMaxPacketSize0;
217
static int hf_usb_idVendor;
218
static int hf_usb_idProduct;
219
static int hf_usb_bcdDevice;
220
static int hf_usb_iManufacturer;
221
static int hf_usb_iProduct;
222
static int hf_usb_iSerialNumber;
223
static int hf_usb_bNumConfigurations;
224
static int hf_usb_wLANGID;
225
static int hf_usb_bString;
226
static int hf_usb_bInterfaceNumber;
227
static int hf_usb_bAlternateSetting;
228
static int hf_usb_bNumEndpoints;
229
static int hf_usb_bInterfaceClass;
230
static int hf_usb_bInterfaceSubClass;
231
static int hf_usb_bInterfaceSubClass_audio;
232
static int hf_usb_bInterfaceSubClass_cdc;
233
static int hf_usb_bInterfaceSubClass_massstorage;
234
static int hf_usb_bInterfaceSubClass_hid;
235
static int hf_usb_bInterfaceSubClass_misc;
236
static int hf_usb_bInterfaceSubClass_app;
237
static int hf_usb_bInterfaceProtocol;
238
static int hf_usb_bInterfaceProtocol_cdc;
239
static int hf_usb_bInterfaceProtocol_massstorage;
240
static int hf_usb_bInterfaceProtocol_cdc_data;
241
static int hf_usb_bInterfaceProtocol_hid_boot;
242
static int hf_usb_bInterfaceProtocol_app_dfu;
243
static int hf_usb_bInterfaceProtocol_app_irda;
244
static int hf_usb_bInterfaceProtocol_app_usb_test_and_measurement;
245
static int hf_usb_iInterface;
246
static int hf_usb_bEndpointAddress;
247
static int hf_usb_bmAttributes;
248
static int hf_usb_bEndpointAttributeTransfer;
249
static int hf_usb_bEndpointAttributeSynchonisation;
250
static int hf_usb_bEndpointAttributeBehaviour;
251
static int hf_usb_wMaxPacketSize;
252
static int hf_usb_wMaxPacketSize_size;
253
static int hf_usb_wMaxPacketSize_slots;
254
static int hf_usb_bInterval;
255
static int hf_usb_bMaxBurst;
256
static int hf_usb_audio_bRefresh;
257
static int hf_usb_audio_bSynchAddress;
258
static int hf_usb_bSSEndpointAttributeBulkMaxStreams;
259
static int hf_usb_bSSEndpointAttributeIsoMult;
260
static int hf_usb_wBytesPerInterval;
261
static int hf_usb_wTotalLength;
262
static int hf_usb_bNumInterfaces;
263
static int hf_usb_bConfigurationValue;
264
static int hf_usb_iConfiguration;
265
static int hf_usb_bMaxPower;
266
static int hf_usb_configuration_bmAttributes;
267
static int hf_usb_configuration_legacy10buspowered;
268
static int hf_usb_configuration_selfpowered;
269
static int hf_usb_configuration_remotewakeup;
270
static int hf_usb_bEndpointAddress_direction;
271
static int hf_usb_bEndpointAddress_number;
272
static int hf_usb_response_in;
273
static int hf_usb_time;
274
static int hf_usb_request_in;
275
static int hf_usb_bFirstInterface;
276
static int hf_usb_bInterfaceCount;
277
static int hf_usb_bFunctionClass;
278
static int hf_usb_bFunctionSubClass;
279
static int hf_usb_bFunctionProtocol;
280
static int hf_usb_iFunction;
281
static int hf_usb_bNumDeviceCaps;
282
static int hf_usb_bDevCapabilityType;
283
static int hf_usb_usb20ext_bmAttributes;
284
static int hf_usb_usb20ext_LPM;
285
static int hf_usb_usb20ext_BESL_HIRD;
286
static int hf_usb_usb20ext_baseline_BESL_valid;
287
static int hf_usb_usb20ext_deep_BESL_valid;
288
static int hf_usb_usb20ext_baseline_BESL;
289
static int hf_usb_usb20ext_deep_BESL;
290
static int hf_usb_bReserved;
291
static int hf_usb_PlatformCapabilityUUID;
292
static int hf_usb_webusb_bcdVersion;
293
static int hf_usb_webusb_bVendorCode;
294
static int hf_usb_webusb_iLandingPage;
295
static int hf_usb_msos20_dwWindowsVersion;
296
static int hf_usb_msos20_wMSOSDescriptorSetTotalLength;
297
static int hf_usb_msos20_bMS_VendorCode;
298
static int hf_usb_msos20_bAltEnumCode;
299
static int hf_usb_data_fragment;
300
static int hf_usb_src;
301
static int hf_usb_dst;
302
static int hf_usb_addr;
303
static int hf_usb_ss_bmAttributes;
304
static int hf_usb_ss_bmAttributes_reserved0;
305
static int hf_usb_ss_bmAttributes_LTM;
306
static int hf_usb_ss_bmAttributes_reserved7_2;
307
static int hf_usb_ss_wSpeedSupported;
308
static int hf_usb_ss_wSpeedSupported_LS;
309
static int hf_usb_ss_wSpeedSupported_FS;
310
static int hf_usb_ss_wSpeedSupported_HS;
311
static int hf_usb_ss_wSpeedSupported_Gen1;
312
static int hf_usb_ss_wSpeedSupported_reserved;
313
static int hf_usb_ss_bFunctionalitySupport;
314
static int hf_usb_ss_bU1DevExitLat;
315
static int hf_usb_ss_wU2DevExitLat;
316
317
/* macOS */
318
static int hf_usb_darwin_bcd_version;
319
static int hf_usb_darwin_header_len;
320
static int hf_usb_darwin_request_type;
321
static int hf_usb_darwin_io_len;
322
static int hf_usb_darwin_io_status;
323
static int hf_usb_darwin_iso_num_packets;
324
static int hf_usb_darwin_io_id;
325
static int hf_usb_darwin_device_location;
326
static int hf_usb_darwin_speed;
327
static int hf_usb_darwin_device_address;
328
static int hf_usb_darwin_endpoint_address;
329
static int hf_usb_darwin_endpoint_type;
330
static int hf_usb_darwin_iso_status;
331
static int hf_usb_darwin_iso_frame_number;
332
static int hf_usb_darwin_iso_timestamp;
333
334
/* NetMon */
335
static int hf_usbport_event_id;
336
static int hf_usbport_device_object;
337
static int hf_usbport_pci_bus;
338
static int hf_usbport_pci_device;
339
static int hf_usbport_pci_function;
340
static int hf_usbport_pci_vendor_id;
341
static int hf_usbport_pci_device_id;
342
static int hf_usbport_port_path_depth;
343
static int hf_usbport_port_path0;
344
static int hf_usbport_port_path1;
345
static int hf_usbport_port_path2;
346
static int hf_usbport_port_path3;
347
static int hf_usbport_port_path4;
348
static int hf_usbport_port_path5;
349
static int hf_usbport_device_handle;
350
static int hf_usbport_device_speed;
351
static int hf_usbport_endpoint;
352
static int hf_usbport_pipehandle;
353
static int hf_usbport_endpoint_desc_length;
354
static int hf_usbport_endpoint_desc_type;
355
static int hf_usbport_endpoint_address;
356
static int hf_usbport_bm_attributes;
357
static int hf_usbport_max_packet_size;
358
static int hf_usbport_interval;
359
static int hf_usbport_irp;
360
static int hf_usbport_urb;
361
static int hf_usbport_urb_transfer_data;
362
static int hf_usbport_urb_header_length;
363
static int hf_usbport_urb_header_function;
364
static int hf_usbport_urb_header_status;
365
static int hf_usbport_urb_header_usbddevice_handle;
366
static int hf_usbport_urb_header_usbdflags;
367
static int hf_usbport_urb_configuration_desc;
368
static int hf_usbport_urb_configuration_handle;
369
static int hf_usbport_urb_pipe_handle;
370
static int hf_usbport_urb_xferflags;
371
static int hf_usbport_urb_transfer_buffer_length;
372
static int hf_usbport_urb_transfer_buffer;
373
static int hf_usbport_urb_transfer_buffer_mdl;
374
static int hf_usbport_urb_reserved_mbz;
375
static int hf_usbport_urb_reserved_hcd;
376
static int hf_usbport_urb_reserved;
377
static int hf_usbport_keyword;
378
static int hf_usbport_keyword_diagnostic;
379
static int hf_usbport_keyword_power_diagnostics;
380
static int hf_usbport_keyword_perf_diagnostics;
381
static int hf_usbport_keyword_reserved1;
382
383
static int ett_usb_hdr;
384
static int ett_usb_setup_hdr;
385
static int ett_usb_isodesc;
386
static int ett_usb_win32_iso_packet;
387
static int ett_usb_endpoint;
388
static int ett_usb_setup_bmrequesttype;
389
static int ett_usb_usbpcap_info;
390
static int ett_descriptor_device;
391
static int ett_configuration_bmAttributes;
392
static int ett_configuration_bEndpointAddress;
393
static int ett_endpoint_bmAttributes;
394
static int ett_endpoint_wMaxPacketSize;
395
static int ett_usb_xferflags;
396
static int ett_usb_xferstatus;
397
static int ett_usb_frame;
398
static int ett_usb_frame_flags;
399
static int ett_usbport;
400
static int ett_usbport_host_controller;
401
static int ett_usbport_path;
402
static int ett_usbport_device;
403
static int ett_usbport_endpoint;
404
static int ett_usbport_endpoint_desc;
405
static int ett_usbport_urb;
406
static int ett_usbport_keyword;
407
static int ett_transfer_flags;
408
static int ett_usb20ext_bmAttributes;
409
static int ett_ss_bmAttributes;
410
static int ett_ss_wSpeedSupported;
411
412
static expert_field ei_usb_undecoded;
413
static expert_field ei_usb_bLength_even;
414
static expert_field ei_usb_bLength_too_short;
415
static expert_field ei_usb_desc_length_invalid;
416
static expert_field ei_usb_invalid_setup;
417
static expert_field ei_usb_ss_ep_companion_before_ep;
418
static expert_field ei_usb_usbpcap_unknown_urb;
419
static expert_field ei_usb_bad_length;
420
static expert_field ei_usb_invalid_max_packet_size;
421
static expert_field ei_usb_invalid_max_packet_size0;
422
static expert_field ei_usb_invalid_endpoint_type;
423
static expert_field ei_usb_unexpected_desc_type;
424
425
static expert_field ei_usbport_invalid_path_depth;
426
427
static int usb_address_type = -1;
428
429
static int * const usb_endpoint_fields[] = {
430
    &hf_usb_endpoint_direction,
431
    &hf_usb_endpoint_number,
432
    NULL
433
};
434
435
static int * const usb_usbpcap_info_fields[] = {
436
    &hf_usb_usbpcap_info_reserved,
437
    &hf_usb_usbpcap_info_direction,
438
    NULL
439
};
440
441
static int usb_tap;
442
static bool try_heuristics = true;
443
444
static dissector_table_t usb_bulk_dissector_table;
445
static dissector_table_t usb_control_dissector_table;
446
static dissector_table_t usb_interrupt_dissector_table;
447
static dissector_table_t usb_descriptor_dissector_table;
448
449
static heur_dissector_list_t heur_bulk_subdissector_list;
450
static heur_dissector_list_t heur_control_subdissector_list;
451
static heur_dissector_list_t heur_interrupt_subdissector_list;
452
453
static wmem_tree_t *device_to_protocol_table;
454
static wmem_tree_t *device_to_product_table;
455
static wmem_tree_t *usbpcap_setup_data;
456
457
static dissector_table_t device_to_dissector;
458
static dissector_table_t protocol_to_dissector;
459
static dissector_table_t product_to_dissector;
460
461
typedef struct _device_product_data_t {
462
    uint16_t vendor;
463
    uint16_t product;
464
    uint16_t device;
465
    unsigned  bus_id;
466
    unsigned  device_address;
467
} device_product_data_t;
468
469
typedef struct _device_protocol_data_t {
470
    uint32_t protocol;
471
    unsigned  bus_id;
472
    unsigned  device_address;
473
} device_protocol_data_t;
474
475
typedef struct _usb_alt_setting_t {
476
    uint8_t altSetting;
477
    uint8_t interfaceClass;
478
    uint8_t interfaceSubclass;
479
    uint8_t interfaceProtocol;
480
    uint8_t interfaceNum;
481
} usb_alt_setting_t;
482
483
typedef struct {
484
    uint64_t usb_id;
485
    uint8_t setup_data[8];
486
} usbpcap_setup_data_t;
487
488
static const value_string usb_speed_vals[] = {
489
    {USB_SPEED_UNKNOWN, "Unknown Speed"},
490
    {USB_SPEED_LOW,     "Low-Speed"},
491
    {USB_SPEED_FULL,    "Full-Speed"},
492
    {USB_SPEED_HIGH,    "High-Speed"},
493
    {0, NULL}
494
};
495
496
/* http://www.usb.org/developers/docs/USB_LANGIDs.pdf */
497
static const value_string usb_langid_vals[] = {
498
    {0x0000, "no language specified"},
499
    {0x0401, "Arabic (Saudi Arabia)"},
500
    {0x0402, "Bulgarian"},
501
    {0x0403, "Catalan"},
502
    {0x0404, "Chinese (Taiwan)"},
503
    {0x0405, "Czech"},
504
    {0x0406, "Danish"},
505
    {0x0407, "German (Standard)"},
506
    {0x0408, "Greek"},
507
    {0x0409, "English (United States)"},
508
    {0x040a, "Spanish (Traditional Sort)"},
509
    {0x040b, "Finnish"},
510
    {0x040c, "French (Standard)"},
511
    {0x040d, "Hebrew"},
512
    {0x040e, "Hungarian"},
513
    {0x040f, "Icelandic"},
514
    {0x0410, "Italian (Standard)"},
515
    {0x0411, "Japanese"},
516
    {0x0412, "Korean"},
517
    {0x0413, "Dutch (Netherlands)"},
518
    {0x0414, "Norwegian (Bokmal)"},
519
    {0x0415, "Polish"},
520
    {0x0416, "Portuguese (Brazil)"},
521
    {0x0418, "Romanian"},
522
    {0x0419, "Russian"},
523
    {0x041a, "Croatian"},
524
    {0x041b, "Slovak"},
525
    {0x041c, "Albanian"},
526
    {0x041d, "Swedish"},
527
    {0x041e, "Thai"},
528
    {0x041f, "Turkish"},
529
    {0x0420, "Urdu (Pakistan)"},
530
    {0x0421, "Indonesian"},
531
    {0x0422, "Ukrainian"},
532
    {0x0423, "Belarussian"},
533
    {0x0424, "Slovenian"},
534
    {0x0425, "Estonian"},
535
    {0x0426, "Latvian"},
536
    {0x0427, "Lithuanian"},
537
    {0x0429, "Farsi"},
538
    {0x042a, "Vietnamese"},
539
    {0x042b, "Armenian"},
540
    {0x042c, "Azeri (Latin)"},
541
    {0x042d, "Basque"},
542
    {0x042f, "Macedonian"},
543
    {0x0430, "Sutu"},
544
    {0x0436, "Afrikaans"},
545
    {0x0437, "Georgian"},
546
    {0x0438, "Faeroese"},
547
    {0x0439, "Hindi"},
548
    {0x043e, "Malay (Malaysian)"},
549
    {0x043f, "Kazakh"},
550
    {0x0441, "Swahili (Kenya)"},
551
    {0x0443, "Uzbek (Latin)"},
552
    {0x0444, "Tatar (Tatarstan)"},
553
    {0x0445, "Bengali"},
554
    {0x0446, "Punjabi"},
555
    {0x0447, "Gujarati"},
556
    {0x0448, "Oriya"},
557
    {0x0449, "Tamil"},
558
    {0x044a, "Telugu"},
559
    {0x044b, "Kannada"},
560
    {0x044c, "Malayalam"},
561
    {0x044d, "Assamese"},
562
    {0x044e, "Marathi"},
563
    {0x044f, "Sanskrit"},
564
    {0x0455, "Burmese"},
565
    {0x0457, "Konkani"},
566
    {0x0458, "Manipuri"},
567
    {0x0459, "Sindhi"},
568
    {0x04ff, "HID (Usage Data Descriptor)"},
569
    {0x0801, "Arabic (Iraq)"},
570
    {0x0804, "Chinese (PRC)"},
571
    {0x0807, "German (Switzerland)"},
572
    {0x0809, "English (United Kingdom)"},
573
    {0x080a, "Spanish (Mexican)"},
574
    {0x080c, "French (Belgian)"},
575
    {0x0810, "Italian (Switzerland)"},
576
    {0x0812, "Korean (Johab)"},
577
    {0x0813, "Dutch (Belgium)"},
578
    {0x0814, "Norwegian (Nynorsk)"},
579
    {0x0816, "Portuguese (Standard)"},
580
    {0x081a, "Serbian (Latin)"},
581
    {0x081d, "Swedish (Finland)"},
582
    {0x0820, "Urdu (India)"},
583
    {0x0827, "Lithuanian (Classic)"},
584
    {0x082c, "Azeri (Cyrillic)"},
585
    {0x083e, "Malay (Brunei Darussalam)"},
586
    {0x0843, "Uzbek (Cyrillic)"},
587
    {0x0860, "Kashmiri (India)"},
588
    {0x0861, "Nepali (India)"},
589
    {0x0c01, "Arabic (Egypt)"},
590
    {0x0c04, "Chinese (Hong Kong SAR, PRC)"},
591
    {0x0c07, "German (Austria)"},
592
    {0x0c09, "English (Australian)"},
593
    {0x0c0a, "Spanish (Modern Sort)"},
594
    {0x0c0c, "French (Canadian)"},
595
    {0x0c1a, "Serbian (Cyrillic)"},
596
    {0x1001, "Arabic (Libya)"},
597
    {0x1004, "Chinese (Singapore)"},
598
    {0x1007, "German (Luxembourg)"},
599
    {0x1009, "English (Canadian)"},
600
    {0x100a, "Spanish (Guatemala)"},
601
    {0x100c, "French (Switzerland)"},
602
    {0x1401, "Arabic (Algeria)"},
603
    {0x1404, "Chinese (Macau SAR)"},
604
    {0x1407, "German (Liechtenstein)"},
605
    {0x1409, "English (New Zealand)"},
606
    {0x140a, "Spanish (Costa Rica)"},
607
    {0x140c, "French (Luxembourg)"},
608
    {0x1801, "Arabic (Morocco)"},
609
    {0x1809, "English (Ireland)"},
610
    {0x180a, "Spanish (Panama)"},
611
    {0x180c, "French (Monaco)"},
612
    {0x1c01, "Arabic (Tunisia)"},
613
    {0x1c09, "English (South Africa)"},
614
    {0x1c0a, "Spanish (Dominican Republic)"},
615
    {0x2001, "Arabic (Oman)"},
616
    {0x2009, "English (Jamaica)"},
617
    {0x200a, "Spanish (Venezuela)"},
618
    {0x2401, "Arabic (Yemen)"},
619
    {0x2409, "English (Caribbean)"},
620
    {0x240a, "Spanish (Colombia)"},
621
    {0x2801, "Arabic (Syria)"},
622
    {0x2809, "English (Belize)"},
623
    {0x280a, "Spanish (Peru)"},
624
    {0x2c01, "Arabic (Jordan)"},
625
    {0x2c09, "English (Trinidad)"},
626
    {0x2c0a, "Spanish (Argentina)"},
627
    {0x3001, "Arabic (Lebanon)"},
628
    {0x3009, "English (Zimbabwe)"},
629
    {0x300a, "Spanish (Ecuador)"},
630
    {0x3401, "Arabic (Kuwait)"},
631
    {0x3409, "English (Philippines)"},
632
    {0x340a, "Spanish (Chile)"},
633
    {0x3801, "Arabic (U.A.E.)"},
634
    {0x380a, "Spanish (Uruguay)"},
635
    {0x3c01, "Arabic (Bahrain)"},
636
    {0x3c0a, "Spanish (Paraguay)"},
637
    {0x4001, "Arabic (Qatar)"},
638
    {0x400a, "Spanish (Bolivia)"},
639
    {0x440a, "Spanish (El Salvador)"},
640
    {0x480a, "Spanish (Honduras)"},
641
    {0x4c0a, "Spanish (Nicaragua)"},
642
    {0x500a, "Spanish (Puerto Rico)"},
643
    {0xf0ff, "HID (Vendor Defined 1)"},
644
    {0xf4ff, "HID (Vendor Defined 2)"},
645
    {0xf8ff, "HID (Vendor Defined 3)"},
646
    {0xfcff, "HID (Vendor Defined 4)"},
647
    {0, NULL}
648
};
649
value_string_ext usb_langid_vals_ext = VALUE_STRING_EXT_INIT(usb_langid_vals);
650
651
static const value_string usb_class_vals[] = {
652
    {IF_CLASS_DEVICE,                   "Device"},
653
    {IF_CLASS_AUDIO,                    "Audio"},
654
    {IF_CLASS_COMMUNICATIONS,           "Communications and CDC Control"},
655
    {IF_CLASS_HID,                      "HID"},
656
    {IF_CLASS_PHYSICAL,                 "Physical"},
657
    {IF_CLASS_IMAGE,                    "Imaging"},
658
    {IF_CLASS_PRINTER,                  "Printer"},
659
    {IF_CLASS_MASS_STORAGE,             "Mass Storage"},
660
    {IF_CLASS_HUB,                      "Hub"},
661
    {IF_CLASS_CDC_DATA,                 "CDC-Data"},
662
    {IF_CLASS_SMART_CARD,               "Smart Card"},
663
    {IF_CLASS_CONTENT_SECURITY,         "Content Security"},
664
    {IF_CLASS_VIDEO,                    "Video"},
665
    {IF_CLASS_PERSONAL_HEALTHCARE,      "Personal Healthcare"},
666
    {IF_CLASS_AUDIO_VIDEO,              "Audio/Video Devices"},
667
    {IF_CLASS_BILLBOARD,                "Billboard Device"},
668
    {IF_CLASS_USB_C_BRIDGE,             "USB Type-C Bridge"},
669
    {IF_CLASS_BULK_DISPLAY_PROTO,       "USB Bulk Display Protocol Device"},
670
    {IF_CLASS_MCTP_USB_EP,              "MCTP over USB Protocol Endpoint Device"},
671
    {IF_CLASS_I3C,                      "I3C Device"},
672
    {IF_CLASS_DIAGNOSTIC_DEVICE,        "Diagnostic Device"},
673
    {IF_CLASS_WIRELESS_CONTROLLER,      "Wireless Controller"},
674
    {IF_CLASS_MISCELLANEOUS,            "Miscellaneous"},
675
    {IF_CLASS_APPLICATION_SPECIFIC,     "Application Specific"},
676
    {IF_CLASS_VENDOR_SPECIFIC,          "Vendor Specific"},
677
    {0, NULL}
678
};
679
value_string_ext usb_class_vals_ext = VALUE_STRING_EXT_INIT(usb_class_vals);
680
681
/* use usb class, subclass and protocol id together
682
  http://www.usb.org/developers/defined_class
683
  USB Class Definitions for Communications Devices, Revision 1.2 December 6, 2012
684
*/
685
static const value_string usb_protocols[] = {
686
    {0x000000,    "Use class code info from Interface Descriptors"},
687
    {0x060101,    "Still Imaging"},
688
    {0x090000,    "Full speed Hub"},
689
    {0x090001,    "Hi-speed hub with single TT"},
690
    {0x090002,    "Hi-speed hub with multiple TTs"},
691
    {0x0D0000,    "Content Security"},
692
    {0x100100,    "AVControl Interface"},
693
    {0x100200,    "AVData Video Streaming Interface"},
694
    {0x100300,    "AVData Audio Streaming Interface"},
695
    {0x140001,    "MCTP 1.x - MCTP Management-controller and Managed-Device endpoints"},
696
    {0x140002,    "MCTP 2.x - MCTP Management-controller and Managed-Device endpoints"},
697
    {0x140101,    "MCTP 1.x - MCTP Host Interface endpoint"},
698
    {0x140102,    "MCTP 2.x - MCTP Host Interface endpoint"},
699
    {0xDC0101,    "USB2 Compliance Device"},
700
    {0xDC0200,    "Debug Target vendor defined"},
701
    {0xDC0201,    "GNU Remote Debug Command Set"},
702
    {0xDC0301,    "Vendor defined Trace protocol on DbC"},
703
    {0xDC0401,    "Vendor defined Dfx protocol on DbC"},
704
    {0xDC0500,    "Vendor defined Trace protocol over General Purpose (GP) endpoint on DvC"},
705
    {0xDC0501,    "GNU Protocol protocol over General Purpose (GP) endpoint on DvC"},
706
    {0xDC0601,    "Vendor defined Dfx protocol on DvC"},
707
    {0xDC0701,    "Vendor defined Trace protocol on DvC"},
708
    {0xE00101,    "Bluetooth Programming Interface"},
709
    {0xE00102,    "UWB Radio Control Interface"},
710
    {0xE00103,    "Remote NDIS"},
711
    {0xE00104,    "Bluetooth AMP Controller"},
712
    {0xE00201,    "Host Wire Adapter Control/Data interface"},
713
    {0xE00202,    "Device Wire Adapter Control/Data interface"},
714
    {0xE00203,    "Device Wire Adapter Isochronous interface"},
715
    {0xEF0101,    "Active Sync device"},
716
    {0xEF0102,    "Palm Sync"},
717
    {0xEF0201,    "Interface Association Descriptor"},
718
    {0xEF0202,    "Wire Adapter Multifunction Peripheral programming interface"},
719
    {0xEF0301,    "Cable Based Association Framework"},
720
    {0xEF0401,    "RNDIS over Ethernet"},
721
    {0xEF0402,    "RNDIS over WiFi"},
722
    {0xEF0403,    "RNDIS over WiMAX"},
723
    {0xEF0404,    "RNDIS over WWAN"},
724
    {0xEF0405,    "RNDIS for Raw IPv4"},
725
    {0xEF0406,    "RNDIS for Raw IPv6"},
726
    {0xEF0407,    "RNDIS for GPRS"},
727
    {0xEF0500,    "USB3 Vision Control Interface"},
728
    {0xEF0501,    "USB3 Vision Event Interface"},
729
    {0xEF0502,    "USB3 Vision Streaming Interface"},
730
    {0xEF0601,    "Stream Transport Efficient Protocol for content protection"},
731
    {0xEF0602,    "Stream Transport Efficient Protocol for Raw content protection"},
732
    {0xEF0700,    "Command Interface in IAD"},
733
    {0xEF0702,    "Command Interface in Interface Descriptor"},
734
    {0xEF0703,    "Media Interface in Interface Descriptor"},
735
    {0xFE0101,    "Device Firmware Upgrade"},
736
    {0xFE0200,    "IRDA Bridge device"},
737
    {0xFE0300,    "USB Test and Measurement Device"},
738
    {0xFE0301,    "USB Test and Measurement Device conforming to the USBTMC USB488"},
739
    {0, NULL}
740
};
741
static value_string_ext usb_protocols_ext = VALUE_STRING_EXT_INIT(usb_protocols);
742
743
/* BOS Descriptor Device Capability Type Codes
744
   https://www.usb.org/bos-descriptor-types
745
*/
746
#define BOS_CAP_WIRELESS_USB           0x01
747
0
#define BOS_CAP_USB_20_EXTENSION       0x02
748
0
#define BOS_CAP_SUPERSPEED_USB         0x03
749
#define BOS_CAP_CONTAINER_ID           0x04
750
0
#define BOS_CAP_PLATFORM               0x05
751
#define BOS_CAP_POWER_DELIVERY         0x06
752
#define BOS_CAP_BATTERY_INFO           0x07
753
#define BOS_CAP_PD_CONSUMER_PORT       0x08
754
#define BOS_CAP_PD_PROVIDER_PORT       0x09
755
#define BOS_CAP_SUPERSPEED_PLUS        0x0A
756
#define BOS_CAP_PRECISION_TIME_MEAS    0x0B
757
#define BOS_CAP_WIRELESS_USB_EXT       0x0C
758
#define BOS_CAP_BILLBOARD              0x0D
759
#define BOS_CAP_AUTHENTICATION         0x0E
760
#define BOS_CAP_BILLBOARD_EX           0x0F
761
#define BOS_CAP_CONFIGURATION_SUMMARY  0x10
762
#define BOS_CAP_FWSTATUS               0x11
763
#define BOS_CAP_USB3_GEN_T             0x13
764
static const value_string usb_capability_vals[] = {
765
    {BOS_CAP_WIRELESS_USB,          "Wireless USB"},
766
    {BOS_CAP_USB_20_EXTENSION,      "USB 2.0 Extension Descriptor"},
767
    {BOS_CAP_SUPERSPEED_USB,        "SuperSpeed USB"},
768
    {BOS_CAP_CONTAINER_ID,          "Container ID"},
769
    {BOS_CAP_PLATFORM,              "Platform"},
770
    {BOS_CAP_POWER_DELIVERY,        "Power Delivery Capability"},
771
    {BOS_CAP_BATTERY_INFO,          "Battery Info Capability"},
772
    {BOS_CAP_PD_CONSUMER_PORT,      "PD Consumer Port Capability"},
773
    {BOS_CAP_PD_PROVIDER_PORT,      "PD Provider Port Capability"},
774
    {BOS_CAP_SUPERSPEED_PLUS,       "SuperSpeed Plus"},
775
    {BOS_CAP_PRECISION_TIME_MEAS,   "Precision Time Measurement"},
776
    {BOS_CAP_WIRELESS_USB_EXT,      "Wireless USB Ext"},
777
    {BOS_CAP_BILLBOARD,             "Billboard Capability"},
778
    {BOS_CAP_AUTHENTICATION,        "Authentication Capability Descriptor"},
779
    {BOS_CAP_BILLBOARD_EX,          "Billboard Ex capability"},
780
    {BOS_CAP_CONFIGURATION_SUMMARY, "Configuration Summary"},
781
    {BOS_CAP_FWSTATUS,              "Firmware Status"},
782
    {0x12,                          "TBD (reserved for USB Audio 4.0)"},
783
    {BOS_CAP_USB3_GEN_T,            "USB 3 Gen T Capability"},
784
    {0x14,                          "TBD (reserved for USB PD)"},
785
    {0, NULL}
786
};
787
static value_string_ext usb_capability_vals_ext = VALUE_STRING_EXT_INIT(usb_capability_vals);
788
789
15
#define SS_SPEED_SUPPORTED_BIT_LS        0
790
15
#define SS_SPEED_SUPPORTED_BIT_FS        1
791
15
#define SS_SPEED_SUPPORTED_BIT_HS        2
792
15
#define SS_SPEED_SUPPORTED_BIT_GEN1      3
793
15
#define SS_SPEED_SUPPORTED_STR_LS        "low-speed"
794
15
#define SS_SPEED_SUPPORTED_STR_FS        "full-speed"
795
15
#define SS_SPEED_SUPPORTED_STR_HS        "high-speed"
796
15
#define SS_SPEED_SUPPORTED_STR_GEN1      "Gen 1 speed"
797
static const value_string usb_ss_bFunctionalitySupport_vals[] = {
798
    {SS_SPEED_SUPPORTED_BIT_LS,        SS_SPEED_SUPPORTED_STR_LS},
799
    {SS_SPEED_SUPPORTED_BIT_FS,        SS_SPEED_SUPPORTED_STR_FS},
800
    {SS_SPEED_SUPPORTED_BIT_HS,        SS_SPEED_SUPPORTED_STR_HS},
801
    {SS_SPEED_SUPPORTED_BIT_GEN1,      SS_SPEED_SUPPORTED_STR_GEN1},
802
    {0, NULL}
803
};
804
static value_string_ext usb_ss_bFunctionalitySupport_vals_ext =
805
    VALUE_STRING_EXT_INIT(usb_ss_bFunctionalitySupport_vals);
806
static const true_false_string tfs_usb_ss_bmAttributes_reserved0 = {
807
    "FIXME: Shall be set to zero",
808
    "Shall be set to zero"
809
};
810
811
/* FreeBSD header */
812
813
/* Transfer mode */
814
#define FREEBSD_MODE_HOST       0
815
#define FREEBSD_MODE_DEVICE     1
816
static const value_string usb_freebsd_transfer_mode_vals[] = {
817
    {FREEBSD_MODE_HOST,   "Host"},
818
    {FREEBSD_MODE_DEVICE, "Device"},
819
    {0, NULL}
820
};
821
822
/* Type */
823
#define FREEBSD_URB_SUBMIT   0
824
#define FREEBSD_URB_COMPLETE 1
825
static const value_string usb_freebsd_urb_type_vals[] = {
826
    {FREEBSD_URB_SUBMIT,   "URB_SUBMIT"},
827
    {FREEBSD_URB_COMPLETE, "URB_COMPLETE"},
828
    {0, NULL}
829
};
830
831
/* Transfer type */
832
#define FREEBSD_URB_CONTROL     0
833
#define FREEBSD_URB_ISOCHRONOUS 1
834
#define FREEBSD_URB_BULK        2
835
#define FREEBSD_URB_INTERRUPT   3
836
837
static const value_string usb_freebsd_transfer_type_vals[] = {
838
    {FREEBSD_URB_CONTROL,     "URB_CONTROL"},
839
    {FREEBSD_URB_ISOCHRONOUS, "URB_ISOCHRONOUS"},
840
    {FREEBSD_URB_BULK,        "URB_BULK"},
841
    {FREEBSD_URB_INTERRUPT,   "URB_INTERRUPT"},
842
    {0, NULL}
843
};
844
845
/* Transfer flags */
846
15
#define FREEBSD_FLAG_FORCE_SHORT_XFER 0x00000001
847
15
#define FREEBSD_FLAG_SHORT_XFER_OK    0x00000002
848
15
#define FREEBSD_FLAG_SHORT_FRAMES_OK  0x00000004
849
15
#define FREEBSD_FLAG_PIPE_BOF         0x00000008
850
15
#define FREEBSD_FLAG_PROXY_BUFFER     0x00000010
851
15
#define FREEBSD_FLAG_EXT_BUFFER       0x00000020
852
15
#define FREEBSD_FLAG_MANUAL_STATUS    0x00000040
853
15
#define FREEBSD_FLAG_NO_PIPE_OK       0x00000080
854
15
#define FREEBSD_FLAG_STALL_PIPE       0x00000100
855
856
static int * const usb_xferflags_fields[] = {
857
    &hf_usb_xferflags_force_short_xfer,
858
    &hf_usb_xferflags_short_xfer_ok,
859
    &hf_usb_xferflags_short_frames_ok,
860
    &hf_usb_xferflags_pipe_bof,
861
    &hf_usb_xferflags_proxy_buffer,
862
    &hf_usb_xferflags_ext_buffer,
863
    &hf_usb_xferflags_manual_status,
864
    &hf_usb_xferflags_no_pipe_ok,
865
    &hf_usb_xferflags_stall_pipe,
866
    NULL
867
};
868
869
/* Transfer status */
870
15
#define FREEBSD_STATUS_OPEN              0x00000001
871
15
#define FREEBSD_STATUS_TRANSFERRING      0x00000002
872
15
#define FREEBSD_STATUS_DID_DMA_DELAY     0x00000004
873
15
#define FREEBSD_STATUS_DID_CLOSE         0x00000008
874
15
#define FREEBSD_STATUS_DRAINING          0x00000010
875
15
#define FREEBSD_STATUS_STARTED           0x00000020
876
15
#define FREEBSD_STATUS_BW_RECLAIMED      0x00000040
877
15
#define FREEBSD_STATUS_CONTROL_XFR       0x00000080
878
15
#define FREEBSD_STATUS_CONTROL_HDR       0x00000100
879
15
#define FREEBSD_STATUS_CONTROL_ACT       0x00000200
880
15
#define FREEBSD_STATUS_CONTROL_STALL     0x00000400
881
15
#define FREEBSD_STATUS_SHORT_FRAMES_OK   0x00000800
882
15
#define FREEBSD_STATUS_SHORT_XFER_OK     0x00001000
883
15
#define FREEBSD_STATUS_BDMA_ENABLE       0x00002000
884
15
#define FREEBSD_STATUS_BDMA_NO_POST_SYNC 0x00004000
885
15
#define FREEBSD_STATUS_BDMA_SETUP        0x00008000
886
15
#define FREEBSD_STATUS_ISOCHRONOUS_XFR   0x00010000
887
15
#define FREEBSD_STATUS_CURR_DMA_SET      0x00020000
888
15
#define FREEBSD_STATUS_CAN_CANCEL_IMMED  0x00040000
889
15
#define FREEBSD_STATUS_DOING_CALLBACK    0x00080000
890
891
static int * const usb_xferstatus_fields[] = {
892
    &hf_usb_xferstatus_open,
893
    &hf_usb_xferstatus_transferring,
894
    &hf_usb_xferstatus_did_dma_delay,
895
    &hf_usb_xferstatus_did_close,
896
    &hf_usb_xferstatus_draining,
897
    &hf_usb_xferstatus_started,
898
    &hf_usb_xferstatus_bw_reclaimed,
899
    &hf_usb_xferstatus_control_xfr,
900
    &hf_usb_xferstatus_control_hdr,
901
    &hf_usb_xferstatus_control_act,
902
    &hf_usb_xferstatus_control_stall,
903
    &hf_usb_xferstatus_short_frames_ok,
904
    &hf_usb_xferstatus_short_xfer_ok,
905
    &hf_usb_xferstatus_bdma_enable,
906
    &hf_usb_xferstatus_bdma_no_post_sync,
907
    &hf_usb_xferstatus_bdma_setup,
908
    &hf_usb_xferstatus_isochronous_xfr,
909
    &hf_usb_xferstatus_curr_dma_set,
910
    &hf_usb_xferstatus_can_cancel_immed,
911
    &hf_usb_xferstatus_doing_callback,
912
    NULL
913
};
914
915
/* USB errors */
916
#define FREEBSD_ERR_NORMAL_COMPLETION 0
917
#define FREEBSD_ERR_PENDING_REQUESTS  1
918
#define FREEBSD_ERR_NOT_STARTED       2
919
#define FREEBSD_ERR_INVAL             3
920
#define FREEBSD_ERR_NOMEM             4
921
#define FREEBSD_ERR_CANCELLED         5
922
#define FREEBSD_ERR_BAD_ADDRESS       6
923
#define FREEBSD_ERR_BAD_BUFSIZE       7
924
#define FREEBSD_ERR_BAD_FLAG          8
925
#define FREEBSD_ERR_NO_CALLBACK       9
926
#define FREEBSD_ERR_IN_USE            10
927
#define FREEBSD_ERR_NO_ADDR           11
928
#define FREEBSD_ERR_NO_PIPE           12
929
#define FREEBSD_ERR_ZERO_NFRAMES      13
930
#define FREEBSD_ERR_ZERO_MAXP         14
931
#define FREEBSD_ERR_SET_ADDR_FAILED   15
932
#define FREEBSD_ERR_NO_POWER          16
933
#define FREEBSD_ERR_TOO_DEEP          17
934
#define FREEBSD_ERR_IOERROR           18
935
#define FREEBSD_ERR_NOT_CONFIGURED    19
936
#define FREEBSD_ERR_TIMEOUT           20
937
#define FREEBSD_ERR_SHORT_XFER        21
938
#define FREEBSD_ERR_STALLED           22
939
#define FREEBSD_ERR_INTERRUPTED       23
940
#define FREEBSD_ERR_DMA_LOAD_FAILED   24
941
#define FREEBSD_ERR_BAD_CONTEXT       25
942
#define FREEBSD_ERR_NO_ROOT_HUB       26
943
#define FREEBSD_ERR_NO_INTR_THREAD    27
944
#define FREEBSD_ERR_NOT_LOCKED        28
945
946
static const value_string usb_freebsd_err_vals[] = {
947
    {FREEBSD_ERR_NORMAL_COMPLETION, "Normal completion"},
948
    {FREEBSD_ERR_PENDING_REQUESTS,  "Pending requests"},
949
    {FREEBSD_ERR_NOT_STARTED,       "Not started"},
950
    {FREEBSD_ERR_INVAL,             "Invalid"},
951
    {FREEBSD_ERR_NOMEM,             "No memory"},
952
    {FREEBSD_ERR_CANCELLED,         "Cancelled"},
953
    {FREEBSD_ERR_BAD_ADDRESS,       "Bad address"},
954
    {FREEBSD_ERR_BAD_BUFSIZE,       "Bad buffer size"},
955
    {FREEBSD_ERR_BAD_FLAG,          "Bad flag"},
956
    {FREEBSD_ERR_NO_CALLBACK,       "No callback"},
957
    {FREEBSD_ERR_IN_USE,            "In use"},
958
    {FREEBSD_ERR_NO_ADDR,           "No address"},
959
    {FREEBSD_ERR_NO_PIPE,           "No pipe"},
960
    {FREEBSD_ERR_ZERO_NFRAMES,      "Number of frames is zero"},
961
    {FREEBSD_ERR_ZERO_MAXP,         "MAXP is zero"},
962
    {FREEBSD_ERR_SET_ADDR_FAILED,   "Set address failed"},
963
    {FREEBSD_ERR_NO_POWER,          "No power"},
964
    {FREEBSD_ERR_TOO_DEEP,          "Too deep"},
965
    {FREEBSD_ERR_IOERROR,           "I/O error"},
966
    {FREEBSD_ERR_NOT_CONFIGURED,    "Not configured"},
967
    {FREEBSD_ERR_TIMEOUT,           "Timeout"},
968
    {FREEBSD_ERR_SHORT_XFER,        "Short transfer"},
969
    {FREEBSD_ERR_STALLED,           "Stalled"},
970
    {FREEBSD_ERR_INTERRUPTED,       "Interrupted"},
971
    {FREEBSD_ERR_DMA_LOAD_FAILED,   "DMA load failed"},
972
    {FREEBSD_ERR_BAD_CONTEXT,       "Bad context"},
973
    {FREEBSD_ERR_NO_ROOT_HUB,       "No root hub"},
974
    {FREEBSD_ERR_NO_INTR_THREAD,    "No interrupt thread"},
975
    {FREEBSD_ERR_NOT_LOCKED,        "Not locked"},
976
    {0, NULL}
977
};
978
979
/* USB speeds */
980
#define FREEBSD_SPEED_VARIABLE 0
981
#define FREEBSD_SPEED_LOW      1
982
#define FREEBSD_SPEED_FULL     2
983
#define FREEBSD_SPEED_HIGH     3
984
#define FREEBSD_SPEED_SUPER    4
985
986
static const value_string usb_freebsd_speed_vals[] = {
987
    {FREEBSD_SPEED_VARIABLE, "Variable"},
988
    {FREEBSD_SPEED_LOW,      "Low"},
989
    {FREEBSD_SPEED_FULL,     "Full"},
990
    {FREEBSD_SPEED_HIGH,     "High"},
991
    {FREEBSD_SPEED_SUPER,    "Super"},
992
    {0, NULL}
993
};
994
995
/* Frame flags */
996
15
#define FREEBSD_FRAMEFLAG_READ         0x00000001
997
55
#define FREEBSD_FRAMEFLAG_DATA_FOLLOWS 0x00000002
998
999
static int * const usb_frame_flags_fields[] = {
1000
    &hf_usb_frame_flags_read,
1001
    &hf_usb_frame_flags_data_follows,
1002
    NULL
1003
};
1004
1005
static const value_string usb_linux_urb_type_vals[] = {
1006
    {URB_SUBMIT,   "URB_SUBMIT"},
1007
    {URB_COMPLETE, "URB_COMPLETE"},
1008
    {URB_ERROR,    "URB_ERROR"},
1009
    {0, NULL}
1010
};
1011
1012
static const value_string usb_linux_transfer_type_vals[] = {
1013
    {URB_CONTROL,                       "URB_CONTROL"},
1014
    {URB_ISOCHRONOUS,                   "URB_ISOCHRONOUS"},
1015
    {URB_INTERRUPT,                     "URB_INTERRUPT"},
1016
    {URB_BULK,                          "URB_BULK"},
1017
    {0, NULL}
1018
};
1019
1020
static const value_string usb_transfer_type_and_direction_vals[] = {
1021
    {URB_CONTROL,                       "URB_CONTROL out"},
1022
    {URB_ISOCHRONOUS,                   "URB_ISOCHRONOUS out"},
1023
    {URB_INTERRUPT,                     "URB_INTERRUPT out"},
1024
    {URB_BULK,                          "URB_BULK out"},
1025
    {URB_CONTROL | URB_TRANSFER_IN,     "URB_CONTROL in"},
1026
    {URB_ISOCHRONOUS | URB_TRANSFER_IN, "URB_ISOCHRONOUS in"},
1027
    {URB_INTERRUPT | URB_TRANSFER_IN,   "URB_INTERRUPT in"},
1028
    {URB_BULK | URB_TRANSFER_IN,        "URB_BULK in"},
1029
    {0, NULL}
1030
};
1031
1032
static const value_string usb_endpoint_direction_vals[] = {
1033
    {0, "OUT"},
1034
    {1, "IN"},
1035
    {0, NULL}
1036
};
1037
1038
static const range_string usb_setup_flag_rvals[] = {
1039
    {0, 0, "relevant"},
1040
    {1, 255, "not relevant"},
1041
    {0, 0, NULL}
1042
};
1043
1044
static const range_string usb_data_flag_rvals[] = {
1045
    {0, 0, "present"},
1046
    {1, 255, "not present"},
1047
    {0, 0, NULL}
1048
};
1049
1050
extern value_string_ext ext_usb_vendors_vals;
1051
extern value_string_ext ext_usb_products_vals;
1052
extern value_string_ext ext_usb_audio_subclass_vals;
1053
extern value_string_ext ext_usb_com_subclass_vals;
1054
extern value_string_ext ext_usb_massstorage_subclass_vals;
1055
extern value_string_ext linux_negative_errno_vals_ext;
1056
1057
/*
1058
 * Standard descriptor types.
1059
 *
1060
 * all class specific descriptor types were removed from this list
1061
 * a descriptor type is not globally unique
1062
 * dissectors for the USB classes should provide their own value string
1063
 *  and pass it to dissect_usb_descriptor_header()
1064
 *
1065
 */
1066
0
#define USB_DT_DEVICE                          1
1067
0
#define USB_DT_CONFIG                          2
1068
0
#define USB_DT_STRING                          3
1069
0
#define USB_DT_INTERFACE                       4
1070
0
#define USB_DT_ENDPOINT                        5
1071
0
#define USB_DT_DEVICE_QUALIFIER                6
1072
0
#define USB_DT_OTHER_SPEED_CONFIG              7
1073
#define USB_DT_INTERFACE_POWER                 8
1074
/* these are from a minor usb 2.0 revision (ECN) */
1075
#define USB_DT_OTG                             9
1076
#define USB_DT_DEBUG                          10
1077
0
#define USB_DT_INTERFACE_ASSOCIATION          11
1078
/* these are from usb 3.0 specification */
1079
0
#define USB_DT_BOS                          0x0F
1080
0
#define USB_DT_DEVICE_CAPABILITY            0x10
1081
0
#define USB_DT_SUPERSPEED_EP_COMPANION      0x30
1082
/* these are from usb 3.1 specification */
1083
#define USB_DT_SUPERSPEED_ISO_EP_COMPANION  0x31
1084
1085
/* There are only Standard Descriptor Types, Class-specific types are
1086
   provided by "usb.descriptor" descriptors table*/
1087
static const value_string std_descriptor_type_vals[] = {
1088
    {USB_DT_DEVICE,                         "DEVICE"},
1089
    {USB_DT_CONFIG,                         "CONFIGURATION"},
1090
    {USB_DT_STRING,                         "STRING"},
1091
    {USB_DT_INTERFACE,                      "INTERFACE"},
1092
    {USB_DT_ENDPOINT,                       "ENDPOINT"},
1093
    {USB_DT_DEVICE_QUALIFIER,               "DEVICE QUALIFIER"},
1094
    {USB_DT_OTHER_SPEED_CONFIG,             "OTHER SPEED CONFIG"},
1095
    {USB_DT_INTERFACE_POWER,                "INTERFACE POWER"},
1096
    {USB_DT_OTG,                            "OTG"},
1097
    {USB_DT_DEBUG,                          "DEBUG"},
1098
    {USB_DT_INTERFACE_ASSOCIATION,          "INTERFACE ASSOCIATION"},
1099
    {USB_DT_BOS,                            "BOS"},
1100
    {USB_DT_DEVICE_CAPABILITY,              "DEVICE CAPABILITY"},
1101
    {USB_DT_SUPERSPEED_EP_COMPANION,        "SUPERSPEED USB ENDPOINT COMPANION"},
1102
    {USB_DT_SUPERSPEED_ISO_EP_COMPANION,    "SUPERSPEED PLUS ISOCHRONOUS ENDPOINT COMPANION"},
1103
    {0,NULL}
1104
};
1105
static value_string_ext std_descriptor_type_vals_ext =
1106
               VALUE_STRING_EXT_INIT(std_descriptor_type_vals);
1107
1108
/*
1109
 * Feature selectors.
1110
 * Per USB 3.1 spec, Table 9-7
1111
 */
1112
#define USB_FS_ENDPOINT_HALT            0
1113
#define USB_FS_FUNCTION_SUSPEND         0 /* same as ENDPOINT_HALT */
1114
#define USB_FS_DEVICE_REMOTE_WAKEUP     1
1115
#define USB_FS_TEST_MODE                2
1116
#define USB_FS_B_HNP_ENABLE             3
1117
#define USB_FS_A_HNP_SUPPORT            4
1118
#define USB_FS_A_ALT_HNP_SUPPORT        5
1119
#define USB_FS_WUSB_DEVICE              6
1120
#define USB_FS_U1_ENABLE                48
1121
#define USB_FS_U2_ENABLE                49
1122
#define USB_FS_LTM_ENABLE               50
1123
#define USB_FS_B3_NTF_HOST_REL          51
1124
#define USB_FS_B3_RSP_ENABLE            52
1125
#define USB_FS_LDM_ENABLE               53
1126
1127
static const value_string usb_endpoint_feature_selector_vals[] = {
1128
    {USB_FS_ENDPOINT_HALT,              "ENDPOINT HALT"},
1129
    {0, NULL}
1130
};
1131
1132
static const value_string usb_interface_feature_selector_vals[] = {
1133
    {USB_FS_FUNCTION_SUSPEND,           "FUNCTION SUSPEND"},
1134
    {0, NULL}
1135
};
1136
1137
static const value_string usb_device_feature_selector_vals[] = {
1138
    {USB_FS_DEVICE_REMOTE_WAKEUP,       "DEVICE REMOTE WAKEUP"},
1139
    {USB_FS_TEST_MODE,                  "TEST MODE"},
1140
    {USB_FS_B_HNP_ENABLE,               "B HNP ENABLE"},
1141
    {USB_FS_A_HNP_SUPPORT,              "A HNP SUPPORT"},
1142
    {USB_FS_A_ALT_HNP_SUPPORT,          "A ALT HNP SUPPORT"},
1143
    {USB_FS_WUSB_DEVICE,                "WUSB DEVICE"},
1144
    {USB_FS_U1_ENABLE,                  "U1 ENABLE"},
1145
    {USB_FS_U2_ENABLE,                  "U2 ENABLE"},
1146
    {USB_FS_LTM_ENABLE,                 "LTM ENABLE"},
1147
    {USB_FS_B3_NTF_HOST_REL,            "B3 NTF HOST REL"},
1148
    {USB_FS_B3_RSP_ENABLE,              "B3 RSP ENABLE"},
1149
    {USB_FS_LDM_ENABLE,                 "LDM ENABLE"},
1150
    {0, NULL}
1151
};
1152
1153
1154
/* the transfer type in the endpoint descriptor, i.e. the type of the endpoint
1155
   (this is not the same as the URB transfer type) */
1156
0
#define USB_EP_CONTROL     0x00
1157
0
#define USB_EP_ISOCHRONOUS 0x01
1158
#define USB_EP_BULK        0x02
1159
0
#define USB_EP_INTERRUPT   0x03
1160
1161
static const value_string usb_bmAttributes_transfer_vals[] = {
1162
    {USB_EP_CONTROL,     "Control-Transfer"},
1163
    {USB_EP_ISOCHRONOUS, "Isochronous-Transfer"},
1164
    {USB_EP_BULK,        "Bulk-Transfer"},
1165
    {USB_EP_INTERRUPT,   "Interrupt-Transfer"},
1166
    {0, NULL}
1167
};
1168
1169
static const value_string usb_bmAttributes_sync_vals[] = {
1170
    {0x00,      "No Sync"},
1171
    {0x01,      "Asynchronous"},
1172
    {0x02,      "Adaptive"},
1173
    {0x03,      "Synchronous"},
1174
    {0, NULL}
1175
};
1176
1177
static const value_string usb_bmAttributes_behaviour_vals[] = {
1178
    {0x00,      "Data-Endpoint"},
1179
    {0x01,      "Explicit Feedback-Endpoint"},
1180
    {0x02,      "Implicit Feedback-Data-Endpoint"},
1181
    {0x03,      "Reserved"},
1182
    {0, NULL}
1183
};
1184
1185
static const value_string usb_wMaxPacketSize_slots_vals[]  = {
1186
    {0x00,      "1"},
1187
    {0x01,      "2"},
1188
    {0x02,      "3"},
1189
    {0x03,      "Reserved"},
1190
    {0, NULL}
1191
};
1192
1193
/* USBPcap versions up to 1.4.1.0 captures USB control as 2 or 3 packets:
1194
 *   * SETUP with 8 bytes of Setup data
1195
 *   * DATA with optional data (either OUT or IN)
1196
 *   * STATUS without any USB payload, only the pseudoheader
1197
 *
1198
 * USBPcap versions 1.5.0.0 and up captures USB control as 2 packets:
1199
 *   * SETUP with 8 bytes of Setup data and optional DATA OUT
1200
 *   * COMPLETE with optional DATA IN
1201
 *
1202
 * The SETUP/COMPLETE matches the way control transfers are captured by
1203
 * usbmon on Linux.
1204
 */
1205
1
#define USB_CONTROL_STAGE_SETUP    0x00
1206
2
#define USB_CONTROL_STAGE_DATA     0x01
1207
0
#define USB_CONTROL_STAGE_STATUS   0x02
1208
#define USB_CONTROL_STAGE_COMPLETE 0x03
1209
1210
static const value_string usb_control_stage_vals[] = {
1211
    {USB_CONTROL_STAGE_SETUP,    "Setup"},
1212
    {USB_CONTROL_STAGE_DATA,     "Data"},
1213
    {USB_CONTROL_STAGE_STATUS,   "Status"},
1214
    {USB_CONTROL_STAGE_COMPLETE, "Complete"},
1215
    {0, NULL}
1216
};
1217
1218
/* Extra URB code to indicate relevant USB IRPs that don't directly
1219
 * have any matching USB transfer.
1220
 */
1221
9
#define USBPCAP_URB_IRP_INFO 0xFE
1222
1223
static const value_string win32_usb_transfer_type_vals[] = {
1224
    {URB_CONTROL,                       "URB_CONTROL"},
1225
    {URB_ISOCHRONOUS,                   "URB_ISOCHRONOUS"},
1226
    {URB_INTERRUPT,                     "URB_INTERRUPT"},
1227
    {URB_BULK,                          "URB_BULK"},
1228
    {USBPCAP_URB_IRP_INFO,              "USB IRP Info"},
1229
    {0, NULL}
1230
};
1231
1232
static const value_string win32_urb_function_vals[] = {
1233
    {0x0000, "URB_FUNCTION_SELECT_CONFIGURATION"},
1234
    {0x0001, "URB_FUNCTION_SELECT_INTERFACE"},
1235
    {0x0002, "URB_FUNCTION_ABORT_PIPE"},
1236
    {0x0003, "URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL"},
1237
    {0x0004, "URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL"},
1238
    {0x0005, "URB_FUNCTION_GET_FRAME_LENGTH"},
1239
    {0x0006, "URB_FUNCTION_SET_FRAME_LENGTH"},
1240
    {0x0007, "URB_FUNCTION_GET_CURRENT_FRAME_NUMBER"},
1241
    {0x0008, "URB_FUNCTION_CONTROL_TRANSFER"},
1242
    {0x0009, "URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER"},
1243
    {0x000A, "URB_FUNCTION_ISOCH_TRANSFER"},
1244
    {0x000B, "URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE"},
1245
    {0x000C, "URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE"},
1246
    {0x000D, "URB_FUNCTION_SET_FEATURE_TO_DEVICE"},
1247
    {0x000E, "URB_FUNCTION_SET_FEATURE_TO_INTERFACE"},
1248
    {0x000F, "URB_FUNCTION_SET_FEATURE_TO_ENDPOINT"},
1249
    {0x0010, "URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE"},
1250
    {0x0011, "URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE"},
1251
    {0x0012, "URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT"},
1252
    {0x0013, "URB_FUNCTION_GET_STATUS_FROM_DEVICE"},
1253
    {0x0014, "URB_FUNCTION_GET_STATUS_FROM_INTERFACE"},
1254
    {0x0015, "URB_FUNCTION_GET_STATUS_FROM_ENDPOINT"},
1255
    {0x0016, "URB_FUNCTION_RESERVED_0X0016"},
1256
    {0x0017, "URB_FUNCTION_VENDOR_DEVICE"},
1257
    {0x0018, "URB_FUNCTION_VENDOR_INTERFACE"},
1258
    {0x0019, "URB_FUNCTION_VENDOR_ENDPOINT"},
1259
    {0x001A, "URB_FUNCTION_CLASS_DEVICE"},
1260
    {0x001B, "URB_FUNCTION_CLASS_INTERFACE"},
1261
    {0x001C, "URB_FUNCTION_CLASS_ENDPOINT"},
1262
    {0x001D, "URB_FUNCTION_RESERVE_0X001D"},
1263
    {0x001E, "URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL"},
1264
    {0x001F, "URB_FUNCTION_CLASS_OTHER"},
1265
    {0x0020, "URB_FUNCTION_VENDOR_OTHER"},
1266
    {0x0021, "URB_FUNCTION_GET_STATUS_FROM_OTHER"},
1267
    {0x0022, "URB_FUNCTION_CLEAR_FEATURE_TO_OTHER"},
1268
    {0x0023, "URB_FUNCTION_SET_FEATURE_TO_OTHER"},
1269
    {0x0024, "URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT"},
1270
    {0x0025, "URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT"},
1271
    {0x0026, "URB_FUNCTION_GET_CONFIGURATION"},
1272
    {0x0027, "URB_FUNCTION_GET_INTERFACE"},
1273
    {0x0028, "URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE"},
1274
    {0x0029, "URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE"},
1275
    {0x002A, "URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR"},
1276
    {0x002B, "URB_FUNCTION_RESERVE_0X002B"},
1277
    {0x002C, "URB_FUNCTION_RESERVE_0X002C"},
1278
    {0x002D, "URB_FUNCTION_RESERVE_0X002D"},
1279
    {0x002E, "URB_FUNCTION_RESERVE_0X002E"},
1280
    {0x002F, "URB_FUNCTION_RESERVE_0X002F"},
1281
    {0x0030, "URB_FUNCTION_SYNC_RESET_PIPE"},
1282
    {0x0031, "URB_FUNCTION_SYNC_CLEAR_STALL"},
1283
    {0x0032, "URB_FUNCTION_CONTROL_TRANSFER_EX"},
1284
    {0x0033, "URB_FUNCTION_RESERVE_0X0033"},
1285
    {0x0034, "URB_FUNCTION_RESERVE_0X0034"},
1286
    {0, NULL}
1287
};
1288
static value_string_ext win32_urb_function_vals_ext = VALUE_STRING_EXT_INIT(win32_urb_function_vals);
1289
1290
static const value_string win32_usbd_status_vals[] = {
1291
    {0x00000000, "USBD_STATUS_SUCCESS"},
1292
    {0x40000000, "USBD_STATUS_PENDING"},
1293
1294
    {0x80000200, "USBD_STATUS_INVALID_URB_FUNCTION"},
1295
    {0x80000300, "USBD_STATUS_INVALID_PARAMETER"},
1296
    {0x80000400, "USBD_STATUS_ERROR_BUSY"},
1297
    {0x80000600, "USBD_STATUS_INVALID_PIPE_HANDLE"},
1298
    {0x80000700, "USBD_STATUS_NO_BANDWIDTH"},
1299
    {0x80000800, "USBD_STATUS_INTERNAL_HC_ERROR"},
1300
    {0x80000900, "USBD_STATUS_ERROR_SHORT_TRANSFER"},
1301
1302
    {0xC0000001, "USBD_STATUS_CRC"},
1303
    {0xC0000002, "USBD_STATUS_BTSTUFF"},
1304
    {0xC0000003, "USBD_STATUS_DATA_TOGGLE_MISMATCH"},
1305
    {0xC0000004, "USBD_STATUS_STALL_PID"},
1306
    {0xC0000005, "USBD_STATUS_DEV_NOT_RESPONDING"},
1307
    {0xC0000006, "USBD_STATUS_PID_CHECK_FAILURE"},
1308
    {0xC0000007, "USBD_STATUS_UNEXPECTED_PID"},
1309
    {0xC0000008, "USBD_STATUS_DATA_OVERRUN"},
1310
    {0xC0000009, "USBD_STATUS_DATA_UNDERRUN"},
1311
    {0xC000000A, "USBD_STATUS_RESERVED1"},
1312
    {0xC000000B, "USBD_STATUS_RESERVED2"},
1313
    {0xC000000C, "USBD_STATUS_BUFFER_OVERRUN"},
1314
    {0xC000000D, "USBD_STATUS_BUFFER_UNDERRUN"},
1315
    {0xC000000F, "USBD_STATUS_NOT_ACCESSED"},
1316
    {0xC0000010, "USBD_STATUS_FIFO"},
1317
    {0xC0000011, "USBD_STATUS_XACT_ERROR"},
1318
    {0xC0000012, "USBD_STATUS_BABBLE_DETECTED"},
1319
    {0xC0000013, "USBD_STATUS_DATA_BUFFER_ERROR"},
1320
    {0xC0000030, "USBD_STATUS_ENDPOINT_HALTED"},
1321
1322
    {0xC0000A00, "USBD_STATUS_BAD_START_FRAME"},
1323
    {0xC0000B00, "USBD_STATUS_ISOCH_REQUEST_FAILED"},
1324
    {0xC0000C00, "USBD_STATUS_FRAME_CONTROL_OWNED"},
1325
    {0xC0000D00, "USBD_STATUS_FRAME_CONTROL_NOT_OWNED"},
1326
    {0xC0000E00, "USBD_STATUS_NOT_SUPPORTED"},
1327
    {0xC0000F00, "USBD_STATUS_INVALID_CONFIGURATION_DESCRIPTOR"},
1328
    {0xC0001000, "USBD_STATUS_INSUFFICIENT_RESOURCES"},
1329
    {0xC0002000, "USBD_STATUS_SET_CONFIG_FAILED"},
1330
    {0xC0003000, "USBD_STATUS_BUFFER_TOO_SMALL"},
1331
    {0xC0004000, "USBD_STATUS_INTERFACE_NOT_FOUND"},
1332
    {0xC0005000, "USBD_STATUS_INVALID_PIPE_FLAGS"},
1333
    {0xC0006000, "USBD_STATUS_TIMEOUT"},
1334
    {0xC0007000, "USBD_STATUS_DEVICE_GONE"},
1335
    {0xC0008000, "USBD_STATUS_STATUS_NOT_MAPPED"},
1336
    {0xC0009000, "USBD_STATUS_HUB_INTERNAL_ERROR"},
1337
    {0xC0010000, "USBD_STATUS_CANCELED"},
1338
    {0xC0020000, "USBD_STATUS_ISO_NOT_ACCESSED_BY_HW"},
1339
    {0xC0030000, "USBD_STATUS_ISO_TD_ERROR"},
1340
    {0xC0040000, "USBD_STATUS_ISO_NA_LATE_USBPORT"},
1341
    {0xC0050000, "USBD_STATUS_ISO_NOT_ACCESSED_LATE"},
1342
    {0xC0100000, "USBD_STATUS_BAD_DESCRIPTOR"},
1343
    {0xC0100001, "USBD_STATUS_BAD_DESCRIPTOR_BLEN"},
1344
    {0xC0100002, "USBD_STATUS_BAD_DESCRIPTOR_TYPE"},
1345
    {0xC0100003, "USBD_STATUS_BAD_INTERFACE_DESCRIPTOR"},
1346
    {0xC0100004, "USBD_STATUS_BAD_ENDPOINT_DESCRIPTOR"},
1347
    {0xC0100005, "USBD_STATUS_BAD_INTERFACE_ASSOC_DESCRIPTOR"},
1348
    {0xC0100006, "USBD_STATUS_BAD_CONFIG_DESC_LENGTH"},
1349
    {0xC0100007, "USBD_STATUS_BAD_NUMBER_OF_INTERFACES"},
1350
    {0xC0100008, "USBD_STATUS_BAD_NUMBER_OF_ENDPOINTS"},
1351
    {0xC0100009, "USBD_STATUS_BAD_ENDPOINT_ADDRESS"},
1352
    {0, NULL}
1353
};
1354
static value_string_ext win32_usbd_status_vals_ext = VALUE_STRING_EXT_INIT(win32_usbd_status_vals);
1355
1356
static const value_string win32_usb_info_direction_vals[] = {
1357
    {0, "FDO -> PDO"},
1358
    {1, "PDO -> FDO"},
1359
    {0, NULL}
1360
};
1361
1362
static const value_string usb_cdc_protocol_vals[] = {
1363
    {0x00, "No class specific protocol required"},
1364
    {0x01, "AT Commands: V.250 etc"},
1365
    {0x02, "AT Commands defined by PCCA-101"},
1366
    {0x03, "AT Commands defined by PCCA-101 & Annex O"},
1367
    {0x04, "AT Commands defined by GSM 07.07"},
1368
    {0x05, "AT Commands defined by 3GPP 27.007"},
1369
    {0x06, "AT Commands defined by TIA for CDMA"},
1370
    {0x07, "Ethernet Emulation Model"},
1371
    {0xFE, "External Protocol: Commands defined by Command Set Functional Descriptor"},
1372
    {0xFF, "Vendor-specific"},
1373
    {0, NULL}
1374
};
1375
static value_string_ext usb_cdc_protocol_vals_ext = VALUE_STRING_EXT_INIT(usb_cdc_protocol_vals);
1376
1377
extern value_string_ext usb_massstorage_protocol_vals_ext;
1378
1379
static const value_string usb_cdc_data_protocol_vals[] = {
1380
    {0x00, "No class specific protocol required"},
1381
    {0x01, "Network Transfer Block"},
1382
    {0x02, "Network Transfer Block (IP + DSS)"},
1383
    {0x30, "Physical interface protocol for ISDN BRI"},
1384
    {0x31, "HDLC"},
1385
    {0x32, "Transparent"},
1386
    {0x50, "Management protocol for Q.921 data link protocol"},
1387
    {0x51, "Data link protocol for Q.931"},
1388
    {0x52, "TEI-multiplexor for Q.921 data link protocol"},
1389
    {0x90, "Data compression procedures"},
1390
    {0x91, "Euro-ISDN protocol control"},
1391
    {0x92, "V.24 rate adaptation to ISDN"},
1392
    {0x93, "CAPI Commands"},
1393
    {0xFE, "The protocol(s) are described using a Protocol Unit Functional Descriptors on Communications Class Interface"},
1394
    {0xFF, "Vendor-specific"},
1395
    {0, NULL}
1396
};
1397
static value_string_ext usb_cdc_data_protocol_vals_ext = VALUE_STRING_EXT_INIT(usb_cdc_data_protocol_vals);
1398
1399
static const value_string usb_hid_subclass_vals[] = {
1400
    {0, "No Subclass"},
1401
    {1, "Boot Interface"},
1402
    {0, NULL}
1403
};
1404
static value_string_ext usb_hid_subclass_vals_ext = VALUE_STRING_EXT_INIT(usb_hid_subclass_vals);
1405
1406
static const value_string usb_hid_boot_protocol_vals[] = {
1407
    {0, "None"},
1408
    {1, "Keyboard"},
1409
    {2, "Mouse"},
1410
    {0, NULL}
1411
};
1412
static value_string_ext usb_hid_boot_protocol_vals_ext = VALUE_STRING_EXT_INIT(usb_hid_boot_protocol_vals);
1413
1414
static const value_string usb_misc_subclass_vals[] = {
1415
    {0x03, "Cable Based Association Framework"},
1416
    {0x04, "RNDIS"},
1417
    {IF_SUBCLASS_MISC_U3V, "USB3 Vision"},
1418
    {0x06, "Stream Transport Efficient Protocol"},
1419
    {0, NULL}
1420
};
1421
static value_string_ext usb_misc_subclass_vals_ext = VALUE_STRING_EXT_INIT(usb_misc_subclass_vals);
1422
1423
1424
static const value_string usb_app_subclass_vals[] = {
1425
    {0x01, "Device Firmware Upgrade"},
1426
    {0x02, "IRDA Bridge"},
1427
    {0x03, "USB Test and Measurement Device"},
1428
    {0, NULL}
1429
};
1430
static value_string_ext usb_app_subclass_vals_ext = VALUE_STRING_EXT_INIT(usb_app_subclass_vals);
1431
1432
1433
static const value_string usb_app_dfu_protocol_vals[] = {
1434
    {0x01, "Runtime protocol"},
1435
    {0x02, "DFU mode protocol"},
1436
    {0, NULL}
1437
};
1438
static value_string_ext usb_app_dfu_protocol_vals_ext = VALUE_STRING_EXT_INIT(usb_app_dfu_protocol_vals);
1439
1440
static const value_string usb_app_irda_protocol_vals[] = {
1441
    {0x00, "IRDA Bridge device"},
1442
    {0, NULL}
1443
};
1444
static value_string_ext usb_app_irda_protocol_vals_ext = VALUE_STRING_EXT_INIT(usb_app_irda_protocol_vals);
1445
1446
static const value_string usb_app_usb_test_and_measurement_protocol_vals[] = {
1447
    {0x00, "USB Test and Measurement Device"},
1448
    {0x01, "USB Test and Measurement Device conforming to the USBTMC USB488 Subclass Specification"},
1449
    {0, NULL}
1450
};
1451
static value_string_ext usb_app_usb_test_and_measurement_protocol_vals_ext = VALUE_STRING_EXT_INIT(usb_app_usb_test_and_measurement_protocol_vals);
1452
1453
/* macOS */
1454
1455
/* Request Type */
1456
5
#define DARWIN_IO_SUBMIT   0
1457
#define DARWIN_IO_COMPLETE 1
1458
1459
1460
static const value_string usb_darwin_request_type_vals[] = {
1461
    {DARWIN_IO_SUBMIT,   "SUBMIT"},
1462
    {DARWIN_IO_COMPLETE, "COMPLETE"},
1463
    {0, NULL}
1464
};
1465
1466
/* Transfer type */
1467
static const value_string usb_darwin_endpoint_type_vals[] = {
1468
    {USB_EP_CONTROL,     "Control"},
1469
    {USB_EP_ISOCHRONOUS, "Isochronous"},
1470
    {USB_EP_BULK,        "Bulk"},
1471
    {USB_EP_INTERRUPT,   "Interrupt"},
1472
    {0, NULL}
1473
};
1474
1475
/* USB speeds */
1476
#define DARWIN_SPEED_LOW         0
1477
#define DARWIN_SPEED_FULL        1
1478
#define DARWIN_SPEED_HIGH        2
1479
#define DARWIN_SPEED_SUPER       3
1480
#define DARWIN_SPEED_SUPERPLUS   4
1481
1482
static const value_string usb_darwin_speed_vals[] = {
1483
    {DARWIN_SPEED_LOW,       "Low"},
1484
    {DARWIN_SPEED_FULL,      "Full"},
1485
    {DARWIN_SPEED_HIGH,      "High"},
1486
    {DARWIN_SPEED_SUPER,     "Super"},
1487
    {DARWIN_SPEED_SUPERPLUS, "Super+"},
1488
    {0, NULL}
1489
};
1490
1491
static const value_string darwin_usb_status_vals[] = {
1492
    {0x00000000, "kIOReturnSuccess"},
1493
    {0xe00002bc, "kIOReturnError"},
1494
    {0xe00002bd, "kIOReturnNoMemory"},
1495
    {0xe00002be, "kIOReturnNoResources"},
1496
    {0xe00002bf, "kIOReturnIPCError"},
1497
    {0xe00002c0, "kIOReturnNoDevice"},
1498
    {0xe00002c1, "kIOReturnNotPrivileged"},
1499
    {0xe00002c2, "kIOReturnBadArgument"},
1500
    {0xe00002c3, "kIOReturnLockedRead"},
1501
    {0xe00002c4, "kIOReturnLockedWrite"},
1502
    {0xe00002c5, "kIOReturnExclusiveAccess"},
1503
    {0xe00002c6, "kIOReturnBadMessageID"},
1504
    {0xe00002c7, "kIOReturnUnsupported"},
1505
    {0xe00002c8, "kIOReturnVMError"},
1506
    {0xe00002c9, "kIOReturnInternalError"},
1507
    {0xe00002ca, "kIOReturnIOError"},
1508
1509
    {0xe00002cc, "kIOReturnCannotLock"},
1510
    {0xe00002cd, "kIOReturnNotOpen"},
1511
    {0xe00002ce, "kIOReturnNotReadable"},
1512
    {0xe00002cf, "kIOReturnNotWritable"},
1513
    {0xe00002d0, "kIOReturnNotAligned"},
1514
    {0xe00002d1, "kIOReturnBadMedia"},
1515
    {0xe00002d2, "kIOReturnStillOpen"},
1516
    {0xe00002d3, "kIOReturnRLDError"},
1517
    {0xe00002d4, "kIOReturnDMAError"},
1518
    {0xe00002d5, "kIOReturnBusy"},
1519
    {0xe00002d6, "kIOReturnTimeout"},
1520
    {0xe00002d7, "kIOReturnOffline"},
1521
    {0xe00002d8, "kIOReturnNotReady"},
1522
    {0xe00002d9, "kIOReturnNotAttached"},
1523
    {0xe00002da, "kIOReturnNoChannels"},
1524
    {0xe00002db, "kIOReturnNoSpace"},
1525
1526
    {0xe00002dd, "kIOReturnPortExists"},
1527
    {0xe00002de, "kIOReturnCannotWire"},
1528
    {0xe00002df, "kIOReturnNoInterrupt"},
1529
    {0xe00002e0, "kIOReturnNoFrames"},
1530
    {0xe00002e1, "kIOReturnMessageTooLarge"},
1531
    {0xe00002e2, "kIOReturnNotPermitted"},
1532
    {0xe00002e3, "kIOReturnNoPower"},
1533
    {0xe00002e4, "kIOReturnNoMedia"},
1534
    {0xe00002e5, "kIOReturnUnformattedMedia"},
1535
    {0xe00002e6, "kIOReturnUnsupportedMode"},
1536
    {0xe00002e7, "kIOReturnUnderrun"},
1537
    {0xe00002e8, "kIOReturnOverrun"},
1538
    {0xe00002e9, "kIOReturnDeviceError"},
1539
    {0xe00002ea, "kIOReturnNoCompletion"},
1540
    {0xe00002eb, "kIOReturnAborted"},
1541
    {0xe00002ec, "kIOReturnNoBandwidth"},
1542
    {0xe00002ed, "kIOReturnNotResponding"},
1543
    {0xe00002ee, "kIOReturnIsoTooOld"},
1544
    {0xe00002ef, "kIOReturnIsoTooNew"},
1545
    {0xe00002f0, "kIOReturnNotFound"},
1546
    {0, NULL}
1547
};
1548
1549
static const uint32_t darwin_endpoint_to_linux[] =
1550
{
1551
    URB_CONTROL,
1552
    URB_ISOCHRONOUS,
1553
    URB_BULK,
1554
    URB_INTERRUPT,
1555
    URB_UNKNOWN
1556
};
1557
1558
static value_string_ext usb_darwin_status_vals_ext = VALUE_STRING_EXT_INIT(darwin_usb_status_vals);
1559
1560
1561
static const value_string netmon_event_id_vals[] = {
1562
    {1, "USBPORT_ETW_EVENT_HC_ADD USBPORT_ETW_EVENT_HC_ADD"},
1563
    {2, "USBPORT_ETW_EVENT_HC_REMOVAL USBPORT_ETW_EVENT_HC_REMOVAL"},
1564
    {3, "USBPORT_ETW_EVENT_HC_INFORMATION USBPORT_ETW_EVENT_HC_INFORMATION"},
1565
    {4, "USBPORT_ETW_EVENT_HC_START USBPORT_ETW_EVENT_HC_START"},
1566
    {5, "USBPORT_ETW_EVENT_HC_STOP USBPORT_ETW_EVENT_HC_STOP"},
1567
    {6, "USBPORT_ETW_EVENT_HC_SUSPEND USBPORT_ETW_EVENT_HC_SUSPEND"},
1568
    {7, "USBPORT_ETW_EVENT_HC_RESUME USBPORT_ETW_EVENT_HC_RESUME"},
1569
    {8, "USBPORT_ETW_EVENT_HC_ASYNC_SCHEDULE_ENABLE"},
1570
    {9, "USBPORT_ETW_EVENT_HC_ASYNC_SCHEDULE_DISABLE"},
1571
    {10, "USBPORT_ETW_EVENT_HC_PERIODIC_SCHEDULE_ENABLE"},
1572
    {11, "USBPORT_ETW_EVENT_HC_PERIODIC_SCHEDULE_DISABLE"},
1573
    {12, "USBPORT_ETW_EVENT_DEVICE_CREATE"},
1574
    {13, "USBPORT_ETW_EVENT_DEVICE_INITIALIZE"},
1575
    {14, "USBPORT_ETW_EVENT_DEVICE_REMOVAL"},
1576
    {15, "USBPORT_ETW_EVENT_DEVICE_INFORMATION"},
1577
    {16, "USBPORT_ETW_EVENT_DEVICE_IDLE_STATE_SET"},
1578
    {17, "USBPORT_ETW_EVENT_DEVICE_IDLE_STATE_CLEAR"},
1579
    {18, "USBPORT_ETW_EVENT_ENDPOINT_OPEN"},
1580
    {19, "USBPORT_ETW_EVENT_ENDPOINT_CLOSE USBPORT_ETW_EVENT_ENDPOINT_CLOSE"},
1581
    {20, "USBPORT_ETW_EVENT_ENDPOINT_INFORMATION"},
1582
    {21, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SELECT_CONFIGURATION"},
1583
    {22, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SELECT_INTERFACE"},
1584
    {23, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_CURRENT_FRAME_NUMBER"},
1585
    {24, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CONTROL_TRANSFER"},
1586
    {25, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CONTROL_TRANSFER_EX"},
1587
    {26, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER"},
1588
    {27, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_ISOCH_TRANSFER"},
1589
    {28, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE"},
1590
    {29, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE"},
1591
    {30, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT"},
1592
    {31, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT"},
1593
    {32, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE"},
1594
    {33, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE"},
1595
    {34, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_FEATURE_TO_DEVICE"},
1596
    {35, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_FEATURE_TO_INTERFACE"},
1597
    {36, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_FEATURE_TO_ENDPOINT"},
1598
    {37, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE"},
1599
    {38, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE"},
1600
    {39, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT"},
1601
    {40, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLEAR_FEATURE_TO_OTHER"},
1602
    {41, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_FEATURE_TO_OTHER"},
1603
    {42, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_STATUS_FROM_DEVICE"},
1604
    {43, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_STATUS_FROM_INTERFACE"},
1605
    {44, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_STATUS_FROM_ENDPOINT"},
1606
    {45, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_STATUS_FROM_OTHER"},
1607
    {46, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_VENDOR_DEVICE"},
1608
    {47, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_VENDOR_INTERFACE"},
1609
    {48, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_VENDOR_ENDPOINT"},
1610
    {49, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLASS_DEVICE"},
1611
    {50, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLASS_INTERFACE"},
1612
    {51, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLASS_ENDPOINT"},
1613
    {52, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_CLASS_OTHER"},
1614
    {53, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_VENDOR_OTHER"},
1615
    {54, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_ABORT_PIPE"},
1616
    {55, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL"},
1617
    {56, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SYNC_RESET_PIPE"},
1618
    {57, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SYNC_CLEAR_STALL"},
1619
    {58, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_CONFIGURATION"},
1620
    {59, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_INTERFACE"},
1621
    {60, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR"},
1622
    {61, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL"},
1623
    {62, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL"},
1624
    {63, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_GET_FRAME_LENGTH"},
1625
    {64, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_SET_FRAME_LENGTH"},
1626
    {65, "USBPORT_ETW_EVENT_DISPATCH_URB_FUNCTION_RESERVED"},
1627
    {66, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_CONTROL_TRANSFER"},
1628
    {67, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_CONTROL_TRANSFER_EX"},
1629
    {68, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_CONTROL_TRANSFER_DATA"},
1630
    {69, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_CONTROL_TRANSFER_EX_DATA"},
1631
    {70, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER"},
1632
    {71, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER_DATA"},
1633
    {72, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_ISOCH_TRANSFER"},
1634
    {73, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_ISOCH_TRANSFER_DATA"},
1635
    {74, "USBPORT_ETW_EVENT_INTERNAL_URB_FUNCTION_CONTROL_TRANSFER"},
1636
    {75, "USBPORT_ETW_EVENT_COMPLETE_INTERNAL_URB_FUNCTION_CONTROL_TRANSFER"},
1637
    {76, "USBPORT_ETW_EVENT_COMPLETE_INTERNAL_URB_FUNCTION_CONTROL_TRANSFER_DATA"},
1638
    {77, "USBPORT_ETW_EVENT_COMPLETE_URB_FUNCTION_ABORT_PIPE"},
1639
    {78, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_HEADER_LENGTH_WARNING"},
1640
    {79, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_FUNCTION"},
1641
    {80, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_HEADER_LENGTH"},
1642
    {81, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_DEVICE_HANDLE"},
1643
    {82, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_FUNCTION_NOT_SUPPORTED"},
1644
    {83, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_FUNCTION_RESERVED"},
1645
    {84, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_DUE_TO_HC_SUSPEND"},
1646
    {85, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_URB_LINK"},
1647
    {86, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_PIPE_HANDLE"},
1648
    {87, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_ZERO_BW_PIPE_HANDLE"},
1649
    {88, "USBPORT_ETW_EVENT_DISPATCH_URB_NOP_ZERO_BW_PIPE_HANDLE_REQUEST"},
1650
    {89, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_CONTROL_TRANSFER_ENDPOINT"},
1651
    {90, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_CONTROL_TRANSFER_BUFFER_LENGTH"},
1652
    {91, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_BULK_OR_INTERRUPT_TRANSFER_ENDPOINT"},
1653
    {92, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_BULK_OR_INTERRUPT_TRANSFER_BUFFER_LENGTH"},
1654
    {93, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_ISOCHRONOUS_TRANSFER_ENDPOINT"},
1655
    {94, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_NULL_TRANSFER_BUFFER_AND_MDL"},
1656
    {95, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_NON_NULL_TRANSFER_BUFFER_MDL"},
1657
    {96, "USBPORT_ETW_EVENT_DISPATCH_URB_ALLOCATE_MDL_FAILURE"},
1658
    {97, "USBPORT_ETW_EVENT_DISPATCH_URB_ALLOCATE_TRANSFER_CONTEXT_FAILURE"},
1659
    {98, "USBPORT_ETW_EVENT_DISPATCH_URB_NOP_ROOTHUB_PIPE_HANDLE_REQUEST"},
1660
    {99, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_ISOCHRONOUS_ZERO_LENGTH"},
1661
    {100, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_ISOCHRONOUS_NUM_PACKETS"},
1662
    {101, "USBPORT_ETW_EVENT_DISPATCH_URB_INVALID_ISOCHRONOUS_START_FRAME"},
1663
    {102, "USBPORT_ETW_EVENT_IRP_CANCEL"},
1664
    {103, "USBPORT_ETW_EVENT_USBUSER_OP_RAW_RESET_PORT_DISPATCH"},
1665
    {104, "USBPORT_ETW_EVENT_USBUSER_OP_RAW_RESET_PORT_STATUS1"},
1666
    {105, "USBPORT_ETW_EVENT_USBUSER_OP_RAW_RESET_PORT_STATUS2"},
1667
    {106, "USBPORT_ETW_EVENT_USBUSER_OP_RAW_RESET_PORT_STATUS3"},
1668
    {107, "USBPORT_ETW_EVENT_USBUSER_OP_RAW_RESET_PORT_COMPLETE"},
1669
    {108, "USBPORT_ETW_EVENT_USBUSER_OP_SEND_ONE_PACKET_DISPATCH"},
1670
    {109, "USBPORT_ETW_EVENT_USBUSER_OP_SEND_ONE_PACKET_DISPATCH_DATA"},
1671
    {110, "USBPORT_ETW_EVENT_USBUSER_OP_SEND_ONE_PACKET_TIMEOUT"},
1672
    {111, "USBPORT_ETW_EVENT_USBUSER_OP_SEND_ONE_PACKET_COMPLETE"},
1673
    {112, "USBPORT_ETW_EVENT_USBUSER_OP_SEND_ONE_PACKET_COMPLETE_DATA"},
1674
    {113, "USBPORT_ETW_EVENT_CODE_EXECUTION_TIME"},
1675
    {114, "USBPORT_ETW_EVENT_PUT_SGLIST_EXECUTION_TIME"},
1676
    {115, "USBPORT_ETW_EVENT_BUILD_SGLIST_EXECUTION_TIME"},
1677
    {1024, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_START_DISPATCH"},
1678
    {1025, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_START_COMPLETE"},
1679
    {1026, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_START_COMPLETE_ERROR_1"},
1680
    {1027, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_START_COMPLETE_ERROR_2"},
1681
    {1028, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_START_COMPLETE_ERROR_3"},
1682
    {1029, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_START_COMPLETE_ERROR_4"},
1683
    {1030, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_START_COMPLETE_ERROR_5"},
1684
    {1031, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_STOP_DISPATCH"},
1685
    {1032, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_STOP_COMPLETE"},
1686
    {1033, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_SUSPEND_DISPATCH"},
1687
    {1034, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_SUSPEND_COMPLETE"},
1688
    {1035, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_DISPATCH"},
1689
    {1036, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_COMPLETE"},
1690
    {1037, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_COMPLETE_ERROR_1"},
1691
    {1038, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_COMPLETE_ERROR_2"},
1692
    {1039, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_COMPLETE_ERROR_3"},
1693
    {1040, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_COMPLETE_ERROR_4"},
1694
    {1041, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_COMPLETE_ERROR_5"},
1695
    {1042, "USBPORT_ETW_EVENT_HC_EHCI_MINIPORT_RESUME_COMPLETE_ERROR_6"},
1696
    {2048, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_START_DISPATCH"},
1697
    {2049, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_START_COMPLETE"},
1698
    {2050, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_START_COMPLETE_ERROR_1"},
1699
    {2051, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_START_COMPLETE_ERROR_2"},
1700
    {2052, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_START_COMPLETE_ERROR_3"},
1701
    {2053, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_START_COMPLETE_ERROR_4"},
1702
    {2054, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_START_COMPLETE_ERROR_5"},
1703
    {2055, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_STOP_DISPATCH"},
1704
    {2056, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_STOP_COMPLETE"},
1705
    {2057, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_SUSPEND_DISPATCH"},
1706
    {2058, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_SUSPEND_COMPLETE"},
1707
    {2059, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_RESUME_DISPATCH"},
1708
    {2060, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_RESUME_COMPLETE"},
1709
    {2061, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_RESUME_COMPLETE_ERROR_1"},
1710
    {2062, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_RESUME_COMPLETE_ERROR_2"},
1711
    {2063, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_RESUME_COMPLETE_ERROR_3"},
1712
    {2064, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_RESUME_COMPLETE_ERROR_4"},
1713
    {2065, "USBPORT_ETW_EVENT_HC_OHCI_MINIPORT_RESUME_COMPLETE_ERROR_5"},
1714
    {3072, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_START_DISPATCH"},
1715
    {3073, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_START_COMPLETE"},
1716
    {3074, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_START_COMPLETE_ERROR_1"},
1717
    {3075, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_START_COMPLETE_ERROR_2"},
1718
    {3076, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_START_COMPLETE_ERROR_3"},
1719
    {3077, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_START_COMPLETE_ERROR_4"},
1720
    {3078, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_STOP_DISPATCH"},
1721
    {3079, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_STOP_COMPLETE"},
1722
    {3080, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_SUSPEND_DISPATCH"},
1723
    {3081, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_SUSPEND_COMPLETE"},
1724
    {3082, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_RESUME_DISPATCH"},
1725
    {3083, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_RESUME_COMPLETE"},
1726
    {3084, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_RESUME_COMPLETE_ERROR_1"},
1727
    {3085, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_RESUME_COMPLETE_ERROR_2"},
1728
    {3086, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_RESUME_COMPLETE_ERROR_3"},
1729
    {3087, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_RESUME_COMPLETE_ERROR_4"},
1730
    {3088, "USBPORT_ETW_EVENT_HC_UHCI_MINIPORT_RESUME_COMPLETE_ERROR_5"},
1731
    {3089, "USBPORT_ETW_EVENT_RTPM_TRANSITION"},
1732
    {3090, "USBPORT_ETW_EVENT_DISPATCH_WAIT_WAKE"},
1733
    {3091, "USBPORT_ETW_EVENT_COMPLETE_WAIT_WAKE"},
1734
    {0, NULL}
1735
};
1736
static value_string_ext netmon_event_id_vals_ext = VALUE_STRING_EXT_INIT(netmon_event_id_vals);
1737
1738
static const value_string netmon_urb_function_vals[] = {
1739
    {0x0000, "SELECT_CONFIGURATION"},
1740
    {0x0001, "SELECT_INTERFACE"},
1741
    {0x0002, "ABORT_PIPE"},
1742
    {0x0003, "TAKE_FRAME_LENGTH_CONTROL"},
1743
    {0x0004, "RELEASE_FRAME_LENGTH_CONTROL"},
1744
    {0x0005, "GET_FRAME_LENGTH"},
1745
    {0x0006, "SET_FRAME_LENGTH"},
1746
    {0x0007, "GET_CURRENT_FRAME_NUMBER"},
1747
    {0x0008, "CONTROL_TRANSFER"},
1748
    {0x0009, "BULK_OR_INTERRUPT_TRANSFER"},
1749
    {0x000A, "ISOCH_TRANSFER"},
1750
    {0x000B, "GET_DESCRIPTOR_FROM_DEVICE"},
1751
    {0x000C, "SET_DESCRIPTOR_TO_DEVICE"},
1752
    {0x000D, "SET_FEATURE_TO_DEVICE"},
1753
    {0x000E, "SET_FEATURE_TO_INTERFACE"},
1754
    {0x000F, "SET_FEATURE_TO_ENDPOINT"},
1755
    {0x0010, "CLEAR_FEATURE_TO_DEVICE"},
1756
    {0x0011, "CLEAR_FEATURE_TO_INTERFACE"},
1757
    {0x0012, "CLEAR_FEATURE_TO_ENDPOINT"},
1758
    {0x0013, "GET_STATUS_FROM_DEVICE"},
1759
    {0x0014, "GET_STATUS_FROM_INTERFACE"},
1760
    {0x0015, "GET_STATUS_FROM_ENDPOINT"},
1761
    {0x0016, "RESERVED"},
1762
    {0x0017, "VENDOR_DEVICE"},
1763
    {0x0018, "VENDOR_INTERFACE"},
1764
    {0x0019, "VENDOR_ENDPOINT"},
1765
    {0x001A, "CLASS_DEVICE"},
1766
    {0x001B, "CLASS_INTERFACE"},
1767
    {0x001C, "CLASS_ENDPOINT"},
1768
    {0x001D, "RESERVE_0X001D"},
1769
    {0x001E, "SYNC_RESET_PIPE_AND_CLEAR_STALL"},
1770
    {0x001F, "CLASS_OTHER"},
1771
    {0x0020, "VENDOR_OTHER"},
1772
    {0x0021, "GET_STATUS_FROM_OTHER"},
1773
    {0x0022, "CLEAR_FEATURE_TO_OTHER"},
1774
    {0x0023, "SET_FEATURE_TO_OTHER"},
1775
    {0x0024, "GET_DESCRIPTOR_FROM_ENDPOINT"},
1776
    {0x0025, "SET_DESCRIPTOR_TO_ENDPOINT"},
1777
    {0x0026, "GET_CONFIGURATION"},
1778
    {0x0027, "GET_INTERFACE"},
1779
    {0x0028, "GET_DESCRIPTOR_FROM_INTERFACE"},
1780
    {0x0029, "SET_DESCRIPTOR_TO_INTERFACE"},
1781
    {0x002A, "GET_MS_FEATURE_DESCRIPTOR"},
1782
    {0x0030, "SYNC_RESET_PIPE"},
1783
    {0x0031, "SYNC_CLEAR_STALL"},
1784
    {0x0032, "CONTROL_TRANSFER_EX"},
1785
    {0x0035, "OPEN_STATIC_STREAMS"},
1786
    {0x0036, "CLOSE_STATIC_STREAMS"},
1787
    {0x0037, "BULK_OR_INTERRUPT_TRANSFER_USING_CHAINED_MDL"},
1788
    {0x0038, "ISOCH_TRANSFER_USING_CHAINED_MDL"},
1789
    {0, NULL}
1790
};
1791
static value_string_ext netmon_urb_function_vals_ext = VALUE_STRING_EXT_INIT(netmon_urb_function_vals);
1792
1793
1794
void proto_register_usb(void);
1795
void proto_reg_handoff_usb(void);
1796
1797
/* USB address handling */
1798
static int usb_addr_to_str(const address* addr, char *buf, int buf_len _U_)
1799
56
{
1800
56
    const uint8_t *addrp = (const uint8_t *)addr->data;
1801
1802
56
    if(pletohu32(&addrp[0])==0xffffffff){
1803
28
        (void) g_strlcpy(buf, "host", buf_len);
1804
28
    } else {
1805
28
        snprintf(buf, buf_len, "%d.%d.%d", pletohu16(&addrp[8]),
1806
28
                        pletohu32(&addrp[0]), pletohu32(&addrp[4]) & 0x0f);
1807
28
    }
1808
1809
56
    return (int)(strlen(buf)+1);
1810
56
}
1811
1812
static int usb_addr_str_len(const address* addr _U_)
1813
56
{
1814
56
    return 50;
1815
56
}
1816
1817
1818
/* This keys provide information for DecodeBy and other dissector via
1819
   per packet data: p_get_proto_data()/p_add_proto_data() */
1820
8
#define USB_BUS_ID           0
1821
8
#define USB_DEVICE_ADDRESS   1
1822
0
#define USB_VENDOR_ID        2
1823
0
#define USB_PRODUCT_ID       3
1824
0
#define USB_DEVICE_CLASS     4
1825
0
#define USB_DEVICE_SUBCLASS  5
1826
0
#define USB_DEVICE_PROTOCOL  6
1827
1828
static void
1829
usb_device_prompt(packet_info *pinfo, char* result)
1830
0
{
1831
0
    snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Bus ID %u \nDevice Address %u\nas ",
1832
0
            GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_BUS_ID)),
1833
0
            GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_ADDRESS)));
1834
0
}
1835
1836
static void *
1837
usb_device_value(packet_info *pinfo)
1838
0
{
1839
0
    uint32_t value = GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_BUS_ID)) << 16;
1840
0
    value |= GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_ADDRESS));
1841
0
    return GUINT_TO_POINTER(value);
1842
0
}
1843
1844
static void
1845
usb_product_prompt(packet_info *pinfo, char* result)
1846
0
{
1847
0
    snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Vendor ID 0x%04x \nProduct ID 0x%04x\nas ",
1848
0
            GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_VENDOR_ID)),
1849
0
            GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_PRODUCT_ID)));
1850
0
}
1851
1852
static void *
1853
usb_product_value(packet_info *pinfo)
1854
0
{
1855
0
    uint32_t value = GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_VENDOR_ID)) << 16;
1856
0
    value |= GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_PRODUCT_ID));
1857
0
    return GUINT_TO_POINTER(value);
1858
0
}
1859
1860
static void
1861
usb_protocol_prompt(packet_info *pinfo, char* result)
1862
0
{
1863
0
    snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Class ID 0x%04x \nSubclass ID 0x%04x\nProtocol 0x%04x\nas ",
1864
0
            GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_CLASS)),
1865
0
            GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_SUBCLASS)),
1866
0
            GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_PROTOCOL)));
1867
0
}
1868
1869
static void *
1870
usb_protocol_value(packet_info *pinfo)
1871
0
{
1872
0
    uint32_t value = GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_CLASS)) << 16;
1873
0
    value |= GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_SUBCLASS)) << 8;
1874
0
    value |= GPOINTER_TO_UINT(p_get_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_PROTOCOL));
1875
0
    return GUINT_TO_POINTER(value);
1876
0
}
1877
1878
static build_valid_func   usb_product_da_build_value[1] = {usb_product_value};
1879
static decode_as_value_t  usb_product_da_values         = {usb_product_prompt, 1, usb_product_da_build_value};
1880
static decode_as_t        usb_product_da = {
1881
        "usb", "usb.product",
1882
        1, 0, &usb_product_da_values, NULL, NULL,
1883
        decode_as_default_populate_list, decode_as_default_reset,
1884
        decode_as_default_change, NULL, NULL, NULL };
1885
1886
static build_valid_func   usb_device_da_build_value[1] = {usb_device_value};
1887
static decode_as_value_t  usb_device_da_values         = {usb_device_prompt, 1, usb_device_da_build_value};
1888
static decode_as_t        usb_device_da = {
1889
        "usb", "usb.device",
1890
        1, 0, &usb_device_da_values, NULL, NULL,
1891
        decode_as_default_populate_list, decode_as_default_reset,
1892
        decode_as_default_change, NULL, NULL, NULL };
1893
1894
static build_valid_func   usb_protocol_da_build_value[1] = {usb_protocol_value};
1895
static decode_as_value_t  usb_protocol_da_values         = {usb_protocol_prompt, 1, usb_protocol_da_build_value};
1896
static decode_as_t        usb_protocol_da = {
1897
        "usb", "usb.protocol",
1898
        1, 0, &usb_protocol_da_values, NULL, NULL,
1899
        decode_as_default_populate_list, decode_as_default_reset,
1900
        decode_as_default_change, NULL, NULL, NULL };
1901
1902
1903
static usb_conv_info_t *
1904
get_usb_conv_info(conversation_t *conversation)
1905
28
{
1906
28
    usb_conv_info_t *usb_conv_info;
1907
1908
    /* do we have conversation specific data ? */
1909
28
    usb_conv_info = (usb_conv_info_t *)conversation_get_proto_data(conversation, proto_usb);
1910
28
    if (!usb_conv_info) {
1911
        /* no not yet so create some */
1912
19
        usb_conv_info = wmem_new0(wmem_file_scope(), usb_conv_info_t);
1913
19
        usb_conv_info->interfaceClass    = IF_CLASS_UNKNOWN;
1914
19
        usb_conv_info->interfaceSubclass = IF_SUBCLASS_UNKNOWN;
1915
19
        usb_conv_info->interfaceProtocol = IF_PROTOCOL_UNKNOWN;
1916
19
        usb_conv_info->deviceVendor      = DEV_VENDOR_UNKNOWN;
1917
19
        usb_conv_info->deviceProduct     = DEV_PRODUCT_UNKNOWN;
1918
19
        usb_conv_info->deviceVersion     = DEV_VERSION_UNKNOWN;
1919
19
        usb_conv_info->alt_settings      = wmem_array_new(wmem_file_scope(), sizeof(usb_alt_setting_t));
1920
19
        usb_conv_info->transactions      = wmem_tree_new(wmem_file_scope());
1921
19
        usb_conv_info->descriptor_transfer_type = URB_UNKNOWN;
1922
19
        usb_conv_info->max_packet_size   = 0;
1923
1924
19
        conversation_add_proto_data(conversation, proto_usb, usb_conv_info);
1925
19
    }
1926
1927
28
    return usb_conv_info;
1928
28
}
1929
1930
1931
/* urb_info_t contains some components that are valid only for one specific packet
1932
   clear_usb_conv_tmp_data() clears these components, it should be called
1933
   before we dissect a new packet */
1934
static void clear_usb_conv_tmp_data(urb_info_t *urb)
1935
28
{
1936
    /* caller must have checked that urb!= NULL */
1937
1938
28
    urb->direction = P2P_DIR_UNKNOWN;
1939
28
    urb->transfer_type = URB_UNKNOWN;
1940
28
    urb->is_request = false;
1941
28
    urb->is_setup = false;
1942
28
    urb->setup_requesttype = 0;
1943
28
    urb->speed = USB_SPEED_UNKNOWN;
1944
1945
    /* when we parse the configuration, interface and endpoint
1946
       descriptors, we store the current interface class in endpoint 0's
1947
       conversation
1948
1949
       this must be cleared since endpoint 0 does not belong to any
1950
       interface class
1951
1952
       we used to clear these info in dissect_usb_configuration_descriptor()
1953
       this doesn't work when the descriptor parsing throws an exception */
1954
1955
28
    if (urb->conv && (urb->endpoint == 0)) {
1956
8
        urb->conv->interfaceClass    = IF_CLASS_UNKNOWN;
1957
8
        urb->conv->interfaceSubclass = IF_SUBCLASS_UNKNOWN;
1958
8
        urb->conv->interfaceProtocol = IF_PROTOCOL_UNKNOWN;
1959
8
    }
1960
28
}
1961
1962
static conversation_t *
1963
get_usb_conversation(packet_info *pinfo,
1964
                     address *src_addr, address *dst_addr,
1965
                     uint32_t src_endpoint, uint32_t dst_endpoint)
1966
28
{
1967
28
    conversation_t *conversation;
1968
1969
    /*
1970
     * Do we have a conversation for this connection?
1971
     */
1972
28
    conversation = find_conversation(pinfo->num,
1973
28
                               src_addr, dst_addr,
1974
28
                               conversation_pt_to_conversation_type(pinfo->ptype),
1975
28
                               src_endpoint, dst_endpoint, 0);
1976
28
    if (conversation) {
1977
9
        return conversation;
1978
9
    }
1979
1980
    /* We don't yet have a conversation, so create one. */
1981
19
    conversation = conversation_new(pinfo->num,
1982
19
                           src_addr, dst_addr,
1983
19
                           conversation_pt_to_conversation_type(pinfo->ptype),
1984
19
                           src_endpoint, dst_endpoint, 0);
1985
19
    return conversation;
1986
28
}
1987
1988
/* Fetch or create usb_conv_info for a specified interface. */
1989
usb_conv_info_t *
1990
get_usb_iface_conv_info(packet_info *pinfo, uint8_t interface_num)
1991
0
{
1992
0
    conversation_t *conversation;
1993
0
    uint32_t if_port;
1994
1995
0
    if_port = GUINT32_TO_LE(INTERFACE_PORT | interface_num);
1996
1997
0
    if (pinfo->srcport == NO_ENDPOINT) {
1998
0
        conversation = get_usb_conversation(pinfo, &pinfo->src, &pinfo->dst, pinfo->srcport, if_port);
1999
0
    } else {
2000
0
        conversation = get_usb_conversation(pinfo, &pinfo->src, &pinfo->dst, if_port, pinfo->destport);
2001
0
    }
2002
2003
0
    return get_usb_conv_info(conversation);
2004
0
}
2005
2006
/* Fetch usb_conv_info for specified endpoint, return NULL if not found */
2007
usb_conv_info_t *
2008
get_existing_usb_ep_conv_info(packet_info* pinfo, uint16_t bus_id, uint16_t device_address, int endpoint)
2009
0
{
2010
0
    usb_address_t   *src_addr = wmem_new0(pinfo->pool, usb_address_t),
2011
0
                    *dst_addr = wmem_new0(pinfo->pool, usb_address_t);
2012
0
    address          src, dst;
2013
0
    conversation_t  *conversation;
2014
0
    usb_conv_info_t *usb_conv_info = NULL;
2015
2016
0
    src_addr->bus_id   = GUINT16_TO_LE(bus_id);
2017
0
    src_addr->device   = GUINT16_TO_LE(device_address);
2018
0
    src_addr->endpoint = GUINT32_TO_LE(endpoint);
2019
2020
0
    dst_addr->bus_id   = GUINT16_TO_LE(bus_id);
2021
0
    dst_addr->device   = 0xffffffff;
2022
0
    dst_addr->endpoint = NO_ENDPOINT;
2023
2024
0
    set_address(&src, usb_address_type, USB_ADDR_LEN, (char *)src_addr);
2025
0
    set_address(&dst, usb_address_type, USB_ADDR_LEN, (char *)dst_addr);
2026
2027
0
    conversation = find_conversation(pinfo->num, &src, &dst,
2028
0
                                     conversation_pt_to_conversation_type(PT_USB),
2029
0
                                     src_addr->endpoint, dst_addr->endpoint, 0);
2030
0
    if (conversation) {
2031
0
        usb_conv_info = (usb_conv_info_t *)conversation_get_proto_data(conversation, proto_usb);
2032
0
    }
2033
0
    return usb_conv_info;
2034
0
}
2035
2036
static const char* usb_conv_get_filter_type(conv_item_t* conv, conv_filter_type_e filter)
2037
0
{
2038
0
    if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == usb_address_type))
2039
0
        return "usb.src";
2040
2041
0
    if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == usb_address_type))
2042
0
        return "usb.dst";
2043
2044
0
    if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == usb_address_type))
2045
0
        return "usb.addr";
2046
2047
0
    return CONV_FILTER_INVALID;
2048
0
}
2049
2050
static ct_dissector_info_t usb_ct_dissector_info = {&usb_conv_get_filter_type};
2051
2052
static tap_packet_status
2053
usb_conversation_packet(void *pct, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip _U_, tap_flags_t flags)
2054
0
{
2055
0
    conv_hash_t *hash = (conv_hash_t*) pct;
2056
0
    hash->flags = flags;
2057
2058
0
    add_conversation_table_data(hash, &pinfo->src, &pinfo->dst, 0, 0, 1, pinfo->fd->pkt_len, &pinfo->rel_ts, &pinfo->abs_ts, &usb_ct_dissector_info, CONVERSATION_NONE);
2059
2060
0
    return TAP_PACKET_REDRAW;
2061
0
}
2062
2063
static const char* usb_endpoint_get_filter_type(endpoint_item_t* endpoint, conv_filter_type_e filter)
2064
0
{
2065
0
    if ((filter == CONV_FT_ANY_ADDRESS) && (endpoint->myaddress.type == usb_address_type))
2066
0
        return "usb.addr";
2067
2068
0
    return CONV_FILTER_INVALID;
2069
0
}
2070
2071
static const char*
2072
usb_col_filter_str(const address* addr _U_, bool is_src)
2073
0
{
2074
0
    return is_src ? "usb.src" : "usb.dst";
2075
0
}
2076
2077
static et_dissector_info_t usb_endpoint_dissector_info = {&usb_endpoint_get_filter_type};
2078
2079
static tap_packet_status
2080
usb_endpoint_packet(void *pit, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip _U_, tap_flags_t flags)
2081
0
{
2082
0
    conv_hash_t *hash = (conv_hash_t*) pit;
2083
0
    hash->flags = flags;
2084
2085
    /* Take two "add" passes per packet, adding for each direction, ensures that all
2086
       packets are counted properly (even if address is sending to itself)
2087
       XXX - this could probably be done more efficiently inside endpoint_table */
2088
0
    add_endpoint_table_data(hash, &pinfo->src, 0, true, 1, pinfo->fd->pkt_len, &usb_endpoint_dissector_info, ENDPOINT_NONE);
2089
0
    add_endpoint_table_data(hash, &pinfo->dst, 0, false, 1, pinfo->fd->pkt_len, &usb_endpoint_dissector_info, ENDPOINT_NONE);
2090
2091
0
    return TAP_PACKET_REDRAW;
2092
0
}
2093
2094
/* SETUP dissectors */
2095
2096
2097
/*
2098
 * These dissectors are used to dissect the setup part and the data
2099
 * for URB_CONTROL_INPUT / CLEAR FEATURE
2100
 */
2101
2102
2103
/* 9.4.1 */
2104
static int
2105
dissect_usb_setup_clear_feature_request(packet_info *pinfo _U_, proto_tree *tree,
2106
                                        tvbuff_t *tvb, int offset,
2107
                                        urb_info_t *urb)
2108
0
{
2109
0
    uint8_t recip;
2110
2111
0
    if (urb) {
2112
0
        recip = USB_RECIPIENT(urb->usb_trans_info->setup.requesttype);
2113
2114
        /* feature selector, zero/interface/endpoint */
2115
0
        switch (recip) {
2116
0
        case RQT_SETUP_RECIPIENT_DEVICE:
2117
0
            proto_tree_add_item(tree, hf_usb_device_wFeatureSelector, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2118
0
            offset += 2;
2119
0
            proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2120
0
            break;
2121
2122
0
        case RQT_SETUP_RECIPIENT_INTERFACE:
2123
0
            proto_tree_add_item(tree, hf_usb_interface_wFeatureSelector, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2124
0
            offset += 2;
2125
0
            proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2126
0
            break;
2127
2128
0
        case RQT_SETUP_RECIPIENT_ENDPOINT:
2129
0
            proto_tree_add_item(tree, hf_usb_endpoint_wFeatureSelector, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2130
0
            offset += 2;
2131
0
            proto_tree_add_item(tree, hf_usb_wEndpoint, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2132
0
            break;
2133
2134
0
        case RQT_SETUP_RECIPIENT_OTHER:
2135
0
        default:
2136
0
            proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2137
0
            offset += 2;
2138
0
            proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2139
0
            break;
2140
0
        }
2141
0
    } else {
2142
        /* No conversation information, so recipient type is unknown */
2143
0
        proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2144
0
        offset += 2;
2145
0
        proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2146
0
    }
2147
0
    offset += 2;
2148
2149
    /* length */
2150
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2151
0
    offset += 2;
2152
2153
0
    return offset;
2154
0
}
2155
2156
static int
2157
dissect_usb_setup_clear_feature_response(packet_info *pinfo _U_, proto_tree *tree _U_,
2158
                                         tvbuff_t *tvb _U_, int offset,
2159
                                         urb_info_t *urb _U_)
2160
0
{
2161
0
    return offset;
2162
0
}
2163
2164
2165
/*
2166
 * These dissectors are used to dissect the setup part and the data
2167
 * for URB_CONTROL_INPUT / GET CONFIGURATION
2168
 */
2169
2170
2171
/* 9.4.2 */
2172
static int
2173
dissect_usb_setup_get_configuration_response(packet_info *pinfo _U_, proto_tree *tree _U_,
2174
                                             tvbuff_t *tvb _U_, int offset,
2175
                                             urb_info_t *urb _U_)
2176
0
{
2177
0
    proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2178
0
    offset += 1;
2179
2180
0
    return offset;
2181
0
}
2182
2183
2184
/*
2185
 * These dissectors are used to dissect the setup part and the data
2186
 * for URB_CONTROL_INPUT / GET DESCRIPTOR
2187
 */
2188
2189
proto_item * dissect_usb_descriptor_header(proto_tree *tree,
2190
                                           tvbuff_t *tvb, int offset,
2191
                                           value_string_ext *type_val_str)
2192
0
{
2193
0
    uint8_t     desc_type;
2194
0
    proto_item *length_item;
2195
2196
2197
0
    length_item = proto_tree_add_item(tree, hf_usb_bLength,
2198
0
          tvb, offset, 1,  ENC_LITTLE_ENDIAN);
2199
0
    offset++;
2200
2201
0
    desc_type = tvb_get_uint8(tvb, offset);
2202
    /* if the caller provided no class specific value string, we're
2203
     * using the standard descriptor types */
2204
0
    if (!type_val_str)
2205
0
        type_val_str = &std_descriptor_type_vals_ext;
2206
2207
0
    proto_tree_add_uint_format_value(tree, hf_usb_bDescriptorType,
2208
0
        tvb, offset, 1, desc_type, "0x%02x (%s)", desc_type,
2209
0
        val_to_str_ext_const(desc_type, type_val_str, "unknown"));
2210
2211
0
    return length_item;
2212
0
}
2213
2214
static void
2215
dissect_max_packet_size0(packet_info *pinfo, proto_tree *tree,
2216
                         tvbuff_t *tvb, int offset,
2217
                         urb_info_t *urb, bool other_speed)
2218
0
{
2219
0
    proto_item  *item;
2220
0
    uint32_t     max_packet_size;
2221
0
    unsigned int sanitized_max_packet_size;
2222
0
    usb_speed_t  speed = urb->speed;
2223
2224
0
    item = proto_tree_add_item_ret_uint(tree, hf_usb_bMaxPacketSize0, tvb, offset, 1, ENC_LITTLE_ENDIAN, &max_packet_size);
2225
0
    if (other_speed) {
2226
0
        if (speed == USB_SPEED_FULL)
2227
0
            speed = USB_SPEED_HIGH;
2228
0
        else if (speed == USB_SPEED_HIGH)
2229
0
            speed = USB_SPEED_FULL;
2230
0
    }
2231
0
    sanitized_max_packet_size = sanitize_usb_max_packet_size(ENDPOINT_TYPE_CONTROL, speed, max_packet_size);
2232
0
    if (sanitized_max_packet_size != max_packet_size) {
2233
0
        expert_add_info_format(pinfo, item, &ei_usb_invalid_max_packet_size0,
2234
0
            "%s endpoint zero max packet size cannot be %u, using %d instead.",
2235
0
            try_val_to_str(speed, usb_speed_vals), max_packet_size, sanitized_max_packet_size);
2236
0
    }
2237
0
}
2238
2239
/* 9.6.2 */
2240
static int
2241
dissect_usb_device_qualifier_descriptor(packet_info *pinfo, proto_tree *parent_tree,
2242
                                        tvbuff_t *tvb, int offset,
2243
                                        urb_info_t *urb)
2244
0
{
2245
0
    proto_item *item;
2246
0
    proto_tree *tree;
2247
0
    proto_item *nitem;
2248
0
    int         old_offset = offset;
2249
0
    uint32_t    protocol;
2250
0
    const char *description;
2251
2252
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "DEVICE QUALIFIER DESCRIPTOR");
2253
2254
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
2255
0
    offset += 2;
2256
2257
    /* bcdUSB */
2258
0
    proto_tree_add_item(tree, hf_usb_bcdUSB, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2259
0
    offset += 2;
2260
2261
0
    protocol = tvb_get_ntoh24(tvb, offset);
2262
0
    description = val_to_str_ext_const(protocol, &usb_protocols_ext, "");
2263
2264
    /* bDeviceClass */
2265
0
    proto_tree_add_item(tree, hf_usb_bDeviceClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2266
0
    offset += 1;
2267
2268
    /* bDeviceSubClass */
2269
0
    proto_tree_add_item(tree, hf_usb_bDeviceSubClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2270
0
    offset += 1;
2271
2272
    /* bDeviceProtocol */
2273
0
    nitem = proto_tree_add_item(tree, hf_usb_bDeviceProtocol, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2274
0
    if (*description)
2275
0
        proto_item_append_text(nitem, " (%s)", description);
2276
0
    offset += 1;
2277
2278
0
    if (!pinfo->fd->visited) {
2279
0
        unsigned                k_bus_id;
2280
0
        unsigned                k_device_address;
2281
0
        unsigned                k_frame_number;
2282
0
        wmem_tree_key_t         key[4];
2283
0
        device_protocol_data_t  *device_protocol_data;
2284
2285
0
        k_frame_number = pinfo->num;
2286
0
        k_device_address = urb->device_address;
2287
0
        k_bus_id = urb->bus_id;
2288
2289
0
        key[0].length = 1;
2290
0
        key[0].key    = &k_device_address;
2291
0
        key[1].length = 1;
2292
0
        key[1].key    = &k_bus_id;
2293
0
        key[2].length = 1;
2294
0
        key[2].key    = &k_frame_number;
2295
0
        key[3].length = 0;
2296
0
        key[3].key    = NULL;
2297
2298
0
        device_protocol_data = wmem_new(wmem_file_scope(), device_protocol_data_t);
2299
0
        device_protocol_data->protocol = protocol;
2300
0
        device_protocol_data->bus_id = urb->bus_id;
2301
0
        device_protocol_data->device_address = urb->device_address;
2302
0
        wmem_tree_insert32_array(device_to_protocol_table, key, device_protocol_data);
2303
0
    }
2304
2305
    /* bMaxPacketSize0 */
2306
0
    dissect_max_packet_size0(pinfo, tree, tvb, offset, urb, true);
2307
0
    offset += 1;
2308
2309
    /* bNumConfigurations */
2310
0
    proto_tree_add_item(tree, hf_usb_bNumConfigurations, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2311
0
    offset += 1;
2312
2313
    /* one reserved byte */
2314
0
    offset += 1;
2315
2316
0
    proto_item_set_len(item, offset-old_offset);
2317
2318
0
    return offset;
2319
0
}
2320
2321
/* 9.6.1 */
2322
static int
2323
dissect_usb_device_descriptor(packet_info *pinfo, proto_tree *parent_tree,
2324
                              tvbuff_t *tvb, int offset,
2325
                              urb_info_t *urb)
2326
0
{
2327
0
    proto_item        *item;
2328
0
    proto_tree        *tree;
2329
0
    proto_item        *nitem;
2330
0
    int                old_offset = offset;
2331
0
    uint32_t           protocol;
2332
0
    const char        *description;
2333
0
    uint32_t           vendor_id;
2334
0
    uint32_t           product;
2335
0
    uint16_t           product_id;
2336
2337
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "DEVICE DESCRIPTOR");
2338
2339
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
2340
0
    offset += 2;
2341
2342
    /* bcdUSB */
2343
0
    proto_tree_add_item(tree, hf_usb_bcdUSB, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2344
0
    offset += 2;
2345
2346
0
    protocol = tvb_get_ntoh24(tvb, offset);
2347
0
    description = val_to_str_ext_const(protocol, &usb_protocols_ext, "");
2348
2349
    /* bDeviceClass */
2350
0
    proto_tree_add_item(tree, hf_usb_bDeviceClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2351
0
    offset += 1;
2352
2353
    /* bDeviceSubClass */
2354
0
    proto_tree_add_item(tree, hf_usb_bDeviceSubClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2355
0
    offset += 1;
2356
2357
    /* bDeviceProtocol */
2358
0
    nitem = proto_tree_add_item(tree, hf_usb_bDeviceProtocol, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2359
0
    if (*description)
2360
0
        proto_item_append_text(nitem, " (%s)", description);
2361
0
    offset += 1;
2362
2363
    /* bMaxPacketSize0 */
2364
0
    dissect_max_packet_size0(pinfo, tree, tvb, offset, urb, false);
2365
0
    offset += 1;
2366
2367
    /* if request was only for the first 8 bytes */
2368
    /* per 5.5.3 of USB2.0 Spec */
2369
0
    if (8 == urb->usb_trans_info->setup.wLength) {
2370
0
        proto_item_set_len(item, offset-old_offset);
2371
0
        return offset;
2372
0
    }
2373
2374
    /* idVendor */
2375
0
    proto_tree_add_item_ret_uint(tree, hf_usb_idVendor, tvb, offset, 2, ENC_LITTLE_ENDIAN, &vendor_id);
2376
0
    urb->conv->deviceVendor = (uint16_t)vendor_id;
2377
0
    offset += 2;
2378
2379
    /* idProduct */
2380
0
    product_id = tvb_get_letohs(tvb, offset);
2381
0
    urb->conv->deviceProduct = product_id;
2382
0
    product = (uint16_t)vendor_id << 16 | product_id;
2383
2384
0
    proto_tree_add_uint_format_value(tree, hf_usb_idProduct, tvb, offset, 2, product_id, "%s (0x%04x)",
2385
0
                                     val_to_str_ext_const(product, &ext_usb_products_vals, "Unknown"),
2386
0
                                     product_id);
2387
0
    offset += 2;
2388
2389
    /* bcdDevice */
2390
0
    urb->conv->deviceVersion = tvb_get_letohs(tvb, offset);
2391
0
    proto_tree_add_item(tree, hf_usb_bcdDevice, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2392
0
    offset += 2;
2393
2394
0
    if (!pinfo->fd->visited) {
2395
0
        unsigned                k_bus_id;
2396
0
        unsigned                k_device_address;
2397
0
        unsigned                k_frame_number;
2398
0
        wmem_tree_key_t         key[4];
2399
0
        device_product_data_t   *device_product_data;
2400
0
        device_protocol_data_t  *device_protocol_data;
2401
2402
0
        k_frame_number = pinfo->num;
2403
0
        k_device_address = urb->device_address;
2404
0
        k_bus_id = urb->bus_id;
2405
2406
0
        key[0].length = 1;
2407
0
        key[0].key    = &k_device_address;
2408
0
        key[1].length = 1;
2409
0
        key[1].key    = &k_bus_id;
2410
0
        key[2].length = 1;
2411
0
        key[2].key    = &k_frame_number;
2412
0
        key[3].length = 0;
2413
0
        key[3].key    = NULL;
2414
2415
0
        device_product_data = wmem_new(wmem_file_scope(), device_product_data_t);
2416
0
        device_product_data->vendor = vendor_id;
2417
0
        device_product_data->product = product_id;
2418
0
        device_product_data->device = urb->conv->deviceVersion;
2419
0
        device_product_data->bus_id = urb->bus_id;
2420
0
        device_product_data->device_address = urb->device_address;
2421
0
        wmem_tree_insert32_array(device_to_product_table, key, device_product_data);
2422
2423
0
        device_protocol_data = wmem_new(wmem_file_scope(), device_protocol_data_t);
2424
0
        device_protocol_data->protocol = protocol;
2425
0
        device_protocol_data->bus_id = urb->bus_id;
2426
0
        device_protocol_data->device_address = urb->device_address;
2427
2428
0
        wmem_tree_insert32_array(device_to_protocol_table, key, device_protocol_data);
2429
0
    }
2430
2431
    /* iManufacturer */
2432
0
    proto_tree_add_item(tree, hf_usb_iManufacturer, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2433
0
    offset += 1;
2434
2435
    /* iProduct */
2436
0
    proto_tree_add_item(tree, hf_usb_iProduct, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2437
0
    offset += 1;
2438
2439
    /* iSerialNumber */
2440
0
    urb->conv->iSerialNumber = tvb_get_uint8(tvb, offset);
2441
0
    proto_tree_add_item(tree, hf_usb_iSerialNumber, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2442
0
    offset += 1;
2443
2444
    /* bNumConfigurations */
2445
0
    proto_tree_add_item(tree, hf_usb_bNumConfigurations, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2446
0
    offset += 1;
2447
2448
0
    proto_item_set_len(item, offset-old_offset);
2449
2450
0
    return offset;
2451
0
}
2452
2453
/* 9.6.7 */
2454
static int
2455
dissect_usb_string_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
2456
                              tvbuff_t *tvb, int offset,
2457
                              urb_info_t *urb)
2458
0
{
2459
0
    proto_item *item;
2460
0
    proto_tree *tree;
2461
0
    int         old_offset = offset;
2462
0
    uint8_t     len;
2463
0
    proto_item *len_item;
2464
0
    usb_trans_info_t *usb_trans_info;
2465
2466
0
    usb_trans_info = urb->usb_trans_info;
2467
2468
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "STRING DESCRIPTOR");
2469
2470
0
    len = tvb_get_uint8(tvb, offset);
2471
    /* The USB spec says that the languages / the string are UTF16 and not
2472
       0-terminated, i.e. the length field must contain an even number */
2473
0
    if (len & 0x1) {
2474
        /* bLength */
2475
0
        len_item = proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2476
0
        expert_add_info(pinfo, len_item, &ei_usb_bLength_even);
2477
2478
        /* bDescriptorType */
2479
0
        proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset+1, 1, ENC_LITTLE_ENDIAN);
2480
0
    }
2481
0
    else
2482
0
       len_item = dissect_usb_descriptor_header(tree, tvb, offset, NULL);
2483
0
    offset += 2;
2484
2485
    /* Report an error, and give up, if the length is < 2 */
2486
0
    if (len < 2) {
2487
0
        expert_add_info(pinfo, len_item, &ei_usb_bLength_too_short);
2488
0
        return offset;
2489
0
    }
2490
2491
0
    if (!usb_trans_info->u.get_descriptor.usb_index) {
2492
        /* list of languages */
2493
0
        while (offset >= old_offset && len > (offset - old_offset)) {
2494
            /* wLANGID */
2495
0
            proto_tree_add_item(tree, hf_usb_wLANGID, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2496
0
            offset+=2;
2497
0
        }
2498
0
    } else {
2499
        /* UTF-16 string */
2500
        /* handle case of host requesting only substring */
2501
0
        uint8_t len_str = MIN(len-2, usb_trans_info->setup.wLength -2);
2502
0
        proto_tree_add_item(tree, hf_usb_bString, tvb, offset, len_str, ENC_UTF_16 | ENC_LITTLE_ENDIAN);
2503
0
        offset += len_str;
2504
0
    }
2505
2506
0
    proto_item_set_len(item, offset-old_offset);
2507
2508
0
    return offset;
2509
0
}
2510
2511
2512
2513
/* 9.6.5 */
2514
static int
2515
dissect_usb_interface_descriptor(packet_info *pinfo, proto_tree *parent_tree,
2516
                                 tvbuff_t *tvb, int offset,
2517
                                 urb_info_t *urb)
2518
0
{
2519
0
    proto_item       *item;
2520
0
    proto_tree       *tree;
2521
0
    const char       *class_str  = NULL;
2522
0
    int               old_offset = offset;
2523
0
    uint8_t           len;
2524
0
    uint8_t           interface_num;
2525
0
    uint8_t           alt_setting;
2526
0
    usb_trans_info_t *usb_trans_info;
2527
2528
0
    usb_trans_info = urb->usb_trans_info;
2529
2530
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "INTERFACE DESCRIPTOR");
2531
2532
0
    len = tvb_get_uint8(tvb, offset);
2533
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
2534
0
    offset += 2;
2535
2536
    /* bInterfaceNumber */
2537
0
    interface_num = tvb_get_uint8(tvb, offset);
2538
0
    proto_tree_add_item(tree, hf_usb_bInterfaceNumber, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2539
0
    urb->conv->interfaceNum = interface_num;
2540
0
    offset += 1;
2541
2542
    /* bAlternateSetting */
2543
0
    alt_setting = tvb_get_uint8(tvb, offset);
2544
0
    proto_tree_add_item(tree, hf_usb_bAlternateSetting, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2545
0
    offset += 1;
2546
2547
    /* bNumEndpoints */
2548
0
    proto_tree_add_item(tree, hf_usb_bNumEndpoints, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2549
0
    offset += 1;
2550
2551
    /* bInterfaceClass */
2552
0
    proto_tree_add_item(tree, hf_usb_bInterfaceClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2553
    /* save the class so we can access it later in the endpoint descriptor */
2554
0
    urb->conv->interfaceClass = tvb_get_uint8(tvb, offset);
2555
2556
0
    class_str = val_to_str_ext(pinfo->pool, urb->conv->interfaceClass, &usb_class_vals_ext, "unknown (0x%X)");
2557
0
    proto_item_append_text(item, " (%u.%u): class %s", interface_num, alt_setting, class_str);
2558
2559
0
    if (!pinfo->fd->visited) {
2560
0
        usb_alt_setting_t alternate_setting;
2561
2562
        /* Register conversation for this interface in case CONTROL messages are sent to it */
2563
0
        usb_trans_info->interface_info = get_usb_iface_conv_info(pinfo, interface_num);
2564
2565
0
        alternate_setting.altSetting = alt_setting;
2566
0
        alternate_setting.interfaceClass = tvb_get_uint8(tvb, offset);
2567
0
        alternate_setting.interfaceSubclass = tvb_get_uint8(tvb, offset+1);
2568
0
        alternate_setting.interfaceProtocol = tvb_get_uint8(tvb, offset+2);
2569
0
        alternate_setting.interfaceNum = interface_num;
2570
0
        wmem_array_append_one(usb_trans_info->interface_info->alt_settings, alternate_setting);
2571
2572
0
        if (alt_setting == 0) {
2573
            /* By default let's assume alternate setting 0 will be used */
2574
2575
0
            usb_trans_info->interface_info->interfaceClass = alternate_setting.interfaceClass;
2576
0
            usb_trans_info->interface_info->interfaceSubclass = alternate_setting.interfaceSubclass;
2577
0
            usb_trans_info->interface_info->interfaceProtocol = alternate_setting.interfaceProtocol;
2578
0
            usb_trans_info->interface_info->interfaceNum      = alternate_setting.interfaceNum;
2579
0
            usb_trans_info->interface_info->deviceVendor      = urb->conv->deviceVendor;
2580
0
            usb_trans_info->interface_info->deviceProduct     = urb->conv->deviceProduct;
2581
0
            usb_trans_info->interface_info->deviceVersion     = urb->conv->deviceVersion;
2582
0
        }
2583
0
    }
2584
0
    offset += 1;
2585
2586
    /* bInterfaceSubClass */
2587
0
    switch (urb->conv->interfaceClass) {
2588
0
    case IF_CLASS_AUDIO:
2589
0
        proto_tree_add_item(tree, hf_usb_bInterfaceSubClass_audio, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2590
0
        break;
2591
0
    case IF_CLASS_COMMUNICATIONS:
2592
0
        proto_tree_add_item(tree, hf_usb_bInterfaceSubClass_cdc, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2593
0
        break;
2594
0
    case IF_CLASS_MASS_STORAGE:
2595
0
        proto_tree_add_item(tree, hf_usb_bInterfaceSubClass_massstorage, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2596
0
        break;
2597
0
    case IF_CLASS_HID:
2598
0
        proto_tree_add_item(tree, hf_usb_bInterfaceSubClass_hid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2599
0
        break;
2600
0
    case IF_CLASS_MISCELLANEOUS:
2601
0
        proto_tree_add_item(tree, hf_usb_bInterfaceSubClass_misc, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2602
0
        break;
2603
0
    case IF_CLASS_APPLICATION_SPECIFIC:
2604
0
        proto_tree_add_item(tree, hf_usb_bInterfaceSubClass_app, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2605
0
        break;
2606
0
    default:
2607
0
        proto_tree_add_item(tree, hf_usb_bInterfaceSubClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2608
0
    }
2609
2610
    /* save the subclass so we can access it later in class-specific descriptors */
2611
0
    urb->conv->interfaceSubclass = tvb_get_uint8(tvb, offset);
2612
0
    offset += 1;
2613
2614
    /* bInterfaceProtocol */
2615
0
    switch (urb->conv->interfaceClass) {
2616
0
    case IF_CLASS_COMMUNICATIONS:
2617
0
        proto_tree_add_item(tree, hf_usb_bInterfaceProtocol_cdc, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2618
0
        break;
2619
0
    case IF_CLASS_MASS_STORAGE:
2620
0
        proto_tree_add_item(tree, hf_usb_bInterfaceProtocol_massstorage, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2621
0
        break;
2622
0
    case IF_CLASS_CDC_DATA:
2623
0
        proto_tree_add_item(tree, hf_usb_bInterfaceProtocol_cdc_data, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2624
0
        break;
2625
0
    case IF_CLASS_APPLICATION_SPECIFIC:
2626
0
        switch (urb->conv->interfaceSubclass) {
2627
0
        case 0x01:
2628
0
            proto_tree_add_item(tree, hf_usb_bInterfaceProtocol_app_dfu, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2629
0
            break;
2630
0
        case 0x02:
2631
0
            proto_tree_add_item(tree, hf_usb_bInterfaceProtocol_app_irda, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2632
0
            break;
2633
0
        case 0x03:
2634
0
            proto_tree_add_item(tree, hf_usb_bInterfaceProtocol_app_usb_test_and_measurement, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2635
0
            break;
2636
0
        default:
2637
0
            proto_tree_add_item(tree, hf_usb_bInterfaceProtocol, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2638
0
        }
2639
0
        break;
2640
0
    case IF_CLASS_HID:
2641
0
        if (urb->conv->interfaceSubclass == 1) {
2642
0
            proto_tree_add_item(tree, hf_usb_bInterfaceProtocol_hid_boot, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2643
0
            break;
2644
0
        }
2645
2646
0
        proto_tree_add_item(tree, hf_usb_bInterfaceProtocol, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2647
2648
0
        break;
2649
0
    default:
2650
0
        proto_tree_add_item(tree, hf_usb_bInterfaceProtocol, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2651
0
    }
2652
2653
0
    urb->conv->interfaceProtocol = tvb_get_uint8(tvb, offset);
2654
0
    offset += 1;
2655
2656
    /* iInterface */
2657
0
    proto_tree_add_item(tree, hf_usb_iInterface, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2658
0
    offset += 1;
2659
2660
0
    proto_item_set_len(item, len);
2661
2662
0
    if (offset < old_offset+len) {
2663
        /* skip unknown records */
2664
0
        offset = old_offset + len;
2665
0
    }
2666
2667
0
    return offset;
2668
0
}
2669
2670
/* 9.6.6 */
2671
const true_false_string tfs_endpoint_direction = {
2672
    "IN Endpoint",
2673
    "OUT Endpoint"
2674
};
2675
2676
void dissect_usb_endpoint_address(proto_tree *tree, tvbuff_t *tvb, int offset)
2677
0
{
2678
0
    proto_item *endpoint_item;
2679
0
    proto_tree *endpoint_tree;
2680
0
    uint8_t     endpoint;
2681
2682
0
    endpoint_item = proto_tree_add_item(tree, hf_usb_bEndpointAddress, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2683
0
    endpoint_tree = proto_item_add_subtree(endpoint_item, ett_configuration_bEndpointAddress);
2684
2685
0
    endpoint = tvb_get_uint8(tvb, offset);
2686
0
    proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_direction, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2687
0
    proto_item_append_text(endpoint_item, "  %s", (endpoint&0x80)?"IN":"OUT");
2688
0
    proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_number, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2689
0
    proto_item_append_text(endpoint_item, "  Endpoint:%d", endpoint&0x0f);
2690
0
}
2691
2692
unsigned int
2693
sanitize_usb_max_packet_size(uint8_t ep_type, usb_speed_t speed,
2694
                             unsigned int max_packet_size)
2695
0
{
2696
0
    unsigned int sanitized_ep_size = USB_MPS_EP_SIZE(max_packet_size);
2697
0
    unsigned int sanitized_adtnl = USB_MPS_ADDNL(max_packet_size);
2698
0
    switch (speed) {
2699
0
    case USB_SPEED_LOW:
2700
0
        sanitized_adtnl = 0;
2701
0
        switch (ep_type) {
2702
0
            case ENDPOINT_TYPE_CONTROL:
2703
                /* 8 is the only allowed value */
2704
0
                sanitized_ep_size = 8;
2705
0
                break;
2706
0
            case ENDPOINT_TYPE_INTERRUPT:
2707
0
                if (max_packet_size > 8)
2708
0
                    sanitized_ep_size = 8;
2709
0
                break;
2710
0
            default:
2711
                /* Not allowed */
2712
0
                break;
2713
0
        }
2714
0
        break;
2715
0
    case USB_SPEED_FULL:
2716
0
        sanitized_adtnl = 0;
2717
0
        switch (ep_type) {
2718
0
        case ENDPOINT_TYPE_CONTROL:
2719
0
        case ENDPOINT_TYPE_BULK:
2720
            /* Allowed values are: 8, 16, 32 and 64 */
2721
0
            if (max_packet_size > 32)
2722
0
                sanitized_ep_size = 64;
2723
0
            else if (max_packet_size > 16)
2724
0
                sanitized_ep_size = 32;
2725
0
            else if (max_packet_size > 8)
2726
0
                sanitized_ep_size = 16;
2727
0
            else
2728
0
                sanitized_ep_size = 8;
2729
0
            break;
2730
0
        case ENDPOINT_TYPE_INTERRUPT:
2731
0
            if (max_packet_size > 64)
2732
0
                sanitized_ep_size = 64;
2733
0
            break;
2734
0
        case ENDPOINT_TYPE_ISOCHRONOUS:
2735
0
            if (max_packet_size > 1023)
2736
0
                sanitized_ep_size = 1023;
2737
0
            break;
2738
0
        default:
2739
0
            break;
2740
0
        }
2741
0
        break;
2742
0
    case USB_SPEED_HIGH:
2743
0
        switch (ep_type) {
2744
0
        case ENDPOINT_TYPE_CONTROL:
2745
0
            sanitized_adtnl = 0;
2746
            /* 64 is the only allowed value */
2747
0
            sanitized_ep_size = 64;
2748
0
            break;
2749
0
        case ENDPOINT_TYPE_BULK:
2750
0
            sanitized_adtnl = 0;
2751
            /* 512 is the only allowed value */
2752
0
            sanitized_ep_size = 512;
2753
0
            break;
2754
0
        case ENDPOINT_TYPE_INTERRUPT:
2755
0
        case ENDPOINT_TYPE_ISOCHRONOUS:
2756
            /* If endpoint max packet size is out of range for high-bandwidth
2757
             * endpoint, treat the endpoint as a standard one.
2758
             */
2759
0
            if ((sanitized_adtnl > 2) ||
2760
0
                ((sanitized_adtnl == 2) && (max_packet_size < 683)) ||
2761
0
                ((sanitized_adtnl == 1) && (max_packet_size < 513)))
2762
0
                sanitized_adtnl = 0;
2763
0
            if (max_packet_size > 1024)
2764
0
                sanitized_ep_size = 1024;
2765
0
            break;
2766
0
        default:
2767
0
            break;
2768
0
        }
2769
0
        break;
2770
0
    case USB_SPEED_UNKNOWN:
2771
0
    default:
2772
0
        break;
2773
0
    }
2774
2775
0
    return USB_MPS(sanitized_ep_size, sanitized_adtnl);
2776
0
}
2777
2778
static char *usb_max_packet_size_str(wmem_allocator_t* allocator, unsigned int max_packet_size)
2779
0
{
2780
0
    unsigned int ep_size = USB_MPS_EP_SIZE(max_packet_size);
2781
0
    unsigned int addnl = USB_MPS_ADDNL(max_packet_size);
2782
2783
0
    if (addnl == 1 || addnl == 2) {
2784
0
        return wmem_strdup_printf(allocator, "%u * %u = %u",
2785
0
                                  addnl + 1, ep_size, (addnl + 1) * ep_size);
2786
0
    } else {
2787
0
        return wmem_strdup_printf(allocator, "%u", ep_size);
2788
0
    }
2789
0
}
2790
2791
int
2792
dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree,
2793
                                tvbuff_t *tvb, int offset,
2794
                                urb_info_t *urb,
2795
                                uint8_t *out_ep_type, usb_speed_t speed)
2796
0
{
2797
0
    proto_item       *item;
2798
0
    proto_tree       *tree;
2799
0
    proto_item       *ep_attrib_item;
2800
0
    proto_tree       *ep_attrib_tree;
2801
0
    proto_item       *ep_type_item;
2802
0
    proto_item       *ep_pktsize_item;
2803
0
    proto_tree       *ep_pktsize_tree;
2804
0
    int               old_offset     = offset;
2805
0
    uint8_t           endpoint;
2806
0
    uint8_t           ep_type;
2807
0
    uint8_t           len;
2808
0
    uint32_t          max_packet_size;
2809
0
    char             *max_packet_size_str;
2810
0
    unsigned int      sanitized_max_packet_size;
2811
0
    usb_trans_info_t *usb_trans_info = NULL;
2812
0
    conversation_t   *conversation   = NULL;
2813
2814
0
    if (urb)
2815
0
        usb_trans_info = urb->usb_trans_info;
2816
2817
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "ENDPOINT DESCRIPTOR");
2818
2819
0
    len = tvb_get_uint8(tvb, offset);
2820
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
2821
0
    offset += 2;
2822
2823
0
    endpoint = tvb_get_uint8(tvb, offset);
2824
0
    dissect_usb_endpoint_address(tree, tvb, offset);
2825
0
    offset += 1;
2826
2827
    /* Together with class from the interface descriptor we know what kind
2828
     * of class the device at endpoint is.
2829
     * Make sure a conversation exists for this endpoint and attach a
2830
     * usb_conv_into_t structure to it.
2831
     *
2832
     * All endpoints for the same interface descriptor share the same
2833
     * usb_conv_info structure.
2834
     */
2835
0
    if ((!pinfo->fd->visited) && usb_trans_info && usb_trans_info->interface_info) {
2836
0
        if (pinfo->destport == NO_ENDPOINT) {
2837
0
            address tmp_addr;
2838
0
            usb_address_t *usb_addr = wmem_new0(pinfo->pool, usb_address_t);
2839
2840
            /* packet is sent from a USB device's endpoint 0 to the host
2841
             * replace endpoint 0 with the endpoint of this descriptor
2842
             * and find the corresponding conversation
2843
             */
2844
0
            usb_addr->bus_id = ((const usb_address_t *)(pinfo->src.data))->bus_id;
2845
0
            usb_addr->device = ((const usb_address_t *)(pinfo->src.data))->device;
2846
0
            usb_addr->endpoint = GUINT32_TO_LE(endpoint);
2847
0
            set_address(&tmp_addr, usb_address_type, USB_ADDR_LEN, (char *)usb_addr);
2848
0
            conversation = get_usb_conversation(pinfo, &tmp_addr, &pinfo->dst, usb_addr->endpoint, pinfo->destport);
2849
0
        }
2850
2851
0
        if (conversation) {
2852
0
            usb_trans_info->interface_endpoint = endpoint;
2853
0
            conversation_add_proto_data(conversation, proto_usb, usb_trans_info->interface_info);
2854
0
        }
2855
0
    }
2856
2857
    /* bmAttributes */
2858
0
    ep_type = ENDPOINT_TYPE(tvb_get_uint8(tvb, offset));
2859
0
    if (out_ep_type) {
2860
0
        *out_ep_type = ep_type;
2861
0
    }
2862
2863
0
    ep_attrib_item = proto_tree_add_item(tree, hf_usb_bmAttributes, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2864
0
    ep_attrib_tree = proto_item_add_subtree(ep_attrib_item, ett_endpoint_bmAttributes);
2865
2866
0
    ep_type_item = proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeTransfer, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2867
0
    if (ep_type==USB_EP_ISOCHRONOUS) {
2868
0
        proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeSynchonisation, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2869
0
        proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeBehaviour, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2870
0
    }
2871
2872
    /* At Low-Speed, only control and interrupt transfers are allowed */
2873
0
    if ((speed == USB_SPEED_LOW) && !((ep_type == USB_EP_CONTROL) || (ep_type == USB_EP_INTERRUPT))) {
2874
0
        expert_add_info(pinfo, ep_type_item, &ei_usb_invalid_endpoint_type);
2875
0
    }
2876
0
    offset += 1;
2877
2878
    /* wMaxPacketSize */
2879
0
    max_packet_size = tvb_get_uint16(tvb, offset, ENC_LITTLE_ENDIAN);
2880
0
    max_packet_size_str = usb_max_packet_size_str(pinfo->pool, max_packet_size);
2881
0
    ep_pktsize_item = proto_tree_add_uint_format_value(tree, hf_usb_wMaxPacketSize,
2882
0
        tvb, offset, 2, max_packet_size, "%s", max_packet_size_str);
2883
0
    ep_pktsize_tree = proto_item_add_subtree(ep_pktsize_item, ett_endpoint_wMaxPacketSize);
2884
0
    if ((ep_type == ENDPOINT_TYPE_INTERRUPT) || (ep_type == ENDPOINT_TYPE_ISOCHRONOUS)) {
2885
0
        proto_tree_add_item(ep_pktsize_tree, hf_usb_wMaxPacketSize_slots, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2886
0
    }
2887
0
    proto_tree_add_item(ep_pktsize_tree, hf_usb_wMaxPacketSize_size, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2888
0
    sanitized_max_packet_size = sanitize_usb_max_packet_size(ep_type, speed, max_packet_size);
2889
0
    if (sanitized_max_packet_size != max_packet_size) {
2890
0
        expert_add_info_format(pinfo, ep_pktsize_item, &ei_usb_invalid_max_packet_size,
2891
0
            "%s %s endpoint max packet size cannot be %s, using %s instead.",
2892
0
            try_val_to_str(speed, usb_speed_vals), try_val_to_str(ep_type, usb_bmAttributes_transfer_vals),
2893
0
            max_packet_size_str, usb_max_packet_size_str(pinfo->pool, sanitized_max_packet_size));
2894
0
        max_packet_size = sanitized_max_packet_size;
2895
0
    }
2896
0
    offset+=2;
2897
2898
0
    if (conversation) {
2899
0
        usb_conv_info_t* endpoint_conv_info = get_usb_conv_info(conversation);
2900
0
        uint8_t transfer_type;
2901
2902
0
        switch(ep_type) {
2903
0
        case ENDPOINT_TYPE_CONTROL:
2904
0
            transfer_type = URB_CONTROL;
2905
0
            break;
2906
0
        case ENDPOINT_TYPE_ISOCHRONOUS:
2907
0
            transfer_type = URB_ISOCHRONOUS;
2908
0
            break;
2909
0
        case ENDPOINT_TYPE_BULK:
2910
0
            transfer_type = URB_BULK;
2911
0
            break;
2912
0
        case ENDPOINT_TYPE_INTERRUPT:
2913
0
            transfer_type = URB_INTERRUPT;
2914
0
            break;
2915
0
        default:
2916
0
            transfer_type = URB_UNKNOWN;
2917
0
            break;
2918
0
        }
2919
0
        endpoint_conv_info->descriptor_transfer_type = transfer_type;
2920
0
        endpoint_conv_info->max_packet_size = max_packet_size;
2921
0
    }
2922
2923
    /* bInterval */
2924
0
    proto_tree_add_item(tree, hf_usb_bInterval, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2925
0
    offset += 1;
2926
2927
    /* bRefresh and bSynchAddress are present only in the Audio 1.0
2928
     * Endpoint Descriptors, so observe the descriptor size  */
2929
0
    if (urb && urb->conv && (urb->conv->interfaceClass == IF_CLASS_AUDIO)
2930
0
            && (len >= 9)) {
2931
0
        proto_tree_add_item(tree, hf_usb_audio_bRefresh, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2932
0
        offset += 1;
2933
2934
0
        proto_tree_add_item(tree, hf_usb_audio_bSynchAddress, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2935
0
        offset += 1;
2936
0
    }
2937
2938
0
    proto_item_set_len(item, len);
2939
2940
0
    if (offset < old_offset+len) {
2941
        /* mark unknown records as undecoded */
2942
0
        proto_tree_add_expert(tree, pinfo, &ei_usb_undecoded, tvb, offset, old_offset + len - offset);
2943
0
        offset = old_offset + len;
2944
0
    }
2945
2946
0
    return offset;
2947
0
}
2948
2949
static int
2950
dissect_usb_endpoint_companion_descriptor(packet_info *pinfo, proto_tree *parent_tree,
2951
                                          tvbuff_t *tvb, int offset,
2952
                                          urb_info_t *urb _U_,
2953
                                          uint8_t ep_type)
2954
0
{
2955
0
    proto_item       *item;
2956
0
    proto_tree       *tree;
2957
0
    proto_item       *ep_attrib_item;
2958
0
    proto_tree       *ep_attrib_tree;
2959
0
    int               old_offset = offset;
2960
0
    uint8_t           len;
2961
2962
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "SUPERSPEED ENDPOINT COMPANION DESCRIPTOR");
2963
2964
0
    len = tvb_get_uint8(tvb, offset);
2965
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
2966
0
    offset += 2;
2967
2968
    /* bMaxBurst */
2969
0
    proto_tree_add_item(tree, hf_usb_bMaxBurst, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2970
0
    offset += 1;
2971
2972
    /* bmAttributes */
2973
0
    ep_attrib_item = proto_tree_add_item(tree, hf_usb_bmAttributes, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2974
0
    switch (ep_type) {
2975
0
    case ENDPOINT_TYPE_CONTROL:
2976
0
        break;
2977
0
    case ENDPOINT_TYPE_ISOCHRONOUS:
2978
0
        ep_attrib_tree = proto_item_add_subtree(ep_attrib_item, ett_endpoint_bmAttributes);
2979
0
        proto_tree_add_item(ep_attrib_tree, hf_usb_bSSEndpointAttributeIsoMult, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2980
0
        break;
2981
0
    case ENDPOINT_TYPE_BULK:
2982
0
        ep_attrib_tree = proto_item_add_subtree(ep_attrib_item, ett_endpoint_bmAttributes);
2983
0
        proto_tree_add_item(ep_attrib_tree, hf_usb_bSSEndpointAttributeBulkMaxStreams, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2984
0
        break;
2985
0
    case ENDPOINT_TYPE_INTERRUPT:
2986
0
        break;
2987
0
    default:
2988
0
        expert_add_info(pinfo, ep_attrib_item, &ei_usb_ss_ep_companion_before_ep);
2989
0
        break;
2990
0
    }
2991
0
    offset += 1;
2992
2993
    /* wBytesPerInterval */
2994
0
    proto_tree_add_item(tree, hf_usb_wBytesPerInterval, tvb, offset, 2, ENC_LITTLE_ENDIAN);
2995
0
    offset += 2;
2996
2997
0
    proto_item_set_len(item, len);
2998
2999
0
    if (offset < old_offset + len) {
3000
        /* mark unknown records as undecoded */
3001
0
        proto_tree_add_expert(tree, pinfo, &ei_usb_undecoded, tvb, offset, old_offset + len - offset);
3002
0
        offset = old_offset + len;
3003
0
    }
3004
3005
0
    return offset;
3006
0
}
3007
3008
/* ECN */
3009
static int
3010
dissect_usb_interface_assn_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
3011
                                      tvbuff_t *tvb, int offset,
3012
                                      urb_info_t  *urb _U_)
3013
0
{
3014
0
    proto_item *item;
3015
0
    proto_tree *tree;
3016
0
    int         old_offset = offset;
3017
3018
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "INTERFACE ASSOCIATION DESCRIPTOR");
3019
3020
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
3021
0
    offset += 2;
3022
3023
    /* bFirstInterface */
3024
0
    proto_tree_add_item(tree, hf_usb_bFirstInterface, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3025
0
    offset += 1;
3026
3027
    /* bInterfaceCount */
3028
0
    proto_tree_add_item(tree, hf_usb_bInterfaceCount, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3029
0
    offset += 1;
3030
3031
    /* bFunctionClass */
3032
0
    proto_tree_add_item(tree, hf_usb_bFunctionClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3033
0
    offset += 1;
3034
3035
    /* bFunctionSubclass */
3036
0
    proto_tree_add_item(tree, hf_usb_bFunctionSubClass, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3037
0
    offset += 1;
3038
3039
    /* bFunctionProtocol */
3040
0
    proto_tree_add_item(tree, hf_usb_bFunctionProtocol, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3041
0
    offset += 1;
3042
3043
    /* iFunction */
3044
0
    proto_tree_add_item(tree, hf_usb_iFunction, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3045
0
    offset += 1;
3046
3047
0
    proto_item_set_len(item, offset-old_offset);
3048
3049
0
    return offset;
3050
0
}
3051
3052
int
3053
dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
3054
                               tvbuff_t *tvb, int offset,
3055
                               urb_info_t *urb _U_)
3056
0
{
3057
0
    proto_item *item;
3058
0
    proto_tree *tree;
3059
0
    uint8_t     bLength;
3060
3061
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "UNKNOWN DESCRIPTOR");
3062
3063
0
    bLength = tvb_get_uint8(tvb, offset);
3064
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
3065
0
    offset += bLength;
3066
3067
0
    proto_item_set_len(item, bLength);
3068
3069
0
    return offset;
3070
0
}
3071
3072
/* 9.6.3 */
3073
static const true_false_string tfs_mustbeone = {
3074
    "Must be 1 for USB 1.1 and higher",
3075
    "FIXME: Is this a USB 1.0 device"
3076
};
3077
static const true_false_string tfs_selfpowered = {
3078
    "This device is SELF-POWERED",
3079
    "This device is powered from the USB bus"
3080
};
3081
static const true_false_string tfs_remotewakeup = {
3082
    "This device supports REMOTE WAKEUP",
3083
    "This device does NOT support remote wakeup"
3084
};
3085
static int
3086
dissect_usb_configuration_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree,
3087
                                     tvbuff_t *tvb, int offset,
3088
                                     urb_info_t *urb, usb_speed_t speed)
3089
0
{
3090
0
    proto_item *item;
3091
0
    proto_tree *tree;
3092
0
    int         old_offset = offset;
3093
0
    uint16_t    len;
3094
0
    proto_item *flags_item;
3095
0
    proto_tree *flags_tree;
3096
0
    uint8_t     flags;
3097
0
    uint8_t     last_ep_type = ENDPOINT_TYPE_NOT_SET;
3098
0
    proto_item *power_item;
3099
0
    uint8_t     power;
3100
0
    bool        truncation_expected;
3101
0
    usb_trans_info_t *usb_trans_info;
3102
3103
0
    usb_trans_info = urb->usb_trans_info;
3104
3105
0
    urb->conv->interfaceClass    = IF_CLASS_UNKNOWN;
3106
0
    urb->conv->interfaceSubclass = IF_SUBCLASS_UNKNOWN;
3107
0
    urb->conv->interfaceProtocol = IF_PROTOCOL_UNKNOWN;
3108
3109
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "CONFIGURATION DESCRIPTOR");
3110
3111
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
3112
0
    offset += 2;
3113
3114
    /* wTotalLength */
3115
0
    proto_tree_add_item(tree, hf_usb_wTotalLength, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3116
0
    len = tvb_get_letohs(tvb, offset);
3117
0
    offset+=2;
3118
3119
    /* bNumInterfaces */
3120
0
    proto_tree_add_item(tree, hf_usb_bNumInterfaces, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3121
0
    offset += 1;
3122
3123
    /* bConfigurationValue */
3124
0
    proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3125
0
    offset += 1;
3126
3127
    /* iConfiguration */
3128
0
    proto_tree_add_item(tree, hf_usb_iConfiguration, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3129
0
    offset += 1;
3130
3131
    /* bmAttributes */
3132
0
    flags_item = proto_tree_add_item(tree, hf_usb_configuration_bmAttributes, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3133
0
    flags_tree = proto_item_add_subtree(flags_item, ett_configuration_bmAttributes);
3134
3135
0
    flags = tvb_get_uint8(tvb, offset);
3136
0
    proto_tree_add_item(flags_tree, hf_usb_configuration_legacy10buspowered, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3137
0
    proto_tree_add_item(flags_tree, hf_usb_configuration_selfpowered, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3138
0
    proto_item_append_text(flags_item, "  %sSELF-POWERED", (flags&0x40)?"":"NOT ");
3139
0
    proto_tree_add_item(flags_tree, hf_usb_configuration_remotewakeup, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3140
0
    proto_item_append_text(flags_item, "  %sREMOTE-WAKEUP", (flags&0x20)?"":"NO ");
3141
0
    offset += 1;
3142
3143
    /* bMaxPower */
3144
0
    power_item = proto_tree_add_item(tree, hf_usb_bMaxPower, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3145
0
    power = tvb_get_uint8(tvb, offset);
3146
0
    proto_item_append_text(power_item, "  (%dmA)", power*2);
3147
0
    offset += 1;
3148
3149
    /* initialize interface_info to NULL */
3150
0
    usb_trans_info->interface_info = NULL;
3151
3152
0
    truncation_expected = (usb_trans_info->setup.wLength < len);
3153
3154
    /* decode any additional interface and endpoint descriptors */
3155
0
    while(len>(offset-old_offset)) {
3156
0
        uint8_t next_type;
3157
0
        uint8_t next_len = 0;
3158
0
        int remaining_tvb, remaining_len;
3159
0
        tvbuff_t *next_tvb = NULL;
3160
3161
        /* Handle truncated descriptors appropriately */
3162
0
        remaining_tvb = tvb_reported_length_remaining(tvb, offset);
3163
0
        if (remaining_tvb > 0) {
3164
0
            next_len  = tvb_get_uint8(tvb, offset);
3165
0
            remaining_len = len - (offset - old_offset);
3166
0
            if ((next_len < 3) || (next_len > remaining_len)) {
3167
0
                proto_tree_add_expert_format(parent_tree, pinfo, &ei_usb_desc_length_invalid,
3168
0
                    tvb, offset, 1, "Invalid descriptor length: %u",  next_len);
3169
0
                item = NULL;
3170
0
                break;
3171
0
            }
3172
0
        }
3173
3174
0
        if ((remaining_tvb == 0) || (next_len > remaining_tvb)) {
3175
0
            if (truncation_expected)
3176
0
                break;
3177
0
        }
3178
3179
0
        next_type = tvb_get_uint8(tvb, offset+1);
3180
0
        switch(next_type) {
3181
0
        case USB_DT_INTERFACE:
3182
0
            offset = dissect_usb_interface_descriptor(pinfo, parent_tree, tvb, offset, urb);
3183
0
            break;
3184
0
        case USB_DT_ENDPOINT:
3185
0
            offset = dissect_usb_endpoint_descriptor(pinfo, parent_tree, tvb, offset, urb, &last_ep_type, speed);
3186
0
            break;
3187
0
        case USB_DT_INTERFACE_ASSOCIATION:
3188
0
            offset = dissect_usb_interface_assn_descriptor(pinfo, parent_tree, tvb, offset, urb);
3189
0
            break;
3190
0
        case USB_DT_SUPERSPEED_EP_COMPANION:
3191
0
            offset = dissect_usb_endpoint_companion_descriptor(pinfo, parent_tree, tvb, offset, urb, last_ep_type);
3192
0
            break;
3193
0
        default:
3194
0
            next_tvb = tvb_new_subset_length(tvb, offset, next_len);
3195
0
            if (dissector_try_uint_with_data(usb_descriptor_dissector_table, urb->conv->interfaceClass, next_tvb, pinfo, parent_tree, true, urb)) {
3196
0
                offset += next_len;
3197
0
            } else {
3198
0
                offset = dissect_usb_unknown_descriptor(pinfo, parent_tree, tvb, offset, urb);
3199
0
            }
3200
0
            break;
3201
            /* was: return offset; */
3202
0
        }
3203
0
    }
3204
3205
0
    proto_item_set_len(item, offset-old_offset);
3206
3207
0
    return offset;
3208
0
}
3209
3210
/* https://wicg.github.io/webusb/#webusb-platform-capability-descriptor */
3211
static int
3212
dissect_webusb_platform_descriptor(packet_info *pinfo _U_, proto_tree *tree,
3213
                                   tvbuff_t *tvb, int offset,
3214
                                   urb_info_t *urb _U_)
3215
0
{
3216
0
    proto_tree_add_item(tree, hf_usb_webusb_bcdVersion, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3217
0
    offset += 2;
3218
3219
0
    proto_tree_add_item(tree, hf_usb_webusb_bVendorCode, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3220
0
    offset += 1;
3221
3222
0
    proto_tree_add_item(tree, hf_usb_webusb_iLandingPage, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3223
0
    offset += 1;
3224
3225
0
    return offset;
3226
0
}
3227
3228
/* Microsoft OS 2.0 Descriptors Specification */
3229
static int
3230
dissect_msos20_platform_descriptor(packet_info *pinfo _U_, proto_tree *tree,
3231
                                   tvbuff_t *tvb, int offset,
3232
                                   urb_info_t *urb _U_)
3233
0
{
3234
0
    proto_tree_add_item(tree, hf_usb_msos20_dwWindowsVersion, tvb, offset, 4, ENC_LITTLE_ENDIAN);
3235
0
    offset += 4;
3236
3237
0
    proto_tree_add_item(tree, hf_usb_msos20_wMSOSDescriptorSetTotalLength, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3238
0
    offset += 2;
3239
3240
0
    proto_tree_add_item(tree, hf_usb_msos20_bMS_VendorCode, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3241
0
    offset += 1;
3242
3243
0
    proto_tree_add_item(tree, hf_usb_msos20_bAltEnumCode, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3244
0
    offset += 1;
3245
3246
0
    return offset;
3247
0
}
3248
3249
static struct {
3250
    e_guid_t uuid;
3251
    const char *text;
3252
    int (*dissect)(packet_info *pinfo, proto_tree *tree,
3253
                   tvbuff_t *tvb, int offset,
3254
                   urb_info_t *urb);
3255
} bos_platform_uuids[] = {
3256
    { {0x3408b638, 0x09a9, 0x47a0, {0x8b, 0xfd, 0xa0, 0x76, 0x88, 0x15, 0xb6, 0x65}},
3257
      "WebUSB Platform Capability descriptor",
3258
      dissect_webusb_platform_descriptor },
3259
3260
    { {0xd8dd60df, 0x4589, 0x4cc7, {0x9c, 0xd2, 0x65, 0x9d, 0x9e, 0x64, 0x8a, 0x9f}},
3261
      "Microsoft OS 2.0 Platform Capability descriptor",
3262
      dissect_msos20_platform_descriptor },
3263
};
3264
3265
/* USB 3.2 Specification Table 9-13. Format of a Device Capability Descriptor */
3266
static int
3267
dissect_usb_device_capability_descriptor(packet_info *pinfo, proto_tree *tree,
3268
                                         tvbuff_t *tvb, int offset,
3269
                                         urb_info_t *urb)
3270
0
{
3271
0
    uint8_t      cap_type;
3272
0
    const char *cap_text;
3273
0
    e_guid_t     uuid;
3274
0
    unsigned int i;
3275
3276
0
    proto_tree_add_item(tree, hf_usb_bDevCapabilityType, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3277
0
    cap_type = tvb_get_uint8(tvb, offset);
3278
0
    offset += 1;
3279
3280
0
    cap_text = try_val_to_str_ext(cap_type, &usb_capability_vals_ext);
3281
3282
0
    if (cap_type == BOS_CAP_USB_20_EXTENSION) {
3283
        /* USB 2.0 ECN Errata for Link Power Management */
3284
0
        static int * const usb20ext_fields[] = {
3285
0
            &hf_usb_usb20ext_LPM,
3286
0
            &hf_usb_usb20ext_BESL_HIRD,
3287
0
            &hf_usb_usb20ext_baseline_BESL_valid,
3288
0
            &hf_usb_usb20ext_deep_BESL_valid,
3289
0
            &hf_usb_usb20ext_baseline_BESL,
3290
0
            &hf_usb_usb20ext_deep_BESL,
3291
0
            NULL
3292
0
        };
3293
3294
0
        proto_tree_add_bitmask_with_flags(tree, tvb, offset, hf_usb_usb20ext_bmAttributes,
3295
0
            ett_usb20ext_bmAttributes, usb20ext_fields, ENC_LITTLE_ENDIAN, BMT_NO_APPEND);
3296
0
        offset += 4;
3297
0
    } else if (cap_type == BOS_CAP_PLATFORM) {
3298
0
        proto_tree_add_item(tree, hf_usb_bReserved, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3299
0
        offset += 1;
3300
3301
0
        tvb_get_letohguid(tvb, offset, &uuid);
3302
0
        proto_tree_add_guid(tree, hf_usb_PlatformCapabilityUUID, tvb, offset, 16, &uuid);
3303
0
        offset += 16;
3304
3305
0
        for (i = 0; i < array_length(bos_platform_uuids); i++) {
3306
0
            if (guid_cmp(&bos_platform_uuids[i].uuid, &uuid) == 0) {
3307
0
                offset = bos_platform_uuids[i].dissect(pinfo, tree, tvb, offset, urb);
3308
0
                cap_text = bos_platform_uuids[i].text;
3309
0
                break;
3310
0
            }
3311
0
        }
3312
0
    } else if (cap_type == BOS_CAP_SUPERSPEED_USB) {
3313
        /* USB 3.2 Specification 9.6.2.2 SuperSpeed USB Device Capability */
3314
0
        static int * const usb_ss_bmAttributes_fields[] = {
3315
0
            &hf_usb_ss_bmAttributes_reserved0,
3316
0
            &hf_usb_ss_bmAttributes_LTM,
3317
0
            &hf_usb_ss_bmAttributes_reserved7_2,
3318
0
            NULL
3319
0
        };
3320
0
        static int * const usb_ss_wSpeedSupported_fields[] = {
3321
0
            &hf_usb_ss_wSpeedSupported_LS,
3322
0
            &hf_usb_ss_wSpeedSupported_FS,
3323
0
            &hf_usb_ss_wSpeedSupported_HS,
3324
0
            &hf_usb_ss_wSpeedSupported_Gen1,
3325
0
            &hf_usb_ss_wSpeedSupported_reserved,
3326
0
            NULL
3327
0
        };
3328
3329
0
        proto_tree_add_bitmask(tree, tvb, offset, hf_usb_ss_bmAttributes,
3330
0
            ett_ss_bmAttributes, usb_ss_bmAttributes_fields, ENC_LITTLE_ENDIAN);
3331
0
        offset += 1;
3332
0
        proto_tree_add_bitmask(tree, tvb, offset, hf_usb_ss_wSpeedSupported,
3333
0
            ett_ss_wSpeedSupported, usb_ss_wSpeedSupported_fields, ENC_LITTLE_ENDIAN);
3334
0
        offset += 2;
3335
0
        proto_tree_add_item(tree, hf_usb_ss_bFunctionalitySupport, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3336
0
        offset += 1;
3337
0
        proto_tree_add_item(tree, hf_usb_ss_bU1DevExitLat, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3338
0
        offset += 1;
3339
0
        proto_tree_add_item(tree, hf_usb_ss_wU2DevExitLat, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3340
0
        offset += 2;
3341
0
    }
3342
3343
0
    if (cap_text) {
3344
0
        proto_item_append_text(tree, ": %s", cap_text);
3345
0
    }
3346
3347
0
    return offset;
3348
0
}
3349
3350
/* USB 3.2 Specification 9.6.2 Binary Device Object Store (BOS) */
3351
static int
3352
dissect_usb_bos_descriptor(packet_info *pinfo, proto_tree *parent_tree,
3353
                           tvbuff_t *tvb, int offset,
3354
                           urb_info_t *urb)
3355
0
{
3356
0
    proto_item *item;
3357
0
    proto_tree *tree;
3358
0
    int         old_offset = offset;
3359
0
    uint16_t    total_len;
3360
0
    usb_trans_info_t *usb_trans_info;
3361
3362
0
    usb_trans_info = urb->usb_trans_info;
3363
3364
0
    tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "BOS DESCRIPTOR");
3365
3366
0
    dissect_usb_descriptor_header(tree, tvb, offset, NULL);
3367
0
    offset += 2;
3368
3369
    /* wTotalLength */
3370
0
    proto_tree_add_item(tree, hf_usb_wTotalLength, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3371
0
    total_len = tvb_get_letohs(tvb, offset);
3372
0
    offset += 2;
3373
3374
0
    proto_tree_add_item(tree, hf_usb_bNumDeviceCaps, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3375
0
    offset += 1;
3376
3377
0
    if (offset - old_offset >= usb_trans_info->setup.wLength) {
3378
        /* Do not report the most common case where host finds out about
3379
         * wTotalLength by requesting just BOS descriptor as Malformed Packet.
3380
         * TODO: Generic handling of "host requested too few bytes" (which is
3381
         * perfectly fine, but complicates dissection) because host is allowed
3382
         * to request any number of bytes.
3383
         */
3384
0
        return offset;
3385
0
    }
3386
3387
    /* Dissect capabilities */
3388
0
    while (total_len > (offset - old_offset)) {
3389
0
        proto_item *desc_item;
3390
0
        int         prev_offset = offset;
3391
0
        uint8_t     desc_len, desc_type;
3392
3393
0
        tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &desc_item, "DEVICE CAPABILITY DESCRIPTOR");
3394
3395
0
        item = proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3396
0
        desc_len = tvb_get_uint8(tvb, offset);
3397
0
        offset += 1;
3398
0
        if (desc_len < 3) {
3399
0
            expert_add_info_format(pinfo, item, &ei_usb_bLength_too_short, "Invalid Length (must be 3 or larger)");
3400
0
            break;
3401
0
        }
3402
3403
0
        item = proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3404
0
        desc_type = tvb_get_uint8(tvb, offset);
3405
0
        offset += 1;
3406
0
        if (desc_type == USB_DT_DEVICE_CAPABILITY) {
3407
0
            tvbuff_t *desc_tvb = tvb_new_subset_length(tvb, offset, desc_len - 2);
3408
0
            offset += dissect_usb_device_capability_descriptor(pinfo, tree, desc_tvb, 0, urb);
3409
0
        } else {
3410
0
            expert_add_info(pinfo, item, &ei_usb_unexpected_desc_type);
3411
            /* Already reported unexpected type, do not mark rest as undecoded */
3412
0
            offset = prev_offset + desc_len;
3413
0
        }
3414
3415
0
        if (offset < prev_offset + desc_len) {
3416
0
            proto_tree_add_expert(tree, pinfo, &ei_usb_undecoded, tvb, offset, prev_offset + desc_len - offset);
3417
0
            offset = prev_offset + desc_len;
3418
0
        }
3419
0
        proto_item_set_len(item, offset - prev_offset);
3420
0
    }
3421
3422
0
    proto_item_set_len(item, offset - old_offset);
3423
3424
0
    return offset;
3425
0
}
3426
3427
/* 9.4.3 */
3428
static int
3429
dissect_usb_setup_get_descriptor_request(packet_info *pinfo, proto_tree *tree,
3430
                                         tvbuff_t *tvb, int offset,
3431
                                         urb_info_t *urb)
3432
0
{
3433
0
    usb_trans_info_t *usb_trans_info, trans_info;
3434
3435
0
    if (urb)
3436
0
        usb_trans_info = urb->usb_trans_info;
3437
0
    else
3438
0
        usb_trans_info = &trans_info;
3439
3440
    /* descriptor index */
3441
0
    proto_tree_add_item(tree, hf_usb_descriptor_index, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3442
0
    usb_trans_info->u.get_descriptor.usb_index = tvb_get_uint8(tvb, offset);
3443
0
    offset += 1;
3444
3445
    /* descriptor type */
3446
0
    proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3447
0
    usb_trans_info->u.get_descriptor.type = tvb_get_uint8(tvb, offset);
3448
0
    offset += 1;
3449
0
    col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
3450
0
        val_to_str_ext(pinfo->pool, usb_trans_info->u.get_descriptor.type, &std_descriptor_type_vals_ext, "Unknown type %u"));
3451
3452
    /* language id */
3453
0
    proto_tree_add_item(tree, hf_usb_language_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3454
0
    offset+=2;
3455
3456
    /* length */
3457
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3458
0
    offset += 2;
3459
3460
0
    return offset;
3461
0
}
3462
3463
static int
3464
dissect_usb_setup_get_descriptor_response(packet_info *pinfo, proto_tree *tree,
3465
                                          tvbuff_t *tvb, int offset,
3466
                                          urb_info_t *urb)
3467
0
{
3468
0
    usb_trans_info_t *usb_trans_info;
3469
0
    usb_speed_t       speed;
3470
3471
0
    usb_trans_info = urb->usb_trans_info;
3472
0
    speed = urb->speed;
3473
3474
0
    col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
3475
0
        val_to_str_ext(pinfo->pool, usb_trans_info->u.get_descriptor.type, &std_descriptor_type_vals_ext, "Unknown type %u"));
3476
3477
0
    switch(usb_trans_info->u.get_descriptor.type) {
3478
0
        case USB_DT_INTERFACE:
3479
0
        case USB_DT_ENDPOINT:
3480
            /* an interface or an endpoint descriptor can only be accessed
3481
               as part of a configuration descriptor */
3482
0
            break;
3483
0
        case USB_DT_DEVICE:
3484
0
            offset = dissect_usb_device_descriptor(pinfo, tree, tvb, offset, urb);
3485
0
            break;
3486
0
        case USB_DT_OTHER_SPEED_CONFIG:
3487
            /* USB 2.0 Specification: 9.2.6.6 Speed Dependent Descriptors */
3488
0
            if (speed == USB_SPEED_FULL)
3489
0
                speed = USB_SPEED_HIGH;
3490
0
            else if (speed == USB_SPEED_HIGH)
3491
0
                speed = USB_SPEED_FULL;
3492
            /* fall-through */
3493
0
        case USB_DT_CONFIG:
3494
0
            offset = dissect_usb_configuration_descriptor(pinfo, tree, tvb, offset, urb, speed);
3495
0
            break;
3496
0
        case USB_DT_STRING:
3497
0
            offset = dissect_usb_string_descriptor(pinfo, tree, tvb, offset, urb);
3498
0
            break;
3499
0
        case USB_DT_DEVICE_QUALIFIER:
3500
0
            offset = dissect_usb_device_qualifier_descriptor(pinfo, tree, tvb, offset, urb);
3501
0
            break;
3502
0
        case USB_DT_BOS:
3503
0
            offset = dissect_usb_bos_descriptor(pinfo, tree, tvb, offset, urb);
3504
0
            break;
3505
0
        default:
3506
            /* XXX dissect the descriptor coming back from the device */
3507
0
            {
3508
0
                unsigned len = tvb_reported_length_remaining(tvb, offset);
3509
0
                proto_tree_add_bytes_format(tree, hf_usb_get_descriptor_resp_generic, tvb, offset, len, NULL,
3510
0
                                            "GET DESCRIPTOR Response data (unknown descriptor type %u): %s",
3511
0
                                            usb_trans_info->u.get_descriptor.type,
3512
0
                                            tvb_bytes_to_str(pinfo->pool, tvb, offset, len));
3513
0
                offset = offset + len;
3514
0
            }
3515
0
            break;
3516
0
    }
3517
3518
0
    return offset;
3519
0
}
3520
3521
3522
/*
3523
 * These dissectors are used to dissect the setup part and the data
3524
 * for URB_CONTROL_INPUT / GET INTERFACE
3525
 */
3526
3527
3528
/* 9.4.4 */
3529
static int
3530
dissect_usb_setup_get_interface_request(packet_info *pinfo _U_, proto_tree *tree,
3531
                                        tvbuff_t *tvb, int offset,
3532
                                        urb_info_t *urb _U_)
3533
0
{
3534
    /* zero */
3535
0
    proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3536
0
    offset += 2;
3537
3538
    /* interface */
3539
0
    proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3540
0
    offset += 2;
3541
3542
    /* length */
3543
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3544
0
    offset += 2;
3545
3546
0
    return offset;
3547
0
}
3548
3549
static int
3550
dissect_usb_setup_get_interface_response(packet_info *pinfo _U_, proto_tree *tree,
3551
                                         tvbuff_t *tvb, int offset,
3552
                                         urb_info_t *urb _U_)
3553
0
{
3554
    /* alternate setting */
3555
0
    proto_tree_add_item(tree, hf_usb_bAlternateSetting, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3556
0
    offset += 1;
3557
3558
0
    return offset;
3559
0
}
3560
3561
3562
/*
3563
 * These dissectors are used to dissect the setup part and the data
3564
 * for URB_CONTROL_INPUT / GET STATUS
3565
 */
3566
3567
3568
/* 9.4.5 */
3569
static int
3570
dissect_usb_setup_get_status_request(packet_info *pinfo _U_, proto_tree *tree,
3571
                                     tvbuff_t *tvb, int offset,
3572
                                     urb_info_t *urb _U_)
3573
0
{
3574
    /* zero */
3575
0
    proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3576
0
    offset += 2;
3577
3578
    /* zero/interface/endpoint */
3579
0
    if (urb) {
3580
0
        uint8_t recip;
3581
3582
0
        recip = USB_RECIPIENT(urb->usb_trans_info->setup.requesttype);
3583
3584
0
        switch (recip) {
3585
0
        case RQT_SETUP_RECIPIENT_INTERFACE:
3586
0
            proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3587
0
            break;
3588
3589
0
        case RQT_SETUP_RECIPIENT_ENDPOINT:
3590
0
            proto_tree_add_item(tree, hf_usb_wEndpoint, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3591
0
            break;
3592
3593
0
        case RQT_SETUP_RECIPIENT_DEVICE:
3594
0
        case RQT_SETUP_RECIPIENT_OTHER:
3595
0
        default:
3596
0
            proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3597
0
            break;
3598
0
        }
3599
0
    } else {
3600
0
        proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3601
0
    }
3602
0
    offset += 2;
3603
3604
    /* length */
3605
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3606
0
    offset += 2;
3607
3608
0
    return offset;
3609
0
}
3610
3611
static int
3612
dissect_usb_setup_get_status_response(packet_info *pinfo _U_, proto_tree *tree,
3613
                                      tvbuff_t *tvb, int offset,
3614
                                      urb_info_t *urb _U_)
3615
0
{
3616
    /* status */
3617
    /* XXX - show bits */
3618
0
    proto_tree_add_item(tree, hf_usb_wStatus, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3619
0
    offset += 2;
3620
3621
0
    return offset;
3622
0
}
3623
3624
3625
/*
3626
 * These dissectors are used to dissect the setup part and the data
3627
 * for URB_CONTROL_INPUT / SET ADDRESS
3628
 */
3629
3630
3631
/* 9.4.6 */
3632
static int
3633
dissect_usb_setup_set_address_request(packet_info *pinfo _U_, proto_tree *tree,
3634
                                      tvbuff_t *tvb, int offset,
3635
                                      urb_info_t *urb _U_)
3636
0
{
3637
    /* device address */
3638
0
    proto_tree_add_item(tree, hf_usb_device_address, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3639
0
    offset += 2;
3640
3641
    /* zero */
3642
0
    proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3643
0
    offset += 2;
3644
3645
    /* zero */
3646
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3647
0
    offset += 2;
3648
3649
0
    return offset;
3650
0
}
3651
3652
static int
3653
dissect_usb_setup_set_address_response(packet_info *pinfo _U_, proto_tree *tree _U_,
3654
                                       tvbuff_t *tvb _U_, int offset,
3655
                                       urb_info_t *urb _U_)
3656
0
{
3657
0
    return offset;
3658
0
}
3659
3660
3661
/*
3662
 * These dissectors are used to dissect the setup part and the data
3663
 * for URB_CONTROL_INPUT / SET CONFIGURATION
3664
 */
3665
3666
3667
/* 9.4.7 */
3668
static int
3669
dissect_usb_setup_set_configuration_request(packet_info *pinfo _U_, proto_tree *tree,
3670
                                            tvbuff_t *tvb, int offset,
3671
                                            urb_info_t *urb _U_)
3672
0
{
3673
    /* configuration value */
3674
0
    proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3675
0
    offset += 2;
3676
3677
    /* zero */
3678
0
    proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3679
0
    offset += 2;
3680
3681
    /* zero */
3682
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3683
0
    offset += 2;
3684
3685
0
    return offset;
3686
0
}
3687
3688
static int
3689
dissect_usb_setup_set_configuration_response(packet_info *pinfo _U_, proto_tree *tree _U_,
3690
                                             tvbuff_t *tvb _U_, int offset,
3691
                                             urb_info_t *urb _U_)
3692
0
{
3693
0
    return offset;
3694
0
}
3695
3696
3697
/*
3698
 * These dissectors are used to dissect the setup part and the data
3699
 * for URB_CONTROL_INPUT / SET FEATURE
3700
 */
3701
3702
3703
/* 9.4.9 */
3704
static int
3705
dissect_usb_setup_set_feature_request(packet_info *pinfo _U_, proto_tree *tree,
3706
                                      tvbuff_t *tvb, int offset,
3707
                                      urb_info_t *urb)
3708
0
{
3709
0
    uint8_t recip;
3710
3711
0
    if (urb) {
3712
0
        recip = USB_RECIPIENT(urb->usb_trans_info->setup.requesttype);
3713
3714
        /* feature selector, zero/interface/endpoint */
3715
0
        switch (recip) {
3716
0
        case RQT_SETUP_RECIPIENT_DEVICE:
3717
0
            proto_tree_add_item(tree, hf_usb_device_wFeatureSelector, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3718
0
            offset += 2;
3719
0
            proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3720
0
            break;
3721
3722
0
        case RQT_SETUP_RECIPIENT_INTERFACE:
3723
0
            proto_tree_add_item(tree, hf_usb_interface_wFeatureSelector, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3724
0
            offset += 2;
3725
0
            proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3726
0
            break;
3727
3728
0
        case RQT_SETUP_RECIPIENT_ENDPOINT:
3729
0
            proto_tree_add_item(tree, hf_usb_endpoint_wFeatureSelector, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3730
0
            offset += 2;
3731
0
            proto_tree_add_item(tree, hf_usb_wEndpoint, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3732
0
            break;
3733
3734
0
        case RQT_SETUP_RECIPIENT_OTHER:
3735
0
        default:
3736
0
            proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3737
0
            offset += 2;
3738
0
            proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3739
0
            break;
3740
0
        }
3741
0
    } else {
3742
        /* No conversation information, so recipient type is unknown */
3743
0
        proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3744
0
        offset += 2;
3745
0
        proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3746
0
    }
3747
0
    offset += 2;
3748
3749
    /* zero */
3750
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3751
0
    offset += 2;
3752
3753
0
    return offset;
3754
0
}
3755
3756
static int
3757
dissect_usb_setup_set_feature_response(packet_info *pinfo _U_, proto_tree *tree _U_,
3758
                                       tvbuff_t *tvb _U_, int offset,
3759
                                       urb_info_t *urb _U_)
3760
0
{
3761
0
    return offset;
3762
0
}
3763
3764
3765
/*
3766
 * These dissectors are used to dissect the setup part and the data
3767
 * for URB_CONTROL_INPUT / SET INTERFACE
3768
 */
3769
3770
3771
/* 9.4.10 */
3772
static int
3773
dissect_usb_setup_set_interface_request(packet_info *pinfo, proto_tree *tree,
3774
                                        tvbuff_t *tvb, int offset,
3775
                                        urb_info_t *urb _U_)
3776
0
{
3777
0
    uint8_t alt_setting, interface_num;
3778
3779
    /* alternate setting */
3780
0
    alt_setting = tvb_get_uint8(tvb, offset);
3781
0
    proto_tree_add_uint(tree, hf_usb_bAlternateSetting, tvb, offset, 2, alt_setting);
3782
0
    offset += 2;
3783
3784
    /* interface */
3785
0
    interface_num = tvb_get_uint8(tvb, offset);
3786
0
    proto_tree_add_uint(tree, hf_usb_wInterface, tvb, offset, 2, interface_num);
3787
0
    offset += 2;
3788
3789
    /* zero */
3790
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3791
0
    offset += 2;
3792
3793
0
    if (!PINFO_FD_VISITED(pinfo)) {
3794
0
        unsigned i, count;
3795
0
        usb_conv_info_t *iface_conv_info = get_usb_iface_conv_info(pinfo, interface_num);
3796
3797
        /* update the conversation info with the selected alternate setting */
3798
0
        count = wmem_array_get_count(iface_conv_info->alt_settings);
3799
0
        for (i = 0; i < count; i++) {
3800
0
            usb_alt_setting_t *alternate_setting = (usb_alt_setting_t *)wmem_array_index(iface_conv_info->alt_settings, i);
3801
3802
0
            if (alternate_setting->altSetting == alt_setting) {
3803
0
                iface_conv_info->interfaceClass = alternate_setting->interfaceClass;
3804
0
                iface_conv_info->interfaceSubclass = alternate_setting->interfaceSubclass;
3805
0
                iface_conv_info->interfaceProtocol = alternate_setting->interfaceProtocol;
3806
0
                iface_conv_info->interfaceNum = alternate_setting->interfaceNum;
3807
0
                break;
3808
0
            }
3809
0
        }
3810
0
    }
3811
3812
0
    return offset;
3813
0
}
3814
3815
static int
3816
dissect_usb_setup_set_interface_response(packet_info *pinfo _U_, proto_tree *tree _U_,
3817
                                         tvbuff_t *tvb _U_, int offset,
3818
                                         urb_info_t *urb _U_)
3819
0
{
3820
0
    return offset;
3821
0
}
3822
3823
3824
/*
3825
 * These dissectors are used to dissect the setup part and the data
3826
 * for URB_CONTROL_INPUT / SYNCH FRAME
3827
 */
3828
3829
3830
/* 9.4.11 */
3831
static int
3832
dissect_usb_setup_synch_frame_request(packet_info *pinfo _U_, proto_tree *tree,
3833
                                      tvbuff_t *tvb, int offset,
3834
                                      urb_info_t *urb _U_)
3835
0
{
3836
    /* zero */
3837
0
    proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3838
0
    offset += 2;
3839
3840
    /* endpoint */
3841
0
    proto_tree_add_item(tree, hf_usb_wEndpoint, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3842
0
    offset += 2;
3843
3844
    /* two */
3845
0
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3846
0
    offset += 2;
3847
3848
0
    return offset;
3849
0
}
3850
3851
static int
3852
dissect_usb_setup_synch_frame_response(packet_info *pinfo _U_, proto_tree *tree _U_,
3853
                                       tvbuff_t *tvb _U_, int offset,
3854
                                       urb_info_t *urb _U_)
3855
0
{
3856
    /* frame number */
3857
0
    proto_tree_add_item(tree, hf_usb_wFrameNumber, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3858
0
    offset += 2;
3859
3860
0
    return offset;
3861
0
}
3862
3863
/* Dissector used for unknown USB setup request/responses */
3864
static int
3865
dissect_usb_setup_generic(packet_info *pinfo _U_, proto_tree *tree ,
3866
                                       tvbuff_t *tvb, int offset,
3867
                                       urb_info_t *urb _U_)
3868
3
{
3869
3870
3
    proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3871
3
    offset += 2;
3872
3
    proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3873
3
    offset += 2;
3874
3
    proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
3875
3
    offset += 2;
3876
3877
3
    return offset;
3878
3
}
3879
3880
3881
3882
typedef int (*usb_setup_dissector)(packet_info *pinfo, proto_tree *tree,
3883
                                   tvbuff_t *tvb, int offset,
3884
                                   urb_info_t *urb);
3885
3886
typedef struct _usb_setup_dissector_table_t {
3887
    uint8_t request;
3888
    usb_setup_dissector dissector;
3889
3890
} usb_setup_dissector_table_t;
3891
static const usb_setup_dissector_table_t setup_request_dissectors[] = {
3892
    {USB_SETUP_GET_STATUS,        dissect_usb_setup_get_status_request},
3893
    {USB_SETUP_CLEAR_FEATURE,     dissect_usb_setup_clear_feature_request},
3894
    {USB_SETUP_SET_FEATURE,       dissect_usb_setup_set_feature_request},
3895
    {USB_SETUP_SET_ADDRESS,       dissect_usb_setup_set_address_request},
3896
    {USB_SETUP_GET_DESCRIPTOR,    dissect_usb_setup_get_descriptor_request},
3897
    {USB_SETUP_SET_CONFIGURATION, dissect_usb_setup_set_configuration_request},
3898
    {USB_SETUP_GET_INTERFACE,     dissect_usb_setup_get_interface_request},
3899
    {USB_SETUP_SET_INTERFACE,     dissect_usb_setup_set_interface_request},
3900
    {USB_SETUP_SYNCH_FRAME,       dissect_usb_setup_synch_frame_request},
3901
    {0, NULL}
3902
};
3903
3904
static const usb_setup_dissector_table_t setup_response_dissectors[] = {
3905
    {USB_SETUP_GET_STATUS,        dissect_usb_setup_get_status_response},
3906
    {USB_SETUP_CLEAR_FEATURE,     dissect_usb_setup_clear_feature_response},
3907
    {USB_SETUP_SET_FEATURE,       dissect_usb_setup_set_feature_response},
3908
    {USB_SETUP_SET_ADDRESS,       dissect_usb_setup_set_address_response},
3909
    {USB_SETUP_GET_DESCRIPTOR,    dissect_usb_setup_get_descriptor_response},
3910
    {USB_SETUP_GET_CONFIGURATION, dissect_usb_setup_get_configuration_response},
3911
    {USB_SETUP_SET_CONFIGURATION, dissect_usb_setup_set_configuration_response},
3912
    {USB_SETUP_GET_INTERFACE,     dissect_usb_setup_get_interface_response},
3913
    {USB_SETUP_SET_INTERFACE,     dissect_usb_setup_set_interface_response},
3914
    {USB_SETUP_SYNCH_FRAME,       dissect_usb_setup_synch_frame_response},
3915
    {0, NULL}
3916
};
3917
3918
static const value_string setup_request_names_vals[] = {
3919
    {USB_SETUP_GET_STATUS,              "GET STATUS"},
3920
    {USB_SETUP_CLEAR_FEATURE,           "CLEAR FEATURE"},
3921
    {USB_SETUP_SET_FEATURE,             "SET FEATURE"},
3922
    {USB_SETUP_SET_ADDRESS,             "SET ADDRESS"},
3923
    {USB_SETUP_GET_DESCRIPTOR,          "GET DESCRIPTOR"},
3924
    {USB_SETUP_SET_DESCRIPTOR,          "SET DESCRIPTOR"},
3925
    {USB_SETUP_GET_CONFIGURATION,       "GET CONFIGURATION"},
3926
    {USB_SETUP_SET_CONFIGURATION,       "SET CONFIGURATION"},
3927
    {USB_SETUP_GET_INTERFACE,           "GET INTERFACE"},
3928
    {USB_SETUP_SET_INTERFACE,           "SET INTERFACE"},
3929
    {USB_SETUP_SYNCH_FRAME,             "SYNCH FRAME"},
3930
    {USB_SETUP_SET_SEL,                 "SET SEL"},
3931
    {USB_SETUP_SET_ISOCH_DELAY,         "SET ISOCH DELAY"},
3932
    {0, NULL}
3933
};
3934
static value_string_ext setup_request_names_vals_ext = VALUE_STRING_EXT_INIT(setup_request_names_vals);
3935
3936
3937
static const true_false_string tfs_bmrequesttype_direction = {
3938
    "Device-to-host",
3939
    "Host-to-device"
3940
};
3941
3942
static const value_string bmrequesttype_type_vals[] = {
3943
    {RQT_SETUP_TYPE_STANDARD, "Standard"},
3944
    {RQT_SETUP_TYPE_CLASS,    "Class"},
3945
    {RQT_SETUP_TYPE_VENDOR,   "Vendor"},
3946
    {0, NULL}
3947
};
3948
3949
static const value_string bmrequesttype_recipient_vals[] = {
3950
    {RQT_SETUP_RECIPIENT_DEVICE,    "Device" },
3951
    {RQT_SETUP_RECIPIENT_INTERFACE, "Interface" },
3952
    {RQT_SETUP_RECIPIENT_ENDPOINT,  "Endpoint" },
3953
    {RQT_SETUP_RECIPIENT_OTHER,     "Other" },
3954
    {0, NULL }
3955
};
3956
3957
/* Dissector used for standard usb setup requests */
3958
static int
3959
dissect_usb_standard_setup_request(packet_info *pinfo, proto_tree *tree ,
3960
                                   tvbuff_t *tvb, urb_info_t *urb,
3961
                                   usb_trans_info_t *usb_trans_info)
3962
1
{
3963
1
    int offset = 0;
3964
1
    const usb_setup_dissector_table_t *tmp;
3965
1
    usb_setup_dissector dissector;
3966
3967
1
    proto_tree_add_item(tree, hf_usb_request, tvb, offset, 1, ENC_LITTLE_ENDIAN);
3968
1
    offset += 1;
3969
3970
1
    col_add_fstr(pinfo->cinfo, COL_INFO, "%s Request",
3971
1
            val_to_str_ext(pinfo->pool, usb_trans_info->setup.request, &setup_request_names_vals_ext, "Unknown type %x"));
3972
3973
1
    dissector = NULL;
3974
10
    for(tmp = setup_request_dissectors;tmp->dissector;tmp++) {
3975
9
        if (tmp->request == usb_trans_info->setup.request) {
3976
0
            dissector = tmp->dissector;
3977
0
            break;
3978
0
        }
3979
9
    }
3980
3981
1
    if (!dissector) {
3982
1
            dissector = &dissect_usb_setup_generic;
3983
1
    }
3984
3985
1
    offset = dissector(pinfo, tree, tvb, offset, urb);
3986
3987
1
    return offset;
3988
3989
1
}
3990
3991
/* Dissector used for standard usb setup responses */
3992
static int
3993
dissect_usb_standard_setup_response(packet_info *pinfo, proto_tree *tree,
3994
                                    tvbuff_t *tvb, int offset,
3995
                                    urb_info_t *urb)
3996
0
{
3997
0
    const usb_setup_dissector_table_t *tmp;
3998
0
    usb_setup_dissector dissector;
3999
0
    int length_remaining;
4000
4001
4002
0
    col_add_fstr(pinfo->cinfo, COL_INFO, "%s Response",
4003
0
        val_to_str_ext(pinfo->pool, urb->usb_trans_info->setup.request,
4004
0
            &setup_request_names_vals_ext, "Unknown type %x"));
4005
4006
0
    dissector = NULL;
4007
0
    for(tmp = setup_response_dissectors;tmp->dissector;tmp++) {
4008
0
        if (tmp->request == urb->usb_trans_info->setup.request) {
4009
0
            dissector = tmp->dissector;
4010
0
            break;
4011
0
        }
4012
0
    }
4013
4014
0
    length_remaining = tvb_reported_length_remaining(tvb, offset);
4015
4016
0
    if (length_remaining <= 0)
4017
0
        return offset;
4018
4019
0
    if (dissector) {
4020
0
        offset = dissector(pinfo, tree, tvb, offset, urb);
4021
0
    } else {
4022
0
        proto_tree_add_item(tree, hf_usb_control_response_generic,
4023
0
                            tvb, offset, length_remaining, ENC_NA);
4024
0
        offset += length_remaining;
4025
0
    }
4026
4027
0
    return offset;
4028
0
}
4029
4030
4031
static void
4032
usb_tap_queue_packet(packet_info *pinfo, uint8_t urb_type,
4033
                     urb_info_t *urb)
4034
24
{
4035
24
    usb_tap_data_t *tap_data;
4036
4037
24
    tap_data                = wmem_new(pinfo->pool, usb_tap_data_t);
4038
24
    tap_data->urb_type      = urb_type;
4039
24
    tap_data->transfer_type = (uint8_t)(urb->transfer_type);
4040
24
    tap_data->urb           = urb;
4041
24
    tap_data->trans_info    = urb->usb_trans_info;
4042
4043
24
    tap_queue_packet(usb_tap, pinfo, tap_data);
4044
24
}
4045
4046
4047
static bool
4048
is_usb_standard_setup_request(usb_trans_info_t *usb_trans_info)
4049
5
{
4050
5
    uint8_t type, recip;
4051
4052
5
    type = USB_TYPE(usb_trans_info->setup.requesttype);
4053
5
    recip = USB_RECIPIENT(usb_trans_info->setup.requesttype);
4054
4055
5
    if (type != RQT_SETUP_TYPE_STANDARD)
4056
4
        return false;
4057
4058
    /* the USB standards defines the GET_DESCRIPTOR request only as a
4059
       request to a device
4060
       if it's not aimed at a device, it's a non-standard request that
4061
       should be handled by a class-specific dissector */
4062
1
    if (usb_trans_info->setup.request == USB_SETUP_GET_DESCRIPTOR &&
4063
0
            recip != RQT_SETUP_RECIPIENT_DEVICE) {
4064
0
        return false;
4065
0
    }
4066
4067
1
    return true;
4068
1
}
4069
4070
4071
static int
4072
try_dissect_next_protocol(proto_tree *tree, tvbuff_t *next_tvb, packet_info *pinfo,
4073
        urb_info_t *urb, uint8_t urb_type, proto_tree *urb_tree,
4074
        proto_tree *setup_tree)
4075
7
{
4076
7
    int                      ret;
4077
7
    wmem_tree_key_t          key[4];
4078
7
    uint32_t                 k_frame_number;
4079
7
    uint32_t                 k_device_address;
4080
7
    uint32_t                 k_bus_id;
4081
7
    usb_trans_info_t        *usb_trans_info;
4082
7
    heur_dtbl_entry_t       *hdtbl_entry;
4083
7
    heur_dissector_list_t    heur_subdissector_list = NULL;
4084
7
    dissector_table_t        usb_dissector_table = NULL;
4085
7
    proto_item              *sub_item;
4086
7
    device_product_data_t   *device_product_data;
4087
7
    device_protocol_data_t  *device_protocol_data;
4088
7
    uint8_t                  ctrl_recip;
4089
    /* if we select the next dissector based on a class,
4090
       this is the (device or interface) class we're using */
4091
7
    uint32_t                 usb_class;
4092
7
    uint32_t                 protocol;
4093
7
    uint8_t                  transfer_type;
4094
7
    bool                     use_setup_tree = false;
4095
4096
7
    if (!urb) {
4097
        /*
4098
         * Not enough information to choose the next protocol.
4099
         * XXX - is there something we can still do here?
4100
         */
4101
0
        if (tvb_reported_length(next_tvb) > 0)
4102
0
            call_data_dissector(next_tvb, pinfo, tree);
4103
4104
0
        return tvb_captured_length(next_tvb);
4105
0
    }
4106
4107
    /* try dissect by "usb.device" */
4108
7
    ret = dissector_try_uint_with_data(device_to_dissector,
4109
7
            (uint32_t)(urb->bus_id<<16 | urb->device_address),
4110
7
            next_tvb, pinfo, tree, true, urb);
4111
7
    if (ret)
4112
0
        return tvb_captured_length(next_tvb);
4113
4114
7
    k_frame_number = pinfo->num;
4115
7
    k_device_address = urb->device_address;
4116
7
    k_bus_id = urb->bus_id;
4117
4118
7
    key[0].length = 1;
4119
7
    key[0].key    = &k_device_address;
4120
7
    key[1].length = 1;
4121
7
    key[1].key    = &k_bus_id;
4122
7
    key[2].length = 1;
4123
7
    key[2].key    = &k_frame_number;
4124
7
    key[3].length = 0;
4125
7
    key[3].key    = NULL;
4126
4127
    /* try dissect by "usb.protocol" */
4128
7
    device_protocol_data = (device_protocol_data_t *)wmem_tree_lookup32_array_le(device_to_protocol_table, key);
4129
4130
7
    if (device_protocol_data &&
4131
0
            device_protocol_data->bus_id == urb->bus_id &&
4132
0
            device_protocol_data->device_address == urb->device_address) {
4133
0
                ret = dissector_try_uint_with_data(protocol_to_dissector,
4134
0
                        (uint32_t)device_protocol_data->protocol,
4135
0
                        next_tvb, pinfo, tree, true, urb);
4136
0
                if (ret)
4137
0
                    return tvb_captured_length(next_tvb);
4138
0
    }
4139
4140
7
    device_product_data = (device_product_data_t *)wmem_tree_lookup32_array_le(device_to_product_table, key);
4141
4142
7
    if (device_product_data && device_product_data->bus_id == urb->bus_id &&
4143
0
            device_product_data->device_address == urb->device_address) {
4144
0
                ret = dissector_try_uint_with_data(product_to_dissector,
4145
0
                        (uint32_t)(device_product_data->vendor<<16 | device_product_data->product),
4146
0
                        next_tvb, pinfo, tree, true, urb);
4147
0
                if (ret)
4148
0
                    return tvb_captured_length(next_tvb);
4149
0
    }
4150
4151
7
    transfer_type = urb->transfer_type;
4152
7
    if (transfer_type == URB_UNKNOWN)
4153
2
        transfer_type = urb->conv->descriptor_transfer_type;
4154
4155
7
    switch(transfer_type) {
4156
0
        case URB_BULK:
4157
0
            heur_subdissector_list = heur_bulk_subdissector_list;
4158
0
            usb_dissector_table = usb_bulk_dissector_table;
4159
0
            break;
4160
4161
0
        case URB_INTERRUPT:
4162
0
            heur_subdissector_list = heur_interrupt_subdissector_list;
4163
0
            usb_dissector_table = usb_interrupt_dissector_table;
4164
0
            break;
4165
4166
3
        case URB_CONTROL:
4167
3
            usb_trans_info = urb->usb_trans_info;
4168
3
            if (!usb_trans_info)
4169
1
                break;
4170
4171
            /* for standard control requests and responses, there's no
4172
               need to query dissector tables */
4173
2
            if (is_usb_standard_setup_request(usb_trans_info))
4174
0
                break;
4175
4176
            /* When dissecting requests, and Setup Data tree is created,
4177
               pass it to next dissector instead of parent. */
4178
2
            if (urb->is_request && setup_tree)
4179
2
                use_setup_tree = true;
4180
4181
2
            ctrl_recip = USB_RECIPIENT(usb_trans_info->setup.requesttype);
4182
4183
2
            if (ctrl_recip == RQT_SETUP_RECIPIENT_INTERFACE) {
4184
0
                uint8_t interface_num = usb_trans_info->setup.wIndex & 0xff;
4185
0
                urb_info_t *new_urb = wmem_new(pinfo->pool, urb_info_t);
4186
4187
0
                memcpy(new_urb, urb, sizeof(urb_info_t));
4188
0
                urb = new_urb;
4189
4190
0
                heur_subdissector_list = heur_control_subdissector_list;
4191
0
                usb_dissector_table = usb_control_dissector_table;
4192
4193
0
                urb->conv = get_usb_iface_conv_info(pinfo, interface_num);
4194
0
                urb->usb_trans_info = usb_trans_info;
4195
0
                urb->endpoint = NO_ENDPOINT8;
4196
0
            }
4197
2
            else if (ctrl_recip == RQT_SETUP_RECIPIENT_ENDPOINT) {
4198
0
                address               endpoint_addr;
4199
0
                int                   endpoint;
4200
0
                uint32_t              src_endpoint, dst_endpoint;
4201
0
                conversation_t       *conversation;
4202
0
                urb_info_t           *new_urb = wmem_new(pinfo->pool, urb_info_t);
4203
4204
0
                memcpy(new_urb, urb, sizeof(urb_info_t));
4205
0
                urb = new_urb;
4206
4207
0
                heur_subdissector_list = heur_control_subdissector_list;
4208
0
                usb_dissector_table = usb_control_dissector_table;
4209
4210
0
                endpoint = usb_trans_info->setup.wIndex & 0xff;
4211
4212
0
                if (urb->is_request) {
4213
0
                    usb_address_t *dst_addr = wmem_new0(pinfo->pool, usb_address_t);
4214
0
                    dst_addr->bus_id = urb->bus_id;
4215
0
                    dst_addr->device = urb->device_address;
4216
0
                    dst_addr->endpoint = dst_endpoint = GUINT32_TO_LE(endpoint);
4217
0
                    set_address(&endpoint_addr, usb_address_type, USB_ADDR_LEN, (char *)dst_addr);
4218
4219
0
                    conversation = get_usb_conversation(pinfo, &pinfo->src, &endpoint_addr, pinfo->srcport, dst_endpoint);
4220
0
                }
4221
0
                else {
4222
0
                    usb_address_t *src_addr = wmem_new0(pinfo->pool, usb_address_t);
4223
0
                    src_addr->bus_id = urb->bus_id;
4224
0
                    src_addr->device = urb->device_address;
4225
0
                    src_addr->endpoint = src_endpoint = GUINT32_TO_LE(endpoint);
4226
0
                    set_address(&endpoint_addr, usb_address_type, USB_ADDR_LEN, (char *)src_addr);
4227
4228
0
                    conversation  = get_usb_conversation(pinfo, &endpoint_addr, &pinfo->dst, src_endpoint, pinfo->destport);
4229
0
                }
4230
4231
0
                urb->conv = get_usb_conv_info(conversation);
4232
0
                urb->usb_trans_info = usb_trans_info;
4233
0
            }
4234
2
            else {
4235
                /* the recipient is "device" or "other" or "reserved"
4236
                   there's no way for us to determine the interfaceClass
4237
                   we set the usb_dissector_table anyhow as some
4238
                   dissectors register for control messages to
4239
                   IF_CLASS_UNKNOWN (this should be fixed) */
4240
2
                heur_subdissector_list = heur_control_subdissector_list;
4241
2
                usb_dissector_table = usb_control_dissector_table;
4242
2
            }
4243
4244
2
            usb_tap_queue_packet(pinfo, urb_type, urb);
4245
2
            sub_item = proto_tree_add_uint(urb_tree, hf_usb_bInterfaceClass, next_tvb, 0, 0, urb->conv->interfaceClass);
4246
2
            proto_item_set_generated(sub_item);
4247
2
            break;
4248
4249
4
        default:
4250
4
            break;
4251
7
    }
4252
4253
    /* try "usb.protocol" on interface level */
4254
7
    protocol = (urb->conv->interfaceClass & 0xFF) << 16 |
4255
7
               (urb->conv->interfaceSubclass & 0xFF) << 8 |
4256
7
               (urb->conv->interfaceProtocol & 0xFF);
4257
7
    ret = dissector_try_uint_with_data(protocol_to_dissector, protocol,
4258
7
                                 next_tvb, pinfo, tree, true, urb);
4259
7
    if (ret)
4260
0
        return tvb_captured_length(next_tvb);
4261
4262
7
    if (try_heuristics && heur_subdissector_list) {
4263
2
        bool dissector_found = dissector_try_heuristic(heur_subdissector_list,
4264
2
                next_tvb, pinfo, use_setup_tree ? setup_tree : tree, &hdtbl_entry, urb);
4265
2
        if (dissector_found)
4266
0
            return tvb_captured_length(next_tvb);
4267
2
    }
4268
4269
7
    if (usb_dissector_table) {
4270
        /* we prefer the interface class unless it says we should refer
4271
           to the device class
4272
           XXX - use the device class if the interface class is unknown */
4273
2
        if (urb->conv->interfaceClass == IF_CLASS_DEVICE) {
4274
0
            usb_class = (urb->device_protocol>>16) & 0xFF;
4275
0
        }
4276
2
        else {
4277
2
            usb_class = urb->conv->interfaceClass;
4278
2
        }
4279
4280
2
        ret = dissector_try_uint_with_data(usb_dissector_table, usb_class,
4281
2
                next_tvb, pinfo, use_setup_tree ? setup_tree : tree, true, urb);
4282
2
        if (ret)
4283
0
            return tvb_captured_length(next_tvb);
4284
4285
        /* try protocol specific dissector if there is one */
4286
2
        usb_class = USB_PROTOCOL_KEY(urb->conv->interfaceClass,
4287
2
                                     urb->conv->interfaceSubclass,
4288
2
                                     urb->conv->interfaceProtocol);
4289
2
        ret = dissector_try_uint_with_data(usb_dissector_table, usb_class,
4290
2
                next_tvb, pinfo, use_setup_tree ? setup_tree : tree, true, urb);
4291
2
        if (ret)
4292
0
            return tvb_captured_length(next_tvb);
4293
2
    }
4294
4295
7
    return 0;
4296
7
}
4297
4298
4299
static int
4300
dissect_usb_setup_response(packet_info *pinfo, proto_tree *tree,
4301
                           tvbuff_t *tvb, int offset,
4302
                           uint8_t urb_type, urb_info_t *urb)
4303
2
{
4304
2
    proto_tree *parent;
4305
2
    tvbuff_t   *next_tvb = NULL;
4306
2
    int         length_remaining;
4307
4308
2
    parent = proto_tree_get_parent_tree(tree);
4309
4310
2
    if (urb) {
4311
2
        if (urb->usb_trans_info && is_usb_standard_setup_request(urb->usb_trans_info)) {
4312
0
            offset = dissect_usb_standard_setup_response(pinfo, parent, tvb, offset, urb);
4313
0
        }
4314
2
        else {
4315
2
            next_tvb = tvb_new_subset_remaining(tvb, offset);
4316
2
            offset += try_dissect_next_protocol(parent, next_tvb, pinfo, urb, urb_type, tree, NULL);
4317
4318
2
            length_remaining = tvb_reported_length_remaining(tvb, offset);
4319
2
            if (length_remaining > 0) {
4320
1
                proto_tree_add_item(parent, hf_usb_control_response_generic,
4321
1
                        tvb, offset, length_remaining, ENC_NA);
4322
1
                offset += length_remaining;
4323
1
            }
4324
2
        }
4325
2
    }
4326
0
    else {
4327
        /* no matching request available */
4328
0
        length_remaining = tvb_reported_length_remaining(tvb, offset);
4329
0
        if (length_remaining > 0) {
4330
0
            proto_tree_add_item(parent, hf_usb_control_response_generic, tvb,
4331
0
                    offset, length_remaining, ENC_NA);
4332
0
            offset += length_remaining;
4333
0
        }
4334
0
    }
4335
4336
2
    return offset;
4337
2
}
4338
4339
4340
static int
4341
dissect_usb_bmrequesttype(proto_tree *parent_tree, tvbuff_t *tvb, int offset, uint8_t *byte)
4342
3
{
4343
3
    uint64_t val;
4344
4345
3
    static int * const bmRequestType_bits[] = {
4346
3
        &hf_usb_bmRequestType_direction,
4347
3
        &hf_usb_bmRequestType_type,
4348
3
        &hf_usb_bmRequestType_recipient,
4349
3
        NULL
4350
3
    };
4351
4352
3
    proto_tree_add_bitmask_with_flags_ret_uint64(parent_tree, tvb, offset, hf_usb_bmRequestType, ett_usb_setup_bmrequesttype,
4353
3
                                                 bmRequestType_bits, ENC_LITTLE_ENDIAN, BMT_NO_APPEND, &val);
4354
3
    *byte = (uint8_t) val;
4355
4356
3
    return ++offset;
4357
3
}
4358
4359
int
4360
dissect_urb_transfer_flags(tvbuff_t *tvb, int offset, proto_tree* tree, int hf, int endian)
4361
12
{
4362
12
    proto_tree_add_bitmask(tree, tvb, offset, hf, ett_transfer_flags, transfer_flags_fields, endian);
4363
12
    return 4;
4364
12
}
4365
4366
static int
4367
dissect_linux_usb_pseudo_header_ext(tvbuff_t *tvb, int offset,
4368
                                    packet_info *pinfo _U_,
4369
                                    proto_tree *tree)
4370
13
{
4371
13
    proto_tree_add_item(tree, hf_usb_urb_interval, tvb, offset, 4, ENC_HOST_ENDIAN);
4372
13
    offset += 4;
4373
13
    proto_tree_add_item(tree, hf_usb_urb_start_frame, tvb, offset, 4, ENC_HOST_ENDIAN);
4374
13
    offset += 4;
4375
13
    dissect_urb_transfer_flags(tvb, offset, tree, hf_usb_urb_copy_of_transfer_flags, ENC_HOST_ENDIAN);
4376
13
    offset += 4;
4377
13
    proto_tree_add_item(tree, hf_usb_iso_numdesc, tvb, offset, 4, ENC_HOST_ENDIAN);
4378
13
    offset += 4;
4379
4380
13
    return offset;
4381
13
}
4382
4383
4384
/* Dissector used for usb setup requests */
4385
static int
4386
dissect_usb_setup_request(packet_info *pinfo, proto_tree *tree,
4387
                          tvbuff_t *tvb, int offset,
4388
                          uint8_t urb_type, urb_info_t *urb,
4389
                          usb_header_t header_type, uint64_t usb_id)
4390
3
{
4391
3
    int               setup_offset;
4392
3
    int               req_type;
4393
3
    int               ret;
4394
3
    proto_tree       *parent, *setup_tree;
4395
3
    usb_trans_info_t *usb_trans_info, trans_info;
4396
3
    tvbuff_t         *next_tvb, *data_tvb = NULL;
4397
3
    uint8_t           bm_request_type;
4398
4399
    /* we should do the NULL check in all non-static functions */
4400
3
    if (urb)
4401
3
        usb_trans_info = urb->usb_trans_info;
4402
0
    else
4403
0
        usb_trans_info = &trans_info;
4404
4405
3
    parent = proto_tree_get_parent_tree(tree);
4406
4407
3
    setup_tree = proto_tree_add_subtree(parent, tvb, offset, 8, ett_usb_setup_hdr, NULL, "Setup Data");
4408
4409
3
    req_type = USB_TYPE(tvb_get_uint8(tvb, offset));
4410
3
    usb_trans_info->setup.requesttype = tvb_get_uint8(tvb, offset);
4411
3
    if (urb) {
4412
3
        urb->setup_requesttype = tvb_get_uint8(tvb, offset);
4413
3
        if (req_type != RQT_SETUP_TYPE_CLASS)
4414
2
            usb_tap_queue_packet(pinfo, urb_type, urb);
4415
3
    }
4416
4417
3
    offset = dissect_usb_bmrequesttype(setup_tree, tvb, offset, &bm_request_type);
4418
4419
    /* as we're going through the data, we build a next_tvb that
4420
       contains the the setup packet without the request type
4421
       and request-specific data
4422
       all subsequent dissection routines work on this tvb */
4423
4424
3
    setup_offset = offset;
4425
3
    usb_trans_info->setup.request = tvb_get_uint8(tvb, offset);
4426
3
    offset++;
4427
3
    usb_trans_info->setup.wValue  = tvb_get_letohs(tvb, offset);
4428
3
    offset += 2;
4429
3
    usb_trans_info->setup.wIndex  = tvb_get_letohs(tvb, offset);
4430
3
    offset += 2;
4431
3
    usb_trans_info->setup.wLength = tvb_get_letohs(tvb, offset);
4432
3
    offset += 2;
4433
4434
3
    if (header_type == USB_HEADER_LINUX_64_BYTES) {
4435
0
        offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
4436
3
    } else if (header_type == USB_HEADER_USBPCAP) {
4437
0
        if ((bm_request_type & 0x80) == 0 &&
4438
0
            usb_trans_info->setup.wLength > 0 &&
4439
0
            tvb_reported_length_remaining(tvb, offset) == 0) {
4440
            /* UPBPcap older than 1.5.0.0 packet, save setup data
4441
               and do not call subdissector */
4442
0
            if (!PINFO_FD_VISITED(pinfo)) {
4443
0
                wmem_tree_key_t key[3];
4444
0
                usbpcap_setup_data_t *setup_data = wmem_new(wmem_file_scope(), usbpcap_setup_data_t);
4445
0
                setup_data->usb_id = usb_id;
4446
0
                tvb_memcpy(tvb, setup_data->setup_data, setup_offset-1, 8);
4447
0
                key[0].length = 2;
4448
0
                key[0].key = (uint32_t *)&usb_id;
4449
0
                key[1].length = 1;
4450
0
                key[1].key = &pinfo->num;
4451
0
                key[2].length = 0;
4452
0
                key[2].key = NULL;
4453
0
                wmem_tree_insert32_array(usbpcap_setup_data, key, setup_data);
4454
0
            }
4455
0
            proto_tree_add_item(setup_tree, hf_usb_request_unknown_class, tvb, setup_offset, 1, ENC_LITTLE_ENDIAN);
4456
0
            dissect_usb_setup_generic(pinfo, setup_tree, tvb, setup_offset+1, urb);
4457
0
            return offset;
4458
0
        }
4459
0
    }
4460
4461
4462
3
    if (tvb_captured_length_remaining(tvb, offset) > 0) {
4463
3
        next_tvb = tvb_new_composite();
4464
3
        tvb_composite_append(next_tvb, tvb_new_subset_length(tvb, setup_offset, 7));
4465
4466
3
        data_tvb = tvb_new_subset_remaining(tvb, offset);
4467
3
        tvb_composite_append(next_tvb, data_tvb);
4468
3
        offset += tvb_captured_length(data_tvb);
4469
3
        tvb_composite_finalize(next_tvb);
4470
3
        next_tvb = tvb_new_child_real_data(tvb,
4471
3
                (const uint8_t *) tvb_memdup(pinfo->pool, next_tvb, 0, tvb_captured_length(next_tvb)),
4472
3
                tvb_captured_length(next_tvb),
4473
3
                tvb_captured_length(next_tvb));
4474
3
        add_new_data_source(pinfo, next_tvb, "USB Control");
4475
3
    } else {
4476
0
        next_tvb = tvb_new_subset_length(tvb, setup_offset, 7);
4477
0
    }
4478
4479
    /* at this point, offset contains the number of bytes that we
4480
       dissected */
4481
4482
3
    if (is_usb_standard_setup_request(usb_trans_info)) {
4483
        /* there's no point in checking the return value as there's no
4484
           fallback for standard setup requests */
4485
1
        dissect_usb_standard_setup_request(pinfo, setup_tree,
4486
1
                next_tvb, urb, usb_trans_info);
4487
1
    }
4488
2
    else {
4489
        /* no standard request - pass it on to class-specific dissectors */
4490
2
        ret = try_dissect_next_protocol(
4491
2
                parent, next_tvb, pinfo, urb, urb_type, tree, setup_tree);
4492
2
        if (ret <= 0) {
4493
            /* no class-specific dissector could handle it,
4494
               dissect it as generic setup request */
4495
2
            proto_tree_add_item(setup_tree, hf_usb_request_unknown_class,
4496
2
                    next_tvb, 0, 1, ENC_LITTLE_ENDIAN);
4497
2
            dissect_usb_setup_generic(pinfo, setup_tree,
4498
2
                    next_tvb, 1, urb);
4499
2
        }
4500
        /* at this point, non-standard request has been dissected */
4501
2
    }
4502
4503
3
    if (data_tvb)
4504
3
        proto_tree_add_item(setup_tree, hf_usb_data_fragment, data_tvb, 0, -1, ENC_NA);
4505
4506
3
    return offset;
4507
3
}
4508
4509
4510
/* dissect the linux-specific USB pseudo header and fill the conversation struct
4511
   return the number of dissected bytes */
4512
static int
4513
dissect_linux_usb_pseudo_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
4514
        urb_info_t *urb, uint64_t *urb_id)
4515
14
{
4516
14
    uint8_t transfer_type;
4517
14
    uint8_t endpoint_byte;
4518
14
    uint8_t transfer_type_and_direction;
4519
14
    uint8_t urb_type;
4520
14
    uint32_t flag;
4521
14
    uint32_t bus_id;
4522
4523
14
    *urb_id = tvb_get_uint64(tvb, 0, ENC_HOST_ENDIAN);
4524
14
    proto_tree_add_uint64(tree, hf_usb_urb_id, tvb, 0, 8, *urb_id);
4525
4526
    /* show the urb type of this URB as string and as a character */
4527
14
    urb_type = tvb_get_uint8(tvb, 8);
4528
14
    urb->is_request = (urb_type==URB_SUBMIT);
4529
14
    proto_tree_add_uint(tree, hf_usb_linux_urb_type, tvb, 8, 1, urb_type);
4530
14
    proto_tree_add_item_ret_uint8(tree, hf_usb_linux_transfer_type, tvb, 9, 1, ENC_LITTLE_ENDIAN, &transfer_type);
4531
4532
14
    urb->transfer_type = transfer_type;
4533
4534
14
    endpoint_byte = tvb_get_uint8(tvb, 10);   /* direction bit | endpoint */
4535
14
    urb->endpoint = endpoint_byte;
4536
14
    if (endpoint_byte & URB_TRANSFER_IN)
4537
2
        urb->direction = P2P_DIR_RECV;
4538
12
    else
4539
12
        urb->direction = P2P_DIR_SENT;
4540
4541
14
    transfer_type_and_direction = (transfer_type & 0x7F) | (endpoint_byte & 0x80);
4542
14
    col_append_str(pinfo->cinfo, COL_INFO,
4543
14
                    val_to_str(pinfo->pool, transfer_type_and_direction, usb_transfer_type_and_direction_vals, "Unknown type %x"));
4544
4545
14
    proto_tree_add_bitmask(tree, tvb, 10, hf_usb_endpoint_address, ett_usb_endpoint, usb_endpoint_fields, ENC_NA);
4546
14
    proto_tree_add_item(tree, hf_usb_device_address, tvb, 11, 1, ENC_LITTLE_ENDIAN);
4547
14
    urb->device_address = (uint16_t)tvb_get_uint8(tvb, 11);
4548
4549
14
    proto_tree_add_item_ret_uint(tree, hf_usb_bus_id, tvb, 12, 2, ENC_HOST_ENDIAN, &bus_id);
4550
14
    urb->bus_id = (uint16_t) bus_id;
4551
4552
    /* Right after the pseudo header we always have
4553
     * sizeof(struct usb_device_setup_hdr) bytes. The content of these
4554
     * bytes only have meaning in case setup_flag == 0.
4555
     */
4556
14
    proto_tree_add_item_ret_uint(tree, hf_usb_setup_flag, tvb, 14, 1, ENC_ASCII, &flag);
4557
14
    if (flag == 0) {
4558
3
        urb->is_setup = true;
4559
3
        if (urb->transfer_type!=URB_CONTROL)
4560
3
            proto_tree_add_expert(tree, pinfo, &ei_usb_invalid_setup, tvb, 14, 1);
4561
11
    } else {
4562
11
        urb->is_setup = false;
4563
11
    }
4564
4565
14
    proto_tree_add_item(tree, hf_usb_data_flag, tvb, 15, 1, ENC_ASCII);
4566
4567
14
    proto_tree_add_item(tree, hf_usb_urb_ts_sec, tvb, 16, 8, ENC_HOST_ENDIAN);
4568
14
    proto_tree_add_item(tree, hf_usb_urb_ts_usec, tvb, 24, 4, ENC_HOST_ENDIAN);
4569
14
    proto_tree_add_item(tree, hf_usb_urb_status, tvb, 28, 4, ENC_HOST_ENDIAN);
4570
14
    proto_tree_add_item(tree, hf_usb_urb_len, tvb, 32, 4, ENC_HOST_ENDIAN);
4571
14
    proto_tree_add_item(tree, hf_usb_urb_data_len, tvb, 36, 4, ENC_HOST_ENDIAN);
4572
4573
14
    return 40;
4574
14
}
4575
4576
/* dissect the usbpcap_buffer_packet_header and fill the conversation struct
4577
   this function does not handle the transfer-specific headers
4578
   return the number of bytes processed */
4579
static int
4580
dissect_usbpcap_buffer_packet_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
4581
        urb_info_t *urb, uint32_t *win32_data_len, uint64_t *irp_id)
4582
9
{
4583
9
    proto_item *item;
4584
9
    uint32_t function_code;
4585
9
    uint8_t  transfer_type;
4586
9
    uint8_t  endpoint_byte;
4587
9
    uint8_t  transfer_type_and_direction;
4588
9
    uint8_t  tmp_val8;
4589
4590
9
    proto_tree_add_item(tree, hf_usb_win32_header_len, tvb, 0, 2, ENC_LITTLE_ENDIAN);
4591
9
    *irp_id = tvb_get_uint64(tvb, 2, ENC_LITTLE_ENDIAN);
4592
9
    proto_tree_add_uint64(tree, hf_usb_irp_id, tvb, 2, 8, *irp_id);
4593
9
    proto_tree_add_item(tree, hf_usb_usbd_status, tvb, 10, 4, ENC_LITTLE_ENDIAN);
4594
9
    proto_tree_add_item_ret_uint(tree, hf_usb_function, tvb, 14, 2, ENC_LITTLE_ENDIAN, &function_code);
4595
4596
9
    proto_tree_add_bitmask(tree, tvb, 16, hf_usb_info, ett_usb_usbpcap_info, usb_usbpcap_info_fields, ENC_LITTLE_ENDIAN);
4597
9
    tmp_val8 = tvb_get_uint8(tvb, 16);
4598
    /* TODO: Handle errors */
4599
9
    if (tmp_val8 & 0x01) {
4600
7
        urb->is_request = false;
4601
7
    } else {
4602
2
        urb->is_request = true;
4603
2
    }
4604
4605
9
    proto_tree_add_item(tree, hf_usb_bus_id, tvb, 17, 2, ENC_LITTLE_ENDIAN);
4606
9
    urb->bus_id = tvb_get_letohs(tvb, 17);
4607
4608
9
    proto_tree_add_item(tree, hf_usb_win32_device_address, tvb, 19, 2, ENC_LITTLE_ENDIAN);
4609
9
    urb->device_address = tvb_get_letohs(tvb, 19);
4610
4611
9
    endpoint_byte = tvb_get_uint8(tvb, 21);
4612
9
    urb->direction = endpoint_byte&URB_TRANSFER_IN ?  P2P_DIR_RECV : P2P_DIR_SENT;
4613
9
    urb->endpoint = endpoint_byte;
4614
9
    proto_tree_add_bitmask(tree, tvb, 21, hf_usb_endpoint_address, ett_usb_endpoint, usb_endpoint_fields, ENC_LITTLE_ENDIAN);
4615
4616
9
    transfer_type = tvb_get_uint8(tvb, 22);
4617
9
    urb->transfer_type = transfer_type;
4618
9
    item = proto_tree_add_item(tree, hf_usb_win32_transfer_type, tvb, 22, 1, ENC_LITTLE_ENDIAN);
4619
9
    if (transfer_type == URB_UNKNOWN) {
4620
2
        expert_add_info(pinfo, item, &ei_usb_usbpcap_unknown_urb);
4621
2
    }
4622
4623
    /* Workaround bug in captures created with USBPcap earlier than 1.3.0.0 */
4624
9
    if ((endpoint_byte == 0x00) && (transfer_type == URB_CONTROL) && (tvb_get_uint8(tvb, 27) == USB_CONTROL_STAGE_DATA)) {
4625
0
        urb->is_request = true;
4626
0
    }
4627
4628
9
    if (transfer_type != USBPCAP_URB_IRP_INFO) {
4629
9
        transfer_type_and_direction = (transfer_type & 0x7F) | (endpoint_byte & 0x80);
4630
9
        col_append_str(pinfo->cinfo, COL_INFO,
4631
9
            val_to_str(pinfo->pool, transfer_type_and_direction, usb_transfer_type_and_direction_vals, "Unknown type %x"));
4632
9
    } else {
4633
0
        col_append_str(pinfo->cinfo, COL_INFO,
4634
0
            val_to_str_ext(pinfo->pool, function_code, &win32_urb_function_vals_ext, "Unknown function %x"));
4635
0
    }
4636
4637
9
    *win32_data_len = tvb_get_letohl(tvb, 23);
4638
9
    proto_tree_add_item(tree, hf_usb_win32_data_len, tvb, 23, 4, ENC_LITTLE_ENDIAN);
4639
4640
    /* by default, we assume it's no setup packet
4641
       the correct values will be set when we parse the control header */
4642
9
    urb->is_setup = false;
4643
9
    urb->setup_requesttype = 0;
4644
4645
    /* we don't handle the transfer-specific headers here */
4646
9
    return 27;
4647
9
}
4648
4649
4650
static int
4651
dissect_darwin_buffer_packet_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
4652
        urb_info_t *urb, uint64_t *id)
4653
5
{
4654
5
    uint8_t  transfer_type;
4655
5
    uint8_t  request_type;
4656
5
    uint8_t  endpoint_byte;
4657
5
    uint8_t  transfer_type_and_direction;
4658
5
    uint8_t  header_length;
4659
4660
5
    proto_tree_add_item(tree, hf_usb_darwin_bcd_version, tvb, 0, 2, ENC_LITTLE_ENDIAN);
4661
4662
5
    header_length = tvb_get_uint8(tvb, 2);
4663
5
    proto_tree_add_item(tree, hf_usb_darwin_header_len, tvb, 2, 1, ENC_LITTLE_ENDIAN);
4664
4665
5
    request_type = tvb_get_uint8(tvb, 3);
4666
5
    urb->is_request = (request_type == DARWIN_IO_SUBMIT);
4667
5
    proto_tree_add_uint(tree, hf_usb_darwin_request_type, tvb, 3, 1, request_type);
4668
4669
5
    proto_tree_add_item(tree, hf_usb_darwin_io_len, tvb, 4, 4, ENC_LITTLE_ENDIAN);
4670
4671
5
    proto_tree_add_item(tree, hf_usb_darwin_io_status, tvb, 8, 4, ENC_LITTLE_ENDIAN);
4672
4673
5
    proto_tree_add_item(tree, hf_usb_darwin_iso_num_packets, tvb, 12, 4, ENC_LITTLE_ENDIAN);
4674
4675
5
    *id = tvb_get_uint64(tvb, 16, ENC_LITTLE_ENDIAN);
4676
5
    proto_tree_add_uint64(tree, hf_usb_darwin_io_id, tvb, 16, 8, *id);
4677
4678
5
    proto_tree_add_item(tree, hf_usb_darwin_device_location, tvb, 24, 4, ENC_LITTLE_ENDIAN);
4679
5
    urb->bus_id = tvb_get_letohl(tvb, 24) >> 24;
4680
4681
5
    proto_tree_add_item(tree, hf_usb_darwin_speed, tvb, 28, 1, ENC_LITTLE_ENDIAN);
4682
4683
5
    urb->device_address = (uint16_t)tvb_get_uint8(tvb, 29);
4684
5
    proto_tree_add_uint(tree, hf_usb_darwin_device_address, tvb, 29, 1, urb->device_address);
4685
4686
5
    endpoint_byte = tvb_get_uint8(tvb, 30);   /* direction bit | endpoint */
4687
5
    urb->endpoint = endpoint_byte;
4688
5
    if (endpoint_byte & URB_TRANSFER_IN) {
4689
0
        urb->direction = P2P_DIR_RECV;
4690
0
    }
4691
5
    else {
4692
5
        urb->direction = P2P_DIR_SENT;
4693
5
    }
4694
5
    proto_tree_add_uint(tree, hf_usb_darwin_endpoint_address, tvb, 30, 1, endpoint_byte);
4695
5
    proto_tree_add_bitmask(tree, tvb, 30, hf_usb_endpoint_number, ett_usb_endpoint, usb_endpoint_fields, ENC_LITTLE_ENDIAN);
4696
4697
5
    transfer_type = MIN(tvb_get_uint8(tvb, 31), G_N_ELEMENTS(darwin_endpoint_to_linux) - 1);
4698
5
    urb->transfer_type = darwin_endpoint_to_linux[transfer_type];
4699
5
    proto_tree_add_uint(tree, hf_usb_darwin_endpoint_type, tvb, 31, 1, transfer_type);
4700
4701
5
    transfer_type_and_direction = (darwin_endpoint_to_linux[transfer_type] & 0x7F) | (endpoint_byte & 0x80);
4702
5
    col_append_str(pinfo->cinfo, COL_INFO,
4703
5
                   val_to_str(pinfo->pool, transfer_type_and_direction, usb_transfer_type_and_direction_vals, "Unknown type %x"));
4704
5
    col_append_str(pinfo->cinfo, COL_INFO, urb->is_request == true ? " (submitted)" : " (completed)");
4705
4706
5
    urb->is_setup = false;
4707
5
    if ((urb->is_request == true) && (urb->transfer_type == URB_CONTROL)) {
4708
3
        urb->is_setup = true;
4709
3
    }
4710
4711
5
    urb->setup_requesttype = 0;
4712
4713
    /* we don't handle the transfer-specific headers here */
4714
5
    return header_length;
4715
5
}
4716
4717
/* Set the usb_address_t fields based on the direction of the urb */
4718
static void
4719
usb_set_addr(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, uint16_t bus_id, uint16_t device_address,
4720
             int endpoint, bool req)
4721
28
{
4722
28
    proto_item     *sub_item;
4723
28
    usb_address_t  *src_addr = wmem_new0(pinfo->pool, usb_address_t),
4724
28
                   *dst_addr = wmem_new0(pinfo->pool, usb_address_t);
4725
28
    const char     *str_src_addr;
4726
28
    const char     *str_dst_addr;
4727
4728
28
    if (req) {
4729
        /* request */
4730
6
        src_addr->device   = 0xffffffff;
4731
6
        src_addr->endpoint = NO_ENDPOINT;
4732
6
        dst_addr->device   = GUINT16_TO_LE(device_address);
4733
6
        dst_addr->endpoint = GUINT32_TO_LE(endpoint);
4734
22
    } else {
4735
        /* response */
4736
22
        src_addr->device   = GUINT16_TO_LE(device_address);
4737
22
        src_addr->endpoint = GUINT32_TO_LE(endpoint);
4738
22
        dst_addr->device   = 0xffffffff;
4739
22
        dst_addr->endpoint = NO_ENDPOINT;
4740
22
    }
4741
28
    src_addr->bus_id = GUINT16_TO_LE(bus_id);
4742
28
    dst_addr->bus_id = GUINT16_TO_LE(bus_id);
4743
4744
28
    set_address(&pinfo->net_src, usb_address_type, USB_ADDR_LEN, (char *)src_addr);
4745
28
    copy_address_shallow(&pinfo->src, &pinfo->net_src);
4746
28
    set_address(&pinfo->net_dst, usb_address_type, USB_ADDR_LEN, (char *)dst_addr);
4747
28
    copy_address_shallow(&pinfo->dst, &pinfo->net_dst);
4748
4749
28
    pinfo->ptype = PT_USB;
4750
28
    pinfo->srcport = src_addr->endpoint;
4751
28
    pinfo->destport = dst_addr->endpoint;
4752
    /* sent/received is from the perspective of the USB host */
4753
28
    pinfo->p2p_dir = req ? P2P_DIR_SENT : P2P_DIR_RECV;
4754
4755
28
    str_src_addr = address_to_str(pinfo->pool, &pinfo->src);
4756
28
    str_dst_addr = address_to_str(pinfo->pool, &pinfo->dst);
4757
4758
28
    sub_item = proto_tree_add_string(tree, hf_usb_src, tvb, 0, 0, str_src_addr);
4759
28
    proto_item_set_generated(sub_item);
4760
4761
28
    sub_item = proto_tree_add_string(tree, hf_usb_addr, tvb, 0, 0, str_src_addr);
4762
28
    proto_item_set_hidden(sub_item);
4763
4764
28
    sub_item = proto_tree_add_string(tree, hf_usb_dst, tvb, 0, 0, str_dst_addr);
4765
28
    proto_item_set_generated(sub_item);
4766
4767
28
    sub_item = proto_tree_add_string(tree, hf_usb_addr, tvb, 0, 0, str_dst_addr);
4768
28
    proto_item_set_hidden(sub_item);
4769
28
}
4770
4771
4772
/* Gets the transfer info for a given packet
4773
 * Generates transfer info if none exists yet
4774
 * Also adds request/response info to the tree for the given packet */
4775
static usb_trans_info_t
4776
*usb_get_trans_info(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
4777
                    usb_header_t header_type, urb_info_t *urb, uint64_t usb_id)
4778
25
{
4779
25
    usb_trans_info_t *usb_trans_info;
4780
25
    proto_item       *ti;
4781
25
    nstime_t          t, deltat;
4782
25
    wmem_tree_key_t   key[3];
4783
4784
    /* request/response matching so we can keep track of transaction specific
4785
     * data.
4786
     */
4787
25
    key[0].length = 2;
4788
25
    key[0].key = (uint32_t *)&usb_id;
4789
25
    key[1].length = 1;
4790
25
    key[1].key = &pinfo->num;
4791
25
    key[2].length = 0;
4792
25
    key[2].key = NULL;
4793
4794
25
    if (urb->is_request) {
4795
        /* this is a request */
4796
5
        usb_trans_info = (usb_trans_info_t *)wmem_tree_lookup32_array(urb->conv->transactions, key);
4797
5
        if (!usb_trans_info) {
4798
5
            usb_trans_info              = wmem_new0(wmem_file_scope(), usb_trans_info_t);
4799
5
            usb_trans_info->request_in  = pinfo->num;
4800
5
            usb_trans_info->req_time    = pinfo->abs_ts;
4801
5
            usb_trans_info->header_type = header_type;
4802
5
            usb_trans_info->usb_id      = usb_id;
4803
4804
5
            wmem_tree_insert32_array(urb->conv->transactions, key, usb_trans_info);
4805
5
        }
4806
4807
5
        if (usb_trans_info->response_in) {
4808
0
            ti = proto_tree_add_uint(tree, hf_usb_response_in, tvb, 0, 0, usb_trans_info->response_in);
4809
0
            proto_item_set_generated(ti);
4810
0
        }
4811
4812
20
    } else {
4813
        /* this is a response */
4814
20
        if (pinfo->fd->visited) {
4815
0
            usb_trans_info = (usb_trans_info_t *)wmem_tree_lookup32_array(urb->conv->transactions, key);
4816
4817
20
        } else {
4818
20
            usb_trans_info = (usb_trans_info_t *)wmem_tree_lookup32_array_le(urb->conv->transactions, key);
4819
20
            if (usb_trans_info) {
4820
0
                if (usb_trans_info->usb_id == usb_id) {
4821
0
                    if (usb_trans_info->response_in == 0) {
4822
                        /* USBPcap generates 2 frames for response; store the first one */
4823
0
                        usb_trans_info->response_in = pinfo->num;
4824
0
                    }
4825
0
                    wmem_tree_insert32_array(urb->conv->transactions, key, usb_trans_info);
4826
0
                } else {
4827
0
                    usb_trans_info = NULL;
4828
0
                }
4829
0
            }
4830
20
        }
4831
4832
20
        if (usb_trans_info && usb_trans_info->request_in) {
4833
4834
0
            ti = proto_tree_add_uint(tree, hf_usb_request_in, tvb, 0, 0, usb_trans_info->request_in);
4835
0
            proto_item_set_generated(ti);
4836
4837
0
            t = pinfo->abs_ts;
4838
0
            nstime_delta(&deltat, &t, &usb_trans_info->req_time);
4839
0
            ti = proto_tree_add_time(tree, hf_usb_time, tvb, 0, 0, &deltat);
4840
0
            proto_item_set_generated(ti);
4841
0
        }
4842
20
    }
4843
4844
25
    return usb_trans_info;
4845
25
}
4846
4847
4848
/* dissect a group of isochronous packets inside an usb packet in
4849
   usbpcap format */
4850
5
#define MAX_ISO_PACKETS 100000 // Arbitrary
4851
static int
4852
dissect_usbpcap_iso_packets(packet_info *pinfo _U_, proto_tree *urb_tree, uint8_t urb_type,
4853
        tvbuff_t *tvb, int offset, uint32_t win32_data_len, urb_info_t *urb)
4854
5
{
4855
5
    uint32_t    i;
4856
5
    uint32_t    num_packets;
4857
5
    int         data_start_offset;
4858
5
    proto_item *num_packets_ti, *urb_tree_ti;
4859
4860
5
    proto_tree_add_item(urb_tree, hf_usb_win32_iso_start_frame, tvb, offset, 4, ENC_LITTLE_ENDIAN);
4861
5
    offset += 4;
4862
4863
5
    num_packets_ti = proto_tree_add_item_ret_uint(urb_tree, hf_usb_win32_iso_num_packets, tvb, offset, 4, ENC_LITTLE_ENDIAN, &num_packets);
4864
5
    offset += 4;
4865
4866
5
    proto_tree_add_item(urb_tree, hf_usb_win32_iso_error_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);
4867
5
    offset += 4;
4868
4869
5
    if (num_packets > MAX_ISO_PACKETS) {
4870
0
        expert_add_info_format(pinfo, num_packets_ti, &ei_usb_bad_length, "Too many isochronous transfer packets (%u)", num_packets);
4871
0
        return tvb_captured_length(tvb);
4872
0
    }
4873
4874
5
    data_start_offset = offset + 12 * num_packets;
4875
5
    urb_tree_ti = proto_tree_get_parent(urb_tree);
4876
5
    proto_item_set_len(urb_tree_ti, data_start_offset);
4877
4878
32
    for (i = 0; i < num_packets; i++) {
4879
27
        uint32_t this_offset;
4880
27
        uint32_t next_offset;
4881
27
        uint32_t iso_len;
4882
27
        proto_item *iso_packet_ti, *ti;
4883
27
        proto_tree *iso_packet_tree;
4884
4885
27
        iso_packet_ti = proto_tree_add_protocol_format(
4886
27
                proto_tree_get_root(urb_tree), proto_usb,
4887
27
                tvb, offset, 12, "USB isochronous packet");
4888
27
        iso_packet_tree = proto_item_add_subtree(iso_packet_ti, ett_usb_win32_iso_packet);
4889
4890
27
        this_offset = tvb_get_letohl(tvb, offset);
4891
27
        if (num_packets - i == 1) {
4892
            /* this is the last packet */
4893
1
            next_offset = win32_data_len;
4894
26
        } else {
4895
            /* there is next packet */
4896
26
            next_offset = tvb_get_letohl(tvb, offset + 12);
4897
26
        }
4898
4899
27
        if (next_offset > this_offset) {
4900
9
            iso_len = next_offset - this_offset;
4901
18
        } else {
4902
18
            iso_len = 0;
4903
18
        }
4904
4905
        /* If this packet does not contain isochronous data, do not try to display it */
4906
27
        if (!((urb->is_request && urb->direction==P2P_DIR_SENT) ||
4907
21
             (!urb->is_request && urb->direction==P2P_DIR_RECV))) {
4908
15
            iso_len = 0;
4909
15
        }
4910
4911
27
        proto_tree_add_item(iso_packet_tree, hf_usb_win32_iso_offset, tvb, offset, 4, ENC_LITTLE_ENDIAN);
4912
27
        offset += 4;
4913
4914
27
        ti = proto_tree_add_item(iso_packet_tree, hf_usb_win32_iso_length, tvb, offset, 4, ENC_LITTLE_ENDIAN);
4915
27
        if (urb->direction==P2P_DIR_SENT) {
4916
            /* Isochronous OUT transfer */
4917
17
            proto_item_append_text(ti, " (not used)");
4918
17
        } else {
4919
            /* Isochronous IN transfer.
4920
             * Length field is being set by host controller.
4921
             */
4922
10
            if (urb->is_request) {
4923
                /* Length was not yet set */
4924
0
                proto_item_append_text(ti, " (irrelevant)");
4925
10
            } else {
4926
                /* Length was set and (should be) valid */
4927
10
                proto_item_append_text(ti, " (relevant)");
4928
10
                iso_len = tvb_get_letohl(tvb, offset);
4929
10
            }
4930
10
        }
4931
27
        offset += 4;
4932
4933
27
        ti = proto_tree_add_item(iso_packet_tree, hf_usb_win32_iso_status, tvb, offset, 4, ENC_LITTLE_ENDIAN);
4934
27
        if (urb_type == URB_SUBMIT) {
4935
2
            proto_item_append_text(ti, " (irrelevant)");
4936
25
        } else {
4937
25
            proto_item_append_text(ti, " (relevant)");
4938
25
        }
4939
27
        offset += 4;
4940
4941
27
        if (iso_len && data_start_offset + this_offset + iso_len <= tvb_captured_length(tvb)) {
4942
0
            proto_tree_add_item(iso_packet_tree, hf_usb_iso_data, tvb, (int)(data_start_offset + this_offset), (int)iso_len, ENC_NA);
4943
0
            proto_tree_set_appendix(iso_packet_tree, tvb, (int)(data_start_offset + this_offset), (int)iso_len);
4944
0
        }
4945
27
    }
4946
4947
5
    if ((urb->is_request && urb->direction==P2P_DIR_SENT) ||
4948
1
        (!urb->is_request && urb->direction==P2P_DIR_RECV)) {
4949
        /* We have dissected all the isochronous data */
4950
0
        offset += win32_data_len;
4951
0
    }
4952
4953
5
    return offset;
4954
5
}
4955
4956
4957
static int
4958
dissect_linux_usb_iso_transfer(packet_info *pinfo _U_, proto_tree *urb_tree,
4959
        usb_header_t header_type, tvbuff_t *tvb, int offset,
4960
        urb_info_t *urb)
4961
11
{
4962
11
    uint32_t    iso_numdesc = 0;
4963
11
    proto_item *tii;
4964
11
    uint32_t    i;
4965
11
    unsigned    data_base;
4966
11
    int32_t     iso_status;
4967
11
    uint32_t    iso_off = 0;
4968
11
    uint32_t    iso_len = 0;
4969
4970
11
    tii = proto_tree_add_uint(urb_tree, hf_usb_bInterfaceClass, tvb, offset, 0, urb->conv->interfaceClass);
4971
11
    proto_item_set_generated(tii);
4972
4973
    /* All fields which belong to Linux usbmon headers are in host-endian
4974
     * byte order. The fields coming from the USB communication are in little
4975
     * endian format (see usb_20.pdf, chapter 8.1 Byte/Bit ordering).
4976
     *
4977
     * When a capture file is transferred to a host with different endianness
4978
     * than packet was captured then the necessary swapping happens in
4979
     * wiretap/pcap-common.c, pcap_byteswap_linux_usb_pseudoheader().
4980
     */
4981
4982
    /* iso urbs on linux can't possibly contain a setup packet
4983
       see mon_bin_event() in the linux kernel */
4984
4985
11
    proto_tree_add_item(urb_tree, hf_usb_iso_error_count, tvb, offset, 4, ENC_HOST_ENDIAN);
4986
11
    offset += 4;
4987
4988
11
    proto_tree_add_item_ret_uint(urb_tree, hf_usb_iso_numdesc, tvb, offset, 4, ENC_HOST_ENDIAN, &iso_numdesc);
4989
11
    offset += 4;
4990
4991
11
    if (header_type == USB_HEADER_LINUX_64_BYTES) {
4992
11
        offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, urb_tree);
4993
11
    }
4994
4995
11
    data_base = offset + iso_numdesc*16;
4996
179
    for (i = 0; i<iso_numdesc; i++) {
4997
168
        proto_item   *iso_desc_ti;
4998
168
        proto_tree   *iso_desc_tree;
4999
5000
168
        iso_desc_ti = proto_tree_add_protocol_format(urb_tree, proto_usb, tvb, offset,
5001
168
                16, "USB isodesc %u", i);
5002
168
        iso_desc_tree = proto_item_add_subtree(iso_desc_ti, ett_usb_isodesc);
5003
5004
168
        proto_tree_add_item_ret_int(iso_desc_tree, hf_usb_iso_status, tvb, offset, 4, ENC_HOST_ENDIAN, &iso_status);
5005
168
        proto_item_append_text(iso_desc_ti, " [%s]", val_to_str_ext(pinfo->pool, (uint32_t)iso_status, &linux_negative_errno_vals_ext, "Error %d"));
5006
168
        offset += 4;
5007
5008
168
        proto_tree_add_item_ret_uint(iso_desc_tree, hf_usb_iso_off, tvb, offset, 4, ENC_HOST_ENDIAN, &iso_off);
5009
168
        offset += 4;
5010
5011
168
        proto_tree_add_item_ret_uint(iso_desc_tree, hf_usb_iso_len, tvb, offset, 4, ENC_HOST_ENDIAN, &iso_len);
5012
168
        if (iso_len != 0)
5013
145
            proto_item_append_text(iso_desc_ti, " (%u bytes)", iso_len);
5014
168
        offset += 4;
5015
5016
        /* Show the ISO data if we captured them and either the status
5017
           is OK or the packet is sent from host to device.
5018
           The Linux kernel sets the status field in outgoing isochronous
5019
           URBs to -EXDEV and fills the data part with valid data.
5020
         */
5021
168
        if ((pinfo->p2p_dir==P2P_DIR_SENT || !iso_status) &&
5022
16
                iso_len && data_base + iso_off + iso_len <= tvb_captured_length(tvb)) {
5023
0
            proto_tree_add_item(iso_desc_tree, hf_usb_iso_data, tvb, data_base + iso_off, iso_len, ENC_NA);
5024
0
            proto_tree_set_appendix(iso_desc_tree, tvb, (int)(data_base+iso_off), (int)iso_len);
5025
0
        }
5026
5027
168
        proto_tree_add_item(iso_desc_tree, hf_usb_iso_pad, tvb, offset, 4, ENC_HOST_ENDIAN);
5028
168
        offset += 4;
5029
168
    }
5030
5031
    /* we jump to the end of the last iso data chunk
5032
       this assumes that the iso data starts immediately after the
5033
       iso descriptors
5034
       we have to use the offsets from the last iso descriptor, we can't keep
5035
       track of the offset ourselves as there may be gaps
5036
       between data packets in the transfer buffer */
5037
11
    return data_base+iso_off+iso_len;
5038
11
}
5039
5040
static int
5041
dissect_usbip_iso_transfer(packet_info *pinfo _U_, proto_tree *urb_tree,
5042
        tvbuff_t *tvb, int offset, uint32_t iso_numdesc, uint32_t desc_offset,
5043
        urb_info_t *urb)
5044
0
{
5045
0
    proto_item *tii;
5046
0
    uint32_t    i;
5047
0
    unsigned    data_base;
5048
0
    uint32_t    iso_off = 0;
5049
0
    uint32_t    iso_len = 0;
5050
5051
0
    tii = proto_tree_add_uint(urb_tree, hf_usb_bInterfaceClass, tvb, offset, 0, urb->conv->interfaceClass);
5052
0
    proto_item_set_generated(tii);
5053
5054
    /* All fields which belong to usbip are in big-endian byte order.
5055
     * unlike the linux kernel, the usb isoc descriptor is appended at
5056
     * the end of the isoc data. We have to reassemble the pdus and jump
5057
     * to the end (actual_length) and the remaining data is the isoc
5058
     * descriptor.
5059
     */
5060
5061
0
    data_base = offset;
5062
0
    for (i = 0; i<iso_numdesc; i++) {
5063
0
        proto_item   *iso_desc_ti;
5064
0
        proto_tree   *iso_desc_tree;
5065
0
        int32_t       iso_status;
5066
5067
0
        iso_desc_ti = proto_tree_add_protocol_format(urb_tree, proto_usb, tvb, desc_offset,
5068
0
                16, "USB isodesc %u", i);
5069
0
        iso_desc_tree = proto_item_add_subtree(iso_desc_ti, ett_usb_isodesc);
5070
5071
0
        proto_tree_add_item_ret_uint(iso_desc_tree, hf_usb_iso_off, tvb, desc_offset, 4, ENC_BIG_ENDIAN, &iso_off);
5072
0
        desc_offset += 4;
5073
5074
0
        proto_tree_add_item(iso_desc_tree, hf_usb_iso_len, tvb, desc_offset, 4, ENC_BIG_ENDIAN);
5075
0
        desc_offset += 4;
5076
5077
0
        proto_tree_add_item_ret_uint(iso_desc_tree, hf_usb_iso_actual_len, tvb, desc_offset, 4, ENC_BIG_ENDIAN, &iso_len);
5078
0
        desc_offset += 4;
5079
5080
0
        proto_tree_add_item_ret_int(iso_desc_tree, hf_usb_iso_status, tvb, desc_offset, 4, ENC_BIG_ENDIAN, &iso_status);
5081
0
        proto_item_append_text(iso_desc_ti, " [%s]", val_to_str_ext(pinfo->pool, iso_status, &linux_negative_errno_vals_ext, "Error %d"));
5082
0
        desc_offset += 4;
5083
5084
0
        if (iso_len > 0)
5085
0
            proto_item_append_text(iso_desc_ti, " (%u bytes)", iso_len);
5086
5087
        /* Show the ISO data if we captured them and either the status
5088
           is OK or the packet is sent from host to device.
5089
           The Linux kernel sets the status field in outgoing isochronous
5090
           URBs to -EXDEV and fills the data part with valid data.
5091
         */
5092
0
        if ((pinfo->p2p_dir==P2P_DIR_SENT || !iso_status) &&
5093
0
                iso_len && data_base + iso_off + iso_len <= tvb_reported_length(tvb)) {
5094
0
            proto_tree_add_item(iso_desc_tree, hf_usb_iso_data, tvb, (unsigned) data_base + iso_off, iso_len, ENC_NA);
5095
0
            proto_tree_set_appendix(iso_desc_tree, tvb, (unsigned) data_base + iso_off, (int)iso_len);
5096
0
        }
5097
0
    }
5098
0
    return desc_offset;
5099
0
}
5100
5101
static int
5102
dissect_darwin_usb_iso_transfer(packet_info *pinfo _U_, proto_tree *tree, usb_header_t header_type _U_,
5103
                    uint8_t urb_type _U_, tvbuff_t *tvb, int32_t offset, urb_info_t *urb)
5104
1
{
5105
1
    uint32_t    frame_length;
5106
1
    uint32_t    frame_header_length;
5107
1
    uint32_t    status;
5108
1
    uint32_t    iso_tree_start;
5109
1
    uint32_t    i;
5110
1
    uint32_t    iso_numdesc;
5111
1
    uint32_t    len;
5112
1
    proto_item *tii;
5113
5114
1
    len  = (int32_t)tvb_captured_length(tvb);
5115
1
    len -= offset;
5116
5117
1
    tii = proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, offset, 0, urb->conv->interfaceClass);
5118
1
    proto_item_set_generated(tii);
5119
5120
1
    status      = tvb_get_uint32(tvb, 8, ENC_LITTLE_ENDIAN);
5121
1
    iso_numdesc = tvb_get_uint32(tvb, 12, ENC_LITTLE_ENDIAN);
5122
5123
1
    iso_tree_start = offset;
5124
1
    for (i = 0; (i < iso_numdesc) && (len > 8 /* header len + frame len */); i++) {
5125
1
        proto_item   *iso_desc_ti;
5126
1
        proto_tree   *iso_desc_tree;
5127
5128
        /* Fetch ISO descriptor fields stored in little-endian byte order. */
5129
1
        frame_header_length = tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN);
5130
1
        frame_length        = tvb_get_uint32(tvb, offset + 4, ENC_LITTLE_ENDIAN);
5131
5132
1
        if ((len < frame_header_length) || (frame_header_length < 20)) {
5133
1
            break;
5134
1
        }
5135
5136
0
        iso_desc_ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset,
5137
0
                20, "Frame %u", i);
5138
5139
0
        iso_desc_tree = proto_item_add_subtree(iso_desc_ti, ett_usb_isodesc);
5140
5141
0
        proto_tree_add_item(iso_desc_tree, hf_usb_darwin_iso_frame_number, tvb, offset + 12, 8, ENC_LITTLE_ENDIAN);
5142
5143
0
        proto_tree_add_item(iso_desc_tree, hf_usb_iso_len, tvb, offset + 4, 4, ENC_LITTLE_ENDIAN);
5144
5145
0
        if (urb->is_request == false) {
5146
0
            proto_tree_add_item(iso_desc_tree, hf_usb_darwin_iso_timestamp, tvb, offset + 20, 8, ENC_LITTLE_ENDIAN);
5147
0
            proto_tree_add_item_ret_uint(iso_desc_tree, hf_usb_darwin_iso_status, tvb, offset + 8, 4, ENC_LITTLE_ENDIAN, &status);
5148
5149
0
            proto_item_append_text(iso_desc_ti, " [%s]", val_to_str_ext(pinfo->pool, status, &usb_darwin_status_vals_ext, "Error %d"));
5150
5151
            /* Data */
5152
0
            if (frame_length > len) {
5153
0
                frame_length = len;
5154
0
            }
5155
5156
0
            proto_tree_add_item(iso_desc_tree, hf_usb_iso_data, tvb, offset + frame_header_length, frame_length, ENC_NA);
5157
0
            proto_tree_set_appendix(iso_desc_tree, tvb, (int)iso_tree_start, (int)(offset - iso_tree_start));
5158
5159
0
            len    -= frame_length;
5160
0
            offset += frame_length;
5161
0
        }
5162
5163
        /* Padding to align the next header */
5164
0
        offset        += frame_header_length;
5165
0
        offset         = WS_ROUNDUP_4(offset);
5166
0
        iso_tree_start = offset;
5167
5168
0
        len -= frame_header_length;
5169
0
    }
5170
5171
1
    return offset;
5172
1
}
5173
5174
static int
5175
dissect_usb_payload(tvbuff_t *tvb, packet_info *pinfo,
5176
                    proto_tree *parent, proto_tree *tree,
5177
                    urb_info_t *urb, uint8_t urb_type,
5178
                    int offset, uint16_t device_address)
5179
8
{
5180
8
    wmem_tree_key_t          key[4];
5181
8
    uint32_t                 k_frame_number;
5182
8
    uint32_t                 k_device_address;
5183
8
    uint32_t                 k_bus_id;
5184
8
    device_product_data_t   *device_product_data = NULL;
5185
8
    device_protocol_data_t  *device_protocol_data = NULL;
5186
8
    tvbuff_t                *next_tvb = NULL;
5187
5188
8
    k_frame_number = pinfo->num;
5189
8
    k_device_address = device_address;
5190
8
    k_bus_id = urb->bus_id;
5191
5192
8
    key[0].length = 1;
5193
8
    key[0].key    = &k_device_address;
5194
8
    key[1].length = 1;
5195
8
    key[1].key    = &k_bus_id;
5196
8
    key[2].length = 1;
5197
8
    key[2].key    = &k_frame_number;
5198
8
    key[3].length = 0;
5199
8
    key[3].key    = NULL;
5200
5201
8
    device_product_data = (device_product_data_t *) wmem_tree_lookup32_array_le(device_to_product_table, key);
5202
8
    if (device_product_data && device_product_data->bus_id == urb->bus_id &&
5203
0
            device_product_data->device_address == device_address) {
5204
0
        p_add_proto_data(pinfo->pool, pinfo, proto_usb, USB_VENDOR_ID, GUINT_TO_POINTER((unsigned)device_product_data->vendor));
5205
0
        p_add_proto_data(pinfo->pool, pinfo, proto_usb, USB_PRODUCT_ID, GUINT_TO_POINTER((unsigned)device_product_data->product));
5206
0
        urb->conv->deviceVendor = device_product_data->vendor;
5207
0
        urb->conv->deviceProduct = device_product_data->product;
5208
0
        urb->conv->deviceVersion = device_product_data->device;
5209
0
    }
5210
5211
8
    device_protocol_data = (device_protocol_data_t *) wmem_tree_lookup32_array_le(device_to_protocol_table, key);
5212
8
    if (device_protocol_data && device_protocol_data->bus_id == urb->bus_id &&
5213
0
            device_protocol_data->device_address == device_address) {
5214
0
        p_add_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_CLASS, GUINT_TO_POINTER(device_protocol_data->protocol >> 16));
5215
0
        p_add_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_SUBCLASS, GUINT_TO_POINTER((device_protocol_data->protocol >> 8) & 0xFF));
5216
0
        p_add_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_PROTOCOL, GUINT_TO_POINTER(device_protocol_data->protocol & 0xFF));
5217
0
        urb->device_protocol = device_protocol_data->protocol;
5218
0
    }
5219
5220
8
    p_add_proto_data(pinfo->pool, pinfo, proto_usb, USB_BUS_ID, GUINT_TO_POINTER((unsigned)urb->bus_id));
5221
8
    p_add_proto_data(pinfo->pool, pinfo, proto_usb, USB_DEVICE_ADDRESS, GUINT_TO_POINTER((unsigned)device_address));
5222
5223
8
    if (tvb_captured_length_remaining(tvb, offset) > 0) {
5224
4
        next_tvb = tvb_new_subset_remaining(tvb, offset);
5225
4
        offset += try_dissect_next_protocol(parent, next_tvb, pinfo, urb, urb_type, tree, NULL);
5226
4
    }
5227
5228
8
    if (tvb_captured_length_remaining(tvb, offset) > 0) {
5229
        /* There is still leftover capture data to add (padding?) */
5230
4
        proto_tree_add_item(parent, hf_usb_capdata, tvb, offset, -1, ENC_NA);
5231
4
    }
5232
5233
8
    return offset;
5234
8
}
5235
5236
static int
5237
dissect_freebsd_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, void *data _U_)
5238
6
{
5239
6
    int offset = 0;
5240
6
    proto_item *ti;
5241
6
    proto_tree *tree = NULL, *frame_tree = NULL;
5242
6
    uint32_t nframes;
5243
6
    uint32_t i;
5244
5245
6
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "USB");
5246
5247
    /* add usb hdr*/
5248
6
    if (parent) {
5249
6
      ti = proto_tree_add_protocol_format(parent, proto_usb, tvb, 0, 128,
5250
6
                                          "USB URB");
5251
6
      tree = proto_item_add_subtree(ti, ett_usb_hdr);
5252
6
    }
5253
5254
6
    proto_tree_add_item(tree, hf_usb_totlen, tvb, 0, 4, ENC_LITTLE_ENDIAN);
5255
6
    proto_tree_add_item(tree, hf_usb_busunit, tvb, 4, 4, ENC_LITTLE_ENDIAN);
5256
6
    proto_tree_add_item(tree, hf_usb_address, tvb, 8, 1, ENC_LITTLE_ENDIAN);
5257
6
    proto_tree_add_item(tree, hf_usb_mode, tvb, 9, 1, ENC_LITTLE_ENDIAN);
5258
6
    proto_tree_add_item(tree, hf_usb_freebsd_urb_type, tvb, 10, 1, ENC_LITTLE_ENDIAN);
5259
6
    proto_tree_add_item(tree, hf_usb_freebsd_transfer_type, tvb, 11, 1, ENC_LITTLE_ENDIAN);
5260
6
    proto_tree_add_bitmask(tree, tvb, 12, hf_usb_xferflags, ett_usb_xferflags,
5261
6
                           usb_xferflags_fields, ENC_LITTLE_ENDIAN);
5262
6
    proto_tree_add_bitmask(tree, tvb, 16, hf_usb_xferstatus, ett_usb_xferstatus,
5263
6
                           usb_xferstatus_fields, ENC_LITTLE_ENDIAN);
5264
6
    proto_tree_add_item(tree, hf_usb_error, tvb, 20, 4, ENC_LITTLE_ENDIAN);
5265
6
    proto_tree_add_item(tree, hf_usb_interval, tvb, 24, 4, ENC_LITTLE_ENDIAN);
5266
6
    proto_tree_add_item_ret_uint(tree, hf_usb_nframes, tvb, 28, 4, ENC_LITTLE_ENDIAN, &nframes);
5267
6
    proto_tree_add_item(tree, hf_usb_packet_size, tvb, 32, 4, ENC_LITTLE_ENDIAN);
5268
6
    proto_tree_add_item(tree, hf_usb_packet_count, tvb, 36, 4, ENC_LITTLE_ENDIAN);
5269
6
    proto_tree_add_bitmask(tree, tvb, 40, hf_usb_endpoint_address, ett_usb_endpoint, usb_endpoint_fields, ENC_NA);
5270
6
    proto_tree_add_item(tree, hf_usb_speed, tvb, 44, 1, ENC_LITTLE_ENDIAN);
5271
5272
6
    offset += 128;
5273
46
    for (i = 0; i < nframes; i++) {
5274
40
        uint32_t framelen;
5275
40
        uint64_t frameflags;
5276
5277
40
        frame_tree = proto_tree_add_subtree_format(tree, tvb, offset, -1,
5278
40
                                                   ett_usb_frame, &ti,
5279
40
                                                   "Frame %u", i);
5280
40
        proto_tree_add_item_ret_uint(frame_tree, hf_usb_frame_length,
5281
40
                                     tvb, offset, 4, ENC_LITTLE_ENDIAN,
5282
40
                                     &framelen);
5283
40
        offset += 4;
5284
40
        proto_tree_add_bitmask_ret_uint64(frame_tree, tvb, offset,
5285
40
                                          hf_usb_frame_flags,
5286
40
                                          ett_usb_frame_flags,
5287
40
                                          usb_frame_flags_fields,
5288
40
                                          ENC_LITTLE_ENDIAN, &frameflags);
5289
40
        offset += 4;
5290
40
        if (frameflags & FREEBSD_FRAMEFLAG_DATA_FOLLOWS) {
5291
            /*
5292
             * XXX - ultimately, we should dissect this data.
5293
             */
5294
7
            proto_tree_add_item(frame_tree, hf_usb_frame_data, tvb, offset,
5295
7
                                framelen, ENC_NA);
5296
7
            offset += WS_ROUNDUP_4(framelen);
5297
7
        }
5298
40
        proto_item_set_end(ti, tvb, offset);
5299
40
    }
5300
5301
6
    return tvb_captured_length(tvb);
5302
6
}
5303
5304
static int
5305
netmon_HostController2(proto_tree *tree, tvbuff_t *tvb, int offset, uint16_t flags)
5306
0
{
5307
0
    proto_tree *host_tree;
5308
5309
0
    host_tree = proto_tree_add_subtree(tree, tvb, offset, (flags & EVENT_HEADER_FLAG_64_BIT_HEADER) ? 20 : 16, ett_usbport_host_controller, NULL, "HostController");
5310
0
    netmon_etl_field(host_tree, tvb, &offset, hf_usbport_device_object, flags);
5311
5312
0
    proto_tree_add_item(host_tree, hf_usbport_pci_bus, tvb, offset, 4, ENC_LITTLE_ENDIAN);
5313
0
    offset += 4;
5314
0
    proto_tree_add_item(host_tree, hf_usbport_pci_device, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5315
0
    offset += 2;
5316
0
    proto_tree_add_item(host_tree, hf_usbport_pci_function, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5317
0
    offset += 2;
5318
0
    proto_tree_add_item(host_tree, hf_usbport_pci_vendor_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5319
0
    offset += 2;
5320
0
    proto_tree_add_item(host_tree, hf_usbport_pci_device_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5321
0
    offset += 2;
5322
5323
0
    return offset;
5324
0
}
5325
5326
static int
5327
netmon_UsbPortPath(proto_tree *tree, tvbuff_t *tvb, int offset, packet_info *pinfo)
5328
0
{
5329
0
    proto_item *path_item, *depth_item;
5330
0
    proto_tree *path_tree;
5331
0
    uint32_t path_depth, path0, path1, path2, path3, path4, path5;
5332
5333
0
    path_tree = proto_tree_add_subtree(tree, tvb, offset, 28, ett_usbport_path, &path_item, "PortPath: ");
5334
0
    depth_item = proto_tree_add_item_ret_uint(path_tree, hf_usbport_port_path_depth, tvb, offset, 4, ENC_LITTLE_ENDIAN, &path_depth);
5335
0
    offset += 4;
5336
0
    proto_tree_add_item_ret_uint(path_tree, hf_usbport_port_path0, tvb, offset, 4, ENC_LITTLE_ENDIAN, &path0);
5337
0
    offset += 4;
5338
0
    proto_tree_add_item_ret_uint(path_tree, hf_usbport_port_path1, tvb, offset, 4, ENC_LITTLE_ENDIAN, &path1);
5339
0
    offset += 4;
5340
0
    proto_tree_add_item_ret_uint(path_tree, hf_usbport_port_path2, tvb, offset, 4, ENC_LITTLE_ENDIAN, &path2);
5341
0
    offset += 4;
5342
0
    proto_tree_add_item_ret_uint(path_tree, hf_usbport_port_path3, tvb, offset, 4, ENC_LITTLE_ENDIAN, &path3);
5343
0
    offset += 4;
5344
0
    proto_tree_add_item_ret_uint(path_tree, hf_usbport_port_path4, tvb, offset, 4, ENC_LITTLE_ENDIAN, &path4);
5345
0
    offset += 4;
5346
0
    proto_tree_add_item_ret_uint(path_tree, hf_usbport_port_path5, tvb, offset, 4, ENC_LITTLE_ENDIAN, &path5);
5347
0
    offset += 4;
5348
0
    if (path_depth == 0) {
5349
0
        proto_item_append_text(path_item, "-");
5350
0
    }
5351
0
    if (path_depth > 0) {
5352
0
        proto_item_append_text(path_item, "%d", path0);
5353
0
    }
5354
0
    if (path_depth > 1) {
5355
0
        proto_item_append_text(path_item, ",%d", path1);
5356
0
    }
5357
0
    if (path_depth > 2) {
5358
0
        proto_item_append_text(path_item, ",%d", path2);
5359
0
    }
5360
0
    if (path_depth > 3) {
5361
0
        proto_item_append_text(path_item, ",%d", path3);
5362
0
    }
5363
0
    if (path_depth > 4) {
5364
0
        proto_item_append_text(path_item, ",%d", path4);
5365
0
    }
5366
0
    if (path_depth > 5) {
5367
0
        proto_item_append_text(path_item, ",%d", path5);
5368
0
    }
5369
0
    if (path_depth > 6) {
5370
0
        expert_add_info(pinfo, depth_item, &ei_usbport_invalid_path_depth);
5371
0
    }
5372
5373
0
    return offset;
5374
0
}
5375
5376
static int
5377
netmon_fid_USBPORT_Device(proto_tree *tree, tvbuff_t *tvb, int offset, uint16_t flags, packet_info *pinfo)
5378
0
{
5379
0
    proto_item *device_item;
5380
0
    proto_tree *device_tree;
5381
5382
0
    device_tree = proto_tree_add_subtree(tree, tvb, offset, 4, ett_usbport_device, &device_item, "Device");
5383
0
    netmon_etl_field(device_tree, tvb, &offset, hf_usbport_device_handle, flags);
5384
0
    proto_tree_add_item(device_tree, hf_usb_idVendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5385
0
    offset += 2;
5386
0
    proto_tree_add_item(device_tree, hf_usb_idProduct, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5387
0
    offset += 2;
5388
0
    offset = netmon_UsbPortPath(device_tree, tvb, offset, pinfo);
5389
0
    proto_tree_add_item(device_tree, hf_usbport_device_speed, tvb, offset, 4, ENC_LITTLE_ENDIAN);
5390
0
    offset += 4;
5391
0
    proto_tree_add_item(device_tree, hf_usb_device_address, tvb, offset, 4, ENC_LITTLE_ENDIAN);
5392
0
    offset += 4;
5393
5394
0
    return offset;
5395
0
}
5396
5397
static int
5398
netmon_fid_USBPORT_Endpoint(proto_tree *tree, tvbuff_t *tvb, int offset, uint16_t flags)
5399
0
{
5400
0
    proto_tree *endpoint_tree;
5401
5402
0
    endpoint_tree = proto_tree_add_subtree(tree, tvb, offset, (flags & EVENT_HEADER_FLAG_64_BIT_HEADER) ? 24 : 12, ett_usbport_endpoint, NULL, "Endpoint");
5403
0
    netmon_etl_field(endpoint_tree, tvb, &offset, hf_usbport_endpoint, flags);
5404
0
    netmon_etl_field(endpoint_tree, tvb, &offset, hf_usbport_pipehandle, flags);
5405
0
    netmon_etl_field(endpoint_tree, tvb, &offset, hf_usbport_device_handle, flags);
5406
5407
0
    return offset;
5408
0
}
5409
5410
static int
5411
netmon_fid_USBPORT_Endpoint_Descriptor(proto_tree *tree, tvbuff_t *tvb, int offset)
5412
0
{
5413
0
    proto_tree *endpoint_desc_tree;
5414
5415
0
    endpoint_desc_tree = proto_tree_add_subtree(tree, tvb, offset, 7, ett_usbport_endpoint_desc, NULL, "Endpoint Descriptor");
5416
0
    proto_tree_add_item(endpoint_desc_tree, hf_usbport_endpoint_desc_length, tvb, offset, 1, ENC_LITTLE_ENDIAN);
5417
0
    offset += 1;
5418
0
    proto_tree_add_item(endpoint_desc_tree, hf_usbport_endpoint_desc_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
5419
0
    offset += 1;
5420
0
    proto_tree_add_item(endpoint_desc_tree, hf_usbport_endpoint_address, tvb, offset, 1, ENC_LITTLE_ENDIAN);
5421
0
    offset += 1;
5422
0
    proto_tree_add_item(endpoint_desc_tree, hf_usbport_bm_attributes, tvb, offset, 1, ENC_LITTLE_ENDIAN);
5423
0
    offset += 1;
5424
0
    proto_tree_add_item(endpoint_desc_tree, hf_usbport_max_packet_size, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5425
0
    offset += 2;
5426
0
    proto_tree_add_item(endpoint_desc_tree, hf_usbport_interval, tvb, offset, 1, ENC_LITTLE_ENDIAN);
5427
0
    offset += 1;
5428
5429
0
    return offset;
5430
0
}
5431
5432
static int
5433
netmon_URB(proto_tree *tree, tvbuff_t *tvb, int offset, uint16_t flags)
5434
0
{
5435
0
    proto_item *urb_item;
5436
0
    proto_tree *urb_tree;
5437
0
    uint32_t func;
5438
0
    int i, start_offset = offset;
5439
5440
0
    urb_tree = proto_tree_add_subtree(tree, tvb, offset, 8, ett_usbport_urb, &urb_item, "URB");
5441
0
    proto_tree_add_item(urb_tree, hf_usbport_urb_header_length, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5442
0
    offset += 2;
5443
0
    proto_tree_add_item_ret_uint(urb_tree, hf_usbport_urb_header_function, tvb, offset, 2, ENC_LITTLE_ENDIAN, &func);
5444
0
    proto_item_append_text(urb_item, ": %s", val_to_str_ext_const(func, &netmon_urb_function_vals_ext, "Unknown"));
5445
0
    offset += 2;
5446
0
    proto_tree_add_item(urb_tree, hf_usbport_urb_header_status, tvb, offset, 4, ENC_LITTLE_ENDIAN);
5447
0
    offset += 4;
5448
0
    netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_header_usbddevice_handle, flags);
5449
0
    netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_header_usbdflags, flags);
5450
5451
0
    switch (func)
5452
0
    {
5453
0
    case 0x0000:
5454
0
        netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_configuration_desc, flags);
5455
0
        netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_configuration_handle, flags);
5456
0
        break;
5457
0
    case 0x0008: //URB_FUNCTION_CONTROL_TRANSFER
5458
0
    case 0x0009: //URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
5459
0
    case 0x000A: //URB_FUNCTION_ISOCH_TRANSFER
5460
0
    case 0x000B: //URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
5461
0
    case 0x000C: //URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE
5462
0
    case 0x000D: //URB_FUNCTION_SET_FEATURE_TO_DEVICE
5463
0
    case 0x000E: //URB_FUNCTION_SET_FEATURE_TO_INTERFACE
5464
0
    case 0x000F: //URB_FUNCTION_SET_FEATURE_TO_ENDPOINT
5465
0
    case 0x0010: //URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE
5466
0
    case 0x0011: //URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE
5467
0
    case 0x0012: //URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT
5468
0
    case 0x0013: //URB_FUNCTION_GET_STATUS_FROM_DEVICE
5469
0
    case 0x0014: //URB_FUNCTION_GET_STATUS_FROM_INTERFACE
5470
0
    case 0x0015: //URB_FUNCTION_GET_STATUS_FROM_ENDPOINT
5471
0
    case 0x0017: //URB_FUNCTION_VENDOR_DEVICE
5472
0
    case 0x0018: //URB_FUNCTION_VENDOR_INTERFACE
5473
0
    case 0x0019: //URB_FUNCTION_VENDOR_ENDPOINT
5474
0
    case 0x001A: //URB_FUNCTION_CLASS_DEVICE
5475
0
    case 0x001B: //URB_FUNCTION_CLASS_INTERFACE
5476
0
    case 0x001C: //URB_FUNCTION_CLASS_ENDPOINT
5477
0
    case 0x001F: //URB_FUNCTION_CLASS_OTHER
5478
0
    case 0x0020: //URB_FUNCTION_VENDOR_OTHER
5479
0
    case 0x0021: //URB_FUNCTION_GET_STATUS_FROM_OTHER
5480
0
    case 0x0022: //URB_FUNCTION_CLEAR_FEATURE_TO_OTHER
5481
0
    case 0x0023: //URB_FUNCTION_SET_FEATURE_TO_OTHER
5482
0
    case 0x0024: //URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT
5483
0
    case 0x0025: //URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT
5484
0
    case 0x0026: //URB_FUNCTION_GET_CONFIGURATION
5485
0
    case 0x0027: //URB_FUNCTION_GET_INTERFACE
5486
0
    case 0x0028: //URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE
5487
0
    case 0x0029: //URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE
5488
0
    case 0x002A: //URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR
5489
0
    case 0x0032: //URB_FUNCTION_CONTROL_TRANSFER_EX
5490
0
    case 0x0037: //URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER_USING_CHAINED_MDL
5491
0
    case 0x0038: //URB_FUNCTION_ISOCH_TRANSFER_USING_CHAINED_MDL
5492
0
        netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_pipe_handle, flags);
5493
0
        proto_tree_add_bitmask(urb_tree, tvb, offset, hf_usbport_urb_xferflags, ett_usb_xferflags,
5494
0
                           usb_xferflags_fields, ENC_LITTLE_ENDIAN);
5495
0
        offset += 4;
5496
0
        proto_tree_add_item(urb_tree, hf_usbport_urb_transfer_buffer_length, tvb, offset, 4, ENC_LITTLE_ENDIAN);
5497
0
        offset += 4;
5498
0
        netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_transfer_buffer, flags);
5499
0
        netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_transfer_buffer_mdl, flags);
5500
0
        netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_reserved_mbz, flags);
5501
0
        for (i = 0; i < 8; i++)
5502
0
        {
5503
0
            netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_reserved_hcd, flags);
5504
0
        }
5505
0
        break;
5506
5507
0
    case 0x0002: //URB_FUNCTION_ABORT_PIPE
5508
0
    case 0x001E: //URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
5509
0
    case 0x0030: //URB_FUNCTION_SYNC_RESET_PIPE
5510
0
    case 0x0031: //URB_FUNCTION_SYNC_CLEAR_STALL
5511
0
    case 0x0036: //URB_FUNCTION_CLOSE_STATIC_STREAMS
5512
0
        netmon_etl_field(urb_tree, tvb, &offset, hf_usbport_urb_pipe_handle, flags);
5513
0
        proto_tree_add_item(urb_tree, hf_usbport_urb_reserved, tvb, offset, 4, ENC_LITTLE_ENDIAN);
5514
0
        offset += 4;
5515
0
        break;
5516
0
    }
5517
5518
0
    proto_item_set_len(urb_item, offset-start_offset);
5519
0
    return offset;
5520
0
}
5521
5522
15
#define USBPORT_KEYWORD_DIAGNOSTIC         UINT64_C(0x0000000000000001)
5523
15
#define USBPORT_KEYWORD_POWER_DIAGNOSTICS  UINT64_C(0x0000000000000002)
5524
15
#define USBPORT_KEYWORD_PERF_DIAGNOSTICS   UINT64_C(0x0000000000000004)
5525
15
#define USBPORT_KEYWORD_RESERVED1          UINT64_C(0xFFFFFFFFFFFFFFF8)
5526
5527
static int
5528
dissect_netmon_usb_port(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, void* data)
5529
0
{
5530
0
    proto_item *ti, *generated;
5531
0
    proto_tree *usb_port_tree;
5532
0
    int offset = 0;
5533
0
    struct netmon_provider_id_data *provider_id_data = (struct netmon_provider_id_data*)data;
5534
0
    static int * const keyword_fields[] = {
5535
0
        &hf_usbport_keyword_diagnostic,
5536
0
        &hf_usbport_keyword_power_diagnostics,
5537
0
        &hf_usbport_keyword_perf_diagnostics,
5538
0
        &hf_usbport_keyword_reserved1,
5539
0
        NULL
5540
0
    };
5541
5542
0
    DISSECTOR_ASSERT(provider_id_data != NULL);
5543
5544
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "USBPort");
5545
0
    col_clear(pinfo->cinfo, COL_INFO);
5546
5547
0
    ti = proto_tree_add_item(parent, proto_usbport, tvb, 0, -1, ENC_NA);
5548
0
    usb_port_tree = proto_item_add_subtree(ti, ett_usbport);
5549
5550
0
    generated = proto_tree_add_uint(usb_port_tree, hf_usbport_event_id, tvb, 0, 0, provider_id_data->event_id);
5551
0
    proto_item_set_generated(generated);
5552
0
    generated = proto_tree_add_bitmask_value(usb_port_tree, tvb, 0, hf_usbport_keyword, ett_usbport_keyword, keyword_fields, provider_id_data->keyword);
5553
0
    proto_item_set_generated(generated);
5554
5555
0
    switch (provider_id_data->event_id)
5556
0
    {
5557
0
    case 71:
5558
0
        offset = netmon_HostController2(usb_port_tree, tvb, offset, provider_id_data->event_flags);
5559
0
        offset = netmon_fid_USBPORT_Device(usb_port_tree, tvb, offset, provider_id_data->event_flags, pinfo);
5560
0
        offset = netmon_fid_USBPORT_Endpoint(usb_port_tree, tvb, offset, provider_id_data->event_flags);
5561
0
        offset = netmon_fid_USBPORT_Endpoint_Descriptor(usb_port_tree, tvb, offset);
5562
0
        netmon_etl_field(usb_port_tree, tvb, &offset, hf_usbport_irp, provider_id_data->event_flags);
5563
0
        netmon_etl_field(usb_port_tree, tvb, &offset, hf_usbport_urb, provider_id_data->event_flags);
5564
0
        offset = netmon_URB(usb_port_tree, tvb, offset, provider_id_data->event_flags);
5565
0
        proto_tree_add_item(usb_port_tree, hf_usbport_urb_transfer_data, tvb, offset, 2, ENC_LITTLE_ENDIAN);
5566
0
        break;
5567
0
    }
5568
5569
0
    return tvb_captured_length(tvb);
5570
0
}
5571
5572
void
5573
dissect_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent,
5574
                   usb_header_t header_type, void *extra_data)
5575
28
{
5576
28
    int                   offset = 0;
5577
28
    int                   endpoint;
5578
28
    uint8_t               urb_type;
5579
28
    uint32_t              win32_data_len = 0;
5580
28
    uint32_t              iso_numdesc = 0;
5581
28
    uint32_t              desc_offset = 0;
5582
28
    uint32_t              location = 0;
5583
28
    proto_item           *urb_tree_ti;
5584
28
    proto_tree           *tree;
5585
28
    proto_item           *item;
5586
28
    urb_info_t           *urb;
5587
28
    conversation_t       *conversation;
5588
28
    uint16_t             device_address;
5589
28
    uint16_t             bus_id;
5590
28
    uint8_t                  usbpcap_control_stage = 0;
5591
28
    uint64_t                 usb_id;
5592
28
    struct mausb_header  *ma_header = NULL;
5593
28
    struct usbip_header  *ip_header = NULL;
5594
28
    usb_pseudo_urb_t     *pseudo_urb = NULL;
5595
5596
    /* the goal is to get the conversation struct as early as possible
5597
       and store all status values in this struct
5598
       at first, we read the fields required to create/identify
5599
       the right conversation struct */
5600
28
    switch (header_type) {
5601
5602
0
    case USB_HEADER_LINUX_48_BYTES:
5603
14
    case USB_HEADER_LINUX_64_BYTES:
5604
14
        urb_type = tvb_get_uint8(tvb, 8);
5605
14
        endpoint = tvb_get_uint8(tvb, 10);
5606
14
        device_address = (uint16_t)tvb_get_uint8(tvb, 11);
5607
14
        bus_id = tvb_get_letohs(tvb, 12);
5608
14
        break;
5609
5610
9
    case USB_HEADER_USBPCAP:
5611
9
        urb_type = tvb_get_uint8(tvb, 16) & 0x01 ? URB_COMPLETE : URB_SUBMIT;
5612
9
        device_address = tvb_get_letohs(tvb, 19);
5613
9
        endpoint = tvb_get_uint8(tvb, 21);
5614
9
        if ((endpoint == 0x00) && (tvb_get_uint8(tvb, 22) == URB_CONTROL) &&
5615
0
            (tvb_get_uint8(tvb, 27) == USB_CONTROL_STAGE_DATA)) {
5616
            /* USBPcap before 1.3.0.0 DATA OUT packet (the info at offset 16 is wrong) */
5617
0
            urb_type = URB_SUBMIT;
5618
0
        }
5619
9
        bus_id = tvb_get_letohs(tvb, 17);
5620
9
        break;
5621
5622
0
    case USB_HEADER_MAUSB:
5623
0
        ma_header = (struct mausb_header *) extra_data;
5624
0
        urb_type = mausb_is_from_host(ma_header) ? URB_SUBMIT : URB_COMPLETE;
5625
0
        device_address = mausb_ep_handle_dev_addr(ma_header->handle);
5626
0
        endpoint = mausb_ep_handle_ep_num(ma_header->handle);
5627
0
        bus_id = mausb_ep_handle_bus_num(ma_header->handle);
5628
0
        if (mausb_ep_handle_ep_d(ma_header->handle)) {
5629
            /* IN endpoint */
5630
0
            endpoint |= 0x80;
5631
0
        }
5632
0
        break;
5633
5634
0
    case USB_HEADER_USBIP:
5635
0
        ip_header = (struct usbip_header *) extra_data;
5636
0
        urb_type = tvb_get_ntohl(tvb, 0) == 1 ? URB_SUBMIT : URB_COMPLETE;
5637
0
        device_address = ip_header->devid;
5638
0
        bus_id = ip_header->busid;
5639
0
        endpoint = ip_header->ep;
5640
0
        if (ip_header->dir == 1) {
5641
            /* IN endpoint */
5642
0
            endpoint |= 0x80;
5643
0
        }
5644
0
        break;
5645
5646
5
    case USB_HEADER_DARWIN:
5647
5
        urb_type = tvb_get_uint8(tvb, 3) ? URB_COMPLETE : URB_SUBMIT;
5648
5
        endpoint = tvb_get_uint8(tvb, 30);
5649
5
        device_address = (uint16_t)tvb_get_uint8(tvb, 29);
5650
5
        location = tvb_get_letohl(tvb, 24);
5651
5
        bus_id = location >> 24;
5652
5
        break;
5653
5654
0
    case USB_HEADER_PSEUDO_URB:
5655
0
        pseudo_urb = (usb_pseudo_urb_t *) extra_data;
5656
0
        urb_type = pseudo_urb->from_host ? URB_SUBMIT : URB_COMPLETE;
5657
0
        device_address = pseudo_urb->device_address;
5658
0
        endpoint = pseudo_urb->endpoint;
5659
0
        bus_id = pseudo_urb->bus_id;
5660
0
        break;
5661
5662
0
    default:
5663
0
        return; /* invalid USB pseudo header */
5664
28
    }
5665
5666
28
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "USB");
5667
28
    urb_tree_ti = proto_tree_add_protocol_format(parent, proto_usb, tvb, 0, -1, "USB URB");
5668
28
    tree = proto_item_add_subtree(urb_tree_ti, ett_usb_hdr);
5669
5670
28
    if (endpoint == 0x80) {
5671
        /* Control endpoint is only bidirectional endpoint, use 0 to look up
5672
         * correct conversation.
5673
         */
5674
0
        endpoint = 0;
5675
0
    }
5676
5677
28
    usb_set_addr(tree, tvb, pinfo, bus_id, device_address, endpoint,
5678
28
                 (urb_type == URB_SUBMIT));
5679
5680
28
    conversation = get_usb_conversation(pinfo, &pinfo->src, &pinfo->dst, pinfo->srcport, pinfo->destport);
5681
28
    urb = wmem_new0(pinfo->pool, urb_info_t);
5682
28
    urb->conv = get_usb_conv_info(conversation);
5683
28
    urb->endpoint = endpoint;
5684
28
    clear_usb_conv_tmp_data(urb);
5685
5686
5687
28
    switch (header_type) {
5688
5689
0
    case USB_HEADER_LINUX_48_BYTES:
5690
14
    case USB_HEADER_LINUX_64_BYTES:
5691
14
        proto_item_set_len(urb_tree_ti, (header_type == USB_HEADER_LINUX_64_BYTES) ? 64 : 48);
5692
14
        offset = dissect_linux_usb_pseudo_header(tvb, pinfo, tree, urb, &usb_id);
5693
14
        break;
5694
5695
9
    case USB_HEADER_USBPCAP:
5696
9
        offset = dissect_usbpcap_buffer_packet_header(tvb, pinfo, tree, urb, &win32_data_len, &usb_id);
5697
        /* the length that we're setting here might have to be corrected
5698
           if there's a transfer-specific pseudo-header following */
5699
9
        proto_item_set_len(urb_tree_ti, offset);
5700
9
        break;
5701
5702
0
    case USB_HEADER_MAUSB:
5703
        /* MA USB header gets dissected earlier, just set conversation variables */
5704
0
        offset = MAUSB_DPH_LENGTH;
5705
0
        mausb_set_urb_info(urb, ma_header);
5706
0
        usb_id = 0;
5707
0
        break;
5708
5709
0
    case USB_HEADER_USBIP:
5710
0
        iso_numdesc = tvb_get_ntohl(tvb, 0x20);
5711
0
        urb->transfer_type = endpoint == 0 ? URB_CONTROL : (iso_numdesc != 0xffffffff ? URB_ISOCHRONOUS : URB_UNKNOWN);
5712
0
        urb->direction = ip_header->dir == USBIP_DIR_OUT ? P2P_DIR_SENT : P2P_DIR_RECV;
5713
0
        urb->is_setup = endpoint == 0 ? (tvb_get_ntoh64(tvb, 0x28) != UINT64_C(0)) : false;
5714
0
        urb->is_request = (urb_type==URB_SUBMIT);
5715
0
        offset = urb->is_setup ? USBIP_HEADER_WITH_SETUP_LEN : USBIP_HEADER_LEN;
5716
5717
        /* The ISOC descriptor is located at the end of the isoc frame behind the isoc data. */
5718
0
        if ((urb->is_request && urb->direction == USBIP_DIR_OUT) ||
5719
0
            (!urb->is_request && urb->direction == USBIP_DIR_IN)) {
5720
0
            desc_offset += tvb_get_ntohl(tvb, 0x18);
5721
0
        }
5722
5723
0
        desc_offset += offset;
5724
0
        usb_id = 0;
5725
0
        break;
5726
5727
5
    case USB_HEADER_DARWIN:
5728
5
        offset = dissect_darwin_buffer_packet_header(tvb, pinfo, tree, urb, &usb_id);
5729
5
        proto_item_set_len(urb_tree_ti, offset);
5730
5
        break;
5731
5732
0
    case USB_HEADER_PSEUDO_URB:
5733
0
        urb->transfer_type = pseudo_urb->transfer_type;
5734
0
        urb->direction = pseudo_urb->from_host ? P2P_DIR_SENT : P2P_DIR_RECV;
5735
0
        urb->is_setup = pseudo_urb->from_host && (pseudo_urb->transfer_type == URB_CONTROL);
5736
0
        urb->is_request = pseudo_urb->from_host;
5737
0
        urb->speed = pseudo_urb->speed;
5738
0
        usb_id = 0;
5739
0
        break;
5740
5741
0
    default:
5742
0
        usb_id = 0;
5743
0
        break;
5744
28
    }
5745
5746
25
    urb->usb_trans_info = usb_get_trans_info(tvb, pinfo, tree, header_type, urb, usb_id);
5747
5748
25
    if (urb->transfer_type != URB_CONTROL) {
5749
20
        usb_tap_queue_packet(pinfo, urb_type, urb);
5750
20
    }
5751
5752
25
    switch(urb->transfer_type) {
5753
1
    case URB_BULK:
5754
1
    case URB_INTERRUPT:
5755
1
        item = proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, 0, 0, urb->conv->interfaceClass);
5756
1
        proto_item_set_generated(item);
5757
5758
1
        switch (header_type) {
5759
5760
0
        case USB_HEADER_LINUX_48_BYTES:
5761
1
        case USB_HEADER_LINUX_64_BYTES:
5762
            /* bulk and interrupt transfers never contain a setup packet */
5763
1
            proto_tree_add_item(tree, hf_usb_urb_unused_setup_header, tvb, offset, 8, ENC_NA);
5764
1
            offset += 8;
5765
1
            if (header_type == USB_HEADER_LINUX_64_BYTES) {
5766
1
                offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
5767
1
            }
5768
1
            break;
5769
5770
0
        case USB_HEADER_USBPCAP:
5771
0
            break;
5772
5773
0
        case USB_HEADER_MAUSB:
5774
0
            break;
5775
5776
0
        case USB_HEADER_USBIP:
5777
0
            break;
5778
5779
0
        case USB_HEADER_DARWIN:
5780
0
            break;
5781
5782
0
        case USB_HEADER_PSEUDO_URB:
5783
0
            break;
5784
1
        }
5785
0
        break;
5786
5787
5
    case URB_CONTROL:
5788
5
        if (header_type == USB_HEADER_USBPCAP) {
5789
1
            proto_tree_add_item(tree, hf_usb_win32_control_stage, tvb, offset, 1, ENC_LITTLE_ENDIAN);
5790
1
            usbpcap_control_stage = tvb_get_uint8(tvb, offset);
5791
1
            offset++;
5792
1
            proto_item_set_len(urb_tree_ti, offset);
5793
1
            if (usbpcap_control_stage == USB_CONTROL_STAGE_SETUP) {
5794
0
                urb->is_setup = true;
5795
1
            } else if (usbpcap_control_stage == USB_CONTROL_STAGE_DATA && urb_type == URB_SUBMIT) {
5796
                /* USBPcap before 1.5.0.0 */
5797
0
                wmem_tree_key_t key[3];
5798
0
                key[0].length = 2;
5799
0
                key[0].key = (uint32_t *)&usb_id;
5800
0
                key[1].length = 1;
5801
0
                key[1].key = &pinfo->num;
5802
0
                key[2].length = 0;
5803
0
                key[2].key = NULL;
5804
0
                usbpcap_setup_data_t *setup_data = (usbpcap_setup_data_t *)wmem_tree_lookup32_array_le(usbpcap_setup_data, key);
5805
0
                if (setup_data && setup_data->usb_id == usb_id) {
5806
0
                    tvbuff_t *reassembled_tvb = tvb_new_composite();
5807
0
                    tvb_composite_append(reassembled_tvb, tvb_new_child_real_data(tvb, setup_data->setup_data, 8, 8));
5808
0
                    tvb_composite_append(reassembled_tvb, tvb_new_subset_remaining(tvb, offset));
5809
0
                    tvb_composite_finalize(reassembled_tvb);
5810
0
                    add_new_data_source(pinfo, reassembled_tvb, "USBPcap reassembled setup");
5811
0
                    urb->is_setup = true;
5812
0
                    tvb = reassembled_tvb;
5813
0
                    offset = 0;
5814
0
                }
5815
0
            }
5816
1
        }
5817
5818
5
        if (urb->is_request) {
5819
3
            if (urb->is_setup) {
5820
3
                offset = dissect_usb_setup_request(pinfo, tree, tvb, offset, urb_type,
5821
3
                                                   urb, header_type, usb_id);
5822
5823
3
            } else {
5824
0
                switch (header_type) {
5825
5826
0
                case USB_HEADER_LINUX_48_BYTES:
5827
0
                case USB_HEADER_LINUX_64_BYTES:
5828
0
                    proto_tree_add_item(tree, hf_usb_urb_unused_setup_header, tvb, offset, 8, ENC_NA);
5829
0
                    offset += 8;
5830
0
                    if (header_type == USB_HEADER_LINUX_64_BYTES) {
5831
0
                        offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
5832
0
                    }
5833
0
                    break;
5834
5835
0
                case USB_HEADER_USBPCAP:
5836
0
                    break;
5837
5838
0
                case USB_HEADER_MAUSB:
5839
0
                    break;
5840
5841
0
                case USB_HEADER_USBIP:
5842
0
                    break;
5843
5844
0
                case USB_HEADER_DARWIN:
5845
0
                    break;
5846
5847
0
                case USB_HEADER_PSEUDO_URB:
5848
0
                    break;
5849
0
                }
5850
0
            }
5851
3
        } else {
5852
            /* this is a response */
5853
5854
2
            switch (header_type) {
5855
5856
0
            case USB_HEADER_LINUX_48_BYTES:
5857
0
            case USB_HEADER_LINUX_64_BYTES:
5858
                /* Skip setup header - it's never applicable for responses */
5859
0
                proto_tree_add_item(tree, hf_usb_urb_unused_setup_header, tvb, offset, 8, ENC_NA);
5860
0
                offset += 8;
5861
0
                if (header_type == USB_HEADER_LINUX_64_BYTES) {
5862
0
                    offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
5863
0
                }
5864
0
                break;
5865
5866
1
            case USB_HEADER_USBPCAP:
5867
                /* Check if this is status stage */
5868
1
                if ((urb->usb_trans_info) &&
5869
0
                    (usbpcap_control_stage == USB_CONTROL_STAGE_STATUS)) {
5870
0
                    const char *description;
5871
0
                    if (USB_TYPE(urb->usb_trans_info->setup.requesttype) == RQT_SETUP_TYPE_STANDARD) {
5872
0
                        description = val_to_str_ext(pinfo->pool, urb->usb_trans_info->setup.request,
5873
0
                            &setup_request_names_vals_ext, "Unknown type %x") ;
5874
0
                    } else {
5875
0
                        description = "URB_CONTROL";
5876
0
                    }
5877
0
                    col_add_fstr(pinfo->cinfo, COL_INFO, "%s status", description);
5878
                    /* There is no data to dissect */
5879
0
                    return;
5880
0
                }
5881
1
                break;
5882
5883
1
            case USB_HEADER_MAUSB:
5884
0
                break;
5885
5886
0
            case USB_HEADER_USBIP:
5887
0
                break;
5888
5889
1
            case USB_HEADER_DARWIN:
5890
1
                break;
5891
5892
0
            case USB_HEADER_PSEUDO_URB:
5893
0
                break;
5894
2
            }
5895
5896
2
            offset = dissect_usb_setup_response(pinfo, tree, tvb, offset,
5897
2
                                                urb_type, urb);
5898
2
        }
5899
5
        break;
5900
17
    case URB_ISOCHRONOUS:
5901
17
        switch (header_type) {
5902
5903
0
        case USB_HEADER_LINUX_48_BYTES:
5904
11
        case USB_HEADER_LINUX_64_BYTES:
5905
11
            offset = dissect_linux_usb_iso_transfer(pinfo, tree, header_type,
5906
11
                    tvb, offset, urb);
5907
11
            break;
5908
5909
5
        case USB_HEADER_USBPCAP:
5910
5
            offset = dissect_usbpcap_iso_packets(pinfo, tree,
5911
5
                    urb_type, tvb, offset, win32_data_len, urb);
5912
5
            break;
5913
5914
0
        case USB_HEADER_MAUSB:
5915
0
            break;
5916
5917
0
        case USB_HEADER_USBIP:
5918
0
            offset = dissect_usbip_iso_transfer(pinfo, tree,
5919
0
                    tvb, offset, iso_numdesc, desc_offset, urb);
5920
0
            break;
5921
5922
1
        case USB_HEADER_DARWIN:
5923
1
            offset = dissect_darwin_usb_iso_transfer(pinfo, tree, header_type,
5924
1
                    urb_type, tvb, offset, urb);
5925
1
            break;
5926
5927
0
        case USB_HEADER_PSEUDO_URB:
5928
0
            break;
5929
17
        }
5930
2
        break;
5931
5932
2
    default:
5933
        /* unknown transfer type */
5934
2
        switch (header_type) {
5935
0
        case USB_HEADER_LINUX_48_BYTES:
5936
1
        case USB_HEADER_LINUX_64_BYTES:
5937
1
            proto_tree_add_item(tree, hf_usb_urb_unused_setup_header, tvb, offset, 8, ENC_NA);
5938
1
            offset += 8;
5939
1
            if (header_type == USB_HEADER_LINUX_64_BYTES) {
5940
1
                offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
5941
1
            }
5942
1
            break;
5943
5944
1
        case USB_HEADER_USBPCAP:
5945
1
            break;
5946
5947
0
        case USB_HEADER_MAUSB:
5948
0
            break;
5949
5950
0
        case USB_HEADER_USBIP:
5951
0
            break;
5952
5953
0
        case USB_HEADER_DARWIN:
5954
0
            break;
5955
5956
0
        case USB_HEADER_PSEUDO_URB:
5957
0
            break;
5958
2
        }
5959
2
        break;
5960
25
    }
5961
5962
8
    dissect_usb_payload(tvb, pinfo, parent, tree, urb, urb_type,
5963
8
                        offset, device_address);
5964
8
}
5965
5966
static int
5967
dissect_linux_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, void* data _U_)
5968
0
{
5969
0
    dissect_usb_common(tvb, pinfo, parent, USB_HEADER_LINUX_48_BYTES, NULL);
5970
0
    return tvb_captured_length(tvb);
5971
0
}
5972
5973
static int
5974
dissect_linux_usb_mmapped(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, void* data _U_)
5975
14
{
5976
14
    dissect_usb_common(tvb, pinfo, parent, USB_HEADER_LINUX_64_BYTES, NULL);
5977
14
    return tvb_captured_length(tvb);
5978
14
}
5979
5980
5981
static int
5982
dissect_win32_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, void* data _U_)
5983
9
{
5984
9
    dissect_usb_common(tvb, pinfo, parent, USB_HEADER_USBPCAP, NULL);
5985
9
    return tvb_captured_length(tvb);
5986
9
}
5987
5988
static int
5989
dissect_darwin_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent, void* data _U_)
5990
5
{
5991
5
    dissect_usb_common(tvb, pinfo, parent, USB_HEADER_DARWIN, NULL);
5992
5
    return tvb_captured_length(tvb);
5993
5
}
5994
5995
void
5996
proto_register_usb(void)
5997
15
{
5998
15
    module_t *usb_module;
5999
15
    static hf_register_info hf[] = {
6000
6001
    /* USB packet pseudoheader members */
6002
6003
15
        { &hf_usb_totlen,
6004
15
          { "Total length", "usb.totlen",
6005
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6006
15
            NULL, HFILL }},
6007
6008
15
        { &hf_usb_busunit,
6009
15
          { "Host controller unit number", "usb.busunit",
6010
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6011
15
            NULL, HFILL }},
6012
6013
15
        { &hf_usb_address,
6014
15
          { "USB device index", "usb.address",
6015
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6016
15
            NULL, HFILL }},
6017
6018
15
        { &hf_usb_mode,
6019
15
          { "Mode of transfer", "usb.transfer_mode",
6020
15
            FT_UINT8, BASE_DEC, VALS(usb_freebsd_transfer_mode_vals), 0x0,
6021
15
            NULL, HFILL }},
6022
6023
15
        { &hf_usb_freebsd_urb_type,
6024
15
          { "URB type", "usb.freebsd_type",
6025
15
            FT_UINT8, BASE_DEC, VALS(usb_freebsd_urb_type_vals), 0x0,
6026
15
            NULL, HFILL }},
6027
6028
15
        { &hf_usb_freebsd_transfer_type,
6029
15
          { "URB transfer type", "usb.freebsd_transfer_type",
6030
15
            FT_UINT8, BASE_HEX, VALS(usb_freebsd_transfer_type_vals), 0x0,
6031
15
            NULL, HFILL }},
6032
6033
15
        { &hf_usb_xferflags,
6034
15
          { "Transfer flags", "usb.xferflags",
6035
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
6036
15
            NULL, HFILL }},
6037
6038
15
        { &hf_usb_xferflags_force_short_xfer,
6039
15
          { "Force short transfer", "usb.xferflags.force_short_xfer",
6040
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_FORCE_SHORT_XFER,
6041
15
            NULL, HFILL }},
6042
6043
15
        { &hf_usb_xferflags_short_xfer_ok,
6044
15
          { "Short transfer OK", "usb.xferflags.short_xfer_ok",
6045
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_SHORT_XFER_OK,
6046
15
            NULL, HFILL }},
6047
6048
15
        { &hf_usb_xferflags_short_frames_ok,
6049
15
          { "Short frames OK", "usb.xferflags.short_frames_ok",
6050
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_SHORT_FRAMES_OK,
6051
15
            NULL, HFILL }},
6052
6053
15
        { &hf_usb_xferflags_pipe_bof,
6054
15
          { "Pipe BOF", "usb.xferflags.pipe_bof",
6055
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_PIPE_BOF,
6056
15
            NULL, HFILL }},
6057
6058
15
        { &hf_usb_xferflags_proxy_buffer,
6059
15
          { "Proxy buffer", "usb.xferflags.proxy_buffer",
6060
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_PROXY_BUFFER,
6061
15
            NULL, HFILL }},
6062
6063
15
        { &hf_usb_xferflags_ext_buffer,
6064
15
          { "External buffer", "usb.xferflags.ext_buffer",
6065
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_EXT_BUFFER,
6066
15
            NULL, HFILL }},
6067
6068
15
        { &hf_usb_xferflags_manual_status,
6069
15
          { "Manual status", "usb.xferflags.manual_status",
6070
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_MANUAL_STATUS,
6071
15
            NULL, HFILL }},
6072
6073
15
        { &hf_usb_xferflags_no_pipe_ok,
6074
15
          { "No pipe OK", "usb.xferflags.no_pipe_ok",
6075
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_NO_PIPE_OK,
6076
15
            NULL, HFILL }},
6077
6078
15
        { &hf_usb_xferflags_stall_pipe,
6079
15
          { "Stall pipe", "usb.xferflags.stall_pipe",
6080
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FLAG_STALL_PIPE,
6081
15
            NULL, HFILL }},
6082
6083
15
        { &hf_usb_xferstatus,
6084
15
          { "Transfer status", "usb.xferstatus",
6085
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
6086
15
            NULL, HFILL }},
6087
6088
15
        { &hf_usb_xferstatus_open,
6089
15
          { "Pipe has been opened", "usb.xferstatus.open",
6090
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_OPEN,
6091
15
            NULL, HFILL }},
6092
6093
15
        { &hf_usb_xferstatus_transferring,
6094
15
          { "Transfer in progress", "usb.xferstatus.transferring",
6095
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_TRANSFERRING,
6096
15
            NULL, HFILL }},
6097
6098
15
        { &hf_usb_xferstatus_did_dma_delay,
6099
15
          { "Waited for hardware DMA", "usb.xferstatus.did_dma_delay",
6100
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_DID_DMA_DELAY,
6101
15
            NULL, HFILL }},
6102
6103
15
        { &hf_usb_xferstatus_did_close,
6104
15
          { "Transfer closed", "usb.xferstatus.did_close",
6105
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_DID_CLOSE,
6106
15
            NULL, HFILL }},
6107
6108
15
        { &hf_usb_xferstatus_draining,
6109
15
          { "Draining transfer", "usb.xferstatus.draining",
6110
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_DRAINING,
6111
15
            NULL, HFILL }},
6112
6113
15
        { &hf_usb_xferstatus_started,
6114
15
          { "Transfer started", "usb.xferstatus.started",
6115
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_STARTED,
6116
15
            "Whether the transfer is started or stopped", HFILL }},
6117
6118
15
        { &hf_usb_xferstatus_bw_reclaimed,
6119
15
          { "Bandwidth reclaimed", "usb.xferstatus.bw_reclaimed",
6120
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_BW_RECLAIMED,
6121
15
            NULL, HFILL }},
6122
6123
15
        { &hf_usb_xferstatus_control_xfr,
6124
15
          { "Control transfer", "usb.xferstatus.control_xfr",
6125
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_CONTROL_XFR,
6126
15
            NULL, HFILL }},
6127
6128
15
        { &hf_usb_xferstatus_control_hdr,
6129
15
          { "Control header being sent", "usb.xferstatus.control_hdr",
6130
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_CONTROL_HDR,
6131
15
            NULL, HFILL }},
6132
6133
15
        { &hf_usb_xferstatus_control_act,
6134
15
          { "Control transfer active", "usb.xferstatus.control_act",
6135
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_CONTROL_ACT,
6136
15
            NULL, HFILL }},
6137
6138
15
        { &hf_usb_xferstatus_control_stall,
6139
15
          { "Control transfer should be stalled", "usb.xferstatus.control_stall",
6140
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_CONTROL_STALL,
6141
15
            NULL, HFILL }},
6142
6143
15
        { &hf_usb_xferstatus_short_frames_ok,
6144
15
          { "Short frames OK", "usb.xferstatus.short_frames_ok",
6145
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_SHORT_FRAMES_OK,
6146
15
            NULL, HFILL }},
6147
6148
15
        { &hf_usb_xferstatus_short_xfer_ok,
6149
15
          { "Short transfer OK", "usb.xferstatus.short_xfer_ok",
6150
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_SHORT_XFER_OK,
6151
15
            NULL, HFILL }},
6152
6153
15
        { &hf_usb_xferstatus_bdma_enable,
6154
15
          { "BUS-DMA enabled", "usb.xferstatus.bdma_enable",
6155
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_BDMA_ENABLE,
6156
15
            NULL, HFILL }},
6157
6158
15
        { &hf_usb_xferstatus_bdma_no_post_sync,
6159
15
          { "BUS-DMA post sync op not done", "usb.xferstatus.bdma_no_post_sync",
6160
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_BDMA_NO_POST_SYNC,
6161
15
            NULL, HFILL }},
6162
6163
15
        { &hf_usb_xferstatus_bdma_setup,
6164
15
          { "BUS-DMA set up", "usb.xferstatus.bdma_setup",
6165
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_BDMA_SETUP,
6166
15
            NULL, HFILL }},
6167
6168
15
        { &hf_usb_xferstatus_isochronous_xfr,
6169
15
          { "Isochronous transfer", "usb.xferstatus.isochronous_xfr",
6170
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_ISOCHRONOUS_XFR,
6171
15
            NULL, HFILL }},
6172
6173
15
        { &hf_usb_xferstatus_curr_dma_set,
6174
15
          { "Current DMA set", "usb.xferstatus.curr_dma_set",
6175
15
            FT_UINT32, BASE_DEC, NULL, FREEBSD_STATUS_CURR_DMA_SET,
6176
15
            NULL, HFILL }},
6177
6178
15
        { &hf_usb_xferstatus_can_cancel_immed,
6179
15
          { "Transfer can be cancelled immediately", "usb.xferstatus.can_cancel_immed",
6180
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_CAN_CANCEL_IMMED,
6181
15
            NULL, HFILL }},
6182
6183
15
        { &hf_usb_xferstatus_doing_callback,
6184
15
          { "Executing the callback", "usb.xferstatus.doing_callback",
6185
15
            FT_BOOLEAN, 32, NULL, FREEBSD_STATUS_DOING_CALLBACK,
6186
15
            NULL, HFILL }},
6187
6188
15
        { &hf_usb_error,
6189
15
          { "Error", "usb.error",
6190
15
            FT_UINT32, BASE_DEC, VALS(usb_freebsd_err_vals), 0x0,
6191
15
            NULL, HFILL }},
6192
6193
15
        { &hf_usb_interval,
6194
15
          { "Interval", "usb.interval",
6195
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6196
15
            "Interval (ms)", HFILL }},
6197
6198
15
        { &hf_usb_nframes,
6199
15
          { "Number of following frames", "usb.nframes",
6200
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6201
15
            NULL, HFILL }},
6202
6203
15
        { &hf_usb_packet_size,
6204
15
          { "Packet size used", "usb.packet_size",
6205
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6206
15
            NULL, HFILL }},
6207
6208
15
        { &hf_usb_packet_count,
6209
15
          { "Packet count used", "usb.packet_count",
6210
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6211
15
            NULL, HFILL }},
6212
6213
15
        { &hf_usb_speed,
6214
15
          { "Speed", "usb.speed",
6215
15
            FT_UINT8, BASE_DEC, VALS(usb_freebsd_speed_vals), 0x0,
6216
15
            NULL, HFILL }},
6217
6218
15
        { &hf_usb_frame_length,
6219
15
          { "Frame length", "usb.frame.length",
6220
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6221
15
            NULL, HFILL }},
6222
6223
15
        { &hf_usb_frame_flags,
6224
15
          { "Frame flags", "usb.frame.flags",
6225
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
6226
15
            NULL, HFILL }},
6227
6228
15
        { &hf_usb_frame_flags_read,
6229
15
          { "Data direction is read", "usb.frame.read",
6230
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FRAMEFLAG_READ,
6231
15
            NULL, HFILL }},
6232
6233
15
        { &hf_usb_frame_flags_data_follows,
6234
15
          { "Frame contains data", "usb.frame.data_follows",
6235
15
            FT_BOOLEAN, 32, NULL, FREEBSD_FRAMEFLAG_DATA_FOLLOWS,
6236
15
            NULL, HFILL }},
6237
6238
15
        { &hf_usb_frame_data,
6239
15
          { "Frame data", "usb.frame.data",
6240
15
            FT_BYTES, BASE_NONE, NULL, 0x0,
6241
15
            NULL, HFILL }},
6242
6243
15
        { &hf_usb_urb_id,
6244
15
          { "URB id", "usb.urb_id",
6245
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
6246
15
            NULL, HFILL }},
6247
6248
15
        { &hf_usb_linux_urb_type,
6249
15
          { "URB type", "usb.urb_type",
6250
15
            FT_CHAR, BASE_HEX, VALS(usb_linux_urb_type_vals), 0x0,
6251
15
            NULL, HFILL }},
6252
6253
15
        { &hf_usb_linux_transfer_type,
6254
15
          { "URB transfer type", "usb.transfer_type",
6255
15
            FT_UINT8, BASE_HEX, VALS(usb_linux_transfer_type_vals), 0x0,
6256
15
            NULL, HFILL }},
6257
6258
15
        { &hf_usb_endpoint_address,
6259
15
          { "Endpoint", "usb.endpoint_address",
6260
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6261
15
            "USB endpoint address", HFILL }},
6262
6263
15
        { &hf_usb_endpoint_direction,
6264
15
          { "Direction", "usb.endpoint_address.direction",
6265
15
            FT_UINT8, BASE_DEC, VALS(usb_endpoint_direction_vals), 0x80,
6266
15
            "USB endpoint direction", HFILL }},
6267
6268
15
        { &hf_usb_endpoint_number,
6269
15
          { "Endpoint number", "usb.endpoint_address.number",
6270
15
            FT_UINT8, BASE_DEC, NULL, 0x0F,
6271
15
            "USB endpoint number", HFILL }},
6272
6273
15
        { &hf_usb_device_address,
6274
15
          { "Device", "usb.device_address",
6275
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6276
15
            "USB device address", HFILL }},
6277
6278
15
        { &hf_usb_bus_id,
6279
15
          { "URB bus id", "usb.bus_id",
6280
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6281
15
            NULL, HFILL }},
6282
6283
15
        { &hf_usb_setup_flag,
6284
15
          { "Device setup request", "usb.setup_flag",
6285
15
            FT_CHAR, BASE_HEX|BASE_RANGE_STRING, RVALS(usb_setup_flag_rvals), 0x0,
6286
15
            "USB device setup request is relevant (0) or not", HFILL }},
6287
6288
15
        { &hf_usb_data_flag,
6289
15
          { "Data", "usb.data_flag",
6290
15
            FT_CHAR, BASE_HEX|BASE_RANGE_STRING, RVALS(usb_data_flag_rvals), 0x0,
6291
15
            "USB data is present (0) or not", HFILL }},
6292
6293
15
        { &hf_usb_urb_ts_sec,
6294
15
          { "URB sec", "usb.urb_ts_sec",
6295
15
            FT_UINT64, BASE_DEC, NULL, 0x0,
6296
15
            NULL, HFILL }},
6297
6298
15
        { &hf_usb_urb_ts_usec,
6299
15
          { "URB usec", "usb.urb_ts_usec",
6300
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6301
15
            NULL, HFILL }},
6302
6303
15
        { &hf_usb_urb_status,
6304
15
          { "URB status", "usb.urb_status",
6305
15
            FT_INT32, BASE_DEC|BASE_EXT_STRING, &linux_negative_errno_vals_ext, 0x0,
6306
15
            NULL, HFILL }},
6307
6308
15
        { &hf_usb_urb_len,
6309
15
          { "URB length [bytes]", "usb.urb_len",
6310
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6311
15
            "URB length in bytes", HFILL }},
6312
6313
15
        { &hf_usb_urb_data_len,
6314
15
          { "Data length [bytes]", "usb.data_len",
6315
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6316
15
            "URB data length in bytes", HFILL }},
6317
6318
15
        { &hf_usb_urb_unused_setup_header,
6319
15
          { "Unused Setup Header",
6320
15
            "usb.unused_setup_header", FT_NONE, BASE_NONE,
6321
15
            NULL, 0x0, NULL, HFILL }},
6322
6323
15
        { &hf_usb_urb_interval,
6324
15
          { "Interval",
6325
15
            "usb.interval", FT_UINT32, BASE_DEC,
6326
15
            NULL, 0x0, NULL, HFILL }},
6327
6328
15
        { &hf_usb_urb_start_frame,
6329
15
          { "Start frame",
6330
15
            "usb.start_frame", FT_UINT32, BASE_DEC,
6331
15
            NULL, 0x0, NULL, HFILL }},
6332
6333
15
        { &hf_usb_urb_copy_of_transfer_flags,
6334
15
          { "Copy of Transfer Flags",
6335
15
            "usb.copy_of_transfer_flags", FT_UINT32, BASE_HEX,
6336
15
            NULL, 0x0, NULL, HFILL }},
6337
6338
15
        { &hf_short_not_ok,
6339
15
          { "Short not OK",
6340
15
            "usb.transfer_flags.short_not_ok", FT_BOOLEAN, 32,
6341
15
            NULL, URB_SHORT_NOT_OK, NULL, HFILL }},
6342
6343
15
        { &hf_iso_asap,
6344
15
          { "ISO ASAP",
6345
15
            "usb.transfer_flags.iso_asap", FT_BOOLEAN, 32,
6346
15
            NULL, URB_ISO_ASAP, NULL, HFILL }},
6347
6348
15
        { &hf_no_transfer_dma_map,
6349
15
          { "No transfer DMA map",
6350
15
            "usb.transfer_flags.no_transfer_dma_map", FT_BOOLEAN, 32,
6351
15
            NULL, URB_NO_TRANSFER_DMA_MAP, NULL, HFILL }},
6352
6353
15
        { &hf_no_fsbr,
6354
15
          { "No FSBR",
6355
15
            "usb.transfer_flags.no_fsbr", FT_BOOLEAN, 32,
6356
15
            NULL, URB_NO_FSBR, NULL, HFILL }},
6357
6358
15
        { &hf_zero_packet,
6359
15
          { "Zero Packet", "usb.transfer_flags.zero_packet", FT_BOOLEAN, 32,
6360
15
            NULL, URB_ZERO_PACKET, NULL, HFILL }},
6361
6362
15
        { &hf_no_interrupt,
6363
15
          { "No Interrupt", "usb.transfer_flags.no_interrupt", FT_BOOLEAN, 32,
6364
15
            NULL, URB_NO_INTERRUPT, NULL, HFILL }},
6365
6366
15
        { &hf_free_buffer,
6367
15
          { "Free Buffer", "usb.transfer_flags.free_buffer", FT_BOOLEAN, 32,
6368
15
            NULL, URB_FREE_BUFFER, NULL, HFILL }},
6369
6370
15
        { &hf_dir_in,
6371
15
          { "Dir IN", "usb.transfer_flags.dir_in", FT_BOOLEAN, 32,
6372
15
            NULL, URB_DIR_IN, NULL, HFILL }},
6373
6374
15
        { &hf_dma_map_single,
6375
15
          { "DMA Map Single", "usb.transfer_flags.dma_map_single", FT_BOOLEAN, 32,
6376
15
            NULL, URB_DMA_MAP_SINGLE, NULL, HFILL }},
6377
6378
15
        { &hf_dma_map_page,
6379
15
          { "DMA Map Page", "usb.transfer_flags.dma_map_page", FT_BOOLEAN, 32,
6380
15
            NULL, URB_DMA_MAP_PAGE, NULL, HFILL }},
6381
6382
15
        { &hf_dma_map_sg,
6383
15
          { "DMA Map SG", "usb.transfer_flags.dma_map_sg", FT_BOOLEAN, 32,
6384
15
            NULL, URB_DMA_MAP_SG, NULL, HFILL }},
6385
6386
15
        { &hf_map_local,
6387
15
          { "Map Local", "usb.transfer_flags.map_local", FT_BOOLEAN, 32,
6388
15
            NULL, URB_MAP_LOCAL, NULL, HFILL }},
6389
6390
15
        { &hf_setup_map_single,
6391
15
          { "Setup Map Single", "usb.transfer_flags.setup_map_single", FT_BOOLEAN, 32,
6392
15
            NULL, URB_SETUP_MAP_SINGLE, NULL, HFILL }},
6393
6394
15
        { &hf_setup_map_local,
6395
15
          { "Setup Map Local", "usb.transfer_flags.setup_map_local", FT_BOOLEAN, 32,
6396
15
            NULL, URB_SETUP_MAP_LOCAL, NULL, HFILL }},
6397
6398
15
        { &hf_dma_sg_combined,
6399
15
          { "DMA S-G Combined", "usb.transfer_flags.dma_sg_combined", FT_BOOLEAN, 32,
6400
15
            NULL, URB_DMA_SG_COMBINED, NULL, HFILL }},
6401
6402
15
        { &hf_aligned_temp_buffer,
6403
15
          { "Aligned Temp Buffer", "usb.transfer_flags.aligned_temp_buffer", FT_BOOLEAN, 32,
6404
15
            NULL, URB_ALIGNED_TEMP_BUFFER, NULL, HFILL }},
6405
6406
        /* Win32 USBPcap pseudoheader */
6407
15
        { &hf_usb_win32_header_len,
6408
15
          { "USBPcap pseudoheader length", "usb.usbpcap_header_len",
6409
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6410
15
            NULL, HFILL }},
6411
6412
15
        { &hf_usb_irp_id,
6413
15
          { "IRP ID", "usb.irp_id",
6414
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
6415
15
            NULL, HFILL }},
6416
6417
15
        { &hf_usb_usbd_status,
6418
15
          { "IRP USBD_STATUS", "usb.usbd_status",
6419
15
            FT_UINT32, BASE_HEX | BASE_EXT_STRING, &win32_usbd_status_vals_ext, 0x0,
6420
15
            "USB request status value", HFILL }},
6421
6422
15
        { &hf_usb_function,
6423
15
          { "URB Function", "usb.function",
6424
15
            FT_UINT16, BASE_HEX|BASE_EXT_STRING, &win32_urb_function_vals_ext, 0x0,
6425
15
            NULL, HFILL }},
6426
6427
15
        { &hf_usb_info,
6428
15
          { "IRP information", "usb.irp_info",
6429
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6430
15
            NULL, HFILL }},
6431
6432
15
        { &hf_usb_usbpcap_info_reserved,
6433
15
          { "Reserved", "usb.irp_info.reserved",
6434
15
            FT_UINT8, BASE_HEX, NULL, 0xFE,
6435
15
            NULL, HFILL }},
6436
6437
15
        { &hf_usb_usbpcap_info_direction,
6438
15
          { "Direction", "usb.irp_info.direction",
6439
15
            FT_UINT8, BASE_HEX, VALS(win32_usb_info_direction_vals), 0x01,
6440
15
            NULL, HFILL }},
6441
6442
15
        { &hf_usb_win32_device_address,
6443
15
          { "Device address", "usb.device_address",
6444
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6445
15
            "Windows USB device address", HFILL }},
6446
6447
15
        { &hf_usb_win32_transfer_type,
6448
15
          { "URB transfer type", "usb.transfer_type",
6449
15
            FT_UINT8, BASE_HEX, VALS(win32_usb_transfer_type_vals), 0x0,
6450
15
            NULL, HFILL } },
6451
6452
15
        { &hf_usb_win32_data_len,
6453
15
          { "Packet Data Length", "usb.data_len",
6454
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6455
15
            NULL, HFILL }},
6456
6457
15
        { &hf_usb_win32_control_stage,
6458
15
          { "Control transfer stage", "usb.control_stage",
6459
15
            FT_UINT8, BASE_DEC, VALS(usb_control_stage_vals), 0x0,
6460
15
            NULL, HFILL }},
6461
6462
15
        { &hf_usb_win32_iso_start_frame,
6463
15
          { "Isochronous transfer start frame", "usb.win32.iso_frame",
6464
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6465
15
            NULL, HFILL }},
6466
6467
15
        { &hf_usb_win32_iso_num_packets,
6468
15
          { "Isochronous transfer number of packets", "usb.win32.iso_num_packets",
6469
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6470
15
            NULL, HFILL }},
6471
6472
15
        { &hf_usb_win32_iso_error_count,
6473
15
          { "Isochronous transfer error count", "usb.win32.iso_error_count",
6474
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6475
15
            NULL, HFILL }},
6476
6477
15
        { &hf_usb_win32_iso_offset,
6478
15
          { "ISO Data offset", "usb.win32.iso_offset",
6479
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
6480
15
            NULL, HFILL }},
6481
6482
15
        { &hf_usb_win32_iso_length,
6483
15
          { "ISO Data length", "usb.win32.iso_data_len",
6484
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
6485
15
            NULL, HFILL }},
6486
6487
15
        { &hf_usb_win32_iso_status,
6488
15
          { "ISO USBD status", "usb.win32.iso_status",
6489
15
            FT_UINT32, BASE_HEX | BASE_EXT_STRING, &win32_usbd_status_vals_ext, 0x0,
6490
15
            NULL, HFILL }},
6491
6492
        /* macOS usbdump pseudoheader */
6493
15
        { &hf_usb_darwin_bcd_version,
6494
15
          { "Darwin header bcdVersion", "usb.darwin.bcdVersion",
6495
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
6496
15
            NULL, HFILL }},
6497
6498
15
        { &hf_usb_darwin_header_len,
6499
15
          { "Darwin header length", "usb.darwin.header_len",
6500
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6501
15
            NULL, HFILL }},
6502
6503
15
        { &hf_usb_darwin_request_type,
6504
15
          { "Request type", "usb.darwin.request_type",
6505
15
            FT_UINT8, BASE_DEC, VALS(usb_darwin_request_type_vals), 0x0,
6506
15
            NULL, HFILL }},
6507
6508
15
        { &hf_usb_darwin_io_len,
6509
15
          { "I/O length [bytes]", "usb.darwin.io_len",
6510
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6511
15
            "Request length in bytes", HFILL }},
6512
6513
15
        { &hf_usb_darwin_io_status,
6514
15
          { "Request status", "usb.darwin.io_status",
6515
15
            FT_UINT32, BASE_HEX | BASE_EXT_STRING, &usb_darwin_status_vals_ext, 0x0,
6516
15
            "USB request status", HFILL }},
6517
6518
15
        { &hf_usb_darwin_iso_num_packets,
6519
15
          { "Isochronous transfer number of frames", "usb.darwin.io_frame_count",
6520
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6521
15
            NULL, HFILL }},
6522
6523
15
        { &hf_usb_darwin_io_id,
6524
15
          { "I/O ID", "usb.darwin.io_id",
6525
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
6526
15
            NULL, HFILL }},
6527
6528
15
        { &hf_usb_darwin_device_location,
6529
15
          { "Device location ID", "usb.darwin.location_id",
6530
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
6531
15
            NULL, HFILL }},
6532
6533
15
        { &hf_usb_darwin_speed,
6534
15
          { "Device speed", "usb.darwin_device_speed",
6535
15
            FT_UINT8, BASE_DEC, VALS(usb_darwin_speed_vals), 0x0,
6536
15
            NULL, HFILL }},
6537
6538
15
        { &hf_usb_darwin_device_address,
6539
15
          { "USB device index", "usb.darwin.device_address",
6540
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6541
15
            NULL, HFILL }},
6542
6543
15
        { &hf_usb_darwin_endpoint_address,
6544
15
          { "Endpoint address", "usb.darwin.endpoint_address",
6545
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6546
15
            "Endpoint address and direction", HFILL }},
6547
6548
15
        { &hf_usb_darwin_endpoint_type,
6549
15
          { "Endpoint transfer type", "usb.darwin.endpoint_type",
6550
15
            FT_UINT8, BASE_DEC, VALS(usb_darwin_endpoint_type_vals), 0x0,
6551
15
            NULL, HFILL }},
6552
6553
15
        { &hf_usb_darwin_iso_status,
6554
15
          { "Frame status", "usb.darwin.iso.status",
6555
15
            FT_UINT32, BASE_HEX | BASE_EXT_STRING, &usb_darwin_status_vals_ext, 0x0,
6556
15
            NULL, HFILL }},
6557
6558
15
        { &hf_usb_darwin_iso_timestamp,
6559
15
          { "Frame timestamp", "usb.darwin.iso.timestamp",
6560
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
6561
15
            NULL, HFILL }},
6562
6563
15
        { &hf_usb_darwin_iso_frame_number,
6564
15
          { "Frame number", "usb.darwin.iso.frame_number",
6565
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
6566
15
            NULL, HFILL }},
6567
6568
15
        { &hf_usb_bmRequestType,
6569
15
          { "bmRequestType", "usb.bmRequestType",
6570
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6571
15
            NULL, HFILL }},
6572
6573
        /* Only used when response type cannot be determined */
6574
15
        { &hf_usb_control_response_generic,
6575
15
          { "CONTROL response data", "usb.control.Response",
6576
15
            FT_BYTES, BASE_NONE, NULL, 0x0,
6577
15
            NULL, HFILL }},
6578
6579
15
        { &hf_usb_request,
6580
15
          { "bRequest", "usb.setup.bRequest",
6581
15
            FT_UINT8, BASE_DEC | BASE_EXT_STRING, &setup_request_names_vals_ext, 0x0,
6582
15
            NULL, HFILL }},
6583
6584
        /* Same as hf_usb_request but no descriptive text */
6585
15
        { &hf_usb_request_unknown_class,
6586
15
          { "bRequest", "usb.setup.bRequest",
6587
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6588
15
            NULL, HFILL }},
6589
6590
15
        { &hf_usb_value,
6591
15
          { "wValue", "usb.setup.wValue",
6592
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
6593
15
            NULL, HFILL }},
6594
6595
15
        { &hf_usb_index,
6596
15
          { "wIndex", "usb.setup.wIndex",
6597
15
            FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
6598
15
            NULL, HFILL }},
6599
6600
15
        { &hf_usb_length,
6601
15
          { "wLength", "usb.setup.wLength",
6602
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6603
15
            NULL, HFILL }},
6604
6605
15
        { &hf_usb_device_wFeatureSelector,
6606
15
          { "wFeatureSelector", "usb.setup.wFeatureSelector",
6607
15
            FT_UINT16, BASE_DEC, VALS(usb_device_feature_selector_vals), 0x0,
6608
15
            NULL, HFILL }},
6609
6610
15
        { &hf_usb_interface_wFeatureSelector,
6611
15
          { "wFeatureSelector", "usb.setup.wFeatureSelector",
6612
15
            FT_UINT16, BASE_DEC, VALS(usb_interface_feature_selector_vals), 0x0,
6613
15
            NULL, HFILL }},
6614
6615
15
        { &hf_usb_endpoint_wFeatureSelector,
6616
15
          { "wFeatureSelector", "usb.setup.wFeatureSelector",
6617
15
            FT_UINT16, BASE_DEC, VALS(usb_endpoint_feature_selector_vals), 0x0,
6618
15
            NULL, HFILL }},
6619
6620
15
        { &hf_usb_wInterface,
6621
15
          { "wInterface", "usb.setup.wInterface",
6622
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6623
15
            NULL, HFILL }},
6624
6625
15
        { &hf_usb_wEndpoint,
6626
15
          { "wEndpoint", "usb.setup.wEndpoint",
6627
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6628
15
            NULL, HFILL }},
6629
6630
15
        { &hf_usb_wStatus,
6631
15
          { "wStatus", "usb.setup.wStatus",
6632
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
6633
15
            NULL, HFILL }},
6634
6635
15
        { &hf_usb_wFrameNumber,
6636
15
          { "wFrameNumber", "usb.setup.wFrameNumber",
6637
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6638
15
            NULL, HFILL }},
6639
6640
    /* --------------------------------- */
6641
15
        { &hf_usb_iso_error_count,                /* host endian byte order */
6642
15
          { "ISO error count", "usb.iso.error_count",
6643
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6644
15
            NULL, HFILL }},
6645
6646
15
        { &hf_usb_iso_numdesc,
6647
15
          { "Number of ISO descriptors", "usb.iso.numdesc",
6648
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6649
15
            NULL, HFILL }},
6650
6651
        /* fields of struct mon_bin_isodesc from linux/drivers/usb/mon/mon_bin.c */
6652
15
        { &hf_usb_iso_status,
6653
15
          { "Status", "usb.iso.iso_status",
6654
15
            FT_INT32, BASE_DEC|BASE_EXT_STRING, &linux_negative_errno_vals_ext, 0x0,
6655
15
            "ISO descriptor status", HFILL }},
6656
6657
15
        { &hf_usb_iso_off,
6658
15
          { "Offset [bytes]", "usb.iso.iso_off",
6659
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6660
15
            "ISO data offset in bytes starting from the end of the last ISO descriptor", HFILL }},
6661
6662
15
        { &hf_usb_iso_len,
6663
15
          { "Length [bytes]", "usb.iso.iso_len",
6664
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6665
15
            "ISO data length in bytes", HFILL }},
6666
6667
15
        { &hf_usb_iso_actual_len,
6668
15
          { "Actual Length [bytes]", "usb.iso.iso_actual_len",
6669
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
6670
15
            "ISO data actual length in bytes", HFILL }},
6671
6672
15
        { &hf_usb_iso_pad,                        /* host endian byte order */
6673
15
          { "Padding", "usb.iso.pad",
6674
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
6675
15
            "Padding field of ISO descriptor structure", HFILL }},
6676
6677
15
        { &hf_usb_iso_data,
6678
15
          {"ISO Data", "usb.iso.data",
6679
15
           FT_BYTES, BASE_NONE, NULL, 0x0,
6680
15
           NULL, HFILL }},
6681
    /* --------------------------------- */
6682
#if 0
6683
        { &hf_usb_data_len,
6684
          {"Application Data Length", "usb.data.length",
6685
           FT_UINT32, BASE_DEC, NULL, 0x0,
6686
           NULL, HFILL }},
6687
#endif
6688
6689
15
        { &hf_usb_capdata,
6690
15
          {"Leftover Capture Data", "usb.capdata",
6691
15
           FT_BYTES, BASE_NONE, NULL, 0x0,
6692
15
           "Padding added by the USB capture system", HFILL }},
6693
6694
15
        { &hf_usb_bmRequestType_direction,
6695
15
          { "Direction", "usb.bmRequestType.direction",
6696
15
            FT_BOOLEAN, 8, TFS(&tfs_bmrequesttype_direction), USB_DIR_IN,
6697
15
            NULL, HFILL }},
6698
6699
15
        { &hf_usb_bmRequestType_type,
6700
15
          { "Type", "usb.bmRequestType.type",
6701
15
            FT_UINT8, BASE_HEX, VALS(bmrequesttype_type_vals), USB_TYPE_MASK,
6702
15
            NULL, HFILL }},
6703
6704
15
        { &hf_usb_bmRequestType_recipient,
6705
15
          { "Recipient", "usb.bmRequestType.recipient",
6706
15
            FT_UINT8, BASE_HEX, VALS(bmrequesttype_recipient_vals), 0x1f,
6707
15
            NULL, HFILL }},
6708
6709
15
        { &hf_usb_bDescriptorType,
6710
15
          { "bDescriptorType", "usb.bDescriptorType",
6711
15
            FT_UINT8, BASE_HEX|BASE_EXT_STRING, &std_descriptor_type_vals_ext, 0x0,
6712
15
            NULL, HFILL }},
6713
6714
        /* Only used when descriptor type cannot be determined */
6715
15
        { &hf_usb_get_descriptor_resp_generic,
6716
15
          { "GET DESCRIPTOR Response data", "usb.getDescriptor.Response",
6717
15
            FT_BYTES, BASE_NONE, NULL, 0x0,
6718
15
            NULL, HFILL }},
6719
6720
15
        { &hf_usb_descriptor_index,
6721
15
          { "Descriptor Index", "usb.DescriptorIndex",
6722
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6723
15
            NULL, HFILL }},
6724
6725
15
        { &hf_usb_language_id,
6726
15
          { "Language Id", "usb.LanguageId",
6727
15
            FT_UINT16, BASE_HEX|BASE_EXT_STRING,&usb_langid_vals_ext, 0x0,
6728
15
            NULL, HFILL }},
6729
6730
15
        { &hf_usb_bLength,
6731
15
          { "bLength", "usb.bLength",
6732
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6733
15
            NULL, HFILL }},
6734
6735
15
        { &hf_usb_bcdUSB,
6736
15
          { "bcdUSB", "usb.bcdUSB",
6737
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
6738
15
            NULL, HFILL }},
6739
6740
15
        { &hf_usb_bDeviceClass,
6741
15
          { "bDeviceClass", "usb.bDeviceClass",
6742
15
            FT_UINT8, BASE_HEX|BASE_EXT_STRING, &usb_class_vals_ext, 0x0,
6743
15
            NULL, HFILL }},
6744
6745
15
        { &hf_usb_bDeviceSubClass,
6746
15
          { "bDeviceSubClass", "usb.bDeviceSubClass",
6747
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6748
15
            NULL, HFILL }},
6749
6750
15
        { &hf_usb_bDeviceProtocol,
6751
15
          { "bDeviceProtocol", "usb.bDeviceProtocol",
6752
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6753
15
            NULL, HFILL }},
6754
6755
15
        { &hf_usb_bMaxPacketSize0,
6756
15
          { "bMaxPacketSize0", "usb.bMaxPacketSize0",
6757
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6758
15
            NULL, HFILL }},
6759
6760
15
        { &hf_usb_idVendor,
6761
15
          { "idVendor", "usb.idVendor",
6762
15
            FT_UINT16, BASE_HEX | BASE_EXT_STRING, &ext_usb_vendors_vals, 0x0,
6763
15
            NULL, HFILL }},
6764
6765
15
        { &hf_usb_idProduct,
6766
15
          { "idProduct", "usb.idProduct",
6767
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
6768
15
            NULL, HFILL }},
6769
6770
15
        { &hf_usb_bcdDevice,
6771
15
          { "bcdDevice", "usb.bcdDevice",
6772
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
6773
15
            NULL, HFILL }},
6774
6775
15
        { &hf_usb_iManufacturer,
6776
15
          { "iManufacturer", "usb.iManufacturer",
6777
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6778
15
            NULL, HFILL }},
6779
6780
15
        { &hf_usb_iProduct,
6781
15
          { "iProduct", "usb.iProduct",
6782
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6783
15
            NULL, HFILL }},
6784
6785
15
        { &hf_usb_iSerialNumber,
6786
15
          { "iSerialNumber", "usb.iSerialNumber",
6787
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6788
15
            NULL, HFILL }},
6789
6790
15
        { &hf_usb_bNumConfigurations,
6791
15
          { "bNumConfigurations", "usb.bNumConfigurations",
6792
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6793
15
            NULL, HFILL }},
6794
6795
15
        { &hf_usb_wLANGID,
6796
15
          { "wLANGID", "usb.wLANGID",
6797
15
            FT_UINT16, BASE_HEX|BASE_EXT_STRING,&usb_langid_vals_ext, 0x0,
6798
15
            NULL, HFILL }},
6799
6800
15
        { &hf_usb_bString,
6801
15
          { "bString", "usb.bString",
6802
15
            FT_STRING, BASE_NONE, NULL, 0x0,
6803
15
            NULL, HFILL }},
6804
6805
15
        { &hf_usb_bInterfaceNumber,
6806
15
          { "bInterfaceNumber", "usb.bInterfaceNumber",
6807
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6808
15
            NULL, HFILL }},
6809
6810
15
        { &hf_usb_bAlternateSetting,
6811
15
          { "bAlternateSetting", "usb.bAlternateSetting",
6812
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6813
15
            NULL, HFILL }},
6814
6815
15
        { &hf_usb_bNumEndpoints,
6816
15
          { "bNumEndpoints", "usb.bNumEndpoints",
6817
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6818
15
            NULL, HFILL }},
6819
6820
15
        { &hf_usb_bInterfaceClass,
6821
15
          { "bInterfaceClass", "usb.bInterfaceClass",
6822
15
            FT_UINT8, BASE_HEX|BASE_EXT_STRING, &usb_class_vals_ext, 0x0,
6823
15
            NULL, HFILL }},
6824
6825
15
        { &hf_usb_bInterfaceSubClass,
6826
15
          { "bInterfaceSubClass", "usb.bInterfaceSubClass",
6827
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6828
15
            NULL, HFILL }},
6829
6830
15
        { &hf_usb_bInterfaceSubClass_audio,
6831
15
          { "bInterfaceSubClass", "usb.bInterfaceSubClass",
6832
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &ext_usb_audio_subclass_vals, 0x0,
6833
15
            NULL, HFILL }},
6834
6835
15
        { &hf_usb_bInterfaceSubClass_cdc,
6836
15
          { "bInterfaceSubClass", "usb.bInterfaceSubClass",
6837
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &ext_usb_com_subclass_vals, 0x0,
6838
15
            NULL, HFILL }},
6839
6840
15
        { &hf_usb_bInterfaceSubClass_massstorage ,
6841
15
          { "bInterfaceSubClass", "usb.bInterfaceSubClass",
6842
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &ext_usb_massstorage_subclass_vals, 0x0,
6843
15
            NULL, HFILL }},
6844
6845
15
        { &hf_usb_bInterfaceSubClass_hid,
6846
15
          { "bInterfaceSubClass", "usb.bInterfaceSubClass",
6847
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_hid_subclass_vals_ext, 0x0,
6848
15
            NULL, HFILL }},
6849
6850
15
        { &hf_usb_bInterfaceSubClass_misc,
6851
15
          { "bInterfaceSubClass", "usb.bInterfaceSubClass",
6852
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_misc_subclass_vals_ext, 0x0,
6853
15
            NULL, HFILL }},
6854
6855
15
        { &hf_usb_bInterfaceSubClass_app,
6856
15
          { "bInterfaceSubClass", "usb.bInterfaceSubClass",
6857
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_app_subclass_vals_ext, 0x0,
6858
15
            NULL, HFILL }},
6859
6860
15
        { &hf_usb_bInterfaceProtocol,
6861
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6862
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6863
15
            NULL, HFILL }},
6864
6865
15
        { &hf_usb_bInterfaceProtocol_cdc,
6866
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6867
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_cdc_protocol_vals_ext, 0x0,
6868
15
            NULL, HFILL }},
6869
6870
15
        { &hf_usb_bInterfaceProtocol_massstorage,
6871
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6872
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_massstorage_protocol_vals_ext, 0x0,
6873
15
            NULL, HFILL }},
6874
6875
15
        { &hf_usb_bInterfaceProtocol_cdc_data,
6876
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6877
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_cdc_data_protocol_vals_ext, 0x0,
6878
15
            NULL, HFILL }},
6879
6880
15
        { &hf_usb_bInterfaceProtocol_hid_boot,
6881
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6882
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_hid_boot_protocol_vals_ext, 0x0,
6883
15
            NULL, HFILL }},
6884
6885
15
        { &hf_usb_bInterfaceProtocol_app_dfu,
6886
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6887
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_app_dfu_protocol_vals_ext, 0x0,
6888
15
            NULL, HFILL }},
6889
6890
15
        { &hf_usb_bInterfaceProtocol_app_irda,
6891
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6892
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_app_irda_protocol_vals_ext, 0x0,
6893
15
            NULL, HFILL }},
6894
6895
15
        { &hf_usb_bInterfaceProtocol_app_usb_test_and_measurement,
6896
15
          { "bInterfaceProtocol", "usb.bInterfaceProtocol",
6897
15
            FT_UINT8, BASE_HEX | BASE_EXT_STRING, &usb_app_usb_test_and_measurement_protocol_vals_ext, 0x0,
6898
15
            NULL, HFILL }},
6899
6900
6901
15
        { &hf_usb_iInterface,
6902
15
          { "iInterface", "usb.iInterface",
6903
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6904
15
            NULL, HFILL }},
6905
6906
15
        { &hf_usb_bEndpointAddress,
6907
15
          { "bEndpointAddress", "usb.bEndpointAddress",
6908
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6909
15
            NULL, HFILL }},
6910
6911
15
        { &hf_usb_configuration_bmAttributes,
6912
15
          { "Configuration bmAttributes", "usb.configuration.bmAttributes",
6913
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6914
15
            NULL, HFILL }},
6915
6916
15
        { &hf_usb_bmAttributes,
6917
15
          { "bmAttributes", "usb.bmAttributes",
6918
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
6919
15
            NULL, HFILL }},
6920
6921
15
        { &hf_usb_bEndpointAttributeTransfer,
6922
15
          { "Transfertype", "usb.bmAttributes.transfer",
6923
15
            FT_UINT8, BASE_HEX, VALS(usb_bmAttributes_transfer_vals), 0x03,
6924
15
            NULL, HFILL }},
6925
6926
15
        { &hf_usb_bEndpointAttributeSynchonisation,
6927
15
          { "Synchronisationtype", "usb.bmAttributes.sync",
6928
15
            FT_UINT8, BASE_HEX, VALS(usb_bmAttributes_sync_vals), 0x0c,
6929
15
            NULL, HFILL }},
6930
6931
15
        { &hf_usb_bEndpointAttributeBehaviour,
6932
15
          { "Behaviourtype", "usb.bmAttributes.behaviour",
6933
15
            FT_UINT8, BASE_HEX, VALS(usb_bmAttributes_behaviour_vals), 0x30,
6934
15
            NULL, HFILL }},
6935
6936
15
        { &hf_usb_wMaxPacketSize,
6937
15
          { "wMaxPacketSize", "usb.wMaxPacketSize",
6938
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6939
15
            NULL, HFILL }},
6940
6941
15
        { &hf_usb_wMaxPacketSize_size,
6942
15
          { "Maximum Packet Size", "usb.wMaxPacketSize.size",
6943
15
            FT_UINT16, BASE_DEC, NULL, 0x07FF,
6944
15
            NULL, HFILL }},
6945
6946
15
        { &hf_usb_wMaxPacketSize_slots,
6947
15
          { "Transactions per microframe", "usb.wMaxPacketSize.slots",
6948
15
            FT_UINT16, BASE_DEC, VALS(usb_wMaxPacketSize_slots_vals), (3<<11),
6949
15
            NULL, HFILL }},
6950
6951
15
        { &hf_usb_bInterval,
6952
15
          { "bInterval", "usb.bInterval",
6953
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6954
15
            NULL, HFILL }},
6955
6956
15
        { &hf_usb_bMaxBurst,
6957
15
          { "bMaxBurst", "usb.bMaxBurst",
6958
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6959
15
            "Valid values are from 0 to 15. For control endpoints this value shall be 0.", HFILL }},
6960
6961
15
        { &hf_usb_audio_bRefresh,
6962
15
          { "bRefresh", "usb.audio.bRefresh",
6963
15
            FT_UINT8, BASE_DEC, NULL, 0x00,
6964
15
            NULL, HFILL }},
6965
6966
15
        { &hf_usb_audio_bSynchAddress,
6967
15
          { "bSynchAddress", "usb.audio.bSynchAddress",
6968
15
            FT_UINT8, BASE_DEC, NULL, 0x00,
6969
15
            NULL, HFILL }},
6970
6971
15
        { &hf_usb_bSSEndpointAttributeBulkMaxStreams,
6972
15
          { "MaxStreams", "usb.bmAttributes.MaxStreams",
6973
15
            FT_UINT8, BASE_DEC, NULL, 0x0F,
6974
15
            "Number of streams = 2 to the power MaxStreams", HFILL }},
6975
6976
15
        { &hf_usb_bSSEndpointAttributeIsoMult,
6977
15
          { "Mult", "usb.bmAttributes.Mult",
6978
15
            FT_UINT8, BASE_DEC, NULL, 0x03,
6979
15
            "Maximum number of packets = bMaxBurst * (Mult + 1)", HFILL } },
6980
6981
15
        { &hf_usb_wBytesPerInterval,
6982
15
          { "wBytesPerInterval", "usb.wBytesPerInterval",
6983
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6984
15
            NULL, HFILL } },
6985
6986
15
        { &hf_usb_wTotalLength,
6987
15
          { "wTotalLength", "usb.wTotalLength",
6988
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
6989
15
            NULL, HFILL }},
6990
6991
15
        { &hf_usb_bNumInterfaces,
6992
15
          { "bNumInterfaces", "usb.bNumInterfaces",
6993
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6994
15
            NULL, HFILL }},
6995
6996
15
        { &hf_usb_bConfigurationValue,
6997
15
          { "bConfigurationValue", "usb.bConfigurationValue",
6998
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
6999
15
            NULL, HFILL }},
7000
7001
15
        { &hf_usb_iConfiguration,
7002
15
          { "iConfiguration", "usb.iConfiguration",
7003
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7004
15
            NULL, HFILL }},
7005
7006
15
        { &hf_usb_bMaxPower,
7007
15
          { "bMaxPower", "usb.bMaxPower",
7008
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7009
15
            NULL, HFILL }},
7010
7011
15
        { &hf_usb_configuration_legacy10buspowered,
7012
15
          { "Must be 1", "usb.configuration.legacy10buspowered",
7013
15
            FT_BOOLEAN, 8, TFS(&tfs_mustbeone), 0x80,
7014
15
            "Legacy USB 1.0 bus powered", HFILL }},
7015
7016
15
        { &hf_usb_configuration_selfpowered,
7017
15
          { "Self-Powered", "usb.configuration.selfpowered",
7018
15
            FT_BOOLEAN, 8, TFS(&tfs_selfpowered), 0x40,
7019
15
            NULL, HFILL }},
7020
7021
15
        { &hf_usb_configuration_remotewakeup,
7022
15
          { "Remote Wakeup", "usb.configuration.remotewakeup",
7023
15
            FT_BOOLEAN, 8, TFS(&tfs_remotewakeup), 0x20,
7024
15
            NULL, HFILL }},
7025
7026
15
        { &hf_usb_bEndpointAddress_number,
7027
15
          { "Endpoint Number", "usb.bEndpointAddress.number",
7028
15
            FT_UINT8, BASE_HEX, NULL, 0x0f,
7029
15
            NULL, HFILL }},
7030
7031
15
        { &hf_usb_bEndpointAddress_direction,
7032
15
          { "Direction", "usb.bEndpointAddress.direction",
7033
15
            FT_BOOLEAN, 8, TFS(&tfs_endpoint_direction), 0x80,
7034
15
            NULL, HFILL }},
7035
7036
15
        { &hf_usb_request_in,
7037
15
          { "Request in", "usb.request_in",
7038
15
            FT_FRAMENUM, BASE_NONE,  FRAMENUM_TYPE(FT_FRAMENUM_REQUEST), 0,
7039
15
            "The request to this packet is in this packet", HFILL }},
7040
7041
15
        { &hf_usb_time,
7042
15
          { "Time from request", "usb.time",
7043
15
            FT_RELATIVE_TIME, BASE_NONE,  NULL, 0,
7044
15
            "Time between Request and Response for USB cmds", HFILL }},
7045
7046
15
        { &hf_usb_response_in,
7047
15
          { "Response in", "usb.response_in",
7048
15
            FT_FRAMENUM, BASE_NONE,  FRAMENUM_TYPE(FT_FRAMENUM_RESPONSE), 0,
7049
15
            "The response to this packet is in this packet", HFILL }},
7050
7051
15
        { &hf_usb_bFirstInterface,
7052
15
          { "bFirstInterface", "usb.bFirstInterface",
7053
15
            FT_UINT8, BASE_DEC,  NULL, 0x0, NULL, HFILL }},
7054
7055
15
        { &hf_usb_bInterfaceCount,
7056
15
          { "bInterfaceCount",
7057
15
            "usb.bInterfaceCount", FT_UINT8, BASE_DEC,
7058
15
            NULL, 0x0, NULL, HFILL }},
7059
7060
15
        { &hf_usb_bFunctionClass,
7061
15
          { "bFunctionClass", "usb.bFunctionClass",
7062
15
            FT_UINT8, BASE_HEX|BASE_EXT_STRING,  &usb_class_vals_ext, 0x0, NULL, HFILL }},
7063
7064
15
        { &hf_usb_bFunctionSubClass,
7065
15
          { "bFunctionSubClass",
7066
15
            "usb.bFunctionSubClass", FT_UINT8, BASE_HEX,
7067
15
            NULL, 0x0, NULL, HFILL }},
7068
7069
15
        { &hf_usb_bFunctionProtocol,
7070
15
          { "bFunctionProtocol", "usb.bFunctionProtocol",
7071
15
            FT_UINT8, BASE_HEX,  NULL, 0x0, NULL, HFILL }},
7072
7073
15
        { &hf_usb_iFunction,
7074
15
          { "iFunction",
7075
15
            "usb.iFunction", FT_UINT8, BASE_DEC,
7076
15
            NULL, 0x0, NULL, HFILL }},
7077
7078
15
        { &hf_usb_bNumDeviceCaps,
7079
15
          { "bNumDeviceCaps", "usb.bNumDeviceCaps",
7080
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7081
15
            NULL, HFILL }},
7082
7083
15
        { &hf_usb_bDevCapabilityType,
7084
15
          { "bDevCapabilityType", "usb.bDevCapabilityType",
7085
15
            FT_UINT8, BASE_HEX|BASE_EXT_STRING, &usb_capability_vals_ext, 0x0,
7086
15
            NULL, HFILL }},
7087
7088
15
        { &hf_usb_usb20ext_bmAttributes,
7089
15
          { "bmAttributes", "usb.usb20ext.bmAttributes",
7090
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
7091
15
            NULL, HFILL }},
7092
7093
15
        { &hf_usb_usb20ext_LPM,
7094
15
          { "LPM", "usb.usb20ext.bmAttributes.LPM",
7095
15
            FT_BOOLEAN, 32, NULL, 0x00000002,
7096
15
            NULL, HFILL }},
7097
7098
15
        { &hf_usb_usb20ext_BESL_HIRD,
7099
15
          { "BESL & Alternate HIRD", "usb.usb20ext.bmAttributes.BESL",
7100
15
            FT_BOOLEAN, 32, NULL, 0x00000004,
7101
15
            NULL, HFILL }},
7102
7103
15
        { &hf_usb_usb20ext_baseline_BESL_valid,
7104
15
          { "Baseline BESL valid", "usb.usb20ext.bmAttributes.baseline_BESL_valid",
7105
15
            FT_BOOLEAN, 32, NULL, 0x00000008,
7106
15
            NULL, HFILL }},
7107
7108
15
        { &hf_usb_usb20ext_deep_BESL_valid,
7109
15
          { "Deep BESL valid", "usb.usb20ext.bmAttributes.deep_BESL_valid",
7110
15
            FT_BOOLEAN, 32, NULL, 0x00000010,
7111
15
            NULL, HFILL }},
7112
7113
15
        { &hf_usb_usb20ext_baseline_BESL,
7114
15
          { "Recommended Baseline BESL", "usb.usb20ext.bmAttributes.baseline_BESL",
7115
15
            FT_UINT32, BASE_CUSTOM, CF_FUNC(usb_lpm_besl_str), 0x00000F00,
7116
15
            NULL, HFILL }},
7117
7118
15
        { &hf_usb_usb20ext_deep_BESL,
7119
15
          { "Recommended Deep BESL", "usb.usb20ext.bmAttributes.deep_BESL",
7120
15
            FT_UINT32, BASE_CUSTOM, CF_FUNC(usb_lpm_besl_str), 0x0000F000,
7121
15
            NULL, HFILL }},
7122
7123
15
        { &hf_usb_bReserved,
7124
15
          { "bReserved", "usb.bReserved",
7125
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7126
15
            "This field is reserved and shall be set to zero", HFILL }},
7127
7128
15
        { &hf_usb_PlatformCapabilityUUID,
7129
15
          { "PlatformCapabilityUUID", "usb.PlatformCapabilityUUID",
7130
15
            FT_GUID, BASE_NONE, NULL, 0x0,
7131
15
            NULL, HFILL }},
7132
7133
15
        { &hf_usb_webusb_bcdVersion,
7134
15
          { "bcdVersion", "usb.webusb.bcdVersion",
7135
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
7136
15
            "WebUSB descriptor version", HFILL }},
7137
7138
15
        { &hf_usb_webusb_bVendorCode,
7139
15
          { "bVendorCode", "usb.webusb.bVendorCode",
7140
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7141
15
            "bRequest value for WebUSB", HFILL }},
7142
7143
15
        { &hf_usb_webusb_iLandingPage,
7144
15
          { "iLandingPage", "usb.webusb.iLandingPage",
7145
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7146
15
            "URL for landing page", HFILL }},
7147
7148
15
        { &hf_usb_msos20_dwWindowsVersion,
7149
15
          { "dwWindowsVersion", "usb.msos20.dwWindowsVersion",
7150
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
7151
15
            NULL, HFILL }},
7152
7153
15
        { &hf_usb_msos20_wMSOSDescriptorSetTotalLength,
7154
15
          { "wMSOSDescriptorSetTotalLength", "usb.msos20.wMSOSDescriptorSetTotalLength",
7155
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
7156
15
            NULL, HFILL }},
7157
7158
15
        { &hf_usb_msos20_bMS_VendorCode,
7159
15
          { "bMS_VendorCode", "usb.msos20.bMS_VendorCode",
7160
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7161
15
            NULL, HFILL }},
7162
7163
15
        { &hf_usb_msos20_bAltEnumCode,
7164
15
          { "bAltEnumCode", "usb.msos20.bAltEnumCode",
7165
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7166
15
            NULL, HFILL }},
7167
7168
15
        { &hf_usb_data_fragment,
7169
15
          { "Data Fragment",
7170
15
            "usb.data_fragment", FT_BYTES, BASE_NONE,
7171
15
            NULL, 0x0, NULL, HFILL }},
7172
15
        { &hf_usb_src,
7173
15
            { "Source",                              "usb.src",
7174
15
            FT_STRING, BASE_NONE, NULL, 0x0,
7175
15
            NULL, HFILL }
7176
15
        },
7177
15
        { &hf_usb_dst,
7178
15
            { "Destination",                         "usb.dst",
7179
15
            FT_STRING, BASE_NONE, NULL, 0x0,
7180
15
            NULL, HFILL }
7181
15
        },
7182
15
        { &hf_usb_addr,
7183
15
            { "Source or Destination",               "usb.addr",
7184
15
            FT_STRING, BASE_NONE, NULL, 0x0,
7185
15
            NULL, HFILL }
7186
15
        },
7187
15
        { &hf_usb_ss_bmAttributes,
7188
15
          { "bmAttributes", "usb.ss.bmAttributes",
7189
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
7190
15
            NULL, HFILL }},
7191
15
        { &hf_usb_ss_bmAttributes_reserved0,
7192
15
          { "Reserved", "usb.ss.bmAttributes.reserved0",
7193
15
            FT_BOOLEAN, 8, TFS(&tfs_usb_ss_bmAttributes_reserved0), 0x01,
7194
15
            NULL, HFILL }},
7195
15
        { &hf_usb_ss_bmAttributes_LTM,
7196
15
          { "LTM", "usb.ss.bmAttributes.LTM",
7197
15
            FT_BOOLEAN, 8, NULL, 0x02,
7198
15
            NULL, HFILL }},
7199
15
        { &hf_usb_ss_bmAttributes_reserved7_2,
7200
15
          { "Reserved", "usb.ss.bmAttributes.reserved7_2",
7201
15
            FT_UINT8, BASE_HEX, NULL, 0xFC,
7202
15
            NULL, HFILL }},
7203
15
        { &hf_usb_ss_wSpeedSupported,
7204
15
          { "wSpeedSupported", "usb.ss.wSpeedSupported",
7205
15
            FT_UINT16, BASE_HEX, NULL, 0x0,
7206
15
            NULL, HFILL }},
7207
15
        { &hf_usb_ss_wSpeedSupported_LS,
7208
15
          { SS_SPEED_SUPPORTED_STR_LS, "usb.ss.wSpeedSupported.LS",
7209
15
            FT_BOOLEAN, 16, NULL, 1 << SS_SPEED_SUPPORTED_BIT_LS,
7210
15
            NULL, HFILL }},
7211
15
        { &hf_usb_ss_wSpeedSupported_FS,
7212
15
          { SS_SPEED_SUPPORTED_STR_FS, "usb.ss.wSpeedSupported.FS",
7213
15
            FT_BOOLEAN, 16, NULL, 1 << SS_SPEED_SUPPORTED_BIT_FS,
7214
15
            NULL, HFILL }},
7215
15
        { &hf_usb_ss_wSpeedSupported_HS,
7216
15
          { SS_SPEED_SUPPORTED_STR_HS, "usb.ss.wSpeedSupported.HS",
7217
15
            FT_BOOLEAN, 16, NULL, 1 << SS_SPEED_SUPPORTED_BIT_HS,
7218
15
            NULL, HFILL }},
7219
15
        { &hf_usb_ss_wSpeedSupported_Gen1,
7220
15
          { SS_SPEED_SUPPORTED_STR_GEN1, "usb.ss.wSpeedSupported.Gen1",
7221
15
            FT_BOOLEAN, 16, NULL, 1 << SS_SPEED_SUPPORTED_BIT_GEN1,
7222
15
            NULL, HFILL }},
7223
15
        { &hf_usb_ss_wSpeedSupported_reserved,
7224
15
          { "Reserved", "usb.ss.wSpeedSupported.reserved",
7225
15
            FT_UINT16, BASE_HEX, NULL, 0xFFF0,
7226
15
            NULL, HFILL }},
7227
15
        { &hf_usb_ss_bFunctionalitySupport,
7228
15
          { "bFunctionalitySupport", "usb.ss.bFunctionalitySupport",
7229
15
            FT_UINT8, BASE_HEX|BASE_EXT_STRING, &usb_ss_bFunctionalitySupport_vals_ext, 0x0,
7230
15
            NULL, HFILL }},
7231
15
        { &hf_usb_ss_bU1DevExitLat,
7232
15
          { "bU1DevExitLat", "usb.ss.bU1DevExitLat",
7233
15
            FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_microseconds), 0x0,
7234
15
            NULL, HFILL }},
7235
15
        { &hf_usb_ss_wU2DevExitLat,
7236
15
          { "wU2DevExitLat", "usb.ss.wU2DevExitLat",
7237
15
            FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_microseconds), 0x0,
7238
15
            NULL, HFILL }},
7239
15
    };
7240
7241
15
    static hf_register_info hf_usbport[] = {
7242
15
        { &hf_usbport_event_id,
7243
15
            { "Event ID",               "usbport.event_id",
7244
15
            FT_UINT32, BASE_DEC_HEX|BASE_EXT_STRING, &netmon_event_id_vals_ext, 0x0,
7245
15
            NULL, HFILL }
7246
15
        },
7247
15
        { &hf_usbport_device_object,
7248
15
            { "Device Object",          "usbport.device_object",
7249
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7250
15
            NULL, HFILL }
7251
15
        },
7252
15
        { &hf_usbport_pci_bus,
7253
15
            { "PCI Bus",          "usbport.pci_bus",
7254
15
            FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
7255
15
            NULL, HFILL }
7256
15
        },
7257
15
        { &hf_usbport_pci_device,
7258
15
            { "PCI Bus",          "usbport.pci_device",
7259
15
            FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
7260
15
            NULL, HFILL }
7261
15
        },
7262
15
        { &hf_usbport_pci_function,
7263
15
            { "PCI Function",          "usbport.pci_function",
7264
15
            FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
7265
15
            NULL, HFILL }
7266
15
        },
7267
15
        { &hf_usbport_pci_vendor_id,
7268
15
            { "PCI Vendor ID",          "usbport.pci_vendor_id",
7269
15
            FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
7270
15
            NULL, HFILL }
7271
15
        },
7272
15
        { &hf_usbport_pci_device_id,
7273
15
            { "PCI Device ID",          "usbport.pci_device_id",
7274
15
            FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
7275
15
            NULL, HFILL }
7276
15
        },
7277
15
        { &hf_usbport_port_path_depth,
7278
15
            { "Path Depth",          "usbport.port_path_depth",
7279
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7280
15
            NULL, HFILL }
7281
15
        },
7282
15
        { &hf_usbport_port_path0,
7283
15
            { "Path0",          "usbport.port_path0",
7284
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7285
15
            NULL, HFILL }
7286
15
        },
7287
15
        { &hf_usbport_port_path1,
7288
15
            { "Path1",          "usbport.port_path1",
7289
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7290
15
            NULL, HFILL }
7291
15
        },
7292
15
        { &hf_usbport_port_path2,
7293
15
            { "Path2",          "usbport.port_path2",
7294
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7295
15
            NULL, HFILL }
7296
15
        },
7297
15
        { &hf_usbport_port_path3,
7298
15
            { "Path3",          "usbport.port_path3",
7299
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7300
15
            NULL, HFILL }
7301
15
        },
7302
15
        { &hf_usbport_port_path4,
7303
15
            { "Path4",          "usbport.port_path4",
7304
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7305
15
            NULL, HFILL }
7306
15
        },
7307
15
        { &hf_usbport_port_path5,
7308
15
            { "Path5",          "usbport.port_path5",
7309
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7310
15
            NULL, HFILL }
7311
15
        },
7312
15
        { &hf_usbport_device_handle,
7313
15
            { "Device Handle",          "usbport.device_handle",
7314
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7315
15
            NULL, HFILL }
7316
15
        },
7317
15
        { &hf_usbport_device_speed,
7318
15
            { "Device Speed",          "usbport.device_speed",
7319
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7320
15
            NULL, HFILL }
7321
15
        },
7322
15
        { &hf_usbport_endpoint,
7323
15
            { "Endpoint",          "usbport.endpoint",
7324
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7325
15
            NULL, HFILL }
7326
15
        },
7327
15
        { &hf_usbport_pipehandle,
7328
15
            { "Pipe Handle",          "usbport.pipehandle",
7329
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7330
15
            NULL, HFILL }
7331
15
        },
7332
15
        { &hf_usbport_endpoint_desc_length,
7333
15
            { "Length",          "usbport.endpoint_desc_length",
7334
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7335
15
            NULL, HFILL }
7336
15
        },
7337
15
        { &hf_usbport_endpoint_desc_type,
7338
15
            { "Description Type",          "usbport.endpoint_desc_type",
7339
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7340
15
            NULL, HFILL }
7341
15
        },
7342
15
        { &hf_usbport_endpoint_address,
7343
15
            { "Endpoint Address",          "usbport.endpoint_address",
7344
15
            FT_UINT8, BASE_HEX, NULL, 0x0,
7345
15
            NULL, HFILL }
7346
15
        },
7347
15
        { &hf_usbport_bm_attributes,
7348
15
            { "bmAttributes",          "usbport.bm_attributes",
7349
15
            FT_UINT8, BASE_DEC_HEX, NULL, 0x0,
7350
15
            NULL, HFILL }
7351
15
        },
7352
15
        { &hf_usbport_max_packet_size,
7353
15
            { "Max Packet Size",          "usbport.max_packet_size",
7354
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
7355
15
            NULL, HFILL }
7356
15
        },
7357
15
        { &hf_usbport_interval,
7358
15
            { "Interval",          "usbport.interval",
7359
15
            FT_UINT8, BASE_DEC, NULL, 0x0,
7360
15
            NULL, HFILL }
7361
15
        },
7362
15
        { &hf_usbport_irp,
7363
15
            { "IRP",          "usbport.irp",
7364
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7365
15
            NULL, HFILL }
7366
15
        },
7367
15
        { &hf_usbport_urb,
7368
15
            { "URB",          "usbport.urb",
7369
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7370
15
            NULL, HFILL }
7371
15
        },
7372
15
        { &hf_usbport_urb_transfer_data,
7373
15
            { "URB Transfer data",          "usbport.urb_transfer_data",
7374
15
            FT_UINT_BYTES, BASE_NONE, NULL, 0x0,
7375
15
            NULL, HFILL }
7376
15
        },
7377
15
        { &hf_usbport_urb_header_length,
7378
15
            { "URB Header Length",          "usbport.urb_header_length",
7379
15
            FT_UINT16, BASE_DEC, NULL, 0x0,
7380
15
            NULL, HFILL }
7381
15
        },
7382
15
        { &hf_usbport_urb_header_function,
7383
15
            { "URB Header Function",          "usbport.urb_header_function",
7384
15
            FT_UINT16, BASE_DEC|BASE_EXT_STRING, &netmon_urb_function_vals_ext, 0x0,
7385
15
            NULL, HFILL }
7386
15
        },
7387
15
        { &hf_usbport_urb_header_status,
7388
15
            { "URB Header Status",          "usbport.urb_header_status",
7389
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7390
15
            NULL, HFILL }
7391
15
        },
7392
15
        { &hf_usbport_urb_header_usbddevice_handle,
7393
15
            { "URB Header Device Handle",          "usbport.urb_header_usbddevice_handle",
7394
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7395
15
            NULL, HFILL }
7396
15
        },
7397
15
        { &hf_usbport_urb_header_usbdflags,
7398
15
            { "URB Header Flags",          "usbport.urb_header_usbdflags",
7399
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7400
15
            NULL, HFILL }
7401
15
        },
7402
15
        { &hf_usbport_urb_configuration_desc,
7403
15
            { "URB Configuration Description",          "usbport.urb_configuration_desc",
7404
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7405
15
            NULL, HFILL }
7406
15
        },
7407
15
        { &hf_usbport_urb_configuration_handle,
7408
15
            { "URB Configuration Handle",          "usbport.urb_configuration_handle",
7409
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7410
15
            NULL, HFILL }
7411
15
        },
7412
15
        { &hf_usbport_urb_pipe_handle,
7413
15
            { "URB Pipe Handle",          "usbport.urb_pipe_handle",
7414
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7415
15
            NULL, HFILL }
7416
15
        },
7417
15
        { &hf_usbport_urb_xferflags,
7418
15
            { "URB Transfer Flags",          "usbport.urb_xferflags",
7419
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
7420
15
            NULL, HFILL }
7421
15
        },
7422
15
        { &hf_usbport_urb_transfer_buffer_length,
7423
15
            { "URB Transfer Buffer Length",          "usbport.urb_transfer_buffer_length",
7424
15
            FT_UINT32, BASE_DEC, NULL, 0x0,
7425
15
            NULL, HFILL }
7426
15
        },
7427
15
        { &hf_usbport_urb_transfer_buffer,
7428
15
            { "URB Transfer Buffer",          "usbport.urb_transfer_buffer",
7429
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7430
15
            NULL, HFILL }
7431
15
        },
7432
15
        { &hf_usbport_urb_transfer_buffer_mdl,
7433
15
            { "URB Transfer Buffer MDL",          "usbport.urb_transfer_buffer_mdl",
7434
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7435
15
            NULL, HFILL }
7436
15
        },
7437
15
        { &hf_usbport_urb_reserved_mbz,
7438
15
            { "URB Reserved MBZ",          "usbport.urb_reserved_mbz",
7439
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7440
15
            NULL, HFILL }
7441
15
        },
7442
15
        { &hf_usbport_urb_reserved_hcd,
7443
15
            { "URB Reserved HCD",          "usbport.urb_reserved_hcd",
7444
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7445
15
            NULL, HFILL }
7446
15
        },
7447
15
        { &hf_usbport_urb_reserved,
7448
15
            { "URB Reserved",          "usbport.urb_reserved",
7449
15
            FT_UINT32, BASE_HEX, NULL, 0x0,
7450
15
            NULL, HFILL }
7451
15
        },
7452
15
        { &hf_usbport_keyword,
7453
15
            { "Keyword",          "usbport.keyword",
7454
15
            FT_UINT64, BASE_HEX, NULL, 0x0,
7455
15
            NULL, HFILL }
7456
15
        },
7457
15
        { &hf_usbport_keyword_diagnostic,
7458
15
            { "USBPORT_ETW_KEYWORD_DIAGNOSTIC",          "usbport.keyword.diagnostic",
7459
15
            FT_BOOLEAN, 64, NULL, USBPORT_KEYWORD_DIAGNOSTIC,
7460
15
            NULL, HFILL }
7461
15
        },
7462
15
        { &hf_usbport_keyword_power_diagnostics,
7463
15
            { "USBPORT_ETW_KEYWORD_POWER_DIAGNOSTICS",          "usbport.keyword.power_diagnostics",
7464
15
            FT_BOOLEAN, 64, NULL, USBPORT_KEYWORD_POWER_DIAGNOSTICS,
7465
15
            NULL, HFILL }
7466
15
        },
7467
15
        { &hf_usbport_keyword_perf_diagnostics,
7468
15
            { "USBPORT_ETW_KEYWORD_PERF_DIAGNOSTICS",          "usbport.keyword.perf_diagnostics",
7469
15
            FT_BOOLEAN, 64, NULL, USBPORT_KEYWORD_PERF_DIAGNOSTICS,
7470
15
            NULL, HFILL }
7471
15
        },
7472
15
        { &hf_usbport_keyword_reserved1,
7473
15
            { "Reserved1",          "usbport.keyword.reserved1",
7474
15
            FT_UINT64, BASE_HEX, NULL, USBPORT_KEYWORD_RESERVED1,
7475
15
            NULL, HFILL }
7476
15
        },
7477
15
    };
7478
7479
15
    static int *usb_ett[] = {
7480
15
        &ett_usb_hdr,
7481
15
        &ett_usb_setup_hdr,
7482
15
        &ett_usb_isodesc,
7483
15
        &ett_usb_win32_iso_packet,
7484
15
        &ett_usb_endpoint,
7485
15
        &ett_usb_xferflags,
7486
15
        &ett_usb_xferstatus,
7487
15
        &ett_usb_frame,
7488
15
        &ett_usb_frame_flags,
7489
15
        &ett_usb_setup_bmrequesttype,
7490
15
        &ett_usb_usbpcap_info,
7491
15
        &ett_descriptor_device,
7492
15
        &ett_configuration_bmAttributes,
7493
15
        &ett_configuration_bEndpointAddress,
7494
15
        &ett_endpoint_bmAttributes,
7495
15
        &ett_endpoint_wMaxPacketSize,
7496
15
        &ett_transfer_flags,
7497
15
        &ett_usb20ext_bmAttributes,
7498
15
        &ett_ss_bmAttributes,
7499
15
        &ett_ss_wSpeedSupported,
7500
15
    };
7501
7502
15
    static int *usbport_ett[] = {
7503
15
        &ett_usbport,
7504
15
        &ett_usbport_host_controller,
7505
15
        &ett_usbport_path,
7506
15
        &ett_usbport_device,
7507
15
        &ett_usbport_endpoint,
7508
15
        &ett_usbport_endpoint_desc,
7509
15
        &ett_usbport_urb,
7510
15
        &ett_usbport_keyword,
7511
15
    };
7512
7513
15
    static ei_register_info ei[] = {
7514
15
        { &ei_usb_undecoded, { "usb.undecoded", PI_UNDECODED, PI_WARN, "Not dissected yet (report to wireshark.org)", EXPFILL }},
7515
15
        { &ei_usb_bLength_even, { "usb.bLength.even", PI_PROTOCOL, PI_WARN, "Invalid STRING DESCRIPTOR Length (must be even)", EXPFILL }},
7516
15
        { &ei_usb_bLength_too_short, { "usb.bLength.too_short", PI_MALFORMED, PI_ERROR, "Invalid STRING DESCRIPTOR Length (must be 2 or larger)", EXPFILL }},
7517
15
        { &ei_usb_desc_length_invalid, { "usb.desc_length.invalid", PI_MALFORMED, PI_ERROR, "Invalid descriptor length", EXPFILL }},
7518
15
        { &ei_usb_invalid_setup, { "usb.setup.invalid", PI_MALFORMED, PI_ERROR, "Only control URBs may contain a setup packet", EXPFILL }},
7519
15
        { &ei_usb_ss_ep_companion_before_ep, { "usb.bmAttributes.invalid_order", PI_MALFORMED, PI_ERROR, "SuperSpeed Endpoint Companion must come after Endpoint Descriptor", EXPFILL }},
7520
15
        { &ei_usb_usbpcap_unknown_urb, { "usb.usbpcap.unknown_urb", PI_MALFORMED, PI_ERROR, "USBPcap did not recognize URB Function code (report to desowin.org/USBPcap)", EXPFILL }},
7521
15
        { &ei_usb_bad_length, { "usb.bad_length", PI_MALFORMED, PI_ERROR, "Invalid length", EXPFILL }},
7522
15
        { &ei_usb_invalid_max_packet_size, { "usb.wMaxPacketSize.invalid", PI_PROTOCOL, PI_WARN, "Invalid Max Packet Size", EXPFILL }},
7523
15
        { &ei_usb_invalid_max_packet_size0, { "usb.bMaxPacketSize0.invalid", PI_PROTOCOL, PI_WARN, "Invalid Max Packet Size", EXPFILL }},
7524
15
        { &ei_usb_invalid_endpoint_type, { "usb.bmAttributes.transfer.invalid", PI_PROTOCOL, PI_WARN, "Transfer type not allowed at Low-Speed", EXPFILL }},
7525
15
        { &ei_usb_unexpected_desc_type, { "usb.bDescriptorType.unexpected", PI_MALFORMED, PI_ERROR, "Unexpected descriptor type", EXPFILL }},
7526
15
    };
7527
15
    static ei_register_info ei_usbport[] = {
7528
15
        { &ei_usbport_invalid_path_depth, { "usbport.path_depth.invalid", PI_PROTOCOL, PI_WARN, "Invalid path depth", EXPFILL }},
7529
15
    };
7530
7531
15
    expert_module_t *expert_usb, *expert_usbport;
7532
7533
15
    proto_usb = proto_register_protocol("USB", "USB", "usb");
7534
15
    proto_usbport = proto_register_protocol("USBPort", "USBPort", "usbport");
7535
7536
15
    proto_register_field_array(proto_usb, hf, array_length(hf));
7537
15
    proto_register_field_array(proto_usbport, hf_usbport, array_length(hf_usbport));
7538
15
    proto_register_subtree_array(usb_ett, array_length(usb_ett));
7539
15
    proto_register_subtree_array(usbport_ett, array_length(usbport_ett));
7540
7541
15
    expert_usb = expert_register_protocol(proto_usb);
7542
15
    expert_register_field_array(expert_usb, ei, array_length(ei));
7543
15
    expert_usbport = expert_register_protocol(proto_usbport);
7544
15
    expert_register_field_array(expert_usbport, ei_usbport, array_length(ei_usbport));
7545
7546
15
    device_to_product_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
7547
15
    device_to_protocol_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
7548
15
    usbpcap_setup_data = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
7549
15
    device_to_dissector = register_dissector_table("usb.device",     "USB device",   proto_usb, FT_UINT32, BASE_HEX);
7550
15
    protocol_to_dissector = register_dissector_table("usb.protocol", "USB protocol", proto_usb, FT_UINT32, BASE_HEX);
7551
15
    product_to_dissector = register_dissector_table("usb.product",   "USB product",  proto_usb, FT_UINT32, BASE_HEX);
7552
7553
15
    usb_bulk_dissector_table = register_dissector_table("usb.bulk",
7554
15
        "USB bulk endpoint", proto_usb, FT_UINT32, BASE_HEX);
7555
15
    heur_bulk_subdissector_list = register_heur_dissector_list_with_description("usb.bulk", "USB bulk fallback", proto_usb);
7556
15
    usb_control_dissector_table = register_dissector_table("usb.control",
7557
15
        "USB control endpoint", proto_usb, FT_UINT32, BASE_HEX);
7558
15
    heur_control_subdissector_list = register_heur_dissector_list_with_description("usb.control", "USB control fallback", proto_usb);
7559
15
    usb_interrupt_dissector_table = register_dissector_table("usb.interrupt",
7560
15
        "USB interrupt endpoint", proto_usb, FT_UINT32, BASE_HEX);
7561
15
    heur_interrupt_subdissector_list = register_heur_dissector_list_with_description("usb.interrupt", "USB interrupt fallback", proto_usb);
7562
15
    usb_descriptor_dissector_table = register_dissector_table("usb.descriptor",
7563
15
        "USB descriptor", proto_usb, FT_UINT8, BASE_DEC);
7564
7565
15
    usb_module = prefs_register_protocol(proto_usb, NULL);
7566
15
    prefs_register_bool_preference(usb_module, "try_heuristics",
7567
15
        "Try heuristic sub-dissectors",
7568
15
        "Try to decode a packet using a heuristic sub-dissector before "
7569
15
         "attempting to dissect the packet using the \"usb.bulk\", \"usb.interrupt\" or "
7570
15
         "\"usb.control\" dissector tables.", &try_heuristics);
7571
7572
15
    usb_tap = register_tap("usb");
7573
7574
15
    register_decode_as(&usb_protocol_da);
7575
15
    register_decode_as(&usb_product_da);
7576
15
    register_decode_as(&usb_device_da);
7577
7578
15
    linux_usb_handle = register_dissector("usb_linux", dissect_linux_usb, proto_usb);
7579
15
    linux_usb_mmapped_handle = register_dissector("usb_linux_mmapped", dissect_linux_usb_mmapped, proto_usb);
7580
15
    win32_usb_handle = register_dissector("usb_win32", dissect_win32_usb, proto_usb);
7581
15
    freebsd_usb_handle = register_dissector("usb_freebsd", dissect_freebsd_usb, proto_usb);
7582
15
    darwin_usb_handle = register_dissector("usb_darwin", dissect_darwin_usb, proto_usb);
7583
15
    netmon_usb_port_handle = register_dissector("usb_netmon", dissect_netmon_usb_port, proto_usbport);
7584
7585
15
    usb_address_type = address_type_dissector_register("AT_USB", "USB Address", usb_addr_to_str, usb_addr_str_len, NULL, usb_col_filter_str, NULL, NULL, NULL);
7586
7587
15
    register_conversation_table(proto_usb, true, usb_conversation_packet, usb_endpoint_packet);
7588
15
}
7589
7590
void
7591
proto_reg_handoff_usb(void)
7592
15
{
7593
15
    static guid_key usb_port_key = {{ 0xc88a4ef5, 0xd048, 0x4013, { 0x94, 0x08, 0xe0, 0x4b, 0x7d, 0xb2, 0x81, 0x4a }}, 0 };
7594
7595
15
    dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_LINUX, linux_usb_handle);
7596
15
    dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_LINUX_MMAPPED, linux_usb_mmapped_handle);
7597
15
    dissector_add_uint("wtap_encap", WTAP_ENCAP_USBPCAP, win32_usb_handle);
7598
15
    dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_FREEBSD, freebsd_usb_handle);
7599
15
    dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_DARWIN, darwin_usb_handle);
7600
7601
15
    dissector_add_guid( "netmon.provider_id", &usb_port_key, netmon_usb_port_handle);
7602
15
}
7603
7604
/*
7605
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
7606
 *
7607
 * Local variables:
7608
 * c-basic-offset: 4
7609
 * tab-width: 8
7610
 * indent-tabs-mode: nil
7611
 * End:
7612
 *
7613
 * vi: set shiftwidth=4 tabstop=8 expandtab:
7614
 * :indentSize=4:tabSize=8:noTabs=true:
7615
 */