2011-01-12 07:02:01

by Zhangfei Gao

[permalink] [raw]
Subject: Any flag indicating bt/fm is ready to run "hcitool cmd"

Is there any flag indicating bt/fm is ready to run "hcitool cmd", ie,
"hciconfig hci0 up" is really finished.

We met error "Send failed: File descriptor in bad state", if run
hcitool immediately after "hciconfig hci0 up"
For example:
hciconfig hci0 up
hcitool cmd 3f 66 02 26 00 00 00 30

And it could be workaround adding sleep.
The reason is "hciconfig hci0 up" is asynchronous, when it return,
bt/fm is not ready in fact, so add sleep could solve the issue, but
still may fail in stress test since race condition.
We have test bit HCI_UP, but hcitool cmd still would failed, when
HCI_UP=1, which is set in hci_dev_open instead of handler.
How about HCI_RAW?

The question is any bit user place could check and then safe to send
any command via hcitool cmd.

Thanks in advance.


2011-01-13 12:26:22

by Johan Hedberg

[permalink] [raw]
Subject: Re: Any flag indicating bt/fm is ready to run "hcitool cmd"

Hi,

On Thu, Jan 13, 2011, zhangfei gao wrote:
> > The HCIDEVUP ioctl is at least synchronized with the open() callback for
> > the HCI driver so in that sense if the driver is working fine it should
> > be possible to send commands when it returns. There is however an issue
> > with existing kernels that HCIDEVUP doesn't wait for all of the kernels
> > own HCI commands to finish before returning to user space. There was a
> > patch sent for this some time ago which you might be interested in
> > trying: http://marc.info/?l=linux-bluetooth&m=129296529630642&w=4
>
> Really thanks Johan,
> The patch synchronize hci_dev_open, it solve the problem we met, and
> "hcitool cmd" could immediately send after "hciconfig hci0 up" without
> problem.

Good to hear that it's working now.

> By the way, is this patch already in the kernel?

At least it's in the bluetooth-next tree:
http://git.kernel.org/?p=linux/kernel/git/padovan/bluetooth-next-2.6.git;a=commitdiff;h=23bb57633df97ede067ea26f3cdc8a7ba2cd8109

Johan

2011-01-13 06:53:07

by Zhangfei Gao

[permalink] [raw]
Subject: Re: Any flag indicating bt/fm is ready to run "hcitool cmd"

On Wed, Jan 12, 2011 at 3:37 AM, Johan Hedberg <[email protected]> wrote:
> Hi,
>
> On Wed, Jan 12, 2011, zhangfei gao wrote:
>> Is there any flag indicating bt/fm is ready to run "hcitool cmd", ie,
>> "hciconfig hci0 up" is really finished.
>>
>> We met error "Send failed: File descriptor in bad state", if run
>> hcitool immediately after "hciconfig hci0 up"
>> For example:
>> hciconfig hci0 up
>> hcitool cmd 3f 66 02 26 00 00 00 30
>
> The HCIDEVUP ioctl is at least synchronized with the open() callback for
> the HCI driver so in that sense if the driver is working fine it should
> be possible to send commands when it returns. There is however an issue
> with existing kernels that HCIDEVUP doesn't wait for all of the kernels
> own HCI commands to finish before returning to user space. There was a
> patch sent for this some time ago which you might be interested in
> trying: http://marc.info/?l=linux-bluetooth&m=129296529630642&w=4

Really thanks Johan,
The patch synchronize hci_dev_open, it solve the problem we met, and
"hcitool cmd" could immediately send after "hciconfig hci0 up" without
problem.
By the way, is this patch already in the kernel?

>
> Johan
>

2011-01-12 08:37:26

by Johan Hedberg

[permalink] [raw]
Subject: Re: Any flag indicating bt/fm is ready to run "hcitool cmd"

Hi,

On Wed, Jan 12, 2011, zhangfei gao wrote:
> Is there any flag indicating bt/fm is ready to run "hcitool cmd", ie,
> "hciconfig hci0 up" is really finished.
>
> We met error "Send failed: File descriptor in bad state", if run
> hcitool immediately after "hciconfig hci0 up"
> For example:
> hciconfig hci0 up
> hcitool cmd 3f 66 02 26 00 00 00 30

The HCIDEVUP ioctl is at least synchronized with the open() callback for
the HCI driver so in that sense if the driver is working fine it should
be possible to send commands when it returns. There is however an issue
with existing kernels that HCIDEVUP doesn't wait for all of the kernels
own HCI commands to finish before returning to user space. There was a
patch sent for this some time ago which you might be interested in
trying: http://marc.info/?l=linux-bluetooth&m=129296529630642&w=4

Johan