Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2682304pxt; Mon, 9 Aug 2021 06:34:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyR70pppc95cpbmMktBY5GEAGjeTRwQoH26wdNchZI9+/lVcXC5StU9+h0gNSrkPfkBZMeF X-Received: by 2002:a05:6402:430b:: with SMTP id m11mr29969266edc.55.1628516076454; Mon, 09 Aug 2021 06:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628516076; cv=none; d=google.com; s=arc-20160816; b=nNqPwksFs10Ag6Ide8MF6K4Xc3EnH+7ezvti/vLr9jj07MsjWKdJLWqdbbQQ+xBPh3 9UowGVU84ExnWd3S9/zYEDweBJi08Ok1Sb/l8RSv4z6M4qN6tqo5HNxPMzqveRZxF+Ym qfYtA2eGMCtGMN6arMtQNOHSI3Y8zgUxeTbVnTtPnMVk9I4inTmKNR8hf6xXfMcytYjg /+1K5knwmIDXTaKIoJIKPiNYvp9XJo8S0xSUnW3Vv+TV/4WOXPl6F1Vby450AmgrE10O Ge53Di6FC05gxVmQztQxBniFw89v9zWl8cQ8+EfUENM6i89gvnQ4GeYYHkcr7F97yypI qYnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=zoA6h0jMXh4hXBS30TjK+J/DyA222WXEhU5B+QHhvsw=; b=qlH4MnZZ6Z4kUyWux2uvs4OpqjbR4grj/ZcHhRTLOGezAyuf2pDNrZKeB3OKn4/wIn 0GF8DhfKfwFpMzI73843NdBRutB+4taGCFcsSkGIDsSj0kUr48eV0aIYqovfZtNnlOc+ wtluo04j58c4sA64fNQ1BLQmSrL3t2r9SGx0qndzagQERYkUfKNb/4NyJAPOzIKBspPa Rqoj004j/ifeawI79S1HRjlk+VGce2UqBaR8qVhXDcSTy1pwl62d4IspMwvSuwfSHT20 bRNFSHMNj5T3ZsnhV46nGq0Iq9maYnHHdm3xI6C0NL1KAUO44irCp3wUagGHnKTJ7BM6 q18w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a2si17602366edk.106.2021.08.09.06.34.11; Mon, 09 Aug 2021 06:34:36 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229474AbhHINc0 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 9 Aug 2021 09:32:26 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:47453 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233327AbhHINcZ (ORCPT ); Mon, 9 Aug 2021 09:32:25 -0400 Received: from smtpclient.apple (p5b3d23f8.dip0.t-ipconnect.de [91.61.35.248]) by mail.holtmann.org (Postfix) with ESMTPSA id 95A99CEE01; Mon, 9 Aug 2021 15:32:03 +0200 (CEST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.100.0.2.22\)) Subject: Re: [BlueZ PATCH v5 2/4] error: BR/EDR and LE connection failure reasons From: Marcel Holtmann In-Reply-To: <20210806164624.BlueZ.v5.2.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid> Date: Mon, 9 Aug 2021 15:32:03 +0200 Cc: Bluetooth Kernel Mailing List , Howard Chung , Luiz Augusto von Dentz , Alain Michaud Content-Transfer-Encoding: 8BIT Message-Id: <991E0A86-77E3-46E1-8E19-CED2742D374F@holtmann.org> References: <20210806234720.286157-1-mcchou@chromium.org> <20210806164624.BlueZ.v5.2.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid> To: Miao-chen Chou X-Mailer: Apple Mail (2.3654.100.0.2.22) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Miao-chen, > 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 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 > #endif > > +#include > +#include > #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 > +#include > > #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" I rather have you use strings like “le-connection-not-supported” to make this similar to what we are using for other strings in the API. And I am always torn between using “bredr-“ and just using “br-“. Regards Marcel