usb_template.h revision 269922
1/* $FreeBSD: stable/10/sys/dev/usb/template/usb_template.h 269922 2014-08-13 08:21:52Z hselasky $ */
2/*-
3 * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28/* USB templates are used to build up real USB descriptors */
29
30#ifndef _USB_TEMPLATE_H_
31#define	_USB_TEMPLATE_H_
32
33#ifndef USB_TEMPLATE_VENDOR
34#define	USB_TEMPLATE_VENDOR	0x0001
35#endif
36
37typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
38typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen);
39
40struct usb_temp_packet_size {
41	uint16_t mps[USB_SPEED_MAX];
42};
43
44struct usb_temp_interval {
45	uint8_t	bInterval[USB_SPEED_MAX];
46};
47
48struct usb_temp_endpoint_desc {
49	const void **ppRawDesc;
50	const struct usb_temp_packet_size *pPacketSize;
51	const struct usb_temp_interval *pIntervals;
52	/*
53	 * If (bEndpointAddress & UE_ADDR) is non-zero the endpoint number
54	 * is pre-selected for this endpoint descriptor. Else an endpoint
55	 * number is automatically chosen.
56	 */
57	uint8_t	bEndpointAddress;	/* UE_DIR_IN or UE_DIR_OUT */
58	uint8_t	bmAttributes;
59};
60
61struct usb_temp_interface_desc {
62	const void **ppRawDesc;
63	const struct usb_temp_endpoint_desc **ppEndpoints;
64	uint8_t	bInterfaceClass;
65	uint8_t	bInterfaceSubClass;
66	uint8_t	bInterfaceProtocol;
67	uint8_t	iInterface;
68	uint8_t	isAltInterface;
69};
70
71struct usb_temp_config_desc {
72	const struct usb_temp_interface_desc **ppIfaceDesc;
73	uint8_t	bmAttributes;
74	uint8_t	bMaxPower;
75	uint8_t	iConfiguration;
76};
77
78struct usb_temp_device_desc {
79	usb_temp_get_string_desc_t *getStringDesc;
80	usb_temp_get_vendor_desc_t *getVendorDesc;
81	const struct usb_temp_config_desc **ppConfigDesc;
82	uint16_t idVendor;
83	uint16_t idProduct;
84	uint16_t bcdDevice;
85	uint8_t	bDeviceClass;
86	uint8_t	bDeviceSubClass;
87	uint8_t	bDeviceProtocol;
88	uint8_t	iManufacturer;
89	uint8_t	iProduct;
90	uint8_t	iSerialNumber;
91};
92
93struct usb_temp_data {
94	const struct usb_temp_device_desc *tdd;
95	struct usb_device_descriptor udd;	/* device descriptor */
96	struct usb_device_qualifier udq;	/* device qualifier */
97};
98
99/* prototypes */
100
101extern const struct usb_temp_device_desc usb_template_audio;
102extern const struct usb_temp_device_desc usb_template_cdce;
103extern const struct usb_temp_device_desc usb_template_kbd;
104extern const struct usb_temp_device_desc usb_template_modem;
105extern const struct usb_temp_device_desc usb_template_mouse;
106extern const struct usb_temp_device_desc usb_template_msc;
107extern const struct usb_temp_device_desc usb_template_mtp;
108extern const struct usb_temp_device_desc usb_template_phone;
109
110usb_error_t	usb_temp_setup(struct usb_device *,
111		    const struct usb_temp_device_desc *);
112void	usb_temp_unsetup(struct usb_device *);
113
114#endif					/* _USB_TEMPLATE_H_ */
115