@@ -60,6 +60,8 @@ namespace {
60
60
constexpr uint32_t kAdvertisingOptions = BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME;
61
61
constexpr uint8_t kAdvertisingFlags = BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR;
62
62
63
+ constexpr uint8_t kLowestRequestPriority = 7 ;
64
+
63
65
const bt_uuid_128 UUID128_CHIPoBLEChar_RX =
64
66
BT_UUID_INIT_128 (0x11 , 0x9D , 0x9F , 0x42 , 0x9C , 0x4F , 0x9F , 0x95 , 0x59 , 0x45 , 0x3D , 0x26 , 0xF5 , 0x2E , 0xEE , 0x18 );
65
67
const bt_uuid_128 UUID128_CHIPoBLEChar_TX =
@@ -161,7 +163,7 @@ BLEManagerImpl BLEManagerImpl::sInstance;
161
163
CHIP_ERROR BLEManagerImpl::_Init ()
162
164
{
163
165
int err = 0 ;
164
- int id = 0 ;
166
+ int id = 0 ;
165
167
166
168
mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled ;
167
169
mFlags .ClearAll ().Set (Flags::kAdvertisingEnabled , CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART);
@@ -245,7 +247,11 @@ void BLEManagerImpl::DriveBLEState()
245
247
}
246
248
else
247
249
{
248
- if (mFlags .Has (Flags::kAdvertising ))
250
+ if (mFlags .Has (Flags::kAdvertising )
251
+ #if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
252
+ && mFlags .Has (Flags::kExtendedAdvertisingEnabled )
253
+ #endif
254
+ )
249
255
{
250
256
err = StopAdvertising ();
251
257
SuccessOrExit (err);
@@ -293,18 +299,45 @@ inline CHIP_ERROR BLEManagerImpl::PrepareAdvertisingRequest()
293
299
Encoding::LittleEndian::Put16 (serviceData.uuid , UUID16_CHIPoBLEService.val );
294
300
ReturnErrorOnFailure (ConfigurationMgr ().GetBLEDeviceIdentificationInfo (serviceData.deviceIdInfo ));
295
301
302
+ #if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
303
+ if (mFlags .Has (Flags::kExtendedAdvertisingEnabled ))
304
+ {
305
+ serviceData.deviceIdInfo .SetVendorId (DEVICE_HANDLE_NULL);
306
+ serviceData.deviceIdInfo .SetProductId (DEVICE_HANDLE_NULL);
307
+ serviceData.deviceIdInfo .SetExtendedAnnouncementFlag (true );
308
+ }
309
+ #endif
310
+
296
311
advertisingData[0 ] = BT_DATA (BT_DATA_FLAGS, &kAdvertisingFlags , sizeof (kAdvertisingFlags ));
297
312
advertisingData[1 ] = BT_DATA (BT_DATA_SVC_DATA16, &serviceData, sizeof (serviceData));
298
313
scanResponseData[0 ] = BT_DATA (BT_DATA_NAME_COMPLETE, name, nameSize);
299
314
300
- mAdvertisingRequest .priority = CHIP_DEVICE_BLE_ADVERTISING_PRIORITY;
301
- mAdvertisingRequest .options = kAdvertisingOptions ;
302
- mAdvertisingRequest .minInterval = mFlags .Has (Flags::kFastAdvertisingEnabled )
303
- ? CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN
304
- : CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
305
- mAdvertisingRequest .maxInterval = mFlags .Has (Flags::kFastAdvertisingEnabled )
306
- ? CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MAX
307
- : CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
315
+ mAdvertisingRequest .priority = CHIP_DEVICE_BLE_ADVERTISING_PRIORITY;
316
+ mAdvertisingRequest .options = kAdvertisingOptions ;
317
+
318
+ if (mFlags .Has (Flags::kFastAdvertisingEnabled ))
319
+ {
320
+ mAdvertisingRequest .minInterval = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MIN;
321
+ mAdvertisingRequest .maxInterval = CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL_MAX;
322
+ }
323
+ else
324
+ {
325
+ #if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
326
+ if (mFlags .Has (Flags::kExtendedAdvertisingEnabled ))
327
+ {
328
+ mAdvertisingRequest .minInterval = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MIN;
329
+ mAdvertisingRequest .maxInterval = CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_MAX;
330
+ }
331
+ else
332
+ {
333
+ mAdvertisingRequest .minInterval = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
334
+ mAdvertisingRequest .maxInterval = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
335
+ }
336
+ #else
337
+ mAdvertisingRequest .minInterval = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MIN;
338
+ mAdvertisingRequest .maxInterval = CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL_MAX;
339
+ #endif
340
+ }
308
341
mAdvertisingRequest .advertisingData = Span<bt_data>(advertisingData);
309
342
mAdvertisingRequest .scanResponseData = nameSize ? Span<bt_data>(scanResponseData) : Span<bt_data>{};
310
343
@@ -363,10 +396,17 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising()
363
396
364
397
if (mFlags .Has (Flags::kFastAdvertisingEnabled ))
365
398
{
366
- // Start timer to change advertising interval.
399
+ // Start timer to change advertising fast to slow interval.
367
400
DeviceLayer::SystemLayer ().StartTimer (
368
401
System::Clock::Milliseconds32 (CHIP_DEVICE_CONFIG_BLE_ADVERTISING_INTERVAL_CHANGE_TIME),
369
- HandleBLEAdvertisementIntervalChange, this );
402
+ HandleSlowBLEAdvertisementInterval, this );
403
+ #if CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING
404
+
405
+ // Start timer to change advertising slow to extended interval.
406
+ DeviceLayer::SystemLayer ().StartTimer (
407
+ System::Clock::Milliseconds32 (CHIP_DEVICE_CONFIG_BLE_EXT_ADVERTISING_INTERVAL_CHANGE_TIME_MS),
408
+ HandleExtendedBLEAdvertisementInterval, this );
409
+ #endif
370
410
}
371
411
}
372
412
@@ -394,7 +434,8 @@ CHIP_ERROR BLEManagerImpl::StopAdvertising()
394
434
}
395
435
396
436
// Cancel timer event changing CHIPoBLE advertisement interval
397
- DeviceLayer::SystemLayer ().CancelTimer (HandleBLEAdvertisementIntervalChange, this );
437
+ DeviceLayer::SystemLayer ().CancelTimer (HandleSlowBLEAdvertisementInterval, this );
438
+ DeviceLayer::SystemLayer ().CancelTimer (HandleExtendedBLEAdvertisementInterval, this );
398
439
}
399
440
400
441
return CHIP_NO_ERROR;
@@ -423,6 +464,9 @@ CHIP_ERROR BLEManagerImpl::_SetAdvertisingMode(BLEAdvertisingMode mode)
423
464
case BLEAdvertisingMode::kSlowAdvertising :
424
465
mFlags .Set (Flags::kFastAdvertisingEnabled , false );
425
466
break ;
467
+ case BLEAdvertisingMode::kExtendedAdvertising :
468
+ mFlags .Set (Flags::kExtendedAdvertisingEnabled , true );
469
+ break ;
426
470
default :
427
471
return CHIP_ERROR_INVALID_ARGUMENT;
428
472
}
@@ -607,12 +651,18 @@ CHIP_ERROR BLEManagerImpl::PrepareC3CharData()
607
651
}
608
652
#endif
609
653
610
- void BLEManagerImpl::HandleBLEAdvertisementIntervalChange (System::Layer * layer, void * param)
654
+ void BLEManagerImpl::HandleSlowBLEAdvertisementInterval (System::Layer * layer, void * param)
611
655
{
612
656
BLEMgr ().SetAdvertisingMode (BLEAdvertisingMode::kSlowAdvertising );
613
657
ChipLogProgress (DeviceLayer, " CHIPoBLE advertising mode changed to slow" );
614
658
}
615
659
660
+ void BLEManagerImpl::HandleExtendedBLEAdvertisementInterval (System::Layer * layer, void * param)
661
+ {
662
+ BLEMgr ().SetAdvertisingMode (BLEAdvertisingMode::kExtendedAdvertising );
663
+ ChipLogProgress (DeviceLayer, " CHIPoBLE advertising mode changed to extended" );
664
+ }
665
+
616
666
void BLEManagerImpl::_OnPlatformEvent (const ChipDeviceEvent * event)
617
667
{
618
668
CHIP_ERROR err = CHIP_NO_ERROR;
0 commit comments