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