Skip to content

Commit 1214522

Browse files
shgutterestyled-commits
authored andcommitted
[Silabs] [EFR32] Random BLE address changes on every boot for RS9116 and 917 SoC BLE (#26518)
* Added chnages for ble random address * Added changes for genrating random number on every boot * Restyled by clang-format * Adds changes for random number and resolved comment * removed the additional logic for random number genrator * Restyled by clang-format * Added changes for the ble address lenght * Adds changes for advertisement minimum and maximum value * Adds chnages for the random address genration for BLE * changed the name of the BLE address variable * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent dd895cf commit 1214522

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/platform/silabs/BLEManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
7272
void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId);
7373
void HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt);
7474
void HandleSoftTimerEvent(void);
75+
int32_t SendBLEAdvertisementCommand(void);
7576
#else
7677
void HandleConnectEvent(volatile sl_bt_msg_t * evt);
7778
void HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt);

src/platform/silabs/rs911x/BLEManagerImpl.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#ifndef SIWX_917
3232
#include "rail.h"
3333
#endif
34-
34+
#include <crypto/RandUtils.h>
3535
#ifdef __cplusplus
3636
extern "C" {
3737
#endif
@@ -77,6 +77,8 @@ using namespace ::chip::DeviceLayer::Internal;
7777

7878
void sl_ble_init()
7979
{
80+
uint8_t randomAddrBLE[6] = { 0 };
81+
uint64_t randomAddr = chip::Crypto::GetRandU64();
8082

8183
// registering the GAP callback functions
8284
rsi_ble_gap_register_callbacks(NULL, NULL, rsi_ble_on_disconnect_event, NULL, NULL, NULL, rsi_ble_on_enhance_conn_status_event,
@@ -88,10 +90,13 @@ void sl_ble_init()
8890
rsi_ble_on_event_indication_confirmation, NULL);
8991

9092
// Exchange of GATT info with BLE stack
93+
9194
rsi_ble_add_matter_service();
9295

9396
// initializing the application events map
9497
rsi_ble_app_init_events();
98+
memcpy(randomAddrBLE, &randomAddr, 6);
99+
rsi_ble_set_random_address_with_value(randomAddrBLE);
95100
chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent();
96101
}
97102

@@ -621,8 +626,8 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
621626
sl_wfx_mac_address_t macaddr;
622627
wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &macaddr);
623628

624-
//! Set local name
625-
status = rsi_ble_start_advertising();
629+
status = sInstance.SendBLEAdvertisementCommand();
630+
626631
if (status == RSI_SUCCESS)
627632
{
628633
ChipLogProgress(DeviceLayer, "rsi_ble_start_advertising Success");
@@ -643,6 +648,24 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
643648
return CHIP_NO_ERROR; // err;
644649
}
645650

651+
int32_t BLEManagerImpl::SendBLEAdvertisementCommand(void)
652+
{
653+
654+
rsi_ble_req_adv_t ble_adv = { 0 };
655+
656+
ble_adv.status = RSI_BLE_START_ADV;
657+
658+
ble_adv.adv_type = RSI_BLE_ADV_TYPE;
659+
ble_adv.filter_type = RSI_BLE_ADV_FILTER_TYPE;
660+
ble_adv.direct_addr_type = RSI_BLE_ADV_DIR_ADDR_TYPE;
661+
rsi_ascii_dev_address_to_6bytes_rev(ble_adv.direct_addr, (int8_t *) RSI_BLE_ADV_DIR_ADDR);
662+
ble_adv.adv_int_min = RSI_BLE_ADV_INT_MIN;
663+
ble_adv.adv_int_max = RSI_BLE_ADV_INT_MAX;
664+
ble_adv.own_addr_type = LE_RANDOM_ADDRESS;
665+
ble_adv.adv_channel_map = RSI_BLE_ADV_CHANNEL_MAP;
666+
return rsi_ble_start_advertising_with_values(&ble_adv);
667+
}
668+
646669
// TODO:: Implementation need to be done.
647670
CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
648671
{

0 commit comments

Comments
 (0)