Add documentation and fix style of SecurityManager
This commit is contained in:
parent
c9b6bb9bbb
commit
2ebbcb08b5
|
@ -45,19 +45,8 @@ static ble_gap_sec_params_t securityParameters = {
|
||||||
}, /**< Key distribution bitmap: keys that the peripheral device will distribute. */
|
}, /**< Key distribution bitmap: keys that the peripheral device will distribute. */
|
||||||
};
|
};
|
||||||
|
|
||||||
ble_error_t btle_createWhitelistFromBondTable(ble_gap_whitelist_t *p_whitelist)
|
bool
|
||||||
{
|
btle_hasInitializedSecurity(void)
|
||||||
ret_code_t err = dm_whitelist_create(&applicationInstance, p_whitelist);
|
|
||||||
if (err == NRF_SUCCESS) {
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
} else if (err == NRF_ERROR_NULL) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
} else {
|
|
||||||
return BLE_ERROR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool btle_hasInitializedSecurity(void)
|
|
||||||
{
|
{
|
||||||
return initialized;
|
return initialized;
|
||||||
}
|
}
|
||||||
|
@ -281,7 +270,26 @@ dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t ev
|
||||||
return NRF_SUCCESS;
|
return NRF_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool btle_matchAddressAndIrk(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_irk)
|
ble_error_t
|
||||||
|
btle_createWhitelistFromBondTable(ble_gap_whitelist_t *p_whitelist)
|
||||||
{
|
{
|
||||||
|
ret_code_t err = dm_whitelist_create(&applicationInstance, p_whitelist);
|
||||||
|
if (err == NRF_SUCCESS) {
|
||||||
|
return BLE_ERROR_NONE;
|
||||||
|
} else if (err == NRF_ERROR_NULL) {
|
||||||
|
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
||||||
|
} else {
|
||||||
|
return BLE_ERROR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
btle_matchAddressAndIrk(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_irk)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Use a helper function from the Nordic SDK to test whether the BLE
|
||||||
|
* address can be generated using the IRK.
|
||||||
|
*/
|
||||||
return im_address_resolve(p_addr, p_irk);
|
return im_address_resolve(p_addr, p_irk);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,25 @@ ble_error_t btle_setLinkSecurity(Gap::Handle_t connectionHandle, SecurityManager
|
||||||
*/
|
*/
|
||||||
ble_error_t btle_purgeAllBondingState(void);
|
ble_error_t btle_purgeAllBondingState(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to test whether the SecurityManager has been initialized.
|
||||||
|
* Possible by a call to @ref btle_initializeSecurity().
|
||||||
|
*
|
||||||
|
* @return True if the SecurityManager was previously initialized, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
bool btle_hasInitializedSecurity(void);
|
bool btle_hasInitializedSecurity(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function to test whether a BLE address is generated using an IRK.
|
||||||
|
*
|
||||||
|
* @param[in] p_addr
|
||||||
|
* Pointer to a BLE address.
|
||||||
|
* @param[in] p_irk
|
||||||
|
* Pointer to an IRK.
|
||||||
|
*
|
||||||
|
* @return True if p_addr can be generated using p_irk, false otherwise.
|
||||||
|
*/
|
||||||
bool btle_matchAddressAndIrk(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_irk);
|
bool btle_matchAddressAndIrk(ble_gap_addr_t const * p_addr, ble_gap_irk_t const * p_irk);
|
||||||
|
|
||||||
#endif /* _BTLE_SECURITY_H_ */
|
#endif /* _BTLE_SECURITY_H_ */
|
||||||
|
|
|
@ -79,13 +79,28 @@ private:
|
||||||
nRF5xSecurityManager(const nRF5xSecurityManager &);
|
nRF5xSecurityManager(const nRF5xSecurityManager &);
|
||||||
const nRF5xSecurityManager& operator=(const nRF5xSecurityManager &);
|
const nRF5xSecurityManager& operator=(const nRF5xSecurityManager &);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Expose an interface that allows us to query the SoftDevice bond table
|
||||||
|
* and extract a whitelist.
|
||||||
|
*/
|
||||||
ble_error_t createWhitelistFromBondTable(ble_gap_whitelist_t &whitelistFromBondTable) const {
|
ble_error_t createWhitelistFromBondTable(ble_gap_whitelist_t &whitelistFromBondTable) const {
|
||||||
return btle_createWhitelistFromBondTable(&whitelistFromBondTable);
|
return btle_createWhitelistFromBondTable(&whitelistFromBondTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Given a BLE address and a IRK this function check whether the address
|
||||||
|
* can be generated from the IRK. To do so, this function uses the hash
|
||||||
|
* function and algorithm described in the Bluetooth low Energy
|
||||||
|
* Specification. Internally, Nordic SDK functions are used.
|
||||||
|
*/
|
||||||
bool matchAddressAndIrk(ble_gap_addr_t *address, ble_gap_irk_t *irk) const {
|
bool matchAddressAndIrk(ble_gap_addr_t *address, ble_gap_irk_t *irk) const {
|
||||||
return btle_matchAddressAndIrk(address, irk);
|
return btle_matchAddressAndIrk(address, irk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Give nRF5xGap access to createWhitelistFromBondTable() and
|
||||||
|
* matchAddressAndIrk()
|
||||||
|
*/
|
||||||
friend class nRF5xGap;
|
friend class nRF5xGap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue