3 * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
28 /* USB templates are used to build up real USB descriptors */
30 #ifndef _USB_TEMPLATE_H_
31 #define _USB_TEMPLATE_H_
33 typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
34 typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen);
36 struct usb_temp_packet_size {
37 uint16_t mps[USB_SPEED_MAX];
40 struct usb_temp_interval {
41 uint8_t bInterval[USB_SPEED_MAX];
44 struct usb_temp_endpoint_desc {
45 const void **ppRawDesc;
46 const struct usb_temp_packet_size *pPacketSize;
47 const struct usb_temp_interval *pIntervals;
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.
53 uint8_t bEndpointAddress; /* UE_DIR_IN or UE_DIR_OUT */
57 struct usb_temp_interface_desc {
58 const void **ppRawDesc;
59 const struct usb_temp_endpoint_desc **ppEndpoints;
60 uint8_t bInterfaceClass;
61 uint8_t bInterfaceSubClass;
62 uint8_t bInterfaceProtocol;
64 uint8_t isAltInterface;
67 struct usb_temp_config_desc {
68 const struct usb_temp_interface_desc **ppIfaceDesc;
71 uint8_t iConfiguration;
74 struct usb_temp_device_desc {
75 usb_temp_get_string_desc_t *getStringDesc;
76 usb_temp_get_vendor_desc_t *getVendorDesc;
77 const struct usb_temp_config_desc **ppConfigDesc;
82 uint8_t bDeviceSubClass;
83 uint8_t bDeviceProtocol;
84 uint8_t iManufacturer;
86 uint8_t iSerialNumber;
89 struct usb_temp_data {
90 const struct usb_temp_device_desc *tdd;
91 struct usb_device_descriptor udd; /* device descriptor */
92 struct usb_device_qualifier udq; /* device qualifier */
97 extern const struct usb_temp_device_desc usb_template_cdce;
98 extern const struct usb_temp_device_desc usb_template_msc; /* Mass Storage Class */
99 extern const struct usb_temp_device_desc usb_template_mtp; /* Message Transfer
101 usb_error_t usb_temp_setup(struct usb_device *,
102 const struct usb_temp_device_desc *);
103 void usb_temp_unsetup(struct usb_device *);
105 #endif /* _USB_TEMPLATE_H_ */