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(-)
diff --git a/monitor/uuid.c b/monitor/uuid.c
index 9839d03be..bc638a2f3 100644
--- a/monitor/uuid.c
+++ b/monitor/uuid.c
@@ -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++) {
--
2.13.6
Hi Eramoto,
On Thu, Dec 14, 2017 at 7:12 AM, ERAMOTO Masaya
<[email protected]> wrote:
> Hi Luiz,
>
> On 12/13/2017 09:36 PM, Luiz Augusto von Dentz wrote:
>> 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(-)
>>
>> diff --git a/client/main.c b/client/main.c
>> index 1728a4d82..d8d911a37 100644
>> --- a/client/main.c
>> +++ b/client/main.c
>> @@ -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]);
>
> 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.
>
> Regards,
> Eramoto
>
--
Luiz Augusto von Dentz
Hi Luiz,
On 12/13/2017 09:36 PM, Luiz Augusto von Dentz wrote:
> 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(-)
>
> diff --git a/client/main.c b/client/main.c
> index 1728a4d82..d8d911a37 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -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]);
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
From: Luiz Augusto von Dentz <[email protected]>
Command clear shall clear all filters including DuplicateData.
---
client/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/client/main.c b/client/main.c
index 1617b7cb3..bbfdea80d 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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;
--
2.13.6
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(-)
diff --git a/client/main.c b/client/main.c
index 849033870..1617b7cb3 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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." },
{ } },
};
--
2.13.6
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(-)
diff --git a/client/main.c b/client/main.c
index 1728a4d82..d8d911a37 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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",
--
2.13.6
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(-)
diff --git a/client/main.c b/client/main.c
index d8d911a37..849033870 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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." },
--
2.13.6
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(-)
diff --git a/client/main.c b/client/main.c
index 8dd92549e..06e4905e9 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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,
--
2.13.6
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(-)
diff --git a/client/main.c b/client/main.c
index 06e4905e9..1728a4d82 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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]",
--
2.13.6
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(-)
diff --git a/client/main.c b/client/main.c
index e5a080696..8dd92549e 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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,
--
2.13.6
From: Luiz Augusto von Dentz <[email protected]>
Optional parameters uses "[]" delimiters.
---
src/shared/shell.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/shared/shell.c b/src/shared/shell.c
index b4fdf7043..6cdea1c7e 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -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;
}
--
2.13.6