1 /*
2  * SPDX-FileCopyrightText: 2017 PHYTEC Messtechnik GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief USB Communications Device Class (CDC) public header
10  *
11  * Header follows the Class Definitions for
12  * Communications Devices Specification (CDC120-20101103-track.pdf),
13  * PSTN Devices Specification (PSTN120.pdf) and
14  * Ethernet Control Model Devices Specification (ECM120.pdf).
15  * Header is limited to ACM and ECM Subclasses.
16  */
17 
18 #pragma once
19 
20 #include <stdint.h>
21 #include <sys/cdefs.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /** CDC Specification release number in BCD format */
28 #define CDC_SRN_1_20            0x0120
29 
30 /** Communications Class Subclass Codes */
31 #define ACM_SUBCLASS            0x02
32 #define ECM_SUBCLASS            0x06
33 #define EEM_SUBCLASS            0x0c
34 
35 /** Communications Class Protocol Codes */
36 #define AT_CMD_V250_PROTOCOL        0x01
37 #define EEM_PROTOCOL            0x07
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 Values for the bDescriptorType Field
47  * @note CDC120-20101103-track.pdf, 5.2.3, Table 12
48  */
49 #define CS_INTERFACE            0x24
50 #define CS_ENDPOINT         0x25
51 
52 /**
53  * @brief bDescriptor SubType for Communications
54  * Class Functional Descriptors
55  * @note CDC120-20101103-track.pdf, 5.2.3, Table 13
56  */
57 #define HEADER_FUNC_DESC        0x00
58 #define CALL_MANAGEMENT_FUNC_DESC   0x01
59 #define ACM_FUNC_DESC           0x02
60 #define UNION_FUNC_DESC         0x06
61 #define ETHERNET_FUNC_DESC      0x0F
62 
63 /**
64  * @brief PSTN Subclass Specific Requests
65  * for ACM devices
66  * @note PSTN120.pdf, 6.3, Table 13
67  */
68 #define CDC_SEND_ENC_CMD        0x00
69 #define CDC_GET_ENC_RSP         0x01
70 #define SET_LINE_CODING         0x20
71 #define GET_LINE_CODING         0x21
72 #define SET_CONTROL_LINE_STATE      0x22
73 
74 /** Control Signal Bitmap Values for SetControlLineState */
75 #define SET_CONTROL_LINE_STATE_RTS  0x02
76 #define SET_CONTROL_LINE_STATE_DTR  0x01
77 
78 /** UART State Bitmap Values */
79 #define SERIAL_STATE_OVERRUN        0x40
80 #define SERIAL_STATE_PARITY     0x20
81 #define SERIAL_STATE_FRAMING        0x10
82 #define SERIAL_STATE_RING       0x08
83 #define SERIAL_STATE_BREAK      0x04
84 #define SERIAL_STATE_TX_CARRIER     0x02
85 #define SERIAL_STATE_RX_CARRIER     0x01
86 
87 /**
88  * @brief Class-Specific Request Codes for Ethernet subclass
89  * @note ECM120.pdf, 6.2, Table 6
90  */
91 #define SET_ETHERNET_MULTICAST_FILTERS  0x40
92 #define SET_ETHERNET_PM_FILTER      0x41
93 #define GET_ETHERNET_PM_FILTER      0x42
94 #define SET_ETHERNET_PACKET_FILTER  0x43
95 #define GET_ETHERNET_STATISTIC      0x44
96 
97 /** Ethernet Packet Filter Bitmap */
98 #define PACKET_TYPE_MULTICAST       0x10
99 #define PACKET_TYPE_BROADCAST       0x08
100 #define PACKET_TYPE_DIRECTED        0x04
101 #define PACKET_TYPE_ALL_MULTICAST   0x02
102 #define PACKET_TYPE_PROMISCUOUS     0x01
103 
104 /** Header Functional Descriptor */
105 struct cdc_header_descriptor {
106     uint8_t bFunctionLength;
107     uint8_t bDescriptorType;
108     uint8_t bDescriptorSubtype;
109     uint16_t bcdCDC;
110 } __packed;
111 
112 /** Union Interface Functional Descriptor */
113 struct cdc_union_descriptor {
114     uint8_t bFunctionLength;
115     uint8_t bDescriptorType;
116     uint8_t bDescriptorSubtype;
117     uint8_t bControlInterface;
118     uint8_t bSubordinateInterface0;
119 } __packed;
120 
121 /** Call Management Functional Descriptor */
122 struct cdc_cm_descriptor {
123     uint8_t bFunctionLength;
124     uint8_t bDescriptorType;
125     uint8_t bDescriptorSubtype;
126     uint8_t bmCapabilities;
127     uint8_t bDataInterface;
128 } __packed;
129 
130 /** Abstract Control Management Functional Descriptor */
131 struct cdc_acm_descriptor {
132     uint8_t bFunctionLength;
133     uint8_t bDescriptorType;
134     uint8_t bDescriptorSubtype;
135     uint8_t bmCapabilities;
136 } __packed;
137 
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 #ifdef __cplusplus
170 }
171 #endif
172