diff --git a/src/app/server/CommissioningWindowManager.h b/src/app/server/CommissioningWindowManager.h index df9b1dcd5e36c6..26a2f9ceb19b71 100644 --- a/src/app/server/CommissioningWindowManager.h +++ b/src/app/server/CommissioningWindowManager.h @@ -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 diff --git a/src/ble/CHIPBleServiceData.h b/src/ble/CHIPBleServiceData.h index 965ae74307448b..6fbee69b7c268f 100644 --- a/src/ble/CHIPBleServiceData.h +++ b/src/ble/CHIPBleServiceData.h @@ -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; @@ -112,6 +113,19 @@ struct ChipBLEDeviceIdentificationInfo AdditionalDataFlag &= static_cast(~kAdditionalDataFlagMask); } } + + void SetExtendedAnnouncementFlag(bool flag) + { + if (flag) + { + AdditionalDataFlag |= kExtendedAnnouncementFlagMask; + } + else + { + AdditionalDataFlag &= static_cast(~kExtendedAnnouncementFlagMask); + } + } + } __attribute__((packed)); } /* namespace Ble */ diff --git a/src/include/platform/CHIPDeviceConfig.h b/src/include/platform/CHIPDeviceConfig.h index 9734e4bfa28b35..b203c997db8ff8 100644 --- a/src/include/platform/CHIPDeviceConfig.h +++ b/src/include/platform/CHIPDeviceConfig.h @@ -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 -------------------- /** diff --git a/src/platform/silabs/BLEManagerImpl.h b/src/platform/silabs/BLEManagerImpl.h index 72cca87af37351..12b3ba121886af 100644 --- a/src/platform/silabs/BLEManagerImpl.h +++ b/src/platform/silabs/BLEManagerImpl.h @@ -151,6 +151,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla kRestartAdvertising = 0x0008, kEFRBLEStackInitialized = 0x0010, kDeviceNameSet = 0x0020, + kExtAdvertisingEnabled = 0x0040, }; enum diff --git a/src/platform/silabs/efr32/BLEManagerImpl.cpp b/src/platform/silabs/efr32/BLEManagerImpl.cpp index 0cc4ae0d6c54ec..193d15bb018d6b 100644 --- a/src/platform/silabs/efr32/BLEManagerImpl.cpp +++ b/src/platform/silabs/efr32/BLEManagerImpl.cpp @@ -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; @@ -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); @@ -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)