usbd_desc.h
Go to the documentation of this file.
1 /**
2  * @file usbd_desc.h
3  * @brief USB descriptors
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _USBD_DESC_H
32 #define _USBD_DESC_H
33 
34 //Dependencies
35 #include "os_port.h"
36 
37 //Endpoint identifiers
38 #define USB_EP0 0
39 #define USB_EP1 1
40 #define USB_EP2 2
41 #define USB_EP3 3
42 
43 //Data transfer direction
44 #define USB_DIR_MASK 0x80
45 #define USB_DIR_OUT 0x00
46 #define USB_DIR_IN 0x80
47 
48 //Endpoint maximum packet size
49 #define USB_EP0_MAX_PACKET_SIZE 64
50 #define USB_EP1_MAX_PACKET_SIZE 64
51 #define USB_EP2_MAX_PACKET_SIZE 64
52 #define USB_EP3_MAX_PACKET_SIZE 64
53 
54 //bmAttributes field
55 #define USB_SELF_POWERED 0xC0
56 #define USB_BUS_POWERED 0x80
57 #define USB_REMOTE_WAKEUP 0xA0
58 #define USB_NO_REMOTE_WAKEUP 0x80
59 
60 //Endpoint types
61 #define USB_ENDPOINT_TYPE_MASK 0x03
62 #define USB_ENDPOINT_TYPE_CONTROL 0x00
63 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
64 #define USB_ENDPOINT_TYPE_BULK 0x02
65 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
66 
67 //Device class
68 #define USB_DEVICE_CLASS_CDC 0x02
69 //Device subclass
70 #define USB_DEVICE_SUBCLASS_CDC 0x00
71 //Device protocol
72 #define USB_DEVICE_PROTOCOL_CDC 0x00
73 
74 //CDC communication interface class
75 #define CDC_INTERFACE_CLASS_COMMUNICATION 0x02
76 #define CDC_INTERFACE_CLASS_RNDIS 0xEF
77 //CDC communication interface subclass
78 #define CDC_INTERFACE_SUBCLASS_ACM 0x02
79 #define CDC_INTERFACE_SUBCLASS_RNDIS 0x04
80 //CDC communication interface protocol
81 #define CDC_INTERFACE_PROTOCOL_RNDIS 0x01
82 #define CDC_INTERFACE_PROTOCOL_VENDOR_SPECIFIC 0xFF
83 
84 //CDC data interface class
85 #define CDC_INTERFACE_CLASS_DATA 0x0A
86 //CDC data interface subclass
87 #define CDC_INTERFACE_SUBCLASS_DATA 0x00
88 //CDC data interface protocol
89 #define CDC_INTERFACE_PROTOCOL_DATA 0x00
90 
91 //CDC descriptor types
92 #define CDC_CS_INTERFACE 0x24
93 #define CDC_CS_ENDPOINT 0x25
94 
95 //CDC descriptor subtypes
96 #define CDC_HEADER_DESC_SUBTYPE 0x00
97 #define CDC_CALL_MANAGEMENT_DESC_SUBTYPE 0x01
98 #define CDC_ACM_DESC_SUBTYPE 0x02
99 #define CDC_UNION_DESC_SUBTYPE 0x06
100 
101 
102 /**
103  * @brief Device descriptor
104  **/
105 
107 {
108  uint8_t bLength;
110  uint16_t bcdUsb;
111  uint8_t bDeviceClass;
115  uint16_t idVendor;
116  uint16_t idProduct;
117  uint16_t bcdDevice;
118  uint8_t iManufacturer;
119  uint8_t iProduct;
120  uint8_t iSerialNumber;
123 
124 
125 /**
126  * @brief Configuration descriptor
127  **/
128 
129 typedef __packed_struct
130 {
131  uint8_t bLength;
132  uint8_t bDescriptorType;
133  uint16_t wTotalLength;
134  uint8_t bNumInterfaces;
136  uint8_t iConfiguration;
137  uint8_t bmAttributes;
138  uint8_t bMaxPower;
140 
141 
142 /**
143  * @brief Interface descriptor
144  **/
145 
146 typedef __packed_struct
147 {
148  uint8_t bLength;
149  uint8_t bDescriptorType;
152  uint8_t bNumEndpoints;
156  uint8_t iInterface;
158 
159 
160 /**
161  * @brief Endpoint descriptor
162  **/
163 
164 typedef __packed_struct
165 {
166  uint8_t bLength;
167  uint8_t bDescriptorType;
169  uint8_t bmAttributes;
170  uint16_t wMaxPacketSize;
171  uint8_t bInterval;
173 
174 
175 /**
176  * @brief String descriptor
177  **/
178 
179 typedef __packed_struct
180 {
181  uint8_t bLength;
182  uint8_t bDescriptorType;
183  uint16_t bString[];
185 
186 
187 /**
188  * @brief CDC header functional descriptor
189  **/
190 
191 typedef __packed_struct
192 {
193  uint8_t bFunctionLength;
194  uint8_t bDescriptorType;
196  uint16_t bcdCdc;
198 
199 
200 /**
201  * @brief CDC call management functional descriptor
202  **/
203 
204 typedef __packed_struct
205 {
206  uint8_t bFunctionLength;
207  uint8_t bDescriptorType;
208  uint8_t bDescriptorSubtype;
209  uint8_t bmCapabilities;
210  uint8_t bDataInterface;
212 
213 
214 /**
215  * @brief CDC abstract control management functional descriptor
216  **/
217 
218 typedef __packed_struct
219 {
220  uint8_t bFunctionLength;
221  uint8_t bDescriptorType;
222  uint8_t bDescriptorSubtype;
223  uint8_t bmCapabilities;
225 
226 
227 /**
228  * @brief CDC union functional descriptor
229  **/
230 
231 typedef __packed_struct
232 {
233  uint8_t bFunctionLength;
234  uint8_t bDescriptorType;
235  uint8_t bDescriptorSubtype;
239 
240 
241 /**
242  * @brief Configuration descriptors
243  **/
244 
245 typedef __packed_struct
246 {
247  //Standard configuration descriptor
248  UsbConfigDescriptor configDescriptor;
249  //Communication class interface descriptor
251  //CDC header functional descriptor
253  //CDC call management functional descriptor
255  //CDC abstract control management functional descriptor
257  //CDC union functional descriptor
259  //Notification endpoint descriptor
261  //Data class interface descriptor
263  //Data OUT endpoint descriptor
265  //Data IN endpoint descriptor
268 
269 
270 //Global variables
271 extern USBD_DescriptorsTypeDef usbdRndisDescriptors;
274 
275 //USB related functions
276 uint8_t *usbdGetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
277 uint8_t *usbdGetLangIdStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
278 uint8_t *usbdGetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
279 uint8_t *usbdGetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
280 uint8_t *usbdGetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
281 uint8_t *usbdGetConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
282 uint8_t *usbdGetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
283 
284 #endif
RTOS abstraction layer.
uint8_t length
Definition: tcp.h:368
uint8_t * usbdGetLangIdStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the languages supported by the device.
Definition: usbd_desc.c:227
UsbInterfaceDescriptor communicationInterfaceDescriptor
Definition: usbd_desc.h:250
CdcCallManagementDescriptor cdcCallManagementDescriptor
Definition: usbd_desc.h:254
uint8_t bNumInterfaces
Definition: usbd_desc.h:134
CdcHeaderDescriptor cdcHeaderDescriptor
Definition: usbd_desc.h:252
uint8_t bDeviceSubClass
Definition: usbd_desc.h:112
UsbInterfaceDescriptor
Definition: usbd_desc.h:157
uint16_t idProduct
Definition: usbd_desc.h:116
uint8_t iInterface
Definition: usbd_desc.h:156
CdcAcmDescriptor
Definition: usbd_desc.h:224
uint16_t bcdCdc
Definition: usbd_desc.h:196
UsbEndpointDescriptor dataInEndpointDescriptor
Definition: usbd_desc.h:266
const UsbConfigDescriptors usbdConfigDescriptors
USB configuration descriptors.
Definition: usbd_desc.c:99
uint8_t bInterfaceSubClass
Definition: usbd_desc.h:154
uint8_t bInterfaceNumber
Definition: usbd_desc.h:150
uint8_t bDeviceProtocol
Definition: usbd_desc.h:113
uint8_t bMasterInterface
Definition: usbd_desc.h:236
uint16_t bcdDevice
Definition: usbd_desc.h:117
uint8_t bAlternateSetting
Definition: usbd_desc.h:151
UsbEndpointDescriptor dataOutEndpointDescriptor
Definition: usbd_desc.h:264
uint8_t bEndpointAddress
Definition: usbd_desc.h:168
USBD_DescriptorsTypeDef usbdRndisDescriptors
USB descriptors.
Definition: usbd_desc.c:61
uint8_t * usbdGetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the serial number string descriptor.
Definition: usbd_desc.c:285
uint8_t iConfiguration
Definition: usbd_desc.h:136
CdcCallManagementDescriptor
Definition: usbd_desc.h:211
CdcUnionDescriptor
Definition: usbd_desc.h:238
UsbConfigDescriptor
Definition: usbd_desc.h:139
uint8_t bDescriptorType
Definition: usbd_desc.h:109
uint8_t bInterfaceProtocol
Definition: usbd_desc.h:155
uint8_t bDataInterface
Definition: usbd_desc.h:210
uint8_t iProduct
Definition: usbd_desc.h:119
uint8_t iManufacturer
Definition: usbd_desc.h:118
UsbEndpointDescriptor notificationEndpointDescriptor
Definition: usbd_desc.h:260
uint16_t wTotalLength
Definition: usbd_desc.h:133
uint8_t bmCapabilities
Definition: usbd_desc.h:209
CdcAcmDescriptor cdcAcmDescriptor
Definition: usbd_desc.h:256
UsbInterfaceDescriptor dataInterfaceDescriptor
Definition: usbd_desc.h:262
uint8_t bMaxPacketSize0
Definition: usbd_desc.h:114
uint8_t bSlaveInterface0
Definition: usbd_desc.h:237
uint16_t bcdUsb
Definition: usbd_desc.h:110
UsbDeviceDescriptor
Definition: usbd_desc.h:122
uint8_t * usbdGetConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the configuration string descriptor.
Definition: usbd_desc.c:301
UsbEndpointDescriptor
Definition: usbd_desc.h:172
uint16_t idVendor
Definition: usbd_desc.h:115
const UsbDeviceDescriptor usbdDeviceDescriptor
USB device descriptor.
Definition: usbd_desc.c:76
uint8_t bDeviceClass
Definition: usbd_desc.h:111
uint8_t * usbdGetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the product string descriptor.
Definition: usbd_desc.c:269
uint16_t wMaxPacketSize
Definition: usbd_desc.h:170
uint8_t bNumConfigurations
Definition: usbd_desc.h:121
uint16_t bString[]
Definition: usbd_desc.h:183
typedef __packed_struct
Device descriptor.
Definition: usbd_desc.h:107
uint8_t bDescriptorSubtype
Definition: usbd_desc.h:195
uint8_t bNumEndpoints
Definition: usbd_desc.h:152
uint8_t * usbdGetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the manufacturer string descriptor.
Definition: usbd_desc.c:253
uint8_t * usbdGetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve device descriptor.
Definition: usbd_desc.c:211
UsbConfigDescriptors
Definition: usbd_desc.h:267
uint8_t bMaxPower
Definition: usbd_desc.h:138
CdcHeaderDescriptor
Definition: usbd_desc.h:197
uint8_t bmAttributes
Definition: usbd_desc.h:137
CdcUnionDescriptor cdcUnionDescriptor
Definition: usbd_desc.h:258
uint8_t bInterfaceClass
Definition: usbd_desc.h:153
uint8_t iSerialNumber
Definition: usbd_desc.h:120
uint8_t bConfigurationValue
Definition: usbd_desc.h:135
uint8_t * usbdGetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the interface string descriptor.
Definition: usbd_desc.c:317
UsbStringDescriptor
Definition: usbd_desc.h:184
uint8_t bInterval
Definition: usbd_desc.h:171