1 /******************************************************************************
3 * Copyright 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>
35 #include <frameworks/base/core/proto/android/bluetooth/enums.pb.h>
36 #include <frameworks/base/core/proto/android/bluetooth/hci/enums.pb.h>
42 #include "bt_common.h"
48 #include "common/metrics.h"
49 #include "device/include/controller.h"
50 #include "hci_layer.h"
53 #include "osi/include/log.h"
54 #include "osi/include/osi.h"
58 extern void btm_process_cancel_complete(uint8_t status, uint8_t mode);
59 extern void btm_ble_test_command_complete(uint8_t* p);
60 extern void smp_cancel_start_encryption_attempt();
62 /******************************************************************************/
63 /* L O C A L F U N C T I O N P R O T O T Y P E S */
64 /******************************************************************************/
65 static void btu_hcif_inquiry_comp_evt(uint8_t* p);
66 static void btu_hcif_inquiry_result_evt(uint8_t* p);
67 static void btu_hcif_inquiry_rssi_result_evt(uint8_t* p);
68 static void btu_hcif_extended_inquiry_result_evt(uint8_t* p);
70 static void btu_hcif_connection_comp_evt(uint8_t* p);
71 static void btu_hcif_connection_request_evt(uint8_t* p);
72 static void btu_hcif_disconnection_comp_evt(uint8_t* p);
73 static void btu_hcif_authentication_comp_evt(uint8_t* p);
74 static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len);
75 static void btu_hcif_encryption_change_evt(uint8_t* p);
76 static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p);
77 static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p);
78 static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p);
79 static void btu_hcif_qos_setup_comp_evt(uint8_t* p);
80 static void btu_hcif_command_complete_evt(BT_HDR* response, void* context);
81 static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command,
83 static void btu_hcif_hardware_error_evt(uint8_t* p);
84 static void btu_hcif_flush_occured_evt(void);
85 static void btu_hcif_role_change_evt(uint8_t* p);
86 static void btu_hcif_num_compl_data_pkts_evt(uint8_t* p);
87 static void btu_hcif_mode_change_evt(uint8_t* p);
88 static void btu_hcif_pin_code_request_evt(uint8_t* p);
89 static void btu_hcif_link_key_request_evt(uint8_t* p);
90 static void btu_hcif_link_key_notification_evt(uint8_t* p);
91 static void btu_hcif_loopback_command_evt(void);
92 static void btu_hcif_data_buf_overflow_evt(void);
93 static void btu_hcif_max_slots_changed_evt(void);
94 static void btu_hcif_read_clock_off_comp_evt(uint8_t* p);
95 static void btu_hcif_conn_pkt_type_change_evt(void);
96 static void btu_hcif_qos_violation_evt(uint8_t* p);
97 static void btu_hcif_page_scan_mode_change_evt(void);
98 static void btu_hcif_page_scan_rep_mode_chng_evt(void);
99 static void btu_hcif_esco_connection_comp_evt(uint8_t* p);
100 static void btu_hcif_esco_connection_chg_evt(uint8_t* p);
102 /* Simple Pairing Events */
103 static void btu_hcif_host_support_evt(uint8_t* p);
104 static void btu_hcif_io_cap_request_evt(uint8_t* p);
105 static void btu_hcif_io_cap_response_evt(uint8_t* p);
106 static void btu_hcif_user_conf_request_evt(uint8_t* p);
107 static void btu_hcif_user_passkey_request_evt(uint8_t* p);
108 static void btu_hcif_user_passkey_notif_evt(uint8_t* p);
109 static void btu_hcif_keypress_notif_evt(uint8_t* p);
110 static void btu_hcif_rem_oob_request_evt(uint8_t* p);
112 static void btu_hcif_simple_pair_complete_evt(uint8_t* p);
113 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
114 static void btu_hcif_enhanced_flush_complete_evt(void);
117 #if (BTM_SSR_INCLUDED == TRUE)
118 static void btu_hcif_ssr_evt(uint8_t* p, uint16_t evt_len);
119 #endif /* BTM_SSR_INCLUDED == TRUE */
121 static void btu_ble_ll_conn_complete_evt(uint8_t* p, uint16_t evt_len);
122 static void btu_ble_read_remote_feat_evt(uint8_t* p);
123 static void btu_ble_ll_conn_param_upd_evt(uint8_t* p, uint16_t evt_len);
124 static void btu_ble_proc_ltk_req(uint8_t* p);
125 static void btu_hcif_encryption_key_refresh_cmpl_evt(uint8_t* p);
126 static void btu_ble_data_length_change_evt(uint8_t* p, uint16_t evt_len);
127 #if (BLE_LLT_INCLUDED == TRUE)
128 static void btu_ble_rc_param_req_evt(uint8_t* p);
130 #if (BLE_PRIVACY_SPT == TRUE)
131 static void btu_ble_proc_enhanced_conn_cmpl(uint8_t* p, uint16_t evt_len);
135 * Log HCI event metrics that are not handled in special functions
136 * @param evt_code event code
137 * @param p_event pointer to event parameter, skipping paremter length
139 void btu_hcif_log_event_metrics(uint8_t evt_code, uint8_t* p_event) {
140 uint32_t cmd = android::bluetooth::hci::CMD_UNKNOWN;
141 uint16_t status = android::bluetooth::hci::STATUS_UNKNOWN;
142 uint16_t reason = android::bluetooth::hci::STATUS_UNKNOWN;
143 uint16_t handle = bluetooth::common::kUnknownConnectionHandle;
145 RawAddress bda = RawAddress::kEmpty;
147 case HCI_IO_CAPABILITY_REQUEST_EVT:
148 case HCI_IO_CAPABILITY_RESPONSE_EVT:
149 case HCI_LINK_KEY_REQUEST_EVT:
150 case HCI_LINK_KEY_NOTIFICATION_EVT:
151 case HCI_USER_PASSKEY_REQUEST_EVT:
152 case HCI_USER_PASSKEY_NOTIFY_EVT:
153 case HCI_USER_CONFIRMATION_REQUEST_EVT:
154 case HCI_KEYPRESS_NOTIFY_EVT:
155 case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
156 STREAM_TO_BDADDR(bda, p_event);
157 bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
160 case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
161 case HCI_RMT_NAME_REQUEST_COMP_EVT:
162 STREAM_TO_UINT8(status, p_event);
163 STREAM_TO_BDADDR(bda, p_event);
164 bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
167 case HCI_AUTHENTICATION_COMP_EVT:
168 STREAM_TO_UINT8(status, p_event);
169 STREAM_TO_UINT16(handle, p_event);
170 handle = HCID_GET_HANDLE(handle);
171 bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
174 case HCI_ENCRYPTION_CHANGE_EVT: {
175 uint8_t encryption_enabled;
176 STREAM_TO_UINT8(status, p_event);
177 STREAM_TO_UINT16(handle, p_event);
178 STREAM_TO_UINT8(encryption_enabled, p_event);
179 // Use reason field to store encryption enabled
180 bluetooth::common::LogClassicPairingEvent(bda, handle, cmd, evt_code,
181 status, encryption_enabled);
184 case HCI_CONNECTION_COMP_EVT: {
186 STREAM_TO_UINT8(status, p_event);
187 STREAM_TO_UINT16(handle, p_event);
188 STREAM_TO_BDADDR(bda, p_event);
189 STREAM_TO_UINT8(link_type, p_event);
190 handle = HCID_GET_HANDLE(handle);
191 bluetooth::common::LogLinkLayerConnectionEvent(
192 &bda, handle, android::bluetooth::DIRECTION_UNKNOWN, link_type, cmd,
193 evt_code, android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
196 case HCI_CONNECTION_REQUEST_EVT: {
199 STREAM_TO_BDADDR(bda, p_event);
200 STREAM_TO_DEVCLASS(dc, p_event);
201 STREAM_TO_UINT8(link_type, p_event);
202 bluetooth::common::LogLinkLayerConnectionEvent(
203 &bda, bluetooth::common::kUnknownConnectionHandle,
204 android::bluetooth::DIRECTION_INCOMING, link_type, cmd, evt_code,
205 android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
208 case HCI_DISCONNECTION_COMP_EVT: {
209 STREAM_TO_UINT8(status, p_event);
210 STREAM_TO_UINT16(handle, p_event);
211 STREAM_TO_UINT8(reason, p_event);
212 handle = HCID_GET_HANDLE(handle);
213 bluetooth::common::LogLinkLayerConnectionEvent(
214 nullptr, handle, android::bluetooth::DIRECTION_UNKNOWN,
215 android::bluetooth::LINK_TYPE_UNKNOWN, cmd, evt_code,
216 android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
219 case HCI_ESCO_CONNECTION_COMP_EVT: {
221 STREAM_TO_UINT8(status, p_event);
222 STREAM_TO_UINT16(handle, p_event);
223 STREAM_TO_BDADDR(bda, p_event);
224 STREAM_TO_UINT8(link_type, p_event);
225 handle = HCID_GET_HANDLE(handle);
226 bluetooth::common::LogLinkLayerConnectionEvent(
227 &bda, handle, android::bluetooth::DIRECTION_UNKNOWN, link_type, cmd,
228 evt_code, android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
231 case HCI_ESCO_CONNECTION_CHANGED_EVT: {
232 STREAM_TO_UINT8(status, p_event);
233 STREAM_TO_UINT16(handle, p_event);
234 handle = HCID_GET_HANDLE(handle);
235 bluetooth::common::LogLinkLayerConnectionEvent(
236 nullptr, handle, android::bluetooth::DIRECTION_UNKNOWN,
237 android::bluetooth::LINK_TYPE_UNKNOWN, cmd, evt_code,
238 android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
244 /*******************************************************************************
246 * Function btu_hcif_process_event
248 * Description This function is called when an event is received from
249 * the Host Controller.
253 ******************************************************************************/
254 void btu_hcif_process_event(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_msg) {
255 uint8_t* p = (uint8_t*)(p_msg + 1) + p_msg->offset;
256 uint8_t hci_evt_code, hci_evt_len;
257 uint8_t ble_sub_code;
258 STREAM_TO_UINT8(hci_evt_code, p);
259 STREAM_TO_UINT8(hci_evt_len, p);
261 btu_hcif_log_event_metrics(hci_evt_code, p);
263 switch (hci_evt_code) {
264 case HCI_INQUIRY_COMP_EVT:
265 btu_hcif_inquiry_comp_evt(p);
267 case HCI_INQUIRY_RESULT_EVT:
268 btu_hcif_inquiry_result_evt(p);
270 case HCI_INQUIRY_RSSI_RESULT_EVT:
271 btu_hcif_inquiry_rssi_result_evt(p);
273 case HCI_EXTENDED_INQUIRY_RESULT_EVT:
274 btu_hcif_extended_inquiry_result_evt(p);
276 case HCI_CONNECTION_COMP_EVT:
277 btu_hcif_connection_comp_evt(p);
279 case HCI_CONNECTION_REQUEST_EVT:
280 btu_hcif_connection_request_evt(p);
282 case HCI_DISCONNECTION_COMP_EVT:
283 btu_hcif_disconnection_comp_evt(p);
285 case HCI_AUTHENTICATION_COMP_EVT:
286 btu_hcif_authentication_comp_evt(p);
288 case HCI_RMT_NAME_REQUEST_COMP_EVT:
289 btu_hcif_rmt_name_request_comp_evt(p, hci_evt_len);
291 case HCI_ENCRYPTION_CHANGE_EVT:
292 btu_hcif_encryption_change_evt(p);
294 case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT:
295 btu_hcif_encryption_key_refresh_cmpl_evt(p);
297 case HCI_READ_RMT_FEATURES_COMP_EVT:
298 btu_hcif_read_rmt_features_comp_evt(p);
300 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
301 btu_hcif_read_rmt_ext_features_comp_evt(p);
303 case HCI_READ_RMT_VERSION_COMP_EVT:
304 btu_hcif_read_rmt_version_comp_evt(p);
306 case HCI_QOS_SETUP_COMP_EVT:
307 btu_hcif_qos_setup_comp_evt(p);
309 case HCI_COMMAND_COMPLETE_EVT:
311 "%s should not have received a command complete event. "
312 "Someone didn't go through the hci transmit_command function.",
315 case HCI_COMMAND_STATUS_EVT:
317 "%s should not have received a command status event. "
318 "Someone didn't go through the hci transmit_command function.",
321 case HCI_HARDWARE_ERROR_EVT:
322 btu_hcif_hardware_error_evt(p);
324 case HCI_FLUSH_OCCURED_EVT:
325 btu_hcif_flush_occured_evt();
327 case HCI_ROLE_CHANGE_EVT:
328 btu_hcif_role_change_evt(p);
330 case HCI_NUM_COMPL_DATA_PKTS_EVT:
331 btu_hcif_num_compl_data_pkts_evt(p);
333 case HCI_MODE_CHANGE_EVT:
334 btu_hcif_mode_change_evt(p);
336 case HCI_PIN_CODE_REQUEST_EVT:
337 btu_hcif_pin_code_request_evt(p);
339 case HCI_LINK_KEY_REQUEST_EVT:
340 btu_hcif_link_key_request_evt(p);
342 case HCI_LINK_KEY_NOTIFICATION_EVT:
343 btu_hcif_link_key_notification_evt(p);
345 case HCI_LOOPBACK_COMMAND_EVT:
346 btu_hcif_loopback_command_evt();
348 case HCI_DATA_BUF_OVERFLOW_EVT:
349 btu_hcif_data_buf_overflow_evt();
351 case HCI_MAX_SLOTS_CHANGED_EVT:
352 btu_hcif_max_slots_changed_evt();
354 case HCI_READ_CLOCK_OFF_COMP_EVT:
355 btu_hcif_read_clock_off_comp_evt(p);
357 case HCI_CONN_PKT_TYPE_CHANGE_EVT:
358 btu_hcif_conn_pkt_type_change_evt();
360 case HCI_QOS_VIOLATION_EVT:
361 btu_hcif_qos_violation_evt(p);
363 case HCI_PAGE_SCAN_MODE_CHANGE_EVT:
364 btu_hcif_page_scan_mode_change_evt();
366 case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT:
367 btu_hcif_page_scan_rep_mode_chng_evt();
369 case HCI_ESCO_CONNECTION_COMP_EVT:
370 btu_hcif_esco_connection_comp_evt(p);
372 case HCI_ESCO_CONNECTION_CHANGED_EVT:
373 btu_hcif_esco_connection_chg_evt(p);
375 #if (BTM_SSR_INCLUDED == TRUE)
376 case HCI_SNIFF_SUB_RATE_EVT:
377 btu_hcif_ssr_evt(p, hci_evt_len);
379 #endif /* BTM_SSR_INCLUDED == TRUE */
380 case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT:
381 btu_hcif_host_support_evt(p);
383 case HCI_IO_CAPABILITY_REQUEST_EVT:
384 btu_hcif_io_cap_request_evt(p);
386 case HCI_IO_CAPABILITY_RESPONSE_EVT:
387 btu_hcif_io_cap_response_evt(p);
389 case HCI_USER_CONFIRMATION_REQUEST_EVT:
390 btu_hcif_user_conf_request_evt(p);
392 case HCI_USER_PASSKEY_REQUEST_EVT:
393 btu_hcif_user_passkey_request_evt(p);
395 case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
396 btu_hcif_rem_oob_request_evt(p);
398 case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
399 btu_hcif_simple_pair_complete_evt(p);
401 case HCI_USER_PASSKEY_NOTIFY_EVT:
402 btu_hcif_user_passkey_notif_evt(p);
404 case HCI_KEYPRESS_NOTIFY_EVT:
405 btu_hcif_keypress_notif_evt(p);
407 #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
408 case HCI_ENHANCED_FLUSH_COMPLETE_EVT:
409 btu_hcif_enhanced_flush_complete_evt();
413 case HCI_BLE_EVENT: {
414 STREAM_TO_UINT8(ble_sub_code, p);
416 HCI_TRACE_EVENT("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code,
419 uint8_t ble_evt_len = hci_evt_len - 1;
420 switch (ble_sub_code) {
421 case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
422 HCI_TRACE_EVENT("HCI_BLE_ADV_PKT_RPT_EVT");
423 btm_ble_process_adv_pkt(ble_evt_len, p);
425 case HCI_BLE_CONN_COMPLETE_EVT:
426 btu_ble_ll_conn_complete_evt(p, hci_evt_len);
428 case HCI_BLE_LL_CONN_PARAM_UPD_EVT:
429 btu_ble_ll_conn_param_upd_evt(p, hci_evt_len);
431 case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT:
432 btu_ble_read_remote_feat_evt(p);
434 case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */
435 btu_ble_proc_ltk_req(p);
437 #if (BLE_PRIVACY_SPT == TRUE)
438 case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT:
439 btu_ble_proc_enhanced_conn_cmpl(p, hci_evt_len);
442 #if (BLE_LLT_INCLUDED == TRUE)
443 case HCI_BLE_RC_PARAM_REQ_EVT:
444 btu_ble_rc_param_req_evt(p);
447 case HCI_BLE_DATA_LENGTH_CHANGE_EVT:
448 btu_ble_data_length_change_evt(p, hci_evt_len);
451 case HCI_BLE_PHY_UPDATE_COMPLETE_EVT:
452 btm_ble_process_phy_update_pkt(ble_evt_len, p);
455 case HCI_LE_EXTENDED_ADVERTISING_REPORT_EVT:
456 btm_ble_process_ext_adv_pkt(hci_evt_len, p);
459 case HCI_LE_ADVERTISING_SET_TERMINATED_EVT:
460 btm_le_on_advertising_set_terminated(p, hci_evt_len);
466 case HCI_VENDOR_SPECIFIC_EVT:
467 btm_vendor_specific_evt(p, hci_evt_len);
472 static void btu_hcif_log_command_metrics(uint16_t opcode, uint8_t* p_cmd,
474 bool is_cmd_status) {
475 static uint16_t kUnknownBleEvt = android::bluetooth::hci::BLE_EVT_UNKNOWN;
477 uint16_t hci_event = android::bluetooth::hci::EVT_COMMAND_STATUS;
478 if (!is_cmd_status) {
479 hci_event = android::bluetooth::hci::EVT_UNKNOWN;
480 cmd_status = android::bluetooth::hci::STATUS_UNKNOWN;
488 case HCI_CREATE_CONNECTION:
489 case HCI_CREATE_CONNECTION_CANCEL:
490 STREAM_TO_BDADDR(bd_addr, p_cmd);
491 bluetooth::common::LogLinkLayerConnectionEvent(
492 &bd_addr, bluetooth::common::kUnknownConnectionHandle,
493 android::bluetooth::DIRECTION_OUTGOING,
494 android::bluetooth::LINK_TYPE_ACL, opcode, hci_event, kUnknownBleEvt,
495 cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
498 STREAM_TO_UINT16(handle, p_cmd);
499 STREAM_TO_UINT8(reason, p_cmd);
500 bluetooth::common::LogLinkLayerConnectionEvent(
501 nullptr, handle, android::bluetooth::DIRECTION_UNKNOWN,
502 android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event,
503 kUnknownBleEvt, cmd_status, reason);
505 case HCI_SETUP_ESCO_CONNECTION:
506 case HCI_ENH_SETUP_ESCO_CONNECTION:
507 STREAM_TO_UINT16(handle, p_cmd);
508 bluetooth::common::LogLinkLayerConnectionEvent(
509 nullptr, handle, android::bluetooth::DIRECTION_OUTGOING,
510 android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event,
511 kUnknownBleEvt, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
513 case HCI_ACCEPT_CONNECTION_REQUEST:
514 case HCI_ACCEPT_ESCO_CONNECTION:
515 case HCI_ENH_ACCEPT_ESCO_CONNECTION:
516 STREAM_TO_BDADDR(bd_addr, p_cmd);
517 bluetooth::common::LogLinkLayerConnectionEvent(
518 &bd_addr, bluetooth::common::kUnknownConnectionHandle,
519 android::bluetooth::DIRECTION_INCOMING,
520 android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event,
521 kUnknownBleEvt, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
523 case HCI_REJECT_CONNECTION_REQUEST:
524 case HCI_REJECT_ESCO_CONNECTION:
525 STREAM_TO_BDADDR(bd_addr, p_cmd);
526 STREAM_TO_UINT8(reason, p_cmd);
527 bluetooth::common::LogLinkLayerConnectionEvent(
528 &bd_addr, bluetooth::common::kUnknownConnectionHandle,
529 android::bluetooth::DIRECTION_INCOMING,
530 android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event,
531 kUnknownBleEvt, cmd_status, reason);
535 case HCI_BLE_CREATE_LL_CONN: {
536 p_cmd += 2; // Skip LE_Scan_Interval
537 p_cmd += 2; // Skip LE_Scan_Window;
538 uint8_t initiator_filter_policy;
539 STREAM_TO_UINT8(initiator_filter_policy, p_cmd);
540 uint8_t peer_address_type;
541 STREAM_TO_UINT8(peer_address_type, p_cmd);
542 STREAM_TO_BDADDR(bd_addr, p_cmd);
543 // Peer address should not be used if initiator filter policy is not 0x00
544 const RawAddress* bd_addr_p = nullptr;
545 if (initiator_filter_policy == 0x00) {
546 bd_addr_p = &bd_addr;
547 #if (BLE_PRIVACY_SPT == TRUE)
548 if (peer_address_type == BLE_ADDR_PUBLIC_ID ||
549 peer_address_type == BLE_ADDR_RANDOM_ID) {
550 // if identity address is not matched, this address is invalid
551 if (!btm_identity_addr_to_random_pseudo(&bd_addr, &peer_address_type,
558 if (initiator_filter_policy == 0x00 ||
559 (cmd_status != HCI_SUCCESS && !is_cmd_status)) {
560 // Selectively log to avoid log spam due to whitelist connections:
561 // - When doing non-whitelist connection
562 // - When there is an error in command status
563 bluetooth::common::LogLinkLayerConnectionEvent(
564 bd_addr_p, bluetooth::common::kUnknownConnectionHandle,
565 android::bluetooth::DIRECTION_OUTGOING,
566 android::bluetooth::LINK_TYPE_ACL, opcode, hci_event,
567 kUnknownBleEvt, cmd_status,
568 android::bluetooth::hci::STATUS_UNKNOWN);
572 case HCI_LE_EXTENDED_CREATE_CONNECTION: {
573 uint8_t initiator_filter_policy;
574 STREAM_TO_UINT8(initiator_filter_policy, p_cmd);
575 p_cmd += 1; // Skip Own_Address_Type
576 uint8_t peer_addr_type;
577 STREAM_TO_UINT8(peer_addr_type, p_cmd);
578 STREAM_TO_BDADDR(bd_addr, p_cmd);
579 // Peer address should not be used if initiator filter policy is not 0x00
580 const RawAddress* bd_addr_p = nullptr;
581 if (initiator_filter_policy == 0x00) {
582 bd_addr_p = &bd_addr;
583 #if (BLE_PRIVACY_SPT == TRUE)
584 // if identity address is not matched, this should be a static address
585 btm_identity_addr_to_random_pseudo(&bd_addr, &peer_addr_type, false);
588 if (initiator_filter_policy == 0x00 ||
589 (cmd_status != HCI_SUCCESS && !is_cmd_status)) {
590 // Selectively log to avoid log spam due to whitelist connections:
591 // - When doing non-whitelist connection
592 // - When there is an error in command status
593 bluetooth::common::LogLinkLayerConnectionEvent(
594 bd_addr_p, bluetooth::common::kUnknownConnectionHandle,
595 android::bluetooth::DIRECTION_OUTGOING,
596 android::bluetooth::LINK_TYPE_ACL, opcode, hci_event,
597 kUnknownBleEvt, cmd_status,
598 android::bluetooth::hci::STATUS_UNKNOWN);
602 case HCI_BLE_CREATE_CONN_CANCEL:
603 if (cmd_status != HCI_SUCCESS && !is_cmd_status) {
604 // Only log errors to prevent log spam due to whitelist connections
605 bluetooth::common::LogLinkLayerConnectionEvent(
606 nullptr, bluetooth::common::kUnknownConnectionHandle,
607 android::bluetooth::DIRECTION_OUTGOING,
608 android::bluetooth::LINK_TYPE_ACL, opcode, hci_event,
609 kUnknownBleEvt, cmd_status,
610 android::bluetooth::hci::STATUS_UNKNOWN);
613 case HCI_BLE_CLEAR_WHITE_LIST:
614 bluetooth::common::LogLinkLayerConnectionEvent(
615 nullptr, bluetooth::common::kUnknownConnectionHandle,
616 android::bluetooth::DIRECTION_INCOMING,
617 android::bluetooth::LINK_TYPE_ACL, opcode, hci_event, kUnknownBleEvt,
618 cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
620 case HCI_BLE_ADD_WHITE_LIST:
621 case HCI_BLE_REMOVE_WHITE_LIST: {
622 uint8_t peer_addr_type;
623 STREAM_TO_UINT8(peer_addr_type, p_cmd);
624 STREAM_TO_BDADDR(bd_addr, p_cmd);
625 const RawAddress* bd_addr_p = nullptr;
626 // When peer_addr_type is 0xFF, bd_addr should be ignored per BT spec
627 if (peer_addr_type != BLE_ADDR_ANONYMOUS) {
628 bd_addr_p = &bd_addr;
629 #if (BLE_PRIVACY_SPT == TRUE)
630 bool addr_is_rpa = peer_addr_type == BLE_ADDR_RANDOM &&
631 BTM_BLE_IS_RESOLVE_BDA(bd_addr);
632 // Only try to match identity address for pseudo if address is not RPA
634 // if identity address is not matched, this should be a static address
635 btm_identity_addr_to_random_pseudo(&bd_addr, &peer_addr_type, false);
639 bluetooth::common::LogLinkLayerConnectionEvent(
640 bd_addr_p, bluetooth::common::kUnknownConnectionHandle,
641 android::bluetooth::DIRECTION_INCOMING,
642 android::bluetooth::LINK_TYPE_ACL, opcode, hci_event, kUnknownBleEvt,
643 cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
646 case HCI_READ_LOCAL_OOB_DATA:
647 bluetooth::common::LogClassicPairingEvent(
648 RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
649 opcode, hci_event, cmd_status,
650 android::bluetooth::hci::STATUS_UNKNOWN);
652 case HCI_WRITE_SIMPLE_PAIRING_MODE: {
653 uint8_t simple_pairing_mode;
654 STREAM_TO_UINT8(simple_pairing_mode, p_cmd);
655 // Use reason field to log simple pairing mode
656 bluetooth::common::LogClassicPairingEvent(
657 RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
658 opcode, hci_event, cmd_status, simple_pairing_mode);
661 case HCI_WRITE_SECURE_CONNS_SUPPORT: {
662 uint8_t secure_conn_host_support;
663 STREAM_TO_UINT8(secure_conn_host_support, p_cmd);
664 // Use reason field to log secure connection host support
665 bluetooth::common::LogClassicPairingEvent(
666 RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
667 opcode, hci_event, cmd_status, secure_conn_host_support);
670 case HCI_AUTHENTICATION_REQUESTED:
671 STREAM_TO_UINT16(handle, p_cmd);
672 bluetooth::common::LogClassicPairingEvent(
673 RawAddress::kEmpty, handle, opcode, hci_event, cmd_status,
674 android::bluetooth::hci::STATUS_UNKNOWN);
676 case HCI_SET_CONN_ENCRYPTION: {
677 STREAM_TO_UINT16(handle, p_cmd);
678 uint8_t encryption_enable;
679 STREAM_TO_UINT8(encryption_enable, p_cmd);
680 // Use reason field to log encryption enable
681 bluetooth::common::LogClassicPairingEvent(RawAddress::kEmpty, handle,
682 opcode, hci_event, cmd_status,
686 case HCI_DELETE_STORED_LINK_KEY: {
687 uint8_t delete_all_flag;
688 STREAM_TO_BDADDR(bd_addr, p_cmd);
689 STREAM_TO_UINT8(delete_all_flag, p_cmd);
690 // Use reason field to log delete_all_flag
691 bluetooth::common::LogClassicPairingEvent(
692 bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
693 hci_event, cmd_status, delete_all_flag);
696 case HCI_RMT_NAME_REQUEST:
697 case HCI_RMT_NAME_REQUEST_CANCEL:
698 case HCI_LINK_KEY_REQUEST_REPLY:
699 case HCI_LINK_KEY_REQUEST_NEG_REPLY:
700 case HCI_IO_CAPABILITY_REQUEST_REPLY:
701 case HCI_USER_CONF_REQUEST_REPLY:
702 case HCI_USER_CONF_VALUE_NEG_REPLY:
703 case HCI_USER_PASSKEY_REQ_REPLY:
704 case HCI_USER_PASSKEY_REQ_NEG_REPLY:
705 case HCI_REM_OOB_DATA_REQ_REPLY:
706 case HCI_REM_OOB_DATA_REQ_NEG_REPLY:
707 STREAM_TO_BDADDR(bd_addr, p_cmd);
708 bluetooth::common::LogClassicPairingEvent(
709 bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
710 hci_event, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
712 case HCI_IO_CAP_REQ_NEG_REPLY:
713 STREAM_TO_BDADDR(bd_addr, p_cmd);
714 STREAM_TO_UINT8(reason, p_cmd);
715 bluetooth::common::LogClassicPairingEvent(
716 bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
717 hci_event, cmd_status, reason);
722 /*******************************************************************************
724 * Function btu_hcif_send_cmd
726 * Description This function is called to send commands to the Host
731 ******************************************************************************/
732 void btu_hcif_send_cmd(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_buf) {
736 uint8_t* stream = p_buf->data + p_buf->offset;
737 void* vsc_callback = NULL;
739 STREAM_TO_UINT16(opcode, stream);
741 // Eww...horrible hackery here
742 /* If command was a VSC, then extract command_complete callback */
743 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC ||
744 (opcode == HCI_BLE_RAND) || (opcode == HCI_BLE_ENCRYPT)) {
745 vsc_callback = *((void**)(p_buf + 1));
748 // Skip parameter length before logging
750 btu_hcif_log_command_metrics(opcode, stream,
751 android::bluetooth::hci::STATUS_UNKNOWN, false);
753 hci_layer_get_interface()->transmit_command(
754 p_buf, btu_hcif_command_complete_evt, btu_hcif_command_status_evt,
758 using hci_cmd_cb = base::OnceCallback<void(
759 uint8_t* /* return_parameters */, uint16_t /* return_parameters_length*/)>;
761 struct cmd_with_cb_data {
763 Location posted_from;
766 void cmd_with_cb_data_init(cmd_with_cb_data* cb_wrapper) {
767 new (&cb_wrapper->cb) hci_cmd_cb;
768 new (&cb_wrapper->posted_from) Location;
771 void cmd_with_cb_data_cleanup(cmd_with_cb_data* cb_wrapper) {
772 cb_wrapper->cb.~hci_cmd_cb();
773 cb_wrapper->posted_from.~Location();
777 * Log command complete events that is not handled individually in this file
778 * @param opcode opcode of the command
779 * @param p_return_params pointer to returned parameter after parameter length
782 static void btu_hcif_log_command_complete_metrics(uint16_t opcode,
783 uint8_t* p_return_params) {
784 uint16_t status = android::bluetooth::hci::STATUS_UNKNOWN;
785 uint16_t reason = android::bluetooth::hci::STATUS_UNKNOWN;
786 uint16_t hci_event = android::bluetooth::hci::EVT_COMMAND_COMPLETE;
787 uint16_t hci_ble_event = android::bluetooth::hci::BLE_EVT_UNKNOWN;
788 RawAddress bd_addr = RawAddress::kEmpty;
790 case HCI_BLE_CLEAR_WHITE_LIST:
791 case HCI_BLE_ADD_WHITE_LIST:
792 case HCI_BLE_REMOVE_WHITE_LIST: {
793 STREAM_TO_UINT8(status, p_return_params);
794 bluetooth::common::LogLinkLayerConnectionEvent(
795 nullptr, bluetooth::common::kUnknownConnectionHandle,
796 android::bluetooth::DIRECTION_INCOMING,
797 android::bluetooth::LINK_TYPE_ACL, opcode, hci_event, hci_ble_event,
801 case HCI_DELETE_STORED_LINK_KEY:
802 case HCI_READ_LOCAL_OOB_DATA:
803 case HCI_WRITE_SIMPLE_PAIRING_MODE:
804 case HCI_WRITE_SECURE_CONNS_SUPPORT:
805 STREAM_TO_UINT8(status, p_return_params);
806 bluetooth::common::LogClassicPairingEvent(
807 RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
808 opcode, hci_event, status, reason);
810 case HCI_LINK_KEY_REQUEST_REPLY:
811 case HCI_LINK_KEY_REQUEST_NEG_REPLY:
812 case HCI_IO_CAPABILITY_REQUEST_REPLY:
813 case HCI_IO_CAP_REQ_NEG_REPLY:
814 case HCI_USER_CONF_REQUEST_REPLY:
815 case HCI_USER_CONF_VALUE_NEG_REPLY:
816 case HCI_USER_PASSKEY_REQ_REPLY:
817 case HCI_USER_PASSKEY_REQ_NEG_REPLY:
818 case HCI_REM_OOB_DATA_REQ_REPLY:
819 case HCI_REM_OOB_DATA_REQ_NEG_REPLY:
820 STREAM_TO_UINT8(status, p_return_params);
821 STREAM_TO_BDADDR(bd_addr, p_return_params);
822 bluetooth::common::LogClassicPairingEvent(
823 bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
824 hci_event, status, reason);
829 static void btu_hcif_command_complete_evt_with_cb_on_task(BT_HDR* event,
831 command_opcode_t opcode;
832 // 2 for event header: event code (1) + parameter length (1)
833 // 1 for num_hci_pkt command credit
834 uint8_t* stream = event->data + event->offset + 3;
835 STREAM_TO_UINT16(opcode, stream);
837 btu_hcif_log_command_complete_metrics(opcode, stream);
839 cmd_with_cb_data* cb_wrapper = (cmd_with_cb_data*)context;
840 HCI_TRACE_DEBUG("command complete for: %s",
841 cb_wrapper->posted_from.ToString().c_str());
842 // 2 for event header: event code (1) + parameter length (1)
843 // 3 for command complete header: num_hci_pkt (1) + opcode (2)
844 uint16_t param_len = static_cast<uint16_t>(event->len - 5);
845 std::move(cb_wrapper->cb).Run(stream, param_len);
846 cmd_with_cb_data_cleanup(cb_wrapper);
847 osi_free(cb_wrapper);
852 static void btu_hcif_command_complete_evt_with_cb(BT_HDR* response,
854 do_in_main_thread(FROM_HERE,
855 base::Bind(btu_hcif_command_complete_evt_with_cb_on_task,
859 static void btu_hcif_command_status_evt_with_cb_on_task(uint8_t status,
862 command_opcode_t opcode;
863 uint8_t* stream = event->data + event->offset;
864 STREAM_TO_UINT16(opcode, stream);
868 // stream + 1 to skip parameter length field
869 // No need to check length since stream is written by us
870 btu_hcif_log_command_metrics(opcode, stream + 1, status, true);
872 // report command status error
873 cmd_with_cb_data* cb_wrapper = (cmd_with_cb_data*)context;
874 HCI_TRACE_DEBUG("command status for: %s",
875 cb_wrapper->posted_from.ToString().c_str());
876 std::move(cb_wrapper->cb).Run(&status, sizeof(uint16_t));
877 cmd_with_cb_data_cleanup(cb_wrapper);
878 osi_free(cb_wrapper);
883 static void btu_hcif_command_status_evt_with_cb(uint8_t status, BT_HDR* command,
885 // Command is pending, we report only error.
892 FROM_HERE, base::Bind(btu_hcif_command_status_evt_with_cb_on_task, status,
896 /* This function is called to send commands to the Host Controller. |cb| is
897 * called when command status event is called with error code, or when the
898 * command complete event is received. */
899 void btu_hcif_send_cmd_with_cb(const Location& posted_from, uint16_t opcode,
900 uint8_t* params, uint8_t params_len,
902 BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
903 uint8_t* pp = (uint8_t*)(p + 1);
905 p->len = HCIC_PREAMBLE_SIZE + params_len;
908 UINT16_TO_STREAM(pp, opcode);
909 UINT8_TO_STREAM(pp, params_len);
911 memcpy(pp, params, params_len);
914 btu_hcif_log_command_metrics(opcode, pp,
915 android::bluetooth::hci::STATUS_UNKNOWN, false);
917 cmd_with_cb_data* cb_wrapper =
918 (cmd_with_cb_data*)osi_malloc(sizeof(cmd_with_cb_data));
920 cmd_with_cb_data_init(cb_wrapper);
921 cb_wrapper->cb = std::move(cb);
922 cb_wrapper->posted_from = posted_from;
924 hci_layer_get_interface()->transmit_command(
925 p, btu_hcif_command_complete_evt_with_cb,
926 btu_hcif_command_status_evt_with_cb, (void*)cb_wrapper);
929 /*******************************************************************************
931 * Function btu_hcif_inquiry_comp_evt
933 * Description Process event HCI_INQUIRY_COMP_EVT
937 ******************************************************************************/
938 static void btu_hcif_inquiry_comp_evt(uint8_t* p) {
941 STREAM_TO_UINT8(status, p);
943 /* Tell inquiry processing that we are done */
944 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
947 /*******************************************************************************
949 * Function btu_hcif_inquiry_result_evt
951 * Description Process event HCI_INQUIRY_RESULT_EVT
955 ******************************************************************************/
956 static void btu_hcif_inquiry_result_evt(uint8_t* p) {
957 /* Store results in the cache */
958 btm_process_inq_results(p, BTM_INQ_RESULT_STANDARD);
961 /*******************************************************************************
963 * Function btu_hcif_inquiry_rssi_result_evt
965 * Description Process event HCI_INQUIRY_RSSI_RESULT_EVT
969 ******************************************************************************/
970 static void btu_hcif_inquiry_rssi_result_evt(uint8_t* p) {
971 /* Store results in the cache */
972 btm_process_inq_results(p, BTM_INQ_RESULT_WITH_RSSI);
975 /*******************************************************************************
977 * Function btu_hcif_extended_inquiry_result_evt
979 * Description Process event HCI_EXTENDED_INQUIRY_RESULT_EVT
983 ******************************************************************************/
984 static void btu_hcif_extended_inquiry_result_evt(uint8_t* p) {
985 /* Store results in the cache */
986 btm_process_inq_results(p, BTM_INQ_RESULT_EXTENDED);
989 /*******************************************************************************
991 * Function btu_hcif_connection_comp_evt
993 * Description Process event HCI_CONNECTION_COMP_EVT
997 ******************************************************************************/
998 static void btu_hcif_connection_comp_evt(uint8_t* p) {
1004 tBTM_ESCO_DATA esco_data;
1006 STREAM_TO_UINT8(status, p);
1007 STREAM_TO_UINT16(handle, p);
1008 STREAM_TO_BDADDR(bda, p);
1009 STREAM_TO_UINT8(link_type, p);
1010 STREAM_TO_UINT8(enc_mode, p);
1012 handle = HCID_GET_HANDLE(handle);
1014 if (status != HCI_SUCCESS) {
1016 "%s: Connection failed: status=%d, handle=%d, link_type=%d, "
1018 __func__, status, handle, link_type, enc_mode);
1021 if (link_type == HCI_LINK_TYPE_ACL) {
1022 btm_sec_connected(bda, handle, status, enc_mode);
1024 l2c_link_hci_conn_comp(status, handle, bda);
1026 memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA));
1027 /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */
1028 esco_data.bd_addr = bda;
1029 btm_sco_connected(status, &bda, handle, &esco_data);
1033 /*******************************************************************************
1035 * Function btu_hcif_connection_request_evt
1037 * Description Process event HCI_CONNECTION_REQUEST_EVT
1041 ******************************************************************************/
1042 static void btu_hcif_connection_request_evt(uint8_t* p) {
1047 STREAM_TO_BDADDR(bda, p);
1048 STREAM_TO_DEVCLASS(dc, p);
1049 STREAM_TO_UINT8(link_type, p);
1051 /* Pass request to security manager to check connect filters before */
1052 /* passing request to l2cap */
1053 if (link_type == HCI_LINK_TYPE_ACL) {
1054 btm_sec_conn_req(bda, dc);
1056 btm_sco_conn_req(bda, dc, link_type);
1060 /*******************************************************************************
1062 * Function btu_hcif_disconnection_comp_evt
1064 * Description Process event HCI_DISCONNECTION_COMP_EVT
1068 ******************************************************************************/
1069 static void btu_hcif_disconnection_comp_evt(uint8_t* p) {
1074 STREAM_TO_UINT8(status, p);
1075 STREAM_TO_UINT16(handle, p);
1076 STREAM_TO_UINT8(reason, p);
1078 handle = HCID_GET_HANDLE(handle);
1080 if ((reason != HCI_ERR_CONN_CAUSE_LOCAL_HOST) &&
1081 (reason != HCI_ERR_PEER_USER)) {
1082 /* Uncommon disconnection reasons */
1083 HCI_TRACE_DEBUG("%s: Got Disconn Complete Event: reason=%d, handle=%d",
1084 __func__, reason, handle);
1087 /* If L2CAP doesn't know about it, send it to SCO */
1088 if (!l2c_link_hci_disc_comp(handle, reason)) btm_sco_removed(handle, reason);
1090 /* Notify security manager */
1091 btm_sec_disconnected(handle, reason);
1094 /*******************************************************************************
1096 * Function btu_hcif_authentication_comp_evt
1098 * Description Process event HCI_AUTHENTICATION_COMP_EVT
1102 ******************************************************************************/
1103 static void btu_hcif_authentication_comp_evt(uint8_t* p) {
1107 STREAM_TO_UINT8(status, p);
1108 STREAM_TO_UINT16(handle, p);
1110 btm_sec_auth_complete(handle, status);
1113 /*******************************************************************************
1115 * Function btu_hcif_rmt_name_request_comp_evt
1117 * Description Process event HCI_RMT_NAME_REQUEST_COMP_EVT
1121 ******************************************************************************/
1122 static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len) {
1126 STREAM_TO_UINT8(status, p);
1127 STREAM_TO_BDADDR(bd_addr, p);
1129 evt_len -= (1 + BD_ADDR_LEN);
1131 btm_process_remote_name(&bd_addr, p, evt_len, status);
1133 btm_sec_rmt_name_request_complete(&bd_addr, p, status);
1136 /*******************************************************************************
1138 * Function btu_hcif_encryption_change_evt
1140 * Description Process event HCI_ENCRYPTION_CHANGE_EVT
1144 ******************************************************************************/
1145 static void btu_hcif_encryption_change_evt(uint8_t* p) {
1148 uint8_t encr_enable;
1150 STREAM_TO_UINT8(status, p);
1151 STREAM_TO_UINT16(handle, p);
1152 STREAM_TO_UINT8(encr_enable, p);
1154 if (status == HCI_ERR_CONNECTION_TOUT) {
1155 smp_cancel_start_encryption_attempt();
1159 btm_acl_encrypt_change(handle, status, encr_enable);
1160 btm_sec_encrypt_change(handle, status, encr_enable);
1163 /*******************************************************************************
1165 * Function btu_hcif_read_rmt_features_comp_evt
1167 * Description Process event HCI_READ_RMT_FEATURES_COMP_EVT
1171 ******************************************************************************/
1172 static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p) {
1173 btm_read_remote_features_complete(p);
1176 /*******************************************************************************
1178 * Function btu_hcif_read_rmt_ext_features_comp_evt
1180 * Description Process event HCI_READ_RMT_EXT_FEATURES_COMP_EVT
1184 ******************************************************************************/
1185 static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p) {
1190 STREAM_TO_UINT8(status, p_cur);
1192 if (status == HCI_SUCCESS)
1193 btm_read_remote_ext_features_complete(p);
1195 STREAM_TO_UINT16(handle, p_cur);
1196 btm_read_remote_ext_features_failed(status, handle);
1200 /*******************************************************************************
1202 * Function btu_hcif_read_rmt_version_comp_evt
1204 * Description Process event HCI_READ_RMT_VERSION_COMP_EVT
1208 ******************************************************************************/
1209 static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p) {
1210 btm_read_remote_version_complete(p);
1213 /*******************************************************************************
1215 * Function btu_hcif_qos_setup_comp_evt
1217 * Description Process event HCI_QOS_SETUP_COMP_EVT
1221 ******************************************************************************/
1222 static void btu_hcif_qos_setup_comp_evt(uint8_t* p) {
1227 STREAM_TO_UINT8(status, p);
1228 STREAM_TO_UINT16(handle, p);
1229 STREAM_TO_UINT8(flow.qos_flags, p);
1230 STREAM_TO_UINT8(flow.service_type, p);
1231 STREAM_TO_UINT32(flow.token_rate, p);
1232 STREAM_TO_UINT32(flow.peak_bandwidth, p);
1233 STREAM_TO_UINT32(flow.latency, p);
1234 STREAM_TO_UINT32(flow.delay_variation, p);
1236 btm_qos_setup_complete(status, handle, &flow);
1239 /*******************************************************************************
1241 * Function btu_hcif_esco_connection_comp_evt
1243 * Description Process event HCI_ESCO_CONNECTION_COMP_EVT
1247 ******************************************************************************/
1248 static void btu_hcif_esco_connection_comp_evt(uint8_t* p) {
1249 tBTM_ESCO_DATA data;
1254 STREAM_TO_UINT8(status, p);
1255 STREAM_TO_UINT16(handle, p);
1256 STREAM_TO_BDADDR(bda, p);
1258 STREAM_TO_UINT8(data.link_type, p);
1259 STREAM_TO_UINT8(data.tx_interval, p);
1260 STREAM_TO_UINT8(data.retrans_window, p);
1261 STREAM_TO_UINT16(data.rx_pkt_len, p);
1262 STREAM_TO_UINT16(data.tx_pkt_len, p);
1263 STREAM_TO_UINT8(data.air_mode, p);
1265 handle = HCID_GET_HANDLE(handle);
1268 btm_sco_connected(status, &bda, handle, &data);
1271 /*******************************************************************************
1273 * Function btu_hcif_esco_connection_chg_evt
1275 * Description Process event HCI_ESCO_CONNECTION_CHANGED_EVT
1279 ******************************************************************************/
1280 static void btu_hcif_esco_connection_chg_evt(uint8_t* p) {
1282 uint16_t tx_pkt_len;
1283 uint16_t rx_pkt_len;
1285 uint8_t tx_interval;
1286 uint8_t retrans_window;
1288 STREAM_TO_UINT8(status, p);
1289 STREAM_TO_UINT16(handle, p);
1291 STREAM_TO_UINT8(tx_interval, p);
1292 STREAM_TO_UINT8(retrans_window, p);
1293 STREAM_TO_UINT16(rx_pkt_len, p);
1294 STREAM_TO_UINT16(tx_pkt_len, p);
1296 handle = HCID_GET_HANDLE(handle);
1298 btm_esco_proc_conn_chg(status, handle, tx_interval, retrans_window,
1299 rx_pkt_len, tx_pkt_len);
1302 /*******************************************************************************
1304 * Function btu_hcif_hdl_command_complete
1306 * Description Handle command complete event
1310 ******************************************************************************/
1311 static void btu_hcif_hdl_command_complete(uint16_t opcode, uint8_t* p,
1313 void* p_cplt_cback) {
1315 case HCI_INQUIRY_CANCEL:
1316 /* Tell inquiry processing that we are done */
1317 btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK);
1319 case HCI_SET_EVENT_FILTER:
1320 btm_event_filter_complete(p);
1323 case HCI_DELETE_STORED_LINK_KEY:
1324 btm_delete_stored_link_key_complete(p);
1327 case HCI_READ_LOCAL_NAME:
1328 btm_read_local_name_complete(p, evt_len);
1331 case HCI_GET_LINK_QUALITY:
1332 btm_read_link_quality_complete(p);
1336 btm_read_rssi_complete(p);
1339 case HCI_READ_FAILED_CONTACT_COUNTER:
1340 btm_read_failed_contact_counter_complete(p);
1343 case HCI_READ_AUTOMATIC_FLUSH_TIMEOUT:
1344 btm_read_automatic_flush_timeout_complete(p);
1347 case HCI_READ_TRANSMIT_POWER_LEVEL:
1348 btm_read_tx_power_complete(p, false);
1351 case HCI_CREATE_CONNECTION_CANCEL:
1352 btm_create_conn_cancel_complete(p);
1355 case HCI_READ_LOCAL_OOB_DATA:
1356 btm_read_local_oob_complete(p);
1359 case HCI_READ_INQ_TX_POWER_LEVEL:
1360 btm_read_inq_tx_power_complete(p);
1363 /* BLE Commands sComplete*/
1365 case HCI_BLE_ENCRYPT:
1366 btm_ble_rand_enc_complete(p, opcode, (tBTM_RAND_ENC_CB*)p_cplt_cback);
1369 case HCI_BLE_READ_ADV_CHNL_TX_POWER:
1370 btm_read_tx_power_complete(p, true);
1373 case HCI_BLE_WRITE_ADV_ENABLE:
1374 btm_ble_write_adv_enable_complete(p);
1377 case HCI_BLE_CREATE_LL_CONN:
1378 case HCI_LE_EXTENDED_CREATE_CONNECTION:
1379 // No command complete event for those commands according to spec
1380 LOG(ERROR) << "No command complete expected, but received!";
1383 case HCI_BLE_CREATE_CONN_CANCEL:
1384 btm_ble_create_conn_cancel_complete(p);
1387 case HCI_BLE_TRANSMITTER_TEST:
1388 case HCI_BLE_RECEIVER_TEST:
1389 case HCI_BLE_TEST_END:
1390 btm_ble_test_command_complete(p);
1393 #if (BLE_PRIVACY_SPT == TRUE)
1394 case HCI_BLE_ADD_DEV_RESOLVING_LIST:
1395 btm_ble_add_resolving_list_entry_complete(p, evt_len);
1398 case HCI_BLE_RM_DEV_RESOLVING_LIST:
1399 btm_ble_remove_resolving_list_entry_complete(p, evt_len);
1402 case HCI_BLE_CLEAR_RESOLVING_LIST:
1403 btm_ble_clear_resolving_list_complete(p, evt_len);
1406 case HCI_BLE_READ_RESOLVABLE_ADDR_PEER:
1407 btm_ble_read_resolving_list_entry_complete(p, evt_len);
1410 case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL:
1411 case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE:
1412 case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT:
1416 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1417 btm_vsc_complete(p, opcode, evt_len, (tBTM_VSC_CMPL_CB*)p_cplt_cback);
1422 /*******************************************************************************
1424 * Function btu_hcif_command_complete_evt
1426 * Description Process event HCI_COMMAND_COMPLETE_EVT
1430 ******************************************************************************/
1431 static void btu_hcif_command_complete_evt_on_task(BT_HDR* event,
1433 command_opcode_t opcode;
1434 // 2 for event header: event code (1) + parameter length (1)
1435 // 1 for num_hci_pkt command credit
1436 uint8_t* stream = event->data + event->offset + 3;
1437 STREAM_TO_UINT16(opcode, stream);
1439 btu_hcif_log_command_complete_metrics(opcode, stream);
1440 // 2 for event header: event code (1) + parameter length (1)
1441 // 3 for command complete header: num_hci_pkt (1) + opcode (2)
1442 uint16_t param_len = static_cast<uint16_t>(event->len - 5);
1443 btu_hcif_hdl_command_complete(opcode, stream, param_len, context);
1448 static void btu_hcif_command_complete_evt(BT_HDR* response, void* context) {
1449 do_in_main_thread(FROM_HERE, base::Bind(btu_hcif_command_complete_evt_on_task,
1450 response, context));
1453 /*******************************************************************************
1455 * Function btu_hcif_hdl_command_status
1457 * Description Handle a command status event
1461 ******************************************************************************/
1462 static void btu_hcif_hdl_command_status(uint16_t opcode, uint8_t status,
1464 void* p_vsc_status_cback) {
1465 CHECK_NE(p_cmd, nullptr) << "Null command for opcode 0x" << loghex(opcode);
1466 p_cmd++; // Skip parameter total length
1472 // Link Control Commands
1474 if (status != HCI_SUCCESS) {
1475 // Tell inquiry processing that we are done
1476 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
1480 if (status != HCI_SUCCESS) {
1481 // Tell qos setup that we are done
1482 btm_qos_setup_complete(status, 0, nullptr);
1485 case HCI_SWITCH_ROLE:
1486 if (status != HCI_SUCCESS) {
1487 // Tell BTM that the command failed
1488 STREAM_TO_BDADDR(bd_addr, p_cmd);
1489 btm_acl_role_changed(status, &bd_addr, BTM_ROLE_UNDEFINED);
1490 l2c_link_role_changed(nullptr, BTM_ROLE_UNDEFINED,
1491 HCI_ERR_COMMAND_DISALLOWED);
1494 case HCI_CREATE_CONNECTION:
1495 if (status != HCI_SUCCESS) {
1496 STREAM_TO_BDADDR(bd_addr, p_cmd);
1497 btm_sec_connected(bd_addr, HCI_INVALID_HANDLE, status, 0);
1498 l2c_link_hci_conn_comp(status, HCI_INVALID_HANDLE, bd_addr);
1501 case HCI_AUTHENTICATION_REQUESTED:
1502 if (status != HCI_SUCCESS) {
1503 // Device refused to start authentication
1504 // This is treated as an authentication failure
1505 btm_sec_auth_complete(BTM_INVALID_HCI_HANDLE, status);
1508 case HCI_SET_CONN_ENCRYPTION:
1509 if (status != HCI_SUCCESS) {
1510 // Device refused to start encryption
1511 // This is treated as an encryption failure
1512 btm_sec_encrypt_change(BTM_INVALID_HCI_HANDLE, status, false);
1515 case HCI_RMT_NAME_REQUEST:
1516 if (status != HCI_SUCCESS) {
1517 // Tell inquiry processing that we are done
1518 btm_process_remote_name(nullptr, nullptr, 0, status);
1519 btm_sec_rmt_name_request_complete(nullptr, nullptr, status);
1522 case HCI_READ_RMT_EXT_FEATURES:
1523 if (status != HCI_SUCCESS) {
1524 STREAM_TO_UINT16(handle, p_cmd);
1525 btm_read_remote_ext_features_failed(status, handle);
1528 case HCI_SETUP_ESCO_CONNECTION:
1529 case HCI_ENH_SETUP_ESCO_CONNECTION:
1530 if (status != HCI_SUCCESS) {
1531 STREAM_TO_UINT16(handle, p_cmd);
1532 // Determine if initial connection failed or is a change of setup
1533 if (btm_is_sco_active(handle)) {
1534 btm_esco_proc_conn_chg(status, handle, 0, 0, 0, 0);
1536 btm_sco_connected(status, nullptr, handle, nullptr);
1542 case HCI_BLE_CREATE_LL_CONN:
1543 case HCI_LE_EXTENDED_CREATE_CONNECTION:
1544 if (status != HCI_SUCCESS) {
1545 btm_ble_create_ll_conn_complete(status);
1548 case HCI_BLE_START_ENC:
1549 // Race condition: disconnection happened right before we send
1550 // "LE Encrypt", controller responds with no connection, we should
1551 // cancel the encryption attempt, rather than unpair the device.
1552 if (status == HCI_ERR_NO_CONNECTION) {
1553 smp_cancel_start_encryption_attempt();
1557 // Link Policy Commands
1558 case HCI_EXIT_SNIFF_MODE:
1559 case HCI_EXIT_PARK_MODE:
1560 if (status != HCI_SUCCESS) {
1561 // Allow SCO initiation to continue if waiting for change mode event
1562 STREAM_TO_UINT16(handle, p_cmd);
1563 btm_sco_chk_pend_unpark(status, handle);
1565 FALLTHROUGH_INTENDED; /* FALLTHROUGH */
1567 case HCI_SNIFF_MODE:
1569 btm_pm_proc_cmd_status(status);
1573 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) {
1574 btm_vsc_complete(&status, opcode, 1,
1575 (tBTM_VSC_CMPL_CB*)p_vsc_status_cback);
1580 /*******************************************************************************
1582 * Function btu_hcif_command_status_evt
1584 * Description Process event HCI_COMMAND_STATUS_EVT
1588 ******************************************************************************/
1589 static void btu_hcif_command_status_evt_on_task(uint8_t status, BT_HDR* event,
1591 command_opcode_t opcode;
1592 uint8_t* stream = event->data + event->offset;
1593 STREAM_TO_UINT16(opcode, stream);
1595 // stream + 1 to skip parameter length field
1596 // No need to check length since stream is written by us
1597 btu_hcif_log_command_metrics(opcode, stream + 1, status, true);
1599 btu_hcif_hdl_command_status(opcode, status, stream, context);
1603 static void btu_hcif_command_status_evt(uint8_t status, BT_HDR* command,
1605 do_in_main_thread(FROM_HERE, base::Bind(btu_hcif_command_status_evt_on_task,
1606 status, command, context));
1609 /*******************************************************************************
1611 * Function btu_hcif_hardware_error_evt
1613 * Description Process event HCI_HARDWARE_ERROR_EVT
1617 ******************************************************************************/
1618 static void btu_hcif_hardware_error_evt(uint8_t* p) {
1619 HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p);
1621 /* If anyone wants device status notifications, give him one. */
1622 btm_report_device_status(BTM_DEV_STATUS_DOWN);
1624 /* Reset the controller */
1625 if (BTM_IsDeviceUp()) BTM_DeviceReset(NULL);
1628 /*******************************************************************************
1630 * Function btu_hcif_flush_occured_evt
1632 * Description Process event HCI_FLUSH_OCCURED_EVT
1636 ******************************************************************************/
1637 static void btu_hcif_flush_occured_evt(void) {}
1639 /*******************************************************************************
1641 * Function btu_hcif_role_change_evt
1643 * Description Process event HCI_ROLE_CHANGE_EVT
1647 ******************************************************************************/
1648 static void btu_hcif_role_change_evt(uint8_t* p) {
1653 STREAM_TO_UINT8(status, p);
1654 STREAM_TO_BDADDR(bda, p);
1655 STREAM_TO_UINT8(role, p);
1657 btm_blacklist_role_change_device(bda, status);
1658 l2c_link_role_changed(&bda, role, status);
1659 btm_acl_role_changed(status, &bda, role);
1662 /*******************************************************************************
1664 * Function btu_hcif_num_compl_data_pkts_evt
1666 * Description Process event HCI_NUM_COMPL_DATA_PKTS_EVT
1670 ******************************************************************************/
1671 static void btu_hcif_num_compl_data_pkts_evt(uint8_t* p) {
1672 /* Process for L2CAP and SCO */
1673 l2c_link_process_num_completed_pkts(p);
1675 /* Send on to SCO */
1676 /*?? No SCO for now */
1679 /*******************************************************************************
1681 * Function btu_hcif_mode_change_evt
1683 * Description Process event HCI_MODE_CHANGE_EVT
1687 ******************************************************************************/
1688 static void btu_hcif_mode_change_evt(uint8_t* p) {
1691 uint8_t current_mode;
1694 STREAM_TO_UINT8(status, p);
1696 STREAM_TO_UINT16(handle, p);
1697 STREAM_TO_UINT8(current_mode, p);
1698 STREAM_TO_UINT16(interval, p);
1699 btm_sco_chk_pend_unpark(status, handle);
1700 btm_pm_proc_mode_change(status, handle, current_mode, interval);
1702 #if (HID_DEV_INCLUDED == TRUE && HID_DEV_PM_INCLUDED == TRUE)
1703 hidd_pm_proc_mode_change(status, current_mode, interval);
1707 /*******************************************************************************
1709 * Function btu_hcif_ssr_evt
1711 * Description Process event HCI_SNIFF_SUB_RATE_EVT
1715 ******************************************************************************/
1716 #if (BTM_SSR_INCLUDED == TRUE)
1717 static void btu_hcif_ssr_evt(uint8_t* p, uint16_t evt_len) {
1718 btm_pm_proc_ssr_evt(p, evt_len);
1722 /*******************************************************************************
1724 * Function btu_hcif_pin_code_request_evt
1726 * Description Process event HCI_PIN_CODE_REQUEST_EVT
1730 ******************************************************************************/
1731 static void btu_hcif_pin_code_request_evt(uint8_t* p) {
1734 STREAM_TO_BDADDR(bda, p);
1736 /* Tell L2CAP that there was a PIN code request, */
1737 /* it may need to stretch timeouts */
1738 l2c_pin_code_request(bda);
1740 btm_sec_pin_code_request(bda);
1743 /*******************************************************************************
1745 * Function btu_hcif_link_key_request_evt
1747 * Description Process event HCI_LINK_KEY_REQUEST_EVT
1751 ******************************************************************************/
1752 static void btu_hcif_link_key_request_evt(uint8_t* p) {
1755 STREAM_TO_BDADDR(bda, p);
1756 btm_sec_link_key_request(bda);
1759 /*******************************************************************************
1761 * Function btu_hcif_link_key_notification_evt
1763 * Description Process event HCI_LINK_KEY_NOTIFICATION_EVT
1767 ******************************************************************************/
1768 static void btu_hcif_link_key_notification_evt(uint8_t* p) {
1773 STREAM_TO_BDADDR(bda, p);
1774 STREAM_TO_ARRAY16(key.data(), p);
1775 STREAM_TO_UINT8(key_type, p);
1777 btm_sec_link_key_notification(bda, key, key_type);
1780 /*******************************************************************************
1782 * Function btu_hcif_loopback_command_evt
1784 * Description Process event HCI_LOOPBACK_COMMAND_EVT
1788 ******************************************************************************/
1789 static void btu_hcif_loopback_command_evt(void) {}
1791 /*******************************************************************************
1793 * Function btu_hcif_data_buf_overflow_evt
1795 * Description Process event HCI_DATA_BUF_OVERFLOW_EVT
1799 ******************************************************************************/
1800 static void btu_hcif_data_buf_overflow_evt(void) {}
1802 /*******************************************************************************
1804 * Function btu_hcif_max_slots_changed_evt
1806 * Description Process event HCI_MAX_SLOTS_CHANGED_EVT
1810 ******************************************************************************/
1811 static void btu_hcif_max_slots_changed_evt(void) {}
1813 /*******************************************************************************
1815 * Function btu_hcif_read_clock_off_comp_evt
1817 * Description Process event HCI_READ_CLOCK_OFF_COMP_EVT
1821 ******************************************************************************/
1822 static void btu_hcif_read_clock_off_comp_evt(uint8_t* p) {
1825 uint16_t clock_offset;
1827 STREAM_TO_UINT8(status, p);
1829 /* If failed to get clock offset just drop the result */
1830 if (status != HCI_SUCCESS) return;
1832 STREAM_TO_UINT16(handle, p);
1833 STREAM_TO_UINT16(clock_offset, p);
1835 handle = HCID_GET_HANDLE(handle);
1837 btm_process_clk_off_comp_evt(handle, clock_offset);
1838 btm_sec_update_clock_offset(handle, clock_offset);
1841 /*******************************************************************************
1843 * Function btu_hcif_conn_pkt_type_change_evt
1845 * Description Process event HCI_CONN_PKT_TYPE_CHANGE_EVT
1849 ******************************************************************************/
1850 static void btu_hcif_conn_pkt_type_change_evt(void) {}
1852 /*******************************************************************************
1854 * Function btu_hcif_qos_violation_evt
1856 * Description Process event HCI_QOS_VIOLATION_EVT
1860 ******************************************************************************/
1861 static void btu_hcif_qos_violation_evt(uint8_t* p) {
1864 STREAM_TO_UINT16(handle, p);
1866 handle = HCID_GET_HANDLE(handle);
1868 l2c_link_hci_qos_violation(handle);
1871 /*******************************************************************************
1873 * Function btu_hcif_page_scan_mode_change_evt
1875 * Description Process event HCI_PAGE_SCAN_MODE_CHANGE_EVT
1879 ******************************************************************************/
1880 static void btu_hcif_page_scan_mode_change_evt(void) {}
1882 /*******************************************************************************
1884 * Function btu_hcif_page_scan_rep_mode_chng_evt
1886 * Description Process event HCI_PAGE_SCAN_REP_MODE_CHNG_EVT
1890 ******************************************************************************/
1891 static void btu_hcif_page_scan_rep_mode_chng_evt(void) {}
1893 /**********************************************
1894 * Simple Pairing Events
1895 **********************************************/
1897 /*******************************************************************************
1899 * Function btu_hcif_host_support_evt
1901 * Description Process event HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT
1905 ******************************************************************************/
1906 static void btu_hcif_host_support_evt(uint8_t* p) {
1907 btm_sec_rmt_host_support_feat_evt(p);
1910 /*******************************************************************************
1912 * Function btu_hcif_io_cap_request_evt
1914 * Description Process event HCI_IO_CAPABILITY_REQUEST_EVT
1918 ******************************************************************************/
1919 static void btu_hcif_io_cap_request_evt(uint8_t* p) {
1921 STREAM_TO_BDADDR(bda, p);
1922 btm_io_capabilities_req(bda);
1925 /*******************************************************************************
1927 * Function btu_hcif_io_cap_response_evt
1929 * Description Process event HCI_IO_CAPABILITY_RESPONSE_EVT
1933 ******************************************************************************/
1934 static void btu_hcif_io_cap_response_evt(uint8_t* p) {
1935 btm_io_capabilities_rsp(p);
1938 /*******************************************************************************
1940 * Function btu_hcif_user_conf_request_evt
1942 * Description Process event HCI_USER_CONFIRMATION_REQUEST_EVT
1946 ******************************************************************************/
1947 static void btu_hcif_user_conf_request_evt(uint8_t* p) {
1948 btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p);
1951 /*******************************************************************************
1953 * Function btu_hcif_user_passkey_request_evt
1955 * Description Process event HCI_USER_PASSKEY_REQUEST_EVT
1959 ******************************************************************************/
1960 static void btu_hcif_user_passkey_request_evt(uint8_t* p) {
1961 btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p);
1964 /*******************************************************************************
1966 * Function btu_hcif_user_passkey_notif_evt
1968 * Description Process event HCI_USER_PASSKEY_NOTIFY_EVT
1972 ******************************************************************************/
1973 static void btu_hcif_user_passkey_notif_evt(uint8_t* p) {
1974 btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p);
1977 /*******************************************************************************
1979 * Function btu_hcif_keypress_notif_evt
1981 * Description Process event HCI_KEYPRESS_NOTIFY_EVT
1985 ******************************************************************************/
1986 static void btu_hcif_keypress_notif_evt(uint8_t* p) {
1987 btm_keypress_notif_evt(p);
1990 /*******************************************************************************
1992 * Function btu_hcif_rem_oob_request_evt
1994 * Description Process event HCI_REMOTE_OOB_DATA_REQUEST_EVT
1998 ******************************************************************************/
1999 static void btu_hcif_rem_oob_request_evt(uint8_t* p) { btm_rem_oob_req(p); }
2001 /*******************************************************************************
2003 * Function btu_hcif_simple_pair_complete_evt
2005 * Description Process event HCI_SIMPLE_PAIRING_COMPLETE_EVT
2009 ******************************************************************************/
2010 static void btu_hcif_simple_pair_complete_evt(uint8_t* p) {
2011 btm_simple_pair_complete(p);
2014 /*******************************************************************************
2016 * Function btu_hcif_enhanced_flush_complete_evt
2018 * Description Process event HCI_ENHANCED_FLUSH_COMPLETE_EVT
2022 ******************************************************************************/
2023 #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
2024 static void btu_hcif_enhanced_flush_complete_evt(void) {
2025 /* This is empty until an upper layer cares about returning event */
2028 /**********************************************
2029 * End of Simple Pairing Events
2030 **********************************************/
2032 /**********************************************
2034 **********************************************/
2035 static void btu_hcif_encryption_key_refresh_cmpl_evt(uint8_t* p) {
2037 uint8_t enc_enable = 0;
2040 STREAM_TO_UINT8(status, p);
2041 STREAM_TO_UINT16(handle, p);
2043 if (status == HCI_SUCCESS) enc_enable = 1;
2045 btm_sec_encrypt_change(handle, status, enc_enable);
2048 static void btu_ble_ll_conn_complete_evt(uint8_t* p, uint16_t evt_len) {
2049 btm_ble_conn_complete(p, evt_len, false);
2051 #if (BLE_PRIVACY_SPT == TRUE)
2052 static void btu_ble_proc_enhanced_conn_cmpl(uint8_t* p, uint16_t evt_len) {
2053 btm_ble_conn_complete(p, evt_len, true);
2057 extern void gatt_notify_conn_update(uint16_t handle, uint16_t interval,
2058 uint16_t latency, uint16_t timeout,
2061 static void btu_ble_ll_conn_param_upd_evt(uint8_t* p, uint16_t evt_len) {
2062 /* LE connection update has completed successfully as a master. */
2063 /* We can enable the update request if the result is a success. */
2064 /* extract the HCI handle first */
2071 STREAM_TO_UINT8(status, p);
2072 STREAM_TO_UINT16(handle, p);
2073 STREAM_TO_UINT16(interval, p);
2074 STREAM_TO_UINT16(latency, p);
2075 STREAM_TO_UINT16(timeout, p);
2077 l2cble_process_conn_update_evt(handle, status, interval, latency, timeout);
2079 gatt_notify_conn_update(handle & 0x0FFF, interval, latency, timeout, status);
2082 static void btu_ble_read_remote_feat_evt(uint8_t* p) {
2083 btm_ble_read_remote_features_complete(p);
2086 static void btu_ble_proc_ltk_req(uint8_t* p) {
2087 uint16_t ediv, handle;
2090 STREAM_TO_UINT16(handle, p);
2092 STREAM_TO_UINT16(ediv, pp);
2093 btm_ble_ltk_request(handle, p, ediv);
2094 /* This is empty until an upper layer cares about returning event */
2097 static void btu_ble_data_length_change_evt(uint8_t* p, uint16_t evt_len) {
2099 uint16_t tx_data_len;
2100 uint16_t rx_data_len;
2102 if (!controller_get_interface()->supports_ble_packet_extension()) {
2103 HCI_TRACE_WARNING("%s, request not supported", __func__);
2107 STREAM_TO_UINT16(handle, p);
2108 STREAM_TO_UINT16(tx_data_len, p);
2109 p += 2; /* Skip the TxTimer */
2110 STREAM_TO_UINT16(rx_data_len, p);
2112 l2cble_process_data_length_change_event(handle, tx_data_len, rx_data_len);
2115 /**********************************************
2116 * End of BLE Events Handler
2117 **********************************************/
2118 #if (BLE_LLT_INCLUDED == TRUE)
2119 static void btu_ble_rc_param_req_evt(uint8_t* p) {
2121 uint16_t int_min, int_max, latency, timeout;
2123 STREAM_TO_UINT16(handle, p);
2124 STREAM_TO_UINT16(int_min, p);
2125 STREAM_TO_UINT16(int_max, p);
2126 STREAM_TO_UINT16(latency, p);
2127 STREAM_TO_UINT16(timeout, p);
2129 l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency,
2132 #endif /* BLE_LLT_INCLUDED */