bluez5:无法连接到 Ubuntu 17.10 上的配对蓝牙设备

bluez5:无法连接到 Ubuntu 17.10 上的配对蓝牙设备

我在 Ubuntu 17.10 上使用 bluez v5.46,无法连接到配对的蓝牙设备。

以下是该命令的输出bluetoothctl

$ bluetoothctl 
[NEW] Controller 6C:0B:84:27:43:66 tensorFlowPHY [default]
Agent registered
[bluetooth]# scan on
Discovery started
[CHG] Controller 6C:0B:84:27:43:66 Discovering: yes
[NEW] Device FC:58:FA:A1:C2:70 OE-P51
[bluetooth]# pair FC:58:FA:A1:C2:70 
Attempting to pair with FC:58:FA:A1:C2:70
[CHG] Device FC:58:FA:A1:C2:70 Connected: yes
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 ServicesResolved: yes
[CHG] Device FC:58:FA:A1:C2:70 Paired: yes
Pairing successful
[CHG] Device FC:58:FA:A1:C2:70 ServicesResolved: no
[CHG] Device FC:58:FA:A1:C2:70 Connected: no
[CHG] Controller 6C:0B:84:27:43:66 Discoverable: no
[bluetooth]# connect FC:58:FA:A1:C2:70 
Attempting to connect to FC:58:FA:A1:C2:70
Failed to connect: org.bluez.Error.Failed

以下是更多信息:

$ journalctl -u bluetooth | tail
Mar 29 12:06:01 tensorFlowPHY systemd[1]: Started Bluetooth service.
Mar 29 12:06:01 tensorFlowPHY bluetoothd[1136]: Starting SDP server
Mar 29 12:06:01 tensorFlowPHY bluetoothd[1136]: Bluetooth management interface 1.14 initialized
Mar 29 14:36:12 tensorFlowPHY bluetoothd[1136]: a2dp-sink profile connect failed for FC:58:FA:A1:C2:70: Protocol not available
Mar 29 14:36:59 tensorFlowPHY bluetoothd[1136]: a2dp-sink profile connect failed for FC:58:FA:A1:C2:70: Protocol not available

systemctl说 :

$ systemctl status bluetooth
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-03-30 16:30:15 CEST; 21s ago
     Docs: man:bluetoothd(8)
 Main PID: 1492 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4915)
   Memory: 1.5M
      CPU: 42ms
   CGroup: /system.slice/bluetooth.service
           └─1492 /usr/lib/bluetooth/bluetoothd

Mar 30 16:30:15 tensorFlowPHY systemd[1]: Starting Bluetooth service...
Mar 30 16:30:15 tensorFlowPHY bluetoothd[1492]: Bluetooth daemon 5.46
Mar 30 16:30:15 tensorFlowPHY systemd[1]: Started Bluetooth service.
Mar 30 16:30:15 tensorFlowPHY bluetoothd[1492]: Starting SDP server
Mar 30 16:30:15 tensorFlowPHY bluetoothd[1492]: Bluetooth management interface 1.14 initialized
Mar 30 16:30:20 tensorFlowPHY bluetoothd[1492]: a2dp-sink profile connect failed for FC:58:FA:A1:C2:70: Protocol not available
Mar 30 16:30:31 tensorFlowPHY bluetoothd[1492]: a2dp-sink profile connect failed for FC:58:FA:A1:C2:70: Protocol not available

编辑 1:我安装了一个缺少的 Ubuntu 包:pulseaudio-module-bluetooth并使用以下命令重新启动 pulseaudio:pulseaudio -k

现在连接试验后的蓝牙日志的输出是:

Mar 30 16:36:59 tensorFlowPHY bluetoothd[1492]: Unable to get connect data for Headset Voice gateway: getpeername: Transport endpoint is not connected (107)
Mar 30 16:37:00 tensorFlowPHY bluetoothd[1492]: connect error: Connection refused (111)
Mar 30 16:37:02 tensorFlowPHY bluetoothd[1492]: connect error: Connection refused (111)

知道为什么吗?

编辑 2:我刚刚按照某人的要求重新启动了 Ubuntu。仍然有相同的 pb。

编辑 3:我已经加载了两个模块/etc/pulse/default.pa

$ egrep "(policy|discover)" /etc/pulse/default.pa
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover

但是我无法在硬盘上找到它们,我需要安装其他东西吗?

编辑 4:我的错误,我使用了locate命令。经过 之后sudo updatedb,该locate命令现在可以找到这 2 个文件。

编辑 5:这是pactl输出:

$ pactl list modules | grep "Name:"
    Name: module-device-restore
    Name: module-stream-restore
    Name: module-card-restore
    Name: module-augment-properties
    Name: module-switch-on-port-available
    Name: module-udev-detect
    Name: module-alsa-card
    Name: module-alsa-card
    Name: module-bluetooth-policy
    Name: module-bluetooth-discover
    Name: module-bluez5-discover
    Name: module-native-protocol-unix
    Name: module-default-device-restore
    Name: module-rescue-streams
    Name: module-always-sink
    Name: module-intended-roles
    Name: module-suspend-on-idle
    Name: module-console-kit
    Name: module-systemd-login
    Name: module-position-event-sounds
    Name: module-role-cork
    Name: module-filter-heuristics
    Name: module-filter-apply
    Name: module-switch-on-connect
    Name: module-x11-publish
    Name: module-x11-cork-request
    Name: module-x11-xsmp

输出dpkg -l

$ dpkg -l | grep blue
ii  bluefish                                  2.2.9-1                                                    amd64        advanced Gtk+ text editor for web and software development
ii  bluefish-data                             2.2.9-1                                                    all          advanced Gtk+ text editor (data)
ii  bluefish-plugins                          2.2.9-1                                                    amd64        advanced Gtk+ text editor (plugins)
ii  blueman                                   2.0.4-1ubuntu3                                             amd64        Graphical bluetooth manager
ii  bluez                                     5.46-0ubuntu3                                              amd64        Bluetooth tools and daemons
ii  bluez-cups                                5.46-0ubuntu3                                              amd64        Bluetooth printer driver for CUPS
ii  bluez-obexd                               5.46-0ubuntu3                                              amd64        bluez obex daemon
ii  bluez-tools                               0.2.0~20140808-5build1                                     amd64        Set of tools to manage Bluetooth devices for linux
ii  gnome-bluetooth                           3.26.1-1                                                   amd64        GNOME Bluetooth tools
ii  indicator-bluetooth                       0.0.6+17.10.20170605-0ubuntu3                              amd64        System bluetooth indicator.
ii  libbluetooth3:amd64                       5.46-0ubuntu3                                              amd64        Library to use the BlueZ Linux Bluetooth stack
ii  libgnome-bluetooth13:amd64                3.26.1-1                                                   amd64        GNOME Bluetooth tools - support library
ii  pulseaudio-module-bluetooth               1:10.0-2ubuntu3.1                                          amd64        Bluetooth module for PulseAudio sound server

以下是已加载的蓝牙 pulseaudio 模块:

$ pactl list modules short | grep module-bluetooth
9   module-bluetooth-policy     
10  module-bluetooth-discover

编辑 6:您的解决方案有效!总结一下:

$ bluetoothctl
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 6C:0B:84:27:43:66 Powered: yes
[bluetooth]# remove FC:58:FA:A1:C2:70
[DEL] Device FC:58:FA:A1:C2:70 OE-P51
Device has been removed
[bluetooth]# exit
Agent unregistered
[DEL] Controller 6C:0B:84:27:43:66 tensorFlowPHY [default]
$ sudo service bluetooth restart

最后:

$ bluetoothctl
[NEW] Controller 6C:0B:84:27:43:66 tensorFlowPHY [default]
Agent registered
[bluetooth]# power on
Changing power on succeeded
[CHG] Controller 6C:0B:84:27:43:66 Powered: yes
[bluetooth]# scan on
Discovery started
[CHG] Controller 6C:0B:84:27:43:66 Discovering: yes
[NEW] Device FC:58:FA:A1:C2:70 OE-P51
[bluetooth]# pair FC:58:FA:A1:C2:70 
Attempting to pair with FC:58:FA:A1:C2:70
[CHG] Device FC:58:FA:A1:C2:70 Connected: yes
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 ServicesResolved: yes
[CHG] Device FC:58:FA:A1:C2:70 Paired: yes
Pairing successful
[CHG] Device FC:58:FA:A1:C2:70 ServicesResolved: no
[CHG] Device FC:58:FA:A1:C2:70 Connected: no
[bluetooth]# connect FC:58:FA:A1:C2:70 
Attempting to connect to FC:58:FA:A1:C2:70
[CHG] Device FC:58:FA:A1:C2:70 Connected: yes
Connection successful
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[CHG] Device FC:58:FA:A1:C2:70 ServicesResolved: yes
[OE-P51]#

答案1

Arch 维基配对成功,但无法连接, 部分:

这可能是由于未安装 pulseaudio-bluetooth 包。如果缺少,请安装它,然后重新启动 pulseaudio。

但是pulseaudio-bluetooth包的名称pulseaudio-module-bluetooth在 Ubuntu 上。

所以安装后你的问题应该就解决了:

sudo apt install pulseaudio-module-bluetooth

安装此包后重新开始您的系统加载一些脉冲音频模块,如module-bluetooth-policymodule-bluetooth-discover

更新:

但如果仍然存在,重启后您将收到以下消息:

连接错误:连接被拒绝(111)

根据答案,你应该将这些行添加到/etc/pulse/default.pa文件中。(如果不存在):

load-module module-bluetooth-policy
load-module module-bluetooth-discover

但这些行应该默认存在,并且重新启动系统后,这些模块应该被加载。

更新2:

根据本文在 Arch wiki 上:

这可能是因为您已经使用同一个蓝牙适配器将设备与另一个操作系统配对(例如双启动)。某些设备无法处理与同一 MAC 地址(即蓝牙适配器)关联的多个配对。您可以通过重新配对设备来解决这个问题

因此请使用以下命令重新配对您的设备(或者您可以使用 GUI 方法):

第一次运行:

bluetoothctl

然后使用此命令显示配对的设备:

devices

这应该有一些像这样的输出:

Device XX:XX:XX:XX:XX:XX Device Name

然后使用此命令删除配对的设备:

remove XX:XX:XX:XX:XX:XX

并重新启动蓝牙服务:

sudo service bluetooth restart

然后尝试再次配对设备。

答案2

禁用网络管理器

...或类似的网络管理。它可以解决大多数网络问题,您可以手动尝试控制 NetworkManager 所编程来监督的服务。

在 Kali Linux 中编辑/usr/sbin/update-rc.d“自动禁用我们不想默认启动的服务”。

在白名单中查找此条目

# List of whitelisted init scripts
#
...
network-manager enabled
...

并将其移至黑名单,并将启用更改为已禁用。同样,如果您希望手动打开蓝牙后,蓝牙在重启后仍保持开启状态,请将蓝牙移至白名单并启用。其次,不要忘记打开蓝牙使连接持久化。

...
[bluetooth]# power on
Changing power on succeeded
[CHG] Device FC:58:FA:A1:C2:70 Connected: yes

你也可以为单个设备禁用 NetworkManager/etc/NetworkManager/NetworkManager.conf,通过 MAC 地址或接口名称进行屏蔽:

[keyfile]
unmanaged-devices=mac:<hwaddr>
[keyfile]
unmanaged-devices=interface-name:<ifname>

要查找本地蓝牙设备的 MAC 地址和接口名称,请使用以下命令

hcitool dev

答案3

您可能需要重新阅读设备的配对手册。我为这个特定问题浪费了 3 个小时,结果发现我的设备有关于如何配对的具体说明。按照说明操作后,我可以毫无问题地配对

相关内容