From 2dceb1d6118d6fab7a20ac5f44c01164f505746b Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 30 Jul 2020 12:14:32 +0200 Subject: [PATCH] gap: provide gap_get_role to query master/slave role for HCI connection handle --- CHANGELOG.md | 3 ++- src/bluetooth.h | 7 +++++-- src/gap.h | 7 +++++++ src/hci.c | 8 ++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad61b1d6a..9902c1ad2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Windows port for Dialog DA14585 connected via serial port - AVRCP: introduced AVRCP_FEATURE_MASK_* as alternative to avrcp_controller_supported_feature_t and avrcp_target_supported_feature_t enums - AVDTP: renamed definition of supported features from AVDTP_SOURCE_SF_ and AVDTP_SINK_SF_ to AVDTP_SOURCE_FEATURE_MASK_ and AVDTP_SINK_FEATURE_MASK_ respectively. - +- GAP: Provide gap_get_role to query master/slave role for HCI connection handle + ### Changed - CVSD PLC: treat zero frames as good and allow to mark data as bad, e.g. if reported by controller as erroneous - btstack_audio: add set_volume() to sink and set_gain() to source interfaces diff --git a/src/bluetooth.h b/src/bluetooth.h index 02b7d09ec..044c0ef55 100644 --- a/src/bluetooth.h +++ b/src/bluetooth.h @@ -299,8 +299,11 @@ typedef enum { /* ENUM_END */ // HCI roles -#define HCI_ROLE_MASTER 0 -#define HCI_ROLE_SLAVE 1 +typedef enum { + HCI_ROLE_MASTER = 0, + HCI_ROLE_SLAVE = 1, + HCI_ROLE_INVALID = 0xff, +} hci_role_t; // packet sizes (max payload) #define HCI_ACL_DM1_SIZE 17 diff --git a/src/gap.h b/src/gap.h index 2d5287c23..8c3e2848a 100644 --- a/src/gap.h +++ b/src/gap.h @@ -130,6 +130,13 @@ uint8_t gap_disconnect(hci_con_handle_t handle); */ gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle); +/** + * @brief Get HCI connection role + * @param con_handle + * @result hci_role_t HCI_ROLE_MASTER / HCI_ROLE_SLAVE / HCI_ROLE_INVALID (if connection does not exist) + */ +hci_role_t gap_get_role(hci_con_handle_t connection_handle); + // Classic /** diff --git a/src/hci.c b/src/hci.c index 5d7eb4470..177c51b97 100644 --- a/src/hci.c +++ b/src/hci.c @@ -194,6 +194,7 @@ static hci_connection_t * create_connection_for_bd_addr_and_type(bd_addr_t addr, hci_connection_t * conn = btstack_memory_hci_connection_get(); if (!conn) return NULL; bd_addr_copy(conn->address, addr); + conn->role = HCI_ROLE_INVALID; conn->address_type = addr_type; conn->con_handle = 0xffff; conn->authentication_flags = AUTH_FLAGS_NONE; @@ -5167,6 +5168,13 @@ gap_connection_type_t gap_get_connection_type(hci_con_handle_t connection_handle } } +hci_role_t gap_get_role(hci_con_handle_t connection_handle){ + hci_connection_t * conn = hci_connection_for_handle(connection_handle); + if (!conn) return HCI_ROLE_INVALID; + return (hci_role_t) conn->role; +} + + #ifdef ENABLE_BLE uint8_t gap_le_set_phy(hci_con_handle_t connection_handle, uint8_t all_phys, uint8_t tx_phys, uint8_t rx_phys, uint8_t phy_options){