test
Fork of nRF51822 by
Diff: source/btle/btle_security.cpp
- Revision:
- 613:cbc548e9df98
- Parent:
- 599:3e66e1eb264d
- Child:
- 615:65ea2acfc6a2
--- a/source/btle/btle_security.cpp Tue Jan 12 13:44:47 2016 +0000 +++ b/source/btle/btle_security.cpp Tue Jan 12 19:58:02 2016 +0000 @@ -273,6 +273,9 @@ ble_error_t btle_createWhitelistFromBondTable(ble_gap_whitelist_t *p_whitelist) { + if (!btle_hasInitializedSecurity()) { + return BLE_ERROR_INITIALIZATION_INCOMPLETE; + } ret_code_t err = dm_whitelist_create(&applicationInstance, p_whitelist); if (err == NRF_SUCCESS) { return BLE_ERROR_NONE; @@ -292,4 +295,22 @@ * address can be generated using the IRK. */ return im_address_resolve(p_addr, p_irk); +} + +void +btle_generateResolvableAddress(const ble_gap_irk_t &irk, ble_gap_addr_t &address) +{ + /* Set type to resolvable */ + address.addr_type = BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE; + + /* + * Assign a random number to the most significant 3 bytes + * of the address. + */ + address.addr[BLE_GAP_ADDR_LEN - 3] = 0x8E; + address.addr[BLE_GAP_ADDR_LEN - 2] = 0x4F; + address.addr[BLE_GAP_ADDR_LEN - 1] = 0x7C; + + /* Calculate the hash and store it in the top half of the address */ + ah(irk.irk, &address.addr[BLE_GAP_ADDR_LEN - 3], address.addr); } \ No newline at end of file