Return-Path: From: Michael Janssen To: linux-bluetooth@vger.kernel.org Cc: Michael Janssen Subject: [BlueZ 08/12] advertising-manager: Parse ServiceUUIDs Date: Thu, 12 Mar 2015 10:11:55 -0700 Message-Id: <1426180319-16509-9-git-send-email-jamuraa@chromium.org> In-Reply-To: <1426180319-16509-1-git-send-email-jamuraa@chromium.org> References: <1426180319-16509-1-git-send-email-jamuraa@chromium.org> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: Parse the ServiceUUIDs property of the LEAdvertisement1 object. --- src/advertising-manager.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- tools/advertisement-example | 3 ++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/advertising-manager.c b/src/advertising-manager.c index 3f53637..92e5cad 100644 --- a/src/advertising-manager.c +++ b/src/advertising-manager.c @@ -174,6 +174,44 @@ static bool parse_advertising_type(GDBusProxy *proxy, uint8_t *type) return false; } +static bool parse_advertising_service_uuids(GDBusProxy *proxy, + struct advertising_data *data) +{ + DBusMessageIter iter, ariter; + + if (!g_dbus_proxy_get_property(proxy, "ServiceUUIDs", &iter)) + return true; + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) + return false; + + dbus_message_iter_recurse(&iter, &ariter); + + advertising_data_clear_service_uuid(data); + + while (dbus_message_iter_get_arg_type(&ariter) == DBUS_TYPE_STRING) { + const char *uuid_str; + bt_uuid_t uuid; + + dbus_message_iter_get_basic(&ariter, &uuid_str); + + DBG("Adding ServiceUUID: %s", uuid_str); + + if (bt_string_to_uuid(&uuid, uuid_str) < 0) + goto fail; + + advertising_data_add_service_uuid(data, &uuid); + + dbus_message_iter_next(&ariter); + } + + return true; + +fail: + advertising_data_clear_service_uuid(data); + return false; +} + static void refresh_advertisement(struct advertisement *ad) { DBG("Refreshing advertisement: %s", ad->path); @@ -189,7 +227,12 @@ static bool parse_advertisement(struct advertisement *ad) return false; } - /* TODO: parse the remaining properties into a shared structure */ + if (!parse_advertising_service_uuids(ad->proxy, ad->data)) { + error("Property \"ServiceUUIDs\" failed to parse correctly"); + return false; + } + + /* TODO: parse the rest of the properties */ refresh_advertisement(ad); diff --git a/tools/advertisement-example b/tools/advertisement-example index dcd2ea2..fb2bdde 100644 --- a/tools/advertisement-example +++ b/tools/advertisement-example @@ -107,7 +107,8 @@ class TestAdvertisement(Advertisement): def __init__(self, bus, index): Advertisement.__init__(self, bus, index, 'broadcast') - self.add_manufacturer_data(0x00ff, 'testing') + self.add_service_uuid('0000180D-0000-1000-8000-00805F9B34FB') + self.add_service_uuid('0000180F-0000-1000-8000-00805F9B34FB') def register_ad_cb(): -- 2.2.0.rc0.207.ga3a616c