FreeBSD kernel usb device Code
usb_template.h
Go to the documentation of this file.
1/* $FreeBSD$ */
2/*-
3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 *
5 * Copyright (c) 2007 Hans Petter Selasky <hselasky@FreeBSD.org>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
16 *
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
27 * SUCH DAMAGE.
28 */
29
30/* USB templates are used to build up real USB descriptors */
31
32#ifndef _USB_TEMPLATE_H_
33#define _USB_TEMPLATE_H_
34
35#ifndef USB_TEMPLATE_VENDOR
36/*
37 * https://github.com/obdev/v-usb/blob/master/usbdrv/USB-IDs-for-free.txt
38 */
39#define USB_TEMPLATE_VENDOR 0x16c0
40#define USB_TEMPLATE_MANUFACTURER \
41 "The FreeBSD Project (https://www.FreeBSD.org)"
42#endif
43
44typedef const void *(usb_temp_get_string_desc_t)(uint16_t lang_id, uint8_t string_index);
45typedef const void *(usb_temp_get_vendor_desc_t)(const struct usb_device_request *req, uint16_t *plen);
46
48 uint16_t mps[USB_SPEED_MAX];
49};
50
53};
54
56 const void **ppRawDesc;
59 /*
60 * If (bEndpointAddress & UE_ADDR) is non-zero the endpoint number
61 * is pre-selected for this endpoint descriptor. Else an endpoint
62 * number is automatically chosen.
63 */
64 uint8_t bEndpointAddress; /* UE_DIR_IN or UE_DIR_OUT */
65 uint8_t bmAttributes;
66};
67
69 const void **ppRawDesc;
74 uint8_t iInterface;
76};
77
80 uint8_t bmAttributes;
81 uint8_t bMaxPower;
83};
84
89 uint16_t idVendor;
90 uint16_t idProduct;
91 uint16_t bcdDevice;
92 uint8_t bDeviceClass;
96 uint8_t iProduct;
98};
99
102 struct usb_device_descriptor udd; /* device descriptor */
103 struct usb_device_qualifier udq; /* device qualifier */
104};
105
106/* prototypes */
107
120
122 char *buf, size_t buflen);
124 const struct usb_temp_device_desc *);
125void usb_temp_unsetup(struct usb_device *);
126int usb_temp_sysctl(SYSCTL_HANDLER_ARGS);
127
128SYSCTL_DECL(_hw_usb_templates);
129
130#endif /* _USB_TEMPLATE_H_ */
const struct usb_temp_interface_desc ** ppIfaceDesc
Definition: usb_template.h:79
struct usb_device_descriptor udd
Definition: usb_template.h:102
const struct usb_temp_device_desc * tdd
Definition: usb_template.h:101
struct usb_device_qualifier udq
Definition: usb_template.h:103
usb_temp_get_string_desc_t * getStringDesc
Definition: usb_template.h:86
const struct usb_temp_config_desc ** ppConfigDesc
Definition: usb_template.h:88
usb_temp_get_vendor_desc_t * getVendorDesc
Definition: usb_template.h:87
const struct usb_temp_packet_size * pPacketSize
Definition: usb_template.h:57
const struct usb_temp_interval * pIntervals
Definition: usb_template.h:58
const void ** ppRawDesc
Definition: usb_template.h:56
const struct usb_temp_endpoint_desc ** ppEndpoints
Definition: usb_template.h:70
const void ** ppRawDesc
Definition: usb_template.h:69
uint8_t bInterval[USB_SPEED_MAX]
Definition: usb_template.h:52
uint16_t mps[USB_SPEED_MAX]
Definition: usb_template.h:48
#define USB_SPEED_MAX
Definition: usb.h:758
uint16_t * plen
Definition: usb_if.m:53
const void * req
Definition: usb_if.m:51
usb_error_t usb_temp_setup(struct usb_device *, const struct usb_temp_device_desc *)
struct usb_temp_device_desc usb_template_cdceem
struct usb_temp_device_desc usb_template_mtp
struct usb_temp_device_desc usb_template_mouse
struct usb_temp_device_desc usb_template_modem
struct usb_temp_device_desc usb_template_audio
struct usb_temp_device_desc usb_template_multi
void usb_temp_unsetup(struct usb_device *)
struct usb_temp_device_desc usb_template_phone
struct usb_temp_device_desc usb_template_serialnet
struct usb_temp_device_desc usb_template_msc
const void *() usb_temp_get_vendor_desc_t(const struct usb_device_request *req, uint16_t *plen)
Definition: usb_template.h:45
const void *() usb_temp_get_string_desc_t(uint16_t lang_id, uint8_t string_index)
Definition: usb_template.h:44
int usb_temp_sysctl(SYSCTL_HANDLER_ARGS)
Definition: usb_template.c:173
void usb_decode_str_desc(struct usb_string_descriptor *sd, char *buf, size_t buflen)
Definition: usb_template.c:151
SYSCTL_DECL(_hw_usb_templates)
struct usb_temp_device_desc usb_template_midi
struct usb_temp_device_desc usb_template_kbd
struct usb_temp_device_desc usb_template_cdce
usb_error_t
Definition: usbdi.h:45