1 /** @file
2  *  @brief Bluetooth subsystem core APIs.
3  */
4 
5 /*
6  * Copyright (c) 2017 Nordic Semiconductor ASA
7  * Copyright (c) 2015-2016 Intel Corporation
8  *
9  * SPDX-License-Identifier: Apache-2.0
10  */
11 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_BLUETOOTH_H_
12 #define ZEPHYR_INCLUDE_BLUETOOTH_BLUETOOTH_H_
13 
14 /**
15  * @brief Bluetooth APIs
16  * @defgroup bluetooth Bluetooth APIs
17  * @ingroup connectivity
18  * @{
19  */
20 
21 #include <stdbool.h>
22 #include <string.h>
23 
24 #include <zephyr/sys/util.h>
25 #include <zephyr/net/buf.h>
26 #include <zephyr/bluetooth/gap.h>
27 #include <zephyr/bluetooth/addr.h>
28 #include <zephyr/bluetooth/crypto.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * @brief Generic Access Profile (GAP)
36  * @defgroup bt_gap Generic Access Profile (GAP)
37  * @since 1.0
38  * @version 1.0.0
39  * @ingroup bluetooth
40  * @{
41  */
42 
43 /**
44  * Convenience macro for specifying the default identity. This helps
45  * make the code more readable, especially when only one identity is
46  * supported.
47  */
48 #define BT_ID_DEFAULT 0
49 
50 /** Opaque type representing an advertiser. */
51 struct bt_le_ext_adv;
52 
53 /** Opaque type representing an periodic advertising sync. */
54 struct bt_le_per_adv_sync;
55 
56 /* Don't require everyone to include conn.h */
57 struct bt_conn;
58 
59 /* Don't require everyone to include iso.h */
60 struct bt_iso_biginfo;
61 
62 /* Don't require everyone to include direction.h */
63 struct bt_df_per_adv_sync_iq_samples_report;
64 
65 struct bt_le_ext_adv_sent_info {
66 	/** The number of advertising events completed. */
67 	uint8_t num_sent;
68 };
69 
70 struct bt_le_ext_adv_connected_info {
71 	/** Connection object of the new connection */
72 	struct bt_conn *conn;
73 };
74 
75 struct bt_le_ext_adv_scanned_info {
76 	/** Active scanner LE address and type */
77 	bt_addr_le_t *addr;
78 };
79 
80 struct bt_le_per_adv_data_request {
81 	/** The first subevent data can be set for */
82 	uint8_t start;
83 
84 	/** The number of subevents data can be set for */
85 	uint8_t count;
86 };
87 
88 struct bt_le_per_adv_response_info {
89 	/** The subevent the response was received in */
90 	uint8_t subevent;
91 
92 	/** @brief Status of the subevent indication.
93 	 *
94 	 * 0 if subevent indication was transmitted.
95 	 * 1 if subevent indication was not transmitted.
96 	 * All other values RFU.
97 	 */
98 	uint8_t tx_status;
99 
100 	/** The TX power of the response in dBm */
101 	int8_t tx_power;
102 
103 	/** The RSSI of the response in dBm */
104 	int8_t rssi;
105 
106 	/** The Constant Tone Extension (CTE) of the advertisement (@ref bt_df_cte_type) */
107 	uint8_t cte_type;
108 
109 	/** The slot the response was received in */
110 	uint8_t response_slot;
111 };
112 
113 struct bt_le_ext_adv_cb {
114 	/**
115 	 * @brief The advertising set has finished sending adv data.
116 	 *
117 	 * This callback notifies the application that the advertising set has
118 	 * finished sending advertising data.
119 	 * The advertising set can either have been stopped by a timeout or
120 	 * because the specified number of advertising events has been reached.
121 	 *
122 	 * @param adv  The advertising set object.
123 	 * @param info Information about the sent event.
124 	 */
125 	void (*sent)(struct bt_le_ext_adv *adv,
126 		     struct bt_le_ext_adv_sent_info *info);
127 
128 	/**
129 	 * @brief The advertising set has accepted a new connection.
130 	 *
131 	 * This callback notifies the application that the advertising set has
132 	 * accepted a new connection.
133 	 *
134 	 * @param adv  The advertising set object.
135 	 * @param info Information about the connected event.
136 	 */
137 	void (*connected)(struct bt_le_ext_adv *adv,
138 			  struct bt_le_ext_adv_connected_info *info);
139 
140 	/**
141 	 * @brief The advertising set has sent scan response data.
142 	 *
143 	 * This callback notifies the application that the advertising set has
144 	 * has received a Scan Request packet, and has sent a Scan Response
145 	 * packet.
146 	 *
147 	 * @param adv  The advertising set object.
148 	 * @param addr Information about the scanned event.
149 	 */
150 	void (*scanned)(struct bt_le_ext_adv *adv,
151 			struct bt_le_ext_adv_scanned_info *info);
152 
153 #if defined(CONFIG_BT_PRIVACY)
154 	/**
155 	 * @brief The RPA validity of the advertising set has expired.
156 	 *
157 	 * This callback notifies the application that the RPA validity of
158 	 * the advertising set has expired. The user can use this callback
159 	 * to synchronize the advertising payload update with the RPA rotation.
160 	 *
161 	 * If rpa sharing is enabled and rpa expired cb of any adv-sets belonging
162 	 * to same adv id returns false, then adv-sets will continue with old rpa
163 	 * through out the rpa rotations.
164 	 *
165 	 * @param adv  The advertising set object.
166 	 *
167 	 * @return true to rotate the current RPA, or false to use it for the
168 	 *         next rotation period.
169 	 */
170 	bool (*rpa_expired)(struct bt_le_ext_adv *adv);
171 #endif /* defined(CONFIG_BT_PRIVACY) */
172 
173 #if defined(CONFIG_BT_PER_ADV_RSP)
174 	/**
175 	 * @brief The Controller indicates it is ready to transmit one or more subevent.
176 	 *
177 	 * This callback notifies the application that the controller has requested
178 	 * data for upcoming subevents.
179 	 *
180 	 * @param adv     The advertising set object.
181 	 * @param request Information about the upcoming subevents.
182 	 */
183 	void (*pawr_data_request)(struct bt_le_ext_adv *adv,
184 				  const struct bt_le_per_adv_data_request *request);
185 	/**
186 	 * @brief The Controller indicates that one or more synced devices have
187 	 * responded to a periodic advertising subevent indication.
188 	 *
189 	 * @param adv  The advertising set object.
190 	 * @param info Information about the responses received.
191 	 * @param buf  The received data. NULL if the controller reported
192 	 *             that it did not receive any response.
193 	 */
194 	void (*pawr_response)(struct bt_le_ext_adv *adv, struct bt_le_per_adv_response_info *info,
195 			      struct net_buf_simple *buf);
196 
197 #endif /* defined(CONFIG_BT_PER_ADV_RSP) */
198 };
199 
200 /**
201  * @typedef bt_ready_cb_t
202  * @brief Callback for notifying that Bluetooth has been enabled.
203  *
204  * @param err zero on success or (negative) error code otherwise.
205  */
206 typedef void (*bt_ready_cb_t)(int err);
207 
208 /**
209  * @brief Enable Bluetooth
210  *
211  * Enable Bluetooth. Must be the called before any calls that
212  * require communication with the local Bluetooth hardware.
213  *
214  * When @kconfig{CONFIG_BT_SETTINGS} is enabled, the application must load the
215  * Bluetooth settings after this API call successfully completes before
216  * Bluetooth APIs can be used. Loading the settings before calling this function
217  * is insufficient. Bluetooth settings can be loaded with settings_load() or
218  * settings_load_subtree() with argument "bt". The latter selectively loads only
219  * Bluetooth settings and is recommended if settings_load() has been called
220  * earlier.
221  *
222  * @param cb Callback to notify completion or NULL to perform the
223  * enabling synchronously. The callback is called from the system workqueue.
224  *
225  * @return Zero on success or (negative) error code otherwise.
226  */
227 int bt_enable(bt_ready_cb_t cb);
228 
229 /**
230  * @brief Disable Bluetooth
231  *
232  * Disable Bluetooth. Can't be called before bt_enable has completed.
233  *
234  * This API will clear all configured identities and keys that are not persistently
235  * stored with @kconfig{CONFIG_BT_SETTINGS}. These can be restored
236  * with settings_load() before reenabling the stack.
237  *
238  * This API does _not_ clear previously registered callbacks
239  * like @ref bt_le_scan_cb_register and @ref bt_conn_cb_register.
240  * That is, the application shall not re-register them when
241  * the Bluetooth subsystem is re-enabled later.
242  *
243  * Close and release HCI resources. Result is architecture dependent.
244  *
245  * @return Zero on success or (negative) error code otherwise.
246  */
247 int bt_disable(void);
248 
249 /**
250  * @brief Check if Bluetooth is ready
251  *
252  * @return true when Bluetooth is ready, false otherwise
253  */
254 bool bt_is_ready(void);
255 
256 /**
257  * @brief Set Bluetooth Device Name
258  *
259  * Set Bluetooth GAP Device Name.
260  *
261  * When advertising with device name in the advertising data the name should
262  * be updated by calling @ref bt_le_adv_update_data or
263  * @ref bt_le_ext_adv_set_data.
264  *
265  * @note Requires @kconfig{CONFIG_BT_DEVICE_NAME_DYNAMIC}.
266  *
267  * @sa @kconfig{CONFIG_BT_DEVICE_NAME_MAX}.
268  *
269  * @param name New name
270  *
271  * @return Zero on success or (negative) error code otherwise.
272  */
273 int bt_set_name(const char *name);
274 
275 /**
276  * @brief Get Bluetooth Device Name
277  *
278  * Get Bluetooth GAP Device Name.
279  *
280  * @return Bluetooth Device Name
281  */
282 const char *bt_get_name(void);
283 
284 /**
285  * @brief Get local Bluetooth appearance
286  *
287  * Bluetooth Appearance is a description of the external appearance of a device
288  * in terms of an Appearance Value.
289  *
290  * @see https://specificationrefs.bluetooth.com/assigned-values/Appearance%20Values.pdf
291  *
292  * @returns Appearance Value of local Bluetooth host.
293  */
294 uint16_t bt_get_appearance(void);
295 
296 /**
297  * @brief Set local Bluetooth appearance
298  *
299  * Automatically preserves the new appearance across reboots if
300  * @kconfig{CONFIG_BT_SETTINGS} is enabled.
301  *
302  * This symbol is linkable if @kconfig{CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC} is
303  * enabled.
304  *
305  * @param new_appearance Appearance Value
306  *
307  * @retval 0 Success.
308  * @retval other Persistent storage failed. Appearance was not updated.
309  */
310 int bt_set_appearance(uint16_t new_appearance);
311 
312 /**
313  * @brief Get the currently configured identities.
314  *
315  * Returns an array of the currently configured identity addresses. To
316  * make sure all available identities can be retrieved, the number of
317  * elements in the @a addrs array should be CONFIG_BT_ID_MAX. The identity
318  * identifier that some APIs expect (such as advertising parameters) is
319  * simply the index of the identity in the @a addrs array.
320  *
321  * If @a addrs is passed as NULL, then returned @a count contains the
322  * count of all available identities that can be retrieved with a
323  * subsequent call to this function with non-NULL @a addrs parameter.
324  *
325  * @note Deleted identities may show up as @ref BT_ADDR_LE_ANY in the returned
326  * array.
327  *
328  * @param addrs Array where to store the configured identities.
329  * @param count Should be initialized to the array size. Once the function
330  *              returns it will contain the number of returned identities.
331  */
332 void bt_id_get(bt_addr_le_t *addrs, size_t *count);
333 
334 /**
335  * @brief Create a new identity.
336  *
337  * Create a new identity using the given address and IRK. This function can be
338  * called before calling bt_enable(). However, the new identity will only be
339  * stored persistently in flash when this API is used after bt_enable(). The
340  * reason is that the persistent settings are loaded after bt_enable() and would
341  * therefore cause potential conflicts with the stack blindly overwriting what's
342  * stored in flash. The identity will also not be written to flash in case a
343  * pre-defined address is provided, since in such a situation the app clearly
344  * has some place it got the address from and will be able to repeat the
345  * procedure on every power cycle, i.e. it would be redundant to also store the
346  * information in flash.
347  *
348  * Generating random static address or random IRK is not supported when calling
349  * this function before bt_enable().
350  *
351  * If the application wants to have the stack randomly generate identities
352  * and store them in flash for later recovery, the way to do it would be
353  * to first initialize the stack (using bt_enable), then call settings_load(),
354  * and after that check with bt_id_get() how many identities were recovered.
355  * If an insufficient amount of identities were recovered the app may then
356  * call bt_id_create() to create new ones.
357  *
358  * If supported by the HCI driver (indicated by setting
359  * @kconfig{CONFIG_BT_HCI_SET_PUBLIC_ADDR}), the first call to this function can be
360  * used to set the controller's public identity address. This call must happen
361  * before calling bt_enable(). Subsequent calls always add/generate random
362  * static addresses.
363  *
364  * @param addr Address to use for the new identity. If NULL or initialized
365  *             to BT_ADDR_LE_ANY the stack will generate a new random
366  *             static address for the identity and copy it to the given
367  *             parameter upon return from this function (in case the
368  *             parameter was non-NULL).
369  * @param irk  Identity Resolving Key (16 bytes) to be used with this
370  *             identity. If set to all zeroes or NULL, the stack will
371  *             generate a random IRK for the identity and copy it back
372  *             to the parameter upon return from this function (in case
373  *             the parameter was non-NULL). If privacy
374  *             @kconfig{CONFIG_BT_PRIVACY} is not enabled this parameter must
375  *             be NULL.
376  *
377  * @return Identity identifier (>= 0) in case of success, or a negative
378  *         error code on failure.
379  */
380 int bt_id_create(bt_addr_le_t *addr, uint8_t *irk);
381 
382 /**
383  * @brief Reset/reclaim an identity for reuse.
384  *
385  * The semantics of the @a addr and @a irk parameters of this function
386  * are the same as with bt_id_create(). The difference is the first
387  * @a id parameter that needs to be an existing identity (if it doesn't
388  * exist this function will return an error). When given an existing
389  * identity this function will disconnect any connections created using it,
390  * remove any pairing keys or other data associated with it, and then create
391  * a new identity in the same slot, based on the @a addr and @a irk
392  * parameters.
393  *
394  * @note the default identity (BT_ID_DEFAULT) cannot be reset, i.e. this
395  * API will return an error if asked to do that.
396  *
397  * @param id   Existing identity identifier.
398  * @param addr Address to use for the new identity. If NULL or initialized
399  *             to BT_ADDR_LE_ANY the stack will generate a new static
400  *             random address for the identity and copy it to the given
401  *             parameter upon return from this function (in case the
402  *             parameter was non-NULL).
403  * @param irk  Identity Resolving Key (16 bytes) to be used with this
404  *             identity. If set to all zeroes or NULL, the stack will
405  *             generate a random IRK for the identity and copy it back
406  *             to the parameter upon return from this function (in case
407  *             the parameter was non-NULL). If privacy
408  *             @kconfig{CONFIG_BT_PRIVACY} is not enabled this parameter must
409  *             be NULL.
410  *
411  * @return Identity identifier (>= 0) in case of success, or a negative
412  *         error code on failure.
413  */
414 int bt_id_reset(uint8_t id, bt_addr_le_t *addr, uint8_t *irk);
415 
416 /**
417  * @brief Delete an identity.
418  *
419  * When given a valid identity this function will disconnect any connections
420  * created using it, remove any pairing keys or other data associated with
421  * it, and then flag is as deleted, so that it can not be used for any
422  * operations. To take back into use the slot the identity was occupying the
423  * bt_id_reset() API needs to be used.
424  *
425  * @note the default identity (BT_ID_DEFAULT) cannot be deleted, i.e. this
426  * API will return an error if asked to do that.
427  *
428  * @param id   Existing identity identifier.
429  *
430  * @return 0 in case of success, or a negative error code on failure.
431  */
432 int bt_id_delete(uint8_t id);
433 
434 /**
435  * @brief Bluetooth data serialized size.
436  *
437  * Get the size of a serialized @ref bt_data given its data length.
438  *
439  * Size of 'AD Structure'->'Length' field, equal to 1.
440  * Size of 'AD Structure'->'Data'->'AD Type' field, equal to 1.
441  * Size of 'AD Structure'->'Data'->'AD Data' field, equal to data_len.
442  *
443  * See Core Specification Version 5.4 Vol. 3 Part C, 11, Figure 11.1.
444  */
445 #define BT_DATA_SERIALIZED_SIZE(data_len) ((data_len) + 2)
446 
447 /**
448  * @brief Bluetooth data.
449  *
450  * Description of different data types that can be encoded into
451  * advertising data. Used to form arrays that are passed to the
452  * bt_le_adv_start() function.
453  */
454 struct bt_data {
455 	uint8_t type;
456 	uint8_t data_len;
457 	const uint8_t *data;
458 };
459 
460 /**
461  * @brief Helper to declare elements of bt_data arrays
462  *
463  * This macro is mainly for creating an array of struct bt_data
464  * elements which is then passed to e.g. @ref bt_le_adv_start().
465  *
466  * @param _type Type of advertising data field
467  * @param _data Pointer to the data field payload
468  * @param _data_len Number of bytes behind the _data pointer
469  */
470 #define BT_DATA(_type, _data, _data_len) \
471 	{ \
472 		.type = (_type), \
473 		.data_len = (_data_len), \
474 		.data = (const uint8_t *)(_data), \
475 	}
476 
477 /**
478  * @brief Helper to declare elements of bt_data arrays
479  *
480  * This macro is mainly for creating an array of struct bt_data
481  * elements which is then passed to e.g. @ref bt_le_adv_start().
482  *
483  * @param _type Type of advertising data field
484  * @param _bytes Variable number of single-byte parameters
485  */
486 #define BT_DATA_BYTES(_type, _bytes...) \
487 	BT_DATA(_type, ((uint8_t []) { _bytes }), \
488 		sizeof((uint8_t []) { _bytes }))
489 
490 /**
491  * @brief Get the total size (in bytes) of a given set of @ref bt_data
492  * structures.
493  *
494  * @param[in] data Array of @ref bt_data structures.
495  * @param[in] data_count Number of @ref bt_data structures in @p data.
496  *
497  * @return Size of the concatenated data, built from the @ref bt_data structure
498  *         set.
499  */
500 size_t bt_data_get_len(const struct bt_data data[], size_t data_count);
501 
502 /**
503  * @brief Serialize a @ref bt_data struct into an advertising structure (a flat
504  * byte array).
505  *
506  * The data are formatted according to the Bluetooth Core Specification v. 5.4,
507  * vol. 3, part C, 11.
508  *
509  * @param[in]  input Single @ref bt_data structure to read from.
510  * @param[out] output Buffer large enough to store the advertising structure in
511  *             @p input. The size of it must be at least the size of the
512  *             `input->data_len + 2` (for the type and the length).
513  *
514  * @return Number of bytes written in @p output.
515  */
516 size_t bt_data_serialize(const struct bt_data *input, uint8_t *output);
517 
518 /** Advertising options */
519 enum {
520 	/** Convenience value when no options are specified. */
521 	BT_LE_ADV_OPT_NONE = 0,
522 
523 	/**
524 	 * @brief Advertise as connectable.
525 	 *
526 	 * Advertise as connectable. If not connectable then the type of
527 	 * advertising is determined by providing scan response data.
528 	 * The advertiser address is determined by the type of advertising
529 	 * and/or enabling privacy @kconfig{CONFIG_BT_PRIVACY}.
530 	 */
531 	BT_LE_ADV_OPT_CONNECTABLE = BIT(0),
532 
533 	/**
534 	 * @brief Advertise one time.
535 	 *
536 	 * Don't try to resume connectable advertising after a connection.
537 	 * This option is only meaningful when used together with
538 	 * BT_LE_ADV_OPT_CONNECTABLE. If set the advertising will be stopped
539 	 * when bt_le_adv_stop() is called or when an incoming (peripheral)
540 	 * connection happens. If this option is not set the stack will
541 	 * take care of keeping advertising enabled even as connections
542 	 * occur.
543 	 * If Advertising directed or the advertiser was started with
544 	 * @ref bt_le_ext_adv_start then this behavior is the default behavior
545 	 * and this flag has no effect.
546 	 */
547 	BT_LE_ADV_OPT_ONE_TIME = BIT(1),
548 
549 	/**
550 	 * @brief Advertise using identity address.
551 	 *
552 	 * Advertise using the identity address as the advertiser address.
553 	 * @warning This will compromise the privacy of the device, so care
554 	 *          must be taken when using this option.
555 	 * @note The address used for advertising will not be the same as
556 	 *        returned by @ref bt_le_oob_get_local, instead @ref bt_id_get
557 	 *        should be used to get the LE address.
558 	 */
559 	BT_LE_ADV_OPT_USE_IDENTITY = BIT(2),
560 
561 	/**
562 	 * @deprecated This option will be removed in the near future, see
563 	 * https://github.com/zephyrproject-rtos/zephyr/issues/71686
564 	 *
565 	 * @brief Advertise using GAP device name.
566 	 *
567 	 * Include the GAP device name automatically when advertising.
568 	 * By default the GAP device name is put at the end of the scan
569 	 * response data.
570 	 * When advertising using @ref BT_LE_ADV_OPT_EXT_ADV and not
571 	 * @ref BT_LE_ADV_OPT_SCANNABLE then it will be put at the end of the
572 	 * advertising data.
573 	 * If the GAP device name does not fit into advertising data it will be
574 	 * converted to a shortened name if possible.
575 	 * @ref BT_LE_ADV_OPT_FORCE_NAME_IN_AD can be used to force the device
576 	 * name to appear in the advertising data of an advert with scan
577 	 * response data.
578 	 *
579 	 * The application can set the device name itself by including the
580 	 * following in the advertising data.
581 	 * @code
582 	 * BT_DATA(BT_DATA_NAME_COMPLETE, name, sizeof(name) - 1)
583 	 * @endcode
584 	 */
585 	BT_LE_ADV_OPT_USE_NAME = BIT(3),
586 
587 	/**
588 	 * @brief Low duty cycle directed advertising.
589 	 *
590 	 * Use low duty directed advertising mode, otherwise high duty mode
591 	 * will be used.
592 	 */
593 	BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY = BIT(4),
594 
595 	/**
596 	 * @brief Directed advertising to privacy-enabled peer.
597 	 *
598 	 * Enable use of Resolvable Private Address (RPA) as the target address
599 	 * in directed advertisements.
600 	 * This is required if the remote device is privacy-enabled and
601 	 * supports address resolution of the target address in directed
602 	 * advertisement.
603 	 * It is the responsibility of the application to check that the remote
604 	 * device supports address resolution of directed advertisements by
605 	 * reading its Central Address Resolution characteristic.
606 	 */
607 	BT_LE_ADV_OPT_DIR_ADDR_RPA = BIT(5),
608 
609 	/** Use filter accept list to filter devices that can request scan
610 	 *  response data.
611 	 */
612 	BT_LE_ADV_OPT_FILTER_SCAN_REQ = BIT(6),
613 
614 	/** Use filter accept list to filter devices that can connect. */
615 	BT_LE_ADV_OPT_FILTER_CONN = BIT(7),
616 
617 	/** Notify the application when a scan response data has been sent to an
618 	 *  active scanner.
619 	 */
620 	BT_LE_ADV_OPT_NOTIFY_SCAN_REQ = BIT(8),
621 
622 	/**
623 	 * @brief Support scan response data.
624 	 *
625 	 * When used together with @ref BT_LE_ADV_OPT_EXT_ADV then this option
626 	 * cannot be used together with the @ref BT_LE_ADV_OPT_CONNECTABLE
627 	 * option.
628 	 * When used together with @ref BT_LE_ADV_OPT_EXT_ADV then scan
629 	 * response data must be set.
630 	 */
631 	BT_LE_ADV_OPT_SCANNABLE = BIT(9),
632 
633 	/**
634 	 * @brief Advertise with extended advertising.
635 	 *
636 	 * This options enables extended advertising in the advertising set.
637 	 * In extended advertising the advertising set will send a small header
638 	 * packet on the three primary advertising channels. This small header
639 	 * points to the advertising data packet that will be sent on one of
640 	 * the 37 secondary advertising channels.
641 	 * The advertiser will send primary advertising on LE 1M PHY, and
642 	 * secondary advertising on LE 2M PHY.
643 	 * Connections will be established on LE 2M PHY.
644 	 *
645 	 * Without this option the advertiser will send advertising data on the
646 	 * three primary advertising channels.
647 	 *
648 	 * @note Enabling this option requires extended advertising support in
649 	 *       the peer devices scanning for advertisement packets.
650 	 *
651 	 * @note This cannot be used with bt_le_adv_start().
652 	 */
653 	BT_LE_ADV_OPT_EXT_ADV = BIT(10),
654 
655 	/**
656 	 * @brief Disable use of LE 2M PHY on the secondary advertising
657 	 * channel.
658 	 *
659 	 * Disabling the use of LE 2M PHY could be necessary if scanners don't
660 	 * support the LE 2M PHY.
661 	 * The advertiser will send primary advertising on LE 1M PHY, and
662 	 * secondary advertising on LE 1M PHY.
663 	 * Connections will be established on LE 1M PHY.
664 	 *
665 	 * @note Cannot be set if BT_LE_ADV_OPT_CODED is set.
666 	 *
667 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV.
668 	 */
669 	BT_LE_ADV_OPT_NO_2M = BIT(11),
670 
671 	/**
672 	 * @brief Advertise on the LE Coded PHY (Long Range).
673 	 *
674 	 * The advertiser will send both primary and secondary advertising
675 	 * on the LE Coded PHY. This gives the advertiser increased range with
676 	 * the trade-off of lower data rate and higher power consumption.
677 	 * Connections will be established on LE Coded PHY.
678 	 *
679 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
680 	 */
681 	BT_LE_ADV_OPT_CODED = BIT(12),
682 
683 	/**
684 	 * @brief Advertise without a device address (identity or RPA).
685 	 *
686 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
687 	 */
688 	BT_LE_ADV_OPT_ANONYMOUS = BIT(13),
689 
690 	/**
691 	 * @brief Advertise with transmit power.
692 	 *
693 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
694 	 */
695 	BT_LE_ADV_OPT_USE_TX_POWER = BIT(14),
696 
697 	/** Disable advertising on channel index 37. */
698 	BT_LE_ADV_OPT_DISABLE_CHAN_37 = BIT(15),
699 
700 	/** Disable advertising on channel index 38. */
701 	BT_LE_ADV_OPT_DISABLE_CHAN_38 = BIT(16),
702 
703 	/** Disable advertising on channel index 39. */
704 	BT_LE_ADV_OPT_DISABLE_CHAN_39 = BIT(17),
705 
706 	/**
707 	 * @deprecated This option will be removed in the near future, see
708 	 * https://github.com/zephyrproject-rtos/zephyr/issues/71686
709 	 *
710 	 * @brief Put GAP device name into advert data
711 	 *
712 	 * Will place the GAP device name into the advertising data rather than
713 	 * the scan response data.
714 	 *
715 	 * @note Requires @ref BT_LE_ADV_OPT_USE_NAME
716 	 */
717 	BT_LE_ADV_OPT_FORCE_NAME_IN_AD = BIT(18),
718 
719 	/**
720 	 * @brief Advertise using a Non-Resolvable Private Address.
721 	 *
722 	 * A new NRPA is set when updating the advertising parameters.
723 	 *
724 	 * This is an advanced feature; most users will want to enable
725 	 * @kconfig{CONFIG_BT_EXT_ADV} instead.
726 	 *
727 	 * @note Not implemented when @kconfig{CONFIG_BT_PRIVACY}.
728 	 *
729 	 * @note Mutually exclusive with BT_LE_ADV_OPT_USE_IDENTITY.
730 	 */
731 	BT_LE_ADV_OPT_USE_NRPA = BIT(19),
732 };
733 
734 /** LE Advertising Parameters. */
735 struct bt_le_adv_param {
736 	/**
737 	 * @brief Local identity.
738 	 *
739 	 * @note When extended advertising @kconfig{CONFIG_BT_EXT_ADV} is not
740 	 *       enabled or not supported by the controller it is not possible
741 	 *       to scan and advertise simultaneously using two different
742 	 *       random addresses.
743 	 */
744 	uint8_t  id;
745 
746 	/**
747 	 * @brief Advertising Set Identifier, valid range 0x00 - 0x0f.
748 	 *
749 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
750 	 **/
751 	uint8_t  sid;
752 
753 	/**
754 	 * @brief Secondary channel maximum skip count.
755 	 *
756 	 * Maximum advertising events the advertiser can skip before it must
757 	 * send advertising data on the secondary advertising channel.
758 	 *
759 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
760 	 */
761 	uint8_t  secondary_max_skip;
762 
763 	/** Bit-field of advertising options */
764 	uint32_t options;
765 
766 	/** Minimum Advertising Interval (N * 0.625 milliseconds)
767 	 * Minimum Advertising Interval shall be less than or equal to the
768 	 * Maximum Advertising Interval. The Minimum Advertising Interval and
769 	 * Maximum Advertising Interval should not be the same value (as stated
770 	 * in Bluetooth Core Spec 5.2, section 7.8.5)
771 	 * Range: 0x0020 to 0x4000
772 	 */
773 	uint32_t interval_min;
774 
775 	/** Maximum Advertising Interval (N * 0.625 milliseconds)
776 	 * Minimum Advertising Interval shall be less than or equal to the
777 	 * Maximum Advertising Interval. The Minimum Advertising Interval and
778 	 * Maximum Advertising Interval should not be the same value (as stated
779 	 * in Bluetooth Core Spec 5.2, section 7.8.5)
780 	 * Range: 0x0020 to 0x4000
781 	 */
782 	uint32_t interval_max;
783 
784 	/**
785 	 * @brief Directed advertising to peer
786 	 *
787 	 * When this parameter is set the advertiser will send directed
788 	 * advertising to the remote device.
789 	 *
790 	 * The advertising type will either be high duty cycle, or low duty
791 	 * cycle if the BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY option is enabled.
792 	 * When using @ref BT_LE_ADV_OPT_EXT_ADV then only low duty cycle is
793 	 * allowed.
794 	 *
795 	 * In case of connectable high duty cycle if the connection could not
796 	 * be established within the timeout the connected() callback will be
797 	 * called with the status set to @ref BT_HCI_ERR_ADV_TIMEOUT.
798 	 */
799 	const bt_addr_le_t *peer;
800 };
801 
802 
803 /** Periodic Advertising options */
804 enum {
805 	/** Convenience value when no options are specified. */
806 	BT_LE_PER_ADV_OPT_NONE = 0,
807 
808 	/**
809 	 * @brief Advertise with transmit power.
810 	 *
811 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
812 	 */
813 	BT_LE_PER_ADV_OPT_USE_TX_POWER = BIT(1),
814 
815 	/**
816 	 * @brief Advertise with included AdvDataInfo (ADI).
817 	 *
818 	 * @note Requires @ref BT_LE_ADV_OPT_EXT_ADV
819 	 */
820 	BT_LE_PER_ADV_OPT_INCLUDE_ADI = BIT(2),
821 };
822 
823 struct bt_le_per_adv_param {
824 	/**
825 	 * @brief Minimum Periodic Advertising Interval (N * 1.25 ms)
826 	 *
827 	 * Shall be greater or equal to BT_GAP_PER_ADV_MIN_INTERVAL and
828 	 * less or equal to interval_max.
829 	 */
830 	uint16_t interval_min;
831 
832 	/**
833 	 * @brief Maximum Periodic Advertising Interval (N * 1.25 ms)
834 	 *
835 	 * Shall be less or equal to BT_GAP_PER_ADV_MAX_INTERVAL and
836 	 * greater or equal to interval_min.
837 	 */
838 	uint16_t interval_max;
839 
840 	/** Bit-field of periodic advertising options */
841 	uint32_t options;
842 
843 #if defined(CONFIG_BT_PER_ADV_RSP)
844 	/**
845 	 * @brief Number of subevents
846 	 *
847 	 * If zero, the periodic advertiser will be a broadcaster, without responses.
848 	 */
849 	uint8_t num_subevents;
850 
851 	/**
852 	 * @brief Interval between subevents (N * 1.25 ms)
853 	 *
854 	 * Shall be between 7.5ms and 318.75 ms.
855 	 */
856 	uint8_t subevent_interval;
857 
858 	/**
859 	 * @brief Time between the advertising packet in a subevent and the
860 	 * first response slot (N * 1.25 ms)
861 	 *
862 	 */
863 	uint8_t response_slot_delay;
864 
865 	/**
866 	 * @brief Time between response slots (N * 0.125 ms)
867 	 *
868 	 * Shall be between 0.25 and 31.875 ms.
869 	 */
870 	uint8_t response_slot_spacing;
871 
872 	/**
873 	 * @brief Number of subevent response slots
874 	 *
875 	 * If zero, response_slot_delay and response_slot_spacing are ignored.
876 	 */
877 	uint8_t num_response_slots;
878 #endif /* CONFIG_BT_PER_ADV_RSP */
879 };
880 
881 /**
882  * @brief Initialize advertising parameters
883  *
884  * @param _options   Advertising Options
885  * @param _int_min   Minimum advertising interval
886  * @param _int_max   Maximum advertising interval
887  * @param _peer      Peer address, set to NULL for undirected advertising or
888  *                   address of peer for directed advertising.
889  */
890 #define BT_LE_ADV_PARAM_INIT(_options, _int_min, _int_max, _peer) \
891 { \
892 	.id = BT_ID_DEFAULT, \
893 	.sid = 0, \
894 	.secondary_max_skip = 0, \
895 	.options = (_options), \
896 	.interval_min = (_int_min), \
897 	.interval_max = (_int_max), \
898 	.peer = (_peer), \
899 }
900 
901 /**
902  * @brief Helper to declare advertising parameters inline
903  *
904  * @param _options   Advertising Options
905  * @param _int_min   Minimum advertising interval
906  * @param _int_max   Maximum advertising interval
907  * @param _peer      Peer address, set to NULL for undirected advertising or
908  *                   address of peer for directed advertising.
909  */
910 #define BT_LE_ADV_PARAM(_options, _int_min, _int_max, _peer) \
911 	((const struct bt_le_adv_param[]) { \
912 		BT_LE_ADV_PARAM_INIT(_options, _int_min, _int_max, _peer) \
913 	 })
914 
915 #define BT_LE_ADV_CONN_DIR(_peer) BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE |  \
916 						  BT_LE_ADV_OPT_ONE_TIME, 0, 0,\
917 						  _peer)
918 
919 
920 #define BT_LE_ADV_CONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE, \
921 				       BT_GAP_ADV_FAST_INT_MIN_2, \
922 				       BT_GAP_ADV_FAST_INT_MAX_2, NULL)
923 
924 /** This is the recommended default for connectable advertisers.
925  */
926 #define BT_LE_ADV_CONN_ONE_TIME                                                                    \
927 	BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME,                        \
928 			BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, NULL)
929 
930 /**
931  * @deprecated This macro will be removed in the near future, see
932  * https://github.com/zephyrproject-rtos/zephyr/issues/71686
933  */
934 #define BT_LE_ADV_CONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \
935 					    BT_LE_ADV_OPT_USE_NAME, \
936 					    BT_GAP_ADV_FAST_INT_MIN_2, \
937 					    BT_GAP_ADV_FAST_INT_MAX_2, NULL) \
938 					    __DEPRECATED_MACRO
939 
940 /**
941  * @deprecated This macro will be removed in the near future, see
942  * https://github.com/zephyrproject-rtos/zephyr/issues/71686
943  */
944 #define BT_LE_ADV_CONN_NAME_AD BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | \
945 					    BT_LE_ADV_OPT_USE_NAME | \
946 					    BT_LE_ADV_OPT_FORCE_NAME_IN_AD, \
947 					    BT_GAP_ADV_FAST_INT_MIN_2, \
948 					    BT_GAP_ADV_FAST_INT_MAX_2, NULL) \
949 					    __DEPRECATED_MACRO
950 
951 #define BT_LE_ADV_CONN_DIR_LOW_DUTY(_peer) \
952 	BT_LE_ADV_PARAM(BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME | \
953 			BT_LE_ADV_OPT_DIR_MODE_LOW_DUTY, \
954 			BT_GAP_ADV_FAST_INT_MIN_2, BT_GAP_ADV_FAST_INT_MAX_2, \
955 			_peer)
956 
957 /** Non-connectable advertising with private address */
958 #define BT_LE_ADV_NCONN BT_LE_ADV_PARAM(0, BT_GAP_ADV_FAST_INT_MIN_2, \
959 					BT_GAP_ADV_FAST_INT_MAX_2, NULL)
960 
961 /**
962  * @deprecated This macro will be removed in the near future, see
963  * https://github.com/zephyrproject-rtos/zephyr/issues/71686
964  *
965  * Non-connectable advertising with @ref BT_LE_ADV_OPT_USE_NAME
966  */
967 #define BT_LE_ADV_NCONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_NAME, \
968 					     BT_GAP_ADV_FAST_INT_MIN_2, \
969 					     BT_GAP_ADV_FAST_INT_MAX_2, NULL) \
970 					     __DEPRECATED_MACRO
971 
972 /** Non-connectable advertising with @ref BT_LE_ADV_OPT_USE_IDENTITY */
973 #define BT_LE_ADV_NCONN_IDENTITY BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_IDENTITY, \
974 						 BT_GAP_ADV_FAST_INT_MIN_2, \
975 						 BT_GAP_ADV_FAST_INT_MAX_2, \
976 						 NULL)
977 
978 /** Connectable extended advertising */
979 #define BT_LE_EXT_ADV_CONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
980 					   BT_LE_ADV_OPT_CONNECTABLE, \
981 					   BT_GAP_ADV_FAST_INT_MIN_2, \
982 					   BT_GAP_ADV_FAST_INT_MAX_2, \
983 					   NULL)
984 
985 /**
986  * @deprecated This macro will be removed in the near future, see
987  * https://github.com/zephyrproject-rtos/zephyr/issues/71686
988  *
989  * Connectable extended advertising with @ref BT_LE_ADV_OPT_USE_NAME
990  */
991 #define BT_LE_EXT_ADV_CONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
992 						BT_LE_ADV_OPT_CONNECTABLE | \
993 						BT_LE_ADV_OPT_USE_NAME, \
994 						BT_GAP_ADV_FAST_INT_MIN_2, \
995 						BT_GAP_ADV_FAST_INT_MAX_2, \
996 						NULL) \
997 						__DEPRECATED_MACRO
998 
999 /** Scannable extended advertising */
1000 #define BT_LE_EXT_ADV_SCAN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
1001 					   BT_LE_ADV_OPT_SCANNABLE, \
1002 					   BT_GAP_ADV_FAST_INT_MIN_2, \
1003 					   BT_GAP_ADV_FAST_INT_MAX_2, \
1004 					   NULL)
1005 
1006 /**
1007  * @deprecated This macro will be removed in the near future, see
1008  * https://github.com/zephyrproject-rtos/zephyr/issues/71686
1009  *
1010  * Scannable extended advertising with @ref BT_LE_ADV_OPT_USE_NAME
1011  */
1012 #define BT_LE_EXT_ADV_SCAN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
1013 						BT_LE_ADV_OPT_SCANNABLE | \
1014 						BT_LE_ADV_OPT_USE_NAME, \
1015 						BT_GAP_ADV_FAST_INT_MIN_2, \
1016 						BT_GAP_ADV_FAST_INT_MAX_2, \
1017 						NULL) \
1018 						__DEPRECATED_MACRO
1019 
1020 /** Non-connectable extended advertising with private address */
1021 #define BT_LE_EXT_ADV_NCONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV, \
1022 					    BT_GAP_ADV_FAST_INT_MIN_2, \
1023 					    BT_GAP_ADV_FAST_INT_MAX_2, NULL)
1024 
1025 /**
1026  * @deprecated This macro will be removed in the near future, see
1027  * https://github.com/zephyrproject-rtos/zephyr/issues/71686
1028  *
1029  * Non-connectable extended advertising with @ref BT_LE_ADV_OPT_USE_NAME
1030  */
1031 #define BT_LE_EXT_ADV_NCONN_NAME BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
1032 						 BT_LE_ADV_OPT_USE_NAME, \
1033 						 BT_GAP_ADV_FAST_INT_MIN_2, \
1034 						 BT_GAP_ADV_FAST_INT_MAX_2, \
1035 						 NULL) \
1036 						 __DEPRECATED_MACRO
1037 
1038 /** Non-connectable extended advertising with @ref BT_LE_ADV_OPT_USE_IDENTITY */
1039 #define BT_LE_EXT_ADV_NCONN_IDENTITY \
1040 		BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
1041 				BT_LE_ADV_OPT_USE_IDENTITY, \
1042 				BT_GAP_ADV_FAST_INT_MIN_2, \
1043 				BT_GAP_ADV_FAST_INT_MAX_2, NULL)
1044 
1045 /** Non-connectable extended advertising on coded PHY with private address */
1046 #define BT_LE_EXT_ADV_CODED_NCONN BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | \
1047 						  BT_LE_ADV_OPT_CODED, \
1048 						  BT_GAP_ADV_FAST_INT_MIN_2, \
1049 						  BT_GAP_ADV_FAST_INT_MAX_2, \
1050 						  NULL)
1051 
1052 /**
1053  * @deprecated This macro will be removed in the near future, see
1054  * https://github.com/zephyrproject-rtos/zephyr/issues/71686
1055  *
1056  * Non-connectable extended advertising on coded PHY with
1057  * @ref BT_LE_ADV_OPT_USE_NAME
1058  */
1059 #define BT_LE_EXT_ADV_CODED_NCONN_NAME \
1060 		BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | \
1061 				BT_LE_ADV_OPT_USE_NAME, \
1062 				BT_GAP_ADV_FAST_INT_MIN_2, \
1063 				BT_GAP_ADV_FAST_INT_MAX_2, NULL) \
1064 				__DEPRECATED_MACRO
1065 
1066 /** Non-connectable extended advertising on coded PHY with
1067  *  @ref BT_LE_ADV_OPT_USE_IDENTITY
1068  */
1069 #define BT_LE_EXT_ADV_CODED_NCONN_IDENTITY \
1070 		BT_LE_ADV_PARAM(BT_LE_ADV_OPT_EXT_ADV | BT_LE_ADV_OPT_CODED | \
1071 				BT_LE_ADV_OPT_USE_IDENTITY, \
1072 				BT_GAP_ADV_FAST_INT_MIN_2, \
1073 				BT_GAP_ADV_FAST_INT_MAX_2, NULL)
1074 
1075 /**
1076  * Helper to initialize extended advertising start parameters inline
1077  *
1078  * @param _timeout Advertiser timeout
1079  * @param _n_evts  Number of advertising events
1080  */
1081 #define BT_LE_EXT_ADV_START_PARAM_INIT(_timeout, _n_evts) \
1082 { \
1083 	.timeout = (_timeout), \
1084 	.num_events = (_n_evts), \
1085 }
1086 
1087 /**
1088  * Helper to declare extended advertising start parameters inline
1089  *
1090  * @param _timeout Advertiser timeout
1091  * @param _n_evts  Number of advertising events
1092  */
1093 #define BT_LE_EXT_ADV_START_PARAM(_timeout, _n_evts) \
1094 	((const struct bt_le_ext_adv_start_param[]) { \
1095 		BT_LE_EXT_ADV_START_PARAM_INIT((_timeout), (_n_evts)) \
1096 	})
1097 
1098 #define BT_LE_EXT_ADV_START_DEFAULT BT_LE_EXT_ADV_START_PARAM(0, 0)
1099 
1100 /**
1101  * Helper to declare periodic advertising parameters inline
1102  *
1103  * @param _int_min     Minimum periodic advertising interval
1104  * @param _int_max     Maximum periodic advertising interval
1105  * @param _options     Periodic advertising properties bitfield.
1106  */
1107 #define BT_LE_PER_ADV_PARAM_INIT(_int_min, _int_max, _options) \
1108 { \
1109 	.interval_min = (_int_min), \
1110 	.interval_max = (_int_max), \
1111 	.options = (_options), \
1112 }
1113 
1114 /**
1115  * Helper to declare periodic advertising parameters inline
1116  *
1117  * @param _int_min     Minimum periodic advertising interval
1118  * @param _int_max     Maximum periodic advertising interval
1119  * @param _options     Periodic advertising properties bitfield.
1120  */
1121 #define BT_LE_PER_ADV_PARAM(_int_min, _int_max, _options) \
1122 	((struct bt_le_per_adv_param[]) { \
1123 		BT_LE_PER_ADV_PARAM_INIT(_int_min, _int_max, _options) \
1124 	})
1125 
1126 #define BT_LE_PER_ADV_DEFAULT BT_LE_PER_ADV_PARAM(BT_GAP_PER_ADV_SLOW_INT_MIN, \
1127 						  BT_GAP_PER_ADV_SLOW_INT_MAX, \
1128 						  BT_LE_PER_ADV_OPT_NONE)
1129 
1130 /**
1131  * @brief Start advertising
1132  *
1133  * Set advertisement data, scan response data, advertisement parameters
1134  * and start advertising.
1135  *
1136  * When the advertisement parameter peer address has been set the advertising
1137  * will be directed to the peer. In this case advertisement data and scan
1138  * response data parameters are ignored. If the mode is high duty cycle
1139  * the timeout will be @ref BT_GAP_ADV_HIGH_DUTY_CYCLE_MAX_TIMEOUT.
1140  *
1141  * This function cannot be used with @ref BT_LE_ADV_OPT_EXT_ADV in the @p param.options.
1142  * For extended advertising, the bt_le_ext_adv_* functions must be used.
1143  *
1144  * @param param Advertising parameters.
1145  * @param ad Data to be used in advertisement packets.
1146  * @param ad_len Number of elements in ad
1147  * @param sd Data to be used in scan response packets.
1148  * @param sd_len Number of elements in sd
1149  *
1150  * @return Zero on success or (negative) error code otherwise.
1151  * @return -ENOMEM No free connection objects available for connectable
1152  *                 advertiser.
1153  * @return -ECONNREFUSED When connectable advertising is requested and there
1154  *                       is already maximum number of connections established
1155  *                       in the controller.
1156  *                       This error code is only guaranteed when using Zephyr
1157  *                       controller, for other controllers code returned in
1158  *                       this case may be -EIO.
1159  */
1160 int bt_le_adv_start(const struct bt_le_adv_param *param,
1161 		    const struct bt_data *ad, size_t ad_len,
1162 		    const struct bt_data *sd, size_t sd_len);
1163 
1164 /**
1165  * @brief Update advertising
1166  *
1167  * Update advertisement and scan response data.
1168  *
1169  * @param ad Data to be used in advertisement packets.
1170  * @param ad_len Number of elements in ad
1171  * @param sd Data to be used in scan response packets.
1172  * @param sd_len Number of elements in sd
1173  *
1174  * @return Zero on success or (negative) error code otherwise.
1175  */
1176 int bt_le_adv_update_data(const struct bt_data *ad, size_t ad_len,
1177 			  const struct bt_data *sd, size_t sd_len);
1178 
1179 /**
1180  * @brief Stop advertising
1181  *
1182  * Stops ongoing advertising.
1183  *
1184  * @return Zero on success or (negative) error code otherwise.
1185  */
1186 int bt_le_adv_stop(void);
1187 
1188 /**
1189  * @brief Create advertising set.
1190  *
1191  * Create a new advertising set and set advertising parameters.
1192  * Advertising parameters can be updated with @ref bt_le_ext_adv_update_param.
1193  *
1194  * @param[in] param Advertising parameters.
1195  * @param[in] cb    Callback struct to notify about advertiser activity. Can be
1196  *                  NULL. Must point to valid memory during the lifetime of the
1197  *                  advertising set.
1198  * @param[out] adv  Valid advertising set object on success.
1199  *
1200  * @return Zero on success or (negative) error code otherwise.
1201  */
1202 int bt_le_ext_adv_create(const struct bt_le_adv_param *param,
1203 			 const struct bt_le_ext_adv_cb *cb,
1204 			 struct bt_le_ext_adv **adv);
1205 
1206 struct bt_le_ext_adv_start_param {
1207 	/**
1208 	 * @brief Advertiser timeout (N * 10 ms).
1209 	 *
1210 	 * Application will be notified by the advertiser sent callback.
1211 	 * Set to zero for no timeout.
1212 	 *
1213 	 * When using high duty cycle directed connectable advertising then
1214 	 * this parameters must be set to a non-zero value less than or equal
1215 	 * to the maximum of @ref BT_GAP_ADV_HIGH_DUTY_CYCLE_MAX_TIMEOUT.
1216 	 *
1217 	 * If privacy @kconfig{CONFIG_BT_PRIVACY} is enabled then the timeout
1218 	 * must be less than @kconfig{CONFIG_BT_RPA_TIMEOUT}.
1219 	 */
1220 	uint16_t timeout;
1221 	/**
1222 	 * @brief Number of advertising events.
1223 	 *
1224 	 * Application will be notified by the advertiser sent callback.
1225 	 * Set to zero for no limit.
1226 	 */
1227 	uint8_t  num_events;
1228 };
1229 
1230 /**
1231  * @brief Start advertising with the given advertising set
1232  *
1233  * If the advertiser is limited by either the timeout or number of advertising
1234  * events the application will be notified by the advertiser sent callback once
1235  * the limit is reached.
1236  * If the advertiser is limited by both the timeout and the number of
1237  * advertising events then the limit that is reached first will stop the
1238  * advertiser.
1239  *
1240  * @param adv    Advertising set object.
1241  * @param param  Advertise start parameters.
1242  */
1243 int bt_le_ext_adv_start(struct bt_le_ext_adv *adv,
1244 			const struct bt_le_ext_adv_start_param *param);
1245 
1246 /**
1247  * @brief Stop advertising with the given advertising set
1248  *
1249  * Stop advertising with a specific advertising set. When using this function
1250  * the advertising sent callback will not be called.
1251  *
1252  * @param adv Advertising set object.
1253  *
1254  * @return Zero on success or (negative) error code otherwise.
1255  */
1256 int bt_le_ext_adv_stop(struct bt_le_ext_adv *adv);
1257 
1258 /**
1259  * @brief Set an advertising set's advertising or scan response data.
1260  *
1261  * Set advertisement data or scan response data. If the advertising set is
1262  * currently advertising then the advertising data will be updated in
1263  * subsequent advertising events.
1264  *
1265  * When both @ref BT_LE_ADV_OPT_EXT_ADV and @ref BT_LE_ADV_OPT_SCANNABLE are
1266  * enabled then advertising data is ignored.
1267  * When @ref BT_LE_ADV_OPT_SCANNABLE is not enabled then scan response data is
1268  * ignored.
1269  *
1270  * If the advertising set has been configured to send advertising data on the
1271  * primary advertising channels then the maximum data length is
1272  * @ref BT_GAP_ADV_MAX_ADV_DATA_LEN bytes.
1273  * If the advertising set has been configured for extended advertising,
1274  * then the maximum data length is defined by the controller with the maximum
1275  * possible of @ref BT_GAP_ADV_MAX_EXT_ADV_DATA_LEN bytes.
1276  *
1277  * @note Not all scanners support extended data length advertising data.
1278  *
1279  * @note When updating the advertising data while advertising the advertising
1280  *       data and scan response data length must be smaller or equal to what
1281  *       can be fit in a single advertising packet. Otherwise the
1282  *       advertiser must be stopped.
1283  *
1284  * @param adv     Advertising set object.
1285  * @param ad      Data to be used in advertisement packets.
1286  * @param ad_len  Number of elements in ad
1287  * @param sd      Data to be used in scan response packets.
1288  * @param sd_len  Number of elements in sd
1289  *
1290  * @return Zero on success or (negative) error code otherwise.
1291  */
1292 int bt_le_ext_adv_set_data(struct bt_le_ext_adv *adv,
1293 			   const struct bt_data *ad, size_t ad_len,
1294 			   const struct bt_data *sd, size_t sd_len);
1295 
1296 /**
1297  * @brief Update advertising parameters.
1298  *
1299  * Update the advertising parameters. The function will return an error if the
1300  * advertiser set is currently advertising. Stop the advertising set before
1301  * calling this function.
1302  *
1303  * @note When changing the option @ref BT_LE_ADV_OPT_USE_NAME then
1304  *       @ref bt_le_ext_adv_set_data needs to be called in order to update the
1305  *       advertising data and scan response data.
1306  *
1307  * @param adv   Advertising set object.
1308  * @param param Advertising parameters.
1309  *
1310  * @return Zero on success or (negative) error code otherwise.
1311  */
1312 int bt_le_ext_adv_update_param(struct bt_le_ext_adv *adv,
1313 			       const struct bt_le_adv_param *param);
1314 
1315 /**
1316  * @brief Delete advertising set.
1317  *
1318  * Delete advertising set. This will free up the advertising set and make it
1319  * possible to create a new advertising set.
1320  *
1321  * @return Zero on success or (negative) error code otherwise.
1322  */
1323 int bt_le_ext_adv_delete(struct bt_le_ext_adv *adv);
1324 
1325 /**
1326  * @brief Get array index of an advertising set.
1327  *
1328  * This function is used to map bt_adv to index of an array of
1329  * advertising sets. The array has CONFIG_BT_EXT_ADV_MAX_ADV_SET elements.
1330  *
1331  * @param adv Advertising set.
1332  *
1333  * @return Index of the advertising set object.
1334  * The range of the returned value is 0..CONFIG_BT_EXT_ADV_MAX_ADV_SET-1
1335  */
1336 uint8_t bt_le_ext_adv_get_index(struct bt_le_ext_adv *adv);
1337 
1338 /** @brief Advertising set info structure. */
1339 struct bt_le_ext_adv_info {
1340 	/* Local identity */
1341 	uint8_t                    id;
1342 
1343 	/** Currently selected Transmit Power (dBM). */
1344 	int8_t                     tx_power;
1345 
1346 	/** Current local advertising address used. */
1347 	const bt_addr_le_t         *addr;
1348 };
1349 
1350 /**
1351  * @brief Get advertising set info
1352  *
1353  * @param adv Advertising set object
1354  * @param info Advertising set info object
1355  *
1356  * @return Zero on success or (negative) error code on failure.
1357  */
1358 int bt_le_ext_adv_get_info(const struct bt_le_ext_adv *adv,
1359 			   struct bt_le_ext_adv_info *info);
1360 
1361 /**
1362  * @typedef bt_le_scan_cb_t
1363  * @brief Callback type for reporting LE scan results.
1364  *
1365  * A function of this type is given to the bt_le_scan_start() function
1366  * and will be called for any discovered LE device.
1367  *
1368  * @param addr Advertiser LE address and type.
1369  * @param rssi Strength of advertiser signal.
1370  * @param adv_type Type of advertising response from advertiser.
1371  *                 Uses the BT_GAP_ADV_TYPE_* values.
1372  * @param buf Buffer containing advertiser data.
1373  */
1374 typedef void bt_le_scan_cb_t(const bt_addr_le_t *addr, int8_t rssi,
1375 			     uint8_t adv_type, struct net_buf_simple *buf);
1376 
1377 /**
1378  * @brief Set or update the periodic advertising parameters.
1379  *
1380  * The periodic advertising parameters can only be set or updated on an
1381  * extended advertisement set which is neither scannable, connectable nor
1382  * anonymous.
1383  *
1384  * @param adv   Advertising set object.
1385  * @param param Advertising parameters.
1386  *
1387  * @return Zero on success or (negative) error code otherwise.
1388  */
1389 int bt_le_per_adv_set_param(struct bt_le_ext_adv *adv,
1390 			    const struct bt_le_per_adv_param *param);
1391 
1392 /**
1393  * @brief Set or update the periodic advertising data.
1394  *
1395  * The periodic advertisement data can only be set or updated on an
1396  * extended advertisement set which is neither scannable, connectable nor
1397  * anonymous.
1398  *
1399  * @param adv       Advertising set object.
1400  * @param ad        Advertising data.
1401  * @param ad_len    Advertising data length.
1402  *
1403  * @return          Zero on success or (negative) error code otherwise.
1404  */
1405 int bt_le_per_adv_set_data(const struct bt_le_ext_adv *adv,
1406 			   const struct bt_data *ad, size_t ad_len);
1407 
1408 struct bt_le_per_adv_subevent_data_params {
1409 	/** The subevent to set data for */
1410 	uint8_t subevent;
1411 
1412 	/** The first response slot to listen to */
1413 	uint8_t response_slot_start;
1414 
1415 	/** The number of response slots to listen to */
1416 	uint8_t response_slot_count;
1417 
1418 	/** The data to send */
1419 	const struct net_buf_simple *data;
1420 };
1421 
1422 /**
1423  * @brief Set the periodic advertising with response subevent data.
1424  *
1425  * Set the data for one or more subevents of a Periodic Advertising with
1426  * Responses Advertiser in reply data request.
1427  *
1428  * @pre There are @p num_subevents elements in @p params.
1429  * @pre The controller has requested data for the subevents in @p params.
1430  *
1431  * @param adv           The extended advertiser the PAwR train belongs to.
1432  * @param num_subevents The number of subevents to set data for.
1433  * @param params        Subevent parameters.
1434  *
1435  * @return Zero on success or (negative) error code otherwise.
1436  */
1437 int bt_le_per_adv_set_subevent_data(const struct bt_le_ext_adv *adv, uint8_t num_subevents,
1438 				    const struct bt_le_per_adv_subevent_data_params *params);
1439 
1440 /**
1441  * @brief Starts periodic advertising.
1442  *
1443  * Enabling the periodic advertising can be done independently of extended
1444  * advertising, but both periodic advertising and extended advertising
1445  * shall be enabled before any periodic advertising data is sent. The
1446  * periodic advertising and extended advertising can be enabled in any order.
1447  *
1448  * Once periodic advertising has been enabled, it will continue advertising
1449  * until @ref bt_le_per_adv_stop() has been called, or if the advertising set
1450  * is deleted by @ref bt_le_ext_adv_delete(). Calling @ref bt_le_ext_adv_stop()
1451  * will not stop the periodic advertising.
1452  *
1453  * @param adv      Advertising set object.
1454  *
1455  * @return         Zero on success or (negative) error code otherwise.
1456  */
1457 int bt_le_per_adv_start(struct bt_le_ext_adv *adv);
1458 
1459 /**
1460  * @brief Stops periodic advertising.
1461  *
1462  * Disabling the periodic advertising can be done independently of extended
1463  * advertising. Disabling periodic advertising will not disable extended
1464  * advertising.
1465  *
1466  * @param adv      Advertising set object.
1467  *
1468  * @return         Zero on success or (negative) error code otherwise.
1469  */
1470 int bt_le_per_adv_stop(struct bt_le_ext_adv *adv);
1471 
1472 struct bt_le_per_adv_sync_synced_info {
1473 	/** Advertiser LE address and type. */
1474 	const bt_addr_le_t *addr;
1475 
1476 	/** Advertiser SID */
1477 	uint8_t sid;
1478 
1479 	/** Periodic advertising interval (N * 1.25 ms) */
1480 	uint16_t interval;
1481 
1482 	/** Advertiser PHY */
1483 	uint8_t phy;
1484 
1485 	/** True if receiving periodic advertisements, false otherwise. */
1486 	bool recv_enabled;
1487 
1488 	/**
1489 	 * @brief Service Data provided by the peer when sync is transferred
1490 	 *
1491 	 * Will always be 0 when the sync is locally created.
1492 	 */
1493 	uint16_t service_data;
1494 
1495 	/**
1496 	 * @brief Peer that transferred the periodic advertising sync
1497 	 *
1498 	 * Will always be 0 when the sync is locally created.
1499 	 *
1500 	 */
1501 	struct bt_conn *conn;
1502 #if defined(CONFIG_BT_PER_ADV_SYNC_RSP)
1503 	/** Number of subevents */
1504 	uint8_t num_subevents;
1505 
1506 	/** Subevent interval (N * 1.25 ms) */
1507 	uint8_t subevent_interval;
1508 
1509 	/** Response slot delay (N * 1.25 ms) */
1510 	uint8_t response_slot_delay;
1511 
1512 	/** Response slot spacing (N * 1.25 ms) */
1513 	uint8_t response_slot_spacing;
1514 
1515 #endif /* CONFIG_BT_PER_ADV_SYNC_RSP */
1516 };
1517 
1518 struct bt_le_per_adv_sync_term_info {
1519 	/** Advertiser LE address and type. */
1520 	const bt_addr_le_t *addr;
1521 
1522 	/** Advertiser SID */
1523 	uint8_t sid;
1524 
1525 	/** Cause of periodic advertising termination */
1526 	uint8_t reason;
1527 };
1528 
1529 struct bt_le_per_adv_sync_recv_info {
1530 	/** Advertiser LE address and type. */
1531 	const bt_addr_le_t *addr;
1532 
1533 	/** Advertiser SID */
1534 	uint8_t sid;
1535 
1536 	/** The TX power of the advertisement. */
1537 	int8_t tx_power;
1538 
1539 	/** The RSSI of the advertisement excluding any CTE. */
1540 	int8_t rssi;
1541 
1542 	/** The Constant Tone Extension (CTE) of the advertisement (@ref bt_df_cte_type) */
1543 	uint8_t cte_type;
1544 #if defined(CONFIG_BT_PER_ADV_SYNC_RSP)
1545 	/** The value of the event counter where the subevent indication was received. */
1546 	uint16_t periodic_event_counter;
1547 
1548 	/** The subevent where the subevent indication was received. */
1549 	uint8_t subevent;
1550 #endif /* CONFIG_BT_PER_ADV_SYNC_RSP */
1551 };
1552 
1553 
1554 struct bt_le_per_adv_sync_state_info {
1555 	/** True if receiving periodic advertisements, false otherwise. */
1556 	bool recv_enabled;
1557 };
1558 
1559 struct bt_le_per_adv_sync_cb {
1560 	/**
1561 	 * @brief The periodic advertising has been successfully synced.
1562 	 *
1563 	 * This callback notifies the application that the periodic advertising
1564 	 * set has been successfully synced, and will now start to
1565 	 * receive periodic advertising reports.
1566 	 *
1567 	 * @param sync The periodic advertising sync object.
1568 	 * @param info Information about the sync event.
1569 	 */
1570 	void (*synced)(struct bt_le_per_adv_sync *sync,
1571 		       struct bt_le_per_adv_sync_synced_info *info);
1572 
1573 	/**
1574 	 * @brief The periodic advertising sync has been terminated.
1575 	 *
1576 	 * This callback notifies the application that the periodic advertising
1577 	 * sync has been terminated, either by local request, remote request or
1578 	 * because due to missing data, e.g. by being out of range or sync.
1579 	 *
1580 	 * @param sync  The periodic advertising sync object.
1581 	 */
1582 	void (*term)(struct bt_le_per_adv_sync *sync,
1583 		     const struct bt_le_per_adv_sync_term_info *info);
1584 
1585 	/**
1586 	 * @brief Periodic advertising data received.
1587 	 *
1588 	 * This callback notifies the application of an periodic advertising
1589 	 * report.
1590 	 *
1591 	 * @param sync  The advertising set object.
1592 	 * @param info  Information about the periodic advertising event.
1593 	 * @param buf   Buffer containing the periodic advertising data.
1594 	 *              NULL if the controller failed to receive a subevent
1595 	 *              indication. Only happens if
1596 	 *              @kconfig{CONFIG_BT_PER_ADV_SYNC_RSP} is enabled.
1597 	 */
1598 	void (*recv)(struct bt_le_per_adv_sync *sync,
1599 		     const struct bt_le_per_adv_sync_recv_info *info,
1600 		     struct net_buf_simple *buf);
1601 
1602 	/**
1603 	 * @brief The periodic advertising sync state has changed.
1604 	 *
1605 	 * This callback notifies the application about changes to the sync
1606 	 * state. Initialize sync and termination is handled by their individual
1607 	 * callbacks, and won't be notified here.
1608 	 *
1609 	 * @param sync  The periodic advertising sync object.
1610 	 * @param info  Information about the state change.
1611 	 */
1612 	void (*state_changed)(struct bt_le_per_adv_sync *sync,
1613 			      const struct bt_le_per_adv_sync_state_info *info);
1614 
1615 	/**
1616 	 * @brief BIGInfo advertising report received.
1617 	 *
1618 	 * This callback notifies the application of a BIGInfo advertising report.
1619 	 * This is received if the advertiser is broadcasting isochronous streams in a BIG.
1620 	 * See iso.h for more information.
1621 	 *
1622 	 * @param sync     The advertising set object.
1623 	 * @param biginfo  The BIGInfo report.
1624 	 */
1625 	void (*biginfo)(struct bt_le_per_adv_sync *sync, const struct bt_iso_biginfo *biginfo);
1626 
1627 	/**
1628 	 * @brief Callback for IQ samples report collected when sampling
1629 	 *        CTE received with periodic advertising PDU.
1630 	 *
1631 	 * @param sync The periodic advertising sync object.
1632 	 * @param info Information about the sync event.
1633 	 */
1634 	void (*cte_report_cb)(struct bt_le_per_adv_sync *sync,
1635 			      struct bt_df_per_adv_sync_iq_samples_report const *info);
1636 
1637 	sys_snode_t node;
1638 };
1639 
1640 /** Periodic advertising sync options */
1641 enum {
1642 	/** Convenience value when no options are specified. */
1643 	BT_LE_PER_ADV_SYNC_OPT_NONE = 0,
1644 
1645 	/**
1646 	 * @brief Use the periodic advertising list to sync with advertiser
1647 	 *
1648 	 * When this option is set, the address and SID of the parameters
1649 	 * are ignored.
1650 	 */
1651 	BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST = BIT(0),
1652 
1653 	/**
1654 	 * @brief Disables periodic advertising reports
1655 	 *
1656 	 * No advertisement reports will be handled until enabled.
1657 	 */
1658 	BT_LE_PER_ADV_SYNC_OPT_REPORTING_INITIALLY_DISABLED = BIT(1),
1659 
1660 	/** Filter duplicate Periodic Advertising reports */
1661 	BT_LE_PER_ADV_SYNC_OPT_FILTER_DUPLICATE = BIT(2),
1662 
1663 	/** Sync with Angle of Arrival (AoA) constant tone extension */
1664 	BT_LE_PER_ADV_SYNC_OPT_DONT_SYNC_AOA = BIT(3),
1665 
1666 	/** Sync with Angle of Departure (AoD) 1 us constant tone extension */
1667 	BT_LE_PER_ADV_SYNC_OPT_DONT_SYNC_AOD_1US = BIT(4),
1668 
1669 	/** Sync with Angle of Departure (AoD) 2 us constant tone extension */
1670 	BT_LE_PER_ADV_SYNC_OPT_DONT_SYNC_AOD_2US = BIT(5),
1671 
1672 	/** Do not sync to packets without a constant tone extension */
1673 	BT_LE_PER_ADV_SYNC_OPT_SYNC_ONLY_CONST_TONE_EXT = BIT(6),
1674 };
1675 
1676 struct bt_le_per_adv_sync_param {
1677 	/**
1678 	 * @brief Periodic Advertiser Address
1679 	 *
1680 	 * Only valid if not using the periodic advertising list
1681 	 * (BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST)
1682 	 */
1683 	bt_addr_le_t addr;
1684 
1685 	/**
1686 	 * @brief Advertiser SID
1687 	 *
1688 	 * Only valid if not using the periodic advertising list
1689 	 * (BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST)
1690 	 */
1691 	uint8_t sid;
1692 
1693 	/** Bit-field of periodic advertising sync options. */
1694 	uint32_t options;
1695 
1696 	/**
1697 	 * @brief Maximum event skip
1698 	 *
1699 	 * Maximum number of periodic advertising events that can be
1700 	 * skipped after a successful receive.
1701 	 * Range: 0x0000 to 0x01F3
1702 	 */
1703 	uint16_t skip;
1704 
1705 	/**
1706 	 * @brief Synchronization timeout (N * 10 ms)
1707 	 *
1708 	 * Synchronization timeout for the periodic advertising sync.
1709 	 * Range 0x000A to 0x4000 (100 ms to 163840 ms)
1710 	 */
1711 	uint16_t timeout;
1712 };
1713 
1714 /**
1715  * @brief Get array index of an periodic advertising sync object.
1716  *
1717  * This function is get the index of an array of periodic advertising sync
1718  * objects. The array has CONFIG_BT_PER_ADV_SYNC_MAX elements.
1719  *
1720  * @param per_adv_sync The periodic advertising sync object.
1721  *
1722  * @return Index of the periodic advertising sync object.
1723  * The range of the returned value is 0..CONFIG_BT_PER_ADV_SYNC_MAX-1
1724  */
1725 uint8_t bt_le_per_adv_sync_get_index(struct bt_le_per_adv_sync *per_adv_sync);
1726 
1727 /**
1728  * @brief Get a periodic advertising sync object from the array index.
1729  *
1730  * This function is to get the periodic advertising sync object from
1731  * the array index.
1732  * The array has CONFIG_BT_PER_ADV_SYNC_MAX elements.
1733  *
1734  * @param index The index of the periodic advertising sync object.
1735  *              The range of the index value is 0..CONFIG_BT_PER_ADV_SYNC_MAX-1
1736  *
1737  * @return The periodic advertising sync object of the array index or NULL if invalid index.
1738  */
1739 struct bt_le_per_adv_sync *bt_le_per_adv_sync_lookup_index(uint8_t index);
1740 
1741 /** @brief Advertising set info structure. */
1742 struct bt_le_per_adv_sync_info {
1743 	/** Periodic Advertiser Address */
1744 	bt_addr_le_t addr;
1745 
1746 	/** Advertiser SID */
1747 	uint8_t sid;
1748 
1749 	/** Periodic advertising interval (N * 1.25 ms) */
1750 	uint16_t interval;
1751 
1752 	/** Advertiser PHY */
1753 	uint8_t phy;
1754 };
1755 
1756 /**
1757  * @brief Get periodic adv sync information.
1758  *
1759  * @param per_adv_sync Periodic advertising sync object.
1760  * @param info          Periodic advertising sync info object
1761  *
1762  * @return Zero on success or (negative) error code on failure.
1763  */
1764 int bt_le_per_adv_sync_get_info(struct bt_le_per_adv_sync *per_adv_sync,
1765 				struct bt_le_per_adv_sync_info *info);
1766 
1767 /**
1768  * @brief Look up an existing periodic advertising sync object by advertiser address.
1769  *
1770  * @param adv_addr Advertiser address.
1771  * @param sid      The advertising set ID.
1772  *
1773  * @return Periodic advertising sync object or NULL if not found.
1774  */
1775 struct bt_le_per_adv_sync *bt_le_per_adv_sync_lookup_addr(const bt_addr_le_t *adv_addr,
1776 							  uint8_t sid);
1777 
1778 /**
1779  * @brief Create a periodic advertising sync object.
1780  *
1781  * Create a periodic advertising sync object that can try to synchronize
1782  * to periodic advertising reports from an advertiser. Scan shall either be
1783  * disabled or extended scan shall be enabled.
1784  *
1785  * This function does not timeout, and will continue to look for an advertiser until it either
1786  * finds it or bt_le_per_adv_sync_delete() is called. It is thus suggested to implement a timeout
1787  * when using this, if it is expected to find the advertiser within a reasonable timeframe.
1788  *
1789  * @param[in]  param     Periodic advertising sync parameters.
1790  * @param[out] out_sync  Periodic advertising sync object on.
1791  *
1792  * @return Zero on success or (negative) error code otherwise.
1793  */
1794 int bt_le_per_adv_sync_create(const struct bt_le_per_adv_sync_param *param,
1795 			      struct bt_le_per_adv_sync **out_sync);
1796 
1797 /**
1798  * @brief Delete periodic advertising sync.
1799  *
1800  * Delete the periodic advertising sync object. Can be called regardless of the
1801  * state of the sync. If the syncing is currently syncing, the syncing is
1802  * cancelled. If the sync has been established, it is terminated. The
1803  * periodic advertising sync object will be invalidated afterwards.
1804  *
1805  * If the state of the sync object is syncing, then a new periodic advertising
1806  * sync object may not be created until the controller has finished canceling
1807  * this object.
1808  *
1809  * @param per_adv_sync The periodic advertising sync object.
1810  *
1811  * @return Zero on success or (negative) error code otherwise.
1812  */
1813 int bt_le_per_adv_sync_delete(struct bt_le_per_adv_sync *per_adv_sync);
1814 
1815 /**
1816  * @brief Register periodic advertising sync callbacks.
1817  *
1818  * Adds the callback structure to the list of callback structures for periodic
1819  * advertising syncs.
1820  *
1821  * This callback will be called for all periodic advertising sync activity,
1822  * such as synced, terminated and when data is received.
1823  *
1824  * @param cb Callback struct. Must point to memory that remains valid.
1825  *
1826  * @retval 0 Success.
1827  * @retval -EEXIST if @p cb was already registered.
1828  */
1829 int bt_le_per_adv_sync_cb_register(struct bt_le_per_adv_sync_cb *cb);
1830 
1831 /**
1832  * @brief Enables receiving periodic advertising reports for a sync.
1833  *
1834  * If the sync is already receiving the reports, -EALREADY is returned.
1835  *
1836  * @param per_adv_sync The periodic advertising sync object.
1837  *
1838  * @return Zero on success or (negative) error code otherwise.
1839  */
1840 int bt_le_per_adv_sync_recv_enable(struct bt_le_per_adv_sync *per_adv_sync);
1841 
1842 /**
1843  * @brief Disables receiving periodic advertising reports for a sync.
1844  *
1845  * If the sync report receiving is already disabled, -EALREADY is returned.
1846  *
1847  * @param per_adv_sync The periodic advertising sync object.
1848  *
1849  * @return Zero on success or (negative) error code otherwise.
1850  */
1851 int bt_le_per_adv_sync_recv_disable(struct bt_le_per_adv_sync *per_adv_sync);
1852 
1853 /** Periodic Advertising Sync Transfer options */
1854 enum {
1855 	/** Convenience value when no options are specified. */
1856 	BT_LE_PER_ADV_SYNC_TRANSFER_OPT_NONE = 0,
1857 
1858 	/**
1859 	 * @brief No Angle of Arrival (AoA)
1860 	 *
1861 	 * Do not sync with Angle of Arrival (AoA) constant tone extension
1862 	 **/
1863 	BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_NO_AOA = BIT(0),
1864 
1865 	/**
1866 	 * @brief No Angle of Departure (AoD) 1 us
1867 	 *
1868 	 * Do not sync with Angle of Departure (AoD) 1 us
1869 	 * constant tone extension
1870 	 */
1871 	BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_NO_AOD_1US = BIT(1),
1872 
1873 	/**
1874 	 * @brief No Angle of Departure (AoD) 2
1875 	 *
1876 	 * Do not sync with Angle of Departure (AoD) 2 us
1877 	 * constant tone extension
1878 	 */
1879 	BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_NO_AOD_2US = BIT(2),
1880 
1881 	/** Only sync to packets with constant tone extension */
1882 	BT_LE_PER_ADV_SYNC_TRANSFER_OPT_SYNC_ONLY_CTE = BIT(3),
1883 
1884 	/**
1885 	 * @brief Sync to received PAST packets but don't generate sync reports
1886 	 *
1887 	 * This option must not be set at the same time as
1888 	 * @ref BT_LE_PER_ADV_SYNC_TRANSFER_OPT_FILTER_DUPLICATES.
1889 	 */
1890 	BT_LE_PER_ADV_SYNC_TRANSFER_OPT_REPORTING_INITIALLY_DISABLED = BIT(4),
1891 
1892 	/**
1893 	 * @brief Sync to received PAST packets and generate sync reports with duplicate filtering
1894 	 *
1895 	 * This option must not be set at the same time as
1896 	 * @ref BT_LE_PER_ADV_SYNC_TRANSFER_OPT_REPORTING_INITIALLY_DISABLED.
1897 	 */
1898 	BT_LE_PER_ADV_SYNC_TRANSFER_OPT_FILTER_DUPLICATES = BIT(5),
1899 };
1900 
1901 struct bt_le_per_adv_sync_transfer_param {
1902 	/**
1903 	 * @brief Maximum event skip
1904 	 *
1905 	 * The number of periodic advertising packets that can be skipped
1906 	 * after a successful receive.
1907 	 */
1908 	uint16_t skip;
1909 
1910 	/**
1911 	 * @brief Synchronization timeout (N * 10 ms)
1912 	 *
1913 	 * Synchronization timeout for the periodic advertising sync.
1914 	 * Range 0x000A to 0x4000 (100 ms to 163840 ms)
1915 	 */
1916 	uint16_t timeout;
1917 
1918 	/** Periodic Advertising Sync Transfer options */
1919 	uint32_t options;
1920 };
1921 
1922 /**
1923  * @brief Transfer the periodic advertising sync information to a peer device.
1924  *
1925  * This will allow another device to quickly synchronize to the same periodic
1926  * advertising train that this device is currently synced to.
1927  *
1928  * @param per_adv_sync  The periodic advertising sync to transfer.
1929  * @param conn          The peer device that will receive the sync information.
1930  * @param service_data  Application service data provided to the remote host.
1931  *
1932  * @return Zero on success or (negative) error code otherwise.
1933  */
1934 int bt_le_per_adv_sync_transfer(const struct bt_le_per_adv_sync *per_adv_sync,
1935 				const struct bt_conn *conn,
1936 				uint16_t service_data);
1937 
1938 
1939 /**
1940  * @brief Transfer the information about a periodic advertising set.
1941  *
1942  * This will allow another device to quickly synchronize to periodic
1943  * advertising set from this device.
1944  *
1945  * @param adv           The periodic advertising set to transfer info of.
1946  * @param conn          The peer device that will receive the information.
1947  * @param service_data  Application service data provided to the remote host.
1948  *
1949  * @return Zero on success or (negative) error code otherwise.
1950  */
1951 int bt_le_per_adv_set_info_transfer(const struct bt_le_ext_adv *adv,
1952 				    const struct bt_conn *conn,
1953 				    uint16_t service_data);
1954 
1955 /**
1956  * @brief Subscribe to periodic advertising sync transfers (PASTs).
1957  *
1958  * Sets the parameters and allow other devices to transfer periodic advertising
1959  * syncs.
1960  *
1961  * @param conn    The connection to set the parameters for. If NULL default
1962  *                parameters for all connections will be set. Parameters set
1963  *                for specific connection will always have precedence.
1964  * @param param   The periodic advertising sync transfer parameters.
1965  *
1966  * @return Zero on success or (negative) error code otherwise.
1967  */
1968 int bt_le_per_adv_sync_transfer_subscribe(
1969 	const struct bt_conn *conn,
1970 	const struct bt_le_per_adv_sync_transfer_param *param);
1971 
1972 /**
1973  * @brief Unsubscribe from periodic advertising sync transfers (PASTs).
1974  *
1975  * Remove the parameters that allow other devices to transfer periodic
1976  * advertising syncs.
1977  *
1978  * @param conn    The connection to remove the parameters for. If NULL default
1979  *                parameters for all connections will be removed. Unsubscribing
1980  *                for a specific device, will still allow other devices to
1981  *                transfer periodic advertising syncs.
1982  *
1983  * @return Zero on success or (negative) error code otherwise.
1984  */
1985 int bt_le_per_adv_sync_transfer_unsubscribe(const struct bt_conn *conn);
1986 
1987 /**
1988  * @brief Add a device to the periodic advertising list.
1989  *
1990  * Add peer device LE address to the periodic advertising list. This will make
1991  * it possibly to automatically create a periodic advertising sync to this
1992  * device.
1993  *
1994  * @param addr Bluetooth LE identity address.
1995  * @param sid  The advertising set ID. This value is obtained from the
1996  *             @ref bt_le_scan_recv_info in the scan callback.
1997  *
1998  * @return Zero on success or (negative) error code otherwise.
1999  */
2000 int bt_le_per_adv_list_add(const bt_addr_le_t *addr, uint8_t sid);
2001 
2002 /**
2003  * @brief Remove a device from the periodic advertising list.
2004  *
2005  * Removes peer device LE address from the periodic advertising list.
2006  *
2007  * @param addr Bluetooth LE identity address.
2008  * @param sid  The advertising set ID. This value is obtained from the
2009  *             @ref bt_le_scan_recv_info in the scan callback.
2010  *
2011  * @return Zero on success or (negative) error code otherwise.
2012  */
2013 int bt_le_per_adv_list_remove(const bt_addr_le_t *addr, uint8_t sid);
2014 
2015 /**
2016  * @brief Clear the periodic advertising list.
2017  *
2018  * Clears the entire periodic advertising list.
2019  *
2020  * @return Zero on success or (negative) error code otherwise.
2021  */
2022 int bt_le_per_adv_list_clear(void);
2023 
2024 
2025 enum {
2026 	/** Convenience value when no options are specified. */
2027 	BT_LE_SCAN_OPT_NONE = 0,
2028 
2029 	/** Filter duplicates. */
2030 	BT_LE_SCAN_OPT_FILTER_DUPLICATE = BIT(0),
2031 
2032 	/** Filter using filter accept list. */
2033 	BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST = BIT(1),
2034 
2035 	/** Enable scan on coded PHY (Long Range).*/
2036 	BT_LE_SCAN_OPT_CODED = BIT(2),
2037 
2038 	/**
2039 	 * @brief Disable scan on 1M phy.
2040 	 *
2041 	 * @note Requires @ref BT_LE_SCAN_OPT_CODED.
2042 	 */
2043 	BT_LE_SCAN_OPT_NO_1M = BIT(3),
2044 };
2045 
2046 #define BT_LE_SCAN_OPT_FILTER_WHITELIST __DEPRECATED_MACRO BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST
2047 
2048 enum {
2049 	/** Scan without requesting additional information from advertisers. */
2050 	BT_LE_SCAN_TYPE_PASSIVE = 0x00,
2051 
2052 	/**
2053 	 * @brief Scan and request additional information from advertisers.
2054 	 *
2055 	 * Using this scan type will automatically send scan requests to all
2056 	 * devices. Scan responses are received in the same manner and using the
2057 	 * same callbacks as advertising reports.
2058 	 */
2059 	BT_LE_SCAN_TYPE_ACTIVE = 0x01,
2060 };
2061 
2062 /** LE scan parameters */
2063 struct bt_le_scan_param {
2064 	/** Scan type (BT_LE_SCAN_TYPE_ACTIVE or BT_LE_SCAN_TYPE_PASSIVE) */
2065 	uint8_t  type;
2066 
2067 	/** Bit-field of scanning options. */
2068 	uint32_t options;
2069 
2070 	/** Scan interval (N * 0.625 ms) */
2071 	uint16_t interval;
2072 
2073 	/** Scan window (N * 0.625 ms) */
2074 	uint16_t window;
2075 
2076 	/**
2077 	 * @brief Scan timeout (N * 10 ms)
2078 	 *
2079 	 * Application will be notified by the scan timeout callback.
2080 	 * Set zero to disable timeout.
2081 	 */
2082 	uint16_t timeout;
2083 
2084 	/**
2085 	 * @brief Scan interval LE Coded PHY (N * 0.625 MS)
2086 	 *
2087 	 * Set zero to use same as LE 1M PHY scan interval.
2088 	 */
2089 	uint16_t interval_coded;
2090 
2091 	/**
2092 	 * @brief Scan window LE Coded PHY (N * 0.625 MS)
2093 	 *
2094 	 * Set zero to use same as LE 1M PHY scan window.
2095 	 */
2096 	uint16_t window_coded;
2097 };
2098 
2099 /** LE advertisement and scan response packet information */
2100 struct bt_le_scan_recv_info {
2101 	/**
2102 	 * @brief Advertiser LE address and type.
2103 	 *
2104 	 * If advertiser is anonymous then this address will be
2105 	 * @ref BT_ADDR_LE_ANY.
2106 	 */
2107 	const bt_addr_le_t *addr;
2108 
2109 	/** Advertising Set Identifier. */
2110 	uint8_t sid;
2111 
2112 	/** Strength of advertiser signal. */
2113 	int8_t rssi;
2114 
2115 	/** Transmit power of the advertiser. */
2116 	int8_t tx_power;
2117 
2118 	/**
2119 	 * @brief Advertising packet type.
2120 	 *
2121 	 * Uses the BT_GAP_ADV_TYPE_* value.
2122 	 *
2123 	 * May indicate that this is a scan response if the type is
2124 	 * @ref BT_GAP_ADV_TYPE_SCAN_RSP.
2125 	 */
2126 	uint8_t adv_type;
2127 
2128 	/**
2129 	 * @brief Advertising packet properties bitfield.
2130 	 *
2131 	 * Uses the BT_GAP_ADV_PROP_* values.
2132 	 * May indicate that this is a scan response if the value contains the
2133 	 * @ref BT_GAP_ADV_PROP_SCAN_RESPONSE bit.
2134 	 *
2135 	 */
2136 	uint16_t adv_props;
2137 
2138 	/**
2139 	 * @brief Periodic advertising interval (N * 1.25 ms).
2140 	 *
2141 	 * If 0 there is no periodic advertising.
2142 	 */
2143 	uint16_t interval;
2144 
2145 	/** Primary advertising channel PHY. */
2146 	uint8_t primary_phy;
2147 
2148 	/** Secondary advertising channel PHY. */
2149 	uint8_t secondary_phy;
2150 };
2151 
2152 /** Listener context for (LE) scanning. */
2153 struct bt_le_scan_cb {
2154 
2155 	/**
2156 	 * @brief Advertisement packet and scan response received callback.
2157 	 *
2158 	 * @param info Advertiser packet and scan response information.
2159 	 * @param buf  Buffer containing advertiser data.
2160 	 */
2161 	void (*recv)(const struct bt_le_scan_recv_info *info,
2162 		     struct net_buf_simple *buf);
2163 
2164 	/** @brief The scanner has stopped scanning after scan timeout. */
2165 	void (*timeout)(void);
2166 
2167 	sys_snode_t node;
2168 };
2169 
2170 /**
2171  * @brief Initialize scan parameters
2172  *
2173  * @param _type     Scan Type, BT_LE_SCAN_TYPE_ACTIVE or
2174  *                  BT_LE_SCAN_TYPE_PASSIVE.
2175  * @param _options  Scan options
2176  * @param _interval Scan Interval (N * 0.625 ms)
2177  * @param _window   Scan Window (N * 0.625 ms)
2178  */
2179 #define BT_LE_SCAN_PARAM_INIT(_type, _options, _interval, _window) \
2180 { \
2181 	.type = (_type), \
2182 	.options = (_options), \
2183 	.interval = (_interval), \
2184 	.window = (_window), \
2185 	.timeout = 0, \
2186 	.interval_coded = 0, \
2187 	.window_coded = 0, \
2188 }
2189 
2190 /**
2191  * @brief Helper to declare scan parameters inline
2192  *
2193  * @param _type     Scan Type, BT_LE_SCAN_TYPE_ACTIVE or
2194  *                  BT_LE_SCAN_TYPE_PASSIVE.
2195  * @param _options  Scan options
2196  * @param _interval Scan Interval (N * 0.625 ms)
2197  * @param _window   Scan Window (N * 0.625 ms)
2198  */
2199 #define BT_LE_SCAN_PARAM(_type, _options, _interval, _window) \
2200 	((struct bt_le_scan_param[]) { \
2201 		BT_LE_SCAN_PARAM_INIT(_type, _options, _interval, _window) \
2202 	 })
2203 
2204 /**
2205  * @brief Helper macro to enable active scanning to discover new devices.
2206  */
2207 #define BT_LE_SCAN_ACTIVE BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_ACTIVE, \
2208 					   BT_LE_SCAN_OPT_FILTER_DUPLICATE, \
2209 					   BT_GAP_SCAN_FAST_INTERVAL, \
2210 					   BT_GAP_SCAN_FAST_WINDOW)
2211 
2212 /**
2213  * @brief Helper macro to enable active scanning to discover new devices with window == interval.
2214  *
2215  * Continuous scanning should be used to maximize the chances of receiving advertising packets.
2216  */
2217 #define BT_LE_SCAN_ACTIVE_CONTINUOUS BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_ACTIVE, \
2218 						      BT_LE_SCAN_OPT_FILTER_DUPLICATE, \
2219 						      BT_GAP_SCAN_FAST_INTERVAL_MIN, \
2220 						      BT_GAP_SCAN_FAST_WINDOW)
2221 BUILD_ASSERT(BT_GAP_SCAN_FAST_WINDOW == BT_GAP_SCAN_FAST_INTERVAL_MIN,
2222 	     "Continuous scanning is requested by setting window and interval equal.");
2223 
2224 /**
2225  * @brief Helper macro to enable passive scanning to discover new devices.
2226  *
2227  * This macro should be used if information required for device identification
2228  * (e.g., UUID) are known to be placed in Advertising Data.
2229  */
2230 #define BT_LE_SCAN_PASSIVE BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_PASSIVE, \
2231 					    BT_LE_SCAN_OPT_FILTER_DUPLICATE, \
2232 					    BT_GAP_SCAN_FAST_INTERVAL, \
2233 					    BT_GAP_SCAN_FAST_WINDOW)
2234 
2235 /**
2236  * @brief Helper macro to enable passive scanning to discover new devices with window==interval.
2237  *
2238  * This macro should be used if information required for device identification
2239  * (e.g., UUID) are known to be placed in Advertising Data.
2240  */
2241 #define BT_LE_SCAN_PASSIVE_CONTINUOUS BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_PASSIVE, \
2242 						       BT_LE_SCAN_OPT_FILTER_DUPLICATE, \
2243 						       BT_GAP_SCAN_FAST_INTERVAL_MIN, \
2244 						       BT_GAP_SCAN_FAST_WINDOW)
2245 BUILD_ASSERT(BT_GAP_SCAN_FAST_WINDOW == BT_GAP_SCAN_FAST_INTERVAL_MIN,
2246 	     "Continuous scanning is requested by setting window and interval equal.");
2247 
2248 /**
2249  * @brief Helper macro to enable active scanning to discover new devices.
2250  * Include scanning on Coded PHY in addition to 1M PHY.
2251  */
2252 #define BT_LE_SCAN_CODED_ACTIVE \
2253 		BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_ACTIVE, \
2254 				 BT_LE_SCAN_OPT_CODED | \
2255 				 BT_LE_SCAN_OPT_FILTER_DUPLICATE, \
2256 				 BT_GAP_SCAN_FAST_INTERVAL, \
2257 				 BT_GAP_SCAN_FAST_WINDOW)
2258 
2259 /**
2260  * @brief Helper macro to enable passive scanning to discover new devices.
2261  * Include scanning on Coded PHY in addition to 1M PHY.
2262  *
2263  * This macro should be used if information required for device identification
2264  * (e.g., UUID) are known to be placed in Advertising Data.
2265  */
2266 #define BT_LE_SCAN_CODED_PASSIVE \
2267 		BT_LE_SCAN_PARAM(BT_LE_SCAN_TYPE_PASSIVE, \
2268 				 BT_LE_SCAN_OPT_CODED | \
2269 				 BT_LE_SCAN_OPT_FILTER_DUPLICATE, \
2270 				 BT_GAP_SCAN_FAST_INTERVAL, \
2271 				 BT_GAP_SCAN_FAST_WINDOW)
2272 
2273 /**
2274  * @brief Start (LE) scanning
2275  *
2276  * Start LE scanning with given parameters and provide results through
2277  * the specified callback.
2278  *
2279  * @note The LE scanner by default does not use the Identity Address of the
2280  *       local device when @kconfig{CONFIG_BT_PRIVACY} is disabled. This is to
2281  *       prevent the active scanner from disclosing the identity information
2282  *       when requesting additional information from advertisers.
2283  *       In order to enable directed advertiser reports then
2284  *       @kconfig{CONFIG_BT_SCAN_WITH_IDENTITY} must be enabled.
2285  *
2286  * @note Setting the `param.timeout` parameter is not supported when
2287  *       @kconfig{CONFIG_BT_PRIVACY} is enabled, when the param.type is @ref
2288  *       BT_LE_SCAN_TYPE_ACTIVE. Supplying a non-zero timeout will result in an
2289  *       -EINVAL error code.
2290  *
2291  * @param param Scan parameters.
2292  * @param cb Callback to notify scan results. May be NULL if callback
2293  *           registration through @ref bt_le_scan_cb_register is preferred.
2294  *
2295  * @return Zero on success or error code otherwise, positive in case of
2296  *         protocol error or negative (POSIX) in case of stack internal error.
2297  */
2298 int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb);
2299 
2300 /**
2301  * @brief Stop (LE) scanning.
2302  *
2303  * Stops ongoing LE scanning.
2304  *
2305  * @return Zero on success or error code otherwise, positive in case of
2306  *         protocol error or negative (POSIX) in case of stack internal error.
2307  */
2308 int bt_le_scan_stop(void);
2309 
2310 /**
2311  * @brief Register scanner packet callbacks.
2312  *
2313  * Adds the callback structure to the list of callback structures that monitors
2314  * scanner activity.
2315  *
2316  * This callback will be called for all scanner activity, regardless of what
2317  * API was used to start the scanner.
2318  *
2319  * @param cb Callback struct. Must point to memory that remains valid.
2320  *
2321  * @retval 0 Success.
2322  * @retval -EEXIST if @p cb was already registered.
2323  */
2324 int bt_le_scan_cb_register(struct bt_le_scan_cb *cb);
2325 
2326 /**
2327  * @brief Unregister scanner packet callbacks.
2328  *
2329  * Remove the callback structure from the list of scanner callbacks.
2330  *
2331  * @param cb Callback struct. Must point to memory that remains valid.
2332  */
2333 void bt_le_scan_cb_unregister(struct bt_le_scan_cb *cb);
2334 
2335 /**
2336  * @brief Add device (LE) to filter accept list.
2337  *
2338  * Add peer device LE address to the filter accept list.
2339  *
2340  * @note The filter accept list cannot be modified when an LE role is using
2341  * the filter accept list, i.e advertiser or scanner using a filter accept list
2342  * or automatic connecting to devices using filter accept list.
2343  *
2344  * @param addr Bluetooth LE identity address.
2345  *
2346  * @return Zero on success or error code otherwise, positive in case of
2347  *         protocol error or negative (POSIX) in case of stack internal error.
2348  */
2349 int bt_le_filter_accept_list_add(const bt_addr_le_t *addr);
2350 
2351 /**
2352  * @brief Remove device (LE) from filter accept list.
2353  *
2354  * Remove peer device LE address from the filter accept list.
2355  *
2356  * @note The filter accept list cannot be modified when an LE role is using
2357  * the filter accept list, i.e advertiser or scanner using a filter accept list
2358  * or automatic connecting to devices using filter accept list.
2359  *
2360  * @param addr Bluetooth LE identity address.
2361  *
2362  * @return Zero on success or error code otherwise, positive in case of
2363  *         protocol error or negative (POSIX) in case of stack internal error.
2364  */
2365 int bt_le_filter_accept_list_remove(const bt_addr_le_t *addr);
2366 
2367 /**
2368  * @brief Clear filter accept list.
2369  *
2370  * Clear all devices from the filter accept list.
2371  *
2372  * @note The filter accept list cannot be modified when an LE role is using
2373  * the filter accept list, i.e advertiser or scanner using a filter accept
2374  * list or automatic connecting to devices using filter accept list.
2375  *
2376  * @return Zero on success or error code otherwise, positive in case of
2377  *         protocol error or negative (POSIX) in case of stack internal error.
2378  */
2379 int bt_le_filter_accept_list_clear(void);
2380 
2381 /**
2382  * @brief Set (LE) channel map.
2383  *
2384  * @param chan_map Channel map.
2385  *
2386  * @return Zero on success or error code otherwise, positive in case of
2387  *         protocol error or negative (POSIX) in case of stack internal error.
2388  */
2389 int bt_le_set_chan_map(uint8_t chan_map[5]);
2390 
2391 /**
2392  * @brief Set the Resolvable Private Address timeout in runtime
2393  *
2394  * The new RPA timeout value will be used for the next RPA rotation
2395  * and all subsequent rotations until another override is scheduled
2396  * with this API.
2397  *
2398  * Initially, the if @kconfig{CONFIG_BT_RPA_TIMEOUT} is used as the
2399  * RPA timeout.
2400  *
2401  * This symbol is linkable if @kconfig{CONFIG_BT_RPA_TIMEOUT_DYNAMIC}
2402  * is enabled.
2403  *
2404  * @param new_rpa_timeout Resolvable Private Address timeout in seconds
2405  *
2406  * @retval 0 Success.
2407  * @retval -EINVAL RPA timeout value is invalid. Valid range is 1s - 3600s.
2408  */
2409 int bt_le_set_rpa_timeout(uint16_t new_rpa_timeout);
2410 
2411 /**
2412  * @brief Helper for parsing advertising (or EIR or OOB) data.
2413  *
2414  * A helper for parsing the basic data types used for Extended Inquiry
2415  * Response (EIR), Advertising Data (AD), and OOB data blocks. The most
2416  * common scenario is to call this helper on the advertising data
2417  * received in the callback that was given to bt_le_scan_start().
2418  *
2419  * @warning This helper function will consume `ad` when parsing. The user should
2420  *          make a copy if the original data is to be used afterwards
2421  *
2422  * @param ad        Advertising data as given to the bt_le_scan_cb_t callback.
2423  * @param func      Callback function which will be called for each element
2424  *                  that's found in the data. The callback should return
2425  *                  true to continue parsing, or false to stop parsing.
2426  * @param user_data User data to be passed to the callback.
2427  */
2428 void bt_data_parse(struct net_buf_simple *ad,
2429 		   bool (*func)(struct bt_data *data, void *user_data),
2430 		   void *user_data);
2431 
2432 /** LE Secure Connections pairing Out of Band data. */
2433 struct bt_le_oob_sc_data {
2434 	/** Random Number. */
2435 	uint8_t r[16];
2436 
2437 	/** Confirm Value. */
2438 	uint8_t c[16];
2439 };
2440 
2441 /** LE Out of Band information. */
2442 struct bt_le_oob {
2443 	/** LE address. If privacy is enabled this is a Resolvable Private
2444 	 *  Address.
2445 	 */
2446 	bt_addr_le_t addr;
2447 
2448 	/** LE Secure Connections pairing Out of Band data. */
2449 	struct bt_le_oob_sc_data le_sc_data;
2450 };
2451 
2452 /**
2453  * @brief Get local LE Out of Band (OOB) information.
2454  *
2455  * This function allows to get local information that are useful for
2456  * Out of Band pairing or connection creation.
2457  *
2458  * If privacy @kconfig{CONFIG_BT_PRIVACY} is enabled this will result in
2459  * generating new Resolvable Private Address (RPA) that is valid for
2460  * @kconfig{CONFIG_BT_RPA_TIMEOUT} seconds. This address will be used for
2461  * advertising started by @ref bt_le_adv_start, active scanning and
2462  * connection creation.
2463  *
2464  * @note If privacy is enabled the RPA cannot be refreshed in the following
2465  *       cases:
2466  *       - Creating a connection in progress, wait for the connected callback.
2467  *      In addition when extended advertising @kconfig{CONFIG_BT_EXT_ADV} is
2468  *      not enabled or not supported by the controller:
2469  *       - Advertiser is enabled using a Random Static Identity Address for a
2470  *         different local identity.
2471  *       - The local identity conflicts with the local identity used by other
2472  *         roles.
2473  *
2474  * @param[in]  id  Local identity, in most cases BT_ID_DEFAULT.
2475  * @param[out] oob LE OOB information
2476  *
2477  * @return Zero on success or error code otherwise, positive in case of
2478  *         protocol error or negative (POSIX) in case of stack internal error.
2479  */
2480 int bt_le_oob_get_local(uint8_t id, struct bt_le_oob *oob);
2481 
2482 /**
2483  * @brief Get local LE Out of Band (OOB) information.
2484  *
2485  * This function allows to get local information that are useful for
2486  * Out of Band pairing or connection creation.
2487  *
2488  * If privacy @kconfig{CONFIG_BT_PRIVACY} is enabled this will result in
2489  * generating new Resolvable Private Address (RPA) that is valid for
2490  * @kconfig{CONFIG_BT_RPA_TIMEOUT} seconds. This address will be used by the
2491  * advertising set.
2492  *
2493  * @note When generating OOB information for multiple advertising set all
2494  *       OOB information needs to be generated at the same time.
2495  *
2496  * @note If privacy is enabled the RPA cannot be refreshed in the following
2497  *       cases:
2498  *       - Creating a connection in progress, wait for the connected callback.
2499  *
2500  * @param[in]  adv The advertising set object
2501  * @param[out] oob LE OOB information
2502  *
2503  * @return Zero on success or error code otherwise, positive in case
2504  * of protocol error or negative (POSIX) in case of stack internal error.
2505  */
2506 int bt_le_ext_adv_oob_get_local(struct bt_le_ext_adv *adv,
2507 				struct bt_le_oob *oob);
2508 
2509 /** @brief BR/EDR discovery result structure */
2510 struct bt_br_discovery_result {
2511 	/** private */
2512 	uint8_t _priv[4];
2513 
2514 	/** Remote device address */
2515 	bt_addr_t addr;
2516 
2517 	/** RSSI from inquiry */
2518 	int8_t rssi;
2519 
2520 	/** Class of Device */
2521 	uint8_t cod[3];
2522 
2523 	/** Extended Inquiry Response */
2524 	uint8_t eir[240];
2525 };
2526 
2527 /**
2528  * @typedef bt_br_discovery_cb_t
2529  * @brief Callback type for reporting BR/EDR discovery (inquiry)
2530  *        results.
2531  *
2532  * A callback of this type is given to the bt_br_discovery_start()
2533  * function and will be called at the end of the discovery with
2534  * information about found devices populated in the results array.
2535  *
2536  * @param results Storage used for discovery results
2537  * @param count Number of valid discovery results.
2538  */
2539 typedef void bt_br_discovery_cb_t(struct bt_br_discovery_result *results,
2540 				  size_t count);
2541 
2542 /** BR/EDR discovery parameters */
2543 struct bt_br_discovery_param {
2544 	/** Maximum length of the discovery in units of 1.28 seconds.
2545 	 *  Valid range is 0x01 - 0x30.
2546 	 */
2547 	uint8_t length;
2548 
2549 	/** True if limited discovery procedure is to be used. */
2550 	bool limited;
2551 };
2552 
2553 /**
2554  * @brief Start BR/EDR discovery
2555  *
2556  * Start BR/EDR discovery (inquiry) and provide results through the specified
2557  * callback. When bt_br_discovery_cb_t is called it indicates that discovery
2558  * has completed. If more inquiry results were received during session than
2559  * fits in provided result storage, only ones with highest RSSI will be
2560  * reported.
2561  *
2562  * @param param Discovery parameters.
2563  * @param results Storage for discovery results.
2564  * @param count Number of results in storage. Valid range: 1-255.
2565  * @param cb Callback to notify discovery results.
2566  *
2567  * @return Zero on success or error code otherwise, positive in case
2568  * of protocol error or negative (POSIX) in case of stack internal error
2569  */
2570 int bt_br_discovery_start(const struct bt_br_discovery_param *param,
2571 			  struct bt_br_discovery_result *results, size_t count,
2572 			  bt_br_discovery_cb_t cb);
2573 
2574 /**
2575  * @brief Stop BR/EDR discovery.
2576  *
2577  * Stops ongoing BR/EDR discovery. If discovery was stopped by this call
2578  * results won't be reported
2579  *
2580  * @return Zero on success or error code otherwise, positive in case of
2581  *         protocol error or negative (POSIX) in case of stack internal error.
2582  */
2583 int bt_br_discovery_stop(void);
2584 
2585 struct bt_br_oob {
2586 	/** BR/EDR address. */
2587 	bt_addr_t addr;
2588 };
2589 
2590 /**
2591  * @brief Get BR/EDR local Out Of Band information
2592  *
2593  * This function allows to get local controller information that are useful
2594  * for Out Of Band pairing or connection creation process.
2595  *
2596  * @param oob Out Of Band information
2597  */
2598 int bt_br_oob_get_local(struct bt_br_oob *oob);
2599 
2600 
2601 /**
2602  * @brief Enable/disable set controller in discoverable state.
2603  *
2604  * Allows make local controller to listen on INQUIRY SCAN channel and responds
2605  * to devices making general inquiry. To enable this state it's mandatory
2606  * to first be in connectable state.
2607  *
2608  * @param enable Value allowing/disallowing controller to become discoverable.
2609  *
2610  * @return Negative if fail set to requested state or requested state has been
2611  *         already set. Zero if done successfully.
2612  */
2613 int bt_br_set_discoverable(bool enable);
2614 
2615 /**
2616  * @brief Enable/disable set controller in connectable state.
2617  *
2618  * Allows make local controller to be connectable. It means the controller
2619  * start listen to devices requests on PAGE SCAN channel. If disabled also
2620  * resets discoverability if was set.
2621  *
2622  * @param enable Value allowing/disallowing controller to be connectable.
2623  *
2624  * @return Negative if fail set to requested state or requested state has been
2625  *         already set. Zero if done successfully.
2626  */
2627 int bt_br_set_connectable(bool enable);
2628 
2629 /**
2630  * @brief Clear pairing information.
2631  *
2632  * @param id    Local identity (mostly just BT_ID_DEFAULT).
2633  * @param addr  Remote address, NULL or BT_ADDR_LE_ANY to clear all remote
2634  *              devices.
2635  *
2636  * @return 0 on success or negative error value on failure.
2637  */
2638 int bt_unpair(uint8_t id, const bt_addr_le_t *addr);
2639 
2640 /** Information about a bond with a remote device. */
2641 struct bt_bond_info {
2642 	/** Address of the remote device. */
2643 	bt_addr_le_t addr;
2644 };
2645 
2646 /**
2647  * @brief Iterate through all existing bonds.
2648  *
2649  * @param id         Local identity (mostly just BT_ID_DEFAULT).
2650  * @param func       Function to call for each bond.
2651  * @param user_data  Data to pass to the callback function.
2652  */
2653 void bt_foreach_bond(uint8_t id, void (*func)(const struct bt_bond_info *info,
2654 					   void *user_data),
2655 		     void *user_data);
2656 
2657 /** @brief Configure vendor data path
2658  *
2659  *  Request the Controller to configure the data transport path in a given direction between
2660  *  the Controller and the Host.
2661  *
2662  *  @param dir            Direction to be configured, BT_HCI_DATAPATH_DIR_HOST_TO_CTLR or
2663  *                        BT_HCI_DATAPATH_DIR_CTLR_TO_HOST
2664  *  @param id             Vendor specific logical transport channel ID, range
2665  *                        [BT_HCI_DATAPATH_ID_VS..BT_HCI_DATAPATH_ID_VS_END]
2666  *  @param vs_config_len  Length of additional vendor specific configuration data
2667  *  @param vs_config      Pointer to additional vendor specific configuration data
2668  *
2669  *  @return 0 in case of success or negative value in case of error.
2670  */
2671 int bt_configure_data_path(uint8_t dir, uint8_t id, uint8_t vs_config_len,
2672 			   const uint8_t *vs_config);
2673 
2674 struct bt_le_per_adv_sync_subevent_params {
2675 	/** @brief Periodic Advertising Properties.
2676 	 *
2677 	 * Bit 6 is include TxPower, all others RFU.
2678 	 *
2679 	 */
2680 	uint16_t properties;
2681 
2682 	/** Number of subevents to sync to */
2683 	uint8_t num_subevents;
2684 
2685 	/** @brief The subevent(s) to synchronize with
2686 	 *
2687 	 * The array must have @ref num_subevents elements.
2688 	 *
2689 	 */
2690 	uint8_t *subevents;
2691 };
2692 
2693 /** @brief Synchronize with a subset of subevents
2694  *
2695  *  Until this command is issued, the subevent(s) the controller is synchronized
2696  *  to is unspecified.
2697  *
2698  *  @param per_adv_sync   The periodic advertising sync object.
2699  *  @param params         Parameters.
2700  *
2701  *  @return 0 in case of success or negative value in case of error.
2702  */
2703 int bt_le_per_adv_sync_subevent(struct bt_le_per_adv_sync *per_adv_sync,
2704 				struct bt_le_per_adv_sync_subevent_params *params);
2705 
2706 struct bt_le_per_adv_response_params {
2707 	/** @brief The periodic event counter of the request the response is sent to.
2708 	 *
2709 	 * @ref bt_le_per_adv_sync_recv_info
2710 	 *
2711 	 * @note The response can be sent up to one periodic interval after
2712 	 * the request was received.
2713 	 *
2714 	 */
2715 	uint16_t request_event;
2716 
2717 	/** @brief The subevent counter of the request the response is sent to.
2718 	 *
2719 	 * @ref bt_le_per_adv_sync_recv_info
2720 	 *
2721 	 */
2722 	uint8_t request_subevent;
2723 
2724 	/** The subevent the response shall be sent in */
2725 	uint8_t response_subevent;
2726 
2727 	/** The response slot the response shall be sent in */
2728 	uint8_t response_slot;
2729 };
2730 
2731 /**
2732  * @brief Set the data for a response slot in a specific subevent of the PAwR.
2733  *
2734  * This function is called by the application to set the response data.
2735  * The data for a response slot shall be transmitted only once.
2736  *
2737  * @param per_adv_sync The periodic advertising sync object.
2738  * @param params       Parameters.
2739  * @param data         The response data to send.
2740  *
2741  * @return Zero on success or (negative) error code otherwise.
2742  */
2743 int bt_le_per_adv_set_response_data(struct bt_le_per_adv_sync *per_adv_sync,
2744 				    const struct bt_le_per_adv_response_params *params,
2745 				    const struct net_buf_simple *data);
2746 
2747 /**
2748  * @}
2749  */
2750 
2751 #ifdef __cplusplus
2752 }
2753 #endif
2754 /**
2755  * @}
2756  */
2757 
2758 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_BLUETOOTH_H_ */
2759