Skip to content

Commit

Permalink
Merge pull request stm32duino#52 from elle-bi/main
Browse files Browse the repository at this point in the history
Add API to get random address
  • Loading branch information
cparata authored Mar 15, 2023
2 parents 616f2fb + 240590a commit 02fd64f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 02fd64f

Please sign in to comment.