@@ -64,8 +64,6 @@ extern "C"
6464void adafruit_ble_task (void * arg);
6565void adafruit_soc_task (void * arg);
6666
67- void _adafruit_save_bond_key_dfr (uint32_t conn_handle);
68-
6967#if CFG_DEBUG >= 2
7068#define printBondDir () dbgPrintDir(CFG_BOND_NFFS_DIR)
7169#else
@@ -954,9 +952,6 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
954952 break ;
955953
956954 case BLE_GAP_EVT_DISCONNECTED:
957- // Save all configured cccd
958- if (_bonded) _saveBondCCCD ();
959-
960955 if (_disconnect_cb) ada_callback (NULL , _disconnect_cb, _conn_hdl, evt->evt .gap_evt .params .disconnected .reason );
961956
962957 LOG_LV2 (" GAP" , " Disconnect Reason 0x%02X" , evt->evt .gap_evt .params .disconnected .reason );
@@ -1012,7 +1007,7 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
10121007 // return security information. Otherwise NULL
10131008 ble_gap_evt_sec_info_request_t * sec_request = (ble_gap_evt_sec_info_request_t *) &evt->evt .gap_evt .params .sec_info_request ;
10141009
1015- if ( _loadBondKeys (sec_request->master_id .ediv ) )
1010+ if ( bond_load_keys (sec_request->master_id .ediv , &_bond_data ) )
10161011 {
10171012 sd_ble_gap_sec_info_reply (evt->evt .gap_evt .conn_handle , &_bond_data.own_enc .enc_info , &_bond_data.peer_id .id_info , NULL );
10181013 } else
@@ -1039,10 +1034,10 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
10391034 // Connection is secured aka Paired
10401035 COMMENT_OUT ( ble_gap_conn_sec_t * conn_sec = (ble_gap_conn_sec_t *) &evt->evt .gap_evt .params .conn_sec_update .conn_sec ; )
10411036
1042- // Previously bonded --> secure by re-connection process
1043- // --> Load & Set Sys Attr (Apply Service Context)
1044- // Else Init Sys Attr
1045- _loadBondCCCD ( _bond_data.own_enc .master_id .ediv );
1037+ // Previously bonded --> secure by re-connection process
1038+ // --> Load & Set Sys Attr (Apply Service Context)
1039+ // Else Init Sys Attr
1040+ bond_load_cccd (evt_conn_hdl, _bond_data.own_enc .master_id .ediv );
10461041
10471042 // Consider Paired as Bonded
10481043 _bonded = true ;
@@ -1157,11 +1152,11 @@ void AdafruitBluefruit::clearBonds(void)
11571152// Bluefruit._saveBondKeys();
11581153// }
11591154
1160- void _adafruit_save_bond_cccd_dfr (uint32_t conn_handle)
1161- {
1162- (void ) conn_handle;
1163- Bluefruit._saveBondCCCD ();
1164- }
1155+ // void _adafruit_save_bond_cccd_dfr(uint32_t conn_handle)
1156+ // {
1157+ // (void) conn_handle;
1158+ // Bluefruit._saveBondCCCD();
1159+ // }
11651160
11661161// void AdafruitBluefruit::_saveBondKeys(void)
11671162// {
@@ -1201,103 +1196,103 @@ void _adafruit_save_bond_cccd_dfr(uint32_t conn_handle)
12011196// printBondDir();
12021197// }
12031198
1204- bool AdafruitBluefruit::_loadBondKeys (uint16_t ediv)
1205- {
1206- VERIFY_STATIC (sizeof (_bond_data) == 80 );
1207-
1208- char filename[BOND_FILENAME_LEN];
1209- sprintf (filename, BOND_FILENAME, ediv);
1210-
1211- bool result = (Nffs.readFile (filename, &_bond_data, sizeof (_bond_data)) > 0 );
1212-
1213- if ( result )
1214- {
1215- LOG_LV2 (" BOND" , " Load Keys from file %s" , filename);
1216- }else
1217- {
1218- LOG_LV1 (" BOND" , " Keys not found" );
1219- }
1220-
1221- return result;
1222- }
1223-
1224- void AdafruitBluefruit::_saveBondCCCD (void )
1225- {
1226- VERIFY ( _bond_data.own_enc .master_id .ediv != 0xFFFF , );
1227-
1228- uint16_t len=0 ;
1229- sd_ble_gatts_sys_attr_get (_conn_hdl, NULL , &len, SVC_CONTEXT_FLAG);
1230-
1231- uint8_t * sys_attr = (uint8_t *) rtos_malloc ( len );
1232- VERIFY ( sys_attr, );
1233-
1234- if ( ERROR_NONE == sd_ble_gatts_sys_attr_get (_conn_hdl, sys_attr, &len, SVC_CONTEXT_FLAG) )
1235- {
1236- // save to file
1237- char filename[BOND_FILENAME_LEN];
1238- sprintf (filename, BOND_FILENAME, _bond_data.own_enc .master_id .ediv );
1239-
1240- if ( Nffs.writeFile (filename, sys_attr, len, BOND_FILE_CCCD_OFFSET) )
1241- {
1242- LOG_LV2 (" BOND" , " CCCD setting is saved to file %s" , filename);
1243- }else
1244- {
1245- LOG_LV1 (" BOND" , " Failed to save CCCD setting" );
1246- }
1247-
1248- }
1249-
1250- printBondDir ();
1251-
1252- rtos_free (sys_attr);
1253- }
1254-
1255- void AdafruitBluefruit::_loadBondCCCD (uint16_t ediv)
1256- {
1257- bool loaded = false ;
1258-
1259- char filename[BOND_FILENAME_LEN];
1260- sprintf (filename, BOND_FILENAME, ediv);
1261-
1262- NffsFile file (filename, FS_ACCESS_READ);
1263-
1264- if ( file.exists () )
1265- {
1266- int32_t len = file.size () - BOND_FILE_CCCD_OFFSET;
1267-
1268- if ( len )
1269- {
1270- uint8_t * sys_attr = (uint8_t *) rtos_malloc ( len );
1271-
1272- if (sys_attr)
1273- {
1274- file.seek (BOND_FILE_CCCD_OFFSET);
1275-
1276- if ( file.read (sys_attr, len ) )
1277- {
1278- if (ERROR_NONE == sd_ble_gatts_sys_attr_set (_conn_hdl, sys_attr, len, SVC_CONTEXT_FLAG) )
1279- {
1280- loaded = true ;
1281-
1282- LOG_LV2 (" BOND" , " Load CCCD from file %s" , filename);
1283- }else
1284- {
1285- LOG_LV1 (" BOND" , " CCCD setting not found" );
1286- }
1287- }
1288-
1289- rtos_free (sys_attr);
1290- }
1291- }
1292- }
1199+ // bool AdafruitBluefruit::_loadBondKeys(uint16_t ediv)
1200+ // {
1201+ // VERIFY_STATIC(sizeof(_bond_data) == 80 );
1202+ //
1203+ // char filename[BOND_FILENAME_LEN];
1204+ // sprintf(filename, BOND_FILENAME, ediv);
1205+ //
1206+ // bool result = (Nffs.readFile(filename, &_bond_data, sizeof(_bond_data)) > 0);
1207+ //
1208+ // if ( result )
1209+ // {
1210+ // LOG_LV2("BOND", "Load Keys from file %s", filename);
1211+ // }else
1212+ // {
1213+ // LOG_LV1("BOND", "Keys not found");
1214+ // }
1215+ //
1216+ // return result;
1217+ // }
12931218
1294- file.close ();
1219+ // void AdafruitBluefruit::_saveBondCCCD(void)
1220+ // {
1221+ // VERIFY( _bond_data.own_enc.master_id.ediv != 0xFFFF, );
1222+ //
1223+ // uint16_t len=0;
1224+ // sd_ble_gatts_sys_attr_get(_conn_hdl, NULL, &len, SVC_CONTEXT_FLAG);
1225+ //
1226+ // uint8_t* sys_attr = (uint8_t*) rtos_malloc( len );
1227+ // VERIFY( sys_attr, );
1228+ //
1229+ // if ( ERROR_NONE == sd_ble_gatts_sys_attr_get(_conn_hdl, sys_attr, &len, SVC_CONTEXT_FLAG) )
1230+ // {
1231+ // // save to file
1232+ // char filename[BOND_FILENAME_LEN];
1233+ // sprintf(filename, BOND_FILENAME, _bond_data.own_enc.master_id.ediv);
1234+ //
1235+ // if ( Nffs.writeFile(filename, sys_attr, len, BOND_FILE_CCCD_OFFSET) )
1236+ // {
1237+ // LOG_LV2("BOND", "CCCD setting is saved to file %s", filename);
1238+ // }else
1239+ // {
1240+ // LOG_LV1("BOND", "Failed to save CCCD setting");
1241+ // }
1242+ //
1243+ // }
1244+ //
1245+ // printBondDir();
1246+ //
1247+ // rtos_free(sys_attr);
1248+ // }
12951249
1296- if ( !loaded )
1297- {
1298- sd_ble_gatts_sys_attr_set (_conn_hdl, NULL , 0 , 0 );
1299- }
1300- }
1250+ // void AdafruitBluefruit::_loadBondCCCD(uint16_t ediv)
1251+ // {
1252+ // bool loaded = false;
1253+ //
1254+ // char filename[BOND_FILENAME_LEN];
1255+ // sprintf(filename, BOND_FILENAME, ediv);
1256+ //
1257+ // NffsFile file(filename, FS_ACCESS_READ);
1258+ //
1259+ // if ( file.exists() )
1260+ // {
1261+ // int32_t len = file.size() - BOND_FILE_CCCD_OFFSET;
1262+ //
1263+ // if ( len )
1264+ // {
1265+ // uint8_t* sys_attr = (uint8_t*) rtos_malloc( len );
1266+ //
1267+ // if (sys_attr)
1268+ // {
1269+ // file.seek(BOND_FILE_CCCD_OFFSET);
1270+ //
1271+ // if ( file.read(sys_attr, len ) )
1272+ // {
1273+ // if (ERROR_NONE == sd_ble_gatts_sys_attr_set(_conn_hdl, sys_attr, len, SVC_CONTEXT_FLAG) )
1274+ // {
1275+ // loaded = true;
1276+ //
1277+ // LOG_LV2("BOND", "Load CCCD from file %s", filename);
1278+ // }else
1279+ // {
1280+ // LOG_LV1("BOND", "CCCD setting not found");
1281+ // }
1282+ // }
1283+ //
1284+ // rtos_free(sys_attr);
1285+ // }
1286+ // }
1287+ // }
1288+ //
1289+ // file.close();
1290+ //
1291+ // if ( !loaded )
1292+ // {
1293+ // sd_ble_gatts_sys_attr_set(_conn_hdl, NULL, 0, 0);
1294+ // }
1295+ // }
13011296
13021297void AdafruitBluefruit::_bledfu_get_bond_data (ble_gap_addr_t * addr, ble_gap_irk_t * irk, ble_gap_enc_key_t * enc_key)
13031298{
0 commit comments