Diff between 177eccc14523bfd936323ba6bb422ff087a3b626 and 80cee3a56c2066737c6915772c034e4ad3a1de32

Changed Files

File Additions Deletions Status
doc/advertising-api.txt +6 -0 modified
src/advertising.c +31 -4 modified

Full Patch

diff --git a/doc/advertising-api.txt b/doc/advertising-api.txt
index c9bc9a1..36fe130 100644
--- a/doc/advertising-api.txt
+++ b/doc/advertising-api.txt
@@ -78,6 +78,12 @@ Properties	string Type
 			If this property is available 'local-name' cannot be
 			present in the Includes.
 
+		uint16 Appearance
+
+			Appearance to be used in the advertising report.
+
+			Possible values: as found on GAP Service.
+
 LE Advertising Manager hierarchy
 ================================
 
diff --git a/src/advertising.c b/src/advertising.c
index e452070..9eb22b9 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -62,6 +62,7 @@ struct btd_adv_client {
 	char *owner;
 	char *path;
 	char *name;
+	uint16_t appearance;
 	GDBusClient *client;
 	GDBusProxy *proxy;
 	DBusMessage *reg;
@@ -472,6 +473,22 @@ static bool parse_local_name(DBusMessageIter *iter,
 	return true;
 }
 
+static bool parse_appearance(DBusMessageIter *iter,
+					struct btd_adv_client *client)
+{
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT16)
+		return false;
+
+	if (client->flags & MGMT_ADV_FLAG_APPEARANCE) {
+		error("Appearance already included");
+		return false;
+	}
+
+	dbus_message_iter_get_basic(iter, &client->appearance);
+
+	return true;
+}
+
 static struct adv_parser {
 	const char *name;
 	bool (*func)(DBusMessageIter *iter, struct btd_adv_client *client);
@@ -483,6 +500,7 @@ static struct adv_parser {
 	{ "ServiceData", parse_service_data },
 	{ "Includes", parse_includes },
 	{ "LocalName", parse_local_name },
+	{ "Appearance", parse_appearance },
 	{ },
 };
 
@@ -562,10 +580,18 @@ static size_t calc_max_adv_len(struct btd_adv_client *client, uint32_t flags)
 static uint8_t *generate_adv_data(struct btd_adv_client *client,
 						uint32_t *flags, size_t *len)
 {
-	if ((*flags & MGMT_ADV_FLAG_APPEARANCE)) {
-		*flags &= ~MGMT_ADV_FLAG_APPEARANCE;
-		/* TODO: Get the appearance from the adaptor once supported. */
-		bt_ad_add_appearance(client->data, 0x0000);
+	if ((*flags & MGMT_ADV_FLAG_APPEARANCE) ||
+					client->appearance != UINT16_MAX) {
+		uint16_t appearance;
+
+		appearance = client->appearance;
+		if (appearance == UINT16_MAX)
+			/* TODO: Get the appearance from the adaptor once
+			 * supported.
+			 */
+			appearance = 0x000;
+
+		bt_ad_add_appearance(client->data, appearance);
 	}
 
 	return bt_ad_generate(client->data, len);
@@ -753,6 +779,7 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager,
 		goto fail;
 
 	client->manager = manager;
+	client->appearance = UINT16_MAX;
 
 	return client;