Skip to content

Commit

Permalink
[TCR] Extended Announcement additions (#31532)
Browse files Browse the repository at this point in the history
* additions to support changes as discussed in connectedhomeip-spec #7825

* add Silabs platform example implementation

* add extension for ExtendedAnnouncementFlag + Silabs platform usage

* Restyled by clang-format

* adjust based on review comments - 1

* Restyled by clang-format

* add missing include guard for default case

* Revert "Restyled by clang-format"

This reverts commit 6d3f9e1.

* fix extra bracket causing a bug + restyle changes

* Restyled by clang-format

* adjust based on review comments - 2

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 29, 2024
1 parent 5ee22ba commit 2273384
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/server/CommissioningWindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ class CommissioningWindowManager : public Messaging::UnsolicitedMessageHandler,

static constexpr System::Clock::Seconds16 MaxCommissioningTimeout()
{
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
// Specification section 2.3.1 - Extended Announcement Duration up to 48h
return System::Clock::Seconds16(60 * 60 * 48);
#else
// Specification section 5.4.2.3. Announcement Duration says 15 minutes.
return System::Clock::Seconds16(15 * 60);
#endif
}

System::Clock::Seconds16 MinCommissioningTimeout() const
Expand Down
14 changes: 14 additions & 0 deletions src/ble/CHIPBleServiceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct ChipBLEDeviceIdentificationInfo
{
constexpr static uint16_t kDiscriminatorMask = 0xfff;
constexpr static uint8_t kAdditionalDataFlagMask = 0x1;
constexpr static uint8_t kExtendedAnnouncementFlagMask = 0x2;
constexpr static uint8_t kAdvertisementVersionMask = 0xf0;
constexpr static uint8_t kAdvertisementVersionShiftBits = 4u;

Expand Down Expand Up @@ -112,6 +113,19 @@ struct ChipBLEDeviceIdentificationInfo
AdditionalDataFlag &= static_cast<uint8_t>(~kAdditionalDataFlagMask);
}
}

void SetExtendedAnnouncementFlag(bool flag)
{
if (flag)
{
AdditionalDataFlag |= kExtendedAnnouncementFlagMask;
}
else
{
AdditionalDataFlag &= static_cast<uint8_t>(~kExtendedAnnouncementFlagMask);
}
}

} __attribute__((packed));

} /* namespace Ble */
Expand Down
55 changes: 55 additions & 0 deletions src/include/platform/CHIPDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,61 @@
#define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME 30000
#endif

/**
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
*
* Optional configuration to enable Extended Announcement Duration up to 48h.
* Should be used together with extending CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS past 15 minutes.
* Disabled by default.
*/

#ifndef CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING 0
#endif

#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING

/**
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS
*
* The amount of time in miliseconds after which BLE advertisement should be switched from the slow
* advertising to the extended advertising, counting from the moment of advertisement commencement.
*
* Defaults to 900000 ms.
*/
#ifndef CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS (15 * 60 * 1000)
#endif

/**
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN
*
* The minimum interval (in units of 0.625ms) at which the device will send BLE advertisements while
* in the extended advertising mode. The minimum interval shall not be smaller than the default value
* and should not be equal to the CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX.
*
* Defaults to 1920 (1200 ms).
*/
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN 1920

/**
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX
*
* The maximum interval (in units of 0.625ms) at which the device will send BLE advertisements while
* in the extended advertising mode. The maximum interval should be greater and not equal to the
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN.
*
* Defaults to 1936 (1210 ms).
*/
#ifndef CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX 1936
#endif

static_assert(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN < CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX,
"Max Extended Advertising Interval cannot be smaller or equal to the Min Extended Advertising Interval");

#endif

// -------------------- Service Provisioning Configuration --------------------

/**
Expand Down
1 change: 1 addition & 0 deletions src/platform/silabs/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
kRestartAdvertising = 0x0008,
kEFRBLEStackInitialized = 0x0010,
kDeviceNameSet = 0x0020,
kExtAdvertisingEnabled = 0x0040,
};

enum
Expand Down
38 changes: 38 additions & 0 deletions src/platform/silabs/efr32/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
advData[index++] = CHIP_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data
advData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value
advData[index++] = ShortUUID_CHIPoBLEService[1];

#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
// Check for extended advertisement interval and redact VID/PID if past the initial period.
if (mFlags.Has(Flags::kExtAdvertisingEnabled))
{
mDeviceIdInfo.SetVendorId(0);
mDeviceIdInfo.SetProductId(0);
mDeviceIdInfo.SetExtendedAnnouncementFlag(true);
}
#endif

memcpy(&advData[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value
index += mDeviceIdInfoLength;

Expand Down Expand Up @@ -554,8 +565,21 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
}
else
{
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
if (!mFlags.Has(Flags::kExtAdvertisingEnabled))
{
interval_min = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
interval_max = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
}
else
{
interval_min = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN;
interval_max = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX;
}
#else
interval_min = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
interval_max = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
#endif
}

ret = sl_bt_advertiser_set_timing(advertising_set_handle, interval_min, interval_max, 0, 0);
Expand Down Expand Up @@ -953,8 +977,22 @@ void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
if (BLEMgrImpl().mFlags.Has(Flags::kFastAdvertisingEnabled))
{
ChipLogDetail(DeviceLayer, "bleAdv Timeout : Start slow advertissment");
BLEMgrImpl().mFlags.Set(Flags::kAdvertising);
BLEMgr().SetAdvertisingMode(BLEAdvertisingMode::kSlowAdvertising);
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
BLEMgrImpl().mFlags.Clear(Flags::kExtAdvertisingEnabled);
BLEMgrImpl().StartBleAdvTimeoutTimer(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS);
#endif
}
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
else
{
ChipLogDetail(DeviceLayer, "bleAdv Timeout : Start extended advertisment");
BLEMgrImpl().mFlags.Set(Flags::kAdvertising);
BLEMgrImpl().mFlags.Set(Flags::kExtAdvertisingEnabled);
BLEMgr().SetAdvertisingMode(BLEAdvertisingMode::kSlowAdvertising);
}
#endif
}

void BLEManagerImpl::CancelBleAdvTimeoutTimer(void)
Expand Down

0 comments on commit 2273384

Please sign in to comment.