Merge branch 'ble-bondtablepurge'

This commit is contained in:
Joe Finney 2016-02-01 22:51:23 +00:00
commit 104493299e
2 changed files with 14 additions and 11 deletions

View file

@ -17,7 +17,7 @@
"mbed-classic": "~0.0.4",
"ble": "lancaster-university/BLE_API#v2.5.0+mb",
"ble-nrf51822": "lancaster-university/nrf51822#v2.5.0+mb3",
"nrf51-sdk": "lancaster-university/nrf51-sdk#v2.2.0+mb"
"nrf51-sdk": "lancaster-university/nrf51-sdk#v2.2.0+mb2"
},
"extraIncludes": [
"inc"

View file

@ -144,6 +144,7 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
ble = new BLEDevice();
ble->init();
// automatically restart advertising after a device disconnects.
ble->onDisconnection(bleDisconnectionCallback);
ble->onConnection(bleConnectionCallback);
@ -159,6 +160,18 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
ble->securityManager().onSecuritySetupCompleted(securitySetupCompletedCallback);
ble->securityManager().init(enableBonding, MICROBIT_BLE_REQUIRE_MITM, SecurityManager::IO_CAPS_DISPLAY_ONLY);
// If we're in pairing mode, review the size of the bond table.
if (enableBonding)
{
// TODO: It would be much better to implement some sort of LRU/NFU policy here,
// but this isn't currently supported in mbed, so we'd need to layer break...
int bonds = getBondCount();
// If we're full, empty the bond table.
if (bonds >= MICROBIT_BLE_MAXIMUM_BONDS)
ble->securityManager().purgeAllBondingState();
}
#if CONFIG_ENABLED(MICROBIT_BLE_WHITELIST)
// 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.
@ -286,16 +299,6 @@ int MicroBitBLEManager::getBondCount()
*/
void MicroBitBLEManager::pairingRequested(ManagedString passKey)
{
// Firstly, determine if there is free space in the bonding table.
// If not, clear it out to make room.
// TODO: It would be much better to implement some sort of LRU/NFU policy here,
// but this isn't currently supported in mbed, so we'd need to layer break...
// If we're full, empty the bond table.
if (getBondCount() >= MICROBIT_BLE_MAXIMUM_BONDS)
ble->securityManager().purgeAllBondingState();
// Update our mode to display the passkey.
this->passKey = passKey;
this->pairingStatus = MICROBIT_BLE_PAIR_REQUEST;