microbit: Support for bonding only available in pairing mode
Update to BLE initialisation code. Ability to initiate pairing is now restricted to pairing mode.
This commit is contained in:
parent
99d7231945
commit
e3fdc5a290
4 changed files with 17 additions and 12 deletions
|
@ -72,7 +72,7 @@ class MicroBitBLEManager
|
|||
* uBit.init();
|
||||
* @endcode
|
||||
*/
|
||||
void init(ManagedString deviceName, ManagedString serialNumber);
|
||||
void init(ManagedString deviceName, ManagedString serialNumber, bool enableBonding);
|
||||
|
||||
/**
|
||||
* Change the output power level of the transmitter to the given value.
|
||||
|
|
|
@ -133,13 +133,6 @@ void MicroBit::init()
|
|||
// Seed our random number generator
|
||||
seedRandom();
|
||||
|
||||
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
|
||||
// Start the BLE stack.
|
||||
bleManager.init(this->getName(), this->getSerial());
|
||||
|
||||
ble = bleManager.ble;
|
||||
#endif
|
||||
|
||||
// Start refreshing the Matrix Display
|
||||
systemTicker.attach(this, &MicroBit::systemTick, MICROBIT_DISPLAY_REFRESH_PERIOD);
|
||||
|
||||
|
|
|
@ -46,9 +46,12 @@ int main()
|
|||
|
||||
if (i == 10)
|
||||
{
|
||||
// Bring up the BLE stack if it isn't alredy done.
|
||||
// Start the BLE stack, if it isn't already running.
|
||||
if (!uBit.ble)
|
||||
uBit.bleManager.init(uBit.getName(), uBit.getSerial());
|
||||
{
|
||||
uBit.bleManager.init(uBit.getName(), uBit.getSerial(), true);
|
||||
uBit.ble = uBit.bleManager.ble;
|
||||
}
|
||||
|
||||
// Enter pairing mode, using the LED matrix for any necessary pairing operations
|
||||
uBit.bleManager.pairingMode(uBit.display);
|
||||
|
@ -56,6 +59,15 @@ int main()
|
|||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
|
||||
// Start the BLE stack, if it isn't already running.
|
||||
if (!uBit.ble)
|
||||
{
|
||||
uBit.bleManager.init(uBit.getName(), uBit.getSerial(), false);
|
||||
uBit.ble = uBit.bleManager.ble;
|
||||
}
|
||||
#endif
|
||||
|
||||
app_main();
|
||||
|
||||
// If app_main exits, there may still be other fibers running, registered event handlers etc.
|
||||
|
|
|
@ -127,7 +127,7 @@ void MicroBitBLEManager::advertise()
|
|||
* uBit.init();
|
||||
* @endcode
|
||||
*/
|
||||
void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumber)
|
||||
void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumber, bool enableBonding)
|
||||
{
|
||||
ManagedString BLEName("BBC micro:bit");
|
||||
|
||||
|
@ -156,7 +156,7 @@ void MicroBitBLEManager::init(ManagedString deviceName, ManagedString serialNumb
|
|||
// Setup our security requirements.
|
||||
ble->securityManager().onPasskeyDisplay(passkeyDisplayCallback);
|
||||
ble->securityManager().onSecuritySetupCompleted(securitySetupCompletedCallback);
|
||||
ble->securityManager().init(MICROBIT_BLE_ENABLE_BONDING, MICROBIT_BLE_REQUIRE_MITM, SecurityManager::IO_CAPS_DISPLAY_ONLY);
|
||||
ble->securityManager().init(enableBonding, MICROBIT_BLE_REQUIRE_MITM, SecurityManager::IO_CAPS_DISPLAY_ONLY);
|
||||
|
||||
#if CONFIG_ENABLED(MICROBIT_BLE_WHITELIST)
|
||||
// Configure a whitelist to filter all connection requetss from unbonded devices.
|
||||
|
|
Loading…
Reference in a new issue