2018-01-16 19:24:48

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 1/8] client: Rename set-uuids to uuids

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# uuids 0x1820
[bluetooth]# uuids
UUID: Internet Protocol Support (0x1820
---
client/advertising.c | 39 ++++++++++++++++++++++++++++++++++++---
client/main.c | 6 +++---
2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index f0fd3599e..5174417a8 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -32,6 +32,7 @@
#include <string.h>

#include "gdbus/gdbus.h"
+#include "src/shared/util.h"
#include "src/shared/shell.h"
#include "advertising.h"

@@ -434,15 +435,47 @@ void ad_unregister(DBusConnection *conn, GDBusProxy *manager)
}
}

+static void print_uuid(const char *uuid)
+{
+ const char *text;
+
+ text = bt_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(%s)\n", str, uuid);
+ } else
+ bt_shell_printf("\tUUID: (%s)\n", uuid);
+}
+
void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[])
{
+ if (argc < 2 || !strlen(argv[1])) {
+ char **uuid;
+
+ for (uuid = ad.uuids; uuid && *uuid; uuid++)
+ print_uuid(*uuid);
+
+ return;
+ }
+
g_strfreev(ad.uuids);
ad.uuids = NULL;
ad.uuids_len = 0;

- if (argc < 2 || !strlen(argv[1]))
- return;
-
ad.uuids = g_strdupv(&argv[1]);
if (!ad.uuids) {
bt_shell_printf("Failed to parse input\n");
diff --git a/client/main.c b/client/main.c
index a52599deb..d13dabdd0 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2191,7 +2191,7 @@ static char *ad_generator(const char *text, int state)
return argument_generator(text, state, ad_arguments);
}

-static void cmd_set_advertise_uuids(int argc, char *argv[])
+static void cmd_advertise_uuids(int argc, char *argv[])
{
ad_advertise_uuids(dbus_conn, argc, argv);
}
@@ -2287,8 +2287,8 @@ static const struct bt_shell_menu advertise_menu = {
.name = "advertise",
.desc = "Advertise Options Submenu",
.entries = {
- { "set-uuids", "[uuid1 uuid2 ...]",
- cmd_set_advertise_uuids, "Set advertise uuids" },
+ { "uuids", "[uuid1 uuid2 ...]", cmd_advertise_uuids,
+ "Set advertise uuids" },
{ "set-service", "[uuid] [data=xx xx ...]", cmd_set_advertise_service,
"Set advertise service data" },
{ "set-manufacturer", "[id] [data=xx xx ...]",
--
2.14.3



2018-01-19 13:46:21

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ 1/8] client: Rename set-uuids to uuids

Hi,

On Tue, Jan 16, 2018 at 5:24 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> Make the command return the current value if no parameters:
>
> [bluetooth]# uuids 0x1820
> [bluetooth]# uuids
> UUID: Internet Protocol Support (0x1820
> ---
> client/advertising.c | 39 ++++++++++++++++++++++++++++++++++++---
> client/main.c | 6 +++---
> 2 files changed, 39 insertions(+), 6 deletions(-)
>
> diff --git a/client/advertising.c b/client/advertising.c
> index f0fd3599e..5174417a8 100644
> --- a/client/advertising.c
> +++ b/client/advertising.c
> @@ -32,6 +32,7 @@
> #include <string.h>
>
> #include "gdbus/gdbus.h"
> +#include "src/shared/util.h"
> #include "src/shared/shell.h"
> #include "advertising.h"
>
> @@ -434,15 +435,47 @@ void ad_unregister(DBusConnection *conn, GDBusProxy *manager)
> }
> }
>
> +static void print_uuid(const char *uuid)
> +{
> + const char *text;
> +
> + text = bt_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(%s)\n", str, uuid);
> + } else
> + bt_shell_printf("\tUUID: (%s)\n", uuid);
> +}
> +
> void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[])
> {
> + if (argc < 2 || !strlen(argv[1])) {
> + char **uuid;
> +
> + for (uuid = ad.uuids; uuid && *uuid; uuid++)
> + print_uuid(*uuid);
> +
> + return;
> + }
> +
> g_strfreev(ad.uuids);
> ad.uuids = NULL;
> ad.uuids_len = 0;
>
> - if (argc < 2 || !strlen(argv[1]))
> - return;
> -
> ad.uuids = g_strdupv(&argv[1]);
> if (!ad.uuids) {
> bt_shell_printf("Failed to parse input\n");
> diff --git a/client/main.c b/client/main.c
> index a52599deb..d13dabdd0 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -2191,7 +2191,7 @@ static char *ad_generator(const char *text, int state)
> return argument_generator(text, state, ad_arguments);
> }
>
> -static void cmd_set_advertise_uuids(int argc, char *argv[])
> +static void cmd_advertise_uuids(int argc, char *argv[])
> {
> ad_advertise_uuids(dbus_conn, argc, argv);
> }
> @@ -2287,8 +2287,8 @@ static const struct bt_shell_menu advertise_menu = {
> .name = "advertise",
> .desc = "Advertise Options Submenu",
> .entries = {
> - { "set-uuids", "[uuid1 uuid2 ...]",
> - cmd_set_advertise_uuids, "Set advertise uuids" },
> + { "uuids", "[uuid1 uuid2 ...]", cmd_advertise_uuids,
> + "Set advertise uuids" },
> { "set-service", "[uuid] [data=xx xx ...]", cmd_set_advertise_service,
> "Set advertise service data" },
> { "set-manufacturer", "[id] [data=xx xx ...]",
> --
> 2.14.3

Applied.


--
Luiz Augusto von Dentz

2018-01-18 05:35:29

by ERAMOTO Masaya

[permalink] [raw]
Subject: Re: [PATCH BlueZ] shared/shell: Introduce bt_shell_{get,set}_env

Hi Luiz,

On 01/17/2018 04:24 AM, Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> These function can be used to share environment variable accross
> different files.
> ---
> src/shared/shell.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> src/shared/shell.h | 3 +++
> 2 files changed, 66 insertions(+)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index 6cdea1c7e..09f7896c6 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -56,6 +56,11 @@
>
> static GMainLoop *main_loop;
>
> +struct bt_shell_env {
> + char *name;
> + void *value;
> +};
> +
> static struct {
> struct io *input;
>
> @@ -66,6 +71,8 @@ static struct {
> const struct bt_shell_menu *menu;
> const struct bt_shell_menu *main;
> struct queue *submenus;
> +
> + struct queue *envs;
> } data;
>
> static void shell_print_menu(void);
> @@ -759,6 +766,14 @@ static void rl_cleanup(void)
> rl_callback_handler_remove();
> }
>
> +static void env_destroy(void *data)
> +{
> + struct bt_shell_env *env = data;
> +
> + free(env->name);
> + free(env);
> +}
> +
> void bt_shell_run(void)
> {
> struct io *signal;
> @@ -775,6 +790,11 @@ void bt_shell_run(void)
> g_main_loop_unref(main_loop);
> main_loop = NULL;
>
> + if (data.envs) {
> + queue_destroy(data.envs, env_destroy);
> + data.envs = NULL;
> + }
> +
> rl_cleanup();
> }
>
> @@ -849,3 +869,46 @@ bool bt_shell_detach(void)
>
> return true;
> }
> +
> +static bool match_env(const void *data, const void *user_data)
> +{
> + const struct bt_shell_env *env = data;
> + const char *name = user_data;
> +
> + return !strcmp(env->name, name);
> +}
> +
> +void bt_shell_set_env(const char *name, void *value)
> +{
> + struct bt_shell_env *env;
> +
> + if (!data.envs) {
> + data.envs = queue_new();
> + goto done;
> + }
> +
> + env = queue_remove_if(data.envs, match_env, (void *) name);
> + if (env)
> + env_destroy(env);
> +
> +done:
> + env = new0(struct bt_shell_env, 1);
> + env->name = strdup(name);
> + env->value = value;
> +
> + queue_push_tail(data.envs, env);
> +}
> +
> +void *bt_shell_get_env(const char *name)
> +{
> + const struct bt_shell_env *env;
> +
> + if (!data.envs)
> + return NULL;
> +
> + env = queue_find(data.envs, match_env, name);
> + if (!env)
> + return NULL;
> +
> + return env->name;
> +}

I think that it is better to return the env or the env->value so that we
can use the env->value in a caller, otherwise this function shall return
boolean type because it checks if the passed name exist.


Regards,
Eramoto

> diff --git a/src/shared/shell.h b/src/shared/shell.h
> index 8b8b1f634..359629896 100644
> --- a/src/shared/shell.h
> +++ b/src/shared/shell.h
> @@ -87,4 +87,7 @@ int bt_shell_release_prompt(const char *input);
> bool bt_shell_attach(int fd);
> bool bt_shell_detach(void);
>
> +void bt_shell_set_env(const char *name, void *value);
> +void *bt_shell_get_env(const char *name);
> +
> void bt_shell_cleanup(void);
>


2018-01-16 19:24:56

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 8/8] client: Rename set-timeout to timeout

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# timeout 1
[bluetooth]# timeout
Timeout: 1 sec
---
client/advertising.c | 11 ++++++++---
client/advertising.h | 2 +-
client/main.c | 13 +++++++++----
3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index ae639df9b..f7d054c73 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -684,12 +684,17 @@ void ad_advertise_duration(DBusConnection *conn, long int *value)
g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Duration");
}

-void ad_advertise_timeout(DBusConnection *conn, uint16_t value)
+void ad_advertise_timeout(DBusConnection *conn, long int *value)
{
- if (ad.timeout == value)
+ if (!value) {
+ bt_shell_printf("Timeout: %u sec\n", ad.timeout);
+ return;
+ }
+
+ if (ad.timeout == *value)
return;

- ad.timeout = value;
+ ad.timeout = *value;

g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Timeout");
}
diff --git a/client/advertising.h b/client/advertising.h
index 04fe38b1a..13e076438 100644
--- a/client/advertising.h
+++ b/client/advertising.h
@@ -33,4 +33,4 @@ void ad_advertise_appearance(DBusConnection *conn, bool value);
void ad_advertise_local_name(DBusConnection *conn, const char *name);
void ad_advertise_local_appearance(DBusConnection *conn, long int *value);
void ad_advertise_duration(DBusConnection *conn, long int *value);
-void ad_advertise_timeout(DBusConnection *conn, uint16_t value);
+void ad_advertise_timeout(DBusConnection *conn, long int *value);
diff --git a/client/main.c b/client/main.c
index 80e4c82ed..85803f1a3 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2289,18 +2289,23 @@ static void cmd_advertise_duration(int argc, char *argv[])
ad_advertise_duration(dbus_conn, &value);
}

-static void cmd_set_advertise_timeout(int argc, char *argv[])
+static void cmd_advertise_timeout(int argc, char *argv[])
{
long int value;
char *endptr = NULL;

+ if (argc < 2) {
+ ad_advertise_timeout(dbus_conn, NULL);
+ return;
+ }
+
value = strtol(argv[1], &endptr, 0);
if (!endptr || *endptr != '\0' || value > UINT16_MAX) {
bt_shell_printf("Invalid argument\n");
return;
}

- ad_advertise_timeout(dbus_conn, value);
+ ad_advertise_timeout(dbus_conn, &value);
}

static const struct bt_shell_menu advertise_menu = {
@@ -2323,8 +2328,8 @@ static const struct bt_shell_menu advertise_menu = {
"Set custom appearance to be advertised" },
{ "duration", "[seconds]", cmd_advertise_duration,
"Set/Get advertise duration" },
- { "set-timeout", "<seconds>", cmd_set_advertise_timeout,
- "Set advertise timeout" },
+ { "timeout", "[seconds]", cmd_advertise_timeout,
+ "Set/Get advertise timeout" },
{ } },
};

--
2.14.3


2018-01-16 19:24:55

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 7/8] client: Rename set-duration to duration

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# duration 1
[bluetooth]# duration
Duration: 1 sec
---
client/advertising.c | 11 ++++++++---
client/advertising.h | 2 +-
client/main.c | 13 +++++++++----
3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index d95974f08..ae639df9b 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -669,12 +669,17 @@ void ad_advertise_local_appearance(DBusConnection *conn, long int *value)
g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Appearance");
}

-void ad_advertise_duration(DBusConnection *conn, uint16_t value)
+void ad_advertise_duration(DBusConnection *conn, long int *value)
{
- if (ad.duration == value)
+ if (!value) {
+ bt_shell_printf("Duration: %u sec\n", ad.duration);
+ return;
+ }
+
+ if (ad.duration == *value)
return;

- ad.duration = value;
+ ad.duration = *value;

g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Duration");
}
diff --git a/client/advertising.h b/client/advertising.h
index 7edf4fd95..04fe38b1a 100644
--- a/client/advertising.h
+++ b/client/advertising.h
@@ -32,5 +32,5 @@ void ad_advertise_name(DBusConnection *conn, bool value);
void ad_advertise_appearance(DBusConnection *conn, bool value);
void ad_advertise_local_name(DBusConnection *conn, const char *name);
void ad_advertise_local_appearance(DBusConnection *conn, long int *value);
-void ad_advertise_duration(DBusConnection *conn, uint16_t value);
+void ad_advertise_duration(DBusConnection *conn, long int *value);
void ad_advertise_timeout(DBusConnection *conn, uint16_t value);
diff --git a/client/main.c b/client/main.c
index 49b165231..80e4c82ed 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2270,18 +2270,23 @@ static void cmd_advertise_appearance(int argc, char *argv[])
ad_advertise_local_appearance(dbus_conn, &value);
}

-static void cmd_set_advertise_duration(int argc, char *argv[])
+static void cmd_advertise_duration(int argc, char *argv[])
{
long int value;
char *endptr = NULL;

+ if (argc < 2) {
+ ad_advertise_duration(dbus_conn, NULL);
+ return;
+ }
+
value = strtol(argv[1], &endptr, 0);
if (!endptr || *endptr != '\0' || value > UINT16_MAX) {
bt_shell_printf("Invalid argument\n");
return;
}

- ad_advertise_duration(dbus_conn, value);
+ ad_advertise_duration(dbus_conn, &value);
}

static void cmd_set_advertise_timeout(int argc, char *argv[])
@@ -2316,8 +2321,8 @@ static const struct bt_shell_menu advertise_menu = {
"Enable/disable local name to be advertised" },
{ "appearance", "[value]", cmd_advertise_appearance,
"Set custom appearance to be advertised" },
- { "set-duration", "<seconds>", cmd_set_advertise_duration,
- "Set advertise duration" },
+ { "duration", "[seconds]", cmd_advertise_duration,
+ "Set/Get advertise duration" },
{ "set-timeout", "<seconds>", cmd_set_advertise_timeout,
"Set advertise timeout" },
{ } },
--
2.14.3


2018-01-16 19:24:54

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 6/8] client: Rename set-appearance to appearance

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# appearance 0x0001
[bluetooth]# appearance
Appearance: Unknown (0x0001)
---
client/advertising.c | 18 +++++++++++++++---
client/advertising.h | 2 +-
client/main.c | 11 ++++++++---
3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index f5ba0b97b..d95974f08 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -647,12 +647,24 @@ void ad_advertise_appearance(DBusConnection *conn, bool value)
g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Includes");
}

-void ad_advertise_local_appearance(DBusConnection *conn, uint16_t value)
+void ad_advertise_local_appearance(DBusConnection *conn, long int *value)
{
- if (ad.local_appearance == value)
+ if (!value) {
+ if (ad.local_appearance != UINT16_MAX)
+ bt_shell_printf("Appearance: %s (0x%04x)\n",
+ bt_appear_to_str(ad.local_appearance),
+ ad.local_appearance);
+ else
+ bt_shell_printf("Apperance: %s\n",
+ ad.appearance ? "on" : "off");
+
+ return;
+ }
+
+ if (ad.local_appearance == *value)
return;

- ad.local_appearance = value;
+ ad.local_appearance = *value;

g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Appearance");
}
diff --git a/client/advertising.h b/client/advertising.h
index 6c73b638d..7edf4fd95 100644
--- a/client/advertising.h
+++ b/client/advertising.h
@@ -31,6 +31,6 @@ 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);
void ad_advertise_local_name(DBusConnection *conn, const char *name);
-void ad_advertise_local_appearance(DBusConnection *conn, uint16_t value);
+void ad_advertise_local_appearance(DBusConnection *conn, long int *value);
void ad_advertise_duration(DBusConnection *conn, uint16_t value);
void ad_advertise_timeout(DBusConnection *conn, uint16_t value);
diff --git a/client/main.c b/client/main.c
index 01a3c2131..49b165231 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2241,11 +2241,16 @@ static void cmd_advertise_name(int argc, char *argv[])
ad_advertise_local_name(dbus_conn, argv[1]);
}

-static void cmd_set_advertise_appearance(int argc, char *argv[])
+static void cmd_advertise_appearance(int argc, char *argv[])
{
long int value;
char *endptr = NULL;

+ if (argc < 2) {
+ ad_advertise_local_appearance(dbus_conn, NULL);
+ return;
+ }
+
if (strcmp(argv[1], "on") == 0 || strcmp(argv[1], "yes") == 0) {
ad_advertise_appearance(dbus_conn, true);
return;
@@ -2262,7 +2267,7 @@ static void cmd_set_advertise_appearance(int argc, char *argv[])
return;
}

- ad_advertise_local_appearance(dbus_conn, value);
+ ad_advertise_local_appearance(dbus_conn, &value);
}

static void cmd_set_advertise_duration(int argc, char *argv[])
@@ -2309,7 +2314,7 @@ static const struct bt_shell_menu advertise_menu = {
mode_generator },
{ "name", "[on/off/name]", cmd_advertise_name,
"Enable/disable local name to be advertised" },
- { "set-appearance", "<value>", cmd_set_advertise_appearance,
+ { "appearance", "[value]", cmd_advertise_appearance,
"Set custom appearance to be advertised" },
{ "set-duration", "<seconds>", cmd_set_advertise_duration,
"Set advertise duration" },
--
2.14.3


2018-01-16 19:24:53

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 5/8] client: Rename set-name to name

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# name blah
[bluetooth]# name
LocalName: blah
---
client/advertising.c | 6 ++++++
client/main.c | 9 +++++++--
2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index 05c69102c..f5ba0b97b 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -619,6 +619,12 @@ void ad_advertise_name(DBusConnection *conn, bool value)

void ad_advertise_local_name(DBusConnection *conn, const char *name)
{
+ if (!name) {
+ if (ad.local_name)
+ bt_shell_printf("LocalName: %s\n", ad.local_name);
+ return;
+ }
+
if (ad.local_name && !strcmp(name, ad.local_name))
return;

diff --git a/client/main.c b/client/main.c
index 195a86141..01a3c2131 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2221,8 +2221,13 @@ static void cmd_advertise_tx_power(int argc, char *argv[])
ad_advertise_tx_power(dbus_conn, &powered);
}

-static void cmd_set_advertise_name(int argc, char *argv[])
+static void cmd_advertise_name(int argc, char *argv[])
{
+ if (argc < 2) {
+ ad_advertise_local_name(dbus_conn, NULL);
+ return;
+ }
+
if (strcmp(argv[1], "on") == 0 || strcmp(argv[1], "yes") == 0) {
ad_advertise_name(dbus_conn, true);
return;
@@ -2302,7 +2307,7 @@ static const struct bt_shell_menu advertise_menu = {
{ "tx-power", "[on/off]", cmd_advertise_tx_power,
"Enable/disable TX power to be advertised",
mode_generator },
- { "set-name", "<on/off/name>", cmd_set_advertise_name,
+ { "name", "[on/off/name]", cmd_advertise_name,
"Enable/disable local name to be advertised" },
{ "set-appearance", "<value>", cmd_set_advertise_appearance,
"Set custom appearance to be advertised" },
--
2.14.3


2018-01-16 19:24:52

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 4/8] client: Rename set-tx-power to tx-power

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# tx-power on
[bluetooth]# tx-power
Tx Power: on
---
client/advertising.c | 11 ++++++++---
client/advertising.h | 2 +-
client/main.c | 11 ++++++++---
3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index 304ae683e..05c69102c 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -587,12 +587,17 @@ void ad_advertise_manufacturer(DBusConnection *conn, int argc, char *argv[])
"ManufacturerData");
}

-void ad_advertise_tx_power(DBusConnection *conn, bool value)
+void ad_advertise_tx_power(DBusConnection *conn, dbus_bool_t *value)
{
- if (ad.tx_power == value)
+ if (!value) {
+ bt_shell_printf("Tx Power: %s\n", ad.tx_power ? "on" : "off");
+ return;
+ }
+
+ if (ad.tx_power == *value)
return;

- ad.tx_power = value;
+ ad.tx_power = *value;

g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Includes");
}
diff --git a/client/advertising.h b/client/advertising.h
index d7472e1a5..6c73b638d 100644
--- a/client/advertising.h
+++ b/client/advertising.h
@@ -27,7 +27,7 @@ void ad_unregister(DBusConnection *conn, GDBusProxy *manager);
void ad_advertise_uuids(DBusConnection *conn, int argc, char *argv[]);
void ad_advertise_service(DBusConnection *conn, int argc, char *argv[]);
void ad_advertise_manufacturer(DBusConnection *conn, int argc, char *argv[]);
-void ad_advertise_tx_power(DBusConnection *conn, bool value);
+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);
void ad_advertise_local_name(DBusConnection *conn, const char *name);
diff --git a/client/main.c b/client/main.c
index 26bbc7e80..195a86141 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2206,14 +2206,19 @@ static void cmd_advertise_manufacturer(int argc, char *argv[])
ad_advertise_manufacturer(dbus_conn, argc, argv);
}

-static void cmd_set_advertise_tx_power(int argc, char *argv[])
+static void cmd_advertise_tx_power(int argc, char *argv[])
{
dbus_bool_t powered;

+ if (argc < 2) {
+ ad_advertise_tx_power(dbus_conn, NULL);
+ return;
+ }
+
if (!parse_argument(argc, argv, NULL, NULL, &powered, NULL))
return;

- ad_advertise_tx_power(dbus_conn, powered);
+ ad_advertise_tx_power(dbus_conn, &powered);
}

static void cmd_set_advertise_name(int argc, char *argv[])
@@ -2294,7 +2299,7 @@ static const struct bt_shell_menu advertise_menu = {
{ "manufacturer", "[id] [data=xx xx ...]",
cmd_advertise_manufacturer,
"Set advertise manufacturer data" },
- { "set-tx-power", "<on/off>", cmd_set_advertise_tx_power,
+ { "tx-power", "[on/off]", cmd_advertise_tx_power,
"Enable/disable TX power to be advertised",
mode_generator },
{ "set-name", "<on/off/name>", cmd_set_advertise_name,
--
2.14.3


2018-01-16 19:24:51

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 3/8] client: Rename set-manufacturer to manufacturer

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# manufacturer 2 00
[bluetooth]# manufacturer
Manufacturer: 2
00
---
client/advertising.c | 12 ++++++++++--
client/main.c | 6 +++---
2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index 974462124..304ae683e 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -543,10 +543,18 @@ void ad_advertise_manufacturer(DBusConnection *conn, int argc, char *argv[])
long int val;
struct ad_data *data;

- ad_clear_manufacturer();
+ if (argc < 2 || !strlen(argv[1])) {
+ if (ad.manufacturer.data.len) {
+ bt_shell_printf("Manufacturer: %u\n",
+ ad.manufacturer.id);
+ bt_shell_hexdump(ad.manufacturer.data.data,
+ ad.manufacturer.data.len);
+ }

- if (argc < 2)
return;
+ }
+
+ ad_clear_manufacturer();

val = strtol(argv[1], &endptr, 0);
if (!endptr || *endptr != '\0' || val > UINT16_MAX) {
diff --git a/client/main.c b/client/main.c
index 9d68be62f..26bbc7e80 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2201,7 +2201,7 @@ static void cmd_advertise_service(int argc, char *argv[])
ad_advertise_service(dbus_conn, argc, argv);
}

-static void cmd_set_advertise_manufacturer(int argc, char *argv[])
+static void cmd_advertise_manufacturer(int argc, char *argv[])
{
ad_advertise_manufacturer(dbus_conn, argc, argv);
}
@@ -2291,8 +2291,8 @@ static const struct bt_shell_menu advertise_menu = {
"Set advertise uuids" },
{ "service", "[uuid] [data=xx xx ...]", cmd_advertise_service,
"Set advertise service data" },
- { "set-manufacturer", "[id] [data=xx xx ...]",
- cmd_set_advertise_manufacturer,
+ { "manufacturer", "[id] [data=xx xx ...]",
+ cmd_advertise_manufacturer,
"Set advertise manufacturer data" },
{ "set-tx-power", "<on/off>", cmd_set_advertise_tx_power,
"Enable/disable TX power to be advertised",
--
2.14.3


2018-01-16 19:24:50

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 2/8] client: Rename set-service to service

From: Luiz Augusto von Dentz <[email protected]>

Make the command return the current value if no parameters:

[bluetooth]# service 0x1820 00 00 00
[bluetooth]# service
UUID: Internet Protocol Support (0x1820)
00 00 00 ...
---
client/advertising.c | 9 +++++----
client/main.c | 4 ++--
2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/client/advertising.c b/client/advertising.c
index 5174417a8..974462124 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -498,15 +498,16 @@ void ad_advertise_service(DBusConnection *conn, int argc, char *argv[])
unsigned int i;
struct ad_data *data;

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

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

- for (i = 1; i < (unsigned int) argc; i++) {
+ for (i = 2; i < (unsigned int) argc; i++) {
long int val;
char *endptr = NULL;

diff --git a/client/main.c b/client/main.c
index d13dabdd0..9d68be62f 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2196,7 +2196,7 @@ static void cmd_advertise_uuids(int argc, char *argv[])
ad_advertise_uuids(dbus_conn, argc, argv);
}

-static void cmd_set_advertise_service(int argc, char *argv[])
+static void cmd_advertise_service(int argc, char *argv[])
{
ad_advertise_service(dbus_conn, argc, argv);
}
@@ -2289,7 +2289,7 @@ static const struct bt_shell_menu advertise_menu = {
.entries = {
{ "uuids", "[uuid1 uuid2 ...]", cmd_advertise_uuids,
"Set advertise uuids" },
- { "set-service", "[uuid] [data=xx xx ...]", cmd_set_advertise_service,
+ { "service", "[uuid] [data=xx xx ...]", cmd_advertise_service,
"Set advertise service data" },
{ "set-manufacturer", "[id] [data=xx xx ...]",
cmd_set_advertise_manufacturer,
--
2.14.3


2018-01-16 19:24:49

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ] shared/shell: Introduce bt_shell_{get,set}_env

From: Luiz Augusto von Dentz <[email protected]>

These function can be used to share environment variable accross
different files.
---
src/shared/shell.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/shared/shell.h | 3 +++
2 files changed, 66 insertions(+)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 6cdea1c7e..09f7896c6 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -56,6 +56,11 @@

static GMainLoop *main_loop;

+struct bt_shell_env {
+ char *name;
+ void *value;
+};
+
static struct {
struct io *input;

@@ -66,6 +71,8 @@ static struct {
const struct bt_shell_menu *menu;
const struct bt_shell_menu *main;
struct queue *submenus;
+
+ struct queue *envs;
} data;

static void shell_print_menu(void);
@@ -759,6 +766,14 @@ static void rl_cleanup(void)
rl_callback_handler_remove();
}

+static void env_destroy(void *data)
+{
+ struct bt_shell_env *env = data;
+
+ free(env->name);
+ free(env);
+}
+
void bt_shell_run(void)
{
struct io *signal;
@@ -775,6 +790,11 @@ void bt_shell_run(void)
g_main_loop_unref(main_loop);
main_loop = NULL;

+ if (data.envs) {
+ queue_destroy(data.envs, env_destroy);
+ data.envs = NULL;
+ }
+
rl_cleanup();
}

@@ -849,3 +869,46 @@ bool bt_shell_detach(void)

return true;
}
+
+static bool match_env(const void *data, const void *user_data)
+{
+ const struct bt_shell_env *env = data;
+ const char *name = user_data;
+
+ return !strcmp(env->name, name);
+}
+
+void bt_shell_set_env(const char *name, void *value)
+{
+ struct bt_shell_env *env;
+
+ if (!data.envs) {
+ data.envs = queue_new();
+ goto done;
+ }
+
+ env = queue_remove_if(data.envs, match_env, (void *) name);
+ if (env)
+ env_destroy(env);
+
+done:
+ env = new0(struct bt_shell_env, 1);
+ env->name = strdup(name);
+ env->value = value;
+
+ queue_push_tail(data.envs, env);
+}
+
+void *bt_shell_get_env(const char *name)
+{
+ const struct bt_shell_env *env;
+
+ if (!data.envs)
+ return NULL;
+
+ env = queue_find(data.envs, match_env, name);
+ if (!env)
+ return NULL;
+
+ return env->name;
+}
diff --git a/src/shared/shell.h b/src/shared/shell.h
index 8b8b1f634..359629896 100644
--- a/src/shared/shell.h
+++ b/src/shared/shell.h
@@ -87,4 +87,7 @@ int bt_shell_release_prompt(const char *input);
bool bt_shell_attach(int fd);
bool bt_shell_detach(void);

+void bt_shell_set_env(const char *name, void *value);
+void *bt_shell_get_env(const char *name);
+
void bt_shell_cleanup(void);
--
2.14.3