2011-09-27 08:25:49

by Keng-Yu Lin

[permalink] [raw]
Subject: Bug: bluetooth not working after suspend/resume

Hi all:
Since kernel.org/bugzilla is dead for a while, I sent the bug report
here in hope to get more insight.

This is a long-lasting bug and happens across several distros with
different combinations of bluez/kernel verisions but shares much the
same symptom that bluetooth is not working after the resume. As seen
in the bug report below, it happens on a variety of different laptops
too.

Redhat:
https://bugzilla.redhat.com/show_bug.cgi?id=727106

Debian:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614929

Ubuntu:
https://launchpad.net/bugs/824144
https://launchpad.net/bugs/824633
https://launchpad.net/bugs/823467
https://launchpad.net/bugs/822705

Personally I did some investigation on the issue and found that
bluetoothd does not receive the HCI commands of read_bd_addr,
read_local_version, read_local_features, nor read_local_name. So in
bluez.plugins/hciops.c:device_devup_setup(), init_adapter() is not
called at resume.

It can be further confirmed by the attached patch of bluez. It is
ugly but can work around the bug as reported in some of the bug
trackers above.

I am looking for any advice to get it move on, for the debugging
and the fixing.

Thanks,
-kengyu


Attachments:
06-Fix-disabled-after-resume.patch (326.00 B)

2011-09-27 13:55:46

by sunil.kumar5

[permalink] [raw]
Subject: RE: Bug: bluetooth not working after suspend/resume

SGkgZXRzYW5nLExpbiwNCg0KSSB0aGluayB0aGlzIGlzc3VlIGlzIG9ic2VydmVkIHdoZW4gdGhl
IEZpcm13YXJlIGlzIGJlaW5nIGRvd25sb2FkZWQgdG8gQlQgbW9kdWxlIHdpdGggbW9yZSBsb2Fk
IG9uIENQVSh3aXRoIG90aGVyIGFjdGl2aXRpZXMpIGFuZCB0aGUgRmlybXdhcmUgZG93bmxvYWQg
dGFzayBub3QgZ2V0dGluZyBlbm91Z2ggb2YgQ1BVLg0KDQpTaW1pbGFyIGlzc3VlIHdhcyBvYnNl
cnZlZCB3aXRoIFdMMTI3MSBhbmQga2VybmVsIDIuNi4yOC4yLg0KDQpUaGFua3MgJiBSZWdhcmRz
LA0KU3VuaWwNCg0KLS0tLS1PcmlnaW5hbCBNZXNz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GFkZHJl
c3NlZCBvciBieSB0aGVpciBkZXNpZ25lZS4gSWYgdGhlIHJlYWRlciBvZiB0aGlzIG1lc3NhZ2Ug
aXMgbm90IHRoZSBpbnRlbmRlZCByZWNpcGllbnQsIHlvdSBhcmUgb24gbm90aWNlIHRoYXQgYW55
IGRpc3RyaWJ1dGlvbiBvZiB0aGlzIG1lc3NhZ2UsIGluIGFueSBmb3JtLCBpcyBzdHJpY3RseSBw
cm9oaWJpdGVkLiBJZiB5b3UgaGF2ZSByZWNlaXZlZCB0aGlzIG1lc3NhZ2UgaW4gZXJyb3IsIHBs
ZWFzZSBpbW1lZGlhdGVseSBub3RpZnkgdGhlIHNlbmRlciBhbmQgZGVsZXRlIG9yIGRlc3Ryb3kg
YW55IGNvcHkgb2YgdGhpcyBtZXNzYWdlDQoNCi0tDQpUbyB1bnN1YnNjcmliZSBmcm9tIHRoaXMg
bGlzdDogc2VuZCB0aGUgbGluZSAidW5zdWJzY3JpYmUgbGludXgtYmx1ZXRvb3RoIiBpbg0KdGhl
IGJvZHkgb2YgYSBtZXNzYWdlIHRvIG1ham9yZG9tb0B2Z2VyLmtlcm5lbC5vcmcNCk1vcmUgbWFq
b3Jkb21vIGluZm8gYXQgIGh0dHA6Ly92Z2VyLmtlcm5lbC5vcmcvbWFqb3Jkb21vLWluZm8uaHRt
bA0K

2011-09-27 13:52:11

by etsang

[permalink] [raw]
Subject: Re: Bug: bluetooth not working after suspend/resume

Hi Kenyu,
I am working on a similar BT issue. But it is on Android Gingerbread
kernel 2.6.25.7+. After a idle for a while the BT was not return any
inquiry result (if it was not), if turn off BT then it will not turn
again until a power cycle. On the kernal log it was showing problem
loading into the TI wl327x.
---
TIinit_7.2.31.bts
no proper response during fw download.
Do you you have a similar fw download failure when attempt to turn on
BT. Or might be a different issue?

Ed
On Tue, 2011-09-27 at 16:25 +0800, Keng-Yü Lin wrote:
> Hi all:
> Since kernel.org/bugzilla is dead for a while, I sent the bug report
> here in hope to get more insight.
>
> This is a long-lasting bug and happens across several distros with
> different combinations of bluez/kernel verisions but shares much the
> same symptom that bluetooth is not working after the resume. As seen
> in the bug report below, it happens on a variety of different laptops
> too.
>
> Redhat:
> https://bugzilla.redhat.com/show_bug.cgi?id=727106
>
> Debian:
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614929
>
> Ubuntu:
> https://launchpad.net/bugs/824144
> https://launchpad.net/bugs/824633
> https://launchpad.net/bugs/823467
> https://launchpad.net/bugs/822705
>
> Personally I did some investigation on the issue and found that
> bluetoothd does not receive the HCI commands of read_bd_addr,
> read_local_version, read_local_features, nor read_local_name. So in
> bluez.plugins/hciops.c:device_devup_setup(), init_adapter() is not
> called at resume.
>
> It can be further confirmed by the attached patch of bluez. It is
> ugly but can work around the bug as reported in some of the bug
> trackers above.
>
> I am looking for any advice to get it move on, for the debugging
> and the fixing.
>
> Thanks,
> -kengyu



Legal Disclaimer:
The information contained in this message may be privileged and confidential. It is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. If you have received this message in error, please immediately notify the sender and delete or destroy any copy of this message


2011-10-19 10:30:19

by Keng-Yu Lin

[permalink] [raw]
Subject: Re: [RFC] Bluez: Fix the adapter is not initialised after resume

Hi Luiz:
I'd just like to confirm that you patch fixes Dell Latitude 2110
with this bug.
Thanks for this.

On Thu, Oct 13, 2011 at 7:23 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi,
>
> On Thu, Oct 13, 2011 at 10:35 AM, Luiz Augusto von Dentz
> <[email protected]> wrote:
>>
>> Thanks for the patch, but I suspect this may cause some problems if we
>> didn't receive all the pending information, do you have bluetoothd
>> logs showing the sequence of the events leading to this?
>>
>> --
>
> Ive been able to reproduce it myself, it is not all the time that it
> happens but when it does happen it is because we missed a command
> (might be a kernel bug). We have a workaround for this already but it
> doesn't work most of the times because the adapter is not up so it
> doesn't accept commands, the following should fix the problem:
>
> diff --git a/plugins/hciops.c b/plugins/hciops.c
> index 9fb28c8..d0ba3ad 100644
> --- a/plugins/hciops.c
> +++ b/plugins/hciops.c
> @@ -1482,21 +1482,6 @@ static void read_local_name_complete(int index,
> read_local_name_rp *rp)
>
>        DBG("Got name for hci%d", index);
>
> -       /* Even though it shouldn't happen (assuming the kernel behaves
> -        * properly) it seems like we might miss the very first
> -        * initialization commands that the kernel sends. So check for
> -        * it here (since read_local_name is one of the last init
> -        * commands) and resend the first ones if we haven't seen
> -        * their results yet */
> -
> -       if (hci_test_bit(PENDING_FEATURES, &dev->pending))
> -               hci_send_cmd(dev->sk, OGF_INFO_PARAM,
> -                                       OCF_READ_LOCAL_FEATURES, 0, NULL);
> -
> -       if (hci_test_bit(PENDING_VERSION, &dev->pending))
> -               hci_send_cmd(dev->sk, OGF_INFO_PARAM,
> -                                       OCF_READ_LOCAL_VERSION, 0, NULL);
> -
>        if (!dev->pending && dev->up)
>                init_adapter(index);
>  }
> @@ -2502,8 +2487,31 @@ static void device_devup_setup(int index)
>        hci_send_cmd(dev->sk, OGF_HOST_CTL, OCF_READ_STORED_LINK_KEY,
>                                        READ_STORED_LINK_KEY_CP_SIZE, &cp);
>
> -       if (!dev->pending)
> +       if (!dev->pending) {
>                init_adapter(index);
> +               return;
> +       }
> +
> +       /* Even though it shouldn't happen (assuming the kernel behaves
> +        * properly) it seems like we might miss the very first
> +        * initialization commands that the kernel sends. So check for
> +        * it here and resend the ones we haven't seen their results yet */
> +
> +       if (hci_test_bit(PENDING_FEATURES, &dev->pending))
> +               hci_send_cmd(dev->sk, OGF_INFO_PARAM,
> +                                       OCF_READ_LOCAL_FEATURES, 0, NULL);
> +
> +       if (hci_test_bit(PENDING_VERSION, &dev->pending))
> +               hci_send_cmd(dev->sk, OGF_INFO_PARAM,
> +                                       OCF_READ_LOCAL_VERSION, 0, NULL);
> +
> +       if (hci_test_bit(PENDING_NAME, &dev->pending))
> +               hci_send_cmd(dev->sk, OGF_HOST_CTL,
> +                                       OCF_READ_LOCAL_NAME, 0, 0);
> +
> +       if (hci_test_bit(PENDING_BDADDR, &dev->pending))
> +               hci_send_cmd(dev->sk, OGF_INFO_PARAM,
> +                                       OCF_READ_BD_ADDR, 0, NULL);
>  }
>
>  static void init_pending(int index)
>
> --
> Luiz Augusto von Dentz
>

2011-10-13 11:23:01

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [RFC] Bluez: Fix the adapter is not initialised after resume

Hi,

On Thu, Oct 13, 2011 at 10:35 AM, Luiz Augusto von Dentz
<[email protected]> wrote:
>
> Thanks for the patch, but I suspect this may cause some problems if we
> didn't receive all the pending information, do you have bluetoothd
> logs showing the sequence of the events leading to this?
>
> --

Ive been able to reproduce it myself, it is not all the time that it
happens but when it does happen it is because we missed a command
(might be a kernel bug). We have a workaround for this already but it
doesn't work most of the times because the adapter is not up so it
doesn't accept commands, the following should fix the problem:

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 9fb28c8..d0ba3ad 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -1482,21 +1482,6 @@ static void read_local_name_complete(int index,
read_local_name_rp *rp)

DBG("Got name for hci%d", index);

- /* Even though it shouldn't happen (assuming the kernel behaves
- * properly) it seems like we might miss the very first
- * initialization commands that the kernel sends. So check for
- * it here (since read_local_name is one of the last init
- * commands) and resend the first ones if we haven't seen
- * their results yet */
-
- if (hci_test_bit(PENDING_FEATURES, &dev->pending))
- hci_send_cmd(dev->sk, OGF_INFO_PARAM,
- OCF_READ_LOCAL_FEATURES, 0, NULL);
-
- if (hci_test_bit(PENDING_VERSION, &dev->pending))
- hci_send_cmd(dev->sk, OGF_INFO_PARAM,
- OCF_READ_LOCAL_VERSION, 0, NULL);
-
if (!dev->pending && dev->up)
init_adapter(index);
}
@@ -2502,8 +2487,31 @@ static void device_devup_setup(int index)
hci_send_cmd(dev->sk, OGF_HOST_CTL, OCF_READ_STORED_LINK_KEY,
READ_STORED_LINK_KEY_CP_SIZE, &cp);

- if (!dev->pending)
+ if (!dev->pending) {
init_adapter(index);
+ return;
+ }
+
+ /* Even though it shouldn't happen (assuming the kernel behaves
+ * properly) it seems like we might miss the very first
+ * initialization commands that the kernel sends. So check for
+ * it here and resend the ones we haven't seen their results yet */
+
+ if (hci_test_bit(PENDING_FEATURES, &dev->pending))
+ hci_send_cmd(dev->sk, OGF_INFO_PARAM,
+ OCF_READ_LOCAL_FEATURES, 0, NULL);
+
+ if (hci_test_bit(PENDING_VERSION, &dev->pending))
+ hci_send_cmd(dev->sk, OGF_INFO_PARAM,
+ OCF_READ_LOCAL_VERSION, 0, NULL);
+
+ if (hci_test_bit(PENDING_NAME, &dev->pending))
+ hci_send_cmd(dev->sk, OGF_HOST_CTL,
+ OCF_READ_LOCAL_NAME, 0, 0);
+
+ if (hci_test_bit(PENDING_BDADDR, &dev->pending))
+ hci_send_cmd(dev->sk, OGF_INFO_PARAM,
+ OCF_READ_BD_ADDR, 0, NULL);
}

static void init_pending(int index)

--
Luiz Augusto von Dentz

2011-10-13 07:35:06

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [RFC] Bluez: Fix the adapter is not initialised after resume

Hi,

On Thu, Oct 13, 2011 at 4:35 AM, Keng-Yu Lin <[email protected]> wrote:
> init_adapter() is not called due to missing HCI commands of
> read_bd_addr, read_local_version, read_local_features,
> and read_local_name on some machines.
> ---
> ?plugins/hciops.c | ? ?4 ++--
> ?1 files changed, 2 insertions(+), 2 deletions(-)
>
> ?Please see the links of the bug in different distros:
> ? https://bugzilla.redhat.com/show_bug.cgi?id=727106
> ? http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614929
> ? https://launchpad.net/bugs/824144
> ? https://launchpad.net/bugs/824633
> ? https://launchpad.net/bugs/823467
> ? https://launchpad.net/bugs/822705
>
> ?It is confirmed that this patch fixes for Dell Latutude 2120
> ?and EeePC 1001PXD.
>
> diff --git a/plugins/hciops.c b/plugins/hciops.c
> index 9fb28c8..5f339c1 100644
> --- a/plugins/hciops.c
> +++ b/plugins/hciops.c
> @@ -2502,8 +2502,8 @@ static void device_devup_setup(int index)
> ? ? ? ?hci_send_cmd(dev->sk, OGF_HOST_CTL, OCF_READ_STORED_LINK_KEY,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?READ_STORED_LINK_KEY_CP_SIZE, &cp);
>
> - ? ? ? if (!dev->pending)
> - ? ? ? ? ? ? ? init_adapter(index);
> + ? ? ? DBG("dev->pending=%d", dev->pending);
> + ? ? ? init_adapter(index);
> ?}

Thanks for the patch, but I suspect this may cause some problems if we
didn't receive all the pending information, do you have bluetoothd
logs showing the sequence of the events leading to this?

--
Luiz Augusto von Dentz

2011-10-13 01:35:12

by Keng-Yu Lin

[permalink] [raw]
Subject: [RFC] Bluez: Fix the adapter is not initialised after resume

init_adapter() is not called due to missing HCI commands of
read_bd_addr, read_local_version, read_local_features,
and read_local_name on some machines.
---
plugins/hciops.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

Please see the links of the bug in different distros:
https://bugzilla.redhat.com/show_bug.cgi?id=727106
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614929
https://launchpad.net/bugs/824144
https://launchpad.net/bugs/824633
https://launchpad.net/bugs/823467
https://launchpad.net/bugs/822705

It is confirmed that this patch fixes for Dell Latutude 2120
and EeePC 1001PXD.

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 9fb28c8..5f339c1 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2502,8 +2502,8 @@ static void device_devup_setup(int index)
hci_send_cmd(dev->sk, OGF_HOST_CTL, OCF_READ_STORED_LINK_KEY,
READ_STORED_LINK_KEY_CP_SIZE, &cp);

- if (!dev->pending)
- init_adapter(index);
+ DBG("dev->pending=%d", dev->pending);
+ init_adapter(index);
}

static void init_pending(int index)
--
1.7.5.4