linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miao-chen Chou <mcchou@chromium.org>
To: Bluetooth Kernel Mailing List <linux-bluetooth@vger.kernel.org>
Cc: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>,
	Marcel Holtmann <marcel@holtmann.org>,
	Alain Michaud <alainm@chromium.org>,
	Howard Chung <howardchung@google.com>,
	Miao-chen Chou <mcchou@chromium.org>
Subject: [BlueZ PATCH v3 2/4] error: BR/EDR and LE connection failure reasons
Date: Wed, 14 Jul 2021 18:09:52 -0700	[thread overview]
Message-ID: <20210714180917.BlueZ.v3.2.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid> (raw)
In-Reply-To: <20210715010951.963176-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

- Separate error-code.txt into its own commit

Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Howard Chung <howardchung@google.com>
---

(no changes since v2)

Changes in v2:
- Add error-code.txt
- Remove BtdError from return string

 src/error.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/error.h |  52 ++++++++++++++++++++++++
 2 files changed, 163 insertions(+)

diff --git a/src/error.c b/src/error.c
index 89517075e..eeac39456 100644
--- a/src/error.c
+++ b/src/error.c
@@ -27,6 +27,7 @@
 #include <config.h>
 #endif
 
+#include <stdio.h>
 #include "gdbus/gdbus.h"
 
 #include "error.h"
@@ -43,6 +44,12 @@ DBusMessage *btd_error_invalid_args_str(DBusMessage *msg, const char *str)
 					"%s", str);
 }
 
+DBusMessage *btd_error_invalid_args_err(DBusMessage *msg, uint16_t err)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".InvalidArguments",
+					"0x%04X", err);
+}
+
 DBusMessage *btd_error_busy(DBusMessage *msg)
 {
 	return g_dbus_create_error(msg, ERROR_INTERFACE ".InProgress",
@@ -79,12 +86,24 @@ DBusMessage *btd_error_in_progress(DBusMessage *msg)
 					"In Progress");
 }
 
+DBusMessage *btd_error_in_progress_err(DBusMessage *msg, uint16_t err)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".InProgress", "0x%04X",
+					err);
+}
+
 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_err(DBusMessage *msg, uint16_t err)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotAvailable",
+					"0x%04X", err);
+}
+
 DBusMessage *btd_error_does_not_exist(DBusMessage *msg)
 {
 	return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExist",
@@ -121,8 +140,100 @@ DBusMessage *btd_error_not_ready(DBusMessage *msg)
 					"Resource Not Ready");
 }
 
+DBusMessage *btd_error_not_ready_err(DBusMessage *msg, uint16_t err)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotReady", "0x%04X",
+					err);
+}
+
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str)
 {
 	return g_dbus_create_error(msg, ERROR_INTERFACE
 					".Failed", "%s", str);
 }
+
+DBusMessage *btd_error_failed_err(DBusMessage *msg, uint16_t err)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed", "0x%04X",
+					err);
+}
+
+uint16_t btd_error_bredr_conn_from_errno(int errno_code)
+{
+	switch (-errno_code) {
+	case EALREADY:
+	case EISCONN:
+		return BTD_ERR_BREDR_CONN_ALREADY_CONNECTED;
+	case EHOSTDOWN:
+		return BTD_ERR_BREDR_CONN_PAGE_TIMEOUT;
+	case ENOPROTOOPT:
+		return BTD_ERR_BREDR_CONN_PROFILE_UNAVAILABLE;
+	case EIO:
+		return BTD_ERR_BREDR_CONN_CREATE_SOCKET;
+	case EINVAL:
+		return BTD_ERR_BREDR_CONN_INVALID_ARGUMENTS;
+	case EHOSTUNREACH:
+		return BTD_ERR_BREDR_CONN_ADAPTER_NOT_POWERED;
+	case EOPNOTSUPP:
+	case EPROTONOSUPPORT:
+		return BTD_ERR_BREDR_CONN_NOT_SUPPORTED;
+	case EBADFD:
+		return BTD_ERR_BREDR_CONN_BAD_SOCKET;
+	case ENOMEM:
+		return BTD_ERR_BREDR_CONN_MEMORY_ALLOC;
+	case EBUSY:
+		return BTD_ERR_BREDR_CONN_BUSY;
+	case EMLINK:
+		return BTD_ERR_BREDR_CONN_CNCR_CONNECT_LIMIT;
+	case ETIMEDOUT:
+		return BTD_ERR_BREDR_CONN_TIMEOUT;
+	case ECONNREFUSED:
+		return BTD_ERR_BREDR_CONN_REFUSED;
+	case ECONNRESET:
+		return BTD_ERR_BREDR_CONN_ABORT_BY_REMOTE;
+	case ECONNABORTED:
+		return BTD_ERR_BREDR_CONN_ABORT_BY_LOCAL;
+	case EPROTO:
+		return BTD_ERR_BREDR_CONN_PROTO_ERROR;
+	default:
+		return BTD_ERR_BREDR_CONN_UNKNOWN;
+	}
+}
+
+uint16_t btd_error_le_conn_from_errno(int errno_code)
+{
+	switch (-errno_code) {
+	case EINVAL:
+		return BTD_ERR_LE_CONN_INVALID_ARGUMENTS;
+	case EHOSTUNREACH:
+		return BTD_ERR_LE_CONN_ADAPTER_NOT_POWERED;
+	case EOPNOTSUPP:
+	case EPROTONOSUPPORT:
+		return BTD_ERR_LE_CONN_NOT_SUPPORTED;
+	case EALREADY:
+	case EISCONN:
+		return BTD_ERR_LE_CONN_ALREADY_CONNECTED;
+	case EBADFD:
+		return BTD_ERR_LE_CONN_BAD_SOCKET;
+	case ENOMEM:
+		return BTD_ERR_LE_CONN_MEMORY_ALLOC;
+	case EBUSY:
+		return BTD_ERR_LE_CONN_BUSY;
+	case ECONNREFUSED:
+		return BTD_ERR_LE_CONN_REFUSED;
+	case EIO:
+		return BTD_ERR_LE_CONN_CREATE_SOCKET;
+	case ETIMEDOUT:
+		return BTD_ERR_LE_CONN_TIMEOUT;
+	case EMLINK:
+		return BTD_ERR_LE_CONN_SYNC_CONNECT_LIMIT;
+	case ECONNRESET:
+		return BTD_ERR_LE_CONN_ABORT_BY_REMOTE;
+	case ECONNABORTED:
+		return BTD_ERR_LE_CONN_ABORT_BY_LOCAL;
+	case EPROTO:
+		return BTD_ERR_LE_CONN_PROTO_ERROR;
+	default:
+		return BTD_ERR_LE_CONN_UNKNOWN;
+	}
+}
diff --git a/src/error.h b/src/error.h
index 7c8cad066..74d433aca 100644
--- a/src/error.h
+++ b/src/error.h
@@ -24,22 +24,74 @@
  */
 
 #include <dbus/dbus.h>
+#include <stdint.h>
 
 #define ERROR_INTERFACE "org.bluez.Error"
 
+/* BR/EDR connection failure reasons
+ * BT_ERR_* should be used as one of the parameters to btd_error_*_err().
+ */
+#define BTD_ERR_BREDR_CONN_ALREADY_CONNECTED	0x0001
+#define BTD_ERR_BREDR_CONN_PAGE_TIMEOUT		0x0002
+#define BTD_ERR_BREDR_CONN_PROFILE_UNAVAILABLE	0x0003
+#define BTD_ERR_BREDR_CONN_SDP_SEARCH		0x0004
+#define BTD_ERR_BREDR_CONN_CREATE_SOCKET	0x0005
+#define BTD_ERR_BREDR_CONN_INVALID_ARGUMENTS	0x0006
+#define BTD_ERR_BREDR_CONN_ADAPTER_NOT_POWERED	0x0007
+#define BTD_ERR_BREDR_CONN_NOT_SUPPORTED	0x0008
+#define BTD_ERR_BREDR_CONN_BAD_SOCKET		0x0009
+#define BTD_ERR_BREDR_CONN_MEMORY_ALLOC		0x000A
+#define BTD_ERR_BREDR_CONN_BUSY			0x000B
+#define BTD_ERR_BREDR_CONN_CNCR_CONNECT_LIMIT	0x000C
+#define BTD_ERR_BREDR_CONN_TIMEOUT		0x000D
+#define BTD_ERR_BREDR_CONN_REFUSED		0x000E
+#define BTD_ERR_BREDR_CONN_ABORT_BY_REMOTE	0x000F
+#define BTD_ERR_BREDR_CONN_ABORT_BY_LOCAL	0x0010
+#define BTD_ERR_BREDR_CONN_PROTO_ERROR		0x0011
+#define BTD_ERR_BREDR_CONN_CANCELED		0x0012
+#define BTD_ERR_BREDR_CONN_UNKNOWN		0x0013
+
+/* LE connection failure reasons
+ * BT_ERR_* should be used as one of the parameters to btd_error_*_err().
+ */
+#define BTD_ERR_LE_CONN_INVALID_ARGUMENTS	0x0101
+#define BTD_ERR_LE_CONN_ADAPTER_NOT_POWERED	0x0102
+#define BTD_ERR_LE_CONN_NOT_SUPPORTED		0x0103
+#define BTD_ERR_LE_CONN_ALREADY_CONNECTED	0x0104
+#define BTD_ERR_LE_CONN_BAD_SOCKET		0x0105
+#define BTD_ERR_LE_CONN_MEMORY_ALLOC		0x0106
+#define BTD_ERR_LE_CONN_BUSY			0x0107
+#define BTD_ERR_LE_CONN_REFUSED			0x0108
+#define BTD_ERR_LE_CONN_CREATE_SOCKET		0x0109
+#define BTD_ERR_LE_CONN_TIMEOUT			0x010A
+#define BTD_ERR_LE_CONN_SYNC_CONNECT_LIMIT	0x010B
+#define BTD_ERR_LE_CONN_ABORT_BY_REMOTE		0x010C
+#define BTD_ERR_LE_CONN_ABORT_BY_LOCAL		0x010D
+#define BTD_ERR_LE_CONN_PROTO_ERROR		0x010E
+#define BTD_ERR_LE_CONN_GATT_BROWSE		0x010F
+#define BTD_ERR_LE_CONN_UNKNOWN			0x0110
+
 DBusMessage *btd_error_invalid_args(DBusMessage *msg);
 DBusMessage *btd_error_invalid_args_str(DBusMessage *msg, const char *str);
+DBusMessage *btd_error_invalid_args_err(DBusMessage *msg, uint16_t err);
 DBusMessage *btd_error_busy(DBusMessage *msg);
 DBusMessage *btd_error_already_exists(DBusMessage *msg);
 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_err(DBusMessage *msg, uint16_t err);
 DBusMessage *btd_error_in_progress(DBusMessage *msg);
+DBusMessage *btd_error_in_progress_err(DBusMessage *msg, uint16_t err);
 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_err(DBusMessage *msg, uint16_t err);
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str);
+DBusMessage *btd_error_failed_err(DBusMessage *msg, uint16_t err);
+
+uint16_t btd_error_bredr_conn_from_errno(int errno_code);
+uint16_t btd_error_le_conn_from_errno(int errno_code);
-- 
2.32.0.93.g670b81a890-goog


  parent reply	other threads:[~2021-07-15  1:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  1:09 [BlueZ PATCH v3 0/4] Detailed error code Miao-chen Chou
2021-07-15  1:09 ` [BlueZ PATCH v3 1/4] doc: Add error-codes.txt to describe error codes of D-Bus method returns Miao-chen Chou
2021-07-15  1:24   ` Detailed error code bluez.test.bot
2021-07-15  1:09 ` Miao-chen Chou [this message]
2021-07-15  1:09 ` [BlueZ PATCH v3 3/4] device: Include BtdError code in Connect() return Miao-chen Chou
2021-07-15  1:09 ` [BlueZ PATCH v3 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=20210714180917.BlueZ.v3.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 \
    --subject='Re: [BlueZ PATCH v3 2/4] error: BR/EDR and LE connection failure reasons' \
    /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

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).