hci/gap: support snif mode

This commit is contained in:
Matthias Ringwald 2018-10-22 14:05:59 +02:00
parent 7cd21895df
commit f8ee30711d
4 changed files with 68 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;