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