2006-12-03 18:30:08

by Mikael Lindqvist

[permalink] [raw]
Subject: [Bluez-users] Timeout for connections

Hello,

I would like to be able to set a timeout for service discoveries (and
eventually for rfcomm connections as well, but so far I've been
experimenting with service discoveries). For this I use non blocking
sockets by passing SDP_NON_BLOCKING to sdp_connect. Then I use select
with a timeout on the socket, and if it times out I call sdp_close.

The problem is that after I have done this I can't use the bluetooth
chip for other connections for some time. Dumping the traffic with
hcidump, I saw that this is because even though the l2cap socket is
closed, the bluetooth chip is still doing the connection in the
background. For this connection to actually get canceled the chip
needs to be sent a HCI_Create_Connection_Cancel command, but it is not
sent when the socket is closed.

To work around this I made some code to send this command myself
before calling sdp_close. This works, but the problem is that you need
to be root to send the HCI_Create_Connection_Cancel command. The
implication being that if you want to set a timeout for service
discovery, you need to be root. And this can't be the case, am I
thinking wrong in some fundamental way?

Or can this be considered a bug? shouldn't
HCI_Create_Connection_Cancel be sent automatically on some lower level
of bluez if you close an l2cap/rfcomm socket while it is connecting?

Or is there some other way to set a timeout for l2cap/rfcomm connections?

Thanks in advance,

Mikael

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users


2006-12-04 08:45:21

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-users] Timeout for connections

Hi Mikael,

> I ended up creating a little helper program that I run suid root that
> sets the Page Timeout on startup of my application. I also use this
> program to set the local name and try to force the inquiry mode to get
> RSSI. I have a feeling that you won't like hearing about this at all
> and you will probably take the opportunity to tell me I should use
> D-BUS. Something which I'm thinking about more and more. The problem
> with D-BUS is just that there is no Obex service available, and I
> don't want half my application using D-BUS and the other half not. So
> then I'm thinking more and more about writing a D-BUS Obex service.
> But before I do that it would be nice to get some feedback on the
> thoughts I have for that API. Where would be a good place to get that
> feedback? This mailing list is certanly one place, but what more is
> there?

first of all, you should call "man hcid.conf" and check the options for
setting the name and pageto. The inquiry mode is selected automatically
with bluez-utils-3.x and it picks the best one of course. In case of
Bluetooth 2.1 hardware this would mean of course extended inquiry. For
the bluez-utils-2.x we had the inqmode option to do it manually.

Even using D-Bus only for half of the tasks is still worth using D-Bus
for whatever possible. You can actually script most of the stuff very
easily with dbus-send or a small python program.

And yes, I have plans for a simple OBEX service that allows you to
handle incoming files, but also send files. However I have no idea when
I will get around to write that service. Feel free to start with it.

Regards

Marcel



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

2006-12-04 08:36:41

by Mikael Lindqvist

[permalink] [raw]
Subject: Re: [Bluez-users] Timeout for connections

Hi Marcel,

I ended up creating a little helper program that I run suid root that
sets the Page Timeout on startup of my application. I also use this
program to set the local name and try to force the inquiry mode to get
RSSI. I have a feeling that you won't like hearing about this at all
and you will probably take the opportunity to tell me I should use
D-BUS. Something which I'm thinking about more and more. The problem
with D-BUS is just that there is no Obex service available, and I
don't want half my application using D-BUS and the other half not. So
then I'm thinking more and more about writing a D-BUS Obex service.
But before I do that it would be nice to get some feedback on the
thoughts I have for that API. Where would be a good place to get that
feedback? This mailing list is certanly one place, but what more is
there?

-- Mikael

On 12/3/06, Marcel Holtmann <[email protected]> wrote:
> Hi Mikael,
>
> > > > I would like to be able to set a timeout for service discoveries (and
> > > > eventually for rfcomm connections as well, but so far I've been
> > > > experimenting with service discoveries). For this I use non blocking
> > > > sockets by passing SDP_NON_BLOCKING to sdp_connect. Then I use select
> > > > with a timeout on the socket, and if it times out I call sdp_close.
> > > >
> > > > The problem is that after I have done this I can't use the bluetooth
> > > > chip for other connections for some time. Dumping the traffic with
> > > > hcidump, I saw that this is because even though the l2cap socket is
> > > > closed, the bluetooth chip is still doing the connection in the
> > > > background. For this connection to actually get canceled the chip
> > > > needs to be sent a HCI_Create_Connection_Cancel command, but it is not
> > > > sent when the socket is closed.
> > >
> > > use a 2.6.19 kernel and this command will be sent.
> > >
> >
> > Oh ok... Haven't had to build my own kernel before but I guess there
> > is a first time for everything... I'm using ubuntu and they say it
> > won't be available until next version in april... Problem is that
> > there are people who I can't tell "build the latest kernel" who relies
> > on the software I'm developing... what to do...
>
> there is a chance that Fedora Core will update their kernel to 2.6.19
> very soon. Otherwise you are out of luck.
>
> > Is there another way I can set a timeout for connections?
>
> No. Only the kernel can keep track of connections. If you try to do it
> by yourself in userspace you will break more than you fix. The reference
> count for the ACL link is tricky and only the kernel has all needed
> information to do it right.
>
> Regards
>
> Marcel
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Bluez-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/bluez-users
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

2006-12-03 21:15:10

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-users] Timeout for connections

Hi Mikael,

> > > I would like to be able to set a timeout for service discoveries (and
> > > eventually for rfcomm connections as well, but so far I've been
> > > experimenting with service discoveries). For this I use non blocking
> > > sockets by passing SDP_NON_BLOCKING to sdp_connect. Then I use select
> > > with a timeout on the socket, and if it times out I call sdp_close.
> > >
> > > The problem is that after I have done this I can't use the bluetooth
> > > chip for other connections for some time. Dumping the traffic with
> > > hcidump, I saw that this is because even though the l2cap socket is
> > > closed, the bluetooth chip is still doing the connection in the
> > > background. For this connection to actually get canceled the chip
> > > needs to be sent a HCI_Create_Connection_Cancel command, but it is not
> > > sent when the socket is closed.
> >
> > use a 2.6.19 kernel and this command will be sent.
> >
>
> Oh ok... Haven't had to build my own kernel before but I guess there
> is a first time for everything... I'm using ubuntu and they say it
> won't be available until next version in april... Problem is that
> there are people who I can't tell "build the latest kernel" who relies
> on the software I'm developing... what to do...

there is a chance that Fedora Core will update their kernel to 2.6.19
very soon. Otherwise you are out of luck.

> Is there another way I can set a timeout for connections?

No. Only the kernel can keep track of connections. If you try to do it
by yourself in userspace you will break more than you fix. The reference
count for the ACL link is tricky and only the kernel has all needed
information to do it right.

Regards

Marcel



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

2006-12-03 19:22:48

by Mikael Lindqvist

[permalink] [raw]
Subject: Re: [Bluez-users] Timeout for connections

On 12/3/06, Marcel Holtmann <[email protected]> wrote:
> Hi Mikael,
>
> > I would like to be able to set a timeout for service discoveries (and
> > eventually for rfcomm connections as well, but so far I've been
> > experimenting with service discoveries). For this I use non blocking
> > sockets by passing SDP_NON_BLOCKING to sdp_connect. Then I use select
> > with a timeout on the socket, and if it times out I call sdp_close.
> >
> > The problem is that after I have done this I can't use the bluetooth
> > chip for other connections for some time. Dumping the traffic with
> > hcidump, I saw that this is because even though the l2cap socket is
> > closed, the bluetooth chip is still doing the connection in the
> > background. For this connection to actually get canceled the chip
> > needs to be sent a HCI_Create_Connection_Cancel command, but it is not
> > sent when the socket is closed.
>
> use a 2.6.19 kernel and this command will be sent.
>

Oh ok... Haven't had to build my own kernel before but I guess there
is a first time for everything... I'm using ubuntu and they say it
won't be available until next version in april... Problem is that
there are people who I can't tell "build the latest kernel" who relies
on the software I'm developing... what to do...

Is there another way I can set a timeout for connections?

-- Mikael

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

2006-12-03 18:40:36

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-users] Timeout for connections

Hi Mikael,

> I would like to be able to set a timeout for service discoveries (and
> eventually for rfcomm connections as well, but so far I've been
> experimenting with service discoveries). For this I use non blocking
> sockets by passing SDP_NON_BLOCKING to sdp_connect. Then I use select
> with a timeout on the socket, and if it times out I call sdp_close.
>
> The problem is that after I have done this I can't use the bluetooth
> chip for other connections for some time. Dumping the traffic with
> hcidump, I saw that this is because even though the l2cap socket is
> closed, the bluetooth chip is still doing the connection in the
> background. For this connection to actually get canceled the chip
> needs to be sent a HCI_Create_Connection_Cancel command, but it is not
> sent when the socket is closed.

use a 2.6.19 kernel and this command will be sent.

> To work around this I made some code to send this command myself
> before calling sdp_close. This works, but the problem is that you need
> to be root to send the HCI_Create_Connection_Cancel command. The
> implication being that if you want to set a timeout for service
> discovery, you need to be root. And this can't be the case, am I
> thinking wrong in some fundamental way?

Never ever do that this way. The kernel (and the kernel only) should
control the ACL links.

Regards

Marcel



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users