xref: /openbsd-src/sys/dev/usb/usbpcap.h (revision 4ba11bd8f61508559d6013c795a0888688136394)
1*4ba11bd8Smpi /* $OpenBSD: usbpcap.h,v 1.2 2018/02/26 13:06:49 mpi Exp $ */
24b5720c2Smpi 
34b5720c2Smpi /*
44b5720c2Smpi  * Copyright (c) 2018 Martin Pieuchot
54b5720c2Smpi  *
64b5720c2Smpi  * Permission to use, copy, modify, and distribute this software for any
74b5720c2Smpi  * purpose with or without fee is hereby granted, provided that the above
84b5720c2Smpi  * copyright notice and this permission notice appear in all copies.
94b5720c2Smpi  *
104b5720c2Smpi  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
114b5720c2Smpi  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
124b5720c2Smpi  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
134b5720c2Smpi  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
144b5720c2Smpi  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
154b5720c2Smpi  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
164b5720c2Smpi  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
174b5720c2Smpi  */
184b5720c2Smpi 
194b5720c2Smpi #ifndef _USBCAP_H_
204b5720c2Smpi #define _USBCAP_H_
214b5720c2Smpi 
224b5720c2Smpi /*
234b5720c2Smpi  * Common DLT_USBPCAP header.
244b5720c2Smpi  */
254b5720c2Smpi struct usbpcap_pkt_hdr {
264b5720c2Smpi 	uint16_t		uph_hlen;	/* header length */
274b5720c2Smpi 	uint64_t		uph_id;		/* request ID */
284b5720c2Smpi 	uint32_t		uph_status;	/* USB status code */
294b5720c2Smpi 	uint16_t		uph_function;	/* stack function ID */
304b5720c2Smpi 	uint8_t			uph_info;	/* info flags */
314b5720c2Smpi #define USBPCAP_INFO_DIRECTION_IN	(1 << 0)/* from Device to Host */
324b5720c2Smpi 
334b5720c2Smpi 	uint16_t		uph_bus;	/* bus number */
344b5720c2Smpi 	uint16_t		uph_devaddr;	/* device address */
354b5720c2Smpi 	uint8_t			uph_epaddr;	/* copy of bEndpointAddress */
364b5720c2Smpi 	uint8_t			uph_xfertype;	/* transfer type */
374b5720c2Smpi #define USBPCAP_TRANSFER_ISOCHRONOUS	0
384b5720c2Smpi #define USBPCAP_TRANSFER_INTERRUPT	1
394b5720c2Smpi #define USBPCAP_TRANSFER_CONTROL	2
404b5720c2Smpi #define USBPCAP_TRANSFER_BULK		3
414b5720c2Smpi 
424b5720c2Smpi 	uint32_t		uph_dlen;	/* data length */
434b5720c2Smpi } __attribute__((packed));
444b5720c2Smpi 
454b5720c2Smpi /*
464b5720c2Smpi  * Header used when dumping control transfers.
474b5720c2Smpi  */
484b5720c2Smpi struct usbpcap_ctl_hdr {
494b5720c2Smpi 	struct usbpcap_pkt_hdr	uch_hdr;
504b5720c2Smpi 	uint8_t			uch_stage;
514b5720c2Smpi #define USBPCAP_CONTROL_STAGE_SETUP	0
524b5720c2Smpi #define USBPCAP_CONTROL_STAGE_DATA	1
534b5720c2Smpi #define USBPCAP_CONTROL_STAGE_STATUS	2
544b5720c2Smpi } __attribute__((packed));
554b5720c2Smpi 
56*4ba11bd8Smpi struct usbpcap_iso_pkt {
57*4ba11bd8Smpi 	uint32_t	uip_offset;
58*4ba11bd8Smpi 	uint32_t	uip_length;
59*4ba11bd8Smpi 	uint32_t	uip_status;
60*4ba11bd8Smpi } __attribute__((packed));
61*4ba11bd8Smpi 
62*4ba11bd8Smpi /*
63*4ba11bd8Smpi  * Header used when dumping isochronous transfers.
64*4ba11bd8Smpi  */
65*4ba11bd8Smpi struct usbpcap_iso_hdr {
66*4ba11bd8Smpi 	struct usbpcap_pkt_hdr	uih_hdr;
67*4ba11bd8Smpi 	uint32_t		uih_startframe;
68*4ba11bd8Smpi 	uint32_t		uih_nframes;	/* number of frame */
69*4ba11bd8Smpi 	uint32_t		uih_errors;	/* error count */
70*4ba11bd8Smpi 	struct usbpcap_iso_pkt	uih_frames[1];
71*4ba11bd8Smpi } __attribute__((packed));
72*4ba11bd8Smpi 
73*4ba11bd8Smpi #ifdef _KERNEL
74*4ba11bd8Smpi /*
75*4ba11bd8Smpi  * OpenBSD specific, maximum number of frames per transfer used across
76*4ba11bd8Smpi  * all USB drivers.  This allows us to setup the header on the stack.
77*4ba11bd8Smpi  */
78*4ba11bd8Smpi #define _USBPCAP_MAX_ISOFRAMES 40
79*4ba11bd8Smpi struct usbpcap_iso_hdr_full {
80*4ba11bd8Smpi 	struct usbpcap_pkt_hdr	uih_hdr;
81*4ba11bd8Smpi 	uint32_t		uih_startframe;
82*4ba11bd8Smpi 	uint32_t		uih_nframes;
83*4ba11bd8Smpi 	uint32_t		uih_errors;
84*4ba11bd8Smpi 	struct usbpcap_iso_pkt	uih_frames[_USBPCAP_MAX_ISOFRAMES];
85*4ba11bd8Smpi } __attribute__((packed));
86*4ba11bd8Smpi #endif /* _KERNEL */
874b5720c2Smpi #endif /* _USBCAP_H_ */
88