public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] hci_create_connection assuming timeout too soon
@ 2004-06-09 13:48 Andreas Gaufer
  2004-06-12  9:45 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Gaufer @ 2004-06-09 13:48 UTC (permalink / raw)
  To: Bluez Devel

[-- Attachment #1: Type: text/plain, Size: 1200 bytes --]

Hi,

I noticed that many tools that use hci_create_connection use a hard coded 
timeout-value that varries between 1000 and 25000. 1000 is much to short for 
most mobile phones. 

This leads to error messages even if the chip didnt report a "connection 
complete" yet. Very often a conection complete with 00 is reported 
later but the tool did exit already.

IMHO we could rely on the chips page timeout and wait for its "connection
complete" event. This timeout can also be changed with hciconfig pageto 
by the user.

To catch a condition where the chip is stalled in some way i think the best 
approach would be to time out on host side after the chips 
page time out * 1,5 or so.

I changed hcitool to make it possible to specifiy the host side
timeout via command line but i dont belive that this is a good aproach because
it only fixes the symthoms not the root of the problem. Anyways I attach the 
patch against the latest CVS-HEAD to show what im talking about.

In the moment my time is extremly short, i will try to bring up some code 
that realy helps here later. Since im not that familiar with C please let me 
know if somethings not right with my changes.

Greetings

Andreas Gaufer


[-- Attachment #2: hcitool.c.diff --]
[-- Type: text/plain, Size: 3597 bytes --]

Index: hcitool.c
===================================================================
RCS file: /cvsroot/bluez/utils/tools/hcitool.c,v
retrieving revision 1.43
diff -u -r1.43 hcitool.c
--- hcitool.c	28 Apr 2004 10:39:47 -0000	1.43
+++ hcitool.c	9 Jun 2004 13:37:35 -0000
@@ -380,12 +380,13 @@
 
 static struct option info_options[] = {
 	{"help",	0,0, 'h'},
+	{"to",		1,0, 't'},
 	{0, 0, 0, 0}
 };
 
 static char *info_help = 
 	"Usage:\n"
-	"\tinfo <bdaddr>\n";
+	"\tinfo [--to=timeout] <bdaddr>\n";
 
 static void cmd_info(int dev_id, int argc, char **argv)
 {
@@ -395,10 +396,14 @@
 	unsigned char features[8];
 	struct hci_version version;
 	struct hci_conn_info_req *cr;
-	int opt, dd, cc = 0;
+	int opt, dd, cc = 0, to = 25000;
 
 	for_each_opt(opt, info_options, NULL) {
 		switch(opt) {
+		case 't':
+			to = atoi(optarg);
+			break;
+			
 		default:
 			printf(info_help);
 			return;
@@ -443,7 +448,7 @@
 	bacpy(&cr->bdaddr, &bdaddr);
 	cr->type = ACL_LINK;
 	if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0) {
-		if (hci_create_connection(dd, &bdaddr, htobs(HCI_DM1 | HCI_DH1), 0, 0, &handle, 25000) < 0) {
+		if (hci_create_connection(dd, &bdaddr, htobs(HCI_DM1 | HCI_DH1), 0, 0, &handle, to) < 0) {
 			perror("Can't create connection");
 			close(dd);
 			exit(1);
@@ -454,17 +459,17 @@
 
 	printf("\tBD Address:  %s\n", argv[0]);
 
-	if (hci_read_remote_name(dd, &bdaddr, sizeof(name), name, 25000) == 0)
+	if (hci_read_remote_name(dd, &bdaddr, sizeof(name), name, to) == 0)
 		printf("\tDevice Name: %s\n", name);
 
-	if (hci_read_remote_version(dd, handle, &version, 20000) == 0) {
+	if (hci_read_remote_version(dd, handle, &version, to) == 0) {
 		printf("\tLMP Version: %s (0x%x) LMP Subversion: 0x%x\n"
 			"\tManufacturer: %s (%d)\n",
 			lmp_vertostr(version.lmp_ver), version.lmp_ver, version.lmp_subver, 
 			bt_compidtostr(version.manufacturer), version.manufacturer);
 	}
 
-	if (hci_read_remote_features(dd, handle, features, 20000) == 0) {
+	if (hci_read_remote_features(dd, handle, features, to) == 0) {
 		printf("\tFeatures: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n%s\n",
 				features[0], features[1], features[2], features[3],
 				features[4], features[5], features[6], features[7],
@@ -472,7 +477,7 @@
 	}
 
 	if (cc)
-		hci_disconnect(dd, handle, HCI_OE_USER_ENDED_CONNECTION, 10000);
+		hci_disconnect(dd, handle, HCI_OE_USER_ENDED_CONNECTION, to);
 
 	close(dd);
 }
@@ -601,12 +606,13 @@
 	{"help",	0,0, 'h'},
 	{"role",	1,0, 'r'},
 	{"ptype",	1,0, 'p'},
+	{"to",	1,0, 't'},
 	{0, 0, 0, 0}
 };
 
 static char *cc_help = 
 	"Usage:\n"
-	"\tcc [--role=m|s] [--ptype=pkt_types] <bdaddr>\n"
+	"\tcc [--role=m|s] [--ptype=pkt_types] [--to=timeout] <bdaddr>\n"
 	"Example:\n"
 	"\tcc --ptype=dm1,dh3,dh5 01:02:03:04:05:06\n"
 	"\tcc --role=m 01:02:03:04:05:06\n";
@@ -614,12 +620,13 @@
 static void cmd_cc(int dev_id, int argc, char **argv)
 {
 	bdaddr_t bdaddr;
-	int opt, ptype, dd;
+	int opt, ptype, dd, to;
 	uint16_t handle;
 	uint8_t role;
 
 	role = 0;
 	ptype = HCI_DM1 | HCI_DM3 | HCI_DM5 | HCI_DH1 | HCI_DH3 | HCI_DH5;
+	to = 1000;
 
 	for_each_opt(opt, cc_options, NULL) {
 		switch(opt) {
@@ -630,6 +637,10 @@
 		case 'r':
 			role = optarg[0] == 'm' ? 0 : 1;
 			break;
+		
+		case 't':
+			to = atoi(optarg);
+			break;
 
 		default:
 			printf(cc_help);
@@ -660,7 +671,7 @@
 		exit(1);
 	}
 
-	if (hci_create_connection(dd, &bdaddr, htobs(ptype), 0, role, &handle, 1000) < 0)
+	if (hci_create_connection(dd, &bdaddr, htobs(ptype), 0, role, &handle, to) < 0)
 		perror("Can't create connection");
 	hci_close_dev(dd);
 }

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

end of thread, other threads:[~2004-06-14 16:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-09 13:48 [Bluez-devel] hci_create_connection assuming timeout too soon Andreas Gaufer
2004-06-12  9:45 ` Marcel Holtmann
2004-06-14 13:24   ` Steven Singer
2004-06-14 16:23     ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox