1 /* $FreeBSD: head/sys/dev/usb/template/usb_template_modem.c 246125 2013-01-30 16:05:54Z hselasky $ */
3 * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * This file contains the USB template for an USB Modem Device.
31 #ifdef USB_GLOBAL_INCLUDE_FILE
32 #include USB_GLOBAL_INCLUDE_FILE
34 #include <sys/stdint.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/condvar.h>
44 #include <sys/sysctl.h>
45 #include <sys/unistd.h>
46 #include <sys/callout.h>
47 #include <sys/malloc.h>
50 #include <bus/u4b/usb.h>
51 #include <bus/u4b/usbdi.h>
52 #include <bus/u4b/usb_core.h>
53 #include <bus/u4b/usb_cdc.h>
55 #include <bus/u4b/template/usb_template.h>
56 #endif /* USB_GLOBAL_INCLUDE_FILE */
65 #define STRING_PRODUCT \
66 "M\0o\0d\0e\0m\0 \0T\0e\0s\0t\0 \0D\0e\0v\0i\0c\0e"
68 #define STRING_MODEM \
69 "M\0o\0d\0e\0m\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e"
71 /* make the real string descriptors */
73 USB_MAKE_STRING_DESC(STRING_MODEM, string_modem);
74 USB_MAKE_STRING_DESC(STRING_PRODUCT, string_product);
76 #define MODEM_IFACE_0 0
77 #define MODEM_IFACE_1 1
81 static const struct usb_temp_packet_size modem_bulk_mps = {
82 .mps[USB_SPEED_LOW] = 8,
83 .mps[USB_SPEED_FULL] = 64,
84 .mps[USB_SPEED_HIGH] = 512,
87 static const struct usb_temp_packet_size modem_intr_mps = {
88 .mps[USB_SPEED_LOW] = 8,
89 .mps[USB_SPEED_FULL] = 8,
90 .mps[USB_SPEED_HIGH] = 8,
93 static const struct usb_temp_interval modem_intr_interval = {
94 .bInterval[USB_SPEED_LOW] = 8, /* 8ms */
95 .bInterval[USB_SPEED_FULL] = 8, /* 8ms */
96 .bInterval[USB_SPEED_HIGH] = 7, /* 8ms */
99 static const struct usb_temp_endpoint_desc modem_ep_0 = {
100 .pPacketSize = &modem_intr_mps,
101 .pIntervals = &modem_intr_interval,
102 .bEndpointAddress = UE_DIR_IN,
103 .bmAttributes = UE_INTERRUPT,
106 static const struct usb_temp_endpoint_desc modem_ep_1 = {
107 .pPacketSize = &modem_bulk_mps,
108 .bEndpointAddress = UE_DIR_OUT,
109 .bmAttributes = UE_BULK,
112 static const struct usb_temp_endpoint_desc modem_ep_2 = {
113 .pPacketSize = &modem_bulk_mps,
114 .bEndpointAddress = UE_DIR_IN,
115 .bmAttributes = UE_BULK,
118 static const struct usb_temp_endpoint_desc *modem_iface_0_ep[] = {
123 static const struct usb_temp_endpoint_desc *modem_iface_1_ep[] = {
129 static const uint8_t modem_raw_desc_0[] = {
130 0x05, 0x24, 0x00, 0x10, 0x01
133 static const uint8_t modem_raw_desc_1[] = {
134 0x05, 0x24, 0x06, MODEM_IFACE_0, MODEM_IFACE_1
137 static const uint8_t modem_raw_desc_2[] = {
138 0x05, 0x24, 0x01, 0x03, MODEM_IFACE_1
141 static const uint8_t modem_raw_desc_3[] = {
142 0x04, 0x24, 0x02, 0x07
145 static const void *modem_iface_0_desc[] = {
153 static const struct usb_temp_interface_desc modem_iface_0 = {
154 .ppRawDesc = modem_iface_0_desc,
155 .ppEndpoints = modem_iface_0_ep,
156 .bInterfaceClass = 2,
157 .bInterfaceSubClass = 2,
158 .bInterfaceProtocol = 1,
159 .iInterface = INDEX_MODEM,
162 static const struct usb_temp_interface_desc modem_iface_1 = {
163 .ppEndpoints = modem_iface_1_ep,
164 .bInterfaceClass = 10,
165 .bInterfaceSubClass = 0,
166 .bInterfaceProtocol = 0,
167 .iInterface = INDEX_MODEM,
170 static const struct usb_temp_interface_desc *modem_interfaces[] = {
176 static const struct usb_temp_config_desc modem_config_desc = {
177 .ppIfaceDesc = modem_interfaces,
178 .bmAttributes = UC_BUS_POWERED,
179 .bMaxPower = 25, /* 50 mA */
180 .iConfiguration = INDEX_PRODUCT,
183 static const struct usb_temp_config_desc *modem_configs[] = {
188 static usb_temp_get_string_desc_t modem_get_string_desc;
189 static usb_temp_get_vendor_desc_t modem_get_vendor_desc;
191 const struct usb_temp_device_desc usb_template_modem = {
192 .getStringDesc = &modem_get_string_desc,
193 .getVendorDesc = &modem_get_vendor_desc,
194 .ppConfigDesc = modem_configs,
195 .idVendor = USB_TEMPLATE_VENDOR,
198 .bDeviceClass = UDCLASS_COMM,
199 .bDeviceSubClass = 0,
200 .bDeviceProtocol = 0,
202 .iProduct = INDEX_PRODUCT,
206 /*------------------------------------------------------------------------*
207 * modem_get_vendor_desc
210 * NULL: Failure. No such vendor descriptor.
211 * Else: Success. Pointer to vendor descriptor is returned.
212 *------------------------------------------------------------------------*/
214 modem_get_vendor_desc(const struct usb_device_request *req, uint16_t *plen)
219 /*------------------------------------------------------------------------*
220 * modem_get_string_desc
223 * NULL: Failure. No such string.
224 * Else: Success. Pointer to string descriptor is returned.
225 *------------------------------------------------------------------------*/
227 modem_get_string_desc(uint16_t lang_id, uint8_t string_index)
229 static const void *ptr[INDEX_MAX] = {
230 [INDEX_LANG] = &usb_string_lang_en,
231 [INDEX_MODEM] = &string_modem,
232 [INDEX_PRODUCT] = &string_product,
235 if (string_index == 0) {
236 return (&usb_string_lang_en);
238 if (lang_id != 0x0409) {
241 if (string_index < INDEX_MAX) {
242 return (ptr[string_index]);