Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp900652pxt; Fri, 6 Aug 2021 17:25:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypjfmT+pEx9aT5kebn1kWxVJ1qNuY7h+Kh19Hpj5fuDl59vv8v24S6gLU5oju2Y+JwVN5l X-Received: by 2002:a5d:9b8b:: with SMTP id r11mr2621780iom.26.1628295945476; Fri, 06 Aug 2021 17:25:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628295945; cv=none; d=google.com; s=arc-20160816; b=ieTeVisoagTcoHzF2FPjTi0Xv7+fYRk3kCmNxinBoeomfRAiuTcviuIjwtHYTjLjoi 4428u51+aXwnROKN/Ei4oUeL6G9z113tWfXfnVla/EirjBFcroCBAyZg6QbC4GvUEzqx 7t5pnc5u3XAlgJJtC4oNILsi43EsVMajr9eAdqNTQ1BL7dYnzMuEvobPR4qi8636qtrr stjTnpPc4GYo92cAd5YAHjxyqMK36e4jye2uwy+WzgmG0B7RjVNA8KThglgelyQvOLq9 41sXirqIO4zUidSrWSNsFm9Y1CNoi40nMbuyssTNZ2b4NWgj9vjEdTe6Keoj6GHQpAgX x9/w== 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=9WOqVoAfj34+t/vHFiodLU5+26NK5uCE6eUgJpHFD/s=; b=RHs+1hKFWrCKgdbMcBDNYDLigLKgzEREQjZM8st5+lOn3pJj4KTEn5iCJSvYIRLV8/ JAOiNYSYa+sDZzpOLE1bNaLZWNPZ4+KircDXB/Rra4MhuIdEtkjvECyAzG+yeDfxqCwB ZAQOuTYHEynSfegveQYUXJ5ShUJbHczpfHYmWwmZ0kMCXDrK2ez/Mk2/PFNcqws37MXZ ymF5VogvbFx3w8dVKamp+K2Jdw0wZldsHhVrlbqFHvUx08+Nb0KbDBs1v0tt/O+TUVxZ kuplN7bpiyVzDpalxcMyxy95TdXfiOD6GAlXnGzHL9KR616xVJK2r7d6VKJlDr8hbYkE 3lpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=oBvnF0Hx; 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 g15si10490086ilc.45.2021.08.06.17.25.34; Fri, 06 Aug 2021 17:25:45 -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=oBvnF0Hx; 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 S232233AbhHFXtX (ORCPT + 99 others); Fri, 6 Aug 2021 19:49:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232126AbhHFXtX (ORCPT ); Fri, 6 Aug 2021 19:49:23 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4416AC0613CF for ; Fri, 6 Aug 2021 16:49:06 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id a20so9253947plm.0 for ; Fri, 06 Aug 2021 16:49:06 -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=9WOqVoAfj34+t/vHFiodLU5+26NK5uCE6eUgJpHFD/s=; b=oBvnF0HxiGdkmjeqU/dwTV0OKtceXaehXuaBw+WjDLtroF6Us53O5cxseSx//9B7kc M814mbZMPnUxyF6OoOn/f3ePdYCp4yVZyxl3db7QbRQllCnl2rt0SGECisX+IBA7/z1R HoYkA9G2bbhHeHpC628c00jnP1fnSHdU4kmWQ= 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=9WOqVoAfj34+t/vHFiodLU5+26NK5uCE6eUgJpHFD/s=; b=XqsdSGYVzq9S2BSvL/C7V3tT105KWS7JtftAkxXvCwPrx5S5YuQTMM/3q20nL0XKjW NtOrPZLHiqA2+1OdspUSTLYxd99HtPF5R7hOoOLU0n5bYVZHVQsHLLc5CesPGKfFgaJI D8PWAMuUg4JqqoXx99VUzqShAFS60C0tgEKj3EacFjxMWMV11OM3WqOUL5Ozn4KLE/Om OLwOTTCaoeOICSboXR3OjaHLKgbyclWlEdtWM1IDkO8nvy0RxYSQJg7NIbfeUavu3jSg Iz7GJkscqs1i8SAkXney8U/PSlYwG6vGEWRL3yP6g2bi8YF8wYiwi+cSegZq9sLgdzhb JEVA== X-Gm-Message-State: AOAM532LCr+UE5zTgr0GPSMYorX/GzA4T3geO6s8xIHaokGRWBL54xju WwElYOdSPURf6pgYIgA3WujBUrMIt0HFlg== X-Received: by 2002:a17:902:930b:b029:12c:a7f4:afb2 with SMTP id bc11-20020a170902930bb029012ca7f4afb2mr10989664plb.24.1628293745535; Fri, 06 Aug 2021 16:49:05 -0700 (PDT) Received: from localhost ([2620:15c:202:201:48a2:9887:4da1:32a4]) by smtp.gmail.com with UTF8SMTPSA id q21sm2069245pjg.55.2021.08.06.16.49.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 06 Aug 2021 16:49:05 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Howard Chung , Luiz Augusto von Dentz , Alain Michaud , Miao-chen Chou Subject: [BlueZ PATCH v5 2/4] error: BR/EDR and LE connection failure reasons Date: Fri, 6 Aug 2021 16:47:22 -0700 Message-Id: <20210806164624.BlueZ.v5.2.If79c3f0720cc893be1770c6853fe2fbe626f2caa@changeid> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog In-Reply-To: <20210806234720.286157-1-mcchou@chromium.org> References: <20210806234720.286157-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 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" + DBusMessage *btd_error_invalid_args(DBusMessage *msg); DBusMessage *btd_error_invalid_args_str(DBusMessage *msg, const char *str); DBusMessage *btd_error_busy(DBusMessage *msg); @@ -35,11 +88,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.32.0.605.g8dce9f2422-goog