OSDN Git Service

BLE: Updating the WL if addr_type is not matched for same BDaddr
authorJanardhana Rao Bokka <quic_jbokka@quicinc.com>
Tue, 10 Sep 2019 04:31:16 +0000 (10:01 +0530)
committerJakub Pawlowski <jpawlowski@google.com>
Wed, 11 Sep 2019 06:33:36 +0000 (08:33 +0200)
Issue:
Connection is not happening with same remote device after BT
reset.

Steps to Repro:
1. Scan and connect to remote device with "Random" address
2. Toggle BT OFF and ON
3. Without scanning, App tries to connect to remote device and
device gets added as default "Public" addr_type in WL
4. Connection doesn't go through (as expected) since remote device
has "Random" address
5. App cancels the attempt or 30 sec direct connection timeout
happens. The device is marked for removal
6. App scans for the device and the correct addr_type (Random)
is now in the inquiry database in stack
7. App initiates connection for the device but the connection
attempt still goes with "Public" address type and hence never
succeeds.

RootCause:
At step 5, stack just marks the device to be removed from whitelist
(pending_removal) but doesn't actually remove it from Controller
until the next WL connection is needed. Later in step 7, when the
WL connection is needed from the App, stack attempts to add the
device to the whitelist, but realizes that the device is already in
the Controller whitelist and hence doesn't do remove and add.
There is no check to see if the device in Controller's WL is with
correct addr_type.

Fix:
When checking for remote addr that needs to be added/removed
from WL, also take into the account the remote addr_type.

Test:
Tested with the fix multiple times. Issue not seen with this fix.

Bug: 140085561
Change-Id: I415b5fa29800b975c2ebcbf95b36cf8879841b3e

stack/btm/btm_ble_bgconn.cc

index 73256c8..3af63f4 100644 (file)
@@ -39,6 +39,7 @@ extern void btm_send_hci_create_connection(
     uint16_t conn_timeout, uint16_t min_ce_len, uint16_t max_ce_len,
     uint8_t phy);
 extern void btm_ble_create_conn_cancel();
+void wl_remove_complete(uint8_t* p_data, uint16_t /* evt_len */);
 
 // Unfortunately (for now?) we have to maintain a copy of the device whitelist
 // on the host to determine if a device is pending to be connected or not. This
@@ -72,7 +73,14 @@ static void background_connection_add(uint8_t addr_type,
         BackgroundConnection{address, addr_type, false, 0, false};
   } else {
     BackgroundConnection* connection = &map_iter->second;
-    connection->addr_type = addr_type;
+    if (addr_type != connection->addr_type) {
+      LOG(INFO) << __func__ << " Addr type mismatch " << address;
+      btsnd_hcic_ble_remove_from_white_list(
+        connection->addr_type_in_wl, connection->address,
+        base::Bind(&wl_remove_complete));
+      connection->addr_type = addr_type;
+      connection->in_controller_wl = false;
+    }
     connection->pending_removal = false;
   }
 }