Skip to content

Commit

Permalink
[Silabs] [EFR32] Random BLE address changes on every boot for RS9116 …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
2 people authored and pull[bot] committed Feb 12, 2024
1 parent 7c3bcba commit 2470213
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/platform/silabs/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 26 additions & 3 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef SIWX_917
#include "rail.h"
#endif

#include <crypto/RandUtils.h>
#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -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,
Expand All @@ -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();
}

Expand Down Expand Up @@ -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");
Expand All @@ -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)
{
Expand Down

0 comments on commit 2470213

Please sign in to comment.