diff options
Diffstat (limited to 'system/stack')
-rw-r--r-- | system/stack/acl/ble_acl.cc | 4 | ||||
-rw-r--r-- | system/stack/btm/btm_ble.cc | 16 | ||||
-rw-r--r-- | system/stack/btm/btm_ble_bgconn.cc | 19 | ||||
-rw-r--r-- | system/stack/btm/btm_ble_gap.cc | 30 | ||||
-rw-r--r-- | system/stack/btm/btm_ble_int.h | 5 | ||||
-rw-r--r-- | system/stack/btm/btm_ble_privacy.cc | 187 | ||||
-rw-r--r-- | system/stack/gatt/connection_manager.cc | 64 | ||||
-rw-r--r-- | system/stack/gatt/gatt_api.cc | 54 | ||||
-rw-r--r-- | system/stack/gatt/gatt_main.cc | 45 | ||||
-rw-r--r-- | system/stack/gatt/gatt_utils.cc | 2 | ||||
-rw-r--r-- | system/stack/hcic/hciblecmds.cc | 67 | ||||
-rw-r--r-- | system/stack/include/hcimsgs.h | 14 | ||||
-rwxr-xr-x | system/stack/l2cap/l2c_ble.cc | 10 | ||||
-rw-r--r-- | system/stack/rfcomm/port_api.cc | 2 | ||||
-rw-r--r-- | system/stack/smp/smp_act.cc | 9 | ||||
-rw-r--r-- | system/stack/smp/smp_keys.cc | 2 |
16 files changed, 140 insertions, 390 deletions
diff --git a/system/stack/acl/ble_acl.cc b/system/stack/acl/ble_acl.cc index 448dabd12c..a09012a37b 100644 --- a/system/stack/acl/ble_acl.cc +++ b/system/stack/acl/ble_acl.cc @@ -65,8 +65,6 @@ static bool acl_ble_common_connection(const tBLE_BD_ADDR& address_with_type, return false; } - btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); - /* Tell BTM Acl management about the link */ btm_acl_created(address_with_type.bda, handle, role, BT_TRANSPORT_LE); @@ -154,12 +152,10 @@ void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type, if (status != HCI_ERR_ADVERTISING_TIMEOUT) { btm_cb.ble_ctr_cb.set_connection_state_idle(); btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT); - btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true); connection_manager::on_connection_timed_out_from_shim( address_with_type.bda); } else { btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE; - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); } btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, &address_with_type.bda, status); diff --git a/system/stack/btm/btm_ble.cc b/system/stack/btm/btm_ble.cc index 55d7097587..9d313b3ea8 100644 --- a/system/stack/btm/btm_ble.cc +++ b/system/stack/btm/btm_ble.cc @@ -65,7 +65,7 @@ void BTM_SecAddBleDevice(const RawAddress& bd_addr, tBT_DEVICE_TYPE dev_type, return bluetooth::shim::BTM_SecAddBleDevice(bd_addr, dev_type, addr_type); } - BTM_TRACE_DEBUG("%s: dev_type=0x%x", __func__, dev_type); + LOG_DEBUG("dev_type=0x%x", dev_type); tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); if (!p_dev_rec) { @@ -81,27 +81,27 @@ void BTM_SecAddBleDevice(const RawAddress& bd_addr, tBT_DEVICE_TYPE dev_type, p_dev_rec->conn_params.supervision_tout = BTM_BLE_CONN_PARAM_UNDEF; p_dev_rec->conn_params.peripheral_latency = BTM_BLE_CONN_PARAM_UNDEF; - BTM_TRACE_DEBUG("%s: Device added, handle=0x%x, p_dev_rec=%p, bd_addr=%s", - __func__, p_dev_rec->ble_hci_handle, p_dev_rec, - bd_addr.ToString().c_str()); + LOG_DEBUG("Device added, handle=0x%x, p_dev_rec=%p, bd_addr=%s", + p_dev_rec->ble_hci_handle, p_dev_rec, bd_addr.ToString().c_str()); } memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); p_dev_rec->device_type |= dev_type; - if (is_ble_addr_type_known(addr_type)) + if (is_ble_addr_type_known(addr_type)) { p_dev_rec->ble.SetAddressType(addr_type); - else + } else { LOG_WARN( "Please do not update device record from anonymous le advertisement"); + } /* sync up with the Inq Data base*/ tBTM_INQ_INFO* p_info = BTM_InqDbRead(bd_addr); if (p_info) { p_info->results.ble_addr_type = p_dev_rec->ble.AddressType(); p_info->results.device_type = p_dev_rec->device_type; - BTM_TRACE_DEBUG("InqDb device_type =0x%x addr_type=0x%x", - p_info->results.device_type, p_info->results.ble_addr_type); + LOG_DEBUG("InqDb device_type =0x%x addr_type=0x%x", + p_info->results.device_type, p_info->results.ble_addr_type); } } diff --git a/system/stack/btm/btm_ble_bgconn.cc b/system/stack/btm/btm_ble_bgconn.cc index 965e0d08a1..d093aa5a2a 100644 --- a/system/stack/btm/btm_ble_bgconn.cc +++ b/system/stack/btm/btm_ble_bgconn.cc @@ -205,11 +205,9 @@ bool BTM_AcceptlistAdd(const RawAddress& address) { LOG_WARN("Controller does not support Le"); return false; } - - return bluetooth::shim::ACL_AcceptLeConnectionFrom( - convert_to_address_with_type(address, btm_find_dev(address)), - /* is_direct */ false); - + return bluetooth::shim::ACL_AcceptLeConnectionFrom( + convert_to_address_with_type(address, btm_find_dev(address)), + /* is_direct */ false); } /** Removes the device from acceptlist */ @@ -218,11 +216,8 @@ void BTM_AcceptlistRemove(const RawAddress& address) { LOG_WARN("Controller does not support Le"); return; } - - bluetooth::shim::ACL_IgnoreLeConnectionFrom( - convert_to_address_with_type(address, btm_find_dev(address))); - return; - + bluetooth::shim::ACL_IgnoreLeConnectionFrom( + convert_to_address_with_type(address, btm_find_dev(address))); } /** Clear the acceptlist, end any pending acceptlist connections */ @@ -231,7 +226,5 @@ void BTM_AcceptlistClear() { LOG_WARN("Controller does not support Le"); return; } - - bluetooth::shim::ACL_IgnoreAllLeConnections(); - return; + bluetooth::shim::ACL_IgnoreAllLeConnections(); } diff --git a/system/stack/btm/btm_ble_gap.cc b/system/stack/btm/btm_ble_gap.cc index 1365e76f7b..d87962f489 100644 --- a/system/stack/btm/btm_ble_gap.cc +++ b/system/stack/btm/btm_ble_gap.cc @@ -524,10 +524,6 @@ tBTM_STATUS BTM_BleObserve(bool start, uint8_t duration, p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI : p_inq->scan_type; - /* assume observe always not using acceptlist */ - /* enable resolving list */ - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); - btm_send_hci_set_scan_params( p_inq->scan_type, (uint16_t)scan_interval, (uint16_t)scan_window, btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, BTM_BLE_DEFAULT_SFP); @@ -916,12 +912,6 @@ void btm_ble_start_sync_request(uint8_t sid, RawAddress addr, uint16_t skip, address_type = p_i->inq_info.results.ble_addr_type; // Random } btm_random_pseudo_to_identity_addr(&addr, &address_type); - if (address_type & BLE_ADDR_TYPE_ID_BIT) { -#if (BLE_PRIVACY_SPT == TRUE) - LOG_INFO("Enable resolving list"); - btm_ble_enable_resolving_list(BTM_BLE_RL_SCAN); -#endif - } address_type &= ~BLE_ADDR_TYPE_ID_BIT; uint8_t options = 0; uint8_t cte_type = 7; @@ -1111,9 +1101,6 @@ void btm_ble_periodic_adv_sync_established(uint8_t status, uint16_t sync_handle, tBLE_ADDR_TYPE ble_addr_type = to_ble_addr_type(address_type); if (ble_addr_type & BLE_ADDR_TYPE_ID_BIT) { btm_identity_addr_to_random_pseudo(&bda, &ble_addr_type, true); -#if (BLE_PRIVACY_SPT == TRUE) - btm_ble_disable_resolving_list(BTM_BLE_RL_SCAN, true); -#endif } int index = btm_ble_get_psync_index(adv_sid, bda); if (index == MAX_SYNC_TRANSACTION) { @@ -1531,16 +1518,12 @@ static uint8_t btm_set_conn_mode_adv_init_addr( /* only do so for bonded device */ if ((p_dev_rec = btm_find_or_alloc_dev(p_cb->direct_bda.bda)) != NULL && p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) { - btm_ble_enable_resolving_list(BTM_BLE_RL_ADV); p_peer_addr_ptr = p_dev_rec->ble.identity_address_with_type.bda; *p_peer_addr_type = p_dev_rec->ble.identity_address_with_type.type; *p_own_addr_type = BLE_ADDR_RANDOM_ID; return evt_type; } /* otherwise fall though as normal directed adv */ - else { - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); - } } /* direct adv mode does not have privacy, if privacy is not enabled */ *p_peer_addr_type = p_cb->direct_bda.type; @@ -1840,8 +1823,6 @@ tBTM_STATUS btm_ble_set_discoverability(uint16_t combined_mode) { /* start initial GAP mode adv timer */ alarm_set_on_mloop(p_cb->fast_adv_timer, BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, btm_ble_fast_adv_timer_timeout, NULL); - } else { - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); } /* set up stop advertising timer */ @@ -1925,8 +1906,6 @@ tBTM_STATUS btm_ble_set_connectability(uint16_t combined_mode) { /* start initial GAP mode adv timer */ alarm_set_on_mloop(p_cb->fast_adv_timer, BTM_BLE_GAP_FAST_ADV_TIMEOUT_MS, btm_ble_fast_adv_timer_timeout, NULL); - } else { - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true); } return status; } @@ -2028,8 +2007,6 @@ tBTM_STATUS btm_ble_start_inquiry(uint8_t duration) { BTM_BLE_SCAN_MODE_ACTI, BTM_BLE_LOW_LATENCY_SCAN_INT, BTM_BLE_LOW_LATENCY_SCAN_WIN, btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, SP_ADV_ALL); - /* enable IRK list */ - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); p_ble_cb->inq_var.scan_type = BTM_BLE_SCAN_MODE_ACTI; btm_ble_start_scan(); } else if ((p_ble_cb->inq_var.scan_interval != @@ -3073,13 +3050,6 @@ tBTM_STATUS btm_ble_start_adv(void) { if (!btm_ble_adv_states_operation(btm_ble_topology_check, p_cb->evt_type)) return BTM_WRONG_MODE; - /* To relax resolving list, always have resolving list enabled, unless - * directed adv */ - if (p_cb->evt_type != BTM_BLE_CONNECT_LO_DUTY_DIR_EVT && - p_cb->evt_type != BTM_BLE_CONNECT_DIR_EVT) - /* enable resolving list is desired */ - btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_ADV); - btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_ENABLE); p_cb->adv_mode = BTM_BLE_ADV_ENABLE; btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); diff --git a/system/stack/btm/btm_ble_int.h b/system/stack/btm/btm_ble_int.h index 8ca11f7a8c..25ab518dfb 100644 --- a/system/stack/btm/btm_ble_int.h +++ b/system/stack/btm/btm_ble_int.h @@ -121,12 +121,7 @@ extern bool btm_ble_addr_resolvable(const RawAddress& rpa, tBTM_SEC_DEV_REC* p_dev_rec); extern void btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC& p_dev_rec); -extern bool btm_ble_resolving_list_load_dev( - tBTM_SEC_DEV_REC* p_dev_rec); // DEPRECATED extern void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC* p_dev_rec); -extern void btm_ble_enable_resolving_list(uint8_t); -extern bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume); -extern void btm_ble_enable_resolving_list_for_platform(uint8_t rl_mask); extern void btm_ble_resolving_list_init(uint8_t max_irk_list_sz); extern void btm_ble_adv_init(void); diff --git a/system/stack/btm/btm_ble_privacy.cc b/system/stack/btm/btm_ble_privacy.cc index f5e2b78f3f..0a3035dadf 100644 --- a/system/stack/btm/btm_ble_privacy.cc +++ b/system/stack/btm/btm_ble_privacy.cc @@ -503,131 +503,6 @@ bool btm_ble_read_resolving_list_entry(tBTM_SEC_DEV_REC* p_dev_rec) { return true; } -/******************************************************************************* - * - * Function btm_ble_disable_resolving_list - * - * Description Disable LE Address resolution - * - * Returns none - * - ******************************************************************************/ -bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume) { - LOG_DEBUG("GD automatically disables Address Resolution list"); - return true; -} - -/******************************************************************************* - * - * Function btm_ble_resolving_list_load_dev - * - * Description This function adds a device which is using RPA into the - * acceptlist. - * - * Parameters pointer to device security record - * - * Returns true if device added, otherwise falase. - * - ******************************************************************************/ -bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) { - ASSERT_LOG(false, - "API is disabled...use signature <void(tBTM_SEC_DEV_REC&)>"); - - const uint8_t rl_state = btm_cb.ble_ctr_cb.rl_state; - - if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) { - BTM_TRACE_DEBUG( - "%s: Controller does not support RPA offloading or privacy 1.2", - __func__); - return false; - } - - BTM_TRACE_DEBUG("%s: btm_cb.ble_ctr_cb.privacy_mode = %d", __func__, - btm_cb.ble_ctr_cb.privacy_mode); - - if (!p_dev_rec) { - BTM_TRACE_DEBUG("%s: No device security record", __func__); - return false; - } - - /* only add RPA enabled device into resolving list */ - if (controller_get_interface()->supports_ble_privacy()) { - if ((p_dev_rec->ble.key_type & (BTM_LE_KEY_PID | BTM_LE_KEY_LID)) == 0) { - BTM_TRACE_DEBUG("%s: privacy 1.2: Device not a RPA enabled device", - __func__); - return false; - } - } else if ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) == 0) { - BTM_TRACE_DEBUG("%s: RPA offloading: Device not a RPA enabled device", - __func__); - return false; - } - - if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) || - btm_ble_brcm_find_resolving_pending_entry(p_dev_rec->bd_addr, - BTM_BLE_META_ADD_IRK_ENTRY)) { - BTM_TRACE_ERROR("%s: Device already in Resolving list", __func__); - return true; - } - - if (btm_cb.ble_ctr_cb.resolving_list_avail_size == 0) { - return false; - } - - if (rl_state && !btm_ble_disable_resolving_list(rl_state, false)) { - return false; - } - - if (controller_get_interface()->supports_ble_privacy()) { - const Octet16& peer_irk = p_dev_rec->ble.keys.irk; - const Octet16& local_irk = btm_cb.devcb.id_keys.irk; - - if (p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) { - p_dev_rec->ble.identity_address_with_type.bda = p_dev_rec->bd_addr; - p_dev_rec->ble.identity_address_with_type.type = - p_dev_rec->ble.AddressType(); - } - - BTM_TRACE_DEBUG( - "%s: adding device %s to controller resolving list", __func__, - p_dev_rec->ble.identity_address_with_type.bda.ToString().c_str()); - - // use identical IRK for now - btsnd_hcic_ble_add_device_resolving_list( - p_dev_rec->ble.identity_address_with_type.type, - p_dev_rec->ble.identity_address_with_type.bda, peer_irk, local_irk); - - if (controller_get_interface()->supports_ble_set_privacy_mode()) { - BTM_TRACE_DEBUG("%s: adding device privacy mode", __func__); - btsnd_hcic_ble_set_privacy_mode( - p_dev_rec->ble.identity_address_with_type.type, - p_dev_rec->ble.identity_address_with_type.bda, 0x01); - } - } else { - uint8_t param[40] = {0}; - uint8_t* p = param; - - UINT8_TO_STREAM(p, BTM_BLE_META_ADD_IRK_ENTRY); - ARRAY_TO_STREAM(p, p_dev_rec->ble.keys.irk, OCTET16_LEN); - UINT8_TO_STREAM(p, p_dev_rec->ble.identity_address_with_type.type); - BDADDR_TO_STREAM(p, p_dev_rec->ble.identity_address_with_type.bda); - - BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_META_ADD_IRK_LEN, - param, btm_ble_resolving_list_vsc_op_cmpl); - } - - btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr, - BTM_BLE_META_ADD_IRK_ENTRY); - - /* if resolving list has been turned on, re-enable it */ - if (rl_state) - btm_ble_enable_resolving_list(rl_state); - else - btm_ble_enable_resolving_list(BTM_BLE_RL_INIT); - - return true; -} - static void btm_ble_ble_unsupported_resolving_list_load_dev( tBTM_SEC_DEV_REC* p_dev_rec) { LOG_INFO("Controller does not support BLE privacy"); @@ -707,12 +582,7 @@ void btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC& dev_rec) { * ******************************************************************************/ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC* p_dev_rec) { - uint8_t rl_mask = btm_cb.ble_ctr_cb.rl_state; - BTM_TRACE_EVENT("%s", __func__); - if (rl_mask) { - if (!btm_ble_disable_resolving_list(rl_mask, false)) return; - } if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && !btm_ble_brcm_find_resolving_pending_entry( @@ -722,63 +592,6 @@ void btm_ble_resolving_list_remove_dev(tBTM_SEC_DEV_REC* p_dev_rec) { } else { BTM_TRACE_DEBUG("Device not in resolving list"); } - - /* if resolving list has been turned on, re-enable it */ - if (rl_mask) btm_ble_enable_resolving_list(rl_mask); -} - -/******************************************************************************* - * - * Function btm_ble_enable_resolving_list - * - * Description enable LE resolve address list - * - * Returns none - * - ******************************************************************************/ -void btm_ble_enable_resolving_list(uint8_t rl_mask) { - LOG_DEBUG("GD automatically enables Address Resolution list"); -} - -static bool is_on_resolving_list(void* data, void* context) { - tBTM_SEC_DEV_REC* p_dev = static_cast<tBTM_SEC_DEV_REC*>(data); - if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && - (p_dev->ble.in_controller_list & BTM_ACCEPTLIST_BIT)) - return false; - - return true; -} - -/******************************************************************************* - * - * Function btm_ble_enable_resolving_list_for_platform - * - * Description enable/disable resolving list feature depending on if any - * resolving list is empty and acceptlist is involoved in the - * operation. - * - * Returns none - * - ******************************************************************************/ -void btm_ble_enable_resolving_list_for_platform(uint8_t rl_mask) { - /* if controller does not support, skip */ - if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) - return; - - if (btm_cb.ble_ctr_cb.wl_state == BTM_BLE_WL_IDLE) { - if (controller_get_interface()->get_ble_resolving_list_max_size() > - btm_cb.ble_ctr_cb.resolving_list_avail_size) - btm_ble_enable_resolving_list(rl_mask); - else - btm_ble_disable_resolving_list(rl_mask, true); - return; - } - - list_node_t* n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL); - if (n) - btm_ble_enable_resolving_list(rl_mask); - else - btm_ble_disable_resolving_list(rl_mask, true); } /******************************************************************************* diff --git a/system/stack/gatt/connection_manager.cc b/system/stack/gatt/connection_manager.cc index b2499b4949..c6052c236c 100644 --- a/system/stack/gatt/connection_manager.cc +++ b/system/stack/gatt/connection_manager.cc @@ -86,6 +86,7 @@ bool anyone_connecting( /** background connection device from the list. Returns pointer to the device * record, or nullptr if not found */ std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& address) { + LOG_DEBUG("address=%s", address.ToString().c_str()); auto it = bgconn_dev.find(address); return (it != bgconn_dev.end()) ? it->second.doing_bg_conn : std::set<tAPP_ID>(); @@ -94,6 +95,8 @@ std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& address) { /** Add a device from the background connection list. Returns true if device * added to the list, or already in list, false otherwise */ bool background_connect_add(uint8_t app_id, const RawAddress& address) { + LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), + address.ToString().c_str()); if (bluetooth::shim::is_gd_l2cap_enabled()) { return L2CA_ConnectFixedChnl(L2CAP_ATT_CID, address); } @@ -103,23 +106,30 @@ bool background_connect_add(uint8_t app_id, const RawAddress& address) { if (it != bgconn_dev.end()) { // device already in the acceptlist, just add interested app to the list if (it->second.doing_bg_conn.count(app_id)) { - LOG(INFO) << "App id=" << loghex(app_id) - << "already doing background connection to " << address; + LOG_DEBUG("app_id=%d, already doing background connection to address=%s", + static_cast<int>(app_id), address.ToString().c_str()); return true; } // Already in acceptlist ? if (anyone_connecting(it)) { + LOG_DEBUG("app_id=%d, address=%s, already in accept list", + static_cast<int>(app_id), address.ToString().c_str()); in_acceptlist = true; } } if (!in_acceptlist) { // the device is not in the acceptlist - if (!BTM_AcceptlistAdd(address)) return false; + if (!BTM_AcceptlistAdd(address)) { + LOG_WARN("Failed to add device %s to accept list for app %d", + address.ToString().c_str(), static_cast<int>(app_id)); + return false; + } } - // create endtry for address, and insert app_id. + // create entry for address, and insert app_id. + // new tAPPS_CONNECTING will be default constructed if not exist bgconn_dev[address].doing_bg_conn.insert(app_id); return true; } @@ -127,8 +137,12 @@ bool background_connect_add(uint8_t app_id, const RawAddress& address) { /** Removes all registrations for connection for given device. * Returns true if anything was removed, false otherwise */ bool remove_unconditional(const RawAddress& address) { + LOG_DEBUG("address=%s", address.ToString().c_str()); auto it = bgconn_dev.find(address); - if (it == bgconn_dev.end()) return false; + if (it == bgconn_dev.end()) { + LOG_WARN("address %s is not found", address.ToString().c_str()); + return false; + } BTM_AcceptlistRemove(address); bgconn_dev.erase(it); @@ -140,25 +154,41 @@ bool remove_unconditional(const RawAddress& address) { * shim purposes. * Returns true if anything was removed, false otherwise */ bool remove_unconditional_from_shim(const RawAddress& address) { + LOG_DEBUG("address=%s", address.ToString().c_str()); auto it = bgconn_dev.find(address); - if (it == bgconn_dev.end()) return false; + if (it == bgconn_dev.end()) { + LOG_WARN("address %s is not found", address.ToString().c_str()); + return false; + } bgconn_dev.erase(it); return true; } /** Remove device from the background connection device list or listening to - * advertising list. Returns true if device was on the list and was succesfully - * removed */ + * advertising list. Returns true if device was on the list and was + * successfully removed */ bool background_connect_remove(uint8_t app_id, const RawAddress& address) { - VLOG(2) << __func__; + LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), + address.ToString().c_str()); auto it = bgconn_dev.find(address); - if (it == bgconn_dev.end()) return false; + if (it == bgconn_dev.end()) { + LOG_WARN("address %s is not found", address.ToString().c_str()); + return false; + } - if (!it->second.doing_bg_conn.erase(app_id)) return false; + if (!it->second.doing_bg_conn.erase(app_id)) { + LOG_WARN("Failed to remove background connection app %d for address %s", + static_cast<int>(app_id), address.ToString().c_str()); + return false; + } - if (anyone_connecting(it)) return true; + if (anyone_connecting(it)) { + LOG_DEBUG("some device is still connecting, app_id=%d, address=%s", + static_cast<int>(app_id), address.ToString().c_str()); + return true; + } - // no more apps interested - remove from acceptlist and delete record + // no more apps interested - remove from accept list and delete record BTM_AcceptlistRemove(address); bgconn_dev.erase(it); return true; @@ -166,6 +196,7 @@ bool background_connect_remove(uint8_t app_id, const RawAddress& address) { /** deregister all related background connetion device. */ void on_app_deregistered(uint8_t app_id) { + LOG_DEBUG("app_id=%d", static_cast<int>(app_id)); auto it = bgconn_dev.begin(); auto end = bgconn_dev.end(); /* update the BG conn device list */ @@ -186,6 +217,7 @@ void on_app_deregistered(uint8_t app_id) { static void remove_all_clients_with_pending_connections( const RawAddress& address) { + LOG_DEBUG("address=%s", address.ToString().c_str()); auto it = bgconn_dev.find(address); while (it != bgconn_dev.end() && !it->second.doing_direct_conn.empty()) { uint8_t app_id = it->second.doing_direct_conn.begin()->first; @@ -212,6 +244,8 @@ void reset(bool after_reset) { } void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) { + LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), + address.ToString().c_str()); on_connection_timed_out(app_id, address); // TODO: this would free the timer, from within the timer callback, which is @@ -222,6 +256,8 @@ void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) { /** Add a device to the direcgt connection list. Returns true if device * added to the list, false otherwise */ bool direct_connect_add(uint8_t app_id, const RawAddress& address) { + LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), + address.ToString().c_str()); if (bluetooth::shim::is_gd_l2cap_enabled()) { return L2CA_ConnectFixedChnl(L2CAP_ATT_CID, address); } @@ -274,6 +310,8 @@ static bool any_direct_connect_left() { } bool direct_connect_remove(uint8_t app_id, const RawAddress& address) { + LOG_DEBUG("app_id=%d, address=%s", static_cast<int>(app_id), + address.ToString().c_str()); auto it = bgconn_dev.find(address); if (it == bgconn_dev.end()) { LOG_WARN("Unable to find background connection to remove"); diff --git a/system/stack/gatt/gatt_api.cc b/system/stack/gatt/gatt_api.cc index ded621b2f6..b55e62563e 100644 --- a/system/stack/gatt/gatt_api.cc +++ b/system/stack/gatt/gatt_api.cc @@ -961,16 +961,17 @@ void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout, bool status = false; tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); - if (p_tcb != NULL) { + if (p_tcb != nullptr) { status = L2CA_SetLeGattTimeout(bd_addr, idle_tout); - if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) + if (idle_tout == GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP) { L2CA_SetIdleTimeoutByBdAddr( p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, BT_TRANSPORT_LE); + } } - VLOG(1) << __func__ << " idle_tout=" << idle_tout << ", status=" << +status - << " (1-OK 0-not performed)"; + LOG_INFO("idle_timeout=%d, status=%d, (1-OK 0-not performed)", idle_tout, + +status); } /******************************************************************************* @@ -1162,22 +1163,18 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct, /* Make sure app is registered */ tGATT_REG* p_reg = gatt_get_regcb(gatt_if); if (!p_reg) { - LOG(ERROR) << __func__ - << ": Unable to find registered app gatt_if=" << +gatt_if; + LOG_ERROR("Unable to find registered app gatt_if=%d", +gatt_if); return false; } if (!is_direct && transport != BT_TRANSPORT_LE) { - LOG(ERROR) << __func__ - << ": Unsupported transport for background connection gatt_if=" - << +gatt_if; + LOG_WARN("Unsupported transport for background connection gatt_if=%d", + +gatt_if); return false; } if (opportunistic) { - LOG(INFO) << __func__ - << ": Registered for opportunistic connection gatt_if=" - << +gatt_if; + LOG_INFO("Registered for opportunistic connection gatt_if=%d", +gatt_if); return true; } @@ -1193,20 +1190,27 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, bool is_direct, // RPA can rotate, causing address to "expire" in the background // connection list. RPA is allowed for direct connect, as such request // times out after 30 seconds - LOG(INFO) << __func__ - << ": Unable to add RPA to background connection gatt_if=" - << +gatt_if; - ret = true; + LOG_WARN("Unable to add RPA %s to background connection gatt_if=%d", + bd_addr.ToString().c_str(), +gatt_if); + ret = false; } else { - LOG_DEBUG("Adding to acceptlist device:%s", PRIVATE_ADDRESS(bd_addr)); + LOG_DEBUG("Adding to accept list device:%s", PRIVATE_ADDRESS(bd_addr)); ret = connection_manager::background_connect_add(gatt_if, bd_addr); } } tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bd_addr, transport); // background connections don't necessarily create tcb - if (p_tcb && ret) + if (p_tcb && ret) { gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, !is_direct); + } else { + if (p_tcb == nullptr) { + LOG_DEBUG("p_tcb is null"); + } + if (!ret) { + LOG_DEBUG("Previous step returned false"); + } + } return ret; } @@ -1239,10 +1243,11 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr, return false; } - if (is_direct) + if (is_direct) { return gatt_cancel_open(gatt_if, bd_addr); - else + } else { return gatt_auto_connect_dev_remove(p_reg->gatt_if, bd_addr); + } } VLOG(1) << " unconditional"; @@ -1283,11 +1288,14 @@ bool GATT_CancelConnect(tGATT_IF gatt_if, const RawAddress& bd_addr, * ******************************************************************************/ tGATT_STATUS GATT_Disconnect(uint16_t conn_id) { - LOG(INFO) << __func__ << " conn_id=" << loghex(conn_id); + LOG_INFO("conn_id=%d", +conn_id); uint8_t tcb_idx = GATT_GET_TCB_IDX(conn_id); tGATT_TCB* p_tcb = gatt_get_tcb_by_idx(tcb_idx); - if (!p_tcb) return GATT_ILLEGAL_PARAMETER; + if (!p_tcb) { + LOG_WARN("Cannot find TCB for connection %d", conn_id); + return GATT_ILLEGAL_PARAMETER; + } tGATT_IF gatt_if = GATT_GET_GATT_IF(conn_id); gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true); @@ -1351,6 +1359,6 @@ bool GATT_GetConnIdIfConnected(tGATT_IF gatt_if, const RawAddress& bd_addr, status = true; } - VLOG(1) << __func__ << " status= " << +status; + LOG_DEBUG("status=%d", status); return status; } diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc index 6b61708209..f2d0637b7a 100644 --- a/system/stack/gatt/gatt_main.cc +++ b/system/stack/gatt/gatt_main.cc @@ -290,26 +290,27 @@ bool gatt_disconnect(tGATT_TCB* p_tcb) { ******************************************************************************/ bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb, bool is_add) { + LOG_DEBUG("gatt_if=%d, is_add=%d, peer_bda=%s", +gatt_if, is_add, + p_tcb->peer_bda.ToString().c_str()); auto& holders = p_tcb->app_hold_link; - VLOG(1) << __func__; if (is_add) { auto ret = holders.insert(gatt_if); if (ret.second) { - VLOG(1) << "added gatt_if=" << +gatt_if; + LOG_DEBUG("added gatt_if=%d", +gatt_if); } else { - VLOG(1) << "attempt to add already existing gatt_if=" << +gatt_if; + LOG_DEBUG("attempt to add already existing gatt_if=%d", +gatt_if); } return true; } //! is_add if (!holders.erase(gatt_if)) { - VLOG(1) << "attempt to remove nonexisting gatt_if=" << +gatt_if; + LOG_WARN("attempt to remove non-existing gatt_if=%d", +gatt_if); return false; } - VLOG(1) << "removed gatt_if=" << +gatt_if; + LOG_INFO("removed gatt_if=%d", +gatt_if); return true; } @@ -326,16 +327,23 @@ bool gatt_update_app_hold_link_status(tGATT_IF gatt_if, tGATT_TCB* p_tcb, ******************************************************************************/ void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb, bool is_add, bool check_acl_link) { - VLOG(1) << StringPrintf("%s: is_add=%d chk_link=%d", __func__, is_add, - check_acl_link); + LOG_DEBUG("gatt_if=%d, is_add=%d chk_link=%d", +gatt_if, is_add, + check_acl_link); - if (!p_tcb) return; + if (!p_tcb) { + LOG_WARN("p_tcb is null"); + return; + } // If we make no modification, i.e. kill app that was never connected to a // device, skip updating the device state. - if (!gatt_update_app_hold_link_status(gatt_if, p_tcb, is_add)) return; + if (!gatt_update_app_hold_link_status(gatt_if, p_tcb, is_add)) { + LOG_INFO("App status is not updated for gatt_if=%d", +gatt_if); + return; + } if (!check_acl_link) { + LOG_INFO("check_acl_link is false, no need to check"); return; } @@ -345,28 +353,37 @@ void gatt_update_app_use_link_flag(tGATT_IF gatt_if, tGATT_TCB* p_tcb, if (is_add) { if (p_tcb->att_lcid == L2CAP_ATT_CID && is_valid_handle) { - VLOG(1) << "disable link idle timer"; + LOG_INFO("disable link idle timer for %s", + p_tcb->peer_bda.ToString().c_str()); /* acl link is connected disable the idle timeout */ GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_NO_IDLE_TIMEOUT, p_tcb->transport); + } else { + LOG_INFO("invalid handle %d or dynamic CID %d", is_valid_handle, + p_tcb->att_lcid); } } else { if (p_tcb->app_hold_link.empty()) { // acl link is connected but no application needs to use the link if (p_tcb->att_lcid == L2CAP_ATT_CID && is_valid_handle) { - /* Drop EATT before closing ATT */ EattExtension::GetInstance()->Disconnect(p_tcb->peer_bda); /* for fixed channel, set the timeout value to GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP seconds */ - VLOG(1) << " start link idle timer = " - << GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP << " sec"; + LOG_INFO( + "GATT fixed channel is no longer useful, start link idle timer for " + "%d seconds", + GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP); GATT_SetIdleTimeout(p_tcb->peer_bda, GATT_LINK_IDLE_TIMEOUT_WHEN_NO_APP, p_tcb->transport); - } else + } else { // disconnect the dynamic channel + LOG_INFO("disconnect GATT dynamic channel"); gatt_disconnect(p_tcb); + } + } else { + LOG_INFO("is_add=false, but some app is still using the ACL link"); } } } diff --git a/system/stack/gatt/gatt_utils.cc b/system/stack/gatt/gatt_utils.cc index 338b277aca..11a0f85eb6 100644 --- a/system/stack/gatt/gatt_utils.cc +++ b/system/stack/gatt/gatt_utils.cc @@ -409,7 +409,7 @@ tGATT_TCB* gatt_get_tcb_by_idx(uint8_t tcb_idx) { ******************************************************************************/ tGATT_TCB* gatt_find_tcb_by_addr(const RawAddress& bda, tBT_TRANSPORT transport) { - tGATT_TCB* p_tcb = NULL; + tGATT_TCB* p_tcb = nullptr; uint8_t i = 0; i = gatt_find_i_tcb_by_addr(bda, transport); diff --git a/system/stack/hcic/hciblecmds.cc b/system/stack/hcic/hciblecmds.cc index 63742022ab..25e66d6978 100644 --- a/system/stack/hcic/hciblecmds.cc +++ b/system/stack/hcic/hciblecmds.cc @@ -593,73 +593,6 @@ void btsnd_hcic_ble_rc_param_req_neg_reply(uint16_t handle, uint8_t reason) { btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); } -void btsnd_hcic_ble_add_device_resolving_list(uint8_t addr_type_peer, - const RawAddress& bda_peer, - const Octet16& irk_peer, - const Octet16& irk_local) { - BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t* pp = (uint8_t*)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST; - p->offset = 0; - - UINT16_TO_STREAM(pp, HCI_BLE_ADD_DEV_RESOLVING_LIST); - UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_ADD_DEV_RESOLVING_LIST); - UINT8_TO_STREAM(pp, addr_type_peer); - BDADDR_TO_STREAM(pp, bda_peer); - ARRAY_TO_STREAM(pp, irk_peer.data(), HCIC_BLE_ENCRYPT_KEY_SIZE); - ARRAY_TO_STREAM(pp, irk_local.data(), HCIC_BLE_ENCRYPT_KEY_SIZE); - - btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); -} - -void btsnd_hcic_ble_rm_device_resolving_list(uint8_t addr_type_peer, - const RawAddress& bda_peer) { - BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t* pp = (uint8_t*)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST; - p->offset = 0; - - UINT16_TO_STREAM(pp, HCI_BLE_RM_DEV_RESOLVING_LIST); - UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_RM_DEV_RESOLVING_LIST); - UINT8_TO_STREAM(pp, addr_type_peer); - BDADDR_TO_STREAM(pp, bda_peer); - - btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); -} - -void btsnd_hcic_ble_set_privacy_mode(uint8_t addr_type_peer, - const RawAddress& bda_peer, - uint8_t privacy_type) { - BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t* pp = (uint8_t*)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE; - p->offset = 0; - - UINT16_TO_STREAM(pp, HCI_BLE_SET_PRIVACY_MODE); - UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_PRIVACY_MODE); - UINT8_TO_STREAM(pp, addr_type_peer); - BDADDR_TO_STREAM(pp, bda_peer); - UINT8_TO_STREAM(pp, privacy_type); - - btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); -} - -void btsnd_hcic_ble_clear_resolving_list(void) { - BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); - uint8_t* pp = (uint8_t*)(p + 1); - - p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST; - p->offset = 0; - - UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_RESOLVING_LIST); - UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_CLEAR_RESOLVING_LIST); - - btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); -} - void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer, const RawAddress& bda_peer) { BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE); diff --git a/system/stack/include/hcimsgs.h b/system/stack/include/hcimsgs.h index d35944a66c..6fe70a3e69 100644 --- a/system/stack/include/hcimsgs.h +++ b/system/stack/include/hcimsgs.h @@ -463,11 +463,6 @@ extern void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time); -extern void btsnd_hcic_ble_add_device_resolving_list(uint8_t addr_type_peer, - const RawAddress& bda_peer, - const Octet16& irk_peer, - const Octet16& irk_local); - struct scanning_phy_cfg { uint8_t scan_type; uint16_t scan_int; @@ -501,15 +496,6 @@ extern void btsnd_hcic_ble_ext_create_conn(uint8_t init_filter_policy, uint8_t initiating_phys, EXT_CONN_PHY_CFG* phy_cfg); -extern void btsnd_hcic_ble_rm_device_resolving_list( - tBLE_ADDR_TYPE addr_type_peer, const RawAddress& bda_peer); - -extern void btsnd_hcic_ble_set_privacy_mode(tBLE_ADDR_TYPE addr_type_peer, - const RawAddress& bda_peer, - uint8_t privacy_type); - -extern void btsnd_hcic_ble_clear_resolving_list(void); - extern void btsnd_hcic_ble_read_resolvable_addr_peer( uint8_t addr_type_peer, const RawAddress& bda_peer); diff --git a/system/stack/l2cap/l2c_ble.cc b/system/stack/l2cap/l2c_ble.cc index e3ce2c93b9..5ab208ced3 100755 --- a/system/stack/l2cap/l2c_ble.cc +++ b/system/stack/l2cap/l2c_ble.cc @@ -26,6 +26,7 @@ #include <base/logging.h> #include <base/strings/stringprintf.h> +#include <log/log.h> #include "bt_target.h" #include "bta/include/bta_hearing_aid_api.h" @@ -522,6 +523,15 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { /* Check how many channels remote side wants. */ num_of_channels = (p_pkt_end - p) / sizeof(uint16_t); + if (num_of_channels > L2CAP_CREDIT_BASED_MAX_CIDS) { + android_errorWriteLog(0x534e4554, "232256974"); + LOG_WARN("L2CAP - invalid number of channels requested: %d", + num_of_channels); + l2cu_reject_credit_based_conn_req(p_lcb, id, + L2CAP_CREDIT_BASED_MAX_CIDS, + L2CAP_LE_RESULT_INVALID_PARAMETERS); + return; + } LOG_DEBUG( "Recv L2CAP_CMD_CREDIT_BASED_CONN_REQ with " diff --git a/system/stack/rfcomm/port_api.cc b/system/stack/rfcomm/port_api.cc index 56b0fd1d0f..cca0f05310 100644 --- a/system/stack/rfcomm/port_api.cc +++ b/system/stack/rfcomm/port_api.cc @@ -516,7 +516,7 @@ bool PORT_IsOpening(RawAddress* bd_addr) { } LOG_INFO("RFC_MX_STATE_CONNECTED, found_port=%d, tRFC_PORT_STATE=%d", - found_port, p_port->rfc.state); + found_port, p_port != nullptr ? p_port->rfc.state : 0); if ((!found_port) || (found_port && (p_port->rfc.state < RFC_STATE_OPENED))) { /* Port is not established yet. */ diff --git a/system/stack/smp/smp_act.cc b/system/stack/smp/smp_act.cc index 7ec7c63598..6d8f007c72 100644 --- a/system/stack/smp/smp_act.cc +++ b/system/stack/smp/smp_act.cc @@ -902,15 +902,6 @@ void smp_br_check_authorization_request(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) { } SMP_TRACE_DEBUG("%s: use h7 = %d", __func__, p_cb->key_derivation_h7_used); - /* SMP over BR/EDR should always be used with CTKD, so derive LTK from - * LK before receiving keys */ - if ((p_cb->role == HCI_ROLE_CENTRAL && - (p_cb->local_i_key & SMP_SEC_KEY_TYPE_ENC)) || - (p_cb->role == HCI_ROLE_PERIPHERAL && - (p_cb->local_r_key & SMP_SEC_KEY_TYPE_ENC))) { - smp_generate_ltk(p_cb, p_data); - } - SMP_TRACE_DEBUG( "%s rcvs upgrades: i_keys=0x%x r_keys=0x%x (i-initiator r-responder)", __func__, p_cb->local_i_key, p_cb->local_r_key); diff --git a/system/stack/smp/smp_keys.cc b/system/stack/smp/smp_keys.cc index 8add0a9546..ac9f67423f 100644 --- a/system/stack/smp/smp_keys.cc +++ b/system/stack/smp/smp_keys.cc @@ -533,7 +533,7 @@ static void smp_generate_ltk_cont(uint16_t div, tSMP_CB* p_cb) { void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) { SMP_TRACE_DEBUG("%s", __func__); - if (p_cb->smp_over_br) { + if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) { smp_br_process_link_key(p_cb, NULL); return; } else if (p_cb->le_secure_connections_mode_is_used) { |