xref: /freebsd/contrib/libpcap/pcap/usb.h (revision a0ee43a18de124b6cc4cb968bde5382f17660175)
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  *
33*a0ee43a1SRui Paulo  * @(#) $Header: /tcpdump/master/libpcap/pcap/usb.h,v 1.9 2008-12-23 20:13:29 guy Exp $
34a8e07101SRui Paulo  */
35a8e07101SRui Paulo 
36a8e07101SRui Paulo #ifndef _PCAP_USB_STRUCTS_H__
37a8e07101SRui Paulo #define _PCAP_USB_STRUCTS_H__
38a8e07101SRui Paulo 
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.
57*a0ee43a1SRui Paulo  * Appears at the front of each Control S-type packet in DLT_USB captures.
58a8e07101SRui Paulo  */
59a8e07101SRui Paulo typedef struct _usb_setup {
60a8e07101SRui Paulo 	u_int8_t bmRequestType;
61a8e07101SRui Paulo 	u_int8_t bRequest;
62a8e07101SRui Paulo 	u_int16_t wValue;
63a8e07101SRui Paulo 	u_int16_t wIndex;
64a8e07101SRui Paulo 	u_int16_t wLength;
65a8e07101SRui Paulo } pcap_usb_setup;
66a8e07101SRui Paulo 
67*a0ee43a1SRui Paulo /*
68*a0ee43a1SRui Paulo  * Information from the URB for Isochronous transfers.
69*a0ee43a1SRui Paulo  */
70*a0ee43a1SRui Paulo typedef struct _iso_rec {
71*a0ee43a1SRui Paulo 	int32_t	error_count;
72*a0ee43a1SRui Paulo 	int32_t	numdesc;
73*a0ee43a1SRui 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 {
80a8e07101SRui Paulo 	u_int64_t id;
81a8e07101SRui Paulo 	u_int8_t event_type;
82a8e07101SRui Paulo 	u_int8_t transfer_type;
83a8e07101SRui Paulo 	u_int8_t endpoint_number;
84a8e07101SRui Paulo 	u_int8_t device_address;
85a8e07101SRui Paulo 	u_int16_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;
91a8e07101SRui Paulo 	u_int32_t urb_len;
92a8e07101SRui Paulo 	u_int32_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 
96*a0ee43a1SRui Paulo /*
97*a0ee43a1SRui Paulo  * Header prepended by linux kernel to each event for the 2.6.31
98*a0ee43a1SRui Paulo  * and later kernels; for the 2.6.21 through 2.6.30 kernels, the
99*a0ee43a1SRui Paulo  * "iso_rec" information, and the fields starting with "interval"
100*a0ee43a1SRui Paulo  * are zeroed-out padding fields.
101*a0ee43a1SRui Paulo  *
102*a0ee43a1SRui Paulo  * Appears at the front of each packet in DLT_USB_LINUX_MMAPPED captures.
103*a0ee43a1SRui Paulo  */
104*a0ee43a1SRui Paulo typedef struct _usb_header_mmapped {
105*a0ee43a1SRui Paulo 	u_int64_t id;
106*a0ee43a1SRui Paulo 	u_int8_t event_type;
107*a0ee43a1SRui Paulo 	u_int8_t transfer_type;
108*a0ee43a1SRui Paulo 	u_int8_t endpoint_number;
109*a0ee43a1SRui Paulo 	u_int8_t device_address;
110*a0ee43a1SRui Paulo 	u_int16_t bus_id;
111*a0ee43a1SRui Paulo 	char setup_flag;/*if !=0 the urb setup header is not present*/
112*a0ee43a1SRui Paulo 	char data_flag; /*if !=0 no urb data is present*/
113*a0ee43a1SRui Paulo 	int64_t ts_sec;
114*a0ee43a1SRui Paulo 	int32_t ts_usec;
115*a0ee43a1SRui Paulo 	int32_t status;
116*a0ee43a1SRui Paulo 	u_int32_t urb_len;
117*a0ee43a1SRui Paulo 	u_int32_t data_len; /* amount of urb data really present in this event*/
118*a0ee43a1SRui Paulo 	union {
119*a0ee43a1SRui Paulo 		pcap_usb_setup setup;
120*a0ee43a1SRui Paulo 		iso_rec iso;
121*a0ee43a1SRui Paulo 	} s;
122*a0ee43a1SRui Paulo 	int32_t	interval;	/* for Interrupt and Isochronous events */
123*a0ee43a1SRui Paulo 	int32_t start_frame;	/* for Isochronous events */
124*a0ee43a1SRui Paulo 	u_int32_t xfer_flags;	/* copy of URB's transfer flags */
125*a0ee43a1SRui Paulo 	u_int32_t ndesc;	/* number of isochronous descriptors */
126*a0ee43a1SRui Paulo } pcap_usb_header_mmapped;
127*a0ee43a1SRui Paulo 
128*a0ee43a1SRui Paulo /*
129*a0ee43a1SRui Paulo  * Isochronous descriptors; for isochronous transfers there might be
130*a0ee43a1SRui Paulo  * one or more of these at the beginning of the packet data.  The
131*a0ee43a1SRui Paulo  * number of descriptors is given by the "ndesc" field in the header;
132*a0ee43a1SRui Paulo  * as indicated, in older kernels that don't put the descriptors at
133*a0ee43a1SRui Paulo  * the beginning of the packet, that field is zeroed out, so that field
134*a0ee43a1SRui Paulo  * can be trusted even in captures from older kernels.
135*a0ee43a1SRui Paulo  */
136*a0ee43a1SRui Paulo typedef struct _usb_isodesc {
137*a0ee43a1SRui Paulo 	int32_t		status;
138*a0ee43a1SRui Paulo 	u_int32_t	offset;
139*a0ee43a1SRui Paulo 	u_int32_t	len;
140*a0ee43a1SRui Paulo 	u_int8_t	pad[4];
141*a0ee43a1SRui Paulo } usb_isodesc;
142a8e07101SRui Paulo 
143a8e07101SRui Paulo #endif
144