hci.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /*****************************************************************************
  2. *
  3. * hci.h - CC3000 Host Driver Implementation.
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the
  16. * distribution.
  17. *
  18. * Neither the name of Texas Instruments Incorporated nor the names of
  19. * its contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. *****************************************************************************/
  35. #ifndef __CC3000_HCI_H__
  36. #define __CC3000_HCI_H__
  37. #include "cc3000_common.h"
  38. //*****************************************************************************
  39. //
  40. // If building with a C++ compiler, make all of the definitions in this header
  41. // have a C binding.
  42. //
  43. //*****************************************************************************
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. #define SPI_HEADER_SIZE (5)
  48. #define SIMPLE_LINK_HCI_CMND_HEADER_SIZE (4)
  49. #define HEADERS_SIZE_CMD (SPI_HEADER_SIZE + SIMPLE_LINK_HCI_CMND_HEADER_SIZE)
  50. #define SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE (5)
  51. #define SIMPLE_LINK_HCI_DATA_HEADER_SIZE (5)
  52. #define SIMPLE_LINK_HCI_PATCH_HEADER_SIZE (2)
  53. //*****************************************************************************
  54. //
  55. // Values that can be used as HCI Commands and HCI Packet header defines
  56. //
  57. //*****************************************************************************
  58. #define HCI_TYPE_CMND 0x1
  59. #define HCI_TYPE_DATA 0x2
  60. #define HCI_TYPE_PATCH 0x3
  61. #define HCI_TYPE_EVNT 0x4
  62. #define HCI_EVENT_PATCHES_DRV_REQ (1)
  63. #define HCI_EVENT_PATCHES_FW_REQ (2)
  64. #define HCI_EVENT_PATCHES_BOOTLOAD_REQ (3)
  65. #define HCI_CMND_WLAN_BASE (0x0000)
  66. #define HCI_CMND_WLAN_CONNECT 0x0001
  67. #define HCI_CMND_WLAN_DISCONNECT 0x0002
  68. #define HCI_CMND_WLAN_IOCTL_SET_SCANPARAM 0x0003
  69. #define HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY 0x0004
  70. #define HCI_CMND_WLAN_IOCTL_ADD_PROFILE 0x0005
  71. #define HCI_CMND_WLAN_IOCTL_DEL_PROFILE 0x0006
  72. #define HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS 0x0007
  73. #define HCI_CMND_EVENT_MASK 0x0008
  74. #define HCI_CMND_WLAN_IOCTL_STATUSGET 0x0009
  75. #define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START 0x000A
  76. #define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP 0x000B
  77. #define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX 0x000C
  78. #define HCI_CMND_WLAN_CONFIGURE_PATCH 0x000D
  79. #define HCI_CMND_SOCKET_BASE 0x1000
  80. #define HCI_CMND_SOCKET 0x1001
  81. #define HCI_CMND_BIND 0x1002
  82. #define HCI_CMND_RECV 0x1004
  83. #define HCI_CMND_ACCEPT 0x1005
  84. #define HCI_CMND_LISTEN 0x1006
  85. #define HCI_CMND_CONNECT 0x1007
  86. #define HCI_CMND_BSD_SELECT 0x1008
  87. #define HCI_CMND_SETSOCKOPT 0x1009
  88. #define HCI_CMND_GETSOCKOPT 0x100A
  89. #define HCI_CMND_CLOSE_SOCKET 0x100B
  90. #define HCI_CMND_RECVFROM 0x100D
  91. #define HCI_CMND_GETHOSTNAME 0x1010
  92. #define HCI_CMND_MDNS_ADVERTISE 0x1011
  93. #define HCI_CMND_GETMSSVALUE 0x1012
  94. #define HCI_DATA_BASE 0x80
  95. #define HCI_CMND_SEND (0x01 + HCI_DATA_BASE)
  96. #define HCI_CMND_SENDTO (0x03 + HCI_DATA_BASE)
  97. #define HCI_DATA_BSD_RECVFROM (0x04 + HCI_DATA_BASE)
  98. #define HCI_DATA_BSD_RECV (0x05 + HCI_DATA_BASE)
  99. #define HCI_CMND_NVMEM_CBASE (0x0200)
  100. #define HCI_CMND_NVMEM_CREATE_ENTRY (0x0203)
  101. #define HCI_CMND_NVMEM_SWAP_ENTRY (0x0205)
  102. #define HCI_CMND_NVMEM_READ (0x0201)
  103. #define HCI_CMND_NVMEM_WRITE (0x0090)
  104. #define HCI_CMND_NVMEM_WRITE_PATCH (0x0204)
  105. #define HCI_CMND_READ_SP_VERSION (0x0207)
  106. #define HCI_CMND_READ_BUFFER_SIZE 0x400B
  107. #define HCI_CMND_SIMPLE_LINK_START 0x4000
  108. #define HCI_CMND_NETAPP_BASE 0x2000
  109. #define HCI_NETAPP_DHCP (0x0001 + HCI_CMND_NETAPP_BASE)
  110. #define HCI_NETAPP_PING_SEND (0x0002 + HCI_CMND_NETAPP_BASE)
  111. #define HCI_NETAPP_PING_REPORT (0x0003 + HCI_CMND_NETAPP_BASE)
  112. #define HCI_NETAPP_PING_STOP (0x0004 + HCI_CMND_NETAPP_BASE)
  113. #define HCI_NETAPP_IPCONFIG (0x0005 + HCI_CMND_NETAPP_BASE)
  114. #define HCI_NETAPP_ARP_FLUSH (0x0006 + HCI_CMND_NETAPP_BASE)
  115. #define HCI_NETAPP_SET_DEBUG_LEVEL (0x0008 + HCI_CMND_NETAPP_BASE)
  116. #define HCI_NETAPP_SET_TIMERS (0x0009 + HCI_CMND_NETAPP_BASE)
  117. //*****************************************************************************
  118. //
  119. // Values that can be used as HCI Events defines
  120. //
  121. //*****************************************************************************
  122. #define HCI_EVNT_WLAN_BASE 0x0000
  123. #define HCI_EVNT_WLAN_CONNECT 0x0001
  124. #define HCI_EVNT_WLAN_DISCONNECT \
  125. 0x0002
  126. #define HCI_EVNT_WLAN_IOCTL_ADD_PROFILE \
  127. 0x0005
  128. #define HCI_EVNT_SOCKET HCI_CMND_SOCKET
  129. #define HCI_EVNT_BIND HCI_CMND_BIND
  130. #define HCI_EVNT_RECV HCI_CMND_RECV
  131. #define HCI_EVNT_ACCEPT HCI_CMND_ACCEPT
  132. #define HCI_EVNT_LISTEN HCI_CMND_LISTEN
  133. #define HCI_EVNT_CONNECT HCI_CMND_CONNECT
  134. #define HCI_EVNT_SELECT HCI_CMND_BSD_SELECT
  135. #define HCI_EVNT_CLOSE_SOCKET HCI_CMND_CLOSE_SOCKET
  136. #define HCI_EVNT_RECVFROM HCI_CMND_RECVFROM
  137. #define HCI_EVNT_SETSOCKOPT HCI_CMND_SETSOCKOPT
  138. #define HCI_EVNT_GETSOCKOPT HCI_CMND_GETSOCKOPT
  139. #define HCI_EVNT_BSD_GETHOSTBYNAME HCI_CMND_GETHOSTNAME
  140. #define HCI_EVNT_MDNS_ADVERTISE HCI_CMND_MDNS_ADVERTISE
  141. #define HCI_EVNT_GETMSSVALUE HCI_CMND_GETMSSVALUE
  142. #define HCI_EVNT_SEND 0x1003
  143. #define HCI_EVNT_WRITE 0x100E
  144. #define HCI_EVNT_SENDTO 0x100F
  145. #define HCI_EVNT_PATCHES_REQ 0x1000
  146. #define HCI_EVNT_UNSOL_BASE 0x4000
  147. #define HCI_EVNT_WLAN_UNSOL_BASE (0x8000)
  148. #define HCI_EVNT_WLAN_UNSOL_CONNECT (0x0001 + HCI_EVNT_WLAN_UNSOL_BASE)
  149. #define HCI_EVNT_WLAN_UNSOL_DISCONNECT (0x0002 + HCI_EVNT_WLAN_UNSOL_BASE)
  150. #define HCI_EVNT_WLAN_UNSOL_INIT (0x0004 + HCI_EVNT_WLAN_UNSOL_BASE)
  151. #define HCI_EVNT_WLAN_TX_COMPLETE (0x0008 + HCI_EVNT_WLAN_UNSOL_BASE)
  152. #define HCI_EVNT_WLAN_UNSOL_DHCP (0x0010 + HCI_EVNT_WLAN_UNSOL_BASE)
  153. #define HCI_EVNT_WLAN_ASYNC_PING_REPORT (0x0040 + HCI_EVNT_WLAN_UNSOL_BASE)
  154. #define HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE (0x0080 + HCI_EVNT_WLAN_UNSOL_BASE)
  155. #define HCI_EVNT_WLAN_KEEPALIVE (0x0200 + HCI_EVNT_WLAN_UNSOL_BASE)
  156. #define HCI_EVNT_BSD_TCP_CLOSE_WAIT (0x0800 + HCI_EVNT_WLAN_UNSOL_BASE)
  157. #define HCI_EVNT_DATA_UNSOL_FREE_BUFF \
  158. 0x4100
  159. #define HCI_EVNT_NVMEM_CREATE_ENTRY \
  160. HCI_CMND_NVMEM_CREATE_ENTRY
  161. #define HCI_EVNT_NVMEM_SWAP_ENTRY HCI_CMND_NVMEM_SWAP_ENTRY
  162. #define HCI_EVNT_NVMEM_READ HCI_CMND_NVMEM_READ
  163. #define HCI_EVNT_NVMEM_WRITE (0x0202)
  164. #define HCI_EVNT_READ_SP_VERSION \
  165. HCI_CMND_READ_SP_VERSION
  166. #define HCI_EVNT_INPROGRESS 0xFFFF
  167. #define HCI_DATA_RECVFROM 0x84
  168. #define HCI_DATA_RECV 0x85
  169. #define HCI_DATA_NVMEM 0x91
  170. #define HCI_EVENT_CC3000_CAN_SHUT_DOWN 0x99
  171. //*****************************************************************************
  172. //
  173. // Prototypes for the structures for APIs.
  174. //
  175. //*****************************************************************************
  176. #define HCI_DATA_HEADER_SIZE (5)
  177. #define HCI_EVENT_HEADER_SIZE (5)
  178. #define HCI_DATA_CMD_HEADER_SIZE (5)
  179. #define HCI_PATCH_HEADER_SIZE (6)
  180. #define HCI_PACKET_TYPE_OFFSET (0)
  181. #define HCI_PACKET_ARGSIZE_OFFSET (2)
  182. #define HCI_PACKET_LENGTH_OFFSET (3)
  183. #define HCI_EVENT_OPCODE_OFFSET (1)
  184. #define HCI_EVENT_LENGTH_OFFSET (3)
  185. #define HCI_EVENT_STATUS_OFFSET (4)
  186. #define HCI_DATA_LENGTH_OFFSET (3)
  187. //*****************************************************************************
  188. //
  189. // Prototypes for the APIs.
  190. //
  191. //*****************************************************************************
  192. //*****************************************************************************
  193. //
  194. //! hci_command_send
  195. //!
  196. //! @param usOpcode command operation code
  197. //! @param pucBuff pointer to the command's arguments buffer
  198. //! @param ucArgsLength length of the arguments
  199. //!
  200. //! @return none
  201. //!
  202. //! @brief Initiate an HCI command.
  203. //
  204. //*****************************************************************************
  205. extern UINT16 hci_command_send(UINT16 usOpcode,
  206. UINT8 *ucArgs,
  207. UINT8 ucArgsLength);
  208. //*****************************************************************************
  209. //
  210. //! hci_data_send
  211. //!
  212. //! @param usOpcode command operation code
  213. //! @param ucArgs pointer to the command's arguments buffer
  214. //! @param usArgsLength length of the arguments
  215. //! @param ucTail pointer to the data buffer
  216. //! @param usTailLength buffer length
  217. //!
  218. //! @return none
  219. //!
  220. //! @brief Initiate an HCI data write operation
  221. //
  222. //*****************************************************************************
  223. extern INT32 hci_data_send(UINT8 ucOpcode,
  224. UINT8 *ucArgs,
  225. UINT16 usArgsLength,
  226. UINT16 usDataLength,
  227. const UINT8 *ucTail,
  228. UINT16 usTailLength);
  229. //*****************************************************************************
  230. //
  231. //! hci_data_command_send
  232. //!
  233. //! @param usOpcode command operation code
  234. //! @param pucBuff pointer to the data buffer
  235. //! @param ucArgsLength arguments length
  236. //! @param ucDataLength data length
  237. //!
  238. //! @return none
  239. //!
  240. //! @brief Prepare HCI header and initiate an HCI data write operation
  241. //
  242. //*****************************************************************************
  243. extern void hci_data_command_send(UINT16 usOpcode, UINT8 *pucBuff,
  244. UINT8 ucArgsLength, UINT16 ucDataLength);
  245. //*****************************************************************************
  246. //
  247. //! hci_patch_send
  248. //!
  249. //! @param usOpcode command operation code
  250. //! @param pucBuff pointer to the command's arguments buffer
  251. //! @param patch pointer to patch content buffer
  252. //! @param usDataLength data length
  253. //!
  254. //! @return none
  255. //!
  256. //! @brief Prepare HCI header and initiate an HCI patch write operation
  257. //
  258. //*****************************************************************************
  259. extern void hci_patch_send(UINT8 ucOpcode, UINT8 *pucBuff, CHAR *patch, UINT16 usDataLength);
  260. //*****************************************************************************
  261. //
  262. // Mark the end of the C bindings section for C++ compilers.
  263. //
  264. //*****************************************************************************
  265. #ifdef __cplusplus
  266. }
  267. #endif // __cplusplus
  268. #endif // __CC3000_HCI_H__