From patchwork Tue Sep 21 16:47:05 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: 12508343 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=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 C6B6EC433F5 for ; Tue, 21 Sep 2021 16:48:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E31861168 for ; Tue, 21 Sep 2021 16:48:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229605AbhIUQuN (ORCPT ); Tue, 21 Sep 2021 12:50:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbhIUQuL (ORCPT ); Tue, 21 Sep 2021 12:50:11 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F931C061574 for ; Tue, 21 Sep 2021 09:48:43 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id k23so60918pji.0 for ; Tue, 21 Sep 2021 09:48: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=CnnAbp8Nzz5Zz5gwdrICLzrxPOeX7imY24A4AfqiiWE=; b=JLcK6roqWRzk3yiEz4WMbM/Knif0RqyXZ6ugp4stNgJIAS7ridJ1rLvJXJotK06uku Vu+ZImMNEPGtFKpF9gOTa8v3RMEG1yYBnkKvJRamNiWsNxSJ+Wvhfm7/K7VBmP0cnmQ1 IiRGly6afgBSDxayuRgjbu/9ZOqAovoG1ojRU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CnnAbp8Nzz5Zz5gwdrICLzrxPOeX7imY24A4AfqiiWE=; b=reNznH14ZX/rx/EaskhSqNbpdpHm4G/l9T3OtrZsm1iAjnxP0SJ85QzqGY+zN828eN pzATQADta28CljwAgFoPQelGGtem+Dr9AidbJ0Bv8c4XACGds6flCUAAxexE5nUm4P+H 9U+uUQozRtHkvtT5WG15Im53+SMj2yzVgRxAwEhrlELt9jGOxS2mdG33Xc2PeohpFTv+ ezpBGHcKKMI0RL3NwtGSGbp3VAN+Ih04owdrO30CcQimW7YRoFRaCrx7Kt/PhwtGsSHf cUnhZ8baiu8etfUgHi5KhAgxZ+aPxwNFsHxpIc+KLGPhJqSBvBHcIGCNopDcuI/PapkD IBgw== X-Gm-Message-State: AOAM532kyDrXYIa5g39aBY+N25BfQAf36Ox6TVsnyi8aVcIhXtYMXMld S/Sbb5u+kwrl/TKBM5RD24dATLYT3tBsSg== X-Google-Smtp-Source: ABdhPJygzGuMDgn5XxaQDXRuJ4WZ3UzAdIlGtpsS6XT8hXHRoJzTfcTTyxnlBPC3tdpbFr7neKAATw== X-Received: by 2002:a17:902:f704:b029:11a:cdee:490 with SMTP id h4-20020a170902f704b029011acdee0490mr28093582plo.37.1632242922413; Tue, 21 Sep 2021 09:48:42 -0700 (PDT) Received: from localhost ([2620:15c:202:201:db3:f19e:7f67:74f]) by smtp.gmail.com with UTF8SMTPSA id p2sm20023639pgd.84.2021.09.21.09.48.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Sep 2021 09:48:41 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Howard Chung , Alain Michaud , Luiz Augusto von Dentz , Miao-chen Chou Subject: [BlueZ PATCH v6 1/4] doc: Add errors.txt to describe errors of D-Bus method returns Date: Tue, 21 Sep 2021 09:47:05 -0700 Message-Id: <20210921094400.BlueZ.v6.1.Ide6362da19898d001b053656ee8bf76e183633d8@changeid> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210921164708.1497029-1-mcchou@chromium.org> References: <20210921164708.1497029-1-mcchou@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- (no changes since v5) Changes in v5: - Remove the use of error codes. doc/errors.txt | 233 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 doc/errors.txt diff --git a/doc/errors.txt b/doc/errors.txt new file mode 100644 index 000000000..047610c74 --- /dev/null +++ b/doc/errors.txt @@ -0,0 +1,233 @@ +D-Bus Method Return Error Codes +=============================== + +The motivation of having detailed error 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 +=================================== + errno: EALREADY, EISCONN + + Either the profile is already connected or ACL connection is in place. + +BR/EDR connection page timeout +============================== + errno: EHOSTDOWN + + Failed due to page timeout. + +BR/EDR connection profile unavailable +===================================== + errno: ENOPROTOOPT + + Failed to find connectable services or the target service. + +BR/EDR connection SDP search +============================ + errno: none + + Failed to complete the SDP search. + +BR/EDR connection create socket +=============================== + 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 +=================================== + errno: EHOSTUNREACH + + Failed due to invalid arguments. + +BR/EDR connection not powered +============================= + errno: EHOSTUNREACH + + Failed due to adapter not powered. + +BR/EDR connection not supported +=============================== + 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 +============================ + errno: EBADFD + + Failed due to the socket is in bad state. + +BR/EDR connection memory allocation +=================================== + errno: ENOMEM + + Failed to allocate memory in either host stack or controller. + +BR/EDR connection busy +====================== + 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 +============================================= + errno: EMLINK + + Failed due to reaching the concurrent connection limit to a device. + +BR/EDR connection timeout +========================= + errno: ETIMEDOUT + + Failed due to connection timeout + +BR/EDR connection refused +========================= + errno: ECONNREFUSED + + Refused by the remote device due to limited resource, security reason + or unacceptable address type. + +BR/EDR connection aborted by remote +=================================== + errno: ECONNRESET + + Terminated by the remote device due to limited resource or power off. + +BR/EDR connection aborted by local +================================== + errno: ECONNABORTED + + Aborted by the local host. + +BR/EDR connection LMP protocol error +==================================== + errno: EPROTO + + Failed due to LMP protocol error. + +BR/EDR connection canceled +========================== + errno: none + + Failed due to cancellation caused by adapter drop, unexpected device + drop, orincoming disconnection request before connection request is + completed. + +BR/EDR connection unknown error +=============================== + errno: ENOSYS + + Failed due to unknown reason. + +LE connection invalid arguments +=============================== + errno: EINVAL + + Failed due to invalid arguments. + +LE connection not powered +========================= + errno: EHOSTUNREACH + + Failed due to adapter not powered. + +LE connection not supported +=========================== + 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 +=============================== + errno: EALREADY, EISCONN + + Either the BT IO is already connected or LE link connection in place. + +LE connection bad socket +======================== + errno: EBADFD + + Failed due to the socket is in bad state. + +LE connection memory allocation +=============================== + errno: ENOMEM + + Failed to allocate memory in either host stack or controller. + +LE connection busy +================== + 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 +===================== + 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 +=========================== + errno: EIO + + Failed to create or connect to BT IO socket. This can also indicate + hardware failure in the controller. + +LE connection timeout +===================== + errno: ETIMEDOUT + + Failed due to connection timeout + +LE connection concurrent connection limit +========================================= + errno: EMLINK + + Failed due to reaching the synchronous connection limit to a device. + +LE connection abort by remote +============================= + errno: ECONNRESET + + Aborted by the remote device due to limited resource or power off. + +LE connection abort by local +============================ + errno: ECONNABORTED + + Aborted by the local host. + +LE connection link layer protocol error +======================================= + errno: EPROTO + + Failed due to link layer protocol error. + +LE connection GATT browsing +=========================== + errno: none + + Failed to complete the GATT browsing. + +LE connection unknown error +=========================== + errno: ENOSYS + + Failed due to unknown reason. From patchwork Tue Sep 21 16:47:07 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: 12508365 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=-20.2 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 3F9E4C433F5 for ; Tue, 21 Sep 2021 16:49:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 212EA61184 for ; Tue, 21 Sep 2021 16:49:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229676AbhIUQu5 (ORCPT ); Tue, 21 Sep 2021 12:50:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbhIUQuz (ORCPT ); Tue, 21 Sep 2021 12:50:55 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA700C061574 for ; Tue, 21 Sep 2021 09:49:26 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id c4so13786910pls.6 for ; Tue, 21 Sep 2021 09:49:26 -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=yjCujCNv75N9S8hy4VUHJ8ZotgSGTx6b7LLzgwfR3hg=; b=GG80hgn0KydrEtZDr4UWAvaZDMmsPS70yMPrHH4QpJrb27w4JiGBXhSzGfQHi89sMk WBLhHXDsHHiAzRymputcObC+w+p5YX4Ely3U4CHZ0jWbXqXKSrliW0Ew3y5+a8JG2Ix6 4fRAH3QxE0/hbg4HqFp/RukMdWbx9hHyaCoQw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yjCujCNv75N9S8hy4VUHJ8ZotgSGTx6b7LLzgwfR3hg=; b=tIJGek2HAZ/QkZY5ZOCmx2AZaT7RlEcgEp2FeFEsqVKGIGPRfSnsO7H2VIBp/TWA08 +7YiiOUBZWekgiy2z8yrQdsozH3kcItiAGxvN77JOR23otej2VBtZ82XIuNpjz3ON4E3 mQGPrJpX/eCxX1o1cbgFL/bjq7DsJ/kJu49IamidLo9jzUtgln2HsGxdLwRvuvat36Ep OnHGDZtjaE1+YJC7+Qq+sk+Bvx/W00yFFLP/R/hXLe7aJNGWRTDVDXb66izR6TpCgeSq cJx8YmheGZo/gQK2iDbya822tAwsm9EUSSMhvK0Y5YEbKQi30EPg5kh4XyxjNPu5Ce+v UoMg== X-Gm-Message-State: AOAM530xeQOpoI7zbAy/WalPqKCVZ4p7vb0FODQt2LLuljoiFVk/oMXT EGxu1tr9EEIn7ZjpdLB4zvQ6l8ht4pi7Gg== X-Google-Smtp-Source: ABdhPJzUikYv7l2INW9A2vHjV53PU2Yqiy1BcrtZQv4zy8Zy/oaeR++eC7siip/yC3sCKLZH568+tA== X-Received: by 2002:a17:90a:19d8:: with SMTP id 24mr6278170pjj.129.1632242965986; Tue, 21 Sep 2021 09:49:25 -0700 (PDT) Received: from localhost ([2620:15c:202:201:db3:f19e:7f67:74f]) by smtp.gmail.com with UTF8SMTPSA id w9sm2824126pjl.56.2021.09.21.09.49.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Sep 2021 09:49:25 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Howard Chung , Alain Michaud , Luiz Augusto von Dentz , Miao-chen Chou Subject: [BlueZ PATCH v6 2/4] error: BR/EDR and LE connection failure reasons Date: Tue, 21 Sep 2021 09:47:07 -0700 Message-Id: <20210921094400.BlueZ.v6.2.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210921164708.1497029-1-mcchou@chromium.org> References: <20210921164708.1497029-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 Reviewed-by: Alain Michaud Reviewed-by: Howard Chung --- Changes in v6: - Rephrase error strings. 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 | 57 ++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) diff --git a/src/error.c b/src/error.c index dd85cd288..caeee1cc7 100644 --- a/src/error.c +++ b/src/error.c @@ -14,6 +14,8 @@ #include #endif +#include +#include #include "gdbus/gdbus.h" #include "error.h" @@ -66,12 +68,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", @@ -108,8 +122,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 7fcddaf4a..d0552bef1 100644 --- a/src/error.h +++ b/src/error.h @@ -11,9 +11,60 @@ */ #include +#include #define ERROR_INTERFACE "org.bluez.Error" +/* BR/EDR connection failure reasons */ +#define ERR_BREDR_CONN_ALREADY_CONNECTED "br-connection-already-"\ + "connected" +#define ERR_BREDR_CONN_PAGE_TIMEOUT "br-connection-page-timeout" +#define ERR_BREDR_CONN_PROFILE_UNAVAILABLE "br-connection-profile-"\ + "unavailable" +#define ERR_BREDR_CONN_SDP_SEARCH "br-connection-sdp-search" +#define ERR_BREDR_CONN_CREATE_SOCKET "br-connection-create-socket" +#define ERR_BREDR_CONN_INVALID_ARGUMENTS "br-connection-invalid-"\ + "argument" +#define ERR_BREDR_CONN_ADAPTER_NOT_POWERED "br-connection-adapter-not-"\ + "powered" +#define ERR_BREDR_CONN_NOT_SUPPORTED "br-connection-not-suuported" +#define ERR_BREDR_CONN_BAD_SOCKET "br-connection-bad-socket" +#define ERR_BREDR_CONN_MEMORY_ALLOC "br-connection-memory-"\ + "allocation" +#define ERR_BREDR_CONN_BUSY "br-connection-busy" +#define ERR_BREDR_CONN_CNCR_CONNECT_LIMIT "br-connection-concurrent-"\ + "connection-limit" +#define ERR_BREDR_CONN_TIMEOUT "br-connection-timeout" +#define ERR_BREDR_CONN_REFUSED "br-connection-refused" +#define ERR_BREDR_CONN_ABORT_BY_REMOTE "br-connection-aborted-by-"\ + "remote" +#define ERR_BREDR_CONN_ABORT_BY_LOCAL "br-connection-aborted-by-"\ + "local" +#define ERR_BREDR_CONN_LMP_PROTO_ERROR "br-connection-lmp-protocol-"\ + "error" +#define ERR_BREDR_CONN_CANCELED "br-connection-canceled" +#define ERR_BREDR_CONN_UNKNOWN "br-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); @@ -22,11 +73,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); From patchwork Tue Sep 21 16:47:09 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: 12508367 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=-20.2 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 082AEC433F5 for ; Tue, 21 Sep 2021 16:49:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E474161166 for ; Tue, 21 Sep 2021 16:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbhIUQv0 (ORCPT ); Tue, 21 Sep 2021 12:51:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbhIUQv0 (ORCPT ); Tue, 21 Sep 2021 12:51:26 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE6B3C061574 for ; Tue, 21 Sep 2021 09:49:57 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id me5-20020a17090b17c500b0019af76b7bb4so2429565pjb.2 for ; Tue, 21 Sep 2021 09:49:57 -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=xRXvFilc8lwgq6QPf0tPcFU77zb4bdVFTnUqWSbeJ/k=; b=eAkS+AA3FXQk0p2eG0TzIB41ILq71Wl2GYDmLaBWySwjSZIE97D7qSiwiPpS/nabNz Kb2Z9n1iGpiftS8mrNpJnzAbKyfXKeY6p7yd50Ox/qvOIl3VQoYV1WwcSfirtC6fZFc7 G0uWtsTjoUjeN0njpcXBI66ERlezJ6TxdZT/U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xRXvFilc8lwgq6QPf0tPcFU77zb4bdVFTnUqWSbeJ/k=; b=J09ncgt1617KveHwYGURVe3z3mD0spfMSsVg/tkQ760Lg5EVugK0MNWb00je3ytTwM JTFnNoxveGiQjM71awMKRY8kwz2Cq46oTJSLtQnjDLub7pYd8grP9UHCer5ITNUJU1Mi QVnN6iWvLfaTRMC0VqDlZHskmuIPJr+1QXfxCSL6m1CAM0pKNvglbbhM+yP8LdWfUsfL K0WpfKGA8ZAZIKA0tepneg4jFoF/YSXO2nfYZ6xEXv+xp80HJl79dCvTmu2NrNI72/aW CMSlc8eh5jCx2zaGSTbGBwsXH0yEp6GIPLupdG8eLBTWJoikmiPzDFeFwBxD8m3utb94 XqnQ== X-Gm-Message-State: AOAM532CZTO9MgIQZwjaWe7+J4sjLmnoGl1EtSy5YKNe+Dj+6vJZd7yX JsMsgExhBRx3/VnSfO1YtVhIcq247vUWNg== X-Google-Smtp-Source: ABdhPJwttFn/AP1H8EwZbfLwjln01/M6RBwWfzdLv/pvbWeBiza678L6feg9sUiYSkQLIwWlmzBQbQ== X-Received: by 2002:a17:90a:1b2a:: with SMTP id q39mr6369224pjq.219.1632242996925; Tue, 21 Sep 2021 09:49:56 -0700 (PDT) Received: from localhost ([2620:15c:202:201:db3:f19e:7f67:74f]) by smtp.gmail.com with UTF8SMTPSA id u16sm18021056pfn.68.2021.09.21.09.49.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Sep 2021 09:49:56 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Howard Chung , Alain Michaud , Luiz Augusto von Dentz , Miao-chen Chou Subject: [BlueZ PATCH v6 3/4] device: Include detailed error string in Connect() return Date: Tue, 21 Sep 2021 09:47:09 -0700 Message-Id: <20210921094400.BlueZ.v6.3.Idd761b9b9f4620480db8889e7885a17952c2c13a@changeid> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210921164708.1497029-1-mcchou@chromium.org> References: <20210921164708.1497029-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 detailed error string 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 v5) Changes in v5: - Address the changes from error code to string src/device.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/device.c b/src/device.c index b29aa195d..230274ee1 100644 --- a/src/device.c +++ b/src/device.c @@ -1605,7 +1605,7 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg) if (device->connect) { DBusMessage *reply = btd_error_failed(device->connect, - "Cancelled"); + ERR_BREDR_CONN_CANCELED); g_dbus_send_message(dbus_conn, reply); dbus_message_unref(device->connect); device->connect = NULL; @@ -1799,7 +1799,8 @@ done: } g_dbus_send_message(dbus_conn, - btd_error_failed(dev->connect, strerror(-err))); + btd_error_failed(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) @@ -2000,10 +2001,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_str(msg, 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_str(msg, + ERR_BREDR_CONN_ADAPTER_NOT_POWERED); + } btd_device_set_temporary(dev, false); @@ -2016,10 +2019,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_str(msg, + ERR_BREDR_CONN_PROFILE_UNAVAILABLE); + } } goto resolve_services; @@ -2029,7 +2034,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(msg, + btd_error_bredr_conn_from_errno(err)); } dev->connect = dbus_message_ref(msg); @@ -2043,8 +2049,10 @@ 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(msg, bdaddr_type == BDADDR_BREDR ? + ERR_BREDR_CONN_SDP_SEARCH : ERR_LE_CONN_GATT_BROWSE); + } return NULL; } @@ -2154,8 +2162,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_str(msg, + ERR_BREDR_CONN_INVALID_ARGUMENTS); + } uuid = bt_name2string(pattern); reply = connect_profiles(dev, BDADDR_BREDR, msg, uuid); @@ -2538,7 +2548,10 @@ 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 = btd_error_failed(req->msg, + bdaddr_type == BDADDR_BREDR ? + btd_error_bredr_conn_from_errno(err) : + btd_error_le_conn_from_errno(err)); goto done; } @@ -3030,7 +3043,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(device->connect, + ERR_BREDR_CONN_CANCELED); g_dbus_send_message(dbus_conn, reply); dbus_message_unref(device->connect); device->connect = NULL; @@ -5454,7 +5468,7 @@ done: if (device->connect) { if (err < 0) reply = btd_error_failed(device->connect, - strerror(-err)); + btd_error_le_conn_from_errno(err)); else reply = dbus_message_new_method_return(device->connect); From patchwork Tue Sep 21 16:47:11 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: 12508369 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=-20.2 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 CEB93C433FE for ; Tue, 21 Sep 2021 16:50:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2F0061166 for ; Tue, 21 Sep 2021 16:50:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229753AbhIUQvx (ORCPT ); Tue, 21 Sep 2021 12:51:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbhIUQvw (ORCPT ); Tue, 21 Sep 2021 12:51:52 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7FCAC061574 for ; Tue, 21 Sep 2021 09:50:23 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id c4so13788792pls.6 for ; Tue, 21 Sep 2021 09:50:23 -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=/FXhO2NSMQzvQTLywyJVzhht/202PftsHvkwRYE2cG4=; b=oNoYNr2glEdgHrV9JaOsd98via4j/f1Q91g1rh0HhSk7F2Fn8np6TWYd13AUAouajU f8ZFrnS85wl5kwczDEsdGYcXC2G3v6g53tepyNcjTsXUqkphclzCNgy6xH6NGofqYAg0 HRI8CQ+xkawZVIFHqMO7slq/3eSOZyW0xeAlI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/FXhO2NSMQzvQTLywyJVzhht/202PftsHvkwRYE2cG4=; b=pVVOI6io2IseS+Ueq5roCJFdxQSHsV0qS7bp7bsqxhZQS86tDpXZ0hfVTU2xb5PuyN kyaVUYJ8KkTkKPzJ5X9KgGz0vsOchNvJMN6VJxFprMVwwO19rl60KCoaKiRaFCHrB+PK 3aG5nn4SaX4iMyykcBLixAMgVKgi4Vv7S6su/OCku/uxuAtTQlWqi6rTeJUwg640sAEg 3gJw034Ve3FC5My0UZ1PI3tLMIvpl8AXRf0chp2qomX2GcDN3ntVe2c16H2kCj8U9ol6 J4AyJsfOwmgXgOxxIGoNQKLNJ9o3YRuSj4RUUHSE9FpSAwGQG2MZ7dUN/+KU42VKiDUw nQhA== X-Gm-Message-State: AOAM533N7s2hVZPya/MEOQAplGYB7xBPktwzHhwFAqRwgstMynbGyjsk VYl8RfKwyKBAxJVJYOjr3EPUsXBIssVjBQ== X-Google-Smtp-Source: ABdhPJwecBCfUsrK9f/RchndqEkettK23JKfKnKKL/t8Yhy8JWtFGmnt8IY7+siNkC0u1xvYq+IVUw== X-Received: by 2002:a17:90a:c58b:: with SMTP id l11mr6230617pjt.134.1632243023105; Tue, 21 Sep 2021 09:50:23 -0700 (PDT) Received: from localhost ([2620:15c:202:201:db3:f19e:7f67:74f]) by smtp.gmail.com with UTF8SMTPSA id m9sm19200841pfh.94.2021.09.21.09.50.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Sep 2021 09:50:22 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Howard Chung , Alain Michaud , Luiz Augusto von Dentz , Miao-chen Chou Subject: [BlueZ PATCH v6 4/4] client: Print error code for connect methods Date: Tue, 21 Sep 2021 09:47:11 -0700 Message-Id: <20210921094400.BlueZ.v6.4.I226fdcdd12b13e4875c8cd03b42fc52283920cc4@changeid> X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog In-Reply-To: <20210921164708.1497029-1-mcchou@chromium.org> References: <20210921164708.1497029-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 v6: - Rephrase error string Changes in v5: - Replace error code with error string Changes in v4: - Address make errors. Changes in v3: - Correct error-codes.txt. 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 c1a62edb7..61650c289 100644 --- a/client/main.c +++ b/client/main.c @@ -1966,7 +1966,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); }