I'm developing a C application on C.H.I.P. board (Debian Jessie on it) ; while I was able to scan for classic and BLE devices using the source code of hcitool scan and hcitool lescan that we can find in /tools/hcitool.c of bluez package, I can't pair with devices without interact with the prompt given by hcitool auth XX:XX:XX:XX:XX:XX or rfcomm bind "MY DEVICE" XX:XX:XX:XX:XX:XX. I need to bypass the prompt given by these function without having interaction with it. I tried to find which function call the prompt and it seems to be the IOCTL, but i can't understand how to avoid this step. Can anyone could help me?
Related
I'm working on a project where I need to establish connection between my computer and a Adafruit feather 32u4 with BLE incorporated.
Due to comments on lots of webs, I decided to use linux to do the job.
I got everything installed and I can connect my BLE with the PC successfully.
----MY CONNECTION PROCEDURE-----
I can even recieve data and send data between them with gatttool.
To connect both devices i use this commands:
sudo hcitool lescan
sudo gatttool -t random -b F6:E5:F4:A7:71:E6 -I
connect
The devices are connected correctly. I can use all the gatttool commands and they respond as expected.
----END OF CONNECTION PROCEDURE----
---MAIN PROBLEM---
I don't know how I could implement all the commands in a packed C program.
I need to be able to manage all the commands in the same program !! without using brute force with system().
It would be great if someone could show me how gatttool do its magic.
I mainly need to know how to get the data from Rx and how to send it to Tx via code not commands.
Note: I can supply any further information if needed.
My Raspberry Pi 3 can connect briefly to my Android mobile, but once I accept the connection on the Raspberry Pi, I get this error:
GDBus.Error:org.bluez.Error.Failed: No such file or directory. Try to connect manually.
Please help me on this.
You can fix that from Bluetooth control. Type $bluetoothctl as root then you will end up with Bluetooth shall. There you should type "power on" command. After that you can use "scan on" command to check connection.
to continue from Dinusha's answer, after you scan and find your device's ID (you should also be able to see it's name in parentheses) you'll need to pair with the device by doing
pair <device ID>
then connect with the device by doing
connect <device ID>
You'll be able to see status of the connection
There are cases where I use a separate bluetooth dongle for connections I don't want dropped
Raspbian Jessie has some issues as far as I know with the Bluetooth module. I'd recommend using bullseye or buster. Also, there are a couple issues regarding the newest kernel. Run the following command to see if your phone which you are willing to connect is listed:
sudo bluetoothctl devices
If your mobile device is still listed here and not paired on the mobile side, there is your problem. Remove the device using the following command in RPI:
sudo bluetoothctl remove <mac-adress-of-device>
My bluetooth adapter in Settings (on Ubuntu) can detect my AR Drone (MiniSpider) device. But using the simple Bluez code example to detect Bluetooth devices, I'm not able to detect the drone device. My code is exactly the same as the code in the before mentioned link. I can detect a phone using the code (if the phone has made itself visible).
Any idea what could be the problem?
Output from hcitool lescan: it successfully finds the drone bluetooth device.
sudo hcitool lescan
LE Scan ...
A0:14:31:48:8C:EB RS_W082091
A0:14:31:48:8C:EB RS_W082091
A0:14:31:48:8C:EB RS_W082091
The code snippet you are using is for scanning classic Bluetooth devices. This is the equivalent of using hcitool inq from the command line, in which case you'll probably not be able to detect your device.
However, the AR Drone seems to support Bluetooth Low Energy (BLE), and not classic Bluetooth. Therefore, using the inquiry method you were not able to detect it. If you use code that scan for BLE devices, you'll be able to find your device. You can have a look at the source for hcitool.c below:-
https://github.com/aguedes/bluez/blob/master/tools/hcitool.c
And then your starting point would be to use the hcitool lescan code:-
static void cmd_lescan(int dev_id, int argc, char **argv)
{
...
}
For a small project i am using libudev to get notification for USB devices plug-in/plug-out.
Is there any way of knowing which USB port was used to plug in the device via libudev.
Actually there are multiple ports available and it is necessary to know which one was used.
Any hints would be highly appreciated!
Using the lsusb command and doing a grep to find the line with the name of the device. This command will output all sorts of useful information about all connected USB devices. You can also use lsusb -v to get very detailed info.
Check out the manpage for lsusb
http://manpages.ubuntu.com/manpages/hardy/man8/lsusb.8.html
After a bit of a research i found that it is possible using libusb.
From here, libusb can be used to get a list of all devices plugged in , now the devices discovered using libudev can be checked in the list of devices available via libusb_get_device_list.
Further libusb_get_port_number could be used to get the port number for the same device.
I am looking for information, documentation, sample code or something else about the management of Bluetooth pairing/encryption in C under linux. Where can i find that ?
Regards,
Alban
The dominant bluetooth stack at the moment is Bluez; a good tutorial can be found at An Introduction to Bluetooth Programming
You can use hciconfig, which is a tool supplied as part of BlueZ. The actual pairing / encryption is done inside the BT device, not the host stack. You just configure the BT device using hciconfig to tell it whether to do authentication and encryption.
See hciconfig man page, specifically the auth/noauth and encrypt/noencrypt commands
AFAIK the pairing API is via D-Bus, which can be accessed in C.
See e.g. http://git.kernel.org/?p=bluetooth/bluez.git;a=blob;f=doc/adapter-api.txt;hb=HEAD and http://git.kernel.org/?p=bluetooth/bluez.git;a=blob;f=doc/agent-api.txt;hb=HEAD