Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2385076pxb; Tue, 13 Apr 2021 00:05:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTAPSLfcd7Vl4GmaoUeKrU6B/i+IcvYyj4Y1uNyICeSRp0a6uCoK6xqGtlsAwW5sY41CwN X-Received: by 2002:a05:6a00:248f:b029:244:7ae0:ba2c with SMTP id c15-20020a056a00248fb02902447ae0ba2cmr24037520pfv.49.1618297548160; Tue, 13 Apr 2021 00:05:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1618297548; cv=pass; d=google.com; s=arc-20160816; b=KorY1lREjnnr8qR2xLmtRhhS/uFrnod4QldZ0wTUFdN6DjRhNjf8NG4SRjyuwLcedw MG7yYOViwlgQfk+8PuZ6LeassVkQ6AGERqTBMZujQCULf5DRHqCHBb1FlQd9TselCe0v BTXb3e7lZpYDeHkpgq+AdCizh3MgLWIVCVWUigzdOFbJdt7Eb1XJWACneEAglbeDBktt mCCgC1nhFeasS1YJslQNTo7gVmlAln5+ybgL0Ft9TENkVuO5Wd65OcBTDt9Z/YuEfz++ tKyX3PRlxVOejPk810W97L2t+HuZ33htu7NWnHCxVjjwy2KWvd2YPUdmCib8jRxU2ieI yVkg== ARC-Message-Signature: i=2; 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=GjFl7TQkTCGqxAZckifq9fw2B/wpPtWZ1Y9gUPlpq5k=; b=LkOBwtrCO42lt6Ycbr2u6+uSfaTdyQv0s3ehN5hDNU02cr3KQe5Qzi6hGussSJOFLg LBBhnWHv+tc7qYTcmG5byuMefi2Nx3yXIr717LwZhd8sDR5pZj1zW5yaH1R/rlWpQ/6M aiVdozWy278pt7KyRrk8nki3MdNEveTaU3xwtDhxrr11OVWks9PXrRXful/B+rxMcjoL ETsrX04VQsqHJrZwGUFJ4aOSq7d64nxzC5c8PiXEa0mIT+ppPy2J61XPaz/drgCyxTZs SB5kAFiQR7zw2ehc5oTZsyUj9JDej5xQD00bVCm+Steu0TmDygFTR4LvMzjoodigbnQm 40UQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@maves.io header.s=dkim header.b=M8nrjiDa; 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 m9si16835665plt.7.2021.04.13.00.05.33; Tue, 13 Apr 2021 00:05:48 -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=@maves.io header.s=dkim header.b=M8nrjiDa; 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 S239016AbhDLUfG (ORCPT + 99 others); Mon, 12 Apr 2021 16:35:06 -0400 Received: from sender4-op-o13.zoho.com ([136.143.188.13]:17390 "EHLO sender4-op-o13.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238066AbhDLUfF (ORCPT ); Mon, 12 Apr 2021 16:35:05 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1618259686; cv=none; d=zohomail.com; s=zohoarc; b=Bw2swC3nRLw1LjxN7XnibNpYQ9zLoxFz0HJkS2O4tQ6kENpwD3aHgOEj61XYFB8xN+Guus8WgZurhVINIqhL4P7nOg9n+4pjteypTtnpCGWHLPX+87nejuSsJtrVmxtuM5KeYMv/u6R7ZBAEBU/effa69AR1QfidLF/6v4PfZ48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618259686; h=Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=GjFl7TQkTCGqxAZckifq9fw2B/wpPtWZ1Y9gUPlpq5k=; b=HTcGKGNbEtiRQdwtaisvMHKclrWX6XbEdXCvjqCDbmVRCQZ2qFBdQGtHa8Lv1XtFMtB21+zyRqbJGMJL7XV3uybXw81XsMpmTRIR4Yvy6p0nNAhxxwNywTQxCPsvBZ+O78tOQMkCfBoIcOwwkJXzmyYthKUTg94jJP2Y3qFAMtA= 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=1618259686; s=dkim; d=maves.io; i=curtis@maves.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Transfer-Encoding; bh=GjFl7TQkTCGqxAZckifq9fw2B/wpPtWZ1Y9gUPlpq5k=; b=M8nrjiDaOm64Jhj8ciMtdaMnisUjDzlZV6jz52mAu0QPaxNk0EFVs4lyUAsigtaf RbNFy/Vzvf7ozob+emjFBLBcbklf8iVCNsom1PAMILcnBp/ga8UdUEe4oqQ4cKl9/rU VGUidbVTLG8h9ZXM5Wm9oD7GNo/nZJXOcGTx5RxI= Received: from maves-arch-laptop.attlocal.net (107-216-162-79.lightspeed.iplsin.sbcglobal.net [107.216.162.79]) by mx.zohomail.com with SMTPS id 1618259683082683.5709696986727; Mon, 12 Apr 2021 13:34:43 -0700 (PDT) From: Curtis Maves To: linux-bluetooth@vger.kernel.org Cc: Curtis Maves Subject: [PATCH Bluez v2] gatt: Either notify or indicate, do not do both Date: Mon, 12 Apr 2021 16:34:26 -0400 Message-Id: <20210412203426.213872-1-curtis@maves.io> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-ZohoMailClient: External Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org AcquireNotify and StartNotify starts notifications and/or indications by whether the characteristic supports them. Before this patch, if both were supported, Bluez would try to start both simultaneously. This patch changes this behavior so if both are supported, only notifications are started. Test cases have also be updated accordingly. --- src/shared/gatt-client.c | 10 +++++----- unit/test-gatt.c | 43 +++++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index 4e10f244d..9511ea8ca 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -1585,20 +1585,20 @@ static bool notify_data_write_ccc(struct notify_data *notify_data, bool enable, { uint8_t pdu[4]; unsigned int att_id; + uint16_t properties = notify_data->chrc->properties; assert(notify_data->chrc->ccc_handle); memset(pdu, 0, sizeof(pdu)); put_le16(notify_data->chrc->ccc_handle, pdu); if (enable) { - /* Try to enable notifications and/or indications based on + /* Try to enable notifications or indications based on * whatever the characteristic supports. */ - if (notify_data->chrc->properties & BT_GATT_CHRC_PROP_NOTIFY) + if (properties & BT_GATT_CHRC_PROP_NOTIFY) pdu[2] = 0x01; - - if (notify_data->chrc->properties & BT_GATT_CHRC_PROP_INDICATE) - pdu[2] |= 0x02; + else if (properties & BT_GATT_CHRC_PROP_INDICATE) + pdu[2] = 0x02; if (!pdu[2]) return false; diff --git a/unit/test-gatt.c b/unit/test-gatt.c index 4aa87d09c..6a47268e6 100644 --- a/unit/test-gatt.c +++ b/unit/test-gatt.c @@ -241,8 +241,8 @@ struct context { #define CHARACTERISTIC_DISC_SMALL_DB \ raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x03, 0x28), \ raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29, \ - 0x2a), \ - raw_pdu(0x08, 0x03, 0x00, 0xff, 0xff, 0x03, 0x28), \ + 0x2a, 0x07, 0x00, 0x22, 0x08, 0x00, 0x28, 0x2a),\ + raw_pdu(0x08, 0x08, 0x00, 0xff, 0xff, 0x03, 0x28), \ raw_pdu(0x09, 0x07, 0x12, 0xf0, 0x02, 0x13, 0xf0, 0x00, \ 0x2a), \ raw_pdu(0x08, 0x13, 0xf0, 0xff, 0xff, 0x03, 0x28), \ @@ -256,11 +256,17 @@ struct context { raw_pdu(0x01, 0x08, 0x18, 0xf0, 0x0a) #define DESCRIPTOR_DISC_SMALL_DB \ - raw_pdu(0x04, 0x04, 0x00, 0x10, 0x00), \ + raw_pdu(0x04, 0x04, 0x00, 0x06, 0x00), \ raw_pdu(0x05, 0x01, 0x04, 0x00, 0x02, 0x29, 0x05, 0x00, \ 0x01, 0x29), \ - raw_pdu(0x04, 0x06, 0x00, 0x10, 0x00), \ - raw_pdu(0x01, 0x04, 0x06, 0x00, 0x0a), \ + raw_pdu(0x04, 0x06, 0x00, 0x06, 0x00), \ + raw_pdu(0x05, 0x01, 0x06, 0x00, 0x00, 0x29), \ + raw_pdu(0x0a, 0x06, 0x00), \ + raw_pdu(0x0b, 0x01, 0x00), \ + raw_pdu(0x04, 0x09, 0x00, 0x10, 0x00), \ + raw_pdu(0x05, 0x01, 0x09, 0x00, 0x02, 0x29), \ + raw_pdu(0x04, 0x0a, 0x00, 0x10, 0x00), \ + raw_pdu(0x01, 0x04, 0x0a, 0x00, 0x0a), \ raw_pdu(0x04, 0x16, 0xf0, 0x16, 0xf0), \ raw_pdu(0x05, 0x01, 0x16, 0xf0, 0x00, 0x29), \ raw_pdu(0x0a, 0x16, 0xf0), \ @@ -1565,6 +1571,13 @@ static struct gatt_db *make_test_spec_small_db(void) "Manufacturer Name"), DESCRIPTOR(GATT_CHARAC_EXT_PROPER_UUID, BT_ATT_PERM_READ, 0x01, 0x00), + CHARACTERISTIC_STR(GATT_CHARAC_SOFTWARE_REVISION_STRING, + BT_ATT_PERM_READ, + BT_GATT_CHRC_PROP_READ | + BT_GATT_CHRC_PROP_INDICATE, + "5.59"), + DESCRIPTOR(GATT_CLIENT_CHARAC_CFG_UUID, BT_ATT_PERM_READ + | BT_ATT_PERM_WRITE, 0x00, 0x00), PRIMARY_SERVICE(0xF010, GAP_UUID, 9), INCLUDE(0x0001), @@ -2308,7 +2321,7 @@ static void test_indication(struct context *context) } static const struct test_step test_indication_1 = { - .handle = 0x0003, + .handle = 0x0008, .func = test_indication, .value = read_data_1, .length = 0x03, @@ -2573,9 +2586,10 @@ int main(int argc, char *argv[]) raw_pdu(0x03, 0x00, 0x02), raw_pdu(0x08, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x28), raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29, - 0x2a), - raw_pdu(0x08, 0x03, 0x00, 0x0f, 0x00, 0x03, 0x28), - raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a)); + 0x2a, 0x07, 0x00, 0x22, 0x08, 0x00, + 0x28, 0x2a), + raw_pdu(0x08, 0x08, 0x00, 0x0f, 0x00, 0x03, 0x28), + raw_pdu(0x01, 0x08, 0x08, 0x00, 0x0a)); define_test_server("/TP/GAD/SR/BV-04-C/large-1", test_server, ts_large_db_1, NULL, @@ -2626,9 +2640,10 @@ int main(int argc, char *argv[]) raw_pdu(0x03, 0x00, 0x02), raw_pdu(0x08, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x28), raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29, - 0x2a), - raw_pdu(0x08, 0x03, 0x00, 0x0f, 0x00, 0x03, 0x28), - raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a)); + 0x2a, 0x07, 0x00, 0x22, 0x08, 0x00, + 0x28, 0x2a), + raw_pdu(0x08, 0x08, 0x00, 0x0f, 0x00, 0x03, 0x28), + raw_pdu(0x01, 0x08, 0x08, 0x00, 0x0a)); define_test_server("/TP/GAD/SR/BV-05-C/large-1", test_server, ts_large_db_1, NULL, @@ -3241,7 +3256,7 @@ int main(int argc, char *argv[]) &test_notification_1, CLIENT_INIT_PDUS, SMALL_DB_DISCOVERY_PDUS, - raw_pdu(0x12, 0x04, 0x00, 0x03, 0x00), + raw_pdu(0x12, 0x04, 0x00, 0x01, 0x00), raw_pdu(0x13), raw_pdu(), raw_pdu(0x1B, 0x03, 0x00, 0x01, 0x02, 0x03)); @@ -3267,7 +3282,7 @@ int main(int argc, char *argv[]) &test_indication_1, CLIENT_INIT_PDUS, SMALL_DB_DISCOVERY_PDUS, - raw_pdu(0x12, 0x04, 0x00, 0x03, 0x00), + raw_pdu(0x12, 0x09, 0x00, 0x02, 0x00), raw_pdu(0x13), raw_pdu(), raw_pdu(0x1D, 0x03, 0x00, 0x01, 0x02, 0x03), -- 2.31.1