Skip to content

Commit 4e3a9ff

Browse files
authored
Merge pull request #48 from paul-szczepanek-arm/sm-init-error
allow changing database at runtime and add checking for initialisation
2 parents a8ac925 + 17e8ed9 commit 4e3a9ff

File tree

3 files changed

+146
-45
lines changed

3 files changed

+146
-45
lines changed

features/FEATURE_BLE/ble/SecurityManager.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class SecurityManager {
441441
* support out-of-band exchanges of security data.
442442
* @param[in] passkey To specify a static passkey.
443443
* @param[in] signing Generate and distribute signing key during pairing
444-
* @param[in] dbPath Path to the folder used to store keys in the filesystem,
444+
* @param[in] dbPath Path to the file used to store keys in the filesystem,
445445
* if NULL keys will be only stored in memory
446446
*
447447
*
@@ -452,17 +452,33 @@ class SecurityManager {
452452
SecurityIOCapabilities_t iocaps = IO_CAPS_NONE,
453453
const Passkey_t passkey = NULL,
454454
bool signing = true,
455-
const char *dbPath = NULL) {
455+
const char *dbFilepath = NULL) {
456456
/* Avoid compiler warnings about unused variables. */
457457
(void)enableBonding;
458458
(void)requireMITM;
459459
(void)iocaps;
460460
(void)passkey;
461-
(void)dbPath;
461+
(void)dbFilepath;
462462

463463
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */
464464
}
465465

466+
/**
467+
* Change the file used for the security database. If path is invalid or a NULL is passed
468+
* keys will only be stored in memory.
469+
*
470+
* @note This operation is only allowed with no active connections.
471+
*
472+
* @param[in] dbPath Path to the file used to store keys in the filesystem,
473+
* if NULL keys will be only stored in memory
474+
*
475+
* @return BLE_ERROR_NONE on success.
476+
*/
477+
virtual ble_error_t setDatabaseFilepath(const char *dbFilepath = NULL) {
478+
(void)dbFilepath;
479+
return BLE_ERROR_NOT_IMPLEMENTED; /* Requesting action from porters: override this API if security is supported. */
480+
}
481+
466482
/**
467483
* Notify all registered onShutdown callbacks that the SecurityManager is
468484
* about to be shutdown and clear all SecurityManager state of the

features/FEATURE_BLE/ble/generic/GenericSecurityManager.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class GenericSecurityManager : public SecurityManager,
5353
const char* db_path = NULL
5454
);
5555

56+
virtual ble_error_t setDatabaseFilepath(const char *db_path = NULL);
57+
5658
virtual ble_error_t reset();
5759

5860
virtual ble_error_t preserveBondingStateOnReset(
@@ -263,6 +265,22 @@ class GenericSecurityManager : public SecurityManager,
263265
//
264266

265267
private:
268+
269+
/**
270+
* Initialise the database, if database already exists it will close it and open the new one.
271+
*
272+
* @param db_path path to file to store secure db
273+
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
274+
*/
275+
ble_error_t init_database(const char *db_path = NULL);
276+
277+
/**
278+
* Generate identity list based on the database of IRK and apply it to the resolving list.
279+
*
280+
* @return BLE_ERROR_NONE or appropriate error code indicating the failure reason.
281+
*/
282+
ble_error_t init_resolving_list();
283+
266284
/**
267285
* Generate the CSRK if needed.
268286
*

0 commit comments

Comments
 (0)