3 * Copyright (c) 2008 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
29 * This file contains the USB templates for an USB Mass Storage Device.
32 #ifdef USB_GLOBAL_INCLUDE_FILE
33 #include USB_GLOBAL_INCLUDE_FILE
35 #include <sys/stdint.h>
36 #include <sys/stddef.h>
37 #include <sys/param.h>
38 #include <sys/queue.h>
39 #include <sys/types.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
43 #include <sys/module.h>
45 #include <sys/mutex.h>
46 #include <sys/condvar.h>
47 #include <sys/sysctl.h>
49 #include <sys/unistd.h>
50 #include <sys/callout.h>
51 #include <sys/malloc.h>
54 #include <dev/usb/usb.h>
55 #include <dev/usb/usbdi.h>
56 #include <dev/usb/usb_core.h>
58 #include <dev/usb/template/usb_template.h>
59 #endif /* USB_GLOBAL_INCLUDE_FILE */
63 STRING_MSC_DATA_INDEX,
64 STRING_MSC_CONFIG_INDEX,
65 STRING_MSC_VENDOR_INDEX,
66 STRING_MSC_PRODUCT_INDEX,
67 STRING_MSC_SERIAL_INDEX,
71 #define STRING_MSC_DATA \
72 "U\0S\0B\0 \0M\0a\0s\0s\0 \0S\0t\0o\0r\0a\0g\0e\0 " \
73 "\0I\0n\0t\0e\0r\0f\0a\0c\0e"
75 #define STRING_MSC_CONFIG \
76 "D\0e\0f\0a\0u\0l\0t\0 \0c\0o\0n\0f\0i\0g"
78 #define STRING_MSC_VENDOR \
79 "F\0r\0e\0e\0B\0S\0D\0 \0f\0o\0u\0n\0d\0a\0t\0i\0o\0n"
81 #define STRING_MSC_PRODUCT \
82 "U\0S\0B\0 \0M\0e\0m\0o\0r\0y\0 \0S\0t\0i\0c\0k"
84 #define STRING_MSC_SERIAL \
85 "M\0a\0r\0c\0h\0 \0002\0000\0000\08"
87 /* make the real string descriptors */
89 USB_MAKE_STRING_DESC(STRING_MSC_DATA, string_msc_data);
90 USB_MAKE_STRING_DESC(STRING_MSC_CONFIG, string_msc_config);
91 USB_MAKE_STRING_DESC(STRING_MSC_VENDOR, string_msc_vendor);
92 USB_MAKE_STRING_DESC(STRING_MSC_PRODUCT, string_msc_product);
93 USB_MAKE_STRING_DESC(STRING_MSC_SERIAL, string_msc_serial);
97 static usb_temp_get_string_desc_t msc_get_string_desc;
99 static const struct usb_temp_packet_size bulk_mps = {
100 .mps[USB_SPEED_FULL] = 64,
101 .mps[USB_SPEED_HIGH] = 512,
104 static const struct usb_temp_endpoint_desc bulk_in_ep = {
105 .pPacketSize = &bulk_mps,
106 #ifdef USB_HIP_IN_EP_0
107 .bEndpointAddress = USB_HIP_IN_EP_0,
109 .bEndpointAddress = UE_DIR_IN,
111 .bmAttributes = UE_BULK,
114 static const struct usb_temp_endpoint_desc bulk_out_ep = {
115 .pPacketSize = &bulk_mps,
116 #ifdef USB_HIP_OUT_EP_0
117 .bEndpointAddress = USB_HIP_OUT_EP_0,
119 .bEndpointAddress = UE_DIR_OUT,
121 .bmAttributes = UE_BULK,
124 static const struct usb_temp_endpoint_desc *msc_data_endpoints[] = {
130 static const struct usb_temp_interface_desc msc_data_interface = {
131 .ppEndpoints = msc_data_endpoints,
132 .bInterfaceClass = UICLASS_MASS,
133 .bInterfaceSubClass = UISUBCLASS_SCSI,
134 .bInterfaceProtocol = UIPROTO_MASS_BBB,
135 .iInterface = STRING_MSC_DATA_INDEX,
138 static const struct usb_temp_interface_desc *msc_interfaces[] = {
143 static const struct usb_temp_config_desc msc_config_desc = {
144 .ppIfaceDesc = msc_interfaces,
145 .bmAttributes = UC_BUS_POWERED,
146 .bMaxPower = 25, /* 50 mA */
147 .iConfiguration = STRING_MSC_CONFIG_INDEX,
150 static const struct usb_temp_config_desc *msc_configs[] = {
155 const struct usb_temp_device_desc usb_template_msc = {
156 .getStringDesc = &msc_get_string_desc,
157 .ppConfigDesc = msc_configs,
158 .idVendor = USB_TEMPLATE_VENDOR,
161 .bDeviceClass = UDCLASS_COMM,
162 .bDeviceSubClass = 0,
163 .bDeviceProtocol = 0,
164 .iManufacturer = STRING_MSC_VENDOR_INDEX,
165 .iProduct = STRING_MSC_PRODUCT_INDEX,
166 .iSerialNumber = STRING_MSC_SERIAL_INDEX,
169 /*------------------------------------------------------------------------*
170 * msc_get_string_desc
173 * NULL: Failure. No such string.
174 * Else: Success. Pointer to string descriptor is returned.
175 *------------------------------------------------------------------------*/
177 msc_get_string_desc(uint16_t lang_id, uint8_t string_index)
179 static const void *ptr[STRING_MSC_MAX] = {
180 [STRING_LANG_INDEX] = &usb_string_lang_en,
181 [STRING_MSC_DATA_INDEX] = &string_msc_data,
182 [STRING_MSC_CONFIG_INDEX] = &string_msc_config,
183 [STRING_MSC_VENDOR_INDEX] = &string_msc_vendor,
184 [STRING_MSC_PRODUCT_INDEX] = &string_msc_product,
185 [STRING_MSC_SERIAL_INDEX] = &string_msc_serial,
188 if (string_index == 0) {
189 return (&usb_string_lang_en);
191 if (lang_id != 0x0409) {
194 if (string_index < STRING_MSC_MAX) {
195 return (ptr[string_index]);