OSDN Git Service

Merge cherrypicks of [6452478, 6451642, 6451643, 6453811, 6451644, 6451645, 6453831...
[android-x86/system-bt.git] / stack / include / hcimsgs.h
1 /******************************************************************************
2  *
3  *  Copyright (C) 1999-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18
19 #ifndef HCIMSGS_H
20 #define HCIMSGS_H
21
22 #include "bt_target.h"
23 #include "bt_types.h"
24 #include "device/include/esco_parameters.h"
25 #include "hcidefs.h"
26
27 #include <base/callback_forward.h>
28
29 void bte_main_hci_send(BT_HDR* p_msg, uint16_t event);
30
31 /* Message by message.... */
32
33 extern void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration,
34                                uint8_t response_cnt);
35
36 #define HCIC_PARAM_SIZE_INQUIRY 5
37
38 #define HCIC_INQ_INQ_LAP_OFF 0
39 #define HCIC_INQ_DUR_OFF 3
40 #define HCIC_INQ_RSP_CNT_OFF 4
41 /* Inquiry */
42
43 /* Inquiry Cancel */
44 extern void btsnd_hcic_inq_cancel(void);
45
46 #define HCIC_PARAM_SIZE_INQ_CANCEL 0
47
48 /* Periodic Inquiry Mode */
49 extern void btsnd_hcic_per_inq_mode(uint16_t max_period, uint16_t min_period,
50                                     const LAP inq_lap, uint8_t duration,
51                                     uint8_t response_cnt);
52
53 #define HCIC_PARAM_SIZE_PER_INQ_MODE 9
54
55 #define HCI_PER_INQ_MAX_INTRVL_OFF 0
56 #define HCI_PER_INQ_MIN_INTRVL_OFF 2
57 #define HCI_PER_INQ_INQ_LAP_OFF 4
58 #define HCI_PER_INQ_DURATION_OFF 7
59 #define HCI_PER_INQ_RSP_CNT_OFF 8
60 /* Periodic Inquiry Mode */
61
62 /* Exit Periodic Inquiry Mode */
63 extern void btsnd_hcic_exit_per_inq(void);
64
65 #define HCIC_PARAM_SIZE_EXIT_PER_INQ 0
66 /* Create Connection */
67 extern void btsnd_hcic_create_conn(const RawAddress& dest,
68                                    uint16_t packet_types,
69                                    uint8_t page_scan_rep_mode,
70                                    uint8_t page_scan_mode,
71                                    uint16_t clock_offset, uint8_t allow_switch);
72
73 #define HCIC_PARAM_SIZE_CREATE_CONN 13
74
75 #define HCIC_CR_CONN_BD_ADDR_OFF 0
76 #define HCIC_CR_CONN_PKT_TYPES_OFF 6
77 #define HCIC_CR_CONN_REP_MODE_OFF 8
78 #define HCIC_CR_CONN_PAGE_SCAN_MODE_OFF 9
79 #define HCIC_CR_CONN_CLK_OFF_OFF 10
80 #define HCIC_CR_CONN_ALLOW_SWITCH_OFF 12
81 /* Create Connection */
82
83 /* Disconnect */
84 extern void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason);
85
86 #define HCIC_PARAM_SIZE_DISCONNECT 3
87
88 #define HCI_DISC_HANDLE_OFF 0
89 #define HCI_DISC_REASON_OFF 2
90 /* Disconnect */
91
92 #if (BTM_SCO_INCLUDED == TRUE)
93 /* Add SCO Connection */
94 extern void btsnd_hcic_add_SCO_conn(uint16_t handle, uint16_t packet_types);
95 #endif /* BTM_SCO_INCLUDED */
96
97 #define HCIC_PARAM_SIZE_ADD_SCO_CONN 4
98
99 #define HCI_ADD_SCO_HANDLE_OFF 0
100 #define HCI_ADD_SCO_PACKET_TYPES_OFF 2
101 /* Add SCO Connection */
102
103 /* Create Connection Cancel */
104 extern void btsnd_hcic_create_conn_cancel(const RawAddress& dest);
105
106 #define HCIC_PARAM_SIZE_CREATE_CONN_CANCEL 6
107
108 #define HCIC_CR_CONN_CANCEL_BD_ADDR_OFF 0
109 /* Create Connection Cancel */
110
111 /* Accept Connection Request */
112 extern void btsnd_hcic_accept_conn(const RawAddress& bd_addr, uint8_t role);
113
114 #define HCIC_PARAM_SIZE_ACCEPT_CONN 7
115
116 #define HCI_ACC_CONN_BD_ADDR_OFF 0
117 #define HCI_ACC_CONN_ROLE_OFF 6
118 /* Accept Connection Request */
119
120 /* Reject Connection Request */
121 extern void btsnd_hcic_reject_conn(const RawAddress& bd_addr, uint8_t reason);
122
123 #define HCIC_PARAM_SIZE_REJECT_CONN 7
124
125 #define HCI_REJ_CONN_BD_ADDR_OFF 0
126 #define HCI_REJ_CONN_REASON_OFF 6
127 /* Reject Connection Request */
128
129 /* Link Key Request Reply */
130 extern void btsnd_hcic_link_key_req_reply(const RawAddress& bd_addr,
131                                           LINK_KEY link_key);
132
133 #define HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY 22
134
135 #define HCI_LINK_KEY_REPLY_BD_ADDR_OFF 0
136 #define HCI_LINK_KEY_REPLY_LINK_KEY_OFF 6
137 /* Link Key Request Reply  */
138
139 /* Link Key Request Neg Reply */
140 extern void btsnd_hcic_link_key_neg_reply(const RawAddress& bd_addr);
141
142 #define HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY 6
143
144 #define HCI_LINK_KEY_NEG_REP_BD_ADR_OFF 0
145 /* Link Key Request Neg Reply  */
146
147 /* PIN Code Request Reply */
148 extern void btsnd_hcic_pin_code_req_reply(const RawAddress& bd_addr,
149                                           uint8_t pin_code_len,
150                                           PIN_CODE pin_code);
151
152 #define HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY 23
153
154 #define HCI_PIN_CODE_REPLY_BD_ADDR_OFF 0
155 #define HCI_PIN_CODE_REPLY_PIN_LEN_OFF 6
156 #define HCI_PIN_CODE_REPLY_PIN_CODE_OFF 7
157 /* PIN Code Request Reply  */
158
159 /* Link Key Request Neg Reply */
160 extern void btsnd_hcic_pin_code_neg_reply(const RawAddress& bd_addr);
161
162 #define HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY 6
163
164 #define HCI_PIN_CODE_NEG_REP_BD_ADR_OFF 0
165 /* Link Key Request Neg Reply  */
166
167 /* Change Connection Type */
168 extern void btsnd_hcic_change_conn_type(uint16_t handle, uint16_t packet_types);
169
170 #define HCIC_PARAM_SIZE_CHANGE_CONN_TYPE 4
171
172 #define HCI_CHNG_PKT_TYPE_HANDLE_OFF 0
173 #define HCI_CHNG_PKT_TYPE_PKT_TYPE_OFF 2
174 /* Change Connection Type */
175
176 #define HCIC_PARAM_SIZE_CMD_HANDLE 2
177
178 #define HCI_CMD_HANDLE_HANDLE_OFF 0
179
180 extern void btsnd_hcic_auth_request(
181     uint16_t handle); /* Authentication Request */
182
183 /* Set Connection Encryption */
184 extern void btsnd_hcic_set_conn_encrypt(uint16_t handle, bool enable);
185 #define HCIC_PARAM_SIZE_SET_CONN_ENCRYPT 3
186
187 #define HCI_SET_ENCRYPT_HANDLE_OFF 0
188 #define HCI_SET_ENCRYPT_ENABLE_OFF 2
189 /* Set Connection Encryption */
190
191 /* Remote Name Request */
192 extern void btsnd_hcic_rmt_name_req(const RawAddress& bd_addr,
193                                     uint8_t page_scan_rep_mode,
194                                     uint8_t page_scan_mode,
195                                     uint16_t clock_offset);
196
197 #define HCIC_PARAM_SIZE_RMT_NAME_REQ 10
198
199 #define HCI_RMT_NAME_BD_ADDR_OFF 0
200 #define HCI_RMT_NAME_REP_MODE_OFF 6
201 #define HCI_RMT_NAME_PAGE_SCAN_MODE_OFF 7
202 #define HCI_RMT_NAME_CLK_OFF_OFF 8
203 /* Remote Name Request */
204
205 /* Remote Name Request Cancel */
206 extern void btsnd_hcic_rmt_name_req_cancel(const RawAddress& bd_addr);
207
208 #define HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL 6
209
210 #define HCI_RMT_NAME_CANCEL_BD_ADDR_OFF 0
211 /* Remote Name Request Cancel */
212
213 extern void btsnd_hcic_rmt_features_req(
214     uint16_t handle); /* Remote Features Request */
215
216 /* Remote Extended Features */
217 extern void btsnd_hcic_rmt_ext_features(uint16_t handle, uint8_t page_num);
218
219 #define HCIC_PARAM_SIZE_RMT_EXT_FEATURES 3
220
221 #define HCI_RMT_EXT_FEATURES_HANDLE_OFF 0
222 #define HCI_RMT_EXT_FEATURES_PAGE_NUM_OFF 2
223 /* Remote Extended Features */
224
225 extern void btsnd_hcic_rmt_ver_req(
226     uint16_t handle); /* Remote Version Info Request */
227 extern void btsnd_hcic_read_rmt_clk_offset(
228     uint16_t handle); /* Remote Clock Offset */
229 extern void btsnd_hcic_read_lmp_handle(uint16_t handle); /* Remote LMP Handle */
230 extern void btsnd_hcic_setup_esco_conn(uint16_t handle,
231                                        uint32_t transmit_bandwidth,
232                                        uint32_t receive_bandwidth,
233                                        uint16_t max_latency, uint16_t voice,
234                                        uint8_t retrans_effort,
235                                        uint16_t packet_types);
236 #define HCIC_PARAM_SIZE_SETUP_ESCO 17
237
238 #define HCI_SETUP_ESCO_HANDLE_OFF 0
239 #define HCI_SETUP_ESCO_TX_BW_OFF 2
240 #define HCI_SETUP_ESCO_RX_BW_OFF 6
241 #define HCI_SETUP_ESCO_MAX_LAT_OFF 10
242 #define HCI_SETUP_ESCO_VOICE_OFF 12
243 #define HCI_SETUP_ESCO_RETRAN_EFF_OFF 14
244 #define HCI_SETUP_ESCO_PKT_TYPES_OFF 15
245
246 extern void btsnd_hcic_accept_esco_conn(
247     const RawAddress& bd_addr, uint32_t transmit_bandwidth,
248     uint32_t receive_bandwidth, uint16_t max_latency, uint16_t content_fmt,
249     uint8_t retrans_effort, uint16_t packet_types);
250 #define HCIC_PARAM_SIZE_ACCEPT_ESCO 21
251
252 #define HCI_ACCEPT_ESCO_BDADDR_OFF 0
253 #define HCI_ACCEPT_ESCO_TX_BW_OFF 6
254 #define HCI_ACCEPT_ESCO_RX_BW_OFF 10
255 #define HCI_ACCEPT_ESCO_MAX_LAT_OFF 14
256 #define HCI_ACCEPT_ESCO_VOICE_OFF 16
257 #define HCI_ACCEPT_ESCO_RETRAN_EFF_OFF 18
258 #define HCI_ACCEPT_ESCO_PKT_TYPES_OFF 19
259
260 extern void btsnd_hcic_reject_esco_conn(const RawAddress& bd_addr,
261                                         uint8_t reason);
262 #define HCIC_PARAM_SIZE_REJECT_ESCO 7
263
264 #define HCI_REJECT_ESCO_BDADDR_OFF 0
265 #define HCI_REJECT_ESCO_REASON_OFF 6
266
267 /* Hold Mode */
268 extern void btsnd_hcic_hold_mode(uint16_t handle, uint16_t max_hold_period,
269                                  uint16_t min_hold_period);
270
271 #define HCIC_PARAM_SIZE_HOLD_MODE 6
272
273 #define HCI_HOLD_MODE_HANDLE_OFF 0
274 #define HCI_HOLD_MODE_MAX_PER_OFF 2
275 #define HCI_HOLD_MODE_MIN_PER_OFF 4
276 /* Hold Mode */
277
278 /* Sniff Mode */
279 extern void btsnd_hcic_sniff_mode(uint16_t handle, uint16_t max_sniff_period,
280                                   uint16_t min_sniff_period,
281                                   uint16_t sniff_attempt,
282                                   uint16_t sniff_timeout);
283
284 #define HCIC_PARAM_SIZE_SNIFF_MODE 10
285
286 #define HCI_SNIFF_MODE_HANDLE_OFF 0
287 #define HCI_SNIFF_MODE_MAX_PER_OFF 2
288 #define HCI_SNIFF_MODE_MIN_PER_OFF 4
289 #define HCI_SNIFF_MODE_ATTEMPT_OFF 6
290 #define HCI_SNIFF_MODE_TIMEOUT_OFF 8
291 /* Sniff Mode */
292
293 extern void btsnd_hcic_exit_sniff_mode(uint16_t handle); /* Exit Sniff Mode */
294
295 /* Park Mode */
296 extern void btsnd_hcic_park_mode(uint16_t handle, uint16_t beacon_max_interval,
297                                  uint16_t beacon_min_interval);
298
299 #define HCIC_PARAM_SIZE_PARK_MODE 6
300
301 #define HCI_PARK_MODE_HANDLE_OFF 0
302 #define HCI_PARK_MODE_MAX_PER_OFF 2
303 #define HCI_PARK_MODE_MIN_PER_OFF 4
304 /* Park Mode */
305
306 extern void btsnd_hcic_exit_park_mode(uint16_t handle); /* Exit Park Mode */
307
308 /* QoS Setup */
309 extern void btsnd_hcic_qos_setup(uint16_t handle, uint8_t flags,
310                                  uint8_t service_type, uint32_t token_rate,
311                                  uint32_t peak, uint32_t latency,
312                                  uint32_t delay_var);
313
314 #define HCIC_PARAM_SIZE_QOS_SETUP 20
315
316 #define HCI_QOS_HANDLE_OFF 0
317 #define HCI_QOS_FLAGS_OFF 2
318 #define HCI_QOS_SERVICE_TYPE_OFF 3
319 #define HCI_QOS_TOKEN_RATE_OFF 4
320 #define HCI_QOS_PEAK_BANDWIDTH_OFF 8
321 #define HCI_QOS_LATENCY_OFF 12
322 #define HCI_QOS_DELAY_VAR_OFF 16
323 /* QoS Setup */
324
325 /* Switch Role Request */
326 extern void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role);
327
328 #define HCIC_PARAM_SIZE_SWITCH_ROLE 7
329
330 #define HCI_SWITCH_BD_ADDR_OFF 0
331 #define HCI_SWITCH_ROLE_OFF 6
332 /* Switch Role Request */
333
334 /* Write Policy Settings */
335 extern void btsnd_hcic_write_policy_set(uint16_t handle, uint16_t settings);
336
337 #define HCIC_PARAM_SIZE_WRITE_POLICY_SET 4
338
339 #define HCI_WRITE_POLICY_HANDLE_OFF 0
340 #define HCI_WRITE_POLICY_SETTINGS_OFF 2
341 /* Write Policy Settings */
342
343 /* Write Default Policy Settings */
344 extern void btsnd_hcic_write_def_policy_set(uint16_t settings);
345
346 #define HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET 2
347
348 #define HCI_WRITE_DEF_POLICY_SETTINGS_OFF 0
349 /* Write Default Policy Settings */
350
351 /******************************************
352  *    Lisbon Features
353  ******************************************/
354 #if (BTM_SSR_INCLUDED == TRUE)
355 /* Sniff Subrating */
356 extern void btsnd_hcic_sniff_sub_rate(uint16_t handle, uint16_t max_lat,
357                                       uint16_t min_remote_lat,
358                                       uint16_t min_local_lat);
359
360 #define HCIC_PARAM_SIZE_SNIFF_SUB_RATE 8
361
362 #define HCI_SNIFF_SUB_RATE_HANDLE_OFF 0
363 #define HCI_SNIFF_SUB_RATE_MAX_LAT_OFF 2
364 #define HCI_SNIFF_SUB_RATE_MIN_REM_LAT_OFF 4
365 #define HCI_SNIFF_SUB_RATE_MIN_LOC_LAT_OFF 6
366 /* Sniff Subrating */
367
368 #else /* BTM_SSR_INCLUDED == FALSE */
369
370 #define btsnd_hcic_sniff_sub_rate(handle, max_lat, min_remote_lat, \
371                                   min_local_lat)                   \
372   false
373
374 #endif /* BTM_SSR_INCLUDED */
375
376 /* Extended Inquiry Response */
377 extern void btsnd_hcic_write_ext_inquiry_response(void* buffer,
378                                                   uint8_t fec_req);
379
380 #define HCIC_PARAM_SIZE_EXT_INQ_RESP 241
381
382 #define HCIC_EXT_INQ_RESP_FEC_OFF 0
383 #define HCIC_EXT_INQ_RESP_RESPONSE 1
384 /* IO Capabilities Response */
385 extern void btsnd_hcic_io_cap_req_reply(const RawAddress& bd_addr,
386                                         uint8_t capability, uint8_t oob_present,
387                                         uint8_t auth_req);
388
389 #define HCIC_PARAM_SIZE_IO_CAP_RESP 9
390
391 #define HCI_IO_CAP_BD_ADDR_OFF 0
392 #define HCI_IO_CAPABILITY_OFF 6
393 #define HCI_IO_CAP_OOB_DATA_OFF 7
394 #define HCI_IO_CAP_AUTH_REQ_OFF 8
395
396 /* IO Capabilities Req Neg Reply */
397 extern void btsnd_hcic_io_cap_req_neg_reply(const RawAddress& bd_addr,
398                                             uint8_t err_code);
399
400 #define HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY 7
401
402 #define HCI_IO_CAP_NR_BD_ADDR_OFF 0
403 #define HCI_IO_CAP_NR_ERR_CODE 6
404
405 /* Read Local OOB Data */
406 extern void btsnd_hcic_read_local_oob_data(void);
407
408 #define HCIC_PARAM_SIZE_R_LOCAL_OOB 0
409
410 extern void btsnd_hcic_user_conf_reply(const RawAddress& bd_addr, bool is_yes);
411
412 #define HCIC_PARAM_SIZE_UCONF_REPLY 6
413
414 #define HCI_USER_CONF_BD_ADDR_OFF 0
415
416 extern void btsnd_hcic_user_passkey_reply(const RawAddress& bd_addr,
417                                           uint32_t value);
418
419 #define HCIC_PARAM_SIZE_U_PKEY_REPLY 10
420
421 #define HCI_USER_PASSKEY_BD_ADDR_OFF 0
422 #define HCI_USER_PASSKEY_VALUE_OFF 6
423
424 extern void btsnd_hcic_user_passkey_neg_reply(const RawAddress& bd_addr);
425
426 #define HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY 6
427
428 #define HCI_USER_PASSKEY_NEG_BD_ADDR_OFF 0
429
430 /* Remote OOB Data Request Reply */
431 extern void btsnd_hcic_rem_oob_reply(const RawAddress& bd_addr, uint8_t* p_c,
432                                      uint8_t* p_r);
433
434 #define HCIC_PARAM_SIZE_REM_OOB_REPLY 38
435
436 #define HCI_REM_OOB_DATA_BD_ADDR_OFF 0
437 #define HCI_REM_OOB_DATA_C_OFF 6
438 #define HCI_REM_OOB_DATA_R_OFF 22
439
440 /* Remote OOB Data Request Negative Reply */
441 extern void btsnd_hcic_rem_oob_neg_reply(const RawAddress& bd_addr);
442
443 #define HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY 6
444
445 #define HCI_REM_OOB_DATA_NEG_BD_ADDR_OFF 0
446
447 /* Read Tx Power Level */
448 extern void btsnd_hcic_read_inq_tx_power(void);
449
450 #define HCIC_PARAM_SIZE_R_TX_POWER 0
451
452 /* Read Default Erroneous Data Reporting */
453 extern void btsnd_hcic_read_default_erroneous_data_rpt(void);
454
455 #define HCIC_PARAM_SIZE_R_ERR_DATA_RPT 0
456
457 #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
458 extern void btsnd_hcic_enhanced_flush(uint16_t handle, uint8_t packet_type);
459
460 #define HCIC_PARAM_SIZE_ENHANCED_FLUSH 3
461 #endif
462
463 extern void btsnd_hcic_send_keypress_notif(const RawAddress& bd_addr,
464                                            uint8_t notif);
465
466 #define HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF 7
467
468 #define HCI_SEND_KEYPRESS_NOTIF_BD_ADDR_OFF 0
469 #define HCI_SEND_KEYPRESS_NOTIF_NOTIF_OFF 6
470
471 /**** end of Simple Pairing Commands ****/
472
473 /* Store Current Settings */
474 #define MAX_FILT_COND (sizeof(BD_ADDR) + 1)
475
476 extern void btsnd_hcic_set_event_filter(uint8_t filt_type,
477                                         uint8_t filt_cond_type,
478                                         uint8_t* filt_cond,
479                                         uint8_t filt_cond_len);
480
481 #define HCIC_PARAM_SIZE_SET_EVT_FILTER 9
482
483 #define HCI_FILT_COND_FILT_TYPE_OFF 0
484 #define HCI_FILT_COND_COND_TYPE_OFF 1
485 #define HCI_FILT_COND_FILT_OFF 2
486 /* Set Event Filter */
487
488 /* Delete Stored Key */
489 extern void btsnd_hcic_delete_stored_key(const RawAddress& bd_addr,
490                                          bool delete_all_flag);
491
492 #define HCIC_PARAM_SIZE_DELETE_STORED_KEY 7
493
494 #define HCI_DELETE_KEY_BD_ADDR_OFF 0
495 #define HCI_DELETE_KEY_ALL_FLAG_OFF 6
496 /* Delete Stored Key */
497
498 /* Change Local Name */
499 extern void btsnd_hcic_change_name(BD_NAME name);
500
501 #define HCIC_PARAM_SIZE_CHANGE_NAME BD_NAME_LEN
502
503 #define HCI_CHANGE_NAME_NAME_OFF 0
504 /* Change Local Name */
505
506 #define HCIC_PARAM_SIZE_READ_CMD 0
507
508 #define HCIC_PARAM_SIZE_WRITE_PARAM1 1
509
510 #define HCIC_WRITE_PARAM1_PARAM_OFF 0
511
512 #define HCIC_PARAM_SIZE_WRITE_PARAM2 2
513
514 #define HCIC_WRITE_PARAM2_PARAM_OFF 0
515
516 #define HCIC_PARAM_SIZE_WRITE_PARAM3 3
517
518 #define HCIC_WRITE_PARAM3_PARAM_OFF 0
519
520 #define HCIC_PARAM_SIZE_SET_AFH_CHANNELS 10
521
522 extern void btsnd_hcic_write_pin_type(uint8_t type);    /* Write PIN Type */
523 extern void btsnd_hcic_write_auto_accept(uint8_t flag); /* Write Auto Accept */
524 extern void btsnd_hcic_read_name(void);                 /* Read Local Name */
525 extern void btsnd_hcic_write_page_tout(
526     uint16_t timeout);                                  /* Write Page Timout */
527 extern void btsnd_hcic_write_scan_enable(uint8_t flag); /* Write Scan Enable */
528 extern void btsnd_hcic_write_pagescan_cfg(
529     uint16_t interval, uint16_t window); /* Write Page Scan Activity */
530
531 #define HCIC_PARAM_SIZE_ENH_SET_ESCO_CONN 59
532 #define HCIC_PARAM_SIZE_ENH_ACC_ESCO_CONN 63
533
534 #define HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG 4
535
536 #define HCI_SCAN_CFG_INTERVAL_OFF 0
537 #define HCI_SCAN_CFG_WINDOW_OFF 2
538 /* Write Page Scan Activity */
539
540 /* Write Inquiry Scan Activity */
541 extern void btsnd_hcic_write_inqscan_cfg(uint16_t interval, uint16_t window);
542
543 #define HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG 4
544
545 #define HCI_SCAN_CFG_INTERVAL_OFF 0
546 #define HCI_SCAN_CFG_WINDOW_OFF 2
547 /* Write Inquiry Scan Activity */
548
549 extern void btsnd_hcic_write_auth_enable(
550     uint8_t flag); /* Write Authentication Enable */
551 extern void btsnd_hcic_write_dev_class(
552     DEV_CLASS dev); /* Write Class of Device */
553 extern void btsnd_hcic_write_voice_settings(
554     uint16_t flags); /* Write Voice Settings */
555
556 /* Host Controller to Host flow control */
557 #define HCI_HOST_FLOW_CTRL_OFF 0
558 #define HCI_HOST_FLOW_CTRL_ACL_ON 1
559 #define HCI_HOST_FLOW_CTRL_SCO_ON 2
560 #define HCI_HOST_FLOW_CTRL_BOTH_ON 3
561
562 extern void btsnd_hcic_write_auto_flush_tout(
563     uint16_t handle, uint16_t timeout); /* Write Retransmit Timout */
564
565 #define HCIC_PARAM_SIZE_WRITE_AUTOMATIC_FLUSH_TIMEOUT 4
566
567 #define HCI_FLUSH_TOUT_HANDLE_OFF 0
568 #define HCI_FLUSH_TOUT_TOUT_OFF 2
569
570 extern void btsnd_hcic_read_tx_power(uint16_t handle,
571                                      uint8_t type); /* Read Tx Power */
572
573 #define HCIC_PARAM_SIZE_READ_TX_POWER 3
574
575 #define HCI_READ_TX_POWER_HANDLE_OFF 0
576 #define HCI_READ_TX_POWER_TYPE_OFF 2
577
578 /* Read transmit power level parameter */
579 #define HCI_READ_CURRENT 0x00
580 #define HCI_READ_MAXIMUM 0x01
581
582 extern void btsnd_hcic_host_num_xmitted_pkts(
583     uint8_t num_handles, uint16_t* handle,
584     uint16_t* num_pkts); /* Set Host Buffer Size */
585
586 #define HCIC_PARAM_SIZE_NUM_PKTS_DONE_SIZE sizeof(btmsg_hcic_num_pkts_done_t)
587
588 #define MAX_DATA_HANDLES 10
589
590 #define HCI_PKTS_DONE_NUM_HANDLES_OFF 0
591 #define HCI_PKTS_DONE_HANDLE_OFF 1
592 #define HCI_PKTS_DONE_NUM_PKTS_OFF 3
593
594 /* Write Link Supervision Timeout */
595 extern void btsnd_hcic_write_link_super_tout(uint8_t local_controller_id,
596                                              uint16_t handle, uint16_t timeout);
597
598 #define HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT 4
599
600 #define HCI_LINK_SUPER_TOUT_HANDLE_OFF 0
601 #define HCI_LINK_SUPER_TOUT_TOUT_OFF 2
602 /* Write Link Supervision Timeout */
603
604 extern void btsnd_hcic_write_cur_iac_lap(
605     uint8_t num_cur_iac, LAP* const iac_lap); /* Write Current IAC LAP */
606
607 #define MAX_IAC_LAPS 0x40
608
609 #define HCI_WRITE_IAC_LAP_NUM_OFF 0
610 #define HCI_WRITE_IAC_LAP_LAP_OFF 1
611 /* Write Current IAC LAP */
612
613 extern void btsnd_hcic_get_link_quality(uint16_t handle); /* Get Link Quality */
614 extern void btsnd_hcic_read_rssi(uint16_t handle);        /* Read RSSI */
615 extern void btsnd_hcic_read_failed_contact_counter(uint16_t handle);
616 extern void btsnd_hcic_read_automatic_flush_timeout(uint16_t handle);
617 extern void btsnd_hcic_enable_test_mode(
618     void); /* Enable Device Under Test Mode */
619 extern void btsnd_hcic_write_pagescan_type(
620     uint8_t type); /* Write Page Scan Type */
621 extern void btsnd_hcic_write_inqscan_type(
622     uint8_t type); /* Write Inquiry Scan Type */
623 extern void btsnd_hcic_write_inquiry_mode(
624     uint8_t type); /* Write Inquiry Mode */
625
626 /* Enhanced setup SCO connection (CSA2) */
627 extern void btsnd_hcic_enhanced_set_up_synchronous_connection(
628     uint16_t conn_handle, enh_esco_params_t* p_parms);
629
630 /* Enhanced accept SCO connection request (CSA2) */
631 extern void btsnd_hcic_enhanced_accept_synchronous_connection(
632     const RawAddress& bd_addr, enh_esco_params_t* p_parms);
633
634 #define HCI_DATA_HANDLE_MASK 0x0FFF
635
636 #define HCID_GET_HANDLE_EVENT(p)                     \
637   (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset) + \
638               (*((uint8_t*)((p) + 1) + (p)->offset + 1) << 8)))
639
640 #define HCID_GET_HANDLE(u16) (uint16_t)((u16)&HCI_DATA_HANDLE_MASK)
641
642 #define HCI_DATA_EVENT_MASK 3
643 #define HCI_DATA_EVENT_OFFSET 12
644 #define HCID_GET_EVENT(u16) \
645   (uint8_t)(((u16) >> HCI_DATA_EVENT_OFFSET) & HCI_DATA_EVENT_MASK)
646
647 #define HCI_DATA_BCAST_MASK 3
648 #define HCI_DATA_BCAST_OFFSET 10
649 #define HCID_GET_BCAST(u16) \
650   (uint8_t)(((u16) >> HCI_DATA_BCAST_OFFSET) & HCI_DATA_BCAST_MASK)
651
652 #define HCID_GET_ACL_LEN(p)                              \
653   (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset + 2) + \
654               (*((uint8_t*)((p) + 1) + (p)->offset + 3) << 8)))
655
656 #define HCID_HEADER_SIZE 4
657
658 #define HCID_GET_SCO_LEN(p) (*((uint8_t*)((p) + 1) + (p)->offset + 2))
659
660 extern void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode,
661                                        uint8_t len, uint8_t* p_data,
662                                        void* p_cmd_cplt_cback);
663
664 /*******************************************************************************
665  * BLE Commands
666  *      Note: "local_controller_id" is for transport, not counted in HCI
667  *             message size
668  ******************************************************************************/
669 #define HCIC_BLE_RAND_DI_SIZE 8
670 #define HCIC_BLE_ENCRYT_KEY_SIZE 16
671 #define HCIC_BLE_IRK_SIZE 16
672
673 #define HCIC_PARAM_SIZE_SET_USED_FEAT_CMD 8
674 #define HCIC_PARAM_SIZE_WRITE_RANDOM_ADDR_CMD 6
675 #define HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS 15
676 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP 31
677 #define HCIC_PARAM_SIZE_WRITE_ADV_ENABLE 1
678 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM 7
679 #define HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE 2
680 #define HCIC_PARAM_SIZE_BLE_CREATE_LL_CONN 25
681 #define HCIC_PARAM_SIZE_BLE_CREATE_CONN_CANCEL 0
682 #define HCIC_PARAM_SIZE_CLEAR_WHITE_LIST 0
683 #define HCIC_PARAM_SIZE_ADD_WHITE_LIST 7
684 #define HCIC_PARAM_SIZE_REMOVE_WHITE_LIST 7
685 #define HCIC_PARAM_SIZE_BLE_UPD_LL_CONN_PARAMS 14
686 #define HCIC_PARAM_SIZE_SET_HOST_CHNL_CLASS 5
687 #define HCIC_PARAM_SIZE_READ_CHNL_MAP 2
688 #define HCIC_PARAM_SIZE_BLE_READ_REMOTE_FEAT 2
689 #define HCIC_PARAM_SIZE_BLE_ENCRYPT 32
690 #define HCIC_PARAM_SIZE_WRITE_LE_HOST_SUPPORTED 2
691
692 #define HCIC_BLE_RAND_DI_SIZE 8
693 #define HCIC_BLE_ENCRYT_KEY_SIZE 16
694 #define HCIC_PARAM_SIZE_BLE_START_ENC \
695   (4 + HCIC_BLE_RAND_DI_SIZE + HCIC_BLE_ENCRYT_KEY_SIZE)
696 #define HCIC_PARAM_SIZE_LTK_REQ_REPLY (2 + HCIC_BLE_ENCRYT_KEY_SIZE)
697 #define HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY 2
698 #define HCIC_BLE_CHNL_MAP_SIZE 5
699 #define HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA 31
700
701 #define HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST (7 + HCIC_BLE_IRK_SIZE * 2)
702 #define HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST 7
703 #define HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE 8
704 #define HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST 0
705 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVING_LIST_SIZE 0
706 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_PEER 7
707 #define HCIC_PARAM_SIZE_BLE_READ_RESOLVABLE_ADDR_LOCAL 7
708 #define HCIC_PARAM_SIZE_BLE_SET_ADDR_RESOLUTION_ENABLE 1
709 #define HCIC_PARAM_SIZE_BLE_SET_RAND_PRIV_ADDR_TIMOUT 2
710
711 #define HCIC_PARAM_SIZE_BLE_READ_PHY 2
712 #define HCIC_PARAM_SIZE_BLE_SET_DEFAULT_PHY 3
713 #define HCIC_PARAM_SIZE_BLE_SET_PHY 7
714 #define HCIC_PARAM_SIZE_BLE_ENH_RX_TEST 3
715 #define HCIC_PARAM_SIZE_BLE_ENH_TX_TEST 4
716
717 #define HCIC_PARAM_SIZE_BLE_SET_DATA_LENGTH 6
718 #define HCIC_PARAM_SIZE_BLE_WRITE_EXTENDED_SCAN_PARAM 11
719
720 /* ULP HCI command */
721 extern void btsnd_hcic_ble_set_evt_mask(BT_EVENT_MASK event_mask);
722
723 extern void btsnd_hcic_ble_read_buffer_size(void);
724
725 extern void btsnd_hcic_ble_read_local_spt_feat(void);
726
727 extern void btsnd_hcic_ble_set_local_used_feat(uint8_t feat_set[8]);
728
729 extern void btsnd_hcic_ble_set_random_addr(const RawAddress& random_addr);
730
731 extern void btsnd_hcic_ble_write_adv_params(
732     uint16_t adv_int_min, uint16_t adv_int_max, uint8_t adv_type,
733     uint8_t addr_type_own, uint8_t addr_type_dir, const RawAddress& direct_bda,
734     uint8_t channel_map, uint8_t adv_filter_policy);
735
736 extern void btsnd_hcic_ble_read_adv_chnl_tx_power(void);
737
738 extern void btsnd_hcic_ble_set_adv_data(uint8_t data_len, uint8_t* p_data);
739
740 extern void btsnd_hcic_ble_set_scan_rsp_data(uint8_t data_len,
741                                              uint8_t* p_scan_rsp);
742
743 extern void btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable);
744
745 extern void btsnd_hcic_ble_set_scan_params(uint8_t scan_type, uint16_t scan_int,
746                                            uint16_t scan_win, uint8_t addr_type,
747                                            uint8_t scan_filter_policy);
748
749 extern void btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable,
750                                            uint8_t duplicate);
751
752 extern void btsnd_hcic_ble_create_ll_conn(
753     uint16_t scan_int, uint16_t scan_win, uint8_t init_filter_policy,
754     uint8_t addr_type_peer, const RawAddress& bda_peer, uint8_t addr_type_own,
755     uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency,
756     uint16_t conn_timeout, uint16_t min_ce_len, uint16_t max_ce_len);
757
758 extern void btsnd_hcic_ble_create_conn_cancel(void);
759
760 extern void btsnd_hcic_ble_read_white_list_size(void);
761
762 extern void btsnd_hcic_ble_clear_white_list(void);
763
764 extern void btsnd_hcic_ble_add_white_list(uint8_t addr_type,
765                                           const RawAddress& bda);
766
767 extern void btsnd_hcic_ble_remove_from_white_list(uint8_t addr_type,
768                                                   const RawAddress& bda);
769
770 extern void btsnd_hcic_ble_upd_ll_conn_params(
771     uint16_t handle, uint16_t conn_int_min, uint16_t conn_int_max,
772     uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_len,
773     uint16_t max_len);
774
775 extern void btsnd_hcic_ble_set_host_chnl_class(
776     uint8_t chnl_map[HCIC_BLE_CHNL_MAP_SIZE]);
777
778 extern void btsnd_hcic_ble_read_chnl_map(uint16_t handle);
779
780 extern void btsnd_hcic_ble_read_remote_feat(uint16_t handle);
781
782 extern void btsnd_hcic_ble_encrypt(uint8_t* key, uint8_t key_len,
783                                    uint8_t* plain_text, uint8_t pt_len,
784                                    void* p_cmd_cplt_cback);
785
786 extern void btsnd_hcic_ble_rand(base::Callback<void(BT_OCTET8)> cb);
787
788 extern void btsnd_hcic_ble_start_enc(uint16_t handle,
789                                      uint8_t rand[HCIC_BLE_RAND_DI_SIZE],
790                                      uint16_t ediv,
791                                      uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]);
792
793 extern void btsnd_hcic_ble_ltk_req_reply(uint16_t handle,
794                                          uint8_t ltk[HCIC_BLE_ENCRYT_KEY_SIZE]);
795
796 extern void btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle);
797
798 extern void btsnd_hcic_ble_read_supported_states(void);
799
800 extern void btsnd_hcic_ble_write_host_supported(uint8_t le_host_spt,
801                                                 uint8_t simul_le_host_spt);
802
803 extern void btsnd_hcic_ble_read_host_supported(void);
804
805 extern void btsnd_hcic_ble_receiver_test(uint8_t rx_freq);
806
807 extern void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq,
808                                             uint8_t test_data_len,
809                                             uint8_t payload);
810 extern void btsnd_hcic_ble_test_end(void);
811
812 #if (BLE_LLT_INCLUDED == TRUE)
813
814 #define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_REPLY 14
815 extern void btsnd_hcic_ble_rc_param_req_reply(
816     uint16_t handle, uint16_t conn_int_min, uint16_t conn_int_max,
817     uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_ce_len,
818     uint16_t max_ce_len);
819
820 #define HCIC_PARAM_SIZE_BLE_RC_PARAM_REQ_NEG_REPLY 3
821 extern void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle,
822                                                   uint8_t reason);
823
824 #endif /* BLE_LLT_INCLUDED */
825
826 extern void btsnd_hcic_ble_set_data_length(uint16_t conn_handle,
827                                            uint16_t tx_octets,
828                                            uint16_t tx_time);
829
830 extern void btsnd_hcic_ble_add_device_resolving_list(
831     uint8_t addr_type_peer, const RawAddress& bda_peer,
832     uint8_t irk_peer[HCIC_BLE_IRK_SIZE], uint8_t irk_local[HCIC_BLE_IRK_SIZE]);
833
834 struct scanning_phy_cfg {
835   uint8_t scan_type;
836   uint16_t scan_int;
837   uint16_t scan_win;
838 };
839
840 extern void btsnd_hcic_ble_set_extended_scan_params(
841     uint8_t own_address_type, uint8_t scanning_filter_policy,
842     uint8_t scanning_phys, scanning_phy_cfg* phy_cfg);
843
844 extern void btsnd_hcic_ble_set_extended_scan_enable(uint8_t enable,
845                                                     uint8_t filter_duplicates,
846                                                     uint16_t duration,
847                                                     uint16_t period);
848
849 struct EXT_CONN_PHY_CFG {
850   uint16_t scan_int;
851   uint16_t scan_win;
852   uint16_t conn_int_min;
853   uint16_t conn_int_max;
854   uint16_t conn_latency;
855   uint16_t sup_timeout;
856   uint16_t min_ce_len;
857   uint16_t max_ce_len;
858 };
859
860 extern void btsnd_hcic_ble_ext_create_conn(uint8_t init_filter_policy,
861                                            uint8_t addr_type_own,
862                                            uint8_t addr_type_peer,
863                                            const RawAddress& bda_peer,
864                                            uint8_t initiating_phys,
865                                            EXT_CONN_PHY_CFG* phy_cfg);
866
867 extern void btsnd_hcic_ble_add_device_resolving_list(
868     uint8_t addr_type_peer, const RawAddress& bda_peer,
869     uint8_t irk_peer[HCIC_BLE_IRK_SIZE], uint8_t irk_local[HCIC_BLE_IRK_SIZE]);
870
871 extern void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer,
872                                                     const RawAddress& bda_peer);
873
874 extern void btsnd_hcic_ble_set_privacy_mode(uint8_t addr_type_peer,
875                                             const RawAddress& bda_peer,
876                                             uint8_t privacy_type);
877
878 extern void btsnd_hcic_ble_clear_resolving_list(void);
879
880 extern void btsnd_hcic_ble_read_resolvable_addr_peer(
881     uint8_t addr_type_peer, const RawAddress& bda_peer);
882
883 extern void btsnd_hcic_ble_read_resolvable_addr_local(
884     uint8_t addr_type_peer, const RawAddress& bda_peer);
885
886 extern void btsnd_hcic_ble_set_addr_resolution_enable(
887     uint8_t addr_resolution_enable);
888
889 extern void btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timout);
890
891 extern void btsnd_hcic_read_authenticated_payload_tout(uint16_t handle);
892
893 extern void btsnd_hcic_write_authenticated_payload_tout(uint16_t handle,
894                                                         uint16_t timeout);
895
896 #define HCIC_PARAM_SIZE_WRITE_AUTHENT_PAYLOAD_TOUT 4
897
898 #define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_HANDLE_OFF 0
899 #define HCI__WRITE_AUTHENT_PAYLOAD_TOUT_TOUT_OFF 2
900
901 #endif