microbit: BUGFIX supporting repairing of the same device #2829

Re-pairing the same BLE device under SoftDevice 8.0 Nordic SDK 10 appears to
add a second entry to the bonding table when private resolvable addresses are
used by the central device. This adversely affects whitelisting, as only the
first added matching entry will be succesfully added to the whitelist. i.e. A
central device will no longer be able to connect to a micro:bit after pairing
a second time as the older bond will take prescedence.

Althoguh reported to Nordic, a long term fix is not immediately forthcoming.
This patch applies a workaround, by simply reversing the order of the
whitelist before use. As the list is maintained in the order of insertion,
reversing the list guarantees that the entry added to the whitelist will be
the most recently bonded one for any given peer.
This commit is contained in:
Joe Finney 2016-02-12 18:54:19 +00:00
parent 30ec004dc7
commit 6900bd8415

View file

@ -267,11 +267,21 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
// Configure a whitelist to filter all connection requetss from unbonded devices.
// Most BLE stacks only permit one connection at a time, so this prevents denial of service attacks.
BLEProtocol::Address_t bondedAddresses[MICROBIT_BLE_MAXIMUM_BONDS];
BLEProtocol::Address_t reversedAddresses[MICROBIT_BLE_MAXIMUM_BONDS];
Gap::Whitelist_t whitelist;
whitelist.addresses = bondedAddresses;
whitelist.capacity = MICROBIT_BLE_MAXIMUM_BONDS;
ble->securityManager().getAddressesFromBondTable(whitelist);
// Generate a reversed list of addresses. We do this such that the most recently used
// bonds are added first - thus making the most recent (not oldest) bond the one
// added to the whitelist for any given peer.
for (int i=0; i<whitelist.size; i++)
reversedAddresses[whitelist.size-i-1] = bondedAddresses[i];
whitelist.addresses = reversedAddresses;
ble->gap().setWhitelist(whitelist);
ble->gap().setScanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST);
ble->gap().setAdvertisingPolicyMode(Gap::ADV_POLICY_FILTER_CONN_REQS);