Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AresMaster committed Oct 31, 2023
2 parents 81dd688 + 2019736 commit 578fdb6
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 366 deletions.
5 changes: 0 additions & 5 deletions src/STM32duinoBLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,4 @@
#endif
#include "utility/HCISpiTransport.h"

#if defined(STM32WBxx)
#include "utility/HCISharedMemTransport.h"
#endif
#include "utility/HCISpiTransport.h"

#endif
28 changes: 21 additions & 7 deletions src/local/BLELocalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ int BLELocalDevice::begin()
return 0;
}

uint8_t randomNumber[8] = {0x00,0x80,0xe1,0x27,0xa3,0x30,0,0};
/*if (HCI.leRand(randomNumber) != 0) {
uint8_t randomNumber[8];
if (HCI.leRand(randomNumber) != 0) {
end();
return 0;
}*/
}
/* Random address only requires 6 bytes (48 bits)
* Force both MSB bits to b00 in order to define Static Random Address
*/
//randomNumber[5] |= 0xC0;
randomNumber[5] |= 0xC0;

// Copy the random address in private variable as it will be sent to the BLE chip
randomAddress [0] = randomNumber[0];
Expand All @@ -68,11 +68,19 @@ int BLELocalDevice::begin()
randomAddress [3] = randomNumber[3];
randomAddress [4] = randomNumber[4];
randomAddress [5] = randomNumber[5];

if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) {
// @note Set Random address only when type is STATIC_RANDOM_ADDR
if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0 && _ownBdaddrType == STATIC_RANDOM_ADDR) {
end();
return 0;
}
// @note Save address to HCI.localaddress variable, which is used to encryption in pairing
if(_ownBdaddrType == PUBLIC_ADDR){
HCI.readBdAddr();
}else{
for(int k=0; k<6; k++){
HCI.localAddr[5-k] = randomAddress[k];
}
}

uint8_t hciVer;
uint16_t hciRev;
Expand Down Expand Up @@ -216,7 +224,13 @@ bool BLELocalDevice::disconnect()
String BLELocalDevice::address() const
{
uint8_t addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
HCI.readBdAddr(addr);
// @note return correct device address when is set to STATIC RANDOM (set by HCI)
if(_ownBdaddrType==PUBLIC_ADDR)
HCI.readBdAddr(addr);
else
for(int k=0; k<6; k++){
addr[k]=HCI.localAddr[5-k];
}

char result[18];
sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x", addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/local/BLELocalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum Pairable {

class BLELocalDevice {
public:
BLELocalDevice(HCITransportInterface *HCITransport, uint8_t ownBdaddrType = PUBLIC_ADDR);
BLELocalDevice(HCITransportInterface *HCITransport, uint8_t ownBdaddrType = STATIC_RANDOM_ADDR);
virtual ~BLELocalDevice();

virtual int begin();
Expand Down
5 changes: 1 addition & 4 deletions src/utility/ATT.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ class ATTClass {
uint8_t localIRK[16] = {0x54,0x83,0x63,0x7c,0xc5,0x1e,0xf7,0xec,0x32,0xdd,0xad,0x51,0x89,0x4b,0x9e,0x07};

void setOwnBdaddrType(uint8_t ownBdaddrType);

uint8_t _ownBdaddrType;

uint8_t _ownBdaddrType; //@note Used in L2CAPSignaling to encryption
private:
virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]);
virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]);
Expand Down Expand Up @@ -175,7 +173,6 @@ class ATTClass {
} _pendingResp;

BLEDeviceEventHandler _eventHandlers[2];

};

extern ATTClass& ATT;
Expand Down
142 changes: 0 additions & 142 deletions src/utility/HCIVirtualTransport.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions src/utility/HCIVirtualTransport.h

This file was deleted.

Loading

0 comments on commit 578fdb6

Please sign in to comment.