@@ -411,6 +411,84 @@ start_non_connectable_ext(void)
411
411
console_printf ("instance %u started (non-con non-scan)\n" , instance );
412
412
}
413
413
414
+ static void start_periodic (void )
415
+ {
416
+ struct ble_gap_periodic_adv_params pparams ;
417
+ struct ble_gap_ext_adv_params params ;
418
+ struct ble_hs_adv_fields adv_fields ;
419
+ struct os_mbuf * data ;
420
+ uint8_t instance = 5 ;
421
+ ble_addr_t addr ;
422
+ int rc ;
423
+
424
+ /* For periodic we use nstance with non-connectable advertising */
425
+ memset (& params , 0 , sizeof (params ));
426
+
427
+ /* advertise using random addr */
428
+ params .own_addr_type = BLE_OWN_ADDR_RANDOM ;
429
+
430
+ params .primary_phy = BLE_HCI_LE_PHY_1M ;
431
+ params .secondary_phy = BLE_HCI_LE_PHY_1M ;
432
+ params .tx_power = 127 ;
433
+ params .sid = 2 ;
434
+
435
+ /* configure instance 0 */
436
+ rc = ble_gap_ext_adv_configure (instance , & params , NULL , NULL , NULL );
437
+ assert (rc == 0 );
438
+
439
+ /* set random (NRPA) address for instance */
440
+ rc = ble_hs_id_gen_rnd (1 , & addr );
441
+ assert (rc == 0 );
442
+
443
+ rc = ble_gap_ext_adv_set_addr (instance , & addr );
444
+ assert (rc == 0 );
445
+
446
+ memset (& adv_fields , 0 , sizeof (adv_fields ));
447
+ adv_fields .name = (const uint8_t * )"nimble with periodic" ;
448
+ adv_fields .name_len = strlen ((char * )adv_fields .name );
449
+
450
+ /* Default to legacy PDUs size, mbuf chain will be increased if needed
451
+ */
452
+ data = os_msys_get_pkthdr (BLE_HCI_MAX_ADV_DATA_LEN , 0 );
453
+ assert (data );
454
+
455
+ rc = ble_hs_adv_set_fields_mbuf (& adv_fields , data );
456
+ assert (rc == 0 );
457
+
458
+ rc = ble_gap_ext_adv_set_data (instance , data );
459
+ assert (rc == 0 );
460
+
461
+ /* configure periodic advertising */
462
+ memset (& pparams , 0 , sizeof (pparams ));
463
+ pparams .include_tx_power = 1 ;
464
+ pparams .itvl_min = 160 ;
465
+ pparams .itvl_max = 240 ;
466
+
467
+ rc = ble_gap_periodic_adv_configure (instance , & pparams );
468
+ assert (rc == 0 );
469
+
470
+ /* get mbuf for periodic data */
471
+ data = os_msys_get_pkthdr (sizeof (ext_adv_pattern_1 ), 0 );
472
+ assert (data );
473
+
474
+ /* fill mbuf with periodic data */
475
+ rc = os_mbuf_append (data , ext_adv_pattern_1 , sizeof (ext_adv_pattern_1 ));
476
+ assert (rc == 0 );
477
+
478
+ rc = ble_gap_periodic_adv_set_data (instance , data );
479
+ assert (rc == 0 );
480
+
481
+ /* start periodic advertising */
482
+ rc = ble_gap_periodic_adv_start (instance );
483
+ assert (rc == 0 );
484
+
485
+ /* start advertising */
486
+ rc = ble_gap_ext_adv_start (instance , 0 , 0 );
487
+ assert (rc == 0 );
488
+
489
+ console_printf ("instance %u started (periodic)\n" , instance );
490
+ }
491
+
414
492
static void
415
493
on_sync (void )
416
494
{
@@ -435,6 +513,8 @@ on_sync(void)
435
513
start_legacy_duration (0 , true);
436
514
437
515
start_ext_max_events (0 , true);
516
+
517
+ start_periodic ();
438
518
}
439
519
440
520
/*
0 commit comments