@@ -141,6 +141,8 @@ static int fp_adv_payload_set(bool rpa_rotated, bool new_session)
141141 struct bt_data ad [ad_len ];
142142 struct bt_data sd [sd_len ];
143143
144+ __ASSERT (fp_adv_set , "Fast Pair: invalid state of the advertising set" );
145+
144146 /* Set advertising mode of Fast Pair advertising data provider. */
145147 fp_adv_prov_configure (fp_adv_mode );
146148
@@ -181,26 +183,27 @@ static int bt_stack_advertising_update(void)
181183 int err ;
182184 struct bt_le_ext_adv_start_param ext_adv_start_param = {0 };
183185
184- err = bt_le_ext_adv_stop (fp_adv_set );
185- if (err ) {
186- LOG_ERR ("Fast Pair: cannot stop advertising (err: %d)" , err );
187- return err ;
188- }
186+ __ASSERT (fp_adv_set , "Fast Pair: invalid state of the advertising set" );
187+ __ASSERT (!fp_conn , "Fast Pair: invalid connection state" );
189188
190189 if (fp_adv_mode == APP_FP_ADV_MODE_OFF ) {
191- return 0 ;
192- }
193-
194- err = fp_adv_payload_set (false, true);
195- if (err ) {
196- LOG_ERR ("Fast Pair: cannot set advertising payload (err: %d)" , err );
197- return err ;
198- }
190+ err = bt_le_ext_adv_stop (fp_adv_set );
191+ if (err ) {
192+ LOG_ERR ("Fast Pair: cannot stop advertising (err: %d)" , err );
193+ return err ;
194+ }
195+ } else {
196+ err = fp_adv_payload_set (false, true);
197+ if (err ) {
198+ LOG_ERR ("Fast Pair: cannot set advertising payload (err: %d)" , err );
199+ return err ;
200+ }
199201
200- err = bt_le_ext_adv_start (fp_adv_set , & ext_adv_start_param );
201- if (err ) {
202- LOG_ERR ("Fast Pair: bt_le_ext_adv_start returned error: %d" , err );
203- return err ;
202+ err = bt_le_ext_adv_start (fp_adv_set , & ext_adv_start_param );
203+ if (err ) {
204+ LOG_ERR ("Fast Pair: bt_le_ext_adv_start returned error: %d" , err );
205+ return err ;
206+ }
204207 }
205208
206209 return 0 ;
@@ -210,16 +213,6 @@ static void fp_advertising_update(void)
210213{
211214 int err ;
212215
213- if (!fp_adv_set ) {
214- /* Advertising set is not prepared yet. */
215- return ;
216- }
217-
218- if (fp_conn ) {
219- /* Only one Fast Pair connection is supported. */
220- return ;
221- }
222-
223216 err = bt_stack_advertising_update ();
224217 if (!err ) {
225218 app_ui_state_change_indicate (APP_UI_STATE_FP_ADV ,
@@ -347,7 +340,9 @@ static int fp_adv_set_teardown(void)
347340
348341static void fp_adv_restart_work_handle (struct k_work * w )
349342{
350- fp_advertising_update ();
343+ if (app_fp_adv_is_ready ()) {
344+ fp_advertising_update ();
345+ }
351346}
352347
353348static void fp_adv_conn_clear (void )
@@ -446,13 +441,17 @@ static uint8_t fp_adv_trigger_idx_get(struct app_fp_adv_trigger *trigger)
446441
447442static void fp_adv_mode_set (enum app_fp_adv_mode adv_mode )
448443{
444+ if (fp_adv_mode == adv_mode ) {
445+ return ;
446+ }
447+
449448 fp_adv_mode = adv_mode ;
450449
451450 if (!fp_conn ) {
452451 /* Support only one connection for the Fast Pair advertising set. */
453452 fp_advertising_update ();
454453 } else {
455- LOG_INF ("Fast Pair: automatically switched to %s advertising mode" ,
454+ LOG_INF ("Fast Pair: advertising switched to %s mode" ,
456455 fp_adv_mode_description [fp_adv_mode ]);
457456 LOG_INF ("Fast Pair: advertising inactive due to an active connection" );
458457 }
@@ -493,15 +492,23 @@ void app_fp_adv_request(struct app_fp_adv_trigger *trigger, bool enable)
493492 LOG_INF ("Fast Pair: advertising request from trigger \"%s\": %sable" ,
494493 trigger -> id , enable ? "en" : "dis" );
495494
496- if (is_enabled ) {
495+ if (app_fp_adv_is_ready () ) {
497496 fp_adv_mode_update ();
498497 }
499498}
500499
501500void app_fp_adv_payload_refresh (void )
502501{
503- if (fp_adv_mode != APP_FP_ADV_MODE_OFF ) {
504- fp_adv_mode_set (fp_adv_mode );
502+ int err ;
503+
504+ if (fp_adv_mode == APP_FP_ADV_MODE_OFF ) {
505+ return ;
506+ }
507+
508+ err = fp_adv_payload_set (false, true);
509+ if (err ) {
510+ LOG_ERR ("Fast Pair: cannot refresh the advertising payload (err: %d)" , err );
511+ return ;
505512 }
506513}
507514
0 commit comments