Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp139612rwn; Fri, 16 Sep 2022 17:05:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7xBoleFs4Xg9QcyaLRZT4Fqs0zPq95dDjzJ7D3SOE++9MeDIR2BBXpYM9vXTVJQyZi0+2z X-Received: by 2002:a17:906:8463:b0:771:a3d2:7c3 with SMTP id hx3-20020a170906846300b00771a3d207c3mr4850109ejc.592.1663373154352; Fri, 16 Sep 2022 17:05:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663373154; cv=none; d=google.com; s=arc-20160816; b=uZrXjZ9wXSCIvY9jE1tCJDXgxSWkY0sj7xWoA2qT9PfzNrPmHrHVPU0xOh1AbXr6pi JRhca43YIW8gnmzZstTKQlB8vnEbijN/KwoeT6FVcyO76w6dcMZjPK4j592v7XPrSzZx YCp/yKyNYtu5osb3pmDYd/U8wHKrRKtF30ogZL+KOBhWMREnQpzkDoRrkyUDm8qBwQ/G fPtiW5wu62qVneTEGjf4PE2BUt3Z7Xbq5lDcIWc+Sb6F9JfzgxWnDxswZSfD2C70NZiu 2Xj9/fe6ii2q3jiC28u3lSognFS8rMghec1hgoM+4afRGMpzIF3VUbgBjBoyEaz9Q6se WBuw== 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:to:from:dkim-signature; bh=Vtv/gTubTymgj1pIDsSVd0kQO6l8mBkVJW14q0tTnrs=; b=Qr0VcCppbgevMOzn1bNbNXCGeYCDjHeClmsa8DFeD3mvE1z6JLVn2hNTF0Jt7n9ghv 8i3KU3wTNEGVMxdE7G5fuYUew+nHrXK9h7ZfLUj4oFS2i0GgMUyMPQfI5uGXNlNGps5X gQPaQ7kYzZ+d5+IbPq0Vev34Mooaf+zBe8YOR6Y24TMmJS5Xk1uMJPtfQ0QDXZW4k9dW HI0pwuJeM0ZkcSDi5tnRUJZeVjPzBHWTJmCxsAWkgzJUuB4Pr55J21yDuAAeK7toBHEe olORHjIMt7Gs7qJgWMHkpZ4pRskziD1MpE+3/we+ZbB2e6Z85Htmvv7lqUFlvTwZheRn zJaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=c60c3YDl; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa11-20020a1709076d0b00b007413f3f0acbsi8641857ejc.357.2022.09.16.17.04.56; Fri, 16 Sep 2022 17:05:54 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=c60c3YDl; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbiIPXqL (ORCPT + 99 others); Fri, 16 Sep 2022 19:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbiIPXqI (ORCPT ); Fri, 16 Sep 2022 19:46:08 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7029B99CC for ; Fri, 16 Sep 2022 16:46:07 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id b23so22653618pfp.9 for ; Fri, 16 Sep 2022 16:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=Vtv/gTubTymgj1pIDsSVd0kQO6l8mBkVJW14q0tTnrs=; b=c60c3YDlRMy1PWELzicIXLNN6Ikl/YqYUwCjwcH56AToWFlQKI7uq06ks4qxh0Pw+8 cwNvDBn9HxhswY0SXFveyZfcZvpZ3c2bC5DtlKBUbM0RoEIBpk5UNiWKFJvYvD/TipGz DMjU09C5OzH+M6eH1hsSstkDiAM2B5lgqvlBg1zOXhVVkCZS8cbk0wf3/w2oTcxRFJmn iKRHpbVuxDzt9qactrR7lNZJ3PrOQC/uf0PHBz7J73nVt08FPXXFzp1nGs1jXgZnhsF1 8XhR4+2YgevFbPxueju5myJ64zJNQZQW/Hm8Q2cLe/6Vt8pVCCNQ+B7mOR3CZl6Kmf4A RWuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=Vtv/gTubTymgj1pIDsSVd0kQO6l8mBkVJW14q0tTnrs=; b=5aqF2AeTHOcyElgKshcA9c/Et+WWoQgmvq8Oz6d20iQ35kcRnQfAlIkBZKcc+woBi2 xy01+umlVeVD3VUmmBdnA5hbUT7UkevwC5w6+nC9/Wk3hHe6nA3cN67mAO6jliACFiEi QLGnYS9rMmgGNgHkVcwyIbkamiajaUhAUDTqf3eTbP+sE5A9Em8BeJbIGznAMJ9fziP4 Fl3up6m8ifVQC0B9CvdbY1x2VpIufcXVY4lH6g3tGC4f4oHf4bsMLcA1bbICAQ6FgYve H0Y2qwJtVzWLY5sc1ddXWfXT09r9MkB9znepMfJ9k7srqYji4Pa4FISXLrSnt0oU1Hh+ +7Cg== X-Gm-Message-State: ACrzQf2TOxJwtKr8jPG/jcRMn/4kRlauIa9oAQXsJ9TpeziwjGEunPGa ukkPe4giGaCggxY0BxrTijDuddUdh0c= X-Received: by 2002:a62:a512:0:b0:536:e2bd:e15e with SMTP id v18-20020a62a512000000b00536e2bde15emr7402823pfm.1.1663371966688; Fri, 16 Sep 2022 16:46:06 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id jm15-20020a17090304cf00b00177ff4019d9sm15398059plb.274.2022.09.16.16.46.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 16:46:06 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] shared/gatt-client: Make use of gatt_db_attribute_get_ccc Date: Fri, 16 Sep 2022 16:46:04 -0700 Message-Id: <20220916234604.1156551-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 From: Luiz Augusto von Dentz This makes use of gatt_db_attribute_get_ccc to locate a CCC of a given attribute. --- src/shared/gatt-client.c | 41 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index ba9228ddf3f4..45b6ed92fde1 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -211,22 +211,6 @@ static void notify_data_unref(void *data) free(notify_data); } -static void find_ccc(struct gatt_db_attribute *attr, void *user_data) -{ - struct gatt_db_attribute **ccc_ptr = user_data; - bt_uuid_t uuid; - - if (*ccc_ptr) - return; - - bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID); - - if (bt_uuid_cmp(&uuid, gatt_db_attribute_get_type(attr))) - return; - - *ccc_ptr = attr; -} - static bool match_notify_chrc(const void *data, const void *user_data) { const struct notify_data *notify_data = data; @@ -273,24 +257,25 @@ static void chrc_removed(struct gatt_db_attribute *attr, void *user_data) } static struct notify_chrc *notify_chrc_create(struct bt_gatt_client *client, - uint16_t value_handle) + uint16_t handle) { struct gatt_db_attribute *attr, *ccc; struct notify_chrc *chrc; - bt_uuid_t uuid; + uint16_t value_handle; uint8_t properties; - /* Check that chrc_value_handle belongs to a known characteristic */ - attr = gatt_db_get_attribute(client->db, value_handle - 1); + /* Check that there is an attribute with handle */ + attr = gatt_db_get_attribute(client->db, handle); if (!attr) return NULL; - bt_uuid16_create(&uuid, GATT_CHARAC_UUID); - if (bt_uuid_cmp(&uuid, gatt_db_attribute_get_type(attr))) + if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle, + &properties, NULL, NULL)) return NULL; - if (!gatt_db_attribute_get_char_data(attr, NULL, NULL, &properties, - NULL, NULL)) + /* Check that there is an attribute with value_handle */ + attr = gatt_db_get_attribute(client->db, value_handle); + if (!attr) return NULL; chrc = new0(struct notify_chrc, 1); @@ -301,13 +286,7 @@ static struct notify_chrc *notify_chrc_create(struct bt_gatt_client *client, return NULL; } - /* - * Find the CCC characteristic. Some characteristics that allow - * notifications may not have a CCC descriptor. We treat these as - * automatically successful. - */ - ccc = NULL; - gatt_db_service_foreach_desc(attr, find_ccc, &ccc); + ccc = gatt_db_attribute_get_ccc(attr); if (ccc) chrc->ccc_handle = gatt_db_attribute_get_handle(ccc); -- 2.37.3