@@ -48,7 +48,7 @@ ble_error_t GenericSecurityManager::init(
48
48
return result;
49
49
}
50
50
51
- result = setDatabaseFile (db_path);
51
+ result = init_database (db_path);
52
52
if (result != BLE_ERROR_NONE) {
53
53
return result;
54
54
}
@@ -79,49 +79,38 @@ ble_error_t GenericSecurityManager::init(
79
79
init_signing ();
80
80
}
81
81
82
+ init_resolving_list ();
83
+
82
84
_connection_monitor.set_connection_event_handler (this );
83
85
_signing_monitor.set_signing_event_handler (this );
84
86
_pal.set_event_handler (this );
85
87
86
- uint8_t resolving_list_capacity = _pal.read_resolving_list_capacity ();
87
- SecurityEntryIdentity_t* identity_list_p =
88
- new (std::nothrow) SecurityEntryIdentity_t[resolving_list_capacity];
89
-
90
- if (identity_list_p) {
91
- ArrayView<SecurityEntryIdentity_t> identity_list (
92
- identity_list_p,
93
- resolving_list_capacity
94
- );
95
-
96
- _db->get_identity_list (
97
- mbed::callback (this , &GenericSecurityManager::on_identity_list_retrieved),
98
- identity_list
99
- );
100
- }
101
-
102
88
return BLE_ERROR_NONE;
103
89
}
104
90
105
- ble_error_t GenericSecurityManager::setDatabaseFile (
91
+ ble_error_t GenericSecurityManager::setDatabaseFilepath (
106
92
const char *db_path
107
93
) {
108
- if (_db) {
109
- delete _db;
110
- }
94
+ if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
111
95
112
- FILE* db_file = FileSecurityDb::open_db_file (db_path);
96
+ /* operation only allowed with no connections active */
97
+ for (size_t i = 0 ; i < MAX_CONTROL_BLOCKS; i++) {
98
+ if (_control_blocks[i].connected ) {
99
+ return BLE_ERROR_OPERATION_NOT_PERMITTED;
100
+ }
101
+ }
113
102
114
- if (db_file) {
115
- _db = new (std::nothrow) FileSecurityDb (db_file);
116
- } else {
117
- _db = new (std::nothrow) MemorySecurityDb ();
103
+ ble_error_t result = init_database (db_path);
104
+ if (result != BLE_ERROR_NONE) {
105
+ return result;
118
106
}
119
107
120
- if (!_db) {
121
- return BLE_ERROR_NO_MEM;
108
+ result = init_database (db_path);
109
+ if (result != BLE_ERROR_NONE) {
110
+ return result;
122
111
}
123
112
124
- _db-> restore ();
113
+ init_resolving_list ();
125
114
126
115
return BLE_ERROR_NONE;
127
116
}
@@ -779,6 +768,49 @@ ble_error_t GenericSecurityManager::oobReceived(
779
768
// Helper functions
780
769
//
781
770
771
+ ble_error_t GenericSecurityManager::init_database (
772
+ const char *db_path
773
+ ) {
774
+ if (_db) {
775
+ delete _db;
776
+ }
777
+
778
+ FILE* db_file = FileSecurityDb::open_db_file (db_path);
779
+
780
+ if (db_file) {
781
+ _db = new (std::nothrow) FileSecurityDb (db_file);
782
+ } else {
783
+ _db = new (std::nothrow) MemorySecurityDb ();
784
+ }
785
+
786
+ if (!_db) {
787
+ return BLE_ERROR_NO_MEM;
788
+ }
789
+
790
+ _db->restore ();
791
+
792
+ return BLE_ERROR_NONE;
793
+ }
794
+
795
+ ble_error_t GenericSecurityManager::init_resolving_list () {
796
+ /* match the resolving list to the currently stored set of IRKs */
797
+ uint8_t resolving_list_capacity = _pal.read_resolving_list_capacity ();
798
+ SecurityEntryIdentity_t* identity_list_p =
799
+ new (std::nothrow) SecurityEntryIdentity_t[resolving_list_capacity];
800
+
801
+ if (identity_list_p) {
802
+ ArrayView<SecurityEntryIdentity_t> identity_list (
803
+ identity_list_p,
804
+ resolving_list_capacity
805
+ );
806
+
807
+ _db->get_identity_list (
808
+ mbed::callback (this , &GenericSecurityManager::on_identity_list_retrieved),
809
+ identity_list
810
+ );
811
+ }
812
+ }
813
+
782
814
ble_error_t GenericSecurityManager::init_signing () {
783
815
if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
784
816
const csrk_t *pcsrk = _db->get_local_csrk ();
0 commit comments