diff --git a/src/nimble/nimble/host/store/config/src/ble_store_config_conf.c b/src/nimble/nimble/host/store/config/src/ble_store_config_conf.c index f1d71beb..3d7247dd 100644 --- a/src/nimble/nimble/host/store/config/src/ble_store_config_conf.c +++ b/src/nimble/nimble/host/store/config/src/ble_store_config_conf.c @@ -79,6 +79,14 @@ static struct conf_handler ble_store_config_conf_handler = { #define BLE_STORE_CONFIG_RPA_REC_SET_ENCODE_SZ \ (MYNEWT_VAL(BLE_STORE_MAX_BONDS) * BLE_STORE_CONFIG_RPA_REC_ENCODE_SZ + 1) +#define BLE_STORE_CONFIG_IRK_ENCODE_SZ \ + BASE64_ENCODE_SIZE(sizeof (struct ble_store_value_local_irk)) + +#define BLE_STORE_CONFIG_IRK_SET_ENCODE_SZ \ + (MYNEWT_VAL(BLE_STORE_MAX_BONDS) * BLE_STORE_CONFIG_IRK_ENCODE_SZ + 1) + +static const uint32_t our_irk = 0x6b72696f; /* oirk */ + static void ble_store_config_serialize_arr(const void *arr, int obj_sz, int num_objs, char *out_buf, int buf_sz) @@ -299,7 +307,7 @@ ble_store_config_persist_eads(void) int ble_store_config_persist_rpa_recs(void) { -#ifdef ESP_PLATFORM +#if 0 char buf[BLE_STORE_CONFIG_RPA_REC_SET_ENCODE_SZ]; int rc; ble_store_config_serialize_arr(ble_store_config_rpa_recs, @@ -316,11 +324,23 @@ ble_store_config_persist_rpa_recs(void) return BLE_HS_ESTORE_FAIL; } -#ifndef ESP_PLATFORM -int ble_store_config_persist_local_irk(void){ - return BLE_HS_ESTORE_FAIL; +int +ble_store_config_persist_local_irk(void) { + char buf[BLE_STORE_CONFIG_IRK_SET_ENCODE_SZ]; + int rc; + + ble_store_config_serialize_arr(ble_store_config_local_irks, + sizeof *ble_store_config_local_irks, + ble_store_config_num_local_irks, + buf, sizeof buf); + + rc = ble_bond_nvs_save_entry(our_irk, buf); + if (rc != 0) { + return BLE_HS_ESTORE_FAIL; + } + + return 0; } -#endif void ble_store_config_conf_init(void) @@ -375,6 +395,19 @@ ble_store_config_conf_init(void) } } + rc = ble_bond_nvs_get_entry(our_irk, &val_addr); + if (rc == 0) { + rc = ble_store_config_deserialize_arr( + (char*)val_addr, + ble_store_config_local_irks, + sizeof *ble_store_config_local_irks, + &ble_store_config_num_local_irks); + if (rc != 0) { + BLE_HS_LOG(ERROR, "irk restore error rc=%d\n", rc); + return; + } + } + /* int rc; rc = conf_register(&ble_store_config_conf_handler);