Linux command line howto accept pairing for bluetooth device without pin - linux

Is there a way to pair a device in linux without requiring a pin(for testing purposes so I need it to be done w/out human interaction, assuming you have root access)?
bluez-simple-agent seems to require a pin except with some simple devices such as mice.

Entering a PIN is actually an outdated method of pairing, now called Legacy Pairing. Secure Simple Pairing Mode is available in Bluetooth v2.1 and later, which comprises most modern Bluetooth devices. SSPMode authentication is handled by the Bluetooth protocol stack and thus works without user interaction.
Here is how one might go about connecting to a device:
# hciconfig hci0 sspmode 1
# hciconfig hci0 sspmode
hci0: Type: BR/EDR Bus: USB
BD Address: AA:BB:CC:DD:EE:FF ACL MTU: 1021:8 SCO MTU: 64:1
Simple Pairing mode: Enabled
# hciconfig hci0 piscan
# sdptool add SP
# hcitool scan
00:11:22:33:44:55 My_Device
# rfcomm connect /dev/rfcomm0 00:11:22:33:44:55 1 &
Connected /dev/rfcomm0 to 00:11:22:33:44:55 on channel 1
Press CTRL-C for hangup
This would establish a serial connection to the device.

follow steps (CentOs):
bluetoothctl
devices
scan on
pair 34:88:5D:51:5A:95 (34:88:5D:51:5A:95 is my device code,replace it with yours)
trust 34:88:5D:51:5A:95
connect 34:88:5D:51:5A:95
If you want more details
https://www.youtube.com/watch?v=CB1E4Ir3AV4

Try setting security to none in /etc/bluetooth/hcid.conf
http://linux.die.net/man/5/hcid.conf
This will probably only work for HCI devices (mouse, keyboard, spaceball, etc.). If you have a different kind of device, there's probably a different but similar setting to change.

This worked like a charm for me, of-course it requires super-user privileges :-)
# hcitool cc <target-bdaddr>; hcitool auth <target-bdaddr>
To get <target-bdaddr> you may issue below command:
$ hcitool scan
Note: Exclude # & $ as they are command line prompts.
Courtesy

For Ubuntu 14.04 and Android try:
hcitool scan #get hardware address
sudo bluetooth-agent PIN HARDWARE-ADDRESS
PIN dialog pops up on Android device. Enter same PIN.
Note: sudo apt-get install bluez-utils might be necessary.
Note2: If PIN dialog does not appear, try pairing from Android first (will fail because of wrong PIN). Then try again as described above.

~ $ hciconfig noauth
This should do the trick (I'm using bluez 5.23 and there's no more simple-egent and blue-utils). However, I'm trying to look for a way to make changes hciconfig permanent because after power out and then power on, authentication is needed again. So far, the changes in hciconfig still stays the same when you reboot it. it reverts back only when power out. If anybody has found a way to make hciconfig permanent, do let me know!

~ $ hciconfig noauth
It worked for me in "Linux mx 4.19"
The exact steps are:
1) open a terminal - run: "hciconfig noauth"
2) use the blueman-manager gui to pair the device (in my case it was a keyboard)
3) from the blueman-manager choose "connect to HID"
step(3) is normally asking for a password - the "hciconfig noauth" makes step(3) passwordless

Related

hcitool cc and hcitool auth returns Input/output error

I have successfully set up and enabled Bluetooth on my server running Debian Buster. That in itself is quite an achievement. Anyhow, I am trying to use a Node package called node-bluetooth-serial-port to connect to a tiny Bluetooth speaker with a display. I manage to list/scan devices, but it cannot send anything to the device. I'm thinking this is because my server hasn't been paired with the device yet.
$ hcitool scan
Scanning ...
11:22:33:44:55:66 TimeBox-mini-audio
$ sudo hcitool cc 11:22:33:44:55:66; sudo hcitool auth 11:22:33:44:55:66
HCI authentication request failed: Input/output error
So hcitool can find the device, but it cannot connect to it, for some reason. dmesg doesn't show me any errors what so ever.
I have tried to pair with other devices (like my phone), but that doesn't work either.
The device does not require a 4-digit pin to auth.
What can I do here?

bluetoothctl No default controller available [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
It's a bit wired here.
I have a problem is bluetoothctl always said "No default controller available". I found there are many people had same problem with me. But the situation is a bit different from them.
I can see my hciconfig -a have information like below
And hcitool dev seems no problem as well.
But I have no idea why my bluetoothctl always said "No default controller available"
Even when I turn down and turn up hci0 several times. It always in the same problem.
BTW, my BlueZ is 5.39. And I tried this experiment on buildroot. Kernel is 3.10
Had the same problem. Use:
$ sudo bluetoothctl
Then the controller was found automatically. I also tried https://www.raspberrypi.org/forums/viewtopic.php?t=207025 before. Maybe this effected the solution.
Also happens if rfkill switch is blocking Bluetooth (for some inadvertent reason, in my case):
$ rfkill list all
0: tpacpi_bluetooth_sw: Bluetooth
Soft blocked: yes
Hard blocked: no
To unblock, pass the ID for your Bluetooth device from the list above to the unblock subcommand:
$ rfkill unblock 0
Then controller should be back:
$ bluetoothctl list
Controller .... [default]
Here are the steps that worked for me by modifying the bluez config and the run without sudo:
Create a "bluetooth" group which will be granted with <allow send_destination="org.bluez"/> on bluez's d-bus config
$ sudo groupadd bluetooth
Open the config in /etc/dbus-1/system.d/bluetooth.conf with your favorite text editor
e.g.
$ sudo vi /etc/dbus-1/system.d/bluetooth.conf
Add/append the following lines below in /etc/dbus-1/system.d/bluetooth.conf
<policy group="bluetooth">
<allow send_destination="org.bluez"/>
</policy>
Save your changes.
Add your login user to "bluetooth" group
$ sudo usermod -a -G bluetooth <loginuser>
Reboot the system.
Then try to use "bluetoothctl" without sudo
$ bluetoothctl
[bluetooth]# show
Its an old thread, but might help someone looking for answers.
I have faced this problem most of the times, and the things I verify are:
systemctl status bluetooth == this checks if the bluetooth service daemon is already running or not.
Check for output:
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running)
If not, start it using the command: sudo systemctl start bluetooth
using sudo bluetoothctl
one of these two was the culprit usually.
I had this problem with VanillaArch on Linux Kernel 5.12. After struggling for a day I found the problem is:
1. Some of bluetooth devices firmware are not available in the new linux libraries right out of the box and you need to find. for this problem you can refer to the following repo. In readme it's well documented what you should do. basically you 'd download and copy the frimware in
/lib/firmware/brcm
for Broadcom Bluetooth devices.
https://github.com/winterheart/broadcom-bt-firmware
2. Activation of two conflicting services on Bluetooth.
Referring to "SayantanRC" on Arch froum :
When I compared between the two, I found these two services were enabled on my Manjaro installation, but disabled on my Arch linux installation:
blueman-mechanism.service
bluetooth-mesh.service
Disabled them and rebooted.
sudo systemctl disable blueman-mechanism.service
sudo systemctl disable bluetooth-mesh.service
Now the services are as below:
~ >>> systemctl list-unit-files | grep blue
blueman-mechanism.service disabled disabled
bluetooth-mesh.service disabled disabled
bluetooth.service enabled disabled
dbus-org.bluez.service alias -
bluetooth.target static -
~ >>>
And voila, bluetooth is up!
~ >>> bluetoothctl
Agent registered
[CHG] Controller 68:07:15:DE:1F:15 Pairable: yes
[bluetooth]# show
Controller 68:07:15:DE:1F:15 (public)
Name: src-manjaro
Alias: src-manjaro
Class: 0x00000000
Powered: no
Discoverable: no
DiscoverableTimeout: 0x000000b4
Pairable: yes
UUID: A/V Remote Control (0000110e-0000-1000-8000-00805f9b34fb)
UUID: Audio Source (0000110a-0000-1000-8000-00805f9b34fb)
UUID: PnP Information (00001200-0000-1000-8000-00805f9b34fb)
UUID: Audio Sink (0000110b-0000-1000-8000-00805f9b34fb)
UUID: Headset (00001108-0000-1000-8000-00805f9b34fb)
UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Headset AG (00001112-0000-1000-8000-00805f9b34fb)
Modalias: usb:v1D6Bp0246d0537
Discovering: no
Roles: central
Roles: peripheral
Advertising Features:
ActiveInstances: 0x00 (0)
SupportedInstances: 0x05 (5)
SupportedIncludes: tx-power
SupportedIncludes: appearance
SupportedIncludes: local-name
[bluetooth]# quit
EDIT: For verification purpose, I re-enabled the services and
bluetooth adapter was having trouble again. I disabled them and it is
fine now. Checked on kernel 5.9 and 5.4.
https://bbs.archlinux.org/viewtopic.php?id=259260&p=2
The answer above probably works on some distributions, but may get you into trouble in others. Unfortunately, it seems that every distribution has a different default configuration for Bluetooth - it's a pretty awful mess IMHO.
Here's what worked for me on a Debian derivative Raspberry Pi OS (née Raspbian):
As a preliminary check, on many distros you can check /etc/group to see if a group name bluetooth exists:
$ cat /etc/group | grep blue
If it exists, you obviously don't need to add the group, only add users to the group:
$ sudo usermod -G bluetooth -a <username>
In the distro I'm using, this was all that was required to make the Controller responsive in bluetoothctl.
I had the same issue. After a long research found out that the driver was not installed. Check that answer https://unix.stackexchange.com/questions/545019/bluetooth-doesnt-work-in-debian-10 and see if your drivers are installed correctly =)

Changing raspberry pi bluetooth device name?

I am trying to change a raspberry pi's bluetooth name to something else (an ip address) so that when I scan and pair my android device it will see this ip as the device name. It worked once but then went back to appearing as "raspberrypi-0"
I have tried both the hciconfig set name command, and have also changed the device name inside /etc/bluetooth/main.conf but still all my device sees is "raspberrypi-0". Its driving me crazy so if anyone knows what the issue is please help!
If you want to change the bluetooth device name permanently, you have to create a file called /etc/machine-info which should have the following content:
PRETTY_HOSTNAME=device-name
Then issue "service bluetooth restart" after that
#Evangelos Nannos answer still works (BlueZ 5.50) but if you want to change bluetooth alias on the fly you may try bluetoothctl (tested on Pi Zero W running Raspbian Stretch & BlueZ 5.50)
To set new alias open terminal:
pi#raspberrypi:~ $ bluetoothctl
[bluetooth]# system-alias 'Your New BT Alias'
Changing Your New BT Alias succeeded
[CHG] Controller AA:BB:CC:DD:EE:FF Alias: Your New BT Alias
Use show to see current bluetooth settings:
[bluetooth]# show
Controller AA:BB:CC:DD:EE:FF
Name: Some_other_name #default or as PRETTY_HOSTNAME
Alias: Your New BT Alias #alias will be shown when scanning for bt devices
(...)
Reset alias and go back to using system device name with:
[bluetooth]# reset-alias
Exit bluetootctl with:
[bluetooth]# quit
With Discoverable on (yes) the device will show up during scaning as Your New BT Alias.
Take note that alias will be kept after reboot!
I've use pexpect to manipulate bluetoothctl, bash works too. There were problems registering Agent on BlueZ 5.43 via pexpect, had to upgrade to 5.50
Alternative command (note it will not return a response):
pi#raspberrypi:~ $ sudo hciconfig hci0 name 'New device name'
It stores the display name in /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/config file. If you wants to change the bluetooth display(broadcast) name then you need to follow the below steps:
delete /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/config file.
Edit /etc/bluetooth/main.conf(For ex: Name=%d-%h to Name=abcd-5)
service bluetooth restart.
Note: If this already paired with some other BT devices, so you need to remove the pairing to see the new BT name of the same device(MAC).
You can also just disable the hostname plugin and configure the name.
Run sudo vim /etc/systemd/system/bluetooth.target.wants/bluetooth.service
and append --noplugin=hostname, like this:
ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=hostname
Then edit the bluetooth config and set your desired name:
sudo vim /etc/bluetooth/main.conf
Name = YourNewName
Just follow the below steps
step 1 - write below code in terminal
sudo nano /etc/machine-info
step 2 - It will open a blank file, Now write this line into it
PRETTY_HOSTNAME=PutYourDeviceNameHere
step 3 - Now restart Bluetooth service OR You can reboot Raspberry Pi
service bluetooth restart
OR
sudo reboot
Hope it's Work For you
Use hostnamectl command for change or set your bluetooth name.
hostnamectl --pretty set-hostname <PutYourDeviceNameHere>

gatttool and hcitool on Linux

I'm trying to connect to a device using gatttool on Linux. I run hcitool lescan to get the device MAC address, and then gatttool -i hci1 -b <macaddr> -t random -I. Then I type connect. I see [CON] as expected, but the problem is that it disappears automatically after about 1s, with no error messages. I have been searching for hours, but I don't see why that is so?
Note: I have run hcitool lecc before running gatttool one time just to try it, but it seems to me that since then, gatttool connection is not working properly anymore (unexpected disconnection as explained above). Is it because I have used hcitool lecc? If yes, is there a way to "undo" it?
Not sure if this helps you because I'm seeing this behavior on my Raspberry Pi (an up-to-date wheezy version) and bluez 5.18 (released April 2014.)
I can connect to my BLE peripheral from the command line after doing an lecc without any problems. I don't think you need to reset after an lecc. Regardless, if you do want to reset your BT dongle because it is in some funky state, look at this excellent step-by-step guide to reset the BT dongle. I have followed these steps with consistent results.
I can connect and query say primary but more often than not, the connection drops before I can manually type in primary. See the results below. If I use the up/down arrows after connecting to quickly scroll to primary, I am able to see primary services offered by this peripheral without any problems.
~ $ sudo gatttool -I -i hci0 -m 48 -b 20:CD:39:A8:11:AF
[20:CD:39:A8:11:AF][LE]> connect
Attempting to connect to 20:CD:39:A8:11:AF
Connection successful
[20:CD:39:A8:11:AF][LE]> primary
Command Failed: Disconnected

A2DP sink without pulseaudio

So I'm trying to make my linux server play music sent from my Android phone using bluetooth (the linux machine is the A2DP sink and the phone is the source).
What I have done so far is to:
install bluez and enable audiosource/audiosink
pair phone and server
connect to server from phone (phone says it's streaming audio over bluetooth)
But I can't hear anything. Also, most guides on the internet assumes Pulseaudio and I would prefer to use ALSA.
I currently have the following in /etc/asound.conf:
pcm.!default{
type bluetooth
profile "auto"
}
I'm running Bluez v4.99 and Alsa v1.0.25.
Any ideas?
I know this is an old post, but hopefully the answer is useful to people currently working on this.
You can use /etc/bluetooth/audio.conf, which is the system-wide file, or ~/.asoundrc, which is your local file. Both are read by BlueZ/ALSA. However, I think you need to include the MAC address in your config file, z.B.:
pcm.btheadset {
type bluetooth
device "XX:XX:XX:XX:XX:XX" #MAC address
profile "auto"
}
The best resources I've found for this are:
1) James B's blog post: Bluez must be one of the best kept secrets in Linux
He explains the structure and interface between BlueZ and ALSA, which I found nowhere else on the internet.
2) His second post with code: Bluez A2DP AudioSink for ALSA
3) The ALSA site, which introduces the structure of pcm plugins, but doesn't really explain them very well.
4) Some ALSA plugin tutorials: The ALSA wiki
Some useful commands:
$sudo service bluetooth restart
$sudo alsa force-reload
Run these after you change the asoundrc or audio.conf files.
Here you find a manual to configure bluetooth with ALSA or Pulseaudio:
-tested on Linux Mint 17.3 Mate, 64bit / Ubuntu 14.04 Mate, 64bit-
HOW TO MAKE ALSA AND BLUETOOTH WORK TOGETHER WITHOUT PA
This part is for pure ALSA-based systems without Pulseaudio like KXStudio, QStudio64,Tango studio..!
Be sure that Pulseaudio is deinstalled and your soundcards
configured right in ALSA!
delete pulse-audio cookies and files in
/home/USERNAME/.config/pulse
Modify your bluetooth-audio.conf:
type:
gksudo pluma /etc/bluetooth/audio.conf
Set
# This section contains options which are not specific to any
# particular interface
[General]
Enable=Socket
Save the file.
setup ~/.asoundrc file
type:
sudo hcitool scan
Scanning ...
XX:XX:XX:XX:XX:XX
Stereo Headset
Create a hidden-file named .asoundrc in your home-folder!and write:
pcm.!default {
type plug
slave.pcm {
type bluetooth
device "XX:XX:XX:XX:XX:XX"
profile "auto"
}
}
Replace “XX:XX..” with the adress of your device.
Save the file!
Run these after you change the asoundrc or audio.conf files:
sudo service bluetooth restart
sudo alsa force-reload
or reboot your computer!
———————————————————————————————————–—-
Go to your blueman-applet at your taskbar, search & setup your new device!
Note: Some bluetooth-devices need a passphrase (eg. 0000) by default
while some others takes shuffle-pairing.
Keep your found and paired device to “trust”!
Connect your device as AUDIO via A2DP!
————————————————————————————————————
If your device is connected with your system you can play sound with totem (gui), vlc (gui+terminal), mplayer (terminal), qmmp (gui), banshee and browsers over bluetooth while setting the output in players to “default”!
—————————————————————————————————–———
RENAME THE .ASOUNDRC IN HOME-FOLDER TO “.ASOUNDRC_OFF”
TO GET YOUR OLD SYSTEM-SETTINGS WITHOUT BLUETOOTH BACK!
type: mv /home/USERNAME/.asoundrc /home/USERNAME/.asoundrcOFF
->to disable the bluetooth-specific asoundrc
type: mv /home/USERNAME/.asoundrcOFF /home/USERNAME/.asoundrc
-> to enable it!
Alternative:
Make two “scripts” to activate/deactivate bluetooth with .asoundrc in your home-folder:
Create one empty file and write/paste:
#!/bin/bash
mv /home/USERNAME/.asoundrc /home/USERNAME/.asoundrcOFF
or:
#!/bin/bash
cd /home/USERNAME/
mv .asoundrc .asoundrcOFF
To activate your .asoundrc for bluetooth again, create another file with following entry:
#!/bin/bash
mv /home/USERNAME/.asoundrcOFF /home/USERNAME/.asoundrc
or:
#!/bin/bash
cd /home/USERNAME/
mv .asoundrcOFF .asoundrc
Make the files executable and run them with “open with terminal”!
Now you have two “buttons” to switch bluetooth-sound On or Off.
Give them individual-icons:
;-)
————————————————————————————————————-
PLAYERS
————–
It’s recommend to use totem, Qmmp or Banshee-player - because there is nothing more to do than
play and listen! Also totem-player shows videos too.
VLC-player needs the “default” sounddriver for bluetooth to working right!
Check in: /home/USERNAME/.config/vlc/vlcrc
that alsa-audio-device
in >>line1666<<
is:
# ALSA Device Name (string)
alsa-audio-device=default
Use this commands to use players with terminal:
To play music, type:
MPlayer
———––
mplayer /home/USERNAME/Musik/1.mp3
If you hear no sound or get errors try:
mplayer -ao alsa:device=default /home/USERNAME/Musik/1.mp3
VLC-Player
—————-
cvlc /home/USERNAME/Musik/1.mp3
vlc /home/USERNAME/Musik/1.mp3
rvlc /home/USERNAME/Musik/1.mp3
To add whole directories type:
rvlc add /home/USERNAME/Musik/
type: start/stop/next... to navigate!
or use the vlc-gui.
—————————————————————————————————–——-
To use mplayer with graphical-interface you have to install the gui-package:
type:
sudo apt-get install mplayer-gui
Open a terminal via Ctrl-Alt-T and use the commands below.Use the lines and type/copy one by one to avoid confusion(!):
cd /usr/share/mplayer/skins/default
for FILE in *.png; do sudo convert “$FILE” -define png:format=png24 “$FILE”; done
cd /usr/share/mplayer/skins; sudo rm default; sudo ln -s Blue default
———————————————————————————————————–
Now you can start the mplayer-gui without errors!
If you prefer the terminal type:
gmplayer /home/USERNAME/Musik/1.mp3
or
gmplayer -ao alsa:device=default /home/USERNAME/Musik/1.mp3
if you have problems!
terminal command without gui:
mplayer /DIRECTION/TO/FILE
Available Output-Modules and Drivers:
mplayer -vo help
———————————————————————-
BLUETOOTH WITH PULSEAUDIO
————————————————–--------
For Linux systems that comes with pulseaudio:
(1.) Edit /etc/bluetooth/audio.conf and uncomment the following line:
AutoConnect=true
Run the following command to install latest packages for blueman and related modules:
sudo add-apt-repository ppa:blueman/ppa
sudo apt-get update
sudo apt-get upgrade blueman
enter code here
(3.) Check if the following lines are added in /etc/pulse/default.pa:
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif
If not, add the lines.
REBOOT!
Run the new blueman-applet.
Right click on the panel applet and turn bluetooth on.
The old profie of you bluetooth device would still be there, remove it.
Right click on the blueman-panel applet and select Setup New Device.
Complete the wizard for your device.(If you have problems with “pairing” restart your system and skip this step!)
Now you get a connected bluetooth device!
To send/hear audio over it just follow these 2 steps:
Open Mate-volume control-settings (or pavucontrol) with rightclick in taskbar,
browse to “HARDWARE” -
and use the dropdown to turn the Built-in audio profiles of all other soundcards “off”
so that the bluetooth-device gets active!
use the other dropdown to set the bluetooth device to use A2DP
Now start the totem-player or vlc (with pulseaudio-output) to send audio to bluetooth!
Enjoy your sound!
;-)
WLAN-ISSUES:
——————–—
In case you see a WiFi connection drop after connecting to the bluetooth device run the following
command:
$ echo “options iwlwifi 11n_disable=1 bt_coex_active=0 power_save=0 auto_agg=0 swcrypto=1” |
sudo tee -a /etc/modprobe.d/iwlwifi.conf > /dev/null
tested 2017 for LM 17.3 (Rosa) MATE and Ubuntu 14.04 by chalee:
http://mayastudio.tumblr.com/bluetooth
My guess is that your audio path isn't routing the bluetooth to your speakers. I have seen similar issue, which was fixed by manually doing step 5 "Connect PulseAudio bluetooth source to PulseAudio ALSA sink" from this link: http://jprvita.wordpress.com/2009/12/15/1-2-3-4-a2dp-stream/
I just tried to do the same thing, I'm using Fedora 19, so your mileage my vary. These are the steps I took.
Made computer discoverable
Pair phone to computer (it had a headphone logo next to it)
On my HTC phone I clicked "connect" on the pairing
Go into gnome3's sound settings
Go to the input tab
Select the bluetooth item for your phone
Maybe adjust volume...

Resources