mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-24 06:02:43 +00:00
add function to set page scan enable, keep page scan during sleep mode
This commit is contained in:
parent
8c064dfc09
commit
758b46ce19
31
src/hci.c
31
src/hci.c
@ -61,6 +61,8 @@
|
|||||||
#include "bt_control_iphone.h"
|
#include "bt_control_iphone.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void hci_update_scan_enable(void);
|
||||||
|
|
||||||
// the STACK is here
|
// the STACK is here
|
||||||
static hci_stack_t hci_stack;
|
static hci_stack_t hci_stack;
|
||||||
|
|
||||||
@ -688,6 +690,9 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control, r
|
|||||||
hci_stack.connections = NULL;
|
hci_stack.connections = NULL;
|
||||||
hci_stack.discoverable = 0;
|
hci_stack.discoverable = 0;
|
||||||
|
|
||||||
|
// enable page scan by until l2cap takes over control
|
||||||
|
hci_stack.connectable = 1;
|
||||||
|
|
||||||
// no pending cmds
|
// no pending cmds
|
||||||
hci_stack.decline_reason = 0;
|
hci_stack.decline_reason = 0;
|
||||||
hci_stack.new_scan_enable_value = 0xff;
|
hci_stack.new_scan_enable_value = 0xff;
|
||||||
@ -933,6 +938,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
|||||||
if (bt_control_iphone_power_management_enabled()){
|
if (bt_control_iphone_power_management_enabled()){
|
||||||
hci_stack.state = HCI_STATE_INITIALIZING;
|
hci_stack.state = HCI_STATE_INITIALIZING;
|
||||||
hci_stack.substate = 6;
|
hci_stack.substate = 6;
|
||||||
|
hci_update_scan_enable();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -962,6 +968,12 @@ int hci_power_control(HCI_POWER_MODE power_mode){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hci_update_scan_enable(void){
|
||||||
|
// 2 = page scan, 1 = inq scan
|
||||||
|
hci_stack.new_scan_enable_value = hci_stack.connectable << 1 | hci_stack.discoverable;
|
||||||
|
hci_run();
|
||||||
|
}
|
||||||
|
|
||||||
void hci_discoverable_control(uint8_t enable){
|
void hci_discoverable_control(uint8_t enable){
|
||||||
if (enable) enable = 1; // normalize argument
|
if (enable) enable = 1; // normalize argument
|
||||||
|
|
||||||
@ -970,11 +982,18 @@ void hci_discoverable_control(uint8_t enable){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// store request to send command but accept in higher layer view
|
|
||||||
hci_stack.new_scan_enable_value = 2 | enable; // 1 = inq scan, 2 = page scan
|
|
||||||
hci_stack.discoverable = enable;
|
hci_stack.discoverable = enable;
|
||||||
|
hci_update_scan_enable();
|
||||||
|
}
|
||||||
|
|
||||||
hci_run();
|
void hci_connectable_control(uint8_t enable){
|
||||||
|
if (enable) enable = 1; // normalize argument
|
||||||
|
|
||||||
|
// don't emit event
|
||||||
|
if (hci_stack.connectable == enable) return;
|
||||||
|
|
||||||
|
hci_stack.connectable = enable;
|
||||||
|
hci_update_scan_enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void hci_run(){
|
void hci_run(){
|
||||||
@ -1077,7 +1096,7 @@ void hci_run(){
|
|||||||
hci_send_cmd(&hci_write_page_timeout, 0x6000);
|
hci_send_cmd(&hci_write_page_timeout, 0x6000);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
hci_send_cmd(&hci_write_scan_enable, 2 | hci_stack.discoverable); // page scan
|
hci_send_cmd(&hci_write_scan_enable, (hci_stack.connectable << 1) | hci_stack.discoverable); // page scan
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
#ifndef EMBEDDED
|
#ifndef EMBEDDED
|
||||||
@ -1162,8 +1181,8 @@ void hci_run(){
|
|||||||
// disable page and inquiry scan
|
// disable page and inquiry scan
|
||||||
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
|
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
|
||||||
|
|
||||||
log_info("HCI_STATE_HALTING, disabling inq & page scans\n");
|
log_info("HCI_STATE_HALTING, disabling inq cans\n");
|
||||||
hci_send_cmd(&hci_write_scan_enable, 0); // none
|
hci_send_cmd(&hci_write_scan_enable, hci_stack.connectable << 1); // drop inquiry scan but keep page scan
|
||||||
|
|
||||||
// continue in next sub state
|
// continue in next sub state
|
||||||
hci_stack.substate++;
|
hci_stack.substate++;
|
||||||
|
@ -286,6 +286,7 @@ typedef struct {
|
|||||||
uint8_t cmds_ready;
|
uint8_t cmds_ready;
|
||||||
|
|
||||||
uint8_t discoverable;
|
uint8_t discoverable;
|
||||||
|
uint8_t connectable;
|
||||||
|
|
||||||
/* buffer for scan enable cmd - 0xff no change */
|
/* buffer for scan enable cmd - 0xff no change */
|
||||||
uint8_t new_scan_enable_value;
|
uint8_t new_scan_enable_value;
|
||||||
@ -308,6 +309,7 @@ void hci_close(void);
|
|||||||
// power and inquriy scan control
|
// power and inquriy scan control
|
||||||
int hci_power_control(HCI_POWER_MODE mode);
|
int hci_power_control(HCI_POWER_MODE mode);
|
||||||
void hci_discoverable_control(uint8_t enable);
|
void hci_discoverable_control(uint8_t enable);
|
||||||
|
void hci_connectable_control(uint8_t enable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* run the hci control loop once
|
* run the hci control loop once
|
||||||
|
Loading…
x
Reference in New Issue
Block a user