Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-usbll.c
blob7c775bd309dcdd7cd3e5422cfbb2ff0d216a675e
1 /* packet-usbll.c
3 * 2019 Tomasz Mon <desowin@gmail.com>
5 * USB link layer dissector
7 * This code is separated from packet-usb.c on purpose.
8 * It is important to note that packet-usb.c operates on the USB URB level.
9 * The idea behind this file is to transform low level link layer data
10 * (captured by hardware sniffers) into structures that resemble URB and pass
11 * such URB to the URB common dissection code.
13 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include "config.h"
17 #include <epan/packet.h>
18 #include <epan/expert.h>
19 #include <epan/crc16-tvb.h>
20 #include <wsutil/crc5.h>
21 #include <epan/address_types.h>
22 #include <epan/to_str.h>
23 #include <epan/proto_data.h>
24 #include <epan/reassemble.h>
25 #include <wiretap/wtap.h>
26 #include "packet-usb.h"
28 void proto_register_usbll(void);
29 void proto_reg_handoff_usbll(void);
31 static dissector_handle_t unknown_speed_handle;
32 static dissector_handle_t low_speed_handle;
33 static dissector_handle_t full_speed_handle;
34 static dissector_handle_t high_speed_handle;
36 static int proto_usbll;
38 /* Fields defined by USB 2.0 standard */
39 static int hf_usbll_pid;
40 static int hf_usbll_device_addr;
41 static int hf_usbll_endp;
42 static int hf_usbll_crc5;
43 static int hf_usbll_crc5_status;
44 static int hf_usbll_data;
45 static int hf_usbll_data_crc;
46 static int hf_usbll_data_crc_status;
47 static int hf_usbll_sof_framenum;
48 static int hf_usbll_split_hub_addr;
49 static int hf_usbll_split_sc;
50 static int hf_usbll_split_port;
51 static int hf_usbll_split_s;
52 static int hf_usbll_split_e;
53 static int hf_usbll_split_u;
54 static int hf_usbll_split_iso_se;
55 static int hf_usbll_split_et;
56 static int hf_usbll_split_crc5;
57 static int hf_usbll_split_crc5_status;
58 static int hf_usbll_src;
59 static int hf_usbll_dst;
60 static int hf_usbll_addr;
61 static int hf_usbll_transfer_fragments;
62 static int hf_usbll_transfer_fragment;
63 static int hf_usbll_transfer_fragment_overlap;
64 static int hf_usbll_transfer_fragment_overlap_conflicts;
65 static int hf_usbll_transfer_fragment_multiple_tails;
66 static int hf_usbll_transfer_fragment_too_long_fragment;
67 static int hf_usbll_transfer_fragment_error;
68 static int hf_usbll_transfer_fragment_count;
69 static int hf_usbll_transfer_reassembled_in;
70 static int hf_usbll_transfer_reassembled_length;
71 /* Fields defined by USB 2.0 ECN: Link Power Management (LPM) and
72 * USB 2.0 ECN Errata for Link Power Management 9/28/2011
74 static int hf_usbll_subpid;
75 static int hf_usbll_lpm_link_state;
76 static int hf_usbll_lpm_besl;
77 static int hf_usbll_lpm_remote_wake;
78 static int hf_usbll_lpm_reserved;
80 static int ett_usbll;
81 static int ett_usbll_transfer_fragment;
82 static int ett_usbll_transfer_fragments;
84 static const fragment_items usbll_frag_items = {
85 /* Fragment subtrees */
86 &ett_usbll_transfer_fragment,
87 &ett_usbll_transfer_fragments,
88 /* Fragment Fields */
89 &hf_usbll_transfer_fragments,
90 &hf_usbll_transfer_fragment,
91 &hf_usbll_transfer_fragment_overlap,
92 &hf_usbll_transfer_fragment_overlap_conflicts,
93 &hf_usbll_transfer_fragment_multiple_tails,
94 &hf_usbll_transfer_fragment_too_long_fragment,
95 &hf_usbll_transfer_fragment_error,
96 &hf_usbll_transfer_fragment_count,
97 /* Reassembled in field */
98 &hf_usbll_transfer_reassembled_in,
99 /* Reassembled length field */
100 &hf_usbll_transfer_reassembled_length,
101 /* Reassembled data field */
102 NULL,
103 /* Tag */
104 "USB transfer fragments"
107 static expert_field ei_invalid_pid;
108 static expert_field ei_invalid_subpid;
109 static expert_field ei_conflicting_subpid;
110 static expert_field ei_undecoded;
111 static expert_field ei_wrong_crc5;
112 static expert_field ei_wrong_split_crc5;
113 static expert_field ei_wrong_crc16;
114 static expert_field ei_invalid_s;
115 static expert_field ei_invalid_e_u;
116 static expert_field ei_invalid_pid_sequence;
117 static expert_field ei_invalid_setup_data;
119 static int usbll_address_type = -1;
121 static reassembly_table usbll_reassembly_table;
123 static wmem_map_t *transfer_info;
125 static const enum_val_t dissect_unknown_speed_as[] = {
126 { "unk", "Unknown", USB_SPEED_UNKNOWN },
127 { "low", "Low-Speed", USB_SPEED_LOW },
128 { "full", "Full-Speed", USB_SPEED_FULL },
129 { "high", "High-Speed", USB_SPEED_HIGH },
130 { NULL, NULL, 0 }
133 static int global_dissect_unknown_speed_as = USB_SPEED_UNKNOWN;
135 /* USB packet ID is 4-bit. It is send in octet alongside complemented form.
136 * The list of PIDs is available in Universal Serial Bus Specification Revision 2.0,
137 * Table 8-1. PID Types
138 * Packets here are sorted by the complemented form (high nibble).
140 #define USB_PID_DATA_MDATA 0x0F
141 #define USB_PID_HANDSHAKE_STALL 0x1E
142 #define USB_PID_TOKEN_SETUP 0x2D
143 #define USB_PID_SPECIAL_PRE_OR_ERR 0x3C
144 #define USB_PID_DATA_DATA1 0x4B
145 #define USB_PID_HANDSHAKE_NAK 0x5A
146 #define USB_PID_TOKEN_IN 0x69
147 #define USB_PID_SPECIAL_SPLIT 0x78
148 #define USB_PID_DATA_DATA2 0x87
149 #define USB_PID_HANDSHAKE_NYET 0x96
150 #define USB_PID_TOKEN_SOF 0xA5
151 #define USB_PID_SPECIAL_PING 0xB4
152 #define USB_PID_DATA_DATA0 0xC3
153 #define USB_PID_HANDSHAKE_ACK 0xD2
154 #define USB_PID_TOKEN_OUT 0xE1
155 #define USB_PID_SPECIAL_EXT 0xF0
156 static const value_string usb_packetid_vals[] = {
157 {USB_PID_DATA_MDATA, "MDATA"},
158 {USB_PID_HANDSHAKE_STALL, "STALL"},
159 {USB_PID_TOKEN_SETUP, "SETUP"},
160 {USB_PID_SPECIAL_PRE_OR_ERR, "PRE/ERR"},
161 {USB_PID_DATA_DATA1, "DATA1"},
162 {USB_PID_HANDSHAKE_NAK, "NAK"},
163 {USB_PID_TOKEN_IN, "IN"},
164 {USB_PID_SPECIAL_SPLIT, "SPLIT"},
165 {USB_PID_DATA_DATA2, "DATA2"},
166 {USB_PID_HANDSHAKE_NYET, "NYET"},
167 {USB_PID_TOKEN_SOF, "SOF"},
168 {USB_PID_SPECIAL_PING, "PING"},
169 {USB_PID_DATA_DATA0, "DATA0"},
170 {USB_PID_HANDSHAKE_ACK, "ACK"},
171 {USB_PID_TOKEN_OUT, "OUT"},
172 {USB_PID_SPECIAL_EXT, "EXT"},
173 {0, NULL}
175 static value_string_ext usb_packetid_vals_ext =
176 VALUE_STRING_EXT_INIT(usb_packetid_vals);
178 /* EXT PID and SubPIDs are defined in USB 2.0 ECN: Link Power Management (LPM)
179 * Currently only LPM SubPID is defined, all other are reserved. The reserved
180 * PIDs are either conflicting with USB 2.0 Token PIDs (and can not be reused
181 * as SubPID in order to maintain backwards compatibility) or not yet defined
182 * (reserved for future use, because old devices will simply reject them).
184 #define USB_SUBPID_RESERVED_MDATA 0x0F
185 #define USB_SUBPID_RESERVED_STALL 0x1E
186 #define USB_SUBPID_CONFLICT_SETUP 0x2D
187 #define USB_SUBPID_CONFLICT_PRE 0x3C
188 #define USB_SUBPID_RESERVED_DATA1 0x4B
189 #define USB_SUBPID_RESERVED_NAK 0x5A
190 #define USB_SUBPID_CONFLICT_IN 0x69
191 #define USB_SUBPID_CONFLICT_SPLIT 0x78
192 #define USB_SUBPID_RESERVED_DATA2 0x87
193 #define USB_SUBPID_RESERVED_NYET 0x96
194 #define USB_SUBPID_CONFLICT_SOF 0xA5
195 #define USB_SUBPID_CONFLICT_PING 0xB4
196 #define USB_SUBPID_LPM 0xC3
197 #define USB_SUBPID_RESERVED_ACK 0xD2
198 #define USB_SUBPID_CONFLICT_OUT 0xE1
199 #define USB_SUBPID_RESERVED_EXT 0xF0
200 static const value_string usb_subpid_vals[] = {
201 {USB_SUBPID_RESERVED_MDATA, "Reserved (MDATA)"},
202 {USB_SUBPID_RESERVED_STALL, "Reserved (STALL)"},
203 {USB_SUBPID_CONFLICT_SETUP, "Reserved (conflict with SETUP)"},
204 {USB_SUBPID_CONFLICT_PRE, "Reserved (conflict with PRE)"},
205 {USB_SUBPID_RESERVED_DATA1, "Reserved (DATA1)"},
206 {USB_SUBPID_RESERVED_NAK, "Reserved (NAK)"},
207 {USB_SUBPID_CONFLICT_IN, "Reserved (conflict with IN)"},
208 {USB_SUBPID_CONFLICT_SPLIT, "Reserved (conflict with SPLIT)"},
209 {USB_SUBPID_RESERVED_DATA2, "Reserved (DATA2)"},
210 {USB_SUBPID_RESERVED_NYET, "Reserved (NYET)"},
211 {USB_SUBPID_CONFLICT_SOF, "Reserved (conflict with SOF)"},
212 {USB_SUBPID_CONFLICT_PING, "Reserved (conflict with PING)"},
213 {USB_SUBPID_LPM, "LPM"},
214 {USB_SUBPID_RESERVED_ACK, "Reserved (ACK)"},
215 {USB_SUBPID_CONFLICT_OUT, "Reserved (conflict with OUT)"},
216 {USB_SUBPID_RESERVED_EXT, "Reserved (EXT)"},
217 {0, NULL}
219 static value_string_ext usb_subpid_vals_ext =
220 VALUE_STRING_EXT_INIT(usb_subpid_vals);
222 static void lpm_link_state_str(char *buf, uint32_t value)
224 if (value == 0x01) {
225 snprintf(buf, ITEM_LABEL_LENGTH, "L1 (Sleep)");
226 } else {
227 snprintf(buf, ITEM_LABEL_LENGTH, "Reserved for future use");
231 static unsigned besl_to_us(uint8_t besl)
233 unsigned int us;
234 if (besl == 0) {
235 us = 125;
236 } else if (besl == 1) {
237 us = 150;
238 } else if (besl <= 5) {
239 us = 100 * besl;
240 } else {
241 us = 1000 * (besl - 5);
243 return us;
246 void usb_lpm_besl_str(char *buf, uint32_t value)
248 snprintf(buf, ITEM_LABEL_LENGTH, "%d us (%d)", besl_to_us(value), value);
251 static const value_string usb_lpm_remote_wake_vals[] = {
252 {0, "Disable"},
253 {1, "Enable"},
254 {0, NULL},
257 static const value_string usb_start_complete_vals[] = {
258 {0, "Start"},
259 {1, "Complete"},
260 {0, NULL}
263 static const value_string usb_split_speed_vals[] = {
264 {0, "Full"},
265 {1, "Low"},
266 {0, NULL}
269 static const value_string usb_split_iso_se_vals[] = {
270 {0, "High-speed data is the middle of the fullspeed data payload"},
271 {1, "High-speed data is the beginning of the full-speed data payload"},
272 {2, "High-speed data is the end of the full-speed data payload"},
273 {3, "High-speed data is all of the full-speed data payload"},
274 {0, NULL}
277 #define USB_EP_TYPE_CONTROL 0
278 #define USB_EP_TYPE_ISOCHRONOUS 1
279 #define USB_EP_TYPE_BULK 2
280 #define USB_EP_TYPE_INTERRUPT 3
281 static const value_string usb_endpoint_type_vals[] = {
282 {USB_EP_TYPE_CONTROL, "Control"},
283 {USB_EP_TYPE_ISOCHRONOUS, "Isochronous"},
284 {USB_EP_TYPE_BULK, "Bulk"},
285 {USB_EP_TYPE_INTERRUPT, "Interrupt"},
286 {0, NULL}
289 /* Macros for Token Packets. */
290 #define TOKEN_BITS_GET_ADDRESS(bits) (bits & 0x007F)
291 #define TOKEN_BITS_GET_ENDPOINT(bits) ((bits & 0x0780) >> 7)
293 /* Macros for Split Packets. */
294 #define SPLIT_BITS_GET_HUB_ADDRESS(bits) (uint8_t)(bits & 0x007F)
295 #define SPLIT_BITS_GET_HUB_PORT(bits) (uint8_t)((bits & 0x7F00) >> 8)
296 #define SPLIT_BITS_GET_ENDPOINT_TYPE(bits) ((bits & 0x060000) >> 17)
297 #define SPLIT_BIT_SPEED 0x8000
298 #define SPLIT_BIT_E_U 0x10000
299 #define SPLIT_BIT_START_COMPLETE 0x0080
301 /* Bitmasks definitions for usbll_address_t flags
302 * and 'flags' parameter of usbll_set_address function.
304 #define USBLL_ADDRESS_STANDARD 0
305 #define USBLL_ADDRESS_HOST 0x01
306 #define USBLL_ADDRESS_HUB_PORT 0x02
307 #define USBLL_ADDRESS_BROADCAST 0x04
308 #define USBLL_ADDRESS_HOST_TO_DEV 0
309 #define USBLL_ADDRESS_DEV_TO_HOST 0x08
311 #define USBLL_ADDRESS_IS_DEV_TO_HOST(flags) \
312 (flags & USBLL_ADDRESS_DEV_TO_HOST)
314 #define USBLL_ADDRESS_IS_HOST_TO_DEV(flags) \
315 (!USBLL_ADDRESS_IS_DEV_TO_HOST(flags))
317 typedef enum usbll_state {
318 STATE_IDLE, /* No transaction, e.g. after SOF */
319 STATE_INVALID, /* Invalid PID sequence, e.g. ACK without transaction */
320 STATE_IN,
321 STATE_IN_DATA0,
322 STATE_IN_DATA1,
323 STATE_IN_HS_ISOCHRONOUS_DATA2,
324 STATE_IN_ACK,
325 STATE_IN_NAK,
326 STATE_IN_STALL,
327 STATE_OUT,
328 STATE_OUT_DATA0,
329 STATE_OUT_DATA1,
330 STATE_OUT_HS_ISOCHRONOUS_DATA2,
331 STATE_OUT_HS_ISOCHRONOUS_MDATA,
332 STATE_OUT_ACK,
333 STATE_OUT_NAK,
334 STATE_OUT_STALL,
335 STATE_OUT_NYET,
336 STATE_PING,
337 STATE_PING_ACK,
338 STATE_PING_NAK,
339 STATE_PING_STALL,
340 STATE_SETUP,
341 STATE_SETUP_DATA0,
342 STATE_SETUP_ACK,
343 /* LS/FS Control transactions via HS hub */
344 STATE_SSPLIT_CONTROL,
345 STATE_SSPLIT_CONTROL_SETUP,
346 STATE_SSPLIT_CONTROL_SETUP_DATA0,
347 STATE_SSPLIT_CONTROL_SETUP_ACK,
348 STATE_SSPLIT_CONTROL_SETUP_NAK,
349 STATE_SSPLIT_CONTROL_OUT,
350 STATE_SSPLIT_CONTROL_OUT_DATA0,
351 STATE_SSPLIT_CONTROL_OUT_DATA1,
352 STATE_SSPLIT_CONTROL_OUT_ACK,
353 STATE_SSPLIT_CONTROL_OUT_NAK,
354 STATE_SSPLIT_CONTROL_IN,
355 STATE_SSPLIT_CONTROL_IN_ACK,
356 STATE_SSPLIT_CONTROL_IN_NAK,
357 STATE_CSPLIT_CONTROL,
358 STATE_CSPLIT_CONTROL_SETUP,
359 STATE_CSPLIT_CONTROL_SETUP_ACK,
360 STATE_CSPLIT_CONTROL_SETUP_NYET,
361 STATE_CSPLIT_CONTROL_OUT,
362 STATE_CSPLIT_CONTROL_OUT_ACK,
363 STATE_CSPLIT_CONTROL_OUT_NAK,
364 STATE_CSPLIT_CONTROL_OUT_STALL,
365 STATE_CSPLIT_CONTROL_OUT_NYET,
366 STATE_CSPLIT_CONTROL_IN,
367 STATE_CSPLIT_CONTROL_IN_DATA0,
368 STATE_CSPLIT_CONTROL_IN_DATA1,
369 STATE_CSPLIT_CONTROL_IN_NAK,
370 STATE_CSPLIT_CONTROL_IN_STALL,
371 STATE_CSPLIT_CONTROL_IN_NYET,
372 /* LS/FS Bulk transactions via HS hub */
373 STATE_SSPLIT_BULK,
374 STATE_SSPLIT_BULK_OUT,
375 STATE_SSPLIT_BULK_OUT_DATA0,
376 STATE_SSPLIT_BULK_OUT_DATA1,
377 STATE_SSPLIT_BULK_OUT_ACK,
378 STATE_SSPLIT_BULK_OUT_NAK,
379 STATE_SSPLIT_BULK_IN,
380 STATE_SSPLIT_BULK_IN_ACK,
381 STATE_SSPLIT_BULK_IN_NAK,
382 STATE_CSPLIT_BULK,
383 STATE_CSPLIT_BULK_OUT,
384 STATE_CSPLIT_BULK_OUT_ACK,
385 STATE_CSPLIT_BULK_OUT_NAK,
386 STATE_CSPLIT_BULK_OUT_STALL,
387 STATE_CSPLIT_BULK_OUT_NYET,
388 STATE_CSPLIT_BULK_IN,
389 STATE_CSPLIT_BULK_IN_DATA0,
390 STATE_CSPLIT_BULK_IN_DATA1,
391 STATE_CSPLIT_BULK_IN_NAK,
392 STATE_CSPLIT_BULK_IN_STALL,
393 STATE_CSPLIT_BULK_IN_NYET,
394 /* LS/FS Interrupt transactions via HS hub */
395 STATE_SSPLIT_INTERRUPT,
396 STATE_SSPLIT_INTERRUPT_OUT,
397 STATE_SSPLIT_INTERRUPT_OUT_DATA0,
398 STATE_SSPLIT_INTERRUPT_OUT_DATA1,
399 STATE_SSPLIT_INTERRUPT_IN,
400 STATE_CSPLIT_INTERRUPT,
401 STATE_CSPLIT_INTERRUPT_OUT,
402 STATE_CSPLIT_INTERRUPT_OUT_ACK,
403 STATE_CSPLIT_INTERRUPT_OUT_NAK,
404 STATE_CSPLIT_INTERRUPT_OUT_STALL,
405 STATE_CSPLIT_INTERRUPT_OUT_ERR,
406 STATE_CSPLIT_INTERRUPT_OUT_NYET,
407 STATE_CSPLIT_INTERRUPT_IN,
408 STATE_CSPLIT_INTERRUPT_IN_MDATA,
409 STATE_CSPLIT_INTERRUPT_IN_DATA0,
410 STATE_CSPLIT_INTERRUPT_IN_DATA1,
411 STATE_CSPLIT_INTERRUPT_IN_NAK,
412 STATE_CSPLIT_INTERRUPT_IN_STALL,
413 STATE_CSPLIT_INTERRUPT_IN_ERR,
414 STATE_CSPLIT_INTERRUPT_IN_NYET,
415 /* FS Isochronous transactions via HS hub */
416 STATE_SSPLIT_ISOCHRONOUS,
417 STATE_SSPLIT_ISOCHRONOUS_OUT,
418 STATE_SSPLIT_ISOCHRONOUS_OUT_DATA0,
419 STATE_SSPLIT_ISOCHRONOUS_IN,
420 STATE_CSPLIT_ISOCHRONOUS,
421 STATE_CSPLIT_ISOCHRONOUS_IN,
422 STATE_CSPLIT_ISOCHRONOUS_IN_DATA0,
423 STATE_CSPLIT_ISOCHRONOUS_IN_MDATA,
424 STATE_CSPLIT_ISOCHRONOUS_IN_ERR,
425 STATE_CSPLIT_ISOCHRONOUS_IN_NYET,
426 /* USB 2.0 ECN: Link Power Management (LPM) */
427 STATE_EXT,
428 STATE_SUBPID_INVALID,
429 STATE_SUBPID_NOT_REUSABLE,
430 STATE_SUBPID_LPM,
431 STATE_SUBPID_LPM_ACK,
432 STATE_SUBPID_LPM_NYET,
433 STATE_SUBPID_LPM_STALL,
434 STATE_SUBPID_RESERVED,
435 } usbll_state_t;
437 typedef enum usbll_ep_type {
438 USBLL_EP_UNKNOWN,
439 USBLL_EP_CONTROL,
440 USBLL_EP_BULK,
441 USBLL_EP_INTERRUPT,
442 USBLL_EP_ISOCHRONOUS,
443 } usbll_ep_type_t;
445 /* usbll_address_t represents the address
446 * of Host, Hub and Devices.
448 typedef struct {
449 uint8_t flags; /* flags - Contains information if address is
450 * Host, Hub, Device or Broadcast.
452 uint8_t device; /* device - Device or Hub Address */
453 uint8_t endpoint; /* endpoint - It represents endpoint number for
454 * Device and port number for Hub.
456 } usbll_address_t;
458 typedef struct usbll_transaction_info {
459 uint32_t starts_in;
460 uint8_t pid;
461 uint8_t address;
462 uint8_t endpoint;
463 usb_speed_t speed;
464 struct usbll_transaction_info *split_start;
465 struct usbll_transaction_info *split_complete;
466 } usbll_transaction_info_t;
468 typedef struct usbll_transfer_info {
469 /* First data packet number, used as reassembly key */
470 uint32_t first_packet;
471 /* Offset this packet starts at */
472 uint32_t offset;
473 usbll_ep_type_t type;
474 /* true if data from host to device, false when from device to host */
475 bool from_host;
476 /* false if this is the last packet */
477 bool more_frags;
478 } usbll_transfer_info_t;
480 /* USB is a stateful protocol. The addresses of Data Packets
481 * and Handshake Packets depend on the packets before them.
483 * We maintain a static global pointer of the type usbll_data_t.
484 * Maintaining a pointer instead of a conversation helps in reducing
485 * memory usage, taking the following advantages:
486 * 1. Packets are always ordered.
487 * 2. Addresses of packets only up to last 3 packets are required.
489 * Previous pointer is used in the initial pass to link packets
490 * into transactions.
492 typedef struct usbll_data {
493 usbll_state_t transaction_state;
494 usbll_transaction_info_t *transaction;
495 struct usbll_data *prev;
496 struct usbll_data *next;
497 } usbll_data_t;
499 static usbll_data_t *usbll_data_ptr;
501 /* Transaction Translator arrays used only during first pass. */
502 static usbll_transaction_info_t ***tt_non_periodic;
503 static usbll_transaction_info_t ***tt_periodic;
505 typedef enum usbll_transfer_data {
506 USBLL_TRANSFER_NORMAL,
507 USBLL_TRANSFER_GET_DEVICE_DESCRIPTOR,
508 } usbll_transfer_data_t;
510 typedef struct usbll_endpoint_info {
511 usbll_ep_type_t type;
512 usbll_transfer_data_t data;
513 /* Maximum packet size, 0 if not known */
514 uint16_t max_packet_size;
515 /* DATA0/DATA1 tracking to detect retransmissions */
516 uint8_t last_data_pid;
517 /* true if last data packet was acknowledged */
518 bool last_data_acked;
519 /* Current transfer key, 0 if no transfer in progress */
520 uint32_t active_transfer_key;
521 /* Offset where next packet should start at */
522 uint32_t transfer_offset;
523 /* Last data packet length that was part of transfer */
524 uint32_t last_data_len;
525 /* Transfer length if known, 0 if unknown */
526 uint32_t requested_transfer_length;
527 } usbll_endpoint_info_t;
529 /* Endpoint info arrays used only during first pass. */
530 static usbll_endpoint_info_t **ep_info_in;
531 static usbll_endpoint_info_t **ep_info_out;
533 static unsigned usbll_fragment_key_hash(const void *k)
535 return GPOINTER_TO_UINT(k);
538 static int usbll_fragment_key_equal(const void *k1, const void *k2)
540 return GPOINTER_TO_UINT(k1) == GPOINTER_TO_UINT(k2);
543 static void *usbll_fragment_key(const packet_info *pinfo _U_, const uint32_t id, const void *data _U_)
545 return GUINT_TO_POINTER(id);
548 static void usbll_fragment_free_key(void *ptr _U_)
550 /* there's nothing to be freed */
553 static const reassembly_table_functions usbll_reassembly_table_functions = {
554 .hash_func = usbll_fragment_key_hash,
555 .equal_func = usbll_fragment_key_equal,
556 .temporary_key_func = usbll_fragment_key,
557 .persistent_key_func = usbll_fragment_key,
558 .free_temporary_key_func = usbll_fragment_free_key,
559 .free_persistent_key_func = usbll_fragment_free_key,
562 static usbll_state_t
563 usbll_next_state(usbll_state_t state, uint8_t pid)
565 if (state == STATE_EXT)
567 switch (pid)
569 case USB_SUBPID_RESERVED_MDATA: return STATE_SUBPID_RESERVED;
570 case USB_SUBPID_RESERVED_STALL: return STATE_SUBPID_RESERVED;
571 case USB_SUBPID_CONFLICT_SETUP: return STATE_SUBPID_NOT_REUSABLE;
572 case USB_SUBPID_CONFLICT_PRE: return STATE_SUBPID_NOT_REUSABLE;
573 case USB_SUBPID_RESERVED_DATA1: return STATE_SUBPID_RESERVED;
574 case USB_SUBPID_RESERVED_NAK: return STATE_SUBPID_RESERVED;
575 case USB_SUBPID_CONFLICT_IN: return STATE_SUBPID_NOT_REUSABLE;
576 case USB_SUBPID_CONFLICT_SPLIT: return STATE_SUBPID_NOT_REUSABLE;
577 case USB_SUBPID_RESERVED_DATA2: return STATE_SUBPID_RESERVED;
578 case USB_SUBPID_RESERVED_NYET: return STATE_SUBPID_RESERVED;
579 case USB_SUBPID_CONFLICT_SOF: return STATE_SUBPID_NOT_REUSABLE;
580 case USB_SUBPID_CONFLICT_PING: return STATE_SUBPID_NOT_REUSABLE;
581 case USB_SUBPID_LPM: return STATE_SUBPID_LPM;
582 case USB_SUBPID_RESERVED_ACK: return STATE_SUBPID_RESERVED;
583 case USB_SUBPID_CONFLICT_OUT: return STATE_SUBPID_NOT_REUSABLE;
584 case USB_SUBPID_RESERVED_EXT: return STATE_SUBPID_RESERVED;
585 default: return STATE_SUBPID_INVALID;
588 else if (pid == USB_PID_SPECIAL_EXT)
590 return STATE_EXT;
592 else if (pid == USB_PID_TOKEN_SOF)
594 return STATE_IDLE;
596 else if (pid == USB_PID_SPECIAL_PING)
598 return STATE_PING;
600 else if (pid == USB_PID_TOKEN_SETUP)
602 switch (state)
604 case STATE_SSPLIT_CONTROL: return STATE_SSPLIT_CONTROL_SETUP;
605 case STATE_CSPLIT_CONTROL: return STATE_CSPLIT_CONTROL_SETUP;
606 default: return STATE_SETUP;
609 else if (pid == USB_PID_TOKEN_OUT)
611 switch (state)
613 case STATE_SSPLIT_CONTROL: return STATE_SSPLIT_CONTROL_OUT;
614 case STATE_CSPLIT_CONTROL: return STATE_CSPLIT_CONTROL_OUT;
615 case STATE_SSPLIT_BULK: return STATE_SSPLIT_BULK_OUT;
616 case STATE_CSPLIT_BULK: return STATE_CSPLIT_BULK_OUT;
617 case STATE_SSPLIT_INTERRUPT: return STATE_SSPLIT_INTERRUPT_OUT;
618 case STATE_CSPLIT_INTERRUPT: return STATE_CSPLIT_INTERRUPT_OUT;
619 case STATE_SSPLIT_ISOCHRONOUS: return STATE_SSPLIT_ISOCHRONOUS_OUT;
620 default: return STATE_OUT;
623 else if (pid == USB_PID_TOKEN_IN)
625 switch (state)
627 case STATE_SSPLIT_CONTROL: return STATE_SSPLIT_CONTROL_IN;
628 case STATE_CSPLIT_CONTROL: return STATE_CSPLIT_CONTROL_IN;
629 case STATE_SSPLIT_BULK: return STATE_SSPLIT_BULK_IN;
630 case STATE_CSPLIT_BULK: return STATE_CSPLIT_BULK_IN;
631 case STATE_SSPLIT_INTERRUPT: return STATE_SSPLIT_INTERRUPT_IN;
632 case STATE_CSPLIT_INTERRUPT: return STATE_CSPLIT_INTERRUPT_IN;
633 case STATE_SSPLIT_ISOCHRONOUS: return STATE_SSPLIT_ISOCHRONOUS_IN;
634 case STATE_CSPLIT_ISOCHRONOUS: return STATE_CSPLIT_ISOCHRONOUS_IN;
635 default: return STATE_IN;
638 else if (pid == USB_PID_DATA_DATA0)
640 switch (state)
642 case STATE_IN: return STATE_IN_DATA0;
643 case STATE_OUT: return STATE_OUT_DATA0;
644 case STATE_SETUP: return STATE_SETUP_DATA0;
645 case STATE_SSPLIT_CONTROL_SETUP: return STATE_SSPLIT_CONTROL_SETUP_DATA0;
646 case STATE_SSPLIT_CONTROL_OUT: return STATE_SSPLIT_CONTROL_OUT_DATA0;
647 case STATE_CSPLIT_CONTROL_IN: return STATE_CSPLIT_CONTROL_IN_DATA0;
648 case STATE_SSPLIT_BULK_OUT: return STATE_SSPLIT_BULK_OUT_DATA0;
649 case STATE_CSPLIT_BULK_IN: return STATE_CSPLIT_BULK_IN_DATA0;
650 case STATE_SSPLIT_INTERRUPT_OUT: return STATE_SSPLIT_INTERRUPT_OUT_DATA0;
651 case STATE_CSPLIT_INTERRUPT_IN: return STATE_CSPLIT_INTERRUPT_IN_DATA0;
652 case STATE_SSPLIT_ISOCHRONOUS_OUT: return STATE_SSPLIT_ISOCHRONOUS_OUT_DATA0;
653 case STATE_CSPLIT_ISOCHRONOUS_IN: return STATE_CSPLIT_ISOCHRONOUS_IN_DATA0;
654 default: return STATE_INVALID;
657 else if (pid == USB_PID_DATA_DATA1)
659 switch (state)
661 case STATE_IN: return STATE_IN_DATA1;
662 case STATE_OUT: return STATE_OUT_DATA1;
663 case STATE_SSPLIT_CONTROL_OUT: return STATE_SSPLIT_CONTROL_OUT_DATA1;
664 case STATE_CSPLIT_CONTROL_IN: return STATE_CSPLIT_CONTROL_IN_DATA1;
665 case STATE_SSPLIT_BULK_OUT: return STATE_SSPLIT_BULK_OUT_DATA1;
666 case STATE_CSPLIT_BULK_IN: return STATE_CSPLIT_BULK_IN_DATA1;
667 case STATE_SSPLIT_INTERRUPT_OUT: return STATE_SSPLIT_INTERRUPT_OUT_DATA1;
668 case STATE_CSPLIT_INTERRUPT_IN: return STATE_CSPLIT_INTERRUPT_IN_DATA1;
669 default: return STATE_INVALID;
672 else if (pid == USB_PID_DATA_DATA2)
674 switch (state)
676 case STATE_IN: return STATE_IN_HS_ISOCHRONOUS_DATA2;
677 default: return STATE_INVALID;
680 else if (pid == USB_PID_DATA_MDATA)
682 switch (state)
684 case STATE_OUT: return STATE_OUT_HS_ISOCHRONOUS_MDATA;
685 case STATE_CSPLIT_INTERRUPT_IN: return STATE_CSPLIT_INTERRUPT_IN_MDATA;
686 case STATE_CSPLIT_ISOCHRONOUS_IN: return STATE_CSPLIT_ISOCHRONOUS_IN_MDATA;
687 default: return STATE_INVALID;
690 else if (pid == USB_PID_HANDSHAKE_ACK)
692 switch (state)
694 case STATE_IN_DATA0: return STATE_IN_ACK;
695 case STATE_IN_DATA1: return STATE_IN_ACK;
696 case STATE_OUT_DATA0: return STATE_OUT_ACK;
697 case STATE_OUT_DATA1: return STATE_OUT_ACK;
698 case STATE_PING: return STATE_PING_ACK;
699 case STATE_SETUP_DATA0: return STATE_SETUP_ACK;
700 case STATE_SSPLIT_CONTROL_SETUP_DATA0: return STATE_SSPLIT_CONTROL_SETUP_ACK;
701 case STATE_CSPLIT_CONTROL_SETUP: return STATE_CSPLIT_CONTROL_SETUP_ACK;
702 case STATE_SSPLIT_CONTROL_OUT_DATA0: return STATE_SSPLIT_CONTROL_OUT_ACK;
703 case STATE_SSPLIT_CONTROL_OUT_DATA1: return STATE_SSPLIT_CONTROL_OUT_ACK;
704 case STATE_CSPLIT_CONTROL_OUT: return STATE_CSPLIT_CONTROL_OUT_ACK;
705 case STATE_SSPLIT_CONTROL_IN: return STATE_SSPLIT_CONTROL_IN_ACK;
706 case STATE_SSPLIT_BULK_OUT_DATA0: return STATE_SSPLIT_BULK_OUT_ACK;
707 case STATE_SSPLIT_BULK_OUT_DATA1: return STATE_SSPLIT_BULK_OUT_ACK;
708 case STATE_SSPLIT_BULK_IN: return STATE_SSPLIT_BULK_IN_ACK;
709 case STATE_CSPLIT_BULK_OUT: return STATE_CSPLIT_BULK_OUT_ACK;
710 case STATE_CSPLIT_INTERRUPT_OUT: return STATE_CSPLIT_INTERRUPT_OUT_ACK;
711 case STATE_SUBPID_LPM: return STATE_SUBPID_LPM_ACK;
712 default: return STATE_INVALID;
715 else if (pid == USB_PID_HANDSHAKE_NAK)
717 switch (state)
719 case STATE_IN: return STATE_IN_NAK;
720 case STATE_OUT_DATA0: return STATE_OUT_NAK;
721 case STATE_OUT_DATA1: return STATE_OUT_NAK;
722 case STATE_PING: return STATE_PING_NAK;
723 case STATE_SSPLIT_CONTROL_SETUP_DATA0: return STATE_SSPLIT_CONTROL_SETUP_NAK;
724 case STATE_SSPLIT_CONTROL_OUT_DATA0: return STATE_SSPLIT_CONTROL_OUT_NAK;
725 case STATE_SSPLIT_CONTROL_OUT_DATA1: return STATE_SSPLIT_CONTROL_OUT_NAK;
726 case STATE_SSPLIT_CONTROL_IN: return STATE_SSPLIT_CONTROL_IN_NAK;
727 case STATE_CSPLIT_CONTROL_OUT: return STATE_CSPLIT_CONTROL_OUT_NAK;
728 case STATE_CSPLIT_CONTROL_IN: return STATE_CSPLIT_CONTROL_IN_NAK;
729 case STATE_SSPLIT_BULK_OUT_DATA0: return STATE_SSPLIT_BULK_OUT_NAK;
730 case STATE_SSPLIT_BULK_OUT_DATA1: return STATE_SSPLIT_BULK_OUT_NAK;
731 case STATE_SSPLIT_BULK_IN: return STATE_SSPLIT_BULK_IN_NAK;
732 case STATE_CSPLIT_BULK_OUT: return STATE_CSPLIT_BULK_OUT_NAK;
733 case STATE_CSPLIT_BULK_IN: return STATE_CSPLIT_BULK_IN_NAK;
734 case STATE_CSPLIT_INTERRUPT_OUT: return STATE_CSPLIT_INTERRUPT_OUT_NAK;
735 case STATE_CSPLIT_INTERRUPT_IN: return STATE_CSPLIT_INTERRUPT_IN_NAK;
736 default: return STATE_INVALID;
739 else if (pid == USB_PID_HANDSHAKE_STALL)
741 switch (state)
743 case STATE_IN: return STATE_IN_STALL;
744 case STATE_OUT_DATA0: return STATE_OUT_STALL;
745 case STATE_OUT_DATA1: return STATE_OUT_STALL;
746 case STATE_PING: return STATE_PING_STALL;
747 case STATE_CSPLIT_CONTROL_OUT: return STATE_CSPLIT_CONTROL_OUT_STALL;
748 case STATE_CSPLIT_CONTROL_IN: return STATE_CSPLIT_CONTROL_IN_STALL;
749 case STATE_CSPLIT_BULK_OUT: return STATE_CSPLIT_BULK_OUT_STALL;
750 case STATE_CSPLIT_BULK_IN: return STATE_CSPLIT_BULK_IN_STALL;
751 case STATE_CSPLIT_INTERRUPT_OUT: return STATE_CSPLIT_INTERRUPT_OUT_STALL;
752 case STATE_CSPLIT_INTERRUPT_IN: return STATE_CSPLIT_INTERRUPT_IN_STALL;
753 case STATE_SUBPID_LPM: return STATE_SUBPID_LPM_STALL;
754 default: return STATE_INVALID;
757 else if (pid == USB_PID_HANDSHAKE_NYET)
759 /* Allowed only in High-Speed */
760 switch (state)
762 case STATE_OUT_DATA0: return STATE_OUT_NYET;
763 case STATE_OUT_DATA1: return STATE_OUT_NYET;
764 case STATE_CSPLIT_CONTROL_SETUP: return STATE_CSPLIT_CONTROL_SETUP_NYET;
765 case STATE_CSPLIT_CONTROL_OUT: return STATE_CSPLIT_CONTROL_OUT_NYET;
766 case STATE_CSPLIT_CONTROL_IN: return STATE_CSPLIT_CONTROL_IN_NYET;
767 case STATE_CSPLIT_BULK_OUT: return STATE_CSPLIT_BULK_OUT_NYET;
768 case STATE_CSPLIT_BULK_IN: return STATE_CSPLIT_BULK_IN_NYET;
769 case STATE_CSPLIT_INTERRUPT_OUT: return STATE_CSPLIT_INTERRUPT_OUT_NYET;
770 case STATE_CSPLIT_INTERRUPT_IN: return STATE_CSPLIT_INTERRUPT_IN_NYET;
771 case STATE_CSPLIT_ISOCHRONOUS_IN: return STATE_CSPLIT_ISOCHRONOUS_IN_NYET;
772 case STATE_SUBPID_LPM: return STATE_SUBPID_LPM_NYET;
773 default: return STATE_INVALID;
776 else if (pid == USB_PID_SPECIAL_PRE_OR_ERR)
778 switch (state)
780 case STATE_CSPLIT_INTERRUPT_OUT: return STATE_CSPLIT_INTERRUPT_OUT_ERR;
781 case STATE_CSPLIT_INTERRUPT_IN: return STATE_CSPLIT_INTERRUPT_IN_ERR;
782 case STATE_CSPLIT_ISOCHRONOUS_IN: return STATE_CSPLIT_ISOCHRONOUS_IN_ERR;
783 default: return STATE_IDLE;
787 /* SPLIT is not suitable for this function as the state cannot be
788 * determined by looking solely at PID.
790 DISSECTOR_ASSERT(pid != USB_PID_SPECIAL_SPLIT);
792 return STATE_IDLE;
795 static bool usbll_is_non_periodic_split_start_token(usbll_state_t state)
797 switch (state)
799 case STATE_SSPLIT_CONTROL_SETUP:
800 case STATE_SSPLIT_CONTROL_OUT:
801 case STATE_SSPLIT_CONTROL_IN:
802 case STATE_SSPLIT_BULK_OUT:
803 case STATE_SSPLIT_BULK_IN:
804 return true;
805 default:
806 return false;
810 static bool usbll_is_periodic_split_start_token(usbll_state_t state)
812 switch (state)
814 case STATE_SSPLIT_INTERRUPT_OUT:
815 case STATE_SSPLIT_INTERRUPT_IN:
816 case STATE_SSPLIT_ISOCHRONOUS_OUT:
817 case STATE_SSPLIT_ISOCHRONOUS_IN:
818 return true;
819 default:
820 return false;
824 static bool usbll_is_split_start_token(usbll_state_t state)
826 return usbll_is_non_periodic_split_start_token(state) || usbll_is_periodic_split_start_token(state);
829 static bool usbll_is_non_periodic_split_complete_token(usbll_state_t state)
831 switch (state)
833 case STATE_CSPLIT_CONTROL_SETUP:
834 case STATE_CSPLIT_CONTROL_OUT:
835 case STATE_CSPLIT_CONTROL_IN:
836 case STATE_CSPLIT_BULK_OUT:
837 case STATE_CSPLIT_BULK_IN:
838 return true;
839 default:
840 return false;
844 static bool usbll_is_periodic_split_complete_token(usbll_state_t state)
846 switch (state)
848 case STATE_CSPLIT_INTERRUPT_OUT:
849 case STATE_CSPLIT_INTERRUPT_IN:
850 case STATE_CSPLIT_ISOCHRONOUS_IN:
851 return true;
852 default:
853 return false;
857 static bool usbll_is_split_complete_token(usbll_state_t state)
859 return usbll_is_non_periodic_split_complete_token(state) || usbll_is_periodic_split_complete_token(state);
862 static bool usbll_is_split_token(usbll_state_t state)
864 return usbll_is_split_start_token(state) || usbll_is_split_complete_token(state);
867 static bool usbll_is_non_split_token(usbll_state_t state)
869 switch (state)
871 case STATE_IN:
872 case STATE_OUT:
873 case STATE_PING:
874 case STATE_SETUP:
875 case STATE_EXT:
876 return true;
877 default:
878 return false;
882 static bool usbll_is_extended_subpid(usbll_state_t state)
884 switch (state)
886 case STATE_SUBPID_INVALID:
887 case STATE_SUBPID_NOT_REUSABLE:
888 case STATE_SUBPID_LPM:
889 case STATE_SUBPID_RESERVED:
890 return true;
891 default:
892 return false;
896 static bool usbll_is_setup_data(usbll_state_t state)
898 switch (state)
900 case STATE_SETUP_DATA0:
901 case STATE_SSPLIT_CONTROL_SETUP_DATA0:
902 return true;
903 default:
904 return false;
908 static bool usbll_is_data_from_host(usbll_state_t state)
910 switch (state)
912 case STATE_OUT_DATA0:
913 case STATE_OUT_DATA1:
914 case STATE_OUT_HS_ISOCHRONOUS_DATA2:
915 case STATE_OUT_HS_ISOCHRONOUS_MDATA:
916 case STATE_SETUP_DATA0:
917 case STATE_SSPLIT_CONTROL_SETUP_DATA0:
918 case STATE_SSPLIT_CONTROL_OUT_DATA0:
919 case STATE_SSPLIT_CONTROL_OUT_DATA1:
920 case STATE_SSPLIT_BULK_OUT_DATA0:
921 case STATE_SSPLIT_BULK_OUT_DATA1:
922 case STATE_SSPLIT_INTERRUPT_OUT_DATA0:
923 case STATE_SSPLIT_INTERRUPT_OUT_DATA1:
924 case STATE_SSPLIT_ISOCHRONOUS_OUT_DATA0:
925 return true;
926 case STATE_IN_DATA0:
927 case STATE_IN_DATA1:
928 case STATE_IN_HS_ISOCHRONOUS_DATA2:
929 case STATE_CSPLIT_CONTROL_IN_DATA0:
930 case STATE_CSPLIT_CONTROL_IN_DATA1:
931 case STATE_CSPLIT_BULK_IN_DATA0:
932 case STATE_CSPLIT_BULK_IN_DATA1:
933 case STATE_CSPLIT_INTERRUPT_IN_MDATA:
934 case STATE_CSPLIT_INTERRUPT_IN_DATA0:
935 case STATE_CSPLIT_INTERRUPT_IN_DATA1:
936 case STATE_CSPLIT_ISOCHRONOUS_IN_DATA0:
937 case STATE_CSPLIT_ISOCHRONOUS_IN_MDATA:
938 return false;
939 default:
940 DISSECTOR_ASSERT_NOT_REACHED();
944 static bool usbll_is_split_data_from_device(usbll_state_t state)
946 switch (state)
948 case STATE_CSPLIT_CONTROL_IN_DATA0:
949 case STATE_CSPLIT_CONTROL_IN_DATA1:
950 case STATE_CSPLIT_BULK_IN_DATA0:
951 case STATE_CSPLIT_BULK_IN_DATA1:
952 case STATE_CSPLIT_INTERRUPT_IN_MDATA:
953 case STATE_CSPLIT_INTERRUPT_IN_DATA0:
954 case STATE_CSPLIT_INTERRUPT_IN_DATA1:
955 case STATE_CSPLIT_ISOCHRONOUS_IN_DATA0:
956 case STATE_CSPLIT_ISOCHRONOUS_IN_MDATA:
957 return true;
958 default:
959 return false;
963 static bool usbll_is_setup_ack(usbll_state_t state)
965 switch (state)
967 case STATE_SETUP_ACK:
968 case STATE_CSPLIT_CONTROL_SETUP_ACK:
969 return true;
970 default:
971 return false;
975 static bool usbll_is_data_ack(usbll_state_t state)
977 switch (state)
979 case STATE_IN_ACK:
980 case STATE_OUT_ACK:
981 case STATE_OUT_NYET:
982 case STATE_CSPLIT_CONTROL_OUT_ACK:
983 case STATE_CSPLIT_BULK_OUT_ACK:
984 case STATE_CSPLIT_INTERRUPT_OUT_ACK:
985 return true;
986 default:
987 return false;
991 static bool usbll_is_acked_data_from_host(usbll_state_t state)
993 switch (state)
995 case STATE_OUT_ACK:
996 case STATE_OUT_NYET:
997 case STATE_CSPLIT_CONTROL_OUT_ACK:
998 case STATE_CSPLIT_BULK_OUT_ACK:
999 case STATE_CSPLIT_INTERRUPT_OUT_ACK:
1000 return true;
1001 case STATE_IN_ACK:
1002 return false;
1003 default:
1004 DISSECTOR_ASSERT_NOT_REACHED();
1008 static bool usbll_is_endpoint_stall(usbll_state_t state)
1010 switch (state)
1012 case STATE_IN_STALL:
1013 case STATE_OUT_STALL:
1014 case STATE_PING_STALL:
1015 case STATE_CSPLIT_CONTROL_OUT_STALL:
1016 case STATE_CSPLIT_CONTROL_IN_STALL:
1017 case STATE_CSPLIT_BULK_OUT_STALL:
1018 case STATE_CSPLIT_BULK_IN_STALL:
1019 case STATE_CSPLIT_INTERRUPT_OUT_STALL:
1020 case STATE_CSPLIT_INTERRUPT_IN_STALL:
1021 return true;
1022 default:
1023 return false;
1027 static bool usbll_is_stalled_data_from_host(usbll_state_t state)
1029 switch (state)
1031 case STATE_OUT_STALL:
1032 case STATE_PING_STALL:
1033 case STATE_CSPLIT_CONTROL_OUT_STALL:
1034 case STATE_CSPLIT_BULK_OUT_STALL:
1035 case STATE_CSPLIT_INTERRUPT_OUT_STALL:
1036 return true;
1037 case STATE_IN_STALL:
1038 case STATE_CSPLIT_CONTROL_IN_STALL:
1039 case STATE_CSPLIT_BULK_IN_STALL:
1040 case STATE_CSPLIT_INTERRUPT_IN_STALL:
1041 return false;
1042 default:
1043 DISSECTOR_ASSERT_NOT_REACHED();
1047 static usb_speed_t usbll_get_data_transaction_speed(usbll_data_t *data)
1049 switch (data->transaction_state)
1051 case STATE_IN_DATA0:
1052 case STATE_IN_DATA1:
1053 case STATE_IN_HS_ISOCHRONOUS_DATA2:
1054 case STATE_IN_STALL:
1055 case STATE_OUT_DATA0:
1056 case STATE_OUT_DATA1:
1057 case STATE_OUT_HS_ISOCHRONOUS_DATA2:
1058 case STATE_OUT_HS_ISOCHRONOUS_MDATA:
1059 case STATE_OUT_STALL:
1060 case STATE_PING_STALL:
1061 case STATE_SETUP_DATA0:
1062 DISSECTOR_ASSERT(data->transaction != NULL);
1063 return data->transaction->speed;
1064 case STATE_SSPLIT_CONTROL_SETUP_DATA0:
1065 case STATE_SSPLIT_CONTROL_OUT_DATA0:
1066 case STATE_SSPLIT_CONTROL_OUT_DATA1:
1067 case STATE_SSPLIT_BULK_OUT_DATA0:
1068 case STATE_SSPLIT_BULK_OUT_DATA1:
1069 case STATE_SSPLIT_INTERRUPT_OUT_DATA0:
1070 case STATE_SSPLIT_INTERRUPT_OUT_DATA1:
1071 case STATE_SSPLIT_ISOCHRONOUS_OUT_DATA0:
1072 DISSECTOR_ASSERT(data->transaction != NULL);
1073 DISSECTOR_ASSERT(data->transaction->split_start != NULL);
1074 return data->transaction->split_start->speed;
1075 case STATE_CSPLIT_CONTROL_OUT_STALL:
1076 case STATE_CSPLIT_CONTROL_IN_DATA0:
1077 case STATE_CSPLIT_CONTROL_IN_DATA1:
1078 case STATE_CSPLIT_CONTROL_IN_STALL:
1079 case STATE_CSPLIT_BULK_OUT_STALL:
1080 case STATE_CSPLIT_BULK_IN_DATA0:
1081 case STATE_CSPLIT_BULK_IN_DATA1:
1082 case STATE_CSPLIT_BULK_IN_STALL:
1083 case STATE_CSPLIT_INTERRUPT_OUT_STALL:
1084 case STATE_CSPLIT_INTERRUPT_IN_MDATA:
1085 case STATE_CSPLIT_INTERRUPT_IN_DATA0:
1086 case STATE_CSPLIT_INTERRUPT_IN_DATA1:
1087 case STATE_CSPLIT_INTERRUPT_IN_STALL:
1088 case STATE_CSPLIT_ISOCHRONOUS_IN_DATA0:
1089 case STATE_CSPLIT_ISOCHRONOUS_IN_MDATA:
1090 DISSECTOR_ASSERT(data->transaction != NULL);
1091 DISSECTOR_ASSERT(data->transaction->split_complete != NULL);
1092 return data->transaction->split_complete->speed;
1093 default:
1094 DISSECTOR_ASSERT_NOT_REACHED();
1098 static int usbll_addr_to_str(const address* addr, char *buf, int buf_len)
1100 const usbll_address_t *addrp = (const usbll_address_t *)addr->data;
1102 if (addrp->flags & USBLL_ADDRESS_HOST) {
1103 (void) g_strlcpy(buf, "host", buf_len);
1104 } else if (addrp->flags & USBLL_ADDRESS_BROADCAST) {
1105 (void) g_strlcpy(buf, "broadcast", buf_len);
1106 } else if (addrp->flags & USBLL_ADDRESS_HUB_PORT) {
1108 * In split transaction we use : to mark that the last part is port not
1109 * endpoint.
1111 snprintf(buf, buf_len, "%d:%d", addrp->device,
1112 addrp->endpoint);
1113 } else {
1114 /* Just a standard address.endpoint notation. */
1115 snprintf(buf, buf_len, "%d.%d", addrp->device,
1116 addrp->endpoint);
1119 return (int)(strlen(buf)+1);
1122 static int usbll_addr_str_len(const address* addr _U_)
1124 return 50; /* The same as for usb. */
1127 static void
1128 usbll_set_address(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo,
1129 uint8_t device, uint8_t endpoint, uint8_t flags)
1131 proto_item *sub_item;
1132 usbll_address_t *src_addr, *dst_addr;
1133 uint8_t *str_src_addr, *str_dst_addr;
1135 src_addr = wmem_new0(pinfo->pool, usbll_address_t);
1136 dst_addr = wmem_new0(pinfo->pool, usbll_address_t);
1138 if (USBLL_ADDRESS_IS_HOST_TO_DEV(flags)) {
1139 src_addr->flags = USBLL_ADDRESS_HOST;
1141 if (flags & USBLL_ADDRESS_BROADCAST) {
1142 dst_addr->flags = USBLL_ADDRESS_BROADCAST;
1143 pinfo->ptype = PT_NONE;
1144 } else {
1145 dst_addr->device = device;
1146 dst_addr->endpoint = endpoint;
1147 if (flags & USBLL_ADDRESS_HUB_PORT) {
1148 dst_addr->flags = USBLL_ADDRESS_HUB_PORT;
1149 pinfo->ptype = PT_NONE;
1150 } else {
1151 pinfo->ptype = PT_USB;
1152 pinfo->destport = dst_addr->endpoint;
1155 } else {
1156 dst_addr->flags = USBLL_ADDRESS_HOST;
1157 src_addr->device = device;
1158 src_addr->endpoint = endpoint;
1159 if (flags & USBLL_ADDRESS_HUB_PORT) {
1160 src_addr->flags = USBLL_ADDRESS_HUB_PORT;
1161 pinfo->ptype = PT_NONE;
1162 } else {
1163 pinfo->ptype = PT_USB;
1164 pinfo->srcport = src_addr->endpoint;
1165 pinfo->destport = NO_ENDPOINT;
1169 pinfo->p2p_dir = USBLL_ADDRESS_IS_HOST_TO_DEV(flags) ? P2P_DIR_SENT : P2P_DIR_RECV;
1171 set_address(&pinfo->net_src, usbll_address_type, sizeof(usbll_address_t), (char *)src_addr);
1172 copy_address_shallow(&pinfo->src, &pinfo->net_src);
1174 set_address(&pinfo->net_dst, usbll_address_type, sizeof(usbll_address_t), (char *)dst_addr);
1175 copy_address_shallow(&pinfo->dst, &pinfo->net_dst);
1177 str_src_addr = address_to_str(pinfo->pool, &pinfo->src);
1178 str_dst_addr = address_to_str(pinfo->pool, &pinfo->dst);
1180 sub_item = proto_tree_add_string(tree, hf_usbll_src, tvb, 0, 0, str_src_addr);
1181 proto_item_set_generated(sub_item);
1183 sub_item = proto_tree_add_string(tree, hf_usbll_addr, tvb, 0, 0, str_src_addr);
1184 proto_item_set_hidden(sub_item);
1186 sub_item = proto_tree_add_string(tree, hf_usbll_dst, tvb, 0, 0, str_dst_addr);
1187 proto_item_set_generated(sub_item);
1189 sub_item = proto_tree_add_string(tree, hf_usbll_addr, tvb, 0, 0, str_dst_addr);
1190 proto_item_set_hidden(sub_item);
1193 static void
1194 usbll_generate_address(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo, usbll_data_t *data)
1196 switch (data->transaction_state)
1198 case STATE_IDLE:
1199 case STATE_INVALID:
1200 /* Do not set address if we are not sure about it */
1201 break;
1202 case STATE_IN:
1203 case STATE_IN_ACK:
1204 case STATE_OUT:
1205 case STATE_OUT_DATA0:
1206 case STATE_OUT_DATA1:
1207 case STATE_OUT_HS_ISOCHRONOUS_DATA2:
1208 case STATE_OUT_HS_ISOCHRONOUS_MDATA:
1209 case STATE_PING:
1210 case STATE_SETUP:
1211 case STATE_SETUP_DATA0:
1212 case STATE_EXT:
1213 case STATE_SUBPID_INVALID:
1214 case STATE_SUBPID_NOT_REUSABLE:
1215 case STATE_SUBPID_LPM:
1216 case STATE_SUBPID_RESERVED:
1217 DISSECTOR_ASSERT(data->transaction != NULL);
1218 usbll_set_address(tree, tvb, pinfo,
1219 data->transaction->address, data->transaction->endpoint,
1220 USBLL_ADDRESS_HOST_TO_DEV);
1221 break;
1222 case STATE_IN_DATA0:
1223 case STATE_IN_DATA1:
1224 case STATE_IN_HS_ISOCHRONOUS_DATA2:
1225 case STATE_IN_NAK:
1226 case STATE_IN_STALL:
1227 case STATE_OUT_ACK:
1228 case STATE_OUT_NAK:
1229 case STATE_OUT_STALL:
1230 case STATE_OUT_NYET:
1231 case STATE_PING_ACK:
1232 case STATE_PING_NAK:
1233 case STATE_PING_STALL:
1234 case STATE_SETUP_ACK:
1235 case STATE_SUBPID_LPM_ACK:
1236 case STATE_SUBPID_LPM_NYET:
1237 case STATE_SUBPID_LPM_STALL:
1238 DISSECTOR_ASSERT(data->transaction != NULL);
1239 usbll_set_address(tree, tvb, pinfo,
1240 data->transaction->address, data->transaction->endpoint,
1241 USBLL_ADDRESS_DEV_TO_HOST);
1242 break;
1243 case STATE_SSPLIT_CONTROL:
1244 case STATE_CSPLIT_CONTROL:
1245 case STATE_SSPLIT_BULK:
1246 case STATE_CSPLIT_BULK:
1247 case STATE_SSPLIT_INTERRUPT:
1248 case STATE_CSPLIT_INTERRUPT:
1249 case STATE_SSPLIT_ISOCHRONOUS:
1250 case STATE_CSPLIT_ISOCHRONOUS:
1251 DISSECTOR_ASSERT(data->transaction != NULL);
1252 usbll_set_address(tree, tvb, pinfo,
1253 data->transaction->address, data->transaction->endpoint,
1254 USBLL_ADDRESS_HOST_TO_DEV | USBLL_ADDRESS_HUB_PORT);
1255 break;
1256 case STATE_SSPLIT_CONTROL_SETUP:
1257 case STATE_SSPLIT_CONTROL_SETUP_DATA0:
1258 case STATE_SSPLIT_CONTROL_OUT:
1259 case STATE_SSPLIT_CONTROL_OUT_DATA0:
1260 case STATE_SSPLIT_CONTROL_OUT_DATA1:
1261 case STATE_SSPLIT_CONTROL_IN:
1262 case STATE_SSPLIT_BULK_OUT:
1263 case STATE_SSPLIT_BULK_OUT_DATA0:
1264 case STATE_SSPLIT_BULK_OUT_DATA1:
1265 case STATE_SSPLIT_BULK_IN:
1266 case STATE_SSPLIT_INTERRUPT_OUT:
1267 case STATE_SSPLIT_INTERRUPT_OUT_DATA0:
1268 case STATE_SSPLIT_INTERRUPT_OUT_DATA1:
1269 case STATE_SSPLIT_INTERRUPT_IN:
1270 case STATE_SSPLIT_ISOCHRONOUS_OUT:
1271 case STATE_SSPLIT_ISOCHRONOUS_OUT_DATA0:
1272 case STATE_SSPLIT_ISOCHRONOUS_IN:
1273 DISSECTOR_ASSERT(data->transaction != NULL);
1274 DISSECTOR_ASSERT(data->transaction->split_start != NULL);
1275 usbll_set_address(tree, tvb, pinfo,
1276 data->transaction->address, data->transaction->endpoint,
1277 USBLL_ADDRESS_HOST_TO_DEV);
1278 break;
1279 case STATE_SSPLIT_CONTROL_SETUP_ACK:
1280 case STATE_SSPLIT_CONTROL_SETUP_NAK:
1281 case STATE_SSPLIT_CONTROL_OUT_ACK:
1282 case STATE_SSPLIT_CONTROL_OUT_NAK:
1283 case STATE_SSPLIT_CONTROL_IN_ACK:
1284 case STATE_SSPLIT_CONTROL_IN_NAK:
1285 case STATE_SSPLIT_BULK_OUT_ACK:
1286 case STATE_SSPLIT_BULK_OUT_NAK:
1287 case STATE_SSPLIT_BULK_IN_ACK:
1288 case STATE_SSPLIT_BULK_IN_NAK:
1289 DISSECTOR_ASSERT(data->transaction != NULL);
1290 DISSECTOR_ASSERT(data->transaction->split_start != NULL);
1291 usbll_set_address(tree, tvb, pinfo,
1292 data->transaction->split_start->address, data->transaction->split_start->endpoint,
1293 USBLL_ADDRESS_DEV_TO_HOST | USBLL_ADDRESS_HUB_PORT);
1294 break;
1295 case STATE_CSPLIT_CONTROL_SETUP:
1296 case STATE_CSPLIT_CONTROL_OUT:
1297 case STATE_CSPLIT_CONTROL_IN:
1298 case STATE_CSPLIT_BULK_OUT:
1299 case STATE_CSPLIT_BULK_IN:
1300 case STATE_CSPLIT_INTERRUPT_OUT:
1301 case STATE_CSPLIT_INTERRUPT_IN:
1302 case STATE_CSPLIT_ISOCHRONOUS_IN:
1303 DISSECTOR_ASSERT(data->transaction != NULL);
1304 DISSECTOR_ASSERT(data->transaction->split_complete != NULL);
1305 usbll_set_address(tree, tvb, pinfo,
1306 data->transaction->address, data->transaction->endpoint,
1307 USBLL_ADDRESS_HOST_TO_DEV);
1308 break;
1309 case STATE_CSPLIT_CONTROL_SETUP_ACK:
1310 case STATE_CSPLIT_CONTROL_OUT_ACK:
1311 case STATE_CSPLIT_CONTROL_OUT_NAK:
1312 case STATE_CSPLIT_CONTROL_OUT_STALL:
1313 case STATE_CSPLIT_CONTROL_IN_DATA0:
1314 case STATE_CSPLIT_CONTROL_IN_DATA1:
1315 case STATE_CSPLIT_CONTROL_IN_NAK:
1316 case STATE_CSPLIT_CONTROL_IN_STALL:
1317 case STATE_CSPLIT_BULK_OUT_ACK:
1318 case STATE_CSPLIT_BULK_OUT_NAK:
1319 case STATE_CSPLIT_BULK_OUT_STALL:
1320 case STATE_CSPLIT_BULK_IN_DATA0:
1321 case STATE_CSPLIT_BULK_IN_DATA1:
1322 case STATE_CSPLIT_BULK_IN_NAK:
1323 case STATE_CSPLIT_BULK_IN_STALL:
1324 case STATE_CSPLIT_INTERRUPT_OUT_ACK:
1325 case STATE_CSPLIT_INTERRUPT_OUT_NAK:
1326 case STATE_CSPLIT_INTERRUPT_OUT_STALL:
1327 case STATE_CSPLIT_INTERRUPT_IN_MDATA:
1328 case STATE_CSPLIT_INTERRUPT_IN_DATA0:
1329 case STATE_CSPLIT_INTERRUPT_IN_DATA1:
1330 case STATE_CSPLIT_INTERRUPT_IN_NAK:
1331 case STATE_CSPLIT_INTERRUPT_IN_STALL:
1332 case STATE_CSPLIT_ISOCHRONOUS_IN_DATA0:
1333 case STATE_CSPLIT_ISOCHRONOUS_IN_MDATA:
1334 DISSECTOR_ASSERT(data->transaction != NULL);
1335 DISSECTOR_ASSERT(data->transaction->split_complete != NULL);
1336 usbll_set_address(tree, tvb, pinfo,
1337 data->transaction->address, data->transaction->endpoint,
1338 USBLL_ADDRESS_DEV_TO_HOST);
1339 break;
1340 case STATE_CSPLIT_CONTROL_SETUP_NYET:
1341 case STATE_CSPLIT_CONTROL_OUT_NYET:
1342 case STATE_CSPLIT_CONTROL_IN_NYET:
1343 case STATE_CSPLIT_BULK_OUT_NYET:
1344 case STATE_CSPLIT_BULK_IN_NYET:
1345 case STATE_CSPLIT_INTERRUPT_OUT_ERR:
1346 case STATE_CSPLIT_INTERRUPT_OUT_NYET:
1347 case STATE_CSPLIT_INTERRUPT_IN_ERR:
1348 case STATE_CSPLIT_INTERRUPT_IN_NYET:
1349 case STATE_CSPLIT_ISOCHRONOUS_IN_ERR:
1350 case STATE_CSPLIT_ISOCHRONOUS_IN_NYET:
1351 DISSECTOR_ASSERT(data->transaction != NULL);
1352 usbll_set_address(tree, tvb, pinfo,
1353 data->transaction->address, data->transaction->endpoint,
1354 USBLL_ADDRESS_DEV_TO_HOST | USBLL_ADDRESS_HUB_PORT);
1355 break;
1356 default:
1357 DISSECTOR_ASSERT_NOT_REACHED();
1361 static usbll_transaction_info_t *
1362 tt_restore_transaction(packet_info *pinfo, usbll_state_t state, uint8_t hub_address, uint8_t port)
1364 /* The buffer is simply updated with each subsequent packet, this is fine
1365 * if and only if we access it only during first pass.
1367 DISSECTOR_ASSERT(!PINFO_FD_VISITED(pinfo));
1368 DISSECTOR_ASSERT(usbll_is_split_complete_token(state));
1369 DISSECTOR_ASSERT(hub_address <= 127);
1370 DISSECTOR_ASSERT(port <= 127);
1372 if (!tt_periodic || !tt_non_periodic)
1374 /* No transaction has been registered yet */
1375 return NULL;
1378 if (usbll_is_periodic_split_complete_token(state))
1380 return tt_periodic[hub_address][port];
1382 else
1384 DISSECTOR_ASSERT(usbll_is_non_periodic_split_complete_token(state));
1385 return tt_non_periodic[hub_address][port];
1389 static void
1390 tt_store_transaction(packet_info *pinfo, usbll_state_t state, uint8_t hub_address, uint8_t port,
1391 usbll_transaction_info_t *transaction)
1393 DISSECTOR_ASSERT(!PINFO_FD_VISITED(pinfo));
1394 DISSECTOR_ASSERT(usbll_is_split_start_token(state));
1395 DISSECTOR_ASSERT(hub_address <= 127);
1396 DISSECTOR_ASSERT(port <= 127);
1398 if (!tt_periodic || !tt_non_periodic)
1400 /* Lazy allocate lookup table. Both address and port are 7 bit numbers,
1401 * so simply allocate buffers capable to hold all possible combinations.
1403 int i;
1404 tt_periodic = wmem_alloc_array(wmem_file_scope(), usbll_transaction_info_t **, 128);
1405 for (i = 0; i < 128; i++)
1407 tt_periodic[i] = wmem_alloc0_array(wmem_file_scope(), usbll_transaction_info_t *, 128);
1409 tt_non_periodic = wmem_alloc_array(wmem_file_scope(), usbll_transaction_info_t **, 128);
1410 for (i = 0; i < 128; i++)
1412 tt_non_periodic[i] = wmem_alloc0_array(wmem_file_scope(), usbll_transaction_info_t *, 128);
1416 if (usbll_is_periodic_split_start_token(state))
1418 tt_periodic[hub_address][port] = transaction;
1420 else
1422 DISSECTOR_ASSERT(usbll_is_non_periodic_split_start_token(state));
1423 tt_non_periodic[hub_address][port] = transaction;
1427 static usbll_ep_type_t
1428 usbll_ep_type_from_urb_type(uint8_t urb_type)
1430 switch (urb_type)
1432 case URB_ISOCHRONOUS: return USBLL_EP_ISOCHRONOUS;
1433 case URB_INTERRUPT: return USBLL_EP_INTERRUPT;
1434 case URB_CONTROL: return USBLL_EP_CONTROL;
1435 case URB_BULK: return USBLL_EP_BULK;
1436 default: return USBLL_EP_UNKNOWN;
1440 static void
1441 usbll_reset_endpoint_info(usbll_endpoint_info_t *info, usbll_ep_type_t type, uint16_t max_packet_size)
1443 info->type = type;
1444 info->data = USBLL_TRANSFER_NORMAL;
1445 info->max_packet_size = max_packet_size;
1446 info->last_data_pid = 0;
1447 info->last_data_acked = false;
1448 info->active_transfer_key = 0;
1449 info->transfer_offset = 0;
1450 info->last_data_len = 0;
1451 info->requested_transfer_length = 0;
1454 static void usbll_reset_device_endpoints(int addr)
1456 int ep;
1457 DISSECTOR_ASSERT((addr >= 0) && (addr <= 127));
1459 /* Endpoint 0 is always control type */
1460 usbll_reset_endpoint_info(&ep_info_in[addr][0], USBLL_EP_CONTROL, 0);
1461 usbll_reset_endpoint_info(&ep_info_out[addr][0], USBLL_EP_CONTROL, 0);
1462 for (ep = 1; ep < 16; ep++)
1464 usbll_reset_endpoint_info(&ep_info_in[addr][ep], USBLL_EP_UNKNOWN, 0);
1465 usbll_reset_endpoint_info(&ep_info_out[addr][ep], USBLL_EP_UNKNOWN, 0);
1469 static void usbll_init_endpoint_tables(void)
1471 /* Address is 7 bits (0 - 127), while endpoint is 4 bits (0 - 15) */
1472 int addr;
1473 ep_info_in = wmem_alloc_array(wmem_file_scope(), usbll_endpoint_info_t *, 128);
1474 for (addr = 0; addr < 128; addr++)
1476 ep_info_in[addr] = wmem_alloc_array(wmem_file_scope(), usbll_endpoint_info_t, 16);
1478 ep_info_out = wmem_alloc_array(wmem_file_scope(), usbll_endpoint_info_t *, 128);
1479 for (addr = 0; addr < 128; addr++)
1481 ep_info_out[addr] = wmem_alloc_array(wmem_file_scope(), usbll_endpoint_info_t, 16);
1484 for (addr = 0; addr < 128; addr++)
1486 usbll_reset_device_endpoints(addr);
1490 static usbll_endpoint_info_t *
1491 usbll_get_endpoint_info(packet_info *pinfo, uint8_t addr, uint8_t ep, bool from_host)
1493 usbll_endpoint_info_t *info;
1494 DISSECTOR_ASSERT(!PINFO_FD_VISITED(pinfo));
1495 DISSECTOR_ASSERT(addr <= 127);
1496 DISSECTOR_ASSERT(ep <= 15);
1498 if (!ep_info_in || !ep_info_out)
1500 usbll_init_endpoint_tables();
1501 DISSECTOR_ASSERT(ep_info_in != NULL);
1502 DISSECTOR_ASSERT(ep_info_out != NULL);
1505 if (from_host)
1507 info = &ep_info_out[addr][ep];
1509 else
1511 info = &ep_info_in[addr][ep];
1514 if (ep != 0)
1516 /* Get endpoint type and max packet size from USB dissector
1517 * USB dissector gets the information from CONFIGURATION descriptor
1519 * TODO: Reorganize USB dissector to call us whenever selected
1520 * configuration and/or interface changes. USB dissector
1521 * currently assumes only one configuration and that all
1522 * alternate interface settings have matching endpoint
1523 * information. This should be fixed but is good for now
1524 * as most devices fullfills this (wrong) assumption.
1526 usb_conv_info_t *usb_conv_info;
1527 usbll_ep_type_t type = USBLL_EP_UNKNOWN;
1528 uint16_t max_packet_size = 0;
1529 uint8_t endpoint = ep | (from_host ? 0 : 0x80);
1530 usb_conv_info = get_existing_usb_ep_conv_info(pinfo, 0, addr, endpoint);
1531 if (usb_conv_info && usb_conv_info->max_packet_size)
1533 type = usbll_ep_type_from_urb_type(usb_conv_info->descriptor_transfer_type);
1534 max_packet_size = usb_conv_info->max_packet_size;
1536 /* Reset endpoint info if endpoint parameters changed */
1537 if ((info->type != type) || (info->max_packet_size != max_packet_size))
1539 usbll_reset_endpoint_info(info, type, max_packet_size);
1543 return info;
1546 static int
1547 dissect_usbll_sof(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
1549 uint32_t frame;
1550 /* SOF Packets are broadcasted from Host to all devices. */
1551 usbll_set_address(tree, tvb, pinfo, 0, 0, USBLL_ADDRESS_HOST_TO_DEV | USBLL_ADDRESS_BROADCAST);
1553 proto_tree_add_item_ret_uint(tree, hf_usbll_sof_framenum, tvb, offset, 2, ENC_LITTLE_ENDIAN, &frame);
1554 proto_tree_add_checksum(tree, tvb, offset,
1555 hf_usbll_crc5, hf_usbll_crc5_status, &ei_wrong_crc5, pinfo,
1556 crc5_usb_11bit_input(frame),
1557 ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
1558 offset += 2;
1560 return offset;
1563 static int
1564 dissect_usbll_token(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset,
1565 uint8_t pid, usbll_data_t *data, usb_speed_t speed)
1567 uint8_t device_address;
1568 uint8_t endpoint;
1569 uint16_t address_bits;
1571 static int * const address_fields[] = {
1572 &hf_usbll_device_addr,
1573 &hf_usbll_endp,
1574 NULL
1577 address_bits = tvb_get_letohs(tvb, offset);
1578 device_address = TOKEN_BITS_GET_ADDRESS(address_bits);
1579 endpoint = TOKEN_BITS_GET_ENDPOINT(address_bits);
1581 proto_tree_add_bitmask_list_value(tree, tvb, offset, 2, address_fields, address_bits);
1582 proto_tree_add_checksum(tree, tvb, offset,
1583 hf_usbll_crc5, hf_usbll_crc5_status, &ei_wrong_crc5, pinfo,
1584 crc5_usb_11bit_input(address_bits),
1585 ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
1586 offset += 2;
1588 if (!PINFO_FD_VISITED(pinfo))
1590 usbll_state_t prev_state;
1591 usbll_transaction_info_t *transaction = NULL;
1592 usbll_transaction_info_t *split_transaction = NULL;
1594 prev_state = data->prev ? data->prev->transaction_state : STATE_IDLE;
1595 data->transaction_state = usbll_next_state(prev_state, pid);
1597 DISSECTOR_ASSERT(usbll_is_non_split_token(data->transaction_state) ||
1598 usbll_is_split_token(data->transaction_state));
1600 if (usbll_is_split_complete_token(data->transaction_state))
1602 DISSECTOR_ASSERT(data->prev != NULL);
1603 DISSECTOR_ASSERT(data->prev->transaction != NULL);
1604 DISSECTOR_ASSERT(data->prev->transaction->pid == USB_PID_SPECIAL_SPLIT);
1605 split_transaction = data->prev->transaction;
1607 transaction = tt_restore_transaction(pinfo, data->transaction_state,
1608 split_transaction->address, split_transaction->endpoint);
1610 if (transaction == NULL)
1612 /* Most likely capture simply misses Split Start */
1613 transaction = wmem_new0(wmem_file_scope(), usbll_transaction_info_t);
1614 transaction->pid = pid;
1615 transaction->address = device_address;
1616 transaction->endpoint = endpoint;
1617 transaction->speed = speed;
1620 transaction->split_complete = data->prev->transaction;
1622 else
1624 transaction = wmem_new0(wmem_file_scope(), usbll_transaction_info_t);
1625 transaction->starts_in = pinfo->num;
1626 transaction->pid = pid;
1627 transaction->address = device_address;
1628 transaction->endpoint = endpoint;
1629 transaction->speed = speed;
1632 if (usbll_is_split_start_token(data->transaction_state))
1634 DISSECTOR_ASSERT(data->prev != NULL);
1635 DISSECTOR_ASSERT(data->prev->transaction != NULL);
1636 DISSECTOR_ASSERT(data->prev->transaction->pid == USB_PID_SPECIAL_SPLIT);
1637 transaction->split_start = data->prev->transaction;
1639 tt_store_transaction(pinfo, data->transaction_state,
1640 transaction->split_start->address, transaction->split_start->endpoint,
1641 transaction);
1644 data->transaction = transaction;
1647 return offset;
1650 static bool
1651 packet_ends_transfer(usbll_endpoint_info_t *ep_info, uint32_t offset, int data_size)
1653 DISSECTOR_ASSERT(ep_info->type != USBLL_EP_UNKNOWN);
1655 if (ep_info->requested_transfer_length != 0)
1657 /* We know requested transfer length */
1658 if (offset + data_size >= ep_info->requested_transfer_length)
1660 /* No more data needed */
1661 return true;
1663 /* else check max packet size as transfer can end prematurely */
1665 else
1667 DISSECTOR_ASSERT(ep_info->type != USBLL_EP_CONTROL);
1668 DISSECTOR_ASSERT(ep_info->max_packet_size != 0);
1669 /* We don't know requested transfer length, for bulk transfers
1670 * assume that transfer can be larger than max packet length,
1671 * for periodic transfers assume transfer is not larger than
1672 * max packet length.
1674 if (ep_info->type != USBLL_EP_BULK)
1676 /* For High-Bandwidth endpoints allow up to Total Payload Length */
1677 if (USB_MPS_ADDNL(ep_info->max_packet_size))
1679 uint32_t total_payload = USB_MPS_TPL(ep_info->max_packet_size);
1681 /* Short packet always ends transfer */
1682 if (data_size < USB_MPS_EP_SIZE(ep_info->max_packet_size))
1684 return true;
1687 return offset + data_size >= total_payload;
1690 return true;
1694 if (ep_info->max_packet_size)
1696 return data_size < ep_info->max_packet_size;
1699 DISSECTOR_ASSERT(ep_info->type == USBLL_EP_CONTROL);
1700 /* This code is valid only for high-speed control endpoints */
1701 if (data_size < 64)
1703 return true;
1706 return false;
1709 static bool is_get_device_descriptor(uint8_t setup[8])
1711 uint16_t lang_id = setup[4] | (setup[5] << 8);
1712 uint16_t length = setup[6] | (setup[7] << 8);
1713 return (setup[0] == USB_DIR_IN) &&
1714 (setup[1] == USB_SETUP_GET_DESCRIPTOR) &&
1715 (setup[2] == 0x00) && /* Descriptor Index */
1716 (setup[3] == 0x01) && /* DEVICE descriptor */
1717 (lang_id == 0x00) && /* no language specified */
1718 (length >= 8); /* atleast 8 bytes needed to get bMaxPacketSize0 */
1721 static bool is_set_address(uint8_t setup[8])
1723 uint16_t addr = setup[2] | (setup[3] << 8);
1724 uint16_t idx = setup[4] | (setup[5] << 8);
1725 uint16_t length = setup[6] | (setup[7] << 8);
1726 return (setup[0] == USB_DIR_OUT) &&
1727 (setup[1] == USB_SETUP_SET_ADDRESS) &&
1728 (addr <= 127) && (idx == 0x00) && (length == 0x00);
1731 static void
1732 usbll_construct_urb(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1733 int data_offset, int data_size, usbll_data_t *data)
1735 usbll_transfer_info_t *transfer = NULL;
1737 transfer = (usbll_transfer_info_t *)wmem_map_lookup(transfer_info, GUINT_TO_POINTER(pinfo->num));
1738 if (transfer)
1740 tvbuff_t *transfer_tvb;
1742 if ((transfer->first_packet == pinfo->num) && (!transfer->more_frags) &&
1743 (((transfer->type == USBLL_EP_CONTROL) && (transfer->from_host)) ||
1744 (transfer->type == USBLL_EP_ISOCHRONOUS)))
1746 /* No multi-packet reassembly needed, simply construct tvb */
1747 transfer_tvb = tvb_new_subset_length(tvb, data_offset, data_size);
1748 add_new_data_source(pinfo, transfer_tvb, "USB transfer");
1750 else
1752 fragment_head *head;
1753 head = fragment_add_check_with_fallback(&usbll_reassembly_table,
1754 tvb, data_offset,
1755 pinfo, transfer->first_packet, NULL,
1756 transfer->offset, data_size, transfer->more_frags, transfer->first_packet);
1757 transfer_tvb = process_reassembled_data(tvb, data_offset, pinfo,
1758 "USB transfer", head, &usbll_frag_items,
1759 NULL, tree);
1762 if (transfer_tvb != NULL)
1764 usb_pseudo_urb_t pseudo_urb;
1765 pseudo_urb.from_host = transfer->from_host;
1766 switch (transfer->type)
1768 case USBLL_EP_UNKNOWN:
1769 pseudo_urb.transfer_type = URB_UNKNOWN;
1770 break;
1771 case USBLL_EP_CONTROL:
1772 pseudo_urb.transfer_type = URB_CONTROL;
1773 break;
1774 case USBLL_EP_BULK:
1775 pseudo_urb.transfer_type = URB_BULK;
1776 break;
1777 case USBLL_EP_INTERRUPT:
1778 pseudo_urb.transfer_type = URB_INTERRUPT;
1779 break;
1780 case USBLL_EP_ISOCHRONOUS:
1781 pseudo_urb.transfer_type = URB_ISOCHRONOUS;
1782 break;
1783 default:
1784 DISSECTOR_ASSERT_NOT_REACHED();
1786 pseudo_urb.device_address = data->transaction->address;
1787 pseudo_urb.endpoint = data->transaction->endpoint | (transfer->from_host ? 0 : 0x80);
1788 pseudo_urb.bus_id = 0;
1789 pseudo_urb.speed = usbll_get_data_transaction_speed(data);
1790 dissect_usb_common(transfer_tvb, pinfo, proto_tree_get_parent_tree(tree),
1791 USB_HEADER_PSEUDO_URB, &pseudo_urb);
1796 static int
1797 dissect_usbll_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset,
1798 uint8_t pid, usbll_data_t *data, int *payload_size)
1800 /* TODO: How to determine the expected DATA size? */
1801 uint16_t computed_crc, actual_crc;
1802 int data_offset = offset;
1803 int data_size = tvb_reported_length_remaining(tvb, offset) - 2;
1804 proto_item *data_item = NULL;
1805 usbll_transfer_info_t *transfer = NULL;
1807 data_item = proto_tree_add_item(tree, hf_usbll_data, tvb, offset, data_size, ENC_NA);
1808 offset += data_size;
1810 actual_crc = tvb_get_letohs(tvb, offset);
1811 computed_crc = crc16_usb_tvb_offset(tvb, 1, offset - 1);
1812 proto_tree_add_checksum(tree, tvb, offset,
1813 hf_usbll_data_crc, hf_usbll_data_crc_status, &ei_wrong_crc16, pinfo,
1814 computed_crc, ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
1815 offset += 2;
1817 if (!PINFO_FD_VISITED(pinfo))
1819 usbll_state_t prev_state;
1821 prev_state = data->prev ? data->prev->transaction_state : STATE_IDLE;
1822 data->transaction_state = usbll_next_state(prev_state, pid);
1823 if (data->transaction_state != STATE_INVALID)
1825 DISSECTOR_ASSERT(data->prev != NULL);
1826 DISSECTOR_ASSERT(data->prev->transaction != NULL);
1827 data->transaction = data->prev->transaction;
1831 if (actual_crc != computed_crc)
1833 /* Do not reassemble on CRC error */
1834 return offset;
1837 if (usbll_is_setup_data(data->transaction_state))
1839 if (data_size != 8)
1841 expert_add_info(pinfo, data_item, &ei_invalid_setup_data);
1843 else if (!PINFO_FD_VISITED(pinfo))
1845 usbll_endpoint_info_t *ep_out, *ep_in;
1847 ep_out = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, true);
1848 ep_in = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, false);
1850 /* Check if SETUP data is indeed to control endpoint (discard if targtet endpoint is not control).
1851 * Practically all control transfers are to endpoint 0 which is always control endpoint.
1853 if ((ep_out->type == USBLL_EP_CONTROL) && (ep_in->type == USBLL_EP_CONTROL))
1855 uint8_t setup[8];
1856 bool data_stage_from_host;
1857 uint16_t requested_length;
1859 tvb_memcpy(tvb, setup, data_offset, 8);
1861 /* bmRequestType D7 0 = Host-to-device, 1 = Device-to-host */
1862 data_stage_from_host = (setup[0] & 0x80) ? false : true;
1863 /* wLength */
1864 requested_length = setup[6] | (setup[7] << 8);
1866 usbll_reset_endpoint_info(ep_out, USBLL_EP_CONTROL, ep_out->max_packet_size);
1867 usbll_reset_endpoint_info(ep_in, USBLL_EP_CONTROL, ep_in->max_packet_size);
1869 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
1870 transfer->first_packet = pinfo->num;
1871 transfer->offset = 0;
1872 transfer->type = USBLL_EP_CONTROL;
1873 transfer->from_host = true; /* SETUP is always from host to service */
1875 if (requested_length > 0)
1877 if (data_stage_from_host)
1879 /* Merge SETUP data with OUT Data to pass to USB dissector */
1880 transfer->more_frags = true;
1881 ep_out->active_transfer_key = pinfo->num;
1882 ep_out->requested_transfer_length = 8 + requested_length;
1883 ep_out->transfer_offset = 8;
1884 ep_out->last_data_pid = pid;
1885 ep_out->last_data_acked = false;
1886 /* If SETUP is sent again, it always starts a new transfer.
1887 * If we receive DATA0 next then it is really a host failure.
1888 * Do not "overwrite" the 8 SETUP bytes in such case.
1890 ep_out->last_data_len = 0;
1892 else
1894 transfer->more_frags = false;
1895 /* Expect requested_length when reading from control endpoint.
1896 * The data should start with DATA1. If we receive DATA0 then
1897 * this is really device failure.
1899 ep_in->requested_transfer_length = requested_length;
1900 ep_in->last_data_pid = pid;
1901 ep_in->last_data_acked = false;
1902 ep_in->last_data_len = 0;
1906 if (is_get_device_descriptor(setup))
1908 ep_in->data = USBLL_TRANSFER_GET_DEVICE_DESCRIPTOR;
1910 else if (is_set_address(setup))
1912 int addr = setup[2];
1913 if (addr > 0)
1915 /* Prevent transfer reassembly across reset boundary.
1916 * Do not reset for default address (0) because there
1917 * can only be control transfers to default address
1918 * and we don't want to lose max packet size info.
1920 usbll_reset_device_endpoints(addr);
1924 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
1928 else if ((!PINFO_FD_VISITED(pinfo)) && (data->transaction_state != STATE_INVALID))
1930 usbll_endpoint_info_t *ep_info;
1931 bool from_host;
1933 from_host = usbll_is_data_from_host(data->transaction_state);
1934 ep_info = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, from_host);
1936 if (ep_info->type == USBLL_EP_CONTROL)
1938 if (ep_info->requested_transfer_length > 0)
1940 if (pid == ep_info->last_data_pid)
1942 if (ep_info->last_data_len == 0)
1944 /* We received DATA0 immediately after SETUP (as response to OUT or IN)
1945 * Do not reassemble the data, instead mark it as unexpected PID.
1947 data->transaction_state = STATE_INVALID;
1949 else
1951 /* Retransmission */
1952 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
1953 transfer->first_packet = ep_info->active_transfer_key;
1954 transfer->offset = ep_info->transfer_offset - ep_info->last_data_len;
1955 transfer->type = USBLL_EP_CONTROL;
1956 transfer->from_host = from_host;
1957 transfer->more_frags = !packet_ends_transfer(ep_info, transfer->offset, data_size);
1958 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
1959 /* Do not update endpoint info, previously transferred packet must have
1960 * the same data length as retransmitted packet.
1964 else if ((pid == USB_PID_DATA_DATA0) || (pid == USB_PID_DATA_DATA1))
1966 if (ep_info->active_transfer_key == 0)
1968 /* This is allowed only when Data stage is from device to host */
1969 DISSECTOR_ASSERT(!from_host);
1970 DISSECTOR_ASSERT(ep_info->transfer_offset == 0);
1971 DISSECTOR_ASSERT(ep_info->last_data_len == 0);
1972 ep_info->active_transfer_key = pinfo->num;
1974 if ((ep_info->data == USBLL_TRANSFER_GET_DEVICE_DESCRIPTOR) && (data_size >= 8))
1976 usbll_endpoint_info_t *ep_out;
1977 usb_speed_t speed;
1978 uint16_t max_packet_size;
1979 ep_out = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, true);
1980 max_packet_size = tvb_get_uint8(tvb, data_offset + 7);
1981 speed = usbll_get_data_transaction_speed(data);
1982 max_packet_size = sanitize_usb_max_packet_size(ENDPOINT_TYPE_CONTROL, speed, max_packet_size);
1983 ep_info->max_packet_size = ep_out->max_packet_size = max_packet_size;
1986 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
1987 transfer->first_packet = ep_info->active_transfer_key;
1988 transfer->offset = ep_info->transfer_offset;
1989 transfer->type = USBLL_EP_CONTROL;
1990 transfer->from_host = from_host;
1991 transfer->more_frags = !packet_ends_transfer(ep_info, transfer->offset, data_size);
1992 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
1994 ep_info->last_data_pid = pid;
1995 ep_info->last_data_acked = usbll_is_split_data_from_device(data->transaction_state);
1996 ep_info->transfer_offset += data_size;
1997 ep_info->last_data_len = data_size;
1999 else
2001 /* Only DATA0 and DATA1 are allowed in Control transfers */
2002 data->transaction_state = STATE_INVALID;
2005 else
2007 /* We don't know anything about the control transfer.
2008 * Most likely the capture is incomplete, there's nothing to be done here.
2012 else if ((ep_info->type == USBLL_EP_BULK) || (ep_info->type == USBLL_EP_INTERRUPT))
2014 if (pid == ep_info->last_data_pid)
2016 /* Retransmission */
2017 DISSECTOR_ASSERT(ep_info->active_transfer_key != 0);
2018 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
2019 transfer->first_packet = ep_info->active_transfer_key;
2020 transfer->offset = ep_info->transfer_offset - ep_info->last_data_len;
2021 transfer->type = ep_info->type;
2022 transfer->from_host = from_host;
2023 transfer->more_frags = !packet_ends_transfer(ep_info, transfer->offset, data_size);
2024 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
2025 /* Do not update endpoint info, previously transferred packet must have
2026 * the same data length as retransmitted packet.
2029 else if ((ep_info->active_transfer_key == 0) ||
2030 packet_ends_transfer(ep_info, ep_info->transfer_offset - ep_info->last_data_len, ep_info->last_data_len))
2032 /* Packet starts new transfer */
2033 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
2034 transfer->first_packet = pinfo->num;
2035 transfer->offset = 0;
2036 transfer->type = ep_info->type;
2037 transfer->from_host = from_host;
2038 transfer->more_frags = !packet_ends_transfer(ep_info, transfer->offset, data_size);
2039 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
2041 ep_info->last_data_pid = pid;
2042 ep_info->last_data_acked = usbll_is_split_data_from_device(data->transaction_state);
2043 ep_info->active_transfer_key = pinfo->num;
2044 ep_info->transfer_offset = data_size;
2045 ep_info->last_data_len = data_size;
2047 else
2049 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
2050 transfer->first_packet = ep_info->active_transfer_key;
2051 transfer->offset = ep_info->transfer_offset;
2052 transfer->type = ep_info->type;
2053 transfer->from_host = from_host;
2054 transfer->more_frags = !packet_ends_transfer(ep_info, transfer->offset, data_size);
2055 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
2057 ep_info->last_data_pid = pid;
2058 ep_info->last_data_acked = usbll_is_split_data_from_device(data->transaction_state);
2059 ep_info->transfer_offset += data_size;
2060 ep_info->last_data_len = data_size;
2063 else if (ep_info->type == USBLL_EP_ISOCHRONOUS)
2065 /* TODO: Reassemble high-bandwidth endpoints data */
2066 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
2067 transfer->first_packet = pinfo->num;
2068 transfer->offset = 0;
2069 transfer->type = ep_info->type;
2070 transfer->from_host = from_host;
2071 transfer->more_frags = false;
2072 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
2076 *payload_size = data_size;
2078 return offset;
2081 static int
2082 dissect_usbll_split(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset,
2083 uint8_t pid, usbll_data_t *data)
2085 uint8_t hub_address;
2086 uint8_t hub_port;
2087 proto_item *split_e_u;
2088 proto_item *split_s;
2090 int32_t tmp = tvb_get_int24(tvb, offset, ENC_LITTLE_ENDIAN);
2092 hub_address = SPLIT_BITS_GET_HUB_ADDRESS(tmp);
2093 hub_port = SPLIT_BITS_GET_HUB_PORT(tmp);
2095 col_append_str(pinfo->cinfo, COL_INFO, (tmp & SPLIT_BIT_START_COMPLETE) ? " Complete" : " Start");
2097 proto_tree_add_uint(tree, hf_usbll_split_hub_addr, tvb, offset, 3, tmp);
2098 proto_tree_add_uint(tree, hf_usbll_split_sc, tvb, offset, 3, tmp);
2099 proto_tree_add_uint(tree, hf_usbll_split_port, tvb, offset, 3, tmp);
2101 if (tmp & SPLIT_BIT_START_COMPLETE) {
2102 proto_tree_add_uint(tree, hf_usbll_split_s, tvb, offset, 3, tmp);
2103 split_e_u = proto_tree_add_uint(tree, hf_usbll_split_u, tvb, offset, 3, tmp);
2105 if (tmp & SPLIT_BIT_E_U)
2106 expert_add_info(pinfo, split_e_u, &ei_invalid_e_u);
2107 } else {
2108 /* S/E fields have special meaning for Isochronous OUT transfers. */
2109 if (data->next && data->next->transaction_state == STATE_SSPLIT_ISOCHRONOUS_OUT) {
2110 DISSECTOR_ASSERT(SPLIT_BITS_GET_ENDPOINT_TYPE(tmp) == USB_EP_TYPE_ISOCHRONOUS);
2111 proto_tree_add_uint(tree, hf_usbll_split_iso_se, tvb, offset, 3, tmp);
2112 } else if (SPLIT_BITS_GET_ENDPOINT_TYPE(tmp) != USB_EP_TYPE_ISOCHRONOUS) {
2113 split_s = proto_tree_add_uint(tree, hf_usbll_split_s, tvb, offset, 3, tmp);
2114 split_e_u = proto_tree_add_uint(tree, hf_usbll_split_e, tvb, offset, 3, tmp);
2116 if ((SPLIT_BITS_GET_ENDPOINT_TYPE(tmp) == USB_EP_TYPE_BULK) && (tmp & SPLIT_BIT_SPEED))
2117 expert_add_info(pinfo, split_s, &ei_invalid_s);
2118 if (tmp & SPLIT_BIT_E_U)
2119 expert_add_info(pinfo, split_e_u, &ei_invalid_e_u);
2120 } else if (data->next &&
2121 (data->next->transaction_state == STATE_SSPLIT_ISOCHRONOUS_IN ||
2122 data->next->transaction_state == STATE_CSPLIT_ISOCHRONOUS_IN)) {
2123 DISSECTOR_ASSERT(SPLIT_BITS_GET_ENDPOINT_TYPE(tmp) == USB_EP_TYPE_ISOCHRONOUS);
2124 split_s = proto_tree_add_uint(tree, hf_usbll_split_s, tvb, offset, 3, tmp);
2125 split_e_u = proto_tree_add_uint(tree, hf_usbll_split_e, tvb, offset, 3, tmp);
2127 if (tmp & SPLIT_BIT_SPEED)
2128 expert_add_info(pinfo, split_s, &ei_invalid_s);
2129 if (tmp & SPLIT_BIT_E_U)
2130 expert_add_info(pinfo, split_e_u, &ei_invalid_e_u);
2133 proto_tree_add_uint(tree, hf_usbll_split_et, tvb, offset, 3, tmp);
2135 proto_tree_add_checksum(tree, tvb, offset,
2136 hf_usbll_split_crc5, hf_usbll_split_crc5_status, &ei_wrong_split_crc5, pinfo,
2137 crc5_usb_19bit_input(tmp),
2138 ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
2139 offset += 3;
2141 if (!PINFO_FD_VISITED(pinfo))
2143 usbll_transaction_info_t *transaction;
2144 transaction = wmem_new0(wmem_file_scope(), usbll_transaction_info_t);
2145 transaction->starts_in = pinfo->num;
2146 transaction->pid = pid;
2147 transaction->address = hub_address;
2148 transaction->endpoint = hub_port;
2149 if (SPLIT_BITS_GET_ENDPOINT_TYPE(tmp) == USB_EP_TYPE_ISOCHRONOUS)
2150 transaction->speed = USB_SPEED_FULL;
2151 else
2152 transaction->speed = (tmp & SPLIT_BIT_SPEED) ? USB_SPEED_LOW : USB_SPEED_FULL;
2154 data->transaction = transaction;
2155 if (tmp & SPLIT_BIT_START_COMPLETE)
2157 switch (SPLIT_BITS_GET_ENDPOINT_TYPE(tmp))
2159 case USB_EP_TYPE_CONTROL:
2160 data->transaction_state = STATE_CSPLIT_CONTROL;
2161 break;
2162 case USB_EP_TYPE_ISOCHRONOUS:
2163 data->transaction_state = STATE_CSPLIT_ISOCHRONOUS;
2164 break;
2165 case USB_EP_TYPE_BULK:
2166 data->transaction_state = STATE_CSPLIT_BULK;
2167 break;
2168 case USB_EP_TYPE_INTERRUPT:
2169 data->transaction_state = STATE_CSPLIT_INTERRUPT;
2170 break;
2173 else
2175 switch (SPLIT_BITS_GET_ENDPOINT_TYPE(tmp))
2177 case USB_EP_TYPE_CONTROL:
2178 data->transaction_state = STATE_SSPLIT_CONTROL;
2179 break;
2180 case USB_EP_TYPE_ISOCHRONOUS:
2181 data->transaction_state = STATE_SSPLIT_ISOCHRONOUS;
2182 break;
2183 case USB_EP_TYPE_BULK:
2184 data->transaction_state = STATE_SSPLIT_BULK;
2185 break;
2186 case USB_EP_TYPE_INTERRUPT:
2187 data->transaction_state = STATE_SSPLIT_INTERRUPT;
2188 break;
2193 return offset;
2196 static int
2197 dissect_usbll_handshake(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, int offset,
2198 uint8_t pid, usbll_data_t *data)
2200 if (!PINFO_FD_VISITED(pinfo))
2202 usbll_state_t prev_state;
2204 prev_state = data->prev ? data->prev->transaction_state : STATE_IDLE;
2205 data->transaction_state = usbll_next_state(prev_state, pid);
2207 if (data->transaction_state != STATE_INVALID)
2209 DISSECTOR_ASSERT(data->prev != NULL);
2210 DISSECTOR_ASSERT(data->prev->transaction != NULL);
2211 data->transaction = data->prev->transaction;
2214 if (usbll_is_setup_ack(data->transaction_state))
2216 usbll_endpoint_info_t *ep_out, *ep_in;
2217 ep_out = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, true);
2218 ep_in = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, false);
2219 if ((ep_out->type == USBLL_EP_CONTROL) && (ep_in->type == USBLL_EP_CONTROL))
2221 if (ep_out->active_transfer_key != 0)
2223 DISSECTOR_ASSERT(ep_in->active_transfer_key == 0);
2224 ep_out->last_data_acked = true;
2226 else if (ep_in->active_transfer_key != 0)
2228 DISSECTOR_ASSERT(ep_out->active_transfer_key == 0);
2229 ep_in->last_data_acked = true;
2234 if (usbll_is_data_ack(data->transaction_state))
2236 usbll_endpoint_info_t *ep_info;
2237 bool from_host;
2239 from_host = usbll_is_acked_data_from_host(data->transaction_state);
2240 ep_info = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, from_host);
2242 ep_info->last_data_acked = true;
2245 if (usbll_is_endpoint_stall(data->transaction_state))
2247 usbll_endpoint_info_t *ep_info;
2248 usbll_transfer_info_t *transfer;
2249 uint32_t last_offset;
2250 bool from_host;
2252 from_host = usbll_is_stalled_data_from_host(data->transaction_state);
2253 ep_info = usbll_get_endpoint_info(pinfo, data->transaction->address, data->transaction->endpoint, from_host);
2255 last_offset = ep_info->transfer_offset - ep_info->last_data_len;
2257 if (ep_info->active_transfer_key &&
2258 !packet_ends_transfer(ep_info, last_offset, ep_info->last_data_len))
2260 /* STALL terminates ongoing transfer. While the STALL packet is
2261 * always sent by device, the transfer can be either IN or OUT.
2262 * For IN usbll source and destination will match usb source
2263 * and destination. For OUT the source and destination will be
2264 * swapped in usb dissector.
2266 transfer = wmem_new0(wmem_file_scope(), usbll_transfer_info_t);
2267 transfer->first_packet = ep_info->active_transfer_key;
2268 if (!from_host)
2270 /* Data is from device, all reassembled data is in URB */
2271 transfer->offset = ep_info->transfer_offset;
2273 else if (data->transaction_state == STATE_PING_STALL)
2275 if (ep_info->last_data_acked)
2277 /* Last DATA packet was acknowledged with NYET */
2278 transfer->offset = ep_info->transfer_offset;
2280 else
2282 /* Last DATA packet was NAKed. Drop it from URB. */
2283 transfer->offset = last_offset;
2286 else
2288 /* Last DATA packet was not acknowledged by device because
2289 * endpoint was STALLed. Drop last DATA packet from URB.
2291 transfer->offset = last_offset;
2293 transfer->type = ep_info->type;
2294 transfer->from_host = from_host;
2295 transfer->more_frags = false;
2296 wmem_map_insert(transfer_info, GUINT_TO_POINTER(pinfo->num), transfer);
2299 /* Transfers cannot span across STALL handshake */
2300 ep_info->last_data_pid = 0;
2301 ep_info->last_data_acked = false;
2302 ep_info->active_transfer_key = 0;
2303 ep_info->transfer_offset = 0;
2304 ep_info->last_data_len = 0;
2305 ep_info->requested_transfer_length = 0;
2309 return offset;
2312 static void check_for_extended_subpid(uint8_t pid, usbll_data_t *data)
2314 if (data->prev && data->prev->transaction_state == STATE_EXT)
2316 data->transaction_state = usbll_next_state(STATE_EXT, pid);
2318 if (data->transaction_state != STATE_SUBPID_INVALID)
2320 DISSECTOR_ASSERT(data->prev != NULL);
2321 DISSECTOR_ASSERT(data->prev->transaction != NULL);
2322 data->transaction = data->prev->transaction;
2327 static int
2328 dissect_usbll_lpm_token(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset)
2330 uint16_t attributes_bits;
2332 static int * const attributes_fields[] = {
2333 &hf_usbll_lpm_link_state,
2334 &hf_usbll_lpm_besl,
2335 &hf_usbll_lpm_remote_wake,
2336 &hf_usbll_lpm_reserved,
2337 NULL
2340 attributes_bits = tvb_get_letohs(tvb, offset);
2342 proto_tree_add_bitmask_list_value(tree, tvb, offset, 2, attributes_fields, attributes_bits);
2343 proto_tree_add_checksum(tree, tvb, offset,
2344 hf_usbll_crc5, hf_usbll_crc5_status, &ei_wrong_crc5, pinfo,
2345 crc5_usb_11bit_input(attributes_bits),
2346 ENC_LITTLE_ENDIAN, PROTO_CHECKSUM_VERIFY);
2347 offset += 2;
2349 return offset;
2352 static usbll_data_t *
2353 usbll_restore_data(packet_info *pinfo)
2355 return (usbll_data_t *)p_get_proto_data(wmem_file_scope(), pinfo, proto_usbll, pinfo->num);
2358 static usbll_data_t *
2359 usbll_create_data(packet_info *pinfo)
2361 /* allocate a data structure, as it is the first call on this frame. */
2362 usbll_data_t *n_data_ptr = wmem_new0(wmem_file_scope(), usbll_data_t);
2364 p_add_proto_data(wmem_file_scope(), pinfo, proto_usbll, pinfo->num, n_data_ptr);
2366 if (usbll_data_ptr)
2367 *n_data_ptr = *usbll_data_ptr;
2369 n_data_ptr->transaction_state = STATE_IDLE;
2370 n_data_ptr->prev = usbll_data_ptr;
2371 if (n_data_ptr->prev)
2373 n_data_ptr->prev->next = n_data_ptr;
2376 return n_data_ptr;
2379 static void
2380 usbll_cleanup_data(void)
2382 usbll_data_ptr = NULL;
2383 tt_non_periodic = NULL;
2384 tt_periodic = NULL;
2385 ep_info_in = NULL;
2386 ep_info_out = NULL;
2389 static int
2390 dissect_usbll_packet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, usb_speed_t speed)
2392 proto_item *item;
2393 proto_tree *tree;
2394 int offset = 0;
2395 int data_offset;
2396 int data_size;
2397 uint8_t pid;
2398 bool is_subpid;
2399 const char *str;
2400 usbll_data_t *data;
2402 item = proto_tree_add_item(parent_tree, proto_usbll, tvb, offset, -1, ENC_NA);
2403 tree = proto_item_add_subtree(item, ett_usbll);
2405 pid = tvb_get_uint8(tvb, offset);
2407 if (PINFO_FD_VISITED(pinfo)) {
2408 data = usbll_restore_data(pinfo);
2409 } else {
2410 data = usbll_data_ptr = usbll_create_data(pinfo);
2411 check_for_extended_subpid(pid, data);
2414 is_subpid = usbll_is_extended_subpid(data->transaction_state);
2415 if (is_subpid) {
2416 proto_tree_add_item(tree, hf_usbll_subpid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2417 str = try_val_to_str(pid, usb_subpid_vals);
2418 } else {
2419 proto_tree_add_item(tree, hf_usbll_pid, tvb, offset, 1, ENC_LITTLE_ENDIAN);
2420 str = try_val_to_str(pid, usb_packetid_vals);
2422 offset++;
2424 col_set_str(pinfo->cinfo, COL_PROTOCOL, "USBLL");
2425 if (str) {
2426 col_set_str(pinfo->cinfo, COL_INFO, str);
2427 } else if (is_subpid) {
2428 col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid SubPID (0x%02x)", pid);
2429 expert_add_info(pinfo, item, &ei_invalid_subpid);
2430 } else {
2431 col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid Packet ID (0x%02x)", pid);
2432 expert_add_info(pinfo, item, &ei_invalid_pid);
2435 /* If handler updates data size, then it means we should process with data
2436 * reassembly at data offset with the provided data size.
2438 data_offset = offset;
2439 data_size = -1;
2441 if (is_subpid) {
2442 switch (pid)
2444 case USB_SUBPID_LPM:
2445 offset = dissect_usbll_lpm_token(tvb, pinfo, tree, offset);
2446 break;
2448 default:
2449 break;
2451 } else {
2452 switch (pid)
2454 case USB_PID_TOKEN_SETUP:
2455 case USB_PID_TOKEN_OUT:
2456 case USB_PID_TOKEN_IN:
2457 case USB_PID_SPECIAL_PING:
2458 case USB_PID_SPECIAL_EXT:
2459 offset = dissect_usbll_token(tvb, pinfo, tree, offset, pid, data, speed);
2460 break;
2462 case USB_PID_DATA_DATA0:
2463 case USB_PID_DATA_DATA1:
2464 case USB_PID_DATA_DATA2:
2465 case USB_PID_DATA_MDATA:
2466 offset = dissect_usbll_data(tvb, pinfo, tree, offset, pid, data, &data_size);
2467 break;
2469 case USB_PID_HANDSHAKE_ACK:
2470 case USB_PID_HANDSHAKE_NAK:
2471 case USB_PID_HANDSHAKE_NYET:
2472 case USB_PID_HANDSHAKE_STALL:
2473 offset = dissect_usbll_handshake(tvb, pinfo, tree, offset, pid, data);
2474 data_size = 0;
2475 break;
2477 case USB_PID_TOKEN_SOF:
2478 offset = dissect_usbll_sof(tvb, pinfo, tree, offset);
2479 break;
2481 case USB_PID_SPECIAL_SPLIT:
2482 offset = dissect_usbll_split(tvb, pinfo, tree, offset, pid, data);
2483 break;
2484 case USB_PID_SPECIAL_PRE_OR_ERR:
2485 break;
2486 default:
2487 break;
2491 usbll_generate_address(tree, tvb, pinfo, data);
2492 if (data->transaction_state == STATE_INVALID) {
2493 expert_add_info(pinfo, item, &ei_invalid_pid_sequence);
2494 } else if (data->transaction_state == STATE_SUBPID_NOT_REUSABLE) {
2495 expert_add_info(pinfo, item, &ei_conflicting_subpid);
2498 if (tvb_reported_length_remaining(tvb, offset) > 0) {
2499 proto_tree_add_expert(tree, pinfo, &ei_undecoded, tvb, offset, -1);
2500 offset += tvb_captured_length_remaining(tvb, offset);
2503 if (data_size >= 0) {
2504 usbll_construct_urb(tvb, pinfo, tree, data_offset, data_size, data);
2507 return offset;
2510 static int
2511 dissect_usbll_unknown_speed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data _U_)
2513 return dissect_usbll_packet(tvb, pinfo, parent_tree, global_dissect_unknown_speed_as);
2516 static int
2517 dissect_usbll_low_speed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data _U_)
2519 return dissect_usbll_packet(tvb, pinfo, parent_tree, USB_SPEED_LOW);
2522 static int
2523 dissect_usbll_full_speed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data _U_)
2525 return dissect_usbll_packet(tvb, pinfo, parent_tree, USB_SPEED_FULL);
2528 static int
2529 dissect_usbll_high_speed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void *data _U_)
2531 return dissect_usbll_packet(tvb, pinfo, parent_tree, USB_SPEED_HIGH);
2534 void
2535 proto_register_usbll(void)
2537 module_t *usbll_module;
2538 expert_module_t *expert_module;
2540 static hf_register_info hf[] = {
2541 /* Common header fields */
2542 { &hf_usbll_pid,
2543 { "PID", "usbll.pid",
2544 FT_UINT8, BASE_HEX|BASE_EXT_STRING, &usb_packetid_vals_ext, 0x00,
2545 "USB Packet ID", HFILL }},
2546 { &hf_usbll_src,
2547 { "Source", "usbll.src",
2548 FT_STRING, BASE_NONE, NULL, 0x0,
2549 NULL, HFILL }},
2550 { &hf_usbll_dst,
2551 { "Destination", "usbll.dst",
2552 FT_STRING, BASE_NONE, NULL, 0x0,
2553 NULL, HFILL }},
2554 { &hf_usbll_addr,
2555 { "Source or Destination", "usbll.addr",
2556 FT_STRING, BASE_NONE, NULL, 0x0,
2557 NULL, HFILL }},
2559 /* Token header fields */
2560 { &hf_usbll_device_addr,
2561 { "Address", "usbll.device_addr",
2562 FT_UINT16, BASE_DEC, NULL, 0x007F,
2563 NULL, HFILL }},
2564 { &hf_usbll_endp,
2565 { "Endpoint", "usbll.endp",
2566 FT_UINT16, BASE_DEC, NULL, 0x0780,
2567 NULL, HFILL }},
2569 /*SOF header field */
2570 { &hf_usbll_sof_framenum,
2571 { "Frame Number", "usbll.frame_num",
2572 FT_UINT16, BASE_DEC, NULL, 0x07FF,
2573 NULL, HFILL }},
2575 /* Token and SOF header fields */
2576 { &hf_usbll_crc5,
2577 { "CRC5", "usbll.crc5",
2578 FT_UINT16, BASE_HEX, NULL, 0xF800,
2579 NULL, HFILL }},
2580 { &hf_usbll_crc5_status,
2581 { "CRC5 Status", "usbll.crc5.status",
2582 FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0,
2583 NULL, HFILL }},
2585 /* Data header fields */
2586 { &hf_usbll_data,
2587 { "Data", "usbll.data",
2588 FT_BYTES, BASE_NONE|BASE_ALLOW_ZERO, NULL, 0,
2589 NULL, HFILL }},
2590 { &hf_usbll_data_crc,
2591 { "CRC", "usbll.crc16",
2592 FT_UINT16, BASE_HEX, NULL, 0x0,
2593 NULL, HFILL }},
2594 { &hf_usbll_data_crc_status,
2595 { "CRC Status", "usbll.crc16.status",
2596 FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0,
2597 NULL, HFILL }},
2599 /* Split header fields */
2600 { &hf_usbll_split_hub_addr,
2601 { "Hub Address", "usbll.split_hub_addr",
2602 FT_UINT24, BASE_DEC, NULL, 0x00007F,
2603 NULL, HFILL }},
2604 { &hf_usbll_split_sc,
2605 { "SC", "usbll.split_sc",
2606 FT_UINT24, BASE_DEC, VALS(usb_start_complete_vals), 0x000080,
2607 NULL, HFILL }},
2608 { &hf_usbll_split_port,
2609 { "Port", "usbll.split_port",
2610 FT_UINT24, BASE_DEC, NULL, 0x007F00,
2611 NULL, HFILL }},
2612 { &hf_usbll_split_s,
2613 { "Speed", "usbll.split_s",
2614 FT_UINT24, BASE_DEC, VALS(usb_split_speed_vals), 0x008000,
2615 NULL, HFILL }},
2616 { &hf_usbll_split_e,
2617 { "E", "usbll.split_e",
2618 FT_UINT24, BASE_DEC, NULL, 0x010000,
2619 "Unused. Must be 0.", HFILL }},
2620 { &hf_usbll_split_u,
2621 { "U", "usbll.split_u",
2622 FT_UINT24, BASE_DEC, NULL, 0x010000,
2623 "Unused. Must be 0.", HFILL }},
2624 { &hf_usbll_split_iso_se,
2625 { "Start and End", "usbll.split_se",
2626 FT_UINT24, BASE_DEC, VALS(usb_split_iso_se_vals), 0x018000,
2627 NULL, HFILL }},
2628 { &hf_usbll_split_et,
2629 { "Endpoint Type", "usbll.split_et",
2630 FT_UINT24, BASE_DEC, VALS(usb_endpoint_type_vals), 0x060000,
2631 NULL, HFILL }},
2632 { &hf_usbll_split_crc5,
2633 { "CRC5", "usbll.split_crc5",
2634 FT_UINT24, BASE_HEX, NULL, 0xF80000,
2635 NULL, HFILL }},
2636 { &hf_usbll_split_crc5_status,
2637 { "CRC5 Status", "usbll.split_crc5.status",
2638 FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0,
2639 NULL, HFILL }},
2640 { &hf_usbll_transfer_fragments,
2641 { "Transfer fragments", "usbll.fragments",
2642 FT_NONE, BASE_NONE, NULL, 0x00,
2643 NULL, HFILL }},
2644 { &hf_usbll_transfer_fragment,
2645 {"Transfer fragment", "usbll.fragment",
2646 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL }},
2647 { &hf_usbll_transfer_fragment_overlap,
2648 {"Transfer fragment overlap", "usbll.fragment.overlap",
2649 FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL }},
2650 { &hf_usbll_transfer_fragment_overlap_conflicts,
2651 {"Transfer fragment overlapping with conflicting data",
2652 "usbll.fragment.overlap.conflicts",
2653 FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL }},
2654 { &hf_usbll_transfer_fragment_multiple_tails,
2655 {"Transfer has multiple tail fragments",
2656 "usbll.fragment.multiple_tails",
2657 FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL }},
2658 { &hf_usbll_transfer_fragment_too_long_fragment,
2659 {"Transfer fragment too long", "usbll.fragment.too_long_fragment",
2660 FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL }},
2661 { &hf_usbll_transfer_fragment_error,
2662 {"Transfer defragmentation error", "usbll.fragment.error",
2663 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL }},
2664 { &hf_usbll_transfer_fragment_count,
2665 {"Transfer fragment count", "usbll.fragment.count",
2666 FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL }},
2667 { &hf_usbll_transfer_reassembled_in,
2668 {"Reassembled in", "usbll.reassembled.in",
2669 FT_FRAMENUM, BASE_NONE, NULL, 0x00, NULL, HFILL }},
2670 { &hf_usbll_transfer_reassembled_length,
2671 {"Reassembled length", "usbll.reassembled.length",
2672 FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL }},
2674 /* USB 2.0 Link Power Management Addendum */
2675 { &hf_usbll_subpid,
2676 { "SubPID", "usbll.subpid",
2677 FT_UINT8, BASE_HEX|BASE_EXT_STRING, &usb_subpid_vals_ext, 0x00,
2678 "Extended Token Packet SubPID", HFILL }},
2679 { &hf_usbll_lpm_link_state,
2680 { "bLinkState", "usbll.lpm_link_state",
2681 FT_UINT16, BASE_CUSTOM, CF_FUNC(lpm_link_state_str), 0x000F,
2682 NULL, HFILL }},
2683 { &hf_usbll_lpm_besl,
2684 { "BESL", "usbll.lpm_besl",
2685 FT_UINT16, BASE_CUSTOM, CF_FUNC(usb_lpm_besl_str), 0x00F0,
2686 "Best Effort Service Latency", HFILL}},
2687 { &hf_usbll_lpm_remote_wake,
2688 { "bRemoteWake", "usbll.lpm_remote_wake",
2689 FT_UINT16, BASE_DEC, VALS(usb_lpm_remote_wake_vals), 0x0100,
2690 NULL, HFILL }},
2691 { &hf_usbll_lpm_reserved,
2692 { "Reserved", "usbll.lpm_reserved",
2693 FT_UINT16, BASE_DEC, NULL, 0x0600,
2694 NULL, HFILL }},
2697 static ei_register_info ei[] = {
2698 { &ei_invalid_pid, { "usbll.invalid_pid", PI_MALFORMED, PI_ERROR, "Invalid USB Packet ID", EXPFILL }},
2699 { &ei_invalid_subpid, { "usbll.invalid_subpid", PI_MALFORMED, PI_ERROR, "Invalid SubPID", EXPFILL }},
2700 { &ei_conflicting_subpid, { "usbll.conflicting_subpid", PI_MALFORMED, PI_ERROR, "Token PID cannot be reused as SubPID", EXPFILL }},
2701 { &ei_undecoded, { "usbll.undecoded", PI_UNDECODED, PI_WARN, "Not dissected yet (report to wireshark.org)", EXPFILL }},
2702 { &ei_wrong_crc5, { "usbll.crc5.wrong", PI_PROTOCOL, PI_WARN, "Wrong CRC5", EXPFILL }},
2703 { &ei_wrong_split_crc5, { "usbll.split_crc5.wrong", PI_PROTOCOL, PI_WARN, "Wrong Split CRC5", EXPFILL }},
2704 { &ei_wrong_crc16, { "usbll.crc16.wrong", PI_PROTOCOL, PI_WARN, "Wrong CRC16", EXPFILL }},
2705 { &ei_invalid_s, { "usbll.invalid_s", PI_MALFORMED, PI_ERROR, "Invalid bit (Must be 0)", EXPFILL }},
2706 { &ei_invalid_e_u, { "usbll.invalid_e_u", PI_MALFORMED, PI_ERROR, "Invalid bit (Must be 0)", EXPFILL }},
2707 { &ei_invalid_pid_sequence, {"usbll.invalid_pid_sequence", PI_MALFORMED, PI_ERROR, "Invalid PID Sequence",EXPFILL }},
2708 { &ei_invalid_setup_data, {"usbll.invalid_setup_data", PI_MALFORMED, PI_ERROR, "Invalid data length (Must be 8 bytes)", EXPFILL }},
2711 static int *ett[] = {
2712 &ett_usbll,
2713 &ett_usbll_transfer_fragment,
2714 &ett_usbll_transfer_fragments,
2717 transfer_info = wmem_map_new_autoreset(wmem_epan_scope(), wmem_file_scope(), g_direct_hash, g_direct_equal);
2718 proto_usbll = proto_register_protocol("USB Link Layer", "USBLL", "usbll");
2719 proto_register_field_array(proto_usbll, hf, array_length(hf));
2720 proto_register_subtree_array(ett, array_length(ett));
2722 expert_module = expert_register_protocol(proto_usbll);
2723 expert_register_field_array(expert_module, ei, array_length(ei));
2725 usbll_module = prefs_register_protocol(proto_usbll, NULL);
2727 prefs_register_enum_preference(usbll_module, "global_pref_dissect_unknown_speed_as",
2728 "Decode unknown speed packets as",
2729 "Use specified speed if speed is not indicated in capture",
2730 &global_dissect_unknown_speed_as, dissect_unknown_speed_as, false);
2732 unknown_speed_handle = register_dissector("usbll", dissect_usbll_unknown_speed, proto_usbll);
2733 low_speed_handle = register_dissector("usbll.low_speed", dissect_usbll_low_speed, proto_usbll);
2734 full_speed_handle = register_dissector("usbll.full_speed", dissect_usbll_full_speed, proto_usbll);
2735 high_speed_handle = register_dissector("usbll.high_speed", dissect_usbll_high_speed, proto_usbll);
2736 register_cleanup_routine(usbll_cleanup_data);
2738 usbll_address_type = address_type_dissector_register("AT_USBLL", "USBLL Address",
2739 usbll_addr_to_str, usbll_addr_str_len,
2740 NULL, NULL, NULL, NULL, NULL);
2742 reassembly_table_register(&usbll_reassembly_table, &usbll_reassembly_table_functions);
2745 void
2746 proto_reg_handoff_usbll(void)
2748 dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_2_0, unknown_speed_handle);
2749 dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_2_0_LOW_SPEED, low_speed_handle);
2750 dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_2_0_FULL_SPEED, full_speed_handle);
2751 dissector_add_uint("wtap_encap", WTAP_ENCAP_USB_2_0_HIGH_SPEED, high_speed_handle);
2755 * Editor modelines
2757 * Local Variables:
2758 * c-basic-offset: 4
2759 * tab-width: 8
2760 * indent-tabs-mode: nil
2761 * End:
2763 * ex: set shiftwidth=4 tabstop=8 expandtab:
2764 * :indentSize=4:tabSize=8:noTabs=true: