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