cdc_acm_descriptor.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*
  2. * Copyright (c) 2019 Actions Corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief CDC ACM descriptors (Device, Configuration, Interface ...)
  9. */
  10. #ifndef __CDC_ACM_DESC_H__
  11. #define __CDC_ACM_DESC_H__
  12. #include <usb/usb_common.h>
  13. #include <usb/class/usb_cdc.h>
  14. /* Size in bytes of the configuration sent to
  15. * the Host on GetConfiguration() request
  16. * For Communication Device: CONF + IAD + (2 x ITF) +
  17. * (3 x EP) + HF + CMF + ACMF + UF -> 75 bytes
  18. */
  19. #define CDC_CONF_SIZE (USB_CONFIGURATION_DESC_SIZE + 8 + \
  20. (2 * USB_INTERFACE_DESC_SIZE) + (3 * USB_ENDPOINT_DESC_SIZE) + 19)
  21. #define USB_DEVICE_VID 0x10D6
  22. #define USB_DEVICE_PID 0xB00A
  23. /* Misc. macros */
  24. #define LOW_BYTE(x) ((x) & 0xFF)
  25. #define HIGH_BYTE(x) ((x) >> 8)
  26. /* high-speed */
  27. #define HS_BULK_EP_MPS 512
  28. #define HS_INTERRUPT_EP_MPS CONFIG_CDC_ACM_INTERRUPT_EP_MPS
  29. /* Structure representing the global USB description */
  30. static const u8_t cdc_acm_usb_fs_descriptor[] = {
  31. /* Device descriptor */
  32. USB_DEVICE_DESC_SIZE, /* Descriptor size */
  33. USB_DEVICE_DESC, /* Descriptor type */
  34. LOW_BYTE(USB_2_0),
  35. HIGH_BYTE(USB_2_0), /* USB version in BCD format */
  36. COMMUNICATION_DEVICE_CLASS, /* Class */
  37. 0x00, /* SubClass - Interface specific */
  38. 0x00, /* Protocol - Interface specific */
  39. MAX_PACKET_SIZE0, /* Max Packet Size */
  40. /* Vendor Id */
  41. LOW_BYTE(USB_DEVICE_VID),
  42. HIGH_BYTE(USB_DEVICE_VID),
  43. /* Product Id */
  44. LOW_BYTE(USB_DEVICE_PID),
  45. HIGH_BYTE(USB_DEVICE_PID),
  46. LOW_BYTE(BCDDEVICE_RELNUM),
  47. HIGH_BYTE(BCDDEVICE_RELNUM), /* Device Release Number */
  48. /* Index of Manufacturer String Descriptor */
  49. 0x01,
  50. /* Index of Product String Descriptor */
  51. 0x02,
  52. /* Index of Serial Number String Descriptor */
  53. 0x03,
  54. /* Number of Possible Configuration */
  55. 0x01,
  56. /* Configuration descriptor */
  57. USB_CONFIGURATION_DESC_SIZE, /* Descriptor size */
  58. USB_CONFIGURATION_DESC, /* Descriptor type */
  59. /* Total length in bytes of data returned */
  60. LOW_BYTE(CDC_CONF_SIZE),
  61. HIGH_BYTE(CDC_CONF_SIZE),
  62. 0x02, /* Number of interfaces */
  63. 0x01, /* Configuration value */
  64. 0x00, /* Index of the Configuration string */
  65. USB_CONFIGURATION_ATTRIBUTES, /* Attributes */
  66. MAX_LOW_POWER, /* Max power consumption */
  67. /* Association descriptor */
  68. /* Descriptor size */
  69. sizeof(struct usb_association_descriptor),
  70. USB_ASSOCIATION_DESC, /* Descriptor type */
  71. 0x00, /* The first interface number */
  72. 0x02, /* Number of interfaces */
  73. COMMUNICATION_DEVICE_CLASS, /* Function Class */
  74. ACM_SUBCLASS, /* Function SubClass */
  75. V25TER_PROTOCOL, /* Function Protocol */
  76. /* Index of the Interface String Descriptor */
  77. 0x00,
  78. /* Interface descriptor */
  79. USB_INTERFACE_DESC_SIZE, /* Descriptor size */
  80. USB_INTERFACE_DESC, /* Descriptor type */
  81. 0x00, /* Interface index */
  82. 0x00, /* Alternate setting */
  83. 0x01, /* Number of Endpoints */
  84. COMMUNICATION_DEVICE_CLASS, /* Class */
  85. ACM_SUBCLASS, /* SubClass */
  86. V25TER_PROTOCOL, /* Protocol */
  87. /* Index of the Interface String Descriptor */
  88. 0x00,
  89. /* Header Functional Descriptor */
  90. /* Descriptor size */
  91. sizeof(struct cdc_header_descriptor),
  92. CS_INTERFACE, /* Descriptor type */
  93. HEADER_FUNC_DESC, /* Descriptor SubType */
  94. LOW_BYTE(USB_1_1),
  95. HIGH_BYTE(USB_1_1), /* CDC Device Release Number */
  96. /* Call Management Functional Descriptor */
  97. /* Descriptor size */
  98. sizeof(struct cdc_cm_descriptor),
  99. CS_INTERFACE, /* Descriptor type */
  100. CALL_MANAGEMENT_FUNC_DESC, /* Descriptor SubType */
  101. 0x02, /* Capabilities */
  102. 0x01, /* Data Interface */
  103. /* ACM Functional Descriptor */
  104. /* Descriptor size */
  105. sizeof(struct cdc_acm_descriptor),
  106. CS_INTERFACE, /* Descriptor type */
  107. ACM_FUNC_DESC, /* Descriptor SubType */
  108. /* Capabilities - Device supports the request combination of:
  109. * Set_Line_Coding,
  110. * Set_Control_Line_State,
  111. * Get_Line_Coding
  112. * and the notification Serial_State
  113. */
  114. 0x02,
  115. /* Union Functional Descriptor */
  116. /* Descriptor size */
  117. sizeof(struct cdc_union_descriptor),
  118. CS_INTERFACE, /* Descriptor type */
  119. UNION_FUNC_DESC, /* Descriptor SubType */
  120. 0x00, /* Master Interface */
  121. 0x01, /* Slave Interface */
  122. /* Endpoint INT */
  123. USB_ENDPOINT_DESC_SIZE, /* Descriptor size */
  124. USB_ENDPOINT_DESC, /* Descriptor type */
  125. /* Endpoint address */
  126. CONFIG_CDC_ACM_INTERRUPT_EP_ADDR,
  127. USB_DC_EP_INTERRUPT, /* Attributes */
  128. /* Max packet size */
  129. LOW_BYTE(CONFIG_CDC_ACM_INTERRUPT_EP_MPS),
  130. HIGH_BYTE(CONFIG_CDC_ACM_INTERRUPT_EP_MPS),
  131. /* Interval */
  132. CONFIG_CDC_ACM_INTERRUPT_EP_INTERVAL,
  133. /* Interface descriptor */
  134. USB_INTERFACE_DESC_SIZE, /* Descriptor size */
  135. USB_INTERFACE_DESC, /* Descriptor type */
  136. 0x01, /* Interface index */
  137. 0x00, /* Alternate setting */
  138. 0x02, /* Number of Endpoints */
  139. COMMUNICATION_DEVICE_CLASS_DATA,/* Class */
  140. 0x00, /* SubClass */
  141. 0x00, /* Protocol */
  142. /* Index of the Interface String Descriptor */
  143. 0x00,
  144. /* First Endpoint IN */
  145. USB_ENDPOINT_DESC_SIZE, /* Descriptor size */
  146. USB_ENDPOINT_DESC, /* Descriptor type */
  147. CONFIG_CDC_ACM_BULK_IN_EP_ADDR, /* Endpoint address */
  148. USB_DC_EP_BULK, /* Attributes */
  149. /* Max packet size */
  150. LOW_BYTE(CONFIG_CDC_ACM_BULK_EP_MPS),
  151. HIGH_BYTE(CONFIG_CDC_ACM_BULK_EP_MPS),
  152. 0x00, /* Interval */
  153. /* Second Endpoint OUT */
  154. USB_ENDPOINT_DESC_SIZE, /* Descriptor size */
  155. USB_ENDPOINT_DESC, /* Descriptor type */
  156. CONFIG_CDC_ACM_BULK_OUT_EP_ADDR,/* Endpoint address */
  157. USB_DC_EP_BULK, /* Attributes */
  158. /* Max packet size */
  159. LOW_BYTE(CONFIG_CDC_ACM_BULK_EP_MPS),
  160. HIGH_BYTE(CONFIG_CDC_ACM_BULK_EP_MPS),
  161. 0x00, /* Interval */
  162. };
  163. static const u8_t cdc_acm_usb_hs_descriptor[] = {
  164. /* Device descriptor */
  165. USB_DEVICE_DESC_SIZE, /* Descriptor size */
  166. USB_DEVICE_DESC, /* Descriptor type */
  167. LOW_BYTE(USB_2_0),
  168. HIGH_BYTE(USB_2_0), /* USB version in BCD format */
  169. COMMUNICATION_DEVICE_CLASS, /* Class */
  170. 0x00, /* SubClass - Interface specific */
  171. 0x00, /* Protocol - Interface specific */
  172. MAX_PACKET_SIZE0, /* Max Packet Size */
  173. /* Vendor Id */
  174. LOW_BYTE(USB_DEVICE_VID),
  175. HIGH_BYTE(USB_DEVICE_VID),
  176. /* Product Id */
  177. LOW_BYTE(USB_DEVICE_PID),
  178. HIGH_BYTE(USB_DEVICE_PID),
  179. LOW_BYTE(BCDDEVICE_RELNUM),
  180. HIGH_BYTE(BCDDEVICE_RELNUM), /* Device Release Number */
  181. /* Index of Manufacturer String Descriptor */
  182. 0x01,
  183. /* Index of Product String Descriptor */
  184. 0x02,
  185. /* Index of Serial Number String Descriptor */
  186. 0x03,
  187. /* Number of Possible Configuration */
  188. 0x01,
  189. /* Configuration descriptor */
  190. USB_CONFIGURATION_DESC_SIZE, /* Descriptor size */
  191. USB_CONFIGURATION_DESC, /* Descriptor type */
  192. /* Total length in bytes of data returned */
  193. LOW_BYTE(CDC_CONF_SIZE),
  194. HIGH_BYTE(CDC_CONF_SIZE),
  195. 0x02, /* Number of interfaces */
  196. 0x01, /* Configuration value */
  197. 0x00, /* Index of the Configuration string */
  198. USB_CONFIGURATION_ATTRIBUTES, /* Attributes */
  199. MAX_LOW_POWER, /* Max power consumption */
  200. /* Association descriptor */
  201. /* Descriptor size */
  202. sizeof(struct usb_association_descriptor),
  203. USB_ASSOCIATION_DESC, /* Descriptor type */
  204. 0x00, /* The first interface number */
  205. 0x02, /* Number of interfaces */
  206. COMMUNICATION_DEVICE_CLASS, /* Function Class */
  207. ACM_SUBCLASS, /* Function SubClass */
  208. V25TER_PROTOCOL, /* Function Protocol */
  209. /* Index of the Interface String Descriptor */
  210. 0x00,
  211. /* Interface descriptor */
  212. USB_INTERFACE_DESC_SIZE, /* Descriptor size */
  213. USB_INTERFACE_DESC, /* Descriptor type */
  214. 0x00, /* Interface index */
  215. 0x00, /* Alternate setting */
  216. 0x01, /* Number of Endpoints */
  217. COMMUNICATION_DEVICE_CLASS, /* Class */
  218. ACM_SUBCLASS, /* SubClass */
  219. V25TER_PROTOCOL, /* Protocol */
  220. /* Index of the Interface String Descriptor */
  221. 0x00,
  222. /* Header Functional Descriptor */
  223. /* Descriptor size */
  224. sizeof(struct cdc_header_descriptor),
  225. CS_INTERFACE, /* Descriptor type */
  226. HEADER_FUNC_DESC, /* Descriptor SubType */
  227. LOW_BYTE(USB_1_1),
  228. HIGH_BYTE(USB_1_1), /* CDC Device Release Number */
  229. /* Call Management Functional Descriptor */
  230. /* Descriptor size */
  231. sizeof(struct cdc_cm_descriptor),
  232. CS_INTERFACE, /* Descriptor type */
  233. CALL_MANAGEMENT_FUNC_DESC, /* Descriptor SubType */
  234. 0x02, /* Capabilities */
  235. 0x01, /* Data Interface */
  236. /* ACM Functional Descriptor */
  237. /* Descriptor size */
  238. sizeof(struct cdc_acm_descriptor),
  239. CS_INTERFACE, /* Descriptor type */
  240. ACM_FUNC_DESC, /* Descriptor SubType */
  241. /* Capabilities - Device supports the request combination of:
  242. * Set_Line_Coding,
  243. * Set_Control_Line_State,
  244. * Get_Line_Coding
  245. * and the notification Serial_State
  246. */
  247. 0x02,
  248. /* Union Functional Descriptor */
  249. /* Descriptor size */
  250. sizeof(struct cdc_union_descriptor),
  251. CS_INTERFACE, /* Descriptor type */
  252. UNION_FUNC_DESC, /* Descriptor SubType */
  253. 0x00, /* Master Interface */
  254. 0x01, /* Slave Interface */
  255. /* Endpoint INT */
  256. USB_ENDPOINT_DESC_SIZE, /* Descriptor size */
  257. USB_ENDPOINT_DESC, /* Descriptor type */
  258. /* Endpoint address */
  259. CONFIG_CDC_ACM_INTERRUPT_EP_ADDR,
  260. USB_DC_EP_INTERRUPT, /* Attributes */
  261. /* Max packet size */
  262. LOW_BYTE(HS_INTERRUPT_EP_MPS),
  263. HIGH_BYTE(HS_INTERRUPT_EP_MPS),
  264. /* Interval */
  265. CONFIG_CDC_ACM_HS_INTERRUPT_EP_INTERVAL,
  266. /* Interface descriptor */
  267. USB_INTERFACE_DESC_SIZE, /* Descriptor size */
  268. USB_INTERFACE_DESC, /* Descriptor type */
  269. 0x01, /* Interface index */
  270. 0x00, /* Alternate setting */
  271. 0x02, /* Number of Endpoints */
  272. COMMUNICATION_DEVICE_CLASS_DATA,/* Class */
  273. 0x00, /* SubClass */
  274. 0x00, /* Protocol */
  275. /* Index of the Interface String Descriptor */
  276. 0x00,
  277. /* First Endpoint IN */
  278. USB_ENDPOINT_DESC_SIZE, /* Descriptor size */
  279. USB_ENDPOINT_DESC, /* Descriptor type */
  280. CONFIG_CDC_ACM_BULK_IN_EP_ADDR, /* Endpoint address */
  281. USB_DC_EP_BULK, /* Attributes */
  282. /* Max packet size */
  283. LOW_BYTE(HS_BULK_EP_MPS),
  284. HIGH_BYTE(HS_BULK_EP_MPS),
  285. 0x00, /* Interval */
  286. /* Second Endpoint OUT */
  287. USB_ENDPOINT_DESC_SIZE, /* Descriptor size */
  288. USB_ENDPOINT_DESC, /* Descriptor type */
  289. CONFIG_CDC_ACM_BULK_OUT_EP_ADDR,/* Endpoint address */
  290. USB_DC_EP_BULK, /* Attributes */
  291. /* Max packet size */
  292. LOW_BYTE(HS_BULK_EP_MPS),
  293. HIGH_BYTE(HS_BULK_EP_MPS),
  294. 0x00, /* Interval */
  295. };
  296. #endif /* __CDC_ACM_DESC_H__ */