blob: 63ace0c80c0abcdeacfee49cb2b2c854e56d95fb [file] [log] [blame]
Eric Wildf5aa5892019-11-27 18:16:17 +01001/*
2 * Copyright (C) 2019 sysmocom -s.f.m.c. GmbH, Author: Eric Wild <ewild@sysmocom.de>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
Harald Welte34a87062019-04-19 22:33:36 +020019#include "usbd_config.h"
20#include "usbdc.h"
21#include "usb_protocol.h"
22#include "usb_protocol_cdc.h"
23#include "ccid_proto.h"
24#include "cdcdf_acm_desc.h"
Eric Wildf5aa5892019-11-27 18:16:17 +010025#include "usb_descriptors.h"
Harald Welte34a87062019-04-19 22:33:36 +020026
Harald Welte34a87062019-04-19 22:33:36 +020027
Harald Welte34a87062019-04-19 22:33:36 +020028
Eric Wildf5aa5892019-11-27 18:16:17 +010029const struct usb_desc_collection usb_fs_descs = {
Harald Welte34a87062019-04-19 22:33:36 +020030 .dev = {
31 .bLength = sizeof(struct usb_dev_desc),
32 .bDescriptorType = USB_DT_DEVICE,
33 .bcdUSB = USB_V2_0,
34 .bDeviceClass = 0x02,
35 .bDeviceSubClass = 0,
36 .bDeviceProtocol = 0,
37 .bMaxPacketSize0 = CONF_USB_CDCD_ACM_BMAXPKSZ0,
38 .idVendor = CONF_USB_CDCD_ACM_IDVENDER,
39 .idProduct = CONF_USB_CDCD_ACM_IDPRODUCT,
40 .iManufacturer = STR_DESC_MANUF,
41 .iProduct = STR_DESC_PRODUCT,
42 .iSerialNumber = STR_DESC_SERIAL,
43 .bNumConfigurations = 1,
44 },
45 .cfg = {
46 .bLength = sizeof(struct usb_config_desc),
47 .bDescriptorType = USB_DT_CONFIG,
48 .wTotalLength = sizeof(usb_fs_descs.cfg) +
49 sizeof(usb_fs_descs.cdc) +
50 sizeof(usb_fs_descs.ccid),
51 .bNumInterfaces = 3,
52 .bConfigurationValue = CONF_USB_CDCD_ACM_BCONFIGVAL,
53 .iConfiguration = STR_DESC_CONFIG,
54 .bmAttributes = CONF_USB_CDCD_ACM_BMATTRI,
55 .bMaxPower = CONF_USB_CDCD_ACM_BMAXPOWER,
56 },
57 .cdc = {
58 .comm = {
59 .iface = {
60 .bLength = sizeof(struct usb_iface_desc),
61 .bDescriptorType = USB_DT_INTERFACE,
62 .bInterfaceNumber = CONF_USB_CDCD_ACM_COMM_BIFCNUM,
63 .bAlternateSetting = CONF_USB_CDCD_ACM_COMM_BALTSET,
64 .bNumEndpoints = 1,
65 .bInterfaceClass = CDC_CLASS_COMM,
66 .bInterfaceSubClass = CDC_SUBCLASS_ACM,
67 .bInterfaceProtocol = 0x00,
68 .iInterface = STR_DESC_INTF_ACM_COMM,
69 },
70 .cdc_hdr = {
71 .bFunctionLength = sizeof(struct usb_cdc_hdr_desc),
72 .bDescriptorType = CDC_CS_INTERFACE,
73 .bDescriptorSubtype = CDC_SCS_HEADER,
74 .bcdCDC = LE16(0x1001),
75 },
76 .cdc_call_mgmt = {
77 .bFunctionLength = sizeof(struct usb_cdc_call_mgmt_desc),
78 .bDescriptorType = CDC_CS_INTERFACE,
79 .bDescriptorSubtype = CDC_SCS_CALL_MGMT,
80 .bmCapabilities = 0x01,
81 .bDataInterface = 0x00,
82 },
83 .cdc_acm = {
84 .bFunctionLength = sizeof(struct usb_cdc_acm_desc),
85 .bDescriptorType = CDC_CS_INTERFACE,
86 .bDescriptorSubtype = CDC_SCS_ACM,
87 .bmCapabilities = 0x02,
88 },
89 .cdc_union = {
90 .bFunctionLength = sizeof(struct usb_cdc_union_desc),
91 .bDescriptorType = CDC_CS_INTERFACE,
92 .bDescriptorSubtype = CDC_SCS_UNION,
93 .bMasterInterface = CONF_USB_CDCD_ACM_COMM_BIFCNUM,
Harald Welte34507372019-11-11 19:04:41 +010094 .bSlaveInterface0 = CONF_USB_CDCD_ACM_DATA_BIFCNUM,
Harald Welte34a87062019-04-19 22:33:36 +020095 },
96 .ep = {
97 {
98 .bLength = sizeof(struct usb_ep_desc),
99 .bDescriptorType = USB_DT_ENDPOINT,
100 .bEndpointAddress = CONF_USB_CDCD_ACM_COMM_INT_EPADDR,
101 .bmAttributes = USB_EP_TYPE_INTERRUPT,
102 .wMaxPacketSize = CONF_USB_CDCD_ACM_COMM_INT_MAXPKSZ,
103 .bInterval = CONF_USB_CDCD_ACM_COMM_INT_INTERVAL,
104 },
105 },
106 },
107 .data = {
108 .iface = {
109 .bLength = sizeof(struct usb_iface_desc),
110 .bDescriptorType = USB_DT_INTERFACE,
111 .bInterfaceNumber = CONF_USB_CDCD_ACM_DATA_BIFCNUM,
112 .bAlternateSetting = CONF_USB_CDCD_ACM_DATA_BALTSET,
113 .bNumEndpoints = 2,
114 .bInterfaceClass = CDC_CLASS_DATA,
115 .bInterfaceSubClass = 0x00,
116 .bInterfaceProtocol = 0x00,
117 .iInterface = STR_DESC_INTF_ACM_DATA,
118 },
119 .ep = {
120 {
121 .bLength = sizeof(struct usb_ep_desc),
122 .bDescriptorType = USB_DT_ENDPOINT,
123 .bEndpointAddress = CONF_USB_CDCD_ACM_DATA_BULKOUT_EPADDR,
124 .bmAttributes = USB_EP_TYPE_BULK,
125 .wMaxPacketSize = CONF_USB_CDCD_ACM_DATA_BULKOUT_MAXPKSZ,
126 .bInterval = 0,
127 },
128 {
129 .bLength = sizeof(struct usb_ep_desc),
130 .bDescriptorType = USB_DT_ENDPOINT,
131 .bEndpointAddress = CONF_USB_CDCD_ACM_DATA_BULKIN_EPADDR,
132 .bmAttributes = USB_EP_TYPE_BULK,
133 .wMaxPacketSize = CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ,
134 .bInterval = 0,
135 },
136 },
137 },
138 },
139 .ccid = {
140 .iface = {
141 .bLength = sizeof(struct usb_iface_desc),
142 .bDescriptorType = USB_DT_INTERFACE,
Eric Wild76033902019-10-01 15:04:01 +0200143 .bInterfaceNumber = 0,
Harald Welte34a87062019-04-19 22:33:36 +0200144 .bAlternateSetting = 0,
145 .bNumEndpoints = 3,
146 .bInterfaceClass = 11,
147 .bInterfaceSubClass = 0,
148 .bInterfaceProtocol = 0,
149 .iInterface = STR_DESC_INTF_CCID,
150 },
151 .class = {
152 .bLength = sizeof(struct usb_ccid_class_descriptor),
153 .bDescriptorType = 33,
154 .bcdCCID = LE16(0x0110),
155 .bMaxSlotIndex = 7,
Eric Wild76033902019-10-01 15:04:01 +0200156 .bVoltageSupport = 0x07, /* 5/3/1.8V */
Eric Wildf5aa5892019-11-27 18:16:17 +0100157 .dwProtocols = 0x01, /* only t0 */
Harald Welte34a87062019-04-19 22:33:36 +0200158 .dwDefaultClock = LE32(2500),
159 .dwMaximumClock = LE32(20000),
Eric Wildf5aa5892019-11-27 18:16:17 +0100160 .bNumClockSupported = CCID_NUM_CLK_SUPPORTED,
161 .dwDataRate = LE32(6720), /* default clock 2.5M/372 */
Harald Welte34a87062019-04-19 22:33:36 +0200162 .dwMaxDataRate = LE32(921600),
163 .bNumDataRatesSupported = 0,
164 .dwMaxIFSD = LE32(0),
165 .dwSynchProtocols = LE32(0),
166 .dwMechanical = LE32(0),
Eric Wildf5aa5892019-11-27 18:16:17 +0100167 /* 0x10000 TPDU level exchanges with CCID
168 * 0x80 Automatic PPS made by the CCID according to the active parameters
169 * 0x20 Automatic baud rate change according to active parameters
170 * provided by the Host or self determined
171 * 0x10 Automatic ICC clock frequency change according to active parameters
172 * provided by the Host or self determined */
173 .dwFeatures = LE32(0x10 | 0x20 | 0x80 | 0x00010000),
Harald Welte34a87062019-04-19 22:33:36 +0200174 .dwMaxCCIDMessageLength = 272,
175 .bClassGetResponse = 0xff,
176 .bClassEnvelope = 0xff,
177 .wLcdLayout = LE16(0),
178 .bPINSupport = 0,
179 .bMaxCCIDBusySlots = 8,
180 },
181 .ep = {
182 { /* Bulk-OUT descriptor */
183 .bLength = sizeof(struct usb_ep_desc),
184 .bDescriptorType = USB_DT_ENDPOINT,
185 .bEndpointAddress = 0x02,
186 .bmAttributes = USB_EP_TYPE_BULK,
187 .wMaxPacketSize = 64,
188 .bInterval = 0,
189 },
190 { /* Bulk-IN descriptor */
191 .bLength = sizeof(struct usb_ep_desc),
192 .bDescriptorType = USB_DT_ENDPOINT,
193 .bEndpointAddress = 0x83,
194 .bmAttributes = USB_EP_TYPE_BULK,
195 .wMaxPacketSize = 64,
196 .bInterval = 0,
197 },
198 { /* Interrupt dscriptor */
199 .bLength = sizeof(struct usb_ep_desc),
200 .bDescriptorType = USB_DT_ENDPOINT,
201 .bEndpointAddress = 0x84,
202 .bmAttributes = USB_EP_TYPE_INTERRUPT,
203 .wMaxPacketSize = 64,
204 .bInterval = 0x10,
205 },
206 },
207 },
208 //DFURT_IF_DESCRIPTOR,
209 .str = {
210#if 0
211 CDCD_ACM_STR_DESCES
212#else
213 4, 3, 0x09, 0x04,
214 18, 3, 's',0, 'y',0, 's',0, 'm',0, 'o',0, 'c',0, 'o',0, 'm',0,
215 24, 3, 's',0, 'y',0, 's',0, 'm',0, 'o',0, 'O',0, 'C',0, 'T',0, 'S',0, 'I',0, 'M',0,
216 4, 3, 'A', 0,
217 22, 3, 'd',0, 'e',0, 'b',0, 'u',0, 'g',0, ' ',0, 'U',0, 'A',0, 'R',0, 'T',0,
218 22, 3, 'd',0, 'e',0, 'b',0, 'u',0, 'g',0, ' ',0, 'U',0, 'A',0, 'R',0, 'T',0,
219 10, 3, 'C',0, 'C',0, 'I',0, 'D',0,
220 12, 3, 'F',0, 'I',0, 'X',0, 'M',0, 'E',0,
221#endif
222 }
223};
224
225const struct usbd_descriptors usb_descs[]
226 = {{ (uint8_t *)&usb_fs_descs, (uint8_t *)&usb_fs_descs + sizeof(usb_fs_descs) }};