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