diff -u -r1.22 btsco.c --- btsco.c 3 May 2005 15:37:12 -0000 1.22 +++ btsco.c 5 May 2005 18:46:14 -0000 @@ -80,7 +80,7 @@ char *cmd; }; -static volatile int terminate = 0, ring = 0, hupped = 0; +static volatile int terminate = 0, ring = 0, hupped = 0, reconnect = 0; static int verbose = 0; static void sig_term(int sig) @@ -98,6 +98,11 @@ hupped = 1; } +static void sig_usr(int sig) +{ + reconnect = 1; +} + static int rfcomm_connect(bdaddr_t * src, bdaddr_t * dst, uint8_t channel) { struct sockaddr_rc addr; @@ -573,6 +578,9 @@ sa.sa_handler = sig_ring; sigaction(SIGUSR1, &sa, NULL); + sa.sa_handler = sig_usr; + sigaction(SIGUSR2, &sa, NULL); + sa.sa_handler = sig_hup; sigaction(SIGHUP, &sa, NULL); @@ -704,7 +712,11 @@ int substl = 0; subst = NULL; - sysbuf = strdup(args); + + // add the current sco mode to the command string + sysbuf = malloc(strlen(args)+1); + sprintf(sysbuf,args,sco_mode); + for(i = 0; sysbuf[i]; i++) { if((sysbuf[i] == '\\') && (sysbuf[i + 1] >= '0') && (sysbuf[i + 1] <= '9')) { match = sysbuf[i + 1] - '0'; @@ -804,6 +816,40 @@ } + // mean little hack to allow for a signal-triggered reconnect + // force disconnection of the channel (if connected) + if (reconnect == 1) { + if (sco_mode == CONNECTED) { + force_sco = 0; + reconnect = -1; + } else reconnect = 0; + } + + if(((!dr_usage && (force_sco != 1)) || (force_sco == 0)) && (sco_mode == CONNECTED)) { + if(verbose) { + printf("driver is not in use\n"); + fflush(stdout); + } + /* close bt_sco audio handle */ + bt_sco_set_fd(handle, -1); + /* disconnect SCO stream */ + close(sd); + if(verbose) { + printf("disconnected SCO channel\n"); + fflush(stdout); + } + + sco_mode = NOT_CONNECTED; + } + + // if a reconnect has been requested, force + // the sco channel to be acquired again + if (reconnect == -1) { + force_sco = 1; + reconnect = 0; + sleep(3); + } + if(((dr_usage && (force_sco != 0)) || (force_sco == 1)) && (sco_mode == NOT_CONNECTED)) { if(verbose) { printf("driver is in use\n"); @@ -825,24 +871,6 @@ } sco_mode = CONNECTED; } - - } - if(((!dr_usage && (force_sco != 1)) || (force_sco == 0)) && (sco_mode == CONNECTED)) { - if(verbose) { - printf("driver is not in use\n"); - fflush(stdout); - } - /* close bt_sco audio handle */ - bt_sco_set_fd(handle, -1); - /* disconnect SCO stream */ - close(sd); - if(verbose) { - printf("disconnected SCO channel\n"); - fflush(stdout); - } - - sco_mode = NOT_CONNECTED; - } if (ring) {