From patchwork Thu Jan 5 22:09:41 2023 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: 639789 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 5ADA4C54EBC for ; Thu, 5 Jan 2023 22:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235444AbjAEWKJ (ORCPT ); Thu, 5 Jan 2023 17:10:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235705AbjAEWJt (ORCPT ); Thu, 5 Jan 2023 17:09:49 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D37C167BEA for ; Thu, 5 Jan 2023 14:09:47 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id d3so40764809plr.10 for ; Thu, 05 Jan 2023 14:09:47 -0800 (PST) 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:message-id:reply-to; bh=nLx/zURPiGT0IcVnLTUycL4Bg0QmQuAYlvG/tHxlN70=; b=PW8wjLZmTcfPe9sjHOqaoPZJYFTtlILPY/B3AOeu/dqQKeGMrMdTDbVdGmcROyUNVB 6Mi6C3eb5BQlzi/sSMtZ+CavvTcr1qOtyYTG4acympyqvhpeVDZecLmuK3HHe2BBcj0V /fkK1NwWkpCbTnqQpYTUH3zFlVzO/v89x6RPZNialEwkqLeRBFHitPaZ5/qQ8FOMvAnh 3Yl9myBu2wVTvoHP0wyWF95vaU9sGe8x7Sq5eJlJazvdWAfxH5IGMvNB7s2afFrbm9+Z 4BofFE0v8Ex6Ge9BsLNh7YTRudRUtVrG6oh6BtxoP8K61puQc6aNN+ZmxHCYsb4QhpAh ArVg== 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:message-id:reply-to; bh=nLx/zURPiGT0IcVnLTUycL4Bg0QmQuAYlvG/tHxlN70=; b=WpSuXFtQrVSu6YkptW3mFG4BQxfQMOkPQhLot5htZoCOfE/oVGBn9ydz/VffC7ATpT 23lLZpY31ch16hqQle1KSIxiqLkWk2MoYSjJoVoGLllfYnkTrp7AVax4+oVyDmvG9956 WAuwUkWG18VQTKxaGTQp6b+PZ7Q9lSQSNTYG63y6CkYhR8y1Rc1IvU1MCLWr2nwgb+MO CnwjE8Wcq0xblk/rg+uhKBgZxd5lwtaSuUALG3tY9y2vJ/BO4h9nFXVWX8ifCgUcFyjm /cZUP36yWpeva8s4UVWM3vr/IbvOLH5quWANAzrLmXYMY5Nl4DTXKw4j/yoe/TvKsEMb RBlQ== X-Gm-Message-State: AFqh2koRhxCUyM5wyvr7pigArXRMEd6tnU3qYTWJbPTzxUglQQEejext XbAVzXJMFsSyR1YmID2NDTyv8hMJtvA= X-Google-Smtp-Source: AMrXdXuRs/vB5vvxevfw5/gHrqACbw/dmWl1t/+sd/0dwtuX2cTS+wqq7aaanxfe7EIbKYjnV1DuJQ== X-Received: by 2002:a17:902:f201:b0:189:377c:9ab with SMTP id m1-20020a170902f20100b00189377c09abmr48996978plc.51.1672956586631; Thu, 05 Jan 2023 14:09:46 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id jg21-20020a17090326d500b001929827731esm16744861plb.201.2023.01.05.14.09.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 14:09:46 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/4] shared/gatt-client: Use parent debug_callback if not set on clone Date: Thu, 5 Jan 2023 14:09:41 -0800 Message-Id: <20230105220944.2373424-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz If clone don't have a dedicated callback set use its parent so users of bt_gatt_client_clone don't have to keep setting the same callback for all clone instances. --- src/shared/gatt-client.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index cb2e64b6cc6b..4aa5d7d92957 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -38,7 +38,8 @@ #define GATT_SVC_UUID 0x1801 #define SVC_CHNGD_UUID 0x2a05 #define DBG(_client, _format, arg...) \ - gatt_log(_client, "%s:%s() " _format, __FILE__, __func__, ## arg) + gatt_log(_client, "[%p] %s:%s() " _format, _client, __FILE__, \ + __func__, ## arg) struct ready_cb { bt_gatt_client_callback_t callback; @@ -357,15 +358,28 @@ static void discovery_op_free(struct discovery_op *op) static bool read_db_hash(struct discovery_op *op); +static void gatt_log_va(struct bt_gatt_client *client, const char *format, + va_list va) +{ + if (!client || !format) + return; + + if (client->debug_callback) + util_debug_va(client->debug_callback, client->debug_data, + format, va); + else + gatt_log_va(client->parent, format, va); +} + static void gatt_log(struct bt_gatt_client *client, const char *format, ...) { va_list ap; - if (!client || !format || !client->debug_callback) + if (!client || !format) return; va_start(ap, format); - util_debug_va(client->debug_callback, client->debug_data, format, ap); + gatt_log_va(client, format, ap); va_end(ap); } From patchwork Thu Jan 5 22:09:42 2023 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: 639788 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 75A90C3DA7A for ; Thu, 5 Jan 2023 22:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235662AbjAEWKL (ORCPT ); Thu, 5 Jan 2023 17:10:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235717AbjAEWJu (ORCPT ); Thu, 5 Jan 2023 17:09:50 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 563AC67BE4 for ; Thu, 5 Jan 2023 14:09:49 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id p24so18276667plw.11 for ; Thu, 05 Jan 2023 14:09:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=CWJ9a+qVJy1gWUNU381hC5U7R/t9smb2m2ZecZHXjMI=; b=XwGX3NSLqwbaFY0m0V8PU39WiX1KQuTwVOYUoFJV0s5lj/ue5TJvZbJhOYLuTkl+Yx Np7TZCsytKYysjNLTgprFxY9KHFe+AvgOdhG984gbdqp50k3zXKaur95Ko5l1rlnRQUz 8AzcsOIMOtC6ZnJ64NWqPKHc75oZ6a8oMMi8YmBYHq5jgKQZya3BOUc7ClHRo1fHmCb2 eoOHh0VWUlXVAFXKyloSSkHBkp50IhaOZJkcK1WRoMJ34OZnX6+n3LMa7r9ADbyIg/Sq IlPwU9UJ1SeBJ9IqrI0IoCmzQ8A5zUIIS9dDrTYv+OGrJFthltncR32tbbE9P8mZtcUh uV5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CWJ9a+qVJy1gWUNU381hC5U7R/t9smb2m2ZecZHXjMI=; b=ll8kSbG1S0WlSKPkQQCQ89duCN7XKKNnO5IGhm/eizhbu+8zM3qzRzCVkBErxzKTEl RwSOjD66w3g+EvNMs5wL+LXbjwMS5pn4Pw6S0gA0etZHw3Ra6kniowUrNM2jm9hatGun V1pwTcWjlowObgiHYpDKNra1jeXLhw4kDLDeizqgHgujgUfrvAFo2E7OZH8yG4SS2iiW GhvVtPmuioJAeXUW05RfU7mXl7zv8RqNPMQqA/TwiOdnyTfy+LMeZv/0Vij0m7qcxI07 xJIcu8tL7Hc+kKiORXhSty9ZLQqd7K1lhbImSwMRkotWz4RHqQBudZFNhBYITC5JBsHX yimg== X-Gm-Message-State: AFqh2kroIHpYQCSTQww3jya7P/OB2s7kSbpl0R3l9YBHZzdik7zFKMgD oH6E9CayNd2t7JT7Ap8Cn0AOiIKVfz4= X-Google-Smtp-Source: AMrXdXvQbUo632XcGiGwlbcHKJVMu4WdnW2r6lsq9OGKfjQC8I/TKGC8aR+qo3R1X/vd6tuoOGjmRw== X-Received: by 2002:a17:903:28e:b0:193:a5b:cd01 with SMTP id j14-20020a170903028e00b001930a5bcd01mr1054953plr.19.1672956587946; Thu, 05 Jan 2023 14:09:47 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id jg21-20020a17090326d500b001929827731esm16744861plb.201.2023.01.05.14.09.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 14:09:47 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/4] shared/gatt-client: Allow registering with NULL callback Date: Thu, 5 Jan 2023 14:09:42 -0800 Message-Id: <20230105220944.2373424-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230105220944.2373424-1-luiz.dentz@gmail.com> References: <20230105220944.2373424-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 This makes bt_gatt_client_register_notify allow registering with NULL callback which is interpreted as the CCC write has already been performed therefore it won't be written again. --- src/shared/gatt-client.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index 4aa5d7d92957..593b0f27f871 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -1711,8 +1711,11 @@ static unsigned int register_notify(struct bt_gatt_client *client, * descriptor. */ chrc = notify_chrc_create(client, handle); - if (!chrc) + if (!chrc) { + DBG(client, "Unable to locate characteristic at 0x%04x", + handle); return 0; + } } /* Fail if we've hit the maximum allowed notify sessions */ @@ -1750,9 +1753,10 @@ static unsigned int register_notify(struct bt_gatt_client *client, } /* - * If the ref count > 1, then notifications are already enabled. + * If the ref count > 1, ccc handle cannot be found or registration + * callback is not set consider notifications are already enabled. */ - if (chrc->notify_count > 1 || !chrc->ccc_handle) { + if (chrc->notify_count > 1 || !chrc->ccc_handle || !callback) { complete_notify_request(notify_data); return notify_data->id; } @@ -2176,6 +2180,9 @@ static void notify_cb(struct bt_att_chan *chan, uint8_t opcode, struct bt_gatt_client *client = user_data; struct value_data data; + if (queue_isempty(client->notify_list)) + return; + bt_gatt_client_ref(client); memset(&data, 0, sizeof(data)); @@ -3670,7 +3677,8 @@ unsigned int bt_gatt_client_register_notify(struct bt_gatt_client *client, void *user_data, bt_gatt_client_destroy_func_t destroy) { - if (!client || !client->db || !chrc_value_handle || !callback) + if (!client || !client->db || !chrc_value_handle || + (!callback && !notify)) return 0; if (client->in_svc_chngd) From patchwork Thu Jan 5 22:09:43 2023 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: 639435 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 A35D5C54EF0 for ; Thu, 5 Jan 2023 22:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235210AbjAEWKP (ORCPT ); Thu, 5 Jan 2023 17:10:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230402AbjAEWJw (ORCPT ); Thu, 5 Jan 2023 17:09:52 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1432967BEA for ; Thu, 5 Jan 2023 14:09:51 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id n4so40802577plp.1 for ; Thu, 05 Jan 2023 14:09:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Gw6itf7AVrCO7LXSXZODgQaXufV/CbE8VRMeicmNgDc=; b=TyWwwYCGbAZpp2Qiwlr03WssIfQgQ21+P0AZPHakekrKtRUp/u/YoQ9fx9DbCWACcA IbzEQy0xekxmwEJOHXQzromGzkKPnUheWkbAFUGrpl3twIAbSeX81hgN5krj9a3IQ7EF vwwskenk7Ns0jB9NEGRHaxmx22Qed6mVMrDi02umU44o8q/TjFIJjRgo9LBHWS560FkN EEMjRXmOZ/Cj/6B4nud3fmgHBsPaEhWBL9twEMLqUiUqSLxX05q9KXjDRhq07mBB3dVV OaaVjAWEfRx4HhyLgY6rDdH1+mcdguh2DZ8ok20pPoiBY6tilXQxWN+kidRUsoAE0aLz dzVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gw6itf7AVrCO7LXSXZODgQaXufV/CbE8VRMeicmNgDc=; b=Tn/+bMmwHfEcOc1t3Teehz4d/fjXQ6/ujUKtOrwRTg/LnvU0YqFXS75IJhxiK/DL5V C+488s5SdFKbIURnmMp9H2hIFDNNxP8i31rZNRvK3pkJn4ceGezcbL8uMkqLx5Oyocxf P1j8tN2/SFixFA/qcN3/ZtBmHeWUA5Tiysv/XfHWdJsBx35nawdnYOpn++0vFfQV5JHc 7+yBBRRML8wTry/7mTmsKMiIhlLSW/PlXrsmmX2FGC4fU4tbc4hCvehlT22isJms05EY DKjPnz6L8OvzE9UHllTxbKJecB7Huj42l1/ce1E1ojjts16hXrD9fUT5DA1D3HRmyCCT yeIA== X-Gm-Message-State: AFqh2krJMFTO6xvhf7SdQIUpNgQrZxSOo35x83Hc7lDg2hUXnX+ZlW/6 nNor4RG1SsIv591q+7SGc36RGK7syN4= X-Google-Smtp-Source: AMrXdXsLuC1cDYsMsk15nn4cuu3YURR9Qx8FjQK6Se4CmamgruT++5EriN6GVQNzviijVlWsIZHiEw== X-Received: by 2002:a17:903:3311:b0:189:d696:63e2 with SMTP id jk17-20020a170903331100b00189d69663e2mr58379339plb.39.1672956589964; Thu, 05 Jan 2023 14:09:49 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id jg21-20020a17090326d500b001929827731esm16744861plb.201.2023.01.05.14.09.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 14:09:49 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/4] attrib: Introduce g_attrib_attach_client Date: Thu, 5 Jan 2023 14:09:43 -0800 Message-Id: <20230105220944.2373424-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230105220944.2373424-1-luiz.dentz@gmail.com> References: <20230105220944.2373424-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 This introduces g_attrib_attach_client which can be used to attach a bt_gatt_client instance to GAttr so it can be used to register notifications. --- Makefile.am | 6 +++--- attrib/gattrib.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ attrib/gattrib.h | 2 ++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index aa3a5e053cd8..0e8cce249c7d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -565,9 +565,9 @@ unit_tests += unit/test-gattrib unit_test_gattrib_SOURCES = unit/test-gattrib.c attrib/gattrib.c \ $(btio_sources) src/log.h src/log.c -unit_test_gattrib_LDADD = lib/libbluetooth-internal.la \ - src/libshared-glib.la \ - $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt +unit_test_gattrib_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la \ + $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt unit_tests += unit/test-bap diff --git a/attrib/gattrib.c b/attrib/gattrib.c index 041b9d289c64..997af3699c51 100644 --- a/attrib/gattrib.c +++ b/attrib/gattrib.c @@ -21,17 +21,23 @@ #include #include "lib/bluetooth.h" +#include "lib/uuid.h" #include "btio/btio.h" #include "src/log.h" #include "src/shared/util.h" #include "src/shared/att.h" +#include "src/shared/gatt-helpers.h" #include "src/shared/queue.h" +#include "src/shared/gatt-db.h" +#include "src/shared/gatt-client.h" +#include "attrib/att.h" #include "attrib/gattrib.h" struct _GAttrib { int ref_count; struct bt_att *att; + struct bt_gatt_client *client; GIOChannel *io; GDestroyNotify destroy; gpointer destroy_user_data; @@ -145,6 +151,7 @@ void g_attrib_unref(GAttrib *attrib) if (attrib->destroy) attrib->destroy(attrib->destroy_user_data); + bt_gatt_client_unref(attrib->client); bt_att_unref(attrib->att); queue_destroy(attrib->callbacks, attrib_callbacks_destroy); @@ -338,6 +345,20 @@ gboolean g_attrib_cancel_all(GAttrib *attrib) return TRUE; } +static void client_notify_cb(uint16_t value_handle, const uint8_t *value, + uint16_t length, void *user_data) +{ + uint8_t *buf = newa(uint8_t, length + 2); + + put_le16(value_handle, buf); + + if (length) + memcpy(buf + 2, value, length); + + attrib_callback_notify(NULL, ATT_OP_HANDLE_NOTIFY, buf, length + 2, + user_data); +} + guint g_attrib_register(GAttrib *attrib, guint8 opcode, guint16 handle, GAttribNotifyFunc func, gpointer user_data, GDestroyNotify notify) @@ -359,6 +380,16 @@ guint g_attrib_register(GAttrib *attrib, guint8 opcode, guint16 handle, queue_push_head(attrib->callbacks, cb); } + if (opcode == ATT_OP_HANDLE_NOTIFY && attrib->client) { + unsigned int id; + + id = bt_gatt_client_register_notify(attrib->client, handle, + NULL, client_notify_cb, cb, + attrib_callbacks_remove); + if (id) + return id; + } + if (opcode == GATTRIB_ALL_REQS) opcode = BT_ATT_ALL_REQUESTS; @@ -410,6 +441,21 @@ gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu) return bt_att_set_mtu(attrib->att, mtu); } +gboolean g_attrib_attach_client(GAttrib *attrib, struct bt_gatt_client *client) +{ + if (!attrib || !client) + return FALSE; + + if (attrib->client) + bt_gatt_client_unref(attrib->client); + + attrib->client = bt_gatt_client_clone(client); + if (!attrib->client) + return FALSE; + + return TRUE; +} + gboolean g_attrib_unregister(GAttrib *attrib, guint id) { if (!attrib) diff --git a/attrib/gattrib.h b/attrib/gattrib.h index c2877d757342..0111bfc3f2fa 100644 --- a/attrib/gattrib.h +++ b/attrib/gattrib.h @@ -19,6 +19,7 @@ extern "C" { #define GATTRIB_ALL_HANDLES 0x0000 struct bt_att; /* Forward declaration for compatibility */ +struct bt_gatt_client; /* Forward declaration for compatibility */ struct _GAttrib; typedef struct _GAttrib GAttrib; @@ -53,6 +54,7 @@ guint g_attrib_register(GAttrib *attrib, guint8 opcode, guint16 handle, uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len); gboolean g_attrib_set_mtu(GAttrib *attrib, int mtu); +gboolean g_attrib_attach_client(GAttrib *attrib, struct bt_gatt_client *client); gboolean g_attrib_unregister(GAttrib *attrib, guint id); gboolean g_attrib_unregister_all(GAttrib *attrib); From patchwork Thu Jan 5 22:09:44 2023 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: 639436 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 94A5FC54EBD for ; Thu, 5 Jan 2023 22:10:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235717AbjAEWKM (ORCPT ); Thu, 5 Jan 2023 17:10:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235623AbjAEWJw (ORCPT ); Thu, 5 Jan 2023 17:09:52 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F30367BE4 for ; Thu, 5 Jan 2023 14:09:52 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id cl14so4846579pjb.2 for ; Thu, 05 Jan 2023 14:09:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=cNud4kWdkw52+hXAnumbx8Ikmuw+BRe/Pf1t1Z/q3Y8=; b=QOvEbBJ6Pz0b7wJvrbxCCq88bebfI8kMwj31mnJ1IkhpwRY+xbW4RwogMOM/uc90KK h07gzh0+83sDvk19FB091QxdWESboAEzMoW/PxF1Q/q3h2t2favLsXUuMKgLDNzRnkge l05gV0kCYJ5/RNaKgQoWsTm5M1rReUuPQKhKPY8McLsPx+7033AHoEVRS17YWp1P9Y8X jc9Nl7G5uSBeHTqp/TKEldlTnXK3eCA1/a5Okez6Cf4l7p88c6zprnWCkY5JkiBvgqa7 60g7ORKbe/9XUghUtkSEtCuuN/SBz08DR0aRtFWvkvJKLaxQHc1eiJdP+f5O1aMO7iwa p4jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cNud4kWdkw52+hXAnumbx8Ikmuw+BRe/Pf1t1Z/q3Y8=; b=5U3/Z34S6tAsuoue0Mb35CKafc9E26c9srW6ZjHt5d3mzbUZGBc1mDgqGGltgeKi4n p8aWuJldRG/p9i6U6klIANAlQkI+K4Oe18/7fyJwXUYGQYTwrJk/0cwdJzimQqYDVl/u 5lenusYosRwoDtmW3KuWBEosSEILJTgxNA9b98QZ9oq+rPDTyvgUWQ40adpFqg9hYu8L zpcdOiO0TApwVvX0sJ9jE9Q5Sz44ODUWctZb64z7LVUIH47QUS9jmhulc6U8c/619ucW QPcSDOjDgfITRjJcZFA/izWmcmpdpafvwLyYjqZd/T0KCwSWAKsi140MCn8bUDdWcQZ4 yeKA== X-Gm-Message-State: AFqh2koMnpS9g1mj+WR0NS/LjyeeTije3N27TMZ0FT6IUGbb0a/lcs1G vV2ebi9BuIElQ2FlOT/l5rmo7ntu52s= X-Google-Smtp-Source: AMrXdXsGCBdyo3L4/G7HSss0WYQ8vB2kK8TMOpoguSJR2DQsPCYdFgmKK17/6fMgZVFfnXgXj3iQGA== X-Received: by 2002:a17:902:f145:b0:191:10e0:b912 with SMTP id d5-20020a170902f14500b0019110e0b912mr52494033plb.41.1672956591194; Thu, 05 Jan 2023 14:09:51 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id jg21-20020a17090326d500b001929827731esm16744861plb.201.2023.01.05.14.09.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 14:09:50 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/4] hog-lib: Fix not handling BT_ATT_OP_HANDLE_NFY_MULT Date: Thu, 5 Jan 2023 14:09:44 -0800 Message-Id: <20230105220944.2373424-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20230105220944.2373424-1-luiz.dentz@gmail.com> References: <20230105220944.2373424-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 This is a temporary fix for not handling BT_ATT_OP_HANDLE_NFY_MULT in GAttr so the code will use g_attrib_attach_client to attach the bt_gatt_client instance which is then used to register notifications including those sent with BT_ATT_OP_HANDLE_NFY_MULT. Fixes: https://github.com/bluez/bluez/issues/71 --- profiles/input/hog-lib.c | 23 +++++++++++++++++++++-- src/device.c | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 021db386f3b7..7ff1ede3db35 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -374,6 +374,15 @@ static void report_value_cb(const guint8 *pdu, guint16 len, gpointer user_data) error("bt_uhid_send: %s (%d)", strerror(-err), -err); } +static void report_notify_destroy(void *user_data) +{ + struct report *report = user_data; + + DBG(""); + + report->notifyid = 0; +} + static void report_ccc_written_cb(guint8 status, const guint8 *pdu, guint16 plen, gpointer user_data) { @@ -393,7 +402,13 @@ static void report_ccc_written_cb(guint8 status, const guint8 *pdu, report->notifyid = g_attrib_register(hog->attrib, ATT_OP_HANDLE_NOTIFY, report->value_handle, - report_value_cb, report, NULL); + report_value_cb, report, + report_notify_destroy); + if (!report->notifyid) { + error("Unable to register report notification: handle 0x%04x", + report->value_handle); + goto remove; + } DBG("Report characteristic descriptor written: notifications enabled"); @@ -1798,7 +1813,11 @@ bool bt_hog_attach(struct bt_hog *hog, void *gatt) r->notifyid = g_attrib_register(hog->attrib, ATT_OP_HANDLE_NOTIFY, r->value_handle, - report_value_cb, r, NULL); + report_value_cb, r, + report_notify_destroy); + if (!r->notifyid) + error("Unable to register report notification: " + "handle 0x%04x", r->value_handle); } return true; diff --git a/src/device.c b/src/device.c index 995d39f2ccee..28b93eb9ac38 100644 --- a/src/device.c +++ b/src/device.c @@ -5152,6 +5152,7 @@ static void gatt_client_init(struct btd_device *device) } bt_gatt_client_set_debug(device->client, gatt_debug, NULL, NULL); + g_attrib_attach_client(device->attrib, device->client); /* * Notify notify existing service about the new connection so they can