2014-03-05 12:56:04

by Lukasz Rymanowski

[permalink] [raw]
Subject: [RFC 0/2] android: Enable debugs bluetoothd

For user variant build of Android we should not print too much logs.
Therefore we should have possibility to turn on/off logs.

First patch adds simple on/off mechanism using android properties and
bluetoothd-wrapper.

Bluetoothd-wrapper is used because:
1. we can read android properties there
2. We can get early logs from daemon startup
3. bluetoothd-wrapper is not used in user variant build so debug logs
should be off on that variant by default.

Second patch gives us possibility to enable verbose logs and for now it
is mgmt interface logs which also might be useful in some cases.

For now, when verbose debugs are ON then also debug is ON.

Lukasz Rymanowski (2):
android: Add possible to enable BlueZ debug logs
android: Add verbose debugs to BlueZ

android/README | 16 ++++++++++++++++
android/bluetooth.c | 11 ++++++++++-
android/bluetooth.h | 2 +-
android/bluetoothd-wrapper.c | 27 ++++++++++++++++++++++-----
android/main.c | 14 ++++++++++++--
5 files changed, 61 insertions(+), 9 deletions(-)

--
1.8.4



2014-03-05 12:56:06

by Lukasz Rymanowski

[permalink] [raw]
Subject: [RFC 2/2] android: Add verbose debugs to BlueZ

It is usefull in some cases to enable more logs for BlueZ debugging.
This patch introduce possibility to enable verbose debugs.
For now it will enable mgmt interface debug logs

More info in README
---
android/README | 5 +++++
android/bluetooth.c | 11 ++++++++++-
android/bluetooth.h | 2 +-
android/bluetoothd-wrapper.c | 18 ++++++++++++++----
android/main.c | 8 ++++++--
5 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/android/README b/android/README
index b7ecf5f..cf114a4 100644
--- a/android/README
+++ b/android/README
@@ -140,6 +140,11 @@ adb shell setprop persist.sys.bluetooth.debug 1

After changing property value Bluetooth needs to be restarted to apply changes.

+There is also a possibility to enable verbose debug (e.g mgmt interface logs)
+which also enables debugs as above.
+To enable it procced in the same way as described above but use system
+properties called: persist.sys.bluetooth.vdebug
+
Note: Debugs are only available on NON USER build variants
=============================
Building and running on Linux
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 6d94904..cfced4f 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -148,6 +148,12 @@ static GSList *browse_reqs;

static struct ipc *hal_ipc = NULL;

+static void mgmt_debug(const char *str, void *user_data)
+{
+ const char *prefix = user_data;
+ info("%s%s", prefix, str);
+}
+
static void store_adapter_config(void)
{
GKeyFile *key_file;
@@ -2154,7 +2160,7 @@ failed:
cb(-EIO, NULL);
}

-bool bt_bluetooth_start(int index, bt_bluetooth_ready cb)
+bool bt_bluetooth_start(int index, bool vdebug, bt_bluetooth_ready cb)
{
DBG("index %d", index);

@@ -2164,6 +2170,9 @@ bool bt_bluetooth_start(int index, bt_bluetooth_ready cb)
return false;
}

+ if (vdebug)
+ mgmt_set_debug(mgmt_if, mgmt_debug, "mgmt_if: ", NULL);
+
if (mgmt_send(mgmt_if, MGMT_OP_READ_VERSION, MGMT_INDEX_NONE, 0, NULL,
read_version_complete, cb, NULL) == 0) {
error("Error sending READ_VERSION mgmt command");
diff --git a/android/bluetooth.h b/android/bluetooth.h
index 4731e2b..fe3b2b5 100644
--- a/android/bluetooth.h
+++ b/android/bluetooth.h
@@ -22,7 +22,7 @@
*/

typedef void (*bt_bluetooth_ready)(int err, const bdaddr_t *addr);
-bool bt_bluetooth_start(int index, bt_bluetooth_ready cb);
+bool bt_bluetooth_start(int index, bool vdebug, bt_bluetooth_ready cb);

typedef void (*bt_bluetooth_stopped)(void);
bool bt_bluetooth_stop(bt_bluetooth_stopped cb);
diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c
index 2c7d087..59a1e91 100644
--- a/android/bluetoothd-wrapper.c
+++ b/android/bluetoothd-wrapper.c
@@ -26,6 +26,8 @@

#define PROPERTY_DEBUG_NAME "persist.sys.bluetooth.debug"

+#define PROPERTY_VERBOSE_DEBUG_NAME "persist.sys.bluetooth.vdebug"
+
#define VALGRIND_BIN "/system/bin/valgrind"

#define BLUETOOTHD_BIN "/system/bin/bluetoothd-main"
@@ -47,14 +49,15 @@ static void run_valgrind(void)
execve(prg_argv[0], prg_argv, prg_envp);
}

-static void run_bluetoothd(int debug)
+static void run_bluetoothd(int debug, int vdebug)
{
- char *prg_argv[3];
+ char *prg_argv[4];
char *prg_envp[1];

prg_argv[0] = BLUETOOTHD_BIN;
prg_argv[1] = debug ? "-d" : NULL;
- prg_argv[2] = NULL;
+ prg_argv[2] = vdebug ? "-D" : NULL;
+ prg_argv[3] = NULL;

prg_envp[0] = NULL;

@@ -65,6 +68,7 @@ int main(int argc, char *argv[])
{
char value[PROPERTY_VALUE_MAX];
int debug = 0;
+ int vdebug = 0;

if (property_get(PROPERTY_NAME, value, "") > 0 &&
(!strcasecmp(value, "true") || atoi(value) > 0))
@@ -74,10 +78,16 @@ int main(int argc, char *argv[])
(!strcasecmp(value, "true") || atoi(value) > 0))
debug = 1;

+ if (property_get(PROPERTY_VERBOSE_DEBUG_NAME, value, "") > 0 &&
+ (!strcasecmp(value, "true") || atoi(value) > 0)) {
+ debug = 1;
+ vdebug = 1;
+ }
+
/* In case we failed to execute Valgrind, try to run bluetoothd
* without it
*/
- run_bluetoothd(debug);
+ run_bluetoothd(debug, vdebug);

return 0;
}
diff --git a/android/main.c b/android/main.c
index edec7dc..777a1ea 100644
--- a/android/main.c
+++ b/android/main.c
@@ -345,6 +345,7 @@ static guint setup_signalfd(void)
static gboolean option_version = FALSE;
static gint option_index = -1;
static gboolean option_dbg = FALSE;
+static gboolean option_vdbg = FALSE;

static GOptionEntry options[] = {
{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
@@ -353,6 +354,9 @@ static GOptionEntry options[] = {
"Use specified controller", "INDEX"},
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_dbg,
"Enable debug logs", NULL},
+ { "verbose debug", 'D', 0, G_OPTION_ARG_NONE, &option_vdbg,
+ "Enable verbose debug logs, e.g. mgmt", NULL},
+
{ NULL }
};

@@ -476,7 +480,7 @@ int main(int argc, char *argv[])
if (!signal)
return EXIT_FAILURE;

- if (option_dbg)
+ if (option_dbg || option_vdbg)
__btd_log_init("*", 0);
else
__btd_log_init(NULL, 0);
@@ -496,7 +500,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}

- if (!bt_bluetooth_start(option_index, adapter_ready)) {
+ if (!bt_bluetooth_start(option_index, option_vdbg, adapter_ready)) {
__btd_log_cleanup();
g_source_remove(bluetooth_start_timeout);
g_source_remove(signal);
--
1.8.4


2014-03-05 12:56:05

by Lukasz Rymanowski

[permalink] [raw]
Subject: [RFC 1/2] android: Add possible to enable BlueZ debug logs

With this patch it is possible to enable BlueZ logs which. In order
to enable it is required to set property:
persist.sys.bluetooth.debug to 1 or literaly "true".

More info in README
---
android/README | 11 +++++++++++
android/bluetoothd-wrapper.c | 17 ++++++++++++-----
android/main.c | 8 +++++++-
3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/android/README b/android/README
index 3095383..b7ecf5f 100644
--- a/android/README
+++ b/android/README
@@ -130,6 +130,17 @@ will break at e.g. g_free() function without prior callers. It's possible to
have proper library installed automatically by appropriate entry in Android.mk,
see https://code.google.com/p/aosp-bluez.glib/ for an example.

+Enabling BlueZ debugs
+==============================
+
+BlueZ debug logs can be enabled in runtime by setting "persist.sys.bluetooth.debug"
+property to either literal "true" or any numeric value >0. For example:
+adb root
+adb shell setprop persist.sys.bluetooth.debug 1
+
+After changing property value Bluetooth needs to be restarted to apply changes.
+
+Note: Debugs are only available on NON USER build variants
=============================
Building and running on Linux
=============================
diff --git a/android/bluetoothd-wrapper.c b/android/bluetoothd-wrapper.c
index 122e6b0..2c7d087 100644
--- a/android/bluetoothd-wrapper.c
+++ b/android/bluetoothd-wrapper.c
@@ -24,6 +24,8 @@

#define PROPERTY_NAME "persist.sys.bluetooth.valgrind"

+#define PROPERTY_DEBUG_NAME "persist.sys.bluetooth.debug"
+
#define VALGRIND_BIN "/system/bin/valgrind"

#define BLUETOOTHD_BIN "/system/bin/bluetoothd-main"
@@ -45,13 +47,14 @@ static void run_valgrind(void)
execve(prg_argv[0], prg_argv, prg_envp);
}

-static void run_bluetoothd(void)
+static void run_bluetoothd(int debug)
{
- char *prg_argv[2];
+ char *prg_argv[3];
char *prg_envp[1];

prg_argv[0] = BLUETOOTHD_BIN;
- prg_argv[1] = NULL;
+ prg_argv[1] = debug ? "-d" : NULL;
+ prg_argv[2] = NULL;

prg_envp[0] = NULL;

@@ -61,16 +64,20 @@ static void run_bluetoothd(void)
int main(int argc, char *argv[])
{
char value[PROPERTY_VALUE_MAX];
+ int debug = 0;

if (property_get(PROPERTY_NAME, value, "") > 0 &&
(!strcasecmp(value, "true") || atoi(value) > 0))
run_valgrind();

+ if (property_get(PROPERTY_DEBUG_NAME, value, "") > 0 &&
+ (!strcasecmp(value, "true") || atoi(value) > 0))
+ debug = 1;
+
/* In case we failed to execute Valgrind, try to run bluetoothd
* without it
*/
-
- run_bluetoothd();
+ run_bluetoothd(debug);

return 0;
}
diff --git a/android/main.c b/android/main.c
index 42bc982..edec7dc 100644
--- a/android/main.c
+++ b/android/main.c
@@ -344,12 +344,15 @@ static guint setup_signalfd(void)

static gboolean option_version = FALSE;
static gint option_index = -1;
+static gboolean option_dbg = FALSE;

static GOptionEntry options[] = {
{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
"Show version information and exit", NULL },
{ "index", 'i', 0, G_OPTION_ARG_INT, &option_index,
"Use specified controller", "INDEX"},
+ { "debug", 'd', 0, G_OPTION_ARG_NONE, &option_dbg,
+ "Enable debug logs", NULL},
{ NULL }
};

@@ -473,7 +476,10 @@ int main(int argc, char *argv[])
if (!signal)
return EXIT_FAILURE;

- __btd_log_init("*", 0);
+ if (option_dbg)
+ __btd_log_init("*", 0);
+ else
+ __btd_log_init(NULL, 0);

if (!set_capabilities()) {
__btd_log_cleanup();
--
1.8.4