All of lore.kernel.org
 help / color / mirror / Atom feed
* How to make object for RegisterAdvertisement()
@ 2016-05-30  7:22 Seulki Shin
  2016-06-03  9:53 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Seulki Shin @ 2016-05-30  7:22 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

I'm trying to make a BLE avdertising device.
But I have difficulty to use Bluez D-Bus C APIs.

When I try to call RegisterAdvertisement(), I got this message.

journalctl message:
bluetoothd[352]: Failed to read "Type" property of advertisement

dbus message:
GDBus.Error:org.bluez.Error.Failed: Failed to parse advertisement.

version:
bluez: v5.39
kernel: 4.1.15

code chunk:
static const gchar advertisement_introspection_xml[] =
"<node name='/'>"
"  <interface name='org.freedesktop.DBus.ObjectManager'>"
"    <method name='GetManagedObjects'>"
"      <arg type='a{oa{sa{sv}}}'
name='object_paths_interfaces_and_properties' direction='out'/>"
"    </method>"
"  </interface>"
"  <interface name='org.bluez.LEAdvertisement1'>"
"    <property type='s' name='Type' access='read'>"
"    </property>"
"    <property type='as' name='ServiceUUIDs' access='read'>"
"    </property>"
"    <property type='a{sv}' name='ManufacturerData' access='read'>"
"    </property>"
"    <property type='as' name='SolicitUUIDs' access='read'>"
"    </property>"
"    <property type='a{sv}' name='ServiceData' access='read'>"
"    </property>"
"    <property type='b' name='IncludeTxPower' access='read'>"
"    </property>"
"  </interface>"
"</node>";

static void _serv_method_call(GDBusConnection *connection, const gchar *sender,
                const gchar *object_path, const gchar *interface_name,
                const gchar *method_name, GVariant *parameters,
                GDBusMethodInvocation *invocation, gpointer user_data)
{
GVariantBuilder *b, *b1, *b11;
b = g_variant_builder_new( G_VARIANT_TYPE("a{oa{sa{sv}}}"));
b1 = g_variant_builder_new( G_VARIANT_TYPE("a{sa{sv}}"));
b11 = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));

  g_variant_builder_add(b11, "{sv}", "Type",
                                g_variant_new_string("peripheral");
g_variant_builder_add(b1, "{sa{sv}}",
                                "org.bluez.LEAdvertisement1" , b11);
g_variant_builder_add(b, "{oa{sa{sv}}}",
                                object_path, b1);
  g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(a{oa{sa{sv}}})", b));
}

static const GDBusInterfaceVTable adv_interface_vtable = {
        _adv_method_call,
        NULL,
        NULL,
};

node = g_dbus_node_info_new_for_xml(advertisement_introspection_xml, &e);

object_id = g_dbus_connection_register_object(
                        hci.conn,
                        DBUS_ADVERTISEMENT,
                        node->interfaces[0],
                        &adv_interface_vtable,
                        NULL, NULL, &e);

g_dbus_connection_call_sync(
                        hci.conn,
                        DBUS_BLUEZ_BUS,
                        DBUS_BLUEZ_OBJECT_PATH_HCI0,
                        DBUS_IF_ADVERTISINGMANAGER1, "RegisterAdvertisement",
                        g_variant_new("(o)", DBUS_ADVERTISEMENT),
                        NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &e);

Is this right way to make an advertisement object and call
"RegisterAdvertisement()" ?
How can I register object especially having a dict type properties.

I've already tested python script 'example-advertisement' and it works for me.
Any comments would be highly appreciated.

Thanks,
Slki

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to make object for RegisterAdvertisement()
  2016-05-30  7:22 How to make object for RegisterAdvertisement() Seulki Shin
@ 2016-06-03  9:53 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2016-06-03  9:53 UTC (permalink / raw)
  To: Seulki Shin; +Cc: linux-bluetooth

Hi Slki,

On Mon, May 30, 2016 at 10:22 AM, Seulki Shin <sskcorea@gmail.com> wrote:
> Hi,
>
> I'm trying to make a BLE avdertising device.
> But I have difficulty to use Bluez D-Bus C APIs.
>
> When I try to call RegisterAdvertisement(), I got this message.
>
> journalctl message:
> bluetoothd[352]: Failed to read "Type" property of advertisement
>
> dbus message:
> GDBus.Error:org.bluez.Error.Failed: Failed to parse advertisement.
>
> version:
> bluez: v5.39
> kernel: 4.1.15
>
> code chunk:
> static const gchar advertisement_introspection_xml[] =
> "<node name='/'>"
> "  <interface name='org.freedesktop.DBus.ObjectManager'>"
> "    <method name='GetManagedObjects'>"
> "      <arg type='a{oa{sa{sv}}}'
> name='object_paths_interfaces_and_properties' direction='out'/>"
> "    </method>"
> "  </interface>"
> "  <interface name='org.bluez.LEAdvertisement1'>"
> "    <property type='s' name='Type' access='read'>"
> "    </property>"
> "    <property type='as' name='ServiceUUIDs' access='read'>"
> "    </property>"
> "    <property type='a{sv}' name='ManufacturerData' access='read'>"
> "    </property>"
> "    <property type='as' name='SolicitUUIDs' access='read'>"
> "    </property>"
> "    <property type='a{sv}' name='ServiceData' access='read'>"
> "    </property>"
> "    <property type='b' name='IncludeTxPower' access='read'>"
> "    </property>"
> "  </interface>"
> "</node>";

Perhaps ti is missing org.freedesktop.DBus.Properties interface? You
can check that with d-feet or something similar, btw it shouldn't be
necessary to register ObjectManager for advertisement1:

https://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/advertising-api.txt

> static void _serv_method_call(GDBusConnection *connection, const gchar *sender,
>                 const gchar *object_path, const gchar *interface_name,
>                 const gchar *method_name, GVariant *parameters,
>                 GDBusMethodInvocation *invocation, gpointer user_data)
> {
> GVariantBuilder *b, *b1, *b11;
> b = g_variant_builder_new( G_VARIANT_TYPE("a{oa{sa{sv}}}"));
> b1 = g_variant_builder_new( G_VARIANT_TYPE("a{sa{sv}}"));
> b11 = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
>
>   g_variant_builder_add(b11, "{sv}", "Type",
>                                 g_variant_new_string("peripheral");
> g_variant_builder_add(b1, "{sa{sv}}",
>                                 "org.bluez.LEAdvertisement1" , b11);
> g_variant_builder_add(b, "{oa{sa{sv}}}",
>                                 object_path, b1);
>   g_dbus_method_invocation_return_value(invocation,
>                                 g_variant_new("(a{oa{sa{sv}}})", b));
> }
>
> static const GDBusInterfaceVTable adv_interface_vtable = {
>         _adv_method_call,
>         NULL,
>         NULL,
> };
>
> node = g_dbus_node_info_new_for_xml(advertisement_introspection_xml, &e);
>
> object_id = g_dbus_connection_register_object(
>                         hci.conn,
>                         DBUS_ADVERTISEMENT,
>                         node->interfaces[0],
>                         &adv_interface_vtable,
>                         NULL, NULL, &e);
>
> g_dbus_connection_call_sync(
>                         hci.conn,
>                         DBUS_BLUEZ_BUS,
>                         DBUS_BLUEZ_OBJECT_PATH_HCI0,
>                         DBUS_IF_ADVERTISINGMANAGER1, "RegisterAdvertisement",
>                         g_variant_new("(o)", DBUS_ADVERTISEMENT),
>                         NULL, G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &e);
>
> Is this right way to make an advertisement object and call
> "RegisterAdvertisement()" ?
> How can I register object especially having a dict type properties.

I guess what is missing is the interface to be able to read the
properties, once that is fixed that should work.

> I've already tested python script 'example-advertisement' and it works for me.
> Any comments would be highly appreciated.
>
> Thanks,
> Slki
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-03  9:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-30  7:22 How to make object for RegisterAdvertisement() Seulki Shin
2016-06-03  9:53 ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.