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