From 886106d68647b89e52825bb75fb51ba4a0ee846b Mon Sep 17 00:00:00 2001 From: WhyKickAmooCow Date: Sun, 21 Apr 2019 13:53:19 +1200 Subject: [PATCH] Implemented ability to change BLE address Implemented the ability to change the ESP32s BLE device address as according the the BLE specification. This address is used when advertising the ESP32 over BLE. --- libraries/BLE/src/BLEAdvertising.cpp | 21 +++++++++++++++++++++ libraries/BLE/src/BLEAdvertising.h | 1 + 2 files changed, 22 insertions(+) diff --git a/libraries/BLE/src/BLEAdvertising.cpp b/libraries/BLE/src/BLEAdvertising.cpp index aa96baa44cd..84416afb63c 100644 --- a/libraries/BLE/src/BLEAdvertising.cpp +++ b/libraries/BLE/src/BLEAdvertising.cpp @@ -253,6 +253,27 @@ void BLEAdvertising::stop() { log_v("<< stop"); } // stop +/** + * @brief Set BLE address. + * @param [in] Bluetooth address. + * @param [in] Bluetooth address type. + * Set BLE address. + */ + +void BLEAdvertising::setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type) +{ + log_v(">> setPrivateAddress") + + m_advParams.own_addr_type = type; + esp_err_t errRc = esp_ble_gap_set_rand_addr((uint8_t*)addr); + if (errRc != ESP_OK) + { + log_e("esp_ble_gap_set_rand_addr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc)); + return; + } + log_v("<< setPrivateAddress") +} // setPrivateAddress + /** * @brief Add data to the payload to be advertised. * @param [in] data The data to be added to the payload. diff --git a/libraries/BLE/src/BLEAdvertising.h b/libraries/BLE/src/BLEAdvertising.h index 3128b50f1e3..be85371ec64 100644 --- a/libraries/BLE/src/BLEAdvertising.h +++ b/libraries/BLE/src/BLEAdvertising.h @@ -58,6 +58,7 @@ class BLEAdvertising { void setScanFilter(bool scanRequertWhitelistOnly, bool connectWhitelistOnly); void setScanResponseData(BLEAdvertisementData& advertisementData); void setPrivateAddress(esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM); + void setDeviceAddress(esp_bd_addr_t addr, esp_ble_addr_type_t type = BLE_ADDR_TYPE_RANDOM); void handleGAPEvent(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t* param); void setMinPreferred(uint16_t);