使用bluez-simple-agent无法与蓝牙扬声器配对

时间:2015-03-26 08:30:12

标签: bluetooth raspberry-pi

我正在尝试使用Raspberry Pi的蓝牙音箱。

hcitool scan显示设备。

$ hcitool scan
Scanning ...
    xx:xx:xx:xx:xx:xx   MEOSOUND003
    xx:xx:xx:xx:xx:xx   macbook

l2ping没问题。

$ sudo l2ping -c 1 xx:xx:xx:xx:xx:xx
Ping: xx:xx:xx:xx:xx:xx from xx:xx:xx:xx:xx:xx (data size 44) ...
16 bytes from xx:xx:xx:xx:xx:xx id 0 time 14.97ms
1 sent, 1 received, 0% loss

但它无法与扬声器一起使用覆盆子pi。

$ bluez-simple-agent hci0 xx:xx:xx:xx:xx:xx
ERROR:dbus.proxies:Introspect error on :1.1:/: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.11" (uid=1000 pid=3715 comm="/usr/bin/python /usr/bin/bluez-simple-agent hci0 0") interface="org.freedesktop.DBus.Introspectable" member="Introspect" error name="(unset)" requested_reply="0" destination=":1.1" (uid=0 pid=2254 comm="/usr/sbin/bluetoothd ")
Traceback (most recent call last):
  File "/usr/bin/bluez-simple-agent", line 102, in <module>
    path = manager.FindAdapter(args[0])
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.11" (uid=1000 pid=3715 comm="/usr/bin/python /usr/bin/bluez-simple-agent hci0 0") interface="org.bluez.Manager" member="FindAdapter" error name="(unset)" requested_reply="0" destination=":1.1" (uid=0 pid=2254 comm="/usr/sbin/bluetoothd ")

我该如何解决这个问题?

bluetooth.conf

感谢@AlanAu,我发现我必须配置/etc/dbus-1/system.d/bluetooth.conf。但我无法弄清楚如何启用蓝牙音箱。

我添加的是<allow send_type="method_call"></allow>行。

<!-- This configuration file specifies the required security policies
     for Bluetooth core daemon to work. -->

<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>

  <!-- ../system.conf have denied everything, so we just punch some holes -->

  <policy user="root">
    <allow own="org.bluez"/>
    <allow send_destination="org.bluez"/>
    <allow send_type="method_call"></allow>

    <!-- allow root to send to agents -->
    <allow send_interface="org.bluez.Agent"/>

        <allow send_interface="org.bluez.HandsfreeAgent"/>
    <allow send_interface="org.bluez.MediaEndpoint"/>
    <allow send_interface="org.bluez.MediaPlayer"/>
    <allow send_interface="org.bluez.Watcher"/>
    <allow send_interface="org.bluez.ThermometerWatcher"/>
  </policy>

  <!-- allow users at the console, see consolekit or libpam-foreground -->
  <policy at_console="true">
    <allow send_destination="org.bluez"/>
  </policy>

  <!-- allow users of bluetooth group to communicate with hcid -->
  <policy group="bluetooth">
    <allow send_destination="org.bluez"/>
  </policy>

  <!-- allow users of lp group (printing subsystem) to communicate with hcid -->
  <policy group="lp">
    <allow send_destination="org.bluez"/>
  </policy>


  <policy context="default">
    <deny send_destination="org.bluez"/>
  </policy>

</busconfig>

蓝牙服务器恢复后出现以下错误:

$ bluez-simple-agent hci0 00:25:DB:96:09:5E
ERROR:dbus.proxies:Introspect error on :1.1:/: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.45" (uid=1000 pid=5079 comm="/usr/bin/python /usr/bin/bluez-simple-agent hci0 0") interface="org.freedesktop.DBus.Introspectable" member="Introspect" error name="(unset)" requested_reply="0" destination=":1.1" (uid=0 pid=2254 comm="/usr/sbin/bluetoothd ")
Traceback (most recent call last):
  File "/usr/bin/bluez-simple-agent", line 102, in <module>
    path = manager.FindAdapter(args[0])
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.45" (uid=1000 pid=5079 comm="/usr/bin/python /usr/bin/bluez-simple-agent hci0 0") interface="org.bluez.Manager" member="FindAdapter" error name="(unset)" requested_reply="0" destination=":1.1" (uid=0 pid=2254 comm="/usr/sbin/bluetoothd ")

这是sudo

$ sudo bluez-simple-agent hci0 00:25:DB:96:09:5E
Creating device failed: org.bluez.Error.AuthenticationRejected: Authentication Rejected
带有NoInputNotput选项的

$ bluez-simple-agent -c NoInputNoOutput hci0 00:25:DB:96:09:5E
ERROR:dbus.proxies:Introspect error on :1.1:/: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.52" (uid=1000 pid=5218 comm="/usr/bin/python /usr/bin/bluez-simple-agent -c NoI") interface="org.freedesktop.DBus.Introspectable" member="Introspect" error name="(unset)" requested_reply="0" destination=":1.1" (uid=0 pid=2254 comm="/usr/sbin/bluetoothd ")
Traceback (most recent call last):
  File "/usr/bin/bluez-simple-agent", line 102, in <module>
    path = manager.FindAdapter(args[0])
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/usr/lib/python2.7/dist-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.52" (uid=1000 pid=5218 comm="/usr/bin/python /usr/bin/bluez-simple-agent -c NoI") interface="org.bluez.Manager" member="FindAdapter" error name="(unset)" requested_reply="0" destination=":1.1" (uid=0 pid=2254 comm="/usr/sbin/bluetoothd ")

1 个答案:

答案 0 :(得分:2)

这是一个dbus权限问题。应该已经安装了bluetooth.conf dbus文件来设置正确的蓝牙dbus权限。检查您是否有此dbus配置文件,并且它包含正确的策略:/etc/dbus-1/system.d/bluetooth.conf