From 304770a0844a90b1b553125a0ff4ccb43df7351b Mon Sep 17 00:00:00 2001 From: h2zero Date: Sat, 14 Dec 2024 13:11:36 -0700 Subject: [PATCH] [BREAKING] Remove NimBLEAddress type default value. When constructing a NimBLEAddress via string or other non `ble_addr_t` parameters it is important that the address type be specified. This will help prevent issues where applications are not able to connect or identify scanned devices when comparing their addresses. --- src/NimBLEAddress.cpp | 12 +++++++++--- src/NimBLEAddress.h | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/NimBLEAddress.cpp b/src/NimBLEAddress.cpp index 2e6cea01..e1f33a17 100644 --- a/src/NimBLEAddress.cpp +++ b/src/NimBLEAddress.cpp @@ -45,7 +45,9 @@ NimBLEAddress::NimBLEAddress(ble_addr_t address) : ble_addr_t{address} {} * ``` * which is 17 characters in length. * @param [in] addr The hex string representation of the address. - * @param [in] type The type of the address. + * @param [in] type The type of the address, should be one of: + * * BLE_ADDR_PUBLIC (0) + * * BLE_ADDR_RANDOM (1) */ NimBLEAddress::NimBLEAddress(const std::string& addr, uint8_t type) { this->type = type; @@ -70,7 +72,9 @@ NimBLEAddress::NimBLEAddress(const std::string& addr, uint8_t type) { /** * @brief Constructor for compatibility with bluedroid esp library using native ESP representation. * @param [in] address A uint8_t[6] or esp_bd_addr_t containing the address. - * @param [in] type The type of the address. + * @param [in] type The type of the address should be one of: + * * BLE_ADDR_PUBLIC (0) + * * BLE_ADDR_RANDOM (1) */ NimBLEAddress::NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type) { std::reverse_copy(address, address + BLE_DEV_ADDR_LEN, this->val); @@ -81,7 +85,9 @@ NimBLEAddress::NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t ty * @brief Constructor for address using a hex value.\n * Use the same byte order, so use 0xa4c1385def16 for "a4:c1:38:5d:ef:16" * @param [in] address uint64_t containing the address. - * @param [in] type The type of the address. + * @param [in] type The type of the address should be one of: + * * BLE_ADDR_PUBLIC (0) + * * BLE_ADDR_RANDOM (1) */ NimBLEAddress::NimBLEAddress(const uint64_t& address, uint8_t type) { memcpy(this->val, &address, sizeof this->val); diff --git a/src/NimBLEAddress.h b/src/NimBLEAddress.h index a1eebac8..5f78c610 100644 --- a/src/NimBLEAddress.h +++ b/src/NimBLEAddress.h @@ -45,9 +45,9 @@ class NimBLEAddress : private ble_addr_t { */ NimBLEAddress() = default; NimBLEAddress(const ble_addr_t address); - NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type = BLE_ADDR_PUBLIC); - NimBLEAddress(const std::string& stringAddress, uint8_t type = BLE_ADDR_PUBLIC); - NimBLEAddress(const uint64_t& address, uint8_t type = BLE_ADDR_PUBLIC); + NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type); + NimBLEAddress(const std::string& stringAddress, uint8_t type); + NimBLEAddress(const uint64_t& address, uint8_t type); bool isRpa() const; bool isNrpa() const;