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