From c9db5c2133d891c164367ece1d22a06afc659df5 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Mon, 12 Nov 2018 15:00:10 +0100 Subject: [PATCH] hci/gap: save the le connection interval on connection complete and connection update --- src/gap.h | 6 ++++++ src/hci.c | 21 +++++++++++++++++---- src/hci.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/gap.h b/src/gap.h index eefbcbc20..bfa28a460 100644 --- a/src/gap.h +++ b/src/gap.h @@ -396,6 +396,12 @@ int gap_auto_connection_stop(bd_addr_type_t address_typ, bd_addr_t address); */ void gap_auto_connection_stop_all(void); +/** + * @brief Get connection interval + * @return connection interval, otherwise 0 if error + */ +uint16_t gap_le_connection_interval(hci_con_handle_t connection_handle); + /** * * @brief Get encryption key size. diff --git a/src/hci.c b/src/hci.c index 325367b6f..e5751f17f 100644 --- a/src/hci.c +++ b/src/hci.c @@ -2384,8 +2384,9 @@ static void event_handler(uint8_t *packet, int size){ conn->state = OPEN; conn->role = packet[6]; - conn->con_handle = little_endian_read_16(packet, 4); - + conn->con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet); + conn->le_connection_interval = hci_subevent_le_connection_complete_get_conn_interval(packet); + #ifdef ENABLE_LE_PERIPHERAL if (packet[6] == HCI_ROLE_SLAVE){ hci_reenable_advertisements_if_needed(); @@ -2403,8 +2404,14 @@ static void event_handler(uint8_t *packet, int size){ hci_emit_nr_connections_changed(); break; - // log_info("LE buffer size: %u, count %u", little_endian_read_16(packet,6), packet[8]); - + // log_info("LE buffer size: %u, count %u", little_endian_read_16(packet,6), packet[8]); + case HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE: + handle = hci_subevent_le_connection_update_complete_get_connection_handle(packet); + conn = hci_connection_for_handle(handle); + if (!conn) break; + conn->le_connection_interval = hci_subevent_le_connection_update_complete_get_conn_interval(packet); + break; + case HCI_SUBEVENT_LE_REMOTE_CONNECTION_PARAMETER_REQUEST: // connection handle = hci_subevent_le_remote_connection_parameter_request_get_connection_handle(packet); @@ -4599,6 +4606,12 @@ void gap_auto_connection_stop_all(void){ } hci_run(); } + +uint16_t gap_le_connection_interval(hci_con_handle_t connection_handle){ + hci_connection_t * conn = hci_connection_for_handle(connection_handle); + if (!conn) return 0; + return conn->le_connection_interval; +} #endif #endif diff --git a/src/hci.h b/src/hci.h index 583f9aebc..61003bf23 100644 --- a/src/hci.h +++ b/src/hci.h @@ -526,6 +526,7 @@ typedef struct { uint16_t le_supervision_timeout; #ifdef ENABLE_BLE + uint16_t le_connection_interval; // LE Security Manager sm_connection_t sm_connection;