2014-01-05 15:49:42

by Gianluca Anzolin

[permalink] [raw]
Subject: Re: A problem with "rfcomm bind" and wvdial

Hello,

I looked at your problem this afternoon and I think I know what's happening:
wvdial is opening the port with the flag O_NONBLOCK. As expected the rfcomm
code returns immediately instead of waiting for the BT connection to come
up. Then wvdial sends the AT commands and the writes fail.

In the past it worked because the carrier_raised() logic was open coded inside
the rfcomm code: it always waited for a successful or failed connection even
with a non-blocking tty.

But now the code uses the tty_port methods and won't wait for a successful
bluetooth connection on open().

But there is more: when wvdial terminates, it will set the CLOCAL flag for the
tty and this will result in the same behaviour described above, even without
setting the O_NONBLOCK flag. This will affect other users of the tty.

These two cases make clear that the use of carrier_raised() method was not that
fair after all: while that allowed us to remove some code we now have to work
around it to get the previous behaviour.

For example we could mask off the O_NONBLOCK flag before opening the port and
then restore it when the tty_port_open() is completed. We could do something
similar for the CLOCAL flag: always remove it in rfcomm_tty_set_termios().

The alternative is to remove the carrier_raised() method and wait for the BT
connection in rfcomm_dev_activate() like the old code did.

I'm CC-ing some people who know the code better than me to get a suggestion
on how to proceed.

Thank you,
Gianluca


2014-01-06 16:06:45

by Andrey Vihrov

[permalink] [raw]
Subject: Re: A problem with "rfcomm bind" and wvdial

Hello,

Thanks for the update. I applied the patch to the bluetooth-next
kernel and it seems to work as expected. I ran wvdial several times in a
row, and it was able to connect every time.

> On Sun, Jan 05, 2014 at 04:49:42PM +0100, Gianluca Anzolin wrote:
> > Hello,
> >
> > I looked at your problem this afternoon and I think I know what's happening:
> > wvdial is opening the port with the flag O_NONBLOCK. As expected the rfcomm
> > code returns immediately instead of waiting for the BT connection to come
> > up. Then wvdial sends the AT commands and the writes fail.
>
> Hi,
>
> could you please test the attached patch?
>
> If it works and people are ok with it I'll submit it along with the other fixes
> I already sent to the list.
>
> Thank you,
> Gianluca

--
Andrey Vihrov <[email protected]>


Attachments:
signature.asc (198.00 B)
This is a digitally signed message part

2014-01-06 11:33:53

by Gianluca Anzolin

[permalink] [raw]
Subject: Re: A problem with "rfcomm bind" and wvdial

On Sun, Jan 05, 2014 at 04:49:42PM +0100, Gianluca Anzolin wrote:
> Hello,
>
> I looked at your problem this afternoon and I think I know what's happening:
> wvdial is opening the port with the flag O_NONBLOCK. As expected the rfcomm
> code returns immediately instead of waiting for the BT connection to come
> up. Then wvdial sends the AT commands and the writes fail.

Hi,

could you please test the attached patch?

If it works and people are ok with it I'll submit it along with the other fixes
I already sent to the list.

Thank you,
Gianluca


Attachments:
(No filename) (550.00 B)
0001-rfcomm-always-wait-for-a-bt-connection-on-open.patch (5.18 kB)
Download all attachments