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] Refactor 917 NCP and 917 SoC Bluetooth "DriveBLEState" function and bugfix RS9116 Stop Advertising #26450

Merged
Merged
4 changes: 0 additions & 4 deletions src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,6 @@ void ConnectivityManagerImpl::OnStationConnected()
(void) PlatformMgr().PostEvent(&event);
// Setting the rs911x in the power save mode
#if (CHIP_DEVICE_CONFIG_ENABLE_SED && RS911X_WIFI)
// TODO: Remove stop advertising after BLEManagerImpl is fixed
#if RSI_BLE_ENABLE
chip::DeviceLayer::Internal::BLEManagerImpl().StopAdvertising();
#endif /* RSI_BLE_ENABLE */
sl_status_t err = wfx_power_save();
if (err != SL_STATUS_OK)
{
Expand Down
59 changes: 22 additions & 37 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void sl_ble_init()
rsi_ble_app_init_events();

SILABS_LOG("StartAdvertising");
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
chip::DeviceLayer::Internal::BLEManagerImpl().StartAdvertising(); // TODO:: Called on after init of module
chip::DeviceLayer::Internal::BLEMgrImpl().HandleBootEvent();
SILABS_LOG("%s Ended", __func__);
}

Expand Down Expand Up @@ -235,7 +235,6 @@ CHIP_ERROR BLEManagerImpl::_Init()
CHIP_ERROR err;
rsi_semaphore_create(&sl_rs_ble_init_sem, 0);
rsi_semaphore_create(&sl_ble_event_sem, 0);
ChipLogProgress(DeviceLayer, "%s Start ", __func__);

wfx_rsi.ble_task = xTaskCreateStatic((TaskFunction_t) sl_ble_event_handling_task, "rsi_ble", WFX_RSI_TASK_SZ, NULL, 1,
wfxBLETaskStack, &rsiBLETaskStruct);
Expand Down Expand Up @@ -263,12 +262,9 @@ CHIP_ERROR BLEManagerImpl::_Init()

mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
#ifdef SIWX_917
PlatformMgr().ScheduleWork(DriveBLEState, 0);
#endif

exit:
ChipLogProgress(DeviceLayer, "%s END ", __func__);
return err;
}

Expand All @@ -295,9 +291,7 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingEnabled(bool val)
if (mFlags.Has(Flags::kAdvertisingEnabled) != val)
{
mFlags.Set(Flags::kAdvertisingEnabled, val);
#ifdef SIWX_917
PlatformMgr().ScheduleWork(DriveBLEState, 0);
#endif
}

exit:
Expand All @@ -318,9 +312,7 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode)
return CHIP_ERROR_INVALID_ARGUMENT;
}
mFlags.Set(Flags::kRestartAdvertising);
#ifdef SIWX_917
PlatformMgr().ScheduleWork(DriveBLEState, 0);
#endif
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -358,9 +350,7 @@ CHIP_ERROR BLEManagerImpl::_SetDeviceName(const char * deviceName)
{
mDeviceName[0] = 0;
}
#ifdef SIWX_917
PlatformMgr().ScheduleWork(DriveBLEState, 0);
#endif
ChipLogProgress(DeviceLayer, "_SetDeviceName Ended");
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -506,23 +496,21 @@ CHIP_ERROR BLEManagerImpl::MapBLEError(int bleErr)

void BLEManagerImpl::DriveBLEState(void)
{
ChipLogProgress(DeviceLayer, "DriveBLEState starting");
SILABS_LOG("%s starting", __func__);
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
CHIP_ERROR err = CHIP_NO_ERROR;

// Check if BLE stack is initialized ( TODO )
// VerifyOrExit(mFlags.Has(Flags::kEFRBLEStackInitialized),);
VerifyOrExit(mFlags.Has(Flags::kEFRBLEStackInitialized), /* */);

ChipLogProgress(DeviceLayer, "Start advertising if needed...");
// Start advertising if needed...
if (mServiceMode == ConnectivityManager::kCHIPoBLEServiceMode_Enabled && mFlags.Has(Flags::kAdvertisingEnabled) &&
NumConnections() < kMaxConnections)
{

ChipLogProgress(DeviceLayer, "Start/re-start advertising if not already started, or if there is a pending change");
// Start/re-start advertising if not already started, or if there is a pending change
// to the advertising configuration.
if (!mFlags.Has(Flags::kAdvertising) || mFlags.Has(Flags::kRestartAdvertising))
{
SILABS_LOG("Start Advertising");
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
err = StartAdvertising();
SuccessOrExit(err);
}
Expand All @@ -531,12 +519,13 @@ void BLEManagerImpl::DriveBLEState(void)
// Otherwise, stop advertising if it is enabled.
else if (mFlags.Has(Flags::kAdvertising))
{
SILABS_LOG("Stop Advertising");
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
err = StopAdvertising();
SuccessOrExit(err);
}

exit:
ChipLogProgress(DeviceLayer, "DriveBLEState End");
SILABS_LOG("%s End", __func__);
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Disabling CHIPoBLE service due to error: %s", ErrorStr(err));
Expand Down Expand Up @@ -677,19 +666,23 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int32_t status = 0;
// TODO: add the below code in a condition if (mFlags.Has(Flags::kAdvertising))
// Since DriveBLEState is not called the device is still advertising
mFlags.Clear(Flags::kAdvertising).Clear(Flags::kRestartAdvertising);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
status = rsi_ble_stop_advertising();
if (status != RSI_SUCCESS)

if (mFlags.Has(Flags::kAdvertising))
{
ChipLogProgress(DeviceLayer, "advertising failed to stop, with status = 0x%lx", status);
// Since DriveBLEState is not called the device is still advertising
status = rsi_ble_stop_advertising();
if (status != RSI_SUCCESS)
{
mFlags.Clear(Flags::kAdvertising).Clear(Flags::kRestartAdvertising);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
advertising_set_handle = 0xff;
CancelBleAdvTimeoutTimer();
}
else
{
ChipLogProgress(DeviceLayer, "advertising failed to stop, with status = 0x%lx", status);
}
}
advertising_set_handle = 0xff;
CancelBleAdvTimeoutTimer();

// exit:
return err;
}

Expand Down Expand Up @@ -718,19 +711,16 @@ void BLEManagerImpl::UpdateMtu(rsi_ble_event_mtu_t evt)

void BLEManagerImpl::HandleBootEvent(void)
{
ChipLogProgress(DeviceLayer, "HandleBootEvent started");
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
mFlags.Set(Flags::kEFRBLEStackInitialized);
#ifdef SIWX_917
PlatformMgr().ScheduleWork(DriveBLEState, 0);
#endif
}

void BLEManagerImpl::HandleConnectEvent(void)
{
ChipLogProgress(DeviceLayer, "Connect Event for handle : %d", event_msg.connectionHandle);
AddConnection(event_msg.connectionHandle, event_msg.bondingHandle);
#ifdef SIWX_917
PlatformMgr().ScheduleWork(DriveBLEState, 0);
#endif
}

// TODO:: Implementation need to be done.
Expand Down Expand Up @@ -772,15 +762,10 @@ void BLEManagerImpl::HandleConnectionCloseEvent(uint16_t reason)

void BLEManagerImpl::HandleWriteEvent(rsi_ble_event_write_t evt)
{
// RSI_BLE_WRITE_REQUEST_EVENT
ChipLogProgress(DeviceLayer, "Char Write Req, packet type %d", evt.pkt_type);
// uint8_t attribute = (uint8_t) event_msg.rsi_ble_measurement_hndl;

SILABS_LOG("event_msg.rsi_ble_gatt_server_client_config_hndl = %d", event_msg.rsi_ble_gatt_server_client_config_hndl);

if (evt.handle[0] == (uint8_t) event_msg.rsi_ble_gatt_server_client_config_hndl) // TODO:: compare the handle exactly
{
SILABS_LOG("Inside HandleTXCharCCCDWrite ");
HandleTXCharCCCDWrite(&evt);
}
else
Expand Down