Line data Source code
1 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 1 : #define CDC_SRN_1_20 0x0120 26 : 27 : /** Communications Class Subclass Codes */ 28 1 : #define ACM_SUBCLASS 0x02 29 0 : #define ECM_SUBCLASS 0x06 30 0 : #define EEM_SUBCLASS 0x0c 31 0 : #define NCM_SUBCLASS 0x0d 32 : 33 : /** Communications Class Protocol Codes */ 34 1 : #define AT_CMD_V250_PROTOCOL 0x01 35 0 : #define EEM_PROTOCOL 0x07 36 0 : #define ACM_VENDOR_PROTOCOL 0xFF 37 0 : #define NCM_DATA_PROTOCOL 0x01 38 : 39 : /** 40 : * @brief Data Class Interface Codes 41 : * @note CDC120-20101103-track.pdf, 4.5, Table 6 42 : */ 43 1 : #define DATA_INTERFACE_CLASS 0x0A 44 : 45 : /** 46 : * @brief bDescriptor SubType for Communications 47 : * Class Functional Descriptors 48 : * @note CDC120-20101103-track.pdf, 5.2.3, Table 13 49 : */ 50 1 : #define HEADER_FUNC_DESC 0x00 51 0 : #define CALL_MANAGEMENT_FUNC_DESC 0x01 52 0 : #define ACM_FUNC_DESC 0x02 53 0 : #define UNION_FUNC_DESC 0x06 54 0 : #define ETHERNET_FUNC_DESC 0x0F 55 0 : #define ETHERNET_FUNC_DESC_NCM 0x1a 56 : 57 : /** 58 : * @brief PSTN Subclass Specific Requests 59 : * for ACM devices 60 : * @note PSTN120.pdf, 6.3, Table 13 61 : */ 62 1 : #define CDC_SEND_ENC_CMD 0x00 63 0 : #define CDC_GET_ENC_RSP 0x01 64 0 : #define SET_LINE_CODING 0x20 65 0 : #define GET_LINE_CODING 0x21 66 0 : #define SET_CONTROL_LINE_STATE 0x22 67 : 68 : /** 69 : * @brief PSTN Subclass Class-Specific Notification Codes 70 : * @note PSTN120.pdf, 6.5, Table 30 71 : */ 72 1 : #define USB_CDC_NETWORK_CONNECTION 0x00 73 0 : #define USB_CDC_RESPONSE_AVAILABLE 0x01 74 0 : #define USB_CDC_AUX_JACK_HOOK_STATE 0x08 75 0 : #define USB_CDC_RING_DETECT 0x09 76 0 : #define USB_CDC_SERIAL_STATE 0x20 77 0 : #define USB_CDC_CALL_STATE_CHANGE 0x28 78 0 : #define USB_CDC_LINE_STATE_CHANGE 0x23 79 : 80 : /** 81 : * @brief PSTN UART State Bitmap Values 82 : * @note PSTN120.pdf, 6.5.4, Table 31 83 : */ 84 1 : #define USB_CDC_SERIAL_STATE_OVERRUN BIT(6) 85 0 : #define USB_CDC_SERIAL_STATE_PARITY BIT(5) 86 0 : #define USB_CDC_SERIAL_STATE_FRAMING BIT(4) 87 0 : #define USB_CDC_SERIAL_STATE_RINGSIGNAL BIT(3) 88 0 : #define USB_CDC_SERIAL_STATE_BREAK BIT(2) 89 0 : #define USB_CDC_SERIAL_STATE_TXCARRIER BIT(1) 90 0 : #define USB_CDC_SERIAL_STATE_RXCARRIER BIT(0) 91 : 92 : /** Control Signal Bitmap Values for SetControlLineState */ 93 1 : #define SET_CONTROL_LINE_STATE_RTS 0x02 94 0 : #define SET_CONTROL_LINE_STATE_DTR 0x01 95 : 96 : /** Enhance enum uart_line_ctrl with CDC specific values */ 97 1 : #define USB_CDC_LINE_CTRL_BAUD_RATE UART_LINE_CTRL_BAUD_RATE 98 0 : #define USB_CDC_LINE_CTRL_DCD UART_LINE_CTRL_DCD 99 0 : #define USB_CDC_LINE_CTRL_DSR UART_LINE_CTRL_DSR 100 0 : #define USB_CDC_LINE_CTRL_BREAK BIT(5) 101 0 : #define USB_CDC_LINE_CTRL_RING_SIGNAL BIT(6) 102 0 : #define USB_CDC_LINE_CTRL_FRAMING BIT(7) 103 0 : #define USB_CDC_LINE_CTRL_PARITY BIT(8) 104 0 : #define USB_CDC_LINE_CTRL_OVER_RUN BIT(9) 105 : 106 : /** UART State Bitmap Values */ 107 1 : #define SERIAL_STATE_OVER_RUN 0x40 108 0 : #define SERIAL_STATE_PARITY 0x20 109 0 : #define SERIAL_STATE_FRAMING 0x10 110 0 : #define SERIAL_STATE_RING_SIGNAL 0x08 111 0 : #define SERIAL_STATE_BREAK 0x04 112 0 : #define SERIAL_STATE_TX_CARRIER 0x02 113 0 : #define SERIAL_STATE_RX_CARRIER 0x01 114 : 115 : /** 116 : * @brief PSTN Subclass Line Coding Values 117 : * 118 : * @note PSTN120.pdf, 6.3.11, Table 17 119 : */ 120 1 : #define USB_CDC_LINE_CODING_STOP_BITS_1 0 121 0 : #define USB_CDC_LINE_CODING_STOP_BITS_1_5 1 122 0 : #define USB_CDC_LINE_CODING_STOP_BITS_2 2 123 : 124 0 : #define USB_CDC_LINE_CODING_PARITY_NO 0 125 0 : #define USB_CDC_LINE_CODING_PARITY_ODD 1 126 0 : #define USB_CDC_LINE_CODING_PARITY_EVEN 2 127 0 : #define USB_CDC_LINE_CODING_PARITY_MARK 3 128 0 : #define USB_CDC_LINE_CODING_PARITY_SPACE 4 129 : 130 0 : #define USB_CDC_LINE_CODING_DATA_BITS_5 5 131 0 : #define USB_CDC_LINE_CODING_DATA_BITS_6 6 132 0 : #define USB_CDC_LINE_CODING_DATA_BITS_7 7 133 0 : #define USB_CDC_LINE_CODING_DATA_BITS_8 8 134 : 135 : /** 136 : * @brief Class-Specific Request Codes for Ethernet subclass 137 : * @note ECM120.pdf, 6.2, Table 6 138 : */ 139 1 : #define SET_ETHERNET_MULTICAST_FILTERS 0x40 140 0 : #define SET_ETHERNET_PM_FILTER 0x41 141 0 : #define GET_ETHERNET_PM_FILTER 0x42 142 0 : #define SET_ETHERNET_PACKET_FILTER 0x43 143 0 : #define GET_ETHERNET_STATISTIC 0x44 144 : 145 : /** 146 : * @brief Class-Specific Request Codes for NCM subclass 147 : * @note NCM100.pdf, 6.2, Table 6-2 148 : */ 149 1 : #define GET_NTB_PARAMETERS 0x80 150 0 : #define GET_NET_ADDRESS 0x81 151 0 : #define SET_NET_ADDRESS 0x82 152 0 : #define GET_NTB_FORMAT 0x83 153 0 : #define SET_NTB_FORMAT 0x84 154 0 : #define GET_NTB_INPUT_SIZE 0x85 155 0 : #define SET_NTB_INPUT_SIZE 0x86 156 0 : #define GET_MAX_DATAGRAM_SIZE 0x87 157 0 : #define SET_MAX_DATAGRAM_SIZE 0x88 158 0 : #define GET_CRC_MODE 0x89 159 0 : #define SET_CRC_MODE 0x8A 160 : 161 : /** Ethernet Packet Filter Bitmap */ 162 1 : #define PACKET_TYPE_MULTICAST 0x10 163 0 : #define PACKET_TYPE_BROADCAST 0x08 164 0 : #define PACKET_TYPE_DIRECTED 0x04 165 0 : #define PACKET_TYPE_ALL_MULTICAST 0x02 166 0 : #define PACKET_TYPE_PROMISCUOUS 0x01 167 : 168 : /** Header Functional Descriptor */ 169 1 : struct cdc_header_descriptor { 170 0 : uint8_t bFunctionLength; 171 0 : uint8_t bDescriptorType; 172 0 : uint8_t bDescriptorSubtype; 173 0 : uint16_t bcdCDC; 174 : } __packed; 175 : 176 : /** Union Interface Functional Descriptor */ 177 1 : struct cdc_union_descriptor { 178 0 : uint8_t bFunctionLength; 179 0 : uint8_t bDescriptorType; 180 0 : uint8_t bDescriptorSubtype; 181 0 : uint8_t bControlInterface; 182 0 : uint8_t bSubordinateInterface0; 183 : } __packed; 184 : 185 : /** Call Management Functional Descriptor */ 186 1 : struct cdc_cm_descriptor { 187 0 : uint8_t bFunctionLength; 188 0 : uint8_t bDescriptorType; 189 0 : uint8_t bDescriptorSubtype; 190 0 : uint8_t bmCapabilities; 191 0 : uint8_t bDataInterface; 192 : } __packed; 193 : 194 : /** Abstract Control Management Functional Descriptor */ 195 1 : struct cdc_acm_descriptor { 196 0 : uint8_t bFunctionLength; 197 0 : uint8_t bDescriptorType; 198 0 : uint8_t bDescriptorSubtype; 199 0 : uint8_t bmCapabilities; 200 : } __packed; 201 : 202 : /** Data structure for GET_LINE_CODING / SET_LINE_CODING class requests */ 203 1 : struct cdc_acm_line_coding { 204 0 : uint32_t dwDTERate; 205 0 : uint8_t bCharFormat; 206 0 : uint8_t bParityType; 207 0 : uint8_t bDataBits; 208 : } __packed; 209 : 210 : /** Data structure for the notification about SerialState */ 211 1 : struct cdc_acm_notification { 212 0 : uint8_t bmRequestType; 213 0 : uint8_t bNotificationType; 214 0 : uint16_t wValue; 215 0 : uint16_t wIndex; 216 0 : uint16_t wLength; 217 0 : uint16_t data; 218 : } __packed; 219 : 220 : /** Ethernet Networking Functional Descriptor */ 221 1 : struct cdc_ecm_descriptor { 222 0 : uint8_t bFunctionLength; 223 0 : uint8_t bDescriptorType; 224 0 : uint8_t bDescriptorSubtype; 225 0 : uint8_t iMACAddress; 226 0 : uint32_t bmEthernetStatistics; 227 0 : uint16_t wMaxSegmentSize; 228 0 : uint16_t wNumberMCFilters; 229 0 : uint8_t bNumberPowerFilters; 230 : } __packed; 231 : 232 : /** Ethernet Network Control Model (NCM) Descriptor */ 233 1 : struct cdc_ncm_descriptor { 234 0 : uint8_t bFunctionLength; 235 0 : uint8_t bDescriptorType; 236 0 : uint8_t bDescriptorSubtype; 237 0 : uint16_t bcdNcmVersion; 238 0 : uint8_t bmNetworkCapabilities; 239 : } __packed; 240 : 241 : #endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_CDC_H_ */