Bluetooth: Add bt_conn_get_info

Change-Id: I32fd5b1c159623c59a353e1084f47f3cc9f704e6
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2015-11-27 15:00:52 +02:00 committed by Anas Nashif
commit c05ea4c21c
3 changed files with 64 additions and 8 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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;