https://wiki.archlinux.org/api.php?action=feedcontributions&user=Pushkar8723&feedformat=atomArchWiki - User contributions [en]2024-03-29T10:11:51ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Bluetooth&diff=302379Bluetooth2014-02-28T08:39:13Z<p>Pushkar8723: /lib/udev/hid2hci was missing on my system as well as my friends system. Installing bluez-hid2hci fixed the issue.</p>
<hr />
<div>[[Category:Bluetooth]]<br />
[[cs:Bluetooth]]<br />
[[de:Bluetooth]]<br />
[[es:Bluetooth]]<br />
[[fr:Bluetooth]]<br />
[[it:Bluetooth]]<br />
[[ja:Bluetooth]]<br />
[[ru:Bluetooth]]<br />
[[zh-CN:Bluetooth]]<br />
{{Related articles start}}<br />
{{Related|Bluez4}}<br />
{{Related|Bluetooth Mouse}}<br />
{{Related|Bluetooth mouse configuration}}<br />
{{Related|Bluetooth Headset}}<br />
{{Related|Blueman}}<br />
{{Related articles end}}<br />
[http://www.bluetooth.org/ Bluetooth] is a standard for the short-range wireless interconnection of cellular phones, computers, and other electronic devices. In Linux, the canonical implementation of the Bluetooth protocol stack is [http://www.bluez.org/ BlueZ].<br />
<br />
== Installation ==<br />
<br />
Install the Bluetooth protocol stack {{Pkg|bluez}} and the {{Pkg|bluez-utils}} package which provides the {{ic|bluetoothctl}} utility from the [[official repositories]]. The {{ic|dbus}} daemon, which is started automatically by ''systemd'', is used to read settings and for PIN pairing, while the {{ic|bluetooth}} daemon is required for the Bluetooth protocol. <br />
<br />
To start the bluetooth [[systemd]] service use the command:<br />
# systemctl start bluetooth<br />
<br />
To enable the bluetooth service at boot time use the command:<br />
# systemctl enable bluetooth<br />
<br />
{{Note|By default the bluetooth daemon will only give out bnep0 devices to users that are a member of the lp group. Make sure to add your user to that group if you intend to connect to a bluetooth tether. You can change the group that is required in the file {{ic|/etc/dbus-1/system.d/bluetooth.conf}}.}}<br />
<br />
{{Note|Some Bluetooth adapters are bundled with a Wi-Fi card (e.g. [http://www.intel.com/content/www/us/en/wireless-products/centrino-advanced-n-6235.html Intel Centrino]). These require that the Wi-Fi card is first enabled (typically a keyboard shortcut on a laptop) in order to make the Bluetooth adapter visible to the kernel.}}<br />
<br />
== Configuration via the CLI ==<br />
=== Bluetoothctl ===<br />
Pairing a device from the shell is one of the most simplistic and reliable options. The exact procedure depends on the devices involved and their input functionality. What follows is a general outline of pairing a device using {{ic|/usr/bin/bluetoothctl}}:<br />
<br />
Start the {{ic|bluetoothctl}} interactive command. There one can input {{ic|help}} to get a list of available commands. <br />
* Turn the power to the controller on by entering {{ic|power on}}. It is off by default.<br />
* Enter {{ic|devices}} to get the MAC Address of the device with which to pair.<br />
* Enter device discovery mode with {{ic|scan on}} command if device is not yet on the list.<br />
* Turn the agent on with {{ic|agent on}}.<br />
* Enter {{ic|pair ''MAC Address''}} to do the pairing (tab completion works).<br />
* If using a device without a PIN, one may need to manually trust the device before it can reconnect successfully. Enter {{ic|trust ''MAC Address''}} to do so.<br />
* Finally, use {{ic|connect ''MAC_address''}} to establish a connection.<br />
<br />
An example session may look this way:<br />
# bluetoothctl <br />
[NEW] Controller 00:10:20:30:40:50 pi [default]<br />
[bluetooth]# agent KeyboardOnly <br />
Agent registered<br />
[bluetooth]# default-agent <br />
Default agent request successful<br />
[bluetooth]# scan on<br />
Discovery started<br />
[CHG] Controller 00:10:20:30:40:50 Discovering: yes<br />
[NEW] Device 00:12:34:56:78:90 myLino<br />
[CHG] Device 00:12:34:56:78:90 LegacyPairing: yes<br />
[bluetooth]# pair 00:12:34:56:78:90<br />
Attempting to pair with 00:12:34:56:78:90<br />
[CHG] Device 00:12:34:56:78:90 Connected: yes<br />
[CHG] Device 00:12:34:56:78:90 Connected: no<br />
[CHG] Device 00:12:34:56:78:90 Connected: yes<br />
Request PIN code<br />
[agent] Enter PIN code: 1234<br />
[CHG] Device 00:12:34:56:78:90 Paired: yes<br />
Pairing successful<br />
[CHG] Device 00:12:34:56:78:90 Connected: no<br />
<br />
In order to have the device active after a reboot, a udev rule is needed:<br />
{{ic|/etc/udev/rules.d/10-local.rules}}<br />
# Set bluetooth power up<br />
ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"<br />
<br />
After a suspend/resume-cycle, the device can be powered off automatically using something like this systemd service:<br />
{{hc|/etc/systemd/system/bluetooth-auto-power@.service|<nowiki><br />
[Unit]<br />
Description=Bluetooth auto power on<br />
After=bluetooth.service sys-subsystem-bluetooth-devices-%i.device suspend.target<br />
<br />
[Service]<br />
Type=oneshot<br />
#We could also do a 200 char long call to bluez via dbus. Except this does not work since bluez does not react to dbus at this point of the resume sequence and I do not know how I get this service to run at a time it does. So we just ignore bluez and force %i up using hciconfig. Welcome to the 21st century.<br />
#ExecStart=/usr/bin/dbus-send --system --type=method_call --dest=org.bluez /org/bluez/%I org.freedesktop.DBus.Properties.Set string:org.bluez.Adapter1 string:Powered variant:boolean:true<br />
ExecStart=/usr/bin/hciconfig %i up<br />
<br />
[Install]<br />
WantedBy=suspend.target<br />
</nowiki>}}<br />
<br />
== Configuration with a Graphical Front-end ==<br />
<br />
The following packages allow for a graphical interface to customize Bluetooth.<br />
<br />
=== GNOME Bluetooth ===<br />
<br />
[https://wiki.gnome.org/Projects/GnomeBluetooth GNOME Bluetooth] is a fork of the old ''bluez-gnome'' and is focused on integration with the [[GNOME]] desktop environment. The {{Pkg|gnome-bluetooth}} package provides the back-end, {{Pkg|gnome-shell}} provides the status monitor applet, and {{Pkg|gnome-control-center}} provides the configuration front-end GUI that can be accessed by typing Bluetooth on the Activities overview, or with the {{ic|gnome-control-center bluetooth}} command.<br />
<br />
Users who are not using GNOME Shell can install {{AUR|gnome-bluetooth-applet-git}} from AUR, which provides the old status monitor applet, and allows setup devices and transfer of files by clicking the Bluetooth icon. Just make sure that {{ic|bluetooth-applet}} is [[autostart|autostarted]] with your session.<br />
<br />
You can also launch the following commands directly:<br />
* {{ic|bluetooth-sendto}}: send files to a remote device<br />
* {{ic|bluetooth-wizard}}: for new devices to be paired<br />
<br />
To add a Bluetooth entry to the ''SendTo'' menu in Thunar's file properties menu, see instructions [http://docs.xfce.org/xfce/thunar/send-to here]. (The command that needs to be configured is {{ic|bluetooth-sendto %F}})<br />
<br />
=== BlueDevil ===<br />
<br />
The Bluetooth tool for [[KDE]] is [https://projects.kde.org/projects/extragear/base/bluedevil BlueDevil]. It can be installed with the package {{Pkg|bluedevil}}, available in the official repositories.<br />
<br />
Make sure {{ic|bluetooth}} daemon is running, as described above. A Bluetooth icon should be visible in both Dolphin and in the system tray, from which users may configure BlueDevil and detect Bluetooth devices by clicking the icon. An interface is also available from the KDE System Settings.<br />
<br />
== Using Obex for sending and receiving files ==<br />
=== ObexFS ===<br />
Another option, rather than using KDE or Gnome Bluetooth packages, is ObexFS which allows for the mounting of phones which are treated like any other filesystem.<br />
{{Note|To use ObexFS, one needs a device that provides an ObexFTP service.}}<br />
<br />
Install {{Pkg|obexfs}} and mount supported phones by running:<br />
$ obexfs -b ''devices_MAC_address'' /mountpoint<br />
<br />
Once you have finished, to unmount the device use the command:<br />
$ fusermount -u /mountpoint<br />
<br />
For more mounting options see http://dev.zuckschwerdt.org/openobex/wiki/ObexFs<br />
<br />
{{Note|Ensure that the bluetooth device you are mounting is '''not''' set to mount ''read-only''. You should be able to do this from the device's settings. If the device is mounted ''read-only'' you may encounter a permissions error when trying to transfer files to the device.}}<br />
<br />
=== ObexFTP Transfers ===<br />
If your device supports the Obex FTP service but you do not wish to mount the device you can transfer files to and from the device using the obexftp command.<br />
<br />
{{Tip|If you installed {{pkg|obexfs}} earlier then {{pkg|obexftp}} should have also been installed as a dependency.}}<br />
<br />
To send a file to a device run the command:<br />
<br />
$ obexftp -b ''devices_MAC_address'' -p /path/to/file<br />
<br />
To retrieve a file from a device run the command:<br />
<br />
$ obexftp -b ''devices_MAC_address'' -g filename<br />
<br />
{{Note|Ensure that the file you are retrieving is in the device's ''exchange folder''. If the file is in a subfolder of the exchange folder then provide the correct path in the command.}}<br />
<br />
=== Obex Object Push ===<br />
For devices that do not support Obex FTP service, check if Obex Object Push is supported.<br />
<br />
# sdptool browse ''XX:XX:XX:XX:XX:XX''<br />
<br />
Read the output, look for Obex Object Push, remember the channel for this service. If supported, one can use {{pkg|ussp-push}} to send files to this device:<br />
<br />
# ussp-push ''XX:XX:XX:XX:XX:XX''@''CHANNEL'' ''file'' ''wanted_file_name_on_phone''<br />
<br />
== Examples ==<br />
<br />
All examples have been moved to the [[bluez4]] article. They need to be checked and fixed for use with bluez5.<br />
<br />
== Troubleshooting ==<br />
<br />
=== gnome-bluetooth ===<br />
<br />
If you see this when trying to enable receiving files in bluetooth-properties:<br />
Bluetooth OBEX start failed: Invalid path<br />
Bluetooth FTP start failed: Invalid path<br />
Then install {{Pkg|xdg-user-dirs}} and issue:<br />
$ xdg-user-dirs-update<br />
You can edit the paths using:<br />
$ vi ~/.config/user-dirs.dirs<br />
<br />
=== Bluetooth USB Dongle ===<br />
<br />
If you are using a USB dongle, you should check that your Bluetooth dongle is recognized. You can do that by running {{ic|journalctl -f}} when plugging in the USB dongle (or inspecting {{ic|/var/log/messages.log}}). It should look something like the following (look out for hci):<br />
<br />
{{bc|<br />
Feb 20 15:00:24 hostname kernel: [ 2661.349823] usb 4-1: new full-speed USB device number 3 using uhci_hcd<br />
Feb 20 15:00:24 hostname bluetoothd[4568]: HCI dev 0 registered<br />
Feb 20 15:00:24 hostname bluetoothd[4568]: Listening for HCI events on hci0<br />
Feb 20 15:00:25 hostname bluetoothd[4568]: HCI dev 0 up<br />
Feb 20 15:00:25 hostname bluetoothd[4568]: Adapter /org/bluez/4568/hci0 has been enabled<br />
}}<br />
<br />
For a list of supported hardware please refer to the [[#Resources|Resource]] section on this page.<br />
<br />
If you only get the first two lines, you may see that it found the device but you need to bring it up.<br />
Example:<br />
<br />
{{hc|hciconfig -a hci0|<br />
hci0: Type: USB<br />
BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0<br />
DOWN <br />
RX bytes:0 acl:0 sco:0 events:0 errors:0<br />
TX bytes:0 acl:0 sco:0 commands:0 errors:<br />
}}<br />
<br />
# hciconfig hci0 up<br />
<br />
{{hc|hciconfig -a hci0|<br />
hci0: Type: USB<br />
BD Address: 00:02:72:C4:7C:06 ACL MTU: 377:10 SCO MTU: 64:8<br />
UP RUNNING <br />
RX bytes:348 acl:0 sco:0 events:11 errors:0<br />
TX bytes:38 acl:0 sco:0 commands:11 errors:0<br />
}}<br />
<br />
If this fails with an error like:<br />
Operation not possible due to RF-kill<br />
it could be due either to the {{ic|rfkill}} utility, in which case it should be resolved with<br />
# rfkill unblock all<br />
or, it could simply be the hardware switch of the computer. The hardware bluetooth switch (at least sometimes) controls access to USB bluetooth dongles also. Flip/press this switch and try bringing the device up again.<br />
<br />
To verify that the device was detected you can use {{ic|hcitool}} which is part of the {{ic|bluez-utils}}. You can get a list of available devices and their identifiers and their MAC address by issuing:<br />
<br />
{{hc|$ hcitool dev|<br />
Devices:<br />
hci0 00:1B:DC:0F:DB:40<br />
}}<br />
<br />
More detailed information about the device can be retrieved by using {{ic|hciconfig}}.<br />
<br />
{{hc|$ hciconfig -a hci0|<br />
hci0: Type: USB<br />
BD Address: 00:1B:DC:0F:DB:40 ACL MTU: 310:10 SCO MTU: 64:8<br />
UP RUNNING PSCAN ISCAN<br />
RX bytes:1226 acl:0 sco:0 events:27 errors:0<br />
TX bytes:351 acl:0 sco:0 commands:26 errors:0<br />
Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80<br />
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3<br />
Link policy: RSWITCH HOLD SNIFF PARK<br />
Link mode: SLAVE ACCEPT <br />
Name: 'BlueZ (0)'<br />
Class: 0x000100<br />
Service Classes: Unspecified<br />
Device Class: Computer, Uncategorized<br />
HCI Ver: 2.0 (0x3) HCI Rev: 0xc5c LMP Ver: 2.0 (0x3) LMP Subver: 0xc5c<br />
Manufacturer: Cambridge Silicon Radio (10)<br />
}}<br />
<br />
=== Logitech Bluetooth USB Dongle ===<br />
<br />
There are Logitech dongles (ex. Logitech MX5000) that can work in two modes Embedded and HCI. In embedded mode dongle emulates a USB device so it seems to your PC that your using a normal USB mouse/keyoard.<br />
<br />
If you hold the little red Button on the USB BT mini-receiver it will enable the other mode. Hold the red button on the BT dongle and plug it into the computer, and after 3-5 seconds of holding the button, the Bluetooth icon will appear in the system tray. [http://ubuntuforums.org/showthread.php?t=1332197 Discussion]<br />
<br />
=== hcitool scan: Device not found ===<br />
<br />
* On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI using<br />
# hid2hci<br />
<br />
{{Note|hid2hci is no longer in the $PATH, it is under /lib/udev/hid2hci, but udev should run it automatically for you. If it is not present there install {{Pkg|bluez-hid2hci}} and then reboot. }}<br />
<br />
* If the device will not show up and you have a Windows operating system on your machine, try booting it and enable the bluetooth adapter from windows.<br />
<br />
* Sometimes also this simple command helps:<br />
# hciconfig hci0 up<br />
<br />
=== rfkill unblock: Do not unblock ===<br />
<br />
If your device still soft blocked and you run connman.<br />
<br />
Try this:<br />
$ connmanctl enable bluetooth<br />
<br />
=== My computer is not visible ===<br />
<br />
Cannot discover computer from your phone? Enable PSCAN and ISCAN:<br />
# enable PSCAN and ISCAN<br />
$ hciconfig hci0 piscan <br />
# check it worked<br />
{{hc|$ hciconfig|<br />
hci0: Type: USB<br />
BD Address: 00:12:34:56:78:9A ACL MTU: 192:8 SCO MTU: 64:8<br />
'''UP RUNNING PSCAN ISCAN'''<br />
RX bytes:20425 acl:115 sco:0 events:526 errors:0<br />
TX bytes:5543 acl:84 sco:0 commands:340 errors:0<br />
}}<br />
<br />
{{Note|Check DiscoverableTimeout and PairableTimeout in {{ic|/etc/bluetooth/main.conf}}}}<br />
<br />
Try changing device class in {{ic|/etc/bluetooth/main.conf}} as following:<br />
# Default device class. Only the major and minor device class bits are<br />
# considered.<br />
#Class = 0x000100 (from default config)<br />
Class = 0x100100<br />
<br />
This was the only solution to make my computer visible for my phone.<br />
<br />
=== Logitech keyboard does not pair ===<br />
<br />
If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:<br />
$ sudo hciconfig hci0 sspmode 0<br />
<br />
If after pairing, the keyboard still does not connect, check the output of {{ic|hcidump -at}}. If the latter indicates repeatedly connections-disconnections like the following message:<br />
<br />
status 0x00 handle 11 reason 0x13<br />
Reason: Remote User Terminated Connection<br />
<br />
then, the only solution for now is to install [[bluez4|the old Bluetooth stack]].</div>Pushkar8723