@@ -412,7 +412,7 @@ u8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub)
412412 flags |= BT_MESH_NET_FLAG_KR ;
413413 }
414414
415- if (bt_mesh .iv_update ) {
415+ if (atomic_test_bit ( bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ) ) {
416416 flags |= BT_MESH_NET_FLAG_IVU ;
417417 }
418418
@@ -448,7 +448,7 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
448448
449449 BT_DBG ("NetKey %s" , bt_hex (key , 16 ));
450450
451- if (bt_mesh .valid ) {
451+ if (atomic_test_bit ( bt_mesh .flags , BT_MESH_VALID ) ) {
452452 return - EALREADY ;
453453 }
454454
@@ -472,7 +472,7 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
472472 }
473473 }
474474
475- bt_mesh .valid = 1U ;
475+ atomic_set_bit ( bt_mesh .flags , BT_MESH_VALID ) ;
476476 sub -> net_idx = idx ;
477477
478478 if (IS_ENABLED (CONFIG_BT_MESH_GATT_PROXY )) {
@@ -482,7 +482,8 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16],
482482 }
483483
484484 bt_mesh .iv_index = iv_index ;
485- bt_mesh .iv_update = BT_MESH_IV_UPDATE (flags );
485+ atomic_set_bit_to (bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ,
486+ BT_MESH_IV_UPDATE (flags ));
486487
487488 /* Set minimum required hours, since the 96-hour minimum requirement
488489 * doesn't apply straight after provisioning (since we can't know how
@@ -583,7 +584,7 @@ void bt_mesh_rpl_reset(void)
583584#if defined(CONFIG_BT_MESH_IV_UPDATE_TEST )
584585void bt_mesh_iv_update_test (bool enable )
585586{
586- bt_mesh .ivu_test = enable ;
587+ atomic_set_bit_to ( bt_mesh .flags , BT_MESH_IVU_TEST , enable ) ;
587588 /* Reset the duration variable - needed for some PTS tests */
588589 bt_mesh .ivu_duration = 0U ;
589590}
@@ -595,15 +596,15 @@ bool bt_mesh_iv_update(void)
595596 return false;
596597 }
597598
598- if (bt_mesh .iv_update ) {
599+ if (atomic_test_bit ( bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ) ) {
599600 bt_mesh_net_iv_update (bt_mesh .iv_index , false);
600601 } else {
601602 bt_mesh_net_iv_update (bt_mesh .iv_index + 1 , true);
602603 }
603604
604605 bt_mesh_net_sec_update (NULL );
605606
606- return bt_mesh .iv_update ;
607+ return atomic_test_bit ( bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ) ;
607608}
608609#endif /* CONFIG_BT_MESH_IV_UPDATE_TEST */
609610
@@ -624,7 +625,7 @@ bool bt_mesh_net_iv_update(u32_t iv_index, bool iv_update)
624625{
625626 int i ;
626627
627- if (bt_mesh .iv_update ) {
628+ if (atomic_test_bit ( bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ) ) {
628629 /* We're currently in IV Update mode */
629630
630631 if (iv_index != bt_mesh .iv_index ) {
@@ -673,7 +674,8 @@ bool bt_mesh_net_iv_update(u32_t iv_index, bool iv_update)
673674 }
674675 }
675676
676- if (!(IS_ENABLED (CONFIG_BT_MESH_IV_UPDATE_TEST ) && bt_mesh .ivu_test )) {
677+ if (!(IS_ENABLED (CONFIG_BT_MESH_IV_UPDATE_TEST ) &&
678+ atomic_test_bit (bt_mesh .flags , BT_MESH_IVU_TEST ))) {
677679 if (bt_mesh .ivu_duration < BT_MESH_IVU_MIN_HOURS ) {
678680 BT_WARN ("IV Update before minimum duration" );
679681 return false;
@@ -683,15 +685,15 @@ bool bt_mesh_net_iv_update(u32_t iv_index, bool iv_update)
683685 /* Defer change to Normal Operation if there are pending acks */
684686 if (!iv_update && bt_mesh_tx_in_progress ()) {
685687 BT_WARN ("IV Update deferred because of pending transfer" );
686- bt_mesh .pending_update = 1U ;
688+ atomic_set_bit ( bt_mesh .flags , BT_MESH_IVU_PENDING ) ;
687689 return false;
688690 }
689691
690692do_update :
691- bt_mesh .iv_update = iv_update ;
693+ atomic_set_bit_to ( bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS , iv_update ) ;
692694 bt_mesh .ivu_duration = 0U ;
693695
694- if (bt_mesh . iv_update ) {
696+ if (iv_update ) {
695697 bt_mesh .iv_index = iv_index ;
696698 BT_DBG ("IV Update state entered. New index 0x%08x" ,
697699 bt_mesh .iv_index );
@@ -774,7 +776,8 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
774776
775777 bt_mesh_adv_send (buf , cb , cb_data );
776778
777- if (!bt_mesh .iv_update && bt_mesh .seq > IV_UPDATE_SEQ_LIMIT ) {
779+ if (!atomic_test_bit (bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ) &&
780+ bt_mesh .seq > IV_UPDATE_SEQ_LIMIT ) {
778781 bt_mesh_beacon_ivu_initiator (true);
779782 bt_mesh_net_iv_update (bt_mesh .iv_index + 1 , true);
780783 bt_mesh_net_sec_update (NULL );
@@ -1340,7 +1343,8 @@ static void ivu_refresh(struct k_work *work)
13401343 bt_mesh .ivu_duration += BT_MESH_IVU_HOURS ;
13411344
13421345 BT_DBG ("%s for %u hour%s" ,
1343- bt_mesh .iv_update ? "IVU in Progress" : "IVU Normal mode" ,
1346+ atomic_test_bit (bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ) ?
1347+ "IVU in Progress" : "IVU Normal mode" ,
13441348 bt_mesh .ivu_duration , bt_mesh .ivu_duration == 1 ? "" : "s" );
13451349
13461350 if (bt_mesh .ivu_duration < BT_MESH_IVU_MIN_HOURS ) {
@@ -1352,7 +1356,7 @@ static void ivu_refresh(struct k_work *work)
13521356 return ;
13531357 }
13541358
1355- if (bt_mesh .iv_update ) {
1359+ if (atomic_test_bit ( bt_mesh .flags , BT_MESH_IVU_IN_PROGRESS ) ) {
13561360 bt_mesh_beacon_ivu_initiator (true);
13571361 bt_mesh_net_iv_update (bt_mesh .iv_index , false);
13581362 } else if (IS_ENABLED (CONFIG_BT_SETTINGS )) {
0 commit comments