* [Bluez-devel] how to do asynchronous device inquiry?
@ 2004-06-29 2:43 Albert Huang
2004-06-29 4:33 ` James Cameron
2004-06-29 9:21 ` Marcel Holtmann
0 siblings, 2 replies; 8+ messages in thread
From: Albert Huang @ 2004-06-29 2:43 UTC (permalink / raw)
To: BlueZ Mailing List
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 www.blackhat.com
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] how to do asynchronous device inquiry?
2004-06-29 2:43 [Bluez-devel] how to do asynchronous device inquiry? Albert Huang
@ 2004-06-29 4:33 ` James Cameron
2004-06-29 21:37 ` Marcel Holtmann
2004-06-29 9:21 ` Marcel Holtmann
1 sibling, 1 reply; 8+ messages in thread
From: James Cameron @ 2004-06-29 4:33 UTC (permalink / raw)
To: Albert Huang; +Cc: BlueZ Mailing List
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 www.blackhat.com
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] how to do asynchronous device inquiry?
2004-06-29 2:43 [Bluez-devel] how to do asynchronous device inquiry? Albert Huang
2004-06-29 4:33 ` James Cameron
@ 2004-06-29 9:21 ` Marcel Holtmann
2004-06-29 18:30 ` Albert Huang
1 sibling, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2004-06-29 9:21 UTC (permalink / raw)
To: Albert Huang; +Cc: BlueZ Mailing List
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 www.blackhat.com
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] how to do asynchronous device inquiry?
2004-06-29 9:21 ` Marcel Holtmann
@ 2004-06-29 18:30 ` Albert Huang
2004-06-29 21:50 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: Albert Huang @ 2004-06-29 18:30 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: BlueZ Mailing List
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 <marcel@holtmann.org> 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
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] how to do asynchronous device inquiry?
2004-06-29 4:33 ` James Cameron
@ 2004-06-29 21:37 ` Marcel Holtmann
2004-06-30 1:48 ` James Cameron
0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2004-06-29 21:37 UTC (permalink / raw)
To: James Cameron; +Cc: Albert Huang, BlueZ Mailing List
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 www.blackhat.com
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] how to do asynchronous device inquiry?
2004-06-29 18:30 ` Albert Huang
@ 2004-06-29 21:50 ` Marcel Holtmann
0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2004-06-29 21:50 UTC (permalink / raw)
To: Albert Huang; +Cc: BlueZ Mailing List
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 www.blackhat.com
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] how to do asynchronous device inquiry?
2004-06-29 21:37 ` Marcel Holtmann
@ 2004-06-30 1:48 ` James Cameron
2004-06-30 9:09 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: James Cameron @ 2004-06-30 1:48 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Albert Huang, BlueZ Mailing List
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] how to do asynchronous device inquiry?
2004-06-30 1:48 ` James Cameron
@ 2004-06-30 9:09 ` Marcel Holtmann
0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2004-06-30 9:09 UTC (permalink / raw)
To: James Cameron; +Cc: Albert Huang, BlueZ Mailing List
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 www.blackhat.com
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2004-06-30 9:09 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-29 2:43 [Bluez-devel] how to do asynchronous device inquiry? Albert Huang
2004-06-29 4:33 ` James Cameron
2004-06-29 21:37 ` Marcel Holtmann
2004-06-30 1:48 ` James Cameron
2004-06-30 9:09 ` Marcel Holtmann
2004-06-29 9:21 ` Marcel Holtmann
2004-06-29 18:30 ` Albert Huang
2004-06-29 21:50 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox