usb_cdc.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* $NetBSD: usbcdc.h,v 1.9 2004/10/23 13:24:24 augustss Exp $ */
  2. /* $FreeBSD$ */
  3. /*-
  4. * Copyright (c) 1998 The NetBSD Foundation, Inc.
  5. * All rights reserved.
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Lennart Augustsson (lennart@augustsson.net) at
  9. * Carlstedt Research & Technology.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  24. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. * POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef _USB_CDC_H_
  33. #define _USB_CDC_H_
  34. #include <stdint.h>
  35. #define UDESCSUB_CDC_HEADER 0
  36. #define UDESCSUB_CDC_CM 1 /* Call Management */
  37. #define UDESCSUB_CDC_ACM 2 /* Abstract Control Model */
  38. #define UDESCSUB_CDC_DLM 3 /* Direct Line Management */
  39. #define UDESCSUB_CDC_TRF 4 /* Telephone Ringer */
  40. #define UDESCSUB_CDC_TCLSR 5 /* Telephone Call */
  41. #define UDESCSUB_CDC_UNION 6
  42. #define UDESCSUB_CDC_CS 7 /* Country Selection */
  43. #define UDESCSUB_CDC_TOM 8 /* Telephone Operational Modes */
  44. #define UDESCSUB_CDC_USBT 9 /* USB Terminal */
  45. #define UDESCSUB_CDC_NCT 10
  46. #define UDESCSUB_CDC_PUF 11
  47. #define UDESCSUB_CDC_EUF 12
  48. #define UDESCSUB_CDC_MCMF 13
  49. #define UDESCSUB_CDC_CCMF 14
  50. #define UDESCSUB_CDC_ENF 15 /* ethernet desc */
  51. #define UDESCSUB_CDC_ANF 16
  52. #define UCDC_PROTO_NONE 0
  53. #define UCDC_ACM_PROTO_AT_V25TER 1
  54. #define UCDC_ACM_PROTO_AT_PCCA101 2
  55. #define UCDC_ACM_PROTO_AT_PCCA101_WAKE 3
  56. #define UCDC_ACM_PROTO_AT_GSM 4
  57. #define UCDC_ACM_PROTO_AT_3G 5
  58. #define UCDC_ACM_PROTO_AT_CDMA 6
  59. #define UCDC_ACM_PROTO_VENDOR 0xff
  60. #define USB_CDC_PROTO_EEM 7
  61. #define USB_CDC_NCM_PROTO_NTB 1
  62. #define USB_CDC_MBIM_PROTO_NTB 2
  63. struct usb_cdc_header_descriptor {
  64. uint8_t bLength;
  65. uint8_t bDescriptorType;
  66. uint8_t bDescriptorSubtype;
  67. uint16_t bcdCDC;
  68. } __attribute__((packed));
  69. struct usb_cdc_cm_descriptor {
  70. uint8_t bLength;
  71. uint8_t bDescriptorType;
  72. uint8_t bDescriptorSubtype;
  73. uint8_t bmCapabilities;
  74. #define USB_CDC_CM_DOES_CM 0x01
  75. #define USB_CDC_CM_OVER_DATA 0x02
  76. uint8_t bDataInterface;
  77. } __attribute__((packed));
  78. struct usb_cdc_acm_descriptor {
  79. uint8_t bLength;
  80. uint8_t bDescriptorType;
  81. uint8_t bDescriptorSubtype;
  82. uint8_t bmCapabilities;
  83. #define USB_CDC_ACM_HAS_FEATURE 0x01
  84. #define USB_CDC_ACM_HAS_LINE 0x02
  85. #define USB_CDC_ACM_HAS_BREAK 0x04
  86. #define USB_CDC_ACM_HAS_NETWORK_CONN 0x08
  87. } __attribute__((packed));
  88. struct usb_cdc_union_descriptor {
  89. uint8_t bLength;
  90. uint8_t bDescriptorType;
  91. uint8_t bDescriptorSubtype;
  92. uint8_t bMasterInterface;
  93. uint8_t bSlaveInterface[1];
  94. } __attribute__((packed));
  95. struct usb_cdc_ethernet_descriptor {
  96. uint8_t bLength;
  97. uint8_t bDescriptorType;
  98. uint8_t bDescriptorSubtype;
  99. uint8_t iMacAddress;
  100. uint32_t bmEthernetStatistics;
  101. uint16_t wMaxSegmentSize;
  102. uint16_t wNumberMCFilters;
  103. uint8_t bNumberPowerFilters;
  104. } __attribute__((packed));
  105. #define UCDC_SEND_ENCAPSULATED_COMMAND 0x00
  106. #define UCDC_GET_ENCAPSULATED_RESPONSE 0x01
  107. #define UCDC_SET_COMM_FEATURE 0x02
  108. #define UCDC_GET_COMM_FEATURE 0x03
  109. #define UCDC_ABSTRACT_STATE 0x01
  110. #define UCDC_COUNTRY_SETTING 0x02
  111. #define UCDC_CLEAR_COMM_FEATURE 0x04
  112. #define UCDC_SET_LINE_CODING 0x20
  113. #define UCDC_GET_LINE_CODING 0x21
  114. #define UCDC_SET_CONTROL_LINE_STATE 0x22
  115. #define UCDC_LINE_DTR 0x0001
  116. #define UCDC_LINE_RTS 0x0002
  117. #define UCDC_SEND_BREAK 0x23
  118. #define UCDC_BREAK_ON 0xffff
  119. #define UCDC_BREAK_OFF 0x0000
  120. struct usb_cdc_abstract_state {
  121. uint16_t wState;
  122. #define UCDC_IDLE_SETTING 0x0001
  123. #define UCDC_DATA_MULTIPLEXED 0x0002
  124. } __attribute__((packed));
  125. #define UCDC_ABSTRACT_STATE_LENGTH 2
  126. struct usb_cdc_line_state {
  127. uint32_t dwDTERate;
  128. uint8_t bCharFormat;
  129. #define UCDC_STOP_BIT_1 0
  130. #define UCDC_STOP_BIT_1_5 1
  131. #define UCDC_STOP_BIT_2 2
  132. uint8_t bParityType;
  133. #define UCDC_PARITY_NONE 0
  134. #define UCDC_PARITY_ODD 1
  135. #define UCDC_PARITY_EVEN 2
  136. #define UCDC_PARITY_MARK 3
  137. #define UCDC_PARITY_SPACE 4
  138. uint8_t bDataBits;
  139. } __attribute__((packed));
  140. #define UCDC_LINE_STATE_LENGTH 7
  141. struct usb_cdc_notification {
  142. uint8_t bmRequestType;
  143. #define UCDC_NOTIFICATION 0xa1
  144. uint8_t bNotification;
  145. #define UCDC_N_NETWORK_CONNECTION 0x00
  146. #define UCDC_N_RESPONSE_AVAILABLE 0x01
  147. #define UCDC_N_AUX_JACK_HOOK_STATE 0x08
  148. #define UCDC_N_RING_DETECT 0x09
  149. #define UCDC_N_SERIAL_STATE 0x20
  150. #define UCDC_N_CALL_STATE_CHANGED 0x28
  151. #define UCDC_N_LINE_STATE_CHANGED 0x29
  152. #define UCDC_N_CONNECTION_SPEED_CHANGE 0x2a
  153. uint16_t wValue;
  154. uint16_t wIndex;
  155. uint16_t wLength;
  156. uint8_t data[16];
  157. } __attribute__((packed));
  158. #define UCDC_NOTIFICATION_LENGTH 8
  159. /*
  160. * Bits set in the SERIAL STATE notification (first byte of data)
  161. */
  162. #define UCDC_N_SERIAL_OVERRUN 0x40
  163. #define UCDC_N_SERIAL_PARITY 0x20
  164. #define UCDC_N_SERIAL_FRAMING 0x10
  165. #define UCDC_N_SERIAL_RI 0x08
  166. #define UCDC_N_SERIAL_BREAK 0x04
  167. #define UCDC_N_SERIAL_DSR 0x02
  168. #define UCDC_N_SERIAL_DCD 0x01
  169. /* Serial state bit masks */
  170. #define UCDC_MDM_RXCARRIER 0x01
  171. #define UCDC_MDM_TXCARRIER 0x02
  172. #define UCDC_MDM_BREAK 0x04
  173. #define UCDC_MDM_RING 0x08
  174. #define UCDC_MDM_FRAMING_ERR 0x10
  175. #define UCDC_MDM_PARITY_ERR 0x20
  176. #define UCDC_MDM_OVERRUN_ERR 0x40
  177. /*
  178. * Network Control Model, NCM16 + NCM32, protocol definitions
  179. */
  180. struct usb_ncm16_hdr {
  181. uint32_t dwSignature;
  182. uint16_t wHeaderLength;
  183. uint16_t wSequence;
  184. uint16_t wBlockLength;
  185. uint16_t wDptIndex;
  186. } __attribute__((packed));
  187. struct usb_ncm16_dp {
  188. uint16_t wFrameIndex;
  189. uint16_t wFrameLength;
  190. } __attribute__((packed));
  191. struct usb_ncm16_dpt {
  192. uint32_t dwSignature;
  193. uint16_t wLength;
  194. uint16_t wNextNdpIndex;
  195. struct usb_ncm16_dp dp[0];
  196. } __attribute__((packed));
  197. struct usb_ncm32_hdr {
  198. uint32_t dwSignature;
  199. uint16_t wHeaderLength;
  200. uint16_t wSequence;
  201. uint32_t dwBlockLength;
  202. uint32_t dwDptIndex;
  203. } __attribute__((packed));
  204. struct usb_ncm32_dp {
  205. uint32_t dwFrameIndex;
  206. uint32_t dwFrameLength;
  207. } __attribute__((packed));
  208. struct usb_ncm32_dpt {
  209. uint32_t dwSignature;
  210. uint16_t wLength;
  211. uint16_t wReserved6;
  212. uint32_t dwNextNdpIndex;
  213. uint32_t dwReserved12;
  214. struct usb_ncm32_dp dp[0];
  215. } __attribute__((packed));
  216. /* Communications interface class specific descriptors */
  217. #define UCDC_NCM_FUNC_DESC_SUBTYPE 0x1A
  218. struct usb_ncm_func_descriptor {
  219. uint8_t bLength;
  220. uint8_t bDescriptorType;
  221. uint8_t bDescriptorSubtype;
  222. uint8_t bcdNcmVersion[2];
  223. uint8_t bmNetworkCapabilities;
  224. #define UCDC_NCM_CAP_FILTER 0x01
  225. #define UCDC_NCM_CAP_MAC_ADDR 0x02
  226. #define UCDC_NCM_CAP_ENCAP 0x04
  227. #define UCDC_NCM_CAP_MAX_DATA 0x08
  228. #define UCDC_NCM_CAP_CRCMODE 0x10
  229. #define UCDC_NCM_CAP_MAX_DGRAM 0x20
  230. } __attribute__((packed));
  231. /* Communications interface specific class request codes */
  232. #define UCDC_NCM_SET_ETHERNET_MULTICAST_FILTERS 0x40
  233. #define UCDC_NCM_SET_ETHERNET_POWER_MGMT_PATTERN_FILTER 0x41
  234. #define UCDC_NCM_GET_ETHERNET_POWER_MGMT_PATTERN_FILTER 0x42
  235. #define UCDC_NCM_SET_ETHERNET_PACKET_FILTER 0x43
  236. #define UCDC_NCM_GET_ETHERNET_STATISTIC 0x44
  237. #define UCDC_NCM_GET_NTB_PARAMETERS 0x80
  238. #define UCDC_NCM_GET_NET_ADDRESS 0x81
  239. #define UCDC_NCM_SET_NET_ADDRESS 0x82
  240. #define UCDC_NCM_GET_NTB_FORMAT 0x83
  241. #define UCDC_NCM_SET_NTB_FORMAT 0x84
  242. #define UCDC_NCM_GET_NTB_INPUT_SIZE 0x85
  243. #define UCDC_NCM_SET_NTB_INPUT_SIZE 0x86
  244. #define UCDC_NCM_GET_MAX_DATAGRAM_SIZE 0x87
  245. #define UCDC_NCM_SET_MAX_DATAGRAM_SIZE 0x88
  246. #define UCDC_NCM_GET_CRC_MODE 0x89
  247. #define UCDC_NCM_SET_CRC_MODE 0x8A
  248. struct usb_ncm_parameters {
  249. uint16_t wLength;
  250. uint16_t bmNtbFormatsSupported;
  251. #define UCDC_NCM_FORMAT_NTB16 0x0001
  252. #define UCDC_NCM_FORMAT_NTB32 0x0002
  253. uint32_t dwNtbInMaxSize;
  254. uint16_t wNdpInDivisor;
  255. uint16_t wNdpInPayloadRemainder;
  256. uint16_t wNdpInAlignment;
  257. uint16_t wReserved14;
  258. uint32_t dwNtbOutMaxSize;
  259. uint16_t wNdpOutDivisor;
  260. uint16_t wNdpOutPayloadRemainder;
  261. uint16_t wNdpOutAlignment;
  262. uint16_t wNtbOutMaxDatagrams;
  263. } __attribute__((packed));
  264. /* Communications interface specific class notification codes */
  265. #define UCDC_NCM_NOTIF_NETWORK_CONNECTION 0x00
  266. #define UCDC_NCM_NOTIF_RESPONSE_AVAILABLE 0x01
  267. #define UCDC_NCM_NOTIF_CONNECTION_SPEED_CHANGE 0x2A
  268. #endif /* _USB_CDC_H_ */