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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Pro.
10  *
11  * This software is provided under a commercial license. You may
12  * use this software under the conditions stated in the license
13  * terms. This source code cannot be redistributed.
14  *
15  * @author Oryx Embedded SARL (www.oryx-embedded.com)
16  * @version 1.9.0
17  **/
18 
19 #ifndef _USBD_DESC_H
20 #define _USBD_DESC_H
21 
22 //Dependencies
23 #include "os_port.h"
24 
25 //Endpoint identifiers
26 #define USB_EP0 0
27 #define USB_EP1 1
28 #define USB_EP2 2
29 #define USB_EP3 3
30 
31 //Data transfer direction
32 #define USB_DIR_MASK 0x80
33 #define USB_DIR_OUT 0x00
34 #define USB_DIR_IN 0x80
35 
36 //Endpoint maximum packet size
37 #define USB_EP0_MAX_PACKET_SIZE 64
38 #define USB_EP1_MAX_PACKET_SIZE 64
39 #define USB_EP2_MAX_PACKET_SIZE 64
40 #define USB_EP3_MAX_PACKET_SIZE 64
41 
42 //Descriptor types
43 #define USB_DESC_TYPE_DEVICE 1
44 #define USB_DESC_TYPE_CONFIGURATION 2
45 #define USB_DESC_TYPE_STRING 3
46 #define USB_DESC_TYPE_INTERFACE 4
47 #define USB_DESC_TYPE_ENDPOINT 5
48 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6
49 
50 //bmAttributes field
51 #define USB_SELF_POWERED 0xC0
52 #define USB_BUS_POWERED 0x80
53 #define USB_REMOTE_WAKEUP 0xA0
54 #define USB_NO_REMOTE_WAKEUP 0x80
55 
56 //Endpoint types
57 #define USB_EP_TYPE_MASK 0x03
58 #define USB_EP_TYPE_CONTROL 0x00
59 #define USB_EP_TYPE_ISOCHRONOUS 0x01
60 #define USB_EP_TYPE_BULK 0x02
61 #define USB_EP_TYPE_INTERRUPT 0x03
62 
63 //Device class
64 #define USB_DEVICE_CLASS_CDC 0x02
65 //Device subclass
66 #define USB_DEVICE_SUBCLASS_CDC 0x00
67 //Device protocol
68 #define USB_DEVICE_PROTOCOL_CDC 0x00
69 
70 //CDC communication interface class
71 #define CDC_INTERFACE_CLASS_COMMUNICATION 0x02
72 #define CDC_INTERFACE_CLASS_RNDIS 0xEF
73 //CDC communication interface subclass
74 #define CDC_INTERFACE_SUBCLASS_ACM 0x02
75 #define CDC_INTERFACE_SUBCLASS_RNDIS 0x04
76 //CDC communication interface protocol
77 #define CDC_INTERFACE_PROTOCOL_RNDIS 0x01
78 #define CDC_INTERFACE_PROTOCOL_VENDOR_SPECIFIC 0xFF
79 
80 //CDC data interface class
81 #define CDC_INTERFACE_CLASS_DATA 0x0A
82 //CDC data interface subclass
83 #define CDC_INTERFACE_SUBCLASS_DATA 0x00
84 //CDC data interface protocol
85 #define CDC_INTERFACE_PROTOCOL_DATA 0x00
86 
87 //CDC descriptor types
88 #define CDC_CS_INTERFACE 0x24
89 #define CDC_CS_ENDPOINT 0x25
90 
91 //CDC descriptor subtypes
92 #define CDC_HEADER_DESC_SUBTYPE 0x00
93 #define CDC_CALL_MANAGEMENT_DESC_SUBTYPE 0x01
94 #define CDC_ACM_DESC_SUBTYPE 0x02
95 #define CDC_UNION_DESC_SUBTYPE 0x06
96 
97 
98 /**
99  * @brief Device descriptor
100  **/
101 
102 typedef __start_packed struct
103 {
104  uint8_t bLength;
106  uint16_t bcdUsb;
107  uint8_t bDeviceClass;
111  uint16_t idVendor;
112  uint16_t idProduct;
113  uint16_t bcdDevice;
114  uint8_t iManufacturer;
115  uint8_t iProduct;
116  uint8_t iSerialNumber;
119 
120 
121 /**
122  * @brief Configuration descriptor
123  **/
124 
125 typedef __start_packed struct
126 {
127  uint8_t bLength;
128  uint8_t bDescriptorType;
129  uint16_t wTotalLength;
130  uint8_t bNumInterfaces;
132  uint8_t iConfiguration;
133  uint8_t bmAttributes;
134  uint8_t bMaxPower;
136 
137 
138 /**
139  * @brief Interface descriptor
140  **/
141 
142 typedef __start_packed struct
143 {
144  uint8_t bLength;
145  uint8_t bDescriptorType;
148  uint8_t bNumEndpoints;
152  uint8_t iInterface;
154 
155 
156 /**
157  * @brief Endpoint descriptor
158  **/
159 
160 typedef __start_packed struct
161 {
162  uint8_t bLength;
163  uint8_t bDescriptorType;
165  uint8_t bmAttributes;
166  uint16_t wMaxPacketSize;
167  uint8_t bInterval;
169 
170 
171 /**
172  * @brief String descriptor
173  **/
174 
175 typedef __start_packed struct
176 {
177  uint8_t bLength;
178  uint8_t bDescriptorType;
179  uint16_t bString[];
181 
182 
183 /**
184  * @brief CDC header functional descriptor
185  **/
186 
187 typedef __start_packed struct
188 {
190  uint8_t bDescriptorType;
192  uint16_t bcdCdc;
194 
195 
196 /**
197  * @brief CDC call management functional descriptor
198  **/
199 
200 typedef __start_packed struct
201 {
202  uint8_t bFunctionLength;
203  uint8_t bDescriptorType;
204  uint8_t bDescriptorSubtype;
205  uint8_t bmCapabilities;
206  uint8_t bDataInterface;
208 
209 
210 /**
211  * @brief CDC abstract control management functional descriptor
212  **/
213 
214 typedef __start_packed struct
215 {
216  uint8_t bFunctionLength;
217  uint8_t bDescriptorType;
218  uint8_t bDescriptorSubtype;
219  uint8_t bmCapabilities;
221 
222 
223 /**
224  * @brief CDC union functional descriptor
225  **/
226 
227 typedef __start_packed struct
228 {
229  uint8_t bFunctionLength;
230  uint8_t bDescriptorType;
231  uint8_t bDescriptorSubtype;
235 
236 
237 /**
238  * @brief Configuration descriptors
239  **/
240 
241 typedef __start_packed struct
242 {
243  //Standard configuration descriptor
245  //Communication class interface descriptor
247  //CDC header functional descriptor
249  //CDC call management functional descriptor
251  //CDC abstract control management functional descriptor
253  //CDC union functional descriptor
255  //Notification endpoint descriptor
257  //Data class interface descriptor
259  //Data OUT endpoint descriptor
261  //Data IN endpoint descriptor
264 
265 
266 //Global variables
267 extern USBD_DescriptorsTypeDef usbdRndisDescriptors;
270 
271 //USB related functions
272 uint8_t *usbdGetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
273 uint8_t *usbdGetLangIdStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
274 uint8_t *usbdGetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
275 uint8_t *usbdGetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
276 uint8_t *usbdGetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
277 uint8_t *usbdGetConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
278 uint8_t *usbdGetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
279 
280 #endif
__start_packed struct @164 CdcUnionDescriptor
CDC union functional descriptor.
__start_packed struct @163 CdcAcmDescriptor
CDC abstract control management functional descriptor.
uint8_t bDataInterface
Definition: usbd_desc.h:206
uint16_t bString[]
Definition: usbd_desc.h:179
__start_packed struct @157 UsbConfigDescriptor
Configuration descriptor.
__start_packed struct @160 UsbStringDescriptor
String descriptor.
const UsbDeviceDescriptor usbdDeviceDescriptor
USB device descriptor.
Definition: usbd_desc.c:64
uint8_t bSlaveInterface0
Definition: usbd_desc.h:233
UsbEndpointDescriptor dataOutEndpointDescriptor
Definition: usbd_desc.h:260
UsbInterfaceDescriptor dataInterfaceDescriptor
Definition: usbd_desc.h:258
uint16_t bcdUsb
Definition: usbd_desc.h:106
uint8_t bmCapabilities
Definition: usbd_desc.h:205
__start_packed struct @159 UsbEndpointDescriptor
Endpoint descriptor.
uint8_t bMaxPacketSize0
Definition: usbd_desc.h:110
const UsbConfigDescriptors usbdConfigDescriptors
USB configuration descriptors.
Definition: usbd_desc.c:87
uint8_t bLength
Definition: usbd_desc.h:104
uint8_t bInterfaceNumber
Definition: usbd_desc.h:146
uint8_t bInterfaceClass
Definition: usbd_desc.h:149
uint8_t bMaxPower
Definition: usbd_desc.h:134
UsbEndpointDescriptor dataInEndpointDescriptor
Definition: usbd_desc.h:262
uint8_t bDeviceProtocol
Definition: usbd_desc.h:109
uint8_t bInterfaceSubClass
Definition: usbd_desc.h:150
uint8_t bNumInterfaces
Definition: usbd_desc.h:130
uint8_t bDeviceClass
Definition: usbd_desc.h:107
uint8_t * usbdGetLangIdStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the languages supported by the device.
Definition: usbd_desc.c:215
uint8_t bNumEndpoints
Definition: usbd_desc.h:148
uint8_t * usbdGetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the interface string descriptor.
Definition: usbd_desc.c:305
CdcCallManagementDescriptor cdcCallManagementDescriptor
Definition: usbd_desc.h:250
__start_packed struct @162 CdcCallManagementDescriptor
CDC call management functional descriptor.
uint8_t bFunctionLength
Definition: usbd_desc.h:189
__start_packed struct @165 UsbConfigDescriptors
Configuration descriptors.
RTOS abstraction layer.
uint8_t iInterface
Definition: usbd_desc.h:152
uint16_t idVendor
Definition: usbd_desc.h:111
uint8_t bmAttributes
Definition: usbd_desc.h:133
uint8_t iManufacturer
Definition: usbd_desc.h:114
__start_packed struct @156 UsbDeviceDescriptor
Device descriptor.
uint16_t wTotalLength
Definition: usbd_desc.h:129
uint8_t bMasterInterface
Definition: usbd_desc.h:232
uint16_t idProduct
Definition: usbd_desc.h:112
USBD_DescriptorsTypeDef usbdRndisDescriptors
USB descriptors.
Definition: usbd_desc.c:49
uint8_t bNumConfigurations
Definition: usbd_desc.h:117
UsbConfigDescriptor configDescriptor
Definition: usbd_desc.h:244
__start_packed struct _Ipv4Header __end_packed
__start_packed struct @161 CdcHeaderDescriptor
CDC header functional descriptor.
uint8_t bDescriptorType
Definition: usbd_desc.h:105
uint8_t bAlternateSetting
Definition: usbd_desc.h:147
uint8_t bInterfaceProtocol
Definition: usbd_desc.h:151
CdcAcmDescriptor cdcAcmDescriptor
Definition: usbd_desc.h:252
uint8_t bDeviceSubClass
Definition: usbd_desc.h:108
uint8_t iSerialNumber
Definition: usbd_desc.h:116
uint8_t bEndpointAddress
Definition: usbd_desc.h:164
uint8_t * usbdGetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the product string descriptor.
Definition: usbd_desc.c:257
CdcHeaderDescriptor cdcHeaderDescriptor
Definition: usbd_desc.h:248
__start_packed struct @158 UsbInterfaceDescriptor
Interface descriptor.
CdcUnionDescriptor cdcUnionDescriptor
Definition: usbd_desc.h:254
uint8_t bInterval
Definition: usbd_desc.h:167
uint8_t bDescriptorSubtype
Definition: usbd_desc.h:191
UsbInterfaceDescriptor communicationInterfaceDescriptor
Definition: usbd_desc.h:246
uint8_t iConfiguration
Definition: usbd_desc.h:132
uint16_t wMaxPacketSize
Definition: usbd_desc.h:166
UsbEndpointDescriptor notificationEndpointDescriptor
Definition: usbd_desc.h:256
uint8_t * usbdGetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the manufacturer string descriptor.
Definition: usbd_desc.c:241
uint16_t bcdCdc
Definition: usbd_desc.h:192
uint8_t length
Definition: dtls_misc.h:140
uint8_t * usbdGetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve device descriptor.
Definition: usbd_desc.c:199
uint8_t * usbdGetConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the configuration string descriptor.
Definition: usbd_desc.c:289
uint16_t bcdDevice
Definition: usbd_desc.h:113
uint8_t iProduct
Definition: usbd_desc.h:115
uint8_t bConfigurationValue
Definition: usbd_desc.h:131
uint8_t * usbdGetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
Retrieve the serial number string descriptor.
Definition: usbd_desc.c:273