advertising: Add SupportedFeatures to LEAdvertisingManager1
authorDaniel Winkler <danielwinkler@google.com>
Tue, 16 Mar 2021 23:22:15 +0000 (16:22 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:35 +0000 (19:08 +0530)
The new SupportedFeatures member tells advertising clients whether the
platform has hardware support for advertising or capability to set tx
power of advertisements.

Additionally, fix small typo in "secondary_exists" function name.

Change is tested on hatch and kukui chromebooks by using dbus-send to
verify that SupportedFeatures always exists, and is only populated when
extended advertising is available.

Reviewed-by: Miao-chen Chou <mcchou@chromium.org>
Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
lib/mgmt.h
src/advertising.c

index 0979b79..d76a5a9 100644 (file)
@@ -503,6 +503,8 @@ struct mgmt_rp_add_advertising {
 #define MGMT_ADV_FLAG_SEC_1M           (1 << 7)
 #define MGMT_ADV_FLAG_SEC_2M           (1 << 8)
 #define MGMT_ADV_FLAG_SEC_CODED                (1 << 9)
+#define MGMT_ADV_FLAG_CAN_SET_TX_POWER (1 << 10)
+#define MGMT_ADV_FLAG_HW_OFFLOAD       (1 << 11)
 #define MGMT_ADV_PARAM_DURATION                (1 << 12)
 #define MGMT_ADV_PARAM_TIMEOUT         (1 << 13)
 #define MGMT_ADV_PARAM_INTERVALS       (1 << 14)
index 88d96a0..6d3d32d 100644 (file)
@@ -1613,7 +1613,8 @@ static void append_secondary(struct btd_adv_manager *manager,
        }
 }
 
-static gboolean secondary_exits(const GDBusPropertyTable *property, void *data)
+static gboolean secondary_exists(const GDBusPropertyTable *property,
+                                               void *data)
 {
        struct btd_adv_manager *manager = data;
 
@@ -1637,6 +1638,43 @@ static gboolean get_supported_secondary(const GDBusPropertyTable *property,
        return TRUE;
 }
 
+static struct adv_feature {
+       int flag;
+       const char *name;
+} features[] = {
+       { MGMT_ADV_FLAG_CAN_SET_TX_POWER, "CanSetTxPower" },
+       { MGMT_ADV_FLAG_HW_OFFLOAD, "HardwareOffload" },
+       { },
+};
+
+static void append_features(struct btd_adv_manager *manager,
+                                               DBusMessageIter *iter)
+{
+       struct adv_feature *feat;
+
+       for (feat = features; feat->name; feat++) {
+               if (manager->supported_flags & feat->flag)
+                       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
+                                                               &feat->name);
+       }
+}
+
+static gboolean get_supported_features(const GDBusPropertyTable *property,
+                                       DBusMessageIter *iter, void *data)
+{
+       struct btd_adv_manager *manager = data;
+       DBusMessageIter entry;
+
+       dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+                                       DBUS_TYPE_STRING_AS_STRING, &entry);
+
+       append_features(manager, &entry);
+
+       dbus_message_iter_close_container(iter, &entry);
+
+       return TRUE;
+}
+
 static gboolean get_supported_cap(const GDBusPropertyTable *property,
                                        DBusMessageIter *iter, void *data)
 {
@@ -1675,7 +1713,9 @@ static const GDBusPropertyTable properties[] = {
        { "SupportedInstances", "y", get_instances, NULL, NULL },
        { "SupportedIncludes", "as", get_supported_includes, NULL, NULL },
        { "SupportedSecondaryChannels", "as", get_supported_secondary, NULL,
-                                                       secondary_exits },
+                                                       secondary_exists },
+       { "SupportedFeatures", "as", get_supported_features, NULL, NULL,
+                                       G_DBUS_PROPERTY_FLAG_EXPERIMENTAL},
        { "SupportedCapabilities", "a{sv}", get_supported_cap, NULL, NULL,
                                        G_DBUS_PROPERTY_FLAG_EXPERIMENTAL},
        { }