1a8e07101SRui Paulo /* 2a8e07101SRui Paulo * Copyright (c) 2006 Paolo Abeni (Italy) 3a8e07101SRui Paulo * All rights reserved. 4a8e07101SRui Paulo * 5a8e07101SRui Paulo * Redistribution and use in source and binary forms, with or without 6a8e07101SRui Paulo * modification, are permitted provided that the following conditions 7a8e07101SRui Paulo * are met: 8a8e07101SRui Paulo * 9a8e07101SRui Paulo * 1. Redistributions of source code must retain the above copyright 10a8e07101SRui Paulo * notice, this list of conditions and the following disclaimer. 11a8e07101SRui Paulo * 2. Redistributions in binary form must reproduce the above copyright 12a8e07101SRui Paulo * notice, this list of conditions and the following disclaimer in the 13a8e07101SRui Paulo * documentation and/or other materials provided with the distribution. 14a8e07101SRui Paulo * 3. The name of the author may not be used to endorse or promote 15a8e07101SRui Paulo * products derived from this software without specific prior written 16a8e07101SRui Paulo * permission. 17a8e07101SRui Paulo * 18a8e07101SRui Paulo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19a8e07101SRui Paulo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20a8e07101SRui Paulo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21a8e07101SRui Paulo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22a8e07101SRui Paulo * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23a8e07101SRui Paulo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24a8e07101SRui Paulo * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25a8e07101SRui Paulo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26a8e07101SRui Paulo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27a8e07101SRui Paulo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28a8e07101SRui Paulo * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29a8e07101SRui Paulo * 30a8e07101SRui Paulo * Basic USB data struct 31a8e07101SRui Paulo * By Paolo Abeni <paolo.abeni@email.it> 32a8e07101SRui Paulo */ 33a8e07101SRui Paulo 34ada6f083SXin LI #ifndef lib_pcap_usb_h 35ada6f083SXin LI #define lib_pcap_usb_h 36a8e07101SRui Paulo 37b00ab754SHans Petter Selasky #include <pcap/pcap-inttypes.h> 38b00ab754SHans Petter Selasky 39a8e07101SRui Paulo /* 40a8e07101SRui Paulo * possible transfer mode 41a8e07101SRui Paulo */ 42a8e07101SRui Paulo #define URB_TRANSFER_IN 0x80 43a8e07101SRui Paulo #define URB_ISOCHRONOUS 0x0 44a8e07101SRui Paulo #define URB_INTERRUPT 0x1 45a8e07101SRui Paulo #define URB_CONTROL 0x2 46a8e07101SRui Paulo #define URB_BULK 0x3 47a8e07101SRui Paulo 48a8e07101SRui Paulo /* 49a8e07101SRui Paulo * possible event type 50a8e07101SRui Paulo */ 51a8e07101SRui Paulo #define URB_SUBMIT 'S' 52a8e07101SRui Paulo #define URB_COMPLETE 'C' 53a8e07101SRui Paulo #define URB_ERROR 'E' 54a8e07101SRui Paulo 55a8e07101SRui Paulo /* 56a8e07101SRui Paulo * USB setup header as defined in USB specification. 57a0ee43a1SRui Paulo * Appears at the front of each Control S-type packet in DLT_USB captures. 58a8e07101SRui Paulo */ 59a8e07101SRui Paulo typedef struct _usb_setup { 60b00ab754SHans Petter Selasky uint8_t bmRequestType; 61b00ab754SHans Petter Selasky uint8_t bRequest; 62b00ab754SHans Petter Selasky uint16_t wValue; 63b00ab754SHans Petter Selasky uint16_t wIndex; 64b00ab754SHans Petter Selasky uint16_t wLength; 65a8e07101SRui Paulo } pcap_usb_setup; 66a8e07101SRui Paulo 67a0ee43a1SRui Paulo /* 68a0ee43a1SRui Paulo * Information from the URB for Isochronous transfers. 69a0ee43a1SRui Paulo */ 70a0ee43a1SRui Paulo typedef struct _iso_rec { 71a0ee43a1SRui Paulo int32_t error_count; 72a0ee43a1SRui Paulo int32_t numdesc; 73a0ee43a1SRui Paulo } iso_rec; 74a8e07101SRui Paulo 75a8e07101SRui Paulo /* 76a8e07101SRui Paulo * Header prepended by linux kernel to each event. 77a8e07101SRui Paulo * Appears at the front of each packet in DLT_USB_LINUX captures. 78a8e07101SRui Paulo */ 79a8e07101SRui Paulo typedef struct _usb_header { 80b00ab754SHans Petter Selasky uint64_t id; 81b00ab754SHans Petter Selasky uint8_t event_type; 82b00ab754SHans Petter Selasky uint8_t transfer_type; 83b00ab754SHans Petter Selasky uint8_t endpoint_number; 84b00ab754SHans Petter Selasky uint8_t device_address; 85b00ab754SHans Petter Selasky uint16_t bus_id; 86a8e07101SRui Paulo char setup_flag;/*if !=0 the urb setup header is not present*/ 87a8e07101SRui Paulo char data_flag; /*if !=0 no urb data is present*/ 88a8e07101SRui Paulo int64_t ts_sec; 89a8e07101SRui Paulo int32_t ts_usec; 90a8e07101SRui Paulo int32_t status; 91b00ab754SHans Petter Selasky uint32_t urb_len; 92b00ab754SHans Petter Selasky uint32_t data_len; /* amount of urb data really present in this event*/ 93a8e07101SRui Paulo pcap_usb_setup setup; 94a8e07101SRui Paulo } pcap_usb_header; 95a8e07101SRui Paulo 96a0ee43a1SRui Paulo /* 97a0ee43a1SRui Paulo * Header prepended by linux kernel to each event for the 2.6.31 98a0ee43a1SRui Paulo * and later kernels; for the 2.6.21 through 2.6.30 kernels, the 99a0ee43a1SRui Paulo * "iso_rec" information, and the fields starting with "interval" 100a0ee43a1SRui Paulo * are zeroed-out padding fields. 101a0ee43a1SRui Paulo * 102a0ee43a1SRui Paulo * Appears at the front of each packet in DLT_USB_LINUX_MMAPPED captures. 103a0ee43a1SRui Paulo */ 104a0ee43a1SRui Paulo typedef struct _usb_header_mmapped { 105b00ab754SHans Petter Selasky uint64_t id; 106b00ab754SHans Petter Selasky uint8_t event_type; 107b00ab754SHans Petter Selasky uint8_t transfer_type; 108b00ab754SHans Petter Selasky uint8_t endpoint_number; 109b00ab754SHans Petter Selasky uint8_t device_address; 110b00ab754SHans Petter Selasky uint16_t bus_id; 111a0ee43a1SRui Paulo char setup_flag;/*if !=0 the urb setup header is not present*/ 112a0ee43a1SRui Paulo char data_flag; /*if !=0 no urb data is present*/ 113a0ee43a1SRui Paulo int64_t ts_sec; 114a0ee43a1SRui Paulo int32_t ts_usec; 115a0ee43a1SRui Paulo int32_t status; 116b00ab754SHans Petter Selasky uint32_t urb_len; 117b00ab754SHans Petter Selasky uint32_t data_len; /* amount of urb data really present in this event*/ 118a0ee43a1SRui Paulo union { 119a0ee43a1SRui Paulo pcap_usb_setup setup; 120a0ee43a1SRui Paulo iso_rec iso; 121a0ee43a1SRui Paulo } s; 122a0ee43a1SRui Paulo int32_t interval; /* for Interrupt and Isochronous events */ 123a0ee43a1SRui Paulo int32_t start_frame; /* for Isochronous events */ 124b00ab754SHans Petter Selasky uint32_t xfer_flags; /* copy of URB's transfer flags */ 125b00ab754SHans Petter Selasky uint32_t ndesc; /* number of isochronous descriptors */ 126a0ee43a1SRui Paulo } pcap_usb_header_mmapped; 127a0ee43a1SRui Paulo 128a0ee43a1SRui Paulo /* 129*afdbf109SJoseph Mingrone * Maximum number of descriptors supported. 130*afdbf109SJoseph Mingrone * It's currently 128 in the Linux binary USB monitoring code. 131*afdbf109SJoseph Mingrone */ 132*afdbf109SJoseph Mingrone #define USB_MAXDESC 128 133*afdbf109SJoseph Mingrone 134*afdbf109SJoseph Mingrone /* 135a0ee43a1SRui Paulo * Isochronous descriptors; for isochronous transfers there might be 136a0ee43a1SRui Paulo * one or more of these at the beginning of the packet data. The 137a0ee43a1SRui Paulo * number of descriptors is given by the "ndesc" field in the header; 138a0ee43a1SRui Paulo * as indicated, in older kernels that don't put the descriptors at 139a0ee43a1SRui Paulo * the beginning of the packet, that field is zeroed out, so that field 140a0ee43a1SRui Paulo * can be trusted even in captures from older kernels. 141a0ee43a1SRui Paulo */ 142a0ee43a1SRui Paulo typedef struct _usb_isodesc { 143a0ee43a1SRui Paulo int32_t status; 144b00ab754SHans Petter Selasky uint32_t offset; 145b00ab754SHans Petter Selasky uint32_t len; 146b00ab754SHans Petter Selasky uint8_t pad[4]; 147a0ee43a1SRui Paulo } usb_isodesc; 148a8e07101SRui Paulo 149a8e07101SRui Paulo #endif 150