|
| 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_ */ |
0 commit comments