From f8ee30711d382a32d09f62fdcf31e17b8873cde8 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 22 Oct 2018 14:05:59 +0200 Subject: [PATCH] hci/gap: support snif mode --- CHANGELOG.md | 1 + src/gap.h | 16 ++++++++++++++++ src/hci.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/hci.h | 11 ++++++++++- 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c4d5a44f..d6e728587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - SDP Server: queue incoming connections when already connected instead of rejecting them +- GAP: Support enter/exit sniff mode via gap_sniff_mode_enter/exit. gap_set_default_link_policy_settings is needed to enable sniff mode in general. ### Fixed - HCI: fix bug in gap_inquiry_stop that triggered additional GAP_EVENT_INQUIRY_COMPLETE instead of stopping the inquiry diff --git a/src/gap.h b/src/gap.h index f858463af..eefbcbc20 100644 --- a/src/gap.h +++ b/src/gap.h @@ -553,7 +553,23 @@ int gap_ssp_confirmation_response(bd_addr_t addr); */ int gap_ssp_confirmation_negative(bd_addr_t addr); +/** + * @brief Enter Sniff mode + * @param con_handle + * @param sniff_min_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms + * @param sniff_max_interval range: 0x0002 to 0xFFFE; only even values are valid, Time = N * 0.625 ms + * @param sniff_attempt Number of Baseband receive slots for sniff attempt. + * @param sniff_timeout Number of Baseband receive slots for sniff timeout. + @ @return 0 if ok + */ +uint8_t gap_sniff_mode_enter(hci_con_handle_t con_handle, uint16_t sniff_min_interval, uint16_t sniff_max_interval, uint16_t sniff_attempt, uint16_t sniff_timeout); +/** + * @brief Exit Sniff mode + * @param con_handle + @ @return 0 if ok + */ +uint8_t gap_sniff_mode_exit(hci_con_handle_t con_handle); // LE diff --git a/src/hci.c b/src/hci.c index d1f254226..975f930ca 100644 --- a/src/hci.c +++ b/src/hci.c @@ -3463,6 +3463,21 @@ static void hci_run(void){ return; } + uint16_t sniff_min_interval; + switch (connection->sniff_min_interval){ + case 0: + break; + case 0xffff: + connection->sniff_min_interval = 0; + hci_send_cmd(&hci_exit_sniff_mode, connection->con_handle); + return; + default: + sniff_min_interval = connection->sniff_min_interval; + connection->sniff_min_interval = 0; + hci_send_cmd(&hci_sniff_mode, connection->con_handle, connection->sniff_max_interval, sniff_min_interval, connection->sniff_attempt, connection->sniff_timeout); + break; + } + #ifdef ENABLE_BLE switch (connection->le_con_parameter_update_state){ // response to L2CAP CON PARAMETER UPDATE REQUEST @@ -4836,3 +4851,29 @@ authorization_state_t gap_authorization_state(hci_con_handle_t con_handle){ return sm_conn->sm_connection_authorization_state; } #endif + +#ifdef ENABLE_CLASSIC +uint8_t gap_sniff_mode_enter(hci_con_handle_t con_handle, uint16_t sniff_min_interval, uint16_t sniff_max_interval, uint16_t sniff_attempt, uint16_t sniff_timeout){ + hci_connection_t * conn = hci_connection_for_handle(con_handle); + if (!conn) return GAP_CONNECTION_INVALID; + conn->sniff_min_interval = sniff_min_interval; + conn->sniff_max_interval = sniff_max_interval; + conn->sniff_attempt = sniff_attempt; + conn->sniff_timeout = sniff_timeout; + hci_run(); + return 0; +} + +/** + * @brief Exit Sniff mode + * @param con_handle + @ @return 0 if ok + */ +uint8_t gap_sniff_mode_exit(hci_con_handle_t con_handle){ + hci_connection_t * conn = hci_connection_for_handle(con_handle); + if (!conn) return GAP_CONNECTION_INVALID; + conn->sniff_min_interval = 0xffff; + hci_run(); + return 0; +} +#endif diff --git a/src/hci.h b/src/hci.h index fc0a5966c..583f9aebc 100644 --- a/src/hci.h +++ b/src/hci.h @@ -475,6 +475,7 @@ typedef struct { // bonding uint16_t bonding_flags; uint8_t bonding_status; + // requested security level gap_security_level_t requested_security_level; @@ -484,9 +485,17 @@ typedef struct { // remote supported features uint8_t remote_supported_feature_eSCO; - // conenction mode, default ACL_CONNECTION_MODE_ACTIVE +#ifdef ENABLE_CLASSIC + // connection mode, default ACL_CONNECTION_MODE_ACTIVE uint8_t connection_mode; + // enter/exit sniff mode requests + uint16_t sniff_min_interval; // 0: idle, 0xffff exit sniff, else enter sniff + uint16_t sniff_max_interval; + uint16_t sniff_attempt; + uint16_t sniff_timeout; +#endif + // errands uint32_t authentication_flags;