mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-15 12:39:51 +00:00
disable page and inquiry scan when entering sleep mode
This commit is contained in:
parent
574e07e180
commit
89db417b22
65
src/hci.c
65
src/hci.c
@ -488,7 +488,14 @@ static void event_handler(uint8_t *packet, int size){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// help with BT sleep
|
||||||
|
if (hci_stack.state == HCI_STATE_FALLING_ASLEEP
|
||||||
|
&& hci_stack.substate == 1
|
||||||
|
&& COMMAND_COMPLETE_EVENT(packet, hci_write_scan_enable)){
|
||||||
|
hci_stack.substate++;
|
||||||
|
}
|
||||||
|
|
||||||
hci_stack.packet_handler(HCI_EVENT_PACKET, packet, size);
|
hci_stack.packet_handler(HCI_EVENT_PACKET, packet, size);
|
||||||
|
|
||||||
// execute main loop
|
// execute main loop
|
||||||
@ -696,6 +703,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
|||||||
case HCI_POWER_SLEEP:
|
case HCI_POWER_SLEEP:
|
||||||
// see hci_run
|
// see hci_run
|
||||||
hci_stack.state = HCI_STATE_FALLING_ASLEEP;
|
hci_stack.state = HCI_STATE_FALLING_ASLEEP;
|
||||||
|
hci_stack.substate = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -713,6 +721,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
|||||||
case HCI_POWER_SLEEP:
|
case HCI_POWER_SLEEP:
|
||||||
// see hci_run
|
// see hci_run
|
||||||
hci_stack.state = HCI_STATE_FALLING_ASLEEP;
|
hci_stack.state = HCI_STATE_FALLING_ASLEEP;
|
||||||
|
hci_stack.substate = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -817,7 +826,7 @@ void hci_run(){
|
|||||||
hci_send_cmd(&hci_write_page_timeout, 0x6000);
|
hci_send_cmd(&hci_write_page_timeout, 0x6000);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
hci_send_cmd(&hci_write_scan_enable, 3); // 3 inq scan + page scan
|
hci_send_cmd(&hci_write_scan_enable, 2); // page scan
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
#ifndef EMBEDDED
|
#ifndef EMBEDDED
|
||||||
@ -866,23 +875,43 @@ void hci_run(){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_STATE_FALLING_ASLEEP:
|
case HCI_STATE_FALLING_ASLEEP:
|
||||||
// close all open connections
|
switch(hci_stack.substate) {
|
||||||
connection = (hci_connection_t *) hci_stack.connections;
|
case 0:
|
||||||
if (connection){
|
log_dbg("HCI_STATE_FALLING_ASLEEP\n");
|
||||||
// send disconnect
|
// close all open connections
|
||||||
hci_send_cmd(&hci_disconnect, connection->con_handle, 0x13); // remote closed connection
|
connection = (hci_connection_t *) hci_stack.connections;
|
||||||
|
if (connection){
|
||||||
// send disconnected event right away - causes higher layer connections to get closed, too.
|
log_dbg("HCI_STATE_FALLING_ASLEEP, connection %u, handle %u\n", (int) connection, connection->con_handle);
|
||||||
hci_shutdown_connection(connection);
|
// send disconnect
|
||||||
|
hci_send_cmd(&hci_disconnect, connection->con_handle, 0x13); // remote closed connection
|
||||||
// remove from table
|
|
||||||
hci_stack.connections = connection->item.next;
|
// send disconnected event right away - causes higher layer connections to get closed, too.
|
||||||
return;
|
hci_shutdown_connection(connection);
|
||||||
|
|
||||||
|
// remove from table
|
||||||
|
hci_stack.connections = connection->item.next;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_dbg("HCI_STATE_HALTING, disabling inq & page scans\n");
|
||||||
|
|
||||||
|
// disable page and inquiry scan
|
||||||
|
hci_send_cmd(&hci_write_scan_enable, 0); // none
|
||||||
|
|
||||||
|
// continue in next sub state
|
||||||
|
hci_stack.substate++;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
// wait for command complete "hci_write_scan_enable" in event_handler();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
log_dbg("HCI_STATE_HALTING, calling sleep\n");
|
||||||
|
// switch mode
|
||||||
|
hci_power_control_sleep(); // changes hci_stack.state to SLEEP
|
||||||
|
hci_emit_state();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch mode
|
|
||||||
hci_power_control_sleep();
|
|
||||||
hci_emit_state();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user