Skip to content

Commit

Permalink
Generate and store local IRK for non-esp32 devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Dec 13, 2024
1 parent b3b426b commit d61148d
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions src/nimble/nimble/host/store/config/src/ble_store_config_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d61148d

Please sign in to comment.