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