diff --git a/include/bluetooth/conn.h b/include/bluetooth/conn.h index 65f196e513c..eb60c905ffb 100644 --- a/include/bluetooth/conn.h +++ b/include/bluetooth/conn.h @@ -66,6 +66,47 @@ struct bt_conn *bt_conn_lookup_addr_le(const bt_addr_le_t *peer); */ const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn); +/** Connection Type */ +enum { + BT_CONN_TYPE_LE, /** LE Connection Type */ +#if defined(CONFIG_BLUETOOTH_BREDR) + BT_CONN_TYPE_BREDR, /** BR/EDR Connection Type */ +#endif +}; + +/** LE Connection Info Structure */ +struct bt_conn_le_info { + const bt_addr_le_t *src; /** Source Address */ + const bt_addr_le_t *dst; /** Destination Address */ +}; + +#if defined(CONFIG_BLUETOOTH_BREDR) +/** BR/EDR Connection Info Structure */ +struct bt_conn_br_info; +#endif + +/** Connection Info Structure */ +struct bt_conn_info { + /** Connection Type */ + uint8_t type; + union { + /** LE Connection specific Info */ + struct bt_conn_le_info le; +#if defined(CONFIG_BLUETOOTH_BREDR) + struct bt_conn_br_info br; +#endif + }; +}; + +/** @brief Get connection info + * + * @param conn Connection object. + * @param info Connection info object. + * + * @return Zero on success or (negative) error code on failure. + */ +int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info); + /** @brief Disconnect from a remote device or cancel pending connection. * * Disconnect an active connection with the specified reason code or cancel diff --git a/net/bluetooth/conn.c b/net/bluetooth/conn.c index ebc7a1a36a6..a844d81bfe9 100644 --- a/net/bluetooth/conn.c +++ b/net/bluetooth/conn.c @@ -726,6 +726,29 @@ const bt_addr_le_t *bt_conn_get_dst(const struct bt_conn *conn) return &conn->le.dst; } +int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info) +{ + if (conn->state != BT_CONN_CONNECTED) { + return -ENOTCONN; + } + + info->type = conn->type; + + switch (conn->type) { + case BT_CONN_TYPE_LE: + if (conn->role == BT_HCI_ROLE_MASTER) { + info->le.src = &conn->le.init_addr; + info->le.dst = &conn->le.resp_addr; + } else { + info->le.src = &conn->le.resp_addr; + info->le.dst = &conn->le.init_addr; + } + return 0; + } + + return -EINVAL; +} + void bt_conn_set_auto_conn(struct bt_conn *conn, bool auto_conn) { if (auto_conn) { diff --git a/net/bluetooth/conn_internal.h b/net/bluetooth/conn_internal.h index f23568b7a0a..9b2de39b7f9 100644 --- a/net/bluetooth/conn_internal.h +++ b/net/bluetooth/conn_internal.h @@ -32,14 +32,6 @@ enum { }; -enum { - BT_CONN_TYPE_LE, -#if defined(CONFIG_BLUETOOTH_BREDR) - BT_CONN_TYPE_BREDR, -#endif -}; - - struct bt_conn_le { bt_addr_le_t dst;