Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp590521pxb; Thu, 26 Aug 2021 09:45:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtwCoe7jI9CVwuu8A/zY7IsYms1cSfQrZTJyJyZoK0WBD9kJBzakZfain9xLQl+OFq7gMs X-Received: by 2002:a17:906:a24c:: with SMTP id bi12mr5312795ejb.530.1629996315519; Thu, 26 Aug 2021 09:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629996315; cv=none; d=google.com; s=arc-20160816; b=EHXt1B9kCPGrlmvWd31AO9yCy1+7+siryToHqfixaw0+JbCmpJrQSGm+lOb8cBFHlB Bq0v5XCx9IIqBVIacsbkFd/G2P9djkO4fz5ZtPu5Jtgj8OrpOykk0zrKaoGK4IsdixsJ s0AEjQTUDHmG+GjQlK3hxEx/1A02jqg0J8+MM0Lgpp7OTiK71W5OrPBgJ85zUlOD32+i qpG031miR4Vevl6WoBoEO/WE+BOK73PZOjTasy+i61cjmetEJHkMc27oUp91PmxNSxnl URD3tFX3iEFNjX4Q7IzRX0GBMUuUlpNx/wl1gap9lF6Xwg1UhpcDIdIpcrWfo5u7Gsgt d9Ug== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=QSXqVfAdnZkot5M4gaZ5owQQcpSYezGdQ+MD9lWwp1U=; b=VIiFYNcNMlp7Y3sHx2kbTIk4yYnmp8k8wq2ZDTpiOEMfeVhcTyQIOJmFX+Q/aeMJWy ZGUxXw+JTlpYZfF0QZ1VfVR3CgoZdDVT279bOBy8cVMZza4+XiTY+RX7+z9CqbFkFO5z vm8TQUohsIpLq8ymZBlf6ezxA9tZDtpc2rDPEWDdMReS3pzv7nPYXP17EXLK6GBemOAT +7IoJQWLc17iJ6jVOvlJcQppaMMeIUKZxZRk6fwqNGYf2Axpj/F/M8XbMjuX0fBoEqbD BoroXcGOtQnHOFQazZ2YWIV1+AzRf7b4Kr0Vz57QuJdewz+FfUdb4S9pGTJMlS3Ywh/I id6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b="e+bj/dbT"; 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 cn3si3593327edb.298.2021.08.26.09.44.22; Thu, 26 Aug 2021 09:45:15 -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=fail header.i=@lechnology.com header.s=default header.b="e+bj/dbT"; 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 S233556AbhHZQnI (ORCPT + 99 others); Thu, 26 Aug 2021 12:43:08 -0400 Received: from vern.gendns.com ([98.142.107.122]:55776 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232835AbhHZQnI (ORCPT ); Thu, 26 Aug 2021 12:43:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=QSXqVfAdnZkot5M4gaZ5owQQcpSYezGdQ+MD9lWwp1U=; b=e+bj/dbT3zzoy3xQvxwVulr6yE oZKzb2yJ2D23LCTltWKnK/sSAKGWBPm6oO43PjGNcXgZpL6PZU8L5gdByY5zpxMVtTgyMI8It6SAz 3EQl3wnWjieqYJkyh2rzbLxrOmx3Kl1q7a5UCEIcwVTzqVEcTBcIZVdNdWpqTO5j1vDq8MoAsGtlf xA4G/c/6SsVEct0iJw1sIAXMVNEchSQZrRj5aL2/HJZ2o1QYCCU0LhGHmz0XImnoR5rKq7pgVd/oV 1+hDkWbJ3SqtvTwqEvooDCc4uTMBX1TDQYxvFy8bCdwymI4Y7oy3bAolMuSTWW+WODMkFYcsgBICz U1GscehQ==; Received: from [2600:1700:4830:1658::fb2] (port=34192 helo=freyr.lechnology.com) by vern.gendns.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mJIS8-0006y5-Nl; Thu, 26 Aug 2021 12:42:19 -0400 From: David Lechner To: linux-bluetooth@vger.kernel.org Cc: David Lechner Subject: [PATCH BlueZ] device: add MTU D-Bus property Date: Thu, 26 Aug 2021 11:42:11 -0500 Message-Id: <20210826164211.2936133-1-david@lechnology.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When using GATT write without response, it is useful to know how much data can be sent in a single write. This value is the negotiated MTU minus 3 bytes. The D-bus method org.bluez.GattCharacteristic1.AcquireWrite returns the MTU exactly for this reason. However, when using the alternate API org.bluez.GattCharacteristic1.WriteValue with the options dictionary { "type": "command" }, there is no current way to get the MTU value. If the value is too large, then the method returns "Failed to initiate write" [org.bluez.Error.Failed]. This adds an "MTU" property to the org.bluez.Device1 interface that is emitted in gatt_client_ready_cb() which is after the MTU exchange has taken place. Signed-off-by: David Lechner --- client/main.c | 1 + doc/device-api.txt | 4 ++++ src/device.c | 24 ++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/client/main.c b/client/main.c index 506602bbd..b12a7da3e 100644 --- a/client/main.c +++ b/client/main.c @@ -1754,6 +1754,7 @@ static void cmd_info(int argc, char *argv[]) print_property(proxy, "TxPower"); print_property(proxy, "AdvertisingFlags"); print_property(proxy, "AdvertisingData"); + print_property(proxy, "MTU"); battery_proxy = find_proxies_by_path(battery_proxies, g_dbus_proxy_get_path(proxy)); diff --git a/doc/device-api.txt b/doc/device-api.txt index 4e824d2de..030873821 100644 --- a/doc/device-api.txt +++ b/doc/device-api.txt @@ -272,3 +272,7 @@ Properties string Address [readonly] Example: 0x26 0x01 0x01... + + uint16 MTU [readonly, optional] + + The exchanged MTU (GATT client only). diff --git a/src/device.c b/src/device.c index 26a01612a..898f98da7 100644 --- a/src/device.c +++ b/src/device.c @@ -1471,6 +1471,26 @@ static gboolean dev_property_wake_allowed_exist( return device_get_wake_support(device); } +static gboolean +dev_property_get_mtu(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct btd_device *device = data; + + dbus_uint16_t mtu = bt_gatt_client_get_mtu(device->client); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &mtu); + + return TRUE; +} + +static gboolean +dev_property_mtu_exist(const GDBusPropertyTable *property, void *data) +{ + struct btd_device *device = data; + + return bt_gatt_client_get_mtu(device->client) != 0; +} + static bool disconnect_all(gpointer user_data) { struct btd_device *device = user_data; @@ -3014,6 +3034,7 @@ static const GDBusPropertyTable device_properties[] = { { "WakeAllowed", "b", dev_property_get_wake_allowed, dev_property_set_wake_allowed, dev_property_wake_allowed_exist }, + { "MTU", "q", dev_property_get_mtu, NULL, dev_property_mtu_exist }, { } }; @@ -5245,6 +5266,9 @@ static void gatt_client_ready_cb(bool success, uint8_t att_ecode, return; } + g_dbus_emit_property_changed(dbus_conn, device->path, + DEVICE_INTERFACE, "MTU"); + register_gatt_services(device); btd_gatt_client_ready(device->client_dbus); -- 2.25.1