1 /* usb_cdc.h - USB CDC-ACM and CDC-ECM public header */ 2 3 /* 4 * Copyright (c) 2017 PHYTEC Messtechnik GmbH 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 10 /** 11 * @file 12 * @brief USB Communications Device Class (CDC) public header 13 * 14 * Header follows the Class Definitions for 15 * Communications Devices Specification (CDC120-20101103-track.pdf), 16 * PSTN Devices Specification (PSTN120.pdf) and 17 * Ethernet Control Model Devices Specification (ECM120.pdf). 18 * Header is limited to ACM and ECM Subclasses. 19 */ 20 21 #ifndef ZEPHYR_INCLUDE_USB_CLASS_USB_CDC_H_ 22 #define ZEPHYR_INCLUDE_USB_CLASS_USB_CDC_H_ 23 24 /** CDC Specification release number in BCD format */ 25 #define CDC_SRN_1_20 0x0120 26 27 /** Communications Class Subclass Codes */ 28 #define ACM_SUBCLASS 0x02 29 #define ECM_SUBCLASS 0x06 30 #define EEM_SUBCLASS 0x0c 31 32 /** Communications Class Protocol Codes */ 33 #define AT_CMD_V250_PROTOCOL 0x01 34 #define EEM_PROTOCOL 0x07 35 #define ACM_VENDOR_PROTOCOL 0xFF 36 37 /** 38 * @brief Data Class Interface Codes 39 * @note CDC120-20101103-track.pdf, 4.5, Table 6 40 */ 41 #define DATA_INTERFACE_CLASS 0x0A 42 43 /** 44 * @brief bDescriptor SubType for Communications 45 * Class Functional Descriptors 46 * @note CDC120-20101103-track.pdf, 5.2.3, Table 13 47 */ 48 #define HEADER_FUNC_DESC 0x00 49 #define CALL_MANAGEMENT_FUNC_DESC 0x01 50 #define ACM_FUNC_DESC 0x02 51 #define UNION_FUNC_DESC 0x06 52 #define ETHERNET_FUNC_DESC 0x0F 53 54 /** 55 * @brief PSTN Subclass Specific Requests 56 * for ACM devices 57 * @note PSTN120.pdf, 6.3, Table 13 58 */ 59 #define CDC_SEND_ENC_CMD 0x00 60 #define CDC_GET_ENC_RSP 0x01 61 #define SET_LINE_CODING 0x20 62 #define GET_LINE_CODING 0x21 63 #define SET_CONTROL_LINE_STATE 0x22 64 65 /** Control Signal Bitmap Values for SetControlLineState */ 66 #define SET_CONTROL_LINE_STATE_RTS 0x02 67 #define SET_CONTROL_LINE_STATE_DTR 0x01 68 69 /** Enhance enum uart_line_ctrl with CDC specific values */ 70 #define USB_CDC_LINE_CTRL_BAUD_RATE UART_LINE_CTRL_BAUD_RATE 71 #define USB_CDC_LINE_CTRL_DCD UART_LINE_CTRL_DCD 72 #define USB_CDC_LINE_CTRL_DSR UART_LINE_CTRL_DSR 73 #define USB_CDC_LINE_CTRL_BREAK BIT(5) 74 #define USB_CDC_LINE_CTRL_RING_SIGNAL BIT(6) 75 #define USB_CDC_LINE_CTRL_FRAMING BIT(7) 76 #define USB_CDC_LINE_CTRL_PARITY BIT(8) 77 #define USB_CDC_LINE_CTRL_OVER_RUN BIT(9) 78 79 /** UART State Bitmap Values */ 80 #define SERIAL_STATE_OVER_RUN 0x40 81 #define SERIAL_STATE_PARITY 0x20 82 #define SERIAL_STATE_FRAMING 0x10 83 #define SERIAL_STATE_RING_SIGNAL 0x08 84 #define SERIAL_STATE_BREAK 0x04 85 #define SERIAL_STATE_TX_CARRIER 0x02 86 #define SERIAL_STATE_RX_CARRIER 0x01 87 88 /** 89 * @brief Class-Specific Request Codes for Ethernet subclass 90 * @note ECM120.pdf, 6.2, Table 6 91 */ 92 #define SET_ETHERNET_MULTICAST_FILTERS 0x40 93 #define SET_ETHERNET_PM_FILTER 0x41 94 #define GET_ETHERNET_PM_FILTER 0x42 95 #define SET_ETHERNET_PACKET_FILTER 0x43 96 #define GET_ETHERNET_STATISTIC 0x44 97 98 /** Ethernet Packet Filter Bitmap */ 99 #define PACKET_TYPE_MULTICAST 0x10 100 #define PACKET_TYPE_BROADCAST 0x08 101 #define PACKET_TYPE_DIRECTED 0x04 102 #define PACKET_TYPE_ALL_MULTICAST 0x02 103 #define PACKET_TYPE_PROMISCUOUS 0x01 104 105 /** Header Functional Descriptor */ 106 struct cdc_header_descriptor { 107 uint8_t bFunctionLength; 108 uint8_t bDescriptorType; 109 uint8_t bDescriptorSubtype; 110 uint16_t bcdCDC; 111 } __packed; 112 113 /** Union Interface Functional Descriptor */ 114 struct cdc_union_descriptor { 115 uint8_t bFunctionLength; 116 uint8_t bDescriptorType; 117 uint8_t bDescriptorSubtype; 118 uint8_t bControlInterface; 119 uint8_t bSubordinateInterface0; 120 } __packed; 121 122 /** Call Management Functional Descriptor */ 123 struct cdc_cm_descriptor { 124 uint8_t bFunctionLength; 125 uint8_t bDescriptorType; 126 uint8_t bDescriptorSubtype; 127 uint8_t bmCapabilities; 128 uint8_t bDataInterface; 129 } __packed; 130 131 /** Abstract Control Management Functional Descriptor */ 132 struct cdc_acm_descriptor { 133 uint8_t bFunctionLength; 134 uint8_t bDescriptorType; 135 uint8_t bDescriptorSubtype; 136 uint8_t bmCapabilities; 137 } __packed; 138 139 /** Data structure for GET_LINE_CODING / SET_LINE_CODING class requests */ 140 struct cdc_acm_line_coding { 141 uint32_t dwDTERate; 142 uint8_t bCharFormat; 143 uint8_t bParityType; 144 uint8_t bDataBits; 145 } __packed; 146 147 /** Data structure for the notification about SerialState */ 148 struct cdc_acm_notification { 149 uint8_t bmRequestType; 150 uint8_t bNotificationType; 151 uint16_t wValue; 152 uint16_t wIndex; 153 uint16_t wLength; 154 uint16_t data; 155 } __packed; 156 157 /** Ethernet Networking Functional Descriptor */ 158 struct cdc_ecm_descriptor { 159 uint8_t bFunctionLength; 160 uint8_t bDescriptorType; 161 uint8_t bDescriptorSubtype; 162 uint8_t iMACAddress; 163 uint32_t bmEthernetStatistics; 164 uint16_t wMaxSegmentSize; 165 uint16_t wNumberMCFilters; 166 uint8_t bNumberPowerFilters; 167 } __packed; 168 169 #endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_CDC_H_ */ 170