Skip to contentSkip to conversation

advertising: Add IncludeName property

PATCH New Luiz Augusto von Dentz 1 participant 2 messages Aug 3, 2017 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 advertising: Add IncludeName property

From: Luiz Augusto von Dentz <[email protected]>

This adds support to include adapter name, or alias, in the scan response with use of IncludeName property.

---
 doc/advertising-api.txt |  5 +++++
 src/advertising.c       | 27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
doc/advertising-api.txt +5 -0
index 7a29b7095..3ef9a9d94 100644
@@ -66,6 +66,11 @@ Properties	string Type
 			Includes the Tx Power in the advertising packet.
 			If missing, the Tx Power is not included.
 
+		bool IncludeName
+
+			Include adapter Name, or Alias if set, as scan
+			response data.
+
 
 LE Advertising Manager hierarchy
 ================================
src/advertising.c +27 -0
index c2af3acb4..66e380a02 100644
@@ -63,6 +63,7 @@ struct btd_adv_client {
 	DBusMessage *reg;
 	uint8_t type; /* Advertising type */
 	bool include_tx_power;
+	bool include_name;
 	struct bt_ad *data;
 	uint8_t instance;
 };
@@ -411,6 +412,24 @@ static bool parse_include_tx_power(GDBusProxy *proxy, bool *included)
 	return true;
 }
 
+static bool parse_include_name(GDBusProxy *proxy, bool *included)
+{
+	DBusMessageIter iter;
+	dbus_bool_t b;
+
+	if (!g_dbus_proxy_get_property(proxy, "IncludeName", &iter))
+		return true;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN)
+		return false;
+
+	dbus_message_iter_get_basic(&iter, &b);
+
+	*included = b;
+
+	return true;
+}
+
 static void add_client_complete(struct btd_adv_client *client, uint8_t status)
 {
 	DBusMessage *reply;
@@ -497,6 +516,9 @@ static DBusMessage *refresh_advertisement(struct btd_adv_client *client)
 	if (client->include_tx_power)
 		flags |= MGMT_ADV_FLAG_TX_POWER;
 
+	if (client->include_name)
+		flags |= MGMT_ADV_FLAG_LOCAL_NAME;
+
 	adv_data = bt_ad_generate(client->data, &adv_data_len);
 
 	if (!adv_data || (adv_data_len > calc_max_adv_len(client, flags))) {
@@ -573,6 +595,11 @@ static DBusMessage *parse_advertisement(struct btd_adv_client *client)
 		goto fail;
 	}
 
+	if (!parse_include_name(client->proxy, &client->include_name)) {
+		error("Property \"IncludeName\" failed to parse");
+		goto fail;
+	}
+
 	return refresh_advertisement(client);
 
 fail:
Signature · 1 line
2.13.3
author maintainer
#1 lore raw

PATCH 2/2 client: Add set-advertise-name command

From: Luiz Augusto von Dentz <[email protected]>

This adds set-advertise-name which enables the use of adapter name/alias in the scan response:

[bluetooth]# set-advertise-name on
[bluetooth]# advertise on

@ MGMT Command: Add Advertising (0x003e) plen 11
Instance: 1
Flags: 0x00000043
Switch into Connectable mode
Advertise as Discoverable
Add Local Name in Scan Response
Duration: 0
Timeout: 0
Advertising data length: 0
Scan response length: 0

---
 client/advertising.c | 21 +++++++++++++++++++++
 client/advertising.h |  1 +
 client/main.c        | 22 ++++++++++++++++++++++
 3 files changed, 44 insertions(+)
client/advertising.c +21 -0
index 81fa85118..67e87c7ca 100644
@@ -49,6 +49,7 @@ static uint16_t ad_manufacturer_id;
 static uint8_t ad_manufacturer_data[25];
 static uint8_t ad_manufacturer_data_len = 0;
 static gboolean ad_tx_power = FALSE;
+static gboolean ad_name = FALSE;
 
 static void ad_release(DBusConnection *conn)
 {
@@ -252,6 +253,20 @@ static gboolean get_tx_power(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
+static gboolean include_name_exists(const GDBusPropertyTable *property,
+							void *data)
+{
+	return ad_name;
+}
+
+static gboolean get_include_name(const GDBusPropertyTable *property,
+				DBusMessageIter *iter, void *user_data)
+{
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &ad_name);
+
+	return TRUE;
+}
+
 static const GDBusPropertyTable ad_props[] = {
 	{ "Type", "s", get_type },
 	{ "ServiceUUIDs", "as", get_uuids, NULL, uuids_exists },
@@ -259,6 +274,7 @@ static const GDBusPropertyTable ad_props[] = {
 	{ "ManufacturerData", "a{qv}", get_manufacturer_data, NULL,
 						manufacturer_data_exists },
 	{ "IncludeTxPower", "b", get_tx_power, NULL, tx_power_exists },
+	{ "IncludeName", "b", get_include_name, NULL, include_name_exists },
 	{ }
 };
 
@@ -453,3 +469,8 @@ void ad_advertise_tx_power(gboolean value)
 {
 	ad_tx_power = value;
 }
+
+void ad_advertise_name(gboolean value)
+{
+	ad_name = value;
+}
client/advertising.h +1 -0
index 86384656c..a41a2742d 100644
@@ -28,3 +28,4 @@ void ad_advertise_uuids(const char *arg);
 void ad_advertise_service(const char *arg);
 void ad_advertise_manufacturer(const char *arg);
 void ad_advertise_tx_power(gboolean value);
+void ad_advertise_name(gboolean value);
client/main.c +22 -0
index 17de7f81f..e4012aab8 100644
@@ -2362,6 +2362,26 @@ static void cmd_set_advertise_tx_power(const char *arg)
 	rl_printf("Invalid argument\n");
 }
 
+static void cmd_set_advertise_name(const char *arg)
+{
+	if (arg == NULL || strlen(arg) == 0) {
+		rl_printf("Missing on/off argument\n");
+		return;
+	}
+
+	if (strcmp(arg, "on") == 0 || strcmp(arg, "yes") == 0) {
+		ad_advertise_name(TRUE);
+		return;
+	}
+
+	if (strcmp(arg, "off") == 0 || strcmp(arg, "no") == 0) {
+		ad_advertise_name(FALSE);
+		return;
+	}
+
+	rl_printf("Invalid argument\n");
+}
+
 static const struct {
 	const char *cmd;
 	const char *arg;
@@ -2406,6 +2426,8 @@ static const struct {
 	{ "set-advertise-tx-power", "<on/off>",
 			cmd_set_advertise_tx_power,
 			"Enable/disable TX power to be advertised" },
+	{ "set-advertise-name", "<on/off>", cmd_set_advertise_name,
+			"Enable/disable TX power to be advertised" },
 	{ "set-scan-filter-uuids", "[uuid1 uuid2 ...]",
 			cmd_set_scan_filter_uuids, "Set scan filter uuids" },
 	{ "set-scan-filter-rssi", "[rssi]", cmd_set_scan_filter_rssi,
Signature · 1 line
2.13.3