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);
741 proto_item_set_len(item, offset-old_offset);
751 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)
753 proto_item *item=NULL;
754 proto_tree *tree=NULL;
755 int old_offset=offset;
758 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "INTERFACE DESCRIPTOR");
759 tree=proto_item_add_subtree(item, ett_descriptor_device);
763 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
766 /* bDescriptorType */
767 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
770 /* bInterfaceNumber */
771 proto_tree_add_item(tree, hf_usb_bInterfaceNumber, tvb, offset, 1, TRUE);
774 /* bAlternateSetting */
775 proto_tree_add_item(tree, hf_usb_bAlternateSetting, tvb, offset, 1, TRUE);
779 proto_tree_add_item(tree, hf_usb_bNumEndpoints, tvb, offset, 1, TRUE);
782 /* bInterfaceClass */
783 proto_tree_add_item(tree, hf_usb_bInterfaceClass, tvb, offset, 1, TRUE);
784 /* save the class so we can access it later in the endpoint descriptor */
785 usb_conv_info->interfaceClass=tvb_get_guint8(tvb, offset);
786 if(!pinfo->fd->flags.visited){
787 usb_trans_info->interface_info=se_alloc0(sizeof(usb_conv_info_t));
788 usb_trans_info->interface_info->interfaceClass=tvb_get_guint8(tvb, offset);
789 usb_trans_info->interface_info->transactions=se_tree_create_non_persistent(EMEM_TREE_TYPE_RED_BLACK, "usb transactions");
793 /* bInterfaceSubClass */
794 proto_tree_add_item(tree, hf_usb_bInterfaceSubClass, tvb, offset, 1, TRUE);
797 /* bInterfaceProtocol */
798 proto_tree_add_item(tree, hf_usb_bInterfaceProtocol, tvb, offset, 1, TRUE);
802 proto_tree_add_item(tree, hf_usb_iInterface, tvb, offset, 1, TRUE);
806 proto_item_set_len(item, offset-old_offset);
813 static const true_false_string tfs_endpoint_direction = {
818 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_)
820 proto_item *item=NULL;
821 proto_tree *tree=NULL;
822 proto_item *endpoint_item=NULL;
823 proto_tree *endpoint_tree=NULL;
824 proto_item *ep_attrib_item=NULL;
825 proto_tree *ep_attrib_tree=NULL;
826 int old_offset=offset;
830 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "ENDPOINT DESCRIPTOR");
831 tree=proto_item_add_subtree(item, ett_descriptor_device);
835 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
838 /* bDescriptorType */
839 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
842 /* bEndpointAddress */
844 endpoint_item=proto_tree_add_item(tree, hf_usb_bEndpointAddress, tvb, offset, 1, TRUE);
845 endpoint_tree=proto_item_add_subtree(endpoint_item, ett_configuration_bEndpointAddress);
847 endpoint=tvb_get_guint8(tvb, offset)&0x0f;
848 proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_direction, tvb, offset, 1, TRUE);
849 proto_item_append_text(endpoint_item, " %s", (tvb_get_guint8(tvb, offset)&0x80)?"IN":"OUT");
850 proto_tree_add_item(endpoint_tree, hf_usb_bEndpointAddress_number, tvb, offset, 1, TRUE);
851 proto_item_append_text(endpoint_item, " Endpoint:%d", endpoint);
854 /* Together with class from the interface descriptor we know what kind
855 * of class the device at endpoint is.
856 * Make sure a conversation exists for this endpoint and attach a
857 * usb_conv_into_t structure to it.
859 * All endpoints for the same interface descriptor share the same
860 * usb_conv_info structure.
862 if((!pinfo->fd->flags.visited)&&usb_trans_info->interface_info){
863 conversation_t *conversation;
865 if(pinfo->destport==NO_ENDPOINT){
866 static address tmp_addr;
867 static usb_address_t usb_addr;
869 /* Create a new address structure that points to the same device
870 * but the new endpoint.
872 usb_addr.device=((usb_address_t *)(pinfo->src.data))->device;
873 usb_addr.endpoint=endpoint;
874 SET_ADDRESS(&tmp_addr, AT_USB, USB_ADDR_LEN, (char *)&usb_addr);
875 conversation=get_usb_conversation(pinfo, &tmp_addr, &pinfo->dst, endpoint, pinfo->destport);
877 static address tmp_addr;
878 static usb_address_t usb_addr;
880 /* Create a new address structure that points to the same device
881 * but the new endpoint.
883 usb_addr.device=((usb_address_t *)(pinfo->dst.data))->device;
884 usb_addr.endpoint=endpoint;
885 SET_ADDRESS(&tmp_addr, AT_USB, USB_ADDR_LEN, (char *)&usb_addr);
886 conversation=get_usb_conversation(pinfo, &pinfo->src, &tmp_addr, pinfo->srcport, endpoint);
889 conversation_add_proto_data(conversation, proto_usb, usb_trans_info->interface_info);
894 ep_attrib_item=proto_tree_add_item(tree, hf_usb_bmAttributes, tvb, offset, 1, TRUE);
895 ep_attrib_tree=proto_item_add_subtree(ep_attrib_item, ett_endpoint_bmAttributes);
897 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeTransfer, tvb, offset, 1, TRUE);
898 /* isochronous only */
899 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeSynchonisation, tvb, offset, 1, TRUE);
900 /* isochronous only */
901 proto_tree_add_item(ep_attrib_tree, hf_usb_bEndpointAttributeBehaviour, tvb, offset, 1, TRUE);
905 proto_tree_add_item(tree, hf_usb_wMaxPacketSize, tvb, offset, 2, TRUE);
909 proto_tree_add_item(tree, hf_usb_bInterval, tvb, offset, 1, TRUE);
913 proto_item_set_len(item, offset-old_offset);
920 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_)
922 proto_item *item=NULL;
923 proto_tree *tree=NULL;
924 int old_offset=offset;
928 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "UNKNOWN DESCRIPTOR");
929 tree=proto_item_add_subtree(item, ett_descriptor_device);
933 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
934 bLength = tvb_get_guint8(tvb, offset);
937 item = proto_tree_add_text(parent_tree, tvb, offset - 1, 1,
938 "Invalid bLength: %u", bLength);
939 expert_add_info_format(pinfo, item, PI_MALFORMED, PI_ERROR,
940 "Invalid bLength: %u", bLength);
944 /* bDescriptorType */
945 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
948 offset += bLength - 2;
951 proto_item_set_len(item, offset-old_offset);
958 static const true_false_string tfs_mustbeone = {
959 "Must be 1 for USB 1.1 and higher",
960 "FIXME: Is this a USB 1.0 device"
962 static const true_false_string tfs_selfpowered = {
963 "This device is SELF-POWERED",
964 "This device is powered from the USB bus"
966 static const true_false_string tfs_remotewakeup = {
967 "This device supports REMOTE WAKEUP",
968 "This device does NOT support remote wakeup"
971 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)
973 proto_item *item=NULL;
974 proto_tree *tree=NULL;
975 int old_offset=offset;
977 proto_item *flags_item=NULL;
978 proto_tree *flags_tree=NULL;
980 proto_item *power_item=NULL;
984 item=proto_tree_add_text(parent_tree, tvb, offset, 0, "CONFIGURATION DESCRIPTOR");
985 tree=proto_item_add_subtree(item, ett_descriptor_device);
989 proto_tree_add_item(tree, hf_usb_bLength, tvb, offset, 1, TRUE);
992 /* bDescriptorType */
993 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
997 proto_tree_add_item(tree, hf_usb_wTotalLength, tvb, offset, 2, TRUE);
998 len=tvb_get_letohs(tvb, offset);
1001 /* bNumInterfaces */
1002 proto_tree_add_item(tree, hf_usb_bNumInterfaces, tvb, offset, 1, TRUE);
1005 /* bConfigurationValue */
1006 proto_tree_add_item(tree, hf_usb_bConfigurationValue, tvb, offset, 1, TRUE);
1009 /* iConfiguration */
1010 proto_tree_add_item(tree, hf_usb_iConfiguration, tvb, offset, 1, TRUE);
1015 flags_item=proto_tree_add_item(tree, hf_usb_configuration_bmAttributes, tvb, offset, 1, TRUE);
1016 flags_tree=proto_item_add_subtree(flags_item, ett_configuration_bmAttributes);
1018 flags=tvb_get_guint8(tvb, offset);
1019 proto_tree_add_item(flags_tree, hf_usb_configuration_legacy10buspowered, tvb, offset, 1, TRUE);
1020 proto_tree_add_item(flags_tree, hf_usb_configuration_selfpowered, tvb, offset, 1, TRUE);
1021 proto_item_append_text(flags_item, " %sSELF-POWERED", (flags&0x40)?"":"NOT ");
1023 proto_tree_add_item(flags_tree, hf_usb_configuration_remotewakeup, tvb, offset, 1, TRUE);
1024 proto_item_append_text(flags_item, " %sREMOTE-WAKEUP", (flags&0x20)?"":"NO ");
1029 power_item=proto_tree_add_item(tree, hf_usb_bMaxPower, tvb, offset, 1, TRUE);
1030 power=tvb_get_guint8(tvb, offset);
1031 proto_item_append_text(power_item, " (%dmA)", power*2);
1034 /* initialize interface_info to NULL */
1035 usb_trans_info->interface_info=NULL;
1037 /* decode any additional interface and endpoint descriptors */
1038 while(len>(old_offset-offset)){
1041 if(tvb_length_remaining(tvb, offset)<2){
1044 next_type=tvb_get_guint8(tvb, offset+1);
1046 case USB_DT_INTERFACE:
1047 offset=dissect_usb_interface_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1049 case USB_DT_ENDPOINT:
1050 offset=dissect_usb_endpoint_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1053 offset=dissect_usb_unknown_descriptor(pinfo, parent_tree, tvb, offset, usb_trans_info, usb_conv_info);
1055 /* was: return offset; */
1060 proto_item_set_len(item, offset-old_offset);
1068 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)
1071 /* descriptor index */
1072 proto_tree_add_item(tree, hf_usb_descriptor_index, tvb, offset, 1, TRUE);
1073 usb_trans_info->u.get_descriptor.index=tvb_get_guint8(tvb, offset);
1076 /* descriptor type */
1077 proto_tree_add_item(tree, hf_usb_bDescriptorType, tvb, offset, 1, TRUE);
1078 usb_trans_info->u.get_descriptor.type=tvb_get_guint8(tvb, offset);
1080 if (check_col(pinfo->cinfo, COL_INFO)) {
1081 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
1082 val_to_str(usb_trans_info->u.get_descriptor.type, descriptor_type_vals, "Unknown type %x"));
1086 proto_tree_add_item(tree, hf_usb_language_id, tvb, offset, 2, TRUE);
1090 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1093 if (check_col(pinfo->cinfo, COL_INFO)) {
1094 col_append_fstr(pinfo->cinfo, COL_INFO, " %s",
1095 val_to_str(usb_trans_info->u.get_descriptor.type, descriptor_type_vals, "Unknown type %x"));
1097 switch(usb_trans_info->u.get_descriptor.type){
1099 offset=dissect_usb_device_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1102 offset=dissect_usb_configuration_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1105 offset=dissect_usb_string_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1107 case USB_DT_INTERFACE:
1108 offset=dissect_usb_interface_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1110 case USB_DT_ENDPOINT:
1111 offset=dissect_usb_endpoint_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1113 case USB_DT_DEVICE_QUALIFIER:
1114 offset=dissect_usb_device_qualifier_descriptor(pinfo, tree, tvb, offset, usb_trans_info, usb_conv_info);
1117 /* XXX dissect the descriptor coming back from the device */
1118 proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "get descriptor data...");
1126 typedef void (*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);
1128 typedef struct _usb_setup_dissector_table_t {
1130 usb_setup_dissector dissector;
1131 } usb_setup_dissector_table_t;
1132 #define USB_SETUP_GET_DESCRIPTOR 6
1133 static const usb_setup_dissector_table_t setup_dissectors[] = {
1134 {USB_SETUP_GET_DESCRIPTOR, dissect_usb_setup_get_descriptor},
1137 static const value_string setup_request_names_vals[] = {
1138 {USB_SETUP_GET_DESCRIPTOR, "GET DESCRIPTOR"},
1143 #define USB_DIR_OUT 0 /* to device */
1144 #define USB_DIR_IN 0x80 /* to host */
1146 static const true_false_string tfs_bmrequesttype_direction = {
1151 #define USB_TYPE_MASK (0x03 << 5)
1152 #define RQT_SETUP_TYPE_STANDARD 0
1153 #define RQT_SETUP_TYPE_CLASS 1
1154 #define RQT_SETUP_TYPE_VENDOR 2
1156 static const value_string bmrequesttype_type_vals[] = {
1157 {RQT_SETUP_TYPE_STANDARD, "Standard"},
1158 {RQT_SETUP_TYPE_CLASS, "Class"},
1159 {RQT_SETUP_TYPE_VENDOR, "Vendor"},
1162 static const value_string bmrequesttype_recipient_vals[] = {
1171 dissect_usb_bmrequesttype(proto_tree *parent_tree, tvbuff_t *tvb, int offset,
1174 proto_item *item=NULL;
1175 proto_tree *tree=NULL;
1176 guint8 bmRequestType;
1179 item=proto_tree_add_item(parent_tree, hf_usb_bmRequestType, tvb, offset, 1, TRUE);
1180 tree = proto_item_add_subtree(item, ett_usb_setup_bmrequesttype);
1183 bmRequestType = tvb_get_guint8(tvb, offset);
1184 *type = (bmRequestType & USB_TYPE_MASK) >>5;
1185 proto_tree_add_item(tree, hf_usb_bmRequestType_direction, tvb, offset, 1, TRUE);
1186 proto_tree_add_item(tree, hf_usb_bmRequestType_type, tvb, offset, 1, TRUE);
1187 proto_tree_add_item(tree, hf_usb_bmRequestType_recipient, tvb, offset, 1, TRUE);
1194 dissect_linux_usb_pseudo_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1196 guint8 transfer_type;
1197 const gchar* val_str;
1199 proto_tree_add_uint64(tree, hf_usb_urb_id, tvb, 0, 0,
1200 pinfo->pseudo_header->linux_usb.id);
1202 /* show the event type of this URB as string and as a character */
1203 val_str = val_to_str(pinfo->pseudo_header->linux_usb.event_type,
1204 usb_urb_type_vals, "Unknown %d");
1205 proto_tree_add_string_format_value(tree, hf_usb_urb_type, tvb, 0, 0,
1206 &(pinfo->pseudo_header->linux_usb.event_type),
1207 "%s ('%c')", val_str,
1208 pinfo->pseudo_header->linux_usb.event_type);
1210 transfer_type = pinfo->pseudo_header->linux_usb.transfer_type;
1211 proto_tree_add_uint(tree, hf_usb_transfer_type, tvb, 0, 0, transfer_type);
1213 if (check_col(pinfo->cinfo, COL_INFO)) {
1214 col_append_str(pinfo->cinfo, COL_INFO,
1215 val_to_str(transfer_type, usb_transfer_type_vals, "Unknown type %x"));
1218 proto_tree_add_uint(tree, hf_usb_endpoint_number, tvb, 0, 0,
1219 pinfo->pseudo_header->linux_usb.endpoint_number);
1221 proto_tree_add_uint(tree, hf_usb_device_address, tvb, 0, 0,
1222 pinfo->pseudo_header->linux_usb.device_address);
1224 proto_tree_add_uint(tree, hf_usb_bus_id, tvb, 0, 0,
1225 pinfo->pseudo_header->linux_usb.bus_id);
1227 /* Right after the pseudo header we always have
1228 * sizeof(struct usb_device_setup_hdr)=8 bytes. The content of these
1229 * bytes have only meaning in case setup_flag == 0.
1231 if (pinfo->pseudo_header->linux_usb.setup_flag == 0) {
1232 proto_tree_add_string_format_value(tree, hf_usb_setup_flag, tvb,
1233 0, sizeof(struct usb_device_setup_hdr),
1234 &(pinfo->pseudo_header->linux_usb.setup_flag),
1236 pinfo->pseudo_header->linux_usb.setup_flag);
1238 proto_tree_add_string_format_value(tree, hf_usb_setup_flag, tvb,
1239 0, sizeof(struct usb_device_setup_hdr),
1240 &(pinfo->pseudo_header->linux_usb.setup_flag),
1241 "not present ('%c')",
1242 pinfo->pseudo_header->linux_usb.setup_flag);
1245 if (pinfo->pseudo_header->linux_usb.data_flag == 0) {
1246 proto_tree_add_string_format_value(tree, hf_usb_data_flag, tvb,
1247 sizeof(struct usb_device_setup_hdr), -1,
1248 &(pinfo->pseudo_header->linux_usb.data_flag),
1250 pinfo->pseudo_header->linux_usb.data_flag);
1252 proto_tree_add_string_format_value(tree, hf_usb_data_flag, tvb,
1253 sizeof(struct usb_device_setup_hdr), -1,
1254 &(pinfo->pseudo_header->linux_usb.data_flag),
1255 "not present ('%c')",
1256 pinfo->pseudo_header->linux_usb.data_flag);
1259 /* Timestamp was already processed by libpcap,
1261 * pinfo->pseudo_header->linux_usb.ts_sec
1262 * pinfo->pseudo_header->linux_usb.ts_usec
1265 proto_tree_add_int(tree, hf_usb_urb_status, tvb, 0, 0,
1266 pinfo->pseudo_header->linux_usb.status);
1268 proto_tree_add_uint(tree, hf_usb_urb_len, tvb, 0, 0,
1269 pinfo->pseudo_header->linux_usb.urb_len);
1271 proto_tree_add_uint(tree, hf_usb_data_len, tvb,
1272 sizeof(struct usb_device_setup_hdr),
1273 pinfo->pseudo_header->linux_usb.data_len,
1274 pinfo->pseudo_header->linux_usb.data_len);
1279 dissect_linux_usb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent)
1284 proto_tree *tree = NULL;
1285 guint32 src_device, dst_device, tmp_addr;
1286 static usb_address_t src_addr, dst_addr; /* has to be static due to SET_ADDRESS */
1287 guint32 src_endpoint, dst_endpoint;
1288 gboolean is_request=FALSE;
1289 usb_conv_info_t *usb_conv_info=NULL;
1290 usb_trans_info_t *usb_trans_info=NULL;
1291 conversation_t *conversation;
1292 usb_tap_data_t *tap_data=NULL;
1294 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1295 col_set_str(pinfo->cinfo, COL_PROTOCOL, "USB");
1299 proto_item *ti = NULL;
1300 ti = proto_tree_add_protocol_format(parent, proto_usb, tvb, 0, sizeof(struct usb_device_setup_hdr), "USB URB");
1302 tree = proto_item_add_subtree(ti, usb_hdr);
1305 dissect_linux_usb_pseudo_header(tvb, pinfo, tree);
1307 type = pinfo->pseudo_header->linux_usb.transfer_type;
1309 /* The direction flag is broken so we must strip it off */
1310 endpoint=pinfo->pseudo_header->linux_usb.endpoint_number;
1312 endpoint=pinfo->pseudo_header->linux_usb.endpoint_number&(~URB_TRANSFER_IN);
1314 tmp_addr=pinfo->pseudo_header->linux_usb.device_address;
1315 setup_flag = pinfo->pseudo_header->linux_usb.setup_flag;
1318 /* this is how it is supposed to work but this flag seems to be broken -- ronnie */
1319 is_request = endpoint & URB_TRANSFER_IN;
1321 /* Determine whether this is a request or a response */
1325 case URB_ISOCHRONOUS:
1326 switch(pinfo->pseudo_header->linux_usb.event_type){
1335 DISSECTOR_ASSERT_NOT_REACHED();
1339 switch(pinfo->pseudo_header->linux_usb.event_type){
1348 DISSECTOR_ASSERT_NOT_REACHED();
1352 DISSECTOR_ASSERT_NOT_REACHED();
1356 /* Set up addresses and ports.
1357 * Note that URB_INTERRUPT goes in the reverse direction and thus
1358 * the request comes from the device and not the host.
1360 if ( (is_request&&(type!=URB_INTERRUPT))
1361 || (!is_request&&(type==URB_INTERRUPT)) ){
1362 src_addr.device = src_device = 0xffffffff;
1363 src_addr.endpoint = src_endpoint = NO_ENDPOINT;
1364 dst_addr.device = dst_device = htolel(tmp_addr);
1365 dst_addr.endpoint = dst_endpoint = htolel(endpoint);
1367 src_addr.device = src_device = htolel(tmp_addr);
1368 src_addr.endpoint = src_endpoint = htolel(endpoint);
1369 dst_addr.device = dst_device = 0xffffffff;
1370 dst_addr.endpoint = dst_endpoint = NO_ENDPOINT;
1373 SET_ADDRESS(&pinfo->net_src, AT_USB, USB_ADDR_LEN, (char *)&src_addr);
1374 SET_ADDRESS(&pinfo->src, AT_USB, USB_ADDR_LEN, (char *)&src_addr);
1375 SET_ADDRESS(&pinfo->net_dst, AT_USB, USB_ADDR_LEN, (char *)&dst_addr);
1376 SET_ADDRESS(&pinfo->dst, AT_USB, USB_ADDR_LEN, (char *)&dst_addr);
1377 pinfo->ptype=PT_USB;
1378 pinfo->srcport=src_endpoint;
1379 pinfo->destport=dst_endpoint;
1381 conversation=get_usb_conversation(pinfo, &pinfo->src, &pinfo->dst, pinfo->srcport, pinfo->destport);
1383 usb_conv_info=get_usb_conv_info(conversation);
1384 pinfo->usb_conv_info=usb_conv_info;
1387 /* request/response matching so we can keep track of transaction specific
1391 /* this is a request */
1392 usb_trans_info=se_tree_lookup32(usb_conv_info->transactions, pinfo->fd->num);
1393 if(!usb_trans_info){
1394 usb_trans_info=se_alloc0(sizeof(usb_trans_info_t));
1395 usb_trans_info->request_in=pinfo->fd->num;
1396 usb_trans_info->req_time=pinfo->fd->abs_ts;
1397 se_tree_insert32(usb_conv_info->transactions, pinfo->fd->num, usb_trans_info);
1399 usb_conv_info->usb_trans_info=usb_trans_info;
1401 if(usb_trans_info && usb_trans_info->response_in){
1404 ti=proto_tree_add_uint(tree, hf_usb_response_in, tvb, 0, 0, usb_trans_info->response_in);
1405 PROTO_ITEM_SET_GENERATED(ti);
1408 /* this is a response */
1409 if(pinfo->fd->flags.visited){
1410 usb_trans_info=se_tree_lookup32(usb_conv_info->transactions, pinfo->fd->num);
1412 usb_trans_info=se_tree_lookup32_le(usb_conv_info->transactions, pinfo->fd->num);
1414 usb_trans_info->response_in=pinfo->fd->num;
1415 se_tree_insert32(usb_conv_info->transactions, pinfo->fd->num, usb_trans_info);
1418 usb_conv_info->usb_trans_info=usb_trans_info;
1420 if(usb_trans_info && usb_trans_info->request_in){
1424 ti=proto_tree_add_uint(tree, hf_usb_request_in, tvb, 0, 0, usb_trans_info->request_in);
1425 PROTO_ITEM_SET_GENERATED(ti);
1427 t = pinfo->fd->abs_ts;
1428 nstime_delta(&deltat, &t, &usb_trans_info->req_time);
1429 ti=proto_tree_add_time(tree, hf_usb_time, tvb, 0, 0, &deltat);
1430 PROTO_ITEM_SET_GENERATED(ti);
1434 /* For DLT189 it seems
1435 * that all INTERRUPT or BULK packets as well as all CONTROL responses
1436 * are prepended with 8 mysterious bytes.
1440 if(pinfo->pseudo_header->linux_usb.event_type!=URB_SUBMIT){
1445 case URB_ISOCHRONOUS:
1450 DISSECTOR_ASSERT_NOT_REACHED();
1453 tap_data=ep_alloc(sizeof(usb_tap_data_t));
1454 tap_data->urb_type=(guint8)pinfo->pseudo_header->linux_usb.event_type;
1455 tap_data->transfer_type=(guint8)type;
1456 tap_data->conv_info=usb_conv_info;
1457 tap_data->trans_info=usb_trans_info;
1458 tap_queue_packet(usb_tap, pinfo, tap_data);
1466 item=proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, 0, 0, usb_conv_info->interfaceClass);
1467 PROTO_ITEM_SET_GENERATED(item);
1468 if(tvb_length_remaining(tvb, offset)){
1471 pinfo->usb_conv_info=usb_conv_info;
1472 next_tvb=tvb_new_subset(tvb, offset, -1, -1);
1473 if(dissector_try_port(usb_bulk_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, parent)){
1481 const usb_setup_dissector_table_t *tmp;
1482 usb_setup_dissector dissector;
1483 proto_item *ti = NULL;
1484 proto_tree *setup_tree = NULL;
1487 ti=proto_tree_add_uint(tree, hf_usb_bInterfaceClass, tvb, offset, 0, usb_conv_info->interfaceClass);
1488 PROTO_ITEM_SET_GENERATED(ti);
1491 if (setup_flag == 0) {
1494 /* this is a request */
1495 ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset, sizeof(struct usb_device_setup_hdr), "URB setup");
1496 setup_tree = proto_item_add_subtree(ti, usb_setup_hdr);
1497 usb_trans_info->requesttype=tvb_get_guint8(tvb, offset);
1498 offset=dissect_usb_bmrequesttype(setup_tree, tvb, offset, &type);
1501 /* read the request code and spawn off to a class specific
1502 * dissector if found
1504 usb_trans_info->request=tvb_get_guint8(tvb, offset);
1508 case RQT_SETUP_TYPE_STANDARD:
1510 * This is a standard request which is managed by this
1513 proto_tree_add_item(setup_tree, hf_usb_request, tvb, offset, 1, TRUE);
1516 if (check_col(pinfo->cinfo, COL_INFO)) {
1517 col_clear(pinfo->cinfo, COL_INFO);
1518 col_append_fstr(pinfo->cinfo, COL_INFO, "%s Request",
1519 val_to_str(usb_trans_info->request, setup_request_names_vals, "Unknown type %x"));
1523 for(tmp=setup_dissectors;tmp->dissector;tmp++){
1524 if(tmp->request==usb_trans_info->request){
1525 dissector=tmp->dissector;
1531 dissector(pinfo, setup_tree, tvb, offset, is_request, usb_trans_info, usb_conv_info);
1534 proto_tree_add_item(setup_tree, hf_usb_value, tvb, offset, 2, TRUE);
1536 proto_tree_add_item(setup_tree, hf_usb_index, tvb, offset, 2, TRUE);
1538 proto_tree_add_item(setup_tree, hf_usb_length, tvb, offset, 2, TRUE);
1543 case RQT_SETUP_TYPE_CLASS:
1544 /* Try to find a class specific dissector */
1545 next_tvb=tvb_new_subset(tvb, offset, -1, -1);
1546 if(dissector_try_port(usb_control_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, tree)){
1548 /* XXX - dump as hex */
1558 /* this is a response */
1559 if(usb_conv_info->usb_trans_info){
1560 /* Try to find a class specific dissector */
1561 next_tvb=tvb_new_subset(tvb, offset, -1, -1);
1562 if(dissector_try_port(usb_control_dissector_table, usb_conv_info->interfaceClass, next_tvb, pinfo, tree)){
1566 if (check_col(pinfo->cinfo, COL_INFO)) {
1567 col_clear(pinfo->cinfo, COL_INFO);
1568 col_append_fstr(pinfo->cinfo, COL_INFO, "%s Response",
1569 val_to_str(usb_conv_info->usb_trans_info->request, setup_request_names_vals, "Unknown type %x"));
1573 for(tmp=setup_dissectors;tmp->dissector;tmp++){
1574 if(tmp->request==usb_conv_info->usb_trans_info->request){
1575 dissector=tmp->dissector;
1581 dissector(pinfo, tree, tvb, offset, is_request, usb_conv_info->usb_trans_info, usb_conv_info);
1584 /* no matching request available */
1592 if (setup_flag == 0) {
1593 proto_item *ti = NULL;
1594 proto_tree *setup_tree = NULL;
1595 guint8 requesttype, request;
1598 ti = proto_tree_add_protocol_format(tree, proto_usb, tvb, offset, sizeof(struct usb_device_setup_hdr), "URB setup");
1599 setup_tree = proto_item_add_subtree(ti, usb_setup_hdr);
1602 requesttype=tvb_get_guint8(tvb, offset);
1603 offset=dissect_usb_bmrequesttype(setup_tree, tvb, offset, &type);
1605 request=tvb_get_guint8(tvb, offset);
1606 proto_tree_add_item(setup_tree, hf_usb_request, tvb, offset, 1, TRUE);
1609 proto_tree_add_item(tree, hf_usb_value, tvb, offset, 2, TRUE);
1611 proto_tree_add_item(tree, hf_usb_index, tvb, offset, 2, TRUE);
1613 proto_tree_add_item(tree, hf_usb_length, tvb, offset, 2, TRUE);
1621 proto_tree_add_item(tree, hf_usb_data, tvb, offset, -1, FALSE);
1625 proto_register_usb(void)
1627 static hf_register_info hf[] = {
1629 /* USB packet pseudoheader members */
1631 { "URB id", "usb.urb_id", FT_UINT64, BASE_HEX,
1636 { "URB type", "usb.urb_type", FT_STRING, BASE_NONE,
1638 "URB type", HFILL }},
1640 { &hf_usb_transfer_type,
1641 { "URB transfer type", "usb.transfer_type", FT_UINT8, BASE_DEC,
1642 VALS(usb_transfer_type_vals), 0x0,
1643 "URB transfer type", HFILL }},
1645 { &hf_usb_endpoint_number,
1646 { "Endpoint", "usb.endpoint_number", FT_UINT8, BASE_HEX, NULL, 0x0,
1647 "USB endpoint number", HFILL }},
1649 { &hf_usb_device_address,
1650 { "Device", "usb.device_address", FT_UINT8, BASE_DEC, NULL, 0x0,
1651 "USB device address", HFILL }},
1654 { "URB bus id", "usb.bus_id", FT_UINT16, BASE_DEC,
1656 "URB bus id", HFILL }},
1658 { &hf_usb_setup_flag,
1659 { "Device setup request", "usb.setup_flag", FT_STRING, BASE_NONE,
1661 "USB device setup request is present (0) or not", HFILL }},
1663 { &hf_usb_data_flag,
1664 { "Data", "usb.data_flag", FT_STRING, BASE_NONE,
1666 "USB data is present (0) or not", HFILL }},
1668 { &hf_usb_urb_status,
1669 { "URB status", "usb.urb_status", FT_INT32, BASE_DEC,
1670 VALS(usb_urb_status_vals), 0x0,
1671 "URB status", HFILL }},
1674 { "URB length [bytes]", "usb.urb_len", FT_UINT32, BASE_DEC, NULL, 0x0,
1675 "URB length in bytes", HFILL }},
1678 { "Data length [bytes]", "usb.data_len", FT_UINT32, BASE_DEC, NULL, 0x0,
1679 "URB data length in bytes", HFILL }},
1681 /* Generated values */
1682 { &hf_usb_src_endpoint_number,
1683 { "Src Endpoint", "usb.src.endpoint", FT_UINT8, BASE_HEX, NULL, 0x0,
1684 "Source USB endpoint number", HFILL }},
1686 { &hf_usb_dst_endpoint_number,
1687 { "Dst Endpoint", "usb.dst.endpoint", FT_UINT8, BASE_HEX, NULL, 0x0,
1688 "Destination USB endpoint number", HFILL }},
1690 /* Fields from usb20.pdf, Table 9-2 'Format of Setup Data' */
1691 { &hf_usb_bmRequestType,
1692 { "bmRequestType", "usb.bmRequestType", FT_UINT8, BASE_HEX, NULL, 0x0,
1696 { "bRequest", "usb.setup.bRequest", FT_UINT8, BASE_HEX, VALS(setup_request_names_vals), 0x0,
1700 { "wValue", "usb.setup.wValue", FT_UINT16, BASE_HEX, NULL, 0x0,
1704 { "wIndex", "usb.setup.wIndex", FT_UINT16, BASE_DEC, NULL, 0x0,
1708 { "wLength", "usb.setup.wLength", FT_UINT16, BASE_DEC, NULL, 0x0,
1711 /* --------------------------------- */
1713 {"Application Data", "usb.data",
1714 FT_BYTES, BASE_HEX, NULL, 0x0,
1715 "Payload is application data", HFILL }},
1717 { &hf_usb_bmRequestType_direction,
1718 { "Direction", "usb.bmRequestType.direction", FT_BOOLEAN, 8,
1719 TFS(&tfs_bmrequesttype_direction), USB_DIR_IN, "", HFILL }},
1721 { &hf_usb_bmRequestType_type,
1722 { "Type", "usb.bmRequestType.type", FT_UINT8, BASE_HEX,
1723 VALS(bmrequesttype_type_vals), USB_TYPE_MASK, "", HFILL }},
1725 { &hf_usb_bmRequestType_recipient,
1726 { "Recipient", "usb.bmRequestType.recipient", FT_UINT8, BASE_HEX,
1727 VALS(bmrequesttype_recipient_vals), 0x1f, "", HFILL }},
1729 { &hf_usb_bDescriptorType,
1730 { "bDescriptorType", "usb.bDescriptorType", FT_UINT8, BASE_HEX,
1731 VALS(descriptor_type_vals), 0x0, "", HFILL }},
1733 { &hf_usb_descriptor_index,
1734 { "Descriptor Index", "usb.DescriptorIndex", FT_UINT8, BASE_HEX,
1735 NULL, 0x0, "", HFILL }},
1737 { &hf_usb_language_id,
1738 { "Language Id", "usb.LanguageId", FT_UINT16, BASE_HEX,
1739 VALS(usb_langid_vals), 0x0, "", HFILL }},
1742 { "bLength", "usb.bLength", FT_UINT8, BASE_DEC,
1743 NULL, 0x0, "", HFILL }},
1746 { "bcdUSB", "usb.bcdUSB", FT_UINT16, BASE_HEX,
1747 NULL, 0x0, "", HFILL }},
1749 { &hf_usb_bDeviceClass,
1750 { "bDeviceClass", "usb.bDeviceClass", FT_UINT8, BASE_DEC,
1751 NULL, 0x0, "", HFILL }},
1753 { &hf_usb_bDeviceSubClass,
1754 { "bDeviceSubClass", "usb.bDeviceSubClass", FT_UINT8, BASE_DEC,
1755 NULL, 0x0, "", HFILL }},
1757 { &hf_usb_bDeviceProtocol,
1758 { "bDeviceProtocol", "usb.bDeviceProtocol", FT_UINT8, BASE_DEC,
1759 NULL, 0x0, "", HFILL }},
1761 { &hf_usb_bMaxPacketSize0,
1762 { "bMaxPacketSize0", "usb.bMaxPacketSize0", FT_UINT8, BASE_DEC,
1763 NULL, 0x0, "", HFILL }},
1766 { "idVendor", "usb.idVendor", FT_UINT16, BASE_HEX,
1767 NULL, 0x0, "", HFILL }},
1769 { &hf_usb_idProduct,
1770 { "idProduct", "usb.idProduct", FT_UINT16, BASE_HEX,
1771 NULL, 0x0, "", HFILL }},
1773 { &hf_usb_bcdDevice,
1774 { "bcdDevice", "usb.bcdDevice", FT_UINT16, BASE_HEX,
1775 NULL, 0x0, "", HFILL }},
1777 { &hf_usb_iManufacturer,
1778 { "iManufacturer", "usb.iManufacturer", FT_UINT8, BASE_DEC,
1779 NULL, 0x0, "", HFILL }},
1782 { "iProduct", "usb.iProduct", FT_UINT8, BASE_DEC,
1783 NULL, 0x0, "", HFILL }},
1785 { &hf_usb_iSerialNumber,
1786 { "iSerialNumber", "usb.iSerialNumber", FT_UINT8, BASE_DEC,
1787 NULL, 0x0, "", HFILL }},
1789 { &hf_usb_bNumConfigurations,
1790 { "bNumConfigurations", "usb.bNumConfigurations", FT_UINT8, BASE_DEC,
1791 NULL, 0x0, "", HFILL }},
1794 { "wLANGID", "usb.wLANGID", FT_UINT16, BASE_HEX,
1795 VALS(usb_langid_vals), 0x0, "", HFILL }},
1798 { "bString", "usb.bString", FT_STRING, BASE_NONE,
1799 NULL, 0x0, "", HFILL }},
1801 { &hf_usb_bInterfaceNumber,
1802 { "bInterfaceNumber", "usb.bInterfaceNumber", FT_UINT8, BASE_DEC,
1803 NULL, 0x0, "", HFILL }},
1805 { &hf_usb_bAlternateSetting,
1806 { "bAlternateSetting","usb.bAlternateSetting", FT_UINT8, BASE_DEC,
1807 NULL, 0x0, "", HFILL }},
1809 { &hf_usb_bNumEndpoints,
1810 { "bNumEndpoints","usb.bNumEndpoints", FT_UINT8, BASE_DEC,
1811 NULL, 0x0, "", HFILL }},
1813 { &hf_usb_bInterfaceClass,
1814 { "bInterfaceClass", "usb.bInterfaceClass", FT_UINT8, BASE_HEX,
1815 VALS(usb_interfaceclass_vals), 0x0, "", HFILL }},
1817 { &hf_usb_bInterfaceSubClass,
1818 { "bInterfaceSubClass", "usb.bInterfaceSubClass", FT_UINT8, BASE_HEX,
1819 NULL, 0x0, "", HFILL }},
1821 { &hf_usb_bInterfaceProtocol,
1822 { "bInterfaceProtocol", "usb.bInterfaceProtocol", FT_UINT8, BASE_HEX,
1823 NULL, 0x0, "", HFILL }},
1825 { &hf_usb_iInterface,
1826 { "iInterface", "usb.iInterface", FT_UINT8, BASE_DEC,
1827 NULL, 0x0, "", HFILL }},
1829 { &hf_usb_bEndpointAddress,
1830 { "bEndpointAddress", "usb.bEndpointAddress", FT_UINT8, BASE_HEX,
1831 NULL, 0x0, "", HFILL }},
1833 { &hf_usb_configuration_bmAttributes,
1834 { "Configuration bmAttributes", "usb.configuration.bmAttributes", FT_UINT8, BASE_HEX,
1835 NULL, 0x0, "", HFILL }},
1837 { &hf_usb_bmAttributes,
1838 { "bmAttributes", "usb.bmAttributes", FT_UINT8, BASE_HEX,
1839 NULL, 0x0, "", HFILL }},
1841 { &hf_usb_bEndpointAttributeTransfer,
1842 { "Transfertype", "usb.bmAttributes.transfer", FT_UINT8, BASE_HEX,
1843 VALS(usb_bmAttributes_transfer_vals), 0x03, "", HFILL }},
1845 { &hf_usb_bEndpointAttributeSynchonisation,
1846 { "Synchronisationtype", "usb.bmAttributes.sync", FT_UINT8, BASE_HEX,
1847 VALS(usb_bmAttributes_sync_vals), 0x0c, "", HFILL }},
1849 { &hf_usb_bEndpointAttributeBehaviour,
1850 { "Behaviourtype", "usb.bmAttributes.behaviour", FT_UINT8, BASE_HEX,
1851 VALS(usb_bmAttributes_behaviour_vals), 0x30, "", HFILL }},
1853 { &hf_usb_wMaxPacketSize,
1854 { "wMaxPacketSize", "usb.wMaxPacketSize", FT_UINT16, BASE_DEC,
1855 NULL, 0x0, "", HFILL }},
1857 { &hf_usb_bInterval,
1858 { "bInterval", "usb.bInterval", FT_UINT8, BASE_DEC,
1859 NULL, 0x0, "", HFILL }},
1861 { &hf_usb_wTotalLength,
1862 { "wTotalLength", "usb.wTotalLength", FT_UINT16, BASE_DEC,
1863 NULL, 0x0, "", HFILL }},
1865 { &hf_usb_bNumInterfaces,
1866 { "bNumInterfaces", "usb.bNumInterfaces", FT_UINT8, BASE_DEC,
1867 NULL, 0x0, "", HFILL }},
1869 { &hf_usb_bConfigurationValue,
1870 { "bConfigurationValue", "usb.bConfigurationValue", FT_UINT8, BASE_DEC,
1871 NULL, 0x0, "", HFILL }},
1873 { &hf_usb_iConfiguration,
1874 { "iConfiguration", "usb.iConfiguration", FT_UINT8, BASE_DEC,
1875 NULL, 0x0, "", HFILL }},
1877 { &hf_usb_bMaxPower,
1878 { "bMaxPower", "usb.bMaxPower", FT_UINT8, BASE_DEC,
1879 NULL, 0x0, "", HFILL }},
1881 { &hf_usb_configuration_legacy10buspowered,
1882 { "Must be 1", "usb.configuration.legacy10buspowered", FT_BOOLEAN, 8,
1883 TFS(&tfs_mustbeone), 0x80, "Legacy USB 1.0 bus powered", HFILL }},
1885 { &hf_usb_configuration_selfpowered,
1886 { "Self-Powered", "usb.configuration.selfpowered", FT_BOOLEAN, 8,
1887 TFS(&tfs_selfpowered), 0x40, "", HFILL }},
1889 { &hf_usb_configuration_remotewakeup,
1890 { "Remote Wakeup", "usb.configuration.remotewakeup", FT_BOOLEAN, 8,
1891 TFS(&tfs_remotewakeup), 0x20, "", HFILL }},
1893 { &hf_usb_bEndpointAddress_number,
1894 { "Endpoint Number", "usb.bEndpointAddress.number", FT_UINT8, BASE_HEX,
1895 NULL, 0x0f, "", HFILL }},
1897 { &hf_usb_bEndpointAddress_direction,
1898 { "Direction", "usb.bEndpointAddress.direction", FT_BOOLEAN, 8,
1899 TFS(&tfs_endpoint_direction), 0x80, "", HFILL }},
1901 { &hf_usb_request_in,
1902 { "Request in", "usb.request_in", FT_FRAMENUM, BASE_NONE,
1903 NULL, 0, "The request to this packet is in this packet", HFILL }},
1906 { "Time from request", "usb.time", FT_RELATIVE_TIME, BASE_NONE,
1907 NULL, 0, "Time between Request and Response for USB cmds", HFILL }},
1909 { &hf_usb_response_in,
1910 { "Response in", "usb.response_in", FT_FRAMENUM, BASE_NONE,
1911 NULL, 0, "The response to this packet is in this packet", HFILL }},
1915 static gint *usb_subtrees[] = {
1918 &ett_usb_setup_bmrequesttype,
1919 &ett_descriptor_device,
1920 &ett_configuration_bmAttributes,
1921 &ett_configuration_bEndpointAddress,
1922 &ett_endpoint_bmAttributes
1926 proto_usb = proto_register_protocol("USB", "USB", "usb");
1927 proto_register_field_array(proto_usb, hf, array_length(hf));
1928 proto_register_subtree_array(usb_subtrees, array_length(usb_subtrees));
1930 usb_bulk_dissector_table = register_dissector_table("usb.bulk",
1931 "USB bulk endpoint", FT_UINT8, BASE_DEC);
1933 usb_control_dissector_table = register_dissector_table("usb.control",
1934 "USB control endpoint", FT_UINT8, BASE_DEC);
1936 usb_tap=register_tap("usb");
1940 proto_reg_handoff_usb(void)
1942 dissector_handle_t linux_usb_handle;
1944 linux_usb_handle = create_dissector_handle(dissect_linux_usb, proto_usb);
1946 dissector_add("wtap_encap", WTAP_ENCAP_USB_LINUX, linux_usb_handle);