BLE-Stack APIs  3.00.00
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hci_tl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!*****************************************************************************
33  * @addtogroup HCI
34  * @{
35  * @file hci_tl.h
36  * @brief Types, constants, external functions etc. for
37  the BLE HCI Transport Layer.
38  */
39 
40 #ifndef HCI_TL_H
41 #define HCI_TL_H
42 
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 /*******************************************************************************
49  * INCLUDES
50  */
51 
52 #include "hci.h"
53 #include "osal.h"
54 #include "hci_data.h"
55 #include "hci_event.h"
56 
57 extern uint8 hciTaskID;
58 //
59 extern uint8 hciTestTaskID;
60 extern uint8 hciGapTaskID;
61 extern uint8 hciL2capTaskID;
62 extern uint8 hciSmpTaskID;
63 
64 /*******************************************************************************
65  * MACROS
66  */
67 
68 #define HCI_ASSERT(condition) HAL_ASSERT(condition)
69  // end of ATT_GATT
71 
72 /*******************************************************************************
73  * CONSTANTS
74  */
75 
81 // OSAL Task Events
82 #define HCI_TX_PROCESS_EVENT 0x0001
83 #define HCI_TEST_UART_SEND_EVENT 0x0002
84 #define HCI_ADV_NOTICE_EVENT 0x0004
85 #define HCI_SCAN_NOTICE_EVENT 0x0008
86 #define HCI_CONN_NOTICE_EVENT 0x0010
87 #define HCI_BDADDR_UPDATED_EVENT 0x4000
88 
89 // OSAL Message Header Events
90 #define HCI_CTRL_TO_HOST_EVENT 0x01
91 #define HCI_HOST_TO_CTRL_CMD_EVENT 0x02
92 #define HCI_HOST_TO_CTRL_DATA_EVENT 0x03
93 
94 #define HCI_BDADDR_LEN 6
95 
96 // Max Allowed HCI Packet
97 #define HCI_MAX_CMD_PKT_SIZE 0xFF
98 #define HCI_MAX_DATA_PKT_SIZE 0xFFFF
99 
100 // Max Data Length in Packet
101 #define HCI_DATA_MAX_DATA_LENGTH 27
102 
103 //
104 // Minimum length for CMD packet is 1+2+1
105 // | Packet Type (1) | OPCode(2) | Length(1) |
106 //
107 #define HCI_CMD_MIN_LENGTH 4
108 
109 //
110 // Minimum length for EVENT packet is 1+1+1
111 // | Packet Type (1) | Event Code(1) | Length(1) |
112 //
113 #define HCI_EVENT_MIN_LENGTH 3
114 
115 //
116 // Minimum length for DATA packet is 1+2+2
117 // | Packet Type (1) | Handler(2) | Length(2) |
118 //
119 #define HCI_DATA_MIN_LENGTH 5
120 
121 // Max Number of Connections
122 #define HCI_MAX_NUM_CONNECTIONS 0x03
123 //
124 #define HCI_TX_DATA_ANY_CONNECTION 0xFF
125 
126 // HCI Packet Types
127 #define HCI_CMD_PACKET 0x01
128 #define HCI_ACL_DATA_PACKET 0x02
129 #define HCI_SCO_DATA_PACKET 0x03
130 #define HCI_EVENT_PACKET 0x04
131 
132 
133 // States for Command and Data packet parser
134 #define HCI_PARSER_STATE_PKT_TYPE 0
135 //
136 #define HCI_CMD_PARSER_STATE_OPCODE 1
137 #define HCI_CMD_PARSER_STATE_LENGTH 2
138 #define HCI_CMD_PARSER_STATE_DATA 3
139 //
140 #define HCI_DATA_PARSER_STATE_HANDLE 4
141 #define HCI_DATA_PARSER_STATE_LENGTH 5
142 #define HCI_DATA_PARSER_STATE_DATA 6
143 
144 // HCI Command Subgroup
145 #define HCI_OPCODE_CSG_LINK_LAYER 0
146 #define HCI_OPCODE_CSG_CSG_L2CAP 1
147 #define HCI_OPCODE_CSG_CSG_ATT 2
148 #define HCI_OPCODE_CSG_CSG_GATT 3
149 #define HCI_OPCODE_CSG_CSG_GAP 4
150 #define HCI_OPCODE_CSG_CSG_SM 5
151 #define HCI_OPCODE_CSG_CSG_Reserved 6
152 #define HCI_OPCODE_CSG_CSG_USER_PROFILE 7
153 
154 // Vendor Specific OGF
155 #define VENDOR_SPECIFIC_OGF 0x3F
156 
157 /*
158 ** HCI Command Opcodes
159 */
160 
161 // Link Control Commands
162 #define HCI_DISCONNECT 0x0406
163 #define HCI_READ_REMOTE_VERSION_INFO 0x041D
164 
165 // Controller and Baseband Commands
166 #define HCI_SET_EVENT_MASK 0x0C01
167 #define HCI_RESET 0x0C03
168 #define HCI_READ_TRANSMIT_POWER 0x0C2D
169 #define HCI_SET_CONTROLLER_TO_HOST_FLOW_CONTROL 0x0C31
170 #define HCI_HOST_BUFFER_SIZE 0x0C33
171 #define HCI_HOST_NUM_COMPLETED_PACKETS 0x0C35
172 #define HCI_SET_EVENT_MASK_PAGE_2 0x0C63
173 #define HCI_READ_AUTH_PAYLOAD_TIMEOUT 0x0C7B
174 #define HCI_WRITE_AUTH_PAYLOAD_TIMEOUT 0x0C7C
175 
176 // Information Parameters
177 #define HCI_READ_LOCAL_VERSION_INFO 0x1001
178 #define HCI_READ_LOCAL_SUPPORTED_COMMANDS 0x1002
179 #define HCI_READ_LOCAL_SUPPORTED_FEATURES 0x1003
180 #define HCI_READ_BDADDR 0x1009
181 
182 // Status Parameters
183 #define HCI_READ_RSSI 0x1405
184 
185 // LE Commands
186 // V4.0
187 #define HCI_LE_SET_EVENT_MASK 0x2001
188 #define HCI_LE_READ_BUFFER_SIZE 0x2002
189 #define HCI_LE_READ_LOCAL_SUPPORTED_FEATURES 0x2003
190 #define HCI_LE_SET_RANDOM_ADDR 0x2005
191 #define HCI_LE_SET_ADV_PARAM 0x2006
192 #define HCI_LE_READ_ADV_CHANNEL_TX_POWER 0x2007
193 #define HCI_LE_SET_ADV_DATA 0x2008
194 #define HCI_LE_SET_SCAN_RSP_DATA 0x2009
195 #define HCI_LE_SET_ADV_ENABLE 0x200A
196 #define HCI_LE_SET_SCAN_PARAM 0x200B
197 #define HCI_LE_SET_SCAN_ENABLE 0x200C
198 #define HCI_LE_CREATE_CONNECTION 0x200D
199 #define HCI_LE_CREATE_CONNECTION_CANCEL 0x200E
200 #define HCI_LE_READ_WHITE_LIST_SIZE 0x200F
201 #define HCI_LE_CLEAR_WHITE_LIST 0x2010
202 #define HCI_LE_ADD_WHITE_LIST 0x2011
203 #define HCI_LE_REMOVE_WHITE_LIST 0x2012
204 #define HCI_LE_CONNECTION_UPDATE 0x2013
205 #define HCI_LE_SET_HOST_CHANNEL_CLASSIFICATION 0x2014
206 #define HCI_LE_READ_CHANNEL_MAP 0x2015
207 #define HCI_LE_READ_REMOTE_USED_FEATURES 0x2016
208 #define HCI_LE_ENCRYPT 0x2017
209 #define HCI_LE_RAND 0x2018
210 #define HCI_LE_START_ENCRYPTION 0x2019
211 #define HCI_LE_LTK_REQ_REPLY 0x201A
212 #define HCI_LE_LTK_REQ_NEG_REPLY 0x201B
213 #define HCI_LE_READ_SUPPORTED_STATES 0x201C
214 #define HCI_LE_RECEIVER_TEST 0x201D
215 #define HCI_LE_TRANSMITTER_TEST 0x201E
216 #define HCI_LE_TEST_END 0x201F
217 // V4.1
218 #define HCI_LE_REMOTE_CONN_PARAM_REQ_REPLY 0x2020
219 #define HCI_LE_REMOTE_CONN_PARAM_REQ_NEG_REPLY 0x2021
220 // V4.2
221 #define HCI_LE_SET_DATA_LENGTH 0x2022
222 #define HCI_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH 0x2023
223 #define HCI_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH 0x2024
224 #define HCI_LE_READ_LOCAL_P256_PUBLIC_KEY 0x2025
225 #define HCI_LE_GENERATE_DHKEY 0x2026
226 #define HCI_LE_ADD_DEVICE_TO_RESOLVING_LIST 0x2027
227 #define HCI_LE_REMOVE_DEVICE_FROM_RESOLVING_LIST 0x2028
228 #define HCI_LE_CLEAR_RESOLVING_LIST 0x2029
229 #define HCI_LE_READ_RESOLVING_LIST_SIZE 0x202A
230 #define HCI_LE_READ_PEER_RESOLVABLE_ADDRESS 0x202B
231 #define HCI_LE_READ_LOCAL_RESOLVABLE_ADDRESS 0x202C
232 #define HCI_LE_SET_ADDRESS_RESOLUTION_ENABLE 0x202D
233 #define HCI_LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT 0x202E
234 #define HCI_LE_READ_MAX_DATA_LENGTH 0x202F
235 // V5.0
236 #define HCI_LE_READ_PHY 0x2030
237 #define HCI_LE_SET_DEFAULT_PHY 0x2031
238 #define HCI_LE_SET_PHY 0x2032
239 #define HCI_LE_ENHANCED_RECEIVER_TEST 0x2033
240 #define HCI_LE_ENHANCED_TRANSMITTER_TEST 0x2034
241 
242 // LE Vendor Specific LL Extension Commands
243 #define HCI_EXT_SET_RX_GAIN 0xFC00
244 #define HCI_EXT_SET_TX_POWER 0xFC01
245 #define HCI_EXT_ONE_PKT_PER_EVT 0xFC02
246 #define HCI_EXT_CLK_DIVIDE_ON_HALT 0xFC03
247 #define HCI_EXT_DECLARE_NV_USAGE 0xFC04
248 #define HCI_EXT_DECRYPT 0xFC05
249 #define HCI_EXT_SET_LOCAL_SUPPORTED_FEATURES 0xFC06
250 #define HCI_EXT_SET_FAST_TX_RESP_TIME 0xFC07
251 #define HCI_EXT_MODEM_TEST_TX 0xFC08
252 #define HCI_EXT_MODEM_HOP_TEST_TX 0xFC09
253 #define HCI_EXT_MODEM_TEST_RX 0xFC0A
254 #define HCI_EXT_END_MODEM_TEST 0xFC0B
255 #define HCI_EXT_SET_BDADDR 0xFC0C
256 #define HCI_EXT_SET_SCA 0xFC0D
257 #define HCI_EXT_ENABLE_PTM 0xFC0E // Not a supported HCI command! Application only.
258 #define HCI_EXT_SET_FREQ_TUNE 0xFC0F
259 #define HCI_EXT_SAVE_FREQ_TUNE 0xFC10
260 #define HCI_EXT_SET_MAX_DTM_TX_POWER 0xFC11
261 #define HCI_EXT_MAP_PM_IO_PORT 0xFC12
262 #define HCI_EXT_DISCONNECT_IMMED 0xFC13
263 #define HCI_EXT_PER 0xFC14
264 #define HCI_EXT_PER_BY_CHAN 0xFC15 // Not a supported HCI command! Application only.
265 #define HCI_EXT_EXTEND_RF_RANGE 0xFC16
266 #define HCI_EXT_ADV_EVENT_NOTICE 0xFC17 // Not a supported HCI command! Application only.
267 #define HCI_EXT_CONN_EVENT_NOTICE 0xFC18 // Not a supported HCI command! Application only.
268 #define HCI_EXT_HALT_DURING_RF 0xFC19
269 #define HCI_EXT_OVERRIDE_SL 0xFC1A
270 #define HCI_EXT_BUILD_REVISION 0xFC1B
271 #define HCI_EXT_DELAY_SLEEP 0xFC1C
272 #define HCI_EXT_RESET_SYSTEM 0xFC1D
273 #define HCI_EXT_OVERLAPPED_PROCESSING 0xFC1E
274 #define HCI_EXT_NUM_COMPLETED_PKTS_LIMIT 0xFC1F
275 #define HCI_EXT_GET_CONNECTION_INFO 0xFC20
276 #define HCI_EXT_SET_MAX_DATA_LENGTH 0xFC21
277 #define HCI_EXT_SCAN_EVENT_NOTICE 0xFC22 // Not a supported HCI command! Application only.
278 #define HCI_EXT_SCAN_REQ_REPORT 0xFC23
279 #
280 #define HCI_EXT_LL_TEST_MODE 0xFC70
281 
282 /*
283 ** HCI Event Codes
284 */
285 
286 // BT Events
287 #define HCI_DISCONNECTION_COMPLETE_EVENT_CODE 0x05
288 #define HCI_ENCRYPTION_CHANGE_EVENT_CODE 0x08
289 #define HCI_READ_REMOTE_INFO_COMPLETE_EVENT_CODE 0x0C
290 #define HCI_COMMAND_COMPLETE_EVENT_CODE 0x0E
291 #define HCI_COMMAND_STATUS_EVENT_CODE 0x0F
292 #define HCI_BLE_HARDWARE_ERROR_EVENT_CODE 0x10
293 #define HCI_NUM_OF_COMPLETED_PACKETS_EVENT_CODE 0x13
294 #define HCI_DATA_BUFFER_OVERFLOW_EVENT 0x1A
295 #define HCI_KEY_REFRESH_COMPLETE_EVENT_CODE 0x30
296 #define HCI_APTO_EXPIRED_EVENT_CODE 0x57
297 
298 // LE Event Code (for LE Meta Events)
299 #define HCI_LE_EVENT_CODE 0x3E
300 
301 // LE Meta Event Codes
302 #define HCI_BLE_CONNECTION_COMPLETE_EVENT 0x01
303 #define HCI_BLE_ADV_REPORT_EVENT 0x02
304 #define HCI_BLE_CONN_UPDATE_COMPLETE_EVENT 0x03
305 #define HCI_BLE_READ_REMOTE_FEATURE_COMPLETE_EVENT 0x04
306 #define HCI_BLE_LTK_REQUESTED_EVENT 0x05
307 // V4.1
308 #define HCI_BLE_REMOTE_CONN_PARAM_REQUEST_EVENT 0x06
309 // V4.2
310 #define HCI_BLE_DATA_LENGTH_CHANGE_EVENT 0x07
311 #define HCI_BLE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE_EVENT 0x08
312 #define HCI_BLE_GENERATE_DHKEY_COMPLETE_EVENT 0x09
313 #define HCI_BLE_ENHANCED_CONNECTION_COMPLETE_EVENT 0x0A
314 #define HCI_BLE_DIRECT_ADVERTISING_REPORT_EVENT 0x0B
315 // V5.0
316 #define HCI_BLE_PHY_UPDATE_COMPLETE_EVENT 0x0C
317 // VS Meta Event Codes - Texas Instruments Inc specific!
318 #define HCI_BLE_SCAN_REQ_REPORT_EVENT 0x80
319 
320 // Vendor Specific Event Code
321 #define HCI_VE_EVENT_CODE 0xFF
322 
323 // LE Vendor Specific LL Extension Events
324 #define HCI_EXT_SET_RX_GAIN_EVENT 0x0400
325 #define HCI_EXT_SET_TX_POWER_EVENT 0x0401
326 #define HCI_EXT_ONE_PKT_PER_EVT_EVENT 0x0402
327 #define HCI_EXT_CLK_DIVIDE_ON_HALT_EVENT 0x0403
328 #define HCI_EXT_DECLARE_NV_USAGE_EVENT 0x0404
329 #define HCI_EXT_DECRYPT_EVENT 0x0405
330 #define HCI_EXT_SET_LOCAL_SUPPORTED_FEATURES_EVENT 0x0406
331 #define HCI_EXT_SET_FAST_TX_RESP_TIME_EVENT 0x0407
332 #define HCI_EXT_MODEM_TEST_TX_EVENT 0x0408
333 #define HCI_EXT_MODEM_HOP_TEST_TX_EVENT 0x0409
334 #define HCI_EXT_MODEM_TEST_RX_EVENT 0x040A
335 #define HCI_EXT_END_MODEM_TEST_EVENT 0x040B
336 #define HCI_EXT_SET_BDADDR_EVENT 0x040C
337 #define HCI_EXT_SET_SCA_EVENT 0x040D
338 #define HCI_EXT_ENABLE_PTM_EVENT 0x040E // Not a supported HCI command! Application only.
339 #define HCI_EXT_SET_FREQ_TUNE_EVENT 0x040F
340 #define HCI_EXT_SAVE_FREQ_TUNE_EVENT 0x0410
341 #define HCI_EXT_SET_MAX_DTM_TX_POWER_EVENT 0x0411
342 #define HCI_EXT_MAP_PM_IO_PORT_EVENT 0x0412
343 #define HCI_EXT_DISCONNECT_IMMED_EVENT 0x0413
344 #define HCI_EXT_PER_EVENT 0x0414
345 #define HCI_EXT_PER_BY_CHAN_EVENT 0x0415 // Not a supported HCI command! Application only.
346 #define HCI_EXT_EXTEND_RF_RANGE_EVENT 0x0416
347 #define HCI_EXT_ADV_EVENT_NOTICE_EVENT 0x0417 // Not a supported HCI command! Application only.
348 #define HCI_EXT_CONN_EVENT_NOTICE_EVENT 0x0418 // Not a supported HCI command! Application only.
349 #define HCI_EXT_HALT_DURING_RF_EVENT 0x0419
350 #define HCI_EXT_OVERRIDE_SL_EVENT 0x041A
351 #define HCI_EXT_BUILD_REVISION_EVENT 0x041B
352 #define HCI_EXT_DELAY_SLEEP_EVENT 0x041C
353 #define HCI_EXT_RESET_SYSTEM_EVENT 0x041D
354 #define HCI_EXT_OVERLAPPED_PROCESSING_EVENT 0x041E
355 #define HCI_EXT_NUM_COMPLETED_PKTS_LIMIT_EVENT 0x041F
356 #define HCI_EXT_GET_CONNECTION_INFO_EVENT 0x0420
357 #define HCI_EXT_SET_MAX_DATA_LENGTH_EVENT 0x0421
358 #define HCI_EXT_SCAN_EVENT_NOTICE_EVENT 0x0422 // Not a supported HCI command! Application only.
359 #define HCI_EXT_SCAN_REQ_REPORT_EVENT 0x0423
360 #
361 #define HCI_EXT_LL_TEST_MODE_EVENT 0x0470
362 
363  // end of HCI_Constants
365 
366 /*******************************************************************************
367  * TYPEDEFS
368  */
369 
370 /*******************************************************************************
371  * LOCAL VARIABLES
372  */
373 
374 /*******************************************************************************
375  * GLOBAL VARIABLES
376  */
377 
378 /*
379 ** HCI OSAL API
380 */
381 
382 /*******************************************************************************
383  * @fn HCI_Init
384  *
385  * @brief This is the HCI OSAL task initialization routine.
386  *
387  * input parameters
388  *
389  * @param taskID - The HCI OSAL task identifier.
390  *
391  * output parameters
392  *
393  * @param None.
394  *
395  * @return None.
396  */
397 extern void HCI_Init( uint8 taskID );
398 
399 
400 /*******************************************************************************
401  * @fn HCI_TL_getCmdResponderID
402  *
403  * @brief Used by application to intercept and handle HCI TL events and
404  * messages
405  *
406  * input parameters
407  *
408  * @param taskID - The HCI OSAL task identifier.
409  *
410  * output parameters
411  *
412  * @param None.
413  *
414  * @return None.
415  */
416 extern void HCI_TL_getCmdResponderID( uint8 taskID );
417 
418 
419 /*******************************************************************************
420  * @fn HCI_ProcessEvent
421  *
422  * @brief This is the HCI OSAL task process event handler.
423  *
424  * input parameters
425  *
426  * @param taskID - The HCI OSAL task identifier.
427  * @param events - HCI OSAL task events.
428  *
429  * output parameters
430  *
431  * @param None.
432  *
433  * @return Unprocessed events.
434  */
435 extern uint16 HCI_ProcessEvent( uint8 task_id,
436  uint16 events );
437 
438 
439 #ifdef __cplusplus
440 }
441 #endif
442 
443 #endif /* HCI_TL_H */
This API allows the software components in the Z-Stack to be written independently of the specifics o...
HCI layer interface.
Copyright 2016, Texas Instruments Incorporated