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 /**
66  * @brief PSTN Subclass Class-Specific Notification Codes
67  * @note PSTN120.pdf, 6.5, Table 30
68  */
69 #define USB_CDC_NETWORK_CONNECTION	0x00
70 #define USB_CDC_RESPONSE_AVAILABLE	0x01
71 #define USB_CDC_AUX_JACK_HOOK_STATE	0x08
72 #define USB_CDC_RING_DETECT		0x09
73 #define USB_CDC_SERIAL_STATE		0x20
74 #define USB_CDC_CALL_STATE_CHANGE	0x28
75 #define USB_CDC_LINE_STATE_CHANGE	0x23
76 
77 /**
78  * @brief PSTN UART State Bitmap Values
79  * @note PSTN120.pdf, 6.5.4, Table 31
80  */
81 #define USB_CDC_SERIAL_STATE_OVERRUN	BIT(6)
82 #define USB_CDC_SERIAL_STATE_PARITY	BIT(5)
83 #define USB_CDC_SERIAL_STATE_FRAMING	BIT(4)
84 #define USB_CDC_SERIAL_STATE_RINGSIGNAL	BIT(3)
85 #define USB_CDC_SERIAL_STATE_BREAK	BIT(2)
86 #define USB_CDC_SERIAL_STATE_TXCARRIER	BIT(1)
87 #define USB_CDC_SERIAL_STATE_RXCARRIER	BIT(0)
88 
89 /** Control Signal Bitmap Values for SetControlLineState */
90 #define SET_CONTROL_LINE_STATE_RTS	0x02
91 #define SET_CONTROL_LINE_STATE_DTR	0x01
92 
93 /** Enhance enum uart_line_ctrl with CDC specific values */
94 #define USB_CDC_LINE_CTRL_BAUD_RATE	UART_LINE_CTRL_BAUD_RATE
95 #define USB_CDC_LINE_CTRL_DCD		UART_LINE_CTRL_DCD
96 #define USB_CDC_LINE_CTRL_DSR		UART_LINE_CTRL_DSR
97 #define USB_CDC_LINE_CTRL_BREAK		BIT(5)
98 #define USB_CDC_LINE_CTRL_RING_SIGNAL	BIT(6)
99 #define USB_CDC_LINE_CTRL_FRAMING	BIT(7)
100 #define USB_CDC_LINE_CTRL_PARITY	BIT(8)
101 #define USB_CDC_LINE_CTRL_OVER_RUN	BIT(9)
102 
103 /** UART State Bitmap Values */
104 #define SERIAL_STATE_OVER_RUN		0x40
105 #define SERIAL_STATE_PARITY		0x20
106 #define SERIAL_STATE_FRAMING		0x10
107 #define SERIAL_STATE_RING_SIGNAL	0x08
108 #define SERIAL_STATE_BREAK		0x04
109 #define SERIAL_STATE_TX_CARRIER		0x02
110 #define SERIAL_STATE_RX_CARRIER		0x01
111 
112 /**
113  * @brief PSTN Subclass Line Coding Values
114  *
115  * @note PSTN120.pdf, 6.3.11, Table 17
116  */
117 #define USB_CDC_LINE_CODING_STOP_BITS_1		0
118 #define USB_CDC_LINE_CODING_STOP_BITS_1_5	1
119 #define USB_CDC_LINE_CODING_STOP_BITS_2		2
120 
121 #define USB_CDC_LINE_CODING_PARITY_NO		0
122 #define USB_CDC_LINE_CODING_PARITY_ODD		1
123 #define USB_CDC_LINE_CODING_PARITY_EVEN		2
124 #define USB_CDC_LINE_CODING_PARITY_MARK		3
125 #define USB_CDC_LINE_CODING_PARITY_SPACE	4
126 
127 #define USB_CDC_LINE_CODING_DATA_BITS_5		5
128 #define USB_CDC_LINE_CODING_DATA_BITS_6		6
129 #define USB_CDC_LINE_CODING_DATA_BITS_7		7
130 #define USB_CDC_LINE_CODING_DATA_BITS_8		8
131 
132 /**
133  * @brief Class-Specific Request Codes for Ethernet subclass
134  * @note ECM120.pdf, 6.2, Table 6
135  */
136 #define SET_ETHERNET_MULTICAST_FILTERS	0x40
137 #define SET_ETHERNET_PM_FILTER		0x41
138 #define GET_ETHERNET_PM_FILTER		0x42
139 #define SET_ETHERNET_PACKET_FILTER	0x43
140 #define GET_ETHERNET_STATISTIC		0x44
141 
142 /** Ethernet Packet Filter Bitmap */
143 #define PACKET_TYPE_MULTICAST		0x10
144 #define PACKET_TYPE_BROADCAST		0x08
145 #define PACKET_TYPE_DIRECTED		0x04
146 #define PACKET_TYPE_ALL_MULTICAST	0x02
147 #define PACKET_TYPE_PROMISCUOUS		0x01
148 
149 /** Header Functional Descriptor */
150 struct cdc_header_descriptor {
151 	uint8_t bFunctionLength;
152 	uint8_t bDescriptorType;
153 	uint8_t bDescriptorSubtype;
154 	uint16_t bcdCDC;
155 } __packed;
156 
157 /** Union Interface Functional Descriptor */
158 struct cdc_union_descriptor {
159 	uint8_t bFunctionLength;
160 	uint8_t bDescriptorType;
161 	uint8_t bDescriptorSubtype;
162 	uint8_t bControlInterface;
163 	uint8_t bSubordinateInterface0;
164 } __packed;
165 
166 /** Call Management Functional Descriptor */
167 struct cdc_cm_descriptor {
168 	uint8_t bFunctionLength;
169 	uint8_t bDescriptorType;
170 	uint8_t bDescriptorSubtype;
171 	uint8_t bmCapabilities;
172 	uint8_t bDataInterface;
173 } __packed;
174 
175 /** Abstract Control Management Functional Descriptor */
176 struct cdc_acm_descriptor {
177 	uint8_t bFunctionLength;
178 	uint8_t bDescriptorType;
179 	uint8_t bDescriptorSubtype;
180 	uint8_t bmCapabilities;
181 } __packed;
182 
183 /** Data structure for GET_LINE_CODING / SET_LINE_CODING class requests */
184 struct cdc_acm_line_coding {
185 	uint32_t dwDTERate;
186 	uint8_t bCharFormat;
187 	uint8_t bParityType;
188 	uint8_t bDataBits;
189 } __packed;
190 
191 /** Data structure for the notification about SerialState */
192 struct cdc_acm_notification {
193 	uint8_t bmRequestType;
194 	uint8_t bNotificationType;
195 	uint16_t wValue;
196 	uint16_t wIndex;
197 	uint16_t wLength;
198 	uint16_t data;
199 } __packed;
200 
201 /** Ethernet Networking Functional Descriptor */
202 struct cdc_ecm_descriptor {
203 	uint8_t bFunctionLength;
204 	uint8_t bDescriptorType;
205 	uint8_t bDescriptorSubtype;
206 	uint8_t iMACAddress;
207 	uint32_t bmEthernetStatistics;
208 	uint16_t wMaxSegmentSize;
209 	uint16_t wNumberMCFilters;
210 	uint8_t bNumberPowerFilters;
211 } __packed;
212 
213 #endif /* ZEPHYR_INCLUDE_USB_CLASS_USB_CDC_H_ */
214