Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4581661ybz; Tue, 28 Apr 2020 14:08:33 -0700 (PDT) X-Google-Smtp-Source: APiQypKf9NysFb/YvY57RlGKCzgb/LFzcb+bvqWSkbjP2n7xT4Azg43vcGPIw5kY6zcE6OS7FX8u X-Received: by 2002:a17:906:33d4:: with SMTP id w20mr25977911eja.284.1588108113724; Tue, 28 Apr 2020 14:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588108113; cv=none; d=google.com; s=arc-20160816; b=kPBYh7wuNCCSv96KQvUlFhpzoHNLRFke4O1SbHvSS8CPre+IAi/s0BDFWGIH03KMno q8ynR6kasIg7/0XDgL6Dt1o/OIbfT6cIyg0jHkJwiBUvZQczqM3K6yiFthrRafxKzGg1 Q34eQ/x5iv87+zZ7LEMFtViJ43mHiXKN1OvqPRGXxZeAvoL3FKnQPGkFQPkStPcovxsL wijYBGuJhYzOlqroC+W1HBlRRwt7Kc5L/ZP5As9wIKI593Wy3MlxiT1sDlMfG08Ldd27 hwCj49CdeRKSQCIalGmX7+oU4tzSXFTbA993ZTa3OyoFp6cnpQyGukEABEY9NUGSOz1e e0RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=/gUQZIHD+k3WI82+sRa1/EBE1hnpwMzmqhFoAyagTyQ=; b=qL9c+TORNC/+VypbC+PT4Zpvfdz7Axq5SILM9ijzULeod+jU/xC6G44Kk/CV5Cm4sR dtP8ejJ3D+IqmuYQNCKxr/Vgf1F7EEYQwevmd6mp3Z/A/4D6ksM0pmQohlzCpIDhRCj2 SV/vvGHIAyIhA5BxIocWzZha6ka4Ih8LjlIdDRNCV7St5iU61p0Tq11iz6hZsF0quT28 i7LCM0L21tDmPhI9GHNjEj51Z8VC081AY/fXl8shz8Zcl6MoLK/DyqAza1YPNkUGZd2e E9awctQZIhAotE7t4QTSxpm38lxtsg8A5HREJ4Cgwd/oEV3ZwZGCsbcUOA/NbR9XWbQR I3qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Njnf5muZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si3309232edj.174.2020.04.28.14.07.51; Tue, 28 Apr 2020 14:08:33 -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=@gmail.com header.s=20161025 header.b=Njnf5muZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726284AbgD1VHs (ORCPT + 99 others); Tue, 28 Apr 2020 17:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726274AbgD1VHs (ORCPT ); Tue, 28 Apr 2020 17:07:48 -0400 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29AD9C03C1AC for ; Tue, 28 Apr 2020 14:07:47 -0700 (PDT) Received: by mail-ot1-x342.google.com with SMTP id e26so35397144otr.2 for ; Tue, 28 Apr 2020 14:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/gUQZIHD+k3WI82+sRa1/EBE1hnpwMzmqhFoAyagTyQ=; b=Njnf5muZnVbUTZcIiJIMHuxA622phNteq2XgThGVLHni/JZhY1NL6zqqHSLponPg7t UrRxs/d+CfVydSOXJiMPFdwtZ53/aaLHHXT1fQoTgndKXjy3F0mjJy9GLiiPhQUKhs74 nbH+j7dyuftkfsDs8eZwCrxJ4yc/toOpOO4bH+6vyoEOlA0+4M/kR1j373DrhTiC+IpQ ZE1Dqn18hFj2R0m8boSEz5BpbIbwvmWPxeZLpwpvO5feopqGBiV55Jk5i2iVfUnKr692 zy4oKSdO52eAyC0jqkgRzIV0bsqkH/5R7eLhRi3v5gDUXkHxb+Eia9Sc8aN9SNlmk73j BI9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/gUQZIHD+k3WI82+sRa1/EBE1hnpwMzmqhFoAyagTyQ=; b=Oc0+RhviyHvAt3NeLfSvC5nkZ9K9y+q50Q33KnpaSmuy9Swybh4ibyNkXbD/xSe6GM UZElthMUwLhaI4Jc9AlK7alHYYnT0EbWOw9InndikuwpDr2+7fJUoPqv4uuy94+SSx4a 6O717IfFgyDiXetYCmqM0cGPp4P7CDyvNiMQN0Qd3gfUYNJA6SmeyzrQW4uTiwQ+A/la kC7L6GrVGyATJEZ7lUi04pIfaf0vbawW1OeMpfZWbngytoUWq+Me7uodx/h1p9sSfXz4 RYI2mubBwPHpLs4yT0zGPHwCCpeIw7r8t9kD22k9p7hcCzKnpA0Qyl/rhTHCklxbf1Cr vWRw== X-Gm-Message-State: AGi0PuYCIy7FeiXenSPyXeo5jHHeuPImNsTngye3/nA+X8Y+SOhYXfeN OYiyZmR7GtFqTKiMOE1LUJBp293aO4ugcfTAJ+L+ViYW X-Received: by 2002:a9d:7a98:: with SMTP id l24mr25057712otn.79.1588108066365; Tue, 28 Apr 2020 14:07:46 -0700 (PDT) MIME-Version: 1.0 References: <20200427150153.17055-1-david@lechnology.com> <35f37936-e737-ac35-c538-9447a00d1cbc@lechnology.com> <685ddf1b-c824-9c45-298f-97b70cbf975f@lechnology.com> In-Reply-To: <685ddf1b-c824-9c45-298f-97b70cbf975f@lechnology.com> From: Luiz Augusto von Dentz Date: Tue, 28 Apr 2020 14:07:34 -0700 Message-ID: Subject: Re: [PATCH BlueZ v2] src/gatt-client: always check properties in WriteValue To: David Lechner Cc: "linux-bluetooth@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi David, On Tue, Apr 28, 2020 at 10:19 AM David Lechner wrote: > > On 4/28/20 12:03 PM, Luiz Augusto von Dentz wrote: > > Hi David, > > > > On Tue, Apr 28, 2020 at 7:39 AM David Lechner wrote: > >> > >> On 4/27/20 11:28 AM, Luiz Augusto von Dentz wrote: > >>> Hi David, > >>> > >>> On Mon, Apr 27, 2020 at 8:07 AM David Lechner wrote: > >>>> > >>>> This modifies the GATT client characteristic WriteValue D-Bus method to > >>>> always check that the characteristic supports the requested type of > >>>> write by checking for the corresponding property before attempting to > >>>> write. > >>>> > >>>> Before this change, if the "type" option was used and it was set to > >>>> "reliable" or "request", then BlueZ would attempt the write even if the > >>>> characteristic does not support that write type. On the other hand, if > >>>> "type" was set to "command" or was not specified, the method would > >>>> return a org.bluez.Error.NotSupported error without attempting to write. > >>>> > >>>> After this change, the WriteValue method will consistently return > >>>> org.bluez.Error.NotSupported if the corresponding property flag is not > >>>> set for all types of writes. > >>>> --- > >>>> > >>>> v2 changes: > >>>> - remove extra check of test variable not NULL > >>>> - fix one line over 80 chars > >>>> > >>>> src/gatt-client.c | 8 ++++---- > >>>> 1 file changed, 4 insertions(+), 4 deletions(-) > >>>> > >>>> diff --git a/src/gatt-client.c b/src/gatt-client.c > >>>> index a9bfc2802..f80742fbb 100644 > >>>> --- a/src/gatt-client.c > >>>> +++ b/src/gatt-client.c > >>>> @@ -1016,8 +1016,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn, > >>>> * - If value is larger than MTU - 3: long-write > >>>> * * "write-without-response" property set -> write command. > >>>> */ > >>>> - if ((!type && (chrc->ext_props & BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE)) > >>>> - || (type && !strcasecmp(type, "reliable"))) { > >>>> + if ((!type || !strcasecmp(type, "reliable")) && chrc->ext_props & > >>>> + BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE) { > >>>> supported = true; > >>>> chrc->write_op = start_long_write(msg, chrc->value_handle, gatt, > >>>> true, value, value_len, offset, > >>>> @@ -1026,8 +1026,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn, > >>>> return NULL; > >>>> } > >>>> > >>>> - if ((!type && chrc->props & BT_GATT_CHRC_PROP_WRITE) || > >>>> - (type && !strcasecmp(type, "request"))) { > >>>> + if ((!type || !strcasecmp(type, "request")) && chrc->props & > >>>> + BT_GATT_CHRC_PROP_WRITE) { > >>>> uint16_t mtu; > >>>> > >>>> supported = true; > >>>> -- > >>>> 2.17.1 > >>> > >>> As far I can remember this is on purpose so the application can > >>> overwrite the type if it needs to disabling the checks on the client > >>> side, though the kernel can still return not supported, so if we want > >>> to change this it will now not be possible to overwrite it anymore. > >>> > >> > >> If this is the case, does it make sense to make the following change > >> instead so that write without response can also be forced? > >> > >> diff --git a/src/gatt-client.c b/src/gatt-client.c > >> index f80742fbb..3153f571f 100644 > >> --- a/src/gatt-client.c > >> +++ b/src/gatt-client.c > >> @@ -1050,8 +1050,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn, > >> return NULL; > >> } > >> > >> - if ((type && strcasecmp(type, "command")) || offset || > >> - !(chrc->props & BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP)) > >> + if ((type && strcasecmp(type, "command")) || offset || (!type && > >> + !(chrc->props & BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP))) > >> goto fail; > >> > >> supported = true; > > > > Yes, that is probably one of the use cases to use the type to force > > sending a command if the client don't care about the response but the > > server don't mark write without response as supported, is that what > > you are after? That sounds like a bug since it appears the intention > > was to allow commands all along. > > > > I just noticed the inconsistency here while trying to implement > writeValueWithResponse() and writeValueWithoutResponse() in the Web > Bluetooth API for the Chromium browser and thought that it should > probably all be one way or the other. > > FWIW, in the particular case I am working with, the device has both > the WRITE and WRITE_WITHOUT_RESP properties set so I am using "type" > to force writing without response since write with response would > be selected otherwise. > > I will send a proper patch to fix the write without response case. Great, that indeed shall be supported since both are allowed bluetoothd will prefer Write since that gives a response, there is also some means to mark the D-Bus message don't expect a reply as well which might be another to solve this if you don't want to use type. -- Luiz Augusto von Dentz