Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to get random address #52

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/local/BLELocalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ int BLELocalDevice::begin()
* Force both MSB bits to b00 in order to define Static Random Address
*/
randomNumber[5] |= 0xC0;

// Copy the random address in private variable as it will be sent to the BLE chip
randomAddress [0] = randomNumber[0];
randomAddress [1] = randomNumber[1];
randomAddress [2] = randomNumber[2];
randomAddress [3] = randomNumber[3];
randomAddress [4] = randomNumber[4];
randomAddress [5] = randomNumber[5];

if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) {
end();
return 0;
Expand Down Expand Up @@ -105,6 +114,16 @@ void BLELocalDevice::end()
HCI.end();
}

void BLELocalDevice::getRandomAddress(uint8_t buff[6])
{
buff [0] = randomAddress[0];
buff [1] = randomAddress[1];
buff [2] = randomAddress[2];
buff [3] = randomAddress[3];
buff [4] = randomAddress[4];
buff [5] = randomAddress[5];
}

void BLELocalDevice::poll()
{
HCI.poll();
Expand Down
3 changes: 3 additions & 0 deletions src/local/BLELocalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class BLELocalDevice {

virtual void setTimeout(unsigned long timeout);

virtual void getRandomAddress(uint8_t buff[6]);

virtual void debug(Stream& stream);
virtual void noDebug();

Expand All @@ -92,6 +94,7 @@ class BLELocalDevice {
virtual BLEAdvertisingData& getScanResponseData();

private:
uint8_t randomAddress[6];
HCITransportInterface *_HCITransport;
BLEAdvertisingData _advertisingData;
BLEAdvertisingData _scanResponseData;
Expand Down