@@ -79,6 +79,14 @@ static struct conf_handler ble_store_config_conf_handler = {
7979#define BLE_STORE_CONFIG_RPA_REC_SET_ENCODE_SZ \
8080 (MYNEWT_VAL(BLE_STORE_MAX_BONDS) * BLE_STORE_CONFIG_RPA_REC_ENCODE_SZ + 1)
8181
82+ #define BLE_STORE_CONFIG_IRK_ENCODE_SZ \
83+ BASE64_ENCODE_SIZE(sizeof (struct ble_store_value_local_irk))
84+
85+ #define BLE_STORE_CONFIG_IRK_SET_ENCODE_SZ \
86+ (MYNEWT_VAL(BLE_STORE_MAX_BONDS) * BLE_STORE_CONFIG_IRK_ENCODE_SZ + 1)
87+
88+ static const uint32_t our_irk = 0x6b72696f ; /* oirk */
89+
8290static void
8391ble_store_config_serialize_arr (const void * arr , int obj_sz , int num_objs ,
8492 char * out_buf , int buf_sz )
@@ -299,7 +307,7 @@ ble_store_config_persist_eads(void)
299307int
300308ble_store_config_persist_rpa_recs (void )
301309{
302- #ifdef ESP_PLATFORM
310+ #if 0
303311 char buf [BLE_STORE_CONFIG_RPA_REC_SET_ENCODE_SZ ];
304312 int rc ;
305313 ble_store_config_serialize_arr (ble_store_config_rpa_recs ,
@@ -316,11 +324,23 @@ ble_store_config_persist_rpa_recs(void)
316324 return BLE_HS_ESTORE_FAIL ;
317325}
318326
319- #ifndef ESP_PLATFORM
320- int ble_store_config_persist_local_irk (void ){
321- return BLE_HS_ESTORE_FAIL ;
327+ int
328+ ble_store_config_persist_local_irk (void ) {
329+ char buf [BLE_STORE_CONFIG_IRK_SET_ENCODE_SZ ];
330+ int rc ;
331+
332+ ble_store_config_serialize_arr (ble_store_config_local_irks ,
333+ sizeof * ble_store_config_local_irks ,
334+ ble_store_config_num_local_irks ,
335+ buf , sizeof buf );
336+
337+ rc = ble_bond_nvs_save_entry (our_irk , buf );
338+ if (rc != 0 ) {
339+ return BLE_HS_ESTORE_FAIL ;
340+ }
341+
342+ return 0 ;
322343}
323- #endif
324344
325345void
326346ble_store_config_conf_init (void )
@@ -375,6 +395,19 @@ ble_store_config_conf_init(void)
375395 }
376396 }
377397
398+ rc = ble_bond_nvs_get_entry (our_irk , & val_addr );
399+ if (rc == 0 ) {
400+ rc = ble_store_config_deserialize_arr (
401+ (char * )val_addr ,
402+ ble_store_config_local_irks ,
403+ sizeof * ble_store_config_local_irks ,
404+ & ble_store_config_num_local_irks );
405+ if (rc != 0 ) {
406+ BLE_HS_LOG (ERROR , "irk restore error rc=%d\n" , rc );
407+ return ;
408+ }
409+ }
410+
378411 /* int rc;
379412
380413 rc = conf_register(&ble_store_config_conf_handler);
0 commit comments