From ac2e07f8dd09e7f1b309f34acfaf76b249bb0a2e Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Sun, 13 Sep 2009 21:03:22 +0000 Subject: [PATCH] added quick test if Bluetooh UART can be opened before running BlueTool. Before Apple's Bluetooth did turn back on after it was turned off in the Settings --- src/bt_control_iphone.c | 22 +++++++++++++++------- src/hci.c | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/bt_control_iphone.c b/src/bt_control_iphone.c index b1a8e89ad..33fc8ff9d 100644 --- a/src/bt_control_iphone.c +++ b/src/bt_control_iphone.c @@ -95,10 +95,7 @@ static void iphone_set_pskey(int fd, int key, int value){ write(fd, buffer, 21); } -static int iphone_write_initscript (void *config, int output){ - - // get uart config - hci_uart_config_t * uart_config = (hci_uart_config_t *) config; +static int iphone_write_initscript (hci_uart_config_t *uart_config, int output){ // calculate baud rate (assume rate is multiply of 100) uint32_t baud_key = (4096 * (uart_config->baudrate/100) + 4999) / 10000; @@ -248,12 +245,23 @@ static int iphone_write_initscript (void *config, int output){ return 0; } -static int iphone_on (void *config){ +static int iphone_on (void *transport_config){ + + // quick test if Bluetooth UART can be opened + hci_uart_config_t * hci_uart_config = (hci_uart_config_t*) transport_config; + int fd = open(hci_uart_config->device_name, O_RDWR | O_NOCTTY | O_NDELAY); + if (fd == -1) { + perror("init_serialport: Unable to open port "); + perror(hci_uart_config->device_name); + return 1; + } + close(fd); + int err = 0; #if 0 // use tmp file for testing int output = open("/tmp/bt.init", O_WRONLY | O_CREAT | O_TRUNC); - iphone_write_initscript(config, output); + iphone_write_initscript(hci_uart_config, output); close(output); err = system ("BlueTool < /tmp/bt.init"); #else @@ -261,7 +269,7 @@ static int iphone_on (void *config){ FILE * outputFile = popen("BlueTool", "r+"); setvbuf(outputFile, NULL, _IONBF, 0); int output = fileno(outputFile); - iphone_write_initscript(config, output); + iphone_write_initscript(hci_uart_config, output); // log output fflush(outputFile); diff --git a/src/hci.c b/src/hci.c index e7d5cbdcb..ffd294caa 100644 --- a/src/hci.c +++ b/src/hci.c @@ -268,7 +268,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){ // power on int err = hci_stack.control->on(hci_stack.config); if (err){ - fprintf(stderr, "POWER_ON failed"); + fprintf(stderr, "POWER_ON failed\n"); hci_emit_hci_open_failed(); return err; } @@ -276,7 +276,7 @@ int hci_power_control(HCI_POWER_MODE power_mode){ // open low-level device err = hci_stack.hci_transport->open(hci_stack.config); if (err){ - fprintf(stderr, "HCI_INIT failed, turning Bluetooth off again"); + fprintf(stderr, "HCI_INIT failed, turning Bluetooth off again\n"); hci_stack.control->off(hci_stack.config); hci_emit_hci_open_failed(); return err;