hci_tl.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /*******************************************************************************
  29. Filename: hci_tl.h
  30. Revised: $Date: 2012-04-20 15:24:45 -0700 (Fri, 20 Apr 2012) $
  31. Revision: $Revision: 30292 $
  32. Description: This file contains the types, contants, external functions
  33. etc. for the BLE HCI Transport Layer.
  34. *******************************************************************************/
  35. #ifndef HCI_TL_H
  36. #define HCI_TL_H
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. /*******************************************************************************
  42. * INCLUDES
  43. */
  44. #include "hci.h"
  45. #include "OSAL.h"
  46. #include "uart.h"
  47. #include "hci_data.h"
  48. #include "hci_event.h"
  49. extern uint8 hciTaskID;
  50. //
  51. extern uint8 hciTestTaskID;
  52. extern uint8 hciGapTaskID;
  53. extern uint8 hciL2capTaskID;
  54. extern uint8 hciSmpTaskID;
  55. /*******************************************************************************
  56. * MACROS
  57. */
  58. #define HCI_ASSERT(condition) HAL_ASSERT(condition)
  59. /*******************************************************************************
  60. * CONSTANTS
  61. */
  62. // OSAL Task Events
  63. #define HCI_TX_PROCESS_EVENT 0x0001
  64. #define HCI_TEST_UART_SEND_EVENT 0x0002
  65. #define HCI_BDADDR_UPDATED_EVENT 0x4000
  66. #define HCI_OSAL_MSG_EVENT SYS_EVENT_MSG
  67. // OSAL Message Header Events
  68. #define HCI_CTRL_TO_HOST_EVENT 0x01
  69. #define HCI_HOST_TO_CTRL_CMD_EVENT 0x02
  70. #define HCI_HOST_TO_CTRL_DATA_EVENT 0x03
  71. #define HCI_BDADDR_LEN 6
  72. // Max Allowed HCI Packet
  73. #define HCI_MAX_CMD_PKT_SIZE 0xFF
  74. #define HCI_MAX_DATA_PKT_SIZE 0xFFFF
  75. // Max Data Length in Packet
  76. #define HCI_DATA_MAX_DATA_LENGTH 27
  77. //
  78. // Minimum length for CMD packet is 1+2+1
  79. // | Packet Type (1) | OPCode(2) | Length(1) |
  80. //
  81. #define HCI_CMD_MIN_LENGTH 4
  82. //
  83. // Minimum length for EVENT packet is 1+1+1
  84. // | Packet Type (1) | Event Code(1) | Length(1) |
  85. //
  86. #define HCI_EVENT_MIN_LENGTH 3
  87. //
  88. // Minimum length for DATA packet is 1+2+2
  89. // | Packet Type (1) | Handler(2) | Length(2) |
  90. //
  91. #define HCI_DATA_MIN_LENGTH 5
  92. // Max Number of Connections
  93. #define HCI_MAX_NUM_CONNECTIONS 0x03
  94. //
  95. #define HCI_TX_DATA_ANY_CONNECTION 0xFF
  96. // HCI Packet Types
  97. #define HCI_CMD_PACKET 0x01
  98. #define HCI_ACL_DATA_PACKET 0x02
  99. #define HCI_SCO_DATA_PACKET 0x03
  100. #define HCI_EVENT_PACKET 0x04
  101. /*
  102. ** HCI Command Opcodes
  103. */
  104. // Link Control Commands
  105. #define HCI_DISCONNECT 0x0406
  106. #define HCI_READ_REMOTE_VERSION_INFO 0x041D
  107. // Controller and Baseband Commands
  108. #define HCI_SET_EVENT_MASK 0x0C01
  109. #define HCI_RESET 0x0C03
  110. #define HCI_READ_TRANSMIT_POWER 0x0C2D
  111. #define HCI_SET_CONTROLLER_TO_HOST_FLOW_CONTROL 0x0C31
  112. #define HCI_HOST_BUFFER_SIZE 0x0C33
  113. #define HCI_HOST_NUM_COMPLETED_PACKETS 0x0C35
  114. // Information Parameters
  115. #define HCI_READ_LOCAL_VERSION_INFO 0x1001
  116. #define HCI_READ_LOCAL_SUPPORTED_COMMANDS 0x1002
  117. #define HCI_READ_LOCAL_SUPPORTED_FEATURES 0x1003
  118. #define HCI_READ_BDADDR 0x1009
  119. // Status Parameters
  120. #define HCI_READ_RSSI 0x1405
  121. // LE Commands
  122. #define HCI_LE_SET_EVENT_MASK 0x2001
  123. #define HCI_LE_READ_BUFFER_SIZE 0x2002
  124. #define HCI_LE_READ_LOCAL_SUPPORTED_FEATURES 0x2003
  125. #define HCI_LE_SET_RANDOM_ADDR 0x2005
  126. #define HCI_LE_SET_ADV_PARAM 0x2006
  127. #define HCI_LE_READ_ADV_CHANNEL_TX_POWER 0x2007
  128. #define HCI_LE_SET_ADV_DATA 0x2008
  129. #define HCI_LE_SET_SCAN_RSP_DATA 0x2009
  130. #define HCI_LE_SET_ADV_ENABLE 0x200A
  131. #define HCI_LE_SET_SCAN_PARAM 0x200B
  132. #define HCI_LE_SET_SCAN_ENABLE 0x200C
  133. #define HCI_LE_CREATE_CONNECTION 0x200D
  134. #define HCI_LE_CREATE_CONNECTION_CANCEL 0x200E
  135. #define HCI_LE_READ_WHITE_LIST_SIZE 0x200F
  136. #define HCI_LE_CLEAR_WHITE_LIST 0x2010
  137. #define HCI_LE_ADD_WHITE_LIST 0x2011
  138. #define HCI_LE_REMOVE_WHITE_LIST 0x2012
  139. #define HCI_LE_CONNECTION_UPDATE 0x2013
  140. #define HCI_LE_SET_HOST_CHANNEL_CLASSIFICATION 0x2014
  141. #define HCI_LE_READ_CHANNEL_MAP 0x2015
  142. #define HCI_LE_READ_REMOTE_USED_FEATURES 0x2016
  143. #define HCI_LE_ENCRYPT 0x2017
  144. #define HCI_LE_RAND 0x2018
  145. #define HCI_LE_START_ENCRYPTION 0x2019
  146. #define HCI_LE_LTK_REQ_REPLY 0x201A
  147. #define HCI_LE_LTK_REQ_NEG_REPLY 0x201B
  148. #define HCI_LE_READ_SUPPORTED_STATES 0x201C
  149. #define HCI_LE_RECEIVER_TEST 0x201D
  150. #define HCI_LE_TRANSMITTER_TEST 0x201E
  151. #define HCI_LE_TEST_END 0x201F
  152. #define HCI_LE_SET_DATA_LENGTH 0x2022
  153. #define HCI_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH 0x2023
  154. #define HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH 0x2024
  155. #define HCI_LE_READ_MAXIMUM_DATA_LENGTH 0x202F
  156. #define HCI_LE_READ_PHY 0x2030
  157. #define HCI_LE_SET_DEFAULT_PHY 0x2031
  158. #define HCI_LE_SET_PHY 0x2032
  159. // LE Vendor Specific LL Extension Commands
  160. #define HCI_EXT_SET_RX_GAIN 0xFC00
  161. #define HCI_EXT_SET_TX_POWER 0xFC01
  162. #define HCI_EXT_ONE_PKT_PER_EVT 0xFC02
  163. #define HCI_EXT_CLK_DIVIDE_ON_HALT 0xFC03
  164. #define HCI_EXT_DECLARE_NV_USAGE 0xFC04
  165. #define HCI_EXT_DECRYPT 0xFC05
  166. #define HCI_EXT_SET_LOCAL_SUPPORTED_FEATURES 0xFC06
  167. #define HCI_EXT_SET_FAST_TX_RESP_TIME 0xFC07
  168. #define HCI_EXT_MODEM_TEST_TX 0xFC08
  169. #define HCI_EXT_MODEM_HOP_TEST_TX 0xFC09
  170. #define HCI_EXT_MODEM_TEST_RX 0xFC0A
  171. #define HCI_EXT_END_MODEM_TEST 0xFC0B
  172. #define HCI_EXT_SET_BDADDR 0xFC0C
  173. #define HCI_EXT_SET_SCA 0xFC0D
  174. #define HCI_EXT_ENABLE_PTM 0xFC0E // Not a supported HCI command! Application only.
  175. #define HCI_EXT_SET_FREQ_TUNE 0xFC0F
  176. #define HCI_EXT_SAVE_FREQ_TUNE 0xFC10
  177. #define HCI_EXT_SET_MAX_DTM_TX_POWER 0xFC11
  178. #define HCI_EXT_MAP_PM_IO_PORT 0xFC12
  179. #define HCI_EXT_DISCONNECT_IMMED 0xFC13
  180. #define HCI_EXT_PER 0xFC14
  181. #define HCI_EXT_PER_BY_CHAN 0xFC15 // Not a supported HCI command! Application only.
  182. #define HCI_EXT_EXTEND_RF_RANGE 0xFC16
  183. #define HCI_EXT_ADV_EVENT_NOTICE 0xFC17 // Not a supported HCI command! Application only.
  184. #define HCI_EXT_CONN_EVENT_NOTICE 0xFC18 // Not a supported HCI command! Application only.
  185. #define HCI_EXT_HALT_DURING_RF 0xFC19
  186. #define HCI_EXT_OVERRIDE_SL 0xFC1A
  187. #define HCI_EXT_BUILD_REVISION 0xFC1B
  188. #define HCI_EXT_DELAY_SLEEP 0xFC1C
  189. #define HCI_EXT_RESET_SYSTEM 0xFC1D
  190. #define HCI_EXT_OVERLAPPED_PROCESSING 0xFC1E
  191. #define HCI_EXT_NUM_COMPLETED_PKTS_LIMIT 0xFC1F
  192. /*
  193. ** HCI Event Codes
  194. */
  195. // BT Events
  196. #define HCI_DISCONNECTION_COMPLETE_EVENT_CODE 0x05
  197. #define HCI_ENCRYPTION_CHANGE_EVENT_CODE 0x08
  198. #define HCI_READ_REMOTE_INFO_COMPLETE_EVENT_CODE 0x0C
  199. #define HCI_COMMAND_COMPLETE_EVENT_CODE 0x0E
  200. #define HCI_COMMAND_STATUS_EVENT_CODE 0x0F
  201. #define HCI_BLE_HARDWARE_ERROR_EVENT_CODE 0x10
  202. #define HCI_NUM_OF_COMPLETED_PACKETS_EVENT_CODE 0x13
  203. #define HCI_DATA_BUFFER_OVERFLOW_EVENT 0x1A
  204. #define HCI_KEY_REFRESH_COMPLETE_EVENT_CODE 0x30
  205. // LE Event Code (for LE Meta Events)
  206. #define HCI_LE_EVENT_CODE 0x3E
  207. // LE Meta Event Codes
  208. #define HCI_BLE_CONNECTION_COMPLETE_EVENT 0x01
  209. #define HCI_BLE_ADV_REPORT_EVENT 0x02
  210. #define HCI_BLE_CONN_UPDATE_COMPLETE_EVENT 0x03
  211. #define HCI_BLE_READ_REMOTE_FEATURE_COMPLETE_EVENT 0x04
  212. #define HCI_BLE_LTK_REQUESTED_EVENT 0x05
  213. #define HCI_BLE_DATA_LENGTH_CHANGE_EVENT 0x07
  214. #define HCI_BLE_PHY_UPDATE_COMPLETE_EVENT 0x0C
  215. // Vendor Specific Event Code
  216. #define HCI_VE_EVENT_CODE 0xFF
  217. // LE Vendor Specific LL Extension Events
  218. #define HCI_EXT_SET_RX_GAIN_EVENT 0x0400
  219. #define HCI_EXT_SET_TX_POWER_EVENT 0x0401
  220. #define HCI_EXT_ONE_PKT_PER_EVT_EVENT 0x0402
  221. #define HCI_EXT_CLK_DIVIDE_ON_HALT_EVENT 0x0403
  222. #define HCI_EXT_DECLARE_NV_USAGE_EVENT 0x0404
  223. #define HCI_EXT_DECRYPT_EVENT 0x0405
  224. #define HCI_EXT_SET_LOCAL_SUPPORTED_FEATURES_EVENT 0x0406
  225. #define HCI_EXT_SET_FAST_TX_RESP_TIME_EVENT 0x0407
  226. #define HCI_EXT_MODEM_TEST_TX_EVENT 0x0408
  227. #define HCI_EXT_MODEM_HOP_TEST_TX_EVENT 0x0409
  228. #define HCI_EXT_MODEM_TEST_RX_EVENT 0x040A
  229. #define HCI_EXT_END_MODEM_TEST_EVENT 0x040B
  230. #define HCI_EXT_SET_BDADDR_EVENT 0x040C
  231. #define HCI_EXT_SET_SCA_EVENT 0x040D
  232. #define HCI_EXT_ENABLE_PTM_EVENT 0x040E // Not a supported HCI command! Application only.
  233. #define HCI_EXT_SET_FREQ_TUNE_EVENT 0x040F
  234. #define HCI_EXT_SAVE_FREQ_TUNE_EVENT 0x0410
  235. #define HCI_EXT_SET_MAX_DTM_TX_POWER_EVENT 0x0411
  236. #define HCI_EXT_MAP_PM_IO_PORT_EVENT 0x0412
  237. #define HCI_EXT_DISCONNECT_IMMED_EVENT 0x0413
  238. #define HCI_EXT_PER_EVENT 0x0414
  239. #define HCI_EXT_PER_BY_CHAN_EVENT 0x0415 // Not a supported HCI command! Application only.
  240. #define HCI_EXT_EXTEND_RF_RANGE_EVENT 0x0416
  241. #define HCI_EXT_ADV_EVENT_NOTICE_EVENT 0x0417 // Not a supported HCI command! Application only.
  242. #define HCI_EXT_CONN_EVENT_NOTICE_EVENT 0x0418 // Not a supported HCI command! Application only.
  243. #define HCI_EXT_HALT_DURING_RF_EVENT 0x0419
  244. #define HCI_EXT_OVERRIDE_SL_EVENT 0x041A
  245. #define HCI_EXT_BUILD_REVISION_EVENT 0x041B
  246. #define HCI_EXT_DELAY_SLEEP_EVENT 0x041C
  247. #define HCI_EXT_RESET_SYSTEM_EVENT 0x041D
  248. #define HCI_EXT_OVERLAPPED_PROCESSING_EVENT 0x041E
  249. #define HCI_EXT_NUM_COMPLETED_PKTS_LIMIT_EVENT 0x041F
  250. /*******************************************************************************
  251. * TYPEDEFS
  252. */
  253. /*******************************************************************************
  254. * LOCAL VARIABLES
  255. */
  256. /*******************************************************************************
  257. * GLOBAL VARIABLES
  258. */
  259. /*
  260. ** HCI OSAL API
  261. */
  262. /*******************************************************************************
  263. * @fn HCI_Init
  264. *
  265. * @brief This is the HCI OSAL task initialization routine.
  266. *
  267. * input parameters
  268. *
  269. * @param taskID - The HCI OSAL task identifer.
  270. *
  271. * output parameters
  272. *
  273. * @param None.
  274. *
  275. * @return None.
  276. */
  277. extern void HCI_Init( uint8 taskID );
  278. /*******************************************************************************
  279. * @fn HCI_ProcessEvent
  280. *
  281. * @brief This is the HCI OSAL task process event handler.
  282. *
  283. * input parameters
  284. *
  285. * @param taskID - The HCI OSAL task identifer.
  286. * @param events - HCI OSAL task events.
  287. *
  288. * output parameters
  289. *
  290. * @param None.
  291. *
  292. * @return Unprocessed events.
  293. */
  294. extern uint16 HCI_ProcessEvent( uint8 task_id,
  295. uint16 events );
  296. #ifdef __cplusplus
  297. }
  298. #endif
  299. #endif /* HCI_TL_H */