add function to set page scan enable, keep page scan during sleep mode

This commit is contained in:
matthias.ringwald 2011-10-31 18:51:33 +00:00
parent 8c064dfc09
commit 758b46ce19
2 changed files with 30 additions and 9 deletions

View File

@ -61,6 +61,8 @@
#include "bt_control_iphone.h"
#endif
static void hci_update_scan_enable(void);
// the STACK is here
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.discoverable = 0;
// enable page scan by until l2cap takes over control
hci_stack.connectable = 1;
// no pending cmds
hci_stack.decline_reason = 0;
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()){
hci_stack.state = HCI_STATE_INITIALIZING;
hci_stack.substate = 6;
hci_update_scan_enable();
break;
}
#endif
@ -962,6 +968,12 @@ int hci_power_control(HCI_POWER_MODE power_mode){
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){
if (enable) enable = 1; // normalize argument
@ -969,12 +981,19 @@ void hci_discoverable_control(uint8_t enable){
hci_emit_discoverable_enabled(hci_stack.discoverable);
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_update_scan_enable();
}
void hci_connectable_control(uint8_t enable){
if (enable) enable = 1; // normalize argument
hci_run();
// don't emit event
if (hci_stack.connectable == enable) return;
hci_stack.connectable = enable;
hci_update_scan_enable();
}
void hci_run(){
@ -1077,7 +1096,7 @@ void hci_run(){
hci_send_cmd(&hci_write_page_timeout, 0x6000);
break;
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;
case 7:
#ifndef EMBEDDED
@ -1162,8 +1181,8 @@ void hci_run(){
// disable page and inquiry scan
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
log_info("HCI_STATE_HALTING, disabling inq & page scans\n");
hci_send_cmd(&hci_write_scan_enable, 0); // none
log_info("HCI_STATE_HALTING, disabling inq cans\n");
hci_send_cmd(&hci_write_scan_enable, hci_stack.connectable << 1); // drop inquiry scan but keep page scan
// continue in next sub state
hci_stack.substate++;

View File

@ -286,7 +286,8 @@ typedef struct {
uint8_t cmds_ready;
uint8_t discoverable;
uint8_t connectable;
/* buffer for scan enable cmd - 0xff no change */
uint8_t new_scan_enable_value;
@ -306,8 +307,9 @@ void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *p
void hci_close(void);
// 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_connectable_control(uint8_t enable);
/**
* run the hci control loop once