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