From cf288f1ce3f6743cf0c4b38c25fe920320140090 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 11 Nov 2015 11:51:17 +0100 Subject: [PATCH] add gap_get_connection_type --- src/gap.h | 14 ++++++++++++++ src/hci.c | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/gap.h b/src/gap.h index 3da8a0c8c..8f70d0eee 100644 --- a/src/gap.h +++ b/src/gap.h @@ -77,6 +77,13 @@ typedef enum { // GAP_SECURITY_AUTHORIZED } gap_security_state; +typedef enum { + GAP_CONNECTION_INVALID, + GAP_CONNECTION_ACL, + GAP_CONNECTION_SCO, + GAP_CONNECTION_LE +} gap_connection_type_t; + /* API_START */ /** @@ -114,6 +121,13 @@ int gap_mitm_protection_required_for_security_level(gap_security_level_t level) void gap_set_local_name(const char * local_name); /* API_END*/ +/** + * @brief Get connection type + * @param con_handle + * @result connection_type + */ +gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle); + #if defined __cplusplus } #endif diff --git a/src/hci.c b/src/hci.c index 0f153ede8..aaa0337f0 100644 --- a/src/hci.c +++ b/src/hci.c @@ -3217,6 +3217,27 @@ le_command_status_t gap_disconnect(hci_con_handle_t handle){ return BLE_PERIPHERAL_OK; } +/** + * @brief Get connection type + * @param con_handle + * @result connection_type + */ +gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle){ + hci_connection_t * conn = hci_connection_for_handle(connection_handle); + if (!conn) return GAP_CONNECTION_INVALID; + switch (conn->address_type){ + case BD_ADDR_TYPE_LE_PUBLIC: + case BD_ADDR_TYPE_LE_RANDOM: + return GAP_CONNECTION_LE; + case BD_ADDR_TYPE_SCO: + return GAP_CONNECTION_SCO; + case BD_ADDR_TYPE_CLASSIC: + return GAP_CONNECTION_ACL; + default: + return GAP_CONNECTION_INVALID; + } +} + #ifdef HAVE_BLE /**