1 /* $FreeBSD$ */ 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 37 typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index); 38 typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen); 39 40 struct usb_temp_packet_size { 41 uint16_t mps[USB_SPEED_MAX]; 42 }; 43 44 struct usb_temp_interval { 45 uint8_t bInterval[USB_SPEED_MAX]; 46 }; 47 48 struct 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 61 struct 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 71 struct 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 78 struct 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 93 struct 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 101 extern const struct usb_temp_device_desc usb_template_audio; 102 extern const struct usb_temp_device_desc usb_template_cdce; 103 extern const struct usb_temp_device_desc usb_template_kbd; 104 extern const struct usb_temp_device_desc usb_template_modem; 105 extern const struct usb_temp_device_desc usb_template_mouse; 106 extern const struct usb_temp_device_desc usb_template_msc; 107 extern const struct usb_temp_device_desc usb_template_mtp; 108 109 usb_error_t usb_temp_setup(struct usb_device *, 110 const struct usb_temp_device_desc *); 111 void usb_temp_unsetup(struct usb_device *); 112 113 #endif /* _USB_TEMPLATE_H_ */ 114