xref: /freebsd/contrib/libpcap/pcap/usb.h (revision ada6f083b93b4adce9c3b3ba00112528244a3b86)
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 
34*ada6f083SXin LI #ifndef lib_pcap_usb_h
35*ada6f083SXin LI #define lib_pcap_usb_h
36a8e07101SRui Paulo 
37a8e07101SRui Paulo /*
38a8e07101SRui Paulo  * possible transfer mode
39a8e07101SRui Paulo  */
40a8e07101SRui Paulo #define URB_TRANSFER_IN   0x80
41a8e07101SRui Paulo #define URB_ISOCHRONOUS   0x0
42a8e07101SRui Paulo #define URB_INTERRUPT     0x1
43a8e07101SRui Paulo #define URB_CONTROL       0x2
44a8e07101SRui Paulo #define URB_BULK          0x3
45a8e07101SRui Paulo 
46a8e07101SRui Paulo /*
47a8e07101SRui Paulo  * possible event type
48a8e07101SRui Paulo  */
49a8e07101SRui Paulo #define URB_SUBMIT        'S'
50a8e07101SRui Paulo #define URB_COMPLETE      'C'
51a8e07101SRui Paulo #define URB_ERROR         'E'
52a8e07101SRui Paulo 
53a8e07101SRui Paulo /*
54a8e07101SRui Paulo  * USB setup header as defined in USB specification.
55a0ee43a1SRui Paulo  * Appears at the front of each Control S-type packet in DLT_USB captures.
56a8e07101SRui Paulo  */
57a8e07101SRui Paulo typedef struct _usb_setup {
58a8e07101SRui Paulo 	u_int8_t bmRequestType;
59a8e07101SRui Paulo 	u_int8_t bRequest;
60a8e07101SRui Paulo 	u_int16_t wValue;
61a8e07101SRui Paulo 	u_int16_t wIndex;
62a8e07101SRui Paulo 	u_int16_t wLength;
63a8e07101SRui Paulo } pcap_usb_setup;
64a8e07101SRui Paulo 
65a0ee43a1SRui Paulo /*
66a0ee43a1SRui Paulo  * Information from the URB for Isochronous transfers.
67a0ee43a1SRui Paulo  */
68a0ee43a1SRui Paulo typedef struct _iso_rec {
69a0ee43a1SRui Paulo 	int32_t	error_count;
70a0ee43a1SRui Paulo 	int32_t	numdesc;
71a0ee43a1SRui Paulo } iso_rec;
72a8e07101SRui Paulo 
73a8e07101SRui Paulo /*
74a8e07101SRui Paulo  * Header prepended by linux kernel to each event.
75a8e07101SRui Paulo  * Appears at the front of each packet in DLT_USB_LINUX captures.
76a8e07101SRui Paulo  */
77a8e07101SRui Paulo typedef struct _usb_header {
78a8e07101SRui Paulo 	u_int64_t id;
79a8e07101SRui Paulo 	u_int8_t event_type;
80a8e07101SRui Paulo 	u_int8_t transfer_type;
81a8e07101SRui Paulo 	u_int8_t endpoint_number;
82a8e07101SRui Paulo 	u_int8_t device_address;
83a8e07101SRui Paulo 	u_int16_t bus_id;
84a8e07101SRui Paulo 	char setup_flag;/*if !=0 the urb setup header is not present*/
85a8e07101SRui Paulo 	char data_flag; /*if !=0 no urb data is present*/
86a8e07101SRui Paulo 	int64_t ts_sec;
87a8e07101SRui Paulo 	int32_t ts_usec;
88a8e07101SRui Paulo 	int32_t status;
89a8e07101SRui Paulo 	u_int32_t urb_len;
90a8e07101SRui Paulo 	u_int32_t data_len; /* amount of urb data really present in this event*/
91a8e07101SRui Paulo 	pcap_usb_setup setup;
92a8e07101SRui Paulo } pcap_usb_header;
93a8e07101SRui Paulo 
94a0ee43a1SRui Paulo /*
95a0ee43a1SRui Paulo  * Header prepended by linux kernel to each event for the 2.6.31
96a0ee43a1SRui Paulo  * and later kernels; for the 2.6.21 through 2.6.30 kernels, the
97a0ee43a1SRui Paulo  * "iso_rec" information, and the fields starting with "interval"
98a0ee43a1SRui Paulo  * are zeroed-out padding fields.
99a0ee43a1SRui Paulo  *
100a0ee43a1SRui Paulo  * Appears at the front of each packet in DLT_USB_LINUX_MMAPPED captures.
101a0ee43a1SRui Paulo  */
102a0ee43a1SRui Paulo typedef struct _usb_header_mmapped {
103a0ee43a1SRui Paulo 	u_int64_t id;
104a0ee43a1SRui Paulo 	u_int8_t event_type;
105a0ee43a1SRui Paulo 	u_int8_t transfer_type;
106a0ee43a1SRui Paulo 	u_int8_t endpoint_number;
107a0ee43a1SRui Paulo 	u_int8_t device_address;
108a0ee43a1SRui Paulo 	u_int16_t bus_id;
109a0ee43a1SRui Paulo 	char setup_flag;/*if !=0 the urb setup header is not present*/
110a0ee43a1SRui Paulo 	char data_flag; /*if !=0 no urb data is present*/
111a0ee43a1SRui Paulo 	int64_t ts_sec;
112a0ee43a1SRui Paulo 	int32_t ts_usec;
113a0ee43a1SRui Paulo 	int32_t status;
114a0ee43a1SRui Paulo 	u_int32_t urb_len;
115a0ee43a1SRui Paulo 	u_int32_t data_len; /* amount of urb data really present in this event*/
116a0ee43a1SRui Paulo 	union {
117a0ee43a1SRui Paulo 		pcap_usb_setup setup;
118a0ee43a1SRui Paulo 		iso_rec iso;
119a0ee43a1SRui Paulo 	} s;
120a0ee43a1SRui Paulo 	int32_t	interval;	/* for Interrupt and Isochronous events */
121a0ee43a1SRui Paulo 	int32_t start_frame;	/* for Isochronous events */
122a0ee43a1SRui Paulo 	u_int32_t xfer_flags;	/* copy of URB's transfer flags */
123a0ee43a1SRui Paulo 	u_int32_t ndesc;	/* number of isochronous descriptors */
124a0ee43a1SRui Paulo } pcap_usb_header_mmapped;
125a0ee43a1SRui Paulo 
126a0ee43a1SRui Paulo /*
127a0ee43a1SRui Paulo  * Isochronous descriptors; for isochronous transfers there might be
128a0ee43a1SRui Paulo  * one or more of these at the beginning of the packet data.  The
129a0ee43a1SRui Paulo  * number of descriptors is given by the "ndesc" field in the header;
130a0ee43a1SRui Paulo  * as indicated, in older kernels that don't put the descriptors at
131a0ee43a1SRui Paulo  * the beginning of the packet, that field is zeroed out, so that field
132a0ee43a1SRui Paulo  * can be trusted even in captures from older kernels.
133a0ee43a1SRui Paulo  */
134a0ee43a1SRui Paulo typedef struct _usb_isodesc {
135a0ee43a1SRui Paulo 	int32_t		status;
136a0ee43a1SRui Paulo 	u_int32_t	offset;
137a0ee43a1SRui Paulo 	u_int32_t	len;
138a0ee43a1SRui Paulo 	u_int8_t	pad[4];
139a0ee43a1SRui Paulo } usb_isodesc;
140a8e07101SRui Paulo 
141a8e07101SRui Paulo #endif
142