From patchwork Sat Jun 26 05:21:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao-chen Chou X-Patchwork-Id: 467853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5976EC49EA6 for ; Sat, 26 Jun 2021 05:22:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2C28C61939 for ; Sat, 26 Jun 2021 05:22:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229635AbhFZFYz (ORCPT ); Sat, 26 Jun 2021 01:24:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbhFZFYy (ORCPT ); Sat, 26 Jun 2021 01:24:54 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2D85C061574 for ; Fri, 25 Jun 2021 22:22:27 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id g21so7459673pfc.11 for ; Fri, 25 Jun 2021 22:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JALfJhM0xDO0CbsrahAY20YPj1yX4vBjDB/WwM2pRTI=; b=kUMG9xOLwMh/1BGJGxcPzQDqllHV3e+YvNwYRi7dnYWnPyczXd4hWF38CHPDcifxZt DvYE14cgNsMa2sD/Q6jdalIfo0hzhPUGxv1MD9iA4L57KJVEqMC+vZiqhmUNejktQsGV 6xz+GWgKv2f6RZXPTHbX33xa/xf3J9JUvjNO0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JALfJhM0xDO0CbsrahAY20YPj1yX4vBjDB/WwM2pRTI=; b=pvKlIiKCiscgfGH0gHHhUNuQ7JuPZPKr//RUtdS/k/ESvG+Vh/K2zcySnad01zZmDo FC+kzdhFsgi3mp6+1DOWyyKqR+ZV3q27S66hwXukKZInIh9MwrCKOxwLvei2DOhVh60I aqxeS0pnxlALnLFPw2ZlN1OsWrE9gKZYFlNMxd8MruUgz99UB8YfoZJZisc6Eo1NWbQ+ vJzzj8UUTGSOA85Vw+uNLRGYD9L08O36z/1oN4RAUHgfvxXYCgfLzAI6oeFkj3P2Xr45 x+l1IPSZhO8jRQK/YMgdeUtT/QV/cPHPUFnqn0dZ/+BKScdHVTDugu+PC0Jl3sNX/QwY 7KWQ== X-Gm-Message-State: AOAM531BT1TvjevRHwpwjc7b/umhP04lEC7vgNn/8G7dL4spya4Bo//P rooW2bqqJREjdUl3xbVnOpl67OGuzqbfZA== X-Google-Smtp-Source: ABdhPJzNkbkAUPl85bmbnjudV0KS5iVoR6PHl0jTq04r25KeaqzQPr2HsJWS+x0RPaBbNN96MlzYyA== X-Received: by 2002:a63:e114:: with SMTP id z20mr12684430pgh.207.1624684947127; Fri, 25 Jun 2021 22:22:27 -0700 (PDT) Received: from localhost ([2620:15c:202:201:be2:cfe5:893:108f]) by smtp.gmail.com with UTF8SMTPSA id u14sm7198956pfk.10.2021.06.25.22.22.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Jun 2021 22:22:26 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Luiz Augusto von Dentz , Alain Michaud , Marcel Holtmann , Howard Chung , Miao-chen Chou Subject: [BlueZ PATCH v2 1/3] error: BR/EDR and LE connection failure reasons Date: Fri, 25 Jun 2021 22:21:51 -0700 Message-Id: <20210625222111.BlueZ.v2.1.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210626052152.2543526-1-mcchou@chromium.org> References: <20210626052152.2543526-1-mcchou@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.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 This also added error-code.txt to describe these error codes. Reviewed-by: Alain Michaud Reviewed-by: Howard Chung --- Changes in v2: - Add error-code.txt - Remove BtdError from return string doc/error-code.txt | 266 +++++++++++++++++++++++++++++++++++++++++++++ src/error.c | 111 +++++++++++++++++++ src/error.h | 52 +++++++++ 3 files changed, 429 insertions(+) create mode 100644 doc/error-code.txt diff --git a/doc/error-code.txt b/doc/error-code.txt new file mode 100644 index 000000000..e91324855 --- /dev/null +++ b/doc/error-code.txt @@ -0,0 +1,266 @@ +D-Bus Method Return Error Codes +=============================== + +The motivation of having detailed error codes is to provide context-based +failure reasons along with D-Bus method return so that D-Bus clients can +build metrics and optimize their application based on these failure reasons. +For instance, a client can build retry mechanism for a connection failure or +improve the bottleneck of use scenario based on actionable metrics. + +These error codes are context-based but not necessarily tied to interface or +method calls. For instance, if a pairing request failed due to connection +failure, connection error would be attached to the method return of Pair(). + +BR/EDR connection already connected +=================================== + code: 0x0001 + errno: EALREADY, EISCONN + +Either the profile is already connected or ACL connection is in place. + +BR/EDR connection page timeout +============================== + code: 0x0002 + errno: EHOSTDOWN + +Failed due to page timeout. + +BR/EDR connection profile unavailable +===================================== + code: 0x0003 + errno: ENOPROTOOPT + +Failed to find connectable services or the target service. + +BR/EDR connection SDP search +============================ + code: 0x0004 + errno: none + +Failed to complete the SDP search. + +BR/EDR connection create socket +=============================== + code: 0x0005 + errno: EIO + +Failed to create or connect to BT IO socket. This can also indicate hardware +failure in the controller. + +BR/EDR connection invalid arguments +=================================== + code: 0x0006 + errno: EHOSTUNREACH + +Failed due to invalid arguments. + +BR/EDR connection not powered +============================= + code: 0x0007 + errno: EHOSTUNREACH + +Failed due to adapter not powered. + +BR/EDR connection not supported +=============================== + code: 0x0008 + errno: EOPNOTSUPP, EPROTONOSUPPORT + +Failed due to unsupported state transition of L2CAP channel or other features +either by the local host or the remote. + +BR/EDR connection bad socket +============================ + code: 0x0009 + errno: EBADFD + +Failed due to the socket is in bad state. + +BR/EDR connection memory allocation +=================================== + code: 0x000A + errno: EBADFD + +Failed to allocate memory in either host stack or controller. + +BR/EDR connection busy +====================== + code: 0x000B + errno: EBUSY + +Failed due to other ongoing operations, such as pairing, busy L2CAP channel or +the operation disallowed by the controller. + +BR/EDR connection concurrent connection limit +============================================= + code: 0x000C + errno: EMLINK + +Failed due to reaching the concurrent connection limit to a device. + +BR/EDR connection timeout +========================= + code: 0x000D + errno: ETIMEDOUT + +Failed due to connection timeout + +BR/EDR connection refused +========================= + code: 0x000E + errno: ECONNREFUSED + +Refused by the remote device due to limited resource, security reason or +unacceptable address type. + +BR/EDR connection aborted by remote +=================================== + code: 0x000F + errno: ECONNRESET + +Terminated by the remote device due to limited resource or power off. + +BR/EDR connection aborted by local +================================== + code: 0x0010 + errno: ECONNABORTED + +Aborted by the local host. + +BR/EDR connection protocol error +================================ + code: 0x0011 + errno: EPROTO + +Failed due to LMP protocol error. + +BR/EDR connection canceled +========================== + code: 0x0012 + errno: none + +Failed due to cancellation caused by adapter drop, unexpected device drop, or +incoming disconnection request before connection request is completed. + +BR/EDR connection unknown error +=============================== + code: 0x0013 + errno: ENOSYS + +Failed due to unknown reason. + +LE connection invalid arguments +=============================== + code: 0x0101 + errno: EINVAL + +Failed due to invalid arguments. + +LE connection not powered +========================= + code: 0x0102 + errno: EHOSTUNREACH + +Failed due to adapter not powered. + +LE connection not supported +=========================== + code: 0x0103 + errno: EOPNOTSUPP, EPROTONOSUPPORT + +Failed due to unsupported state transition of L2CAP channel or other features +(e.g. LE features) either by the local host or the remote. + +LE connection already connected +=============================== + code: 0x0104 + errno: EALREADY, EISCONN + +Either the BT IO is already connected or LE link connection in place. + +LE connection bad socket +======================== + code: 0x0105 + errno: EBADFD + +Failed due to the socket is in bad state. + +LE connection memory allocation +=============================== + code: 0x0106 + errno: ENOMEM + +Failed to allocate memory in either host stack or controller. + +LE connection busy +================== + code: 0x0107 + errno: EBUSY + +Failed due to other ongoing operations, such as pairing, connecting, busy +L2CAP channel or the operation disallowed by the controller. + +LE connection refused +===================== + code: 0x0108 + errno: ECONNREFUSED + +Failed due to that LE is not enabled or the attempt is refused by the remote +device due to limited resource, security reason or unacceptable address type. + +LE connection create socket +=========================== + code: 0x0109 + errno: EIO + +Failed to create or connect to BT IO socket. This can also indicate hardware +failure in the controller. + +LE connection timeout +===================== + code: 0x010A + errno: ETIMEDOUT + +Failed due to connection timeout + +LE connection concurrent connection limit +========================================= + code: 0x010B + errno: EMLINK + +Failed due to reaching the synchronous connection limit to a device. + +LE connection abort by remote +============================= + code: 0x010C + errno: ECONNRESET + +Aborted by the remote device due to limited resource or power off. + +LE connection abort by local +============================ + code: 0x010D + errno: ECONNABORTED + +Aborted by the local host. + +LE connection link layer protocol error +======================================= + code: 0x010E + errno: EPROTO + +Failed due to link layer protocol error. + +LE connection GATT browsing +=========================== + code: 0x010F + errno: none + +Failed to complete the GATT browsing. + +LE connection unknown error +=========================== + code: 0x0110 + errno: ENOSYS + + Failed due to unknown reason. diff --git a/src/error.c b/src/error.c index 89517075e..73602c4bf 100644 --- a/src/error.c +++ b/src/error.c @@ -27,6 +27,7 @@ #include #endif +#include #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: // Fall through + 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: // Fall through + 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: // Fall through + return BTD_ERR_LE_CONN_NOT_SUPPORTED; + case EALREADY: + case EISCONN: // Fall through + 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 +#include #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); From patchwork Sat Jun 26 05:21:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao-chen Chou X-Patchwork-Id: 467509 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23D93C49EA5 for ; Sat, 26 Jun 2021 05:22:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 097FC6186A for ; Sat, 26 Jun 2021 05:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229873AbhFZFZH (ORCPT ); Sat, 26 Jun 2021 01:25:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbhFZFZF (ORCPT ); Sat, 26 Jun 2021 01:25:05 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BF0EC061574 for ; Fri, 25 Jun 2021 22:22:43 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id u14so3549349pga.11 for ; Fri, 25 Jun 2021 22:22:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yEDW9GgxcjnKM5DbyQ4gCDEWGpAfaZad24mH40e9GQ8=; b=KwOliyLK8Ci+rOawaF+eYzZ18cmD1P6/m0KC86Qo5n7BXi95ZhtLJZr1yQhUkITGq/ JsTVU3SNz7P0vjN0ZiX8dBZGCBiK3P7vl9FLTcJ64SIlToJ8nOnrX1GhPMdOWodNzaO5 +VSc5MtXpTdEGEz5wHuvCBYuYGt1M3PInOkts= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yEDW9GgxcjnKM5DbyQ4gCDEWGpAfaZad24mH40e9GQ8=; b=bJqiP185OV0ZhJ1umAcW4mc48Jp66I+diIxd/Mtz943fPLvRKjwFkxUfGFtu9H10E3 Nb3ElI4iOZN6LGD4XEG5Sci4acoc8MJ82W/mkcdPucnwfX/xv87GZwWrd8nZeE59LHlu gIQCkpDV5YsT5sYIDONnfuiLDa7Og0oB4IyZdo1LHZ6JdDkRqX3qOf4R78cqDh4V+UKH F11JWa9ZYIuVpWoNnwVIF8rxjuva2zoFSqnjsPUQcpDiTDYInB+Q80y27YiBT0fFGXAY vo0ABcCe8MCZMjnY/Beh8oYmGDA6ynTVLI6cRW4WOoRjiD8whQI2I7r/MsEmA1EwsctE 4ltg== X-Gm-Message-State: AOAM533mySr7hLEb7xllrm7VN/3ejpTYeCxcw06EziJlPjoVcBIGVcUN Q+MpgGc3Hk+3S0+UPODm+eKwZ4ZNgsRmSA== X-Google-Smtp-Source: ABdhPJxHkkCJjwMRHAylry482rB7QzMwtykuOoQ03krrXDn5TqVM2vQxadYuHpLgl3zcNx42V/A3aw== X-Received: by 2002:aa7:9695:0:b029:304:95f8:8f6b with SMTP id f21-20020aa796950000b029030495f88f6bmr14258637pfk.28.1624684962605; Fri, 25 Jun 2021 22:22:42 -0700 (PDT) Received: from localhost ([2620:15c:202:201:be2:cfe5:893:108f]) by smtp.gmail.com with UTF8SMTPSA id m13sm1517539pfc.119.2021.06.25.22.22.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Jun 2021 22:22:42 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Luiz Augusto von Dentz , Alain Michaud , Marcel Holtmann , Howard Chung , Miao-chen Chou Subject: [BlueZ PATCH v2 2/3] device: Include BtdError code in Connect() return Date: Fri, 25 Jun 2021 22:21:53 -0700 Message-Id: <20210625222111.BlueZ.v2.2.Idd761b9b9f4620480db8889e7885a17952c2c13a@changeid> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210626052152.2543526-1-mcchou@chromium.org> References: <20210626052152.2543526-1-mcchou@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This replaces generic strerror message with context specific BtdError code to better indicate the detailed failure reason so that the D-Bus clients can optimize their application to work better with BlueZ, e.g. introducing retry mechanism or building metrics. Reviewed-by: Alain Michaud Reviewed-by: Howard Chung --- (no changes since v1) src/device.c | 52 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/device.c b/src/device.c index df440ce09..c9dc616a2 100644 --- a/src/device.c +++ b/src/device.c @@ -1607,8 +1607,8 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg) } if (device->connect) { - DBusMessage *reply = btd_error_failed(device->connect, - "Cancelled"); + DBusMessage *reply = btd_error_failed_err(device->connect, + BTD_ERR_BREDR_CONN_CANCELED); g_dbus_send_message(dbus_conn, reply); dbus_message_unref(device->connect); device->connect = NULL; @@ -1802,7 +1802,8 @@ done: } g_dbus_send_message(dbus_conn, - btd_error_failed(dev->connect, strerror(-err))); + btd_error_failed_err(dev->connect, + btd_error_bredr_conn_from_errno(err))); } else { /* Start passive SDP discovery to update known services */ if (dev->bredr && !dev->svc_refreshed && dev->refresh_discovery) @@ -2003,10 +2004,12 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type dbus_message_get_sender(msg)); if (dev->pending || dev->connect || dev->browse) - return btd_error_in_progress(msg); + return btd_error_in_progress_err(msg, BTD_ERR_BREDR_CONN_BUSY); - if (!btd_adapter_get_powered(dev->adapter)) - return btd_error_not_ready(msg); + if (!btd_adapter_get_powered(dev->adapter)) { + return btd_error_not_ready_err(msg, + BTD_ERR_BREDR_CONN_ADAPTER_NOT_POWERED); + } btd_device_set_temporary(dev, false); @@ -2019,10 +2022,12 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type if (dbus_message_is_method_call(msg, DEVICE_INTERFACE, "Connect") && find_service_with_state(dev->services, - BTD_SERVICE_STATE_CONNECTED)) + BTD_SERVICE_STATE_CONNECTED)) { return dbus_message_new_method_return(msg); - else - return btd_error_not_available(msg); + } else { + return btd_error_not_available_err(msg, + BTD_ERR_BREDR_CONN_PROFILE_UNAVAILABLE); + } } goto resolve_services; @@ -2032,7 +2037,8 @@ static DBusMessage *connect_profiles(struct btd_device *dev, uint8_t bdaddr_type if (err < 0) { if (err == -EALREADY) return dbus_message_new_method_return(msg); - return btd_error_failed(msg, strerror(-err)); + return btd_error_failed_err(msg, + btd_error_bredr_conn_from_errno(err)); } dev->connect = dbus_message_ref(msg); @@ -2046,8 +2052,11 @@ resolve_services: err = device_browse_sdp(dev, msg); else err = device_browse_gatt(dev, msg); - if (err < 0) - return btd_error_failed(msg, strerror(-err)); + if (err < 0) { + return btd_error_failed_err(msg, bdaddr_type == BDADDR_BREDR ? + BTD_ERR_BREDR_CONN_SDP_SEARCH : + BTD_ERR_LE_CONN_GATT_BROWSE); + } return NULL; } @@ -2157,8 +2166,10 @@ static DBusMessage *connect_profile(DBusConnection *conn, DBusMessage *msg, DBusMessage *reply; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, - DBUS_TYPE_INVALID)) - return btd_error_invalid_args(msg); + DBUS_TYPE_INVALID)) { + return btd_error_invalid_args_err(msg, + BTD_ERR_BREDR_CONN_INVALID_ARGUMENTS); + } uuid = bt_name2string(pattern); reply = connect_profiles(dev, BDADDR_BREDR, msg, uuid); @@ -2541,7 +2552,11 @@ static void browse_request_complete(struct browse_req *req, uint8_t type, if (err == 0) goto done; } - reply = btd_error_failed(req->msg, strerror(-err)); + reply = (bdaddr_type == BDADDR_BREDR ? + btd_error_failed_err(req->msg, + btd_error_bredr_conn_from_errno(err)) : + btd_error_failed_err(req->msg, + btd_error_le_conn_from_errno(err))); goto done; } @@ -3027,7 +3042,8 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) */ if (device->connect) { DBG("connection removed while Connect() is waiting reply"); - reply = btd_error_failed(device->connect, "Disconnected early"); + reply = btd_error_failed_err(device->connect, + BTD_ERR_BREDR_CONN_CANCELED); g_dbus_send_message(dbus_conn, reply); dbus_message_unref(device->connect); device->connect = NULL; @@ -5413,8 +5429,8 @@ done: if (device->connect) { if (err < 0) - reply = btd_error_failed(device->connect, - strerror(-err)); + reply = btd_error_failed_err(device->connect, + btd_error_le_conn_from_errno(err)); else reply = dbus_message_new_method_return(device->connect); From patchwork Sat Jun 26 05:21:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao-chen Chou X-Patchwork-Id: 467852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30606C49EA6 for ; Sat, 26 Jun 2021 05:23:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0722C61931 for ; Sat, 26 Jun 2021 05:23:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229906AbhFZFZY (ORCPT ); Sat, 26 Jun 2021 01:25:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbhFZFZX (ORCPT ); Sat, 26 Jun 2021 01:25:23 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC842C061574 for ; Fri, 25 Jun 2021 22:23:00 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id 21so9176123pfp.3 for ; Fri, 25 Jun 2021 22:23:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bHXu6QpYhAF1bUg3eeLJ+I+qTJOic4krZqFaMCKTV0g=; b=b8eKxOAmGy4gBlERq8xINuj3/rC/lHju2Dqro4t69QW06NYdyxrw45n/nFpWmctu4W 3nlELuiDesQkdXzyakXZ7sJzFM/SwtyRQCCeOQBfkkMTvln+FL5q0hAYtYujSJUAue+G rL4yoG6XDqFS/EiZ40xvTVNMkJ5fZUkwfLMFs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bHXu6QpYhAF1bUg3eeLJ+I+qTJOic4krZqFaMCKTV0g=; b=QaZhDGg3yJoz+nvQKFGLGyJZ4Z+abk0twW1UvL+HOHeexuDlZ2fPNe6J3aM38Eo/HA OTbM/OL3fd8PYTLvl+OSuGM0SfO+bwmbch6p1+KTE8wtYPEtneC5yJRCe62YWwE70yUE 26jQ6sj15y6RS2LuM0CqRik0yLXucYkkdpuRVX6hllVvdnnWWQkYnew5DBV64lZmPcW6 mSuuKKdR5jJ39qAiJrYuB7Ctk6ZDZsQnXg/tHoi0ghAAHrdCrjujAsFp+sQTEyGxCumx ufJmT5FU2KaVHLKfGG09kPcxTkE0p0yKSc7nRNuNefYtGE+dM6QNjyjKbAd0LE25/yH1 KqXw== X-Gm-Message-State: AOAM532C9EPTsDQRCMT6XvfLHJn/BW5e/XAdNpRZ0I6GDVM3Bpd4n1wE VBasaBZqQHrQpNm5jFwyElvwDmACPTU85w== X-Google-Smtp-Source: ABdhPJzg1upuSg8Cdyy8xneATFD/1pR+nIPdOFk93/9wFgqQVbRjXV8s6FuQa65CFmN3Luo8xKU/lw== X-Received: by 2002:a65:42c3:: with SMTP id l3mr12607058pgp.259.1624684980129; Fri, 25 Jun 2021 22:23:00 -0700 (PDT) Received: from localhost ([2620:15c:202:201:be2:cfe5:893:108f]) by smtp.gmail.com with UTF8SMTPSA id k25sm7297188pfa.213.2021.06.25.22.22.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Jun 2021 22:22:59 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Luiz Augusto von Dentz , Alain Michaud , Marcel Holtmann , Howard Chung , Miao-chen Chou Subject: [BlueZ PATCH v2 3/3] client: Print error code for connect methods Date: Fri, 25 Jun 2021 22:21:55 -0700 Message-Id: <20210625222111.BlueZ.v2.3.I226fdcdd12b13e4875c8cd03b42fc52283920cc4@changeid> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog In-Reply-To: <20210626052152.2543526-1-mcchou@chromium.org> References: <20210626052152.2543526-1-mcchou@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org The following steps were performed. - Issuing repeated commands to connect the same BLE device. - Verifying the print in bluetoothctl console Reviewed-by: Alain Michaud Reviewed-by: Howard Chung --- Changes in v2: - Add documentation for error codes client/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/main.c b/client/main.c index da877b546..488a24bf6 100644 --- a/client/main.c +++ b/client/main.c @@ -1949,7 +1949,8 @@ static void connect_reply(DBusMessage *message, void *user_data) dbus_error_init(&error); if (dbus_set_error_from_message(&error, message) == TRUE) { - bt_shell_printf("Failed to connect: %s\n", error.name); + bt_shell_printf("Failed to connect: %s %s\n", error.name, + error.message); dbus_error_free(&error); return bt_shell_noninteractive_quit(EXIT_FAILURE); }