Bluetooth, Kali, and the Pi

10-11-2021 Written by: otter-admin


Getting the Bluetooth Keyboard Working


I'm writing a separate post about the bluetooth keyboard setup. I struggled to get this to work, if you did as well, follow along here and yours should work as well. Part of this I started to use a shotgun approach so don't blindly install everything. I'll make a note where there were things I don't think were necessary.  Note - ignore the colored text. I'm trying different ways to separate the code from the text. :)


First running this we can see there isn't a bluetooth connection available. 

┌──(kali㉿kali)-[~]
└─$ sudo rfkill list            
0: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no


Next I tried enabling and starting the bluetooth service.        

┌──(kali㉿kali)-[~]
└─$ sudo systemctl enable bluetooth   
┌──(kali㉿kali)-[~]
└─$ sudo service bluetooth start  
┌──(kali㉿kali)-[~]
└─$ sudo service bluetooth status  
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: disabled)
     Active: inactive (dead)
       Docs: man:bluetoothd(8)


Here you can see bluetooth is there but it's inactive, no amount of turning it on would help. I also tried bluetoothctl as below but there was no default device avaialble anywhere. 

┌──(kali㉿kali)-[~]
└─$ sudo bluetoothctl  


Next I installed bluedevil. Here is the issue where I started installing stuff and not checking - I don't if you actually need bluedevil. So after a restart if your bluetooth status still isn't working go ahead and install it. You don't need bluedevil, but I think there might be a package that comes with it it. 


My next status check showed bluetooth was active. However I still couldn't connect the keyboard. I'd try thought the GUI and it would connect and then immediately disconnect. 

┌──(kali㉿kali)-[~]
└─$ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: disabled)
     Active: active (running) since Mon 2021-10-11 23:57:56 UTC; 9min ago
       Docs: man:bluetoothd(8)
   Main PID: 18413 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 9300)
        CPU: 51ms
     CGroup: /system.slice/bluetooth.service
             └─18413 /usr/libexec/bluetooth/bluetoothd

             

Final step was getting this to start. Running it as wouldn't start. I didn't caputre the error but it something along the lines of no such module. I fixed that by installing pi-bluetooth             

┌──(kali㉿kali)-[~]
└─$ sudo apt-get install pi-bluetooth 


Reboot the pi now and once back up enter these next commands.

┌──(kali㉿kali)-[~]
└─$ sudo systemctl enable hciuart
┌──(kali㉿kali)-[~]
└─$ systemctl start hciuart


Finally bluetooth is here in the list and it's not blocked.                                                                        

┌──(kali㉿kali)-[~]
└─$ rfkill list
0: phy0: Wireless LAN
        Soft blocked: no
        Hard blocked: no
1: hci0: Bluetooth
        Soft blocked: no
        Hard blocked: no


Next start up bluetoothctl and connect the keyboard.        

┌──(kali㉿kali)-[~]
└─$ sudo bluetoothctl            
Agent registered
[bluetooth]# power on
[bluetooth]# scan on
Discovery started
[DEL] Device 46:64:1C:0C:04:AC Bluetooth Keyboard
[bluetooth]# pair 46:64:1C:0C:04:AC
Attempting to pair with 46:64:1C:0C:04:AC
[CHG] Device 46:64:1C:0C:04:AC Connected: yes
[agent] PIN code: 623340
##type this with the keyboard. Nothing will show up on screen. Press enter if nothing happens
[bluetooth]# trust 46:64:1C:0C:04:AC
[CHG] Device 46:64:1C:0C:04:AC Trusted: yes
Changing 46:64:1C:0C:04:AC trust succeeded
[bluetooth]# connect 46:64:1C:0C:04:AC
Attempting to connect to 46:64:1C:0C:04:AC
[CHG] Device 46:64:1C:0C:04:AC Connected: yes
Connection successful
[CHG] Device 46:64:1C:0C:04:AC ServicesResolved: yes
[NEW] Device 5F:D8:C0:45:4C:B5 5F-D8-C0-45-4C-B5
[Bluetooth Keyboard]# exit


After this your keyboard should be working. If it doesn't and you didn't install bluedevil go back and do that now. 


Next up we'll get Kali onto the touchscreen


-ott3r