-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Description of defect
BLE SecurityManager fails to restore saved security parameters from non-volatile memory after reset.
Target(s) affected by this defect ?
Testing using EP_AGORA and NRF52840_DK
Toolchain(s) (name and version) displaying this defect ?
Testing with GCC ARM
What version of Mbed-os are you using (tag or sha) ?
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
How is this defect reproduced ?
Build a BLE app that approves all pairing requests and has an on-board flash/filesystem. I have tried with both LittleFS and FATFileSystem using an internal FlashIAPBlockDevice and an external SPIF/QSPIFBlockDevice. Neither worked as expected.
I initialize the security manager with a file path to use and tell it to save security information -- SecurityManager::preservceBondingStateOnReset()
I am using Nordic's nRFConnect utility to then connect to and initiate pairing with the Mbed BLE device. The pairing goes as expected.
Then I disconnect and reset the Mbed BLE device. On startup, I check the supposedly preserved bonding table:
ble.securityManager().generateWhitelistFromBondTable()
Once the whitelistFromBondTable()
callback is executed, the whitelist size is always 0.
I stepped through the initialization of the security manager at this stage (after pairing and a power cycle) and found that it is reading back an inconsistent security database version number, which causes the SecurityManager to reinitialize (delete) the security database...
I am seeing this happen at this line:
mbed-os/features/FEATURE_BLE/source/generic/FileSecurityDb.cpp
Lines 108 to 121 in f1392d6
if ((fread(&version, sizeof(version), 1, db_file) == 1) && | |
(version == DB_VERSION)) { | |
/* if file size differs from database size init the file */ | |
fseek(db_file, 0, SEEK_END); | |
if (ftell(db_file) != DB_SIZE) { | |
init = true; | |
} | |
} else { | |
init = true; | |
} | |
if (init) { | |
return erase_db_file(db_file); | |
} |
I would suggest using the BLE_SM example in mbed-os-example-ble to try to reproduce this issue, but that example is broken in other ways.
I will continue to debug what is happening. Am I missing a step?