Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6707404rwb; Mon, 12 Dec 2022 05:34:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ZxPPyNJhntGftV+pdk6kU/bzuwdQ+129joB9/tihd9UT5vC9ZL9GMmdfNBB0t8Z0IGEOS X-Received: by 2002:a17:903:548:b0:18f:8295:1859 with SMTP id jo8-20020a170903054800b0018f82951859mr5001502plb.65.1670852072414; Mon, 12 Dec 2022 05:34:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670852072; cv=none; d=google.com; s=arc-20160816; b=Ixx68U2abeMzYw4cXD8H+zFmQAaiSUwQidDrbraNL+mNtV1zKDoXqlLFE8Kl7eIoas aUYmdwI2f8QowIV7vAMe/SU43/wv0xbOmLgHunPxsz9fpDOGLm8W4LUgR92+wXiTmQ+Z I68z5A/zAyBnvIJAVY4gwEg710ZFJ006VzOcafG3d1SgjmdL2f9ObdnPdwAC3E/iwmfw c/hk4gPjFtHvt6af4NMSXjnq6KGOKsOCjFp2Nj2VVEjpCFHwrNH3zV9M4DSWTYsTVO72 7weJyFEiYw/Rtvzd+vIO/WAFcP2KCwQSlRUYdVK40pxiWlwe91AmsTMj9RQ1m3kDEAth 0BmA== 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=jtTQUQd2sJ5ICsP/e2YSk//XoMs2FmRVM8NBROfVR5I=; b=vLUEjt5eORZD/09dLoMcCvwhd1CWey1fHaaKe0sd8Md2UqqWbkGGFEcbSJkY1VB0VT kNHMFxTqa2tEKWZHYGy7uk35+Vg/TAQlqc4V8YSfR5jm/0Rk1ZQc1LQopLqzT8jkP7ab by/RhtqYA2tYru+Cx11fAnF1uXi02oQ9RFksENaFN3jBQPOBsCkRx+ewbyYUmFaYp/T9 5TjMF9p8gFgZ1RbZmbuhKfPc536YGPRCW6Bhisa99K45z/dVVw3xo9KcWThr69P4Bf6D 8DpLm8CTx/bxCimixPovSWt+xaYWyKJ6bGXP9LwprmPpw+ieitGCVdkojLFhup4sfsen U07Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marmottus.net header.s=gm1 header.b=dXfHOxEE; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=marmottus.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ik13-20020a170902ab0d00b001889ad3ed98si8764933plb.462.2022.12.12.05.34.13; Mon, 12 Dec 2022 05:34:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@marmottus.net header.s=gm1 header.b=dXfHOxEE; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=marmottus.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232336AbiLLNc5 (ORCPT + 99 others); Mon, 12 Dec 2022 08:32:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbiLLNc4 (ORCPT ); Mon, 12 Dec 2022 08:32:56 -0500 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [IPv6:2001:4b98:dc4:8::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 618FF260F for ; Mon, 12 Dec 2022 05:32:52 -0800 (PST) Received: (Authenticated sender: arthur@marmottus.net) by mail.gandi.net (Postfix) with ESMTPSA id 30C5410000C; Mon, 12 Dec 2022 13:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marmottus.net; s=gm1; t=1670851970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jtTQUQd2sJ5ICsP/e2YSk//XoMs2FmRVM8NBROfVR5I=; b=dXfHOxEEtotrgVemJacwSYzREYPGI3TI+5k8KxpmJkopPFkanQFWMTzkO8SEgjZeBO5Clv NHD1ybUGI23MMXQvGCGh5gJfN+7I4hPn3guUzWmGIr3XWUS3hMBq2u8cbfgO/hJXsAwBIj kLhEx9zd2GgJ5j/UT4pfCbW233Pma4tb+JSnRuRXX5Kvc75inHwBHgk2mh9lbYGAAg3Y2q EyWNx51YhnfjhlLW0S0IQydSC/Qka7AqcJGvHSYyadwo3uJY0ZMbh9o4oUNaDSYprACjhq yngcKYgmogaqjR0VYM3NRD7nxCuMxVAP6JL6oHv4V9DjN31I1+HHU6dlPKbdag== From: Arthur Crepin-Leblond To: linux-bluetooth@vger.kernel.org Cc: Arthur Crepin-Leblond Subject: [PATCH BlueZ 1/1] device: Expose the disconnect reason over D-Bus Date: Mon, 12 Dec 2022 14:32:35 +0100 Message-Id: <20221212133235.79657-2-arthur@marmottus.net> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212133235.79657-1-arthur@marmottus.net> References: <20221212133235.79657-1-arthur@marmottus.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Get the disconnect reason from the adapter disconnect notify callback and set the D-Bus "DisconnectReason" property. --- src/device.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/device.c b/src/device.c index 995d39f2c..395cbe3e5 100644 --- a/src/device.c +++ b/src/device.c @@ -183,6 +183,7 @@ struct btd_device { bool le; bool pending_paired; /* "Paired" waiting for SDP */ bool svc_refreshed; + uint8_t disconnect_reason; bool refresh_discovery; /* Manage whether this device can wake the system from suspend. @@ -1134,6 +1135,18 @@ dev_property_get_svc_resolved(const GDBusPropertyTable *property, return TRUE; } +static gboolean +dev_property_get_disconnect_reason(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct btd_device *device = data; + guint8 val = device->disconnect_reason; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &val); + + return TRUE; +} + static gboolean dev_property_flags_exist(const GDBusPropertyTable *property, void *data) { @@ -2624,6 +2637,14 @@ static void device_set_svc_refreshed(struct btd_device *device, bool value) DEVICE_INTERFACE, "ServicesResolved"); } +static void btd_device_disconnected_cb(struct btd_device *device, uint8_t reason) +{ + device->disconnect_reason = reason; + + g_dbus_emit_property_changed(dbus_conn, device->path, + DEVICE_INTERFACE, "DisconnectReason"); +} + static void device_svc_resolved(struct btd_device *dev, uint8_t browse_type, uint8_t bdaddr_type, int err) { @@ -2987,6 +3008,7 @@ static const GDBusPropertyTable device_properties[] = { { "TxPower", "n", dev_property_get_tx_power, NULL, dev_property_exists_tx_power }, { "ServicesResolved", "b", dev_property_get_svc_resolved, NULL, NULL }, + { "DisconnectReason", "y", dev_property_get_disconnect_reason, NULL, NULL }, { "AdvertisingFlags", "ay", dev_property_get_flags, NULL, dev_property_flags_exist, G_DBUS_PROPERTY_FLAG_EXPERIMENTAL}, @@ -3910,6 +3932,8 @@ static struct btd_device *device_new(struct btd_adapter *adapter, return NULL; } + device->disconnect_reason = MGMT_DEV_DISCONN_UNKNOWN; + memset(device->ad_flags, INVALID_FLAGS, sizeof(device->ad_flags)); device->ad = bt_ad_new(); @@ -6910,11 +6934,13 @@ void btd_device_init(void) dbus_conn = btd_get_dbus_connection(); service_state_cb_id = btd_service_add_state_cb( service_state_changed, NULL); + btd_add_disconnect_cb(btd_device_disconnected_cb); } void btd_device_cleanup(void) { btd_service_remove_state_cb(service_state_cb_id); + btd_remove_disconnect_cb(btd_device_disconnected_cb); } void btd_device_set_volume(struct btd_device *device, int8_t volume) -- 2.38.1