Search code examples
bluetoothdbusbluezcharacteristics

Writing characteristics value using Dbus API for bluez 5.31 failed with kernel 4.1


I am unable to write to atrribute value to a characteristics exposed via dbus on the new 4.1 kernel.

Before upgrading to kernel 4.1 the same application can write attribute value to the characteristics via dbus without any issue.

Following is the log collected from bluetoothd -

org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 1 matched rules; type="method_call", sender=":1.24" (uid=0 pid=4112 comm="bluez-5.31/src/bluetoothd -ndE ") interface="org.bluez.GattCharacteristic1" member="WriteValue" error name="(unset)" requested_reply="0" destination=":1.25" (uid=0 pid=4114 comm="./test ")

Any suggestions? Thanks in advance.


Solution

  • It showed access denied because by default interface "org.bluez.GattCharacteristic1" was not enabled in kernel 4.1

    To access any dbus interface dbus configuration file must allow the interface name otherwise it will show Access Denied.

    We can find dbus configuration file for bluetooth at /etc/dbus-1/system.d/bluetooth.conf which seems bellow:

    <policy user="root">
        <allow own="org.bluez"/>
        <allow send_destination="org.bluez"/>
        <allow send_interface="org.bluez.Agent1"/>
        ... ... ... ...
      </policy>
    

    permission for the interface org.bluez.GattCharacteristic1 need to add in policy as bellow:

       <policy user="root">
         <allow own="org.bluez"/>
         <allow send_destination="org.bluez"/>
         <allow send_interface="org.bluez.Agent1"/>
         ... ... ... ...
         <allow send_interface="org.bluez.GattCharacteristic1"/>
         <allow send_interface="org.bluez.GattDescriptor1"/>
         <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
         ... ... ... ...
      </policy>
    

    In my case it solved the problem