2015-03-26 03:29:54

by Arman Uguray

[permalink] [raw]
Subject: [PATCH v2 1/4] tools/btmgmt: Rename add-adv --discoverable option

This patch renames the --discoverable option of the add-adv command to
--general-discov, which is more consistent with the --limited-discov
option.
---
tools/btmgmt.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index f64327b..19eeda1 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -3698,7 +3698,7 @@ static struct option add_adv_options[] = {
{ "scan-rsp", 1, 0, 's' },
{ "timeout", 1, 0, 't' },
{ "connectable", 0, 0, 'c' },
- { "discoverable", 0, 0, 'e' },
+ { "general-discov", 0, 0, 'g' },
{ "limited-discov", 0, 0, 'l' },
{ "managed-flags", 0, 0, 'm' },
{ "tx-power", 0, 0, 'p' },
@@ -3765,7 +3765,7 @@ static void cmd_add_adv(struct mgmt *mgmt, uint16_t index,
bool quit = true;
uint32_t flags = 0;

- while ((opt = getopt_long(argc, argv, "+u:d:s:t:celmph",
+ while ((opt = getopt_long(argc, argv, "+u:d:s:t:cglmph",
add_adv_options, NULL)) != -1) {
switch (opt) {
case 'u':
@@ -3829,7 +3829,7 @@ static void cmd_add_adv(struct mgmt *mgmt, uint16_t index,
case 'c':
flags |= MGMT_ADV_FLAG_CONNECTABLE;
break;
- case 'e':
+ case 'g':
flags |= MGMT_ADV_FLAG_DISCOV;
break;
case 'l':
--
2.2.0.rc0.207.ga3a616c



2015-03-26 03:37:53

by Arman Uguray

[permalink] [raw]
Subject: Re: [PATCH v2 2/4] tools/btmgmt: Better usage info for add-adv

Hi,

> On Wed, Mar 25, 2015 at 8:29 PM, Arman Uguray <[email protected]> wrote:
> This patch improves the usage string that gets printed for the add-adv
> command to provide more details about the possible options.
> ---
> tools/btmgmt.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/tools/btmgmt.c b/tools/btmgmt.c
> index 19eeda1..bd83ac7 100644
> --- a/tools/btmgmt.c
> +++ b/tools/btmgmt.c
> @@ -3687,8 +3687,18 @@ static void add_adv_rsp(uint8_t status, uint16_t len, const void *param,
>
> static void add_adv_usage(void)
> {
> - print("Usage: add-adv [-u uuid] [-d adv_data] [-s scan_rsp] "
> - "[-t timeout] [-c] [-d] [-e] [-l] [-m] [-p] <instance_id>");
> + print("Usage: add-adv [options] <instance_id>\nOptions:\n"
> + "\t -u, --uuid <uuid> Service UUID\n"
> + "\t -d, --adv-data <data> Advertising Data bytes\n"
> + "\t -s, --scan-rsp <data> Scan Response Data bytes\n"
> + "\t -t, --timeout <timeout> Timeout in seconds\n"
> + "\t -c, --connectable \"connectable\" flag\n"
> + "\t -g, --general-discov \"general-discoverable\" flag\n"
> + "\t -l, --limited-discov \"limited-discoverable\" flag\n"
> + "\t -m, --managed-flags \"managed-flags\" flag\n"
> + "\t -p, --tx-power \"tx-power\" flag\n"
> + "e.g.:\n"
> + "\tadd-adv -u 180d -u 180f -d 080954657374204C45 1");
> }
>
> static struct option add_adv_options[] = {
> --
> 2.2.0.rc0.207.ga3a616c
>

All 4 patches in this set have been applied.

Thanks,
Arman

2015-03-26 03:29:57

by Arman Uguray

[permalink] [raw]
Subject: [PATCH v2 4/4] tools/btmgmt: Prettify supported flags in advinfo

This patch makes advinfo print human readable strings for the supported
flags field of Read Advertising Features response for the advinfo
command.
---
tools/btmgmt.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index f995ada..36a8681 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -3616,6 +3616,34 @@ static void cmd_le_oob(struct mgmt *mgmt, uint16_t index,
}
}

+static const char *adv_flags_str[] = {
+ "connectable",
+ "general-discoverable",
+ "limited-discoverable",
+ "managed-flags",
+ "tx-power",
+ "scan-rsp-appearance",
+ "scan-rsp-local-name",
+};
+
+static const char *adv_flags2str(uint32_t flags)
+{
+ static char str[256];
+ unsigned i;
+ int off;
+
+ off = 0;
+ str[0] = '\0';
+
+ for (i = 0; i < NELEM(adv_flags_str); i++) {
+ if ((flags & (1 << i)) != 0)
+ off += snprintf(str + off, sizeof(str) - off, "%s ",
+ adv_flags_str[i]);
+ }
+
+ return str;
+}
+
static void adv_features_rsp(uint8_t status, uint16_t len, const void *param,
void *user_data)
{
@@ -3640,7 +3668,7 @@ static void adv_features_rsp(uint8_t status, uint16_t len, const void *param,
}

supported_flags = le32_to_cpu(rp->supported_flags);
- print("Supported flags: 0x%04x", supported_flags);
+ print("Supported flags: %s", adv_flags2str(supported_flags));
print("Max advertising data len: %u", rp->max_adv_data_len);
print("Max scan response data len: %u", rp->max_scan_rsp_len);
print("Max instances: %u", rp->max_instances);
--
2.2.0.rc0.207.ga3a616c


2015-03-26 03:29:56

by Arman Uguray

[permalink] [raw]
Subject: [PATCH v2 3/4] tools/btmgmt: Fix crash in add-adv data parsing

This patch fixes an invalid free in parse_byte when an invalid data
string is given:

0 0x00007ffff78204b7 in raise () from /usr/lib/libc.so.6
1 0x00007ffff782188a in abort () from /usr/lib/libc.so.6
2 0x00007ffff785e993 in __libc_message () from /usr/lib/libc.so.6
3 0x00007ffff7863dee in malloc_printerr () from /usr/lib/libc.so.6
4 0x00007ffff78645cb in _int_free () from /usr/lib/libc.so.6
5 0x00000000004034f4 in parse_bytes (optarg=0x67ee30 "-l", bytes=bytes@entry=0x7fffffffe8f0, len=len@entry=0x7fffffffe900) at tools/btmgmt.c:3739
6 0x0000000000404182 in cmd_add_adv (mgmt=0x635010, index=65535, argc=4, argv=0x67eae0) at tools/btmgmt.c:3814
7 0x00000000004057f8 in rl_handler (input=0x67eb10 "add-adv -d -l 1") at tools/btmgmt.c:4237
8 0x00007ffff7bbe25e in rl_callback_read_char () from /usr/lib/libreadline.so.6
9 0x0000000000403339 in prompt_read (io=<optimized out>, user_data=<optimized out>) at tools/btmgmt.c:4302
10 0x000000000041c7c9 in io_callback (fd=<optimized out>, events=1, user_data=0x635bc0) at src/shared/io-mainloop.c:123
11 0x000000000041cff3 in mainloop_run () at src/shared/mainloop.c:157
12 0x0000000000402630 in main (argc=0, argv=<optimized out>) at tools/btmgmt.c:4389
---
tools/btmgmt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index bd83ac7..f995ada 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -3746,7 +3746,7 @@ static bool parse_bytes(char *optarg, uint8_t **bytes, size_t *len)
for (i = 0; i < *len; i++) {
if (sscanf(optarg + (i * 2), "%2hhx", *bytes + i) != 1) {
error("Invalid data");
- free(bytes);
+ free(*bytes);
*bytes = NULL;
return false;
}
--
2.2.0.rc0.207.ga3a616c


2015-03-26 03:29:55

by Arman Uguray

[permalink] [raw]
Subject: [PATCH v2 2/4] tools/btmgmt: Better usage info for add-adv

This patch improves the usage string that gets printed for the add-adv
command to provide more details about the possible options.
---
tools/btmgmt.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 19eeda1..bd83ac7 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -3687,8 +3687,18 @@ static void add_adv_rsp(uint8_t status, uint16_t len, const void *param,

static void add_adv_usage(void)
{
- print("Usage: add-adv [-u uuid] [-d adv_data] [-s scan_rsp] "
- "[-t timeout] [-c] [-d] [-e] [-l] [-m] [-p] <instance_id>");
+ print("Usage: add-adv [options] <instance_id>\nOptions:\n"
+ "\t -u, --uuid <uuid> Service UUID\n"
+ "\t -d, --adv-data <data> Advertising Data bytes\n"
+ "\t -s, --scan-rsp <data> Scan Response Data bytes\n"
+ "\t -t, --timeout <timeout> Timeout in seconds\n"
+ "\t -c, --connectable \"connectable\" flag\n"
+ "\t -g, --general-discov \"general-discoverable\" flag\n"
+ "\t -l, --limited-discov \"limited-discoverable\" flag\n"
+ "\t -m, --managed-flags \"managed-flags\" flag\n"
+ "\t -p, --tx-power \"tx-power\" flag\n"
+ "e.g.:\n"
+ "\tadd-adv -u 180d -u 180f -d 080954657374204C45 1");
}

static struct option add_adv_options[] = {
--
2.2.0.rc0.207.ga3a616c