Skip to content

Commit c6e7932

Browse files
cparatafpistm
authored andcommitted
feat: add possibility to choose the ownAddressType in the Arduino stack
Signed-off-by: Carlo Parata <[email protected]>
1 parent c6082cd commit c6e7932

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

src/local/BLELocalDevice.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#endif
4040
#endif
4141

42-
BLELocalDevice::BLELocalDevice()
42+
BLELocalDevice::BLELocalDevice(uint8_t ownBdaddrType): _ownBdaddrType(ownBdaddrType)
4343
{
4444
_advertisingData.setFlags(BLEFlagsGeneralDiscoverable | BLEFlagsBREDRNotSupported);
4545
}
@@ -207,6 +207,10 @@ int BLELocalDevice::begin()
207207

208208
GATT.begin();
209209

210+
GAP.setOwnBdaddrType(_ownBdaddrType);
211+
212+
ATT.setOwnBdaddrType(_ownBdaddrType);
213+
210214
return 1;
211215
}
212216

src/local/BLELocalDevice.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ enum Pairable {
3030
ONCE = 2,
3131
};
3232

33+
enum AddressType {
34+
PUBLIC_ADDR = 0,
35+
STATIC_RANDOM_ADDR = 1,
36+
RESOLVABLE_PRIVATE_ADDR = 2,
37+
NON_RESOLVABLE_PRIVATE_ADDR = 3,
38+
};
39+
3340
class BLELocalDevice {
3441
public:
35-
BLELocalDevice();
42+
BLELocalDevice(uint8_t ownBdaddrType = STATIC_RANDOM_ADDR);
3643
virtual ~BLELocalDevice();
3744

3845
virtual int begin();
@@ -107,6 +114,7 @@ class BLELocalDevice {
107114

108115
virtual void setDisplayCode(void (*displayCode)(uint32_t confirmationCode));
109116
virtual void setBinaryConfirmPairing(bool (*binaryConfirmPairing)());
117+
110118
uint8_t BDaddress[6];
111119

112120
protected:
@@ -116,6 +124,7 @@ class BLELocalDevice {
116124
private:
117125
BLEAdvertisingData _advertisingData;
118126
BLEAdvertisingData _scanResponseData;
127+
uint8_t _ownBdaddrType;
119128
};
120129

121130
extern BLELocalDevice& BLE;

src/utility/ATT.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ATTClass::~ATTClass()
114114

115115
bool ATTClass::connect(uint8_t peerBdaddrType, uint8_t peerBdaddr[6])
116116
{
117-
if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, 0x00,
117+
if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, _ownBdaddrType,
118118
0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006) != 0) {
119119
return false;
120120
}
@@ -1957,6 +1957,16 @@ int ATTClass::getPeerResolvedAddress(uint16_t connectionHandle, uint8_t resolved
19571957
return 0;
19581958
}
19591959

1960+
void ATTClass::setOwnBdaddrType(uint8_t ownBdaddrType)
1961+
{
1962+
_ownBdaddrType = ownBdaddrType;
1963+
}
1964+
1965+
uint8_t ATTClass::getOwnBdaddrType(void)
1966+
{
1967+
return _ownBdaddrType;
1968+
}
1969+
19601970
#if !defined(FAKE_ATT)
19611971
ATTClass ATTObj;
19621972
ATTClass& ATT = ATTObj;

src/utility/ATT.h

+6
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ class ATTClass {
109109
uint8_t peerIRK[16];
110110
/// This is just a random number... Not sure it has use unless privacy mode is active.
111111
uint8_t localIRK[16] = {0x54,0x83,0x63,0x7c,0xc5,0x1e,0xf7,0xec,0x32,0xdd,0xad,0x51,0x89,0x4b,0x9e,0x07};
112+
113+
void setOwnBdaddrType(uint8_t ownBdaddrType);
114+
uint8_t getOwnBdaddrType(); // Used in L2CAPSignaling to encryption
115+
112116
private:
113117
virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]);
114118
virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]);
@@ -170,6 +174,8 @@ class ATTClass {
170174
} _pendingResp;
171175

172176
BLEDeviceEventHandler _eventHandlers[2];
177+
178+
uint8_t _ownBdaddrType;
173179
};
174180

175181
extern ATTClass& ATT;

src/utility/GAP.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int GAPClass::advertise(uint8_t* advData, uint8_t advDataLen, uint8_t* scanData,
5454

5555
stopAdvertise();
5656

57-
if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, 0x00, 0x00, directBdaddr, 0x07, 0) != 0) {
57+
if (HCI.leSetAdvertisingParameters(_advertisingInterval, _advertisingInterval, type, _ownBdaddrType, 0x00, directBdaddr, 0x07, 0) != 0) {
5858
return 0;
5959
}
6060

@@ -93,7 +93,7 @@ int GAPClass::scan(bool withDuplicates)
9393
- scan window: mandatory range from 0x0011 to 0x1000
9494
- The scan window can only be less than or equal to the scan interval
9595
*/
96-
if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, 0x00, 0x00) != 0) {
96+
if (HCI.leSetScanParameters(0x01, 0x0020, 0x0020, _ownBdaddrType, 0x00) != 0) {
9797
return false;
9898
}
9999

@@ -266,6 +266,11 @@ bool GAPClass::matchesScanFilter(const BLEDevice& device)
266266
return true;
267267
}
268268

269+
void GAPClass::setOwnBdaddrType(uint8_t ownBdaddrType)
270+
{
271+
_ownBdaddrType = ownBdaddrType;
272+
}
273+
269274
#if !defined(FAKE_GAP)
270275
GAPClass GAPObj;
271276
GAPClass& GAP = GAPObj;

src/utility/GAP.h

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class GAPClass {
4545

4646
virtual void setEventHandler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler);
4747

48+
void setOwnBdaddrType(uint8_t ownBdaddrType);
49+
4850
protected:
4951
friend class HCIClass;
5052

@@ -67,6 +69,7 @@ class GAPClass {
6769
String _scanNameFilter;
6870
String _scanUuidFilter;
6971
String _scanAddressFilter;
72+
uint8_t _ownBdaddrType;
7073
};
7174

7275
extern GAPClass& GAP;

0 commit comments

Comments
 (0)