cdc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Dylan Laduranty <dylan.laduranty@mesotic.com>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for
6  * more details.
7  */
8 
23 #ifndef USB_CDC_H
24 #define USB_CDC_H
25 
26 #include <stdint.h>
27 
28 #include "usb.h"
29 #include "usb/descriptor.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define USB_TYPE_DESCRIPTOR_CDC 0x24
36 #define USB_CDC_VERSION_BCD 0x0120
43 #define USB_CDC_SUBCLASS_NONE 0x00
44 #define USB_CDC_SUBCLASS_DLCM 0x01
45 #define USB_CDC_SUBCLASS_ACM 0x02
46 #define USB_CDC_SUBCLASS_TCM 0x03
47 #define USB_CDC_SUBCLASS_MCCM 0x04
48 #define USB_CDC_SUBCLASS_CCM 0x05
49 #define USB_CDC_SUBCLASS_ENCM 0x06
50 #define USB_CDC_SUBCLASS_ANCM 0x07
51 #define USB_CDC_SUBCLASS_WHCM 0x08
52 #define USB_CDC_SUBCLASS_DM 0x09
53 #define USB_CDC_SUBCLASS_MDLM 0x0A
54 #define USB_CDC_SUBCLASS_OBEX 0x0B
55 #define USB_CDC_SUBCLASS_EEM 0x0C
56 #define USB_CDC_SUBCLASS_NCM 0x0D
63 #define USB_CDC_PROTOCOL_NONE 0x00
64 #define USB_CDC_PROTOCOL_ITU 0x01
65 #define USB_CDC_PROTOCOL_PCCA 0x02
66 #define USB_CDC_PROTOCOL_PCCA_A 0x03
67 #define USB_CDC_PROTOCOL_GSM 0x04
68 #define USB_CDC_PROTOCOL_3GPP 0x05
69 #define USB_CDC_PROTOCOL_CS 0x06
70 #define USB_CDC_PROTOCOL_EEM 0x07
71 #define USB_CDC_PROTOCOL_EXT 0xFE
72 #define USB_CDC_PROTOCOL_VENDOR 0xFF
78 #define USB_CDC_DESCR_SUBTYPE_FUNCTIONAL 0x00
80 #define USB_CDC_DESCR_SUBTYPE_CALL_MGMT 0x01
82 #define USB_CDC_DESCR_SUBTYPE_ACM 0x02
84 #define USB_CDC_DESCR_SUBTYPE_UNION 0x06
85 #define USB_CDC_DESCR_SUBTYPE_ETH_NET 0x0f
96 #define USB_CDC_MGNT_REQUEST_SET_LINE_CODING (0x20)
97 
101 #define USB_CDC_MGNT_REQUEST_GET_LINE_CODING (0x21)
102 
106 #define USB_CDC_MGNT_REQUEST_SET_CONTROL_LINE_STATE (0x22)
107 
111 #define USB_CDC_MGNT_REQUEST_SET_ETH_MULTICAST_FILTER 0x40
112 
116 #define USB_CDC_MGNT_REQUEST_SET_ETH_PM_PATTERN_FILTER 0x41
117 
121 #define USB_CDC_MGNT_REQUEST_GET_ETH_PM_PATTERN_FILTER 0x42
122 
126 #define USB_CDC_MGNT_REQUEST_SET_ETH_PACKET_FILTER 0x43
127 
131 #define USB_CDC_MGNT_REQUEST_GET_ETH_STATISTICS 0x44
132 
142 #define USB_CDC_ACM_CONTROL_LINE_DTE (0x01)
143 
147 #define USB_CDC_ACM_CONTROL_LINE_CARRIER (0x02)
148 
158 #define USB_CDC_MGNT_NOTIF_NETWORK_CONNECTION 0x00
159 
163 #define USB_CDC_MGNT_NOTIF_RESPONSE_AVAILABLE 0x01
164 
168 #define USB_CDC_MGNT_NOTIF_AUX_JACK_HOOK_STATE 0x08
169 
173 #define USB_CDC_MGNT_NOTIF_RING_DETECT 0x09
174 
178 #define USB_CDC_MGNT_NOTIF_SERIAL_STATE 0x20
179 
183 #define USB_CDC_MGNT_NOTIF_CALL_STATE_CHANGE 0x28
184 
188 #define USB_CDC_MGNT_NOTIF_LINE_STATE_CHANGE 0x29
189 
193 #define USB_CDC_MGNT_NOTIF_CONN_SPEED_CHANGE 0x2A
194 
202 typedef struct __attribute__((packed)) {
203  uint8_t length;
204  uint8_t type;
205  uint8_t subtype;
206  uint8_t macaddress;
208  uint16_t maxsegmentsize;
209  uint16_t numbermcfilters;
212 
218 typedef struct __attribute__((packed)) {
219  uint8_t length;
220  uint8_t type;
221  uint8_t subtype;
222  uint8_t capabalities;
224 
230 typedef struct __attribute__((packed)) {
231  uint8_t length;
232  uint8_t type;
233  uint8_t subtype;
234  uint16_t bcd_cdc;
236 
240 typedef struct __attribute__((packed)) {
241  uint8_t length;
242  uint8_t type;
243  uint8_t subtype;
244  uint8_t master_if;
245  uint8_t slave_if;
247 
253 typedef struct __attribute__((packed)) {
254  uint8_t length;
255  uint8_t type;
256  uint8_t subtype;
257  uint8_t capabalities;
258  uint8_t data_if;
260 
266 typedef struct __attribute__((packed)) {
268  uint32_t down;
269  uint32_t up;
271 
281 typedef struct __attribute__((packed)) {
282  uint32_t baud;
283  uint8_t format;
284  uint8_t parity;
285  uint8_t databits;
287 
288 #define USB_CDC_ACM_CODING_STOP_BITS_1 0
289 #define USB_CDC_ACM_CODING_STOP_BITS_1_5 1
290 #define USB_CDC_ACM_CODING_STOP_BITS_2 2
292 #define USB_CDC_ACM_CODING_PARITY_NONE 0
293 #define USB_CDC_ACM_CODING_PARITY_ODD 1
294 #define USB_CDC_ACM_CODING_PARITY_EVEN 2
295 #define USB_CDC_ACM_CODING_PARITY_MARK 3
296 #define USB_CDC_ACM_CODING_PARITY_SPACE 4
302 #ifdef __cplusplus
303 }
304 #endif
305 
306 #endif /* USB_CDC_H */
307 
usb_desc_acm_t
USB CDC ACM descriptor.
Definition: cdc.h:218
usb_req_cdcacm_coding_t::format
uint8_t format
Stop bits settings
Definition: cdc.h:283
usb_desc_ecm_t::numberpowerfilters
uint8_t numberpowerfilters
Number of pattern filters for host wake-up.
Definition: cdc.h:210
usb_desc_union_t::type
uint8_t type
Descriptor type (USB_TYPE_DESCRIPTOR_CDC)
Definition: cdc.h:242
usb_desc_call_mngt_t::capabalities
uint8_t capabalities
Supported capabilities.
Definition: cdc.h:257
usb_desc_cdc_t::bcd_cdc
uint16_t bcd_cdc
CDC release number in bcd (USB_CDC_VERSION_BCD)
Definition: cdc.h:234
usb_desc_acm_t::length
uint8_t length
Size of this descriptor.
Definition: cdc.h:219
usb_desc_acm_t::subtype
uint8_t subtype
Descriptor subtype (USB_CDC_DESCR_SUBTYPE_ACM)
Definition: cdc.h:221
usb_desc_acm_t::type
uint8_t type
Descriptor type (USB_TYPE_DESCRIPTOR_CDC)
Definition: cdc.h:220
usb_req_cdcacm_coding_t
USB CDC ACM line coding setup content.
Definition: cdc.h:281
usb_desc_ecm_t::maxsegmentsize
uint16_t maxsegmentsize
Maximum segment size of the interface.
Definition: cdc.h:208
usb_desc_call_mngt_t
USB CDC call management functional descriptor.
Definition: cdc.h:253
usb_desc_cdcecm_speed_t::down
uint32_t down
Downlink bit rate.
Definition: cdc.h:268
usb_desc_ecm_t::type
uint8_t type
Descriptor type (USB_TYPE_DESCRIPTOR_CDC)
Definition: cdc.h:204
usb_desc_union_t::master_if
uint8_t master_if
Master/controlling interface number.
Definition: cdc.h:244
usb_setup_t
USB setup packet (USB 2.0 spec table 9-2)
Definition: descriptor.h:198
usb_req_cdcacm_coding_t::baud
uint32_t baud
Requested baud rate
Definition: cdc.h:282
usb_desc_call_mngt_t::type
uint8_t type
Descriptor type (USB_TYPE_DESCRIPTOR_CDC)
Definition: cdc.h:255
usb_req_cdcacm_coding_t::databits
uint8_t databits
Number of data bits (5, 6, 7, 8 or 16)
Definition: cdc.h:285
usb_desc_ecm_t::subtype
uint8_t subtype
Descriptor subtype (USB_CDC_DESCR_SUBTYPE_ETH_NET)
Definition: cdc.h:205
usb_desc_cdc_t
Generic USB CDC descriptor.
Definition: cdc.h:230
usb_desc_call_mngt_t::length
uint8_t length
Size of this descriptor.
Definition: cdc.h:254
usb_desc_cdcecm_speed_t::setup
usb_setup_t setup
Setup request header for the notification.
Definition: cdc.h:267
usb_desc_cdcecm_speed_t
USB CDC ECM connection speed change notification.
Definition: cdc.h:266
usb.h
Definition of global compile time configuration options.
usb_desc_union_t::length
uint8_t length
Size of this descriptor.
Definition: cdc.h:241
usb_desc_cdc_t::subtype
uint8_t subtype
Descriptor subtype (usb_cdc_subtype)
Definition: cdc.h:233
usb_desc_call_mngt_t::subtype
uint8_t subtype
Descriptor subtype (USB_CDC_DESCR_SUBTYPE_CALL_MGMT)
Definition: cdc.h:256
usb_desc_cdcecm_speed_t::up
uint32_t up
Uplink bit rate.
Definition: cdc.h:269
usb_desc_ecm_t::ethernetstatistics
uint32_t ethernetstatistics
Bitmap indicating the statistics caps.
Definition: cdc.h:207
usb_desc_ecm_t::numbermcfilters
uint16_t numbermcfilters
Number of configurable multicast filters.
Definition: cdc.h:209
usb_desc_union_t::subtype
uint8_t subtype
Descriptor subtype (USB_CDC_DESCR_SUBTYPE_UNION)
Definition: cdc.h:243
usb_desc_ecm_t::macaddress
uint8_t macaddress
Index of the string containing the ethernet MAC address.
Definition: cdc.h:206
usb_desc_union_t::slave_if
uint8_t slave_if
Slave/subordinate interface number.
Definition: cdc.h:245
usb_desc_ecm_t
USB CDC ECM descriptor.
Definition: cdc.h:202
usb_req_cdcacm_coding_t::parity
uint8_t parity
Parity settings
Definition: cdc.h:284
usb_desc_union_t
USB union descriptor.
Definition: cdc.h:240
usb_desc_ecm_t::length
uint8_t length
Size of this descriptor.
Definition: cdc.h:203
usb_desc_cdc_t::length
uint8_t length
Size of this descriptor.
Definition: cdc.h:231
usb_desc_cdc_t::type
uint8_t type
Descriptor type (USB_TYPE_DESCRIPTOR_CDC)
Definition: cdc.h:232
usb_desc_acm_t::capabalities
uint8_t capabalities
Bitmap indicating the capabilities.
Definition: cdc.h:222
usb_desc_call_mngt_t::data_if
uint8_t data_if
Interface number used for the call management.
Definition: cdc.h:258
descriptor.h
Definitions for USB protocol messages.