Skip to content

Commit 854bbf3

Browse files
cnanoleafrestyled-commits
authored andcommitted
[nrf fromtree][TCR] Extended Announcement additions (#31532)
* 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 6d3f9e107de9a8421524437f44c2113730e52e54. * fix extra bracket causing a bug + restyle changes * Restyled by clang-format * adjust based on review comments - 2 * Restyled by clang-format --------- Cherry picked from: ca17912 Co-authored-by: Restyled.io <commits@restyled.io>
1 parent c1d6f8a commit 854bbf3

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

src/app/server/CommissioningWindowManager.h

+5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ class CommissioningWindowManager : public Messaging::UnsolicitedMessageHandler,
5959

6060
static constexpr System::Clock::Seconds16 MaxCommissioningTimeout()
6161
{
62+
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
63+
// Specification section 2.3.1 - Extended Announcement Duration up to 48h
64+
return System::Clock::Seconds16(60 * 60 * 48);
65+
#else
6266
// Specification section 5.4.2.3. Announcement Duration says 15 minutes.
6367
return System::Clock::Seconds16(15 * 60);
68+
#endif
6469
}
6570

6671
System::Clock::Seconds16 MinCommissioningTimeout() const

src/ble/CHIPBleServiceData.h

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct ChipBLEDeviceIdentificationInfo
4747
{
4848
constexpr static uint16_t kDiscriminatorMask = 0xfff;
4949
constexpr static uint8_t kAdditionalDataFlagMask = 0x1;
50+
constexpr static uint8_t kExtendedAnnouncementFlagMask = 0x2;
5051
constexpr static uint8_t kAdvertisementVersionMask = 0xf0;
5152
constexpr static uint8_t kAdvertisementVersionShiftBits = 4u;
5253

@@ -112,6 +113,19 @@ struct ChipBLEDeviceIdentificationInfo
112113
AdditionalDataFlag &= static_cast<uint8_t>(~kAdditionalDataFlagMask);
113114
}
114115
}
116+
117+
void SetExtendedAnnouncementFlag(bool flag)
118+
{
119+
if (flag)
120+
{
121+
AdditionalDataFlag |= kExtendedAnnouncementFlagMask;
122+
}
123+
else
124+
{
125+
AdditionalDataFlag &= static_cast<uint8_t>(~kExtendedAnnouncementFlagMask);
126+
}
127+
}
128+
115129
} __attribute__((packed));
116130

117131
} /* namespace Ble */

src/include/platform/CHIPDeviceConfig.h

+55
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,61 @@
595595
#define CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME 30000
596596
#endif
597597

598+
/**
599+
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
600+
*
601+
* Optional configuration to enable Extended Announcement Duration up to 48h.
602+
* Should be used together with extending CHIP_DEVICE_CONFIG_DISCOVERY_TIMEOUT_SECS past 15 minutes.
603+
* Disabled by default.
604+
*/
605+
606+
#ifndef CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
607+
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING 0
608+
#endif
609+
610+
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
611+
612+
/**
613+
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS
614+
*
615+
* The amount of time in miliseconds after which BLE advertisement should be switched from the slow
616+
* advertising to the extended advertising, counting from the moment of advertisement commencement.
617+
*
618+
* Defaults to 900000 ms.
619+
*/
620+
#ifndef CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS
621+
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS (15 * 60 * 1000)
622+
#endif
623+
624+
/**
625+
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN
626+
*
627+
* The minimum interval (in units of 0.625ms) at which the device will send BLE advertisements while
628+
* in the extended advertising mode. The minimum interval shall not be smaller than the default value
629+
* and should not be equal to the CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX.
630+
*
631+
* Defaults to 1920 (1200 ms).
632+
*/
633+
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN 1920
634+
635+
/**
636+
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX
637+
*
638+
* The maximum interval (in units of 0.625ms) at which the device will send BLE advertisements while
639+
* in the extended advertising mode. The maximum interval should be greater and not equal to the
640+
* CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN.
641+
*
642+
* Defaults to 1936 (1210 ms).
643+
*/
644+
#ifndef CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX
645+
#define CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX 1936
646+
#endif
647+
648+
static_assert(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN < CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX,
649+
"Max Extended Advertising Interval cannot be smaller or equal to the Min Extended Advertising Interval");
650+
651+
#endif
652+
598653
// -------------------- Service Provisioning Configuration --------------------
599654

600655
/**

src/platform/silabs/BLEManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class BLEManagerImpl final : public BLEManager, private BleLayer, private BlePla
152152
kRestartAdvertising = 0x0008,
153153
kEFRBLEStackInitialized = 0x0010,
154154
kDeviceNameSet = 0x0020,
155+
kExtAdvertisingEnabled = 0x0040,
155156
};
156157

157158
enum

src/platform/silabs/efr32/BLEManagerImpl.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,17 @@ CHIP_ERROR BLEManagerImpl::ConfigureAdvertisingData(void)
457457
advData[index++] = CHIP_ADV_DATA_TYPE_SERVICE_DATA; // AD type : Service Data
458458
advData[index++] = ShortUUID_CHIPoBLEService[0]; // AD value
459459
advData[index++] = ShortUUID_CHIPoBLEService[1];
460+
461+
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
462+
// Check for extended advertisement interval and redact VID/PID if past the initial period.
463+
if (mFlags.Has(Flags::kExtAdvertisingEnabled))
464+
{
465+
mDeviceIdInfo.SetVendorId(0);
466+
mDeviceIdInfo.SetProductId(0);
467+
mDeviceIdInfo.SetExtendedAnnouncementFlag(true);
468+
}
469+
#endif
470+
460471
memcpy(&advData[index], (void *) &mDeviceIdInfo, mDeviceIdInfoLength); // AD value
461472
index += mDeviceIdInfoLength;
462473

@@ -553,8 +564,21 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void)
553564
}
554565
else
555566
{
567+
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
568+
if (!mFlags.Has(Flags::kExtAdvertisingEnabled))
569+
{
570+
interval_min = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
571+
interval_max = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
572+
}
573+
else
574+
{
575+
interval_min = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN;
576+
interval_max = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX;
577+
}
578+
#else
556579
interval_min = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
557580
interval_max = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
581+
#endif
558582
}
559583

560584
ret = sl_bt_advertiser_set_timing(advertising_set_handle, interval_min, interval_max, 0, 0);
@@ -952,8 +976,22 @@ void BLEManagerImpl::BleAdvTimeoutHandler(TimerHandle_t xTimer)
952976
if (BLEMgrImpl().mFlags.Has(Flags::kFastAdvertisingEnabled))
953977
{
954978
ChipLogDetail(DeviceLayer, "bleAdv Timeout : Start slow advertissment");
979+
BLEMgrImpl().mFlags.Set(Flags::kAdvertising);
980+
BLEMgr().SetAdvertisingMode(BLEAdvertisingMode::kSlowAdvertising);
981+
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
982+
BLEMgrImpl().mFlags.Clear(Flags::kExtAdvertisingEnabled);
983+
BLEMgrImpl().StartBleAdvTimeoutTimer(CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS);
984+
#endif
985+
}
986+
#if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
987+
else
988+
{
989+
ChipLogDetail(DeviceLayer, "bleAdv Timeout : Start extended advertisment");
990+
BLEMgrImpl().mFlags.Set(Flags::kAdvertising);
991+
BLEMgrImpl().mFlags.Set(Flags::kExtAdvertisingEnabled);
955992
BLEMgr().SetAdvertisingMode(BLEAdvertisingMode::kSlowAdvertising);
956993
}
994+
#endif
957995
}
958996

959997
void BLEManagerImpl::CancelBleAdvTimeoutTimer(void)

0 commit comments

Comments
 (0)