@@ -79,14 +79,28 @@ APP_FP_ADV_TRIGGER_REGISTER(fp_adv_trigger_fmdn_provisioning, "fmdn_provisioning
79
79
*/
80
80
APP_FP_ADV_TRIGGER_REGISTER (fp_adv_trigger_ui , "ui" );
81
81
82
- static bool factory_reset_executed ;
83
82
static enum factory_reset_trigger factory_reset_trigger ;
84
83
85
84
static void init_work_handle (struct k_work * w );
86
85
87
86
static K_SEM_DEFINE (init_work_sem , 0 , 1 ) ;
88
87
static K_WORK_DEFINE (init_work , init_work_handle ) ;
89
88
89
+ static void fmdn_provisioning_state_set (bool provisioned )
90
+ {
91
+ __ASSERT_NO_MSG (bt_fast_pair_fmdn_is_provisioned () == provisioned );
92
+
93
+ if (fmdn_provisioned == provisioned ) {
94
+ return ;
95
+ }
96
+
97
+ LOG_INF ("FMDN: state changed to %s" ,
98
+ provisioned ? "provisioned" : "unprovisioned" );
99
+
100
+ app_ui_state_change_indicate (APP_UI_STATE_PROVISIONED , provisioned );
101
+ fmdn_provisioned = provisioned ;
102
+ }
103
+
90
104
static void fmdn_factory_reset_prepare (void )
91
105
{
92
106
/* Disable advertising requests related to the FMDN. */
@@ -100,9 +114,20 @@ static void fmdn_factory_reset_prepare(void)
100
114
101
115
static void fmdn_factory_reset_executed (void )
102
116
{
117
+ if (factory_reset_trigger != FACTORY_RESET_TRIGGER_NONE ) {
118
+ LOG_INF ("The device has been reset to factory settings" );
119
+ LOG_INF ("Please press a button to put the device in the Fast Pair discoverable "
120
+ "advertising mode" );
121
+ }
122
+
103
123
/* Clear the trigger state for the scheduled factory reset operations. */
104
124
factory_reset_trigger = FACTORY_RESET_TRIGGER_NONE ;
105
- factory_reset_executed = true;
125
+
126
+ fmdn_provisioning_state_set (bt_fast_pair_fmdn_is_provisioned ());
127
+ __ASSERT_NO_MSG (!fmdn_provisioned );
128
+
129
+ fp_account_key_present = bt_fast_pair_has_account_key ();
130
+ __ASSERT_NO_MSG (!fp_account_key_present );
106
131
}
107
132
108
133
APP_FACTORY_RESET_CALLBACKS_REGISTER (factory_reset_cbs , fmdn_factory_reset_prepare ,
@@ -421,75 +446,66 @@ static void fmdn_conn_authenticated(struct bt_conn *conn)
421
446
fmdn_conn_auth_bm_conn_status_set (conn , true);
422
447
}
423
448
424
- static bool fmdn_provisioning_state_is_first_cb_after_bootup ( void )
449
+ static void fmdn_provisioning_state_changed ( bool provisioned )
425
450
{
426
- static bool first_cb_after_bootup = true;
427
- bool is_first_cb_after_bootup = first_cb_after_bootup ;
451
+ fmdn_provisioning_state_set (provisioned );
452
+ if (provisioned ) {
453
+ /* Fast Pair Implementation Guidelines for the locator tag use case:
454
+ * cancel the provisioning timeout.
455
+ */
456
+ if (factory_reset_trigger == FACTORY_RESET_TRIGGER_PROVISIONING_TIMEOUT ) {
457
+ fmdn_factory_reset_cancel ();
458
+ }
428
459
429
- first_cb_after_bootup = false;
460
+ app_fp_adv_request ( & fp_adv_trigger_fmdn_provisioning , false) ;
430
461
431
- return is_first_cb_after_bootup ;
432
- }
462
+ fp_adv_ui_request = false;
463
+ app_fp_adv_request (& fp_adv_trigger_ui , fp_adv_ui_request );
464
+ } else {
465
+ /* Fast Pair Implementation Guidelines for the locator tag use case:
466
+ * trigger the reset to factory settings on the unprovisioning operation.
467
+ *
468
+ * Delay the factory reset operation to allow the local device
469
+ * to send a response to the unprovisioning command and give
470
+ * the connected peer necessary time to finalize its operations
471
+ * and shutdown the connection.
472
+ */
473
+ fmdn_factory_reset_schedule (FACTORY_RESET_TRIGGER_KEY_STATE_MISMATCH ,
474
+ K_SECONDS (FACTORY_RESET_DELAY ));
433
475
434
- static void fmdn_provisioning_state_changed (bool provisioned )
435
- {
436
- bool clock_sync_required = fmdn_provisioning_state_is_first_cb_after_bootup () &&
437
- provisioned ;
476
+ app_fp_adv_request (& fp_adv_trigger_clock_sync , false);
477
+ }
478
+ }
438
479
439
- LOG_INF ("FMDN: state changed to %s" ,
440
- provisioned ? "provisioned" : "unprovisioned" );
480
+ static struct bt_fast_pair_fmdn_info_cb fmdn_info_cb = {
481
+ .clock_synced = fmdn_clock_synced ,
482
+ .conn_authenticated = fmdn_conn_authenticated ,
483
+ .provisioning_state_changed = fmdn_provisioning_state_changed ,
484
+ };
441
485
442
- app_ui_state_change_indicate (APP_UI_STATE_PROVISIONED , provisioned );
443
- fmdn_provisioned = provisioned ;
486
+ static void fmdn_provisioning_state_init (void )
487
+ {
488
+ bool provisioned ;
444
489
445
- /* Fast Pair Implementation Guidelines for the locator tag use case:
446
- * cancel the provisioning timeout.
447
- */
448
- if (provisioned &&
449
- (factory_reset_trigger == FACTORY_RESET_TRIGGER_PROVISIONING_TIMEOUT )) {
450
- fmdn_factory_reset_cancel ();
451
- }
490
+ provisioned = bt_fast_pair_fmdn_is_provisioned ();
491
+ fmdn_provisioning_state_set (provisioned );
452
492
453
493
/* Fast Pair Implementation Guidelines for the locator tag use case:
454
- * trigger the reset to factory settings on the unprovisioning operation
455
- * or on the loss of the Owner Account Key .
494
+ * trigger the reset to factory settings on the mismatch between the
495
+ * Owner Account Key and the FMDN provisioning state .
456
496
*/
457
497
fp_account_key_present = bt_fast_pair_has_account_key ();
458
498
if (fp_account_key_present != provisioned ) {
459
- /* Delay the factory reset operation to allow the local device
460
- * to send a response to the unprovisioning command and give
461
- * the connected peer necessary time to finalize its operations
462
- * and shutdown the connection.
463
- */
464
- fmdn_factory_reset_schedule (
465
- FACTORY_RESET_TRIGGER_KEY_STATE_MISMATCH ,
466
- K_SECONDS (FACTORY_RESET_DELAY ));
499
+ fmdn_factory_reset_schedule (FACTORY_RESET_TRIGGER_KEY_STATE_MISMATCH , K_NO_WAIT );
467
500
return ;
468
501
}
469
502
470
- /* Triggered on the unprovisioning operation. */
471
- if (factory_reset_executed ) {
472
- LOG_INF ("The device has been reset to factory settings" );
473
- LOG_INF ("Please press a button to put the device in the Fast Pair discoverable "
474
- "advertising mode" );
475
-
476
- factory_reset_executed = false;
477
- return ;
478
- }
479
-
480
- app_fp_adv_request (& fp_adv_trigger_clock_sync , clock_sync_required );
481
- app_fp_adv_request (& fp_adv_trigger_fmdn_provisioning , false);
503
+ app_fp_adv_request (& fp_adv_trigger_clock_sync , provisioned );
482
504
483
505
fp_adv_ui_request = !provisioned ;
484
506
app_fp_adv_request (& fp_adv_trigger_ui , fp_adv_ui_request );
485
507
}
486
508
487
- static struct bt_fast_pair_fmdn_info_cb fmdn_info_cb = {
488
- .clock_synced = fmdn_clock_synced ,
489
- .conn_authenticated = fmdn_conn_authenticated ,
490
- .provisioning_state_changed = fmdn_provisioning_state_changed ,
491
- };
492
-
493
509
static void fp_adv_state_changed (bool enabled )
494
510
{
495
511
app_ui_state_change_indicate (APP_UI_STATE_FP_ADV , enabled );
@@ -686,6 +702,8 @@ static void init_work_handle(struct k_work *w)
686
702
return ;
687
703
}
688
704
705
+ fmdn_provisioning_state_init ();
706
+
689
707
k_sem_give (& init_work_sem );
690
708
}
691
709
0 commit comments