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