usb_cdc.h 4.5 KB

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