Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1013505pxj; Thu, 17 Jun 2021 20:10:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+cPBswm3ji7DiDlJeLotSjtPV9gfv1ByyFPWqh+ZuZ6v+fjPJ4jqLKKOk1aKURvUddFMQ X-Received: by 2002:a17:906:2493:: with SMTP id e19mr8498684ejb.207.1623985854435; Thu, 17 Jun 2021 20:10:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623985854; cv=none; d=google.com; s=arc-20160816; b=IeDN2tjFLNlPsctmygV+Fk2liBCMN1qthRmQnpocBbtx8b79Zc5quk+olkkfvfy9g/ oahPerTVW4UCIyDpuq/6OPsh5pYMEMrrB0ODKraRlkvI+altZ7I5I0ML9nQ8ug5cHbpE 3qWcC+/86BvBaudOaF5BpSxqjEgho2xLXN9riR44KlzHWuRJXJepgNePHTkA7iyj5VF3 iIUOfvE9jPu7oi7fqMmX8YZd65AQvOi09D3SyoY2YlPAKSKcIkov1NZ7ImKedXkjd4mP +0wB58aGTBvYE1LdfamuwkqOu+0aMXXww8KDksI+ES82EcGd4RgcCFBI9bh4A2v4Duy6 rK4g== 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=IiJR3YjCUSEUCdAl6YeU1HOIiffi0akjmAu9i2hhBpQ=; b=DGrvnH8HYUw7ctcPlM7O4/yxNfYLqbFYGBa2sIw3CLCYFOfqSp7A7chOdelTq6EgvT EylE3fyN823Zdc3SqKfasMCh7NuK+fLSoGLn5rnNjW9wTQjk5KJan2S+7KbYlWmiJ1NV 9E1XIX+2OV+0aIq5swg+QNXn4ronzyI+1iiP+uoTByrT0NKRzRySC9lm+TB2RiVTZnWn nLhur5LK6/S/gTLVE+HL+0l53OknA2knLcUqEET1t7WJX8FsTl4o+BE3C1rKbyWGNDKZ b24VzrXESW+sksfB3LuqiCb12edv7HmfqNXA/P0Xn4Aqcd0bN9Z3Cbw9i6HVjOBdJtd5 XUfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=B7PUk4tm; 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 d12si1274692ejj.278.2021.06.17.20.10.21; Thu, 17 Jun 2021 20:10:54 -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=B7PUk4tm; 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 S233240AbhFRATa (ORCPT + 99 others); Thu, 17 Jun 2021 20:19:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233227AbhFRATa (ORCPT ); Thu, 17 Jun 2021 20:19:30 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2288DC061574 for ; Thu, 17 Jun 2021 17:17:22 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id 69so3792227plc.5 for ; Thu, 17 Jun 2021 17:17:22 -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=IiJR3YjCUSEUCdAl6YeU1HOIiffi0akjmAu9i2hhBpQ=; b=B7PUk4tmmAl++V8G2hbvji6U2vLguU4rjJPEWkUA8Yci6pe00eUfsIIoyD08o8mNhO uUY0gyDTkkbmjqmJIApCEsG33rJr249tZqHLX64fzzYze10SNjLmx7ucR3YS1an8Hxqs z1zR+GJGOClr8/GKdLWFsAs0lOKJeJWlsWLWQ= 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=IiJR3YjCUSEUCdAl6YeU1HOIiffi0akjmAu9i2hhBpQ=; b=ShNzYsHjGWE4Pg5YvdXeazWHnS7bqlENZ0WQOlSFLdtHUXgGZ23otX57rUznWrzc0s kTkgZjYnqYn2IleE3tJEqMvkUNeVa5TecUntKYcd0U6WGS9ZtiWo0WSQveGKyTWpU+vP kEgfdxrZvFzeuBkdE8XpVDMC563zYLOj6eLkhf5I/neOHVJYwglPcJyxkLQJHynNm7ts gyc0ep6ld6/YAX23bf1l8o9y5/rClyTwsKBvwm/SvgNR81Jry4z6YRZ7I2QGGGgrsbB+ dOJidxChYTL7ewCk+PS1HRrwpsaJ0NIhbRQNLdnbxbSwbzKkMw/RGYDeVAMjffDCBqQn fOdA== X-Gm-Message-State: AOAM530v0B48PcnWCHpoD63As82gekQeqI9O+gmk+pmcJMuxmXalwD8e PP6LhkTBrzTmx/xllj4TFAEc0HrCjdeuyA== X-Received: by 2002:a17:902:6b82:b029:120:3404:ce99 with SMTP id p2-20020a1709026b82b02901203404ce99mr2286390plk.49.1623975441397; Thu, 17 Jun 2021 17:17:21 -0700 (PDT) Received: from localhost ([2620:15c:202:201:d75:da94:7930:935d]) by smtp.gmail.com with UTF8SMTPSA id z9sm6256096pfc.101.2021.06.17.17.17.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 17:17:20 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Alain Michaud , Luiz Augusto von Dentz , Howard Chung , Miao-chen Chou Subject: [BlueZ PATCH v1 2/3] device: Include BtdError code in Connect() return Date: Thu, 17 Jun 2021 17:16:00 -0700 Message-Id: <20210617170013.BlueZ.v1.2.Idd761b9b9f4620480db8889e7885a17952c2c13a@changeid> X-Mailer: git-send-email 2.32.0.288.g62a8d224e6-goog In-Reply-To: <20210618001559.1284204-1-mcchou@chromium.org> References: <20210618001559.1284204-1-mcchou@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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); -- 2.32.0.288.g62a8d224e6-goog