All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] some btsco hacks
@ 2005-05-05 18:58 Florian Echtler
  2005-05-05 21:09 ` [Bluez-devel] " Brad Midgley
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Echtler @ 2005-05-05 18:58 UTC (permalink / raw)
  To: bmidgley, bluez-devel

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1471 bytes --]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello everyone,

I finally got time to investigate the issues with my headset. Sometimes
after SCO connection establishment, the microphone produces only noise,
and a reconnect is necessary to fix this. The attached patch is against
btsco.c v1.22 from CVS, and does two things:

1. installs a handler for SIGUSR2 which automatically disconnects the
   SCO channel when connected and reconnects it after a short delay

2. allows the command string in .btscorc to contain '%d', which will
   be replaced with the current SCO connection status (0 or 1) upon
   command execution.

1. may be not really useful to most people - as mentioned, my headset
is obviously somewhat buggy and needs a kind of reset sometimes, which
this patch provides (actually, I wrote a shell script which samples
1 second of audio data from the headset, runs it through gzip to determine
whether it's noise and sends SIGUSR2 accordingly - talk about evil hacks ;)

2. was included because I want certain actions to happen only when
the connection is established, and not when it's shutting down.

Brad: if you think this could be useful otherwise, then feel free to 
include the patch into CVS.

Yours, Florian
- -- 
Preserve wildlife - pickle a squirrel today!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCemzI7CzyshGvatgRArpWAJ4g4j5sgUjj3ulgVwxORICyjYdyHgCg5qpr
gE4T1Cniprq057+KD2i79kE=
=jha8
-----END PGP SIGNATURE-----

[-- Attachment #2: Type: TEXT/PLAIN, Size: 2812 bytes --]

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) {

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-05-09 23:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-05 18:58 [Bluez-devel] some btsco hacks Florian Echtler
2005-05-05 21:09 ` [Bluez-devel] " Brad Midgley
2005-05-06 20:52   ` Florian Echtler
2005-05-09  5:16     ` Brad Midgley
2005-05-09 22:14       ` Florian Echtler
2005-05-09 23:11         ` Brad Midgley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.