Skip to contentSkip to conversation

d-bus or management api for beacon stuff

DISCUSSION Don Zickus 4 participants 11 messages Nov 23, 2016 – Nov 30, 2016 Bluetooth drivers

lore
Share & tools
lore

Don Zickus

author
#0 lore raw

Hi,

I was trying to write some code to continuously scan the bluetooth field for bluetooth devices sending advertising packets (ie beacon-mode).

These devices would come and go so I wanted to avoid the cache.

I noticed the D-Bus interface doesn't quite allow me to do this (as it caches the devices and I can't monitor the RSSI field). But I think the bluetooth management interface does. Is that the correct approach?

Cheers,
Don

#1 lore raw

Hi Don,

Quoted 4 lines · Don Zickus

Hi,

I was trying to write some code to continuously scan the bluetooth field for bluetooth devices sending advertising packets (ie beacon-mode).

That is tricky, if you have anyone else trying to use the adapter in this situation it will probably be blocked, we may add support for setting intervals but that will probably be a best effort in case there is no connection or other usage of the adapter by the system.

Quoted 1 line

These devices would come and go so I wanted to avoid the cache.

Beacon are not normally not connectable, connections and continuous advertisement don't go well together so we will probably have to reduce the intervals in order to maintain any traffic on the connections.

Quoted 3 lines

I noticed the D-Bus interface doesn't quite allow me to do this (as it caches the devices and I can't monitor the RSSI field). But I think the bluetooth management interface does. Is that the correct approach?

Yep you could in theory use the MGMT interface and manually add you beacon management on top, but I guess you don't want applications to do that since it would require root permissions to connect to the management socket, so making bluetoothd, via kernel?, to adjust the intervals is probably a better idea in the long run. We would probably have to maintain the biggest advertising window possible, and the consider:

1. Is it connectable/there any advertising instance that is connectable? If yes, the it has to adjust the window to allow them (perhaps using the default connection parameters).
2. In case of a connection is made the controller may not be able to advertise anymore, and in case it can still advertise we need to make sure it doesn't interrupt the connection (this is not very clear if the controller is suppose to manage this somehow).
3. Similar to the connection situation we may have application scanning, again there might be problems if the controller cannot scan while advertising we would probably have to stop advertising.

Signature · 1 line
Luiz Augusto von Dentz
author
#2 lore raw
Quoted 13 lines · Luiz Augusto von Dentz

Hi Don,

Quoted 4 lines · Don Zickus

Hi,

I was trying to write some code to continuously scan the bluetooth field for bluetooth devices sending advertising packets (ie beacon-mode).

That is tricky, if you have anyone else trying to use the adapter in this situation it will probably be blocked, we may add support for setting intervals but that will probably be a best effort in case there is no connection or other usage of the adapter by the system.

Quoted 6 lines
Quoted 1 line

These devices would come and go so I wanted to avoid the cache.

Beacon are not normally not connectable, connections and continuous advertisement don't go well together so we will probably have to reduce the intervals in order to maintain any traffic on the connections.

Hi Luiz,

Thanks for the response. I am wondering if I explained it wrong. I wasn't looking to do advertisements but instead scan for advertisements. I also don't plan to connect to any of the advertising device, just read the advertised data.

Quoted 13 lines
Quoted 4 lines

I noticed the D-Bus interface doesn't quite allow me to do this (as it caches the devices and I can't monitor the RSSI field). But I think the bluetooth management interface does. Is that the correct approach?

Yep you could in theory use the MGMT interface and manually add you beacon management on top, but I guess you don't want applications to do that since it would require root permissions to connect to the management socket, so making bluetoothd, via kernel?, to adjust the intervals is probably a better idea in the long run. We would probably have to maintain the biggest advertising window possible, and the consider:

Quoted 10 lines

1. Is it connectable/there any advertising instance that is connectable? If yes, the it has to adjust the window to allow them (perhaps using the default connection parameters).
2. In case of a connection is made the controller may not be able to advertise anymore, and in case it can still advertise we need to make sure it doesn't interrupt the connection (this is not very clear if the controller is suppose to manage this somehow).
3. Similar to the connection situation we may have application scanning, again there might be problems if the controller cannot scan while advertising we would probably have to stop advertising.

Hmm, as I said above, I am wondering if I explained it wrong.

I was wondering how much was already done because in reality, I was just going to mimic what android does on the phones with apple ibeacons except my machines stay put and the ibeacons travel.

Currently I was using 'hcitool lescan --duplicates' and 'hcidump' and trying to script that. But wanted to be smarter. :-)

Cheers,
Don

#3 lore raw

Hello Don,

Quoted 54 lines · Don Zickus
Quoted 13 lines · Luiz Augusto von Dentz

Hi Don,

Quoted 4 lines · Don Zickus

Hi,

I was trying to write some code to continuously scan the bluetooth field for bluetooth devices sending advertising packets (ie beacon-mode).

That is tricky, if you have anyone else trying to use the adapter in this situation it will probably be blocked, we may add support for setting intervals but that will probably be a best effort in case there is no connection or other usage of the adapter by the system.

Quoted 6 lines
Quoted 1 line

These devices would come and go so I wanted to avoid the cache.

Beacon are not normally not connectable, connections and continuous advertisement don't go well together so we will probably have to reduce the intervals in order to maintain any traffic on the connections.

Hi Luiz,

Thanks for the response. I am wondering if I explained it wrong. I wasn't looking to do advertisements but instead scan for advertisements. I also don't plan to connect to any of the advertising device, just read the advertised data.

Quoted 13 lines
Quoted 4 lines

I noticed the D-Bus interface doesn't quite allow me to do this (as it caches the devices and I can't monitor the RSSI field). But I think the bluetooth management interface does. Is that the correct approach?

Yep you could in theory use the MGMT interface and manually add you beacon management on top, but I guess you don't want applications to do that since it would require root permissions to connect to the management socket, so making bluetoothd, via kernel?, to adjust the intervals is probably a better idea in the long run. We would probably have to maintain the biggest advertising window possible, and the consider:

Quoted 10 lines

1. Is it connectable/there any advertising instance that is connectable? If yes, the it has to adjust the window to allow them (perhaps using the default connection parameters).
2. In case of a connection is made the controller may not be able to advertise anymore, and in case it can still advertise we need to make sure it doesn't interrupt the connection (this is not very clear if the controller is suppose to manage this somehow).
3. Similar to the connection situation we may have application scanning, again there might be problems if the controller cannot scan while advertising we would probably have to stop advertising.

Quoted 8 lines

Hmm, as I said above, I am wondering if I explained it wrong.

I was wondering how much was already done because in reality, I was just going to mimic what android does on the phones with apple ibeacons except my machines stay put and the ibeacons travel.

Currently I was using 'hcitool lescan --duplicates' and 'hcidump' and trying to script that. But wanted to be smarter. :-)

I am planning on doing a similar application as you describe and understood that you should be able to do much of what you want with the dbus API.
Have you taken a look at adapter/StartDiscovery?
It is documented at git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n12 You would then monitor the PropertiesChanged signal on the system dbus.

SetDiscoveryFilter might also be necessary/helpful.

Regards,
Barry

Quoted 7 lines

Cheers,
Don
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Hi Barry, Don,

Quoted 75 lines · Barry Byford

Hello Don,

Quoted 54 lines · Don Zickus
Quoted 13 lines · Luiz Augusto von Dentz

Hi Don,

Quoted 4 lines · Don Zickus

Hi,

I was trying to write some code to continuously scan the bluetooth field for bluetooth devices sending advertising packets (ie beacon-mode).

That is tricky, if you have anyone else trying to use the adapter in this situation it will probably be blocked, we may add support for setting intervals but that will probably be a best effort in case there is no connection or other usage of the adapter by the system.

Quoted 6 lines
Quoted 1 line

These devices would come and go so I wanted to avoid the cache.

Beacon are not normally not connectable, connections and continuous advertisement don't go well together so we will probably have to reduce the intervals in order to maintain any traffic on the connections.

Hi Luiz,

Thanks for the response. I am wondering if I explained it wrong. I wasn't looking to do advertisements but instead scan for advertisements. I also don't plan to connect to any of the advertising device, just read the advertised data.

Quoted 13 lines
Quoted 4 lines

I noticed the D-Bus interface doesn't quite allow me to do this (as it caches the devices and I can't monitor the RSSI field). But I think the bluetooth management interface does. Is that the correct approach?

Yep you could in theory use the MGMT interface and manually add you beacon management on top, but I guess you don't want applications to do that since it would require root permissions to connect to the management socket, so making bluetoothd, via kernel?, to adjust the intervals is probably a better idea in the long run. We would probably have to maintain the biggest advertising window possible, and the consider:

Quoted 10 lines

1. Is it connectable/there any advertising instance that is connectable? If yes, the it has to adjust the window to allow them (perhaps using the default connection parameters).
2. In case of a connection is made the controller may not be able to advertise anymore, and in case it can still advertise we need to make sure it doesn't interrupt the connection (this is not very clear if the controller is suppose to manage this somehow).
3. Similar to the connection situation we may have application scanning, again there might be problems if the controller cannot scan while advertising we would probably have to stop advertising.

Quoted 8 lines

Hmm, as I said above, I am wondering if I explained it wrong.

I was wondering how much was already done because in reality, I was just going to mimic what android does on the phones with apple ibeacons except my machines stay put and the ibeacons travel.

Currently I was using 'hcitool lescan --duplicates' and 'hcidump' and trying to script that. But wanted to be smarter. :-)

I am planning on doing a similar application as you describe and understood that you should be able to do much of what you want with the dbus API.
Have you taken a look at adapter/StartDiscovery?
It is documented at git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt#n12 You would then monitor the PropertiesChanged signal on the system dbus.

Quoted 1 line

SetDiscoveryFilter might also be necessary/helpful.

Yep, the SetDiscoveryFilter might be the way to go, the only missing part that it doesn't do right now is to disable duplicate filtering, but we might need some flag with a big warning that this will spam the bus like crazy or perhaps it can only be used along RSSI filtering, which is to prevent people to use advertisement/scanning APIs as a transport over D-Bus.

We could offer a file descriptor based solution for transport emulation using scanning/advertising to prevent spamming D-Bus but that has to play nicely with other application, either that or we only allow this over MGMT interface which is what we suggest in case there is no other use for Bluetooth in the system.

And btw, I wouldn't account Android and other mobile OSes allowing such raw access for much longer, it takes way too much power and can probably block any other Bluetooth peripheral to work, so it is probably only good to write packet sniffer and other debug tools on top of the system but it really offer nothing to the regular user.

Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw
Quoted 137 lines · Luiz Augusto von Dentz

Hi Barry, Don,

Quoted 116 lines · Barry Byford

Hello Don,

Quoted 96 lines · Don Zickus
Quoted 26 lines · Luiz Augusto von Dentz

Hi Don,

Quoted 7 lines · Don Zickus

Hi,

I was trying to write some code to continuously scan the bluetooth field
for bluetooth devices sending advertising packets (ie beacon- mode).

That is tricky, if you have anyone else trying to use the adapter in
this situation it will probably be blocked, we may add support for
setting intervals but that will probably be a best effort in case
there is no connection or other usage of the adapter by the system.

Quoted 3 lines

These devices would come and go so I wanted to avoid the cache.

Quoted 6 lines

Beacon are not normally not connectable, connections and continuous
advertisement don't go well together so we will probably have to
reduce the intervals in order to maintain any traffic on the connections.

Hi Luiz,

Thanks for the response.  I am wondering if I explained it wrong.  I wasn't
looking to do advertisements but instead scan for advertisements.  I also
don't plan to connect to any of the advertising device, just read the
advertised data.

Quoted 24 lines
Quoted 9 lines

I noticed the D-Bus interface doesn't quite allow me to do this (as it
caches the devices and I can't monitor the RSSI field).  But I think the
bluetooth management interface does. Is that the correct approach?

Yep you could in theory use the MGMT interface and manually add you
beacon management on top, but I guess you don't want applications to
do that since it would require root permissions to connect to the
management socket, so making bluetoothd, via kernel?, to adjust the
intervals is probably a better idea in the long run. We would probably
have to maintain the biggest advertising window possible, and the
consider:

Quoted 15 lines

1.  Is it connectable/there any advertising instance that is connectable? If yes, the it has to adjust the window to allow them
(perhaps using the default connection parameters). 2.  In case of a connection is made the controller may not be able to
advertise anymore, and in case it can still advertise we need to make
sure it doesn't interrupt the connection (this is not very clear if
the controller is suppose to manage this somehow).
3. Similar to the connection situation we may have application scanning, again there might be problems if the controller cannot scan
while advertising we would probably have to stop advertising.

Hmm, as I said above, I am wondering if I explained it wrong.

I was wondering how much was already done because in reality, I was just
going to mimic what android does on the phones with apple ibeacons except my
machines stay put and the ibeacons travel.

Quoted 3 lines

Currently I was using 'hcitool lescan --duplicates' and 'hcidump' and trying
to script that.  But wanted to be smarter. :-)

I am planning on doing a similar application as you describe and understood that you should be able to do much of what you want with the dbus API.
Have you taken a look at adapter/StartDiscovery?
It is documented at git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter- api.txt#n12
You would then monitor the PropertiesChanged signal on the system dbus.

Quoted 1 line

SetDiscoveryFilter might also be necessary/helpful.

Yep, the SetDiscoveryFilter might be the way to go, the only missing part that it doesn't do right now is to disable duplicate filtering, but we might need some flag with a big warning that this will spam the
bus like crazy or perhaps it can only be used along RSSI filtering, which is to prevent people to use advertisement/scanning APIs as a transport over D-Bus.

We could offer a file descriptor based solution for transport emulation using scanning/advertising to prevent spamming D-Bus but that has to play nicely with other application, either that or we only
allow this over MGMT interface which is what we suggest in case there is no other use for Bluetooth in the system.

Quoted 5 lines

And btw, I wouldn't account Android and other mobile OSes allowing such raw access for much longer, it takes way too much power and can probably block any other Bluetooth peripheral to work, so it is probably only good to write packet sniffer and other debug tools on top of the system but it really offer nothing to the regular user.

I have had to resort to using the HCI interface to work with scanning and advertising beacon packets.  I had mentioned in an earlier thread the issue with duplicates.  Not only do you end up with a lot of spam on the dbus interface you end up with an ever increasing number of bluetooth devices.  The Bluetooth mesh uses this transport, so I really would like to see a nice interface to support rx/tx of these packets.

author
#6 lore raw
Quoted 23 lines · Brennan Ashton
Quoted 17 lines
Quoted 1 line

SetDiscoveryFilter might also be necessary/helpful.

Yep, the SetDiscoveryFilter might be the way to go, the only missing part that it doesn't do right now is to disable duplicate filtering, but we might need some flag with a big warning that this will spam the
bus like crazy or perhaps it can only be used along RSSI filtering, which is to prevent people to use advertisement/scanning APIs as a transport over D-Bus.

We could offer a file descriptor based solution for transport emulation using scanning/advertising to prevent spamming D-Bus but that has to play nicely with other application, either that or we only
allow this over MGMT interface which is what we suggest in case there is no other use for Bluetooth in the system.

Quoted 5 lines

And btw, I wouldn't account Android and other mobile OSes allowing such raw access for much longer, it takes way too much power and can probably block any other Bluetooth peripheral to work, so it is probably only good to write packet sniffer and other debug tools on top of the system but it really offer nothing to the regular user.

Quoted 6 lines

I have had to resort to using the HCI interface to work with scanning and advertising beacon packets.  I had mentioned in an earlier thread the issue with duplicates.  Not only do you end up with a lot of spam on the dbus interface you end up with an ever increasing number of bluetooth devices.  The Bluetooth mesh uses this transport, so I really would like to see a nice interface to support rx/tx of these packets.

Hi,

Sorry for being ignorant (as I can't quite find the filter duplicate code other than the setting of the bit), but would throttling work here? Cap the duplicates at say every 100ms or 10x/second. That probably won't help with power consumption (unless start/stop of the radio is quick?).

Just trying to help move this along.. willing to code/test.

Cheers,
Don

#7 lore raw
Quoted 60 lines · Don Zickus
Quoted 37 lines · Brennan Ashton
Quoted 27 lines
Quoted 4 lines

SetDiscoveryFilter might also be necessary/helpful.

Yep, the SetDiscoveryFilter might be the way to go, the only missing
part that it doesn't do right now is to disable duplicate filtering,
but we might need some flag with a big warning that this will spam
the
bus like crazy or perhaps it can only be used along RSSI filtering,
which is to prevent people to use advertisement/scanning APIs as a
transport over D-Bus.

We could offer a file descriptor based solution for transport emulation using scanning/advertising to prevent spamming D-Bus but
that has to play nicely with other application, either that or we only
allow this over MGMT interface which is what we suggest in case there
is no other use for Bluetooth in the system.

Quoted 9 lines

And btw, I wouldn't account Android and other mobile OSes allowing
such raw access for much longer, it takes way too much power and can
probably block any other Bluetooth peripheral to work, so it is probably only good to write packet sniffer and other debug tools on
top of the system but it really offer nothing to the regular user.

Quoted 11 lines

I have had to resort to using the HCI interface to work with scanning
and advertising beacon packets.  I had mentioned in an earlier thread
the issue with duplicates.  Not only do you end up with a lot of spam
on the dbus interface you end up with an ever increasing number of bluetooth devices.  The Bluetooth mesh uses this transport, so I really
would like to see a nice interface to support rx/tx of these packets.

Hi,

Sorry for being ignorant (as I can't quite find the filter duplicate code
other than the setting of the bit), but would throttling work here?  Cap the
duplicates at say every 100ms or 10x/second.  That probably won't help with
power consumption (unless start/stop of the radio is quick?).

Quoted 5 lines

Just trying to help move this along..  willing to code/test.

Cheers,
Don

The thread I mentioned is here:
https://marc.info/?t=147345134200002&r=1&w=2

The constant of interest is this LE_SCAN_FILTER_DUP_ENABLE.  I had to recompile with this disabled because I never wanted the filter for my application.  I had proposed making this an option in the adaptor interface, but there did not seem to be any interest.

--Brennan

author
#8 lore raw
Quoted 27 lines · Brennan Ashton
Quoted 22 lines
Quoted 11 lines

I have had to resort to using the HCI interface to work with scanning
and advertising beacon packets.  I had mentioned in an earlier thread
the issue with duplicates.  Not only do you end up with a lot of spam
on the dbus interface you end up with an ever increasing number of bluetooth devices.  The Bluetooth mesh uses this transport, so I really
would like to see a nice interface to support rx/tx of these packets.

Hi,

Sorry for being ignorant (as I can't quite find the filter duplicate code
other than the setting of the bit), but would throttling work here?  Cap the
duplicates at say every 100ms or 10x/second.  That probably won't help with
power consumption (unless start/stop of the radio is quick?).

Quoted 5 lines

Just trying to help move this along..  willing to code/test.

Cheers,
Don

Quoted 7 lines

The thread I mentioned is here:
https://marc.info/?t=147345134200002&r=1&w=2

The constant of interest is this LE_SCAN_FILTER_DUP_ENABLE.  I had to recompile with this disabled because I never wanted the filter for my application.  I had proposed making this an option in the adaptor interface, but there did not seem to be any interest.

Hi Brennan,

Yup, I saw that thread earlier and that flag. I wasn't sure how that flag was being propagated. Does it go right to the device? I guess I thought the kernel was filtering duplicates, but perhaps not?

Cheers,
Don

#9 lore raw
Quoted 47 lines · Don Zickus
Quoted 37 lines · Brennan Ashton
Quoted 29 lines
Quoted 17 lines

I have had to resort to using the HCI interface to work with scanning
and advertising beacon packets.  I had mentioned in an earlier thread
the issue with duplicates.  Not only do you end up with a lot of
spam
on the dbus interface you end up with an ever increasing number of
bluetooth devices.  The Bluetooth mesh uses this transport, so I
really
would like to see a nice interface to support rx/tx of these packets.

Hi,

Sorry for being ignorant (as I can't quite find the filter duplicate
code
other than the setting of the bit), but would throttling work here?  Cap the
duplicates at say every 100ms or 10x/second.  That probably won't help with
power consumption (unless start/stop of the radio is quick?).

Quoted 5 lines

Just trying to help move this along..  willing to code/test.

Cheers,
Don

The thread I mentioned is here:
https://marc.info/?t=147345134200002&r=1&w=2

Quoted 6 lines

The constant of interest is this LE_SCAN_FILTER_DUP_ENABLE.  I had to
recompile with this disabled because I never wanted the filter for my
application.  I had proposed making this an option in the adaptor interface, but there did not seem to be any interest.

Hi Brennan,

Quoted 8 lines

Yup, I saw that thread earlier and that flag.  I wasn't sure how that flag
was being propagated.  Does it go right to the device?  I guess I thought
the kernel was filtering duplicates, but perhaps not?

Cheers,
Don

It is set in all the LE_SET_SCAN_ENABLE HCI requests so the device is doing the actual filtering.

author
#10 lore raw
In reply to Brennan Ashton
Quoted 14 lines · Brennan Ashton
Quoted 9 lines

Sorry for being ignorant (as I can't quite find the filter duplicate code
other than the setting of the bit), but would throttling work here?  Cap the
duplicates at say every 100ms or 10x/second.  That probably won't help with
power consumption (unless start/stop of the radio is quick?).

Quoted 5 lines

Just trying to help move this along..  willing to code/test.

Cheers,
Don

Quoted 7 lines

The thread I mentioned is here:
https://marc.info/?t=147345134200002&r=1&w=2

The constant of interest is this LE_SCAN_FILTER_DUP_ENABLE.  I had to recompile with this disabled because I never wanted the filter for my application.  I had proposed making this an option in the adaptor interface, but there did not seem to be any interest.

Hi Brennan,

Looking through the code, I am guessing you hacked up

net/bluetooth/hci_request.c::active_scan to set enable_cp.filter_dup = 0?

How did that turn out? Was there a lot of volume?

I am running 'hcitool lescan --duplicates' with a couple of cc2650 tags I have (one custom fw) and see about 20-25 adv/second. That doesn't seem so bad.

What type of numbers did you see?

Cheers,
Don