mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
gap: streamline adv/scan/connection management
This commit is contained in:
parent
bbc366e601
commit
fde725fe22
69
src/hci.c
69
src/hci.c
@ -3616,37 +3616,52 @@ static bool hci_run_general_gap_le(void){
|
|||||||
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;
|
||||||
|
|
||||||
#ifdef ENABLE_LE_CENTRAL
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
// parameter change requires scanning to be stopped first
|
// scanning control
|
||||||
if (hci_stack->le_scan_type != 0xffu) {
|
bool scanning_stop = false;
|
||||||
if (hci_stack->le_scanning_active){
|
if (hci_stack->le_scanning_active) {
|
||||||
hci_stack->le_scanning_active = 0;
|
// parameter change requires scanning to be off, or, it might be disabled
|
||||||
hci_send_cmd(&hci_le_set_scan_enable, 0, 0);
|
if ((hci_stack->le_scan_type != 0xffu) || !hci_stack->le_scanning_enabled){
|
||||||
} else {
|
scanning_stop = false;
|
||||||
int scan_type = (int) hci_stack->le_scan_type;
|
|
||||||
hci_stack->le_scan_type = 0xff;
|
|
||||||
hci_send_cmd(&hci_le_set_scan_parameters, scan_type, hci_stack->le_scan_interval, hci_stack->le_scan_window,
|
|
||||||
hci_stack->le_own_addr_type, hci_stack->le_scan_filter_policy);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scanning_stop){
|
||||||
|
hci_stack->le_scanning_active = 0;
|
||||||
|
hci_send_cmd(&hci_le_set_scan_enable, 0, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// finally, we can enable/disable le scan
|
|
||||||
if ((hci_stack->le_scanning_enabled != hci_stack->le_scanning_active)){
|
if (hci_stack->le_scan_type != 0xffu){
|
||||||
hci_stack->le_scanning_active = hci_stack->le_scanning_enabled;
|
int scan_type = (int) hci_stack->le_scan_type;
|
||||||
hci_send_cmd(&hci_le_set_scan_enable, hci_stack->le_scanning_enabled, 0);
|
hci_stack->le_scan_type = 0xff;
|
||||||
|
hci_send_cmd(&hci_le_set_scan_parameters, scan_type, hci_stack->le_scan_interval, hci_stack->le_scan_window,
|
||||||
|
hci_stack->le_own_addr_type, hci_stack->le_scan_filter_policy);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_LE_PERIPHERAL
|
#ifdef ENABLE_LE_PERIPHERAL
|
||||||
// le advertisement control
|
// le advertisement control
|
||||||
|
bool advertising_stop = false;
|
||||||
// disable advertisements if changes are required
|
if (hci_stack->le_advertisements_active){
|
||||||
if (hci_stack->le_advertisements_active && (hci_stack->le_advertisements_todo != 0)){
|
// parameter change requires scanning to be off, or, it might be disabled
|
||||||
if (hci_stack->le_advertisements_active){
|
if ((hci_stack->le_advertisements_todo != 0) && !hci_stack->le_advertisements_enabled_for_current_roles) {
|
||||||
hci_stack->le_advertisements_active = 0;
|
advertising_stop = true;
|
||||||
hci_send_cmd(&hci_le_set_advertise_enable, 0);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (advertising_stop){
|
||||||
|
hci_stack->le_advertisements_active = 0;
|
||||||
|
hci_send_cmd(&hci_le_set_advertise_enable, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_PARAMS){
|
if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_PARAMS){
|
||||||
hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_PARAMS;
|
hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_PARAMS;
|
||||||
hci_send_cmd(&hci_le_set_advertising_parameters,
|
hci_send_cmd(&hci_le_set_advertising_parameters,
|
||||||
@ -3707,8 +3722,14 @@ static bool hci_run_general_gap_le(void){
|
|||||||
if (whitelist_modification_pending){
|
if (whitelist_modification_pending){
|
||||||
|
|
||||||
#ifdef ENABLE_LE_CENTRAL
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
|
bool connecting_stop = false;
|
||||||
|
|
||||||
// stop connecting if modification pending
|
// stop connecting if modification pending
|
||||||
if (hci_stack->le_connecting_state != LE_CONNECTING_IDLE){
|
if (hci_stack->le_connecting_state != LE_CONNECTING_IDLE) {
|
||||||
|
connecting_stop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connecting_stop){
|
||||||
hci_send_cmd(&hci_le_create_connection_cancel);
|
hci_send_cmd(&hci_le_create_connection_cancel);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -4893,12 +4914,12 @@ void gap_set_local_name(const char * local_name){
|
|||||||
|
|
||||||
#ifdef ENABLE_LE_CENTRAL
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
void gap_start_scan(void){
|
void gap_start_scan(void){
|
||||||
hci_stack->le_scanning_enabled = 1;
|
hci_stack->le_scanning_enabled = true;
|
||||||
hci_run();
|
hci_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gap_stop_scan(void){
|
void gap_stop_scan(void){
|
||||||
hci_stack->le_scanning_enabled = 0;
|
hci_stack->le_scanning_enabled = false;
|
||||||
hci_run();
|
hci_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -890,8 +890,8 @@ typedef struct {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_LE_CENTRAL
|
#ifdef ENABLE_LE_CENTRAL
|
||||||
uint8_t le_scanning_enabled;
|
bool le_scanning_enabled;
|
||||||
uint8_t le_scanning_active;
|
bool le_scanning_active;
|
||||||
|
|
||||||
le_connecting_state_t le_connecting_state;
|
le_connecting_state_t le_connecting_state;
|
||||||
le_connecting_state_t le_connecting_request;
|
le_connecting_state_t le_connecting_request;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user