2014-02-28 07:09:22

by Adam Lee

[permalink] [raw]
Subject: [PATCH BlueZ] core: retry connect_dbus() several times

Sometimes the hardware, especially which needs firmware patching, is not
yet ready when connect_dbus().

Signed-off-by: Adam Lee <[email protected]>
---
src/main.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/main.c b/src/main.c
index b3136fc..cf1f8fa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -491,6 +491,7 @@ int main(int argc, char *argv[])
GKeyFile *config;
guint signal, watchdog;
const char *watchdog_usec;
+ uint8_t reconnect_times = 3;

init_defaults();

@@ -527,9 +528,17 @@ int main(int argc, char *argv[])

parse_config(config);

- if (connect_dbus() < 0) {
- error("Unable to get on D-Bus");
- exit(1);
+ /* Reconnect several times in case the hardware is not ready */
+ while (reconnect_times--) {
+ if (connect_dbus() == 0)
+ break;
+
+ if (reconnect_times != 1) {
+ usleep(500 * 1000);
+ } else {
+ error("Unable to get on D-Bus");
+ exit(1);
+ }
}

if (option_experimental)
--
1.9.0


2014-02-28 14:10:41

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core: retry connect_dbus() several times

Hi Adam,

On Fri, Feb 28, 2014 at 1:22 PM, Anderson Lizardo
<[email protected]> wrote:
> Hi Adam,
>
> On Fri, Feb 28, 2014 at 3:31 AM, Adam Lee <[email protected]> wrote:
>> connect_dbus() fails sometimes with Intel 7260 bluetooth, sleeping 0.5s
>> before executing bluetoothd workarounds it. I assume the firmware
>> patching slows down hardware initialization then fails to connect.
>>
>> Any other possibility? I'm not a D-Bus guru :)
>
> Please provide more details, e.g. the bluetoothd logs showing the
> problems, btmon output and which steps you are using to reproduce it.
> If you are using bluetoothctl, tell us which commands you are using.

My guess is that either your driver is not using .setup hook to do the
firmware patching or it is returning before it has fully initialize
the hardware, so please also add more information what is happening on
the driver side.


--
Luiz Augusto von Dentz

2014-02-28 12:22:17

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core: retry connect_dbus() several times

Hi Adam,

On Fri, Feb 28, 2014 at 3:31 AM, Adam Lee <[email protected]> wrote:
> connect_dbus() fails sometimes with Intel 7260 bluetooth, sleeping 0.5s
> before executing bluetoothd workarounds it. I assume the firmware
> patching slows down hardware initialization then fails to connect.
>
> Any other possibility? I'm not a D-Bus guru :)

Please provide more details, e.g. the bluetoothd logs showing the
problems, btmon output and which steps you are using to reproduce it.
If you are using bluetoothctl, tell us which commands you are using.

Best Regards,
--
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil

2014-02-28 07:40:16

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core: retry connect_dbus() several times

Hi Adam,

>>> Sometimes the hardware, especially which needs firmware patching, is not
>>> yet ready when connect_dbus().
>>
>> this makes no sense. Connecting to D-Bus has nothing to do with
>> firmware patching. What are you exactly fixing here?
>
> connect_dbus() fails sometimes with Intel 7260 bluetooth, sleeping 0.5s
> before executing bluetoothd workarounds it. I assume the firmware
> patching slows down hardware initialization then fails to connect.
>
> Any other possibility? I'm not a D-Bus guru :)

it has nothing to do with D-Bus. You need to find the root cause.

Regards

Marcel


2014-02-28 07:31:13

by Adam Lee

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core: retry connect_dbus() several times

On Thu, Feb 27, 2014 at 11:15:01PM -0800, Marcel Holtmann wrote:
> Hi Adadm,
>
> > Sometimes the hardware, especially which needs firmware patching, is not
> > yet ready when connect_dbus().
>
> this makes no sense. Connecting to D-Bus has nothing to do with
> firmware patching. What are you exactly fixing here?

connect_dbus() fails sometimes with Intel 7260 bluetooth, sleeping 0.5s
before executing bluetoothd workarounds it. I assume the firmware
patching slows down hardware initialization then fails to connect.

Any other possibility? I'm not a D-Bus guru :)

--
Adam Lee
http://adam8157.info

2014-02-28 07:15:01

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core: retry connect_dbus() several times

Hi Adadm,

> Sometimes the hardware, especially which needs firmware patching, is not
> yet ready when connect_dbus().

this makes no sense. Connecting to D-Bus has nothing to do with firmware patching. What are you exactly fixing here?

Regards

Marcel


2014-03-03 07:15:18

by Adam Lee

[permalink] [raw]
Subject: Re: [PATCH BlueZ] core: retry connect_dbus() several times

On Fri, Feb 28, 2014 at 03:10:41PM +0100, Luiz Augusto von Dentz wrote:
> Hi Adam,
>
> On Fri, Feb 28, 2014 at 1:22 PM, Anderson Lizardo
> <[email protected]> wrote:
> > Hi Adam,
> >
> > On Fri, Feb 28, 2014 at 3:31 AM, Adam Lee <[email protected]> wrote:
> >> connect_dbus() fails sometimes with Intel 7260 bluetooth, sleeping 0.5s
> >> before executing bluetoothd workarounds it. I assume the firmware
> >> patching slows down hardware initialization then fails to connect.
> >>
> >> Any other possibility? I'm not a D-Bus guru :)
> >
> > Please provide more details, e.g. the bluetoothd logs showing the
> > problems, btmon output and which steps you are using to reproduce it.
> > If you are using bluetoothctl, tell us which commands you are using.
>
> My guess is that either your driver is not using .setup hook to do the
> firmware patching or it is returning before it has fully initialize
> the hardware, so please also add more information what is happening on
> the driver side.

Hi, all

Please check https://bugs.launchpad.net/bugs/1221618

It's already fixed in btusb. However, if it's related to initialization
as Luiz and I guessed, maybe other hardwares have this issue too, that's
the reason I submitted that harmless retry "workaround" into BlueZ.
(have no objection to NAK)

--
Adam Lee
http://adam8157.info