Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp495528pxb; Sat, 20 Feb 2021 10:33:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJzA1pC2dVg0r5Y5VOqQbn7cEnCfFDHJ9RBg8rmmLwg0krRCTVf4sAlefD/K8NSmiWKpsrnW X-Received: by 2002:a17:907:212e:: with SMTP id qo14mr8659014ejb.515.1613845980245; Sat, 20 Feb 2021 10:33:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1613845980; cv=pass; d=google.com; s=arc-20160816; b=UUAg5XZvvKYbOPw9lC1idbilmD662od6P3XJJMHssHDaknnx3r90Su8CAP5io6+qMM QJC0lMhkTb/5jTjXRrPwYpZqsRc3FEWz4Q0/7aKdaNN4OElWb8k5vmhQdpolPdObcoUv FBnhXMGmoRWiYw31VHOyYw1Ox7CbxtHQ+FX5jWAUrs3r1rScFZb+hacwCmMmmPcz2rHL 4lGAX9sskFIQw2FyGbyStXuRcrUKcfldJZGnuVrtwt0HohBtn7xNeUrWbOjfc3kngY8L NSXXk++IKsJwURX1SkCHm9y+y2QuOBmwv5e1dDrOZdw/+n7muM8A6bJlxjrYhdlNpQC/ K0UQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:importance:content-transfer-encoding :mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:dkim-signature; bh=rRhQtiWk51jpuy35q3+uzYRQLr7ZHkarY/NyMX8/K+Q=; b=LBH2b/PdvAHSU2eJ704gO6gv/6sABGOaDpRH7LFyjSZH7FK8+ugSsdnO9+MWiVhp9m jDsDyo1bzXZbSAppAIIKpAJJU7OwB6Ztxa+wjhrC1ziq9zmVMOU7yCKE3jFgPipJC3gM ydVUBmp+JgvxmeqKp15aERgtq9uxry35bmv+DaFv5GAfFI4XblfxYHtB+SgKBH/67ic7 AIPyQCONd1xzEkNy9XO+GtG/9j8nsPh/Rg4pfJmyl5AWGGIKAN5CBkaWVhj87kxVeeNQ 4mjGrEH1ESfrhZqhc5d+0Yibz/A/aJtq1npC8hUU6Wex0Q9r+prgPAbbPy9BHQLlw7DS asFw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@maves.io header.s=dkim header.b=JReoVEUL; arc=pass (i=1 spf=pass spfdomain=maves.io dkim=pass dkdomain=maves.io dmarc=pass fromdomain=maves.io>); 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 c18si8441052ede.4.2021.02.20.10.32.17; Sat, 20 Feb 2021 10:33:00 -0800 (PST) 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=@maves.io header.s=dkim header.b=JReoVEUL; arc=pass (i=1 spf=pass spfdomain=maves.io dkim=pass dkdomain=maves.io dmarc=pass fromdomain=maves.io>); 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 S229796AbhBTS34 (ORCPT + 99 others); Sat, 20 Feb 2021 13:29:56 -0500 Received: from sender4-op-o13.zoho.com ([136.143.188.13]:17366 "EHLO sender4-op-o13.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbhBTS34 (ORCPT ); Sat, 20 Feb 2021 13:29:56 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1613845752; cv=none; d=zohomail.com; s=zohoarc; b=ZLsQLj54eKD9wyIWUQlb+L1zmdi9mZDHa2oWNYh+Il5YzxIcOsC3RkhAfgZ3cw0SLwjByKoX0+42Kyk29MHj5Ss0ssiQ0HajFif9eIWwsIegjFZewHBMfaggX+frHLDjEGUEq2J3pjFYbcyacEkiEEWXhUO9N0iYQKNpCfspSaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613845752; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=rRhQtiWk51jpuy35q3+uzYRQLr7ZHkarY/NyMX8/K+Q=; b=GyjGEyA3IjlQNmuKNTEN0XLu7bIQiEFzn8XAPKyDgvrAOGvAzvgqvnOpXqR5Wb9HVyTPUA4Xbh7T/qf+T/2QxBJqPdMHklgvdJPjptPKbMjpevQk3ZBz8UTiX8P8a7klfnJg9+c/1T23nProkZQFKnXZ0fc/iNANx632kamXMBg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=maves.io; spf=pass smtp.mailfrom=curtis@maves.io; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1613845752; s=dkim; d=maves.io; i=curtis@maves.io; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=rRhQtiWk51jpuy35q3+uzYRQLr7ZHkarY/NyMX8/K+Q=; b=JReoVEULD0Z+y5IJZbEwx/ELfz280zEhEJr4xkE0dx1BfiHKTluPKQ4ehAqNBUiU EPnhHjlPaVwTNagvb2TRlJZ4UeYfe1OkTDpSzdaZISWRRQ2qQG1ISzLFs7khRs78z62 KdaTGVMIt7bNIH32dK6Ah2d/HOvfKv0306qd3ETU= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1613845750588639.8066717646923; Sat, 20 Feb 2021 10:29:10 -0800 (PST) Date: Sat, 20 Feb 2021 13:29:10 -0500 From: Curtis Maves To: "Luiz Augusto von Dentz" Cc: "linux-bluetooth@vger.kernel.org" Message-ID: <177c0b3e32a.c0b69e35170119.443115256308628377@maves.io> In-Reply-To: References: <20210219174946.599144-1-curtis@maves.io> <177bd04559f.d1a7c05c116102.319856870975137121@maves.io> Subject: Re: [PATCH BlueZ] gatt-database: Fix notifying on indicatable attr MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Luiz, ---- On Sat, 20 Feb 2021 01:07:57 -0500 Luiz Augusto von Dentz wrote ---- > Hi Curtis, > > On Fri, Feb 19, 2021 at 5:18 PM Curtis Maves wrote: > > > > Hi Luiz, > > ---- On Fri, 19 Feb 2021 19:55:06 -0500 Luiz Augusto von Dentz wrote ---- > > > > > Hi Curtis, > > > > > > On Fri, Feb 19, 2021 at 10:11 AM Curtis wrote: > > > > > > > > When a local GATT characteristic has both the indicate and notify > > > > properties, notifications will not be send to clients requesting them. > > > > This change fixes this, allowing for notifications to be sent. > > > > > > > > Also simplifies logic about when notifications/indications should > > > > be sent. > > > > --- > > > > src/gatt-database.c | 15 ++++++--------- > > > > 1 file changed, 6 insertions(+), 9 deletions(-) > > > > > > > > diff --git a/src/gatt-database.c b/src/gatt-database.c > > > > index d635c3214..bd5864bcd 100644 > > > > --- a/src/gatt-database.c > > > > +++ b/src/gatt-database.c > > > > @@ -1344,10 +1344,7 @@ static void send_notification_to_device(void *data, void *user_data) > > > > } > > > > > > > > ccc = find_ccc_state(device_state, notify->ccc_handle); > > > > - if (!ccc) > > > > - return; > > > > - > > > > - if (!ccc->value || (notify->conf && !(ccc->value & 0x0002))) > > > > + if (!ccc || !(ccc->value & 0x0003)) > > > > return; > > > > > > > > device = btd_adapter_find_device(notify->database->adapter, > > > > @@ -1374,7 +1371,7 @@ static void send_notification_to_device(void *data, void *user_data) > > > > * TODO: If the device is not connected but bonded, send the > > > > * notification/indication when it becomes connected. > > > > */ > > > > - if (!notify->conf) { > > > > + if (!(ccc->value & 0x0002)) { > > > > DBG("GATT server sending notification"); > > > > bt_gatt_server_send_notification(server, > > > > notify->handle, notify->value, > > > > @@ -2415,8 +2412,8 @@ static bool sock_io_read(struct io *io, void *user_data) > > > > gatt_db_attribute_get_handle(chrc->attrib), > > > > buf, bytes_read, > > > > gatt_db_attribute_get_handle(chrc->ccc), > > > > - chrc->props & BT_GATT_CHRC_PROP_INDICATE ? > > > > - conf_cb : NULL, chrc->proxy); > > > > + conf_cb, > > > > + chrc->proxy); > > > > > > Not why are you changing this code to always set the conf_cb? This > > > would then always send indication rather then notifications: > > > > > > https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/gatt-database.c#n1387 > > > > > > We might need to check what value it stored in the ccc state if both > > > indication and notification is supported. > > > > > > > > > > > return true; > > > > } > > > > @@ -2725,8 +2722,8 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name, > > > > gatt_db_attribute_get_handle(chrc->attrib), > > > > value, len, > > > > gatt_db_attribute_get_handle(chrc->ccc), > > > > - chrc->props & BT_GATT_CHRC_PROP_INDICATE ? > > > > - conf_cb : NULL, proxy); > > > > + conf_cb, > > > > + proxy); > > > > } > > > > > > > > static bool database_add_ccc(struct external_service *service, > > > > -- > > > > 2.30.1 > > > > > > > > > > > > > > > > > -- > > > Luiz Augusto von Dentz > > > > > > > This patch changes the if-statement around sending notifications to check that the > > ccc->value is not indicating rather than checking if conf_cb (notify->conf) is null. > > This change makes unnecessary to conditionally pass the conf_cb. It's now simpler to always pass it. > > What Im saying is that we can't do this: > > if (!notify->conf) { > DBG("GATT server sending notification"); > > conf callback will always be set so instead we need to change that to: > > if (ccc->value != 0x02) > > > > > -- > > Curtis Maves > > > > -- > Luiz Augusto von Dentz > I agree that we can no longer do the following on line 1377: > if (!notify->conf) { > DBG("GATT server sending notification"); As you said the ccc value needs to be tested instead. This part of the patch already makes a change similar to what you suggested: > > > > @@ -1374,7 +1371,7 @@ static void send_notification_to_device(void *data, void *user_data) > > > > * TODO: If the device is not connected but bonded, send the > > > > * notification/indication when it becomes connected. > > > > */ > > > > - if (!notify->conf) { > > > > + if (!(ccc->value & 0x0002)) { Is there anywhere else where notify->conf is checked? I looked around but did not find any on my own. -- Curtis Maves