use null_object for bt control, test power cycle

This commit is contained in:
matthias.ringwald 2009-06-03 21:21:12 +00:00
parent 8b658ebcf8
commit 7301ad89bc
4 changed files with 70 additions and 25 deletions

View File

@ -5,7 +5,7 @@ VPATH = src
# These paths must be changed to match the compilation environment # These paths must be changed to match the compilation environment
SDK_PATH = /Developer/Platforms/iPhoneOS.platform/Developer SDK_PATH = /Developer/Platforms/iPhoneOS.platform/Developer
SDK_VERSION = 2.0 SDK_VERSION = 2.1
GCC_VERSION = 4.0.1 GCC_VERSION = 4.0.1
# #
@ -44,7 +44,7 @@ $(SRCS): $(HEADERS)
$(NAME): $(SRCS) $(NAME): $(SRCS)
$(CXX) $(CXXFLAGS) -o $(NAME) $(filter %.mm,$^) $(filter %.m,$^) $(filter %.c,$^) $(LDFLAGS) $(CXX) $(CXXFLAGS) -o $(NAME) $(filter %.mm,$^) $(filter %.m,$^) $(filter %.c,$^) $(LDFLAGS)
export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $(NAME) export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $(NAME)
ssh root@192.168.3.102 rm BTdaemon ssh root@192.168.3.102 rm -f BTdaemon
scp $(NAME) root@192.168.3.102:. scp $(NAME) root@192.168.3.102:.
.PHONY: all clean .PHONY: all clean

View File

@ -13,5 +13,5 @@ typedef struct {
int (*on)(void *config); // <-- turn BT module on and configure int (*on)(void *config); // <-- turn BT module on and configure
int (*off)(void *config); // <-- turn BT module off int (*off)(void *config); // <-- turn BT module off
int (*valid)(void *confif); // <-- test if hardware can be supported int (*valid)(void *confif); // <-- test if hardware can be supported
const char * (*names)(void *config); // <-- return hardware name const char * (*name)(void *config); // <-- return hardware name
} bt_control_t; } bt_control_t;

View File

@ -132,6 +132,11 @@ static void event_handler(uint8_t *packet, int size){
// handle BT initialization // handle BT initialization
if (hci_stack.state == HCI_STATE_INITIALIZING){ if (hci_stack.state == HCI_STATE_INITIALIZING){
// handle H4 synchronization loss on restart
// if (hci_stack.substate == 1 && packet[0] == HCI_EVENT_HARDWARE_ERROR){
// hci_stack.substate = 0;
// }
// handle normal init sequence
if (hci_stack.substate % 2){ if (hci_stack.substate % 2){
// odd: waiting for event // odd: waiting for event
if (packet[0] == HCI_EVENT_COMMAND_COMPLETE){ if (packet[0] == HCI_EVENT_COMMAND_COMPLETE){
@ -164,13 +169,31 @@ void hci_register_acl_packet_handler (void (*handler)(uint8_t *packet, int size
hci_stack.acl_packet_handler = handler; hci_stack.acl_packet_handler = handler;
} }
static int null_control_function(void *config){
return 0;
}
static const char * null_control_name(void *config){
return "Hardware unknown";
}
static bt_control_t null_control = {
null_control_function,
null_control_function,
null_control_function,
null_control_name
};
void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){
// reference to use transport layer implementation // reference to use transport layer implementation
hci_stack.hci_transport = transport; hci_stack.hci_transport = transport;
// references to used control implementation // references to used control implementation
if (control) {
hci_stack.control = control; hci_stack.control = control;
} else {
hci_stack.control = &null_control;
}
// reference to used config // reference to used config
hci_stack.config = config; hci_stack.config = config;
@ -178,11 +201,6 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){
// empty cmd buffer // empty cmd buffer
hci_stack.hci_cmd_buffer = malloc(3+255); hci_stack.hci_cmd_buffer = malloc(3+255);
// set up state
hci_stack.num_cmd_packets = 1; // assume that one cmd can be sent
hci_stack.state = HCI_STATE_INITIALIZING;
hci_stack.substate = 0;
// higher level handler // higher level handler
hci_stack.event_packet_handler = dummy_handler; hci_stack.event_packet_handler = dummy_handler;
hci_stack.acl_packet_handler = dummy_handler; hci_stack.acl_packet_handler = dummy_handler;
@ -193,19 +211,30 @@ void hci_init(hci_transport_t *transport, void *config, bt_control_t *control){
// turn on // turn on
hci_power_control(HCI_POWER_ON); hci_power_control(HCI_POWER_ON);
// open low-level device
transport->open(config);
} }
int hci_power_control(HCI_POWER_MODE power_mode){ int hci_power_control(HCI_POWER_MODE power_mode){
if (hci_stack.control) {
if (power_mode == HCI_POWER_ON) { if (power_mode == HCI_POWER_ON) {
// set up state machine
hci_stack.num_cmd_packets = 1; // assume that one cmd can be sent
hci_stack.state = HCI_STATE_INITIALIZING;
hci_stack.substate = 0;
// power on
hci_stack.control->on(hci_stack.config); hci_stack.control->on(hci_stack.config);
// open low-level device
hci_stack.hci_transport->open(hci_stack.config);
} else if (power_mode == HCI_POWER_OFF){ } else if (power_mode == HCI_POWER_OFF){
// close low-level device
hci_stack.hci_transport->close(hci_stack.config);
// power off
hci_stack.control->off(hci_stack.config); hci_stack.control->off(hci_stack.config);
} }
}
return 0; return 0;
} }

View File

@ -13,6 +13,7 @@
#include "hci.h" #include "hci.h"
#include "hci_transport_h4.h" #include "hci_transport_h4.h"
#include "hci_dump.h" #include "hci_dump.h"
#include "bt_control_iphone.h"
#include "l2cap.h" #include "l2cap.h"
@ -23,16 +24,16 @@ hci_con_handle_t con_handle= 0;
uint16_t dest_cid; uint16_t dest_cid;
void event_handler(uint8_t *packet, int size){ void event_handler(uint8_t *packet, int size){
bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9}; // MacBook Pro
// printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8); // printf("Event type: %x, opcode: %x, other %x\n", packet[0], packet[3] | packet[4] << 8);
#if 0
// bd_addr_t addr = {0x00, 0x03, 0xc9, 0x3d, 0x77, 0x43 }; // Think Outside Keyboard
// bd_addr_t addr = { 0x00, 0x16, 0xcb, 0x09, 0x94, 0xa9}; // MacBook Pro
// bt stack activated, set authentication enabled // bt stack activated, set authentication enabled
if (packet[0] == BTSTACK_EVENT_HCI_WORKING) { if (packet[0] == BTSTACK_EVENT_HCI_WORKING) {
hci_send_cmd(&hci_write_authentication_enable, 1); hci_send_cmd(&hci_write_authentication_enable, 1);
// hci_send_cmd(&hci_host_buffer_size, 400, 255, 1, 0, 0); // hci_send_cmd(&hci_host_buffer_size, 400, 255, 1, 0, 0);
// hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 30, 0);
} }
if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) { if ( COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable) ) {
@ -55,6 +56,21 @@ void event_handler(uint8_t *packet, int size){
l2cap_send_signaling_packet(con_handle, CONNECTION_REQUEST, sig_seq_nr++, 0x13, local_cid); l2cap_send_signaling_packet(con_handle, CONNECTION_REQUEST, sig_seq_nr++, 0x13, local_cid);
} }
} }
#else
if (packet[0] == BTSTACK_EVENT_HCI_WORKING) {
hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 10, 0);
}
if (packet[0] == HCI_EVENT_INQUIRY_COMPLETE){
// power cycle
hci_power_control( HCI_POWER_OFF );
//
printf ("Power off!\n");
sleep(10);
printf ("Restart!\n");
hci_power_control( HCI_POWER_ON );
}
#endif
} }
void acl_handler(uint8_t *packet, int size){ void acl_handler(uint8_t *packet, int size){
@ -95,7 +111,7 @@ int main (int argc, const char * argv[]) {
bt_control_t * control = NULL; bt_control_t * control = NULL;
#if 1 #if 0
// //
if (argc <= 1){ if (argc <= 1){
printf("HCI Daemon tester. Specify device name for Ericsson ROK 101 007\n"); printf("HCI Daemon tester. Specify device name for Ericsson ROK 101 007\n");