1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * This file contains functions that interface with the HCI transport. On
22 * the receive side, it routes events to the appropriate handler, e.g.
23 * L2CAP, ScoMgr. On the transmit side, it manages the command
26 ******************************************************************************/
28 #define LOG_TAG "bt_btu_hcif"
30 #include <base/bind.h>
31 #include <base/callback.h>
32 #include <base/location.h>
33 #include <base/logging.h>
34 #include <base/threading/thread.h>
39 #include "bt_common.h"
45 #include "device/include/controller.h"
46 #include "hci_layer.h"
49 #include "osi/include/log.h"
50 #include "osi/include/osi.h"
52 using tracked_objects::Location;
54 extern void btm_process_cancel_complete(uint8_t status, uint8_t mode);
55 extern void btm_ble_test_command_complete(uint8_t* p);
57 /******************************************************************************/
58 /* L O C A L F U N C T I O N P R O T O T Y P E S */
59 /******************************************************************************/
60 static void btu_hcif_inquiry_comp_evt(uint8_t* p);
61 static void btu_hcif_inquiry_result_evt(uint8_t* p);
62 static void btu_hcif_inquiry_rssi_result_evt(uint8_t* p);
63 static void btu_hcif_extended_inquiry_result_evt(uint8_t* p);
65 static void btu_hcif_connection_comp_evt(uint8_t* p);
66 static void btu_hcif_connection_request_evt(uint8_t* p);
67 static void btu_hcif_disconnection_comp_evt(uint8_t* p);
68 static void btu_hcif_authentication_comp_evt(uint8_t* p);
69 static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len);
70 static void btu_hcif_encryption_change_evt(uint8_t* p);
71 static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p);
72 static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p);
73 static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p);
74 static void btu_hcif_qos_setup_comp_evt(uint8_t* p);
75 static void btu_hcif_command_complete_evt(BT_HDR* response, void* context);
76 static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command,
78 static void btu_hcif_hardware_error_evt(uint8_t* p);
79 static void btu_hcif_flush_occured_evt(void);
80 static void btu_hcif_role_change_evt(uint8_t* p);
81 static void btu_hcif_num_compl_data_pkts_evt(uint8_t* p);
82 static void btu_hcif_mode_change_evt(uint8_t* p);
83 static void btu_hcif_pin_code_request_evt(uint8_t* p);
84 static void btu_hcif_link_key_request_evt(uint8_t* p);
85 static void btu_hcif_link_key_notification_evt(uint8_t* p);
86 static void btu_hcif_loopback_command_evt(void);
87 static void btu_hcif_data_buf_overflow_evt(void);
88 static void btu_hcif_max_slots_changed_evt(void);
89 static void btu_hcif_read_clock_off_comp_evt(uint8_t* p);
90 static void btu_hcif_conn_pkt_type_change_evt(void);
91 static void btu_hcif_qos_violation_evt(uint8_t* p);
92 static void btu_hcif_page_scan_mode_change_evt(void);
93 static void btu_hcif_page_scan_rep_mode_chng_evt(void);
94 static void btu_hcif_esco_connection_comp_evt(uint8_t* p);
95 static void btu_hcif_esco_connection_chg_evt(uint8_t* p);
97 /* Simple Pairing Events */
98 static void btu_hcif_host_support_evt(uint8_t* p);
99 static void btu_hcif_io_cap_request_evt(uint8_t* p);
100 static void btu_hcif_io_cap_response_evt(uint8_t* p);
101 static void btu_hcif_user_conf_request_evt(uint8_t* p);
102 static void btu_hcif_user_passkey_request_evt(uint8_t* p);
103 static void btu_hcif_user_passkey_notif_evt(uint8_t* p);
104 static void btu_hcif_keypress_notif_evt(uint8_t* p);
105 static void btu_hcif_rem_oob_request_evt(uint8_t* p);
107 static void btu_hcif_simple_pair_complete_evt(uint8_t* p);
108 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
109 static void btu_hcif_enhanced_flush_complete_evt(void);
112 #if (BTM_SSR_INCLUDED == TRUE)
113 static void btu_hcif_ssr_evt(uint8_t* p, uint16_t evt_len);
114 #endif /* BTM_SSR_INCLUDED == TRUE */
116 static void btu_ble_ll_conn_complete_evt(uint8_t* p, uint16_t evt_len);
117 static void btu_ble_read_remote_feat_evt(uint8_t* p);
118 static void btu_ble_ll_conn_param_upd_evt(uint8_t* p, uint16_t evt_len);
119 static void btu_ble_proc_ltk_req(uint8_t* p);
120 static void btu_hcif_encryption_key_refresh_cmpl_evt(uint8_t* p);
121 static void btu_ble_data_length_change_evt(uint8_t* p, uint16_t evt_len);
122 #if (BLE_LLT_INCLUDED == TRUE)
123 static void btu_ble_rc_param_req_evt(uint8_t* p);
125 #if (BLE_PRIVACY_SPT == TRUE)
126 static void btu_ble_proc_enhanced_conn_cmpl(uint8_t* p, uint16_t evt_len);
129 static void do_in_hci_thread(const tracked_objects::Location& from_here,
130 const base::Closure& task) {
131 base::MessageLoop* hci_message_loop = get_message_loop();
132 if (!hci_message_loop || !hci_message_loop->task_runner().get()) {
133 LOG_ERROR(LOG_TAG, "%s: HCI message loop not running, accessed from %s",
134 __func__, from_here.ToString().c_str());
138 hci_message_loop->task_runner()->PostTask(from_here, task);
141 /*******************************************************************************
143 * Function btu_hcif_process_event
145 * Description This function is called when an event is received from
146 * the Host Controller.
150 ******************************************************************************/
151 void btu_hcif_process_event(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_msg) {
152 uint8_t* p = (uint8_t*)(p_msg + 1) + p_msg->offset;
153 uint8_t hci_evt_code, hci_evt_len;
154 uint8_t ble_sub_code;
155 STREAM_TO_UINT8(hci_evt_code, p);
156 STREAM_TO_UINT8(hci_evt_len, p);
158 switch (hci_evt_code) {
159 case HCI_INQUIRY_COMP_EVT:
160 btu_hcif_inquiry_comp_evt(p);
162 case HCI_INQUIRY_RESULT_EVT:
163 btu_hcif_inquiry_result_evt(p);
165 case HCI_INQUIRY_RSSI_RESULT_EVT:
166 btu_hcif_inquiry_rssi_result_evt(p);
168 case HCI_EXTENDED_INQUIRY_RESULT_EVT:
169 btu_hcif_extended_inquiry_result_evt(p);
171 case HCI_CONNECTION_COMP_EVT:
172 btu_hcif_connection_comp_evt(p);
174 case HCI_CONNECTION_REQUEST_EVT:
175 btu_hcif_connection_request_evt(p);
177 case HCI_DISCONNECTION_COMP_EVT:
178 btu_hcif_disconnection_comp_evt(p);
180 case HCI_AUTHENTICATION_COMP_EVT:
181 btu_hcif_authentication_comp_evt(p);
183 case HCI_RMT_NAME_REQUEST_COMP_EVT:
184 btu_hcif_rmt_name_request_comp_evt(p, hci_evt_len);
186 case HCI_ENCRYPTION_CHANGE_EVT:
187 btu_hcif_encryption_change_evt(p);
189 case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT:
190 btu_hcif_encryption_key_refresh_cmpl_evt(p);
192 case HCI_READ_RMT_FEATURES_COMP_EVT:
193 btu_hcif_read_rmt_features_comp_evt(p);
195 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
196 btu_hcif_read_rmt_ext_features_comp_evt(p);
198 case HCI_READ_RMT_VERSION_COMP_EVT:
199 btu_hcif_read_rmt_version_comp_evt(p);
201 case HCI_QOS_SETUP_COMP_EVT:
202 btu_hcif_qos_setup_comp_evt(p);
204 case HCI_COMMAND_COMPLETE_EVT:
206 "%s should not have received a command complete event. "
207 "Someone didn't go through the hci transmit_command function.",
210 case HCI_COMMAND_STATUS_EVT:
212 "%s should not have received a command status event. "
213 "Someone didn't go through the hci transmit_command function.",
216 case HCI_HARDWARE_ERROR_EVT:
217 btu_hcif_hardware_error_evt(p);
219 case HCI_FLUSH_OCCURED_EVT:
220 btu_hcif_flush_occured_evt();
222 case HCI_ROLE_CHANGE_EVT:
223 btu_hcif_role_change_evt(p);
225 case HCI_NUM_COMPL_DATA_PKTS_EVT:
226 btu_hcif_num_compl_data_pkts_evt(p);
228 case HCI_MODE_CHANGE_EVT:
229 btu_hcif_mode_change_evt(p);
231 case HCI_PIN_CODE_REQUEST_EVT:
232 btu_hcif_pin_code_request_evt(p);
234 case HCI_LINK_KEY_REQUEST_EVT:
235 btu_hcif_link_key_request_evt(p);
237 case HCI_LINK_KEY_NOTIFICATION_EVT:
238 btu_hcif_link_key_notification_evt(p);
240 case HCI_LOOPBACK_COMMAND_EVT:
241 btu_hcif_loopback_command_evt();
243 case HCI_DATA_BUF_OVERFLOW_EVT:
244 btu_hcif_data_buf_overflow_evt();
246 case HCI_MAX_SLOTS_CHANGED_EVT:
247 btu_hcif_max_slots_changed_evt();
249 case HCI_READ_CLOCK_OFF_COMP_EVT:
250 btu_hcif_read_clock_off_comp_evt(p);
252 case HCI_CONN_PKT_TYPE_CHANGE_EVT:
253 btu_hcif_conn_pkt_type_change_evt();
255 case HCI_QOS_VIOLATION_EVT:
256 btu_hcif_qos_violation_evt(p);
258 case HCI_PAGE_SCAN_MODE_CHANGE_EVT:
259 btu_hcif_page_scan_mode_change_evt();
261 case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT:
262 btu_hcif_page_scan_rep_mode_chng_evt();
264 case HCI_ESCO_CONNECTION_COMP_EVT:
265 btu_hcif_esco_connection_comp_evt(p);
267 case HCI_ESCO_CONNECTION_CHANGED_EVT:
268 btu_hcif_esco_connection_chg_evt(p);
270 #if (BTM_SSR_INCLUDED == TRUE)
271 case HCI_SNIFF_SUB_RATE_EVT:
272 btu_hcif_ssr_evt(p, hci_evt_len);
274 #endif /* BTM_SSR_INCLUDED == TRUE */
275 case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT:
276 btu_hcif_host_support_evt(p);
278 case HCI_IO_CAPABILITY_REQUEST_EVT:
279 btu_hcif_io_cap_request_evt(p);
281 case HCI_IO_CAPABILITY_RESPONSE_EVT:
282 btu_hcif_io_cap_response_evt(p);
284 case HCI_USER_CONFIRMATION_REQUEST_EVT:
285 btu_hcif_user_conf_request_evt(p);
287 case HCI_USER_PASSKEY_REQUEST_EVT:
288 btu_hcif_user_passkey_request_evt(p);
290 case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
291 btu_hcif_rem_oob_request_evt(p);
293 case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
294 btu_hcif_simple_pair_complete_evt(p);
296 case HCI_USER_PASSKEY_NOTIFY_EVT:
297 btu_hcif_user_passkey_notif_evt(p);
299 case HCI_KEYPRESS_NOTIFY_EVT:
300 btu_hcif_keypress_notif_evt(p);
302 #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
303 case HCI_ENHANCED_FLUSH_COMPLETE_EVT:
304 btu_hcif_enhanced_flush_complete_evt();
308 case HCI_BLE_EVENT: {
309 STREAM_TO_UINT8(ble_sub_code, p);
311 HCI_TRACE_EVENT("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code,
314 uint8_t ble_evt_len = hci_evt_len - 1;
315 switch (ble_sub_code) {
316 case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
317 HCI_TRACE_EVENT("HCI_BLE_ADV_PKT_RPT_EVT");
318 btm_ble_process_adv_pkt(ble_evt_len, p);
320 case HCI_BLE_CONN_COMPLETE_EVT:
321 btu_ble_ll_conn_complete_evt(p, hci_evt_len);
323 case HCI_BLE_LL_CONN_PARAM_UPD_EVT:
324 btu_ble_ll_conn_param_upd_evt(p, hci_evt_len);
326 case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT:
327 btu_ble_read_remote_feat_evt(p);
329 case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */
330 btu_ble_proc_ltk_req(p);
332 #if (BLE_PRIVACY_SPT == TRUE)
333 case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT:
334 btu_ble_proc_enhanced_conn_cmpl(p, hci_evt_len);
337 #if (BLE_LLT_INCLUDED == TRUE)
338 case HCI_BLE_RC_PARAM_REQ_EVT:
339 btu_ble_rc_param_req_evt(p);
342 case HCI_BLE_DATA_LENGTH_CHANGE_EVT:
343 btu_ble_data_length_change_evt(p, hci_evt_len);
346 case HCI_BLE_PHY_UPDATE_COMPLETE_EVT:
347 btm_ble_process_phy_update_pkt(ble_evt_len, p);
350 case HCI_LE_EXTENDED_ADVERTISING_REPORT_EVT:
351 btm_ble_process_ext_adv_pkt(hci_evt_len, p);
354 case HCI_LE_ADVERTISING_SET_TERMINATED_EVT:
355 btm_le_on_advertising_set_terminated(p, hci_evt_len);
361 case HCI_VENDOR_SPECIFIC_EVT:
362 btm_vendor_specific_evt(p, hci_evt_len);
367 /*******************************************************************************
369 * Function btu_hcif_send_cmd
371 * Description This function is called to send commands to the Host
376 ******************************************************************************/
377 void btu_hcif_send_cmd(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_buf) {
381 uint8_t* stream = p_buf->data + p_buf->offset;
382 void* vsc_callback = NULL;
384 STREAM_TO_UINT16(opcode, stream);
386 // Eww...horrible hackery here
387 /* If command was a VSC, then extract command_complete callback */
388 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC ||
389 (opcode == HCI_BLE_RAND) || (opcode == HCI_BLE_ENCRYPT)) {
390 vsc_callback = *((void**)(p_buf + 1));
393 hci_layer_get_interface()->transmit_command(
394 p_buf, btu_hcif_command_complete_evt, btu_hcif_command_status_evt,
398 using hci_cmd_cb = base::Callback<void(uint8_t* /* return_parameters */,
399 uint16_t /* return_parameters_length*/)>;
401 struct cmd_with_cb_data {
403 Location posted_from;
406 void cmd_with_cb_data_init(cmd_with_cb_data* cb_wrapper) {
407 new (&cb_wrapper->cb) hci_cmd_cb;
408 new (&cb_wrapper->posted_from) Location;
411 void cmd_with_cb_data_cleanup(cmd_with_cb_data* cb_wrapper) {
412 cb_wrapper->cb.~hci_cmd_cb();
413 cb_wrapper->posted_from.~Location();
416 static void btu_hcif_command_complete_evt_with_cb_on_task(BT_HDR* event,
418 command_opcode_t opcode;
420 event->data + event->offset +
421 3; // 2 to skip the event headers, 1 to skip the command credits
422 STREAM_TO_UINT16(opcode, stream);
424 cmd_with_cb_data* cb_wrapper = (cmd_with_cb_data*)context;
425 HCI_TRACE_DEBUG("command complete for: %s",
426 cb_wrapper->posted_from.ToString().c_str());
427 cb_wrapper->cb.Run(stream, event->len - 5);
428 cmd_with_cb_data_cleanup(cb_wrapper);
429 osi_free(cb_wrapper);
434 static void btu_hcif_command_complete_evt_with_cb(BT_HDR* response,
436 do_in_hci_thread(FROM_HERE,
437 base::Bind(btu_hcif_command_complete_evt_with_cb_on_task,
441 static void btu_hcif_command_status_evt_with_cb_on_task(uint8_t status,
444 command_opcode_t opcode;
445 uint8_t* stream = event->data + event->offset;
446 STREAM_TO_UINT16(opcode, stream);
450 // report command status error
451 cmd_with_cb_data* cb_wrapper = (cmd_with_cb_data*)context;
452 HCI_TRACE_DEBUG("command status for: %s",
453 cb_wrapper->posted_from.ToString().c_str());
454 cb_wrapper->cb.Run(&status, sizeof(uint16_t));
455 cmd_with_cb_data_cleanup(cb_wrapper);
456 osi_free(cb_wrapper);
461 static void btu_hcif_command_status_evt_with_cb(uint8_t status, BT_HDR* command,
463 // Command is pending, we report only error.
470 FROM_HERE, base::Bind(btu_hcif_command_status_evt_with_cb_on_task, status,
474 /* This function is called to send commands to the Host Controller. |cb| is
475 * called when command status event is called with error code, or when the
476 * command complete event is received. */
477 void btu_hcif_send_cmd_with_cb(const tracked_objects::Location& posted_from,
478 uint16_t opcode, uint8_t* params,
479 uint8_t params_len, hci_cmd_cb cb) {
480 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
481 uint8_t* pp = (uint8_t*)(p + 1);
483 p->len = HCIC_PREAMBLE_SIZE + params_len;
486 UINT16_TO_STREAM(pp, opcode);
487 UINT8_TO_STREAM(pp, params_len);
489 memcpy(pp, params, params_len);
492 cmd_with_cb_data* cb_wrapper =
493 (cmd_with_cb_data*)osi_malloc(sizeof(cmd_with_cb_data));
495 cmd_with_cb_data_init(cb_wrapper);
497 cb_wrapper->posted_from = posted_from;
499 hci_layer_get_interface()->transmit_command(
500 p, btu_hcif_command_complete_evt_with_cb,
501 btu_hcif_command_status_evt_with_cb, (void*)cb_wrapper);
504 /*******************************************************************************
506 * Function btu_hcif_inquiry_comp_evt
508 * Description Process event HCI_INQUIRY_COMP_EVT
512 ******************************************************************************/
513 static void btu_hcif_inquiry_comp_evt(uint8_t* p) {
516 STREAM_TO_UINT8(status, p);
518 /* Tell inquiry processing that we are done */
519 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
522 /*******************************************************************************
524 * Function btu_hcif_inquiry_result_evt
526 * Description Process event HCI_INQUIRY_RESULT_EVT
530 ******************************************************************************/
531 static void btu_hcif_inquiry_result_evt(uint8_t* p) {
532 /* Store results in the cache */
533 btm_process_inq_results(p, BTM_INQ_RESULT_STANDARD);
536 /*******************************************************************************
538 * Function btu_hcif_inquiry_rssi_result_evt
540 * Description Process event HCI_INQUIRY_RSSI_RESULT_EVT
544 ******************************************************************************/
545 static void btu_hcif_inquiry_rssi_result_evt(uint8_t* p) {
546 /* Store results in the cache */
547 btm_process_inq_results(p, BTM_INQ_RESULT_WITH_RSSI);
550 /*******************************************************************************
552 * Function btu_hcif_extended_inquiry_result_evt
554 * Description Process event HCI_EXTENDED_INQUIRY_RESULT_EVT
558 ******************************************************************************/
559 static void btu_hcif_extended_inquiry_result_evt(uint8_t* p) {
560 /* Store results in the cache */
561 btm_process_inq_results(p, BTM_INQ_RESULT_EXTENDED);
564 /*******************************************************************************
566 * Function btu_hcif_connection_comp_evt
568 * Description Process event HCI_CONNECTION_COMP_EVT
572 ******************************************************************************/
573 static void btu_hcif_connection_comp_evt(uint8_t* p) {
579 #if (BTM_SCO_INCLUDED == TRUE)
580 tBTM_ESCO_DATA esco_data;
583 STREAM_TO_UINT8(status, p);
584 STREAM_TO_UINT16(handle, p);
585 STREAM_TO_BDADDR(bda, p);
586 STREAM_TO_UINT8(link_type, p);
587 STREAM_TO_UINT8(enc_mode, p);
589 handle = HCID_GET_HANDLE(handle);
591 if (link_type == HCI_LINK_TYPE_ACL) {
592 btm_sec_connected(bda, handle, status, enc_mode);
594 l2c_link_hci_conn_comp(status, handle, bda);
596 #if (BTM_SCO_INCLUDED == TRUE)
598 memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA));
599 /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */
600 esco_data.bd_addr = bda;
601 btm_sco_connected(status, &bda, handle, &esco_data);
603 #endif /* BTM_SCO_INCLUDED */
606 /*******************************************************************************
608 * Function btu_hcif_connection_request_evt
610 * Description Process event HCI_CONNECTION_REQUEST_EVT
614 ******************************************************************************/
615 static void btu_hcif_connection_request_evt(uint8_t* p) {
620 STREAM_TO_BDADDR(bda, p);
621 STREAM_TO_DEVCLASS(dc, p);
622 STREAM_TO_UINT8(link_type, p);
624 /* Pass request to security manager to check connect filters before */
625 /* passing request to l2cap */
626 if (link_type == HCI_LINK_TYPE_ACL) {
627 btm_sec_conn_req(bda, dc);
629 #if (BTM_SCO_INCLUDED == TRUE)
631 btm_sco_conn_req(bda, dc, link_type);
633 #endif /* BTM_SCO_INCLUDED */
636 /*******************************************************************************
638 * Function btu_hcif_disconnection_comp_evt
640 * Description Process event HCI_DISCONNECTION_COMP_EVT
644 ******************************************************************************/
645 static void btu_hcif_disconnection_comp_evt(uint8_t* p) {
650 STREAM_TO_UINT16(handle, p);
651 STREAM_TO_UINT8(reason, p);
653 handle = HCID_GET_HANDLE(handle);
655 #if (BTM_SCO_INCLUDED == TRUE)
656 /* If L2CAP doesn't know about it, send it to SCO */
657 if (!l2c_link_hci_disc_comp(handle, reason)) btm_sco_removed(handle, reason);
659 l2c_link_hci_disc_comp(handle, reason);
660 #endif /* BTM_SCO_INCLUDED */
662 /* Notify security manager */
663 btm_sec_disconnected(handle, reason);
666 /*******************************************************************************
668 * Function btu_hcif_authentication_comp_evt
670 * Description Process event HCI_AUTHENTICATION_COMP_EVT
674 ******************************************************************************/
675 static void btu_hcif_authentication_comp_evt(uint8_t* p) {
679 STREAM_TO_UINT8(status, p);
680 STREAM_TO_UINT16(handle, p);
682 btm_sec_auth_complete(handle, status);
685 /*******************************************************************************
687 * Function btu_hcif_rmt_name_request_comp_evt
689 * Description Process event HCI_RMT_NAME_REQUEST_COMP_EVT
693 ******************************************************************************/
694 static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len) {
698 STREAM_TO_UINT8(status, p);
699 STREAM_TO_BDADDR(bd_addr, p);
701 evt_len -= (1 + BD_ADDR_LEN);
703 btm_process_remote_name(&bd_addr, p, evt_len, status);
705 btm_sec_rmt_name_request_complete(&bd_addr, p, status);
708 /*******************************************************************************
710 * Function btu_hcif_encryption_change_evt
712 * Description Process event HCI_ENCRYPTION_CHANGE_EVT
716 ******************************************************************************/
717 static void btu_hcif_encryption_change_evt(uint8_t* p) {
722 STREAM_TO_UINT8(status, p);
723 STREAM_TO_UINT16(handle, p);
724 STREAM_TO_UINT8(encr_enable, p);
726 btm_acl_encrypt_change(handle, status, encr_enable);
727 btm_sec_encrypt_change(handle, status, encr_enable);
730 /*******************************************************************************
732 * Function btu_hcif_read_rmt_features_comp_evt
734 * Description Process event HCI_READ_RMT_FEATURES_COMP_EVT
738 ******************************************************************************/
739 static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p) {
740 btm_read_remote_features_complete(p);
743 /*******************************************************************************
745 * Function btu_hcif_read_rmt_ext_features_comp_evt
747 * Description Process event HCI_READ_RMT_EXT_FEATURES_COMP_EVT
751 ******************************************************************************/
752 static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p) {
757 STREAM_TO_UINT8(status, p_cur);
759 if (status == HCI_SUCCESS)
760 btm_read_remote_ext_features_complete(p);
762 STREAM_TO_UINT16(handle, p_cur);
763 btm_read_remote_ext_features_failed(status, handle);
767 /*******************************************************************************
769 * Function btu_hcif_read_rmt_version_comp_evt
771 * Description Process event HCI_READ_RMT_VERSION_COMP_EVT
775 ******************************************************************************/
776 static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p) {
777 btm_read_remote_version_complete(p);
780 /*******************************************************************************
782 * Function btu_hcif_qos_setup_comp_evt
784 * Description Process event HCI_QOS_SETUP_COMP_EVT
788 ******************************************************************************/
789 static void btu_hcif_qos_setup_comp_evt(uint8_t* p) {
794 STREAM_TO_UINT8(status, p);
795 STREAM_TO_UINT16(handle, p);
796 STREAM_TO_UINT8(flow.qos_flags, p);
797 STREAM_TO_UINT8(flow.service_type, p);
798 STREAM_TO_UINT32(flow.token_rate, p);
799 STREAM_TO_UINT32(flow.peak_bandwidth, p);
800 STREAM_TO_UINT32(flow.latency, p);
801 STREAM_TO_UINT32(flow.delay_variation, p);
803 btm_qos_setup_complete(status, handle, &flow);
806 /*******************************************************************************
808 * Function btu_hcif_esco_connection_comp_evt
810 * Description Process event HCI_ESCO_CONNECTION_COMP_EVT
814 ******************************************************************************/
815 static void btu_hcif_esco_connection_comp_evt(uint8_t* p) {
816 #if (BTM_SCO_INCLUDED == TRUE)
822 STREAM_TO_UINT8(status, p);
823 STREAM_TO_UINT16(handle, p);
824 STREAM_TO_BDADDR(bda, p);
826 STREAM_TO_UINT8(data.link_type, p);
827 STREAM_TO_UINT8(data.tx_interval, p);
828 STREAM_TO_UINT8(data.retrans_window, p);
829 STREAM_TO_UINT16(data.rx_pkt_len, p);
830 STREAM_TO_UINT16(data.tx_pkt_len, p);
831 STREAM_TO_UINT8(data.air_mode, p);
834 btm_sco_connected(status, &bda, handle, &data);
838 /*******************************************************************************
840 * Function btu_hcif_esco_connection_chg_evt
842 * Description Process event HCI_ESCO_CONNECTION_CHANGED_EVT
846 ******************************************************************************/
847 static void btu_hcif_esco_connection_chg_evt(uint8_t* p) {
848 #if (BTM_SCO_INCLUDED == TRUE)
854 uint8_t retrans_window;
856 STREAM_TO_UINT8(status, p);
857 STREAM_TO_UINT16(handle, p);
859 STREAM_TO_UINT8(tx_interval, p);
860 STREAM_TO_UINT8(retrans_window, p);
861 STREAM_TO_UINT16(rx_pkt_len, p);
862 STREAM_TO_UINT16(tx_pkt_len, p);
864 btm_esco_proc_conn_chg(status, handle, tx_interval, retrans_window,
865 rx_pkt_len, tx_pkt_len);
869 /*******************************************************************************
871 * Function btu_hcif_hdl_command_complete
873 * Description Handle command complete event
877 ******************************************************************************/
878 static void btu_hcif_hdl_command_complete(uint16_t opcode, uint8_t* p,
880 void* p_cplt_cback) {
882 case HCI_INQUIRY_CANCEL:
883 /* Tell inquiry processing that we are done */
884 btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK);
886 case HCI_SET_EVENT_FILTER:
887 btm_event_filter_complete(p);
890 case HCI_DELETE_STORED_LINK_KEY:
891 btm_delete_stored_link_key_complete(p);
894 case HCI_READ_LOCAL_NAME:
895 btm_read_local_name_complete(p, evt_len);
898 case HCI_GET_LINK_QUALITY:
899 btm_read_link_quality_complete(p);
903 btm_read_rssi_complete(p);
906 case HCI_READ_TRANSMIT_POWER_LEVEL:
907 btm_read_tx_power_complete(p, false);
910 case HCI_CREATE_CONNECTION_CANCEL:
911 btm_create_conn_cancel_complete(p);
914 case HCI_READ_LOCAL_OOB_DATA:
915 btm_read_local_oob_complete(p);
918 case HCI_READ_INQ_TX_POWER_LEVEL:
919 btm_read_inq_tx_power_complete(p);
922 /* BLE Commands sComplete*/
923 case HCI_BLE_ADD_WHITE_LIST:
924 btm_ble_add_2_white_list_complete(*p);
927 case HCI_BLE_CLEAR_WHITE_LIST:
928 btm_ble_clear_white_list_complete(p, evt_len);
931 case HCI_BLE_REMOVE_WHITE_LIST:
932 btm_ble_remove_from_white_list_complete(p, evt_len);
936 case HCI_BLE_ENCRYPT:
937 btm_ble_rand_enc_complete(p, opcode, (tBTM_RAND_ENC_CB*)p_cplt_cback);
940 case HCI_BLE_READ_ADV_CHNL_TX_POWER:
941 btm_read_tx_power_complete(p, true);
944 case HCI_BLE_WRITE_ADV_ENABLE:
945 btm_ble_write_adv_enable_complete(p);
948 case HCI_BLE_CREATE_LL_CONN:
949 btm_ble_create_ll_conn_complete(*p);
952 case HCI_BLE_TRANSMITTER_TEST:
953 case HCI_BLE_RECEIVER_TEST:
954 case HCI_BLE_TEST_END:
955 btm_ble_test_command_complete(p);
958 #if (BLE_PRIVACY_SPT == TRUE)
959 case HCI_BLE_ADD_DEV_RESOLVING_LIST:
960 btm_ble_add_resolving_list_entry_complete(p, evt_len);
963 case HCI_BLE_RM_DEV_RESOLVING_LIST:
964 btm_ble_remove_resolving_list_entry_complete(p, evt_len);
967 case HCI_BLE_CLEAR_RESOLVING_LIST:
968 btm_ble_clear_resolving_list_complete(p, evt_len);
971 case HCI_BLE_READ_RESOLVABLE_ADDR_PEER:
972 btm_ble_read_resolving_list_entry_complete(p, evt_len);
975 case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL:
976 case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE:
977 case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT:
981 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
982 btm_vsc_complete(p, opcode, evt_len, (tBTM_CMPL_CB*)p_cplt_cback);
987 /*******************************************************************************
989 * Function btu_hcif_command_complete_evt
991 * Description Process event HCI_COMMAND_COMPLETE_EVT
995 ******************************************************************************/
996 static void btu_hcif_command_complete_evt_on_task(BT_HDR* event,
998 command_opcode_t opcode;
1000 event->data + event->offset +
1001 3; // 2 to skip the event headers, 1 to skip the command credits
1002 STREAM_TO_UINT16(opcode, stream);
1004 btu_hcif_hdl_command_complete(
1007 5, // 3 for the command complete headers, 2 for the event headers
1013 static void btu_hcif_command_complete_evt(BT_HDR* response, void* context) {
1014 do_in_hci_thread(FROM_HERE, base::Bind(btu_hcif_command_complete_evt_on_task,
1015 response, context));
1018 /*******************************************************************************
1020 * Function btu_hcif_hdl_command_status
1022 * Description Handle a command status event
1026 ******************************************************************************/
1027 static void btu_hcif_hdl_command_status(uint16_t opcode, uint8_t status,
1029 void* p_vsc_status_cback) {
1032 #if (BTM_SCO_INCLUDED == TRUE)
1033 tBTM_ESCO_DATA esco_data;
1037 case HCI_EXIT_SNIFF_MODE:
1038 case HCI_EXIT_PARK_MODE:
1039 #if (BTM_SCO_WAKE_PARKED_LINK == TRUE)
1040 if (status != HCI_SUCCESS) {
1041 /* Allow SCO initiation to continue if waiting for change mode event */
1042 if (p_cmd != NULL) {
1043 p_cmd++; /* bypass length field */
1044 STREAM_TO_UINT16(handle, p_cmd);
1045 btm_sco_chk_pend_unpark(status, handle);
1049 /* Case Falls Through */
1052 case HCI_SNIFF_MODE:
1054 btm_pm_proc_cmd_status(status);
1058 /* If command failed to start, we may need to tell BTM */
1059 if (status != HCI_SUCCESS) {
1062 /* Tell inquiry processing that we are done */
1063 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
1066 case HCI_RMT_NAME_REQUEST:
1067 /* Tell inquiry processing that we are done */
1068 btm_process_remote_name(NULL, NULL, 0, status);
1070 btm_sec_rmt_name_request_complete(NULL, NULL, status);
1073 case HCI_QOS_SETUP_COMP_EVT:
1074 /* Tell qos setup that we are done */
1075 btm_qos_setup_complete(status, 0, NULL);
1078 case HCI_SWITCH_ROLE:
1079 /* Tell BTM that the command failed */
1080 /* read bd addr out of stored command */
1081 if (p_cmd != NULL) {
1083 STREAM_TO_BDADDR(bd_addr, p_cmd);
1084 btm_acl_role_changed(status, &bd_addr, BTM_ROLE_UNDEFINED);
1086 btm_acl_role_changed(status, NULL, BTM_ROLE_UNDEFINED);
1087 l2c_link_role_changed(nullptr, BTM_ROLE_UNDEFINED,
1088 HCI_ERR_COMMAND_DISALLOWED);
1091 case HCI_CREATE_CONNECTION:
1092 /* read bd addr out of stored command */
1093 if (p_cmd != NULL) {
1095 STREAM_TO_BDADDR(bd_addr, p_cmd);
1096 btm_sec_connected(bd_addr, HCI_INVALID_HANDLE, status, 0);
1097 l2c_link_hci_conn_comp(status, HCI_INVALID_HANDLE, bd_addr);
1101 case HCI_READ_RMT_EXT_FEATURES:
1102 if (p_cmd != NULL) {
1103 p_cmd++; /* skip command length */
1104 STREAM_TO_UINT16(handle, p_cmd);
1106 handle = HCI_INVALID_HANDLE;
1108 btm_read_remote_ext_features_failed(status, handle);
1111 case HCI_AUTHENTICATION_REQUESTED:
1112 /* Device refused to start authentication. That should be treated
1113 * as authentication failure. */
1114 btm_sec_auth_complete(BTM_INVALID_HCI_HANDLE, status);
1117 case HCI_SET_CONN_ENCRYPTION:
1118 /* Device refused to start encryption. That should be treated as
1119 * encryption failure. */
1120 btm_sec_encrypt_change(BTM_INVALID_HCI_HANDLE, status, false);
1123 case HCI_BLE_CREATE_LL_CONN:
1124 btm_ble_create_ll_conn_complete(status);
1127 #if (BTM_SCO_INCLUDED == TRUE)
1128 case HCI_SETUP_ESCO_CONNECTION:
1129 case HCI_ENH_SETUP_ESCO_CONNECTION:
1130 /* read handle out of stored command */
1131 if (p_cmd != NULL) {
1133 STREAM_TO_UINT16(handle, p_cmd);
1135 /* Determine if initial connection failed or is a change
1137 if (btm_is_sco_active(handle))
1138 btm_esco_proc_conn_chg(status, handle, 0, 0, 0, 0);
1140 btm_sco_connected(status, NULL, handle, &esco_data);
1145 /* This is commented out until an upper layer cares about returning
1147 #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
1148 case HCI_ENHANCED_FLUSH:
1153 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1154 btm_vsc_complete(&status, opcode, 1,
1155 (tBTM_CMPL_CB*)p_vsc_status_cback);
1160 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1161 btm_vsc_complete(&status, opcode, 1,
1162 (tBTM_CMPL_CB*)p_vsc_status_cback);
1167 /*******************************************************************************
1169 * Function btu_hcif_command_status_evt
1171 * Description Process event HCI_COMMAND_STATUS_EVT
1175 ******************************************************************************/
1176 static void btu_hcif_command_status_evt_on_task(uint8_t status, BT_HDR* event,
1178 command_opcode_t opcode;
1179 uint8_t* stream = event->data + event->offset;
1180 STREAM_TO_UINT16(opcode, stream);
1182 btu_hcif_hdl_command_status(opcode, status, stream, context);
1186 static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command,
1188 do_in_hci_thread(FROM_HERE, base::Bind(btu_hcif_command_status_evt_on_task,
1189 status, command, context));
1192 /*******************************************************************************
1194 * Function btu_hcif_hardware_error_evt
1196 * Description Process event HCI_HARDWARE_ERROR_EVT
1200 ******************************************************************************/
1201 static void btu_hcif_hardware_error_evt(uint8_t* p) {
1202 HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p);
1204 /* If anyone wants device status notifications, give him one. */
1205 btm_report_device_status(BTM_DEV_STATUS_DOWN);
1207 /* Reset the controller */
1208 if (BTM_IsDeviceUp()) BTM_DeviceReset(NULL);
1211 /*******************************************************************************
1213 * Function btu_hcif_flush_occured_evt
1215 * Description Process event HCI_FLUSH_OCCURED_EVT
1219 ******************************************************************************/
1220 static void btu_hcif_flush_occured_evt(void) {}
1222 /*******************************************************************************
1224 * Function btu_hcif_role_change_evt
1226 * Description Process event HCI_ROLE_CHANGE_EVT
1230 ******************************************************************************/
1231 static void btu_hcif_role_change_evt(uint8_t* p) {
1236 STREAM_TO_UINT8(status, p);
1237 STREAM_TO_BDADDR(bda, p);
1238 STREAM_TO_UINT8(role, p);
1240 btm_blacklist_role_change_device(bda, status);
1241 l2c_link_role_changed(&bda, role, status);
1242 btm_acl_role_changed(status, &bda, role);
1245 /*******************************************************************************
1247 * Function btu_hcif_num_compl_data_pkts_evt
1249 * Description Process event HCI_NUM_COMPL_DATA_PKTS_EVT
1253 ******************************************************************************/
1254 static void btu_hcif_num_compl_data_pkts_evt(uint8_t* p) {
1255 /* Process for L2CAP and SCO */
1256 l2c_link_process_num_completed_pkts(p);
1258 /* Send on to SCO */
1259 /*?? No SCO for now */
1262 /*******************************************************************************
1264 * Function btu_hcif_mode_change_evt
1266 * Description Process event HCI_MODE_CHANGE_EVT
1270 ******************************************************************************/
1271 static void btu_hcif_mode_change_evt(uint8_t* p) {
1274 uint8_t current_mode;
1277 STREAM_TO_UINT8(status, p);
1279 STREAM_TO_UINT16(handle, p);
1280 STREAM_TO_UINT8(current_mode, p);
1281 STREAM_TO_UINT16(interval, p);
1282 #if (BTM_SCO_WAKE_PARKED_LINK == TRUE)
1283 btm_sco_chk_pend_unpark(status, handle);
1285 btm_pm_proc_mode_change(status, handle, current_mode, interval);
1287 #if (HID_DEV_INCLUDED == TRUE && HID_DEV_PM_INCLUDED == TRUE)
1288 hidd_pm_proc_mode_change(status, current_mode, interval);
1292 /*******************************************************************************
1294 * Function btu_hcif_ssr_evt
1296 * Description Process event HCI_SNIFF_SUB_RATE_EVT
1300 ******************************************************************************/
1301 #if (BTM_SSR_INCLUDED == TRUE)
1302 static void btu_hcif_ssr_evt(uint8_t* p, uint16_t evt_len) {
1303 btm_pm_proc_ssr_evt(p, evt_len);
1307 /*******************************************************************************
1309 * Function btu_hcif_pin_code_request_evt
1311 * Description Process event HCI_PIN_CODE_REQUEST_EVT
1315 ******************************************************************************/
1316 static void btu_hcif_pin_code_request_evt(uint8_t* p) {
1319 STREAM_TO_BDADDR(bda, p);
1321 /* Tell L2CAP that there was a PIN code request, */
1322 /* it may need to stretch timeouts */
1323 l2c_pin_code_request(bda);
1325 btm_sec_pin_code_request(bda);
1328 /*******************************************************************************
1330 * Function btu_hcif_link_key_request_evt
1332 * Description Process event HCI_LINK_KEY_REQUEST_EVT
1336 ******************************************************************************/
1337 static void btu_hcif_link_key_request_evt(uint8_t* p) {
1340 STREAM_TO_BDADDR(bda, p);
1341 btm_sec_link_key_request(bda);
1344 /*******************************************************************************
1346 * Function btu_hcif_link_key_notification_evt
1348 * Description Process event HCI_LINK_KEY_NOTIFICATION_EVT
1352 ******************************************************************************/
1353 static void btu_hcif_link_key_notification_evt(uint8_t* p) {
1358 STREAM_TO_BDADDR(bda, p);
1359 STREAM_TO_ARRAY16(key, p);
1360 STREAM_TO_UINT8(key_type, p);
1362 btm_sec_link_key_notification(bda, key, key_type);
1365 /*******************************************************************************
1367 * Function btu_hcif_loopback_command_evt
1369 * Description Process event HCI_LOOPBACK_COMMAND_EVT
1373 ******************************************************************************/
1374 static void btu_hcif_loopback_command_evt(void) {}
1376 /*******************************************************************************
1378 * Function btu_hcif_data_buf_overflow_evt
1380 * Description Process event HCI_DATA_BUF_OVERFLOW_EVT
1384 ******************************************************************************/
1385 static void btu_hcif_data_buf_overflow_evt(void) {}
1387 /*******************************************************************************
1389 * Function btu_hcif_max_slots_changed_evt
1391 * Description Process event HCI_MAX_SLOTS_CHANGED_EVT
1395 ******************************************************************************/
1396 static void btu_hcif_max_slots_changed_evt(void) {}
1398 /*******************************************************************************
1400 * Function btu_hcif_read_clock_off_comp_evt
1402 * Description Process event HCI_READ_CLOCK_OFF_COMP_EVT
1406 ******************************************************************************/
1407 static void btu_hcif_read_clock_off_comp_evt(uint8_t* p) {
1410 uint16_t clock_offset;
1412 STREAM_TO_UINT8(status, p);
1414 /* If failed to get clock offset just drop the result */
1415 if (status != HCI_SUCCESS) return;
1417 STREAM_TO_UINT16(handle, p);
1418 STREAM_TO_UINT16(clock_offset, p);
1420 handle = HCID_GET_HANDLE(handle);
1422 btm_process_clk_off_comp_evt(handle, clock_offset);
1423 btm_sec_update_clock_offset(handle, clock_offset);
1426 /*******************************************************************************
1428 * Function btu_hcif_conn_pkt_type_change_evt
1430 * Description Process event HCI_CONN_PKT_TYPE_CHANGE_EVT
1434 ******************************************************************************/
1435 static void btu_hcif_conn_pkt_type_change_evt(void) {}
1437 /*******************************************************************************
1439 * Function btu_hcif_qos_violation_evt
1441 * Description Process event HCI_QOS_VIOLATION_EVT
1445 ******************************************************************************/
1446 static void btu_hcif_qos_violation_evt(uint8_t* p) {
1449 STREAM_TO_UINT16(handle, p);
1451 handle = HCID_GET_HANDLE(handle);
1453 l2c_link_hci_qos_violation(handle);
1456 /*******************************************************************************
1458 * Function btu_hcif_page_scan_mode_change_evt
1460 * Description Process event HCI_PAGE_SCAN_MODE_CHANGE_EVT
1464 ******************************************************************************/
1465 static void btu_hcif_page_scan_mode_change_evt(void) {}
1467 /*******************************************************************************
1469 * Function btu_hcif_page_scan_rep_mode_chng_evt
1471 * Description Process event HCI_PAGE_SCAN_REP_MODE_CHNG_EVT
1475 ******************************************************************************/
1476 static void btu_hcif_page_scan_rep_mode_chng_evt(void) {}
1478 /**********************************************
1479 * Simple Pairing Events
1480 **********************************************/
1482 /*******************************************************************************
1484 * Function btu_hcif_host_support_evt
1486 * Description Process event HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT
1490 ******************************************************************************/
1491 static void btu_hcif_host_support_evt(uint8_t* p) {
1492 btm_sec_rmt_host_support_feat_evt(p);
1495 /*******************************************************************************
1497 * Function btu_hcif_io_cap_request_evt
1499 * Description Process event HCI_IO_CAPABILITY_REQUEST_EVT
1503 ******************************************************************************/
1504 static void btu_hcif_io_cap_request_evt(uint8_t* p) {
1506 STREAM_TO_BDADDR(bda, p);
1507 btm_io_capabilities_req(bda);
1510 /*******************************************************************************
1512 * Function btu_hcif_io_cap_response_evt
1514 * Description Process event HCI_IO_CAPABILITY_RESPONSE_EVT
1518 ******************************************************************************/
1519 static void btu_hcif_io_cap_response_evt(uint8_t* p) {
1520 btm_io_capabilities_rsp(p);
1523 /*******************************************************************************
1525 * Function btu_hcif_user_conf_request_evt
1527 * Description Process event HCI_USER_CONFIRMATION_REQUEST_EVT
1531 ******************************************************************************/
1532 static void btu_hcif_user_conf_request_evt(uint8_t* p) {
1533 btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p);
1536 /*******************************************************************************
1538 * Function btu_hcif_user_passkey_request_evt
1540 * Description Process event HCI_USER_PASSKEY_REQUEST_EVT
1544 ******************************************************************************/
1545 static void btu_hcif_user_passkey_request_evt(uint8_t* p) {
1546 btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p);
1549 /*******************************************************************************
1551 * Function btu_hcif_user_passkey_notif_evt
1553 * Description Process event HCI_USER_PASSKEY_NOTIFY_EVT
1557 ******************************************************************************/
1558 static void btu_hcif_user_passkey_notif_evt(uint8_t* p) {
1559 btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p);
1562 /*******************************************************************************
1564 * Function btu_hcif_keypress_notif_evt
1566 * Description Process event HCI_KEYPRESS_NOTIFY_EVT
1570 ******************************************************************************/
1571 static void btu_hcif_keypress_notif_evt(uint8_t* p) {
1572 btm_keypress_notif_evt(p);
1575 /*******************************************************************************
1577 * Function btu_hcif_rem_oob_request_evt
1579 * Description Process event HCI_REMOTE_OOB_DATA_REQUEST_EVT
1583 ******************************************************************************/
1584 static void btu_hcif_rem_oob_request_evt(uint8_t* p) { btm_rem_oob_req(p); }
1586 /*******************************************************************************
1588 * Function btu_hcif_simple_pair_complete_evt
1590 * Description Process event HCI_SIMPLE_PAIRING_COMPLETE_EVT
1594 ******************************************************************************/
1595 static void btu_hcif_simple_pair_complete_evt(uint8_t* p) {
1596 btm_simple_pair_complete(p);
1599 /*******************************************************************************
1601 * Function btu_hcif_enhanced_flush_complete_evt
1603 * Description Process event HCI_ENHANCED_FLUSH_COMPLETE_EVT
1607 ******************************************************************************/
1608 #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
1609 static void btu_hcif_enhanced_flush_complete_evt(void) {
1610 /* This is empty until an upper layer cares about returning event */
1613 /**********************************************
1614 * End of Simple Pairing Events
1615 **********************************************/
1617 /**********************************************
1619 **********************************************/
1620 static void btu_hcif_encryption_key_refresh_cmpl_evt(uint8_t* p) {
1622 uint8_t enc_enable = 0;
1625 STREAM_TO_UINT8(status, p);
1626 STREAM_TO_UINT16(handle, p);
1628 if (status == HCI_SUCCESS) enc_enable = 1;
1630 btm_sec_encrypt_change(handle, status, enc_enable);
1633 static void btu_ble_ll_conn_complete_evt(uint8_t* p, uint16_t evt_len) {
1634 btm_ble_conn_complete(p, evt_len, false);
1636 #if (BLE_PRIVACY_SPT == TRUE)
1637 static void btu_ble_proc_enhanced_conn_cmpl(uint8_t* p, uint16_t evt_len) {
1638 btm_ble_conn_complete(p, evt_len, true);
1642 extern void gatt_notify_conn_update(uint16_t handle, uint16_t interval,
1643 uint16_t latency, uint16_t timeout,
1646 static void btu_ble_ll_conn_param_upd_evt(uint8_t* p, uint16_t evt_len) {
1647 /* LE connection update has completed successfully as a master. */
1648 /* We can enable the update request if the result is a success. */
1649 /* extract the HCI handle first */
1656 STREAM_TO_UINT8(status, p);
1657 STREAM_TO_UINT16(handle, p);
1658 STREAM_TO_UINT16(interval, p);
1659 STREAM_TO_UINT16(latency, p);
1660 STREAM_TO_UINT16(timeout, p);
1662 l2cble_process_conn_update_evt(handle, status, interval, latency, timeout);
1664 gatt_notify_conn_update(handle & 0x0FFF, interval, latency, timeout, status);
1667 static void btu_ble_read_remote_feat_evt(uint8_t* p) {
1668 btm_ble_read_remote_features_complete(p);
1671 static void btu_ble_proc_ltk_req(uint8_t* p) {
1672 uint16_t ediv, handle;
1675 STREAM_TO_UINT16(handle, p);
1677 STREAM_TO_UINT16(ediv, pp);
1678 btm_ble_ltk_request(handle, p, ediv);
1679 /* This is empty until an upper layer cares about returning event */
1682 static void btu_ble_data_length_change_evt(uint8_t* p, uint16_t evt_len) {
1684 uint16_t tx_data_len;
1685 uint16_t rx_data_len;
1687 if (!controller_get_interface()->supports_ble_packet_extension()) {
1688 HCI_TRACE_WARNING("%s, request not supported", __func__);
1692 STREAM_TO_UINT16(handle, p);
1693 STREAM_TO_UINT16(tx_data_len, p);
1694 p += 2; /* Skip the TxTimer */
1695 STREAM_TO_UINT16(rx_data_len, p);
1697 l2cble_process_data_length_change_event(handle, tx_data_len, rx_data_len);
1700 /**********************************************
1701 * End of BLE Events Handler
1702 **********************************************/
1703 #if (BLE_LLT_INCLUDED == TRUE)
1704 static void btu_ble_rc_param_req_evt(uint8_t* p) {
1706 uint16_t int_min, int_max, latency, timeout;
1708 STREAM_TO_UINT16(handle, p);
1709 STREAM_TO_UINT16(int_min, p);
1710 STREAM_TO_UINT16(int_max, p);
1711 STREAM_TO_UINT16(latency, p);
1712 STREAM_TO_UINT16(timeout, p);
1714 l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency,
1717 #endif /* BLE_LLT_INCLUDED */