5 * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
30 * This file contains the USB template for an USB Modem Device.
33 #include <sys/stdint.h>
34 #include <sys/stddef.h>
35 #include <sys/param.h>
36 #include <sys/queue.h>
37 #include <sys/types.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
41 #include <sys/module.h>
43 #include <sys/mutex.h>
44 #include <sys/condvar.h>
45 #include <sys/sysctl.h>
47 #include <sys/unistd.h>
48 #include <sys/callout.h>
49 #include <sys/malloc.h>
52 #include <dev/usb/usb.h>
53 #include <dev/usb/usbdi.h>
54 #include <dev/usb/usb_cdc.h>
56 #include <dev/usb/template/usb_template.h>
66 0x09, 0x04, /* American English */
68 #define STRING_PRODUCT \
69 'M', 0, 'o', 0, 'd', 0, 'e', 0, 'm', 0, ' ', 0, \
70 'T', 0, 'e', 0, 's', 0, 't', 0, ' ', 0, \
71 'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, ' ', 0,
73 #define STRING_MODEM \
74 'M', 0, 'o', 0, 'd', 0, 'e', 0, 'm', 0, ' ', 0, \
75 'i', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0,
77 /* make the real string descriptors */
79 USB_MAKE_STRING_DESC(STRING_LANG, string_lang);
80 USB_MAKE_STRING_DESC(STRING_MODEM, string_modem);
81 USB_MAKE_STRING_DESC(STRING_PRODUCT, string_product);
83 #define MODEM_IFACE_0 0
84 #define MODEM_IFACE_1 1
88 static const struct usb_temp_packet_size modem_bulk_mps = {
89 .mps[USB_SPEED_LOW] = 8,
90 .mps[USB_SPEED_FULL] = 64,
91 .mps[USB_SPEED_HIGH] = 512,
94 static const struct usb_temp_packet_size modem_intr_mps = {
95 .mps[USB_SPEED_LOW] = 8,
96 .mps[USB_SPEED_FULL] = 8,
97 .mps[USB_SPEED_HIGH] = 8,
100 static const struct usb_temp_interval modem_intr_interval = {
101 .bInterval[USB_SPEED_LOW] = 10,
102 .bInterval[USB_SPEED_FULL] = 10,
103 .bInterval[USB_SPEED_HIGH] = 10 * 8,
106 static const struct usb_temp_endpoint_desc modem_ep_0 = {
107 .pPacketSize = &modem_intr_mps,
108 .pIntervals = &modem_intr_interval,
109 .bEndpointAddress = UE_DIR_IN,
110 .bmAttributes = UE_INTERRUPT,
113 static const struct usb_temp_endpoint_desc modem_ep_1 = {
114 .pPacketSize = &modem_bulk_mps,
115 .bEndpointAddress = UE_DIR_OUT,
116 .bmAttributes = UE_BULK,
119 static const struct usb_temp_endpoint_desc modem_ep_2 = {
120 .pPacketSize = &modem_bulk_mps,
121 .bEndpointAddress = UE_DIR_IN,
122 .bmAttributes = UE_BULK,
125 static const struct usb_temp_endpoint_desc *modem_iface_0_ep[] = {
130 static const struct usb_temp_endpoint_desc *modem_iface_1_ep[] = {
136 static const uint8_t modem_raw_desc_0[] = {
137 0x05, 0x24, 0x00, 0x10, 0x01
140 static const uint8_t modem_raw_desc_1[] = {
141 0x05, 0x24, 0x06, MODEM_IFACE_0, MODEM_IFACE_1
144 static const uint8_t modem_raw_desc_2[] = {
145 0x05, 0x24, 0x01, 0x03, MODEM_IFACE_1
148 static const uint8_t modem_raw_desc_3[] = {
149 0x04, 0x24, 0x02, 0x07
152 static const void *modem_iface_0_desc[] = {
160 static const struct usb_temp_interface_desc modem_iface_0 = {
161 .ppRawDesc = modem_iface_0_desc,
162 .ppEndpoints = modem_iface_0_ep,
163 .bInterfaceClass = 2,
164 .bInterfaceSubClass = 2,
165 .bInterfaceProtocol = 1,
166 .iInterface = INDEX_MODEM,
169 static const struct usb_temp_interface_desc modem_iface_1 = {
170 .ppEndpoints = modem_iface_1_ep,
171 .bInterfaceClass = 10,
172 .bInterfaceSubClass = 0,
173 .bInterfaceProtocol = 0,
174 .iInterface = INDEX_MODEM,
177 static const struct usb_temp_interface_desc *modem_interfaces[] = {
183 static const struct usb_temp_config_desc modem_config_desc = {
184 .ppIfaceDesc = modem_interfaces,
185 .bmAttributes = UC_BUS_POWERED,
186 .bMaxPower = 25, /* 50 mA */
187 .iConfiguration = INDEX_PRODUCT,
190 static const struct usb_temp_config_desc *modem_configs[] = {
195 static usb_temp_get_string_desc_t modem_get_string_desc;
196 static usb_temp_get_vendor_desc_t modem_get_vendor_desc;
198 const struct usb_temp_device_desc usb_template_modem = {
199 .getStringDesc = &modem_get_string_desc,
200 .getVendorDesc = &modem_get_vendor_desc,
201 .ppConfigDesc = modem_configs,
202 .idVendor = USB_TEMPLATE_VENDOR,
205 .bDeviceClass = UDCLASS_COMM,
206 .bDeviceSubClass = 0,
207 .bDeviceProtocol = 0,
209 .iProduct = INDEX_PRODUCT,
213 /*------------------------------------------------------------------------*
214 * modem_get_vendor_desc
217 * NULL: Failure. No such vendor descriptor.
218 * Else: Success. Pointer to vendor descriptor is returned.
219 *------------------------------------------------------------------------*/
221 modem_get_vendor_desc(const struct usb_device_request *req, uint16_t *plen)
226 /*------------------------------------------------------------------------*
227 * modem_get_string_desc
230 * NULL: Failure. No such string.
231 * Else: Success. Pointer to string descriptor is returned.
232 *------------------------------------------------------------------------*/
234 modem_get_string_desc(uint16_t lang_id, uint8_t string_index)
236 static const void *ptr[INDEX_MAX] = {
237 [INDEX_LANG] = &string_lang,
238 [INDEX_MODEM] = &string_modem,
239 [INDEX_PRODUCT] = &string_product,
242 if (string_index == 0) {
243 return (&string_lang);
245 if (lang_id != 0x0409) {
248 if (string_index < INDEX_MAX) {
249 return (ptr[string_index]);