int ble_store_write_peer_sec(struct ble_store_value_sec *value_sec) { int rc; rc = ble_store_persist_sec(BLE_STORE_OBJ_TYPE_PEER_SEC, value_sec); if (rc != 0) { return rc; } if (value_sec->peer_addr_type != BLE_STORE_ADDR_TYPE_NONE && value_sec->irk_present) { /* Write the peer IRK to the controller keycache * There is not much to do here if it fails */ rc = ble_hs_pvcy_add_entry(value_sec->peer_addr, value_sec->peer_addr_type, value_sec->irk); if (rc != 0) { return rc; } } return 0; }
int ble_hs_pvcy_set_our_irk(const uint8_t *irk) { uint8_t tmp_addr[6]; uint8_t new_irk[16]; int rc; memset(new_irk, 0, sizeof(new_irk)); if (irk != NULL) { memcpy(new_irk, irk, 16); } else { memcpy(new_irk, default_irk, 16); } /* Clear the resolving list if this is a new IRK. */ if (memcmp(ble_hs_pvcy_irk, new_irk, 16) != 0) { memcpy(ble_hs_pvcy_irk, new_irk, 16); rc = ble_hs_pvcy_set_resolve_enabled(0); if (rc != 0) { return rc; } rc = ble_hs_pvcy_clear_entries(); if (rc != 0) { return rc; } rc = ble_hs_pvcy_set_resolve_enabled(1); if (rc != 0) { return rc; } /* Push a null address identity to the controller. The controller uses * this entry to generate an RPA when we do advertising with * own-addr-type = rpa. */ memset(tmp_addr, 0, 6); rc = ble_hs_pvcy_add_entry(tmp_addr, 0, ble_hs_pvcy_irk); if (rc != 0) { return rc; } } return 0; }