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