The D-Bus errors returned in a number of cases aren't in human-readable form, but instead exist as "codes" (listed in src/error.h). This new function will allow us to convert those to human-readable form. --- Makefile.tools | 2 ++ client/error.c | 36 ++++++++++++++++++++++++++++++++++++ client/error.h | 11 +++++++++++ 3 files changed, 49 insertions(+) create mode 100644 client/error.c create mode 100644 client/error.h diff --git a/Makefile.tools b/Makefile.tools index 0dca43327fdd..41b4b4f0545f 100644 --- a/Makefile.tools +++ b/Makefile.tools @@ -10,6 +10,8 @@ client_bluetoothctl_SOURCES = client/main.c \ client/advertising.c \ client/adv_monitor.h \ client/adv_monitor.c \ + client/error.h \ + client/error.c \ client/gatt.h client/gatt.c \ client/admin.h client/admin.c \ client/player.h client/player.c \ diff --git a/client/error.c b/client/error.c new file mode 100644 index 000000000000..975e4030dfc0 --- /dev/null +++ b/client/error.c @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2025 Bastien Nocera <hadess@xxxxxxxxxx> + * + * + */ + +#include <stddef.h> +#include <glib.h> +#include "error.h" + +struct { + const char *error_code; + const char *str; +} error_codes[] = { + { "br-connection-profile-unavailable", "Exhausted the list of BR/EDR profiles to connect to" }, + { "br-connection-busy", "Cannot connect, connection busy" }, + { "br-connection-adapter-not-powered", "Cannot connect, adapter is not powered" }, +}; + +const char *error_code_to_str(const char *error_code) +{ + unsigned int i; + + if (error_code == NULL) + return NULL; + + for (i = 0; i < G_N_ELEMENTS(error_codes); i++) { + if (g_str_equal(error_codes[i].error_code, error_code)) + return error_codes[i].str; + } + return error_code; +} diff --git a/client/error.h b/client/error.h new file mode 100644 index 000000000000..402117f3305b --- /dev/null +++ b/client/error.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2025 Bastien Nocera <hadess@xxxxxxxxxx> + * + * + */ + +const char *error_code_to_str(const char *error_code); -- 2.47.1