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