Skip to content

Commit c1c7d1a

Browse files
committed
Add the possibility to choose the ownAddressType in the Arduino stack
1 parent d1535a0 commit c1c7d1a

File tree

6 files changed

+34
-7
lines changed

6 files changed

+34
-7
lines changed

Diff for: src/local/BLELocalDevice.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "utility/L2CAPSignaling.h"
2424
#include "BLELocalDevice.h"
2525

26-
BLELocalDevice::BLELocalDevice(HCITransportInterface *HCITransport) :
27-
_HCITransport(HCITransport)
26+
BLELocalDevice::BLELocalDevice(HCITransportInterface *HCITransport, uint8_t ownBdaddrType) :
27+
_HCITransport(HCITransport), _ownBdaddrType(ownBdaddrType)
2828
{
2929
_advertisingData.setFlags(BLEFlagsGeneralDiscoverable | BLEFlagsBREDRNotSupported);
3030
}
@@ -76,6 +76,10 @@ int BLELocalDevice::begin()
7676

7777
GATT.begin();
7878

79+
GAP.setOwnBdaddrType(_ownBdaddrType);
80+
81+
ATT.setOwnBdaddrType(_ownBdaddrType);
82+
7983
return 1;
8084
}
8185

Diff for: src/local/BLELocalDevice.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525
#include "BLEService.h"
2626
#include "BLEAdvertisingData.h"
2727

28+
#define PUBLIC_ADDR (0)
29+
#define STATIC_RANDOM_ADDR (1)
30+
#define RESOLVABLE_PRIVATE_ADDR (2)
31+
#define NON_RESOLVABLE_PRIVATE_ADDR (3)
32+
2833
class BLELocalDevice {
2934
public:
30-
BLELocalDevice(HCITransportInterface *HCITransport);
35+
BLELocalDevice(HCITransportInterface *HCITransport, uint8_t ownBdaddrType = STATIC_RANDOM_ADDR);
3136
virtual ~BLELocalDevice();
3237

3338
virtual int begin();
@@ -90,6 +95,7 @@ class BLELocalDevice {
9095
HCITransportInterface *_HCITransport;
9196
BLEAdvertisingData _advertisingData;
9297
BLEAdvertisingData _scanResponseData;
98+
uint8_t _ownBdaddrType;
9399
};
94100

95101
extern BLELocalDevice& BLE;

Diff for: src/utility/ATT.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ ATTClass::~ATTClass()
109109

110110
bool ATTClass::connect(uint8_t peerBdaddrType, uint8_t peerBdaddr[6])
111111
{
112-
if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, 0x00,
112+
if (HCI.leCreateConn(0x0060, 0x0030, 0x00, peerBdaddrType, peerBdaddr, _ownBdaddrType,
113113
0x0006, 0x000c, 0x0000, 0x00c8, 0x0004, 0x0006) != 0) {
114114
return false;
115115
}
@@ -1688,6 +1688,11 @@ void ATTClass::writeCmd(uint16_t connectionHandle, uint16_t handle, const uint8_
16881688
sendReq(connectionHandle, &writeReq, 3 + dataLen, NULL);
16891689
}
16901690

1691+
void ATTClass::setOwnBdaddrType(uint8_t ownBdaddrType)
1692+
{
1693+
_ownBdaddrType = ownBdaddrType;
1694+
}
1695+
16911696
#if !defined(FAKE_ATT)
16921697
ATTClass ATTObj;
16931698
ATTClass& ATT = ATTObj;

Diff for: src/utility/ATT.h

+4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class ATTClass {
7777
virtual int writeReq(uint16_t connectionHandle, uint16_t handle, const uint8_t* data, uint8_t dataLen, uint8_t responseBuffer[]);
7878
virtual void writeCmd(uint16_t connectionHandle, uint16_t handle, const uint8_t* data, uint8_t dataLen);
7979

80+
void setOwnBdaddrType(uint8_t ownBdaddrType);
81+
8082
private:
8183
virtual void error(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]);
8284
virtual void mtuReq(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]);
@@ -135,6 +137,8 @@ class ATTClass {
135137
} _pendingResp;
136138

137139
BLEDeviceEventHandler _eventHandlers[2];
140+
141+
uint8_t _ownBdaddrType;
138142
};
139143

140144
extern ATTClass& ATT;

Diff for: src/utility/GAP.cpp

+8-3
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

@@ -91,8 +91,8 @@ int GAPClass::scan(bool withDuplicates)
9191
}
9292
}
9393

94-
// active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public own address type, no filter
95-
if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, 0x00, 0x00) != 0) {
94+
// active scan, 10 ms scan interval (N * 0.625), 10 ms scan window (N * 0.625), public or static random own address type, no filter
95+
if (HCI.leSetScanParameters(0x01, 0x0010, 0x0010, _ownBdaddrType, 0x00) != 0) {
9696
return false;
9797
}
9898

@@ -270,6 +270,11 @@ bool GAPClass::matchesScanFilter(const BLEDevice& device)
270270
return true;
271271
}
272272

273+
void GAPClass::setOwnBdaddrType(uint8_t ownBdaddrType)
274+
{
275+
_ownBdaddrType = ownBdaddrType;
276+
}
277+
273278
#if !defined(FAKE_GAP)
274279
GAPClass GAPObj;
275280
GAPClass& GAP = GAPObj;

Diff for: 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)