1 /** @file
2  *  @brief Bluetooth connection handling
3  */
4 
5 /*
6  * Copyright (c) 2015-2016 Intel Corporation
7  *
8  * SPDX-License-Identifier: Apache-2.0
9  */
10 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_CONN_H_
11 #define ZEPHYR_INCLUDE_BLUETOOTH_CONN_H_
12 
13 /**
14  * @brief Connection management
15  * @defgroup bt_conn Connection management
16  * @ingroup bluetooth
17  * @{
18  */
19 
20 #include <stdbool.h>
21 #include <stdint.h>
22 
23 #include <zephyr/bluetooth/bluetooth.h>
24 #include <zephyr/bluetooth/hci_types.h>
25 #include <zephyr/bluetooth/addr.h>
26 #include <zephyr/bluetooth/gap.h>
27 #include <zephyr/bluetooth/direction.h>
28 #include <zephyr/sys/iterable_sections.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /** Opaque type representing a connection to a remote device */
35 struct bt_conn;
36 
37 /** Connection parameters for LE connections */
38 struct bt_le_conn_param {
39 	uint16_t interval_min;
40 	uint16_t interval_max;
41 	uint16_t latency;
42 	uint16_t timeout;
43 };
44 
45 /** @brief Initialize connection parameters
46  *
47  *  @param int_min  Minimum Connection Interval (N * 1.25 ms)
48  *  @param int_max  Maximum Connection Interval (N * 1.25 ms)
49  *  @param lat      Connection Latency
50  *  @param to       Supervision Timeout (N * 10 ms)
51  */
52 #define BT_LE_CONN_PARAM_INIT(int_min, int_max, lat, to) \
53 { \
54 	.interval_min = (int_min), \
55 	.interval_max = (int_max), \
56 	.latency = (lat), \
57 	.timeout = (to), \
58 }
59 
60 /** Helper to declare connection parameters inline
61  *
62  *  @param int_min  Minimum Connection Interval (N * 1.25 ms)
63  *  @param int_max  Maximum Connection Interval (N * 1.25 ms)
64  *  @param lat      Connection Latency
65  *  @param to       Supervision Timeout (N * 10 ms)
66  */
67 #define BT_LE_CONN_PARAM(int_min, int_max, lat, to) \
68 	((struct bt_le_conn_param[]) { \
69 		BT_LE_CONN_PARAM_INIT(int_min, int_max, lat, to) \
70 	 })
71 
72 /** Default LE connection parameters:
73  *    Connection Interval: 30-50 ms
74  *    Latency: 0
75  *    Timeout: 4 s
76  */
77 #define BT_LE_CONN_PARAM_DEFAULT BT_LE_CONN_PARAM(BT_GAP_INIT_CONN_INT_MIN, \
78 						  BT_GAP_INIT_CONN_INT_MAX, \
79 						  0, 400)
80 
81 /** Connection PHY information for LE connections */
82 struct bt_conn_le_phy_info {
83 	uint8_t tx_phy; /** Connection transmit PHY */
84 	uint8_t rx_phy; /** Connection receive PHY */
85 };
86 
87 /** Connection PHY options */
88 enum {
89 	/** Convenience value when no options are specified. */
90 	BT_CONN_LE_PHY_OPT_NONE = 0,
91 
92 	/** LE Coded using S=2 coding preferred when transmitting. */
93 	BT_CONN_LE_PHY_OPT_CODED_S2  = BIT(0),
94 
95 	/** LE Coded using S=8 coding preferred when transmitting. */
96 	BT_CONN_LE_PHY_OPT_CODED_S8  = BIT(1),
97 };
98 
99 /** Preferred PHY parameters for LE connections */
100 struct bt_conn_le_phy_param {
101 	uint16_t options; /**< Connection PHY options. */
102 	uint8_t  pref_tx_phy; /**< Bitmask of preferred transmit PHYs */
103 	uint8_t  pref_rx_phy; /**< Bitmask of preferred receive PHYs */
104 };
105 
106 /** Initialize PHY parameters
107  *
108  * @param _pref_tx_phy Bitmask of preferred transmit PHYs.
109  * @param _pref_rx_phy Bitmask of preferred receive PHYs.
110  */
111 #define BT_CONN_LE_PHY_PARAM_INIT(_pref_tx_phy, _pref_rx_phy) \
112 { \
113 	.options = BT_CONN_LE_PHY_OPT_NONE, \
114 	.pref_tx_phy = (_pref_tx_phy), \
115 	.pref_rx_phy = (_pref_rx_phy), \
116 }
117 
118 /** Helper to declare PHY parameters inline
119  *
120  * @param _pref_tx_phy Bitmask of preferred transmit PHYs.
121  * @param _pref_rx_phy Bitmask of preferred receive PHYs.
122  */
123 #define BT_CONN_LE_PHY_PARAM(_pref_tx_phy, _pref_rx_phy) \
124 	((struct bt_conn_le_phy_param []) { \
125 		BT_CONN_LE_PHY_PARAM_INIT(_pref_tx_phy, _pref_rx_phy) \
126 	 })
127 
128 /** Only LE 1M PHY */
129 #define BT_CONN_LE_PHY_PARAM_1M BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_1M, \
130 						     BT_GAP_LE_PHY_1M)
131 
132 /** Only LE 2M PHY */
133 #define BT_CONN_LE_PHY_PARAM_2M BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_2M, \
134 						     BT_GAP_LE_PHY_2M)
135 
136 /** Only LE Coded PHY. */
137 #define BT_CONN_LE_PHY_PARAM_CODED BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_CODED, \
138 							BT_GAP_LE_PHY_CODED)
139 
140 /** All LE PHYs. */
141 #define BT_CONN_LE_PHY_PARAM_ALL BT_CONN_LE_PHY_PARAM(BT_GAP_LE_PHY_1M |   \
142 						      BT_GAP_LE_PHY_2M |   \
143 						      BT_GAP_LE_PHY_CODED, \
144 						      BT_GAP_LE_PHY_1M |   \
145 						      BT_GAP_LE_PHY_2M |   \
146 						      BT_GAP_LE_PHY_CODED)
147 
148 /** Connection data length information for LE connections */
149 struct bt_conn_le_data_len_info {
150 	/** Maximum Link Layer transmission payload size in bytes. */
151 	uint16_t tx_max_len;
152 	/** Maximum Link Layer transmission payload time in us. */
153 	uint16_t tx_max_time;
154 	/** Maximum Link Layer reception payload size in bytes. */
155 	uint16_t rx_max_len;
156 	/** Maximum Link Layer reception payload time in us. */
157 	uint16_t rx_max_time;
158 };
159 
160 /** Connection data length parameters for LE connections */
161 struct bt_conn_le_data_len_param {
162 	/** Maximum Link Layer transmission payload size in bytes. */
163 	uint16_t tx_max_len;
164 	/** Maximum Link Layer transmission payload time in us. */
165 	uint16_t tx_max_time;
166 };
167 
168 /** Initialize transmit data length parameters
169  *
170  * @param  _tx_max_len  Maximum Link Layer transmission payload size in bytes.
171  * @param  _tx_max_time Maximum Link Layer transmission payload time in us.
172  */
173 #define BT_CONN_LE_DATA_LEN_PARAM_INIT(_tx_max_len, _tx_max_time) \
174 { \
175 	.tx_max_len = (_tx_max_len), \
176 	.tx_max_time = (_tx_max_time), \
177 }
178 
179 /** Helper to declare transmit data length parameters inline
180  *
181  * @param  _tx_max_len  Maximum Link Layer transmission payload size in bytes.
182  * @param  _tx_max_time Maximum Link Layer transmission payload time in us.
183  */
184 #define BT_CONN_LE_DATA_LEN_PARAM(_tx_max_len, _tx_max_time) \
185 	((struct bt_conn_le_data_len_param[]) { \
186 		BT_CONN_LE_DATA_LEN_PARAM_INIT(_tx_max_len, _tx_max_time) \
187 	 })
188 
189 /** Default LE data length parameters. */
190 #define BT_LE_DATA_LEN_PARAM_DEFAULT \
191 	BT_CONN_LE_DATA_LEN_PARAM(BT_GAP_DATA_LEN_DEFAULT, \
192 				  BT_GAP_DATA_TIME_DEFAULT)
193 
194 /** Maximum LE data length parameters. */
195 #define BT_LE_DATA_LEN_PARAM_MAX \
196 	BT_CONN_LE_DATA_LEN_PARAM(BT_GAP_DATA_LEN_MAX, \
197 				  BT_GAP_DATA_TIME_MAX)
198 
199 /** Connection Type */
200 enum __packed bt_conn_type {
201 	/** LE Connection Type */
202 	BT_CONN_TYPE_LE = BIT(0),
203 	/** BR/EDR Connection Type */
204 	BT_CONN_TYPE_BR = BIT(1),
205 	/** SCO Connection Type */
206 	BT_CONN_TYPE_SCO = BIT(2),
207 	/** ISO Connection Type */
208 	BT_CONN_TYPE_ISO = BIT(3),
209 	/** All Connection Type */
210 	BT_CONN_TYPE_ALL = BT_CONN_TYPE_LE | BT_CONN_TYPE_BR |
211 			   BT_CONN_TYPE_SCO | BT_CONN_TYPE_ISO,
212 };
213 
214 /** @brief Increment a connection's reference count.
215  *
216  *  Increment the reference count of a connection object.
217  *
218  *  @note Will return NULL if the reference count is zero.
219  *
220  *  @param conn Connection object.
221  *
222  *  @return Connection object with incremented reference count, or NULL if the
223  *          reference count is zero.
224  */
225 struct bt_conn *bt_conn_ref(struct bt_conn *conn);
226 
227 /** @brief Decrement a connection's reference count.
228  *
229  *  Decrement the reference count of a connection object.
230  *
231  *  @param conn Connection object.
232  */
233 void bt_conn_unref(struct bt_conn *conn);
234 
235 /** @brief Iterate through all bt_conn objects.
236  *
237  * Iterates through all bt_conn objects that are alive in the Host allocator.
238  *
239  * To find established connections, combine this with @ref bt_conn_get_info.
240  * Check that @ref bt_conn_info.state is @ref BT_CONN_STATE_CONNECTED.
241  *
242  * Thread safety: This API is thread safe, but it does not guarantee a
243  * sequentially-consistent view for objects allocated during the current
244  * invocation of this API. E.g. If preempted while allocations A then B then C
245  * happen then results may include A and C but miss B.
246  *
247  * @param type  Connection Type
248  * @param func  Function to call for each connection.
249  * @param data  Data to pass to the callback function.
250  */
251 void bt_conn_foreach(enum bt_conn_type type,
252 		     void (*func)(struct bt_conn *conn, void *data),
253 		     void *data);
254 
255 /** @brief Look up an existing connection by address.
256  *
257  *  Look up an existing connection based on the remote address.
258  *
259  *  The caller gets a new reference to the connection object which must be
260  *  released with bt_conn_unref() once done using the object.
261  *
262  *  @param id   Local identity (in most cases BT_ID_DEFAULT).
263  *  @param peer Remote address.
264  *
265  *  @return Connection object or NULL if not found.
266  */
267 struct bt_conn *bt_conn_lookup_addr_le(uint8_t id, const bt_addr_le_t *peer);
268 
269 /** @brief Get destination (peer) address of a connection.
270  *
271  *  @param conn Connection object.
272  *
273  *  @return Destination address.
274  */
275 const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn);
276 
277 /** @brief Get array index of a connection
278  *
279  *  This function is used to map bt_conn to index of an array of
280  *  connections. The array has CONFIG_BT_MAX_CONN elements.
281  *
282  *  @param conn Connection object.
283  *
284  *  @return Index of the connection object.
285  *          The range of the returned value is 0..CONFIG_BT_MAX_CONN-1
286  */
287 uint8_t bt_conn_index(const struct bt_conn *conn);
288 
289 /** LE Connection Info Structure */
290 struct bt_conn_le_info {
291 	/** Source (Local) Identity Address */
292 	const bt_addr_le_t *src;
293 	/** Destination (Remote) Identity Address or remote Resolvable Private
294 	 *  Address (RPA) before identity has been resolved.
295 	 */
296 	const bt_addr_le_t *dst;
297 	/** Local device address used during connection setup. */
298 	const bt_addr_le_t *local;
299 	/** Remote device address used during connection setup. */
300 	const bt_addr_le_t *remote;
301 	uint16_t interval; /**< Connection interval */
302 	uint16_t latency; /**< Connection peripheral latency */
303 	uint16_t timeout; /**< Connection supervision timeout */
304 
305 #if defined(CONFIG_BT_USER_PHY_UPDATE)
306 	const struct bt_conn_le_phy_info      *phy;
307 #endif /* defined(CONFIG_BT_USER_PHY_UPDATE) */
308 
309 #if defined(CONFIG_BT_USER_DATA_LEN_UPDATE)
310 	/* Connection maximum single fragment parameters */
311 	const struct bt_conn_le_data_len_info *data_len;
312 #endif /* defined(CONFIG_BT_USER_DATA_LEN_UPDATE) */
313 };
314 
315 /** @brief Convert connection interval to milliseconds
316  *
317  *  Multiply by 1.25 to get milliseconds.
318  *
319  *  Note that this may be inaccurate, as something like 7.5 ms cannot be
320  *  accurately presented with integers.
321  */
322 #define BT_CONN_INTERVAL_TO_MS(interval) ((interval) * 5U / 4U)
323 
324 /** @brief Convert connection interval to microseconds
325  *
326  *  Multiply by 1250 to get microseconds.
327  */
328 #define BT_CONN_INTERVAL_TO_US(interval) ((interval) * 1250U)
329 
330 /** BR/EDR Connection Info Structure */
331 struct bt_conn_br_info {
332 	const bt_addr_t *dst; /**< Destination (Remote) BR/EDR address */
333 };
334 
335 enum {
336 	BT_CONN_ROLE_CENTRAL = 0,
337 	BT_CONN_ROLE_PERIPHERAL = 1,
338 };
339 
340 enum bt_conn_state {
341 	/** Channel disconnected */
342 	BT_CONN_STATE_DISCONNECTED,
343 	/** Channel in connecting state */
344 	BT_CONN_STATE_CONNECTING,
345 	/** Channel connected and ready for upper layer traffic on it */
346 	BT_CONN_STATE_CONNECTED,
347 	/** Channel in disconnecting state */
348 	BT_CONN_STATE_DISCONNECTING,
349 };
350 
351 /** Security level. */
352 typedef enum __packed {
353 	/** Level 0: Only for BR/EDR special cases, like SDP */
354 	BT_SECURITY_L0,
355 	/** Level 1: No encryption and no authentication. */
356 	BT_SECURITY_L1,
357 	/** Level 2: Encryption and no authentication (no MITM). */
358 	BT_SECURITY_L2,
359 	/** Level 3: Encryption and authentication (MITM). */
360 	BT_SECURITY_L3,
361 	/** Level 4: Authenticated Secure Connections and 128-bit key. */
362 	BT_SECURITY_L4,
363 	/** Bit to force new pairing procedure, bit-wise OR with requested
364 	 *  security level.
365 	 */
366 	BT_SECURITY_FORCE_PAIR = BIT(7),
367 } bt_security_t;
368 
369 /** Security Info Flags. */
370 enum bt_security_flag {
371 	/** Paired with Secure Connections. */
372 	BT_SECURITY_FLAG_SC = BIT(0),
373 	/** Paired with Out of Band method. */
374 	BT_SECURITY_FLAG_OOB = BIT(1),
375 };
376 
377 /** Security Info Structure. */
378 struct bt_security_info {
379 	/** Security Level. */
380 	bt_security_t level;
381 	/** Encryption Key Size. */
382 	uint8_t enc_key_size;
383 	/** Flags. */
384 	enum bt_security_flag flags;
385 };
386 
387 /** Connection Info Structure */
388 struct bt_conn_info {
389 	/** Connection Type. */
390 	enum bt_conn_type type;
391 	/** Connection Role. */
392 	uint8_t role;
393 	/** Which local identity the connection was created with */
394 	uint8_t id;
395 	/** Connection Type specific Info.*/
396 	union {
397 		/** LE Connection specific Info. */
398 		struct bt_conn_le_info le;
399 		/** BR/EDR Connection specific Info. */
400 		struct bt_conn_br_info br;
401 	};
402 	/** Connection state. */
403 	enum bt_conn_state state;
404 	/** Security specific info. */
405 	struct bt_security_info security;
406 };
407 
408 /** LE Connection Remote Info Structure */
409 struct bt_conn_le_remote_info {
410 
411 	/** Remote LE feature set (bitmask). */
412 	const uint8_t *features;
413 };
414 
415 /** BR/EDR Connection Remote Info structure */
416 struct bt_conn_br_remote_info {
417 
418 	/** Remote feature set (pages of bitmasks). */
419 	const uint8_t *features;
420 
421 	/** Number of pages in the remote feature set. */
422 	uint8_t num_pages;
423 };
424 
425 /** @brief Connection Remote Info Structure
426  *
427  *  @note The version, manufacturer and subversion fields will only contain
428  *        valid data if @kconfig{CONFIG_BT_REMOTE_VERSION} is enabled.
429  */
430 struct bt_conn_remote_info {
431 	/** Connection Type */
432 	uint8_t  type;
433 
434 	/** Remote Link Layer version */
435 	uint8_t  version;
436 
437 	/** Remote manufacturer identifier */
438 	uint16_t manufacturer;
439 
440 	/** Per-manufacturer unique revision */
441 	uint16_t subversion;
442 
443 	union {
444 		/** LE connection remote info */
445 		struct bt_conn_le_remote_info le;
446 
447 		/** BR/EDR connection remote info */
448 		struct bt_conn_br_remote_info br;
449 	};
450 };
451 
452 enum bt_conn_le_tx_power_phy {
453 	/** Convenience macro for when no PHY is set. */
454 	BT_CONN_LE_TX_POWER_PHY_NONE,
455 	/** LE 1M PHY */
456 	BT_CONN_LE_TX_POWER_PHY_1M,
457 	 /** LE 2M PHY */
458 	BT_CONN_LE_TX_POWER_PHY_2M,
459 	/** LE Coded PHY using S=8 coding. */
460 	BT_CONN_LE_TX_POWER_PHY_CODED_S8,
461 	/** LE Coded PHY using S=2 coding. */
462 	BT_CONN_LE_TX_POWER_PHY_CODED_S2,
463 };
464 
465 /** LE Transmit Power Level Structure */
466 struct bt_conn_le_tx_power {
467 
468 	/** Input: 1M, 2M, Coded S2 or Coded S8 */
469 	uint8_t phy;
470 
471 	/** Output: current transmit power level */
472 	int8_t current_level;
473 
474 	/** Output: maximum transmit power level */
475 	int8_t max_level;
476 };
477 
478 
479 /** LE Transmit Power Reporting Structure */
480 struct bt_conn_le_tx_power_report {
481 
482 	/** Reason for Transmit power reporting,
483 	 * as documented in Core Spec. Version 5.4 Vol. 4, Part E, 7.7.65.33.
484 	 */
485 	uint8_t reason;
486 
487 	/** Phy of Transmit power reporting. */
488 	enum bt_conn_le_tx_power_phy phy;
489 
490 	/** Transmit power level
491 	 * - 0xXX - Transmit power level
492 	 *  + Range: -127 to 20
493 	 *  + Units: dBm
494 	 *
495 	 * - 0x7E - Remote device is not managing power levels on this PHY.
496 	 * - 0x7F - Transmit power level is not available
497 	 */
498 	int8_t tx_power_level;
499 
500 	/** Bit 0: Transmit power level is at minimum level.
501 	 *  Bit 1: Transmit power level is at maximum level.
502 	 */
503 	uint8_t tx_power_level_flag;
504 
505 	/** Change in transmit power level
506 	 * - 0xXX - Change in transmit power level (positive indicates increased
507 	 *   power, negative indicates decreased power, zero indicates unchanged)
508 	 *   Units: dB
509 	 * - 0x7F - Change is not available or is out of range.
510 	 */
511 	int8_t delta;
512 };
513 
514 /** @brief Path Loss zone that has been entered.
515  *
516  *  The path loss zone that has been entered in the most recent LE Path Loss Monitoring
517  *  Threshold Change event as documented in Core Spec. Version 5.4 Vol.4, Part E, 7.7.65.32.
518  *
519  *  @note BT_CONN_LE_PATH_LOSS_ZONE_UNAVAILABLE has been added to notify when path loss becomes
520  *        unavailable.
521  */
522 enum bt_conn_le_path_loss_zone {
523 	/** Low path loss zone entered. */
524 	BT_CONN_LE_PATH_LOSS_ZONE_ENTERED_LOW,
525 	/** Middle path loss zone entered. */
526 	BT_CONN_LE_PATH_LOSS_ZONE_ENTERED_MIDDLE,
527 	/** High path loss zone entered. */
528 	BT_CONN_LE_PATH_LOSS_ZONE_ENTERED_HIGH,
529 	/** Path loss has become unavailable. */
530 	BT_CONN_LE_PATH_LOSS_ZONE_UNAVAILABLE,
531 };
532 
533 BUILD_ASSERT(BT_CONN_LE_PATH_LOSS_ZONE_ENTERED_LOW == BT_HCI_LE_ZONE_ENTERED_LOW);
534 BUILD_ASSERT(BT_CONN_LE_PATH_LOSS_ZONE_ENTERED_MIDDLE == BT_HCI_LE_ZONE_ENTERED_MIDDLE);
535 BUILD_ASSERT(BT_CONN_LE_PATH_LOSS_ZONE_ENTERED_HIGH == BT_HCI_LE_ZONE_ENTERED_HIGH);
536 
537 /** @brief LE Path Loss Monitoring Threshold Change Report Structure. */
538 struct bt_conn_le_path_loss_threshold_report {
539 
540 	/** Path Loss zone as documented in Core Spec. Version 5.4 Vol.4, Part E, 7.7.65.32. */
541 	enum bt_conn_le_path_loss_zone zone;
542 
543 	/** Current path loss (dB). */
544 	uint8_t path_loss;
545 };
546 
547 /** @brief LE Path Loss Monitoring Parameters Structure as defined in Core Spec. Version 5.4
548  *         Vol.4, Part E, 7.8.119 LE Set Path Loss Reporting Parameters command.
549  */
550 struct bt_conn_le_path_loss_reporting_param {
551 	/** High threshold for the path loss (dB). */
552 	uint8_t high_threshold;
553 	/** Hysteresis value for the high threshold (dB). */
554 	uint8_t high_hysteresis;
555 	/** Low threshold for the path loss (dB). */
556 	uint8_t low_threshold;
557 	/** Hysteresis value for the low threshold (dB). */
558 	uint8_t low_hysteresis;
559 	/** Minimum time in number of connection events to be observed once the
560 	 *  path loss crosses the threshold before an event is generated.
561 	 */
562 	uint16_t min_time_spent;
563 };
564 
565 /** @brief Passkey Keypress Notification type
566  *
567  *  The numeric values are the same as in the Core specification for Pairing
568  *  Keypress Notification PDU.
569  */
570 enum bt_conn_auth_keypress {
571 	BT_CONN_AUTH_KEYPRESS_ENTRY_STARTED = 0x00,
572 	BT_CONN_AUTH_KEYPRESS_DIGIT_ENTERED = 0x01,
573 	BT_CONN_AUTH_KEYPRESS_DIGIT_ERASED = 0x02,
574 	BT_CONN_AUTH_KEYPRESS_CLEARED = 0x03,
575 	BT_CONN_AUTH_KEYPRESS_ENTRY_COMPLETED = 0x04,
576 };
577 
578 /** @brief Get connection info
579  *
580  *  @param conn Connection object.
581  *  @param info Connection info object.
582  *
583  *  @return Zero on success or (negative) error code on failure.
584  */
585 int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info);
586 
587 /** @brief Get connection info for the remote device.
588  *
589  *  @param conn Connection object.
590  *  @param remote_info Connection remote info object.
591  *
592  *  @note In order to retrieve the remote version (version, manufacturer
593  *  and subversion) @kconfig{CONFIG_BT_REMOTE_VERSION} must be enabled
594  *
595  *  @note The remote information is exchanged directly after the connection has
596  *  been established. The application can be notified about when the remote
597  *  information is available through the remote_info_available callback.
598  *
599  *  @return Zero on success or (negative) error code on failure.
600  *  @return -EBUSY The remote information is not yet available.
601  */
602 int bt_conn_get_remote_info(struct bt_conn *conn,
603 			    struct bt_conn_remote_info *remote_info);
604 
605 /** @brief Get connection transmit power level.
606  *
607  *  @param conn           Connection object.
608  *  @param tx_power_level Transmit power level descriptor.
609  *
610  *  @return Zero on success or (negative) error code on failure.
611  *  @return -ENOBUFS HCI command buffer is not available.
612  */
613 int bt_conn_le_get_tx_power_level(struct bt_conn *conn,
614 				  struct bt_conn_le_tx_power *tx_power_level);
615 
616 /** @brief Get local enhanced connection transmit power level.
617  *
618  *  @param conn           Connection object.
619  *  @param tx_power       Transmit power level descriptor.
620  *
621  *  @return Zero on success or (negative) error code on failure.
622  *  @retval -ENOBUFS HCI command buffer is not available.
623  */
624 int bt_conn_le_enhanced_get_tx_power_level(struct bt_conn *conn,
625 					   struct bt_conn_le_tx_power *tx_power);
626 
627 /** @brief Get remote (peer) transmit power level.
628  *
629  *  @param conn           Connection object.
630  *  @param phy            PHY information.
631  *
632  *  @return Zero on success or (negative) error code on failure.
633  *  @retval -ENOBUFS HCI command buffer is not available.
634  */
635 int bt_conn_le_get_remote_tx_power_level(struct bt_conn *conn,
636 					 enum bt_conn_le_tx_power_phy phy);
637 
638 /** @brief Enable transmit power reporting.
639  *
640  *  @param conn           Connection object.
641  *  @param local_enable   Enable/disable reporting for local.
642  *  @param remote_enable  Enable/disable reporting for remote.
643  *
644  *  @return Zero on success or (negative) error code on failure.
645  *  @retval -ENOBUFS HCI command buffer is not available.
646  */
647 int bt_conn_le_set_tx_power_report_enable(struct bt_conn *conn,
648 					  bool local_enable,
649 					  bool remote_enable);
650 
651 /** @brief Set Path Loss Monitoring Parameters.
652  *
653  *  Change the configuration for path loss threshold change events for a given conn handle.
654  *
655  *  @note To use this API @kconfig{CONFIG_BT_PATH_LOSS_MONITORING} must be set.
656  *
657  *  @param conn  Connection object.
658  *  @param param Path Loss Monitoring parameters
659  *
660  *  @return Zero on success or (negative) error code on failure.
661  */
662 int bt_conn_le_set_path_loss_mon_param(struct bt_conn *conn,
663 				       const struct bt_conn_le_path_loss_reporting_param *param);
664 
665 /** @brief Enable or Disable Path Loss Monitoring.
666  *
667  * Enable or disable Path Loss Monitoring, which will decide whether Path Loss Threshold events
668  * are sent from the controller to the host.
669  *
670  * @note To use this API @kconfig{CONFIG_BT_PATH_LOSS_MONITORING} must be set.
671  *
672  * @param conn   Connection Object.
673  * @param enable Enable/disable path loss reporting.
674  *
675  * @return Zero on success or (negative) error code on failure.
676  */
677 int bt_conn_le_set_path_loss_mon_enable(struct bt_conn *conn, bool enable);
678 
679 /** @brief Update the connection parameters.
680  *
681  *  If the local device is in the peripheral role then updating the connection
682  *  parameters will be delayed. This delay can be configured by through the
683  *  @kconfig{CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT} option.
684  *
685  *  @param conn Connection object.
686  *  @param param Updated connection parameters.
687  *
688  *  @return Zero on success or (negative) error code on failure.
689  */
690 int bt_conn_le_param_update(struct bt_conn *conn,
691 			    const struct bt_le_conn_param *param);
692 
693 /** @brief Update the connection transmit data length parameters.
694  *
695  *  @param conn  Connection object.
696  *  @param param Updated data length parameters.
697  *
698  *  @return Zero on success or (negative) error code on failure.
699  */
700 int bt_conn_le_data_len_update(struct bt_conn *conn,
701 			       const struct bt_conn_le_data_len_param *param);
702 
703 /** @brief Update the connection PHY parameters.
704  *
705  *  Update the preferred transmit and receive PHYs of the connection.
706  *  Use @ref BT_GAP_LE_PHY_NONE to indicate no preference.
707  *
708  *  @param conn Connection object.
709  *  @param param Updated connection parameters.
710  *
711  *  @return Zero on success or (negative) error code on failure.
712  */
713 int bt_conn_le_phy_update(struct bt_conn *conn,
714 			  const struct bt_conn_le_phy_param *param);
715 
716 /** @brief Disconnect from a remote device or cancel pending connection.
717  *
718  *  Disconnect an active connection with the specified reason code or cancel
719  *  pending outgoing connection.
720  *
721  *  The disconnect reason for a normal disconnect should be:
722  *  @ref BT_HCI_ERR_REMOTE_USER_TERM_CONN.
723  *
724  *  The following disconnect reasons are accepted:
725  *   - @ref BT_HCI_ERR_AUTH_FAIL
726  *   - @ref BT_HCI_ERR_REMOTE_USER_TERM_CONN
727  *   - @ref BT_HCI_ERR_REMOTE_LOW_RESOURCES
728  *   - @ref BT_HCI_ERR_REMOTE_POWER_OFF
729  *   - @ref BT_HCI_ERR_UNSUPP_REMOTE_FEATURE
730  *   - @ref BT_HCI_ERR_PAIRING_NOT_SUPPORTED
731  *   - @ref BT_HCI_ERR_UNACCEPT_CONN_PARAM
732  *
733  *  @param conn Connection to disconnect.
734  *  @param reason Reason code for the disconnection.
735  *
736  *  @return Zero on success or (negative) error code on failure.
737  */
738 int bt_conn_disconnect(struct bt_conn *conn, uint8_t reason);
739 
740 enum {
741 	/** Convenience value when no options are specified. */
742 	BT_CONN_LE_OPT_NONE = 0,
743 
744 	/** @brief Enable LE Coded PHY.
745 	 *
746 	 *  Enable scanning on the LE Coded PHY.
747 	 */
748 	BT_CONN_LE_OPT_CODED = BIT(0),
749 
750 	/** @brief Disable LE 1M PHY.
751 	 *
752 	 *  Disable scanning on the LE 1M PHY.
753 	 *
754 	 *  @note Requires @ref BT_CONN_LE_OPT_CODED.
755 	 */
756 	BT_CONN_LE_OPT_NO_1M = BIT(1),
757 };
758 
759 struct bt_conn_le_create_param {
760 
761 	/** Bit-field of create connection options. */
762 	uint32_t options;
763 
764 	/** Scan interval (N * 0.625 ms) */
765 	uint16_t interval;
766 
767 	/** Scan window (N * 0.625 ms) */
768 	uint16_t window;
769 
770 	/** @brief Scan interval LE Coded PHY (N * 0.625 MS)
771 	 *
772 	 *  Set zero to use same as LE 1M PHY scan interval
773 	 */
774 	uint16_t interval_coded;
775 
776 	/** @brief Scan window LE Coded PHY (N * 0.625 MS)
777 	 *
778 	 *  Set zero to use same as LE 1M PHY scan window.
779 	 */
780 	uint16_t window_coded;
781 
782 	/** @brief Connection initiation timeout (N * 10 MS)
783 	 *
784 	 *  Set zero to use the default @kconfig{CONFIG_BT_CREATE_CONN_TIMEOUT}
785 	 *  timeout.
786 	 *
787 	 *  @note Unused in @ref bt_conn_le_create_auto
788 	 */
789 	uint16_t timeout;
790 };
791 
792 /** @brief Initialize create connection parameters
793  *
794  *  @param _options  Create connection options.
795  *  @param _interval Create connection scan interval (N * 0.625 ms).
796  *  @param _window   Create connection scan window (N * 0.625 ms).
797  */
798 #define BT_CONN_LE_CREATE_PARAM_INIT(_options, _interval, _window) \
799 { \
800 	.options = (_options), \
801 	.interval = (_interval), \
802 	.window = (_window), \
803 	.interval_coded = 0, \
804 	.window_coded = 0, \
805 	.timeout = 0, \
806 }
807 
808 /** Helper to declare create connection parameters inline
809  *
810  *  @param _options  Create connection options.
811  *  @param _interval Create connection scan interval (N * 0.625 ms).
812  *  @param _window   Create connection scan window (N * 0.625 ms).
813  */
814 #define BT_CONN_LE_CREATE_PARAM(_options, _interval, _window) \
815 	((struct bt_conn_le_create_param[]) { \
816 		BT_CONN_LE_CREATE_PARAM_INIT(_options, _interval, _window) \
817 	 })
818 
819 /** Default LE create connection parameters.
820  *  Scan continuously by setting scan interval equal to scan window.
821  */
822 #define BT_CONN_LE_CREATE_CONN \
823 	BT_CONN_LE_CREATE_PARAM(BT_CONN_LE_OPT_NONE, \
824 				BT_GAP_SCAN_FAST_INTERVAL, \
825 				BT_GAP_SCAN_FAST_INTERVAL)
826 
827 /** Default LE create connection using filter accept list parameters.
828  *  Scan window:   30 ms.
829  *  Scan interval: 60 ms.
830  */
831 #define BT_CONN_LE_CREATE_CONN_AUTO \
832 	BT_CONN_LE_CREATE_PARAM(BT_CONN_LE_OPT_NONE, \
833 				BT_GAP_SCAN_FAST_INTERVAL, \
834 				BT_GAP_SCAN_FAST_WINDOW)
835 
836 /** @brief Initiate an LE connection to a remote device.
837  *
838  *  Allows initiate new LE link to remote peer using its address.
839  *
840  *  The caller gets a new reference to the connection object which must be
841  *  released with bt_conn_unref() once done using the object.
842  *
843  *  This uses the General Connection Establishment procedure.
844  *
845  *  The application must disable explicit scanning before initiating
846  *  a new LE connection if @kconfig{CONFIG_BT_SCAN_AND_INITIATE_IN_PARALLEL}
847  *  is not enabled.
848  *
849  *  @param[in]  peer         Remote address.
850  *  @param[in]  create_param Create connection parameters.
851  *  @param[in]  conn_param   Initial connection parameters.
852  *  @param[out] conn         Valid connection object on success.
853  *
854  *  @return Zero on success or (negative) error code on failure.
855  */
856 int bt_conn_le_create(const bt_addr_le_t *peer,
857 		      const struct bt_conn_le_create_param *create_param,
858 		      const struct bt_le_conn_param *conn_param,
859 		      struct bt_conn **conn);
860 
861 struct bt_conn_le_create_synced_param {
862 
863 	/** @brief Remote address
864 	 *
865 	 * The peer must be synchronized to the PAwR train.
866 	 *
867 	 */
868 	const bt_addr_le_t *peer;
869 
870 	/** The subevent where the connection will be initiated. */
871 	uint8_t subevent;
872 };
873 
874 /** @brief Create a connection to a synced device
875  *
876  *  Initiate a connection to a synced device from a Periodic Advertising
877  *  with Responses (PAwR) train.
878  *
879  *  The caller gets a new reference to the connection object which must be
880  *  released with bt_conn_unref() once done using the object.
881  *
882  *  This uses the Periodic Advertising Connection Procedure.
883  *
884  *  @param[in]  adv          The adverting set the PAwR advertiser belongs to.
885  *  @param[in]  synced_param Create connection parameters.
886  *  @param[in]  conn_param   Initial connection parameters.
887  *  @param[out] conn         Valid connection object on success.
888  *
889  *  @return Zero on success or (negative) error code on failure.
890  */
891 int bt_conn_le_create_synced(const struct bt_le_ext_adv *adv,
892 			     const struct bt_conn_le_create_synced_param *synced_param,
893 			     const struct bt_le_conn_param *conn_param, struct bt_conn **conn);
894 
895 /** @brief Automatically connect to remote devices in the filter accept list.
896  *
897  *  This uses the Auto Connection Establishment procedure.
898  *  The procedure will continue until a single connection is established or the
899  *  procedure is stopped through @ref bt_conn_create_auto_stop.
900  *  To establish connections to all devices in the filter accept list the
901  *  procedure should be started again in the connected callback after a
902  *  new connection has been established.
903  *
904  *  @param create_param Create connection parameters
905  *  @param conn_param   Initial connection parameters.
906  *
907  *  @return Zero on success or (negative) error code on failure.
908  *  @return -ENOMEM No free connection object available.
909  */
910 int bt_conn_le_create_auto(const struct bt_conn_le_create_param *create_param,
911 			   const struct bt_le_conn_param *conn_param);
912 
913 /** @brief Stop automatic connect creation.
914  *
915  *  @return Zero on success or (negative) error code on failure.
916  */
917 int bt_conn_create_auto_stop(void);
918 
919 /** @brief Automatically connect to remote device if it's in range.
920  *
921  *  This function enables/disables automatic connection initiation.
922  *  Every time the device loses the connection with peer, this connection
923  *  will be re-established if connectable advertisement from peer is received.
924  *
925  *  @note Auto connect is disabled during explicit scanning.
926  *
927  *  @param addr Remote Bluetooth address.
928  *  @param param If non-NULL, auto connect is enabled with the given
929  *  parameters. If NULL, auto connect is disabled.
930  *
931  *  @return Zero on success or error code otherwise.
932  */
933 int bt_le_set_auto_conn(const bt_addr_le_t *addr,
934 			const struct bt_le_conn_param *param);
935 
936 /** @brief Set security level for a connection.
937  *
938  *  This function enable security (encryption) for a connection. If the device
939  *  has bond information for the peer with sufficiently strong key encryption
940  *  will be enabled. If the connection is already encrypted with sufficiently
941  *  strong key this function does nothing.
942  *
943  *  If the device has no bond information for the peer and is not already paired
944  *  then the pairing procedure will be initiated. Note that @p sec has no effect
945  *  on the security level selected for the pairing process. The selection is
946  *  instead controlled by the values of the registered @ref bt_conn_auth_cb. If
947  *  the device has bond information or is already paired and the keys are too
948  *  weak then the pairing procedure will be initiated.
949  *
950  *  This function may return an error if the required level of security defined using
951  *  @p sec is not possible to achieve due to local or remote device limitation
952  *  (e.g., input output capabilities), or if the maximum number of paired devices
953  *  has been reached.
954  *
955  *  This function may return an error if the pairing procedure has already been
956  *  initiated by the local device or the peer device.
957  *
958  *  @note When @kconfig{CONFIG_BT_SMP_SC_ONLY} is enabled then the security
959  *        level will always be level 4.
960  *
961  *  @note When @kconfig{CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY} is enabled then the
962  *        security level will always be level 3.
963  *
964  *  @note When @ref BT_SECURITY_FORCE_PAIR within @p sec is enabled then the pairing
965  *        procedure will always be initiated.
966  *
967  *  @param conn Connection object.
968  *  @param sec Requested minimum security level.
969  *
970  *  @return 0 on success or negative error
971  */
972 int bt_conn_set_security(struct bt_conn *conn, bt_security_t sec);
973 
974 /** @brief Get security level for a connection.
975  *
976  *  @return Connection security level
977  */
978 bt_security_t bt_conn_get_security(const struct bt_conn *conn);
979 
980 /** @brief Get encryption key size.
981  *
982  *  This function gets encryption key size.
983  *  If there is no security (encryption) enabled 0 will be returned.
984  *
985  *  @param conn Existing connection object.
986  *
987  *  @return Encryption key size.
988  */
989 uint8_t bt_conn_enc_key_size(const struct bt_conn *conn);
990 
991 enum bt_security_err {
992 	/** Security procedure successful. */
993 	BT_SECURITY_ERR_SUCCESS,
994 
995 	/** Authentication failed. */
996 	BT_SECURITY_ERR_AUTH_FAIL,
997 
998 	/** PIN or encryption key is missing. */
999 	BT_SECURITY_ERR_PIN_OR_KEY_MISSING,
1000 
1001 	/** OOB data is not available.  */
1002 	BT_SECURITY_ERR_OOB_NOT_AVAILABLE,
1003 
1004 	/** The requested security level could not be reached. */
1005 	BT_SECURITY_ERR_AUTH_REQUIREMENT,
1006 
1007 	/** Pairing is not supported */
1008 	BT_SECURITY_ERR_PAIR_NOT_SUPPORTED,
1009 
1010 	/** Pairing is not allowed. */
1011 	BT_SECURITY_ERR_PAIR_NOT_ALLOWED,
1012 
1013 	/** Invalid parameters. */
1014 	BT_SECURITY_ERR_INVALID_PARAM,
1015 
1016 	/** Distributed Key Rejected */
1017 	BT_SECURITY_ERR_KEY_REJECTED,
1018 
1019 	/** Pairing failed but the exact reason could not be specified. */
1020 	BT_SECURITY_ERR_UNSPECIFIED,
1021 };
1022 
1023 /** @brief Connection callback structure.
1024  *
1025  *  This structure is used for tracking the state of a connection.
1026  *  It is registered with the help of the bt_conn_cb_register() API.
1027  *  It's permissible to register multiple instances of this @ref bt_conn_cb
1028  *  type, in case different modules of an application are interested in
1029  *  tracking the connection state. If a callback is not of interest for
1030  *  an instance, it may be set to NULL and will as a consequence not be
1031  *  used for that instance.
1032  */
1033 struct bt_conn_cb {
1034 	/** @brief A new connection has been established.
1035 	 *
1036 	 *  This callback notifies the application of a new connection.
1037 	 *  In case the err parameter is non-zero it means that the
1038 	 *  connection establishment failed.
1039 	 *
1040 	 *  @note If the connection was established from an advertising set then
1041 	 *        the advertising set cannot be restarted directly from this
1042 	 *        callback. Instead use the connected callback of the
1043 	 *        advertising set.
1044 	 *
1045 	 *  @param conn New connection object.
1046 	 *  @param err HCI error. Zero for success, non-zero otherwise.
1047 	 *
1048 	 *  @p err can mean either of the following:
1049 	 *  - @ref BT_HCI_ERR_UNKNOWN_CONN_ID Creating the connection started by
1050 	 *    @ref bt_conn_le_create was canceled either by the user through
1051 	 *    @ref bt_conn_disconnect or by the timeout in the host through
1052 	 *    @ref bt_conn_le_create_param timeout parameter, which defaults to
1053 	 *    @kconfig{CONFIG_BT_CREATE_CONN_TIMEOUT} seconds.
1054 	 *  - @p BT_HCI_ERR_ADV_TIMEOUT High duty cycle directed connectable
1055 	 *    advertiser started by @ref bt_le_adv_start failed to be connected
1056 	 *    within the timeout.
1057 	 */
1058 	void (*connected)(struct bt_conn *conn, uint8_t err);
1059 
1060 	/** @brief A connection has been disconnected.
1061 	 *
1062 	 *  This callback notifies the application that a connection
1063 	 *  has been disconnected.
1064 	 *
1065 	 *  When this callback is called the stack still has one reference to
1066 	 *  the connection object. If the application in this callback tries to
1067 	 *  start either a connectable advertiser or create a new connection
1068 	 *  this might fail because there are no free connection objects
1069 	 *  available.
1070 	 *  To avoid this issue it is recommended to either start connectable
1071 	 *  advertise or create a new connection using @ref k_work_submit or
1072 	 *  increase @kconfig{CONFIG_BT_MAX_CONN}.
1073 	 *
1074 	 *  @param conn Connection object.
1075 	 *  @param reason BT_HCI_ERR_* reason for the disconnection.
1076 	 */
1077 	void (*disconnected)(struct bt_conn *conn, uint8_t reason);
1078 
1079 	/** @brief A connection object has been returned to the pool.
1080 	 *
1081 	 * This callback notifies the application that it might be able to
1082 	 * allocate a connection object. No guarantee, first come, first serve.
1083 	 *
1084 	 * Use this to e.g. re-start connectable advertising or scanning.
1085 	 *
1086 	 * Treat this callback as an ISR, as it originates from
1087 	 * @ref bt_conn_unref which is used by the BT stack. Making
1088 	 * Bluetooth API calls in this context is error-prone and strongly
1089 	 * discouraged.
1090 	 */
1091 	void (*recycled)(void);
1092 
1093 	/** @brief LE connection parameter update request.
1094 	 *
1095 	 *  This callback notifies the application that a remote device
1096 	 *  is requesting to update the connection parameters. The
1097 	 *  application accepts the parameters by returning true, or
1098 	 *  rejects them by returning false. Before accepting, the
1099 	 *  application may also adjust the parameters to better suit
1100 	 *  its needs.
1101 	 *
1102 	 *  It is recommended for an application to have just one of these
1103 	 *  callbacks for simplicity. However, if an application registers
1104 	 *  multiple it needs to manage the potentially different
1105 	 *  requirements for each callback. Each callback gets the
1106 	 *  parameters as returned by previous callbacks, i.e. they are not
1107 	 *  necessarily the same ones as the remote originally sent.
1108 	 *
1109 	 *  If the application does not have this callback then the default
1110 	 *  is to accept the parameters.
1111 	 *
1112 	 *  @param conn Connection object.
1113 	 *  @param param Proposed connection parameters.
1114 	 *
1115 	 *  @return true to accept the parameters, or false to reject them.
1116 	 */
1117 	bool (*le_param_req)(struct bt_conn *conn,
1118 			     struct bt_le_conn_param *param);
1119 
1120 	/** @brief The parameters for an LE connection have been updated.
1121 	 *
1122 	 *  This callback notifies the application that the connection
1123 	 *  parameters for an LE connection have been updated.
1124 	 *
1125 	 *  @param conn Connection object.
1126 	 *  @param interval Connection interval.
1127 	 *  @param latency Connection latency.
1128 	 *  @param timeout Connection supervision timeout.
1129 	 */
1130 	void (*le_param_updated)(struct bt_conn *conn, uint16_t interval,
1131 				 uint16_t latency, uint16_t timeout);
1132 #if defined(CONFIG_BT_SMP)
1133 	/** @brief Remote Identity Address has been resolved.
1134 	 *
1135 	 *  This callback notifies the application that a remote
1136 	 *  Identity Address has been resolved
1137 	 *
1138 	 *  @param conn Connection object.
1139 	 *  @param rpa Resolvable Private Address.
1140 	 *  @param identity Identity Address.
1141 	 */
1142 	void (*identity_resolved)(struct bt_conn *conn,
1143 				  const bt_addr_le_t *rpa,
1144 				  const bt_addr_le_t *identity);
1145 #endif /* CONFIG_BT_SMP */
1146 #if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_CLASSIC)
1147 	/** @brief The security level of a connection has changed.
1148 	 *
1149 	 *  This callback notifies the application that the security of a
1150 	 *  connection has changed.
1151 	 *
1152 	 *  The security level of the connection can either have been increased
1153 	 *  or remain unchanged. An increased security level means that the
1154 	 *  pairing procedure has been performed or the bond information from
1155 	 *  a previous connection has been applied. If the security level
1156 	 *  remains unchanged this means that the encryption key has been
1157 	 *  refreshed for the connection.
1158 	 *
1159 	 *  @param conn Connection object.
1160 	 *  @param level New security level of the connection.
1161 	 *  @param err Security error. Zero for success, non-zero otherwise.
1162 	 */
1163 	void (*security_changed)(struct bt_conn *conn, bt_security_t level,
1164 				 enum bt_security_err err);
1165 #endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_CLASSIC) */
1166 
1167 #if defined(CONFIG_BT_REMOTE_INFO)
1168 	/** @brief Remote information procedures has completed.
1169 	 *
1170 	 *  This callback notifies the application that the remote information
1171 	 *  has been retrieved from the remote peer.
1172 	 *
1173 	 *  @param conn Connection object.
1174 	 *  @param remote_info Connection information of remote device.
1175 	 */
1176 	void (*remote_info_available)(struct bt_conn *conn,
1177 				      struct bt_conn_remote_info *remote_info);
1178 #endif /* defined(CONFIG_BT_REMOTE_INFO) */
1179 
1180 #if defined(CONFIG_BT_USER_PHY_UPDATE)
1181 	/** @brief The PHY of the connection has changed.
1182 	 *
1183 	 *  This callback notifies the application that the PHY of the
1184 	 *  connection has changed.
1185 	 *
1186 	 *  @param conn Connection object.
1187 	 *  @param info Connection LE PHY information.
1188 	 */
1189 	void (*le_phy_updated)(struct bt_conn *conn,
1190 			       struct bt_conn_le_phy_info *param);
1191 #endif /* defined(CONFIG_BT_USER_PHY_UPDATE) */
1192 
1193 #if defined(CONFIG_BT_USER_DATA_LEN_UPDATE)
1194 	/** @brief The data length parameters of the connection has changed.
1195 	 *
1196 	 *  This callback notifies the application that the maximum Link Layer
1197 	 *  payload length or transmission time has changed.
1198 	 *
1199 	 *  @param conn Connection object.
1200 	 *  @param info Connection data length information.
1201 	 */
1202 	void (*le_data_len_updated)(struct bt_conn *conn,
1203 				    struct bt_conn_le_data_len_info *info);
1204 #endif /* defined(CONFIG_BT_USER_DATA_LEN_UPDATE) */
1205 
1206 #if defined(CONFIG_BT_DF_CONNECTION_CTE_RX)
1207 	/** @brief Callback for IQ samples report collected when sampling
1208 	 *        CTE received by data channel PDU.
1209 	 *
1210 	 * @param conn      The connection object.
1211 	 * @param iq_report Report data for collected IQ samples.
1212 	 */
1213 	void (*cte_report_cb)(struct bt_conn *conn,
1214 			      const struct bt_df_conn_iq_samples_report *iq_report);
1215 #endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
1216 
1217 #if defined(CONFIG_BT_TRANSMIT_POWER_CONTROL)
1218 	/** @brief LE Read Remote Transmit Power Level procedure has completed or LE
1219 	 *  Transmit Power Reporting event.
1220 	 *
1221 	 *  This callback notifies the application that either the remote transmit power level
1222 	 *  has been read from the peer or transmit power level has changed for the local or
1223 	 *  remote controller when transmit power reporting is enabled for the respective side
1224 	 *  using @ref bt_conn_le_set_tx_power_report_enable.
1225 	 *
1226 	 *  @param conn Connection object.
1227 	 *  @param report Transmit power report.
1228 	 */
1229 	void (*tx_power_report)(struct bt_conn *conn,
1230 				const struct bt_conn_le_tx_power_report *report);
1231 #endif /* CONFIG_BT_TRANSMIT_POWER_CONTROL */
1232 
1233 #if defined(CONFIG_BT_PATH_LOSS_MONITORING)
1234 	/** @brief LE Path Loss Threshold event.
1235 	 *
1236 	 *  This callback notifies the application that there has been a path loss threshold
1237 	 *  crossing or reporting the initial path loss threshold zone after using
1238 	 *  @ref bt_conn_le_set_path_loss_mon_enable.
1239 	 *
1240 	 *  @param conn Connection object.
1241 	 *  @param report Path loss threshold report.
1242 	 */
1243 	void (*path_loss_threshold_report)(struct bt_conn *conn,
1244 				const struct bt_conn_le_path_loss_threshold_report *report);
1245 #endif /* CONFIG_BT_PATH_LOSS_MONITORING */
1246 
1247 	/** @internal Internally used field for list handling */
1248 	sys_snode_t _node;
1249 };
1250 
1251 /** @brief Register connection callbacks.
1252  *
1253  *  Register callbacks to monitor the state of connections.
1254  *
1255  *  @param cb Callback struct. Must point to memory that remains valid.
1256  *
1257  * @retval 0 Success.
1258  * @retval -EEXIST if @p cb was already registered.
1259  */
1260 int bt_conn_cb_register(struct bt_conn_cb *cb);
1261 
1262 /**
1263  * @brief Unregister connection callbacks.
1264  *
1265  * Unregister the state of connections callbacks.
1266  *
1267  * @param cb Callback struct point to memory that remains valid.
1268  *
1269  * @retval 0 Success
1270  * @retval -EINVAL If @p cb is NULL
1271  * @retval -ENOENT if @p cb was not registered
1272  */
1273 int bt_conn_cb_unregister(struct bt_conn_cb *cb);
1274 
1275 /**
1276  *  @brief Register a callback structure for connection events.
1277  *
1278  *  @param _name Name of callback structure.
1279  */
1280 #define BT_CONN_CB_DEFINE(_name)					\
1281 	static const STRUCT_SECTION_ITERABLE(bt_conn_cb,		\
1282 						_CONCAT(bt_conn_cb_,	\
1283 							_name))
1284 
1285 /** Converts a security error to string.
1286  *
1287  * @return The string representation of the security error code.
1288  *         If @kconfig{CONFIG_BT_SECURITY_ERR_TO_STR} is not enabled,
1289  *         this just returns the empty string
1290  */
1291 #if defined(CONFIG_BT_SECURITY_ERR_TO_STR)
1292 const char *bt_security_err_to_str(enum bt_security_err err);
1293 #else
bt_security_err_to_str(enum bt_security_err err)1294 static inline const char *bt_security_err_to_str(enum bt_security_err err)
1295 {
1296 	ARG_UNUSED(err);
1297 
1298 	return "";
1299 }
1300 #endif
1301 
1302 /** @brief Enable/disable bonding.
1303  *
1304  *  Set/clear the Bonding flag in the Authentication Requirements of
1305  *  SMP Pairing Request/Response data.
1306  *  The initial value of this flag depends on BT_BONDABLE Kconfig setting.
1307  *  For the vast majority of applications calling this function shouldn't be
1308  *  needed.
1309  *
1310  *  @param enable Value allowing/disallowing to be bondable.
1311  */
1312 void bt_set_bondable(bool enable);
1313 
1314 /** @brief Set/clear the bonding flag for a given connection.
1315  *
1316  *  Set/clear the Bonding flag in the Authentication Requirements of
1317  *  SMP Pairing Request/Response data for a given connection.
1318  *
1319  *  The bonding flag for a given connection cannot be set/cleared if
1320  *  security procedures in the SMP module have already started.
1321  *  This function can be called only once per connection.
1322  *
1323  *  If the bonding flag is not set/cleared for a given connection,
1324  *  the value will depend on global configuration which is set using
1325  *  bt_set_bondable.
1326  *  The default value of the global configuration is defined using
1327  *  CONFIG_BT_BONDABLE Kconfig option.
1328  *
1329  *  @param conn Connection object.
1330  *  @param enable Value allowing/disallowing to be bondable.
1331  */
1332 int bt_conn_set_bondable(struct bt_conn *conn, bool enable);
1333 
1334 /** @brief Allow/disallow remote LE SC OOB data to be used for pairing.
1335  *
1336  *  Set/clear the OOB data flag for LE SC SMP Pairing Request/Response data.
1337  *
1338  *  @param enable Value allowing/disallowing remote LE SC OOB data.
1339  */
1340 void bt_le_oob_set_sc_flag(bool enable);
1341 
1342 /** @brief Allow/disallow remote legacy OOB data to be used for pairing.
1343  *
1344  *  Set/clear the OOB data flag for legacy SMP Pairing Request/Response data.
1345  *
1346  *  @param enable Value allowing/disallowing remote legacy OOB data.
1347  */
1348 void bt_le_oob_set_legacy_flag(bool enable);
1349 
1350 /** @brief Set OOB Temporary Key to be used for pairing
1351  *
1352  *  This function allows to set OOB data for the LE legacy pairing procedure.
1353  *  The function should only be called in response to the oob_data_request()
1354  *  callback provided that the legacy method is user pairing.
1355  *
1356  *  @param conn Connection object
1357  *  @param tk Pointer to 16 byte long TK array
1358  *
1359  *  @return Zero on success or -EINVAL if NULL
1360  */
1361 int bt_le_oob_set_legacy_tk(struct bt_conn *conn, const uint8_t *tk);
1362 
1363 /** @brief Set OOB data during LE Secure Connections (SC) pairing procedure
1364  *
1365  *  This function allows to set OOB data during the LE SC pairing procedure.
1366  *  The function should only be called in response to the oob_data_request()
1367  *  callback provided that LE SC method is used for pairing.
1368  *
1369  *  The user should submit OOB data according to the information received in the
1370  *  callback. This may yield three different configurations: with only local OOB
1371  *  data present, with only remote OOB data present or with both local and
1372  *  remote OOB data present.
1373  *
1374  *  @param conn Connection object
1375  *  @param oobd_local Local OOB data or NULL if not present
1376  *  @param oobd_remote Remote OOB data or NULL if not present
1377  *
1378  *  @return Zero on success or error code otherwise, positive in case of
1379  *          protocol error or negative (POSIX) in case of stack internal error.
1380  */
1381 int bt_le_oob_set_sc_data(struct bt_conn *conn,
1382 			  const struct bt_le_oob_sc_data *oobd_local,
1383 			  const struct bt_le_oob_sc_data *oobd_remote);
1384 
1385 /** @brief Get OOB data used for LE Secure Connections (SC) pairing procedure
1386  *
1387  *  This function allows to get OOB data during the LE SC pairing procedure that
1388  *  were set by the bt_le_oob_set_sc_data() API.
1389  *
1390  *  @note The OOB data will only be available as long as the connection object
1391  *  associated with it is valid.
1392  *
1393  *  @param conn Connection object
1394  *  @param oobd_local Local OOB data or NULL if not set
1395  *  @param oobd_remote Remote OOB data or NULL if not set
1396  *
1397  *  @return Zero on success or error code otherwise, positive in case of
1398  *          protocol error or negative (POSIX) in case of stack internal error.
1399  */
1400 int bt_le_oob_get_sc_data(struct bt_conn *conn,
1401 			  const struct bt_le_oob_sc_data **oobd_local,
1402 			  const struct bt_le_oob_sc_data **oobd_remote);
1403 
1404 /**
1405  *  Special passkey value that can be used to disable a previously
1406  *  set fixed passkey.
1407  */
1408 #define BT_PASSKEY_INVALID 0xffffffff
1409 
1410 /** @brief Set a fixed passkey to be used for pairing.
1411  *
1412  *  This API is only available when the CONFIG_BT_FIXED_PASSKEY
1413  *  configuration option has been enabled.
1414  *
1415  *  Sets a fixed passkey to be used for pairing. If set, the
1416  *  pairing_confirm() callback will be called for all incoming pairings.
1417  *
1418  *  @param passkey A valid passkey (0 - 999999) or BT_PASSKEY_INVALID
1419  *                 to disable a previously set fixed passkey.
1420  *
1421  *  @return 0 on success or a negative error code on failure.
1422  */
1423 int bt_passkey_set(unsigned int passkey);
1424 
1425 /** Info Structure for OOB pairing */
1426 struct bt_conn_oob_info {
1427 	/** Type of OOB pairing method */
1428 	enum {
1429 		/** LE legacy pairing */
1430 		BT_CONN_OOB_LE_LEGACY,
1431 
1432 		/** LE SC pairing */
1433 		BT_CONN_OOB_LE_SC,
1434 	} type;
1435 
1436 	union {
1437 		/** LE Secure Connections OOB pairing parameters */
1438 		struct {
1439 			/** OOB data configuration */
1440 			enum {
1441 				/** Local OOB data requested */
1442 				BT_CONN_OOB_LOCAL_ONLY,
1443 
1444 				/** Remote OOB data requested */
1445 				BT_CONN_OOB_REMOTE_ONLY,
1446 
1447 				/** Both local and remote OOB data requested */
1448 				BT_CONN_OOB_BOTH_PEERS,
1449 
1450 				/** No OOB data requested */
1451 				BT_CONN_OOB_NO_DATA,
1452 			} oob_config;
1453 		} lesc;
1454 	};
1455 };
1456 
1457 #if defined(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)
1458 /** @brief Pairing request and pairing response info structure.
1459  *
1460  *  This structure is the same for both smp_pairing_req and smp_pairing_rsp
1461  *  and a subset of the packet data, except for the initial Code octet.
1462  *  It is documented in Core Spec. Vol. 3, Part H, 3.5.1 and 3.5.2.
1463  */
1464 struct bt_conn_pairing_feat {
1465 	/** IO Capability, Core Spec. Vol 3, Part H, 3.5.1, Table 3.4 */
1466 	uint8_t io_capability;
1467 
1468 	/** OOB data flag, Core Spec. Vol 3, Part H, 3.5.1, Table 3.5 */
1469 	uint8_t oob_data_flag;
1470 
1471 	/** AuthReq, Core Spec. Vol 3, Part H, 3.5.1, Fig. 3.3 */
1472 	uint8_t auth_req;
1473 
1474 	/** Maximum Encryption Key Size, Core Spec. Vol 3, Part H, 3.5.1 */
1475 	uint8_t max_enc_key_size;
1476 
1477 	/** Initiator Key Distribution/Generation, Core Spec. Vol 3, Part H,
1478 	 *  3.6.1, Fig. 3.11
1479 	 */
1480 	uint8_t init_key_dist;
1481 
1482 	/** Responder Key Distribution/Generation, Core Spec. Vol 3, Part H
1483 	 *  3.6.1, Fig. 3.11
1484 	 */
1485 	uint8_t resp_key_dist;
1486 };
1487 #endif /* CONFIG_BT_SMP_APP_PAIRING_ACCEPT */
1488 
1489 /** Authenticated pairing callback structure */
1490 struct bt_conn_auth_cb {
1491 #if defined(CONFIG_BT_SMP_APP_PAIRING_ACCEPT)
1492 	/** @brief Query to proceed incoming pairing or not.
1493 	 *
1494 	 *  On any incoming pairing req/rsp this callback will be called for
1495 	 *  the application to decide whether to allow for the pairing to
1496 	 *  continue.
1497 	 *
1498 	 *  The pairing info received from the peer is passed to assist
1499 	 *  making the decision.
1500 	 *
1501 	 *  As this callback is synchronous the application should return
1502 	 *  a response value immediately. Otherwise it may affect the
1503 	 *  timing during pairing. Hence, this information should not be
1504 	 *  conveyed to the user to take action.
1505 	 *
1506 	 *  The remaining callbacks are not affected by this, but do notice
1507 	 *  that other callbacks can be called during the pairing. Eg. if
1508 	 *  pairing_confirm is registered both will be called for Just-Works
1509 	 *  pairings.
1510 	 *
1511 	 *  This callback may be unregistered in which case pairing continues
1512 	 *  as if the Kconfig flag was not set.
1513 	 *
1514 	 *  This callback is not called for BR/EDR Secure Simple Pairing (SSP).
1515 	 *
1516 	 *  @param conn Connection where pairing is initiated.
1517 	 *  @param feat Pairing req/resp info.
1518 	 */
1519 	enum bt_security_err (*pairing_accept)(struct bt_conn *conn,
1520 			      const struct bt_conn_pairing_feat *const feat);
1521 #endif /* CONFIG_BT_SMP_APP_PAIRING_ACCEPT */
1522 
1523 	/** @brief Display a passkey to the user.
1524 	 *
1525 	 *  When called the application is expected to display the given
1526 	 *  passkey to the user, with the expectation that the passkey will
1527 	 *  then be entered on the peer device. The passkey will be in the
1528 	 *  range of 0 - 999999, and is expected to be padded with zeroes so
1529 	 *  that six digits are always shown. E.g. the value 37 should be
1530 	 *  shown as 000037.
1531 	 *
1532 	 *  This callback may be set to NULL, which means that the local
1533 	 *  device lacks the ability do display a passkey. If set
1534 	 *  to non-NULL the cancel callback must also be provided, since
1535 	 *  this is the only way the application can find out that it should
1536 	 *  stop displaying the passkey.
1537 	 *
1538 	 *  @param conn Connection where pairing is currently active.
1539 	 *  @param passkey Passkey to show to the user.
1540 	 */
1541 	void (*passkey_display)(struct bt_conn *conn, unsigned int passkey);
1542 
1543 #if defined(CONFIG_BT_PASSKEY_KEYPRESS)
1544 	/** @brief Receive Passkey Keypress Notification during pairing
1545 	 *
1546 	 *  This allows the remote device to use the local device to give users
1547 	 *  feedback on the progress of entering the passkey over there. This is
1548 	 *  useful when the remote device itself has no display suitable for
1549 	 *  showing the progress.
1550 	 *
1551 	 *  The handler of this callback is expected to keep track of the number
1552 	 *  of digits entered and show a password-field-like feedback to the
1553 	 *  user.
1554 	 *
1555 	 *  This callback is only relevant while the local side does Passkey
1556 	 *  Display.
1557 	 *
1558 	 *  The event type is verified to be in range of the enum. No other
1559 	 *  sanitization has been done. The remote could send a large number of
1560 	 *  events of any type in any order.
1561 	 *
1562 	 *  @param conn The related connection.
1563 	 *  @param type Type of event. Verified in range of the enum.
1564 	 */
1565 	void (*passkey_display_keypress)(struct bt_conn *conn,
1566 					 enum bt_conn_auth_keypress type);
1567 #endif
1568 
1569 	/** @brief Request the user to enter a passkey.
1570 	 *
1571 	 *  When called the user is expected to enter a passkey. The passkey
1572 	 *  must be in the range of 0 - 999999, and should be expected to
1573 	 *  be zero-padded, as that's how the peer device will typically be
1574 	 *  showing it (e.g. 37 would be shown as 000037).
1575 	 *
1576 	 *  Once the user has entered the passkey its value should be given
1577 	 *  to the stack using the bt_conn_auth_passkey_entry() API.
1578 	 *
1579 	 *  This callback may be set to NULL, which means that the local
1580 	 *  device lacks the ability to enter a passkey. If set to non-NULL
1581 	 *  the cancel callback must also be provided, since this is the
1582 	 *  only way the application can find out that it should stop
1583 	 *  requesting the user to enter a passkey.
1584 	 *
1585 	 *  @param conn Connection where pairing is currently active.
1586 	 */
1587 	void (*passkey_entry)(struct bt_conn *conn);
1588 
1589 	/** @brief Request the user to confirm a passkey.
1590 	 *
1591 	 *  When called the user is expected to confirm that the given
1592 	 *  passkey is also shown on the peer device.. The passkey will
1593 	 *  be in the range of 0 - 999999, and should be zero-padded to
1594 	 *  always be six digits (e.g. 37 would be shown as 000037).
1595 	 *
1596 	 *  Once the user has confirmed the passkey to match, the
1597 	 *  bt_conn_auth_passkey_confirm() API should be called. If the
1598 	 *  user concluded that the passkey doesn't match the
1599 	 *  bt_conn_auth_cancel() API should be called.
1600 	 *
1601 	 *  This callback may be set to NULL, which means that the local
1602 	 *  device lacks the ability to confirm a passkey. If set to non-NULL
1603 	 *  the cancel callback must also be provided, since this is the
1604 	 *  only way the application can find out that it should stop
1605 	 *  requesting the user to confirm a passkey.
1606 	 *
1607 	 *  @param conn Connection where pairing is currently active.
1608 	 *  @param passkey Passkey to be confirmed.
1609 	 */
1610 	void (*passkey_confirm)(struct bt_conn *conn, unsigned int passkey);
1611 
1612 	/** @brief Request the user to provide Out of Band (OOB) data.
1613 	 *
1614 	 *  When called the user is expected to provide OOB data. The required
1615 	 *  data are indicated by the information structure.
1616 	 *
1617 	 *  For LE Secure Connections OOB pairing, the user should provide
1618 	 *  local OOB data, remote OOB data or both depending on their
1619 	 *  availability. Their value should be given to the stack using the
1620 	 *  bt_le_oob_set_sc_data() API.
1621 	 *
1622 	 *  This callback must be set to non-NULL in order to support OOB
1623 	 *  pairing.
1624 	 *
1625 	 *  @param conn Connection where pairing is currently active.
1626 	 *  @param info OOB pairing information.
1627 	 */
1628 	void (*oob_data_request)(struct bt_conn *conn,
1629 				 struct bt_conn_oob_info *info);
1630 
1631 	/** @brief Cancel the ongoing user request.
1632 	 *
1633 	 *  This callback will be called to notify the application that it
1634 	 *  should cancel any previous user request (passkey display, entry
1635 	 *  or confirmation).
1636 	 *
1637 	 *  This may be set to NULL, but must always be provided whenever the
1638 	 *  passkey_display, passkey_entry passkey_confirm or pairing_confirm
1639 	 *  callback has been provided.
1640 	 *
1641 	 *  @param conn Connection where pairing is currently active.
1642 	 */
1643 	void (*cancel)(struct bt_conn *conn);
1644 
1645 	/** @brief Request confirmation for an incoming pairing.
1646 	 *
1647 	 *  This callback will be called to confirm an incoming pairing
1648 	 *  request where none of the other user callbacks is applicable.
1649 	 *
1650 	 *  If the user decides to accept the pairing the
1651 	 *  bt_conn_auth_pairing_confirm() API should be called. If the
1652 	 *  user decides to reject the pairing the bt_conn_auth_cancel() API
1653 	 *  should be called.
1654 	 *
1655 	 *  This callback may be set to NULL, which means that the local
1656 	 *  device lacks the ability to confirm a pairing request. If set
1657 	 *  to non-NULL the cancel callback must also be provided, since
1658 	 *  this is the only way the application can find out that it should
1659 	 *  stop requesting the user to confirm a pairing request.
1660 	 *
1661 	 *  @param conn Connection where pairing is currently active.
1662 	 */
1663 	void (*pairing_confirm)(struct bt_conn *conn);
1664 
1665 #if defined(CONFIG_BT_CLASSIC)
1666 	/** @brief Request the user to enter a passkey.
1667 	 *
1668 	 *  This callback will be called for a BR/EDR (Bluetooth Classic)
1669 	 *  connection where pairing is being performed. Once called the
1670 	 *  user is expected to enter a PIN code with a length between
1671 	 *  1 and 16 digits. If the @a highsec parameter is set to true
1672 	 *  the PIN code must be 16 digits long.
1673 	 *
1674 	 *  Once entered, the PIN code should be given to the stack using
1675 	 *  the bt_conn_auth_pincode_entry() API.
1676 	 *
1677 	 *  This callback may be set to NULL, however in that case pairing
1678 	 *  over BR/EDR will not be possible. If provided, the cancel
1679 	 *  callback must be provided as well.
1680 	 *
1681 	 *  @param conn Connection where pairing is currently active.
1682 	 *  @param highsec true if 16 digit PIN is required.
1683 	 */
1684 	void (*pincode_entry)(struct bt_conn *conn, bool highsec);
1685 #endif
1686 };
1687 
1688 /** Authenticated pairing information callback structure */
1689 struct bt_conn_auth_info_cb {
1690 	/** @brief notify that pairing procedure was complete.
1691 	 *
1692 	 *  This callback notifies the application that the pairing procedure
1693 	 *  has been completed.
1694 	 *
1695 	 *  @param conn Connection object.
1696 	 *  @param bonded Bond information has been distributed during the
1697 	 *                pairing procedure.
1698 	 */
1699 	void (*pairing_complete)(struct bt_conn *conn, bool bonded);
1700 
1701 	/** @brief notify that pairing process has failed.
1702 	 *
1703 	 *  @param conn Connection object.
1704 	 *  @param reason Pairing failed reason
1705 	 */
1706 	void (*pairing_failed)(struct bt_conn *conn,
1707 			       enum bt_security_err reason);
1708 
1709 	/** @brief Notify that bond has been deleted.
1710 	 *
1711 	 *  This callback notifies the application that the bond information
1712 	 *  for the remote peer has been deleted
1713 	 *
1714 	 *  @param id   Which local identity had the bond.
1715 	 *  @param peer Remote address.
1716 	 */
1717 	void (*bond_deleted)(uint8_t id, const bt_addr_le_t *peer);
1718 
1719 	/** Internally used field for list handling */
1720 	sys_snode_t node;
1721 };
1722 
1723 /** @brief Register authentication callbacks.
1724  *
1725  *  Register callbacks to handle authenticated pairing. Passing NULL
1726  *  unregisters a previous callbacks structure.
1727  *
1728  *  @param cb Callback struct.
1729  *
1730  *  @return Zero on success or negative error code otherwise
1731  */
1732 int bt_conn_auth_cb_register(const struct bt_conn_auth_cb *cb);
1733 
1734 /** @brief Overlay authentication callbacks used for a given connection.
1735  *
1736  *  This function can be used only for Bluetooth LE connections.
1737  *  The @kconfig{CONFIG_BT_SMP} must be enabled for this function.
1738  *
1739  *  The authentication callbacks for a given connection cannot be overlaid if
1740  *  security procedures in the SMP module have already started. This function
1741  *  can be called only once per connection.
1742  *
1743  *  @param conn	Connection object.
1744  *  @param cb	Callback struct.
1745  *
1746  *  @return Zero on success or negative error code otherwise
1747  */
1748 int bt_conn_auth_cb_overlay(struct bt_conn *conn, const struct bt_conn_auth_cb *cb);
1749 
1750 /** @brief Register authentication information callbacks.
1751  *
1752  *  Register callbacks to get authenticated pairing information. Multiple
1753  *  registrations can be done.
1754  *
1755  *  @param cb Callback struct.
1756  *
1757  *  @return Zero on success or negative error code otherwise
1758  */
1759 int bt_conn_auth_info_cb_register(struct bt_conn_auth_info_cb *cb);
1760 
1761 /** @brief Unregister authentication information callbacks.
1762  *
1763  *  Unregister callbacks to stop getting authenticated pairing information.
1764  *
1765  *  @param cb Callback struct.
1766  *
1767  *  @return Zero on success or negative error code otherwise
1768  */
1769 int bt_conn_auth_info_cb_unregister(struct bt_conn_auth_info_cb *cb);
1770 
1771 /** @brief Reply with entered passkey.
1772  *
1773  *  This function should be called only after passkey_entry callback from
1774  *  bt_conn_auth_cb structure was called.
1775  *
1776  *  @param conn Connection object.
1777  *  @param passkey Entered passkey.
1778  *
1779  *  @return Zero on success or negative error code otherwise
1780  */
1781 int bt_conn_auth_passkey_entry(struct bt_conn *conn, unsigned int passkey);
1782 
1783 /** @brief Send Passkey Keypress Notification during pairing
1784  *
1785  *  This function may be called only after passkey_entry callback from
1786  *  bt_conn_auth_cb structure was called.
1787  *
1788  *  Requires @kconfig{CONFIG_BT_PASSKEY_KEYPRESS}.
1789  *
1790  *  @param conn Destination for the notification.
1791  *  @param type What keypress event type to send. @see bt_conn_auth_keypress.
1792  *
1793  *  @retval 0 Success
1794  *  @retval -EINVAL Improper use of the API.
1795  *  @retval -ENOMEM Failed to allocate.
1796  *  @retval -ENOBUFS Failed to allocate.
1797  */
1798 int bt_conn_auth_keypress_notify(struct bt_conn *conn, enum bt_conn_auth_keypress type);
1799 
1800 /** @brief Cancel ongoing authenticated pairing.
1801  *
1802  *  This function allows to cancel ongoing authenticated pairing.
1803  *
1804  *  @param conn Connection object.
1805  *
1806  *  @return Zero on success or negative error code otherwise
1807  */
1808 int bt_conn_auth_cancel(struct bt_conn *conn);
1809 
1810 /** @brief Reply if passkey was confirmed to match by user.
1811  *
1812  *  This function should be called only after passkey_confirm callback from
1813  *  bt_conn_auth_cb structure was called.
1814  *
1815  *  @param conn Connection object.
1816  *
1817  *  @return Zero on success or negative error code otherwise
1818  */
1819 int bt_conn_auth_passkey_confirm(struct bt_conn *conn);
1820 
1821 /** @brief Reply if incoming pairing was confirmed by user.
1822  *
1823  *  This function should be called only after pairing_confirm callback from
1824  *  bt_conn_auth_cb structure was called if user confirmed incoming pairing.
1825  *
1826  *  @param conn Connection object.
1827  *
1828  *  @return Zero on success or negative error code otherwise
1829  */
1830 int bt_conn_auth_pairing_confirm(struct bt_conn *conn);
1831 
1832 /** @brief Reply with entered PIN code.
1833  *
1834  *  This function should be called only after PIN code callback from
1835  *  bt_conn_auth_cb structure was called. It's for legacy 2.0 devices.
1836  *
1837  *  @param conn Connection object.
1838  *  @param pin Entered PIN code.
1839  *
1840  *  @return Zero on success or negative error code otherwise
1841  */
1842 int bt_conn_auth_pincode_entry(struct bt_conn *conn, const char *pin);
1843 
1844 /** Connection parameters for BR/EDR connections */
1845 struct bt_br_conn_param {
1846 	bool allow_role_switch;
1847 };
1848 
1849 /** @brief Initialize BR/EDR connection parameters
1850  *
1851  *  @param role_switch True if role switch is allowed
1852  */
1853 #define BT_BR_CONN_PARAM_INIT(role_switch) \
1854 { \
1855 	.allow_role_switch = (role_switch), \
1856 }
1857 
1858 /** Helper to declare BR/EDR connection parameters inline
1859   *
1860   * @param role_switch True if role switch is allowed
1861   */
1862 #define BT_BR_CONN_PARAM(role_switch) \
1863 	((struct bt_br_conn_param[]) { \
1864 		BT_BR_CONN_PARAM_INIT(role_switch) \
1865 	 })
1866 
1867 /** Default BR/EDR connection parameters:
1868  *    Role switch allowed
1869  */
1870 #define BT_BR_CONN_PARAM_DEFAULT BT_BR_CONN_PARAM(true)
1871 
1872 
1873 /** @brief Initiate an BR/EDR connection to a remote device.
1874  *
1875  *  Allows initiate new BR/EDR link to remote peer using its address.
1876  *
1877  *  The caller gets a new reference to the connection object which must be
1878  *  released with bt_conn_unref() once done using the object.
1879  *
1880  *  @param peer  Remote address.
1881  *  @param param Initial connection parameters.
1882  *
1883  *  @return Valid connection object on success or NULL otherwise.
1884  */
1885 struct bt_conn *bt_conn_create_br(const bt_addr_t *peer,
1886 				  const struct bt_br_conn_param *param);
1887 
1888 #ifdef __cplusplus
1889 }
1890 #endif
1891 
1892 /**
1893  * @}
1894  */
1895 
1896 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_CONN_H_ */
1897