Skip to contentSkip to conversation

Apple Wireless Keyboard connection issue

DISCUSSION André Kühne 3 participants 8 messages Nov 16, 2010 – Nov 18, 2010 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hi everyone

I noticed the following on my system: After upgrading to bluez-4.79 connecting my Apple Wireless Keyboard does not work anymore. With bluez-4.77 the connection works just fine.

Please let me know if I could be of any help e.g. providing more detailed information.

Best regards
Andre

Signature · 2 lines
Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief!  
Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail
#1 lore raw
Quoted 4 lines · André Kühne

Hi everyone

I noticed the following on my system: After upgrading to bluez-4.79 connecting my Apple Wireless Keyboard does not work anymore. With bluez-4.77 the connection works just fine.

My Microsoft keyboard is not working too. That is probably due to commit abe7cd44124a from Johan. It should be fixed soon.

Signature · 2 lines
Gustavo F. Padovan
http://profusion.mobi
#2 lore raw

Hi Gustavo,

Quoted 7 lines · Gustavo F. Padovan
Quoted 3 lines · André Kühne

I noticed the following on my system: After upgrading to bluez-4.79 connecting my Apple Wireless Keyboard does not work anymore. With bluez-4.77 the connection works just fine.

My Microsoft keyboard is not working too. That is probably due to commit abe7cd44124a from Johan. It should be fixed soon.

The only real difference that patch makes is the reuse of the HCI socket inside hciops.c. Maybe that screws up the event filters somehow or something similar. I don't have a keyboard to verify a fix, but could you try the attached patch and see if it helps?

Johan

plugins/hciops.c +23 -14
index 9d25558..4492983 100644
@@ -338,31 +338,37 @@ static int hciops_encrypt_link(int index, bdaddr_t *dst, bt_hci_result_t cb,
 	uint32_t link_mode;
 	uint16_t handle;
 
+	dd = hci_open_dev(index);
+	if (dd < 0)
+		return -errno;
+
 	cr = g_malloc0(sizeof(*cr) + sizeof(struct hci_conn_info));
 	cr->type = ACL_LINK;
 	bacpy(&cr->bdaddr, dst);
 
-	err = ioctl(SK(index), HCIGETCONNINFO, cr);
+	err = ioctl(dd, HCIGETCONNINFO, cr);
 	link_mode = cr->conn_info->link_mode;
 	handle = cr->conn_info->handle;
 	g_free(cr);
 
-	if (err < 0)
-		return -errno;
+	if (err < 0) {
+		err = -errno;
+		goto fail;
+	}
 
-	if (link_mode & HCI_LM_ENCRYPT)
-		return -EALREADY;
+	if (link_mode & HCI_LM_ENCRYPT) {
+		err = -EALREADY;
+		goto fail;
+	}
 
 	memset(&cp, 0, sizeof(cp));
 	cp.handle = htobs(handle);
 
-	if (hci_send_cmd(SK(index), OGF_LINK_CTL, OCF_AUTH_REQUESTED,
-				AUTH_REQUESTED_CP_SIZE, &cp) < 0)
-		return -errno;
-
-	dd = dup(SK(index));
-	if (dd < 0)
-		return -errno;
+	if (hci_send_cmd(dd, OGF_LINK_CTL, OCF_AUTH_REQUESTED,
+				AUTH_REQUESTED_CP_SIZE, &cp) < 0) {
+		err = -errno;
+		goto fail;
+	}
 
 	cmd = g_new0(struct hci_cmd_data, 1);
 	cmd->handle = handle;
@@ -379,8 +385,7 @@ static int hciops_encrypt_link(int index, bdaddr_t *dst, bt_hci_result_t cb,
 	if (setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf)) < 0) {
 		err = -errno;
 		g_free(cmd);
-		close(dd);
-		return -err;
+		goto fail;
 	}
 
 	io = g_io_channel_unix_new(dup(SK(index)));
@@ -391,6 +396,10 @@ static int hciops_encrypt_link(int index, bdaddr_t *dst, bt_hci_result_t cb,
 	g_io_channel_unref(io);
 
 	return 0;
+
+fail:
+	close(dd);
+	return err;
 }
 
 /* End async HCI command handling */
#3 lore raw

Hi Johan

Quoted 8 lines · Johan Hedberg

Hi Gustavo,

Quoted 5 lines · Gustavo F. Padovan
Quoted 3 lines · André Kühne

I noticed the following on my system: After upgrading to bluez-4.79 connecting my Apple Wireless Keyboard does not work anymore. With bluez-4.77 the connection works just fine.

Quoted 8 lines
Quoted 2 lines

My Microsoft keyboard is not working too. That is probably due to commit abe7cd44124a from Johan. It should be fixed soon.

The only real difference that patch makes is the reuse of the HCI socket inside hciops.c. Maybe that screws up the event filters somehow or something similar. I don't have a keyboard to verify a fix, but could you try the attached patch and see if it helps?

I installed

http://www.kernel.org/pub/linux/bluetooth/bluez-4.79.tar.gz + hciops_encrypt.patch

but the patch does not work for me. For verification I downloaded

http://www.kernel.org/pub/linux/bluetooth/bluez-4.77.tar.gz

and compiled/installed it the same way (without the patch) and the connection works.

I did the same using bluez-4.78 with the result that both my keyboard and mouse failed to connect.

Best regards
Andre

#4 lore raw

Hi,

Quoted 19 lines · Andre Kuehne
Quoted 6 lines · Johan Hedberg
Quoted 5 lines · Gustavo F. Padovan
Quoted 3 lines · André Kühne

I noticed the following on my system: After upgrading to bluez-4.79 connecting my Apple Wireless Keyboard does not work anymore. With bluez-4.77 the connection works just fine.

Quoted 8 lines
Quoted 2 lines

My Microsoft keyboard is not working too. That is probably due to commit abe7cd44124a from Johan. It should be fixed soon.

The only real difference that patch makes is the reuse of the HCI socket inside hciops.c. Maybe that screws up the event filters somehow or something similar. I don't have a keyboard to verify a fix, but could you try the attached patch and see if it helps?

I installed

http://www.kernel.org/pub/linux/bluetooth/bluez-4.79.tar.gz + hciops_encrypt.patch

Quoted 7 lines

but the patch does not work for me. For verification I downloaded

http://www.kernel.org/pub/linux/bluetooth/bluez-4.77.tar.gz

and compiled/installed it the same way (without the patch) and the connection works.

I did the same using bluez-4.78 with the result that both my keyboard and mouse failed to connect.

Ok, so then it seems like abe7cd44124a might not be to blame. Could you do a proper git bisect so we can figure out exactly at which point this broke. abe7cd44124a is really the only commit touching HID code since 4.77 so this is starting to get a bit strange.

Johan

#5 lore raw
Quoted 28 lines · Johan Hedberg

Hi,

Quoted 25 lines · Andre Kuehne
Quoted 6 lines · Johan Hedberg
Quoted 5 lines · Gustavo F. Padovan
Quoted 3 lines · André Kühne

I noticed the following on my system: After upgrading to bluez-4.79 connecting my Apple Wireless Keyboard does not work anymore. With bluez-4.77 the connection works just fine.

Quoted 8 lines
Quoted 2 lines

My Microsoft keyboard is not working too. That is probably due to commit abe7cd44124a from Johan. It should be fixed soon.

The only real difference that patch makes is the reuse of the HCI socket inside hciops.c. Maybe that screws up the event filters somehow or something similar. I don't have a keyboard to verify a fix, but could you try the attached patch and see if it helps?

I installed

http://www.kernel.org/pub/linux/bluetooth/bluez-4.79.tar.gz + hciops_encrypt.patch

but the patch does not work for me. For verification I downloaded

   http://www.kernel.org/pub/linux/bluetooth/bluez-4.77.tar.gz

and compiled/installed it the same way (without the patch) and the connection works.

Quoted 9 lines
Quoted 1 line

I did the same using bluez-4.78 with the result that both my keyboard and mouse failed to connect.

Ok, so then it seems like abe7cd44124a might not be to blame. Could you do a proper git bisect so we can figure out exactly at which point this broke. abe7cd44124a is really the only commit touching HID code since 4.77 so this is starting to get a bit strange.

Johan

Please find attached my bisect results.

Best regards
Andre

Quoted 1 line

git bisect good

a352058752e541539b09e55124d411a534cc14af is the first bad commit commit a352058752e541539b09e55124d411a534cc14af

Author: Johan Hedberg <[email protected]>
Date:   Thu Nov 4 04:38:35 2010 +0200

Cache adapter address for quick lookup

:040000 040000 b7b14eb9f69c0b74ebda87b2fa40a4574f08be44 b96739e2d58fcc5a5c6654431ba49a36ee623932 M plugins

Quoted 1 line

git bisect log

git bisect start
# good: [b079cca768419d11e011cc5a7d59bc802226e633] Release 4.77
git bisect good b079cca768419d11e011cc5a7d59bc802226e633
# bad: [018c5b71748c178dcd2ffb0164c1d975788a2acc] Release 4.78
git bisect bad 018c5b71748c178dcd2ffb0164c1d975788a2acc
# good: [d5d0fa3be8f7a20d128dcbaf8fc529c38bc52395] Optimize device disconnect callback processing git bisect good d5d0fa3be8f7a20d128dcbaf8fc529c38bc52395
# good: [b67a8a42e6ea9c2d2b0877ac3832de75ec4e00e5] Fix bdaddr naming consistency
git bisect good b67a8a42e6ea9c2d2b0877ac3832de75ec4e00e5
# bad: [5295b6a0ab0ad67a27926273a3fbf61f02663219] Fix not ignoring case of uuid given to RegisterEndpoint git bisect bad 5295b6a0ab0ad67a27926273a3fbf61f02663219
# good: [db5266f0afedc33e2fd6fc3601c16498865f746d] Remove redundant tracking of ignored adapters git bisect good db5266f0afedc33e2fd6fc3601c16498865f746d
# bad: [a352058752e541539b09e55124d411a534cc14af] Cache adapter address for quick lookup git bisect bad a352058752e541539b09e55124d411a534cc14af
# good: [b289e54d53c332a51be483c1660a42c267991dd3] Remove redundant hci_devinfo call
git bisect good b289e54d53c332a51be483c1660a42c267991dd3

#6 lore raw

Hi Andre,

Quoted 7 lines · Andre Kuehne
Quoted 1 line

git bisect good

a352058752e541539b09e55124d411a534cc14af is the first bad commit commit a352058752e541539b09e55124d411a534cc14af

Author: Johan Hedberg <[email protected]>
Date:   Thu Nov 4 04:38:35 2010 +0200

Cache adapter address for quick lookup

That's actually not related to the HID issue. There's a later commit that fixed the general initialization issue that this commit caused.

I was now able to get hold of a Bluetooth keyboard and fixed the issue. The problem was indeed in the commit that Gustavo originally pointed out. It's just that my original patch for it was incomplete and so didn't properly fix the issue. Anyway, a proper fix has now been pushed to git. Please test with that.

Johan

#7 lore raw
Quoted 5 lines · Johan Hedberg

I was now able to get hold of a Bluetooth keyboard and fixed the issue. The problem was indeed in the commit that Gustavo originally pointed out. It's just that my original patch for it was incomplete and so didn't properly fix the issue. Anyway, a proper fix has now been pushed to git. Please test with that.

Thank you Johan and Gustavo, current git works fine for me.

Andre