Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Silabs] [EFR32] Random BLE address changes on every boot for RS9116 and 917 SoC BLE #26518

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 42 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 @@ -75,8 +75,19 @@ using namespace ::chip;
using namespace ::chip::Ble;
using namespace ::chip::DeviceLayer::Internal;

void sl_get_bluethooth_addr(uint8_t * addr, uint8_t length)
jepenven-silabs marked this conversation as resolved.
Show resolved Hide resolved
{
while (length > 0)
{
*(addr + length) = chip::Crypto::GetRandU8();
length--;
}
}

void sl_ble_init()
{
constexpr int BLE_ADDR_LENGTH = 6;
jepenven-silabs marked this conversation as resolved.
Show resolved Hide resolved
uint8_t addr[BLE_ADDR_LENGTH] = { 0 };

// 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 +99,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();
sl_get_bluethooth_addr(addr, BLE_ADDR_LENGTH);
jepenven-silabs marked this conversation as resolved.
Show resolved Hide resolved
rsi_ble_set_random_address_with_value(addr);
jepenven-silabs marked this conversation as resolved.
Show resolved Hide resolved
chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent();
}

Expand Down Expand Up @@ -626,8 +640,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 @@ -648,6 +662,31 @@ 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);
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
if (ble_adv.adv_int_min == 0)
{
ble_adv.adv_int_min = RSI_BLE_ADV_INT_MIN;
}
if (ble_adv.adv_int_max == 0)
{
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