From patchwork Mon Mar 14 21:50:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 552661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD606C433F5 for ; Mon, 14 Mar 2022 21:50:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245396AbiCNVv3 (ORCPT ); Mon, 14 Mar 2022 17:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236193AbiCNVv2 (ORCPT ); Mon, 14 Mar 2022 17:51:28 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58030344CE for ; Mon, 14 Mar 2022 14:50:18 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id s42so16352340pfg.0 for ; Mon, 14 Mar 2022 14:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=qOAzIAGITBNGyHFTZ7Cmq/ShOyrjrDEaYD2HgQ928xA=; b=DLYCCBHwiNA5sjj3uvWwFKxvEiTB0jetmihNzm67O409zkWwRO48S4VDNj183TGhBz HMCnDIGgruSeuktVZg7obi6p4q+veP7iHNkLshZijvIrZcnbOaBr0ILMmRtDh0TCJ5Ip qhnwNgEExppuPFN/fZU4qL07RoCAByPUoDCDMnXvvJz8Yc2kxniFSRWvnzaw0AxGpbpX Lzsxx2umpULGzoQkYQ8WE4bC6fxFQXHPNJjmu2kOCAPdMy+xMqRpzW5xxDrb0cmxSdyN D6bEZKISbhZMoislZ0Aook0cQ1/u7sHI+wBqOC16t2jh/RZ/fC41Ei7l9hgJcvgKi/eY v/DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=qOAzIAGITBNGyHFTZ7Cmq/ShOyrjrDEaYD2HgQ928xA=; b=VB8EIOYcQj2ycwR6289fnGNdQbbEhUlmBvswbt1Hc4v8447baaUI41CrDp5udJVTWI kXTEB85Ej/fqmWGQpVmn980+mH/PJuy2vuG/Kv2VQ2oO78UDNoTxs9g/Qax6FDY+7QJ7 0uQnv7uxUzp806qMH+ZxjOBJb9cVDQ4FLmVtghNkBLoz6gUyDZUZragTjT2U9UIF2Mcy yNXuQk+OkePYhHEAvEn8WiM9RpN9JGoFjJOjGazhsR3h18Es3w7KaUZNkNSKoF3M1Zhl Y5PWud8MjuF5bPhcdLYMLXeLkb4v+NRsRgO1X9Fjo83mpUSIopuP4ZgVwVj9D68knohM c/GQ== X-Gm-Message-State: AOAM532NtSLdRF3zRy2nA1ly7cTBL+nukdeWiYYrWQ6Ji31ylMzbfhNr 0d5yMSn45GdWlhdaMv0lk2AmZdlAS4M= X-Google-Smtp-Source: ABdhPJy9EXlOReQq8IvYirkcC2sl+tXUHRegwgZC30HikrABwSOoEAA68wGRBpTdDR+mmZRWn7PHgQ== X-Received: by 2002:a63:9c4:0:b0:380:f8fd:561d with SMTP id 187-20020a6309c4000000b00380f8fd561dmr18248153pgj.60.1647294617305; Mon, 14 Mar 2022 14:50:17 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id s15-20020a63af4f000000b0037c8875108dsm18029032pgo.45.2022.03.14.14.50.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 14:50:17 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] gatt: Print error if gatt_db_attribut_notify fails Date: Mon, 14 Mar 2022 14:50:09 -0700 Message-Id: <20220314215010.23822-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This prints an error if gatt_db_attribut_notify fails. --- src/gatt-database.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gatt-database.c b/src/gatt-database.c index 485af04ea..d6c94058c 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -1523,8 +1523,9 @@ static void send_service_changed(struct btd_gatt_database *database, put_le16(start, value); put_le16(end, value + 2); - gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value), - NULL); + if (!gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value), + NULL)) + error("Failed to notify Service Changed"); } static void gatt_db_service_added(struct gatt_db_attribute *attrib, @@ -3967,6 +3968,7 @@ void btd_gatt_database_restore_svc_chng_ccc(struct btd_gatt_database *database) put_le16(0x0001, value); put_le16(0xffff, value + 2); - gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value), - NULL); + if (!gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value), + NULL)) + error("Failed to notify Service Changed"); } From patchwork Mon Mar 14 21:50:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 551116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05A30C433FE for ; Mon, 14 Mar 2022 21:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245401AbiCNVva (ORCPT ); Mon, 14 Mar 2022 17:51:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236193AbiCNVv3 (ORCPT ); Mon, 14 Mar 2022 17:51:29 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DE5A344CF for ; Mon, 14 Mar 2022 14:50:19 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id z16so16331305pfh.3 for ; Mon, 14 Mar 2022 14:50:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=njAUkH5dFFKuqO+juI/HLGmCs3nd2qaoyWds8EGJd78=; b=YE6lKpEeqWWr7bxVddJNsxSeXHOsfubyQgK5FMK2g021xkXIq7LtC5F/WcOQgXufx5 mLyh8hhgNV8LUmwEgFeJBL+q+zv2OIItg1FLqHy66MI7LGJowUDsvK45gnESLLVTmCqu Bu2TlFZKYyRdWQFI7CBAw+R+2vpSYG1HqWpGYOU/kJEx67i6jH2RrMJRiryi+kxhayDY gZN8RJ72YgE4GaOfk+Qd7IHmwo4Wv3Of4RBsLmMnyCexXopJNG5OJ2f3wkJhYFUWdk3j 0INGwWDo1uGqkDNPEbIMU/KEwq7H8UxNFDrp/o/MS7wyIEpirTiYeiNPv6+y2xkHOF0S XNVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=njAUkH5dFFKuqO+juI/HLGmCs3nd2qaoyWds8EGJd78=; b=ya31GS/qiqUkYQw5I4QPNCpnX1yc8HBWfR3HZyMIPtlxQfIXuPFMuQkczvd2FVL6kR ffhc1GIKiyCwihZHvddOrXdK/9EaDZdSUfZZYU7rcWno2H0iyApA12m/LXsOf+ypG+FG wLqS7EKqdGHZHEA/ZjMOdCOILhswLVr27mmaj9HtM06h79a/WTVaJiyzkKZaDbKXuYXZ v1BsQpfSTsW7E2HZk7/NkvouKEzDCHiJrZ20b/MjvgZUkZKBVVxWpuB+erkyRfwy6UkN +zYysavFrnkzz9vFE/WvEFQAg3tkv4tN3MXiXhn6UL03CWL4jfxQFhNrVpOzik+Mxf5+ f+dg== X-Gm-Message-State: AOAM530CTE4E1XxIr170FuiDFIYng4HLjJqhSb3mrWKsKvoC5R9rXbqv VntVv9nvYYK9jz20KkenE16WXz4eq6A= X-Google-Smtp-Source: ABdhPJwnxh+wn5h6pi3UtQc9xuPn+VaEkwEDjFUcy9/H6hnHms8tu5Pzr4LyCtElRjOxgbR9rw4jhA== X-Received: by 2002:a63:2358:0:b0:380:e306:f0bd with SMTP id u24-20020a632358000000b00380e306f0bdmr19906066pgm.594.1647294618357; Mon, 14 Mar 2022 14:50:18 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id s15-20020a63af4f000000b0037c8875108dsm18029032pgo.45.2022.03.14.14.50.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Mar 2022 14:50:17 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] gatt-db: Fix gatt_db_attribute_notify Date: Mon, 14 Mar 2022 14:50:10 -0700 Message-Id: <20220314215010.23822-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314215010.23822-1-luiz.dentz@gmail.com> References: <20220314215010.23822-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz gatt_db_attribute_notify was only accepting passing the Characteristic Declaration instead of accepting its value as well, gatt_db_service_foreach_desc also have similar limitation so both have been updated to allow working with both value and declaration. --- src/shared/gatt-db.c | 63 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index 53d3e1243..be07cdbe4 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -1528,32 +1528,71 @@ void gatt_db_service_foreach_char(struct gatt_db_attribute *attrib, gatt_db_service_foreach(attrib, &characteristic_uuid, func, user_data); } +static int gatt_db_attribute_get_index(struct gatt_db_attribute *attrib) +{ + struct gatt_db_service *service; + int index; + + if (!attrib) + return -1; + + service = attrib->service; + index = attrib->handle - service->attributes[0]->handle; + + if (index > (service->num_handles - 1)) + return -1; + + return index; +} + +static struct gatt_db_attribute * +gatt_db_attribute_get_value(struct gatt_db_attribute *attrib) +{ + struct gatt_db_service *service; + int index; + + if (!attrib) + return NULL; + + index = gatt_db_attribute_get_index(attrib); + if (index < 0) + return NULL; + + service = attrib->service; + + if (!bt_uuid_cmp(&characteristic_uuid, &attrib->uuid)) + index++; + else if (bt_uuid_cmp(&characteristic_uuid, + &service->attributes[index - 1]->uuid)) + return NULL; + + return service->attributes[index]; +} + void gatt_db_service_foreach_desc(struct gatt_db_attribute *attrib, gatt_db_attribute_cb_t func, void *user_data) { struct gatt_db_service *service; struct gatt_db_attribute *attr; + int index; uint16_t i; if (!attrib || !func) return; - /* Return if this attribute is not a characteristic declaration */ - if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid)) + attrib = gatt_db_attribute_get_value(attrib); + if (!attrib) + return; + + index = gatt_db_attribute_get_index(attrib); + if (index < 0) return; service = attrib->service; /* Start from the attribute following the value handle */ - for (i = 0; i < service->num_handles; i++) { - if (service->attributes[i] == attrib) { - i += 2; - break; - } - } - - for (; i < service->num_handles; i++) { + for (i = index + 1; i < service->num_handles; i++) { attr = service->attributes[i]; if (!attr) continue; @@ -2163,8 +2202,8 @@ bool gatt_db_attribute_notify(struct gatt_db_attribute *attrib, if (!attrib || !attrib->notify_func) return false; - /* Return if this attribute is not a characteristic declaration */ - if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid)) + attrib = gatt_db_attribute_get_value(attrib); + if (!attrib) return false; ccc = gatt_db_attribute_get_ccc(attrib);