From 0f06c7d8e4626c6793c2a9f34d17113ba9cb4ec4 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 15 Oct 2019 17:47:26 +0200 Subject: [PATCH] Bluetooth: HCI: Add function to get connection handle of connection Add public API function to get the connection handle of the connection. The connection handle is needed by applications that intend to send vendor specific commands for a given connection. Signed-off-by: Joakim Andersson --- include/bluetooth/hci.h | 10 ++++++++++ subsys/bluetooth/host/hci_core.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/bluetooth/hci.h b/include/bluetooth/hci.h index 47b96405f98..c5532f944b1 100644 --- a/include/bluetooth/hci.h +++ b/include/bluetooth/hci.h @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -1768,6 +1769,15 @@ int bt_hci_cmd_send(u16_t opcode, struct net_buf *buf); int bt_hci_cmd_send_sync(u16_t opcode, struct net_buf *buf, struct net_buf **rsp); +/** @brief Get connection handle for a connection. + * + * @param conn Connection object. + * @param conn_handle Place to store the Connection handle. + * + * @return 0 on success or negative error value on failure. + */ +int bt_hci_get_conn_handle(const struct bt_conn *conn, u16_t *conn_handle); + /** @typedef bt_hci_vnd_evt_cb_t * @brief Callback type for vendor handling of HCI Vendor-Specific Events. * diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index f816534ffa6..a13aec2ba0f 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3607,6 +3607,16 @@ static void le_adv_report(struct net_buf *buf) } #endif /* CONFIG_BT_OBSERVER */ +int bt_hci_get_conn_handle(const struct bt_conn *conn, u16_t *conn_handle) +{ + if (conn->state != BT_CONN_CONNECTED) { + return -ENOTCONN; + } + + *conn_handle = conn->handle; + return 0; +} + #if defined(CONFIG_BT_HCI_VS_EVT_USER) int bt_hci_register_vnd_evt_cb(bt_hci_vnd_evt_cb_t cb) {