diff --git a/sys/include/usb/cdc.h b/sys/include/usb/cdc.h new file mode 100644 index 0000000000..51d2e71464 --- /dev/null +++ b/sys/include/usb/cdc.h @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2018 Dylan Laduranty + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for + * more details. + */ + +/** + * @defgroup usb_cdc CDC - USB communications device class + * @ingroup usb + * @brief Generic USB CDC defines and helpers + * + * @{ + * + * @file + * @brief Definition for USB CDC interfaces + * + * @author Dylan Laduranty + * @author Koen Zandberg + */ + +#ifndef USB_CDC_H +#define USB_CDC_H + +#include + +#include "usb.h" +#include "usb/descriptor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define USB_TYPE_DESCRIPTOR_CDC 0x24 /**< USB CDC type descriptor*/ +#define USB_CDC_VERSION_BCD 0x0120 /**< USB CDC version in BCD */ + +/** + * @name USB CDC subclass types + * @anchor usb_cdc_subtype + * @{ + */ +#define USB_CDC_SUBCLASS_NONE 0x00 /**< No subclass */ +#define USB_CDC_SUBCLASS_DLCM 0x01 /**< Direct Line Control Model */ +#define USB_CDC_SUBCLASS_ACM 0x02 /**< Abstract Control Model */ +#define USB_CDC_SUBCLASS_TCM 0x03 /**< Telephone Control Model */ +#define USB_CDC_SUBCLASS_MCCM 0x04 /**< Multi-Channel Control Model */ +#define USB_CDC_SUBCLASS_CCM 0x05 /**< CAPI Control Mode */ +#define USB_CDC_SUBCLASS_ENCM 0x06 /**< Eth Networking Control Model */ +#define USB_CDC_SUBCLASS_ANCM 0x07 /**< ATM Networking Control Model */ +#define USB_CDC_SUBCLASS_WHCM 0x08 /**< Wireless Handset Control Model */ +#define USB_CDC_SUBCLASS_DM 0x09 /**< Device Management */ +#define USB_CDC_SUBCLASS_MDLM 0x0A /**< Mobile Direct Line Model */ +#define USB_CDC_SUBCLASS_OBEX 0x0B /**< OBEX */ +#define USB_CDC_SUBCLASS_EEM 0x0C /**< Ethernet Emulation Model */ +#define USB_CDC_SUBCLASS_NCM 0x0D /**< Network Control Model */ +/** @} */ + +/** + * @name USB CDC protocol types + * @{ + */ +#define USB_CDC_PROTOCOL_NONE 0x00 /**< No protocol required */ +#define USB_CDC_PROTOCOL_ITU 0x01 /**< AT Commands: V.250 etc */ +#define USB_CDC_PROTOCOL_PCCA 0x02 /**< AT Commands defined by PCCA-101 */ +#define USB_CDC_PROTOCOL_PCCA_A 0x03 /**< AT Commands defined by PCCA-101 & Annex O */ +#define USB_CDC_PROTOCOL_GSM 0x04 /**< AT Commands defined by GSM 07.07 */ +#define USB_CDC_PROTOCOL_3GPP 0x05 /**< AT Commands defined by 3GPP 27.007 */ +#define USB_CDC_PROTOCOL_CS 0x06 /**< AT Commands defined by TIA for CDMA */ +#define USB_CDC_PROTOCOL_EEM 0x07 /**< Ethernet Emulation Model */ +#define USB_CDC_PROTOCOL_EXT 0xFE /**< External Protocol */ +#define USB_CDC_PROTOCOL_VENDOR 0xFF /**< Vendor-specific */ +/** @} */ + +/** + * @name USB CDC descriptor subtypes + */ +#define USB_CDC_DESCR_SUBTYPE_FUNCTIONAL 0x00 /**< Header functional + * descriptor */ +#define USB_CDC_DESCR_SUBTYPE_CALL_MGMT 0x01 /**< Call management + descriptor */ +#define USB_CDC_DESCR_SUBTYPE_ACM 0x02 /**< Abstract control + management descriptor */ +#define USB_CDC_DESCR_SUBTYPE_UNION 0x06 /**< Union descriptor */ +#define USB_CDC_DESCR_SUBTYPE_ETH_NET 0x0f /**< Ethernet descriptor */ +/** @} */ + +/** + * @name USB CDC management requests + * @{ + */ + +/** + * @brief Set ethernet multicast filter request + */ +#define USB_CDC_MGNT_REQUEST_SET_ETH_MULTICAST_FILTER 0x40 + +/** + * @brief Set ethernet power management pattern filter + */ +#define USB_CDC_MGNT_REQUEST_SET_ETH_PM_PATTERN_FILTER 0x41 + +/** + * @brief Get ethernet power management pattern filter + */ +#define USB_CDC_MGNT_REQUEST_GET_ETH_PM_PATTERN_FILTER 0x42 + +/** + * @brief Set ethernet packet filter + */ +#define USB_CDC_MGNT_REQUEST_SET_ETH_PACKET_FILTER 0x43 + +/** + * @brief Get ethernet statistics + */ +#define USB_CDC_MGNT_REQUEST_GET_ETH_STATISTICS 0x44 +/** @} */ + +/** + * @name USB CDC management notifications + * @{ + */ + +/** + * @brief Network connection status notification + */ +#define USB_CDC_MGNT_NOTIF_NETWORK_CONNECTION 0x00 + +/** + * @brief Response available notification + */ +#define USB_CDC_MGNT_NOTIF_RESPONSE_AVAILABLE 0x01 + +/** + * @brief Hook on the auxiliary phone changed notification + */ +#define USB_CDC_MGNT_NOTIF_AUX_JACK_HOOK_STATE 0x08 + +/** + * @brief Ring voltage on the POTS line interface notification + */ +#define USB_CDC_MGNT_NOTIF_RING_DETECT 0x09 + +/** + * @brief Asynchronous UART status notification + */ +#define USB_CDC_MGNT_NOTIF_SERIAL_STATE 0x20 + +/** + * @brief Call state change notification + */ +#define USB_CDC_MGNT_NOTIF_CALL_STATE_CHANGE 0x28 + +/** + * @brief Line state change notification + */ +#define USB_CDC_MGNT_NOTIF_LINE_STATE_CHANGE 0x29 + +/** + * @brief Throughput change notification + */ +#define USB_CDC_MGNT_NOTIF_CONN_SPEED_CHANGE 0x2A + +/** @} */ + +/** + * @brief USB CDC ECM descriptor + * + * @see USB CDC 1.2 ECM spec table 3 + */ +typedef struct __attribute__((packed)) { + uint8_t length; /**< Size of this descriptor */ + uint8_t type; /**< Descriptor type (@ref USB_TYPE_DESCRIPTOR_CDC) */ + uint8_t subtype; /**< Descriptor subtype (@ref USB_CDC_DESCR_SUBTYPE_ETH_NET) */ + uint8_t macaddress; /**< Index of the string containing the ethernet MAC address */ + uint32_t ethernetstatistics; /**< Bitmap indicating the statistics caps */ + uint16_t maxsegmentsize; /**< Maximum segment size of the interface */ + uint16_t numbermcfilters; /**< Number of configurable multicast filters */ + uint8_t numberpowerfilters; /**< Number of pattern filters for host wake-up */ +} usb_desc_ecm_t; + +/** + * @brief USB CDC ACM descriptor + * + * @see USB CDC 1.2 PTSN spec table 4 + */ +typedef struct __attribute__((packed)) { + uint8_t length; /**< Size of this descriptor */ + uint8_t type; /**< Descriptor type (@ref USB_TYPE_DESCRIPTOR_CDC) */ + uint8_t subtype; /**< Descriptor subtype (@ref USB_CDC_DESCR_SUBTYPE_ACM) */ + uint8_t capabalities; /**< Bitmap indicating the capabilities */ +} usb_desc_acm_t; + +/** + * @brief Generic USB CDC descriptor + * + * @see USB CDC 1.2 spec table 15 + */ +typedef struct __attribute__((packed)) { + uint8_t length; /**< Size of this descriptor */ + uint8_t type; /**< Descriptor type (@ref USB_TYPE_DESCRIPTOR_CDC) */ + uint8_t subtype; /**< Descriptor subtype (@ref usb_cdc_subtype) */ + uint16_t bcd_cdc; /**< CDC release number in bcd (@ref USB_CDC_VERSION_BCD) */ +} usb_desc_cdc_t; + +/** + * @brief USB union descriptor + */ +typedef struct __attribute__((packed)) { + uint8_t length; /**< Size of this descriptor */ + uint8_t type; /**< Descriptor type (@ref USB_TYPE_DESCRIPTOR_CDC) */ + uint8_t subtype; /**< Descriptor subtype (@ref USB_CDC_DESCR_SUBTYPE_UNION) */ + uint8_t master_if; /**< Master/controlling interface number */ + uint8_t slave_if; /**< Slave/subordinate interface number */ +} usb_desc_union_t; + +/** + * @brief USB CDC call management functional descriptor + * + * @see USB CDC 1.2 PSTN spec table 13 + */ +typedef struct __attribute__((packed)) { + uint8_t length; /**< Size of this descriptor */ + uint8_t type; /**< Descriptor type (@ref USB_TYPE_DESCRIPTOR_CDC) */ + uint8_t subtype; /**< Descriptor subtype (@ref USB_CDC_DESCR_SUBTYPE_CALL_MGMT) */ + uint8_t capabalities; /**< Supported capabilities */ + uint8_t data_if; /**< Interface number used for the call management */ +} usb_desc_call_mngt_t; + +/** + * @brief USB CDC ECM connection speed change notification + * + * @see USB CDC 1.2 spec section 6.3.3 + */ +typedef struct __attribute__((packed)) { + usb_setup_t setup; /**< Setup request header for the notification */ + uint32_t down; /**< Downlink bit rate */ + uint32_t up; /**< Uplink bit rate */ +} usb_desc_cdcecm_speed_t; + +#ifdef __cplusplus +} +#endif + +#endif /* USB_CDC_H */ +/** @} */