xref: /openbsd/sys/dev/usb/usbpcap.h (revision 4ba11bd8)
1 /* $OpenBSD: usbpcap.h,v 1.2 2018/02/26 13:06:49 mpi Exp $ */
2 
3 /*
4  * Copyright (c) 2018 Martin Pieuchot
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _USBCAP_H_
20 #define _USBCAP_H_
21 
22 /*
23  * Common DLT_USBPCAP header.
24  */
25 struct usbpcap_pkt_hdr {
26 	uint16_t		uph_hlen;	/* header length */
27 	uint64_t		uph_id;		/* request ID */
28 	uint32_t		uph_status;	/* USB status code */
29 	uint16_t		uph_function;	/* stack function ID */
30 	uint8_t			uph_info;	/* info flags */
31 #define USBPCAP_INFO_DIRECTION_IN	(1 << 0)/* from Device to Host */
32 
33 	uint16_t		uph_bus;	/* bus number */
34 	uint16_t		uph_devaddr;	/* device address */
35 	uint8_t			uph_epaddr;	/* copy of bEndpointAddress */
36 	uint8_t			uph_xfertype;	/* transfer type */
37 #define USBPCAP_TRANSFER_ISOCHRONOUS	0
38 #define USBPCAP_TRANSFER_INTERRUPT	1
39 #define USBPCAP_TRANSFER_CONTROL	2
40 #define USBPCAP_TRANSFER_BULK		3
41 
42 	uint32_t		uph_dlen;	/* data length */
43 } __attribute__((packed));
44 
45 /*
46  * Header used when dumping control transfers.
47  */
48 struct usbpcap_ctl_hdr {
49 	struct usbpcap_pkt_hdr	uch_hdr;
50 	uint8_t			uch_stage;
51 #define USBPCAP_CONTROL_STAGE_SETUP	0
52 #define USBPCAP_CONTROL_STAGE_DATA	1
53 #define USBPCAP_CONTROL_STAGE_STATUS	2
54 } __attribute__((packed));
55 
56 struct usbpcap_iso_pkt {
57 	uint32_t	uip_offset;
58 	uint32_t	uip_length;
59 	uint32_t	uip_status;
60 } __attribute__((packed));
61 
62 /*
63  * Header used when dumping isochronous transfers.
64  */
65 struct usbpcap_iso_hdr {
66 	struct usbpcap_pkt_hdr	uih_hdr;
67 	uint32_t		uih_startframe;
68 	uint32_t		uih_nframes;	/* number of frame */
69 	uint32_t		uih_errors;	/* error count */
70 	struct usbpcap_iso_pkt	uih_frames[1];
71 } __attribute__((packed));
72 
73 #ifdef _KERNEL
74 /*
75  * OpenBSD specific, maximum number of frames per transfer used across
76  * all USB drivers.  This allows us to setup the header on the stack.
77  */
78 #define _USBPCAP_MAX_ISOFRAMES 40
79 struct usbpcap_iso_hdr_full {
80 	struct usbpcap_pkt_hdr	uih_hdr;
81 	uint32_t		uih_startframe;
82 	uint32_t		uih_nframes;
83 	uint32_t		uih_errors;
84 	struct usbpcap_iso_pkt	uih_frames[_USBPCAP_MAX_ISOFRAMES];
85 } __attribute__((packed));
86 #endif /* _KERNEL */
87 #endif /* _USBCAP_H_ */
88