Skip to contentSkip to conversation

monitor: Detect string format

PATCH In review Luiz Augusto von Dentz 2 participants 13 messages Dec 14, 2017 – Dec 15, 2017 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v2 1/11 monitor: Detect string format

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

User may enter UUID in string format other then 128 bits.

---
 monitor/uuid.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
monitor/uuid.c +18 -1
index 9839d03be..bc638a2f3 100644
@@ -27,6 +27,7 @@
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "uuid.h"
@@ -735,12 +736,28 @@ const char *uuid32_to_str(uint32_t uuid)
 const char *uuidstr_to_str(const char *uuid)
 {
 	uint32_t val;
+	size_t len;
 	int i;
 
 	if (!uuid)
 		return NULL;
 
-	if (strlen(uuid) != 36)
+	len = strlen(uuid);
+
+	if (len < 36) {
+		char *endptr = NULL;
+
+		val = strtol(uuid, &endptr, 0);
+		if (!endptr || *endptr != '\0')
+			return NULL;
+
+		if (val > UINT16_MAX)
+			return uuid32_to_str(val);
+
+		return uuid16_to_str(val);
+	}
+
+	if (len != 36)
 		return NULL;
 
 	for (i = 0; uuid128_table[i].str; i++) {
Signature · 1 line
2.13.6
author maintainer
#1 lore raw

PATCH v2 2/11 shared/shell: Fix parsing of optional parameters

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

Optional parameters uses "[]" delimiters.

---
 src/shared/shell.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/shared/shell.c +2 -2
index b4fdf7043..6cdea1c7e 100644
@@ -288,9 +288,9 @@ static int cmd_exec(const struct bt_shell_menu_entry *entry,
 	opt = strdup(entry->arg + len + 1);
 
 optional:
-	if (parse_args(opt, &w, "<>", flags) < 0) {
+	if (parse_args(opt, &w, "[]", flags) < 0) {
 		print_text(COLOR_HIGHLIGHT,
-				"Unable to parse mandatory command arguments");
+				"Unable to parse optional command arguments");
 		return -EINVAL;
 	}
 
Signature · 1 line
2.13.6
author maintainer
#2 lore raw

PATCH v2 3/11 client: Rename set-filter-uuids to uuids

In reply to Luiz Augusto von Dentz

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

All commands under scan submenu are related to set-filter so remove its portion from it and make the command return the current value if no parameters:

[bluetooth]# uuids 0x1820
SetDiscoveryFilter success
[bluetooth]# uuids

	UUID: Internet Protocol Support (0x1820)

Note that to filter all UUIDs user must now use "all" instead of empty list.

---
 client/main.c | 67 ++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 26 deletions(-)
client/main.c +41 -26
index b8454abdc..461eb8487 100644
@@ -325,6 +325,32 @@ static void print_property(GDBusProxy *proxy, const char *name)
 	print_iter("\t", name, &iter);
 }
 
+static void print_uuid(const char *uuid)
+{
+	const char *text;
+
+	text = uuidstr_to_str(uuid);
+	if (text) {
+		char str[26];
+		unsigned int n;
+
+		str[sizeof(str) - 1] = '\0';
+
+		n = snprintf(str, sizeof(str), "%s", text);
+		if (n > sizeof(str) - 1) {
+			str[sizeof(str) - 2] = '.';
+			str[sizeof(str) - 3] = '.';
+			if (str[sizeof(str) - 4] == ' ')
+				str[sizeof(str) - 4] = '.';
+
+			n = sizeof(str) - 1;
+		}
+
+		bt_shell_printf("\tUUID: %s%*c(%s)\n", str, 26 - n, ' ', uuid);
+	} else
+		bt_shell_printf("\tUUID: %*c(%s)\n", 26, ' ', uuid);
+}
+
 static void print_uuids(GDBusProxy *proxy)
 {
 	DBusMessageIter iter, value;
@@ -335,31 +361,11 @@ static void print_uuids(GDBusProxy *proxy)
 	dbus_message_iter_recurse(&iter, &value);
 
 	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
-		const char *uuid, *text;
+		const char *uuid;
 
 		dbus_message_iter_get_basic(&value, &uuid);
 
-		text = uuidstr_to_str(uuid);
-		if (text) {
-			char str[26];
-			unsigned int n;
-
-			str[sizeof(str) - 1] = '\0';
-
-			n = snprintf(str, sizeof(str), "%s", text);
-			if (n > sizeof(str) - 1) {
-				str[sizeof(str) - 2] = '.';
-				str[sizeof(str) - 3] = '.';
-				if (str[sizeof(str) - 4] == ' ')
-					str[sizeof(str) - 4] = '.';
-
-				n = sizeof(str) - 1;
-			}
-
-			bt_shell_printf("\tUUID: %s%*c(%s)\n",
-						str, 26 - n, ' ', uuid);
-		} else
-			bt_shell_printf("\tUUID: %*c(%s)\n", 26, ' ', uuid);
+		print_uuid(uuid);
 
 		dbus_message_iter_next(&value);
 	}
@@ -1291,13 +1297,22 @@ static void cmd_set_scan_filter_commit(void)
 	}
 }
 
-static void cmd_set_scan_filter_uuids(int argc, char *argv[])
+static void cmd_scan_filter_uuids(int argc, char *argv[])
 {
+	if (argc < 2 || !strlen(argv[1])) {
+		char **uuid;
+
+		for (uuid = filtered_scan_uuids; uuid && *uuid; uuid++)
+			print_uuid(*uuid);
+
+		return;
+	}
+
 	g_strfreev(filtered_scan_uuids);
 	filtered_scan_uuids = NULL;
 	filtered_scan_uuids_len = 0;
 
-	if (argc < 2 || !strlen(argv[1]))
+	if (!strcmp(argv[1], "all"))
 		goto commit;
 
 	filtered_scan_uuids = g_strdupv(&argv[1]);
@@ -2229,8 +2244,8 @@ static const struct bt_shell_menu scan_menu = {
 	.name = "scan",
 	.desc = "Scan Options Submenu",
 	.entries = {
-	{ "set-filter-uuids", "[uuid1 uuid2 ...]", cmd_set_scan_filter_uuids,
-				"Set scan filter uuids" },
+	{ "uuids", "[all/uuid1 uuid2 ...]", cmd_scan_filter_uuids,
+				"Set/Get UUIDs filter" },
 	{ "set-filter-rssi", "[rssi]", cmd_set_scan_filter_rssi,
 				"Set scan filter rssi, and clears pathloss" },
 	{ "set-filter-pathloss", "[pathloss]", cmd_set_scan_filter_pathloss,
Signature · 1 line
2.13.6
author maintainer
#3 lore raw

PATCH v2 4/11 client: Rename set-filter-rssi to rssi

In reply to Luiz Augusto von Dentz

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

All commands under scan submenu are related to set-filter so remove its portion from it and make the command return the current value if no parameters:

[bluetooth]# rssi 0
SetDiscoveryFilter success
[bluetooth]# rssi
RSSI: 0

---
 client/main.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
client/main.c +10 -8
index 461eb8487..faeb57758 100644
@@ -1327,14 +1327,16 @@ commit:
 	cmd_set_scan_filter_commit();
 }
 
-static void cmd_set_scan_filter_rssi(int argc, char *argv[])
+static void cmd_scan_filter_rssi(int argc, char *argv[])
 {
-	filtered_scan_pathloss = DISTANCE_VAL_INVALID;
+	if (argc < 2 || !strlen(argv[1])) {
+		if (filtered_scan_rssi != DISTANCE_VAL_INVALID)
+			bt_shell_printf("RSSI: %d\n", filtered_scan_rssi);
+		return;
+	}
 
-	if (argc < 2 || !strlen(argv[1]))
-		filtered_scan_rssi = DISTANCE_VAL_INVALID;
-	else
-		filtered_scan_rssi = atoi(argv[1]);
+	filtered_scan_pathloss = DISTANCE_VAL_INVALID;
+	filtered_scan_rssi = atoi(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -2246,8 +2248,8 @@ static const struct bt_shell_menu scan_menu = {
 	.entries = {
 	{ "uuids", "[all/uuid1 uuid2 ...]", cmd_scan_filter_uuids,
 				"Set/Get UUIDs filter" },
-	{ "set-filter-rssi", "[rssi]", cmd_set_scan_filter_rssi,
-				"Set scan filter rssi, and clears pathloss" },
+	{ "rssi", "[rssi]", cmd_scan_filter_rssi,
+				"Set/Get RSSI filter, and clears pathloss" },
 	{ "set-filter-pathloss", "[pathloss]", cmd_set_scan_filter_pathloss,
 				"Set scan filter pathloss, and clears rssi" },
 	{ "set-filter-transport", "[transport]", cmd_set_scan_filter_transport,
Signature · 1 line
2.13.6
author maintainer
#4 lore raw

PATCH v2 5/11 client: Rename set-filter-pathloss to pathloss

In reply to Luiz Augusto von Dentz

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

All commands under scan submenu are related to set-filter so remove its portion from it and make the command return the current value if no parameters:

[bluetooth]# pathloss 0
SetDiscoveryFilter success
[bluetooth]# pathloss
Pathloss: 0

---
 client/main.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
client/main.c +11 -8
index faeb57758..ce9697e19 100644
@@ -1341,14 +1341,17 @@ static void cmd_scan_filter_rssi(int argc, char *argv[])
 	cmd_set_scan_filter_commit();
 }
 
-static void cmd_set_scan_filter_pathloss(int argc, char *argv[])
+static void cmd_scan_filter_pathloss(int argc, char *argv[])
 {
-	filtered_scan_rssi = DISTANCE_VAL_INVALID;
+	if (argc < 2 || !strlen(argv[1])) {
+		if (filtered_scan_pathloss != DISTANCE_VAL_INVALID)
+			bt_shell_printf("Pathloss: %d\n",
+						filtered_scan_pathloss);
+		return;
+	}
 
-	if (argc < 2 || !strlen(argv[1]))
-		filtered_scan_pathloss = DISTANCE_VAL_INVALID;
-	else
-		filtered_scan_pathloss = atoi(argv[1]);
+	filtered_scan_rssi = DISTANCE_VAL_INVALID;
+	filtered_scan_pathloss = atoi(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -2250,8 +2253,8 @@ static const struct bt_shell_menu scan_menu = {
 				"Set/Get UUIDs filter" },
 	{ "rssi", "[rssi]", cmd_scan_filter_rssi,
 				"Set/Get RSSI filter, and clears pathloss" },
-	{ "set-filter-pathloss", "[pathloss]", cmd_set_scan_filter_pathloss,
-				"Set scan filter pathloss, and clears rssi" },
+	{ "pathloss", "[pathloss]", cmd_scan_filter_pathloss,
+				"Set/Get Pathloss filter, and clears RSSI" },
 	{ "set-filter-transport", "[transport]", cmd_set_scan_filter_transport,
 				"Set scan filter transport" },
 	{ "set-filter-duplicate-data", "[on/off]",
Signature · 1 line
2.13.6
author maintainer
#5 lore raw

PATCH v2 6/11 client: Rename set-filter-transport to transport

In reply to Luiz Augusto von Dentz

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

All commands under scan submenu are related to set-filter so remove its portion from it and make the command return the current value if no parameters:

[bluetooth]# transport le
SetDiscoveryFilter success
[bluetooth]# transport
Transport: le

---
 client/main.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
client/main.c +11 -8
index ce9697e19..af29dca8b 100644
@@ -1356,14 +1356,17 @@ static void cmd_scan_filter_pathloss(int argc, char *argv[])
 	cmd_set_scan_filter_commit();
 }
 
-static void cmd_set_scan_filter_transport(int argc, char *argv[])
+static void cmd_scan_filter_transport(int argc, char *argv[])
 {
-	g_free(filtered_scan_transport);
+	if (argc < 2 || !strlen(argv[1])) {
+		if (filtered_scan_transport)
+			bt_shell_printf("Transport: %s\n",
+					filtered_scan_transport);
+		return;
+	}
 
-	if (argc < 2 || !strlen(argv[1]))
-		filtered_scan_transport = NULL;
-	else
-		filtered_scan_transport = g_strdup(argv[1]);
+	g_free(filtered_scan_transport);
+	filtered_scan_transport = g_strdup(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -2255,8 +2258,8 @@ static const struct bt_shell_menu scan_menu = {
 				"Set/Get RSSI filter, and clears pathloss" },
 	{ "pathloss", "[pathloss]", cmd_scan_filter_pathloss,
 				"Set/Get Pathloss filter, and clears RSSI" },
-	{ "set-filter-transport", "[transport]", cmd_set_scan_filter_transport,
-				"Set scan filter transport" },
+	{ "transport", "[transport]", cmd_scan_filter_transport,
+				"Set/Get transport filter" },
 	{ "set-filter-duplicate-data", "[on/off]",
 				cmd_set_scan_filter_duplicate_data,
 				"Set scan filter duplicate data",
Signature · 1 line
2.13.6
author maintainer
#6 lore raw

PATCH v2 7/11 client: Rename set-filter-duplicate-data to duplicate-data

In reply to Luiz Augusto von Dentz

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

All commands under scan submenu are related to set-filter so remove its portion from it and make the command return the current value if no parameters:

[bluetooth]# duplicate-data on
SetDiscoveryFilter success
[bluetooth]# duplicate-data
DuplicateData: on

---
 client/main.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
client/main.c +10 -7
index af29dca8b..f6f27ea6b 100644
@@ -1371,11 +1371,15 @@ static void cmd_scan_filter_transport(int argc, char *argv[])
 	cmd_set_scan_filter_commit();
 }
 
-static void cmd_set_scan_filter_duplicate_data(int argc, char *argv[])
+static void cmd_scan_filter_duplicate_data(int argc, char *argv[])
 {
-	if (argc < 2 || !strlen(argv[1]))
-		filtered_scan_duplicate_data = false;
-	else if (!strcmp(argv[1], "on"))
+	if (argc < 2 || !strlen(argv[1])) {
+		bt_shell_printf("DuplicateData: %s\n",
+				filtered_scan_duplicate_data ? "on" : "off");
+		return;
+	}
+
+	if (!strcmp(argv[1], "on"))
 		filtered_scan_duplicate_data = true;
 	else if (!strcmp(argv[1], "off"))
 		filtered_scan_duplicate_data = false;
@@ -2260,9 +2264,8 @@ static const struct bt_shell_menu scan_menu = {
 				"Set/Get Pathloss filter, and clears RSSI" },
 	{ "transport", "[transport]", cmd_scan_filter_transport,
 				"Set/Get transport filter" },
-	{ "set-filter-duplicate-data", "[on/off]",
-				cmd_set_scan_filter_duplicate_data,
-				"Set scan filter duplicate data",
+	{ "duplicate-data", "[on/off]", cmd_scan_filter_duplicate_data,
+				"Set/Get duplicate data filter",
 				mode_generator },
 	{ "set-filter-clear", NULL, cmd_set_scan_filter_clear,
 				"Clears discovery filter." },
Signature · 1 line
2.13.6
author maintainer
#7 lore raw

PATCH v2 8/11 client: Rename set-filter-clear to clear

In reply to Luiz Augusto von Dentz

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

All commands under scan submenu are related to set-filter so remove its portion from it and make the command return the current value if no parameters.

---
 client/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
client/main.c +2 -2
index f6f27ea6b..7183ae478 100644
@@ -1404,7 +1404,7 @@ static void clear_discovery_filter_setup(DBusMessageIter *iter, void *user_data)
 	dbus_message_iter_close_container(iter, &dict);
 }
 
-static void cmd_set_scan_filter_clear(int argc, char *argv[])
+static void cmd_scan_filter_clear(int argc, char *argv[])
 {
 	/* set default values for all options */
 	filtered_scan_rssi = DISTANCE_VAL_INVALID;
@@ -2267,7 +2267,7 @@ static const struct bt_shell_menu scan_menu = {
 	{ "duplicate-data", "[on/off]", cmd_scan_filter_duplicate_data,
 				"Set/Get duplicate data filter",
 				mode_generator },
-	{ "set-filter-clear", NULL, cmd_set_scan_filter_clear,
+	{ "clear", NULL, cmd_scan_filter_clear,
 				"Clears discovery filter." },
 	{ } },
 };
Signature · 1 line
2.13.6
author maintainer
#8 lore raw

PATCH v2 9/11 client: Fix command scan:clear

In reply to Luiz Augusto von Dentz

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

Command clear shall clear all filters including DuplicateData.

---
 client/main.c | 1 +
 1 file changed, 1 insertion(+)
client/main.c +1 -0
index 7183ae478..04937bc4b 100644
@@ -1414,6 +1414,7 @@ static void cmd_scan_filter_clear(int argc, char *argv[])
 	filtered_scan_uuids_len = 0;
 	g_free(filtered_scan_transport);
 	filtered_scan_transport = NULL;
+	filtered_scan_duplicate_data = false;
 
 	if (check_default_ctrl() == FALSE)
 		return;
Signature · 1 line
2.13.6
author maintainer
#9 lore raw

PATCH v2 10/11 client: Group discovery filter variables into a struct

In reply to Luiz Augusto von Dentz

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

This should be easier to read and maintain.

---
 client/main.c | 89 +++++++++++++++++++++++++++++++----------------------------
 1 file changed, 47 insertions(+), 42 deletions(-)
client/main.c +47 -42
index 04937bc4b..3fd2c96cc 100644
@@ -1267,24 +1267,29 @@ static void set_discovery_filter_reply(DBusMessage *message, void *user_data)
 	bt_shell_printf("SetDiscoveryFilter success\n");
 }
 
-static gint filtered_scan_rssi = DISTANCE_VAL_INVALID;
-static gint filtered_scan_pathloss = DISTANCE_VAL_INVALID;
-static char **filtered_scan_uuids;
-static size_t filtered_scan_uuids_len;
-static char *filtered_scan_transport;
-static bool filtered_scan_duplicate_data;
+static struct disc_filter {
+	int16_t rssi;
+	int16_t pathloss;
+	char **uuids;
+	size_t uuids_len;
+	char *transport;
+	bool duplicate;
+} filter = {
+	.rssi = DISTANCE_VAL_INVALID,
+	.pathloss = DISTANCE_VAL_INVALID,
+};
 
 static void cmd_set_scan_filter_commit(void)
 {
 	struct set_discovery_filter_args args;
 
 	args.uuids = NULL;
-	args.pathloss = filtered_scan_pathloss;
-	args.rssi = filtered_scan_rssi;
-	args.transport = filtered_scan_transport;
-	args.uuids = filtered_scan_uuids;
-	args.uuids_len = filtered_scan_uuids_len;
-	args.duplicate = filtered_scan_duplicate_data;
+	args.pathloss = filter.pathloss;
+	args.rssi = filter.rssi;
+	args.transport = filter.transport;
+	args.uuids = filter.uuids;
+	args.uuids_len = filter.uuids_len;
+	args.duplicate = filter.duplicate;
 
 	if (check_default_ctrl() == FALSE)
 		return;
@@ -1302,26 +1307,26 @@ static void cmd_scan_filter_uuids(int argc, char *argv[])
 	if (argc < 2 || !strlen(argv[1])) {
 		char **uuid;
 
-		for (uuid = filtered_scan_uuids; uuid && *uuid; uuid++)
+		for (uuid = filter.uuids; uuid && *uuid; uuid++)
 			print_uuid(*uuid);
 
 		return;
 	}
 
-	g_strfreev(filtered_scan_uuids);
-	filtered_scan_uuids = NULL;
-	filtered_scan_uuids_len = 0;
+	g_strfreev(filter.uuids);
+	filter.uuids = NULL;
+	filter.uuids_len = 0;
 
 	if (!strcmp(argv[1], "all"))
 		goto commit;
 
-	filtered_scan_uuids = g_strdupv(&argv[1]);
-	if (!filtered_scan_uuids) {
+	filter.uuids = g_strdupv(&argv[1]);
+	if (!filter.uuids) {
 		bt_shell_printf("Failed to parse input\n");
 		return;
 	}
 
-	filtered_scan_uuids_len = g_strv_length(filtered_scan_uuids);
+	filter.uuids_len = g_strv_length(filter.uuids);
 
 commit:
 	cmd_set_scan_filter_commit();
@@ -1330,13 +1335,13 @@ commit:
 static void cmd_scan_filter_rssi(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
-		if (filtered_scan_rssi != DISTANCE_VAL_INVALID)
-			bt_shell_printf("RSSI: %d\n", filtered_scan_rssi);
+		if (filter.rssi != DISTANCE_VAL_INVALID)
+			bt_shell_printf("RSSI: %d\n", filter.rssi);
 		return;
 	}
 
-	filtered_scan_pathloss = DISTANCE_VAL_INVALID;
-	filtered_scan_rssi = atoi(argv[1]);
+	filter.pathloss = DISTANCE_VAL_INVALID;
+	filter.rssi = atoi(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -1344,14 +1349,14 @@ static void cmd_scan_filter_rssi(int argc, char *argv[])
 static void cmd_scan_filter_pathloss(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
-		if (filtered_scan_pathloss != DISTANCE_VAL_INVALID)
+		if (filter.pathloss != DISTANCE_VAL_INVALID)
 			bt_shell_printf("Pathloss: %d\n",
-						filtered_scan_pathloss);
+						filter.pathloss);
 		return;
 	}
 
-	filtered_scan_rssi = DISTANCE_VAL_INVALID;
-	filtered_scan_pathloss = atoi(argv[1]);
+	filter.rssi = DISTANCE_VAL_INVALID;
+	filter.pathloss = atoi(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -1359,14 +1364,14 @@ static void cmd_scan_filter_pathloss(int argc, char *argv[])
 static void cmd_scan_filter_transport(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
-		if (filtered_scan_transport)
+		if (filter.transport)
 			bt_shell_printf("Transport: %s\n",
-					filtered_scan_transport);
+					filter.transport);
 		return;
 	}
 
-	g_free(filtered_scan_transport);
-	filtered_scan_transport = g_strdup(argv[1]);
+	g_free(filter.transport);
+	filter.transport = g_strdup(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -1375,14 +1380,14 @@ static void cmd_scan_filter_duplicate_data(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
 		bt_shell_printf("DuplicateData: %s\n",
-				filtered_scan_duplicate_data ? "on" : "off");
+				filter.duplicate ? "on" : "off");
 		return;
 	}
 
 	if (!strcmp(argv[1], "on"))
-		filtered_scan_duplicate_data = true;
+		filter.duplicate = true;
 	else if (!strcmp(argv[1], "off"))
-		filtered_scan_duplicate_data = false;
+		filter.duplicate = false;
 	else {
 		bt_shell_printf("Invalid option: %s\n", argv[1]);
 		return;
@@ -1407,14 +1412,14 @@ static void clear_discovery_filter_setup(DBusMessageIter *iter, void *user_data)
 static void cmd_scan_filter_clear(int argc, char *argv[])
 {
 	/* set default values for all options */
-	filtered_scan_rssi = DISTANCE_VAL_INVALID;
-	filtered_scan_pathloss = DISTANCE_VAL_INVALID;
-	g_strfreev(filtered_scan_uuids);
-	filtered_scan_uuids = NULL;
-	filtered_scan_uuids_len = 0;
-	g_free(filtered_scan_transport);
-	filtered_scan_transport = NULL;
-	filtered_scan_duplicate_data = false;
+	filter.rssi = DISTANCE_VAL_INVALID;
+	filter.pathloss = DISTANCE_VAL_INVALID;
+	g_strfreev(filter.uuids);
+	filter.uuids = NULL;
+	filter.uuids_len = 0;
+	g_free(filter.transport);
+	filter.transport = NULL;
+	filter.duplicate = false;
 
 	if (check_default_ctrl() == FALSE)
 		return;
Signature · 1 line
2.13.6
author maintainer
#11 lore raw

PATCH v2 11/11 client: Make scan:clear clear individual fields

In reply to Luiz Augusto von Dentz

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

This reintroduces the option to clear individual fields which was removed when redesining the commands which now read the fields when no arguments are provided.

---
 client/main.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 56 insertions(+), 5 deletions(-)
client/main.c +56 -5
index 3fd2c96cc..802b841e2 100644
@@ -1409,18 +1409,68 @@ static void clear_discovery_filter_setup(DBusMessageIter *iter, void *user_data)
 	dbus_message_iter_close_container(iter, &dict);
 }
 
-static void cmd_scan_filter_clear(int argc, char *argv[])
+static void filter_clear_uuids(void)
 {
-	/* set default values for all options */
-	filter.rssi = DISTANCE_VAL_INVALID;
-	filter.pathloss = DISTANCE_VAL_INVALID;
 	g_strfreev(filter.uuids);
 	filter.uuids = NULL;
 	filter.uuids_len = 0;
+}
+
+static void filter_clear_rssi(void)
+{
+	filter.rssi = DISTANCE_VAL_INVALID;
+}
+
+static void filter_clear_pathloss(void)
+{
+	filter.pathloss = DISTANCE_VAL_INVALID;
+}
+
+static void filter_clear_transport(void)
+{
 	g_free(filter.transport);
 	filter.transport = NULL;
+}
+
+static void filter_clear_duplicate(void)
+{
 	filter.duplicate = false;
+}
+
+static const struct filter_clear {
+	const char *name;
+	void (*clear) (void);
+} filter_clear[] = {
+	{ "uuids", filter_clear_uuids },
+	{ "rssi", filter_clear_rssi },
+	{ "pathloss", filter_clear_pathloss },
+	{ "transport", filter_clear_transport },
+	{ "duplicate-data", filter_clear_duplicate },
+	{}
+};
+
+static void cmd_scan_filter_clear(int argc, char *argv[])
+{
+	const struct filter_clear *fc;
+	bool all = false;
+
+	if (argc < 2 || !strlen(argv[1]))
+		all = true;
 
+	for (fc = filter_clear; fc && fc->name; fc++) {
+		if (all || !strcmp(fc->name, argv[1])) {
+			fc->clear();
+			if (!all)
+				goto done;
+		}
+	}
+
+	if (!all) {
+		bt_shell_printf("Invalid argument %s\n", argv[1]);
+		return;
+	}
+
+done:
 	if (check_default_ctrl() == FALSE)
 		return;
 
@@ -2273,7 +2323,8 @@ static const struct bt_shell_menu scan_menu = {
 	{ "duplicate-data", "[on/off]", cmd_scan_filter_duplicate_data,
 				"Set/Get duplicate data filter",
 				mode_generator },
-	{ "clear", NULL, cmd_scan_filter_clear,
+	{ "clear", "[uuids/rssi/pathloss/transport/duplicate-data]",
+				cmd_scan_filter_clear,
 				"Clears discovery filter." },
 	{ } },
 };
Signature · 1 line
2.13.6
#10 lore raw

Re: [PATCH v2 10/11] client: Group discovery filter variables into a struct

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 22 lines · Luiz Augusto von Dentz

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

This should be easier to read and maintain.

---
 client/main.c | 89 +++++++++++++++++++++++++++++++----------------------------
 1 file changed, 47 insertions(+), 42 deletions(-)
client/main.c +1 -6
index 04937bc4b..3fd2c96cc 100644
@@ -1267,24 +1267,29 @@ static void set_discovery_filter_reply(DBusMessage *message, void *user_data)
 	bt_shell_printf("SetDiscoveryFilter success\n");
 }
 
-static gint filtered_scan_rssi = DISTANCE_VAL_INVALID;
-static gint filtered_scan_pathloss = DISTANCE_VAL_INVALID;
-static char **filtered_scan_uuids;
-static size_t filtered_scan_uuids_len;
-static char *filtered_scan_transport;
-static bool filtered_scan_duplicate_data;
+static struct disc_filter {

client/main.c static void set_discovery_filter_reply(DBusMessage *message, void *user_data) · line 1280

Quoted 10 lines
client/main.c +10 -0
+	int16_t rssi;
+	int16_t pathloss;
+	char **uuids;
+	size_t uuids_len;
+	char *transport;
+	bool duplicate;
+} filter = {
+	.rssi = DISTANCE_VAL_INVALID,
+	.pathloss = DISTANCE_VAL_INVALID,
+};

It is better to use the set_discovery_filter_args struct since the filter variable is copied to its struct variable when calling SetDiscoveryFilter.

Quoted 9 lines
client/main.c +0 -3
 static void cmd_set_scan_filter_commit(void)
 {
 	struct set_discovery_filter_args args;
 
 	args.uuids = NULL;
-	args.pathloss = filtered_scan_pathloss;
-	args.rssi = filtered_scan_rssi;
-	args.transport = filtered_scan_transport;

client/main.c static void set_discovery_filter_reply(DBusMessage *message, void *user_data) · line 1293

Quoted 10 lines
client/main.c +6 -3
-	args.uuids = filtered_scan_uuids;
-	args.uuids_len = filtered_scan_uuids_len;
-	args.duplicate = filtered_scan_duplicate_data;
+	args.pathloss = filter.pathloss;
+	args.rssi = filter.rssi;
+	args.transport = filter.transport;
+	args.uuids = filter.uuids;
+	args.uuids_len = filter.uuids_len;
+	args.duplicate = filter.duplicate;
 

It may be better to pass the filter variable directly to the method instead to copying to the args variable.

Regards,
Eramoto

Quoted 134 lines
client/main.c +30 -30
 	if (check_default_ctrl() == FALSE)
 		return;
@@ -1302,26 +1307,26 @@ static void cmd_scan_filter_uuids(int argc, char *argv[])
 	if (argc < 2 || !strlen(argv[1])) {
 		char **uuid;
 
-		for (uuid = filtered_scan_uuids; uuid && *uuid; uuid++)
+		for (uuid = filter.uuids; uuid && *uuid; uuid++)
 			print_uuid(*uuid);
 
 		return;
 	}
 
-	g_strfreev(filtered_scan_uuids);
-	filtered_scan_uuids = NULL;
-	filtered_scan_uuids_len = 0;
+	g_strfreev(filter.uuids);
+	filter.uuids = NULL;
+	filter.uuids_len = 0;
 
 	if (!strcmp(argv[1], "all"))
 		goto commit;
 
-	filtered_scan_uuids = g_strdupv(&argv[1]);
-	if (!filtered_scan_uuids) {
+	filter.uuids = g_strdupv(&argv[1]);
+	if (!filter.uuids) {
 		bt_shell_printf("Failed to parse input\n");
 		return;
 	}
 
-	filtered_scan_uuids_len = g_strv_length(filtered_scan_uuids);
+	filter.uuids_len = g_strv_length(filter.uuids);
 
 commit:
 	cmd_set_scan_filter_commit();
@@ -1330,13 +1335,13 @@ commit:
 static void cmd_scan_filter_rssi(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
-		if (filtered_scan_rssi != DISTANCE_VAL_INVALID)
-			bt_shell_printf("RSSI: %d\n", filtered_scan_rssi);
+		if (filter.rssi != DISTANCE_VAL_INVALID)
+			bt_shell_printf("RSSI: %d\n", filter.rssi);
 		return;
 	}
 
-	filtered_scan_pathloss = DISTANCE_VAL_INVALID;
-	filtered_scan_rssi = atoi(argv[1]);
+	filter.pathloss = DISTANCE_VAL_INVALID;
+	filter.rssi = atoi(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -1344,14 +1349,14 @@ static void cmd_scan_filter_rssi(int argc, char *argv[])
 static void cmd_scan_filter_pathloss(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
-		if (filtered_scan_pathloss != DISTANCE_VAL_INVALID)
+		if (filter.pathloss != DISTANCE_VAL_INVALID)
 			bt_shell_printf("Pathloss: %d\n",
-						filtered_scan_pathloss);
+						filter.pathloss);
 		return;
 	}
 
-	filtered_scan_rssi = DISTANCE_VAL_INVALID;
-	filtered_scan_pathloss = atoi(argv[1]);
+	filter.rssi = DISTANCE_VAL_INVALID;
+	filter.pathloss = atoi(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -1359,14 +1364,14 @@ static void cmd_scan_filter_pathloss(int argc, char *argv[])
 static void cmd_scan_filter_transport(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
-		if (filtered_scan_transport)
+		if (filter.transport)
 			bt_shell_printf("Transport: %s\n",
-					filtered_scan_transport);
+					filter.transport);
 		return;
 	}
 
-	g_free(filtered_scan_transport);
-	filtered_scan_transport = g_strdup(argv[1]);
+	g_free(filter.transport);
+	filter.transport = g_strdup(argv[1]);
 
 	cmd_set_scan_filter_commit();
 }
@@ -1375,14 +1380,14 @@ static void cmd_scan_filter_duplicate_data(int argc, char *argv[])
 {
 	if (argc < 2 || !strlen(argv[1])) {
 		bt_shell_printf("DuplicateData: %s\n",
-				filtered_scan_duplicate_data ? "on" : "off");
+				filter.duplicate ? "on" : "off");
 		return;
 	}
 
 	if (!strcmp(argv[1], "on"))
-		filtered_scan_duplicate_data = true;
+		filter.duplicate = true;
 	else if (!strcmp(argv[1], "off"))
-		filtered_scan_duplicate_data = false;
+		filter.duplicate = false;
 	else {
 		bt_shell_printf("Invalid option: %s\n", argv[1]);
 		return;
@@ -1407,14 +1412,14 @@ static void clear_discovery_filter_setup(DBusMessageIter *iter, void *user_data)
 static void cmd_scan_filter_clear(int argc, char *argv[])
 {
 	/* set default values for all options */
-	filtered_scan_rssi = DISTANCE_VAL_INVALID;
-	filtered_scan_pathloss = DISTANCE_VAL_INVALID;
-	g_strfreev(filtered_scan_uuids);
-	filtered_scan_uuids = NULL;
-	filtered_scan_uuids_len = 0;
-	g_free(filtered_scan_transport);
-	filtered_scan_transport = NULL;
-	filtered_scan_duplicate_data = false;
+	filter.rssi = DISTANCE_VAL_INVALID;
+	filter.pathloss = DISTANCE_VAL_INVALID;
+	g_strfreev(filter.uuids);
+	filter.uuids = NULL;
+	filter.uuids_len = 0;
+	g_free(filter.transport);
+	filter.transport = NULL;
+	filter.duplicate = false;
 
 	if (check_default_ctrl() == FALSE)
 		return;
author maintainer
#12 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 50 lines · Luiz Augusto von Dentz

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

User may enter UUID in string format other then 128 bits.

---
 monitor/uuid.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
monitor/uuid.c +18 -2
index 9839d03be..bc638a2f3 100644
@@ -27,6 +27,7 @@
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "uuid.h"
@@ -735,12 +736,28 @@ const char *uuid32_to_str(uint32_t uuid)
 const char *uuidstr_to_str(const char *uuid)
 {
        uint32_t val;
+       size_t len;
        int i;
 
        if (!uuid)
                return NULL;
 
-       if (strlen(uuid) != 36)
+       len = strlen(uuid);
+
+       if (len < 36) {
+               char *endptr = NULL;
+
+               val = strtol(uuid, &endptr, 0);
+               if (!endptr || *endptr != '\0')
+                       return NULL;
+
+               if (val > UINT16_MAX)
+                       return uuid32_to_str(val);
+
+               return uuid16_to_str(val);
+       }
+
+       if (len != 36)
                return NULL;
 
        for (i = 0; uuid128_table[i].str; i++) {
--
Quoted 1 line

2.13.6

Patches 1-9 have been applied.

Signature · 1 line
Luiz Augusto von Dentz