无法使用 bluez-simple-agent 与蓝牙扬声器配对
Can't pairing with bluetooth speaker by using bluez-simple-agent
我正在尝试使用来自 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
但无法与扬声器配对raspberry 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 ")
那是 dbus 权限问题。应该已经安装了 bluetooth.conf dbus 文件以设置正确的蓝牙 dbus 权限。检查您是否拥有此 dbus 配置文件并且它包含正确的策略:/etc/dbus-1/system.d/bluetooth.conf
我正在尝试使用来自 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
但无法与扬声器配对raspberry 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 ")
那是 dbus 权限问题。应该已经安装了 bluetooth.conf dbus 文件以设置正确的蓝牙 dbus 权限。检查您是否拥有此 dbus 配置文件并且它包含正确的策略:/etc/dbus-1/system.d/bluetooth.conf