Skip to contentSkip to conversation

Input pairing broken again

DISCUSSION David Woodhouse 2 participants 7 messages Sep 13, 2008 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Using the wizard to pair with my Anycom BTM-100 mouse is broken by commit 58d8ea3c (Make discovery service routine to search for driver uuids.)

I think the pairing actually works OK, but it takes so long that the wizard times out, and doesn't bother to connect the new input device. Looking at the dump at http://david.woodhou.se/btmouse-fail.dump it seems to be taking about 30 seconds.

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#1 lore raw

Hi David,

Could you please provide us the output of bluetoothd -dn and dbus-monitor --system sender='org.bluez'?

If that is taking too long Im afraid we cannot search for drivers uuis thus searching for l2cap uuid seems to be the only alternative.

Signature · 2 lines
Luiz Augusto von Dentz
Engenheiro de Computação
#2 lore raw
In reply to David Woodhouse
Quoted 8 lines · David Woodhouse

Using the wizard to pair with my Anycom BTM-100 mouse is broken by commit 58d8ea3c (Make discovery service routine to search for driver uuids.)

I think the pairing actually works OK, but it takes so long that the wizard times out, and doesn't bother to connect the new input device. Looking at the dump at http://david.woodhou.se/btmouse-fail.dump it seems to be taking about 30 seconds.

src/device.c +7 -6
index b90861b..0e615be 100644
@@ -975,8 +975,9 @@ static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
 	bdaddr_t src;
 	uuid_t uuid;
 
-	/* Public browsing successful or Single record requested */
-	if (err < 0 || (!req->search_uuid && recs))
+	/* If we have a valid response and req->search_uuid == 1, then
+	   public browsing was successful -- we don't need any more */
+	if (err < 0 || (req->search_uuid == 1 && recs))
 		goto done;
 
 	update_services(req, recs);
@@ -984,8 +985,8 @@ static void browse_cb(sdp_list_t *recs, int err, gpointer user_data)
 	adapter_get_address(adapter, &src);
 
 	/* Search for mandatory uuids */
-	if (uuid_list[++req->search_uuid]) {
-		sdp_uuid16_create(&uuid, uuid_list[req->search_uuid]);
+	if (uuid_list[req->search_uuid]) {
+		sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
 		bt_search_service(&src, &device->bdaddr, &uuid, browse_cb, user_data, NULL);
 		return;
 	}
@@ -1057,7 +1061,7 @@ int device_browse(struct btd_device *device, DBusConnection *conn,
 		memcpy(&uuid, search, sizeof(uuid_t));
 		cb = search_cb;
 	} else {
-		sdp_uuid16_create(&uuid, uuid_list[req->search_uuid]);
+		sdp_uuid16_create(&uuid, uuid_list[req->search_uuid++]);
 		init_browse(req);
 		cb = browse_cb;
 	}
@@ -1072,7 +1076,7 @@ int device_browse(struct btd_device *device, DBusConnection *conn,
 						device, NULL);
 
 	return bt_search_service(&src, &device->bdaddr,
-					&uuid, browse_cb, req, NULL);
+					&uuid, cb, req, NULL);
 }
 
 struct btd_adapter *device_get_adapter(struct btd_device *device)
Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#3 lore raw

While we're at it, let's fix init_browse() not to abort completely when it finds one driver asking for a UUID that another driver already wanted, and to eliminate duplicates of the UUIDs in uuid_list[] too...

src/device.c +22 -4
index b90861b..cae29f8 100644
@@ -1022,11 +1023,29 @@ static void init_browse(struct browse_req *req)
 
 		for (i = 0; driver->uuids[i]; i++) {
 			char *uuid;
-
+			int j;
+
+			/* Eliminate duplicates of UUIDs in uuid_list[]... */
+			if (strlen(driver->uuids[i]) == 36 && 
+			    !strncmp(driver->uuids[i], "0000", 4) &&
+			    !strcasecmp(driver->uuids[i] + 8, 
+					"-0000-1000-8000-00805F9B34FB")) {
+				uint16_t uuid16 = strtol(driver->uuids[i],
+							 NULL, 16);
+				for (j = 0; uuid_list[j]; j++) {
+					if (uuid16 == uuid_list[j])
+						continue;
+				}
+					
+			}
+			/* ... and of UUIDs another driver already asked for */
 			if (g_slist_find_custom(req->uuids, driver->uuids[i],
-					(GCompareFunc) strcasecmp))
-				return;
-
+						(GCompareFunc) strcasecmp)) {
+				printf("match on %s: return\n", driver->uuids[i]);
+				continue;
+			}
+			printf("Add uuid %s for driver %s\n",
+			       driver->uuids[i], driver->name);
 			uuid = g_strdup(driver->uuids[i]);
 			req->uuids = g_slist_append(req->uuids, uuid);
 		}
Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#4 lore raw

Both seems good, but please use debug instead of printf. Btw does your first patch solves the problem?

Quoted 48 lines · David Woodhouse

While we're at it, let's fix init_browse() not to abort completely when it finds one driver asking for a UUID that another driver already wanted, and to eliminate duplicates of the UUIDs in uuid_list[] too...

src/device.c +22 -5
index b90861b..cae29f8 100644
@@ -1022,11 +1023,29 @@ static void init_browse(struct browse_req *req)
 
               for (i = 0; driver->uuids[i]; i++) {
                       char *uuid;
-
+                       int j;
+
+                       /* Eliminate duplicates of UUIDs in uuid_list[]... */
+                       if (strlen(driver->uuids[i]) == 36 &&
+                           !strncmp(driver->uuids[i], "0000", 4) &&
+                           !strcasecmp(driver->uuids[i] + 8,
+                                       "-0000-1000-8000-00805F9B34FB")) {
+                               uint16_t uuid16 = strtol(driver->uuids[i],
+                                                        NULL, 16);
+                               for (j = 0; uuid_list[j]; j++) {
+                                       if (uuid16 == uuid_list[j])
+                                               continue;
+                               }
+
+                       }
+                       /* ... and of UUIDs another driver already asked for */
                       if (g_slist_find_custom(req->uuids, driver->uuids[i],
-                                       (GCompareFunc) strcasecmp))
-                               return;
-
+                                               (GCompareFunc) strcasecmp)) {
+                               printf("match on %s: return\n", driver->uuids[i]);
+                               continue;
+                       }
+                       printf("Add uuid %s for driver %s\n",
+                              driver->uuids[i], driver->name);
                       uuid = g_strdup(driver->uuids[i]);
                       req->uuids = g_slist_append(req->uuids, uuid);
               }
 
--

David Woodhouse Open Source Technology Centre
[email protected] Intel Corporation

Signature · 2 lines
Luiz Augusto von Dentz
Engenheiro de Computação
#5 lore raw
Quoted 2 lines · Luiz Augusto von Dentz

Both seems good, but please use debug instead of printf. Btw does your first patch solves the problem?

Oops. I meant to remove the printf before I sent the patch :)

Have committed both to git://git.infradead.org/~dwmw2/bluez.git without the printf.

Before my first patch, look closely at the handling of req->search_uuid in browse_cb().

Note that it's incremented _every_ time we end up back in browse_cb().

Even when we've already finished going through the uuid_list[] array, and we're supposed to be iterating through req->uuids.

So what happens is we handle everything in the uuid_list[] until we reach the zero at the end. Then we handle the first item from req->uuids, then we trawl through the memory _after_ uuid_list[], treating it as more uuids to search for until we reach another zero. Then we handle the second item from req->uuids, then...

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#6 lore raw

Yep, it was obviously wrong, please send a pull request to Marcel so we can have this fixes upstream.

Signature · 2 lines
Luiz Augusto von Dentz
Engenheiro de Computação