Bluetooth Login Lag
zakuArbor opened this issue · 4 comments
If I wish to log into the machine without using bluetooth, the login process takes a few seconds because it is scanning for the device.
We need to think of how to allow signing in with password not be interfered by the bluetooth scanning.
An idea is to fork or create a thread to allow the user authenticate in whatever fashion they wish. One process/thread will allow the user to authenticate based on their password while the other process/thread will scan for the bluetooth device.
A new idea I have unrelated to the issue is to look at if the device is paired with the computer as another alternate way to authenticate. Currently the PAM module scans if the bluetooth is within its range. However, the library we are using is unable to scan devices that have weak bluetooth signals for some reason. If I can check if the bluetooth is currently paired with the device, then there is no need to do a scan since there is a connection which is only possible if the device is nearby. Though I do know bluetooth signal can stretch for a few meter which is a concern but that is another issue we will look at in some milestone.
I have separated the issue of logging in onto the system without bluetooth in #10
I tried looking into seeing what devices are paired. Here are some of my attempts for future documentations:
bluetoothctl paired-devices- tells us what devices have been paired before/var/lib/bluetooth/1C:36:BB:23:B5:CB- contains a list of MAC addresses of devices that has been paired before. Not much useful information other than for each device, there's a fileinfothat tells us if the device is trusted or blocked, what services it has connected before.Theattributefile tells us the uuid of the file. One neat thing I noticed was that the timestamp of the files are updated whenever I pair the device. However, I don't see how it can help us.bluetoothctl info- this tells me if the device is currently paired.
$ bluetoothctl info 20:DA:22:DE:0F:68 | grep Connected
Connected: no
$ bluetoothctl connect 20:DA:22:DE:0F:68
Attempting to connect to 20:DA:22:DE:0F:68
[CHG] Device 20:DA:22:DE:0F:68 Connected: yes
Connection successful
zaku@zaku-laptop:~$ bluetoothctl info 20:DA:22:DE:0F:68 | grep Connected
Connected: yes
However using a command to get the information seems very sloppy because I would be required to fork a process to get that information in C or write the entire program in bash and have the PAM just call an exec to the bash script. I guess I will be searching around for the source code to see what is going on.
Overall, there is a very big lack of documentation available for programming bluetooth in C. I think I will be learning most of how to work with bluetooth from the source code of Bluez and perhaps Gnome.
After looking at the source code, I realized Bluez uses gdbus. After reading documents and a lot of source code on Bluez and about GD Bus, I managed to authenticate via pairing my device with the laptop.
Commit 33e9b16a080237556c2a316ab2176d9ab4d33fad integrates bluetooth pairing login. Bluetooth scanning is still enabled but is used if no trusted devices are paired with the laptop.