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