Skip to contentSkip to conversation

monitor: Detect string format

PATCH Superseded Luiz Augusto von Dentz 2 participants 11 messages Dec 13, 2017 – Dec 14, 2017 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/9 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 2/9 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 3/9 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 e5a080696..8dd92549e 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 4/9 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 8dd92549e..06e4905e9 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 5/9 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 06e4905e9..1728a4d82 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 6/9 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 1728a4d82..d8d911a37 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
#6 lore raw

Re: [PATCH BlueZ 6/9] client: Rename set-filter-transport to transport

Hi Luiz,

Quoted 29 lines · 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 +4 -2
index 1728a4d82..d8d911a37 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",

client/main.c static void cmd_scan_filter_pathloss(int argc, char *argv[]) · line 1369

Quoted 10 lines
client/main.c +5 -4
+					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]);

After applying this patch set, I think that clear command may be needed to enhance for clearing a individual filter value. Since all values is needed to clear when transport is not want to set after setting uuids/rssi/pathloss/data and it.

Regards,
Eramoto

author maintainer
#7 lore raw

Re: [PATCH BlueZ 6/9] client: Rename set-filter-transport to transport

Hi Eramoto,

Quoted 36 lines · ERAMOTO Masaya

Hi Luiz,

Quoted 33 lines · 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 +7 -2
index 1728a4d82..d8d911a37 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;
+     }
 
Quoted 11 lines

client/main.c static void cmd_scan_filter_pathloss(int argc, char *argv[]) · line 1369

Quoted 6 lines
client/main.c +2 -4
-     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]);

After applying this patch set, I think that clear command may be needed to enhance for clearing a individual filter value. Since all values is needed to clear when transport is not want to set after setting uuids/rssi/pathloss/data and it.

Yep, that is the drawback of reusing the command to get the current value, but perhaps we can make clear take an optional parameter to clear individual options.

Quoted 4 lines

Regards,
Eramoto

Signature · 1 line
Luiz Augusto von Dentz
author maintainer
#8 lore raw

PATCH 7/9 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 d8d911a37..849033870 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
#9 lore raw

PATCH 8/9 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 849033870..1617b7cb3 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
#10 lore raw

PATCH 9/9 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 1617b7cb3..bbfdea80d 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