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 #define NCM_SUBCLASS			0x0d
32 
33 /** Communications Class Protocol Codes */
34 #define AT_CMD_V250_PROTOCOL		0x01
35 #define EEM_PROTOCOL			0x07
36 #define ACM_VENDOR_PROTOCOL		0xFF
37 #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 #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 #define HEADER_FUNC_DESC		0x00
51 #define CALL_MANAGEMENT_FUNC_DESC	0x01
52 #define ACM_FUNC_DESC			0x02
53 #define UNION_FUNC_DESC			0x06
54 #define ETHERNET_FUNC_DESC		0x0F
55 #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 #define CDC_SEND_ENC_CMD		0x00
63 #define CDC_GET_ENC_RSP			0x01
64 #define SET_LINE_CODING			0x20
65 #define GET_LINE_CODING			0x21
66 #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 #define USB_CDC_NETWORK_CONNECTION	0x00
73 #define USB_CDC_RESPONSE_AVAILABLE	0x01
74 #define USB_CDC_AUX_JACK_HOOK_STATE	0x08
75 #define USB_CDC_RING_DETECT		0x09
76 #define USB_CDC_SERIAL_STATE		0x20
77 #define USB_CDC_CALL_STATE_CHANGE	0x28
78 #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 #define USB_CDC_SERIAL_STATE_OVERRUN	BIT(6)
85 #define USB_CDC_SERIAL_STATE_PARITY	BIT(5)
86 #define USB_CDC_SERIAL_STATE_FRAMING	BIT(4)
87 #define USB_CDC_SERIAL_STATE_RINGSIGNAL	BIT(3)
88 #define USB_CDC_SERIAL_STATE_BREAK	BIT(2)
89 #define USB_CDC_SERIAL_STATE_TXCARRIER	BIT(1)
90 #define USB_CDC_SERIAL_STATE_RXCARRIER	BIT(0)
91 
92 /** Control Signal Bitmap Values for SetControlLineState */
93 #define SET_CONTROL_LINE_STATE_RTS	0x02
94 #define SET_CONTROL_LINE_STATE_DTR	0x01
95 
96 /** Enhance enum uart_line_ctrl with CDC specific values */
97 #define USB_CDC_LINE_CTRL_BAUD_RATE	UART_LINE_CTRL_BAUD_RATE
98 #define USB_CDC_LINE_CTRL_DCD		UART_LINE_CTRL_DCD
99 #define USB_CDC_LINE_CTRL_DSR		UART_LINE_CTRL_DSR
100 #define USB_CDC_LINE_CTRL_BREAK		BIT(5)
101 #define USB_CDC_LINE_CTRL_RING_SIGNAL	BIT(6)
102 #define USB_CDC_LINE_CTRL_FRAMING	BIT(7)
103 #define USB_CDC_LINE_CTRL_PARITY	BIT(8)
104 #define USB_CDC_LINE_CTRL_OVER_RUN	BIT(9)
105 
106 /** UART State Bitmap Values */
107 #define SERIAL_STATE_OVER_RUN		0x40
108 #define SERIAL_STATE_PARITY		0x20
109 #define SERIAL_STATE_FRAMING		0x10
110 #define SERIAL_STATE_RING_SIGNAL	0x08
111 #define SERIAL_STATE_BREAK		0x04
112 #define SERIAL_STATE_TX_CARRIER		0x02
113 #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 #define USB_CDC_LINE_CODING_STOP_BITS_1		0
121 #define USB_CDC_LINE_CODING_STOP_BITS_1_5	1
122 #define USB_CDC_LINE_CODING_STOP_BITS_2		2
123 
124 #define USB_CDC_LINE_CODING_PARITY_NO		0
125 #define USB_CDC_LINE_CODING_PARITY_ODD		1
126 #define USB_CDC_LINE_CODING_PARITY_EVEN		2
127 #define USB_CDC_LINE_CODING_PARITY_MARK		3
128 #define USB_CDC_LINE_CODING_PARITY_SPACE	4
129 
130 #define USB_CDC_LINE_CODING_DATA_BITS_5		5
131 #define USB_CDC_LINE_CODING_DATA_BITS_6		6
132 #define USB_CDC_LINE_CODING_DATA_BITS_7		7
133 #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 #define SET_ETHERNET_MULTICAST_FILTERS	0x40
140 #define SET_ETHERNET_PM_FILTER		0x41
141 #define GET_ETHERNET_PM_FILTER		0x42
142 #define SET_ETHERNET_PACKET_FILTER	0x43
143 #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 #define GET_NTB_PARAMETERS     0x80
150 #define GET_NET_ADDRESS        0x81
151 #define SET_NET_ADDRESS        0x82
152 #define GET_NTB_FORMAT         0x83
153 #define SET_NTB_FORMAT         0x84
154 #define GET_NTB_INPUT_SIZE     0x85
155 #define SET_NTB_INPUT_SIZE     0x86
156 #define GET_MAX_DATAGRAM_SIZE  0x87
157 #define SET_MAX_DATAGRAM_SIZE  0x88
158 #define GET_CRC_MODE           0x89
159 #define SET_CRC_MODE           0x8A
160 
161 /** Ethernet Packet Filter Bitmap */
162 #define PACKET_TYPE_MULTICAST		0x10
163 #define PACKET_TYPE_BROADCAST		0x08
164 #define PACKET_TYPE_DIRECTED		0x04
165 #define PACKET_TYPE_ALL_MULTICAST	0x02
166 #define PACKET_TYPE_PROMISCUOUS		0x01
167 
168 /** Header Functional Descriptor */
169 struct cdc_header_descriptor {
170 	uint8_t bFunctionLength;
171 	uint8_t bDescriptorType;
172 	uint8_t bDescriptorSubtype;
173 	uint16_t bcdCDC;
174 } __packed;
175 
176 /** Union Interface Functional Descriptor */
177 struct cdc_union_descriptor {
178 	uint8_t bFunctionLength;
179 	uint8_t bDescriptorType;
180 	uint8_t bDescriptorSubtype;
181 	uint8_t bControlInterface;
182 	uint8_t bSubordinateInterface0;
183 } __packed;
184 
185 /** Call Management Functional Descriptor */
186 struct cdc_cm_descriptor {
187 	uint8_t bFunctionLength;
188 	uint8_t bDescriptorType;
189 	uint8_t bDescriptorSubtype;
190 	uint8_t bmCapabilities;
191 	uint8_t bDataInterface;
192 } __packed;
193 
194 /** Abstract Control Management Functional Descriptor */
195 struct cdc_acm_descriptor {
196 	uint8_t bFunctionLength;
197 	uint8_t bDescriptorType;
198 	uint8_t bDescriptorSubtype;
199 	uint8_t bmCapabilities;
200 } __packed;
201 
202 /** Data structure for GET_LINE_CODING / SET_LINE_CODING class requests */
203 struct cdc_acm_line_coding {
204 	uint32_t dwDTERate;
205 	uint8_t bCharFormat;
206 	uint8_t bParityType;
207 	uint8_t bDataBits;
208 } __packed;
209 
210 /** Data structure for the notification about SerialState */
211 struct cdc_acm_notification {
212 	uint8_t bmRequestType;
213 	uint8_t bNotificationType;
214 	uint16_t wValue;
215 	uint16_t wIndex;
216 	uint16_t wLength;
217 	uint16_t data;
218 } __packed;
219 
220 /** Ethernet Networking Functional Descriptor */
221 struct cdc_ecm_descriptor {
222 	uint8_t bFunctionLength;
223 	uint8_t bDescriptorType;
224 	uint8_t bDescriptorSubtype;
225 	uint8_t iMACAddress;
226 	uint32_t bmEthernetStatistics;
227 	uint16_t wMaxSegmentSize;
228 	uint16_t wNumberMCFilters;
229 	uint8_t bNumberPowerFilters;
230 } __packed;
231 
232 /** Ethernet Network Control Model (NCM) Descriptor */
233 struct cdc_ncm_descriptor {
234 	uint8_t bFunctionLength;
235 	uint8_t bDescriptorType;
236 	uint8_t bDescriptorSubtype;
237 	uint16_t bcdNcmVersion;
238 	uint8_t bmNetworkCapabilities;
239 } __packed;
240 
241 #endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_CDC_H_ */
242