From 70dab0e5152a41df91f15142d60e6cbaa6c3bc1a Mon Sep 17 00:00:00 2001 From: shgutte <102281713+shgutte@users.noreply.github.com> Date: Fri, 19 May 2023 21:22:12 +0530 Subject: [PATCH] [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 --- src/platform/silabs/BLEManagerImpl.h | 1 + src/platform/silabs/rs911x/BLEManagerImpl.cpp | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index da6ce3bb4e3002..12e5c7c294ed14 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -72,6 +72,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla void HandleTxConfirmationEvent(BLE_CONNECTION_OBJECT conId); void HandleTXCharCCCDWrite(rsi_ble_event_write_t * evt); void HandleSoftTimerEvent(void); + int32_t SendBLEAdvertisementCommand(void); #else void HandleConnectEvent(volatile sl_bt_msg_t * evt); void HandleConnectionCloseEvent(volatile sl_bt_msg_t * evt); diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 3b908b05275d91..5719b816b95676 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -31,7 +31,7 @@ #ifndef SIWX_917 #include "rail.h" #endif - +#include #ifdef __cplusplus extern "C" { #endif @@ -77,6 +77,8 @@ using namespace ::chip::DeviceLayer::Internal; void sl_ble_init() { + uint8_t randomAddrBLE[6] = { 0 }; + uint64_t randomAddr = chip::Crypto::GetRandU64(); // registering the GAP callback functions 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() rsi_ble_on_event_indication_confirmation, NULL); // Exchange of GATT info with BLE stack + rsi_ble_add_matter_service(); // initializing the application events map rsi_ble_app_init_events(); + memcpy(randomAddrBLE, &randomAddr, 6); + rsi_ble_set_random_address_with_value(randomAddrBLE); chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent(); } @@ -621,8 +626,8 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) sl_wfx_mac_address_t macaddr; wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &macaddr); - //! Set local name - status = rsi_ble_start_advertising(); + status = sInstance.SendBLEAdvertisementCommand(); + if (status == RSI_SUCCESS) { ChipLogProgress(DeviceLayer, "rsi_ble_start_advertising Success"); @@ -643,6 +648,24 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) return CHIP_NO_ERROR; // err; } +int32_t BLEManagerImpl::SendBLEAdvertisementCommand(void) +{ + + rsi_ble_req_adv_t ble_adv = { 0 }; + + ble_adv.status = RSI_BLE_START_ADV; + + ble_adv.adv_type = RSI_BLE_ADV_TYPE; + ble_adv.filter_type = RSI_BLE_ADV_FILTER_TYPE; + ble_adv.direct_addr_type = RSI_BLE_ADV_DIR_ADDR_TYPE; + rsi_ascii_dev_address_to_6bytes_rev(ble_adv.direct_addr, (int8_t *) RSI_BLE_ADV_DIR_ADDR); + ble_adv.adv_int_min = RSI_BLE_ADV_INT_MIN; + ble_adv.adv_int_max = RSI_BLE_ADV_INT_MAX; + ble_adv.own_addr_type = LE_RANDOM_ADDRESS; + ble_adv.adv_channel_map = RSI_BLE_ADV_CHANNEL_MAP; + return rsi_ble_start_advertising_with_values(&ble_adv); +} + // TODO:: Implementation need to be done. CHIP_ERROR BLEManagerImpl::StopAdvertising(void) {