2017-12-14 12:02:50

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 01/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(-)

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



2017-12-15 11:53:29

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH v2 01/11] monitor: Detect string format

Hi,

On Thu, Dec 14, 2017 at 10:02 AM, Luiz Augusto von Dentz
<[email protected]> wrote:
> 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

Patches 1-9 have been applied.


--
Luiz Augusto von Dentz

2017-12-15 02:07:34

by ERAMOTO Masaya

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

Hi Luiz,

On 12/14/2017 09:02 PM, Luiz Augusto von Dentz wrote:
> 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(-)
>
> diff --git a/client/main.c b/client/main.c
> index 04937bc4b..3fd2c96cc 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -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,
> +};

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


>
> 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;
>

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


Regards,
Eramoto

> 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;
>


2017-12-14 12:03:00

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 11/11] client: Make scan:clear clear individual fields

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(-)

diff --git a/client/main.c b/client/main.c
index 3fd2c96cc..802b841e2 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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." },
{ } },
};
--
2.13.6


2017-12-14 12:02:59

by Luiz Augusto von Dentz

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

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(-)

diff --git a/client/main.c b/client/main.c
index 04937bc4b..3fd2c96cc 100644
--- a/client/main.c
+++ b/client/main.c
@@ -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;
--
2.13.6


2017-12-14 12:02:58

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 09/11] client: Fix command scan:clear

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 7183ae478..04937bc4b 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


2017-12-14 12:02:57

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 08/11] client: Rename set-filter-clear to clear

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 f6f27ea6b..7183ae478 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


2017-12-14 12:02:56

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 07/11] client: Rename set-filter-duplicate-data to duplicate-data

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 af29dca8b..f6f27ea6b 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


2017-12-14 12:02:55

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 06/11] client: Rename set-filter-transport to transport

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 ce9697e19..af29dca8b 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


2017-12-14 12:02:54

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 05/11] client: Rename set-filter-pathloss to pathloss

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 faeb57758..ce9697e19 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


2017-12-14 12:02:53

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 04/11] client: Rename set-filter-rssi to rssi

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 461eb8487..faeb57758 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


2017-12-14 12:02:51

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 02/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(-)

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


2017-12-14 12:02:52

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v2 03/11] client: Rename set-filter-uuids to uuids

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 b8454abdc..461eb8487 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