From: Miao-chen Chou <mcchou@chromium.org>
To: Bluetooth Kernel Mailing List <linux-bluetooth@vger.kernel.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
Howard Chung <howardchung@google.com>,
Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,
Alain Michaud <alainm@chromium.org>,
Miao-chen Chou <mcchou@chromium.org>
Subject: [BlueZ PATCH v5 2/4] error: BR/EDR and LE connection failure reasons
Date: Fri, 6 Aug 2021 16:47:22 -0700 [thread overview]
Message-ID: <20210806164624.BlueZ.v5.2.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid> (raw)
In-Reply-To: <20210806234720.286157-1-mcchou@chromium.org>
The source of Connect() failures can be divided into the following
three.
- bluetoothd's device interface state transition and profile state
transition
- Kernel's L2CAP layer state transition
- Potential HCI error codes returned by the remote device
Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Howard Chung <howardchung@google.com>
---
Changes in v5:
- Replace uint16_t error code with string
Changes in v4:
- Address make errors
Changes in v3:
- Separate error-code.txt into its own commit
Changes in v2:
- Add error-code.txt
- Remove BtdError from return string
src/error.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/error.h | 59 +++++++++++++++++++++++++++++++
2 files changed, 159 insertions(+)
diff --git a/src/error.c b/src/error.c
index 89517075e..411f36fcb 100644
--- a/src/error.c
+++ b/src/error.c
@@ -27,6 +27,8 @@
#include <config.h>
#endif
+#include <error.h>
+#include <stdio.h>
#include "gdbus/gdbus.h"
#include "error.h"
@@ -79,12 +81,24 @@ DBusMessage *btd_error_in_progress(DBusMessage *msg)
"In Progress");
}
+DBusMessage *btd_error_in_progress_str(DBusMessage *msg, const char *str)
+{
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".InProgress",
+ "%s", str);
+}
+
DBusMessage *btd_error_not_available(DBusMessage *msg)
{
return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable",
"Operation currently not available");
}
+DBusMessage *btd_error_not_available_str(DBusMessage *msg, const char *str)
+{
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable",
+ "%s", str);
+}
+
DBusMessage *btd_error_does_not_exist(DBusMessage *msg)
{
return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExist",
@@ -121,8 +135,94 @@ DBusMessage *btd_error_not_ready(DBusMessage *msg)
"Resource Not Ready");
}
+DBusMessage *btd_error_not_ready_str(DBusMessage *msg, const char *str)
+{
+ return g_dbus_create_error(msg, ERROR_INTERFACE ".NotReady",
+ "%s", str);
+}
+
DBusMessage *btd_error_failed(DBusMessage *msg, const char *str)
{
return g_dbus_create_error(msg, ERROR_INTERFACE
".Failed", "%s", str);
}
+
+const char* btd_error_bredr_conn_from_errno(int errno_code)
+{
+ switch (-errno_code) {
+ case EALREADY:
+ case EISCONN:
+ return ERR_BREDR_CONN_ALREADY_CONNECTED;
+ case EHOSTDOWN:
+ return ERR_BREDR_CONN_PAGE_TIMEOUT;
+ case ENOPROTOOPT:
+ return ERR_BREDR_CONN_PROFILE_UNAVAILABLE;
+ case EIO:
+ return ERR_BREDR_CONN_CREATE_SOCKET;
+ case EINVAL:
+ return ERR_BREDR_CONN_INVALID_ARGUMENTS;
+ case EHOSTUNREACH:
+ return ERR_BREDR_CONN_ADAPTER_NOT_POWERED;
+ case EOPNOTSUPP:
+ case EPROTONOSUPPORT:
+ return ERR_BREDR_CONN_NOT_SUPPORTED;
+ case EBADFD:
+ return ERR_BREDR_CONN_BAD_SOCKET;
+ case ENOMEM:
+ return ERR_BREDR_CONN_MEMORY_ALLOC;
+ case EBUSY:
+ return ERR_BREDR_CONN_BUSY;
+ case EMLINK:
+ return ERR_BREDR_CONN_CNCR_CONNECT_LIMIT;
+ case ETIMEDOUT:
+ return ERR_BREDR_CONN_TIMEOUT;
+ case ECONNREFUSED:
+ return ERR_BREDR_CONN_REFUSED;
+ case ECONNRESET:
+ return ERR_BREDR_CONN_ABORT_BY_REMOTE;
+ case ECONNABORTED:
+ return ERR_BREDR_CONN_ABORT_BY_LOCAL;
+ case EPROTO:
+ return ERR_BREDR_CONN_LMP_PROTO_ERROR;
+ default:
+ return ERR_BREDR_CONN_UNKNOWN;
+ }
+}
+
+const char* btd_error_le_conn_from_errno(int errno_code)
+{
+ switch (-errno_code) {
+ case EINVAL:
+ return ERR_LE_CONN_INVALID_ARGUMENTS;
+ case EHOSTUNREACH:
+ return ERR_LE_CONN_ADAPTER_NOT_POWERED;
+ case EOPNOTSUPP:
+ case EPROTONOSUPPORT:
+ return ERR_LE_CONN_NOT_SUPPORTED;
+ case EALREADY:
+ case EISCONN:
+ return ERR_LE_CONN_ALREADY_CONNECTED;
+ case EBADFD:
+ return ERR_LE_CONN_BAD_SOCKET;
+ case ENOMEM:
+ return ERR_LE_CONN_MEMORY_ALLOC;
+ case EBUSY:
+ return ERR_LE_CONN_BUSY;
+ case ECONNREFUSED:
+ return ERR_LE_CONN_REFUSED;
+ case EIO:
+ return ERR_LE_CONN_CREATE_SOCKET;
+ case ETIMEDOUT:
+ return ERR_LE_CONN_TIMEOUT;
+ case EMLINK:
+ return ERR_LE_CONN_SYNC_CONNECT_LIMIT;
+ case ECONNRESET:
+ return ERR_LE_CONN_ABORT_BY_REMOTE;
+ case ECONNABORTED:
+ return ERR_LE_CONN_ABORT_BY_LOCAL;
+ case EPROTO:
+ return ERR_LE_CONN_LL_PROTO_ERROR;
+ default:
+ return ERR_LE_CONN_UNKNOWN;
+ }
+}
diff --git a/src/error.h b/src/error.h
index 7c8cad066..91a02654a 100644
--- a/src/error.h
+++ b/src/error.h
@@ -24,9 +24,62 @@
*/
#include <dbus/dbus.h>
+#include <stdint.h>
#define ERROR_INTERFACE "org.bluez.Error"
+/* BR/EDR connection failure reasons */
+#define ERR_BREDR_CONN_ALREADY_CONNECTED "BR/EDR connection already "\
+ "connected"
+#define ERR_BREDR_CONN_PAGE_TIMEOUT "BR/EDR connection page timeout"
+#define ERR_BREDR_CONN_PROFILE_UNAVAILABLE "BR/EDR connection profile "\
+ "unavailable"
+#define ERR_BREDR_CONN_SDP_SEARCH "BR/EDR connection SDP search"
+#define ERR_BREDR_CONN_CREATE_SOCKET "BR/EDR connection create "\
+ "socket"
+#define ERR_BREDR_CONN_INVALID_ARGUMENTS "BR/EDR connection invalid "\
+ "argument"
+#define ERR_BREDR_CONN_ADAPTER_NOT_POWERED "BR/EDR connection adapter "\
+ "not powered"
+#define ERR_BREDR_CONN_NOT_SUPPORTED "BR/EDR connection not "\
+ "suuported"
+#define ERR_BREDR_CONN_BAD_SOCKET "BR/EDR connection bad socket"
+#define ERR_BREDR_CONN_MEMORY_ALLOC "BR/EDR connection memory "\
+ "allocation"
+#define ERR_BREDR_CONN_BUSY "BR/EDR connection busy"
+#define ERR_BREDR_CONN_CNCR_CONNECT_LIMIT "BR/EDR connection concurrent "\
+ "connection limit"
+#define ERR_BREDR_CONN_TIMEOUT "BR/EDR connection timeout"
+#define ERR_BREDR_CONN_REFUSED "BR/EDR connection refused"
+#define ERR_BREDR_CONN_ABORT_BY_REMOTE "BR/EDR connection aborted by "\
+ "remote"
+#define ERR_BREDR_CONN_ABORT_BY_LOCAL "BR/EDR connection aborted by "\
+ "local"
+#define ERR_BREDR_CONN_LMP_PROTO_ERROR "BR/EDR connection LMP "\
+ "protocol error"
+#define ERR_BREDR_CONN_CANCELED "BR/EDR connection canceled"
+#define ERR_BREDR_CONN_UNKNOWN "BR/EDR connection unknown"
+
+/* LE connection failure reasons */
+#define ERR_LE_CONN_INVALID_ARGUMENTS "LE connection invalid arguments"
+#define ERR_LE_CONN_ADAPTER_NOT_POWERED "LE connection adapter not powered"
+#define ERR_LE_CONN_NOT_SUPPORTED "LE connection not supported"
+#define ERR_LE_CONN_ALREADY_CONNECTED "LE connection already connected"
+#define ERR_LE_CONN_BAD_SOCKET "LE connection bad socket"
+#define ERR_LE_CONN_MEMORY_ALLOC "LE connection memory allocation"
+#define ERR_LE_CONN_BUSY "LE connection busy"
+#define ERR_LE_CONN_REFUSED "LE connection refused"
+#define ERR_LE_CONN_CREATE_SOCKET "LE connection create socket"
+#define ERR_LE_CONN_TIMEOUT "LE connection timeout"
+#define ERR_LE_CONN_SYNC_CONNECT_LIMIT "LE connection concurrent connection "\
+ "limit"
+#define ERR_LE_CONN_ABORT_BY_REMOTE "LE connection abort by remote"
+#define ERR_LE_CONN_ABORT_BY_LOCAL "LE connection abort by local"
+#define ERR_LE_CONN_LL_PROTO_ERROR "LE connection link layer protocol "\
+ "error"
+#define ERR_LE_CONN_GATT_BROWSE "LE connection GATT browsing"
+#define ERR_LE_CONN_UNKNOWN "LE connection unknown"
+
DBusMessage *btd_error_invalid_args(DBusMessage *msg);
DBusMessage *btd_error_invalid_args_str(DBusMessage *msg, const char *str);
DBusMessage *btd_error_busy(DBusMessage *msg);
@@ -35,11 +88,17 @@ DBusMessage *btd_error_not_supported(DBusMessage *msg);
DBusMessage *btd_error_not_connected(DBusMessage *msg);
DBusMessage *btd_error_already_connected(DBusMessage *msg);
DBusMessage *btd_error_not_available(DBusMessage *msg);
+DBusMessage *btd_error_not_available_str(DBusMessage *msg, const char *str);
DBusMessage *btd_error_in_progress(DBusMessage *msg);
+DBusMessage *btd_error_in_progress_str(DBusMessage *msg, const char *str);
DBusMessage *btd_error_does_not_exist(DBusMessage *msg);
DBusMessage *btd_error_not_authorized(DBusMessage *msg);
DBusMessage *btd_error_not_permitted(DBusMessage *msg, const char *str);
DBusMessage *btd_error_no_such_adapter(DBusMessage *msg);
DBusMessage *btd_error_agent_not_available(DBusMessage *msg);
DBusMessage *btd_error_not_ready(DBusMessage *msg);
+DBusMessage *btd_error_not_ready_str(DBusMessage *msg, const char *str);
DBusMessage *btd_error_failed(DBusMessage *msg, const char *str);
+
+const char* btd_error_bredr_conn_from_errno(int errno_code);
+const char* btd_error_le_conn_from_errno(int errno_code);
--
2.32.0.605.g8dce9f2422-goog
next prev parent reply other threads:[~2021-08-06 23:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-06 23:47 [BlueZ PATCH v5 0/4] Detailed error string Miao-chen Chou
2021-08-06 23:47 ` [BlueZ PATCH v5 1/4] doc: Add errors.txt to describe errors of D-Bus method returns Miao-chen Chou
2021-08-07 1:17 ` Detailed error string bluez.test.bot
2021-08-06 23:47 ` Miao-chen Chou [this message]
2021-08-09 13:32 ` [BlueZ PATCH v5 2/4] error: BR/EDR and LE connection failure reasons Marcel Holtmann
2021-08-06 23:47 ` [BlueZ PATCH v5 3/4] device: Include detailed error string in Connect() return Miao-chen Chou
2021-08-06 23:47 ` [BlueZ PATCH v5 4/4] client: Print error code for connect methods Miao-chen Chou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210806164624.BlueZ.v5.2.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid \
--to=mcchou@chromium.org \
--cc=alainm@chromium.org \
--cc=howardchung@google.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.von.dentz@intel.com \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).