Difference between revisions of "Bluetooth (简体中文)"

From ArchWiki
Jump to navigation Jump to search
(安装)
(flagged broken section links (interactive))
(Tag: wiki-scripts)
 
(20 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 +
[[Category:简体中文]]
 
[[Category:Bluetooth (简体中文)]]
 
[[Category:Bluetooth (简体中文)]]
 
[[cs:Bluetooth]]
 
[[cs:Bluetooth]]
Line 8: Line 9:
 
[[ja:Bluetooth]]
 
[[ja:Bluetooth]]
 
[[ru:Bluetooth]]
 
[[ru:Bluetooth]]
[http://www.bluetooth.org/ 蓝牙]是一个短距离无线通信标准,适用于手机、计算机和其他电子设备之间的通信。在 Linux 中,通常使用的蓝牙协议栈实现是 [http://www.bluez.org/ BlueZ].
+
[[Wikipedia:Bluetooth|蓝牙(Bluetooth)]]是一个短距离无线通信标准,适用于手机,计算机和其他电子设备之间的通信。在 Linux 中,通常使用的蓝牙协议栈实现是 [http://www.bluez.org/ BlueZ]
 +
== 安装 ==
  
==安装==
+
# [[Install|安装]] {{Pkg|bluez}},这个软件包提供蓝牙的协议栈。
[[Install|安装]] {{Pkg|bluez}} 和  {{Pkg|bluez-utils}} 软件包。{{Pkg|bluez}} 软件包提供蓝牙协议栈,{{Pkg|bluez-utils}} 软件包提供 {{ic|bluetoothctl}} 工具。
+
# [[Install|安装]] {{Pkg|bluez-utils}}, 其提供 {{ic|bluetoothctl}} 工具。 可选的软件包有 {{AUR|bluez-utils-compat}},可额外安装 [[#Deprecated BlueZ tools|已弃用的BLuez工具]]{{Broken section link}}。
如果尚未加载通用蓝牙驱动则需先加载:
+
# 通用蓝牙驱动是 {{ic|btusb}} 内核模块。[[Kernel_module_(简体中文)#获取信息|检查]] 模块是否加载了。如果没有就先[[Kernel_module_(简体中文)#手动加载卸载|加载模块]]。
# modprobe btusb
+
# [[Start/enable]] {{ic|bluetooth.service}}。
 +
 
 +
{{注意|
 +
* 蓝牙守护进程默认只会给属于{{ic|lp}}组的用户暴露出bnep0设备。 如果你想连接到一个蓝牙范围的话先加入那个组。 你可以在 {{ic|/etc/dbus-1/system.d/bluetooth.conf}} 修改那个组。
 +
* 有的蓝牙适配器和无线网卡绑在一起(比如 [http://www.intel.com/content/www/us/en/wireless-products/centrino-advanced-n-6235.html Intel Centrino])。 这样的情况需要先启用无线网卡(笔记本上一般可以用功能键)来让内核可以识别蓝牙适配器。
 +
* 有的蓝牙适配器(比如 Broadcom)和网络适配器冲突。所以你必须在网络服务启动之前先连接蓝牙。
 +
* 类似于hcitool和hciconfig的工具已经停止开发,{{Pkg|bluez-utils}} 里也没有包括,所以尽量不要使用它们。如果还是想用的话可以安装 {{AUR|bluez-utils-compat}}。 参阅和See {{Bug|53110}} and [https://www.spinics.net/lists/linux-bluetooth/msg69239.html Bluez邮件列表]}}
 +
 
 +
=== 前端 ===
 +
 
 +
==== 控制台 ====
 +
 
 +
* {{App|bluetoothctl|Pairing a device from the shell is one of the simplest and most reliable options.|http://www.bluez.org/|{{Pkg|bluez-utils}}}}
 +
 
 +
{{提示|输入 {{ic|echo -e "<command1>\n<command2>\n" {{!}} bluetoothctl}} 来自动化bluetoothctl命令}}
 +
 
 +
==== 图形界面 ====
 +
 
 +
下面的软件包提供图形界面来设置蓝牙。
 +
 
 +
* {{App|GNOME Bluetooth|[[GNOME]]的蓝牙工具。
 +
** {{Pkg|gnome-bluetooth}} 提供后端。
 +
** {{Pkg|gnome-shell}} 提供状态托盘。
 +
** {{Pkg|gnome-control-center}} 可通过图形界面配置蓝牙。可以在活动预览输入“蓝牙”或者运行 {{ic|gnome-control-center bluetooth}} 进行配置。
 +
** 你还可以直接运行 {{ic|bluetooth-sendto}} 命令来把文件发送到远程设备。
 +
** 打开蓝牙设置面板来接收文件;只有在蓝牙设置面板打开时才能接收文件。
 +
** To add a Bluetooth entry to the ''Send To'' 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}}).
 +
|https://wiki.gnome.org/Projects/GnomeBluetooth|}}
 +
* {{App|Bluedevil|[[KDE]]的蓝牙工具。如果Dolphin和系统托盘里没有蓝牙图标,就在系统托盘选项里启用,或者添加一个挂件。点击图标或在KDE系统设置里都可以配置蓝牙。 |https://projects.kde.org/projects/kde/workspace/bluedevil|{{Pkg|bluedevil}}}}
 +
* {{App|Blueberry|Linux Mint的GNOME Bluetooth变种,可在所有桌面环境工作。''Blueberry'' 不支持通过Obex Object推送来接收文件。|https://github.com/linuxmint/blueberry|{{Pkg|blueberry}}}}
 +
* {{App|[[Blueman]]|全功能蓝牙管理器。|https://github.com/blueman-project/blueman|{{Pkg|blueman}}}}
 +
* {{App|[[ObexFTP]]|在任意启动了OBEX的设备上传输文件的工具。|http://dev.zuckschwerdt.org/openobex/wiki/ObexFtp|{{AUR|obexftp}}}}
 +
 
 +
== 配对 ==
 +
 
 +
{{Expansion|Step 5 is unclear. What are Bluetooth agents?}}
  
然后 [[start|启动]] {{ic|bluetooth.service}} systemd 单元。可以在系统引导时自动 [[enable|启用]] 它。
+
{{注意|使用蓝牙之前先检查有没有被 [[rfkill]] 禁用。}}
  
{{注意|
+
这一小节介绍直接用''bluetoothctl''配置''bluez5''的方法,如果你已经有前端(比如GNOME Bluetooth)的话就不需要了。
* 默认情况下,蓝牙仅为 {{ic|lp}} 用户组中的用户启用 bnep0 设备。如果想要加入蓝牙系统,需确认已将用户加入该组。可以修改{{ic|/etc/dbus-1/system.d/bluetooth.conf}}文件中相应的组配置来实现。
 
* 有些蓝牙适配器是与无线网卡绑定在一起的(比如:[http://www.intel.com/content/www/us/en/wireless-products/centrino-advanced-n-6235.html 英特尔迅驰])。这就要求无线网卡先被启用(典型情况是在笔记本电脑上用快捷键启用)以便蓝牙适配器对内核可见。
 
* 有些厂家(如 Broadcom)的蓝牙卡与网卡有冲突(不兼容)。这就需要确认在网络服务引导之前蓝牙设备已连接。}}
 
  
== 图形化前端 ==
+
真实步骤取决于包括的设备和它们的功能。以下是配对设备的一般步骤:
  
下面的软件包提供了一个图形化的界面来自定义蓝牙(Bluetooth)。
+
运行 {{ic|bluetoothctl}} 交互命令。输入 {{ic|help}} 来获取帮助。
  
=== Blueman ===
+
# (optional) Select a default controller with {{ic|select ''MAC_address''}}.
 +
# Enter {{ic|power on}} to turn the power to the controller on. It is off by default and will turn off again each reboot, see [[#Auto power-on after boot]]{{Broken section link}}.
 +
# Enter {{ic|devices}} to get the MAC Address of the device with which to pair.
 +
# Enter device discovery mode with {{ic|scan on}} command if device is not yet on the list.
 +
# Turn the agent on with {{ic|agent on}} or choose a specific agent: if you press tab twice after {{ic|agent}} you should see a list of available agents, e.g. DisplayOnly KeyboardDisplay NoInputNoOutput DisplayYesNo KeyboardOnly off on.
 +
# Enter {{ic|pair ''MAC_address''}} to do the pairing (tab completion works).
 +
# 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.
 +
# Enter {{ic|connect ''MAC_address''}} to establish a connection.
  
[http://blueman-project.org Blueman]是一个全能的基于 [[GTK+ (简体中文)|GTK+]] 开发的蓝牙(Bluetooth)管理器,因此,被[[GNOME (简体中文)|GNOME]]和[[Xfce (简体中文)|Xfce]]所推荐。你可以[[安装]][[官方仓库]]中的{{Pkg|blueman}}。
+
以下为一个交互实例:
  
在确认{{ic|bluetooth}}服务像上文描述的那样正在运行之后,执行{{ic|blueman-applet}}。为了确保这个applet在登录之后运行,将{{ic|blueman-applet}}添加到''System -> Preferences -> Startup Applications'' (GNOME) 或 ''Xfce Menu -> Settings -> Session and Startup'' (Xfce)
+
# bluetoothctl
 +
[NEW] Controller 00:10:20:30:40:50 pi [default]
 +
[bluetooth]# agent KeyboardOnly
 +
Agent registered
 +
[bluetooth]# default-agent
 +
Default agent request successful
 +
[bluetooth]# power on
 +
Changing power on succeeded
 +
[CHG] Controller 00:10:20:30:40:50 Powered: yes
 +
[bluetooth]# scan on
 +
Discovery started
 +
[CHG] Controller 00:10:20:30:40:50 Discovering: yes
 +
[NEW] Device 00:12:34:56:78:90 myLino
 +
[CHG] Device 00:12:34:56:78:90 LegacyPairing: yes
 +
[bluetooth]# pair 00:12:34:56:78:90
 +
Attempting to pair with 00:12:34:56:78:90
 +
[CHG] Device 00:12:34:56:78:90 Connected: yes
 +
[CHG] Device 00:12:34:56:78:90 Connected: no
 +
[CHG] Device 00:12:34:56:78:90 Connected: yes
 +
Request PIN code
 +
[agent] Enter PIN code: 1234
 +
[CHG] Device 00:12:34:56:78:90 Paired: yes
 +
Pairing successful
 +
[CHG] Device 00:12:34:56:78:90 Connected: no
 +
[bluetooth]# connect 00:12:34:56:78:90
 +
Attempting to connect to 00:12:34:56:78:90
 +
[CHG] Device 00:12:34:56:78:90 Connected: yes
 +
Connection successful
  
要用 Blueman 添加或管理设备,用户需要位于 'lp' 组,参见 {{ic|/etc/dbus-1/system.d/bluetooth.conf}} 中对 'lp' 组与 Bluetooth daemon 交互的说明。
+
== 配置 ==
  
{{注意|如果你不是在Gnome/gdm中运行blueman,例如,在Xfce使用朴素的{{ic|startx}}命令,你应当将{{ic|. /etc/X11/xinit/xinitrc.d/*}}添加到你的{{ic|~/.xinitrc}}来确保nautilus能够浏览你的设备。}}
+
=== 开机后自动启动 ===
  
要接收文件,请点击 ''Blueman tray icon -> Local Services -> Transfer -> File Receiving" 并选中 "Enabled".
+
蓝牙在重启后默认不会自动启动。命令 {{ic|hciconfig hci0 up}} 已经被弃用,参阅 [http://www.bluez.org/release-of-bluez-5-35/ release note]。你只需要将 {{ic|1=AutoEnable=true}} 添加在 {{ic|/etc/bluetooth/main.conf}} 底部的 {{ic|[Policy]}} 下面:
  
==== Thunar 脚本工具====
+
{{hc|1=/etc/bluetooth/main.conf|2=
如果你没有使用nautilus(例如thunar)你会发现这个很有用:
+
[Policy]
{{hc|obex_thunar.sh|
+
AutoEnable=true
#!/bin/bash
 
fusermount -u ~/bluetooth
 
obexfs -b $1 ~/bluetooth
 
thunar ~/bluetooth
 
 
}}
 
}}
  
移动脚本到一个合适的位置(例如:{{ic|/usr/bin}}),之后将它设为可执行:
+
== 音频 ==
chmod +x /usr/bin/obex_thunar.sh
 
  
最后更改''Blueman tray icon -> Local Services -> Transfer -> Advanced'' 这一行,改成 {{ic|obex_thunar.sh %d}}
+
要使用蓝牙耳机或音响的话要先安装 {{Pkg|pulseaudio-bluetooth}}。 默认的PulseAudio配置就可以直接用蓝牙耳机或音响了。
 +
{{注意|有时要用 {{Pkg|pavucontrol}} 选择音频的输出设备。}}
  
=== gnome-bluetooth ===
+
如果你有全局的 PulseAudio 设置,首先确保运行守护进程(一般是 {{ic|pulse}})的用户在 {{ic|lp}} 组,并且在 PulseAudio 配置中加载蓝牙模块:
  
[http://live.gnome.org/GnomeBluetooth gnome-bluetooth] 是旧的''bluez-gnome'' 的一个分支,专注于跟[[GNOME (简体中文)|GNOME]]桌面环境相集成。GNOME Bluetooth 是 {{Pkg|gnome-shell}} 需要的,因此如果你在运行 GNOME 3 你应该已经安装了它。 否则,可以用 {{Pkg|gnome-bluetooth}} 这个包安装。
+
{{hc|/etc/pulse/system.pa|2=
 +
...
 +
load-module module-bluetooth-policy
 +
load-module module-bluetooth-discover
 +
...
 +
}}
  
运行{{ic|bluetooth-applet}}来打开一个漂亮的蓝牙(bluetooth)小程序。现在你应该可以能够通过在这个蓝牙(bluetooth)图标来设置设备并且传输文件了。为了保证这个小程序随登录启动,把它添加到''System -> Preferences -> Startup Applications''。
+
[[Bluetooth headset]] 页面有更多关于蓝牙耳机和音响的信息。
  
如果想要在Thunar的文件属性菜单的发送到里添加一个蓝牙(Bluetooth)入口,参考[http://thunar.xfce.org/pwiki/documentation/sendto_menu 这里]。
+
== 疑难解答 ==
  
=== bluedevil ===
+
{{Out of date|Replace hciconfig with newer commands.}}
  
[[KDE (简体中文)|KDE]] 的蓝牙工具是bluedevil,可以用 {{Pkg|bluedevil}} 包[[安装]],它在[[官方仓库]]中。
+
=== 已弃用的Bluez工具 ===
  
确认{{ic|bluetooth}}守护进程在运行。你可以在dolphin和系统通知区域里得到一个蓝牙图标,你可以通过点击这个图标来设置bluedevil、检测蓝牙设备等等。你也可以通过KDE的系统设置来配置bluedevil。
+
Eight BlueZ tools [https://git.kernel.org/pub/scm/bluetooth/bluez.git/commit/?id=b1eb2c4cd057624312e0412f6c4be000f7fc3617 were deprecated] and removed from {{Pkg|bluez-utils}}, although not all of them were superseded by newer tools. The {{AUR|bluez-utils-compat}} package provides an alternative version of {{Pkg|bluez-utils}} with the deprecated tools.
  
=== Fluxbox, openbox, 其他的窗口管理器 ===
+
{| class="wikitable" style="max-width: 50em;"
你当然可以用前面提到过的程序即便你没有用GNOME、Xfce或KDE作为你的桌面管理器。
+
|-
这个列表能够帮助你明白每个程序的功能:
+
! Deprecated tool
* bluetooth-applet -- 能够实现设置、配对向导和已知设备管理的系统通知区域图标。
+
! Most likely replacement
* /usr/lib/gnome-user-share/gnome-user-share -- 如果你想要通过obexBT来从已配对的设备接收文件的话,它应当处于运行状态。
+
|-
 +
| [https://manpages.debian.org/stretch/bluez/gatttool.1.en.html gatttool] || btgatt-client, [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt D-Bus Gatt API]
 +
|-
 +
| [https://manpages.debian.org/stretch/bluez/hciattach.1.en.html hciattach] || btattach
 +
|-
 +
| [https://manpages.debian.org/stretch/bluez/hciconfig.1.en.html hciconfig] || btmgmt (and bluetoothctl?)
 +
|-
 +
| [https://manpages.debian.org/stretch/bluez-hcidump/hcidump.1.en.html hcidump] || btmon (and btsnoop)
 +
|-
 +
| [https://manpages.debian.org/stretch/bluez/hcitool.1.en.html hcitool] || missing, [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt D-Bus Device API] available
 +
|-
 +
| [https://manpages.debian.org/stretch/bluez/rfcomm.1.en.html rfcomm]
 +
| rowspan="2" | missing, implement with [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/profile-api.txt D-Bus Profile1 API]?
 +
|-
 +
| [https://manpages.debian.org/stretch/bluez/ciptool.1.en.html ciptool]
 +
|-
 +
| style="vertical-align: top;" | [https://manpages.debian.org/stretch/bluez/sdptool.1.en.html sdptool]
 +
| missing, functionality seems to be scattered over different D-Bus objects: [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/profile-api.txt Profile], [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/advertising-api.txt Advertising], and the UUIDs arrays in [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/device-api.txt device] and [https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/adapter-api.txt adapter].
 +
|}
  
如果你在文件传输过程中收到了一个错误,并且/或没有收到文件,把下面的代码添加到
+
=== gnome-bluetooth ===
  
<tt>/etc/dbus-1/system.d/bluetooth.conf</tt>
+
如果接收文件时出现以下信息:
  <policy user="your_user_id">
 
    <allow own="org.bluez"/>
 
    <allow send_destination="org.bluez"/>
 
    <allow send_interface="org.bluez.Agent"/>
 
  </policy>
 
  
* bluetooth-wizard -- 负责新设备的配对工作。
+
Bluetooth OBEX start failed: Invalid path
* bluetooth-properties -- 也能够通过Bluetooth-applet图标打开。
+
Bluetooth FTP start failed: Invalid path
* gnome-file-share-properties -- 对通过蓝牙(Bluetooth)传输文件授权。
 
* bluez-sendto -- 提供向远端设备传送文件的图形用户接口。
 
  
== 手工配置 ==
+
确保 [[XDG user directories]] 存在。
  
你需要编辑 {{ic|/etc/bluetooth}} 下的配置文件来实现人工配置Bluez。它们是:
+
=== 蓝牙USB电子狗 ===
audio.conf
 
input.conf
 
main.conf
 
network.conf
 
rfcomm.conf
 
  
默认的配置文件在绝大多数情况下都能都正常工作。绝大多数的配置选项在她们的文件里都有丰富的文档注释,所以自定义成为了一个简单到阅读配置选项的描述和注释的工作。全局设置从{{ic|main.conf}}开始
+
如果你在使用USB电子狗,你要先检查蓝牙电子狗是否被识别。插入USB电子狗后可通过 {{ic|journalctl -f}} 检测(或查看 {{ic|/var/log/messages.log}})。 可能像下面这样:(注意hci):
  
=== 音频流 ===
+
{{bc|
如果你想启用从你的设备到计算机的音频流,你必须更改 {{ic|audio.conf}} 然后添加这个到 {{ic|[General]}} 部分:
+
Feb 20 15:00:24 hostname kernel: [ 2661.349823] usb 4-1: new full-speed USB device number 3 using uhci_hcd
  Enable=Socket
+
Feb 20 15:00:24 hostname bluetoothd[4568]: HCI dev 0 registered
 +
Feb 20 15:00:24 hostname bluetoothd[4568]: Listening for HCI events on hci0
 +
Feb 20 15:00:25 hostname bluetoothd[4568]: HCI dev 0 up
 +
Feb 20 15:00:25 hostname bluetoothd[4568]: Adapter /org/bluez/4568/hci0 has been enabled
 +
}}
  
== 配对 ==
+
如果只有前两行,说明系统找到了设备而只需要启动它。
{{注意| 这一部分描述可能不是完全的准确。感谢'''Gattschardo'''解决了'''个人验证码'''部分}}
+
例:
  
许多蓝牙(Bluetooth)设备要求在使用时[http://en.wikipedia.org/wiki/Bluetooth#Pairing 配对]。
+
{{hc|hciconfig -a hci0|
实际上的过程取决于配对涉及到的设备和这些设备的输入功能。
+
hci0: Type: USB
在移动电话上的配对过程可能会像下面那样:
+
BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
* 计算机向移动电话发送一个配对请求
+
DOWN
* 移动电话上会提示输入一个由计算机给出的PIN(个人识别码)码
+
RX bytes:0 acl:0 sco:0 events:0 errors:0
* 必须在计算机上重新输入同一个序列(指上文中的PIN)。
+
        TX bytes:0 acl:0 sco:0 commands:0 errors:
 +
}}
  
通过执行一下命令来搜索外部设备
+
# hciconfig hci0 up
  $ hcitool scan
 
  
在不使用gnome-bluez包的情况下配对设备,你需要使用一个包含在bluez包里的,叫做''bluez-simple-agent''的工具。你需要从常用的软件仓库里获取几个跟python相关的工具来使这种方法可用:dbus-python和pygobject。 如果你准备好了,你可以以root身份执行这个脚本:
+
{{hc|hciconfig -a hci0|
 +
hci0: Type: USB
 +
BD Address: 00:02:72:C4:7C:06 ACL MTU: 377:10 SCO MTU: 64:8
 +
UP RUNNING
 +
RX bytes:348 acl:0 sco:0 events:11 errors:0
 +
        TX bytes:38 acl:0 sco:0 commands:11 errors:0
 +
}}
  
  # bluez-simple-agent
+
用 {{ic|bluez-utils}} 里的 {{ic|hcitool}} 检查设备是否被检测到。 要获取可用设备和他们的标识和MAC地址可以输入:
  
如果它工作正常,你应当会在控制台得到消息:"Agent registered" 。
+
{{hc|$ hcitool dev|
 +
Devices:
 +
        hci0 00:1B:DC:0F:DB:40
 +
}}
  
现在你可以开始从你的移动电话开始配对工作,这个脚本会在控制台询问你PIN码,你输入进去然后按回车键确认,这样就完成了配对工作。接下来可以通过^C-c终止这个脚本的执行,只需要在配对的时候使用这个脚本,而连接设备时不需要用到它。
+
设备的详细信息可以用获取 {{ic|hciconfig}}:
  
需要查看例子.请向下翻页到示例部分。
+
{{hc|$ hciconfig -a hci0|
 +
hci0:  Type: USB
 +
        BD Address: 00:1B:DC:0F:DB:40 ACL MTU: 310:10 SCO MTU: 64:8
 +
        UP RUNNING PSCAN ISCAN
 +
        RX bytes:1226 acl:0 sco:0 events:27 errors:0
 +
        TX bytes:351 acl:0 sco:0 commands:26 errors:0
 +
        Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80
 +
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
 +
        Link policy: RSWITCH HOLD SNIFF PARK
 +
        Link mode: SLAVE ACCEPT
 +
        Name: 'BlueZ (0)'
 +
        Class: 0x000100
 +
        Service Classes: Unspecified
 +
        Device Class: Computer, Uncategorized
 +
        HCI Ver: 2.0 (0x3) HCI Rev: 0xc5c LMP Ver: 2.0 (0x3) LMP Subver: 0xc5c
 +
        Manufacturer: Cambridge Silicon Radio (10)
 +
}}
  
== 使用 Obex 发送接收文件 ==
+
==== Audio devices start to skip at short distance from dongle ====
除了KDE和Gnome Bluetooth软件包之外,Obexfs是另一个选择,它可以允许你挂载你的移动电话作为文件系统的一部分。注意,如果要使用Obex,你需要一个能够提供Obex FTP服务的设备。
 
安装Obex;
 
# pacman -S obexfs
 
  
然后你可以以root权限运行如下命令来挂载你的移动电话
+
If other devices share the same USB host, they can [https://bbs.archlinux.org/viewtopic.php?pid=1440161#p1440161 interrupt communication with audio devices]. Make sure it is the only device attached to its bus. For example:
# obexfs -b <devices mac address> /mountpoint
 
  
单看更多挂载选项,参阅http://dev.zuckschwerdt.org/openobex/wiki/ObexFs
+
{{hc|$ lsusb|
 +
Bus 002 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
 +
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
Bus 001 Device 004: ID 048d:1345 Integrated Technology Express, Inc. Multi Cardreader
 +
Bus 001 Device 003: ID 0424:a700 Standard Microsystems Corp. 2 Port Hub
 +
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
 +
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 +
}}
  
 +
=== Logitech Bluetooth USB Dongle ===
  
== 示例 ==
+
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 you are using a normal USB mouse/keyoard.
  
=== 西门子 S55 ===
+
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]
  
这是我链接我的S55的过程。(我还没搞明白怎么样通过电话来初始化连接。)
+
Alternatively, you can install the {{Pkg|bluez-hid2hci}} package. When you connect your Logitech dongle it will automatically switch.
* 根据安装步骤
 
 
  $> hcitool scan
 
  Scanning ...
 
          XX:XX:XX:XX:XX:XX  NAME
 
  $> B=XX:XX:XX:XX:XX:XX
 
在另一个终端启动simple-agent
 
  $> su -c bluez-simple-agent
 
  Password:
 
  Agent registered
 
回到上一个终端
 
  $> obexftp -b $B -l "Address book"
 
  # Phone ask for pin, I enter it and answer yes when asked if I want to save the device
 
  ...
 
  <file name="5F07.adr" size="78712" modified="20030101T001858" user-perm="WD" group-perm="" />
 
  ...
 
  $> obexftp -b 00:01:E3:6B:FF:D7 -g "Address book/5F07.adr"
 
  Browsing 00:01:E3:6B:FF:D7 ...
 
  Channel: 5
 
  Connecting...done
 
  Receiving "Address book/5F07.adr"... Sending "Address book"... done
 
  Disconnecting...done
 
  $> obexftp -b 00:01:E3:6B:FF:D7 -p a                     
 
  ...
 
  Sending "a"... done
 
  Disconnecting...done
 
  
=== 罗技鼠标 MX Laser / M555b ===
+
=== hcitool scan: Device not found ===
  
快速测试连接
+
* On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI. Install the {{Pkg|bluez-hid2hci}} package, then [[udev]] should do this automatically. Alternatively, you can run this command to switch to HCI manually:
  
  $> hidd --connect XX:XX:XX:XX:XX:XX
+
  # /usr/lib/udev/hid2hci
  
通过桌面想到设置鼠标一实现自动重连。
+
* 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.
如果你的桌面环境不提供对此任务的支持,参阅[[Bluetooth mouse manual configuration]]向导.
 
  
=== 摩托罗拉 V900 ===
+
* Sometimes also this simple command helps:
  
在安装blueman并且运行blueman-applet之后,在摩托罗拉设备的菜单connections -> bluetooth下单击"find me"。在blueman-applet搜索设备,找到摩托罗拉,然后单击blueman-applet中的“添加。单击“bond”,输入pin码,根据摩托罗达上的提示输入相同的pin码,在终端执行:
+
# hciconfig hci0 up
  
  cd ~/
+
=== rfkill unblock:不能unblock ===
  mkdir bluetooth-temp
 
  obexfs -n xx:yy:zz:... ~/bluetooth-temp
 
  cd ~/bluetooth-temp
 
  
然后浏览... 这样操作时只能访问音频、视频和图片。
+
如果你的设备unblock后依然是soft blocked,试试:
  
=== 摩托罗拉 RAZ ===
+
$ connmanctl enable bluetooth
  
> pacman -S obextool obexfs obexftp openobex bluez
+
=== 电脑蓝牙不可见 ===
  
> lsusb
+
手机蓝牙扫描不到电脑?启动PSCAN和ISCAN:
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 
Bus 002 Device 002: ID 03f0:171d Hewlett-Packard Wireless (Bluetooth + WLAN) Interface [Integrated Module]
 
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 
  
  > hciconfig hci0 up
+
  # enable PSCAN and ISCAN
 +
$ hciconfig hci0 piscan
 +
# check it worked
  
> hciconfig
+
{{hc|$ hciconfig|
hci0:  Type: BR/EDR  Bus: USB
+
hci0:  Type: USB
        BD Address: 00:16:41:97:BA:5E  ACL MTU: 1017:8 SCO MTU: 64:8
+
        BD Address: 00:12:34:56:78:9A ACL MTU: 192:8 SCO MTU: 64:8
        UP RUNNING
+
        '''UP RUNNING PSCAN ISCAN'''
        RX bytes:348 acl:0 sco:0 events:11 errors:0
+
        RX bytes:20425 acl:115 sco:0 events:526 errors:0
        TX bytes:38 acl:0 sco:0 commands:11 errors:0
+
        TX bytes:5543 acl:84 sco:0 commands:340 errors:0
 +
}}
  
> hcitool dev
+
{{注意|在 {{ic|/etc/bluetooth/main.conf}} 检查设备可见超时和配对超时}}
Devices:
 
        hci0    00:16:41:97:BA:5E
 
  
'''注意:确保手机上的蓝牙处于打开状态并且是可见的
+
Try changing device class in {{ic|/etc/bluetooth/main.conf}} as following:
'''
 
  
  > hcitool scan
+
  # Default device class. Only the major and minor device class bits are
  Scanning ...
+
  # considered.
        00:1A:1B:82:9B:6D      [quirxi]
+
#Class = 0x000100 (from default config)
 +
Class = 0x100100
  
> hcitool inq
+
This was the only solution to make my computer visible for my phone.
Inquiring ...
 
        00:1A:1B:82:9B:6D      clock offset: 0x1ee4    class: 0x522204
 
  
> l2ping 00:1A:1B:82:9B:6D
+
=== 罗技键盘配对不了 ===
Ping: 00:1A:1B:82:9B:6D from 00:16:41:97:BA:5E (data size 44) ...
 
44 bytes from 00:1A:1B:82:9B:6D id 0 time 23.94ms
 
44 bytes from 00:1A:1B:82:9B:6D id 1 time 18.85ms
 
44 bytes from 00:1A:1B:82:9B:6D id 2 time 30.88ms
 
44 bytes from 00:1A:1B:82:9B:6D id 3 time 18.88ms
 
44 bytes from 00:1A:1B:82:9B:6D id 4 time 17.88ms
 
44 bytes from 00:1A:1B:82:9B:6D id 5 time 17.88ms
 
6 sent, 6 received, 0% loss
 
  
> hcitool name  00:1A:1B:82:9B:6D
+
If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:
[quirxi]
 
  
  # hciconfig -a hci0
+
  # hciconfig hci0 sspmode 0
hci0:  Type: BR/EDR  Bus: USB
 
        BD Address: 00:16:41:97:BA:5E  ACL MTU: 1017:8  SCO MTU: 64:8
 
        UP RUNNING
 
        RX bytes:9740 acl:122 sco:0 events:170 errors:0
 
        TX bytes:2920 acl:125 sco:0 commands:53 errors:0
 
        Features: 0xff 0xff 0x8d 0xfe 0x9b 0xf9 0x00 0x80
 
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
 
        Link policy:
 
        Link mode: SLAVE ACCEPT
 
        Name: 'BCM2045'
 
        Class: 0x000000
 
        Service Classes: Unspecified
 
        Device Class: Miscellaneous,
 
        HCI Version: 2.0 (0x3)  Revision: 0x204a
 
        LMP Version: 2.0 (0x3)  Subversion: 0x4176
 
        Manufacturer: Broadcoml / Corporation (15)
 
  
> hcitool info 00:1A:1B:82:9B:6D
+
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:
Requesting information ...
 
        BD Address:  00:1A:1B:82:9B:6D
 
        Device Name: [quirxi]
 
        LMP Version: 1.2 (0x2) LMP Subversion: 0x309
 
        Manufacturer: Broadcom Corporation (15)
 
        Features: 0xff 0xfe 0x0d 0x00 0x08 0x08 0x00 0x00
 
                <3-slot packets> <5-slot packets> <encryption> <slot offset>
 
                <timing accuracy> <role switch> <hold mode> <sniff mode>
 
                <RSSI> <channel quality> <SCO link> <HV2 packets>
 
                <HV3 packets> <A-law log> <CVSD> <power control>
 
                <transparent SCO> <AFH cap. slave> <AFH cap. master>
 
  
 +
    status 0x00 handle 11 reason 0x13
 +
    Reason: Remote User Terminated Connection
  
'''编辑你的main.conf并且输入对应与你手机的class( Class = 0x100100 ):'''
+
then, the only solution for now is to install [[bluez4|the old Bluetooth stack]].
> vim /etc/bluetooth/main.conf
 
  
  # Default device class. Only the major and minor device class bits are
+
=== HSP/HFP profiles ===
  # considered.
 
  #Class = 0x000100
 
  Class = 0x100100
 
  
> /etc/rc.d/dbus start
+
bluez5 removed support for the HSP/HFP profiles (telephony headset for [[TeamSpeak]], [[Skype]], etc.). You need to install [[PulseAudio]] (>= version 6) or another application that implements HSP/HFP itself.
:: Starting D-BUS system messagebus
 
[DONE]
 
  
> /etc/rc.d/bluetooth start
+
=== Foxconn / Hon Hai / Lite-On Broadcom device ===
:: Stopping bluetooth subsystem:  pand dund rfcomm hidd  bluetoothd
 
[DONE]
 
:: Starting bluetooth subsystem:  bluetoothd
 
  
 +
Some of these devices require the firmware to be flashed into the device at boot. The firmware is not provided but can converted from a Microsoft Windows ''.hex'' file into a ''.hcd'' using [https://github.com/jessesung/hex2hcd hex2hcd] (which is installed with {{Pkg|bluez-utils}}).
  
'''通过bluez-simple-agent配对只需要做一次。当你的手机要求输入pin码时,输入0000'''
+
In order to get the right ''.hex'' file, try searching the device vendor:product code obtained with ''lsusb'', for example:
> /usr/bin/bluez-simple-agent hci0 00:1A:1B:82:9B:6D
 
RequestPinCode (/org/bluez/10768/hci0/dev_00_1A_1B_82_9B_6D)
 
Enter PIN Code: 0000
 
Release
 
New device (/org/bluez/10768/hci0/dev_00_1A_1B_82_9B_6D)
 
  
'''现在你可以动过ObexFTP来访问你手机上的文件了:'''
+
    ...
> obexftp -v -b 00:1A:1B:82:9B:6D -B 9 -l
+
    Bus 002 Device 004: ID '''04ca:2006''' Lite-On Technology Corp. Broadcom BCM43142A0 Bluetooth Device
Connecting..\done
+
    ...
Tried to connect for 448ms
 
Receiving "(null)"...-<?xml version="1.0" ?>
 
<!DOCTYPE folder-listing SYSTEM "obex-folder-listing.dtd">
 
<folder-listing>
 
<parent-folder />
 
<folder name="audio" size="0" type="folder" modified="20101010T132323Z" user-perm="RW" />
 
<folder name="video" size="0" type="folder" modified="20101010T132323Z" user-perm="RW" />
 
<folder name="picture" size="0" type="folder" modified="20101010T132323Z" user-perm="RW" />
 
</folder-listing>
 
done
 
Disconnecting..\done
 
  
'''你也可以把你的手机作为文件系统的一部分挂载在你的计算机上:'''
+
or
  
> groupadd bluetooth
+
    Bus 004 Device 004: Id '''0489:e031''' Foxconn / Hon Hai
> mkdir /mnt/bluetooth
 
> chown root:bluetooth /mnt/bluetooth
 
> chmod 775 /mnt/bluetooth
 
> usermod -a -G bluetooth arno
 
  
> obexfs -b 00:1A:1B:82:9B:6D /mnt/bluetooth/
+
Alternatively, boot into Windows (a virtual machine installation will suffice) and get the firmware name from the Device Manager utility. If you want to know the model of your device but cannot see it in ''lsusb'', you might see it in ''lsusb -v'' as {{ic|iProduct}}.
> l /mnt/bluetooth/
 
total 6
 
drwxr-xr-x 1 root root    0 10. Okt 13:25 .
 
drwxr-xr-x 5 root root 4096 10. Okt 10:08 ..
 
drwxr-xr-x 1 root root    0 10. Okt 2010  audio
 
drwxr-xr-x 1 root root    0 10. Okt 2010  picture
 
drwxr-xr-x 1 root root    0 10. Okt 2010  video
 
  
=== 使用bluez-simple-agent来跟iPhone配对 ===
+
The ''.hex'' file can be extracted from the downloaded Windows driver without having to run Windows for it. Download the right driver, for example [http://www.fujitsupc.com/downloads/mobile/BLUETOOTH_WIDCOMM_V6.5.0.3100_WIN7-32_FPC46-1771-01.EXE Bluetooth Widcomm] (listed among the drivers for [http://support.fujitsupc.com/CS/Portal/supportsearch.do?srch=DOWNLOADS&Series=P%20Series&Model=P771&ProductType=Notebook%20PC Lifebook P771]), which contains the drivers for many Broadcomm devices. In case of Bluetooth Widcomm, the driver is a self-extracting RAR archive, so it can be extracted using ''{{Pkg|unrar}} x''. To find out which of the many ''.hex'' files is the right one for you, look in the file {{ic|Win32/bcbtums-win7x86-brcm.inf}} and search for {{ic|[RAMUSB'''E031'''.CopyList]}}, where {{ic|E031}} should be replaced with the product code (the second hex number in ''lsusb'') of your device in upper-case. Underneath you should see the file name of the right ''.hex'' file.
  
假设有一个叫做hci0的蓝牙设备和一个在hcitool里显示为'00:00:DE:AD:BE:EF'的iPhone:
+
Once you have the ''.hcd'' file, copy it into {{ic|/lib/firmware/brcm/BCM.hcd}} - this filename is suggested by {{ic|dmesg}} and it may change in your case so check your ''dmesg'' output in order to verify. Then reload the ''btusb'' module:
  
    # bluez-simple-agent hci0 00:00:DE:AD:BE:EF
+
# rmmod btusb
    Passcode:
+
# modprobe btusb
  
== 疑难解答 ==
+
In some cases (with older kernels?), you have to flash the ''.hcd'' file with the ''brcm_patchram_plus'' utility, provided by {{AUR|brcm_patchram_plus-git}}{{Broken package link|{{aur-mirror|brcm_patchram_plus-git}}}}. First, make sure in ''dmesg'' that the device is recognized by ''btusb'' as a bluetooth device. Then, run the following (replace ''04ca 2006'' with your vendor product pair):
  
=== passkey-agent ===
+
  # echo '04ca 2006' > /sys/bus/usb/drivers/btusb/new_id
  $> passkey-agent --default 1234
+
   
Can't register passkey agent
+
Turn on the device:
The name org.bluez was not provided by any .service files
 
你可能在启动<tt>/etc/rc.d/dbus</tt>之前启动了 <tt>/etc/rc.d/bluetooth</tt>
 
$> hciconfig dev
 
# (no listing)
 
尝试运行 <tt>hciconfig hc0 up</tt>
 
  
=== Blueman ===
+
  # hciconfig hci0 up
如果blueman-applet启动失败,试着删除整个''/var/lib/bluetooth''目录然后重新启动电脑(或者仅仅重启hal、dbus和bluetooth这几个服务)。
 
  # rm -rf /var/lib/bluetooth
 
# reboot
 
  
=== gnome-bluetooth ===
+
Flash the firmware:  
如果你通过在蓝牙属性里接受文件时受到如下消息:
 
  Bluetooth OBEX start failed: Invalid path
 
  Bluetooth FTP start failed: Invalid path
 
  
那么运行
+
# brcm_patchram_plus_usb --patchram fw-04ca_2006.hcd hci0
  # pacman -S xdg-user-dirs
 
  $ xdg-user-dirs-update
 
你可以通过下列方式修改路径:
 
  $ vi ~/.config/user-dirs.dirs
 
  
=== Bluetooth USB 适配器 ===
+
The device should now be available. See [https://bbs.archlinux.org/viewtopic.php?id=162688 BBS#162688] for information on making these changes persistent.
如果你在使用USB适配器,你应当确认你的适配器被正确识别。你可以在插入适配器时通过查看<tt>/var/log/messages.log</tt>,这应当会出现类似于下面所示的信息:
 
  
# tail -f /var/log/messages.log
+
=== 设备配对后过一会儿又断开 ===
May  2 23:36:40 tatooine usb 4-1: new full speed USB device using uhci_hcd and address 9
 
May  2 23:36:40 tatooine usb 4-1: configuration #1 chosen from 1 choice
 
May  2 23:36:41 tatooine hcid[8109]: HCI dev 0 registered
 
May  2 23:36:41 tatooine hcid[8109]: HCI dev 0 up
 
May  2 23:36:41 tatooine hcid[8109]: Device hci0 has been added
 
May  2 23:36:41 tatooine hcid[8109]: Starting security manager 0
 
May  2 23:36:41 tatooine hcid[8109]: Device hci0 has been activated
 
  
查看支持的硬件列表,请参考本页的[[Bluetooth#Resources|resources]]。
+
如果运行 {{ic|journalctl}}有以下结果,并且你的设备配对后过一会儿又断开:
  
如果你只得到了前面两行,说明了电脑发现了这个设备,但是你需要手动启动它。
+
bluetoothd: Unable to get connect data for Headset Voice gateway: getpeername: Transport endpoint is not connected (107)
例如:
+
bluetoothd: connect error: Connection refused (111)
  
hciconfig -a hci0
+
这可能是因为你在其它操作系统中用同样的蓝牙适配器配对了这个设备(比如双启动)。有的设备不能在MAC地址和多个设备联系的情况下工作。你可以先移除设配再重新配对:
hci0: Type: USB
 
BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
 
DOWN
 
RX bytes:0 acl:0 sco:0 events:0 errors:0
 
TX bytes:0 acl:0 sco:0 commands:0 errors:
 
sudo hciconfig hci0 up
 
hciconfig -a hci0
 
hci0: Type: USB
 
BD Address: 00:02:72:C4:7C:06 ACL MTU: 377:10 SCO MTU: 64:8
 
UP RUNNING
 
RX bytes:348 acl:0 sco:0 events:11 errors:0
 
TX bytes:38 acl:0 sco:0 commands:11 errors:0
 
  
要验证这个设备被正确检测,你可以使用<tt>bluez-utils</tt>当中的<tt>hcitool</tt>。你可以通过下面方式获得受支持的设备、它们的识别码和硬件地址:
+
$ bluetoothctl
 +
[bluetooth]# devices
 +
Device XX:XX:XX:XX:XX:XX My Device
 +
[bluetooth]# remove XX:XX:XX:XX:XX:XX
  
$ hcitool dev
+
再 [[restart|重启]] {{ic|bluetooth.service}},打开蓝牙适配器,让设备可见,重新扫描配对。因为蓝牙管理器不一样,有时需要重启系统。
Devices:
 
        hci0 00:1B:DC:0F:DB:40
 
  
可以通过<tt>hciconfig</tt>获得关于这个设备更详细的信息。
+
=== 设备连接不了,日志里有错误 ===
  
$ hciconfig -a hci0
+
如果你在连接设备时看见 {{ic|journalctl}} 的输出有类似的消息:
hci0:  Type: USB
 
        BD Address: 00:1B:DC:0F:DB:40 ACL MTU: 310:10 SCO MTU: 64:8
 
        UP RUNNING PSCAN ISCAN
 
        RX bytes:1226 acl:0 sco:0 events:27 errors:0
 
        TX bytes:351 acl:0 sco:0 commands:26 errors:0
 
        Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80
 
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
 
        Link policy: RSWITCH HOLD SNIFF PARK
 
        Link mode: SLAVE ACCEPT
 
        Name: 'BlueZ (0)'
 
        Class: 0x000100
 
        Service Classes: Unspecified
 
        Device Class: Computer, Uncategorized
 
        HCI Ver: 2.0 (0x3) HCI Rev: 0xc5c LMP Ver: 2.0 (0x3) LMP Subver: 0xc5c
 
        Manufacturer: Cambridge Silicon Radio (10)
 
  
=== hcitool scan: 没找到设备 ===
+
a2dp-source profile connect failed for 9C:64:40:22:E1:3F: Protocol not available
* 在某些Dell的笔记本电脑(比如 Studio 15)上,你必须把蓝牙模式由HID改成HCI
 
# hid2hci
 
  
* 有时候这个简单的命令也会有用:
+
安装 {{Pkg|pulseaudio-bluetooth}} 再重启 [[PulseAudio]]。这个错误在文件传输是也会有。
# hciconfig hci0 up
 
  
=== 我的电脑不可见 ===
+
=== 设备扫描不出来 ===
如果不能从你的移动电话上找到你的电脑,打开PSCAN和ISCAN:
 
# 打开 PSCAN 和 ISCAN
 
$ hciconfig hci0 piscan
 
# 确认操作有效
 
$ hciconfig
 
hci0:  Type: USB
 
        BD Address: 00:12:34:56:78:9A ACL MTU: 192:8 SCO MTU: 64:8
 
        '''UP RUNNING PSCAN ISCAN'''
 
        RX bytes:20425 acl:115 sco:0 events:526 errors:0
 
        TX bytes:5543 acl:84 sco:0 commands:340 errors:0
 
  
{{注意 | 检查/etc/bluetooth/main.conf中的发现倒计时和配对倒计时}}
+
有的节能蓝牙设备用bluetoothctl扫描不出来,比如Logitech MX Master。可以安装 {{aur|bluez-utils-compat}}再 [[start|启动]] {{ic|bluetooth.service}} 再输入:
  
试着在 /etc/bluetooth/main.conf 改变设备的class
+
# bluetoothctl
  # Default device class. Only the major and minor device class bits are
+
  [NEW] Controller (MAC) myhostname [default]
  # considered.
+
  [bluetooth]# power on
  #Class = 0x000100 (from default config)
+
  [CHG] Controller (MAC) Class: 0x0c010c
  Class = 0x100100
+
Changing power on succeeded
 +
[CHG] Controller (MAC) Powered: yes
 +
[bluetooth]# scan on
 +
Discovery started
 +
  [CHG] Controller (MAC) Discovering: yes
  
This was the only solution to make my computer visible for my phone.
+
在另一个终端里输入:
  
=== Nautilus cannot browse files ===
+
  # hcitool lescan
If nautilus doesn't open and show this error:
 
Nautilus cannot handle obex: locations. Couldn't display "obex://[XX:XX:XX:XX:XX:XX]/".
 
Install gvfs-obexftp package:
 
  # pacman -S gvfs-obexftp
 
  
== 资源 ==
+
等待你的设备出现,再按 Ctrl+C。 bluetoothctl 就可以获取你的设备并正常配对了。
*[http://www.bluez.org Official Linux Bluetooth protocol stack]
 
*[http://www.holtmann.org/linux/bluetooth/devices.html List of Linux supported Bluetooth Hardware] >> The list is not available anymore!
 
*[http://en.opensuse.org/HCL/Bluetooth_Adapters openSUSE Bluetooth Hardware Compatibility List (HCL)]
 
*[http://www.gentoo.org/doc/en/bluetooth-guide.xml Gentoo wiki is usually good]
 
*[http://linuxgazette.net/109/oregan3.html Accessing a Bluetooth phone on Linux Gazette]
 
*[http://www.adamish.com/blog/#a000361 Bluetooth computer visibility]
 

Latest revision as of 21:42, 8 December 2018

蓝牙(Bluetooth)是一个短距离无线通信标准,适用于手机,计算机和其他电子设备之间的通信。在 Linux 中,通常使用的蓝牙协议栈实现是 BlueZ

安装

  1. 安装 bluez,这个软件包提供蓝牙的协议栈。
  2. 安装 bluez-utils, 其提供 bluetoothctl 工具。 可选的软件包有 bluez-utils-compatAUR,可额外安装 已弃用的BLuez工具[broken link: invalid section]
  3. 通用蓝牙驱动是 btusb 内核模块。检查 模块是否加载了。如果没有就先加载模块
  4. Start/enable bluetooth.service
注意:
  • 蓝牙守护进程默认只会给属于lp组的用户暴露出bnep0设备。 如果你想连接到一个蓝牙范围的话先加入那个组。 你可以在 /etc/dbus-1/system.d/bluetooth.conf 修改那个组。
  • 有的蓝牙适配器和无线网卡绑在一起(比如 Intel Centrino)。 这样的情况需要先启用无线网卡(笔记本上一般可以用功能键)来让内核可以识别蓝牙适配器。
  • 有的蓝牙适配器(比如 Broadcom)和网络适配器冲突。所以你必须在网络服务启动之前先连接蓝牙。
  • 类似于hcitool和hciconfig的工具已经停止开发,bluez-utils 里也没有包括,所以尽量不要使用它们。如果还是想用的话可以安装 bluez-utils-compatAUR。 参阅和See FS#53110 and Bluez邮件列表

前端

控制台

  • bluetoothctl — Pairing a device from the shell is one of the simplest and most reliable options.
http://www.bluez.org/ || bluez-utils
提示: 输入 echo -e "<command1>\n<command2>\n" | bluetoothctl 来自动化bluetoothctl命令

图形界面

下面的软件包提供图形界面来设置蓝牙。

  • GNOME BluetoothGNOME的蓝牙工具。
    • gnome-bluetooth 提供后端。
    • gnome-shell 提供状态托盘。
    • gnome-control-center 可通过图形界面配置蓝牙。可以在活动预览输入“蓝牙”或者运行 gnome-control-center bluetooth 进行配置。
    • 你还可以直接运行 bluetooth-sendto 命令来把文件发送到远程设备。
    • 打开蓝牙设置面板来接收文件;只有在蓝牙设置面板打开时才能接收文件。
    • To add a Bluetooth entry to the Send To menu in Thunar's file properties menu, see instructions here. (The command that needs to be configured is bluetooth-sendto %F).
https://wiki.gnome.org/Projects/GnomeBluetooth ||
  • BluedevilKDE的蓝牙工具。如果Dolphin和系统托盘里没有蓝牙图标,就在系统托盘选项里启用,或者添加一个挂件。点击图标或在KDE系统设置里都可以配置蓝牙。
https://projects.kde.org/projects/kde/workspace/bluedevil || bluedevil
  • Blueberry — Linux Mint的GNOME Bluetooth变种,可在所有桌面环境工作。Blueberry 不支持通过Obex Object推送来接收文件。
https://github.com/linuxmint/blueberry || blueberry
  • Blueman — 全功能蓝牙管理器。
https://github.com/blueman-project/blueman || blueman
  • ObexFTP — 在任意启动了OBEX的设备上传输文件的工具。
http://dev.zuckschwerdt.org/openobex/wiki/ObexFtp || obexftpAUR

配对

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Step 5 is unclear. What are Bluetooth agents? (Discuss in Talk:Bluetooth (简体中文)#)
注意: 使用蓝牙之前先检查有没有被 rfkill 禁用。

这一小节介绍直接用bluetoothctl配置bluez5的方法,如果你已经有前端(比如GNOME Bluetooth)的话就不需要了。

真实步骤取决于包括的设备和它们的功能。以下是配对设备的一般步骤:

运行 bluetoothctl 交互命令。输入 help 来获取帮助。

  1. (optional) Select a default controller with select MAC_address.
  2. Enter power on to turn the power to the controller on. It is off by default and will turn off again each reboot, see #Auto power-on after boot[broken link: invalid section].
  3. Enter devices to get the MAC Address of the device with which to pair.
  4. Enter device discovery mode with scan on command if device is not yet on the list.
  5. Turn the agent on with agent on or choose a specific agent: if you press tab twice after agent you should see a list of available agents, e.g. DisplayOnly KeyboardDisplay NoInputNoOutput DisplayYesNo KeyboardOnly off on.
  6. Enter pair MAC_address to do the pairing (tab completion works).
  7. If using a device without a PIN, one may need to manually trust the device before it can reconnect successfully. Enter trust MAC_address to do so.
  8. Enter connect MAC_address to establish a connection.

以下为一个交互实例:

# bluetoothctl 
[NEW] Controller 00:10:20:30:40:50 pi [default]
[bluetooth]# agent KeyboardOnly 
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 00:10:20:30:40:50 Powered: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller 00:10:20:30:40:50 Discovering: yes
[NEW] Device 00:12:34:56:78:90 myLino
[CHG] Device 00:12:34:56:78:90 LegacyPairing: yes
[bluetooth]# pair 00:12:34:56:78:90
Attempting to pair with 00:12:34:56:78:90
[CHG] Device 00:12:34:56:78:90 Connected: yes
[CHG] Device 00:12:34:56:78:90 Connected: no
[CHG] Device 00:12:34:56:78:90 Connected: yes
Request PIN code
[agent] Enter PIN code: 1234
[CHG] Device 00:12:34:56:78:90 Paired: yes
Pairing successful
[CHG] Device 00:12:34:56:78:90 Connected: no
[bluetooth]# connect 00:12:34:56:78:90
Attempting to connect to 00:12:34:56:78:90
[CHG] Device 00:12:34:56:78:90 Connected: yes
Connection successful

配置

开机后自动启动

蓝牙在重启后默认不会自动启动。命令 hciconfig hci0 up 已经被弃用,参阅 release note。你只需要将 AutoEnable=true 添加在 /etc/bluetooth/main.conf 底部的 [Policy] 下面:

/etc/bluetooth/main.conf
[Policy]
AutoEnable=true

音频

要使用蓝牙耳机或音响的话要先安装 pulseaudio-bluetooth。 默认的PulseAudio配置就可以直接用蓝牙耳机或音响了。

注意: 有时要用 pavucontrol 选择音频的输出设备。

如果你有全局的 PulseAudio 设置,首先确保运行守护进程(一般是 pulse)的用户在 lp 组,并且在 PulseAudio 配置中加载蓝牙模块:

/etc/pulse/system.pa
...
load-module module-bluetooth-policy
load-module module-bluetooth-discover
...

Bluetooth headset 页面有更多关于蓝牙耳机和音响的信息。

疑难解答

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Replace hciconfig with newer commands. (Discuss in Talk:Bluetooth (简体中文)#)

已弃用的Bluez工具

Eight BlueZ tools were deprecated and removed from bluez-utils, although not all of them were superseded by newer tools. The bluez-utils-compatAUR package provides an alternative version of bluez-utils with the deprecated tools.

Deprecated tool Most likely replacement
gatttool btgatt-client, D-Bus Gatt API
hciattach btattach
hciconfig btmgmt (and bluetoothctl?)
hcidump btmon (and btsnoop)
hcitool missing, D-Bus Device API available
rfcomm missing, implement with D-Bus Profile1 API?
ciptool
sdptool missing, functionality seems to be scattered over different D-Bus objects: Profile, Advertising, and the UUIDs arrays in device and adapter.

gnome-bluetooth

如果接收文件时出现以下信息:

Bluetooth OBEX start failed: Invalid path
Bluetooth FTP start failed: Invalid path

确保 XDG user directories 存在。

蓝牙USB电子狗

如果你在使用USB电子狗,你要先检查蓝牙电子狗是否被识别。插入USB电子狗后可通过 journalctl -f 检测(或查看 /var/log/messages.log)。 可能像下面这样:(注意hci):

Feb 20 15:00:24 hostname kernel: [ 2661.349823] usb 4-1: new full-speed USB device number 3 using uhci_hcd
Feb 20 15:00:24 hostname bluetoothd[4568]: HCI dev 0 registered
Feb 20 15:00:24 hostname bluetoothd[4568]: Listening for HCI events on hci0
Feb 20 15:00:25 hostname bluetoothd[4568]: HCI dev 0 up
Feb 20 15:00:25 hostname bluetoothd[4568]: Adapter /org/bluez/4568/hci0 has been enabled

如果只有前两行,说明系统找到了设备而只需要启动它。 例:

hciconfig -a hci0
hci0:	Type: USB
	BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0
	DOWN 
	RX bytes:0 acl:0 sco:0 events:0 errors:0
        TX bytes:0 acl:0 sco:0 commands:0 errors:
# hciconfig hci0 up
hciconfig -a hci0
hci0:	Type: USB
	BD Address: 00:02:72:C4:7C:06 ACL MTU: 377:10 SCO MTU: 64:8
	UP RUNNING 
	RX bytes:348 acl:0 sco:0 events:11 errors:0
        TX bytes:38 acl:0 sco:0 commands:11 errors:0

bluez-utils 里的 hcitool 检查设备是否被检测到。 要获取可用设备和他们的标识和MAC地址可以输入:

$ hcitool dev
Devices:
        hci0	00:1B:DC:0F:DB:40

设备的详细信息可以用获取 hciconfig

$ hciconfig -a hci0
hci0:   Type: USB
        BD Address: 00:1B:DC:0F:DB:40 ACL MTU: 310:10 SCO MTU: 64:8
        UP RUNNING PSCAN ISCAN
        RX bytes:1226 acl:0 sco:0 events:27 errors:0
        TX bytes:351 acl:0 sco:0 commands:26 errors:0
        Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
        Link policy: RSWITCH HOLD SNIFF PARK
        Link mode: SLAVE ACCEPT 
        Name: 'BlueZ (0)'
        Class: 0x000100
        Service Classes: Unspecified
        Device Class: Computer, Uncategorized
        HCI Ver: 2.0 (0x3) HCI Rev: 0xc5c LMP Ver: 2.0 (0x3) LMP Subver: 0xc5c
        Manufacturer: Cambridge Silicon Radio (10)

Audio devices start to skip at short distance from dongle

If other devices share the same USB host, they can interrupt communication with audio devices. Make sure it is the only device attached to its bus. For example:

$ lsusb
Bus 002 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode)
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 048d:1345 Integrated Technology Express, Inc. Multi Cardreader
Bus 001 Device 003: ID 0424:a700 Standard Microsystems Corp. 2 Port Hub
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Logitech Bluetooth USB Dongle

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 you are using a normal USB mouse/keyoard.

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. Discussion

Alternatively, you can install the bluez-hid2hci package. When you connect your Logitech dongle it will automatically switch.

hcitool scan: Device not found

  • On some Dell laptops (e.g. Studio 15) you have to switch the Bluetooth mode from HID to HCI. Install the bluez-hid2hci package, then udev should do this automatically. Alternatively, you can run this command to switch to HCI manually:
# /usr/lib/udev/hid2hci
  • 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.
  • Sometimes also this simple command helps:
# hciconfig hci0 up

rfkill unblock:不能unblock

如果你的设备unblock后依然是soft blocked,试试:

$ connmanctl enable bluetooth

电脑蓝牙不可见

手机蓝牙扫描不到电脑?启动PSCAN和ISCAN:

# enable PSCAN and ISCAN
$ hciconfig hci0 piscan 
# check it worked
$ hciconfig
hci0:   Type: USB
        BD Address: 00:12:34:56:78:9A ACL MTU: 192:8 SCO MTU: 64:8
        UP RUNNING PSCAN ISCAN
        RX bytes:20425 acl:115 sco:0 events:526 errors:0
        TX bytes:5543 acl:84 sco:0 commands:340 errors:0
注意: /etc/bluetooth/main.conf 检查设备可见超时和配对超时

Try changing device class in /etc/bluetooth/main.conf as following:

# Default device class. Only the major and minor device class bits are
# considered.
#Class = 0x000100 (from default config)
Class = 0x100100

This was the only solution to make my computer visible for my phone.

罗技键盘配对不了

If you do not get the passkey when you try to pair your Logitech keyboard, type the following command:

# hciconfig hci0 sspmode 0

If after pairing, the keyboard still does not connect, check the output of hcidump -at. If the latter indicates repeatedly connections-disconnections like the following message:

   status 0x00 handle 11 reason 0x13
   Reason: Remote User Terminated Connection

then, the only solution for now is to install the old Bluetooth stack.

HSP/HFP profiles

bluez5 removed support for the HSP/HFP profiles (telephony headset for TeamSpeak, Skype, etc.). You need to install PulseAudio (>= version 6) or another application that implements HSP/HFP itself.

Foxconn / Hon Hai / Lite-On Broadcom device

Some of these devices require the firmware to be flashed into the device at boot. The firmware is not provided but can converted from a Microsoft Windows .hex file into a .hcd using hex2hcd (which is installed with bluez-utils).

In order to get the right .hex file, try searching the device vendor:product code obtained with lsusb, for example:

   ...
   Bus 002 Device 004: ID 04ca:2006 Lite-On Technology Corp. Broadcom BCM43142A0 Bluetooth Device
   ...

or

   Bus 004 Device 004: Id 0489:e031 Foxconn / Hon Hai

Alternatively, boot into Windows (a virtual machine installation will suffice) and get the firmware name from the Device Manager utility. If you want to know the model of your device but cannot see it in lsusb, you might see it in lsusb -v as iProduct.

The .hex file can be extracted from the downloaded Windows driver without having to run Windows for it. Download the right driver, for example Bluetooth Widcomm (listed among the drivers for Lifebook P771), which contains the drivers for many Broadcomm devices. In case of Bluetooth Widcomm, the driver is a self-extracting RAR archive, so it can be extracted using unrar x. To find out which of the many .hex files is the right one for you, look in the file Win32/bcbtums-win7x86-brcm.inf and search for [RAMUSBE031.CopyList], where E031 should be replaced with the product code (the second hex number in lsusb) of your device in upper-case. Underneath you should see the file name of the right .hex file.

Once you have the .hcd file, copy it into /lib/firmware/brcm/BCM.hcd - this filename is suggested by dmesg and it may change in your case so check your dmesg output in order to verify. Then reload the btusb module:

# rmmod btusb
# modprobe btusb

In some cases (with older kernels?), you have to flash the .hcd file with the brcm_patchram_plus utility, provided by brcm_patchram_plus-gitAUR[broken link: archived in aur-mirror]. First, make sure in dmesg that the device is recognized by btusb as a bluetooth device. Then, run the following (replace 04ca 2006 with your vendor product pair):

# echo '04ca 2006' > /sys/bus/usb/drivers/btusb/new_id
    

Turn on the device:

# hciconfig hci0 up

Flash the firmware:

# brcm_patchram_plus_usb --patchram fw-04ca_2006.hcd hci0

The device should now be available. See BBS#162688 for information on making these changes persistent.

设备配对后过一会儿又断开

如果运行 journalctl有以下结果,并且你的设备配对后过一会儿又断开:

bluetoothd: Unable to get connect data for Headset Voice gateway: getpeername: Transport endpoint is not connected (107)
bluetoothd: connect error: Connection refused (111)

这可能是因为你在其它操作系统中用同样的蓝牙适配器配对了这个设备(比如双启动)。有的设备不能在MAC地址和多个设备联系的情况下工作。你可以先移除设配再重新配对:

$ bluetoothctl
[bluetooth]# devices
Device XX:XX:XX:XX:XX:XX My Device
[bluetooth]# remove XX:XX:XX:XX:XX:XX

重启 bluetooth.service,打开蓝牙适配器,让设备可见,重新扫描配对。因为蓝牙管理器不一样,有时需要重启系统。

设备连接不了,日志里有错误

如果你在连接设备时看见 journalctl 的输出有类似的消息:

a2dp-source profile connect failed for 9C:64:40:22:E1:3F: Protocol not available

安装 pulseaudio-bluetooth 再重启 PulseAudio。这个错误在文件传输是也会有。

设备扫描不出来

有的节能蓝牙设备用bluetoothctl扫描不出来,比如Logitech MX Master。可以安装 bluez-utils-compatAUR启动 bluetooth.service 再输入:

# bluetoothctl
[NEW] Controller (MAC) myhostname [default]
[bluetooth]# power on
[CHG] Controller (MAC) Class: 0x0c010c
Changing power on succeeded
[CHG] Controller (MAC) Powered: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller (MAC) Discovering: yes

在另一个终端里输入:

# hcitool lescan

等待你的设备出现,再按 Ctrl+C。 bluetoothctl 就可以获取你的设备并正常配对了。