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