Add NimBLEDevice::setOwnAddr and NimBLEUtils::generateAddr functions.

Adds a utility to generate random BLE addresses and set the address used.
This commit is contained in:
h2zero
2024-11-02 18:46:04 -06:00
committed by h2zero
parent a2fe5b4780
commit 68b82f5b85
4 changed files with 48 additions and 0 deletions
+26
View File
@@ -1004,6 +1004,32 @@ bool NimBLEDevice::setOwnAddrType(uint8_t type) {
return rc == 0;
} // setOwnAddrType
/**
* @brief Set the device address to use.
* @param [in] addr The address to set.
* @return True if the address was set successfully.
* @details To use the address generated the address type must be set to random with `setOwnAddrType`.
*/
bool NimBLEDevice::setOwnAddr(const NimBLEAddress& addr) {
return setOwnAddr(addr.getBase()->val);
} // setOwnAddr
/**
* @brief Set the device address to use.
* @param [in] addr The address to set.
* @return True if the address was set successfully.
* @details To use the address generated the address type must be set to random with `setOwnAddrType`.
*/
bool NimBLEDevice::setOwnAddr(const uint8_t* addr) {
int rc = ble_hs_id_set_rnd(addr);
if (rc != 0) {
NIMBLE_LOGE(LOG_TAG, "Failed to set address, rc=%d", rc);
return false;
}
return true;
} // setOwnAddr
/* -------------------------------------------------------------------------- */
/* SECURITY */
/* -------------------------------------------------------------------------- */