How do you retrieve the advertising payload for a Bluetooth LE emitter in Linux?
Specifically, I've configured Arduinos and Raspberry Pis using hcitool to act as iBeacons.
What I'm looking for is a command to print out what the current advertising payload is for the device.
At Radius Networks, we put together a set of scripts that parse the iBeacon identifiers out of BLE advertisement detected on Linux. You can find a description of this here.
If you simply want to see the raw advertisement bytes, you can start scanning on Linux with:
sudo hcitool lescan --duplicates &
And then see the results with:
sudo hcidump --raw
More details are in the answer linked above.
Since libpcap-1.0+ now supports Bluetooth capture you can use Wireshark/tshark/tcpdump to capture and display Bluetooth packets - both BTLE and other packet types.
To capture the LE packets with Wireshark you will still need to tell the Bluetooth interface to query for LE packets, as mentioned in the previous answer:
sudo hcitool lescan --duplicates &
In addition if you want the adapter to do a periodic query for Bluetooth devices, which are in discoverable mode, you can run (though these queries won't pick up BTLE emissions):
sudo hcitool spinq
sudo hcitool lescan --duplicates &
sudo hcitool spinq
Both commands runs an infinite loop
how to run a finite loop and get the data
Related
I have a Raspberry Py OS based on Debian Stretch broadcasting an iBeacon with my UUID and Major/Minor. Through an APP built by our team, I was able to identify it by the UUID and read its Major/Minor.
Now, I'll have to read this same iBeacon through Chrome Browser. However, I am not being able to broadcast with the iBeacon a meaningful name to help the user to find the device,
it only shows to me "Unknown or unsupported device"
As far as I could understand from iBeacon and AltBeacon, it isn't possible to send extra data in addition to UUID and Major/Minor. Is this correct? Is it possible to advertise this information within the beacon frame?
Command used to advertise the beacon.
sudo hciconfig hci0 leadv 3
sudo hcitool -i hci0 cmd 0x08 0x0008 1E 02 01 06 1A FF 4C 00 02 15 <<UUID>> <<Major/Minor>> C8 00
Consulting the Specification of the Bluetooth System I tried to change several name or ID features, none of them worked, such as:
sudo hcitool -i hci0 cmd 0x03 0x0013 <<Local Name>>
sudo hcitool -i hci0 cmd 0x03 0x0014
I would like to ask the community if it is possible to advertise this name while using beacons or if I should start using a GATT server to perform it.
Thank you all in advance.
Yes, it is possible for Linux to advertise both the local name and the iBeacon manufacturer advertisement. The way you are setting it up is correct, so it's unclear why you aren't seeing it in the Chrome web browser.
One thing to know is that the local name is not advertised in the same packet along with the iBeacon data that you show in your question. (There simply isn't room in the main advertising packet.) Instead, the local name is put in what is called a scan response packet. This is an additional packet that a Bluetooth LE Peripheral will send out in response to an active scan request packet from the Bluetooth LE Central (e.g. your Chrome device). It may be that Chrome does not send out scan request packets, which is why it won't read the local name.
You can confirm this by using a different device (like an Android or iOS phone using the Nordic nRF Connect Bluetooth test app) to see if they read the local name during a scan.
If you find that this these other devices do read the local name, then your next step would be to try to configure Chrome to do an active scan so it requests the scan response packets. It's unclear how or if this is possible.
I am using #abandonware/noble for scanning and interrogating Bluetooth devices on Linux. I could not, however, find a method to add a MAC address to the LE whitelist, similar to hcitool lewladd on Linux. Is there a way to do it using noble?
I am having issues using tshark to capture BTLE advertising packets.
The system works very well with Wireshark. However, when I try to run tshark from the command line, it immediately quits and says "0 packets captured."
Any ideas why it may be working in Wireshark but not in Tshark?
Setup:
I am using the nRF51 DK for the sniffer. This works well in Wireshark (version 2.6.1) as I mentioned. I have a peripheral device that is sending advertising packets that Wireshark easily detects (i.e. I know the hardware works and there are advertising packets being sent).
Command used:
After navigating to my Wireshark folder on the command line, I type:
tshark -i 6 -a duration:10
My nRF sniffer is interface 6. Everything is run on a Windows 10 machine.
Further Info:
Tshark works correctly if I try to capture wifi
tshark -i 1 -a duration:10
where interface 1 is the wifi interface.
Thanks!
Just had confirmation from Nordic that the nRF-sniffer is not currently supported by TShark.
I'm working on setting up two Linux systems for a BLE demo. Obviously one system will be the peripheral and one will be the central devices. I have several questions surrounding both of these configurations.
Environment
2x Ubuntu 14.04 systems
2x Pluggable USB-BT4LE dongles (http://plugable.com/products/usb-bt4le)
Peripheral Device Setup
The first order of business is getting the peripheral system setup and advertising with a GATT server configured. At this time, it does not seem possible to configure a GATT server from the command line. So, while it is a simple task bringing a USB dongle up and advertising it, this does not allow the creation of custom services and characteristics. The only example of a GATT server I could find was the gatt-example.c file in the Bluez package. So I downloaded and built the latest bluez-5.23 source. (http://www.linuxfromscratch.org/blfs/view/svn/general/bluez.html). Additionally configured using the --enable-maintainer-mode flag to force build the gatt-example.c plugin into bluetoothd. And I validated post-build from the ~/bluez-5.23/plugins directory that there was a bluetoothd-gat-example.o file. Which tells me that the gatt-example was at least successfully built.
I then modified the configuration file to enable LE and the attribute server.
$ sudo vi /etc/bluetooth/main.conf
EnableLE = true // Enable Low Energy support. Default is false.
AttributeServer = true // Enable the GATT attribute server. Default is false.
Then simply reboot or restart the bluetooth daemon...
Central Device Setup
As the central device does not need any special plugins built like the peripheral, I just installed bluez using apt-get. This appears to have installed v4.101 according to bluetoothd -v.
Session Setup
The connection process then should be fairly simple. I setup the peripheral to advertise and then connect with the central device:
Peripheral:
$ sudo hciconfig hci0 up // Make sure the interface is up
$ sudo hciconfig hci0 leadv // Set the interface to advertise
Central:
$ sudo hcitool -i hci0 lescan // Scan for nearby devices advertising
LE Scan ...
00:02:72:C9:5E:0F (unknown) // Not sure why two of the same MAC are found?
00:02:72:C9:5E:0F (unknown) // but I know this is my device...
$ sudo gatttool -i hci0 -b 00:02:72:C9:5E:0F -m 48 --interactive // Connect interactively
[ ][00:02:72:C9:5E:0F][LE]> connect
[CON][00:02:72:C9:5E:0F][LE]> primary
attr handle: 0x0001, end grp handle: 0x0008 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0010, end grp handle: 0x0010 uuid: 00001801-0000-1000-8000-00805f9b34fb
[CON][00:02:72:C9:5E:0F][LE]> characteristics
handle: 0x0004, char properties: 0x02, char value handle: 0x0006, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0007, char properties: 0x02, char value handle: 0x0008, uuid: 00002a01-0000-1000-8000-00805f9b34fb
And we see not one of the services or characteristics from the gatt-example are available.
Questions
--Peripheral Device
How would I go about creating my own custom GATT server? Can it be a stand-alone C application or does it need to be built into bluetoothd as a plugin like the gatt-example? The answer to this question (Creating a Gatt Server?) implies you do the following: "start by initializing the GATT library and additional modules" and then "register your GATT database". But there isn't a single example of how to implement those generic statements and the link provided is simply a URL to the Bluetooth website.
The GATT specifications (https://developer.bluetooth.org/gatt/Pages/default.aspx) provide numerous "adopted" services and characteristics that are downloadable in XML format. But there is no instructions for how to use them?!
How do a validate my GATT server is running?
--Central Device
Why is my central device not seeing the services and characteristics from the GATT server running on the peripheral?
I can provide any additional information necessary. Thanks.
To create a GATT server into a separate process you have (at least) two cases:
Bluez v4.x: your GATT service must be a Bluez plugin
Bluez v5.x: your GATT service should use the new GATT DBus API (but it is recommended to use at least Bluez v5.39 (from April 2016). Otherwise it is safer (in term of Bluez GATT Server API) to use the Bluez v4.x plugin approach.
If your Central Device does not see the newly exported GATT service is probably an issue on the periphal rather than to be an issue on the Central Device.
When you will need to implement the GATT client on the Central Device you still have two cases:
Bluez v4.x: Bluez does not expose the GATT API. Either you use a shell script to launch gatttool commands, or you use a GATT library such as gattlib to interact with the BLE device
Bluez v5.x: Same thing, if you cannot migrate to Bluez v5.39 then it is better to use Bluez v4.x methodology.
I am working on using the Bluetooth low energy modem with Linux. I am using the command line option for that i.e. hcitool . I am able to the find the devices using the command: $ hcitool scan
It is working fine for me, also I am able to broadcast my device using :
sudo hciconfig hci0 leadv
It is also working fine. But I want to add the services and characteristic to the modem device which can be detected by other device. I have tried sdptool add but it is not working for me. Does anyone know how to add the services and characteristics to the peripheral using the command line tools in ubuntu?
Edit: My modem is broadcasting but not able to explore the services and characteristic to the other BLE device. Now I am able to set the name of device using hcio name command
Edit: Now I am able to render the services and characteristic, by simultaneously running sudo hcidump command. But I am not able to track from where I am getting those services and characteristics. One definite observation is those services are rendering from the machine.
SDP is absent in BLE. Broadcast/advertise frame and GATT client/server are used instead.
Several links:
BlueZ gatttool: command line tool to run common GATT procedures
BlueZ GATT's ready profiles
hint: DBUS
GATT and DBUS example
How can I connect to the FitBit Zip over Bluetooth 4.0 LE on Linux with bluez?
Bluetooth Low Energy: listening for notifications/indications in linux
http://comments.gmane.org/gmane.linux.bluez.kernel/29547
I used to broadcast BT services by following this article. This page not only shouws you how to advertise a profile, but also gives you an example on how to implement the HSP profile.
To know the bt class you need to announce, you can check this other page.