mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-28 14:44:39 +08:00
core/advertising: Parse ServiceData
Parse the ServiceData property of LEAdvertisement1
This commit is contained in:
parent
afc287cca0
commit
e3b1d2fa81
@ -296,6 +296,61 @@ fail:
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool parse_advertising_service_data(GDBusProxy *proxy,
|
||||
struct bt_ad *data)
|
||||
{
|
||||
DBusMessageIter iter, entries;
|
||||
|
||||
if (!g_dbus_proxy_get_property(proxy, "ServiceData", &iter))
|
||||
return true;
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
|
||||
return false;
|
||||
|
||||
dbus_message_iter_recurse(&iter, &entries);
|
||||
|
||||
bt_ad_clear_service_data(data);
|
||||
|
||||
while (dbus_message_iter_get_arg_type(&entries)
|
||||
== DBUS_TYPE_DICT_ENTRY) {
|
||||
DBusMessageIter value, entry;
|
||||
const char *uuid_str;
|
||||
bt_uuid_t uuid;
|
||||
uint8_t *service_data;
|
||||
int len;
|
||||
|
||||
dbus_message_iter_recurse(&entries, &entry);
|
||||
dbus_message_iter_get_basic(&entry, &uuid_str);
|
||||
|
||||
if (bt_string_to_uuid(&uuid, uuid_str) < 0)
|
||||
goto fail;
|
||||
|
||||
dbus_message_iter_next(&entry);
|
||||
if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_ARRAY)
|
||||
goto fail;
|
||||
|
||||
dbus_message_iter_recurse(&entry, &value);
|
||||
|
||||
if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_BYTE)
|
||||
goto fail;
|
||||
|
||||
dbus_message_iter_get_fixed_array(&value, &service_data, &len);
|
||||
|
||||
DBG("Adding ServiceData for %s", uuid_str);
|
||||
|
||||
if (!bt_ad_add_service_data(data, &uuid, service_data, len))
|
||||
goto fail;
|
||||
|
||||
dbus_message_iter_next(&entries);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
fail:
|
||||
bt_ad_clear_service_data(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void refresh_advertisement(struct advertisement *ad)
|
||||
{
|
||||
DBG("Refreshing advertisement: %s", ad->path);
|
||||
@ -323,6 +378,11 @@ static bool parse_advertisement(struct advertisement *ad)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parse_advertising_service_data(ad->proxy, ad->data)) {
|
||||
error("Property \"ServiceData\" failed to parse");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* TODO: parse the rest of the properties */
|
||||
|
||||
refresh_advertisement(ad);
|
||||
|
Loading…
Reference in New Issue
Block a user