I try to understand how btmgmt work. I search command equal to:
sudo hciconfig -a hci0 lm master
I have try to use sudo btmon for dumping hci command but I have only this result:
# RAW Open: hciconfig (privileged) version...
with no op-code output, this not realy help me. Writing output to btsnoop format reveal some unknown op codes (btmon -a /tmp/btsnoop). With wireshark I have no HCI events, I don't understand.
Using sudo strace hciconfig... reveal socket and ioctl call with ioctl(ctl, HCISETLINKMODE, dr)
I read HCISETLINKMODE value and hciconfig function
but nothing about op-code to put the interface in MASTER or SLAVE mode. For some others btmgmt commands I use btmon output and the command op-code and I use op-code to search in mgmt-api.txt.
After reading that hciconfig would be deprecated, I'm trying to migrate commands using btmgmt and i just miss this one.
Any help is welcome. Thank you
Related
I want to use gatttool in a shell script.
What I want to achieve is similar to these:
Gatttool non-interactive mode --char-write
Gatttool in non interactive mode
How to use gatttool non-interactive mode
Gatttool Non-Interactive mode, multiple char-write-req
GATTTool fails to read/write characteristics
In interactive mode I can do this:
# gatttool -b xx:xx:xx:xx:xx:xx -I
[xx:xx:xx:xx:xx:xx][LE]> connect
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[xx:xx:xx:xx:xx:xx][LE]> char-write-cmd 0x0025 aabbcc
Notification handle = 0x0025 value: aa bb cc
Now if I run non-interactively:
# gatttool -b xx:xx:xx:xx:xx:xx --char-write --handle=0x0025 --value=aabbcc
It just hangs I need to break it with CTRL+C and does not send anything to the device.
Now, all questions above are recommending to use --char-write-req instead of --char-write.
But that it is misleading, as request and command mean different things.
My device does not accept request, only commands (even in interactive mode!). So trying to send the same data with request will fail:
# gatttool -b xx:xx:xx:xx:xx:xx -I
[xx:xx:xx:xx:xx:xx][LE]> connect
Attempting to connect to xx:xx:xx:xx:xx:xx
Connection successful
[xx:xx:xx:xx:xx:xx][LE]> char-write-req 0x0025 aabbcc
Error: Characteristic Write Request failed: Attribute can't be written
Now of course using the recommendations from the above questions (--char-write-req) will fail:
# gatttool -b xx:xx:xx:xx:xx:xx --char-write-req --handle=0x0025 --value=aabbcc
Characteristic Write Request failed: Attribute can't be written
So what is the non-interactive alternative of writing a characteristic command,
If I don't want to use any Python or similar overkills for this?
what I want to achieve in a test setup is:
running:
hcitool -i hci0 lescan --duplicates --passive
on one shell
and in parallel connect on another via
hcitool -i hci0 lecc <BTADDR>
The moment I issue the connect command the scan process exits.
Why is that? I thought choosing to scan --passive will allow a scan output while managing a connection?
Best,
If you are on kernel 3.2 and above use gatttool or bluetoothctl for LE connections. hcitool is deprecated and you should not be using them anymore. Compile and install latest bluez and use gatttool for LE connections. If your LE device is in the vicinity, you should be able to connect, read and write using gatttool directly:
say, your local BT adapter is hci0 and the remote device BD_ADDR is 12:22:33:44:55:66 then:
gatttool -i hci0 -b 12:22:33:44:55:66 -I
[12:22:33:44:55:66][LE]>connect
Attempting to connect to 12:22:33:44:55:66
Connection successful
[12:22:33:44:55:66][LE]>characteristics
Read manual and help to know more about gattool.
i am trying to create a BLE scan module via nodeJs and Bluez. I want to learn how to get mac address, minor, major and rssi values from the output of hcidump --raw command. I took a look at Radius Networks ibeacon_scan file but i still don't have a clue how i can do it with nodeJs. Can anyone help me with that? Thanks a lot
Try this: sudo hcidump -R -x
Then in a second terminal do your Bluetooth stuff
When I run this command which makes the ble device scanning for just 5 seconds only:
$ sudo timeout 5s hcitool -i hci0 lescan
the output is shown in the terminal screen.
But when I redirect the output to a file to save the addresses of the advertising devices, every time I run the command I find the file is empty and the output isn't visible in the terminal nor in the file.
The command I used:
$ sudo timeout 5s hcitool -i hci0 lescan > file.txt
What do I have to do in order to make hcitool correctly redirect its ouput to the file?
timeout by default sends a SIGTERM to the program. Looks like hcitool doesn't handle that gracefully. Instead use SIGINT (equivalent to ctrl-c).
sudo timeout -s SIGINT 5s hcitool -i hci0 lescan > file.txt
I am able to scan for all available bluetooth devices with hcitool or with my C program.
I can pair the device using it's address with a simple-agent python script.
I would like to know if I can also remove the paired device using either hcitool, hciconfig or some kind of bluetooth command.
I know the information of detected devices for the hci0 controller is stored in /var/lib/bluetooth/XX:XX:XX:XX:XX:XX, where XX:XX:XX:XX:XX is the address of the hci controller.
This would be useful for testing pairing, connecting and disconnecting devices.
For those using Ubuntu 20.04, here is the same command using the bluetoothctl command
#!/bin/bash
for device in $(bluetoothctl devices | grep -o "[[:xdigit:]:]\{8,17\}"); do
echo "removing bluetooth device: $device | $(bluetoothctl remove $device)"
done
bluez-test-device remove XX:XX:XX:XX:XX:XX
If you install the bluez-tools package, run this to unpair a bluetooth device :
bt-device -r xx:xx:xx:xx:xx:xx
where xx:xx:xx:xx:xx:xx is the address of the paired device.
As it is mentioned above on ashish's answer, you can us bluez-test-device to remove the device which that you already know its mac address. So the problem is to parse the mac address of the added devices.
With python or c or whatever you use,
1) list the devices with;
bluez-test-device list
and parse the output and get all the MAC addresses of the devices, add them to a list.
2) disconnect and remove the devices;
bluez-test-device disconnect <MAC ADDRESS>
bluez-test-device remove <MAC ADDRESS>
Command using bluetoothctl binary: for device in $(bluetoothctl devices | grep -vEi '(o que mais vc quer deixar aqui|samsung|jbl|wireless)' | awk '{print $2}'); do bluetoothctl remove $device; done
All these answers don't answer the headline "removing all Bluetooth devices"
I wrote this little bash script to remove all the Bluetooth devices that are listed in the bt-device -l
#!/bin/bash
for device in $(bt-device -l | grep -o "[[:xdigit:]:]\{11,17\}"); do
echo "removing bluetooth device: $device | $(bt-device -r $device)"
done
How to run?
Make a new file like <fileName>.sh and paste the code above.
Run chmod +x <fileName> to make the script executable
Run ./<fileName>.sh
Celebrate! All Bluetooth devices are removed now :)