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 #pragma once
22 
23 #include <stdint.h>
24 #include <sys/cdefs.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /** CDC Specification release number in BCD format */
31 #define CDC_SRN_1_20            0x0120
32 
33 /** Communications Class Subclass Codes */
34 #define ACM_SUBCLASS            0x02
35 #define ECM_SUBCLASS            0x06
36 #define EEM_SUBCLASS            0x0c
37 
38 /** Communications Class Protocol Codes */
39 #define AT_CMD_V250_PROTOCOL        0x01
40 #define EEM_PROTOCOL            0x07
41 
42 /**
43  * @brief Data Class Interface Codes
44  * @note CDC120-20101103-track.pdf, 4.5, Table 6
45  */
46 #define DATA_INTERFACE_CLASS        0x0A
47 
48 /**
49  * @brief Values for the bDescriptorType Field
50  * @note CDC120-20101103-track.pdf, 5.2.3, Table 12
51  */
52 #define CS_INTERFACE            0x24
53 #define CS_ENDPOINT         0x25
54 
55 /**
56  * @brief bDescriptor SubType for Communications
57  * Class Functional Descriptors
58  * @note CDC120-20101103-track.pdf, 5.2.3, Table 13
59  */
60 #define HEADER_FUNC_DESC        0x00
61 #define CALL_MANAGEMENT_FUNC_DESC   0x01
62 #define ACM_FUNC_DESC           0x02
63 #define UNION_FUNC_DESC         0x06
64 #define ETHERNET_FUNC_DESC      0x0F
65 
66 /**
67  * @brief PSTN Subclass Specific Requests
68  * for ACM devices
69  * @note PSTN120.pdf, 6.3, Table 13
70  */
71 #define CDC_SEND_ENC_CMD        0x00
72 #define CDC_GET_ENC_RSP         0x01
73 #define SET_LINE_CODING         0x20
74 #define GET_LINE_CODING         0x21
75 #define SET_CONTROL_LINE_STATE      0x22
76 
77 /** Control Signal Bitmap Values for SetControlLineState */
78 #define SET_CONTROL_LINE_STATE_RTS  0x02
79 #define SET_CONTROL_LINE_STATE_DTR  0x01
80 
81 /** UART State Bitmap Values */
82 #define SERIAL_STATE_OVERRUN        0x40
83 #define SERIAL_STATE_PARITY     0x20
84 #define SERIAL_STATE_FRAMING        0x10
85 #define SERIAL_STATE_RING       0x08
86 #define SERIAL_STATE_BREAK      0x04
87 #define SERIAL_STATE_TX_CARRIER     0x02
88 #define SERIAL_STATE_RX_CARRIER     0x01
89 
90 /**
91  * @brief Class-Specific Request Codes for Ethernet subclass
92  * @note ECM120.pdf, 6.2, Table 6
93  */
94 #define SET_ETHERNET_MULTICAST_FILTERS  0x40
95 #define SET_ETHERNET_PM_FILTER      0x41
96 #define GET_ETHERNET_PM_FILTER      0x42
97 #define SET_ETHERNET_PACKET_FILTER  0x43
98 #define GET_ETHERNET_STATISTIC      0x44
99 
100 /** Ethernet Packet Filter Bitmap */
101 #define PACKET_TYPE_MULTICAST       0x10
102 #define PACKET_TYPE_BROADCAST       0x08
103 #define PACKET_TYPE_DIRECTED        0x04
104 #define PACKET_TYPE_ALL_MULTICAST   0x02
105 #define PACKET_TYPE_PROMISCUOUS     0x01
106 
107 /** Header Functional Descriptor */
108 struct cdc_header_descriptor {
109     uint8_t bFunctionLength;
110     uint8_t bDescriptorType;
111     uint8_t bDescriptorSubtype;
112     uint16_t bcdCDC;
113 } __packed;
114 
115 /** Union Interface Functional Descriptor */
116 struct cdc_union_descriptor {
117     uint8_t bFunctionLength;
118     uint8_t bDescriptorType;
119     uint8_t bDescriptorSubtype;
120     uint8_t bControlInterface;
121     uint8_t bSubordinateInterface0;
122 } __packed;
123 
124 /** Call Management Functional Descriptor */
125 struct cdc_cm_descriptor {
126     uint8_t bFunctionLength;
127     uint8_t bDescriptorType;
128     uint8_t bDescriptorSubtype;
129     uint8_t bmCapabilities;
130     uint8_t bDataInterface;
131 } __packed;
132 
133 /** Abstract Control Management Functional Descriptor */
134 struct cdc_acm_descriptor {
135     uint8_t bFunctionLength;
136     uint8_t bDescriptorType;
137     uint8_t bDescriptorSubtype;
138     uint8_t bmCapabilities;
139 } __packed;
140 
141 
142 /** Data structure for GET_LINE_CODING / SET_LINE_CODING class requests */
143 struct cdc_acm_line_coding {
144     uint32_t dwDTERate;
145     uint8_t bCharFormat;
146     uint8_t bParityType;
147     uint8_t bDataBits;
148 } __packed;
149 
150 /** Data structure for the notification about SerialState */
151 struct cdc_acm_notification {
152     uint8_t bmRequestType;
153     uint8_t bNotificationType;
154     uint16_t wValue;
155     uint16_t wIndex;
156     uint16_t wLength;
157     uint16_t data;
158 } __packed;
159 
160 /** Ethernet Networking Functional Descriptor */
161 struct cdc_ecm_descriptor {
162     uint8_t bFunctionLength;
163     uint8_t bDescriptorType;
164     uint8_t bDescriptorSubtype;
165     uint8_t iMACAddress;
166     uint32_t bmEthernetStatistics;
167     uint16_t wMaxSegmentSize;
168     uint16_t wNumberMCFilters;
169     uint8_t bNumberPowerFilters;
170 } __packed;
171 
172 #ifdef __cplusplus
173 }
174 #endif
175