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