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