6 * By Paolo Abeni <paolo.abeni@email.it>
8 * Chris Maynard 2010 <chris[dot]maynard[at]gtech[dot]com>
10 * http://www.usb.org/developers/docs/usb_20_122909-2.zip
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
35 #include <epan/etypes.h>
36 #include <epan/addr_resolv.h>
37 #include <epan/emem.h>
39 #include <epan/conversation.h>
40 #include <epan/expert.h>
41 #include "packet-usb.h"
42 #include "packet-usb-hid.h"
44 /* protocols and header fields */
45 static int proto_usb = -1;
47 /* Linux USB pseudoheader fields */
48 static int hf_usb_urb_id = -1;
49 static int hf_usb_urb_type = -1;
50 static int hf_usb_transfer_type = -1;
51 static int hf_usb_endpoint_number = -1;
52 static int hf_usb_endpoint_direction = -1;
53 static int hf_usb_endpoint_number_value = -1;
54 static int hf_usb_device_address = -1;
55 static int hf_usb_bus_id = -1;
56 static int hf_usb_setup_flag = -1;
57 static int hf_usb_data_flag = -1;
58 static int hf_usb_urb_ts_sec = -1;
59 static int hf_usb_urb_ts_usec = -1;
60 static int hf_usb_urb_status = -1;
61 static int hf_usb_urb_len = -1;
62 static int hf_usb_data_len = -1;
64 static int hf_usb_src_endpoint_number = -1;
65 static int hf_usb_dst_endpoint_number = -1;
66 static int hf_usb_request = -1;
67 static int hf_usb_request_unknown_class = -1;
68 static int hf_usb_value = -1;
69 static int hf_usb_index = -1;
70 static int hf_usb_length = -1;
71 static int hf_usb_data = -1;
72 static int hf_usb_capdata = -1;
73 static int hf_usb_wFeatureSelector = -1;
74 static int hf_usb_wInterface = -1;
75 static int hf_usb_wStatus = -1;
76 static int hf_usb_wFrameNumber = -1;
78 static int hf_usb_iso_error_count = -1;
79 static int hf_usb_iso_numdesc = -1;
80 static int hf_usb_iso_status = -1;
81 static int hf_usb_iso_off = -1;
82 static int hf_usb_iso_len = -1;
83 static int hf_usb_iso_pad = -1;
84 static int hf_usb_iso_data = -1;
86 static int hf_usb_bmRequestType = -1;
87 static int hf_usb_bmRequestType_direction = -1;
88 static int hf_usb_bmRequestType_type = -1;
89 static int hf_usb_bmRequestType_recipient = -1;
90 static int hf_usb_bDescriptorType = -1;
91 static int hf_usb_descriptor_index = -1;
92 static int hf_usb_language_id = -1;
93 static int hf_usb_bLength = -1;
94 static int hf_usb_bcdUSB = -1;
95 static int hf_usb_bDeviceClass = -1;
96 static int hf_usb_bDeviceSubClass = -1;
97 static int hf_usb_bDeviceProtocol = -1;
98 static int hf_usb_bMaxPacketSize0 = -1;
99 static int hf_usb_idVendor = -1;
100 static int hf_usb_idProduct = -1;
101 static int hf_usb_bcdDevice = -1;
102 static int hf_usb_iManufacturer = -1;
103 static int hf_usb_iProduct = -1;
104 static int hf_usb_iSerialNumber = -1;
105 static int hf_usb_bNumConfigurations = -1;
106 static int hf_usb_wLANGID = -1;
107 static int hf_usb_bString = -1;
108 static int hf_usb_bInterfaceNumber = -1;
109 static int hf_usb_bAlternateSetting = -1;
110 static int hf_usb_bNumEndpoints = -1;
111 static int hf_usb_bInterfaceClass = -1;
112 static int hf_usb_bInterfaceSubClass = -1;
113 static int hf_usb_bInterfaceProtocol = -1;
114 static int hf_usb_iInterface = -1;
115 static int hf_usb_bEndpointAddress = -1;
116 static int hf_usb_bmAttributes = -1;
117 static int hf_usb_bEndpointAttributeTransfer = -1;
118 static int hf_usb_bEndpointAttributeSynchonisation = -1;
119 static int hf_usb_bEndpointAttributeBehaviour = -1;
120 static int hf_usb_wMaxPacketSize = -1;
121 static int hf_usb_bInterval = -1;
122 static int hf_usb_wTotalLength = -1;
123 static int hf_usb_bNumInterfaces = -1;
124 static int hf_usb_bConfigurationValue = -1;
125 static int hf_usb_iConfiguration = -1;
126 static int hf_usb_bMaxPower = -1;
127 static int hf_usb_configuration_bmAttributes = -1;
128 static int hf_usb_configuration_legacy10buspowered = -1;
129 static int hf_usb_configuration_selfpowered = -1;
130 static int hf_usb_configuration_remotewakeup = -1;
131 static int hf_usb_bEndpointAddress_direction = -1;
132 static int hf_usb_bEndpointAddress_number = -1;
133 static int hf_usb_response_in = -1;
134 static int hf_usb_time = -1;
135 static int hf_usb_request_in = -1;
137 static gint usb_hdr = -1;
138 static gint usb_setup_hdr = -1;
139 static gint usb_isodesc = -1;
140 static gint ett_usb_endpoint = -1;
141 static gint ett_usb_setup_bmrequesttype = -1;
142 static gint ett_descriptor_device = -1;
143 static gint ett_configuration_bmAttributes = -1;
144 static gint ett_configuration_bEndpointAddress = -1;
145 static gint ett_endpoint_bmAttributes = -1;
147 static const int *usb_endpoint_fields[] = {
148 &hf_usb_endpoint_direction,
149 &hf_usb_endpoint_number_value,
153 static int usb_tap = -1;
155 static dissector_table_t usb_bulk_dissector_table;
156 static dissector_table_t usb_control_dissector_table;
158 /* http://www.usb.org/developers/docs/USB_LANGIDs.pdf */
159 static const value_string usb_langid_vals[] = {
160 {0x0000, "no language specified"},
161 {0x0401, "Arabic (Saudi Arabia)"},
162 {0x0402, "Bulgarian"},
164 {0x0404, "Chinese (Taiwan)"},
167 {0x0407, "German (Standard)"},
169 {0x0409, "English (United States)"},
170 {0x040a, "Spanish (Traditional Sort)"},
172 {0x040c, "French (Standard)"},
174 {0x040e, "Hungarian"},
175 {0x040f, "Icelandic"},
176 {0x0410, "Italian (Standard)"},
177 {0x0411, "Japanese"},
179 {0x0413, "Dutch (Netherlands)"},
180 {0x0414, "Norwegian (Bokmal)"},
182 {0x0416, "Portuguese (Brazil)"},
183 {0x0418, "Romanian"},
185 {0x041a, "Croatian"},
187 {0x041c, "Albanian"},
191 {0x0420, "Urdu (Pakistan)"},
192 {0x0421, "Indonesian"},
193 {0x0422, "Ukrainian"},
194 {0x0423, "Belarussian"},
195 {0x0424, "Slovenian"},
196 {0x0425, "Estonian"},
198 {0x0427, "Lithuanian"},
200 {0x042a, "Vietnamese"},
201 {0x042b, "Armenian"},
202 {0x042c, "Azeri (Latin)"},
204 {0x042f, "Macedonian"},
206 {0x0436, "Afrikaans"},
207 {0x0437, "Georgian"},
208 {0x0438, "Faeroese"},
210 {0x043e, "Malay (Malaysian)"},
212 {0x0441, "Swahili (Kenya)"},
213 {0x0443, "Uzbek (Latin)"},
214 {0x0444, "Tatar (Tatarstan)"},
217 {0x0447, "Gujarati"},
222 {0x044c, "Malayalam"},
223 {0x044d, "Assamese"},
225 {0x044f, "Sanskrit"},
228 {0x0458, "Manipuri"},
230 {0x04ff, "HID (Usage Data Descriptor)"},
231 {0x0801, "Arabic (Iraq)"},
232 {0x0804, "Chinese (PRC)"},
233 {0x0807, "German (Switzerland)"},
234 {0x0809, "English (United Kingdom)"},
235 {0x080a, "Spanish (Mexican)"},
236 {0x080c, "French (Belgian)"},
237 {0x0810, "Italian (Switzerland)"},
238 {0x0812, "Korean (Johab)"},
239 {0x0813, "Dutch (Belgium)"},
240 {0x0814, "Norwegian (Nynorsk)"},
241 {0x0816, "Portuguese (Standard)"},
242 {0x081a, "Serbian (Latin)"},
243 {0x081d, "Swedish (Finland)"},
244 {0x0820, "Urdu (India)"},
245 {0x0827, "Lithuanian (Classic)"},
246 {0x082c, "Azeri (Cyrillic)"},
247 {0x083e, "Malay (Brunei Darussalam)"},
248 {0x0843, "Uzbek (Cyrillic)"},
249 {0x0860, "Kashmiri (India)"},
250 {0x0861, "Nepali (India)"},
251 {0x0c01, "Arabic (Egypt)"},
252 {0x0c04, "Chinese (Hong Kong SAR, PRC)"},
253 {0x0c07, "German (Austria)"},
254 {0x0c09, "English (Australian)"},
255 {0x0c0a, "Spanish (Modern Sort)"},
256 {0x0c0c, "French (Canadian)"},
257 {0x0c1a, "Serbian (Cyrillic)"},
258 {0x1001, "Arabic (Libya)"},
259 {0x1004, "Chinese (Singapore)"},
260 {0x1007, "German (Luxembourg)"},
261 {0x1009, "English (Canadian)"},
262 {0x100a, "Spanish (Guatemala)"},
263 {0x100c, "French (Switzerland)"},
264 {0x1401, "Arabic (Algeria)"},
265 {0x1404, "Chinese (Macau SAR)"},
266 {0x1407, "German (Liechtenstein)"},
267 {0x1409, "English (New Zealand)"},
268 {0x140a, "Spanish (Costa Rica)"},
269 {0x140c, "French (Luxembourg)"},
270 {0x1801, "Arabic (Morocco)"},
271 {0x1809, "English (Ireland)"},
272 {0x180a, "Spanish (Panama)"},
273 {0x180c, "French (Monaco)"},
274 {0x1c01, "Arabic (Tunisia)"},
275 {0x1c09, "English (South Africa)"},
276 {0x1c0a, "Spanish (Dominican Republic)"},
277 {0x2001, "Arabic (Oman)"},
278 {0x2009, "English (Jamaica)"},
279 {0x200a, "Spanish (Venezuela)"},
280 {0x2401, "Arabic (Yemen)"},
281 {0x2409, "English (Caribbean)"},
282 {0x240a, "Spanish (Colombia)"},
283 {0x2801, "Arabic (Syria)"},
284 {0x2809, "English (Belize)"},
285 {0x280a, "Spanish (Peru)"},
286 {0x2c01, "Arabic (Jordan)"},
287 {0x2c09, "English (Trinidad)"},
288 {0x2c0a, "Spanish (Argentina)"},
289 {0x3001, "Arabic (Lebanon)"},
290 {0x3009, "English (Zimbabwe)"},
291 {0x300a, "Spanish (Ecuador)"},
292 {0x3401, "Arabic (Kuwait)"},
293 {0x3409, "English (Philippines)"},
294 {0x340a, "Spanish (Chile)"},
295 {0x3801, "Arabic (U.A.E.)"},
296 {0x380a, "Spanish (Uruguay)"},
297 {0x3c01, "Arabic (Bahrain)"},
298 {0x3c0a, "Spanish (Paraguay)"},
299 {0x4001, "Arabic (Qatar)"},
300 {0x400a, "Spanish (Bolivia)"},
301 {0x440a, "Spanish (El Salvador)"},
302 {0x480a, "Spanish (Honduras)"},
303 {0x4c0a, "Spanish (Nicaragua)"},
304 {0x500a, "Spanish (Puerto Rico)"},
305 {0xf0ff, "HID (Vendor Defined 1)"},
306 {0xf4ff, "HID (Vendor Defined 2)"},
307 {0xf8ff, "HID (Vendor Defined 3)"},
308 {0xfcff, "HID (Vendor Defined 4)"},
312 static value_string_ext usb_langid_vals_ext = VALUE_STRING_EXT_INIT(usb_langid_vals);
314 static const value_string usb_interfaceclass_vals[] = {
315 {IF_CLASS_FROM_INTERFACE_DESC, "Use class info in Interface Descriptor"},
316 {IF_CLASS_AUDIO, "AUDIO"},
317 {IF_CLASS_COMMUNICATIONS, "COMMUNICATIONS"},
318 {IF_CLASS_HID, "HID"},
319 {IF_CLASS_PHYSICAL, "PHYSICAL"},
320 {IF_CLASS_IMAGE, "IMAGE"},
321 {IF_CLASS_PRINTER, "PRINTER"},
322 {IF_CLASS_MASSTORAGE, "MASSTORAGE"},
323 {IF_CLASS_HUB, "HUB"},
324 {IF_CLASS_CDC_DATA, "CDC_DATA"},
325 {IF_CLASS_SMART_CARD, "SMART_CARD"},
326 {IF_CLASS_CONTENT_SECURITY, "CONTENT_SECURITY"},
327 {IF_CLASS_VIDEO, "VIDEO"},
328 {IF_CLASS_DIAGNOSTIC_DEVICE, "DIAGNOSTIC_DEVICE"},
329 {IF_CLASS_WIRELESS_CONTROLLER, "WIRELESS_CONTROLLER"},
330 {IF_CLASS_MISCELLANEOUS, "MISCELLANEOUS"},
331 {IF_CLASS_APPLICATION_SPECIFIC, "APPLICATION_SPECIFIC"},
332 {IF_CLASS_VENDOR_SPECIFIC, "VENDOR_SPECIFIC"},
337 static const value_string usb_transfer_type_vals[] = {
338 {URB_CONTROL, "URB_CONTROL"},
339 {URB_ISOCHRONOUS,"URB_ISOCHRONOUS"},
340 {URB_INTERRUPT,"URB_INTERRUPT"},
341 {URB_BULK,"URB_BULK"},
345 static const value_string usb_transfer_type_and_direction_vals[] = {
346 {URB_CONTROL, "URB_CONTROL out"},
347 {URB_ISOCHRONOUS,"URB_ISOCHRONOUS out"},
348 {URB_INTERRUPT,"URB_INTERRUPT out"},
349 {URB_BULK,"URB_BULK out"},
350 {URB_CONTROL | URB_TRANSFER_IN, "URB_CONTROL in"},
351 {URB_ISOCHRONOUS | URB_TRANSFER_IN,"URB_ISOCHRONOUS in"},
352 {URB_INTERRUPT | URB_TRANSFER_IN,"URB_INTERRUPT in"},
353 {URB_BULK | URB_TRANSFER_IN,"URB_BULK in"},
357 static const value_string usb_endpoint_direction_vals[] = {
363 static const value_string usb_urb_type_vals[] = {
364 {URB_SUBMIT, "URB_SUBMIT"},
365 {URB_COMPLETE,"URB_COMPLETE"},
366 {URB_ERROR,"URB_ERROR"},
373 #define USB_DT_DEVICE 1
374 #define USB_DT_CONFIG 2
375 #define USB_DT_STRING 3
376 #define USB_DT_INTERFACE 4
377 #define USB_DT_ENDPOINT 5
378 #define USB_DT_DEVICE_QUALIFIER 6
379 #define USB_DT_OTHER_SPEED_CONFIG 7
380 #define USB_DT_INTERFACE_POWER 8
381 /* these are from a minor usb 2.0 revision (ECN) */
383 #define USB_DT_DEBUG 10
384 #define USB_DT_INTERFACE_ASSOCIATION 11
385 /* these are from the Wireless USB spec */
386 #define USB_DT_SECURITY 12
387 #define USB_DT_KEY 13
388 #define USB_DT_ENCRYPTION_TYPE 14
389 #define USB_DT_BOS 15
390 #define USB_DT_DEVICE_CAPABILITY 16
391 #define USB_DT_WIRELESS_ENDPOINT_COMP 17
392 #define USB_DT_HID 33
393 #define USB_DT_RPIPE 34
395 static const value_string descriptor_type_vals[] = {
396 {USB_DT_DEVICE, "DEVICE"},
397 {USB_DT_CONFIG, "CONFIGURATION"},
398 {USB_DT_STRING, "STRING"},
399 {USB_DT_INTERFACE, "INTERFACE"},
400 {USB_DT_ENDPOINT, "ENDPOINT"},
401 {USB_DT_DEVICE_QUALIFIER, "DEVICE QUALIFIER"},
402 {USB_DT_OTHER_SPEED_CONFIG, "OTHER_SPEED CONFIG"},
403 {USB_DT_INTERFACE_POWER, "INTERFACE POWER"},
405 {USB_DT_DEBUG, "DEBUG"},
406 {USB_DT_INTERFACE_ASSOCIATION, "INTERFACE ASSOCIATION"},
407 {USB_DT_SECURITY, "SECURITY"},
409 {USB_DT_ENCRYPTION_TYPE, "ENCRYPTION TYPE"},
411 {USB_DT_DEVICE_CAPABILITY, "DEVICE CAPABILITY"},
412 {USB_DT_WIRELESS_ENDPOINT_COMP, "WIRELESS ENDPOINT COMP"},
414 {USB_DT_RPIPE, "RPIPE"},
421 #define USB_FS_DEVICE_REMOTE_WAKEUP 1
422 #define USB_FS_ENDPOINT_HALT 0
423 #define USB_FS_TEST_MODE 2
425 static const value_string usb_feature_selector_vals[] = {
426 {USB_FS_DEVICE_REMOTE_WAKEUP, "DEVICE REMOTE WAKEUP"},
427 {USB_FS_ENDPOINT_HALT, "ENDPOINT HALT"},
428 {USB_FS_TEST_MODE, "TEST MODE"},
432 static const value_string usb_bmAttributes_transfer_vals[] = {
433 {0x00, "Control-Transfer"},
434 {0x01, "Isochronous-Transfer"},
435 {0x02, "Bulk-Transfer"},
436 {0x03, "Interrupt-Transfer"},
440 static const value_string usb_bmAttributes_sync_vals[] = {
442 {0x04, "Asynchronous"},
444 {0x0c, "Synchronous"},
448 static const value_string usb_bmAttributes_behaviour_vals[] = {
449 {0x00, "Data-Endpoint"},
450 {0x10, "Explicit Feedback-Endpoint"},
451 {0x20, "Implicit Feedback-Data-Endpoint"},
456 /* from linux/include/asm-generic/errno.h */
457 #define EPERM 1 /* Operation not permitted */
458 #define ENOENT 2 /* No such file or directory */
459 #define ESRCH 3 /* No such process */
460 #define EINTR 4 /* Interrupted system call */
461 #define EIO 5 /* I/O error */
462 #define ENXIO 6 /* No such device or address */
463 #define E2BIG 7 /* Argument list too long */
464 #define ENOEXEC 8 /* Exec format error */
465 #define EBADF 9 /* Bad file number */
466 #define ECHILD 10 /* No child processes */
467 #define EAGAIN 11 /* Try again */
468 #define ENOMEM 12 /* Out of memory */
469 #define EACCES 13 /* Permission denied */
470 #define EFAULT 14 /* Bad address */
471 #define ENOTBLK 15 /* Block device required */
472 #define EBUSY 16 /* Device or resource busy */
473 #define EEXIST 17 /* File exists */
474 #define EXDEV 18 /* Cross-device link */
475 #define ENODEV 19 /* No such device */
476 #define ENOTDIR 20 /* Not a directory */
477 #define EISDIR 21 /* Is a directory */
478 #define EINVAL 22 /* Invalid argument */
479 #define ENFILE 23 /* File table overflow */
480 #define EMFILE 24 /* Too many open files */
481 #define ENOTTY 25 /* Not a typewriter */
482 #define ETXTBSY 26 /* Text file busy */
483 #define EFBIG 27 /* File too large */
484 #define ENOSPC 28 /* No space left on device */
485 #define ESPIPE 29 /* Illegal seek */
486 #define EROFS 30 /* Read-only file system */
487 #define EMLINK 31 /* Too many links */
488 #define EPIPE 32 /* Broken pipe */
489 #define EDOM 33 /* Math argument out of domain of func */
490 #define ERANGE 34 /* Math result not representable */
493 /* from linux/include/asm-generic/errno.h*/
494 #define EDEADLK 35 /* Resource deadlock would occur */
495 #define ENAMETOOLONG 36 /* File name too long */
496 #define ENOLCK 37 /* No record locks available */
497 #define ENOSYS 38 /* Function not implemented */
498 #define ENOTEMPTY 39 /* Directory not empty */
499 #define ELOOP 40 /* Too many symbolic links encountered */
500 #define EWOULDBLOCK EAGAIN /* Operation would block */
501 #define ENOMSG 42 /* No message of desired type */
502 #define EIDRM 43 /* Identifier removed */
503 #define ECHRNG 44 /* Channel number out of range */
504 #define EL2NSYNC 45 /* Level 2 not synchronized */
505 #define EL3HLT 46 /* Level 3 halted */
506 #define EL3RST 47 /* Level 3 reset */
507 #define ELNRNG 48 /* Link number out of range */
508 #define EUNATCH 49 /* Protocol driver not attached */
509 #define ENOCSI 50 /* No CSI structure available */
510 #define EL2HLT 51 /* Level 2 halted */
511 #define EBADE 52 /* Invalid exchange */
512 #define EBADR 53 /* Invalid request descriptor */
513 #define EXFULL 54 /* Exchange full */
514 #define ENOANO 55 /* No anode */
515 #define EBADRQC 56 /* Invalid request code */
516 #define EBADSLT 57 /* Invalid slot */
518 #define EDEADLOCK EDEADLK
520 #define EBFONT 59 /* Bad font file format */
521 #define ENOSTR 60 /* Device not a stream */
522 #define ENODATA 61 /* No data available */
523 #define ETIME 62 /* Timer expired */
524 #define ENOSR 63 /* Out of streams resources */
525 #define ENONET 64 /* Machine is not on the network */
526 #define ENOPKG 65 /* Package not installed */
527 #define EREMOTE 66 /* Object is remote */
528 #define ENOLINK 67 /* Link has been severed */
529 #define EADV 68 /* Advertise error */
530 #define ESRMNT 69 /* Srmount error */
531 #define ECOMM 70 /* Communication error on send */
532 #define EPROTO 71 /* Protocol error */
533 #define EMULTIHOP 72 /* Multihop attempted */
534 #define EDOTDOT 73 /* RFS specific error */
535 #define EBADMSG 74 /* Not a data message */
536 #define EOVERFLOW 75 /* Value too large for defined data type */
537 #define ENOTUNIQ 76 /* Name not unique on network */
538 #define EBADFD 77 /* File descriptor in bad state */
539 #define EREMCHG 78 /* Remote address changed */
540 #define ELIBACC 79 /* Can not access a needed shared library */
541 #define ELIBBAD 80 /* Accessing a corrupted shared library */
542 #define ELIBSCN 81 /* .lib section in a.out corrupted */
543 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
544 #define ELIBEXEC 83 /* Cannot exec a shared library directly */
545 #define EILSEQ 84 /* Illegal byte sequence */
546 #define ERESTART 85 /* Interrupted system call should be restarted */
547 #define ESTRPIPE 86 /* Streams pipe error */
548 #define EUSERS 87 /* Too many users */
549 #define ENOTSOCK 88 /* Socket operation on non-socket */
550 #define EDESTADDRREQ 89 /* Destination address required */
551 #define EMSGSIZE 90 /* Message too long */
552 #define EPROTOTYPE 91 /* Protocol wrong type for socket */
553 #define ENOPROTOOPT 92 /* Protocol not available */
554 #define EPROTONOSUPPORT 93 /* Protocol not supported */
555 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
556 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
557 #define EPFNOSUPPORT 96 /* Protocol family not supported */
558 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
559 #define EADDRINUSE 98 /* Address already in use */
560 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
561 #define ENETDOWN 100 /* Network is down */
562 #define ENETUNREACH 101 /* Network is unreachable */
563 #define ENETRESET 102 /* Network dropped connection because of reset */
564 #define ECONNABORTED 103 /* Software caused connection abort */
565 #define ECONNRESET 104 /* Connection reset by peer */
566 #define ENOBUFS 105 /* No buffer space available */
567 #define EISCONN 106 /* Transport endpoint is already connected */
568 #define ENOTCONN 107 /* Transport endpoint is not connected */
569 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
570 #define ETOOMANYREFS 109 /* Too many references: cannot splice */
571 #define ETIMEDOUT 110 /* Connection timed out */
572 #define ECONNREFUSED 111 /* Connection refused */
573 #define EHOSTDOWN 112 /* Host is down */
574 #define EHOSTUNREACH 113 /* No route to host */
575 #define EALREADY 114 /* Operation already in progress */
576 #define EINPROGRESS 115 /* Operation now in progress */
577 #define ESTALE 116 /* Stale NFS file handle */
578 #define EUCLEAN 117 /* Structure needs cleaning */
579 #define ENOTNAM 118 /* Not a XENIX named type file */
580 #define ENAVAIL 119 /* No XENIX semaphores available */
581 #define EISNAM 120 /* Is a named type file */
582 #define EREMOTEIO 121 /* Remote I/O error */
583 #define EDQUOT 122 /* Quota exceeded */
585 #define ENOMEDIUM 123 /* No medium found */
586 #define EMEDIUMTYPE 124 /* Wrong medium type */
587 #define ECANCELED 125 /* Operation Canceled */
588 #define ENOKEY 126 /* Required key not available */
589 #define EKEYEXPIRED 127 /* Key has expired */
590 #define EKEYREVOKED 128 /* Key has been revoked */
591 #define EKEYREJECTED 129 /* Key was rejected by service */
593 /* for robust mutexes */
594 #define EOWNERDEAD 130 /* Owner died */
595 #define ENOTRECOVERABLE 131 /* State not recoverable */
598 static const value_string usb_urb_status_vals[] = {
600 { -EPERM, "Operation not permitted (-EPERM)" },
601 { -ENOENT, "No such file or directory (-ENOENT)" },
602 { -ESRCH, "No such process (-ESRCH)" },
603 { -EINTR, "Interrupted system call (-EINTR)" },
604 { -EIO, "I/O error (-EIO)" },
605 { -ENXIO, "No such device or address (-ENXIO)" },
606 { -E2BIG, "Argument list too long (-E2BIG)" },
607 { -ENOEXEC, "Exec format error (-ENOEXEC)" },
608 { -EBADF, "Bad file number (-EBADF)" },
609 { -ECHILD, "No child processes (-ECHILD)" },
610 { -EAGAIN, "Try again (-EAGAIN)" },
611 { -ENOMEM, "Out of memory (-ENOMEM)" },
612 { -EACCES, "Permission denied (-EACCES)" },
613 { -EFAULT, "Bad address (-EFAULT)" },
614 { -ENOTBLK, "Block device required (-ENOTBLK)" },
615 { -EBUSY, "Device or resource busy (-EBUSY)" },
616 { -EEXIST, "File exists (-EEXIST)" },
617 { -EXDEV, "Cross-device link (-EXDEV)" },
618 { -ENODEV, "No such device (-ENODEV)" },
619 { -ENOTDIR, "Not a directory (-ENOTDIR)" },
620 { -EISDIR, "Is a directory (-EISDIR)" },
621 { -EINVAL, "Invalid argument (-EINVAL)" },
622 { -ENFILE, "File table overflow (-ENFILE)" },
623 { -EMFILE, "Too many open files (-EMFILE)" },
624 { -ENOTTY, "Not a typewriter (-ENOTTY)" },
625 { -ETXTBSY, "Text file busy (-ETXTBSY)" },
626 { -EFBIG, "File too large (-EFBIG)" },
627 { -ENOSPC, "No space left on device (-ENOSPC)" },
628 { -ESPIPE, "Illegal seek (-ESPIPE)" },
629 { -EROFS, "Read-only file system (-EROFS)" },
630 { -EMLINK, "Too many links (-EMLINK)" },
631 { -EPIPE, "Broken pipe (-EPIPE)" },
632 { -EDOM, "Math argument out of domain of func (-EDOM)" },
633 { -ERANGE, "Math result not representable (-ERANGE)" },
634 { -EDEADLK, "Resource deadlock would occur (-EDEADLK)" },
635 { -ENAMETOOLONG, "File name too long (-ENAMETOOLONG)" },
636 { -ENOLCK, "No record locks available (-ENOLCK)" },
637 { -ENOSYS, "Function not implemented (-ENOSYS)" },
638 { -ENOTEMPTY, "Directory not empty (-ENOTEMPTY)" },
639 { -ELOOP, "Too many symbolic links encountered (-ELOOP)" },
640 { -ENOMSG, "No message of desired type (-ENOMSG)" },
641 { -EIDRM, "Identifier removed (-EIDRM)" },
642 { -ECHRNG, "Channel number out of range (-ECHRNG)" },
643 { -EL2NSYNC, "Level 2 not synchronized (-EL2NSYNC)" },
644 { -EL3HLT, "Level 3 halted (-EL3HLT)" },
645 { -EL3RST, "Level 3 reset (-EL3RST)" },
646 { -ELNRNG, "Link number out of range (-ELNRNG)" },
647 { -EUNATCH, "Protocol driver not attached (-EUNATCH)" },
648 { -ENOCSI, "No CSI structure available (-ENOCSI)" },
649 { -EL2HLT, "Level 2 halted (-EL2HLT)" },
650 { -EBADE, "Invalid exchange (-EBADE)" },
651 { -EBADR, "Invalid request descriptor (-EBADR)" },
652 { -EXFULL, "Exchange full (-EXFULL)" },
653 { -ENOANO, "No anode (-ENOANO)" },
654 { -EBADRQC, "Invalid request code (-EBADRQC)" },
655 { -EBADSLT, "Invalid slot (-EBADSLT)" },
656 { -EBFONT, "Bad font file format (-EBFONT)" },
657 { -ENOSTR, "Device not a stream (-ENOSTR)" },
658 { -ENODATA, "No data available (-ENODATA)" },
659 { -ETIME, "Timer expired (-ETIME)" },
660 { -ENOSR, "Out of streams resources (-ENOSR)" },
661 { -ENONET, "Machine is not on the network (-ENONET)" },
662 { -ENOPKG, "Package not installed (-ENOPKG)" },
663 { -EREMOTE, "Object is remote (-EREMOTE)" },
664 { -ENOLINK, "Link has been severed (-ENOLINK)" },
665 { -EADV, "Advertise error (-EADV)" },
666 { -ESRMNT, "Srmount error (-ESRMNT)" },
667 { -ECOMM, "Communication error on send (-ECOMM)" },
668 { -EPROTO, "Protocol error (-EPROTO)" },
669 { -EMULTIHOP, "Multihop attempted (-EMULTIHOP)" },
670 { -EDOTDOT, "RFS specific error (-EDOTDOT)" },
671 { -EBADMSG, "Not a data message (-EBADMSG)" },
672 { -EOVERFLOW, "Value too large for defined data type (-EOVERFLOW)" },
673 { -ENOTUNIQ, "Name not unique on network (-ENOTUNIQ)" },
674 { -EBADFD, "File descriptor in bad state (-EBADFD)" },
675 { -EREMCHG, "Remote address changed (-EREMCHG)" },
676 { -ELIBACC, "Can not access a needed shared library (-ELIBACC)" },
677 { -ELIBBAD, "Accessing a corrupted shared library (-ELIBBAD)" },
678 { -ELIBSCN, ".lib section in a.out corrupted (-ELIBSCN)" },
679 { -ELIBMAX, "Attempting to link in too many shared libraries (-ELIBMAX)" },
680 { -ELIBEXEC, "Cannot exec a shared library directly (-ELIBEXEC)" },
681 { -EILSEQ, "Illegal byte sequence (-EILSEQ)" },
682 { -ERESTART, "Interrupted system call should be restarted (-ERESTART)" },
683 { -ESTRPIPE, "Streams pipe error (-ESTRPIPE)" },
684 { -EUSERS, "Too many users (-EUSERS)" },
685 { -ENOTSOCK, "Socket operation on non-socket (-ENOTSOCK)" },
686 { -EDESTADDRREQ, "Destination address required (-EDESTADDRREQ)" },
687 { -EMSGSIZE, "Message too long (-EMSGSIZE)" },
688 { -EPROTOTYPE, "Protocol wrong type for socket (-EPROTOTYPE)" },
689 { -ENOPROTOOPT, "Protocol not available (-ENOPROTOOPT)" },
690 { -EPROTONOSUPPORT, "Protocol not supported (-EPROTONOSUPPORT)" },
691 { -ESOCKTNOSUPPORT, "Socket type not supported (-ESOCKTNOSUPPORT)" },
692 { -EOPNOTSUPP, "Operation not supported on transport endpoint (-EOPNOTSUPP)" },
693 { -EPFNOSUPPORT, "Protocol family not supported (-EPFNOSUPPORT)" },
694 { -EAFNOSUPPORT, "Address family not supported by protocol (-EAFNOSUPPORT)" },
695 { -EADDRINUSE, "Address already in use (-EADDRINUSE)" },
696 { -EADDRNOTAVAIL, "Cannot assign requested address (-EADDRNOTAVAIL)" },
697 { -ENETDOWN, "Network is down (-ENETDOWN)" },
698 { -ENETUNREACH, "Network is unreachable (-ENETUNREACH)" },
699 { -ENETRESET, "Network dropped connection because of reset (-ENETRESET)" },
700 { -ECONNABORTED, "Software caused connection abort (-ECONNABORTED)" },
701 { -ECONNRESET, "Connection reset by peer (-ECONNRESET)" },
702 { -ENOBUFS, "No buffer space available (-ENOBUFS)" },
703 { -EISCONN, "Transport endpoint is already connected (-EISCONN)" },
704 { -ENOTCONN, "Transport endpoint is not connected (-ENOTCONN)" },
705 { -ESHUTDOWN, "Cannot send after transport endpoint shutdown (-ESHUTDOWN)" },
706 { -ETOOMANYREFS, "Too many references: cannot splice (-ETOOMANYREFS)" },
707 { -ETIMEDOUT, "Connection timed out (-ETIMEDOUT)" },
708 { -ECONNREFUSED, "Connection refused (-ECONNREFUSED)" },
709 { -EHOSTDOWN, "Host is down (-EHOSTDOWN)" },
710 { -EHOSTUNREACH, "No route to host (-EHOSTUNREACH)" },
711 { -EALREADY, "Operation already in progress (-EALREADY)" },
712 { -EINPROGRESS, "Operation now in progress (-EINPROGRESS)" },
713 { -ESTALE, "Stale NFS file handle (-ESTALE)" },
714 { -EUCLEAN, "Structure needs cleaning (-EUCLEAN)" },
715 { -ENOTNAM, "Not a XENIX named type file (-ENOTNAM)" },
716 { -ENAVAIL, "No XENIX semaphores available (-ENAVAIL)" },
717 { -EISNAM, "Is a named type file (-EISNAM)" },
718 { -EREMOTEIO, "Remote I/O error (-EREMOTEIO)" },
719 { -EDQUOT, "Quota exceeded (-EDQUOT)" },
720 { -ENOMEDIUM, "No medium found (-ENOMEDIUM)" },
721 { -EMEDIUMTYPE, "Wrong medium type (-EMEDIUMTYPE)" },
722 { -ECANCELED, "Operation Canceled (-ECANCELED)" },
723 { -ENOKEY, "Required key not available (-ENOKEY)" },
724 { -EKEYEXPIRED, "Key has expired (-EKEYEXPIRED)" },
725 { -EKEYREVOKED, "Key has been revoked (-EKEYREVOKED)" },
726 { -EKEYREJECTED, "Key was rejected by service (-EKEYREJECTED)" },
727 { -EOWNERDEAD, "Owner died (-EOWNERDEAD)" },
728 { -ENOTRECOVERABLE, "State not recoverable (-ENOTRECOVERABLE)" },
733 static usb_conv_info_t *
734 get_usb_conv_info(conversation_t *conversation)
736 usb_conv_info_t *usb_conv_info;
738 /* do we have conversation specific data ? */
739 usb_conv_info = conversation_get_proto_data(conversation, proto_usb);
741 /* no not yet so create some */
742 usb_conv_info = se_alloc0(sizeof(usb_conv_info_t));
743 usb_conv_info->interfaceClass=IF_CLASS_UNKNOWN;
744 usb_conv_info->transactions=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "usb transactions");
746 conversation_add_proto_data(conversation, proto_usb, usb_conv_info);
749 return usb_conv_info;
752 static conversation_t *
753 get_usb_conversation(packet_info *pinfo, address *src_addr, address *dst_addr, guint32 src_endpoint, guint32 dst_endpoint)
755 conversation_t *conversation;
758 * Do we have a conversation for this connection?
760 conversation = find_conversation(pinfo->fd->num,
763 src_endpoint, dst_endpoint, 0);
768 /* We don't yet have a conversation, so create one. */
769 conversation = conversation_new(pinfo->fd->num,
772 src_endpoint, dst_endpoint, 0);
778 /* SETUP dissectors */
782 * These dissectors are used to dissect the setup part and the data
783 * for URB_CONTROL_INPUT / CLEAR FEATURE
789 dissect_usb_setup_clear_feature_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
791 /* feature selector */
792 proto_tree_add_item(tree, hf_usb_wFeatureSelector, tvb, offset, 2, TRUE);
795 /* zero/interface/endpoint */
796 /* XXX - check based on request type */
797 proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, TRUE);
801 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
808 dissect_usb_setup_clear_feature_response(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
815 * These dissectors are used to dissect the setup part and the data
816 * for URB_CONTROL_INPUT / GET CONFIGURATION
822 dissect_usb_setup_get_configuration_response(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
824 proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, TRUE);
832 * These dissectors are used to dissect the setup part and the data
833 * for URB_CONTROL_INPUT / GET DESCRIPTOR
839 dissect_usb_device_qualifier_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
841 proto_item *item=NULL;
842 proto_tree *tree=NULL;
843 int old_offset=offset;
846 item=proto_tree_add_text(parent_tree, tvb, offset, -1, "DEVICE QUALIFIER DESCRIPTOR");
847 tree=proto_item_add_subtree(item, ett_descriptor_device);
851 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
854 /* bDescriptorType */
855 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
859 proto_tree_add_item(tree, hf_usb_bcdUSB, tvb, offset, 2, TRUE);
863 proto_tree_add_item(tree, hf_usb_bDeviceClass, tvb, offset, 1, TRUE);
866 /* bDeviceSubClass */
867 proto_tree_add_item(tree, hf_usb_bDeviceSubClass, tvb, offset, 1, TRUE);
870 /* bDeviceProtocol */
871 proto_tree_add_item(tree, hf_usb_bDeviceProtocol, tvb, offset, 1, TRUE);
874 /* bMaxPacketSize0 */
875 proto_tree_add_item(tree, hf_usb_bMaxPacketSize0, tvb, offset, 1, TRUE);
878 /* bNumConfigurations */
879 proto_tree_add_item(tree, hf_usb_bNumConfigurations, tvb, offset, 1, TRUE);
882 /* one reserved byte */
886 proto_item_set_len(item, offset-old_offset);
894 dissect_usb_device_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
896 proto_item *item=NULL;
897 proto_tree *tree=NULL;
898 int old_offset=offset;
901 item=proto_tree_add_text(parent_tree, tvb, offset, -1, "DEVICE DESCRIPTOR");
902 tree=proto_item_add_subtree(item, ett_descriptor_device);
906 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
909 /* bDescriptorType */
910 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
914 proto_tree_add_item(tree, hf_usb_bcdUSB, tvb, offset, 2, TRUE);
918 proto_tree_add_item(tree, hf_usb_bDeviceClass, tvb, offset, 1, TRUE);
921 /* bDeviceSubClass */
922 proto_tree_add_item(tree, hf_usb_bDeviceSubClass, tvb, offset, 1, TRUE);
925 /* bDeviceProtocol */
926 proto_tree_add_item(tree, hf_usb_bDeviceProtocol, tvb, offset, 1, TRUE);
929 /* bMaxPacketSize0 */
930 proto_tree_add_item(tree, hf_usb_bMaxPacketSize0, tvb, offset, 1, TRUE);
934 proto_tree_add_item(tree, hf_usb_idVendor, tvb, offset, 2, TRUE);
938 proto_tree_add_item(tree, hf_usb_idProduct, tvb, offset, 2, TRUE);
942 proto_tree_add_item(tree, hf_usb_bcdDevice, tvb, offset, 2, TRUE);
946 proto_tree_add_item(tree, hf_usb_iManufacturer, tvb, offset, 1, TRUE);
950 proto_tree_add_item(tree, hf_usb_iProduct, tvb, offset, 1, TRUE);
954 proto_tree_add_item(tree, hf_usb_iSerialNumber, tvb, offset, 1, TRUE);
957 /* bNumConfigurations */
958 proto_tree_add_item(tree, hf_usb_bNumConfigurations, tvb, offset, 1, TRUE);
962 proto_item_set_len(item, offset-old_offset);
970 dissect_usb_string_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info _U_)
972 proto_item *item=NULL;
973 proto_tree *tree=NULL;
974 int old_offset=offset;
978 item=proto_tree_add_text(parent_tree, tvb, offset, -1, "STRING DESCRIPTOR");
979 tree=proto_item_add_subtree(item, ett_descriptor_device);
983 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
984 len=tvb_get_guint8(tvb, offset);
987 /* bDescriptorType */
988 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
991 if(!usb_trans_info->u.get_descriptor.index){
992 /* list of languanges */
993 while(len>(offset-old_offset)){
995 proto_tree_add_item(tree, hf_usb_wLANGID, tvb, offset, 2, TRUE);
1001 /* unicode string */
1002 str=tvb_get_ephemeral_faked_unicode(tvb, offset, (len-2)/2, TRUE);
1003 proto_tree_add_string(tree, hf_usb_bString, tvb, offset, len-2, str);
1008 proto_item_set_len(item, offset-old_offset);
1018 dissect_usb_interface_descriptor(packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info)
1020 proto_item *item=NULL;
1021 proto_tree *tree=NULL;
1022 int old_offset=offset;
1026 item=proto_tree_add_text(parent_tree, tvb, offset, -1, "INTERFACE DESCRIPTOR");
1027 tree=proto_item_add_subtree(item, ett_descriptor_device);
1031 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
1032 len = tvb_get_guint8(tvb, offset);
1035 /* bDescriptorType */
1036 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
1039 /* bInterfaceNumber */
1040 proto_tree_add_item(tree, hf_usb_bInterfaceNumber, tvb, offset, 1, TRUE);
1043 /* bAlternateSetting */
1044 proto_tree_add_item(tree, hf_usb_bAlternateSetting, tvb, offset, 1, TRUE);
1048 proto_tree_add_item(tree, hf_usb_bNumEndpoints, tvb, offset, 1, TRUE);
1051 /* bInterfaceClass */
1052 proto_tree_add_item(tree, hf_usb_bInterfaceClass, tvb, offset, 1, TRUE);
1053 /* save the class so we can access it later in the endpoint descriptor */
1054 usb_conv_info->interfaceClass=tvb_get_guint8(tvb, offset);
1055 if(!pinfo->fd->flags.visited){
1056 usb_trans_info->interface_info=se_alloc0(sizeof(usb_conv_info_t));
1057 usb_trans_info->interface_info->interfaceClass=tvb_get_guint8(tvb, offset);
1058 usb_trans_info->interface_info->transactions=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "usb transactions");
1062 /* bInterfaceSubClass */
1063 proto_tree_add_item(tree, hf_usb_bInterfaceSubClass, tvb, offset, 1, TRUE);
1066 /* bInterfaceProtocol */
1067 proto_tree_add_item(tree, hf_usb_bInterfaceProtocol, tvb, offset, 1, TRUE);
1071 proto_tree_add_item(tree, hf_usb_iInterface, tvb, offset, 1, TRUE);
1075 proto_item_set_len(item, len);
1077 if (offset != old_offset + len) {
1078 /* unknown records */
1080 offset = old_offset + len;
1086 static const true_false_string tfs_endpoint_direction = {
1091 dissect_usb_endpoint_descriptor(packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1093 proto_item *item=NULL;
1094 proto_tree *tree=NULL;
1095 proto_item *endpoint_item=NULL;
1096 proto_tree *endpoint_tree=NULL;
1097 proto_item *ep_attrib_item=NULL;
1098 proto_tree *ep_attrib_tree=NULL;
1099 int old_offset=offset;
1104 item=proto_tree_add_text(parent_tree, tvb, offset, -1, "ENDPOINT DESCRIPTOR");
1105 tree=proto_item_add_subtree(item, ett_descriptor_device);
1109 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
1110 len = tvb_get_guint8(tvb, offset);
1113 /* bDescriptorType */
1114 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
1117 /* bEndpointAddress */
1119 endpoint_item=proto_tree_add_item(tree, hf_usb_bEndpointAddress, tvb, offset, 1, TRUE);
1120 endpoint_tree=proto_item_add_subtree(endpoint_item, ett_configuration_bEndpointAddress);
1122 endpoint=tvb_get_guint8(tvb, offset)&0x0f;
1123 proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_direction, tvb, offset, 1, TRUE);
1124 proto_item_append_text(endpoint_item, " %s", (tvb_get_guint8(tvb, offset)&0x80)?"IN":"OUT");
1125 proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_number, tvb, offset, 1, TRUE);
1126 proto_item_append_text(endpoint_item, " Endpoint:%d", endpoint);
1129 /* Together with class from the interface descriptor we know what kind
1130 * of class the device at endpoint is.
1131 * Make sure a conversation exists for this endpoint and attach a
1132 * usb_conv_into_t structure to it.
1134 * All endpoints for the same interface descriptor share the same
1135 * usb_conv_info structure.
1137 if((!pinfo->fd->flags.visited)&&usb_trans_info->interface_info){
1138 conversation_t *conversation;
1140 if(pinfo->destport==NO_ENDPOINT){
1141 static address tmp_addr;
1142 static usb_address_t usb_addr;
1144 /* Create a new address structure that points to the same device
1145 * but the new endpoint.
1147 usb_addr.device=((usb_address_t *)(pinfo->src.data))->device;
1148 usb_addr.endpoint=endpoint;
1149 SET_ADDRESS(&tmp_addr, AT_USB, USB_ADDR_LEN, (char *)&usb_addr);
1150 conversation=get_usb_conversation(pinfo, &tmp_addr, &pinfo->dst, endpoint, pinfo->destport);
1152 static address tmp_addr;
1153 static usb_address_t usb_addr;
1155 /* Create a new address structure that points to the same device
1156 * but the new endpoint.
1158 usb_addr.device=((usb_address_t *)(pinfo->dst.data))->device;
1159 usb_addr.endpoint=endpoint;
1160 SET_ADDRESS(&tmp_addr, AT_USB, USB_ADDR_LEN, (char *)&usb_addr);
1161 conversation=get_usb_conversation(pinfo, &pinfo->src, &tmp_addr, pinfo->srcport, endpoint);
1164 conversation_add_proto_data(conversation, proto_usb, usb_trans_info->interface_info);
1169 ep_attrib_item=proto_tree_add_item(tree, hf_usb_bmAttributes, tvb, offset, 1, TRUE);
1170 ep_attrib_tree=proto_item_add_subtree(ep_attrib_item, ett_endpoint_bmAttributes);
1172 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeTransfer, tvb, offset, 1, TRUE);
1173 /* isochronous only */
1174 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeSynchonisation, tvb, offset, 1, TRUE);
1175 /* isochronous only */
1176 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeBehaviour, tvb, offset, 1, TRUE);
1179 /* wMaxPacketSize */
1180 proto_tree_add_item(tree, hf_usb_wMaxPacketSize, tvb, offset, 2, TRUE);
1184 proto_tree_add_item(tree, hf_usb_bInterval, tvb, offset, 1, TRUE);
1188 proto_item_set_len(item, len);
1190 if (offset != old_offset + len) {
1191 /* unknown records */
1193 offset = old_offset + len;
1199 dissect_usb_unknown_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1201 proto_item *item=NULL;
1202 proto_tree *tree=NULL;
1203 int old_offset=offset;
1207 item=proto_tree_add_text(parent_tree, tvb, offset, -1, "UNKNOWN DESCRIPTOR");
1208 tree=proto_item_add_subtree(item, ett_descriptor_device);
1212 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
1213 bLength = tvb_get_guint8(tvb, offset);
1217 proto_item_set_len(item, offset-old_offset);
1220 item = proto_tree_add_text(parent_tree, tvb, offset - 1, 1,
1221 "Invalid bLength: %u", bLength);
1222 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR,
1223 "Invalid bLength: %u", bLength);
1228 /* bDescriptorType */
1229 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
1232 offset += bLength - 2;
1235 proto_item_set_len(item, offset-old_offset);
1242 static const true_false_string tfs_mustbeone = {
1243 "Must be 1 for USB 1.1 and higher",
1244 "FIXME: Is this a USB 1.0 device"
1246 static const true_false_string tfs_selfpowered = {
1247 "This device is SELF-POWERED",
1248 "This device is powered from the USB bus"
1250 static const true_false_string tfs_remotewakeup = {
1251 "This device supports REMOTE WAKEUP",
1252 "This device does NOT support remote wakeup"
1255 dissect_usb_configuration_descriptor(packet_info *pinfo _U_, proto_tree *parent_tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info)
1257 proto_item *item=NULL;
1258 proto_tree *tree=NULL;
1259 int old_offset=offset;
1261 proto_item *flags_item=NULL;
1262 proto_tree *flags_tree=NULL;
1264 proto_item *power_item=NULL;
1268 item=proto_tree_add_text(parent_tree, tvb, offset, -1, "CONFIGURATION DESCRIPTOR");
1269 tree=proto_item_add_subtree(item, ett_descriptor_device);
1273 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
1276 /* bDescriptorType */
1277 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
1281 proto_tree_add_item(tree, hf_usb_wTotalLength, tvb, offset, 2, TRUE);
1282 len=tvb_get_letohs(tvb, offset);
1285 /* bNumInterfaces */
1286 proto_tree_add_item(tree, hf_usb_bNumInterfaces, tvb, offset, 1, TRUE);
1289 /* bConfigurationValue */
1290 proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, TRUE);
1293 /* iConfiguration */
1294 proto_tree_add_item(tree, hf_usb_iConfiguration, tvb, offset, 1, TRUE);
1299 flags_item=proto_tree_add_item(tree, hf_usb_configuration_bmAttributes, tvb, offset, 1, TRUE);
1300 flags_tree=proto_item_add_subtree(flags_item, ett_configuration_bmAttributes);
1302 flags=tvb_get_guint8(tvb, offset);
1303 proto_tree_add_item(flags_tree, hf_usb_configuration_legacy10buspowered, tvb, offset, 1, TRUE);
1304 proto_tree_add_item(flags_tree, hf_usb_configuration_selfpowered, tvb, offset, 1, TRUE);
1305 proto_item_append_text(flags_item, " %sSELF-POWERED", (flags&0x40)?"":"NOT ");
1307 proto_tree_add_item(flags_tree, hf_usb_configuration_remotewakeup, tvb, offset, 1, TRUE);
1308 proto_item_append_text(flags_item, " %sREMOTE-WAKEUP", (flags&0x20)?"":"NO ");
1313 power_item=proto_tree_add_item(tree, hf_usb_bMaxPower, tvb, offset, 1, TRUE);
1314 power=tvb_get_guint8(tvb, offset);
1315 proto_item_append_text(power_item, " (%dmA)", power*2);
1318 /* initialize interface_info to NULL */
1319 usb_trans_info->interface_info=NULL;
1321 /* decode any additional interface and endpoint descriptors */
1322 while(len>(old_offset-offset)){
1325 if(tvb_length_remaining(tvb, offset)<2){
1328 next_type=tvb_get_guint8(tvb, offset+1);
1330 case USB_DT_INTERFACE:
1331 offset=dissect_usb_interface_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1333 case USB_DT_ENDPOINT:
1334 offset=dissect_usb_endpoint_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1337 offset=dissect_usb_unknown_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1339 /* was: return offset; */
1344 proto_item_set_len(item, offset-old_offset);
1352 dissect_usb_setup_get_descriptor_request(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info _U_)
1354 /* descriptor index */
1355 proto_tree_add_item(tree, hf_usb_descriptor_index, tvb, offset, 1, TRUE);
1356 usb_trans_info->u.get_descriptor.index=tvb_get_guint8(tvb, offset);
1359 /* descriptor type */
1360 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
1361 usb_trans_info->u.get_descriptor.type=tvb_get_guint8(tvb, offset);
1363 if (check_col(pinfo->cinfo, COL_INFO)) {
1364 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
1365 val_to_str(usb_trans_info->u.get_descriptor.type, descriptor_type_vals, "Unknown type %u"));
1369 proto_tree_add_item(tree, hf_usb_language_id, tvb, offset, 2, TRUE);
1373 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1380 dissect_usb_setup_get_descriptor_response(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info)
1382 proto_item *item=NULL;
1385 if (check_col(pinfo->cinfo, COL_INFO)) {
1386 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
1387 val_to_str(usb_trans_info->u.get_descriptor.type, descriptor_type_vals, "Unknown type %u"));
1389 switch(usb_trans_info->u.get_descriptor.type){
1391 offset=dissect_usb_device_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1394 offset=dissect_usb_configuration_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1397 offset=dissect_usb_string_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1399 case USB_DT_INTERFACE:
1400 offset=dissect_usb_interface_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1402 case USB_DT_ENDPOINT:
1403 offset=dissect_usb_endpoint_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1405 case USB_DT_DEVICE_QUALIFIER:
1406 offset=dissect_usb_device_qualifier_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1409 if (usb_conv_info->interfaceClass == IF_CLASS_HID) {
1410 offset=dissect_usb_hid_get_report_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1413 /* else fall through as default/unknown */
1415 /* XXX dissect the descriptor coming back from the device */
1416 item=proto_tree_add_text(tree, tvb, offset, -1, "GET DESCRIPTOR data (unknown descriptor type)");
1417 tree=proto_item_add_subtree(item, ett_descriptor_device);
1418 tvb_memcpy(tvb, (guint8 *)&data_len, offset, 4);
1419 proto_tree_add_uint(tree, hf_usb_data, tvb, offset, 4, data_len);
1429 * These dissectors are used to dissect the setup part and the data
1430 * for URB_CONTROL_INPUT / GET INTERFACE
1436 dissect_usb_setup_get_interface_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1439 proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, TRUE);
1443 proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, TRUE);
1447 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1454 dissect_usb_setup_get_interface_response(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1456 /* alternate setting */
1457 proto_tree_add_item(tree, hf_usb_bAlternateSetting, tvb, offset, 1, TRUE);
1465 * These dissectors are used to dissect the setup part and the data
1466 * for URB_CONTROL_INPUT / GET STATUS
1472 dissect_usb_setup_get_status_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1475 proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, TRUE);
1478 /* zero/interface/endpoint */
1479 /* XXX - check based on request type */
1480 proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, TRUE);
1484 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1491 dissect_usb_setup_get_status_response(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1494 /* XXX - show bits */
1495 proto_tree_add_item(tree, hf_usb_wStatus, tvb, offset, 2, TRUE);
1503 * These dissectors are used to dissect the setup part and the data
1504 * for URB_CONTROL_INPUT / SET ADDRESS
1510 dissect_usb_setup_set_address_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1512 /* device address */
1513 proto_tree_add_item(tree, hf_usb_device_address, tvb, offset, 2, TRUE);
1517 proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, TRUE);
1521 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1528 dissect_usb_setup_set_address_response(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1535 * These dissectors are used to dissect the setup part and the data
1536 * for URB_CONTROL_INPUT / SET CONFIGURATION
1542 dissect_usb_setup_set_configuration_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1544 /* configuration value */
1545 proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, TRUE);
1549 proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, TRUE);
1553 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1560 dissect_usb_setup_set_configuration_response(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1567 * These dissectors are used to dissect the setup part and the data
1568 * for URB_CONTROL_INPUT / SET FEATURE
1574 dissect_usb_setup_set_feature_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1576 /* feature selector */
1577 proto_tree_add_item(tree, hf_usb_wFeatureSelector, tvb, offset, 2, TRUE);
1580 /* zero/interface/endpoint or test selector */
1581 /* XXX - check based on request type */
1582 proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, TRUE);
1586 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1593 dissect_usb_setup_set_feature_response(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1600 * These dissectors are used to dissect the setup part and the data
1601 * for URB_CONTROL_INPUT / SET INTERFACE
1607 dissect_usb_setup_set_interface_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1609 /* alternate setting */
1610 proto_tree_add_item(tree, hf_usb_bAlternateSetting, tvb, offset, 1, TRUE);
1614 proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, TRUE);
1618 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1625 dissect_usb_setup_set_interface_response(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1632 * These dissectors are used to dissect the setup part and the data
1633 * for URB_CONTROL_INPUT / SYNCH FRAME
1639 dissect_usb_setup_synch_frame_request(packet_info *pinfo _U_, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1642 proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, TRUE);
1647 proto_tree_add_item(tree, hf_usb_wInterface, tvb, offset, 2, TRUE);
1651 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1658 dissect_usb_setup_synch_frame_response(packet_info *pinfo _U_, proto_tree *tree _U_, tvbuff_t *tvb _U_, int offset, usb_trans_info_t *usb_trans_info _U_, usb_conv_info_t *usb_conv_info _U_)
1661 proto_tree_add_item(tree, hf_usb_wFrameNumber, tvb, offset, 2, TRUE);
1668 typedef int (*usb_setup_dissector)(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info);
1670 typedef struct _usb_setup_dissector_table_t {
1672 usb_setup_dissector dissector;
1673 } usb_setup_dissector_table_t;
1674 #define USB_SETUP_GET_STATUS 0
1675 #define USB_SETUP_CLEAR_FEATURE 1
1676 #define USB_SETUP_SET_FEATURE 2
1677 #define USB_SETUP_SET_ADDRESS 5
1678 #define USB_SETUP_GET_DESCRIPTOR 6
1679 #define USB_SETUP_SET_DESCRIPTOR 7
1680 #define USB_SETUP_GET_CONFIGURATION 8
1681 #define USB_SETUP_SET_CONFIGURATION 9
1682 #define USB_SETUP_GET_INTERFACE 10
1683 #define USB_SETUP_SET_INTERFACE 11
1684 #define USB_SETUP_SYNCH_FRAME 12
1686 static const usb_setup_dissector_table_t setup_request_dissectors[] = {
1687 {USB_SETUP_GET_STATUS, dissect_usb_setup_get_status_request},
1688 {USB_SETUP_CLEAR_FEATURE, dissect_usb_setup_clear_feature_request},
1689 {USB_SETUP_SET_FEATURE, dissect_usb_setup_set_feature_request},
1690 {USB_SETUP_SET_ADDRESS, dissect_usb_setup_set_address_request},
1691 {USB_SETUP_GET_DESCRIPTOR, dissect_usb_setup_get_descriptor_request},
1692 {USB_SETUP_SET_CONFIGURATION, dissect_usb_setup_set_configuration_request},
1693 {USB_SETUP_GET_INTERFACE, dissect_usb_setup_get_interface_request},
1694 {USB_SETUP_SET_INTERFACE, dissect_usb_setup_set_interface_request},
1695 {USB_SETUP_SYNCH_FRAME, dissect_usb_setup_synch_frame_request},
1699 static const usb_setup_dissector_table_t setup_response_dissectors[] = {
1700 {USB_SETUP_GET_STATUS, dissect_usb_setup_get_status_response},
1701 {USB_SETUP_CLEAR_FEATURE, dissect_usb_setup_clear_feature_response},
1702 {USB_SETUP_SET_FEATURE, dissect_usb_setup_set_feature_response},
1703 {USB_SETUP_SET_ADDRESS, dissect_usb_setup_set_address_response},
1704 {USB_SETUP_GET_DESCRIPTOR, dissect_usb_setup_get_descriptor_response},
1705 {USB_SETUP_GET_CONFIGURATION, dissect_usb_setup_get_configuration_response},
1706 {USB_SETUP_SET_CONFIGURATION, dissect_usb_setup_set_configuration_response},
1707 {USB_SETUP_GET_INTERFACE, dissect_usb_setup_get_interface_response},
1708 {USB_SETUP_SET_INTERFACE, dissect_usb_setup_set_interface_response},
1709 {USB_SETUP_SYNCH_FRAME, dissect_usb_setup_synch_frame_response},
1713 /* bRequest values but only when bmRequestType.type == 0 (Device) */
1714 static const value_string setup_request_names_vals[] = {
1715 {USB_SETUP_GET_STATUS, "GET STATUS"},
1716 {USB_SETUP_CLEAR_FEATURE, "CLEAR FEATURE"},
1717 {USB_SETUP_SET_FEATURE, "SET FEATURE"},
1718 {USB_SETUP_SET_ADDRESS, "SET ADDRESS"},
1719 {USB_SETUP_GET_DESCRIPTOR, "GET DESCRIPTOR"},
1720 {USB_SETUP_SET_DESCRIPTOR, "SET DESCRIPTOR"},
1721 {USB_SETUP_GET_CONFIGURATION, "GET CONFIGURATION"},
1722 {USB_SETUP_SET_CONFIGURATION, "SET CONFIGURATION"},
1723 {USB_SETUP_GET_INTERFACE, "GET INTERFACE"},
1724 {USB_SETUP_SET_INTERFACE, "SET INTERFACE"},
1725 {USB_SETUP_SYNCH_FRAME, "SYNCH FRAME"},
1730 static const true_false_string tfs_bmrequesttype_direction = {
1735 static const value_string bmrequesttype_type_vals[] = {
1736 {RQT_SETUP_TYPE_STANDARD, "Standard"},
1737 {RQT_SETUP_TYPE_CLASS, "Class"},
1738 {RQT_SETUP_TYPE_VENDOR, "Vendor"},
1742 static const value_string bmrequesttype_recipient_vals[] = {
1743 {RQT_SETUP_RECIPIENT_DEVICE, "Device" },
1744 {RQT_SETUP_RECIPIENT_INTERFACE, "Interface" },
1745 {RQT_SETUP_RECIPIENT_INTERFACE, "Endpoint" },
1746 {RQT_SETUP_RECIPIENT_INTERFACE, "Other" },
1751 dissect_usb_bmrequesttype(proto_tree *parent_tree, tvbuff_t *tvb, int offset,
1754 proto_item *item=NULL;
1755 proto_tree *tree=NULL;
1758 item=proto_tree_add_item(parent_tree, hf_usb_bmRequestType, tvb, offset, 1, TRUE);
1759 tree = proto_item_add_subtree(item, ett_usb_setup_bmrequesttype);
1762 *type = USB_TYPE(tvb_get_guint8(tvb, offset));
1763 proto_tree_add_item(tree, hf_usb_bmRequestType_direction, tvb, offset, 1, TRUE);
1764 proto_tree_add_item(tree, hf_usb_bmRequestType_type, tvb, offset, 1, TRUE);
1765 proto_tree_add_item(tree, hf_usb_bmRequestType_recipient, tvb, offset, 1, TRUE);
1770 /* Adds the Linux USB pseudo header fields to the tree.
1771 * NOTE: The multi-byte fields in this header, and the pseudo-header
1772 * extension, are in host-endian format so we can't
1773 * use proto_tree_add_item() nor the tvb_get_xyz() routines and is
1774 * the reason for the tvb_memcpy() and proto_tree_add_uint[64]()
1777 dissect_linux_usb_pseudo_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1779 guint8 transfer_type;
1780 guint8 endpoint_number;
1781 guint8 transfer_type_and_direction;
1782 const gchar* val_str;
1788 tvb_memcpy(tvb, (guint8 *)&val64, 0, 8);
1789 proto_tree_add_uint64(tree, hf_usb_urb_id, tvb, 0, 8, val64);
1791 /* show the event type of this URB as string and as a character */
1792 type = tvb_get_guint8(tvb, 8);
1793 val_str = val_to_str(type, usb_urb_type_vals, "Unknown %d");
1794 proto_tree_add_string_format_value(tree, hf_usb_urb_type, tvb, 8, 1,
1795 &type, "%s ('%c')", val_str, isprint(type) ? type : '.');
1797 proto_tree_add_item(tree, hf_usb_transfer_type, tvb, 9, 1, FALSE);
1799 if (check_col(pinfo->cinfo, COL_INFO)) {
1800 transfer_type = tvb_get_guint8(tvb, 9);
1801 endpoint_number = tvb_get_guint8(tvb, 10);
1802 transfer_type_and_direction = (transfer_type & 0x7F) | (endpoint_number & 0x80);
1803 col_append_str(pinfo->cinfo, COL_INFO,
1804 val_to_str(transfer_type_and_direction, usb_transfer_type_and_direction_vals, "Unknown type %x"));
1807 proto_tree_add_bitmask(tree, tvb, 10, hf_usb_endpoint_number, ett_usb_endpoint, usb_endpoint_fields, FALSE);
1808 proto_tree_add_item(tree, hf_usb_device_address, tvb, 11, 1, FALSE);
1810 tvb_memcpy(tvb, (guint8 *)&val16, 12, 2);
1811 proto_tree_add_uint(tree, hf_usb_bus_id, tvb, 12, 2, val16);
1813 /* Right after the pseudo header we always have
1814 * sizeof(struct usb_device_setup_hdr) bytes. The content of these
1815 * bytes only have meaning in case setup_flag == 0.
1817 flag = tvb_get_guint8(tvb, 14);
1819 proto_tree_add_string(tree, hf_usb_setup_flag, tvb, 14, 1, "relevant (0)");
1821 proto_tree_add_string_format_value(tree, hf_usb_setup_flag, tvb,
1822 14, 1, &flag, "not relevant ('%c')", isprint(flag) ? flag: '.');
1825 flag = tvb_get_guint8(tvb, 15);
1827 proto_tree_add_string(tree, hf_usb_data_flag, tvb, 15, 1, "present (0)");
1829 proto_tree_add_string_format_value(tree, hf_usb_data_flag, tvb,
1830 15, 1, &flag, "not present ('%c')", isprint(flag) ? flag : '.');
1833 tvb_memcpy(tvb, (guint8 *)&val64, 16, 8);
1834 proto_tree_add_uint64(tree, hf_usb_urb_ts_sec, tvb, 16, 8, val64);
1836 tvb_memcpy(tvb, (guint8 *)&val32, 24, 4);
1837 proto_tree_add_uint(tree, hf_usb_urb_ts_usec, tvb, 24, 4, val32);
1839 tvb_memcpy(tvb, (guint8 *)&val32, 28, 4);
1840 proto_tree_add_int(tree, hf_usb_urb_status, tvb, 28, 4, val32);
1842 tvb_memcpy(tvb, (guint8 *)&val32, 32, 4);
1843 proto_tree_add_uint(tree, hf_usb_urb_len, tvb, 32, 4, val32);
1845 tvb_memcpy(tvb, (guint8 *)&val32, 36, 4);
1846 proto_tree_add_uint(tree, hf_usb_data_len, tvb, 36, 4, val32);
1850 * XXX - put these into the protocol tree as appropriate.
1853 dissect_linux_usb_pseudo_header_ext(tvbuff_t *tvb, int offset,
1854 packet_info *pinfo _U_,
1855 proto_tree *tree _U_)
1859 offset += 4; /* interval */
1860 offset += 4; /* start_frame */
1861 offset += 4; /* copy of URB's transfer flags */
1863 tvb_memcpy(tvb, (guint8 *)&ndesc, offset, 4);
1867 * Isochronous descriptors. Each one is 16 bytes long.
1875 dissect_linux_usb_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent,
1876 gboolean header_len_64_bytes)
1878 unsigned int offset = 0;
1881 proto_tree *tree = NULL;
1882 guint32 src_device, dst_device, tmp_addr;
1883 static usb_address_t src_addr, dst_addr; /* has to be static due to SET_ADDRESS */
1884 guint32 src_endpoint, dst_endpoint;
1885 gboolean is_request=FALSE;
1886 usb_conv_info_t *usb_conv_info=NULL;
1887 usb_trans_info_t *usb_trans_info=NULL;
1888 conversation_t *conversation;
1889 usb_tap_data_t *tap_data=NULL;
1891 col_set_str(pinfo->cinfo, COL_PROTOCOL, "USB");
1895 proto_item *ti = NULL;
1896 ti = proto_tree_add_protocol_format(parent, proto_usb, tvb, 0,
1897 header_len_64_bytes ? 64 : 48, "USB URB");
1898 tree = proto_item_add_subtree(ti, usb_hdr);
1901 dissect_linux_usb_pseudo_header(tvb, pinfo, tree);
1902 is_request = (tvb_get_guint8(tvb, 8) == URB_SUBMIT) ? TRUE : FALSE;
1903 type = tvb_get_guint8(tvb, 9);
1904 endpoint = tvb_get_guint8(tvb, 10) & (~URB_TRANSFER_IN);
1905 tmp_addr = tvb_get_guint8(tvb, 11);
1906 setup_flag = tvb_get_guint8(tvb, 14);
1907 offset += 40; /* skip first part of the pseudo-header */
1909 /* Set up addresses and ports. */
1911 src_addr.device = src_device = 0xffffffff;
1912 src_addr.endpoint = src_endpoint = NO_ENDPOINT;
1913 dst_addr.device = dst_device = htolel(tmp_addr);
1914 dst_addr.endpoint = dst_endpoint = htolel(endpoint);
1916 src_addr.device = src_device = htolel(tmp_addr);
1917 src_addr.endpoint = src_endpoint = htolel(endpoint);
1918 dst_addr.device = dst_device = 0xffffffff;
1919 dst_addr.endpoint = dst_endpoint = NO_ENDPOINT;
1922 SET_ADDRESS(&pinfo->net_src, AT_USB, USB_ADDR_LEN, (char *)&src_addr);
1923 SET_ADDRESS(&pinfo->src, AT_USB, USB_ADDR_LEN, (char *)&src_addr);
1924 SET_ADDRESS(&pinfo->net_dst, AT_USB, USB_ADDR_LEN, (char *)&dst_addr);
1925 SET_ADDRESS(&pinfo->dst, AT_USB, USB_ADDR_LEN, (char *)&dst_addr);
1926 pinfo->ptype=PT_USB;
1927 pinfo->srcport=src_endpoint;
1928 pinfo->destport=dst_endpoint;
1930 conversation=get_usb_conversation(pinfo, &pinfo->src, &pinfo->dst, pinfo->srcport, pinfo->destport);
1932 usb_conv_info=get_usb_conv_info(conversation);
1933 pinfo->usb_conv_info=usb_conv_info;
1936 /* request/response matching so we can keep track of transaction specific
1940 /* this is a request */
1941 usb_trans_info=se_tree_lookup32(usb_conv_info->transactions, pinfo->fd->num);
1942 if(!usb_trans_info){
1943 usb_trans_info=se_alloc0(sizeof(usb_trans_info_t));
1944 usb_trans_info->request_in=pinfo->fd->num;
1945 usb_trans_info->req_time=pinfo->fd->abs_ts;
1946 se_tree_insert32(usb_conv_info->transactions, pinfo->fd->num, usb_trans_info);
1948 usb_conv_info->usb_trans_info=usb_trans_info;
1950 if(usb_trans_info && usb_trans_info->response_in){
1953 ti=proto_tree_add_uint(tree, hf_usb_response_in, tvb, 0, 0, usb_trans_info->response_in);
1954 PROTO_ITEM_SET_GENERATED(ti);
1957 /* this is a response */
1958 if(pinfo->fd->flags.visited){
1959 usb_trans_info=se_tree_lookup32(usb_conv_info->transactions, pinfo->fd->num);
1961 usb_trans_info=se_tree_lookup32_le(usb_conv_info->transactions, pinfo->fd->num);
1963 usb_trans_info->response_in=pinfo->fd->num;
1964 se_tree_insert32(usb_conv_info->transactions, pinfo->fd->num, usb_trans_info);
1967 usb_conv_info->usb_trans_info=usb_trans_info;
1969 if(usb_trans_info && usb_trans_info->request_in){
1973 ti=proto_tree_add_uint(tree, hf_usb_request_in, tvb, 0, 0, usb_trans_info->request_in);
1974 PROTO_ITEM_SET_GENERATED(ti);
1976 t = pinfo->fd->abs_ts;
1977 nstime_delta(&deltat, &t, &usb_trans_info->req_time);
1978 ti=proto_tree_add_time(tree, hf_usb_time, tvb, 0, 0, &deltat);
1979 PROTO_ITEM_SET_GENERATED(ti);
1983 tap_data=ep_alloc(sizeof(usb_tap_data_t));
1984 tap_data->urb_type=tvb_get_guint8(tvb, 8);
1985 tap_data->transfer_type=(guint8)type;
1986 tap_data->conv_info=usb_conv_info;
1987 tap_data->trans_info=usb_trans_info;
1988 tap_queue_packet(usb_tap, pinfo, tap_data);
1995 item=proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, 0, 0, usb_conv_info->interfaceClass);
1996 PROTO_ITEM_SET_GENERATED(item);
1998 /* Skip setup/isochronous header - it's not applicable */
2002 * If this has a 64-byte header, process the extra 16 bytes of
2003 * pseudo-header information.
2005 if (header_len_64_bytes)
2006 offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
2008 if(tvb_reported_length_remaining(tvb, offset)){
2011 pinfo->usb_conv_info=usb_conv_info;
2012 next_tvb=tvb_new_subset_remaining(tvb, offset);
2013 if(dissector_try_port(usb_bulk_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, parent)){
2021 const usb_setup_dissector_table_t *tmp;
2022 usb_setup_dissector dissector;
2023 proto_item *ti = NULL;
2024 proto_tree *setup_tree = NULL;
2027 ti=proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, offset, 0, usb_conv_info->interfaceClass);
2028 PROTO_ITEM_SET_GENERATED(ti);
2031 if (setup_flag == 0) {
2034 /* this is a request */
2036 /* Dissect the setup header - it's applicable */
2038 ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset, 8, "URB setup");
2039 setup_tree = proto_item_add_subtree(ti, usb_setup_hdr);
2040 usb_trans_info->requesttype=tvb_get_guint8(tvb, offset);
2041 offset=dissect_usb_bmrequesttype(setup_tree, tvb, offset, &type_2);
2044 /* read the request code and spawn off to a class specific
2045 * dissector if found
2047 usb_trans_info->request=tvb_get_guint8(tvb, offset);
2051 case RQT_SETUP_TYPE_STANDARD:
2053 * This is a standard request which is managed by this
2056 proto_tree_add_item(setup_tree, hf_usb_request, tvb, offset, 1, TRUE);
2059 if (check_col(pinfo->cinfo, COL_INFO)) {
2060 col_add_fstr(pinfo->cinfo, COL_INFO, "%s Request",
2061 val_to_str(usb_trans_info->request, setup_request_names_vals, "Unknown type %x"));
2065 for(tmp=setup_request_dissectors;tmp->dissector;tmp++){
2066 if(tmp->request==usb_trans_info->request){
2067 dissector=tmp->dissector;
2073 offset=dissector(pinfo, setup_tree, tvb, offset, usb_trans_info, usb_conv_info);
2075 proto_tree_add_item(setup_tree, hf_usb_value, tvb, offset, 2, TRUE);
2077 proto_tree_add_item(setup_tree, hf_usb_index, tvb, offset, 2, TRUE);
2079 proto_tree_add_item(setup_tree, hf_usb_length, tvb, offset, 2, TRUE);
2084 case RQT_SETUP_TYPE_CLASS:
2085 /* Try to find a class specific dissector */
2086 next_tvb=tvb_new_subset_remaining(tvb, offset);
2087 if(dissector_try_port(usb_control_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, tree)){
2090 /* Else no class dissector, just display generic fields */
2091 proto_tree_add_item(setup_tree, hf_usb_request_unknown_class, tvb, offset, 1, TRUE);
2093 proto_tree_add_item(setup_tree, hf_usb_value, tvb, offset, 2, TRUE);
2095 proto_tree_add_item(setup_tree, hf_usb_index, tvb, offset, 2, TRUE);
2097 proto_tree_add_item(setup_tree, hf_usb_length, tvb, offset, 2, TRUE);
2102 proto_tree_add_item(setup_tree, hf_usb_request_unknown_class, tvb, offset, 1, TRUE);
2104 proto_tree_add_item(setup_tree, hf_usb_value, tvb, offset, 2, TRUE);
2106 proto_tree_add_item(setup_tree, hf_usb_index, tvb, offset, 2, TRUE);
2108 proto_tree_add_item(setup_tree, hf_usb_length, tvb, offset, 2, TRUE);
2112 /* Skip setup/isochronous header - it's not applicable */
2117 * If this has a 64-byte header, process the extra 16 bytes of
2118 * pseudo-header information.
2120 if (header_len_64_bytes)
2121 offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
2125 /* this is a response */
2127 /* Skip setup header - it's never applicable for responses */
2131 * If this has a 64-byte header, process the extra 16 bytes of
2132 * pseudo-header information.
2134 if (header_len_64_bytes)
2135 offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
2138 /* Try to find a class specific dissector */
2139 next_tvb=tvb_new_subset_remaining(tvb, offset);
2140 if(dissector_try_port(usb_control_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, tree)){
2144 type_2 = USB_TYPE(usb_trans_info->requesttype);
2147 case RQT_SETUP_TYPE_STANDARD:
2149 * This is a standard response which is managed by this
2152 if (check_col(pinfo->cinfo, COL_INFO)) {
2153 col_add_fstr(pinfo->cinfo, COL_INFO, "%s Response",
2154 val_to_str(usb_conv_info->usb_trans_info->request, setup_request_names_vals, "Unknown type %x"));
2158 for(tmp=setup_response_dissectors;tmp->dissector;tmp++){
2159 if(tmp->request==usb_conv_info->usb_trans_info->request){
2160 dissector=tmp->dissector;
2166 offset = dissector(pinfo, tree, tvb, offset, usb_conv_info->usb_trans_info, usb_conv_info);
2168 if (tvb_reported_length_remaining(tvb, offset) != 0) {
2169 proto_tree_add_text(tree, tvb, offset, -1, "CONTROL response data");
2170 offset += tvb_length_remaining(tvb, offset);
2175 if (tvb_reported_length_remaining(tvb, offset) != 0) {
2176 proto_tree_add_text(tree, tvb, offset, -1, "CONTROL response data");
2177 offset += tvb_length_remaining(tvb, offset);
2182 /* no matching request available */
2183 if (tvb_reported_length_remaining(tvb, offset) != 0) {
2184 proto_tree_add_text(tree, tvb, offset, -1, "CONTROL response data");
2185 offset += tvb_length_remaining(tvb, offset);
2191 case URB_ISOCHRONOUS:
2193 /* All fields which belong to Linux usbmon headers are in host-endian
2194 * byte order. The fields coming from the USB communication are in little
2195 * endian format (see usb_20.pdf, chapter 8.1 Byte/Bit ordering).
2197 * When a capture file is transfered to a host with different endianness
2198 * than packet was captured then the necessary swapping happens in
2199 * wiretap/pcap-common.c, pcap_process_linux_usb_pseudoheader().
2201 guint32 iso_numdesc = 0;
2203 if (setup_flag == 0) {
2204 proto_item *ti = NULL;
2205 proto_tree *setup_tree = NULL;
2208 /* Dissect the setup header - it's applicable */
2210 ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset, 8, "URB setup");
2211 setup_tree = proto_item_add_subtree(ti, usb_setup_hdr);
2213 offset = dissect_usb_bmrequesttype(setup_tree, tvb, offset, &type_2);
2214 proto_tree_add_item(setup_tree, hf_usb_request, tvb, offset, 1, TRUE);
2216 proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, TRUE);
2218 proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, TRUE);
2220 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
2224 /* Process ISO related fields (usbmon_packet.iso). The fields are
2225 * in host endian byte order so use tvb_memcopy() and
2226 * proto_tree_add_uint() pair.
2230 tvb_memcpy(tvb, (guint8 *)&val32, offset, 4);
2231 proto_tree_add_uint(tree, hf_usb_iso_error_count, tvb, offset, 4, val32);
2234 tvb_memcpy(tvb, (guint8 *)&iso_numdesc, offset, 4);
2235 proto_tree_add_uint(tree, hf_usb_iso_numdesc, tvb, offset, 4, iso_numdesc);
2240 * If this has a 64-byte header, process the extra 16 bytes of
2241 * pseudo-header information.
2243 if (header_len_64_bytes) {
2246 offset += 4; /* interval */
2247 offset += 4; /* start_frame */
2248 offset += 4; /* copy of URB's transfer flags */
2250 tvb_memcpy(tvb, (guint8 *)&ndesc, offset, 4);
2255 if (setup_flag != 0) {
2256 proto_tree *urb_tree = NULL;
2258 unsigned int data_base;
2264 data_base = offset + iso_numdesc * 16;
2266 for (i = 0; i != iso_numdesc; i++) {
2268 proto_item *ti = NULL;
2269 ti = proto_tree_add_protocol_format(urb_tree, proto_usb, tvb, offset,
2270 16, "USB isodesc %u", i);
2271 tree = proto_item_add_subtree(ti, usb_isodesc);
2274 /* Add ISO descriptor fields which are stored in host
2275 * endian byte order so use tvb_memcopy() and
2276 * proto_tree_add_uint()/proto_tree_add_int() pair.
2278 tvb_memcpy(tvb, (guint8 *)&iso_status, offset, 4);
2279 proto_tree_add_int(tree, hf_usb_iso_status, tvb, offset, 4, iso_status);
2282 tvb_memcpy(tvb, (guint8 *)&iso_off, offset, 4);
2283 proto_tree_add_uint(tree, hf_usb_iso_off, tvb, offset, 4, iso_off);
2286 tvb_memcpy(tvb, (guint8 *)&iso_len, offset, 4);
2287 proto_tree_add_uint(tree, hf_usb_iso_len, tvb, offset, 4, iso_len);
2290 /* When the ISO status is OK and there is ISO data and this ISO data is
2291 * fully captured then show this data.
2293 if (!iso_status && iso_len && data_base + iso_off + iso_len <= tvb_length(tvb))
2294 proto_tree_add_item(tree, hf_usb_iso_data, tvb, data_base + iso_off, iso_len, TRUE);
2296 tvb_memcpy(tvb, (guint8 *)&iso_pad, offset, 4);
2297 proto_tree_add_uint(tree, hf_usb_iso_pad, tvb, offset, 4, iso_pad);
2308 if (setup_flag == 0) {
2309 proto_item *ti = NULL;
2310 proto_tree *setup_tree = NULL;
2313 /* Dissect the setup header - it's applicable */
2315 ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset, 8, "URB setup");
2316 setup_tree = proto_item_add_subtree(ti, usb_setup_hdr);
2318 offset=dissect_usb_bmrequesttype(setup_tree, tvb, offset, &type_2);
2319 proto_tree_add_item(setup_tree, hf_usb_request, tvb, offset, 1, TRUE);
2321 proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, TRUE);
2323 proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, TRUE);
2325 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
2328 /* Skip setup/isochronous header - it's not applicable */
2333 * If this has a 64-byte header, process the extra 16 bytes of
2334 * pseudo-header information.
2336 if (header_len_64_bytes)
2337 offset = dissect_linux_usb_pseudo_header_ext(tvb, offset, pinfo, tree);
2342 if (tvb_reported_length_remaining(tvb, offset) != 0) {
2343 /* There is leftover capture data to add (padding?) */
2344 proto_tree_add_item(tree, hf_usb_capdata, tvb, offset, -1, FALSE);
2349 dissect_linux_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent)
2351 dissect_linux_usb_common(tvb, pinfo, parent, FALSE);
2355 dissect_linux_usb_mmapped(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent)
2357 dissect_linux_usb_common(tvb, pinfo, parent, TRUE);
2361 proto_register_usb(void)
2363 static hf_register_info hf[] = {
2365 /* USB packet pseudoheader members */
2367 { "URB id", "usb.urb_id", FT_UINT64, BASE_HEX,
2372 { "URB type", "usb.urb_type", FT_STRING, BASE_NONE,
2376 { &hf_usb_transfer_type,
2377 { "URB transfer type", "usb.transfer_type", FT_UINT8, BASE_HEX,
2378 VALS(usb_transfer_type_vals), 0x0,
2381 { &hf_usb_endpoint_number,
2382 { "Endpoint", "usb.endpoint_number", FT_UINT8, BASE_HEX, NULL, 0x0,
2383 "USB endpoint number", HFILL }},
2385 { &hf_usb_endpoint_direction,
2386 { "Direction", "usb.endpoint_number.direction", FT_UINT8, BASE_DEC,
2387 VALS(usb_endpoint_direction_vals), 0x80,
2388 "USB endpoint direction", HFILL }},
2390 { &hf_usb_endpoint_number_value,
2391 { "Endpoint value", "usb.endpoint_number.endpoint", FT_UINT8, BASE_DEC,
2393 "USB endpoint value", HFILL }},
2395 { &hf_usb_device_address,
2396 { "Device", "usb.device_address", FT_UINT8, BASE_DEC, NULL, 0x0,
2397 "USB device address", HFILL }},
2400 { "URB bus id", "usb.bus_id", FT_UINT16, BASE_DEC,
2404 { &hf_usb_setup_flag,
2405 { "Device setup request", "usb.setup_flag", FT_STRING, BASE_NONE,
2407 "USB device setup request is relevant (0) or not", HFILL }},
2409 { &hf_usb_data_flag,
2410 { "Data", "usb.data_flag", FT_STRING, BASE_NONE,
2412 "USB data is present (0) or not", HFILL }},
2414 { &hf_usb_urb_ts_sec,
2415 { "URB sec", "usb.urb_ts_sec", FT_UINT64, BASE_DEC,
2419 { &hf_usb_urb_ts_usec,
2420 { "URB usec", "usb.urb_ts_usec", FT_UINT32, BASE_DEC,
2424 { &hf_usb_urb_status,
2425 { "URB status", "usb.urb_status", FT_INT32, BASE_DEC,
2426 VALS(usb_urb_status_vals), 0x0,
2430 { "URB length [bytes]", "usb.urb_len", FT_UINT32, BASE_DEC, NULL, 0x0,
2431 "URB length in bytes", HFILL }},
2434 { "Data length [bytes]", "usb.data_len", FT_UINT32, BASE_DEC, NULL, 0x0,
2435 "URB data length in bytes", HFILL }},
2437 /* Generated values */
2438 { &hf_usb_src_endpoint_number,
2439 { "Src Endpoint", "usb.src.endpoint", FT_UINT8, BASE_HEX, NULL, 0x0,
2440 "Source USB endpoint number", HFILL }},
2442 { &hf_usb_dst_endpoint_number,
2443 { "Dst Endpoint", "usb.dst.endpoint", FT_UINT8, BASE_HEX, NULL, 0x0,
2444 "Destination USB endpoint number", HFILL }},
2446 /* Fields from usb20.pdf, Table 9-2 'Format of Setup Data' */
2447 { &hf_usb_bmRequestType,
2448 { "bmRequestType", "usb.bmRequestType", FT_UINT8, BASE_HEX, NULL, 0x0,
2452 { "bRequest", "usb.setup.bRequest", FT_UINT8, BASE_DEC, VALS(setup_request_names_vals), 0x0,
2455 /* Same as hf_usb_request but no descriptive text */
2456 { &hf_usb_request_unknown_class,
2457 { "bRequest", "usb.setup.bRequest", FT_UINT8, BASE_DEC, NULL, 0x0,
2461 { "wValue", "usb.setup.wValue", FT_UINT16, BASE_HEX, NULL, 0x0,
2465 { "wIndex", "usb.setup.wIndex", FT_UINT16, BASE_DEC, NULL, 0x0,
2469 { "wLength", "usb.setup.wLength", FT_UINT16, BASE_DEC, NULL, 0x0,
2472 { &hf_usb_wFeatureSelector,
2473 { "wFeatureSelector", "usb.setup.wFeatureSelector", FT_UINT16, BASE_DEC,
2474 VALS(usb_feature_selector_vals), 0x0, NULL, HFILL }},
2476 { &hf_usb_wInterface,
2477 { "wInterface", "usb.setup.wInterface", FT_UINT16, BASE_DEC,
2478 NULL, 0x0, NULL, HFILL }},
2481 { "wStatus", "usb.setup.wStatus", FT_UINT16, BASE_HEX,
2482 NULL, 0x0, NULL, HFILL }},
2484 { &hf_usb_wFrameNumber,
2485 { "wFrameNumber", "usb.setup.wFrameNumber", FT_UINT16, BASE_DEC,
2486 NULL, 0x0, NULL, HFILL }},
2488 /* --------------------------------- */
2489 { &hf_usb_iso_error_count, /* host endian byte order */
2490 { "ISO error count", "usb.iso.error_count", FT_UINT16, BASE_DEC, NULL, 0x0,
2493 { &hf_usb_iso_numdesc, /* host endian byte order */
2494 { "Number of ISO descriptors", "usb.iso.numdesc", FT_UINT16, BASE_DEC, NULL, 0x0,
2497 /* fields of struct mon_bin_isodesc from linux/drivers/usb/mon/mon_bin.c */
2498 { &hf_usb_iso_status, /* host endian byte order */
2499 { "Status", "usb.iso.iso_status", FT_INT32, BASE_DEC,
2500 VALS(usb_urb_status_vals), 0x0,
2501 "ISO descriptor status", HFILL }},
2503 { &hf_usb_iso_off, /* host endian byte order */
2504 { "Offset [bytes]", "usb.iso.iso_off", FT_UINT32, BASE_DEC, NULL, 0x0,
2505 "ISO data offset in bytes starting from the end of the last ISO descriptor", HFILL }},
2507 { &hf_usb_iso_len, /* host endian byte order */
2508 { "Length [bytes]", "usb.iso.iso_len", FT_UINT32, BASE_DEC, NULL, 0x0,
2509 "ISO data length in bytes", HFILL }},
2511 { &hf_usb_iso_pad, /* host endian byte order */
2512 { "Padding", "usb.iso._pad", FT_UINT32, BASE_HEX, NULL, 0x0,
2513 "Padding field of ISO descriptor structure", HFILL }},
2516 {"ISO Data", "usb.iso.data",
2517 FT_BYTES, BASE_NONE, NULL, 0x0,
2519 /* --------------------------------- */
2521 {"Application Data", "usb.data",
2522 FT_BYTES, BASE_NONE, NULL, 0x0,
2523 "Payload is application data", HFILL }},
2526 {"Leftover Capture Data", "usb.capdata",
2527 FT_BYTES, BASE_NONE, NULL, 0x0,
2528 "Padding added by the USB capture system", HFILL }},
2530 { &hf_usb_bmRequestType_direction,
2531 { "Direction", "usb.bmRequestType.direction", FT_BOOLEAN, 8,
2532 TFS(&tfs_bmrequesttype_direction), USB_DIR_IN, NULL, HFILL }},
2534 { &hf_usb_bmRequestType_type,
2535 { "Type", "usb.bmRequestType.type", FT_UINT8, BASE_HEX,
2536 VALS(bmrequesttype_type_vals), USB_TYPE_MASK, NULL, HFILL }},
2538 { &hf_usb_bmRequestType_recipient,
2539 { "Recipient", "usb.bmRequestType.recipient", FT_UINT8, BASE_HEX,
2540 VALS(bmrequesttype_recipient_vals), 0x1f, NULL, HFILL }},
2542 { &hf_usb_bDescriptorType,
2543 { "bDescriptorType", "usb.bDescriptorType", FT_UINT8, BASE_DEC,
2544 VALS(descriptor_type_vals), 0x0, NULL, HFILL }},
2546 { &hf_usb_descriptor_index,
2547 { "Descriptor Index", "usb.DescriptorIndex", FT_UINT8, BASE_HEX,
2548 NULL, 0x0, NULL, HFILL }},
2550 { &hf_usb_language_id,
2551 { "Language Id", "usb.LanguageId", FT_UINT16, BASE_HEX|BASE_EXT_STRING,
2552 &usb_langid_vals_ext, 0x0, NULL, HFILL }},
2555 { "bLength", "usb.bLength", FT_UINT8, BASE_DEC,
2556 NULL, 0x0, NULL, HFILL }},
2559 { "bcdUSB", "usb.bcdUSB", FT_UINT16, BASE_HEX,
2560 NULL, 0x0, NULL, HFILL }},
2562 { &hf_usb_bDeviceClass,
2563 { "bDeviceClass", "usb.bDeviceClass", FT_UINT8, BASE_DEC,
2564 NULL, 0x0, NULL, HFILL }},
2566 { &hf_usb_bDeviceSubClass,
2567 { "bDeviceSubClass", "usb.bDeviceSubClass", FT_UINT8, BASE_DEC,
2568 NULL, 0x0, NULL, HFILL }},
2570 { &hf_usb_bDeviceProtocol,
2571 { "bDeviceProtocol", "usb.bDeviceProtocol", FT_UINT8, BASE_DEC,
2572 NULL, 0x0, NULL, HFILL }},
2574 { &hf_usb_bMaxPacketSize0,
2575 { "bMaxPacketSize0", "usb.bMaxPacketSize0", FT_UINT8, BASE_DEC,
2576 NULL, 0x0, NULL, HFILL }},
2579 { "idVendor", "usb.idVendor", FT_UINT16, BASE_HEX,
2580 NULL, 0x0, NULL, HFILL }},
2582 { &hf_usb_idProduct,
2583 { "idProduct", "usb.idProduct", FT_UINT16, BASE_HEX,
2584 NULL, 0x0, NULL, HFILL }},
2586 { &hf_usb_bcdDevice,
2587 { "bcdDevice", "usb.bcdDevice", FT_UINT16, BASE_HEX,
2588 NULL, 0x0, NULL, HFILL }},
2590 { &hf_usb_iManufacturer,
2591 { "iManufacturer", "usb.iManufacturer", FT_UINT8, BASE_DEC,
2592 NULL, 0x0, NULL, HFILL }},
2595 { "iProduct", "usb.iProduct", FT_UINT8, BASE_DEC,
2596 NULL, 0x0, NULL, HFILL }},
2598 { &hf_usb_iSerialNumber,
2599 { "iSerialNumber", "usb.iSerialNumber", FT_UINT8, BASE_DEC,
2600 NULL, 0x0, NULL, HFILL }},
2602 { &hf_usb_bNumConfigurations,
2603 { "bNumConfigurations", "usb.bNumConfigurations", FT_UINT8, BASE_DEC,
2604 NULL, 0x0, NULL, HFILL }},
2607 { "wLANGID", "usb.wLANGID", FT_UINT16, BASE_HEX|BASE_EXT_STRING,
2608 &usb_langid_vals_ext, 0x0, NULL, HFILL }},
2611 { "bString", "usb.bString", FT_STRING, BASE_NONE,
2612 NULL, 0x0, NULL, HFILL }},
2614 { &hf_usb_bInterfaceNumber,
2615 { "bInterfaceNumber", "usb.bInterfaceNumber", FT_UINT8, BASE_DEC,
2616 NULL, 0x0, NULL, HFILL }},
2618 { &hf_usb_bAlternateSetting,
2619 { "bAlternateSetting","usb.bAlternateSetting", FT_UINT8, BASE_DEC,
2620 NULL, 0x0, NULL, HFILL }},
2622 { &hf_usb_bNumEndpoints,
2623 { "bNumEndpoints","usb.bNumEndpoints", FT_UINT8, BASE_DEC,
2624 NULL, 0x0, NULL, HFILL }},
2626 { &hf_usb_bInterfaceClass,
2627 { "bInterfaceClass", "usb.bInterfaceClass", FT_UINT8, BASE_HEX,
2628 VALS(usb_interfaceclass_vals), 0x0, NULL, HFILL }},
2630 { &hf_usb_bInterfaceSubClass,
2631 { "bInterfaceSubClass", "usb.bInterfaceSubClass", FT_UINT8, BASE_HEX,
2632 NULL, 0x0, NULL, HFILL }},
2634 { &hf_usb_bInterfaceProtocol,
2635 { "bInterfaceProtocol", "usb.bInterfaceProtocol", FT_UINT8, BASE_HEX,
2636 NULL, 0x0, NULL, HFILL }},
2638 { &hf_usb_iInterface,
2639 { "iInterface", "usb.iInterface", FT_UINT8, BASE_DEC,
2640 NULL, 0x0, NULL, HFILL }},
2642 { &hf_usb_bEndpointAddress,
2643 { "bEndpointAddress", "usb.bEndpointAddress", FT_UINT8, BASE_HEX,
2644 NULL, 0x0, NULL, HFILL }},
2646 { &hf_usb_configuration_bmAttributes,
2647 { "Configuration bmAttributes", "usb.configuration.bmAttributes", FT_UINT8, BASE_HEX,
2648 NULL, 0x0, NULL, HFILL }},
2650 { &hf_usb_bmAttributes,
2651 { "bmAttributes", "usb.bmAttributes", FT_UINT8, BASE_HEX,
2652 NULL, 0x0, NULL, HFILL }},
2654 { &hf_usb_bEndpointAttributeTransfer,
2655 { "Transfertype", "usb.bmAttributes.transfer", FT_UINT8, BASE_HEX,
2656 VALS(usb_bmAttributes_transfer_vals), 0x03, NULL, HFILL }},
2658 { &hf_usb_bEndpointAttributeSynchonisation,
2659 { "Synchronisationtype", "usb.bmAttributes.sync", FT_UINT8, BASE_HEX,
2660 VALS(usb_bmAttributes_sync_vals), 0x0c, NULL, HFILL }},
2662 { &hf_usb_bEndpointAttributeBehaviour,
2663 { "Behaviourtype", "usb.bmAttributes.behaviour", FT_UINT8, BASE_HEX,
2664 VALS(usb_bmAttributes_behaviour_vals), 0x30, NULL, HFILL }},
2666 { &hf_usb_wMaxPacketSize,
2667 { "wMaxPacketSize", "usb.wMaxPacketSize", FT_UINT16, BASE_DEC,
2668 NULL, 0x0, NULL, HFILL }},
2670 { &hf_usb_bInterval,
2671 { "bInterval", "usb.bInterval", FT_UINT8, BASE_DEC,
2672 NULL, 0x0, NULL, HFILL }},
2674 { &hf_usb_wTotalLength,
2675 { "wTotalLength", "usb.wTotalLength", FT_UINT16, BASE_DEC,
2676 NULL, 0x0, NULL, HFILL }},
2678 { &hf_usb_bNumInterfaces,
2679 { "bNumInterfaces", "usb.bNumInterfaces", FT_UINT8, BASE_DEC,
2680 NULL, 0x0, NULL, HFILL }},
2682 { &hf_usb_bConfigurationValue,
2683 { "bConfigurationValue", "usb.bConfigurationValue", FT_UINT8, BASE_DEC,
2684 NULL, 0x0, NULL, HFILL }},
2686 { &hf_usb_iConfiguration,
2687 { "iConfiguration", "usb.iConfiguration", FT_UINT8, BASE_DEC,
2688 NULL, 0x0, NULL, HFILL }},
2690 { &hf_usb_bMaxPower,
2691 { "bMaxPower", "usb.bMaxPower", FT_UINT8, BASE_DEC,
2692 NULL, 0x0, NULL, HFILL }},
2694 { &hf_usb_configuration_legacy10buspowered,
2695 { "Must be 1", "usb.configuration.legacy10buspowered", FT_BOOLEAN, 8,
2696 TFS(&tfs_mustbeone), 0x80, "Legacy USB 1.0 bus powered", HFILL }},
2698 { &hf_usb_configuration_selfpowered,
2699 { "Self-Powered", "usb.configuration.selfpowered", FT_BOOLEAN, 8,
2700 TFS(&tfs_selfpowered), 0x40, NULL, HFILL }},
2702 { &hf_usb_configuration_remotewakeup,
2703 { "Remote Wakeup", "usb.configuration.remotewakeup", FT_BOOLEAN, 8,
2704 TFS(&tfs_remotewakeup), 0x20, NULL, HFILL }},
2706 { &hf_usb_bEndpointAddress_number,
2707 { "Endpoint Number", "usb.bEndpointAddress.number", FT_UINT8, BASE_HEX,
2708 NULL, 0x0f, NULL, HFILL }},
2710 { &hf_usb_bEndpointAddress_direction,
2711 { "Direction", "usb.bEndpointAddress.direction", FT_BOOLEAN, 8,
2712 TFS(&tfs_endpoint_direction), 0x80, NULL, HFILL }},
2714 { &hf_usb_request_in,
2715 { "Request in", "usb.request_in", FT_FRAMENUM, BASE_NONE,
2716 NULL, 0, "The request to this packet is in this packet", HFILL }},
2719 { "Time from request", "usb.time", FT_RELATIVE_TIME, BASE_NONE,
2720 NULL, 0, "Time between Request and Response for USB cmds", HFILL }},
2722 { &hf_usb_response_in,
2723 { "Response in", "usb.response_in", FT_FRAMENUM, BASE_NONE,
2724 NULL, 0, "The response to this packet is in this packet", HFILL }},
2727 static gint *usb_subtrees[] = {
2732 &ett_usb_setup_bmrequesttype,
2733 &ett_descriptor_device,
2734 &ett_configuration_bmAttributes,
2735 &ett_configuration_bEndpointAddress,
2736 &ett_endpoint_bmAttributes
2740 proto_usb = proto_register_protocol("USB", "USB", "usb");
2741 proto_register_field_array(proto_usb, hf, array_length(hf));
2742 proto_register_subtree_array(usb_subtrees, array_length(usb_subtrees));
2744 usb_bulk_dissector_table = register_dissector_table("usb.bulk",
2745 "USB bulk endpoint", FT_UINT8, BASE_DEC);
2747 usb_control_dissector_table = register_dissector_table("usb.control",
2748 "USB control endpoint", FT_UINT8, BASE_DEC);
2750 usb_tap=register_tap("usb");
2754 proto_reg_handoff_usb(void)
2756 dissector_handle_t linux_usb_handle, linux_usb_mmapped_handle;
2758 linux_usb_handle = create_dissector_handle(dissect_linux_usb, proto_usb);
2759 linux_usb_mmapped_handle = create_dissector_handle(dissect_linux_usb_mmapped,
2762 dissector_add("wtap_encap", WTAP_ENCAP_USB_LINUX, linux_usb_handle);
2763 dissector_add("wtap_encap", WTAP_ENCAP_USB_LINUX_MMAPPED, linux_usb_mmapped_handle);