Skip to content

Commit ecaacea

Browse files
Pull request project-chip#1796: Update matter support pointer to main
Merge in WMN_TOOLS/matter from feature/update_matter_support to RC_2.3.0-1.3 Squashed commit of the following: commit 3e0dd4c3076d244545844a7d330e4ec31e16b02b Author: Mathieu Kardous <mathieu.kardous@silabs.com> Date: Mon Apr 29 12:33:53 2024 -0400 Update matter support pointer to main commit 5a170da155b4170c80d4d0ce2b1e8b254eeac7f2 Author: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Wed Apr 17 18:25:20 2024 -0500 [Silabs] Change BLE address from random resolvable address to random static address (project-chip#33035) * Change BLE address from random resolvable address to static address * add comment * Replace lambda function with memcmp
1 parent 3475f0f commit ecaacea

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/platform/silabs/efr32/BLEManagerImpl.cpp

+26-11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ extern "C" {
4040
#include "sl_bt_stack_init.h"
4141
#include "timers.h"
4242
#include <ble/CHIPBleServiceData.h>
43+
#include <crypto/RandUtils.h>
44+
#include <cstring>
4345
#include <lib/support/CodeUtils.h>
4446
#include <lib/support/logging/CHIPLogging.h>
4547
#include <platform/CommissionableDataProvider.h>
@@ -109,17 +111,16 @@ const ChipBleUUID ChipUUID_CHIPoBLEChar_RX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0
109111
const ChipBleUUID ChipUUID_CHIPoBLEChar_TX = { { 0x18, 0xEE, 0x2E, 0xF5, 0x26, 0x3D, 0x45, 0x59, 0x95, 0x9F, 0x4F, 0x9C, 0x42, 0x9F,
110112
0x9D, 0x12 } };
111113

114+
bd_addr randomizedAddr = { 0 };
115+
112116
} // namespace
113117

114118
BLEManagerImpl BLEManagerImpl::sInstance;
115119

116120
CHIP_ERROR BLEManagerImpl::_Init()
117121
{
118-
CHIP_ERROR err;
119-
120122
// Initialize the CHIP BleLayer.
121-
err = BleLayer::Init(this, this, &DeviceLayer::SystemLayer());
122-
SuccessOrExit(err);
123+
ReturnErrorOnFailure(BleLayer::Init(this, this, &DeviceLayer::SystemLayer()));
123124

124125
memset(mBleConnections, 0, sizeof(mBleConnections));
125126
memset(mIndConfId, kUnusedIndex, sizeof(mIndConfId));
@@ -135,10 +136,23 @@ CHIP_ERROR BLEManagerImpl::_Init()
135136

136137
mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
137138
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
138-
PlatformMgr().ScheduleWork(DriveBLEState, 0);
139139

140-
exit:
141-
return err;
140+
// Check that an address was not already configured at boot.
141+
// This covers the init-shutdown-init case to comply with the BLE address change at boot only requirement
142+
bd_addr temp = { 0 };
143+
if (memcmp(&randomizedAddr, &temp, sizeof(bd_addr)) == 0)
144+
{
145+
// Since a random address is not configured, configure one
146+
uint64_t random = Crypto::GetRandU64();
147+
// Copy random value to address. We don't care of the ordering since it's a random value.
148+
memcpy(&randomizedAddr, &random, sizeof(randomizedAddr));
149+
150+
// Set two MSBs to 11 to properly the address - BLE Static Device Address requirement
151+
randomizedAddr.addr[5] |= 0xC0;
152+
}
153+
154+
PlatformMgr().ScheduleWork(DriveBLEState, 0);
155+
return CHIP_NO_ERROR;
142156
}
143157

144158
uint16_t BLEManagerImpl::_NumConnections(void)
@@ -487,14 +501,13 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
487501
ChipLogError(DeviceLayer, "sl_bt_advertiser_create_set() failed: %s", ErrorStr(err));
488502
});
489503

490-
bd_addr randomizedAddr = {};
491-
ret = sl_bt_advertiser_set_random_address(advertising_set_handle, sl_bt_gap_random_resolvable_address, randomizedAddr,
492-
&randomizedAddr);
504+
ret =
505+
sl_bt_advertiser_set_random_address(advertising_set_handle, sl_bt_gap_static_address, randomizedAddr, &randomizedAddr);
493506
VerifyOrExit(ret == SL_STATUS_OK, {
494507
err = MapBLEError(ret);
495508
ChipLogError(DeviceLayer, "sl_bt_advertiser_set_random_address() failed: %s", ErrorStr(err));
496509
});
497-
ChipLogDetail(DeviceLayer, "BLE Resolvable private random address %02X:%02X:%02X:%02X:%02X:%02X", randomizedAddr.addr[5],
510+
ChipLogDetail(DeviceLayer, "BLE Static Device Address %02X:%02X:%02X:%02X:%02X:%02X", randomizedAddr.addr[5],
498511
randomizedAddr.addr[4], randomizedAddr.addr[3], randomizedAddr.addr[2], randomizedAddr.addr[1],
499512
randomizedAddr.addr[0]);
500513
}
@@ -628,6 +641,8 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
628641
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
629642

630643
ret = sl_bt_advertiser_stop(advertising_set_handle);
644+
sl_bt_advertiser_clear_random_address(advertising_set_handle);
645+
631646
sl_bt_advertiser_delete_set(advertising_set_handle);
632647
advertising_set_handle = 0xff;
633648
err = MapBLEError(ret);

third_party/silabs/matter_support

Submodule matter_support updated 42 files

0 commit comments

Comments
 (0)