Skip to content

Commit 7e1fd23

Browse files
AresMasterfpistm
authored andcommitted
fix: for pairing with Static Random Address
Signed-off-by: Arkadiusz Ambroziak <[email protected]> Co-Auhthored-by: Frederic Pillon <[email protected]>
1 parent 88c5167 commit 7e1fd23

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/local/BLELocalDevice.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,22 @@ int BLELocalDevice::begin()
142142
randomAddress [4] = randomNumber[4];
143143
randomAddress [5] = randomNumber[5];
144144

145-
if (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0) {
145+
// Set Random address only when type is STATIC_RANDOM_ADDR
146+
if ((_ownBdaddrType == STATIC_RANDOM_ADDR) && (HCI.leSetRandomAddress((uint8_t*)randomNumber) != 0)) {
146147
end();
147148
return 0;
148149
}
150+
// Save address to HCI.localAddr variable, which is used to encryption in pairing
151+
if(_ownBdaddrType == PUBLIC_ADDR){
152+
if (HCI.readBdAddr() != 0) {
153+
end();
154+
return 0;
155+
}
156+
} else {
157+
for(int k=0; k<6; k++){
158+
HCI.localAddr[5-k] = randomAddress[k];
159+
}
160+
}
149161

150162
uint8_t hciVer;
151163
uint16_t hciRev;
@@ -301,7 +313,14 @@ bool BLELocalDevice::disconnect()
301313
String BLELocalDevice::address() const
302314
{
303315
uint8_t addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
304-
HCI.readBdAddr(addr);
316+
// return correct device address when is set to STATIC RANDOM (set by HCI)
317+
if(_ownBdaddrType == PUBLIC_ADDR) {
318+
HCI.readBdAddr(addr);
319+
} else {
320+
for(int k=0; k<6; k++) {
321+
addr[k]=HCI.localAddr[5-k];
322+
}
323+
}
305324

306325
char result[18];
307326
sprintf(result, "%02x:%02x:%02x:%02x:%02x:%02x", addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);

src/utility/L2CAPSignaling.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,12 @@ void L2CAPSignalingClass::smCalculateLTKandConfirm(uint16_t handle, uint8_t expe
369369
uint8_t localAddress[7];
370370
uint8_t remoteAddress[7];
371371
ATT.getPeerAddrWithType(handle, remoteAddress);
372-
373-
HCI.readBdAddr();
372+
373+
// Address is taken directly from HCI.localaddress,
374+
// which is set when object DeviceLocal is created
375+
// HCI.readBdAddr();
374376
memcpy(&localAddress[1],HCI.localAddr,6);
375-
localAddress[0] = 0; // IOT 33 uses a static address // TODO: confirm for Nano BLE
377+
localAddress[0] = ATT.getOwnBdaddrType(); // Adding bit with address type (e.g. Static random or public address)
376378

377379
// Compute the LTK and MacKey
378380
uint8_t MacKey[16];

0 commit comments

Comments
 (0)