6 * By Paolo Abeni <paolo.abeni@email.it>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include <epan/packet.h>
31 #include <epan/etypes.h>
32 #include <epan/addr_resolv.h>
33 #include <epan/emem.h>
35 #include <epan/conversation.h>
36 #include <epan/expert.h>
38 #include "packet-usb.h"
40 /* protocols and header fields */
41 static int proto_usb = -1;
43 /* Linux USB pseudoheader fields */
44 static int hf_usb_urb_id = -1;
45 static int hf_usb_urb_type = -1;
46 static int hf_usb_transfer_type = -1;
47 static int hf_usb_endpoint_number = -1;
48 static int hf_usb_device_address = -1;
49 static int hf_usb_bus_id = -1;
50 static int hf_usb_setup_flag = -1;
51 static int hf_usb_data_flag = -1;
52 static int hf_usb_urb_status = -1;
53 static int hf_usb_urb_len = -1;
54 static int hf_usb_data_len = -1;
56 static int hf_usb_src_endpoint_number = -1;
57 static int hf_usb_dst_endpoint_number = -1;
58 static int hf_usb_request = -1;
59 static int hf_usb_value = -1;
60 static int hf_usb_index = -1;
61 static int hf_usb_length = -1;
62 static int hf_usb_data = -1;
63 static int hf_usb_bmRequestType = -1;
64 static int hf_usb_bmRequestType_direction = -1;
65 static int hf_usb_bmRequestType_type = -1;
66 static int hf_usb_bmRequestType_recipient = -1;
67 static int hf_usb_bDescriptorType = -1;
68 static int hf_usb_descriptor_index = -1;
69 static int hf_usb_language_id = -1;
70 static int hf_usb_bLength = -1;
71 static int hf_usb_bcdUSB = -1;
72 static int hf_usb_bDeviceClass = -1;
73 static int hf_usb_bDeviceSubClass = -1;
74 static int hf_usb_bDeviceProtocol = -1;
75 static int hf_usb_bMaxPacketSize0 = -1;
76 static int hf_usb_idVendor = -1;
77 static int hf_usb_idProduct = -1;
78 static int hf_usb_bcdDevice = -1;
79 static int hf_usb_iManufacturer = -1;
80 static int hf_usb_iProduct = -1;
81 static int hf_usb_iSerialNumber = -1;
82 static int hf_usb_bNumConfigurations = -1;
83 static int hf_usb_wLANGID = -1;
84 static int hf_usb_bString = -1;
85 static int hf_usb_bInterfaceNumber = -1;
86 static int hf_usb_bAlternateSetting = -1;
87 static int hf_usb_bNumEndpoints = -1;
88 static int hf_usb_bInterfaceClass = -1;
89 static int hf_usb_bInterfaceSubClass = -1;
90 static int hf_usb_bInterfaceProtocol = -1;
91 static int hf_usb_iInterface = -1;
92 static int hf_usb_bEndpointAddress = -1;
93 static int hf_usb_bmAttributes = -1;
94 static int hf_usb_bEndpointAttributeTransfer = -1;
95 static int hf_usb_bEndpointAttributeSynchonisation = -1;
96 static int hf_usb_bEndpointAttributeBehaviour = -1;
97 static int hf_usb_wMaxPacketSize = -1;
98 static int hf_usb_bInterval = -1;
99 static int hf_usb_wTotalLength = -1;
100 static int hf_usb_bNumInterfaces = -1;
101 static int hf_usb_bConfigurationValue = -1;
102 static int hf_usb_iConfiguration = -1;
103 static int hf_usb_bMaxPower = -1;
104 static int hf_usb_configuration_bmAttributes = -1;
105 static int hf_usb_configuration_legacy10buspowered = -1;
106 static int hf_usb_configuration_selfpowered = -1;
107 static int hf_usb_configuration_remotewakeup = -1;
108 static int hf_usb_bEndpointAddress_direction = -1;
109 static int hf_usb_bEndpointAddress_number = -1;
110 static int hf_usb_response_in = -1;
111 static int hf_usb_time = -1;
112 static int hf_usb_request_in = -1;
114 static gint usb_hdr = -1;
115 static gint usb_setup_hdr = -1;
116 static gint ett_usb_setup_bmrequesttype = -1;
117 static gint ett_descriptor_device = -1;
118 static gint ett_configuration_bmAttributes = -1;
119 static gint ett_configuration_bEndpointAddress = -1;
120 static gint ett_endpoint_bmAttributes = -1;
123 static int usb_tap = -1;
125 static dissector_table_t usb_bulk_dissector_table;
126 static dissector_table_t usb_control_dissector_table;
128 static const value_string usb_langid_vals[] = {
129 {0x0000, "no language specified"},
130 {0x0409, "English (United States)"},
134 static const value_string usb_interfaceclass_vals[] = {
135 {IF_CLASS_FROM_INTERFACE_DESC, "Use class info in Interface Descriptor"},
136 {IF_CLASS_AUDIO, "AUDIO"},
137 {IF_CLASS_COMMUNICATIONS, "COMMUNICATIONS"},
138 {IF_CLASS_HID, "HID"},
139 {IF_CLASS_PHYSICAL, "PHYSICAL"},
140 {IF_CLASS_IMAGE, "IMAGE"},
141 {IF_CLASS_PRINTER, "PRINTER"},
142 {IF_CLASS_MASSTORAGE, "MASSTORAGE"},
143 {IF_CLASS_HUB, "HUB"},
144 {IF_CLASS_CDC_DATA, "CDC_DATA"},
145 {IF_CLASS_SMART_CARD, "SMART_CARD"},
146 {IF_CLASS_CONTENT_SECURITY, "CONTENT_SECURITY"},
147 {IF_CLASS_VIDEO, "VIDEO"},
148 {IF_CLASS_DIAGNOSTIC_DEVICE, "DIAGNOSTIC_DEVICE"},
149 {IF_CLASS_WIRELESS_CONTROLLER, "WIRELESS_CONTROLLER"},
150 {IF_CLASS_MISCELLANEOUS, "MISCELLANEOUS"},
151 {IF_CLASS_APPLICATION_SPECIFIC, "APPLICATION_SPECIFIC"},
152 {IF_CLASS_VENDOR_SPECIFIC, "VENDOR_SPECIFIC"},
157 static const value_string usb_transfer_type_vals[] = {
158 {URB_CONTROL, "URB_CONTROL"},
159 {URB_ISOCHRONOUS,"URB_ISOCHRONOUS"},
160 {URB_INTERRUPT,"URB_INTERRUPT"},
161 {URB_BULK,"URB_BULK"},
165 static const value_string usb_urb_type_vals[] = {
166 {URB_SUBMIT, "URB_SUBMIT"},
167 {URB_COMPLETE,"URB_COMPLETE"},
168 {URB_ERROR,"URB_ERROR"},
172 #define USB_DT_DEVICE 0x01
173 #define USB_DT_CONFIG 0x02
174 #define USB_DT_STRING 0x03
175 #define USB_DT_INTERFACE 0x04
176 #define USB_DT_ENDPOINT 0x05
177 #define USB_DT_DEVICE_QUALIFIER 0x06
178 #define USB_DT_OTHER_SPEED_CONFIG 0x07
179 #define USB_DT_INTERFACE_POWER 0x08
180 /* these are from a minor usb 2.0 revision (ECN) */
181 #define USB_DT_OTG 0x09
182 #define USB_DT_DEBUG 0x0a
183 #define USB_DT_INTERFACE_ASSOCIATION 0x0b
184 /* these are from the Wireless USB spec */
185 #define USB_DT_SECURITY 0x0c
186 #define USB_DT_KEY 0x0d
187 #define USB_DT_ENCRYPTION_TYPE 0x0e
188 #define USB_DT_BOS 0x0f
189 #define USB_DT_DEVICE_CAPABILITY 0x10
190 #define USB_DT_WIRELESS_ENDPOINT_COMP 0x11
191 #define USB_DT_HID 0x21
192 #define USB_DT_RPIPE 0x22
193 static const value_string descriptor_type_vals[] = {
194 {USB_DT_DEVICE, "DEVICE"},
195 {USB_DT_CONFIG, "CONFIGURATION"},
196 {USB_DT_STRING, "STRING"},
197 {USB_DT_INTERFACE, "INTERFACE"},
198 {USB_DT_ENDPOINT, "ENDPOINT"},
199 {USB_DT_DEVICE_QUALIFIER, "DEVICE QUALIFIER"},
200 {USB_DT_OTHER_SPEED_CONFIG, "OTHER_SPEED CONFIG"},
201 {USB_DT_INTERFACE_POWER, "INTERFACE POWER"},
203 {USB_DT_DEBUG, "DEBUG"},
204 {USB_DT_INTERFACE_ASSOCIATION, "INTERFACE ASSOCIATION"},
205 {USB_DT_SECURITY, "SECURITY"},
207 {USB_DT_ENCRYPTION_TYPE, "ENCRYPTION TYPE"},
209 {USB_DT_DEVICE_CAPABILITY, "DEVICE CAPABILITY"},
210 {USB_DT_WIRELESS_ENDPOINT_COMP, "WIRELESS ENDPOINT COMP"},
212 {USB_DT_RPIPE, "RPIPE"},
216 static const value_string usb_bmAttributes_transfer_vals[] = {
217 {0x00, "Control-Transfer"},
218 {0x01, "Isochronous-Transfer"},
219 {0x02, "Bulk-Transfer"},
220 {0x03, "Interrupt-Transfer"},
224 static const value_string usb_bmAttributes_sync_vals[] = {
226 {0x04, "Asynchronous"},
228 {0x0c, "Synchronous"},
232 static const value_string usb_bmAttributes_behaviour_vals[] = {
233 {0x00, "Data-Endpoint"},
234 {0x10, "Explicit Feedback-Endpoint"},
235 {0x20, "Implicit Feedback-Data-Endpoint"},
240 /* from linux/include/asm-generic/errno.h */
241 #define EPERM 1 /* Operation not permitted */
242 #define ENOENT 2 /* No such file or directory */
243 #define ESRCH 3 /* No such process */
244 #define EINTR 4 /* Interrupted system call */
245 #define EIO 5 /* I/O error */
246 #define ENXIO 6 /* No such device or address */
247 #define E2BIG 7 /* Argument list too long */
248 #define ENOEXEC 8 /* Exec format error */
249 #define EBADF 9 /* Bad file number */
250 #define ECHILD 10 /* No child processes */
251 #define EAGAIN 11 /* Try again */
252 #define ENOMEM 12 /* Out of memory */
253 #define EACCES 13 /* Permission denied */
254 #define EFAULT 14 /* Bad address */
255 #define ENOTBLK 15 /* Block device required */
256 #define EBUSY 16 /* Device or resource busy */
257 #define EEXIST 17 /* File exists */
258 #define EXDEV 18 /* Cross-device link */
259 #define ENODEV 19 /* No such device */
260 #define ENOTDIR 20 /* Not a directory */
261 #define EISDIR 21 /* Is a directory */
262 #define EINVAL 22 /* Invalid argument */
263 #define ENFILE 23 /* File table overflow */
264 #define EMFILE 24 /* Too many open files */
265 #define ENOTTY 25 /* Not a typewriter */
266 #define ETXTBSY 26 /* Text file busy */
267 #define EFBIG 27 /* File too large */
268 #define ENOSPC 28 /* No space left on device */
269 #define ESPIPE 29 /* Illegal seek */
270 #define EROFS 30 /* Read-only file system */
271 #define EMLINK 31 /* Too many links */
272 #define EPIPE 32 /* Broken pipe */
273 #define EDOM 33 /* Math argument out of domain of func */
274 #define ERANGE 34 /* Math result not representable */
277 /* from linux/include/asm-generic/errno.h*/
278 #define EDEADLK 35 /* Resource deadlock would occur */
279 #define ENAMETOOLONG 36 /* File name too long */
280 #define ENOLCK 37 /* No record locks available */
281 #define ENOSYS 38 /* Function not implemented */
282 #define ENOTEMPTY 39 /* Directory not empty */
283 #define ELOOP 40 /* Too many symbolic links encountered */
284 #define EWOULDBLOCK EAGAIN /* Operation would block */
285 #define ENOMSG 42 /* No message of desired type */
286 #define EIDRM 43 /* Identifier removed */
287 #define ECHRNG 44 /* Channel number out of range */
288 #define EL2NSYNC 45 /* Level 2 not synchronized */
289 #define EL3HLT 46 /* Level 3 halted */
290 #define EL3RST 47 /* Level 3 reset */
291 #define ELNRNG 48 /* Link number out of range */
292 #define EUNATCH 49 /* Protocol driver not attached */
293 #define ENOCSI 50 /* No CSI structure available */
294 #define EL2HLT 51 /* Level 2 halted */
295 #define EBADE 52 /* Invalid exchange */
296 #define EBADR 53 /* Invalid request descriptor */
297 #define EXFULL 54 /* Exchange full */
298 #define ENOANO 55 /* No anode */
299 #define EBADRQC 56 /* Invalid request code */
300 #define EBADSLT 57 /* Invalid slot */
302 #define EDEADLOCK EDEADLK
304 #define EBFONT 59 /* Bad font file format */
305 #define ENOSTR 60 /* Device not a stream */
306 #define ENODATA 61 /* No data available */
307 #define ETIME 62 /* Timer expired */
308 #define ENOSR 63 /* Out of streams resources */
309 #define ENONET 64 /* Machine is not on the network */
310 #define ENOPKG 65 /* Package not installed */
311 #define EREMOTE 66 /* Object is remote */
312 #define ENOLINK 67 /* Link has been severed */
313 #define EADV 68 /* Advertise error */
314 #define ESRMNT 69 /* Srmount error */
315 #define ECOMM 70 /* Communication error on send */
316 #define EPROTO 71 /* Protocol error */
317 #define EMULTIHOP 72 /* Multihop attempted */
318 #define EDOTDOT 73 /* RFS specific error */
319 #define EBADMSG 74 /* Not a data message */
320 #define EOVERFLOW 75 /* Value too large for defined data type */
321 #define ENOTUNIQ 76 /* Name not unique on network */
322 #define EBADFD 77 /* File descriptor in bad state */
323 #define EREMCHG 78 /* Remote address changed */
324 #define ELIBACC 79 /* Can not access a needed shared library */
325 #define ELIBBAD 80 /* Accessing a corrupted shared library */
326 #define ELIBSCN 81 /* .lib section in a.out corrupted */
327 #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
328 #define ELIBEXEC 83 /* Cannot exec a shared library directly */
329 #define EILSEQ 84 /* Illegal byte sequence */
330 #define ERESTART 85 /* Interrupted system call should be restarted */
331 #define ESTRPIPE 86 /* Streams pipe error */
332 #define EUSERS 87 /* Too many users */
333 #define ENOTSOCK 88 /* Socket operation on non-socket */
334 #define EDESTADDRREQ 89 /* Destination address required */
335 #define EMSGSIZE 90 /* Message too long */
336 #define EPROTOTYPE 91 /* Protocol wrong type for socket */
337 #define ENOPROTOOPT 92 /* Protocol not available */
338 #define EPROTONOSUPPORT 93 /* Protocol not supported */
339 #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
340 #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
341 #define EPFNOSUPPORT 96 /* Protocol family not supported */
342 #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
343 #define EADDRINUSE 98 /* Address already in use */
344 #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
345 #define ENETDOWN 100 /* Network is down */
346 #define ENETUNREACH 101 /* Network is unreachable */
347 #define ENETRESET 102 /* Network dropped connection because of reset */
348 #define ECONNABORTED 103 /* Software caused connection abort */
349 #define ECONNRESET 104 /* Connection reset by peer */
350 #define ENOBUFS 105 /* No buffer space available */
351 #define EISCONN 106 /* Transport endpoint is already connected */
352 #define ENOTCONN 107 /* Transport endpoint is not connected */
353 #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
354 #define ETOOMANYREFS 109 /* Too many references: cannot splice */
355 #define ETIMEDOUT 110 /* Connection timed out */
356 #define ECONNREFUSED 111 /* Connection refused */
357 #define EHOSTDOWN 112 /* Host is down */
358 #define EHOSTUNREACH 113 /* No route to host */
359 #define EALREADY 114 /* Operation already in progress */
360 #define EINPROGRESS 115 /* Operation now in progress */
361 #define ESTALE 116 /* Stale NFS file handle */
362 #define EUCLEAN 117 /* Structure needs cleaning */
363 #define ENOTNAM 118 /* Not a XENIX named type file */
364 #define ENAVAIL 119 /* No XENIX semaphores available */
365 #define EISNAM 120 /* Is a named type file */
366 #define EREMOTEIO 121 /* Remote I/O error */
367 #define EDQUOT 122 /* Quota exceeded */
369 #define ENOMEDIUM 123 /* No medium found */
370 #define EMEDIUMTYPE 124 /* Wrong medium type */
371 #define ECANCELED 125 /* Operation Canceled */
372 #define ENOKEY 126 /* Required key not available */
373 #define EKEYEXPIRED 127 /* Key has expired */
374 #define EKEYREVOKED 128 /* Key has been revoked */
375 #define EKEYREJECTED 129 /* Key was rejected by service */
377 /* for robust mutexes */
378 #define EOWNERDEAD 130 /* Owner died */
379 #define ENOTRECOVERABLE 131 /* State not recoverable */
382 static const value_string usb_urb_status_vals[] = {
384 { -EPERM, "Operation not permitted (-EPERM)" },
385 { -ENOENT, "No such file or directory (-ENOENT)" },
386 { -ESRCH, "No such process (-ESRCH)" },
387 { -EINTR, "Interrupted system call (-EINTR)" },
388 { -EIO, "I/O error (-EIO)" },
389 { -ENXIO, "No such device or address (-ENXIO)" },
390 { -E2BIG, "Argument list too long (-E2BIG)" },
391 { -ENOEXEC, "Exec format error (-ENOEXEC)" },
392 { -EBADF, "Bad file number (-EBADF)" },
393 { -ECHILD, "No child processes (-ECHILD)" },
394 { -EAGAIN, "Try again (-EAGAIN)" },
395 { -ENOMEM, "Out of memory (-ENOMEM)" },
396 { -EACCES, "Permission denied (-EACCES)" },
397 { -EFAULT, "Bad address (-EFAULT)" },
398 { -ENOTBLK, "Block device required (-ENOTBLK)" },
399 { -EBUSY, "Device or resource busy (-EBUSY)" },
400 { -EEXIST, "File exists (-EEXIST)" },
401 { -EXDEV, "Cross-device link (-EXDEV)" },
402 { -ENODEV, "No such device (-ENODEV)" },
403 { -ENOTDIR, "Not a directory (-ENOTDIR)" },
404 { -EISDIR, "Is a directory (-EISDIR)" },
405 { -EINVAL, "Invalid argument (-EINVAL)" },
406 { -ENFILE, "File table overflow (-ENFILE)" },
407 { -EMFILE, "Too many open files (-EMFILE)" },
408 { -ENOTTY, "Not a typewriter (-ENOTTY)" },
409 { -ETXTBSY, "Text file busy (-ETXTBSY)" },
410 { -EFBIG, "File too large (-EFBIG)" },
411 { -ENOSPC, "No space left on device (-ENOSPC)" },
412 { -ESPIPE, "Illegal seek (-ESPIPE)" },
413 { -EROFS, "Read-only file system (-EROFS)" },
414 { -EMLINK, "Too many links (-EMLINK)" },
415 { -EPIPE, "Broken pipe (-EPIPE)" },
416 { -EDOM, "Math argument out of domain of func (-EDOM)" },
417 { -ERANGE, "Math result not representable (-ERANGE)" },
418 { -EDEADLK, "Resource deadlock would occur (-EDEADLK)" },
419 { -ENAMETOOLONG, "File name too long (-ENAMETOOLONG)" },
420 { -ENOLCK, "No record locks available (-ENOLCK)" },
421 { -ENOSYS, "Function not implemented (-ENOSYS)" },
422 { -ENOTEMPTY, "Directory not empty (-ENOTEMPTY)" },
423 { -ELOOP, "Too many symbolic links encountered (-ELOOP)" },
424 { -ENOMSG, "No message of desired type (-ENOMSG)" },
425 { -EIDRM, "Identifier removed (-EIDRM)" },
426 { -ECHRNG, "Channel number out of range (-ECHRNG)" },
427 { -EL2NSYNC, "Level 2 not synchronized (-EL2NSYNC)" },
428 { -EL3HLT, "Level 3 halted (-EL3HLT)" },
429 { -EL3RST, "Level 3 reset (-EL3RST)" },
430 { -ELNRNG, "Link number out of range (-ELNRNG)" },
431 { -EUNATCH, "Protocol driver not attached (-EUNATCH)" },
432 { -ENOCSI, "No CSI structure available (-ENOCSI)" },
433 { -EL2HLT, "Level 2 halted (-EL2HLT)" },
434 { -EBADE, "Invalid exchange (-EBADE)" },
435 { -EBADR, "Invalid request descriptor (-EBADR)" },
436 { -EXFULL, "Exchange full (-EXFULL)" },
437 { -ENOANO, "No anode (-ENOANO)" },
438 { -EBADRQC, "Invalid request code (-EBADRQC)" },
439 { -EBADSLT, "Invalid slot (-EBADSLT)" },
440 { -EBFONT, "Bad font file format (-EBFONT)" },
441 { -ENOSTR, "Device not a stream (-ENOSTR)" },
442 { -ENODATA, "No data available (-ENODATA)" },
443 { -ETIME, "Timer expired (-ETIME)" },
444 { -ENOSR, "Out of streams resources (-ENOSR)" },
445 { -ENONET, "Machine is not on the network (-ENONET)" },
446 { -ENOPKG, "Package not installed (-ENOPKG)" },
447 { -EREMOTE, "Object is remote (-EREMOTE)" },
448 { -ENOLINK, "Link has been severed (-ENOLINK)" },
449 { -EADV, "Advertise error (-EADV)" },
450 { -ESRMNT, "Srmount error (-ESRMNT)" },
451 { -ECOMM, "Communication error on send (-ECOMM)" },
452 { -EPROTO, "Protocol error (-EPROTO)" },
453 { -EMULTIHOP, "Multihop attempted (-EMULTIHOP)" },
454 { -EDOTDOT, "RFS specific error (-EDOTDOT)" },
455 { -EBADMSG, "Not a data message (-EBADMSG)" },
456 { -EOVERFLOW, "Value too large for defined data type (-EOVERFLOW)" },
457 { -ENOTUNIQ, "Name not unique on network (-ENOTUNIQ)" },
458 { -EBADFD, "File descriptor in bad state (-EBADFD)" },
459 { -EREMCHG, "Remote address changed (-EREMCHG)" },
460 { -ELIBACC, "Can not access a needed shared library (-ELIBACC)" },
461 { -ELIBBAD, "Accessing a corrupted shared library (-ELIBBAD)" },
462 { -ELIBSCN, ".lib section in a.out corrupted (-ELIBSCN)" },
463 { -ELIBMAX, "Attempting to link in too many shared libraries (-ELIBMAX)" },
464 { -ELIBEXEC, "Cannot exec a shared library directly (-ELIBEXEC)" },
465 { -EILSEQ, "Illegal byte sequence (-EILSEQ)" },
466 { -ERESTART, "Interrupted system call should be restarted (-ERESTART)" },
467 { -ESTRPIPE, "Streams pipe error (-ESTRPIPE)" },
468 { -EUSERS, "Too many users (-EUSERS)" },
469 { -ENOTSOCK, "Socket operation on non-socket (-ENOTSOCK)" },
470 { -EDESTADDRREQ, "Destination address required (-EDESTADDRREQ)" },
471 { -EMSGSIZE, "Message too long (-EMSGSIZE)" },
472 { -EPROTOTYPE, "Protocol wrong type for socket (-EPROTOTYPE)" },
473 { -ENOPROTOOPT, "Protocol not available (-ENOPROTOOPT)" },
474 { -EPROTONOSUPPORT, "Protocol not supported (-EPROTONOSUPPORT)" },
475 { -ESOCKTNOSUPPORT, "Socket type not supported (-ESOCKTNOSUPPORT)" },
476 { -EOPNOTSUPP, "Operation not supported on transport endpoint (-EOPNOTSUPP)" },
477 { -EPFNOSUPPORT, "Protocol family not supported (-EPFNOSUPPORT)" },
478 { -EAFNOSUPPORT, "Address family not supported by protocol (-EAFNOSUPPORT)" },
479 { -EADDRINUSE, "Address already in use (-EADDRINUSE)" },
480 { -EADDRNOTAVAIL, "Cannot assign requested address (-EADDRNOTAVAIL)" },
481 { -ENETDOWN, "Network is down (-ENETDOWN)" },
482 { -ENETUNREACH, "Network is unreachable (-ENETUNREACH)" },
483 { -ENETRESET, "Network dropped connection because of reset (-ENETRESET)" },
484 { -ECONNABORTED, "Software caused connection abort (-ECONNABORTED)" },
485 { -ECONNRESET, "Connection reset by peer (-ECONNRESET)" },
486 { -ENOBUFS, "No buffer space available (-ENOBUFS)" },
487 { -EISCONN, "Transport endpoint is already connected (-EISCONN)" },
488 { -ENOTCONN, "Transport endpoint is not connected (-ENOTCONN)" },
489 { -ESHUTDOWN, "Cannot send after transport endpoint shutdown (-ESHUTDOWN)" },
490 { -ETOOMANYREFS, "Too many references: cannot splice (-ETOOMANYREFS)" },
491 { -ETIMEDOUT, "Connection timed out (-ETIMEDOUT)" },
492 { -ECONNREFUSED, "Connection refused (-ECONNREFUSED)" },
493 { -EHOSTDOWN, "Host is down (-EHOSTDOWN)" },
494 { -EHOSTUNREACH, "No route to host (-EHOSTUNREACH)" },
495 { -EALREADY, "Operation already in progress (-EALREADY)" },
496 { -EINPROGRESS, "Operation now in progress (-EINPROGRESS)" },
497 { -ESTALE, "Stale NFS file handle (-ESTALE)" },
498 { -EUCLEAN, "Structure needs cleaning (-EUCLEAN)" },
499 { -ENOTNAM, "Not a XENIX named type file (-ENOTNAM)" },
500 { -ENAVAIL, "No XENIX semaphores available (-ENAVAIL)" },
501 { -EISNAM, "Is a named type file (-EISNAM)" },
502 { -EREMOTEIO, "Remote I/O error (-EREMOTEIO)" },
503 { -EDQUOT, "Quota exceeded (-EDQUOT)" },
504 { -ENOMEDIUM, "No medium found (-ENOMEDIUM)" },
505 { -EMEDIUMTYPE, "Wrong medium type (-EMEDIUMTYPE)" },
506 { -ECANCELED, "Operation Canceled (-ECANCELED)" },
507 { -ENOKEY, "Required key not available (-ENOKEY)" },
508 { -EKEYEXPIRED, "Key has expired (-EKEYEXPIRED)" },
509 { -EKEYREVOKED, "Key has been revoked (-EKEYREVOKED)" },
510 { -EKEYREJECTED, "Key was rejected by service (-EKEYREJECTED)" },
511 { -EOWNERDEAD, "Owner died (-EOWNERDEAD)" },
512 { -ENOTRECOVERABLE, "State not recoverable (-ENOTRECOVERABLE)" },
517 static usb_conv_info_t *
518 get_usb_conv_info(conversation_t *conversation)
520 usb_conv_info_t *usb_conv_info;
522 /* do we have conversation specific data ? */
523 usb_conv_info = conversation_get_proto_data(conversation, proto_usb);
525 /* no not yet so create some */
526 usb_conv_info = se_alloc0(sizeof(usb_conv_info_t));
527 usb_conv_info->interfaceClass=IF_CLASS_UNKNOWN;
528 usb_conv_info->transactions=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "usb transactions");
530 conversation_add_proto_data(conversation, proto_usb, usb_conv_info);
533 return usb_conv_info;
536 static conversation_t *
537 get_usb_conversation(packet_info *pinfo, address *src_addr, address *dst_addr, guint32 src_endpoint, guint32 dst_endpoint)
539 conversation_t *conversation;
542 * Do we have a conversation for this connection?
544 conversation = find_conversation(pinfo->fd->num,
547 src_endpoint, dst_endpoint, 0);
552 /* We don't yet have a conversation, so create one. */
553 conversation = conversation_new(pinfo->fd->num,
556 src_endpoint, dst_endpoint, 0);
562 /* SETUP dissectors */
566 * This dissector is used to dissect the setup part and the data
567 * for URB_CONTROL_INPUT / GET DESCRIPTOR
573 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_)
575 proto_item *item=NULL;
576 proto_tree *tree=NULL;
577 int old_offset=offset;
580 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "DEVICE QUALIFIER DESCRIPTOR");
581 tree=proto_item_add_subtree(item, ett_descriptor_device);
585 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
588 /* bDescriptorType */
589 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
593 proto_tree_add_item(tree, hf_usb_bcdUSB, tvb, offset, 2, TRUE);
597 proto_tree_add_item(tree, hf_usb_bDeviceClass, tvb, offset, 1, TRUE);
600 /* bDeviceSubClass */
601 proto_tree_add_item(tree, hf_usb_bDeviceSubClass, tvb, offset, 1, TRUE);
604 /* bDeviceProtocol */
605 proto_tree_add_item(tree, hf_usb_bDeviceProtocol, tvb, offset, 1, TRUE);
608 /* bMaxPacketSize0 */
609 proto_tree_add_item(tree, hf_usb_bMaxPacketSize0, tvb, offset, 1, TRUE);
612 /* bNumConfigurations */
613 proto_tree_add_item(tree, hf_usb_bNumConfigurations, tvb, offset, 1, TRUE);
616 /* one reserved byte */
620 proto_item_set_len(item, offset-old_offset);
628 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_)
630 proto_item *item=NULL;
631 proto_tree *tree=NULL;
632 int old_offset=offset;
635 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "DEVICE DESCRIPTOR");
636 tree=proto_item_add_subtree(item, ett_descriptor_device);
640 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
643 /* bDescriptorType */
644 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
648 proto_tree_add_item(tree, hf_usb_bcdUSB, tvb, offset, 2, TRUE);
652 proto_tree_add_item(tree, hf_usb_bDeviceClass, tvb, offset, 1, TRUE);
655 /* bDeviceSubClass */
656 proto_tree_add_item(tree, hf_usb_bDeviceSubClass, tvb, offset, 1, TRUE);
659 /* bDeviceProtocol */
660 proto_tree_add_item(tree, hf_usb_bDeviceProtocol, tvb, offset, 1, TRUE);
663 /* bMaxPacketSize0 */
664 proto_tree_add_item(tree, hf_usb_bMaxPacketSize0, tvb, offset, 1, TRUE);
668 proto_tree_add_item(tree, hf_usb_idVendor, tvb, offset, 2, TRUE);
672 proto_tree_add_item(tree, hf_usb_idProduct, tvb, offset, 2, TRUE);
676 proto_tree_add_item(tree, hf_usb_bcdDevice, tvb, offset, 2, TRUE);
680 proto_tree_add_item(tree, hf_usb_iManufacturer, tvb, offset, 1, TRUE);
684 proto_tree_add_item(tree, hf_usb_iProduct, tvb, offset, 1, TRUE);
688 proto_tree_add_item(tree, hf_usb_iSerialNumber, tvb, offset, 1, TRUE);
691 /* bNumConfigurations */
692 proto_tree_add_item(tree, hf_usb_bNumConfigurations, tvb, offset, 1, TRUE);
696 proto_item_set_len(item, offset-old_offset);
704 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_)
706 proto_item *item=NULL;
707 proto_tree *tree=NULL;
708 int old_offset=offset;
712 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "STRING DESCRIPTOR");
713 tree=proto_item_add_subtree(item, ett_descriptor_device);
717 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
718 len=tvb_get_guint8(tvb, offset);
721 /* bDescriptorType */
722 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
725 if(!usb_trans_info->u.get_descriptor.index){
726 /* list of languanges */
727 while(len>(offset-old_offset)){
729 proto_tree_add_item(tree, hf_usb_wLANGID, tvb, offset, 2, TRUE);
736 str=tvb_get_ephemeral_faked_unicode(tvb, offset, (len-2)/2, TRUE);
737 proto_tree_add_string(tree, hf_usb_bString, tvb, offset, len-2, str);
742 proto_item_set_len(item, offset-old_offset);
752 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)
754 proto_item *item=NULL;
755 proto_tree *tree=NULL;
756 int old_offset=offset;
759 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "INTERFACE DESCRIPTOR");
760 tree=proto_item_add_subtree(item, ett_descriptor_device);
764 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
767 /* bDescriptorType */
768 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
771 /* bInterfaceNumber */
772 proto_tree_add_item(tree, hf_usb_bInterfaceNumber, tvb, offset, 1, TRUE);
775 /* bAlternateSetting */
776 proto_tree_add_item(tree, hf_usb_bAlternateSetting, tvb, offset, 1, TRUE);
780 proto_tree_add_item(tree, hf_usb_bNumEndpoints, tvb, offset, 1, TRUE);
783 /* bInterfaceClass */
784 proto_tree_add_item(tree, hf_usb_bInterfaceClass, tvb, offset, 1, TRUE);
785 /* save the class so we can access it later in the endpoint descriptor */
786 usb_conv_info->interfaceClass=tvb_get_guint8(tvb, offset);
787 if(!pinfo->fd->flags.visited){
788 usb_trans_info->interface_info=se_alloc0(sizeof(usb_conv_info_t));
789 usb_trans_info->interface_info->interfaceClass=tvb_get_guint8(tvb, offset);
790 usb_trans_info->interface_info->transactions=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "usb transactions");
794 /* bInterfaceSubClass */
795 proto_tree_add_item(tree, hf_usb_bInterfaceSubClass, tvb, offset, 1, TRUE);
798 /* bInterfaceProtocol */
799 proto_tree_add_item(tree, hf_usb_bInterfaceProtocol, tvb, offset, 1, TRUE);
803 proto_tree_add_item(tree, hf_usb_iInterface, tvb, offset, 1, TRUE);
807 proto_item_set_len(item, offset-old_offset);
814 static const true_false_string tfs_endpoint_direction = {
819 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_)
821 proto_item *item=NULL;
822 proto_tree *tree=NULL;
823 proto_item *endpoint_item=NULL;
824 proto_tree *endpoint_tree=NULL;
825 proto_item *ep_attrib_item=NULL;
826 proto_tree *ep_attrib_tree=NULL;
827 int old_offset=offset;
831 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "ENDPOINT DESCRIPTOR");
832 tree=proto_item_add_subtree(item, ett_descriptor_device);
836 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
839 /* bDescriptorType */
840 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
843 /* bEndpointAddress */
845 endpoint_item=proto_tree_add_item(tree, hf_usb_bEndpointAddress, tvb, offset, 1, TRUE);
846 endpoint_tree=proto_item_add_subtree(endpoint_item, ett_configuration_bEndpointAddress);
848 endpoint=tvb_get_guint8(tvb, offset)&0x0f;
849 proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_direction, tvb, offset, 1, TRUE);
850 proto_item_append_text(endpoint_item, " %s", (tvb_get_guint8(tvb, offset)&0x80)?"IN":"OUT");
851 proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_number, tvb, offset, 1, TRUE);
852 proto_item_append_text(endpoint_item, " Endpoint:%d", endpoint);
855 /* Together with class from the interface descriptor we know what kind
856 * of class the device at endpoint is.
857 * Make sure a conversation exists for this endpoint and attach a
858 * usb_conv_into_t structure to it.
860 * All endpoints for the same interface descriptor share the same
861 * usb_conv_info structure.
863 if((!pinfo->fd->flags.visited)&&usb_trans_info->interface_info){
864 conversation_t *conversation;
866 if(pinfo->destport==NO_ENDPOINT){
867 static address tmp_addr;
868 static usb_address_t usb_addr;
870 /* Create a new address structure that points to the same device
871 * but the new endpoint.
873 usb_addr.device=((usb_address_t *)(pinfo->src.data))->device;
874 usb_addr.endpoint=endpoint;
875 SET_ADDRESS(&tmp_addr, AT_USB, USB_ADDR_LEN, (char *)&usb_addr);
876 conversation=get_usb_conversation(pinfo, &tmp_addr, &pinfo->dst, endpoint, pinfo->destport);
878 static address tmp_addr;
879 static usb_address_t usb_addr;
881 /* Create a new address structure that points to the same device
882 * but the new endpoint.
884 usb_addr.device=((usb_address_t *)(pinfo->dst.data))->device;
885 usb_addr.endpoint=endpoint;
886 SET_ADDRESS(&tmp_addr, AT_USB, USB_ADDR_LEN, (char *)&usb_addr);
887 conversation=get_usb_conversation(pinfo, &pinfo->src, &tmp_addr, pinfo->srcport, endpoint);
890 conversation_add_proto_data(conversation, proto_usb, usb_trans_info->interface_info);
895 ep_attrib_item=proto_tree_add_item(tree, hf_usb_bmAttributes, tvb, offset, 1, TRUE);
896 ep_attrib_tree=proto_item_add_subtree(ep_attrib_item, ett_endpoint_bmAttributes);
898 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeTransfer, tvb, offset, 1, TRUE);
899 /* isochronous only */
900 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeSynchonisation, tvb, offset, 1, TRUE);
901 /* isochronous only */
902 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeBehaviour, tvb, offset, 1, TRUE);
906 proto_tree_add_item(tree, hf_usb_wMaxPacketSize, tvb, offset, 2, TRUE);
910 proto_tree_add_item(tree, hf_usb_bInterval, tvb, offset, 1, TRUE);
914 proto_item_set_len(item, offset-old_offset);
921 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_)
923 proto_item *item=NULL;
924 proto_tree *tree=NULL;
925 int old_offset=offset;
929 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "UNKNOWN DESCRIPTOR");
930 tree=proto_item_add_subtree(item, ett_descriptor_device);
934 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
935 bLength = tvb_get_guint8(tvb, offset);
938 item = proto_tree_add_text(parent_tree, tvb, offset - 1, 1,
939 "Invalid bLength: %u", bLength);
940 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR,
941 "Invalid bLength: %u", bLength);
945 /* bDescriptorType */
946 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
949 offset += bLength - 2;
952 proto_item_set_len(item, offset-old_offset);
959 static const true_false_string tfs_mustbeone = {
960 "Must be 1 for USB 1.1 and higher",
961 "FIXME: Is this a USB 1.0 device"
963 static const true_false_string tfs_selfpowered = {
964 "This device is SELF-POWERED",
965 "This device is powered from the USB bus"
967 static const true_false_string tfs_remotewakeup = {
968 "This device supports REMOTE WAKEUP",
969 "This device does NOT support remote wakeup"
972 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)
974 proto_item *item=NULL;
975 proto_tree *tree=NULL;
976 int old_offset=offset;
978 proto_item *flags_item=NULL;
979 proto_tree *flags_tree=NULL;
981 proto_item *power_item=NULL;
985 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "CONFIGURATION DESCRIPTOR");
986 tree=proto_item_add_subtree(item, ett_descriptor_device);
990 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
993 /* bDescriptorType */
994 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
998 proto_tree_add_item(tree, hf_usb_wTotalLength, tvb, offset, 2, TRUE);
999 len=tvb_get_letohs(tvb, offset);
1002 /* bNumInterfaces */
1003 proto_tree_add_item(tree, hf_usb_bNumInterfaces, tvb, offset, 1, TRUE);
1006 /* bConfigurationValue */
1007 proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, TRUE);
1010 /* iConfiguration */
1011 proto_tree_add_item(tree, hf_usb_iConfiguration, tvb, offset, 1, TRUE);
1016 flags_item=proto_tree_add_item(tree, hf_usb_configuration_bmAttributes, tvb, offset, 1, TRUE);
1017 flags_tree=proto_item_add_subtree(flags_item, ett_configuration_bmAttributes);
1019 flags=tvb_get_guint8(tvb, offset);
1020 proto_tree_add_item(flags_tree, hf_usb_configuration_legacy10buspowered, tvb, offset, 1, TRUE);
1021 proto_tree_add_item(flags_tree, hf_usb_configuration_selfpowered, tvb, offset, 1, TRUE);
1022 proto_item_append_text(flags_item, " %sSELF-POWERED", (flags&0x40)?"":"NOT ");
1024 proto_tree_add_item(flags_tree, hf_usb_configuration_remotewakeup, tvb, offset, 1, TRUE);
1025 proto_item_append_text(flags_item, " %sREMOTE-WAKEUP", (flags&0x20)?"":"NO ");
1030 power_item=proto_tree_add_item(tree, hf_usb_bMaxPower, tvb, offset, 1, TRUE);
1031 power=tvb_get_guint8(tvb, offset);
1032 proto_item_append_text(power_item, " (%dmA)", power*2);
1035 /* initialize interface_info to NULL */
1036 usb_trans_info->interface_info=NULL;
1038 /* decode any additional interface and endpoint descriptors */
1039 while(len>(old_offset-offset)){
1042 if(tvb_length_remaining(tvb, offset)<2){
1045 next_type=tvb_get_guint8(tvb, offset+1);
1047 case USB_DT_INTERFACE:
1048 offset=dissect_usb_interface_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1050 case USB_DT_ENDPOINT:
1051 offset=dissect_usb_endpoint_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1054 offset=dissect_usb_unknown_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1056 /* was: return offset; */
1061 proto_item_set_len(item, offset-old_offset);
1069 dissect_usb_setup_get_descriptor(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gboolean is_request, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info)
1072 /* descriptor index */
1073 proto_tree_add_item(tree, hf_usb_descriptor_index, tvb, offset, 1, TRUE);
1074 usb_trans_info->u.get_descriptor.index=tvb_get_guint8(tvb, offset);
1077 /* descriptor type */
1078 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
1079 usb_trans_info->u.get_descriptor.type=tvb_get_guint8(tvb, offset);
1081 if (check_col(pinfo->cinfo, COL_INFO)) {
1082 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
1083 val_to_str(usb_trans_info->u.get_descriptor.type, descriptor_type_vals, "Unknown type %x"));
1087 proto_tree_add_item(tree, hf_usb_language_id, tvb, offset, 2, TRUE);
1091 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1094 if (check_col(pinfo->cinfo, COL_INFO)) {
1095 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
1096 val_to_str(usb_trans_info->u.get_descriptor.type, descriptor_type_vals, "Unknown type %x"));
1098 switch(usb_trans_info->u.get_descriptor.type){
1100 offset=dissect_usb_device_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1103 offset=dissect_usb_configuration_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1106 offset=dissect_usb_string_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1108 case USB_DT_INTERFACE:
1109 offset=dissect_usb_interface_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1111 case USB_DT_ENDPOINT:
1112 offset=dissect_usb_endpoint_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1114 case USB_DT_DEVICE_QUALIFIER:
1115 offset=dissect_usb_device_qualifier_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1118 /* XXX dissect the descriptor coming back from the device */
1119 proto_tree_add_text(tree, tvb, offset, -1, "GET DESCRIPTOR data");
1120 offset += tvb_length_remaining(tvb, offset);
1130 typedef int (*usb_setup_dissector)(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gboolean is_request, usb_trans_info_t *usb_trans_info, usb_conv_info_t *usb_conv_info);
1132 typedef struct _usb_setup_dissector_table_t {
1134 usb_setup_dissector dissector;
1135 } usb_setup_dissector_table_t;
1136 #define USB_SETUP_GET_STATUS 0
1137 #define USB_SETUP_CLEAR_FEATURE 1
1138 #define USB_SETUP_SET_FEATURE 2
1139 #define USB_SETUP_SET_ADDRESS 5
1140 #define USB_SETUP_GET_DESCRIPTOR 6
1141 #define USB_SETUP_SET_DESCRIPTOR 7
1142 #define USB_SETUP_GET_CONFIGURATION 8
1143 #define USB_SETUP_SET_CONFIGURATION 9
1144 #define USB_SETUP_GET_INTERFACE 10
1145 #define USB_SETUP_SET_INTERFACE 11
1146 #define USB_SETUP_SYNCH_FRAME 12
1147 static const usb_setup_dissector_table_t setup_dissectors[] = {
1148 {USB_SETUP_GET_DESCRIPTOR, dissect_usb_setup_get_descriptor},
1151 static const value_string setup_request_names_vals[] = {
1152 {USB_SETUP_GET_STATUS, "GET STATUS"},
1153 {USB_SETUP_CLEAR_FEATURE, "CLEAR FEATURE"},
1154 {USB_SETUP_SET_FEATURE, "SET FEATURE"},
1155 {USB_SETUP_SET_ADDRESS, "SET ADDRESS"},
1156 {USB_SETUP_GET_DESCRIPTOR, "GET DESCRIPTOR"},
1157 {USB_SETUP_SET_DESCRIPTOR, "SET DESCRIPTOR"},
1158 {USB_SETUP_GET_CONFIGURATION, "GET CONFIGURATION"},
1159 {USB_SETUP_SET_CONFIGURATION, "SET CONFIGURATION"},
1160 {USB_SETUP_GET_INTERFACE, "GET INTERFACE"},
1161 {USB_SETUP_SET_INTERFACE, "SET INTERFACE"},
1162 {USB_SETUP_SYNCH_FRAME, "SYNCH FRAME"},
1167 #define USB_DIR_OUT 0 /* to device */
1168 #define USB_DIR_IN 0x80 /* to host */
1170 static const true_false_string tfs_bmrequesttype_direction = {
1175 #define USB_TYPE_MASK (0x03 << 5)
1176 #define RQT_SETUP_TYPE_STANDARD 0
1177 #define RQT_SETUP_TYPE_CLASS 1
1178 #define RQT_SETUP_TYPE_VENDOR 2
1180 static const value_string bmrequesttype_type_vals[] = {
1181 {RQT_SETUP_TYPE_STANDARD, "Standard"},
1182 {RQT_SETUP_TYPE_CLASS, "Class"},
1183 {RQT_SETUP_TYPE_VENDOR, "Vendor"},
1186 static const value_string bmrequesttype_recipient_vals[] = {
1195 dissect_usb_bmrequesttype(proto_tree *parent_tree, tvbuff_t *tvb, int offset,
1198 proto_item *item=NULL;
1199 proto_tree *tree=NULL;
1200 guint8 bmRequestType;
1203 item=proto_tree_add_item(parent_tree, hf_usb_bmRequestType, tvb, offset, 1, TRUE);
1204 tree = proto_item_add_subtree(item, ett_usb_setup_bmrequesttype);
1207 bmRequestType = tvb_get_guint8(tvb, offset);
1208 *type = (bmRequestType & USB_TYPE_MASK) >>5;
1209 proto_tree_add_item(tree, hf_usb_bmRequestType_direction, tvb, offset, 1, TRUE);
1210 proto_tree_add_item(tree, hf_usb_bmRequestType_type, tvb, offset, 1, TRUE);
1211 proto_tree_add_item(tree, hf_usb_bmRequestType_recipient, tvb, offset, 1, TRUE);
1218 dissect_linux_usb_pseudo_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1220 guint8 transfer_type;
1221 const gchar* val_str;
1223 proto_tree_add_uint64(tree, hf_usb_urb_id, tvb, 0, 0,
1224 pinfo->pseudo_header->linux_usb.id);
1226 /* show the event type of this URB as string and as a character */
1227 val_str = val_to_str(pinfo->pseudo_header->linux_usb.event_type,
1228 usb_urb_type_vals, "Unknown %d");
1229 proto_tree_add_string_format_value(tree, hf_usb_urb_type, tvb, 0, 0,
1230 &(pinfo->pseudo_header->linux_usb.event_type),
1231 "%s ('%c')", val_str,
1232 pinfo->pseudo_header->linux_usb.event_type);
1234 transfer_type = pinfo->pseudo_header->linux_usb.transfer_type;
1235 proto_tree_add_uint(tree, hf_usb_transfer_type, tvb, 0, 0, transfer_type);
1237 if (check_col(pinfo->cinfo, COL_INFO)) {
1238 col_append_str(pinfo->cinfo, COL_INFO,
1239 val_to_str(transfer_type, usb_transfer_type_vals, "Unknown type %x"));
1242 proto_tree_add_uint(tree, hf_usb_endpoint_number, tvb, 0, 0,
1243 pinfo->pseudo_header->linux_usb.endpoint_number);
1245 proto_tree_add_uint(tree, hf_usb_device_address, tvb, 0, 0,
1246 pinfo->pseudo_header->linux_usb.device_address);
1248 proto_tree_add_uint(tree, hf_usb_bus_id, tvb, 0, 0,
1249 pinfo->pseudo_header->linux_usb.bus_id);
1251 /* Right after the pseudo header we always have
1252 * sizeof(struct usb_device_setup_hdr)=8 bytes. The content of these
1253 * bytes have only meaning in case setup_flag == 0.
1255 if (pinfo->pseudo_header->linux_usb.setup_flag == 0) {
1256 proto_tree_add_string_format_value(tree, hf_usb_setup_flag, tvb,
1258 &(pinfo->pseudo_header->linux_usb.setup_flag),
1260 pinfo->pseudo_header->linux_usb.setup_flag);
1262 proto_tree_add_string_format_value(tree, hf_usb_setup_flag, tvb,
1264 &(pinfo->pseudo_header->linux_usb.setup_flag),
1265 "not present ('%c')",
1266 pinfo->pseudo_header->linux_usb.setup_flag);
1269 if (pinfo->pseudo_header->linux_usb.data_flag == 0) {
1270 proto_tree_add_string_format_value(tree, hf_usb_data_flag, tvb,
1272 &(pinfo->pseudo_header->linux_usb.data_flag),
1274 pinfo->pseudo_header->linux_usb.data_flag);
1276 proto_tree_add_string_format_value(tree, hf_usb_data_flag, tvb,
1278 &(pinfo->pseudo_header->linux_usb.data_flag),
1279 "not present ('%c')",
1280 pinfo->pseudo_header->linux_usb.data_flag);
1283 /* Timestamp was already processed by libpcap,
1285 * pinfo->pseudo_header->linux_usb.ts_sec
1286 * pinfo->pseudo_header->linux_usb.ts_usec
1289 proto_tree_add_int(tree, hf_usb_urb_status, tvb, 0, 0,
1290 pinfo->pseudo_header->linux_usb.status);
1292 proto_tree_add_uint(tree, hf_usb_urb_len, tvb, 0, 0,
1293 pinfo->pseudo_header->linux_usb.urb_len);
1295 proto_tree_add_uint(tree, hf_usb_data_len, tvb, 0, 0,
1296 pinfo->pseudo_header->linux_usb.data_len);
1301 dissect_linux_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent)
1306 proto_tree *tree = NULL;
1307 guint32 src_device, dst_device, tmp_addr;
1308 static usb_address_t src_addr, dst_addr; /* has to be static due to SET_ADDRESS */
1309 guint32 src_endpoint, dst_endpoint;
1310 gboolean is_request=FALSE;
1311 usb_conv_info_t *usb_conv_info=NULL;
1312 usb_trans_info_t *usb_trans_info=NULL;
1313 conversation_t *conversation;
1314 usb_tap_data_t *tap_data=NULL;
1316 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1317 col_set_str(pinfo->cinfo, COL_PROTOCOL, "USB");
1321 proto_item *ti = NULL;
1322 ti = proto_tree_add_protocol_format(parent, proto_usb, tvb, 0, sizeof(struct usb_device_setup_hdr), "USB URB");
1324 tree = proto_item_add_subtree(ti, usb_hdr);
1327 dissect_linux_usb_pseudo_header(tvb, pinfo, tree);
1329 type = pinfo->pseudo_header->linux_usb.transfer_type;
1331 /* The direction flag is broken so we must strip it off */
1332 endpoint=pinfo->pseudo_header->linux_usb.endpoint_number;
1334 endpoint=pinfo->pseudo_header->linux_usb.endpoint_number&(~URB_TRANSFER_IN);
1336 tmp_addr=pinfo->pseudo_header->linux_usb.device_address;
1337 setup_flag = pinfo->pseudo_header->linux_usb.setup_flag;
1340 /* this is how it is supposed to work but this flag seems to be broken -- ronnie */
1341 is_request = endpoint & URB_TRANSFER_IN;
1343 /* Determine whether this is a request or a response */
1347 case URB_ISOCHRONOUS:
1348 switch(pinfo->pseudo_header->linux_usb.event_type){
1357 DISSECTOR_ASSERT_NOT_REACHED();
1361 switch(pinfo->pseudo_header->linux_usb.event_type){
1370 DISSECTOR_ASSERT_NOT_REACHED();
1374 DISSECTOR_ASSERT_NOT_REACHED();
1378 /* Set up addresses and ports.
1379 * Note that URB_INTERRUPT goes in the reverse direction and thus
1380 * the request comes from the device and not the host.
1382 if ( (is_request&&(type!=URB_INTERRUPT))
1383 || (!is_request&&(type==URB_INTERRUPT)) ){
1384 src_addr.device = src_device = 0xffffffff;
1385 src_addr.endpoint = src_endpoint = NO_ENDPOINT;
1386 dst_addr.device = dst_device = htolel(tmp_addr);
1387 dst_addr.endpoint = dst_endpoint = htolel(endpoint);
1389 src_addr.device = src_device = htolel(tmp_addr);
1390 src_addr.endpoint = src_endpoint = htolel(endpoint);
1391 dst_addr.device = dst_device = 0xffffffff;
1392 dst_addr.endpoint = dst_endpoint = NO_ENDPOINT;
1395 SET_ADDRESS(&pinfo->net_src, AT_USB, USB_ADDR_LEN, (char *)&src_addr);
1396 SET_ADDRESS(&pinfo->src, AT_USB, USB_ADDR_LEN, (char *)&src_addr);
1397 SET_ADDRESS(&pinfo->net_dst, AT_USB, USB_ADDR_LEN, (char *)&dst_addr);
1398 SET_ADDRESS(&pinfo->dst, AT_USB, USB_ADDR_LEN, (char *)&dst_addr);
1399 pinfo->ptype=PT_USB;
1400 pinfo->srcport=src_endpoint;
1401 pinfo->destport=dst_endpoint;
1403 conversation=get_usb_conversation(pinfo, &pinfo->src, &pinfo->dst, pinfo->srcport, pinfo->destport);
1405 usb_conv_info=get_usb_conv_info(conversation);
1406 pinfo->usb_conv_info=usb_conv_info;
1409 /* request/response matching so we can keep track of transaction specific
1413 /* this is a request */
1414 usb_trans_info=se_tree_lookup32(usb_conv_info->transactions, pinfo->fd->num);
1415 if(!usb_trans_info){
1416 usb_trans_info=se_alloc0(sizeof(usb_trans_info_t));
1417 usb_trans_info->request_in=pinfo->fd->num;
1418 usb_trans_info->req_time=pinfo->fd->abs_ts;
1419 se_tree_insert32(usb_conv_info->transactions, pinfo->fd->num, usb_trans_info);
1421 usb_conv_info->usb_trans_info=usb_trans_info;
1423 if(usb_trans_info && usb_trans_info->response_in){
1426 ti=proto_tree_add_uint(tree, hf_usb_response_in, tvb, 0, 0, usb_trans_info->response_in);
1427 PROTO_ITEM_SET_GENERATED(ti);
1430 /* this is a response */
1431 if(pinfo->fd->flags.visited){
1432 usb_trans_info=se_tree_lookup32(usb_conv_info->transactions, pinfo->fd->num);
1434 usb_trans_info=se_tree_lookup32_le(usb_conv_info->transactions, pinfo->fd->num);
1436 usb_trans_info->response_in=pinfo->fd->num;
1437 se_tree_insert32(usb_conv_info->transactions, pinfo->fd->num, usb_trans_info);
1440 usb_conv_info->usb_trans_info=usb_trans_info;
1442 if(usb_trans_info && usb_trans_info->request_in){
1446 ti=proto_tree_add_uint(tree, hf_usb_request_in, tvb, 0, 0, usb_trans_info->request_in);
1447 PROTO_ITEM_SET_GENERATED(ti);
1449 t = pinfo->fd->abs_ts;
1450 nstime_delta(&deltat, &t, &usb_trans_info->req_time);
1451 ti=proto_tree_add_time(tree, hf_usb_time, tvb, 0, 0, &deltat);
1452 PROTO_ITEM_SET_GENERATED(ti);
1456 /* For DLT189 it seems
1457 * that all INTERRUPT or BULK packets as well as all CONTROL responses
1458 * are prepended with 8 mysterious bytes.
1462 if(pinfo->pseudo_header->linux_usb.event_type!=URB_SUBMIT){
1467 case URB_ISOCHRONOUS:
1472 DISSECTOR_ASSERT_NOT_REACHED();
1475 tap_data=ep_alloc(sizeof(usb_tap_data_t));
1476 tap_data->urb_type=(guint8)pinfo->pseudo_header->linux_usb.event_type;
1477 tap_data->transfer_type=(guint8)type;
1478 tap_data->conv_info=usb_conv_info;
1479 tap_data->trans_info=usb_trans_info;
1480 tap_queue_packet(usb_tap, pinfo, tap_data);
1488 item=proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, 0, 0, usb_conv_info->interfaceClass);
1489 PROTO_ITEM_SET_GENERATED(item);
1490 if(tvb_reported_length_remaining(tvb, offset)){
1493 pinfo->usb_conv_info=usb_conv_info;
1494 next_tvb=tvb_new_subset(tvb, offset, -1, -1);
1495 if(dissector_try_port(usb_bulk_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, parent)){
1503 const usb_setup_dissector_table_t *tmp;
1504 usb_setup_dissector dissector;
1505 proto_item *ti = NULL;
1506 proto_tree *setup_tree = NULL;
1509 ti=proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, offset, 0, usb_conv_info->interfaceClass);
1510 PROTO_ITEM_SET_GENERATED(ti);
1513 if (setup_flag == 0) {
1516 /* this is a request */
1517 ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset, sizeof(struct usb_device_setup_hdr), "URB setup");
1518 setup_tree = proto_item_add_subtree(ti, usb_setup_hdr);
1519 usb_trans_info->requesttype=tvb_get_guint8(tvb, offset);
1520 offset=dissect_usb_bmrequesttype(setup_tree, tvb, offset, &type);
1523 /* read the request code and spawn off to a class specific
1524 * dissector if found
1526 usb_trans_info->request=tvb_get_guint8(tvb, offset);
1530 case RQT_SETUP_TYPE_STANDARD:
1532 * This is a standard request which is managed by this
1535 proto_tree_add_item(setup_tree, hf_usb_request, tvb, offset, 1, TRUE);
1538 if (check_col(pinfo->cinfo, COL_INFO)) {
1539 col_clear(pinfo->cinfo, COL_INFO);
1540 col_append_fstr(pinfo->cinfo, COL_INFO, "%s Request",
1541 val_to_str(usb_trans_info->request, setup_request_names_vals, "Unknown type %x"));
1545 for(tmp=setup_dissectors;tmp->dissector;tmp++){
1546 if(tmp->request==usb_trans_info->request){
1547 dissector=tmp->dissector;
1553 dissector(pinfo, setup_tree, tvb, offset, is_request, usb_trans_info, usb_conv_info);
1556 proto_tree_add_item(setup_tree, hf_usb_value, tvb, offset, 2, TRUE);
1558 proto_tree_add_item(setup_tree, hf_usb_index, tvb, offset, 2, TRUE);
1560 proto_tree_add_item(setup_tree, hf_usb_length, tvb, offset, 2, TRUE);
1565 case RQT_SETUP_TYPE_CLASS:
1566 /* Try to find a class specific dissector */
1567 next_tvb=tvb_new_subset(tvb, offset, -1, -1);
1568 if(dissector_try_port(usb_control_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, tree)){
1570 /* XXX - dump as hex */
1580 /* this is a response */
1582 /* Try to find a class specific dissector */
1583 next_tvb=tvb_new_subset(tvb, offset, -1, -1);
1584 if(dissector_try_port(usb_control_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, tree)){
1588 type = (usb_trans_info->requesttype & USB_TYPE_MASK) >>5;
1591 case RQT_SETUP_TYPE_STANDARD:
1593 * This is a standard reply which is managed by this
1596 if (check_col(pinfo->cinfo, COL_INFO)) {
1597 col_clear(pinfo->cinfo, COL_INFO);
1598 col_append_fstr(pinfo->cinfo, COL_INFO, "%s Response",
1599 val_to_str(usb_conv_info->usb_trans_info->request, setup_request_names_vals, "Unknown type %x"));
1603 for(tmp=setup_dissectors;tmp->dissector;tmp++){
1604 if(tmp->request==usb_conv_info->usb_trans_info->request){
1605 dissector=tmp->dissector;
1611 offset = dissector(pinfo, tree, tvb, offset, is_request, usb_conv_info->usb_trans_info, usb_conv_info);
1613 proto_tree_add_text(tree, tvb, offset, -1, "CONTROL response data");
1614 offset += tvb_length_remaining(tvb, offset);
1618 /* no matching request available */
1619 proto_tree_add_text(tree, tvb, offset, -1, "CONTROL response data");
1620 offset += tvb_length_remaining(tvb, offset);
1627 if (setup_flag == 0) {
1628 proto_item *ti = NULL;
1629 proto_tree *setup_tree = NULL;
1630 guint8 requesttype, request;
1633 ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset, sizeof(struct usb_device_setup_hdr), "URB setup");
1634 setup_tree = proto_item_add_subtree(ti, usb_setup_hdr);
1637 requesttype=tvb_get_guint8(tvb, offset);
1638 offset=dissect_usb_bmrequesttype(setup_tree, tvb, offset, &type);
1640 request=tvb_get_guint8(tvb, offset);
1641 proto_tree_add_item(setup_tree, hf_usb_request, tvb, offset, 1, TRUE);
1644 proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, TRUE);
1646 proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, TRUE);
1648 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1655 if (tvb_reported_length_remaining(tvb, offset) != 0)
1656 proto_tree_add_item(tree, hf_usb_data, tvb, offset, -1, FALSE);
1660 proto_register_usb(void)
1662 static hf_register_info hf[] = {
1664 /* USB packet pseudoheader members */
1666 { "URB id", "usb.urb_id", FT_UINT64, BASE_HEX,
1671 { "URB type", "usb.urb_type", FT_STRING, BASE_NONE,
1673 "URB type", HFILL }},
1675 { &hf_usb_transfer_type,
1676 { "URB transfer type", "usb.transfer_type", FT_UINT8, BASE_DEC,
1677 VALS(usb_transfer_type_vals), 0x0,
1678 "URB transfer type", HFILL }},
1680 { &hf_usb_endpoint_number,
1681 { "Endpoint", "usb.endpoint_number", FT_UINT8, BASE_HEX, NULL, 0x0,
1682 "USB endpoint number", HFILL }},
1684 { &hf_usb_device_address,
1685 { "Device", "usb.device_address", FT_UINT8, BASE_DEC, NULL, 0x0,
1686 "USB device address", HFILL }},
1689 { "URB bus id", "usb.bus_id", FT_UINT16, BASE_DEC,
1691 "URB bus id", HFILL }},
1693 { &hf_usb_setup_flag,
1694 { "Device setup request", "usb.setup_flag", FT_STRING, BASE_NONE,
1696 "USB device setup request is present (0) or not", HFILL }},
1698 { &hf_usb_data_flag,
1699 { "Data", "usb.data_flag", FT_STRING, BASE_NONE,
1701 "USB data is present (0) or not", HFILL }},
1703 { &hf_usb_urb_status,
1704 { "URB status", "usb.urb_status", FT_INT32, BASE_DEC,
1705 VALS(usb_urb_status_vals), 0x0,
1706 "URB status", HFILL }},
1709 { "URB length [bytes]", "usb.urb_len", FT_UINT32, BASE_DEC, NULL, 0x0,
1710 "URB length in bytes", HFILL }},
1713 { "Data length [bytes]", "usb.data_len", FT_UINT32, BASE_DEC, NULL, 0x0,
1714 "URB data length in bytes", HFILL }},
1716 /* Generated values */
1717 { &hf_usb_src_endpoint_number,
1718 { "Src Endpoint", "usb.src.endpoint", FT_UINT8, BASE_HEX, NULL, 0x0,
1719 "Source USB endpoint number", HFILL }},
1721 { &hf_usb_dst_endpoint_number,
1722 { "Dst Endpoint", "usb.dst.endpoint", FT_UINT8, BASE_HEX, NULL, 0x0,
1723 "Destination USB endpoint number", HFILL }},
1725 /* Fields from usb20.pdf, Table 9-2 'Format of Setup Data' */
1726 { &hf_usb_bmRequestType,
1727 { "bmRequestType", "usb.bmRequestType", FT_UINT8, BASE_HEX, NULL, 0x0,
1731 { "bRequest", "usb.setup.bRequest", FT_UINT8, BASE_DEC, VALS(setup_request_names_vals), 0x0,
1735 { "wValue", "usb.setup.wValue", FT_UINT16, BASE_HEX, NULL, 0x0,
1739 { "wIndex", "usb.setup.wIndex", FT_UINT16, BASE_DEC, NULL, 0x0,
1743 { "wLength", "usb.setup.wLength", FT_UINT16, BASE_DEC, NULL, 0x0,
1746 /* --------------------------------- */
1748 {"Application Data", "usb.data",
1749 FT_BYTES, BASE_HEX, NULL, 0x0,
1750 "Payload is application data", HFILL }},
1752 { &hf_usb_bmRequestType_direction,
1753 { "Direction", "usb.bmRequestType.direction", FT_BOOLEAN, 8,
1754 TFS(&tfs_bmrequesttype_direction), USB_DIR_IN, "", HFILL }},
1756 { &hf_usb_bmRequestType_type,
1757 { "Type", "usb.bmRequestType.type", FT_UINT8, BASE_HEX,
1758 VALS(bmrequesttype_type_vals), USB_TYPE_MASK, "", HFILL }},
1760 { &hf_usb_bmRequestType_recipient,
1761 { "Recipient", "usb.bmRequestType.recipient", FT_UINT8, BASE_HEX,
1762 VALS(bmrequesttype_recipient_vals), 0x1f, "", HFILL }},
1764 { &hf_usb_bDescriptorType,
1765 { "bDescriptorType", "usb.bDescriptorType", FT_UINT8, BASE_HEX,
1766 VALS(descriptor_type_vals), 0x0, "", HFILL }},
1768 { &hf_usb_descriptor_index,
1769 { "Descriptor Index", "usb.DescriptorIndex", FT_UINT8, BASE_HEX,
1770 NULL, 0x0, "", HFILL }},
1772 { &hf_usb_language_id,
1773 { "Language Id", "usb.LanguageId", FT_UINT16, BASE_HEX,
1774 VALS(usb_langid_vals), 0x0, "", HFILL }},
1777 { "bLength", "usb.bLength", FT_UINT8, BASE_DEC,
1778 NULL, 0x0, "", HFILL }},
1781 { "bcdUSB", "usb.bcdUSB", FT_UINT16, BASE_HEX,
1782 NULL, 0x0, "", HFILL }},
1784 { &hf_usb_bDeviceClass,
1785 { "bDeviceClass", "usb.bDeviceClass", FT_UINT8, BASE_DEC,
1786 NULL, 0x0, "", HFILL }},
1788 { &hf_usb_bDeviceSubClass,
1789 { "bDeviceSubClass", "usb.bDeviceSubClass", FT_UINT8, BASE_DEC,
1790 NULL, 0x0, "", HFILL }},
1792 { &hf_usb_bDeviceProtocol,
1793 { "bDeviceProtocol", "usb.bDeviceProtocol", FT_UINT8, BASE_DEC,
1794 NULL, 0x0, "", HFILL }},
1796 { &hf_usb_bMaxPacketSize0,
1797 { "bMaxPacketSize0", "usb.bMaxPacketSize0", FT_UINT8, BASE_DEC,
1798 NULL, 0x0, "", HFILL }},
1801 { "idVendor", "usb.idVendor", FT_UINT16, BASE_HEX,
1802 NULL, 0x0, "", HFILL }},
1804 { &hf_usb_idProduct,
1805 { "idProduct", "usb.idProduct", FT_UINT16, BASE_HEX,
1806 NULL, 0x0, "", HFILL }},
1808 { &hf_usb_bcdDevice,
1809 { "bcdDevice", "usb.bcdDevice", FT_UINT16, BASE_HEX,
1810 NULL, 0x0, "", HFILL }},
1812 { &hf_usb_iManufacturer,
1813 { "iManufacturer", "usb.iManufacturer", FT_UINT8, BASE_DEC,
1814 NULL, 0x0, "", HFILL }},
1817 { "iProduct", "usb.iProduct", FT_UINT8, BASE_DEC,
1818 NULL, 0x0, "", HFILL }},
1820 { &hf_usb_iSerialNumber,
1821 { "iSerialNumber", "usb.iSerialNumber", FT_UINT8, BASE_DEC,
1822 NULL, 0x0, "", HFILL }},
1824 { &hf_usb_bNumConfigurations,
1825 { "bNumConfigurations", "usb.bNumConfigurations", FT_UINT8, BASE_DEC,
1826 NULL, 0x0, "", HFILL }},
1829 { "wLANGID", "usb.wLANGID", FT_UINT16, BASE_HEX,
1830 VALS(usb_langid_vals), 0x0, "", HFILL }},
1833 { "bString", "usb.bString", FT_STRING, BASE_NONE,
1834 NULL, 0x0, "", HFILL }},
1836 { &hf_usb_bInterfaceNumber,
1837 { "bInterfaceNumber", "usb.bInterfaceNumber", FT_UINT8, BASE_DEC,
1838 NULL, 0x0, "", HFILL }},
1840 { &hf_usb_bAlternateSetting,
1841 { "bAlternateSetting","usb.bAlternateSetting", FT_UINT8, BASE_DEC,
1842 NULL, 0x0, "", HFILL }},
1844 { &hf_usb_bNumEndpoints,
1845 { "bNumEndpoints","usb.bNumEndpoints", FT_UINT8, BASE_DEC,
1846 NULL, 0x0, "", HFILL }},
1848 { &hf_usb_bInterfaceClass,
1849 { "bInterfaceClass", "usb.bInterfaceClass", FT_UINT8, BASE_HEX,
1850 VALS(usb_interfaceclass_vals), 0x0, "", HFILL }},
1852 { &hf_usb_bInterfaceSubClass,
1853 { "bInterfaceSubClass", "usb.bInterfaceSubClass", FT_UINT8, BASE_HEX,
1854 NULL, 0x0, "", HFILL }},
1856 { &hf_usb_bInterfaceProtocol,
1857 { "bInterfaceProtocol", "usb.bInterfaceProtocol", FT_UINT8, BASE_HEX,
1858 NULL, 0x0, "", HFILL }},
1860 { &hf_usb_iInterface,
1861 { "iInterface", "usb.iInterface", FT_UINT8, BASE_DEC,
1862 NULL, 0x0, "", HFILL }},
1864 { &hf_usb_bEndpointAddress,
1865 { "bEndpointAddress", "usb.bEndpointAddress", FT_UINT8, BASE_HEX,
1866 NULL, 0x0, "", HFILL }},
1868 { &hf_usb_configuration_bmAttributes,
1869 { "Configuration bmAttributes", "usb.configuration.bmAttributes", FT_UINT8, BASE_HEX,
1870 NULL, 0x0, "", HFILL }},
1872 { &hf_usb_bmAttributes,
1873 { "bmAttributes", "usb.bmAttributes", FT_UINT8, BASE_HEX,
1874 NULL, 0x0, "", HFILL }},
1876 { &hf_usb_bEndpointAttributeTransfer,
1877 { "Transfertype", "usb.bmAttributes.transfer", FT_UINT8, BASE_HEX,
1878 VALS(usb_bmAttributes_transfer_vals), 0x03, "", HFILL }},
1880 { &hf_usb_bEndpointAttributeSynchonisation,
1881 { "Synchronisationtype", "usb.bmAttributes.sync", FT_UINT8, BASE_HEX,
1882 VALS(usb_bmAttributes_sync_vals), 0x0c, "", HFILL }},
1884 { &hf_usb_bEndpointAttributeBehaviour,
1885 { "Behaviourtype", "usb.bmAttributes.behaviour", FT_UINT8, BASE_HEX,
1886 VALS(usb_bmAttributes_behaviour_vals), 0x30, "", HFILL }},
1888 { &hf_usb_wMaxPacketSize,
1889 { "wMaxPacketSize", "usb.wMaxPacketSize", FT_UINT16, BASE_DEC,
1890 NULL, 0x0, "", HFILL }},
1892 { &hf_usb_bInterval,
1893 { "bInterval", "usb.bInterval", FT_UINT8, BASE_DEC,
1894 NULL, 0x0, "", HFILL }},
1896 { &hf_usb_wTotalLength,
1897 { "wTotalLength", "usb.wTotalLength", FT_UINT16, BASE_DEC,
1898 NULL, 0x0, "", HFILL }},
1900 { &hf_usb_bNumInterfaces,
1901 { "bNumInterfaces", "usb.bNumInterfaces", FT_UINT8, BASE_DEC,
1902 NULL, 0x0, "", HFILL }},
1904 { &hf_usb_bConfigurationValue,
1905 { "bConfigurationValue", "usb.bConfigurationValue", FT_UINT8, BASE_DEC,
1906 NULL, 0x0, "", HFILL }},
1908 { &hf_usb_iConfiguration,
1909 { "iConfiguration", "usb.iConfiguration", FT_UINT8, BASE_DEC,
1910 NULL, 0x0, "", HFILL }},
1912 { &hf_usb_bMaxPower,
1913 { "bMaxPower", "usb.bMaxPower", FT_UINT8, BASE_DEC,
1914 NULL, 0x0, "", HFILL }},
1916 { &hf_usb_configuration_legacy10buspowered,
1917 { "Must be 1", "usb.configuration.legacy10buspowered", FT_BOOLEAN, 8,
1918 TFS(&tfs_mustbeone), 0x80, "Legacy USB 1.0 bus powered", HFILL }},
1920 { &hf_usb_configuration_selfpowered,
1921 { "Self-Powered", "usb.configuration.selfpowered", FT_BOOLEAN, 8,
1922 TFS(&tfs_selfpowered), 0x40, "", HFILL }},
1924 { &hf_usb_configuration_remotewakeup,
1925 { "Remote Wakeup", "usb.configuration.remotewakeup", FT_BOOLEAN, 8,
1926 TFS(&tfs_remotewakeup), 0x20, "", HFILL }},
1928 { &hf_usb_bEndpointAddress_number,
1929 { "Endpoint Number", "usb.bEndpointAddress.number", FT_UINT8, BASE_HEX,
1930 NULL, 0x0f, "", HFILL }},
1932 { &hf_usb_bEndpointAddress_direction,
1933 { "Direction", "usb.bEndpointAddress.direction", FT_BOOLEAN, 8,
1934 TFS(&tfs_endpoint_direction), 0x80, "", HFILL }},
1936 { &hf_usb_request_in,
1937 { "Request in", "usb.request_in", FT_FRAMENUM, BASE_NONE,
1938 NULL, 0, "The request to this packet is in this packet", HFILL }},
1941 { "Time from request", "usb.time", FT_RELATIVE_TIME, BASE_NONE,
1942 NULL, 0, "Time between Request and Response for USB cmds", HFILL }},
1944 { &hf_usb_response_in,
1945 { "Response in", "usb.response_in", FT_FRAMENUM, BASE_NONE,
1946 NULL, 0, "The response to this packet is in this packet", HFILL }},
1950 static gint *usb_subtrees[] = {
1953 &ett_usb_setup_bmrequesttype,
1954 &ett_descriptor_device,
1955 &ett_configuration_bmAttributes,
1956 &ett_configuration_bEndpointAddress,
1957 &ett_endpoint_bmAttributes
1961 proto_usb = proto_register_protocol("USB", "USB", "usb");
1962 proto_register_field_array(proto_usb, hf, array_length(hf));
1963 proto_register_subtree_array(usb_subtrees, array_length(usb_subtrees));
1965 usb_bulk_dissector_table = register_dissector_table("usb.bulk",
1966 "USB bulk endpoint", FT_UINT8, BASE_DEC);
1968 usb_control_dissector_table = register_dissector_table("usb.control",
1969 "USB control endpoint", FT_UINT8, BASE_DEC);
1971 usb_tap=register_tap("usb");
1975 proto_reg_handoff_usb(void)
1977 dissector_handle_t linux_usb_handle;
1979 linux_usb_handle = create_dissector_handle(dissect_linux_usb, proto_usb);
1981 dissector_add("wtap_encap", WTAP_ENCAP_USB_LINUX, linux_usb_handle);