2004-06-29 02:43:00

by Albert Huang

[permalink] [raw]
Subject: [Bluez-devel] how to do asynchronous device inquiry?

hello,

Can somone point me to an example of how to do an asynchronous device
inquiry using bluez? I'd like to start an inquiry with an ioctl or
something like that, and then be notified either with signals or by
polling as devices are discovered. If this is currently not possible,
can you point me to which source files I could modify that would allow
me to do this? Thanks!

-albert


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit http://www.blackhat.com
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel


2004-06-30 09:09:34

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] how to do asynchronous device inquiry?

Hi James,

> > > You could certainly fork() a process to exec() hcitool, and when it
> > > finishes it could send the information to your program, through a pipe
> > > that your program is select()ing on, or something similar.
> >
> > very bad idea :(
>
> Aww, it's just another way to do it, that doesn't require as much
> dependency or learning. ;-)

It is not fork() that is bad. It the combination of exec() and hcitool
you propose to use. If you fork or use a thread then use hci_inquiry().

> > You don't looked into the details. The inquiry ioctl() is one way. The
> > other one is the HCI raw socket. Open and bind a device and then set an
> > event filter on it. Send an inquiry command according to the spec. and
> > listen for the incoming inquiry result events.
>
> I stand corrected.
>
> Albert, there is a good example of this in src/btctl-discovery-source.c
> in the libbtctl-0.4.1 package.
> http://usefulinc.com/software/gnome-bluetooth/
>
> btctl_discovery_source_new()
> The hci device is opened, then set O_NONBLOCK, and the event filters are
> set. There's no sign of binding.

If you use hci_open_dev() the binding is done by that call.

Regards

Marcel




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit http://www.blackhat.com
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2004-06-30 01:48:36

by James Cameron

[permalink] [raw]
Subject: Re: [Bluez-devel] how to do asynchronous device inquiry?

On Tue, Jun 29, 2004 at 11:37:35PM +0200, Marcel Holtmann wrote:
> James wrote:
> > You could certainly fork() a process to exec() hcitool, and when it
> > finishes it could send the information to your program, through a pipe
> > that your program is select()ing on, or something similar.
>
> very bad idea :(

Aww, it's just another way to do it, that doesn't require as much
dependency or learning. ;-)

> You don't looked into the details. The inquiry ioctl() is one way. The
> other one is the HCI raw socket. Open and bind a device and then set an
> event filter on it. Send an inquiry command according to the spec. and
> listen for the incoming inquiry result events.

I stand corrected.

Albert, there is a good example of this in src/btctl-discovery-source.c
in the libbtctl-0.4.1 package.
http://usefulinc.com/software/gnome-bluetooth/

btctl_discovery_source_new()
The hci device is opened, then set O_NONBLOCK, and the event filters are
set. There's no sign of binding.

btctl_discovery_source_send_inquiry()
is used to send the inquiry command, but returns immediately.

The surrounding code handles the data as it comes back, using the event
model; typical for a GNOME or glib based application.

Fascinating.

--
James Cameron

2004-06-29 21:50:02

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] how to do asynchronous device inquiry?

Hi Albert,

> sorry, I'm having a tough time finding this piece of code you mention.
> The interface to sourceforge mailing list archives is terrible. Do
> you remember around when you posted it?

no I don't know when I posted it. Use the Gmane archive.

Regards

Marcel




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit http://www.blackhat.com
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2004-06-29 21:37:35

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] how to do asynchronous device inquiry?

Hi James,

> You could certainly fork() a process to exec() hcitool, and when it
> finishes it could send the information to your program, through a pipe
> that your program is select()ing on, or something similar.

very bad idea :(

> You could use threads. Erk.

Possible, but not needed.

> But how to implement it asynchronously all in one process using an event
> model ... doesn't seem to be a way to do it. Maybe I just can't find
> it. Here's how I looked ...

You don't looked into the details. The inquiry ioctl() is one way. The
other one is the HCI raw socket. Open and bind a device and then set an
event filter on it. Send an inquiry command according to the spec. and
listen for the incoming inquiry result events.

> Warning though; in hci_request() in the hci_core.c file, all requests to
> the device are serialised. Multiple attempts to do hci_inquiry() will
> be queued.

It is impossible to run two inquiries at the same time. The Bluetooth
chip won't allow and even the HCI core don't accepts it. There is the
INQUIRY flag that will set if an inquiry is in progress.

Regards

Marcel




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit http://www.blackhat.com
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2004-06-29 18:30:00

by Albert Huang

[permalink] [raw]
Subject: Re: [Bluez-devel] how to do asynchronous device inquiry?

sorry, I'm having a tough time finding this piece of code you mention.
The interface to sourceforge mailing list archives is terrible. Do
you remember around when you posted it?

thanks.

-albert

On Tue, 29 Jun 2004 11:21:29 +0200, Marcel Holtmann <[email protected]> wrote:
>
> Hi Albert,
>
>
> > Can somone point me to an example of how to do an asynchronous device
> > inquiry using bluez? I'd like to start an inquiry with an ioctl or
> > something like that, and then be notified either with signals or by
> > polling as devices are discovered. If this is currently not possible,
> > can you point me to which source files I could modify that would allow
> > me to do this? Thanks!
>
> you must use the HCI raw socket interface for it. Some time ago I posted
> example code for integration into the GNOME Bluetooth subsystem. Check
> the mailing list archives.
>
> Regards
>
> Marcel
>
>

2004-06-29 04:33:56

by James Cameron

[permalink] [raw]
Subject: Re: [Bluez-devel] how to do asynchronous device inquiry?

G'day Albert,

You could certainly fork() a process to exec() hcitool, and when it
finishes it could send the information to your program, through a pipe
that your program is select()ing on, or something similar.

If you knew your application environment well, you could configure the
inquiry to take far less time. e.g. "hcitool inq --length=1" is
supposed to work for 1.28 seconds only, assuming no cache. If you can
change the inquiry parameters of the other device, you can help this to
go even faster.

I've tried running "hcitool inq --length=1" repeatedly until another
device is found. It doesn't seem as reliable as doing a full inquiry.

You could use threads. Erk.

But how to implement it asynchronously all in one process using an event
model ... doesn't seem to be a way to do it. Maybe I just can't find
it. Here's how I looked ...

Looking at tools/hcitool.c, an inquiry uses hci_inquiry() function, part
of libbluetooth1 on my system. I'm looking at 2.7.

In libbluetooth1, hci_inquiry() calls ioctl() to do the work. It passes
an hci_inquiry_req struct. I'm not sure what possible flag bits are
valid. IREQ_CACHE_FLUSH is the only one I can see defined.

The ioctl() is handled by kernel function hci_sock_ioctl() in
net/bluetooth/hci_sock.c which dispatches it to hci_inquiry() in
net/bluetooth/hci_core.c and there doesn't seem to be any clear support
for doing the inquiry asynchronously. I'm looking at 2.6.6.

Warning though; in hci_request() in the hci_core.c file, all requests to
the device are serialised. Multiple attempts to do hci_inquiry() will
be queued.

--
James Cameron


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit http://www.blackhat.com
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2004-06-29 09:21:29

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] how to do asynchronous device inquiry?

Hi Albert,

> Can somone point me to an example of how to do an asynchronous device
> inquiry using bluez? I'd like to start an inquiry with an ioctl or
> something like that, and then be notified either with signals or by
> polling as devices are discovered. If this is currently not possible,
> can you point me to which source files I could modify that would allow
> me to do this? Thanks!

you must use the HCI raw socket interface for it. Some time ago I posted
example code for integration into the GNOME Bluetooth subsystem. Check
the mailing list archives.

Regards

Marcel




-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit http://www.blackhat.com
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel