Added change to generate unique IRK for each chip

This commit is contained in:
Rahul Tank
2024-02-20 12:22:49 +05:30
committed by Abhinav Kudnar
parent 07bacaa1dd
commit 12df982603
3 changed files with 55 additions and 7 deletions
+46 -4
View File
@@ -28,10 +28,7 @@ static uint8_t ble_hs_pvcy_started;
static uint8_t ble_hs_pvcy_irk[16];
/** Use this as a default IRK if none gets set. */
const uint8_t ble_hs_pvcy_default_irk[16] = {
0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
};
uint8_t ble_hs_pvcy_default_irk[16];
static int
ble_hs_pvcy_set_addr_timeout(uint16_t timeout)
@@ -203,6 +200,51 @@ ble_hs_pvcy_ensure_started(void)
return 0;
}
void ble_hs_pvcy_set_default_irk(void)
{
struct ble_store_value_sec value_sec;
struct ble_store_key_sec key_sec;
uint8_t *local_id = NULL;
int rc;
memset(&key_sec, 0, sizeof key_sec);
memset(&value_sec, 0x0, sizeof value_sec);
ble_hs_id_addr(BLE_ADDR_PUBLIC, (const uint8_t **) &local_id, NULL);
/* Create key / value */
memcpy (key_sec.peer_addr.val , local_id, BLE_DEV_ADDR_LEN);
key_sec.peer_addr.type = BLE_ADDR_PUBLIC;
/* Read NVS for local IRK */
rc = ble_store_read_our_sec(&key_sec, &value_sec);
if (value_sec.irk_present) {
memcpy(ble_hs_pvcy_default_irk, value_sec.irk, 16);
} else {
/* No entry for local IRK found . Generate one and load in NVS */
memset(ble_hs_pvcy_default_irk, 0x0, 16);
rc = ble_hs_hci_util_rand(ble_hs_pvcy_default_irk, 16);
if (rc != 0) {
BLE_HS_LOG(ERROR, "Failed to generate local IRK");
return;
}
memset(&value_sec, 0x0, sizeof value_sec);
memcpy(value_sec.irk, ble_hs_pvcy_default_irk, 16);
value_sec.irk_present = 1;
memcpy(value_sec.peer_addr.val, local_id, BLE_DEV_ADDR_LEN);
value_sec.peer_addr.type = BLE_ADDR_PUBLIC;
ble_store_write_our_sec(&value_sec);
}
}
int
ble_hs_pvcy_set_our_irk(const uint8_t *irk)
{
+2 -1
View File
@@ -26,8 +26,9 @@
extern "C" {
#endif
extern const uint8_t ble_hs_pvcy_default_irk[16];
extern uint8_t ble_hs_pvcy_default_irk[16];
void ble_hs_pvcy_set_default_irk(void);
int ble_hs_pvcy_set_our_irk(const uint8_t *irk);
int ble_hs_pvcy_our_irk(const uint8_t **out_irk);
int ble_hs_pvcy_remove_entry(uint8_t addr_type, const uint8_t *addr);
+7 -2
View File
@@ -349,8 +349,9 @@ ble_hs_startup_reset_tx(void)
int
ble_hs_startup_go(void)
{
struct ble_store_gen_key gen_key;
//struct ble_store_gen_key gen_key;
int rc;
uint8_t irk[16];
rc = ble_hs_startup_reset_tx();
if (rc != 0) {
@@ -403,7 +404,7 @@ ble_hs_startup_go(void)
if (rc != 0) {
return rc;
}
#if 0
if (ble_hs_cfg.store_gen_key_cb) {
memset(&gen_key, 0, sizeof(gen_key));
rc = ble_hs_cfg.store_gen_key_cb(BLE_STORE_GEN_KEY_IRK, &gen_key,
@@ -418,6 +419,10 @@ ble_hs_startup_go(void)
if (rc != 0) {
ble_hs_pvcy_set_our_irk(NULL);
}
#endif
ble_hs_pvcy_set_default_irk();
ble_hs_pvcy_set_our_irk(irk);
/* If flow control is enabled, configure the controller to use it. */
ble_hs_flow_startup();