38
38
/* 1 transmission, 20ms interval */
39
39
#define PROV_XMIT BT_MESH_TRANSMIT(0, 20)
40
40
41
- static struct k_delayed_work beacon_timer ;
41
+ static struct k_work_delayable beacon_timer ;
42
42
43
43
static int cache_check (struct bt_mesh_subnet * sub , void * beacon_data )
44
44
{
@@ -232,32 +232,30 @@ static void update_beacon_observation(void)
232
232
233
233
static void beacon_send (struct k_work * work )
234
234
{
235
- /* Don't send anything if we have an active provisioning link */
236
- if (IS_ENABLED (CONFIG_BT_MESH_PB_ADV ) && bt_mesh_prov_active ()) {
237
- k_delayed_work_submit (& beacon_timer , K_SECONDS (CONFIG_BT_MESH_UNPROV_BEACON_INT ));
238
- return ;
239
- }
240
-
241
235
BT_DBG ("" );
242
236
243
237
if (bt_mesh_is_provisioned ()) {
238
+ if (!bt_mesh_beacon_enabled () &&
239
+ !atomic_test_bit (bt_mesh .flags , BT_MESH_IVU_INITIATOR )) {
240
+ return ;
241
+ }
242
+
244
243
update_beacon_observation ();
245
244
(void )bt_mesh_subnet_find (secure_beacon_send , NULL );
246
245
247
- /* Only resubmit if beaconing is still enabled */
248
- if (bt_mesh_beacon_enabled () ||
249
- atomic_test_bit (bt_mesh .flags , BT_MESH_IVU_INITIATOR )) {
250
- k_delayed_work_submit (& beacon_timer ,
251
- PROVISIONED_INTERVAL );
252
- }
253
-
246
+ k_work_schedule (& beacon_timer , PROVISIONED_INTERVAL );
254
247
return ;
255
248
}
256
249
257
250
if (IS_ENABLED (CONFIG_BT_MESH_PB_ADV )) {
258
- unprovisioned_beacon_send ();
259
- k_delayed_work_submit (& beacon_timer , K_SECONDS (CONFIG_BT_MESH_UNPROV_BEACON_INT ));
251
+ /* Don't send anything if we have an active provisioning link */
252
+ if (!bt_mesh_prov_active ()) {
253
+ unprovisioned_beacon_send ();
254
+ }
255
+
256
+ k_work_schedule (& beacon_timer , K_SECONDS (CONFIG_BT_MESH_UNPROV_BEACON_INT ));
260
257
}
258
+
261
259
}
262
260
263
261
struct beacon_params {
@@ -430,18 +428,23 @@ BT_MESH_SUBNET_CB_DEFINE(subnet_evt);
430
428
431
429
void bt_mesh_beacon_init (void )
432
430
{
433
- k_delayed_work_init (& beacon_timer , beacon_send );
431
+ k_work_init_delayable (& beacon_timer , beacon_send );
434
432
}
435
433
436
434
void bt_mesh_beacon_ivu_initiator (bool enable )
437
435
{
438
436
atomic_set_bit_to (bt_mesh .flags , BT_MESH_IVU_INITIATOR , enable );
439
437
440
- if (enable ) {
441
- k_delayed_work_submit (& beacon_timer , K_NO_WAIT );
442
- } else if (!bt_mesh_beacon_enabled ()) {
443
- k_delayed_work_cancel (& beacon_timer );
444
- }
438
+ /* Fire the beacon handler straight away if it's not already pending -
439
+ * in which case we'll fire according to the ongoing periodic sending.
440
+ * If beacons are disabled, the handler will exit early.
441
+ *
442
+ * An alternative solution would be to check whether beacons are enabled
443
+ * here, and cancel if not. As the cancel operation may fail, we would
444
+ * still have to implement an early exit mechanism, so we might as well
445
+ * just use this every time.
446
+ */
447
+ k_work_schedule (& beacon_timer , K_NO_WAIT );
445
448
}
446
449
447
450
static void subnet_beacon_enable (struct bt_mesh_subnet * sub )
@@ -454,19 +457,17 @@ static void subnet_beacon_enable(struct bt_mesh_subnet *sub)
454
457
455
458
void bt_mesh_beacon_enable (void )
456
459
{
457
- if (!bt_mesh_is_provisioned ()) {
458
- k_delayed_work_submit (& beacon_timer , K_NO_WAIT );
459
- return ;
460
+ if (bt_mesh_is_provisioned ()) {
461
+ bt_mesh_subnet_foreach (subnet_beacon_enable );
460
462
}
461
463
462
- bt_mesh_subnet_foreach (subnet_beacon_enable );
463
-
464
- k_delayed_work_submit (& beacon_timer , K_NO_WAIT );
464
+ k_work_reschedule (& beacon_timer , K_NO_WAIT );
465
465
}
466
466
467
467
void bt_mesh_beacon_disable (void )
468
468
{
469
469
if (!atomic_test_bit (bt_mesh .flags , BT_MESH_IVU_INITIATOR )) {
470
- k_delayed_work_cancel (& beacon_timer );
470
+ /* If this fails, we'll do an early exit in the work handler. */
471
+ (void )k_work_cancel_delayable (& beacon_timer );
471
472
}
472
473
}
0 commit comments