Skip to content

Commit b247a35

Browse files
committed
feat(gfps_service): Update GFPS to support use of random addreses
* Remove address change implementation from gfps_service, since it is not needed and may constrain application flexibility / design * Update `nearby_platform_GetBleAddress()` to return the random address directly from NimBLE, for applications which support random addresses
1 parent 67b180a commit b247a35

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

components/gfps_service/src/nearby_ble.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
static espp::Logger logger({.tag = "GFPS BLE", .level = espp::gfps::LOG_LEVEL});
44

5+
#include "host/ble_hs.h"
6+
57
static std::vector<uint8_t> REMOTE_PUBLIC_KEY(64, 0);
68

79
static const nearby_platform_BleInterface *g_ble_interface = nullptr;
@@ -92,7 +94,14 @@ int espp::gfps::ble_gap_event_handler(ble_gap_event *event, void *arg) {
9294
uint64_t nearby_platform_GetBleAddress() {
9395
// get the mac address of the radio
9496
#if CONFIG_BT_NIMBLE_ENABLED
95-
auto address = uint64_t(NimBLEDevice::getAddress());
97+
// explicitly get the random address here, since the GetPublicAddress function
98+
// will call NimBLEDevice::getAddress() which will return the public address
99+
uint64_t address = 0;
100+
auto rc = ble_hs_id_copy_addr(BLE_ADDR_RANDOM, (uint8_t *)&address, nullptr);
101+
if (rc != 0) {
102+
logger.error("Failed to get ble address");
103+
return 0;
104+
}
96105
logger.debug("radio mac address: {:#x}", address);
97106
return address;
98107
#else
@@ -105,17 +114,8 @@ uint64_t nearby_platform_GetBleAddress() {
105114
//
106115
// address - BLE address to set.
107116
uint64_t nearby_platform_SetBleAddress(uint64_t address) {
108-
logger.info("SetBleAddress - set to {:#x}", address);
109-
// implement, possibly with esp_iface_mac_addr_set, esp_base_mac_addr_set(),
110-
// or esp_netif_set_mac(). Can use ESP_MAC_BT or ESP_MAC_BASE
111-
112-
// convert the address into an array of bytes
113-
uint8_t addr[6] = {
114-
(uint8_t)((address >> 40) & 0xFF), (uint8_t)((address >> 32) & 0xFF),
115-
(uint8_t)((address >> 24) & 0xFF), (uint8_t)((address >> 16) & 0xFF),
116-
(uint8_t)((address >> 8) & 0xFF), (uint8_t)(address & 0xFF),
117-
};
118-
esp_iface_mac_addr_set(addr, ESP_MAC_BT);
117+
// Since we don't really have to set the requested address, just return the
118+
// current address
119119
return nearby_platform_GetBleAddress();
120120
}
121121

0 commit comments

Comments
 (0)