Skip to content

Commit 35a7c67

Browse files
committed
bluetooth: fast_pair: introduce Fast Pair advertising manager
Added the new Fast Pair advertising manager module to the Google Fast Pair subsystem. The new module is used by the Fast Pair Locator Tag sample. Ref: NCSDK-30487 Signed-off-by: Kamil Piszczek <[email protected]>
1 parent ed97cd7 commit 35a7c67

File tree

21 files changed

+1583
-1071
lines changed

21 files changed

+1583
-1071
lines changed
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef BT_FAST_PAIR_ADV_MANAGER_H_
8+
#define BT_FAST_PAIR_ADV_MANAGER_H_
9+
10+
#include <stdint.h>
11+
12+
#include <zephyr/sys/slist.h>
13+
14+
/**
15+
* @defgroup bt_fast_pair_adv_manager Fast Pair Advertising Manager API
16+
* @brief Fast Pair Advertising Manager API for managing the Fast Pair advertising set
17+
*
18+
* It is required to use the Fast Pair Advertising Manager API in the cooperative thread
19+
* context. Following this requirement guarantees a proper synchronization between the
20+
* user operations and the module operations.
21+
*
22+
* @{
23+
*/
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/** Configuration of the Fast Pair Advertising Manager trigger. */
30+
struct bt_fast_pair_adv_manager_trigger_config {
31+
/** Request activation of the pairing mode.
32+
*
33+
* The pairing mode is active if at least one Fast Pair Advertising Manager trigger is
34+
* enabled while having this flag set to true.
35+
*
36+
* The change of the pairing mode state always triggers the advertising payload update.
37+
*/
38+
bool pairing_mode;
39+
40+
/** Request suspension of the RPA rotations used by Fast Pair advertising set.
41+
*
42+
* The RPA rotation is suspended if at least one Fast Pair Advertising Manager trigger is
43+
* enabled while having this flag set to true.
44+
*
45+
* Use with caution, as this flag decreases the privacy of the advertiser by freezing
46+
* its RPA rotations. It is typically used for triggers that are only active for a short
47+
* period of time.
48+
*/
49+
bool suspend_rpa;
50+
};
51+
52+
/** @brief Check if the Fast Pair Advertising Manager is in the pairing mode.
53+
*
54+
* This function can be used to synchronously check if the Fast Pair Advertising Manager is in
55+
* the pairing mode. In the pairing mode, the Fast Pair advertising set uses the discoverable
56+
* advertising payload. Otherwise, the not discoverable payload is used.
57+
*
58+
* The pairing mode is active if at least one Fast Pair Advertising Manager trigger is enabled
59+
* with the @ref bt_fast_pair_adv_manager_request function and is configured for the pairing mode.
60+
* The @ref bt_fast_pair_adv_manager_trigger_config.pairing_mode flag is used to configure the
61+
* pairing mode for the trigger.
62+
*
63+
* @retval true If the Fast Pair Advertising Manager is configured for the pairing mode.
64+
* @retval false Otherwise.
65+
*/
66+
bool bt_fast_pair_adv_manager_is_pairing_mode(void);
67+
68+
/** Fast Pair Advertising Manager trigger. */
69+
struct bt_fast_pair_adv_manager_trigger {
70+
/** Identifier. */
71+
const char *id;
72+
73+
/** Configuration. */
74+
const struct bt_fast_pair_adv_manager_trigger_config * const config;
75+
};
76+
77+
/** @brief Register a trigger in the Fast Pair Advertising Manager.
78+
*
79+
* @param _name Trigger structure name.
80+
* @param _id Trigger identifier.
81+
* @param _config Trigger configuration.
82+
*/
83+
#define BT_FAST_PAIR_ADV_MANAGER_TRIGGER_REGISTER(_name, _id, _config) \
84+
BUILD_ASSERT(_id != NULL); \
85+
static STRUCT_SECTION_ITERABLE(bt_fast_pair_adv_manager_trigger, _name) = { \
86+
.id = _id, \
87+
.config = _config, \
88+
}
89+
90+
/** @brief Request turning on the Fast Pair advertising.
91+
*
92+
* The Fast Pair advertising will be turned off only when no trigger has requested to keep
93+
* the Fast Pair advertising on.
94+
*
95+
* The Fast Pair Advertising Manager module may change its operating mode in response to the
96+
* requesting trigger configuration (see the @ref bt_fast_pair_adv_manager_trigger_config).
97+
* For example, this module operates in the pairing mode if at least one advertising trigger
98+
* is enabled with this function and is configured for the pairing mode. For more details
99+
* on how other fields from the @ref bt_fast_pair_adv_manager_trigger_config structure affect
100+
* the advertising state of the module, see the structure documentation.
101+
*
102+
* The pairing mode state changes of the Fast Pair Advertising Manager module cause the Fast
103+
* Pair advertising payload update. Apart from this exception, the activation of the trigger
104+
* when the Fast Pair advertising is already enabled do not cause the advertising payload
105+
* update. The @ref bt_fast_pair_adv_manager_payload_refresh can be used to refresh the payload
106+
* instantly if necessary.
107+
*
108+
* You can mark the trigger as enabled and set its configuration using the
109+
* @ref bt_fast_pair_adv_manager_request function when the Fast Pair Advertising Manager module
110+
* is still disabled.
111+
*
112+
* @param trigger Trigger identifier.
113+
* @param enable true to request to turn on the Fast Pair advertising.
114+
* false to remove request to turn on the Fast Pair advertising.
115+
*/
116+
void bt_fast_pair_adv_manager_request(struct bt_fast_pair_adv_manager_trigger *trigger,
117+
bool enable);
118+
119+
/** @brief Refresh the Fast Pair advertising payload.
120+
*
121+
* This function is used to manually trigger the refreshing of the Fast Pair advertising data
122+
* to ensure that the advertising data is up to date.
123+
*
124+
* Use with caution, as it updates the Fast Pair advertising payload asynchronously to the RPA
125+
* address rotation and to the update of other active advertising sets (for example, the FMDN
126+
* advertising set).
127+
*/
128+
void bt_fast_pair_adv_manager_payload_refresh(void);
129+
130+
/** @brief Set the Bluetooth identity for the Fast Pair advertising.
131+
*
132+
* This identity shall be created with the bt_id_create function that is available in the
133+
* Bluetooth API. You can only set the Bluetooth identity when the Fast Pair Advertising
134+
* Manager module is disabled. If you do not explicitly set the identity with this API call,
135+
* the BT_ID_DEFAULT identity is used.
136+
*
137+
* @param id Bluetooth identity for the Fast Pair advertising.
138+
*
139+
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
140+
*/
141+
int bt_fast_pair_adv_manager_id_set(uint8_t id);
142+
143+
/** @brief Get the Bluetooth identity used for the Fast Pair advertising.
144+
*
145+
* @return Bluetooth identity for the Fast Pair advertising.
146+
*/
147+
uint8_t bt_fast_pair_adv_manager_id_get(void);
148+
149+
/** Information callback descriptor for the Fast Pair Advertising Manager. */
150+
struct bt_fast_pair_adv_manager_info_cb {
151+
/** Notify that the advertising state has changed.
152+
*
153+
* This information callback is used to track the state of the Fast Pair advertising set.
154+
* The current state can be used to signal the application mode in the user interface
155+
* (for example, on LEDs).
156+
*
157+
* The @ref bt_fast_pair_adv_manager_is_adv_active API function can be used to
158+
* synchronously check the state of the Fast Pair advertising set.
159+
*
160+
* @param active True: Fast Pair advertising is active.
161+
* False: Fast Pair advertising is inactive.
162+
*/
163+
void (*adv_state_changed)(bool active);
164+
165+
/** Internally used field for list handling. */
166+
sys_snode_t node;
167+
};
168+
169+
/** @brief Register information callbacks for the Fast Pair Advertising Manager.
170+
*
171+
* This function registers an instance of information callbacks. The registered instance needs
172+
* to persist in the memory after this function exits, as it is used directly without the copy
173+
* operation.
174+
*
175+
* This function can only be called before enabling the Fast Pair Advertising Manager module
176+
* with the @ref bt_fast_pair_adv_manager_enable API.
177+
*
178+
* @param cb Callback struct.
179+
*
180+
* @return Zero on success or negative error code otherwise
181+
*/
182+
int bt_fast_pair_adv_manager_info_cb_register(struct bt_fast_pair_adv_manager_info_cb *cb);
183+
184+
/** @brief Check if the Fast Pair advertising set is active.
185+
*
186+
* This function can be used to synchronously check if the Fast Pair advertising set is
187+
* currently being advertised. To track the advertising state asynchronously, use the
188+
* @ref bt_fast_pair_adv_manager_info_cb.adv_state_changed callback.
189+
*
190+
* @retval true If the Fast Pair advertising set is active.
191+
* @retval false Otherwise.
192+
*/
193+
bool bt_fast_pair_adv_manager_is_adv_active(void);
194+
195+
/** @brief Enable the Fast Pair Advertising Manager module.
196+
*
197+
* This function enables the Fast Pair Advertising Manager module. If any trigger is enabled
198+
* with the @ref bt_fast_pair_adv_manager_request function, the module activates the Fair Pair
199+
* advertising in the context of this function. Provided that the module starts advertising
200+
* and the @ref bt_fast_pair_adv_manager_info_cb.adv_state_changed callback is registered,
201+
* the callback will be triggered in the context of this function to indicate that the Fast
202+
* Pair advertising set is active.
203+
*
204+
* This API must be called when the Fast Pair subsystem is ready (see the @ref
205+
* bt_fast_pair_is_ready function).
206+
*
207+
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
208+
*/
209+
int bt_fast_pair_adv_manager_enable(void);
210+
211+
/** @brief Disable the Fast Pair Advertising Manager module.
212+
*
213+
* This function disables the Fast Pair Advertising Manager module. If the Fast Pair advertising
214+
* is active, the module stops the advertising activity in the context of this function. If there
215+
* is any pending Fast Pair connection, the module attempts to terminate this connection in the
216+
* context of this function. Provided that the advertising is active before this API call
217+
* and the @ref bt_fast_pair_adv_manager_info_cb.adv_state_changed callback is registered,
218+
* the callback will be triggered in the context of this function to indicate that the Fast
219+
* Pair advertising set is inactive.
220+
*
221+
* This API should be called before the Fast Pair subsystem gets disable (see the @ref
222+
* bt_fast_pair_disable function).
223+
*
224+
* @return 0 if the operation was successful. Otherwise, a (negative) error code is returned.
225+
*/
226+
int bt_fast_pair_adv_manager_disable(void);
227+
228+
/** @brief Check if the Fast Pair Advertising Manager module is ready.
229+
*
230+
* @return true when the module is ready, false otherwise.
231+
*/
232+
bool bt_fast_pair_adv_manager_is_ready(void);
233+
234+
#ifdef __cplusplus
235+
}
236+
#endif
237+
238+
/**
239+
* @}
240+
*/
241+
242+
#endif /* BT_FAST_PAIR_ADV_MANAGER_H_ */

samples/bluetooth/fast_pair/locator_tag/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ project(locator_tag)
1515
target_sources(app PRIVATE
1616
src/main.c
1717
src/factory_reset.c
18-
src/fp_adv.c
1918
)
2019

2120
zephyr_linker_sources(SECTIONS src/factory_reset_callbacks.ld)
2221

23-
zephyr_linker_sources(DATA_SECTIONS src/fp_adv_trigger.ld)
24-
2522
if (CONFIG_APP_DFU)
2623
target_sources(app PRIVATE src/dfu.c)
2724
endif()

samples/bluetooth/fast_pair/locator_tag/configuration/prj.conf

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
3434
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=100
3535
CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT=500
3636

37-
CONFIG_BT_ADV_PROV=y
38-
CONFIG_BT_ADV_PROV_FLAGS=y
39-
CONFIG_BT_ADV_PROV_TX_POWER=y
40-
CONFIG_BT_ADV_PROV_FAST_PAIR=y
41-
CONFIG_BT_ADV_PROV_DEVICE_NAME=y
42-
CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=y
43-
4437
# Disable automatic initiation of PHY updates.
4538
# Workaround to prevent disconnection with reason 42 (BT_HCI_ERR_DIFF_TRANS_COLLISION).
4639
# Some Android phones reply to the LL_PHY_REQ and at the same time initiate a connection
@@ -56,15 +49,26 @@ CONFIG_BT_RPA_TIMEOUT_DYNAMIC=y
5649
CONFIG_BT_MAX_CONN=3
5750
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
5851

52+
# Fast Pair general configuration
5953
CONFIG_BT_FAST_PAIR=y
60-
CONFIG_BT_FAST_PAIR_USE_CASE_LOCATOR_TAG=y
6154
CONFIG_BT_FAST_PAIR_LOG_LEVEL_DBG=y
6255
CONFIG_BT_FAST_PAIR_STORAGE_USER_RESET_ACTION=y
56+
57+
# Fast Pair advertising manager configuration
58+
CONFIG_BT_FAST_PAIR_ADV_MANAGER=y
59+
CONFIG_BT_FAST_PAIR_ADV_MANAGER_USE_CASE_LOCATOR_TAG=y
60+
CONFIG_BT_ADV_PROV=y
61+
CONFIG_BT_ADV_PROV_FLAGS=y
62+
CONFIG_BT_ADV_PROV_TX_POWER=y
63+
CONFIG_BT_ADV_PROV_FAST_PAIR=y
64+
CONFIG_BT_ADV_PROV_DEVICE_NAME=y
65+
CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=y
66+
67+
# FMDN configuration
6368
CONFIG_BT_FAST_PAIR_FMDN_BATTERY_DULT=y
6469
CONFIG_BT_FAST_PAIR_FMDN_RING_COMP_THREE=y
6570
CONFIG_BT_FAST_PAIR_FMDN_RING_VOLUME=y
6671
CONFIG_BT_FAST_PAIR_FMDN_CLOCK_NVM_UPDATE_TIME=10
67-
6872
CONFIG_BT_FAST_PAIR_FMDN_DULT_MANUFACTURER_NAME="Nordic Semiconductor ASA"
6973
CONFIG_BT_FAST_PAIR_FMDN_DULT_MODEL_NAME="NCS locator tag"
7074
# Set Location Tracker Accessory Category.
@@ -99,3 +103,6 @@ CONFIG_BT_DIS_PNP=n
99103
# * nrf54h20dk/nrf54h20/cpuapp
100104
CONFIG_BT_ADV_PROV_TX_POWER_CORRECTION_VAL=-15
101105
CONFIG_BT_FAST_PAIR_FMDN_TX_POWER_CORRECTION_VAL=-15
106+
107+
# Fast Pair use case configuration
108+
CONFIG_BT_FAST_PAIR_USE_CASE_LOCATOR_TAG=y

samples/bluetooth/fast_pair/locator_tag/configuration/prj_release.conf

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ CONFIG_BT_PERIPHERAL_PREF_LATENCY=0
4242
CONFIG_BT_PERIPHERAL_PREF_TIMEOUT=100
4343
CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT=500
4444

45-
CONFIG_BT_ADV_PROV=y
46-
CONFIG_BT_ADV_PROV_FLAGS=y
47-
CONFIG_BT_ADV_PROV_TX_POWER=y
48-
CONFIG_BT_ADV_PROV_FAST_PAIR=y
49-
CONFIG_BT_ADV_PROV_DEVICE_NAME=y
50-
CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=y
51-
5245
# Disable automatic initiation of PHY updates.
5346
# Workaround to prevent disconnection with reason 42 (BT_HCI_ERR_DIFF_TRANS_COLLISION).
5447
# Some Android phones reply to the LL_PHY_REQ and at the same time initiate a connection
@@ -64,14 +57,25 @@ CONFIG_BT_RPA_TIMEOUT_DYNAMIC=y
6457
CONFIG_BT_MAX_CONN=3
6558
CONFIG_BT_EXT_ADV_MAX_ADV_SET=2
6659

60+
# Fast Pair general configuration
6761
CONFIG_BT_FAST_PAIR=y
68-
CONFIG_BT_FAST_PAIR_USE_CASE_LOCATOR_TAG=y
6962
CONFIG_BT_FAST_PAIR_STORAGE_USER_RESET_ACTION=y
63+
64+
# Fast Pair advertising manager configuration
65+
CONFIG_BT_FAST_PAIR_ADV_MANAGER=y
66+
CONFIG_BT_FAST_PAIR_ADV_MANAGER_USE_CASE_LOCATOR_TAG=y
67+
CONFIG_BT_ADV_PROV=y
68+
CONFIG_BT_ADV_PROV_FLAGS=y
69+
CONFIG_BT_ADV_PROV_TX_POWER=y
70+
CONFIG_BT_ADV_PROV_FAST_PAIR=y
71+
CONFIG_BT_ADV_PROV_DEVICE_NAME=y
72+
CONFIG_BT_ADV_PROV_DEVICE_NAME_SD=y
73+
74+
# FMDN configuration
7075
CONFIG_BT_FAST_PAIR_FMDN_BATTERY_DULT=y
7176
CONFIG_BT_FAST_PAIR_FMDN_RING_COMP_THREE=y
7277
CONFIG_BT_FAST_PAIR_FMDN_RING_VOLUME=y
7378
CONFIG_BT_FAST_PAIR_FMDN_CLOCK_NVM_UPDATE_TIME=10
74-
7579
CONFIG_BT_FAST_PAIR_FMDN_DULT_MANUFACTURER_NAME="Nordic Semiconductor ASA"
7680
CONFIG_BT_FAST_PAIR_FMDN_DULT_MODEL_NAME="NCS locator tag"
7781
# Set Location Tracker Accessory Category.
@@ -104,3 +108,6 @@ CONFIG_BT_DIS_PNP=n
104108
# * nrf54h20dk/nrf54h20/cpuapp
105109
CONFIG_BT_ADV_PROV_TX_POWER_CORRECTION_VAL=-15
106110
CONFIG_BT_FAST_PAIR_FMDN_TX_POWER_CORRECTION_VAL=-15
111+
112+
# Fast Pair use case configuration
113+
CONFIG_BT_FAST_PAIR_USE_CASE_LOCATOR_TAG=y

0 commit comments

Comments
 (0)