Skip to content

Commit

Permalink
Pull request project-chip#1759: [Cherry-Pick] Add adv change event to…
Browse files Browse the repository at this point in the history
… silabs platforms (project-chip#32987)

Merge in WMN_TOOLS/matter from cherry-pick/advertising_change_event to RC_2.3.0-1.3

Squashed commit of the following:

commit 095bd4988dabf92837a81829bf2d8b1d9414200c
Author: mkardous-silabs <[email protected]>
Date:   Mon Apr 15 11:51:14 2024 -0500

    Add adv change event to silabs platforms (project-chip#32987)
  • Loading branch information
mkardous-silabs authored and jmartinez-silabs committed Apr 16, 2024
1 parent b123328 commit 956a24f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
44 changes: 30 additions & 14 deletions src/platform/silabs/efr32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,12 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)

CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
{
CHIP_ERROR err;
sl_status_t ret;
uint32_t interval_min;
uint32_t interval_max;
CHIP_ERROR err = CHIP_NO_ERROR;
sl_status_t ret = SL_STATUS_OK;
uint32_t interval_min = 0;
uint32_t interval_max = 0;
uint16_t numConnectionss = NumConnections();
bool postAdvChangeEvent = false;
uint8_t connectableAdv =
(numConnectionss < kMaxConnections) ? sl_bt_advertiser_connectable_scannable : sl_bt_advertiser_scannable_non_connectable;

Expand All @@ -551,6 +552,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
else
{
ChipLogDetail(DeviceLayer, "Start BLE advertisement");
postAdvChangeEvent = true;
}

err = ConfigureAdvertisingData();
Expand Down Expand Up @@ -589,18 +591,26 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
SuccessOrExit(err);

sl_bt_advertiser_configure(advertising_set_handle, 1);

ret = sl_bt_legacy_advertiser_start(advertising_set_handle, connectableAdv);
err = MapBLEError(ret);
SuccessOrExit(err);

if (SL_STATUS_OK == ret)
if (mFlags.Has(Flags::kFastAdvertisingEnabled))
{
if (mFlags.Has(Flags::kFastAdvertisingEnabled))
{
StartBleAdvTimeoutTimer(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME);
}
mFlags.Set(Flags::kAdvertising);
StartBleAdvTimeoutTimer(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME);
}
mFlags.Set(Flags::kAdvertising);

err = MapBLEError(ret);
if (postAdvChangeEvent)
{
// Post CHIPoBLEAdvertisingChange event.
ChipDeviceEvent advChange;
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Started;

ReturnErrorOnFailure(PlatformMgr().PostEvent(&advChange));
}

exit:
return err;
Expand All @@ -609,23 +619,29 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
sl_status_t ret;

if (mFlags.Has(Flags::kAdvertising))
{
sl_status_t ret = SL_STATUS_OK;

mFlags.Clear(Flags::kAdvertising).Clear(Flags::kRestartAdvertising);
mFlags.Set(Flags::kFastAdvertisingEnabled, true);

ret = sl_bt_advertiser_stop(advertising_set_handle);
sl_bt_advertiser_delete_set(advertising_set_handle);
advertising_set_handle = 0xff;
err = MapBLEError(ret);
SuccessOrExit(err);
VerifyOrReturnError(err == CHIP_NO_ERROR, err);

CancelBleAdvTimeoutTimer();

// Post CHIPoBLEAdvertisingChange event.
ChipDeviceEvent advChange;
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Stopped;
err = PlatformMgr().PostEvent(&advChange);
}

exit:
return err;
}

Expand Down
32 changes: 24 additions & 8 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,9 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)

CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
int32_t status = 0;
CHIP_ERROR err = CHIP_NO_ERROR;
int32_t status = 0;
bool postAdvChangeEvent = false;

ChipLogProgress(DeviceLayer, "StartAdvertising start");

Expand All @@ -695,6 +696,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
else
{
ChipLogDetail(DeviceLayer, "Start BLE advertisement");
postAdvChangeEvent = true;
}

if (!(mFlags.Has(Flags::kAdvertising)))
Expand All @@ -719,15 +721,26 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
StartBleAdvTimeoutTimer(CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME);
}
mFlags.Set(Flags::kAdvertising);

if (postAdvChangeEvent)
{
// Post CHIPoBLEAdvertisingChange event.
ChipDeviceEvent advChange;
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Started;

ReturnErrorOnFailure(PlatformMgr().PostEvent(&advChange));
}
}
else
{
ChipLogProgress(DeviceLayer, "rsi_ble_start_advertising Failed with status: %lx", status);
}

exit:
// TODO: Add MapBLEError to return the correct error code
ChipLogError(DeviceLayer, "StartAdvertising() End error: %s", ErrorStr(err));
return CHIP_NO_ERROR; // err;
return err;
}

int32_t BLEManagerImpl::SendBLEAdvertisementCommand(void)
Expand Down Expand Up @@ -756,7 +769,6 @@ int32_t BLEManagerImpl::SendBLEAdvertisementCommand(void)
return rsi_ble_start_advertising_with_values(&ble_adv);
}

// TODO:: Implementation need to be done.
CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand All @@ -772,12 +784,16 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising(void)
mFlags.Set(Flags::kFastAdvertisingEnabled, true);
advertising_set_handle = 0xff;
CancelBleAdvTimeoutTimer();
}
else
{
ChipLogProgress(DeviceLayer, "advertising failed to stop, with status = 0x%lx", status);

// Post CHIPoBLEAdvertisingChange event.
ChipDeviceEvent advChange;
advChange.Type = DeviceEventType::kCHIPoBLEAdvertisingChange;
advChange.CHIPoBLEAdvertisingChange.Result = kActivity_Stopped;
err = PlatformMgr().PostEvent(&advChange);
}
}

// TODO: Add MapBLEError to return the correct error code
return err;
}

Expand Down

0 comments on commit 956a24f

Please sign in to comment.