xref: /freebsd/sys/dev/usb/template/usb_template.h (revision 71625ec9)
102ac6454SAndrew Thompson /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
45d38a4d4SEd Schouten  * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
502ac6454SAndrew Thompson  * All rights reserved.
602ac6454SAndrew Thompson  *
702ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
802ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
902ac6454SAndrew Thompson  * are met:
1002ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1102ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1202ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1302ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1402ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1502ac6454SAndrew Thompson  *
1602ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1702ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1802ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1902ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2002ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2102ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2202ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2302ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2402ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2502ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2602ac6454SAndrew Thompson  * SUCH DAMAGE.
2702ac6454SAndrew Thompson  */
2802ac6454SAndrew Thompson 
2902ac6454SAndrew Thompson /* USB templates are used to build up real USB descriptors */
3002ac6454SAndrew Thompson 
3102ac6454SAndrew Thompson #ifndef _USB_TEMPLATE_H_
3202ac6454SAndrew Thompson #define	_USB_TEMPLATE_H_
3302ac6454SAndrew Thompson 
34399e6543SHans Petter Selasky #ifndef USB_TEMPLATE_VENDOR
35d01c1c8bSEdward Tomasz Napierala /*
36d01c1c8bSEdward Tomasz Napierala  * https://github.com/obdev/v-usb/blob/master/usbdrv/USB-IDs-for-free.txt
37d01c1c8bSEdward Tomasz Napierala  */
38d01c1c8bSEdward Tomasz Napierala #define	USB_TEMPLATE_VENDOR		0x16c0
39d01c1c8bSEdward Tomasz Napierala #define	USB_TEMPLATE_MANUFACTURER	\
40d01c1c8bSEdward Tomasz Napierala 	"The FreeBSD Project (https://www.FreeBSD.org)"
41399e6543SHans Petter Selasky #endif
42399e6543SHans Petter Selasky 
43a593f6b8SAndrew Thompson typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
449a8e0122SAndrew Thompson typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen);
4502ac6454SAndrew Thompson 
46760bc48eSAndrew Thompson struct usb_temp_packet_size {
4702ac6454SAndrew Thompson 	uint16_t mps[USB_SPEED_MAX];
4802ac6454SAndrew Thompson };
4902ac6454SAndrew Thompson 
50760bc48eSAndrew Thompson struct usb_temp_interval {
5102ac6454SAndrew Thompson 	uint8_t	bInterval[USB_SPEED_MAX];
5202ac6454SAndrew Thompson };
5302ac6454SAndrew Thompson 
54760bc48eSAndrew Thompson struct usb_temp_endpoint_desc {
5502ac6454SAndrew Thompson 	const void **ppRawDesc;
56760bc48eSAndrew Thompson 	const struct usb_temp_packet_size *pPacketSize;
57760bc48eSAndrew Thompson 	const struct usb_temp_interval *pIntervals;
5802ac6454SAndrew Thompson 	/*
5902ac6454SAndrew Thompson 	 * If (bEndpointAddress & UE_ADDR) is non-zero the endpoint number
6002ac6454SAndrew Thompson 	 * is pre-selected for this endpoint descriptor. Else an endpoint
6102ac6454SAndrew Thompson 	 * number is automatically chosen.
6202ac6454SAndrew Thompson 	 */
6302ac6454SAndrew Thompson 	uint8_t	bEndpointAddress;	/* UE_DIR_IN or UE_DIR_OUT */
6402ac6454SAndrew Thompson 	uint8_t	bmAttributes;
6502ac6454SAndrew Thompson };
6602ac6454SAndrew Thompson 
67760bc48eSAndrew Thompson struct usb_temp_interface_desc {
6802ac6454SAndrew Thompson 	const void **ppRawDesc;
69760bc48eSAndrew Thompson 	const struct usb_temp_endpoint_desc **ppEndpoints;
7002ac6454SAndrew Thompson 	uint8_t	bInterfaceClass;
7102ac6454SAndrew Thompson 	uint8_t	bInterfaceSubClass;
7202ac6454SAndrew Thompson 	uint8_t	bInterfaceProtocol;
7302ac6454SAndrew Thompson 	uint8_t	iInterface;
7402ac6454SAndrew Thompson 	uint8_t	isAltInterface;
7502ac6454SAndrew Thompson };
7602ac6454SAndrew Thompson 
77760bc48eSAndrew Thompson struct usb_temp_config_desc {
78760bc48eSAndrew Thompson 	const struct usb_temp_interface_desc **ppIfaceDesc;
7902ac6454SAndrew Thompson 	uint8_t	bmAttributes;
8002ac6454SAndrew Thompson 	uint8_t	bMaxPower;
8102ac6454SAndrew Thompson 	uint8_t	iConfiguration;
8202ac6454SAndrew Thompson };
8302ac6454SAndrew Thompson 
84760bc48eSAndrew Thompson struct usb_temp_device_desc {
85a593f6b8SAndrew Thompson 	usb_temp_get_string_desc_t *getStringDesc;
86a593f6b8SAndrew Thompson 	usb_temp_get_vendor_desc_t *getVendorDesc;
87760bc48eSAndrew Thompson 	const struct usb_temp_config_desc **ppConfigDesc;
8802ac6454SAndrew Thompson 	uint16_t idVendor;
8902ac6454SAndrew Thompson 	uint16_t idProduct;
9002ac6454SAndrew Thompson 	uint16_t bcdDevice;
9102ac6454SAndrew Thompson 	uint8_t	bDeviceClass;
9202ac6454SAndrew Thompson 	uint8_t	bDeviceSubClass;
9302ac6454SAndrew Thompson 	uint8_t	bDeviceProtocol;
9402ac6454SAndrew Thompson 	uint8_t	iManufacturer;
9502ac6454SAndrew Thompson 	uint8_t	iProduct;
9602ac6454SAndrew Thompson 	uint8_t	iSerialNumber;
9702ac6454SAndrew Thompson };
9802ac6454SAndrew Thompson 
99760bc48eSAndrew Thompson struct usb_temp_data {
100760bc48eSAndrew Thompson 	const struct usb_temp_device_desc *tdd;
101760bc48eSAndrew Thompson 	struct usb_device_descriptor udd;	/* device descriptor */
102760bc48eSAndrew Thompson 	struct usb_device_qualifier udq;	/* device qualifier */
10302ac6454SAndrew Thompson };
10402ac6454SAndrew Thompson 
10502ac6454SAndrew Thompson /* prototypes */
10602ac6454SAndrew Thompson 
1078e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_audio;
1088e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_cdce;
1098e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_kbd;
1108e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_modem;
1118e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_mouse;
1128e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_msc;
1138e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_mtp;
1148e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_phone;
1158e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_serialnet;
1168e06491aSEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_midi;
1173dc87e52SEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_multi;
11863722e52SEdward Tomasz Napierala extern struct usb_temp_device_desc usb_template_cdceem;
1198e06491aSEdward Tomasz Napierala 
1208e06491aSEdward Tomasz Napierala void		usb_decode_str_desc(struct usb_string_descriptor *sd,
1218e06491aSEdward Tomasz Napierala 		    char *buf, size_t buflen);
1229a8e0122SAndrew Thompson usb_error_t	usb_temp_setup(struct usb_device *,
1239a8e0122SAndrew Thompson 		    const struct usb_temp_device_desc *);
1249a8e0122SAndrew Thompson void		usb_temp_unsetup(struct usb_device *);
1258e06491aSEdward Tomasz Napierala int		usb_temp_sysctl(SYSCTL_HANDLER_ARGS);
1268e06491aSEdward Tomasz Napierala 
1278e06491aSEdward Tomasz Napierala SYSCTL_DECL(_hw_usb_templates);
12802ac6454SAndrew Thompson 
12902ac6454SAndrew Thompson #endif					/* _USB_TEMPLATE_H_ */
130