3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 /* USB templates are used to build up real USB descriptors */
32 #ifndef _USB_TEMPLATE_H_
33 #define _USB_TEMPLATE_H_
35 #ifndef USB_TEMPLATE_VENDOR
36 #define USB_TEMPLATE_VENDOR 0x0001
39 typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
40 typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen);
42 struct usb_temp_packet_size {
43 uint16_t mps[USB_SPEED_MAX];
46 struct usb_temp_interval {
47 uint8_t bInterval[USB_SPEED_MAX];
50 struct usb_temp_endpoint_desc {
51 const void **ppRawDesc;
52 const struct usb_temp_packet_size *pPacketSize;
53 const struct usb_temp_interval *pIntervals;
55 * If (bEndpointAddress & UE_ADDR) is non-zero the endpoint number
56 * is pre-selected for this endpoint descriptor. Else an endpoint
57 * number is automatically chosen.
59 uint8_t bEndpointAddress; /* UE_DIR_IN or UE_DIR_OUT */
63 struct usb_temp_interface_desc {
64 const void **ppRawDesc;
65 const struct usb_temp_endpoint_desc **ppEndpoints;
66 uint8_t bInterfaceClass;
67 uint8_t bInterfaceSubClass;
68 uint8_t bInterfaceProtocol;
70 uint8_t isAltInterface;
73 struct usb_temp_config_desc {
74 const struct usb_temp_interface_desc **ppIfaceDesc;
77 uint8_t iConfiguration;
80 struct usb_temp_device_desc {
81 usb_temp_get_string_desc_t *getStringDesc;
82 usb_temp_get_vendor_desc_t *getVendorDesc;
83 const struct usb_temp_config_desc **ppConfigDesc;
88 uint8_t bDeviceSubClass;
89 uint8_t bDeviceProtocol;
90 uint8_t iManufacturer;
92 uint8_t iSerialNumber;
95 struct usb_temp_data {
96 const struct usb_temp_device_desc *tdd;
97 struct usb_device_descriptor udd; /* device descriptor */
98 struct usb_device_qualifier udq; /* device qualifier */
103 extern struct usb_temp_device_desc usb_template_audio;
104 extern struct usb_temp_device_desc usb_template_cdce;
105 extern struct usb_temp_device_desc usb_template_kbd;
106 extern struct usb_temp_device_desc usb_template_modem;
107 extern struct usb_temp_device_desc usb_template_mouse;
108 extern struct usb_temp_device_desc usb_template_msc;
109 extern struct usb_temp_device_desc usb_template_mtp;
110 extern struct usb_temp_device_desc usb_template_phone;
111 extern struct usb_temp_device_desc usb_template_serialnet;
112 extern struct usb_temp_device_desc usb_template_midi;
115 void usb_decode_str_desc(struct usb_string_descriptor *sd,
116 char *buf, size_t buflen);
117 usb_error_t usb_temp_setup(struct usb_device *,
118 const struct usb_temp_device_desc *);
119 void usb_temp_unsetup(struct usb_device *);
120 int usb_temp_sysctl(SYSCTL_HANDLER_ARGS);
122 SYSCTL_DECL(_hw_usb_templates);
124 #endif /* _USB_TEMPLATE_H_ */