mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-06 12:39:51 +00:00
gap: interleave stop/update/start phases for adv/scan/connecting, disable scan and/or adv if whitelist is used
This commit is contained in:
parent
fde725fe22
commit
29c24beb69
96
src/hci.c
96
src/hci.c
@ -3615,12 +3615,28 @@ static bool hci_run_general_gap_le(void){
|
|||||||
if (hci_stack->state != HCI_STATE_WORKING) return false;
|
if (hci_stack->state != HCI_STATE_WORKING) return false;
|
||||||
if ( (hci_stack->le_own_addr_type != BD_ADDR_TYPE_LE_PUBLIC) && (hci_stack->le_random_address_set == 0u) ) return false;
|
if ( (hci_stack->le_own_addr_type != BD_ADDR_TYPE_LE_PUBLIC) && (hci_stack->le_random_address_set == 0u) ) return false;
|
||||||
|
|
||||||
|
// check if whitelist needs modification
|
||||||
|
bool whitelist_modification_pending = false;
|
||||||
|
btstack_linked_list_iterator_t lit;
|
||||||
|
btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
|
||||||
|
while (btstack_linked_list_iterator_has_next(&lit)){
|
||||||
|
whitelist_entry_t * entry = (whitelist_entry_t*) btstack_linked_list_iterator_next(&lit);
|
||||||
|
if (entry->state & (LE_WHITELIST_REMOVE_FROM_CONTROLLER | LE_WHITELIST_ADD_TO_CONTROLLER)){
|
||||||
|
whitelist_modification_pending = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_LE_CENTRAL
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
// scanning control
|
// scanning control
|
||||||
bool scanning_stop = false;
|
bool scanning_stop = false;
|
||||||
if (hci_stack->le_scanning_active) {
|
if (hci_stack->le_scanning_active) {
|
||||||
// parameter change requires scanning to be off, or, it might be disabled
|
// stop if:
|
||||||
if ((hci_stack->le_scan_type != 0xffu) || !hci_stack->le_scanning_enabled){
|
// - parameter change required
|
||||||
|
// - it's disabled
|
||||||
|
// - whitelist change required but used for scanning
|
||||||
|
bool scanning_uses_whitelist = (hci_stack->le_scan_filter_policy & 1) == 1;
|
||||||
|
if ((hci_stack->le_scan_type != 0xffu) || !hci_stack->le_scanning_enabled || scanning_uses_whitelist){
|
||||||
scanning_stop = false;
|
scanning_stop = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3638,20 +3654,34 @@ static bool hci_run_general_gap_le(void){
|
|||||||
hci_stack->le_own_addr_type, hci_stack->le_scan_filter_policy);
|
hci_stack->le_own_addr_type, hci_stack->le_scan_filter_policy);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// finally, we can start scanning
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
if ((hci_stack->le_scanning_enabled && !hci_stack->le_scanning_active)){
|
// connecting control
|
||||||
hci_stack->le_scanning_active = true;
|
bool connecting_stop = false;
|
||||||
hci_send_cmd(&hci_le_set_scan_enable, 1, 0);
|
if (hci_stack->le_connecting_state != LE_CONNECTING_IDLE){
|
||||||
|
// stop connecting if modification pending
|
||||||
|
if (whitelist_modification_pending) {
|
||||||
|
connecting_stop = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connecting_stop){
|
||||||
|
hci_send_cmd(&hci_le_create_connection_cancel);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_LE_PERIPHERAL
|
#ifdef ENABLE_LE_PERIPHERAL
|
||||||
// le advertisement control
|
// le advertisement control
|
||||||
bool advertising_stop = false;
|
bool advertising_stop = false;
|
||||||
if (hci_stack->le_advertisements_active){
|
if (hci_stack->le_advertisements_active){
|
||||||
// parameter change requires scanning to be off, or, it might be disabled
|
// stop if:
|
||||||
if ((hci_stack->le_advertisements_todo != 0) && !hci_stack->le_advertisements_enabled_for_current_roles) {
|
// - parameter change required
|
||||||
|
// - it's disabled
|
||||||
|
// - whitelist change required but used for scanning
|
||||||
|
bool advertising_uses_whitelist = hci_stack->le_advertisements_filter_policy > 0;
|
||||||
|
if ((hci_stack->le_advertisements_todo != 0) || !hci_stack->le_advertisements_enabled_for_current_roles || advertising_uses_whitelist) {
|
||||||
advertising_stop = true;
|
advertising_stop = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3695,46 +3725,14 @@ static bool hci_run_general_gap_le(void){
|
|||||||
hci_send_cmd(&hci_le_set_scan_response_data, hci_stack->le_scan_response_data_len, scan_data_clean);
|
hci_send_cmd(&hci_le_set_scan_response_data, hci_stack->le_scan_response_data_len, scan_data_clean);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (hci_stack->le_advertisements_enabled_for_current_roles && (hci_stack->le_advertisements_active == 0)){
|
|
||||||
// check if advertisements should be enabled given
|
|
||||||
hci_stack->le_advertisements_active = 1;
|
|
||||||
hci_send_cmd(&hci_le_set_advertise_enable, 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// LE Whitelist Management
|
// LE Whitelist Management
|
||||||
//
|
//
|
||||||
|
|
||||||
// check if whitelist needs modification
|
|
||||||
btstack_linked_list_iterator_t lit;
|
|
||||||
bool whitelist_modification_pending = false;
|
|
||||||
btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
|
|
||||||
while (btstack_linked_list_iterator_has_next(&lit)){
|
|
||||||
whitelist_entry_t * entry = (whitelist_entry_t*) btstack_linked_list_iterator_next(&lit);
|
|
||||||
if (entry->state & (LE_WHITELIST_REMOVE_FROM_CONTROLLER | LE_WHITELIST_ADD_TO_CONTROLLER)){
|
|
||||||
whitelist_modification_pending = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (whitelist_modification_pending){
|
if (whitelist_modification_pending){
|
||||||
|
|
||||||
#ifdef ENABLE_LE_CENTRAL
|
|
||||||
bool connecting_stop = false;
|
|
||||||
|
|
||||||
// stop connecting if modification pending
|
|
||||||
if (hci_stack->le_connecting_state != LE_CONNECTING_IDLE) {
|
|
||||||
connecting_stop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connecting_stop){
|
|
||||||
hci_send_cmd(&hci_le_create_connection_cancel);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// add/remove entries
|
// add/remove entries
|
||||||
btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
|
btstack_linked_list_iterator_init(&lit, &hci_stack->le_whitelist);
|
||||||
while (btstack_linked_list_iterator_has_next(&lit)){
|
while (btstack_linked_list_iterator_has_next(&lit)){
|
||||||
@ -3756,6 +3754,24 @@ static bool hci_run_general_gap_le(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_LE_PERIPHERAL
|
||||||
|
if (hci_stack->le_advertisements_enabled_for_current_roles && (hci_stack->le_advertisements_active == 0)){
|
||||||
|
// check if advertisements should be enabled given
|
||||||
|
hci_stack->le_advertisements_active = 1;
|
||||||
|
hci_send_cmd(&hci_le_set_advertise_enable, 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
|
// finally, we can start scanning
|
||||||
|
if ((hci_stack->le_scanning_enabled && !hci_stack->le_scanning_active)){
|
||||||
|
hci_stack->le_scanning_active = true;
|
||||||
|
hci_send_cmd(&hci_le_set_scan_enable, 1, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_LE_CENTRAL
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
// start connecting
|
// start connecting
|
||||||
if ( (hci_stack->le_connecting_state == LE_CONNECTING_IDLE) &&
|
if ( (hci_stack->le_connecting_state == LE_CONNECTING_IDLE) &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user