Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2932848pxb; Tue, 21 Sep 2021 10:36:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzamTngfkxM/mBUydo96YFBbU2xf1oJjHt6Cp6UfY1dAQ9R1xcRXF4lBQuyt4H3mOgM9RQW X-Received: by 2002:a17:906:8151:: with SMTP id z17mr35481629ejw.468.1632245799310; Tue, 21 Sep 2021 10:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632245799; cv=none; d=google.com; s=arc-20160816; b=0FO72X/rQk6hUgK8FTSYoJ8iVrge61MdeX/q9a0Zk8QJXY2L/RudO1KHu2n1+ERTKK RtNQwEBjJ9icGE7j4fLOxVGdyxSkrUWtBGk7nRwNUAvFo+KsTIBOMinVTni8c4+u5TEq +GZl5Pe8IXPDTvZQyJD1gwDzUImUDOeQ4iwdqWPIqkrQj4UhWm4lpsKMJn/Vc80IZBrp Qzt7bLX5IMDSYZLZcByZhx+eI5LAzrrKwvxUsrBHtemhYK6wEALugmZqumQbLEQYqg9N 63mr8CDkJFEoJuNFzvF65wHdwZTxF3RYPeGqT4+naonKN9zC6+zoZB2+6Ror6WOaSH2I YudA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yjCujCNv75N9S8hy4VUHJ8ZotgSGTx6b7LLzgwfR3hg=; b=ccYfvyztXN5vzFPnzquADWCZBfN+i24/hq4EAWaDnOZn6NI0lTkCcELR6FQ0ZunkIc SKvKhyRuI7YAcPUnW7QL3zMQMaOX6XDpJtbrI2zjOZUINzcCwOd8MF4fEkmNtzLyexv7 zfRtEVC8ISaaoyV5nxWwzEfUXzeT9B2aiC4s4o2H7k/U/ESgZs/dW0FgWSu23Mi49LX4 lY/SxCtsKHpLGr+ndkdThtkyVn0zM/FIYhMoTcNkyfOPhL6kauyl+n3FpyMq5DSwSWJB CRrTJvUn8dM1jGWxEiciCcZ/fVtg4T0AjXv/1IKhekIMSqpUiJdH/vOahOPTslepDoS2 Of3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GG80hgn0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr1si17761576ejc.424.2021.09.21.10.35.29; Tue, 21 Sep 2021 10:36:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=GG80hgn0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbhIUQu4 (ORCPT + 99 others); Tue, 21 Sep 2021 12:50:56 -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-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 Content-Transfer-Encoding: 8bit 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); -- 2.33.0.464.g1972c5931b-goog