usb_template.h revision 189002
1/* $FreeBSD: head/sys/dev/usb/template/usb_template.h 189002 2009-02-24 17:15:29Z ed $ */
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
33typedef const void *(usb2_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
34typedef const void *(usb2_temp_get_vendor_desc_t)(const struct usb2_device_request *req);
35
36struct usb2_temp_packet_size {
37	uint16_t mps[USB_SPEED_MAX];
38};
39
40struct usb2_temp_interval {
41	uint8_t	bInterval[USB_SPEED_MAX];
42};
43
44struct usb2_temp_endpoint_desc {
45	const void **ppRawDesc;
46	const struct usb2_temp_packet_size *pPacketSize;
47	const struct usb2_temp_interval *pIntervals;
48	/*
49	 * If (bEndpointAddress & UE_ADDR) is non-zero the endpoint number
50	 * is pre-selected for this endpoint descriptor. Else an endpoint
51	 * number is automatically chosen.
52	 */
53	uint8_t	bEndpointAddress;	/* UE_DIR_IN or UE_DIR_OUT */
54	uint8_t	bmAttributes;
55};
56
57struct usb2_temp_interface_desc {
58	const void **ppRawDesc;
59	const struct usb2_temp_endpoint_desc **ppEndpoints;
60	uint8_t	bInterfaceClass;
61	uint8_t	bInterfaceSubClass;
62	uint8_t	bInterfaceProtocol;
63	uint8_t	iInterface;
64	uint8_t	isAltInterface;
65};
66
67struct usb2_temp_config_desc {
68	const struct usb2_temp_interface_desc **ppIfaceDesc;
69	uint8_t	bmAttributes;
70	uint8_t	bMaxPower;
71	uint8_t	iConfiguration;
72};
73
74struct usb2_temp_device_desc {
75	usb2_temp_get_string_desc_t *getStringDesc;
76	usb2_temp_get_vendor_desc_t *getVendorDesc;
77	const struct usb2_temp_config_desc **ppConfigDesc;
78	uint16_t idVendor;
79	uint16_t idProduct;
80	uint16_t bcdDevice;
81	uint8_t	bDeviceClass;
82	uint8_t	bDeviceSubClass;
83	uint8_t	bDeviceProtocol;
84	uint8_t	iManufacturer;
85	uint8_t	iProduct;
86	uint8_t	iSerialNumber;
87};
88
89struct usb2_temp_data {
90	const struct usb2_temp_device_desc *tdd;
91	struct usb2_device_descriptor udd;	/* device descriptor */
92	struct usb2_device_qualifier udq;	/* device qualifier */
93};
94
95/* prototypes */
96
97extern const struct usb2_temp_device_desc usb2_template_cdce;
98extern const struct usb2_temp_device_desc usb2_template_msc;	/* Mass Storage Class */
99extern const struct usb2_temp_device_desc usb2_template_mtp;	/* Message Transfer
100								 * Protocol */
101
102#endif					/* _USB_TEMPLATE_H_ */
103