bluetooth: Get Adapter (controller) properties using GDBUS

In this blog we extent our previous example list HCI controller using GDBUS method to get the properties of the Adapter. We will examine the Adapter properties both by using “GetManagedObject” and also using “GetAll” method in org.freedesktop.DBus.Properties interface.

Code:

In our previous example we have used GetManagedObject and filtered the output only to view Adapter related information (Adapter MAC address and Name). Here we further extended the iteration to view the property of all the interfaces. The same information can also obtained from “GetAll” method in properties interface.

Most important things to note in this sample is the signature which is used to parse the output. For GetManagedObjects we have “a{oa{sa{sv}}}” and GetAll we have {sv}. To understand the format used by DBUS for marshalling and serializing the data one must understand the DBUS type systems. Explaining the complete type system and it’s organization in DBUS is beyond the scope of this blog, but will be covered in dedicated future blog for DBUS specification.

For now, a{oa{sa{sv}}} means,

a{0 – array of object paths (i.e. like int a[10] – array of 10 integers). For example, /org/bluez, /org/bluez/hci0, /org/bluez/hci1, /org/bluez/hci1/dev_XX_YY_ZZ_AA_BB_CC

a{s – array of interfaces. For example, org.bluez.ProfileManager1, org.bluez.Adapter1. Note that our previous curly braces is not closed yet, which means “array of object paths, where each object path may have array of interfaces”. Something like “array of arrays”

a{s – array of properties. Which means, “for each interface, we have array of properties”.

v – variant value. Variant as literally meaning, it can be string, integer, boolean, array of string or even array of arrays. So this details will be part of the software, in our case it’s Bluez. To have specific examples, Adapter Name is a string, Powered is boolean and UUID’s is array of strings.

For GetAll we have “{sv}“, which is again the same representation as in GetManagedObjects for “array of properties name and it’s values in variant”. One can always use “g_variant_get_type_string” to get the exact signature of the data before processing the data.

The same output of GetAll can be observed using dbus-send command. Try the following command after adjusting the adapter path.

dbus-send –system –print-reply –type=method_call –dest=’org.bluez’ ‘/org/bluez/hci0’ org.freedesktop.DBus.Properties.GetAll string:”org.bluez.Adapter1″

Written by -

2 Comments

  • bluetooth: Set Adapter Powered property and watch signal using GDBUS – Linumiz June 6, 2018 at 8:57 pm

    […] our understanding toward BlueZ to set the property in Adapter1 interface in continuation to our Get Property sample. As DBUS based applications can be accessed by any number of clients, modification a […]

    Reply
  • Bluetooth: Adapter scan for new devices using “StartDiscovery” – Linumiz June 8, 2018 at 9:11 am

    […] far we have seen ways to get Adapter properties, set the properties and also to list the devices using GetManagedObjects. To get started with real […]

    Reply
  • Please Post Your Comments & Reviews

    Your email address will not be published. Required fields are marked *

    Send this to a friend