2018-02-16 05:44:31

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 0/7] Improve ad service and add ad clear

The new clear command clears advertise configuration explicitly.

ERAMOTO Masaya (7):
client: Fix null output for ad service uuid
client: Not output ad service info if no uuid sets
client: Fix data growth if reconfiguring ad service
client: Improve help messages for advertise
client: Introduce data_clear() calling ->clear()
client: Introduce ad_disable_{uuids,service,manufacturer}
client: Add clear command for advertise

client/advertising.c | 50 ++++++++++++++++++---
client/advertising.h | 3 ++
client/main.c | 123 +++++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 152 insertions(+), 24 deletions(-)

--
2.14.1



2018-02-19 10:40:33

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ 0/7] Improve ad service and add ad clear

Hi Eramoto,

On Fri, Feb 16, 2018 at 7:44 AM, ERAMOTO Masaya
<[email protected]> wrote:
> The new clear command clears advertise configuration explicitly.
>
> ERAMOTO Masaya (7):
> client: Fix null output for ad service uuid
> client: Not output ad service info if no uuid sets
> client: Fix data growth if reconfiguring ad service
> client: Improve help messages for advertise
> client: Introduce data_clear() calling ->clear()
> client: Introduce ad_disable_{uuids,service,manufacturer}
> client: Add clear command for advertise
>
> client/advertising.c | 50 ++++++++++++++++++---
> client/advertising.h | 3 ++
> client/main.c | 123 +++++++++++++++++++++++++++++++++++++++++++--------
> 3 files changed, 152 insertions(+), 24 deletions(-)
>
> --
> 2.14.1

Applied, thanks.

--
Luiz Augusto von Dentz

2018-02-16 05:51:48

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 7/7] client: Add clear command for advertise

Adds the clear command to advertise-related commands to clear individual
fields or whole of advertise configuration.
---
client/main.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)

diff --git a/client/main.c b/client/main.c
index 288ed032f..38df75828 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2314,6 +2314,74 @@ static void cmd_advertise_timeout(int argc, char *argv[])
ad_advertise_timeout(dbus_conn, &value);
}

+static void ad_clear_uuids(void)
+{
+ ad_disable_uuids(dbus_conn);
+}
+
+static void ad_clear_service(void)
+{
+ ad_disable_service(dbus_conn);
+}
+
+static void ad_clear_manufacturer(void)
+{
+ ad_disable_manufacturer(dbus_conn);
+}
+
+static void ad_clear_tx_power(void)
+{
+ dbus_bool_t powered = false;
+
+ ad_advertise_tx_power(dbus_conn, &powered);
+}
+
+static void ad_clear_name(void)
+{
+ ad_advertise_name(dbus_conn, false);
+}
+
+static void ad_clear_appearance(void)
+{
+ ad_advertise_appearance(dbus_conn, false);
+}
+
+static void ad_clear_duration(void)
+{
+ long int value = 0;
+
+ ad_advertise_duration(dbus_conn, &value);
+}
+
+static void ad_clear_timeout(void)
+{
+ long int value = 0;
+
+ ad_advertise_timeout(dbus_conn, &value);
+}
+
+static const struct clear_entry ad_clear[] = {
+ { "uuids", ad_clear_uuids },
+ { "service", ad_clear_service },
+ { "manufacturer", ad_clear_manufacturer },
+ { "tx-power", ad_clear_tx_power },
+ { "name", ad_clear_name },
+ { "appearance", ad_clear_appearance },
+ { "duration", ad_clear_duration },
+ { "timeout", ad_clear_timeout },
+ {}
+};
+
+static void cmd_ad_clear(int argc, char *argv[])
+{
+ bool all = false;
+
+ if (argc < 2 || !strlen(argv[1]))
+ all = true;
+
+ data_clear(ad_clear, all ? "all" : argv[1]);
+}
+
static const struct bt_shell_menu advertise_menu = {
.name = "advertise",
.desc = "Advertise Options Submenu",
@@ -2336,6 +2404,8 @@ static const struct bt_shell_menu advertise_menu = {
"Set/Get advertise duration" },
{ "timeout", "[seconds]", cmd_advertise_timeout,
"Set/Get advertise timeout" },
+ { "clear", "[uuids/service/manufacturer/config-name...]", cmd_ad_clear,
+ "Clear advertise config" },
{ } },
};

--
2.14.1


2018-02-16 05:51:37

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 6/7] client: Introduce ad_disable_{uuids,service,manufacturer}

---
client/advertising.c | 39 ++++++++++++++++++++++++++++++++++++---
client/advertising.h | 3 +++
2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index f1b08c0b6..3cfc318ba 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -507,6 +507,13 @@ void ad_unregister(DBusConnection *conn, GDBusProxy *manager)
}
}

+static void ad_clear_uuids(void)
+{
+ g_strfreev(ad.uuids);
+ ad.uuids = NULL;
+ ad.uuids_len = 0;
+}
+
void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[])
{
if (argc < 2 || !strlen(argv[1])) {
@@ -514,9 +521,7 @@ void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[])
return;
}

- g_strfreev(ad.uuids);
- ad.uuids = NULL;
- ad.uuids_len = 0;
+ ad_clear_uuids();

ad.uuids = g_strdupv(&argv[1]);
if (!ad.uuids) {
@@ -529,6 +534,15 @@ void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[])
g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "ServiceUUIDs");
}

+void ad_disable_uuids(DBusConnection *conn)
+{
+ if (!ad.uuids)
+ return;
+
+ ad_clear_uuids();
+ g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "ServiceUUIDs");
+}
+
static void ad_clear_service(void)
{
g_free(ad.service.uuid);
@@ -578,6 +592,15 @@ void ad_advertise_service(DBusConnection *conn, int argc, char *argv[])
g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "ServiceData");
}

+void ad_disable_service(DBusConnection *conn)
+{
+ if (!ad.service.uuid)
+ return;
+
+ ad_clear_service();
+ g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "ServiceData");
+}
+
static void ad_clear_manufacturer(void)
{
memset(&ad.manufacturer, 0, sizeof(ad.manufacturer));
@@ -634,6 +657,16 @@ void ad_advertise_manufacturer(DBusConnection *conn, int argc, char *argv[])
"ManufacturerData");
}

+void ad_disable_manufacturer(DBusConnection *conn)
+{
+ if (!ad.manufacturer.id && !ad.manufacturer.data.len)
+ return;
+
+ ad_clear_manufacturer();
+ g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE,
+ "ManufacturerData");
+}
+
void ad_advertise_tx_power(DBusConnection *conn, dbus_bool_t *value)
{
if (!value) {
diff --git a/client/advertising.h b/client/advertising.h
index 13e076438..b73d33b13 100644
--- a/client/advertising.h
+++ b/client/advertising.h
@@ -25,8 +25,11 @@ void ad_register(DBusConnection *conn, GDBusProxy *manager, const char *type);
void ad_unregister(DBusConnection *conn, GDBusProxy *manager);

void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[]);
+void ad_disable_uuids(DBusConnection *conn);
void ad_advertise_service(DBusConnection *conn, int argc, char *argv[]);
+void ad_disable_service(DBusConnection *conn);
void ad_advertise_manufacturer(DBusConnection *conn, int argc, char *argv[]);
+void ad_disable_manufacturer(DBusConnection *conn);
void ad_advertise_tx_power(DBusConnection *conn, dbus_bool_t *value);
void ad_advertise_name(DBusConnection *conn, bool value);
void ad_advertise_appearance(DBusConnection *conn, bool value);
--
2.14.1


2018-02-16 05:51:29

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 5/7] client: Introduce data_clear() calling ->clear()

---
client/main.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/client/main.c b/client/main.c
index 8fc76a6de..288ed032f 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1405,10 +1405,12 @@ static void filter_clear_duplicate(void)
filter.duplicate = false;
}

-static const struct filter_clear {
+struct clear_entry {
const char *name;
void (*clear) (void);
-} filter_clear[] = {
+};
+
+static const struct clear_entry filter_clear[] = {
{ "uuids", filter_clear_uuids },
{ "rssi", filter_clear_rssi },
{ "pathloss", filter_clear_pathloss },
@@ -1437,29 +1439,44 @@ static char *filter_clear_generator(const char *text, int state)
return NULL;
}

-static void cmd_scan_filter_clear(int argc, char *argv[])
+static gboolean data_clear(const struct clear_entry *entry_table,
+ const char *name)
{
- const struct filter_clear *fc;
+ const struct clear_entry *entry;
bool all = false;

- if (argc < 2 || !strlen(argv[1]))
+ if (!name || !strlen(name) || !strcmp("all", name))
all = true;

- for (fc = filter_clear; fc && fc->name; fc++) {
- if (all || !strcmp(fc->name, argv[1])) {
- fc->clear();
- filter.set = false;
+ for (entry = entry_table; entry && entry->name; entry++) {
+ if (all || !strcmp(entry->name, name)) {
+ entry->clear();
if (!all)
goto done;
}
}

if (!all) {
- bt_shell_printf("Invalid argument %s\n", argv[1]);
- return;
+ bt_shell_printf("Invalid argument %s\n", name);
+ return FALSE;
}

done:
+ return TRUE;
+}
+
+static void cmd_scan_filter_clear(int argc, char *argv[])
+{
+ bool all = false;
+
+ if (argc < 2 || !strlen(argv[1]))
+ all = true;
+
+ if (!data_clear(filter_clear, all ? "all" : argv[1]))
+ return;
+
+ filter.set = false;
+
if (check_default_ctrl() == FALSE)
return;

--
2.14.1


2018-02-16 05:51:21

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 4/7] client: Improve help messages for advertise

---
client/main.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/client/main.c b/client/main.c
index a6adb70d2..8fc76a6de 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2302,19 +2302,19 @@ static const struct bt_shell_menu advertise_menu = {
.desc = "Advertise Options Submenu",
.entries = {
{ "uuids", "[uuid1 uuid2 ...]", cmd_advertise_uuids,
- "Set advertise uuids" },
+ "Set/Get advertise uuids" },
{ "service", "[uuid] [data=xx xx ...]", cmd_advertise_service,
- "Set advertise service data" },
+ "Set/Get advertise service data" },
{ "manufacturer", "[id] [data=xx xx ...]",
cmd_advertise_manufacturer,
- "Set advertise manufacturer data" },
+ "Set/Get advertise manufacturer data" },
{ "tx-power", "[on/off]", cmd_advertise_tx_power,
- "Enable/disable TX power to be advertised",
+ "Show/Enable/Disable TX power to be advertised",
NULL },
{ "name", "[on/off/name]", cmd_advertise_name,
- "Enable/disable local name to be advertised" },
- { "appearance", "[value]", cmd_advertise_appearance,
- "Set custom appearance to be advertised" },
+ "Configure local name to be advertised" },
+ { "appearance", "[on/off/value]", cmd_advertise_appearance,
+ "Configure custom appearance to be advertised" },
{ "duration", "[seconds]", cmd_advertise_duration,
"Set/Get advertise duration" },
{ "timeout", "[seconds]", cmd_advertise_timeout,
--
2.14.1


2018-02-16 05:51:15

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 3/7] client: Fix data growth if reconfiguring ad service

Since commit 65eff5c2 ("client: Rename set-service to service"), data
are appended in every run of advertise service with data arguments as
below:

[bluetooth]# service 1 1 2
[bluetooth]# service
UUID: SDP(1)
01 02 ..
[bluetooth]# service 1 1 2 3
[bluetooth]# service
UUID: SDP(1)
01 02 01 02 03 .....
---
client/advertising.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/client/advertising.c b/client/advertising.c
index e500a2e86..f1b08c0b6 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -549,6 +549,8 @@ void ad_advertise_service(DBusConnection *conn, int argc, char *argv[])
return;
}

+ ad_clear_service();
+
ad.service.uuid = g_strdup(argv[1]);
data = &ad.service.data;

--
2.14.1


2018-02-16 05:51:08

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 2/7] client: Not output ad service info if no uuid sets

---
client/advertising.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index 80a48652c..e500a2e86 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -541,8 +541,11 @@ void ad_advertise_service(DBusConnection *conn, int argc, char *argv[])
struct ad_data *data;

if (argc < 2 || !strlen(argv[1])) {
- print_uuid(ad.service.uuid);
- bt_shell_hexdump(ad.service.data.data, ad.service.data.len);
+ if (ad.service.uuid) {
+ print_uuid(ad.service.uuid);
+ bt_shell_hexdump(ad.service.data.data,
+ ad.service.data.len);
+ }
return;
}

--
2.14.1


2018-02-16 05:51:03

by ERAMOTO Masaya

[permalink] [raw]
Subject: [PATCH BlueZ 1/7] client: Fix null output for ad service uuid

If getting the advertise service information without setting, outputs
null as UUID as below:

[bluetooth]# service
UUID: ((null))
---
client/advertising.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/client/advertising.c b/client/advertising.c
index b9b9a7371..80a48652c 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -131,7 +131,7 @@ static void print_uuid(const char *uuid)

bt_shell_printf("UUID: %s(%s)\n", str, uuid);
} else
- bt_shell_printf("UUID: (%s)\n", uuid);
+ bt_shell_printf("UUID: (%s)\n", uuid ? uuid : "");
}

static void print_ad_uuids(void)
--
2.14.1