1 /* 2 * Copyright (c) 2022, sakumisu 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 #ifndef USB_CDC_H 7 #define USB_CDC_H 8 9 /*------------------------------------------------------------------------------ 10 * Definitions based on usbcdc11.pdf (www.usb.org) 11 *----------------------------------------------------------------------------*/ 12 /* Communication device class specification version 1.10 */ 13 #define CDC_V1_10 0x0110U 14 // Communication device class specification version 1.2 15 #define CDC_V1_2_0 0x0120U 16 17 /* Communication interface class code */ 18 /* (usbcdc11.pdf, 4.2, Table 15) */ 19 #define CDC_COMMUNICATION_INTERFACE_CLASS 0x02U 20 21 /* Communication interface class subclass codes */ 22 /* (usbcdc11.pdf, 4.3, Table 16) */ 23 #define CDC_SUBCLASS_NONE 0x00 /* Reserved */ 24 #define CDC_SUBCLASS_DLC 0x01 /* Direct Line Control Model */ 25 #define CDC_SUBCLASS_ACM 0x02 /* Abstract Control Model */ 26 #define CDC_SUBCLASS_TCM 0x03 /* Telephone Control Model */ 27 #define CDC_SUBCLASS_MCM 0x04 /* Multi-Channel Control Model */ 28 #define CDC_SUBCLASS_CAPI 0x05 /* CAPI Control Model */ 29 #define CDC_SUBCLASS_ECM 0x06 /* Ethernet Networking Control Model */ 30 #define CDC_SUBCLASS_ATM 0x07 /* ATM Networking Control Model */ 31 /* 0x08-0x0d Reserved (future use) */ 32 #define CDC_SUBCLASS_MBIM 0x0e /* MBIM Control Model */ 33 /* 0x0f-0x7f Reserved (future use) */ 34 /* 0x80-0xfe Reserved (vendor specific) */ 35 36 #define CDC_DIRECT_LINE_CONTROL_MODEL 0x01U 37 #define CDC_ABSTRACT_CONTROL_MODEL 0x02U 38 #define CDC_TELEPHONE_CONTROL_MODEL 0x03U 39 #define CDC_MULTI_CHANNEL_CONTROL_MODEL 0x04U 40 #define CDC_CAPI_CONTROL_MODEL 0x05U 41 #define CDC_ETHERNET_NETWORKING_CONTROL_MODEL 0x06U 42 #define CDC_ATM_NETWORKING_CONTROL_MODEL 0x07U 43 #define CDC_WIRELESS_HANDSET_CONTROL_MODEL 0x08U 44 #define CDC_DEVICE_MANAGEMENT 0x09U 45 #define CDC_MOBILE_DIRECT_LINE_MODEL 0x0AU 46 #define CDC_OBEX 0x0BU 47 #define CDC_ETHERNET_EMULATION_MODEL 0x0CU 48 #define CDC_NETWORK_CONTROL_MODEL 0x0DU 49 50 /* Communication interface class control protocol codes */ 51 /* (usbcdc11.pdf, 4.4, Table 17) */ 52 #define CDC_COMMON_PROTOCOL_NONE 0x00U 53 #define CDC_COMMON_PROTOCOL_AT_COMMANDS 0x01U 54 #define CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101 0x02U 55 #define CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101_AND_ANNEXO 0x03U 56 #define CDC_COMMON_PROTOCOL_AT_COMMANDS_GSM_707 0x04U 57 #define CDC_COMMON_PROTOCOL_AT_COMMANDS_3GPP_27007 0x05U 58 #define CDC_COMMON_PROTOCOL_AT_COMMANDS_CDMA 0x06U 59 #define CDC_COMMON_PROTOCOL_ETHERNET_EMULATION_MODEL 0x07U 60 // NCM Communication Interface Protocol Codes 61 // (usbncm10.pdf, 4.2, Table 4-2) 62 #define CDC_NCM_PROTOCOL_NONE 0x00U 63 #define CDC_NCM_PROTOCOL_OEM 0xFEU 64 65 /* Data interface class code */ 66 /* (usbcdc11.pdf, 4.5, Table 18) */ 67 #define CDC_DATA_INTERFACE_CLASS 0x0A 68 69 /* Data Interface Sub-Class Codes ********************************************/ 70 #define CDC_DATA_SUBCLASS_NONE 0x00 71 72 /* Data interface class protocol codes */ 73 /* (usbcdc11.pdf, 4.7, Table 19) */ 74 #define CDC_DATA_PROTOCOL_ISDN_BRI 0x30 75 #define CDC_DATA_PROTOCOL_HDLC 0x31 76 #define CDC_DATA_PROTOCOL_TRANSPARENT 0x32 77 #define CDC_DATA_PROTOCOL_Q921_MANAGEMENT 0x50 78 #define CDC_DATA_PROTOCOL_Q921_DATA_LINK 0x51 79 #define CDC_DATA_PROTOCOL_Q921_MULTIPLEXOR 0x52 80 #define CDC_DATA_PROTOCOL_V42 0x90 81 #define CDC_DATA_PROTOCOL_EURO_ISDN 0x91 82 #define CDC_DATA_PROTOCOL_V24_RATE_ADAPTATION 0x92 83 #define CDC_DATA_PROTOCOL_CAPI 0x93 84 #define CDC_DATA_PROTOCOL_HOST_BASED_DRIVER 0xFD 85 #define CDC_DATA_PROTOCOL_DESCRIBED_IN_PUFD 0xFE 86 87 /* Type values for bDescriptorType field of functional descriptors */ 88 /* (usbcdc11.pdf, 5.2.3, Table 24) */ 89 #define CDC_CS_INTERFACE 0x24 90 #define CDC_CS_ENDPOINT 0x25 91 92 /* Type values for bDescriptorSubtype field of functional descriptors */ 93 /* (usbcdc11.pdf, 5.2.3, Table 25) */ 94 #define CDC_FUNC_DESC_HEADER 0x00 95 #define CDC_FUNC_DESC_CALL_MANAGEMENT 0x01 96 #define CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT 0x02 97 #define CDC_FUNC_DESC_DIRECT_LINE_MANAGEMENT 0x03 98 #define CDC_FUNC_DESC_TELEPHONE_RINGER 0x04 99 #define CDC_FUNC_DESC_REPORTING_CAPABILITIES 0x05 100 #define CDC_FUNC_DESC_UNION 0x06 101 #define CDC_FUNC_DESC_COUNTRY_SELECTION 0x07 102 #define CDC_FUNC_DESC_TELEPHONE_OPERATIONAL_MODES 0x08 103 #define CDC_FUNC_DESC_USB_TERMINAL 0x09 104 #define CDC_FUNC_DESC_NETWORK_CHANNEL 0x0A 105 #define CDC_FUNC_DESC_PROTOCOL_UNIT 0x0B 106 #define CDC_FUNC_DESC_EXTENSION_UNIT 0x0C 107 #define CDC_FUNC_DESC_MULTI_CHANNEL_MANAGEMENT 0x0D 108 #define CDC_FUNC_DESC_CAPI_CONTROL_MANAGEMENT 0x0E 109 #define CDC_FUNC_DESC_ETHERNET_NETWORKING 0x0F 110 #define CDC_FUNC_DESC_ATM_NETWORKING 0x10 111 #define CDC_FUNC_DESC_WIRELESS_HANDSET_CONTROL_MODEL 0x11 112 #define CDC_FUNC_DESC_MOBILE_DIRECT_LINE_MODEL 0x12 113 #define CDC_FUNC_DESC_MOBILE_DIRECT_LINE_MODEL_DETAIL 0x13 114 #define CDC_FUNC_DESC_DEVICE_MANAGEMENT_MODEL 0x14 115 #define CDC_FUNC_DESC_OBEX 0x15 116 #define CDC_FUNC_DESC_COMMAND_SET 0x16 117 #define CDC_FUNC_DESC_COMMAND_SET_DETAIL 0x17 118 #define CDC_FUNC_DESC_TELEPHONE_CONTROL_MODEL 0x18 119 #define CDC_FUNC_DESC_OBEX_SERVICE_IDENTIFIER 0x19 120 121 /* CDC class-specific request codes */ 122 /* (usbcdc11.pdf, 6.2, Table 46) */ 123 /* see Table 45 for info about the specific requests. */ 124 #define CDC_REQUEST_SEND_ENCAPSULATED_COMMAND 0x00 125 #define CDC_REQUEST_GET_ENCAPSULATED_RESPONSE 0x01 126 #define CDC_REQUEST_SET_COMM_FEATURE 0x02 127 #define CDC_REQUEST_GET_COMM_FEATURE 0x03 128 #define CDC_REQUEST_CLEAR_COMM_FEATURE 0x04 129 #define CDC_REQUEST_SET_AUX_LINE_STATE 0x10 130 #define CDC_REQUEST_SET_HOOK_STATE 0x11 131 #define CDC_REQUEST_PULSE_SETUP 0x12 132 #define CDC_REQUEST_SEND_PULSE 0x13 133 #define CDC_REQUEST_SET_PULSE_TIME 0x14 134 #define CDC_REQUEST_RING_AUX_JACK 0x15 135 #define CDC_REQUEST_SET_LINE_CODING 0x20 136 #define CDC_REQUEST_GET_LINE_CODING 0x21 137 #define CDC_REQUEST_SET_CONTROL_LINE_STATE 0x22 138 #define CDC_REQUEST_SEND_BREAK 0x23 139 #define CDC_REQUEST_SET_RINGER_PARMS 0x30 140 #define CDC_REQUEST_GET_RINGER_PARMS 0x31 141 #define CDC_REQUEST_SET_OPERATION_PARMS 0x32 142 #define CDC_REQUEST_GET_OPERATION_PARMS 0x33 143 #define CDC_REQUEST_SET_LINE_PARMS 0x34 144 #define CDC_REQUEST_GET_LINE_PARMS 0x35 145 #define CDC_REQUEST_DIAL_DIGITS 0x36 146 #define CDC_REQUEST_SET_UNIT_PARAMETER 0x37 147 #define CDC_REQUEST_GET_UNIT_PARAMETER 0x38 148 #define CDC_REQUEST_CLEAR_UNIT_PARAMETER 0x39 149 #define CDC_REQUEST_GET_PROFILE 0x3A 150 #define CDC_REQUEST_SET_ETHERNET_MULTICAST_FILTERS 0x40 151 #define CDC_REQUEST_SET_ETHERNET_PMP_FILTER 0x41 152 #define CDC_REQUEST_GET_ETHERNET_PMP_FILTER 0x42 153 #define CDC_REQUEST_SET_ETHERNET_PACKET_FILTER 0x43 154 #define CDC_REQUEST_GET_ETHERNET_STATISTIC 0x44 155 #define CDC_REQUEST_SET_ATM_DATA_FORMAT 0x50 156 #define CDC_REQUEST_GET_ATM_DEVICE_STATISTICS 0x51 157 #define CDC_REQUEST_SET_ATM_DEFAULT_VC 0x52 158 #define CDC_REQUEST_GET_ATM_VC_STATISTICS 0x53 159 160 /* Communication feature selector codes */ 161 /* (usbcdc11.pdf, 6.2.2..6.2.4, Table 47) */ 162 #define CDC_ABSTRACT_STATE 0x01 163 #define CDC_COUNTRY_SETTING 0x02 164 165 /** Control Signal Bitmap Values for SetControlLineState */ 166 #define SET_CONTROL_LINE_STATE_RTS 0x02 167 #define SET_CONTROL_LINE_STATE_DTR 0x01 168 169 /* Feature Status returned for ABSTRACT_STATE Selector */ 170 /* (usbcdc11.pdf, 6.2.3, Table 48) */ 171 #define CDC_IDLE_SETTING (1 << 0) 172 #define CDC_DATA_MULTPLEXED_STATE (1 << 1) 173 174 /* Control signal bitmap values for the SetControlLineState request */ 175 /* (usbcdc11.pdf, 6.2.14, Table 51) */ 176 #define CDC_DTE_PRESENT (1 << 0) 177 #define CDC_ACTIVATE_CARRIER (1 << 1) 178 179 /* CDC class-specific notification codes */ 180 /* (usbcdc11.pdf, 6.3, Table 68) */ 181 /* see Table 67 for Info about class-specific notifications */ 182 #define CDC_NOTIFICATION_NETWORK_CONNECTION 0x00 183 #define CDC_RESPONSE_AVAILABLE 0x01 184 #define CDC_AUX_JACK_HOOK_STATE 0x08 185 #define CDC_RING_DETECT 0x09 186 #define CDC_NOTIFICATION_SERIAL_STATE 0x20 187 #define CDC_CALL_STATE_CHANGE 0x28 188 #define CDC_LINE_STATE_CHANGE 0x29 189 #define CDC_CONNECTION_SPEED_CHANGE 0x2A 190 191 /* UART state bitmap values (Serial state notification). */ 192 /* (usbcdc11.pdf, 6.3.5, Table 69) */ 193 #define CDC_SERIAL_STATE_OVERRUN (1 << 6) /* receive data overrun error has occurred */ 194 #define CDC_SERIAL_STATE_OVERRUN_Pos (6) 195 #define CDC_SERIAL_STATE_OVERRUN_Msk (1 << CDC_SERIAL_STATE_OVERRUN_Pos) 196 #define CDC_SERIAL_STATE_PARITY (1 << 5) /* parity error has occurred */ 197 #define CDC_SERIAL_STATE_PARITY_Pos (5) 198 #define CDC_SERIAL_STATE_PARITY_Msk (1 << CDC_SERIAL_STATE_PARITY_Pos) 199 #define CDC_SERIAL_STATE_FRAMING (1 << 4) /* framing error has occurred */ 200 #define CDC_SERIAL_STATE_FRAMING_Pos (4) 201 #define CDC_SERIAL_STATE_FRAMING_Msk (1 << CDC_SERIAL_STATE_FRAMING_Pos) 202 #define CDC_SERIAL_STATE_RING (1 << 3) /* state of ring signal detection */ 203 #define CDC_SERIAL_STATE_RING_Pos (3) 204 #define CDC_SERIAL_STATE_RING_Msk (1 << CDC_SERIAL_STATE_RING_Pos) 205 #define CDC_SERIAL_STATE_BREAK (1 << 2) /* state of break detection */ 206 #define CDC_SERIAL_STATE_BREAK_Pos (2) 207 #define CDC_SERIAL_STATE_BREAK_Msk (1 << CDC_SERIAL_STATE_BREAK_Pos) 208 #define CDC_SERIAL_STATE_TX_CARRIER (1 << 1) /* state of transmission carrier */ 209 #define CDC_SERIAL_STATE_TX_CARRIER_Pos (1) 210 #define CDC_SERIAL_STATE_TX_CARRIER_Msk (1 << CDC_SERIAL_STATE_TX_CARRIER_Pos) 211 #define CDC_SERIAL_STATE_RX_CARRIER (1 << 0) /* state of receiver carrier */ 212 #define CDC_SERIAL_STATE_RX_CARRIER_Pos (0) 213 #define CDC_SERIAL_STATE_RX_CARRIER_Msk (1 << CDC_SERIAL_STATE_RX_CARRIER_Pos) 214 215 #define CDC_ECM_XMIT_OK (1 << 0) 216 #define CDC_ECM_RVC_OK (1 << 1) 217 #define CDC_ECM_XMIT_ERROR (1 << 2) 218 #define CDC_ECM_RCV_ERROR (1 << 3) 219 #define CDC_ECM_RCV_NO_BUFFER (1 << 4) 220 #define CDC_ECM_DIRECTED_BYTES_XMIT (1 << 5) 221 #define CDC_ECM_DIRECTED_FRAMES_XMIT (1 << 6) 222 #define CDC_ECM_MULTICAST_BYTES_XMIT (1 << 7) 223 #define CDC_ECM_MULTICAST_FRAMES_XMIT (1 << 8) 224 #define CDC_ECM_BROADCAST_BYTES_XMIT (1 << 9) 225 #define CDC_ECM_BROADCAST_FRAMES_XMIT (1 << 10) 226 #define CDC_ECM_DIRECTED_BYTES_RCV (1 << 11) 227 #define CDC_ECM_DIRECTED_FRAMES_RCV (1 << 12) 228 #define CDC_ECM_MULTICAST_BYTES_RCV (1 << 13) 229 #define CDC_ECM_MULTICAST_FRAMES_RCV (1 << 14) 230 #define CDC_ECM_BROADCAST_BYTES_RCV (1 << 15) 231 #define CDC_ECM_BROADCAST_FRAMES_RCV (1 << 16) 232 #define CDC_ECM_RCV_CRC_ERROR (1 << 17) 233 #define CDC_ECM_TRANSMIT_QUEUE_LENGTH (1 << 18) 234 #define CDC_ECM_RCV_ERROR_ALIGNMENT (1 << 19) 235 #define CDC_ECM_XMIT_ONE_COLLISION (1 << 20) 236 #define CDC_ECM_XMIT_MORE_COLLISIONS (1 << 21) 237 #define CDC_ECM_XMIT_DEFERRED (1 << 22) 238 #define CDC_ECM_XMIT_MAX_COLLISIONS (1 << 23) 239 #define CDC_ECM_RCV_OVERRUN (1 << 24) 240 #define CDC_ECM_XMIT_UNDERRUN (1 << 25) 241 #define CDC_ECM_XMIT_HEARTBEAT_FAILURE (1 << 26) 242 #define CDC_ECM_XMIT_TIMES_CRS_LOST (1 << 27) 243 #define CDC_ECM_XMIT_LATE_COLLISIONS (1 << 28) 244 245 #define CDC_ECM_MAC_STR_DESC (uint8_t *)"010202030000" 246 #define CDC_ECM_MAC_ADDR0 0x00U /* 01 */ 247 #define CDC_ECM_MAC_ADDR1 0x02U /* 02 */ 248 #define CDC_ECM_MAC_ADDR2 0x02U /* 03 */ 249 #define CDC_ECM_MAC_ADDR3 0x03U /* 00 */ 250 #define CDC_ECM_MAC_ADDR4 0x00U /* 00 */ 251 #define CDC_ECM_MAC_ADDR5 0x00U /* 00 */ 252 253 #define CDC_ECM_NET_DISCONNECTED 0x00U 254 #define CDC_ECM_NET_CONNECTED 0x01U 255 256 #define CDC_ECM_ETH_STATS_RESERVED 0xE0U 257 #define CDC_ECM_BMREQUEST_TYPE_ECM 0xA1U 258 259 #define CDC_ECM_CONNECT_SPEED_UPSTREAM 0x004C4B40U /* 5Mbps */ 260 #define CDC_ECM_CONNECT_SPEED_DOWNSTREAM 0x004C4B40U /* 5Mbps */ 261 262 #define CDC_ECM_NOTIFY_CODE_NETWORK_CONNECTION 0x00 263 #define CDC_ECM_NOTIFY_CODE_RESPONSE_AVAILABLE 0x01 264 #define CDC_ECM_NOTIFY_CODE_CONNECTION_SPEED_CHANGE 0x2A 265 266 /*------------------------------------------------------------------------------ 267 * Structures based on usbcdc11.pdf (www.usb.org) 268 *----------------------------------------------------------------------------*/ 269 270 /* Header functional descriptor */ 271 /* (usbcdc11.pdf, 5.2.3.1) */ 272 /* This header must precede any list of class-specific descriptors. */ 273 struct cdc_header_descriptor { 274 uint8_t bFunctionLength; /* size of this descriptor in bytes */ 275 uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */ 276 uint8_t bDescriptorSubtype; /* Header functional descriptor subtype */ 277 uint16_t bcdCDC; /* USB CDC specification release version */ 278 } __PACKED; 279 280 /* Call management functional descriptor */ 281 /* (usbcdc11.pdf, 5.2.3.2) */ 282 /* Describes the processing of calls for the communication class interface. */ 283 struct cdc_call_management_descriptor { 284 uint8_t bFunctionLength; /* size of this descriptor in bytes */ 285 uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */ 286 uint8_t bDescriptorSubtype; /* call management functional descriptor subtype */ 287 uint8_t bmCapabilities; /* capabilities that this configuration supports */ 288 uint8_t bDataInterface; /* interface number of the data class interface used for call management (optional) */ 289 } __PACKED; 290 291 /* Abstract control management functional descriptor */ 292 /* (usbcdc11.pdf, 5.2.3.3) */ 293 /* Describes the command supported by the communication interface class with the Abstract Control Model subclass code. */ 294 struct cdc_abstract_control_management_descriptor { 295 uint8_t bFunctionLength; /* size of this descriptor in bytes */ 296 uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */ 297 uint8_t bDescriptorSubtype; /* abstract control management functional descriptor subtype */ 298 uint8_t bmCapabilities; /* capabilities supported by this configuration */ 299 } __PACKED; 300 301 /* Union functional descriptors */ 302 /* (usbcdc11.pdf, 5.2.3.8) */ 303 /* Describes the relationship between a group of interfaces that can be considered to form a functional unit. */ 304 struct cdc_union_descriptor { 305 uint8_t bFunctionLength; /* size of this descriptor in bytes */ 306 uint8_t bDescriptorType; /* CS_INTERFACE descriptor type */ 307 uint8_t bDescriptorSubtype; /* union functional descriptor subtype */ 308 uint8_t bMasterInterface; /* interface number designated as master */ 309 } __PACKED; 310 311 /* Union functional descriptors with one slave interface */ 312 /* (usbcdc11.pdf, 5.2.3.8) */ 313 struct cdc_union_1slave_descriptor { 314 uint8_t bFunctionLength; 315 uint8_t bDescriptorType; 316 uint8_t bDescriptorSubtype; 317 uint8_t bControlInterface; 318 uint8_t bSubordinateInterface0; 319 } __PACKED; 320 321 /* Line coding structure for GET_LINE_CODING / SET_LINE_CODING class requests*/ 322 /* Format of the data returned when a GetLineCoding request is received */ 323 /* (usbcdc11.pdf, 6.2.13) */ 324 struct cdc_line_coding { 325 uint32_t dwDTERate; /* Data terminal rate in bits per second */ 326 uint8_t bCharFormat; /* Number of stop bits */ 327 uint8_t bParityType; /* Parity bit type */ 328 uint8_t bDataBits; /* Number of data bits */ 329 } __PACKED; 330 331 /** Data structure for the notification about SerialState */ 332 struct cdc_acm_notification { 333 uint8_t bmRequestType; 334 uint8_t bNotificationType; 335 uint16_t wValue; 336 uint16_t wIndex; 337 uint16_t wLength; 338 uint16_t data; 339 } __PACKED; 340 341 /** Ethernet Networking Functional Descriptor */ 342 struct cdc_ecm_descriptor { 343 uint8_t bFunctionLength; 344 uint8_t bDescriptorType; 345 uint8_t bDescriptorSubtype; 346 uint8_t iMACAddress; 347 uint32_t bmEthernetStatistics; 348 uint16_t wMaxSegmentSize; 349 uint16_t wNumberMCFilters; 350 uint8_t bNumberPowerFilters; 351 } __PACKED; 352 353 struct cdc_ecm_notification { 354 uint8_t bmRequestType; 355 uint8_t bNotificationType; 356 uint16_t wValue; 357 uint16_t wIndex; 358 uint16_t wLength; 359 uint8_t data[8]; 360 } __PACKED; 361 362 /*Length of template descriptor: 66 bytes*/ 363 #define CDC_ACM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 4 + 5 + 7 + 9 + 7 + 7) 364 // clang-format off 365 #define CDC_ACM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, wMaxPacketSize, str_idx) \ 366 /* Interface Associate */ \ 367 0x08, /* bLength */ \ 368 USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \ 369 bFirstInterface, /* bFirstInterface */ \ 370 0x02, /* bInterfaceCount */ \ 371 USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \ 372 CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \ 373 CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \ 374 0x00, /* iFunction */ \ 375 0x09, /* bLength */ \ 376 USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ 377 bFirstInterface, /* bInterfaceNumber */ \ 378 0x00, /* bAlternateSetting */ \ 379 0x01, /* bNumEndpoints */ \ 380 USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \ 381 CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \ 382 CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \ 383 str_idx, /* iInterface */ \ 384 0x05, /* bLength */ \ 385 CDC_CS_INTERFACE, /* bDescriptorType */ \ 386 CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \ 387 WBVAL(CDC_V1_10), /* bcdCDC */ \ 388 0x05, /* bLength */ \ 389 CDC_CS_INTERFACE, /* bDescriptorType */ \ 390 CDC_FUNC_DESC_CALL_MANAGEMENT, /* bDescriptorSubtype */ \ 391 0x00, /* bmCapabilities */ \ 392 (uint8_t)(bFirstInterface + 1), /* bDataInterface */ \ 393 0x04, /* bLength */ \ 394 CDC_CS_INTERFACE, /* bDescriptorType */ \ 395 CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \ 396 0x02, /* bmCapabilities */ \ 397 0x05, /* bLength */ \ 398 CDC_CS_INTERFACE, /* bDescriptorType */ \ 399 CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \ 400 bFirstInterface, /* bMasterInterface */ \ 401 (uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ \ 402 0x07, /* bLength */ \ 403 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 404 int_ep, /* bEndpointAddress */ \ 405 0x03, /* bmAttributes */ \ 406 0x08, 0x00, /* wMaxPacketSize */ \ 407 0x0a, /* bInterval */ \ 408 0x09, /* bLength */ \ 409 USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ 410 (uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \ 411 0x00, /* bAlternateSetting */ \ 412 0x02, /* bNumEndpoints */ \ 413 CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \ 414 0x00, /* bInterfaceSubClass */ \ 415 0x00, /* bInterfaceProtocol */ \ 416 0x00, /* iInterface */ \ 417 0x07, /* bLength */ \ 418 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 419 out_ep, /* bEndpointAddress */ \ 420 0x02, /* bmAttributes */ \ 421 WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \ 422 0x00, /* bInterval */ \ 423 0x07, /* bLength */ \ 424 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 425 in_ep, /* bEndpointAddress */ \ 426 0x02, /* bmAttributes */ \ 427 WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \ 428 0x00 /* bInterval */ 429 // clang-format on 430 431 /*Length of template descriptor: 66 bytes*/ 432 #define CDC_RNDIS_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 4 + 5 + 7 + 9 + 7 + 7) 433 // clang-format off 434 #define CDC_RNDIS_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, wMaxPacketSize, str_idx) \ 435 /* Interface Associate */ \ 436 0x08, /* bLength */ \ 437 USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \ 438 bFirstInterface, /* bFirstInterface */ \ 439 0x02, /* bInterfaceCount */ \ 440 USB_DEVICE_CLASS_WIRELESS, /* bFunctionClass */ \ 441 CDC_DIRECT_LINE_CONTROL_MODEL, /* bFunctionSubClass */ \ 442 CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101_AND_ANNEXO, /* bFunctionProtocol */ \ 443 0x00, /* iFunction */ \ 444 0x09, /* bLength */ \ 445 USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ 446 bFirstInterface, /* bInterfaceNumber */ \ 447 0x00, /* bAlternateSetting */ \ 448 0x01, /* bNumEndpoints */ \ 449 USB_DEVICE_CLASS_WIRELESS, /* bInterfaceClass */ \ 450 CDC_DIRECT_LINE_CONTROL_MODEL, /* bInterfaceSubClass */ \ 451 CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101_AND_ANNEXO, /* bInterfaceProtocol */ \ 452 str_idx, /* iInterface */ \ 453 0x05, /* bLength */ \ 454 CDC_CS_INTERFACE, /* bDescriptorType */ \ 455 CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \ 456 WBVAL(CDC_V1_10), /* bcdCDC */ \ 457 0x05, /* bLength */ \ 458 CDC_CS_INTERFACE, /* bDescriptorType */ \ 459 CDC_FUNC_DESC_CALL_MANAGEMENT, /* bDescriptorSubtype */ \ 460 0x00, /* bmCapabilities */ \ 461 (uint8_t)(bFirstInterface + 1), /* bDataInterface */ \ 462 0x04, /* bLength */ \ 463 CDC_CS_INTERFACE, /* bDescriptorType */ \ 464 CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, /* bDescriptorSubtype */ \ 465 0x00, /* bmCapabilities */ \ 466 0x05, /* bLength */ \ 467 CDC_CS_INTERFACE, /* bDescriptorType */ \ 468 CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \ 469 bFirstInterface, /* bMasterInterface */ \ 470 (uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ \ 471 0x07, /* bLength */ \ 472 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 473 int_ep, /* bEndpointAddress */ \ 474 0x03, /* bmAttributes */ \ 475 0x08, 0x00, /* wMaxPacketSize */ \ 476 0x10, /* bInterval */ \ 477 0x09, /* bLength */ \ 478 USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ 479 (uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \ 480 0x00, /* bAlternateSetting */ \ 481 0x02, /* bNumEndpoints */ \ 482 CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \ 483 0x00, /* bInterfaceSubClass */ \ 484 0x00, /* bInterfaceProtocol */ \ 485 0x00, /* iInterface */ \ 486 0x07, /* bLength */ \ 487 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 488 out_ep, /* bEndpointAddress */ \ 489 0x02, /* bmAttributes */ \ 490 WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \ 491 0x00, /* bInterval */ \ 492 0x07, /* bLength */ \ 493 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 494 in_ep, /* bEndpointAddress */ \ 495 0x02, /* bmAttributes */ \ 496 WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \ 497 0x00 /* bInterval */ 498 // clang-format on 499 500 #define DBVAL_BE(x) ((x >> 24) & 0xFF), ((x >> 16) & 0xFF), ((x >> 8) & 0xFF), (x & 0xFF) 501 502 /*Length of template descriptor: 66 bytes*/ 503 #define CDC_ECM_DESCRIPTOR_LEN (8 + 9 + 5 + 5 + 13 + 7 + 9 + 7 + 7) 504 // clang-format off 505 #define CDC_ECM_DESCRIPTOR_INIT(bFirstInterface, int_ep, out_ep, in_ep, wMaxPacketSize, \ 506 eth_statistics, wMaxSegmentSize, wNumberMCFilters, bNumberPowerFilters, str_idx) \ 507 /* Interface Associate */ \ 508 0x08, /* bLength */ \ 509 USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, /* bDescriptorType */ \ 510 bFirstInterface, /* bFirstInterface */ \ 511 0x02, /* bInterfaceCount */ \ 512 USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \ 513 CDC_ETHERNET_NETWORKING_CONTROL_MODEL, /* bFunctionSubClass */ \ 514 CDC_COMMON_PROTOCOL_NONE, /* bFunctionProtocol */ \ 515 0x00, /* iFunction */ \ 516 0x09, /* bLength */ \ 517 USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ 518 bFirstInterface, /* bInterfaceNumber */ \ 519 0x00, /* bAlternateSetting */ \ 520 0x01, /* bNumEndpoints */ \ 521 USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \ 522 CDC_ETHERNET_NETWORKING_CONTROL_MODEL, /* bInterfaceSubClass */ \ 523 CDC_COMMON_PROTOCOL_NONE, /* bInterfaceProtocol */ \ 524 str_idx, /* iInterface */ \ 525 0x05, /* bLength */ \ 526 CDC_CS_INTERFACE, /* bDescriptorType */ \ 527 CDC_FUNC_DESC_HEADER, /* bDescriptorSubtype */ \ 528 WBVAL(CDC_V1_10), /* bcdCDC */ \ 529 0x05, /* bLength */ \ 530 CDC_CS_INTERFACE, /* bDescriptorType */ \ 531 CDC_FUNC_DESC_UNION, /* bDescriptorSubtype */ \ 532 bFirstInterface, /* bMasterInterface */ \ 533 (uint8_t)(bFirstInterface + 1), /* bSlaveInterface0 */ \ 534 /* CDC_ECM Functional Descriptor */ \ 535 0x0D, /* bFunctionLength */\ 536 CDC_CS_INTERFACE, /* bDescriptorType: CS_INTERFACE */\ 537 CDC_FUNC_DESC_ETHERNET_NETWORKING, /* Ethernet Networking functional descriptor subtype */\ 538 str_idx, /* Device's MAC string index */\ 539 DBVAL_BE(eth_statistics), /* Ethernet statistics (bitmap) */\ 540 WBVAL(wMaxPacketSize),/* wMaxSegmentSize: Ethernet Maximum Segment size, typically 1514 bytes */\ 541 WBVAL(wNumberMCFilters), /* wNumberMCFilters: the number of multicast filters */\ 542 bNumberPowerFilters, /* bNumberPowerFilters: the number of wakeup power filters */\ 543 0x07, /* bLength */ \ 544 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 545 int_ep, /* bEndpointAddress */ \ 546 0x03, /* bmAttributes */ \ 547 0x10, 0x00, /* wMaxPacketSize */ \ 548 0x10, /* bInterval */ \ 549 0x09, /* bLength */ \ 550 USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \ 551 (uint8_t)(bFirstInterface + 1), /* bInterfaceNumber */ \ 552 0x00, /* bAlternateSetting */ \ 553 0x02, /* bNumEndpoints */ \ 554 CDC_DATA_INTERFACE_CLASS, /* bInterfaceClass */ \ 555 0x00, /* bInterfaceSubClass */ \ 556 0x00, /* bInterfaceProtocol */ \ 557 0x00, /* iInterface */ \ 558 0x07, /* bLength */ \ 559 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 560 out_ep, /* bEndpointAddress */ \ 561 0x02, /* bmAttributes */ \ 562 WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \ 563 0x00, /* bInterval */ \ 564 0x07, /* bLength */ \ 565 USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \ 566 in_ep, /* bEndpointAddress */ \ 567 0x02, /* bmAttributes */ \ 568 WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \ 569 0x00 /* bInterval */ 570 // clang-format on 571 572 #endif /* USB_CDC_H */ 573