From patchwork Fri Dec 9 01:03: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: 13069108 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 92ABAC4332F for ; Fri, 9 Dec 2022 01:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbiLIBDT (ORCPT ); Thu, 8 Dec 2022 20:03:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbiLIBDR (ORCPT ); Thu, 8 Dec 2022 20:03:17 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A0D775BC4 for ; Thu, 8 Dec 2022 17:03:17 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id n65-20020a17090a2cc700b0021bc5ef7a14so3362829pjd.0 for ; Thu, 08 Dec 2022 17:03:17 -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=HPxlPB77OzQNUBW1EgOuo55XCJcGR0T2VxU+nuwk8GY=; b=dluj3XPJ+KZScL0LGl/nZhmAgImQu718K3UJ2FLKbHKygChyw/LeSu796II9/bQJ1v u1Gbaux0bbgTTixFjhb+B4lQ/gVyBtOvwMPNUIWvVOVoqZdQGKuHL49RV22aXyymL855 qj8ZitpFI3JtJPVHUr3cQV1beFRL8ZE+Li7uSSrwRkT7FDDAEm8FtsTf25dSR2+rwyXD EmCtQKkscqlirHe76P8brHefdjy/qN3DSRw9kcAz6+yMOvZuZmv9wlCwKbK5RE7Iq0IP 0lT0AzxHODz1GAtkaA9QDR3t2Endp2aff1zwL/llh/O9kWd1X5zOqrsVOZdcnXNHn8OG 7VzQ== 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=HPxlPB77OzQNUBW1EgOuo55XCJcGR0T2VxU+nuwk8GY=; b=Cjtaq+DheY/QUztYEMZNiYJidcLQ601K2ZkK0fwzai2S7UrzixjRJEpNL/k48lI2fN aF45Ysfc8Y8EKGMCaZOeYUuTjnfxtBNPWLpAzQIsFFvN+S8Am3e+0nN7I7+ibmLQCYnH o9IEsXQCecsLkLtGKo3wX1pYSD5PESAvak1VKqHamYo3ky2zEs3kvkEvlngxyZhZJua3 MWeC3jHQfKsSs2nBfk374AoHN8KGbTAO6EtZ3piHJixIORTDwlqLM8LRWUNyLbYNlvcL QdPEk6q8qiVkjkCULPrS4X/VhABbE2R3AL9vJfI/w9PQjR7ey0P8ub4m/3A1W3HfglRA jCMw== X-Gm-Message-State: ANoB5pnjQ1UiEBvNeoagDCmOJal/IGAn6Wizw1fDvqrTcl9cJRK4hH7Z +QO9uOHeopfZIwfSQNvdpVG2wP4hdzlV5g== X-Google-Smtp-Source: AA0mqf5MSySrVtNNuBL688xlmspqLbJlXfvPt8gOJ7++gysGFZbrMk8sTELqEPICGJwaGh1Pe5TYTg== X-Received: by 2002:a05:6a20:b042:b0:a9:ec2a:1013 with SMTP id dx2-20020a056a20b04200b000a9ec2a1013mr4175162pzb.56.1670547795872; Thu, 08 Dec 2022 17:03:15 -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 z21-20020aa79495000000b005746c3b2445sm100253pfk.151.2022.12.08.17.03.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 17:03:15 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/5] shared/att: Fix not requeueing in the same channel Date: Thu, 8 Dec 2022 17:03:10 -0800 Message-Id: <20221209010314.707606-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 request needs to be resend due to change in the security use the chan->queue otherwise it may end up using a different channel. --- src/shared/att.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/att.c b/src/shared/att.c index f7bef08bc169..b90af93ccbf8 100644 --- a/src/shared/att.c +++ b/src/shared/att.c @@ -799,8 +799,8 @@ static bool handle_error_rsp(struct bt_att_chan *chan, uint8_t *pdu, chan->pending_req = NULL; - /* Push operation back to request queue */ - return queue_push_head(att->req_queue, op); + /* Push operation back to channel queue */ + return queue_push_head(chan->queue, op); } static void handle_rsp(struct bt_att_chan *chan, uint8_t opcode, uint8_t *pdu, From patchwork Fri Dec 9 01:03:11 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: 13069109 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 400B3C4332F for ; Fri, 9 Dec 2022 01:03:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229656AbiLIBDW (ORCPT ); Thu, 8 Dec 2022 20:03:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbiLIBDT (ORCPT ); Thu, 8 Dec 2022 20:03:19 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36B3B87C9C for ; Thu, 8 Dec 2022 17:03:18 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id 62so2508012pgb.13 for ; Thu, 08 Dec 2022 17:03:18 -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=JDmk6XJFFnl2esSiVNZZnxUUtO+P3SzcAI3cvB9o72o=; b=e6KRa/jLCIMko9fmt378Ngkzhet4P2/gxrXshtOgyjJMXO8MRsQk5ybySaSt6Bwvqz TfakthUtCX5qH5fnmF1Wueriip3gIS6kvJXoN3qEZMeOYy0HOvYuqg5Xdlqb98BP9HQ0 NB7nm78YGwxQRmdTfuIH/WtT2LLCc5iWVhfRbs2Hd1DxZbd294VT+THuM4EYgx3IDnlR Xe8x7aHBkPVsgsX3kb6NY4wvMQ8gRHDB3q6nVUIa6k/J+mBvru6sMMINJevZWdPxGz2g EIGD/yTkiWH+czaKCP6SJ0vOZoYzaMMfH0rP4NoEmSBjZayvl4ojVxHni0pwN5HhZs07 K7IA== 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=JDmk6XJFFnl2esSiVNZZnxUUtO+P3SzcAI3cvB9o72o=; b=nk51bnytpdo7Wi1EGzx5eyDK6ImiouQb9kz+2KXTgJTp8Ymzw8CYlKRobzn0NN+Nz3 hsvirT7qB6ptwOSikabOVcVulrPpxb2VDfkF0hbGZ7mr/DETgfoTy/iPQANDlFvAjxc5 dD5hZBHA5C/aoGfr6RQN/NoqtOrWAiMNqYAZFwLnAWuMBUfhcrWY/awlPC9Sm0rBKMF2 Z876S8bLBzVWFpEyN03NddOBGdV60HhAZPTG0CQ++uexlDIXoxGzV5IWeQIT0UlOCJ5S n/NJk3btgFWsKeFpb99ydtfP7hn/nDXbFXU4EodKxnxMC9Vs5x8MzU9cc4PoUw52foVk 2UZg== X-Gm-Message-State: ANoB5pkdLKtn7kwzDbVp3w01wq2DFdltZVlYx4yQH4VV2w8qLvEG0rxr q3VjquH8QX0dZoXLIFcyUu5w/F3jQSL50Q== X-Google-Smtp-Source: AA0mqf4NguziJLg21wg7fKl0licnLgG9ANkTMo7n9X4X+CJqEru/NKkea2bAVQrdcckUZCbRYrSIWA== X-Received: by 2002:a62:1781:0:b0:574:58d1:cf9f with SMTP id 123-20020a621781000000b0057458d1cf9fmr3529053pfx.27.1670547797126; Thu, 08 Dec 2022 17:03:17 -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 z21-20020aa79495000000b005746c3b2445sm100253pfk.151.2022.12.08.17.03.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 17:03:16 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/5] shared/bap: Log error message if request cannot be sent Date: Thu, 8 Dec 2022 17:03:11 -0800 Message-Id: <20221209010314.707606-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221209010314.707606-1-luiz.dentz@gmail.com> References: <20221209010314.707606-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 sure a error message is logged if a request cannot be sent for some reason. --- src/shared/bap.c | 71 +++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index 59ef81d11882..04ef4f44c1dd 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -3397,9 +3397,13 @@ static bool bap_send(struct bt_bap *bap, struct bt_bap_req *req) }; size_t i; + DBG(bap, "req %p", req); + if (!gatt_db_attribute_get_char_data(ascs->ase_cp, NULL, &handle, - NULL, NULL, NULL)) + NULL, NULL, NULL)) { + DBG(bap, "Unable to find Control Point"); return false; + } hdr.op = req->op; hdr.num = 1 + queue_length(req->group); @@ -3416,12 +3420,41 @@ static bool bap_send(struct bt_bap *bap, struct bt_bap_req *req) ret = bt_gatt_client_write_without_response(bap->client, handle, false, iov.iov_base, iov.iov_len); - if (!ret) + if (!ret) { + DBG(bap, "Unable to Write to Control Point"); return false; + } bap->req = req; - return false; + return true; +} + +static void bap_req_complete(struct bt_bap_req *req, + const struct bt_ascs_ase_rsp *rsp) +{ + struct queue *group; + + if (!req->func) + goto done; + + if (rsp) + req->func(req->stream, rsp->code, rsp->reason, req->user_data); + else + req->func(req->stream, BT_ASCS_RSP_UNSPECIFIED, 0x00, + req->user_data); + +done: + /* Detach from request so it can be freed separately */ + group = req->group; + req->group = NULL; + + queue_foreach(group, (queue_foreach_func_t)bap_req_complete, + (void *)rsp); + + queue_destroy(group, NULL); + + bap_req_free(req); } static bool bap_process_queue(void *data) @@ -3429,14 +3462,17 @@ static bool bap_process_queue(void *data) struct bt_bap *bap = data; struct bt_bap_req *req; + DBG(bap, ""); + if (bap->process_id) { timeout_remove(bap->process_id); bap->process_id = 0; } while ((req = queue_pop_head(bap->reqs))) { - if (!bap_send(bap, req)) + if (bap_send(bap, req)) break; + bap_req_complete(req, NULL); } return false; @@ -3482,33 +3518,6 @@ static bool bap_queue_req(struct bt_bap *bap, struct bt_bap_req *req) return true; } -static void bap_req_complete(struct bt_bap_req *req, - const struct bt_ascs_ase_rsp *rsp) -{ - struct queue *group; - - if (!req->func) - goto done; - - if (rsp) - req->func(req->stream, rsp->code, rsp->reason, req->user_data); - else - req->func(req->stream, BT_ASCS_RSP_UNSPECIFIED, 0x00, - req->user_data); - -done: - /* Detach from request so it can be freed separately */ - group = req->group; - req->group = NULL; - - queue_foreach(group, (queue_foreach_func_t)bap_req_complete, - (void *)rsp); - - queue_destroy(group, NULL); - - bap_req_free(req); -} - static void bap_cp_notify(struct bt_bap *bap, uint16_t value_handle, const uint8_t *value, uint16_t length, void *user_data) From patchwork Fri Dec 9 01:03:12 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: 13069110 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 94861C001B2 for ; Fri, 9 Dec 2022 01:03:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbiLIBDX (ORCPT ); Thu, 8 Dec 2022 20:03:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbiLIBDU (ORCPT ); Thu, 8 Dec 2022 20:03:20 -0500 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87EA675BC4 for ; Thu, 8 Dec 2022 17:03:19 -0800 (PST) Received: by mail-pg1-x536.google.com with SMTP id f9so2519862pgf.7 for ; Thu, 08 Dec 2022 17:03:19 -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=N7Pmk33GqCmq3eGwtX1OLnE5weBn+sp6rMMlKRau3G0=; b=H4k1dRaHEDfgVZK94iPgyOFBFVwbtHZR/alnJI0EM38OENhgcInVTm6PUZ2P+3zReO 9bMuqQ3NkkiW1lyBUysKOVLe31HY/45fV+cWFHonnXU9o26YNbBtpRWuXgQUQWWTDWFG pZR2NoH5TKvL9Sl2eCsXU7KmEASLG1WOdTy1K4D7cz0ezb32jsYUrV9ykrb1vcofSs/A CrTuX76TDkaaM7ddznIkNcK9SKSsgx3qsxLmGAcDNdTIVcXVFTXFwnhSkXahTD/sG4t4 GVkhiXAyjqPHisn4yYDcwAD4wunvB4cncvdg3MhIR+dpuv2pzqP+B5y16Y/IBWtLqF0N kXMQ== 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=N7Pmk33GqCmq3eGwtX1OLnE5weBn+sp6rMMlKRau3G0=; b=qUEAG7mZXZ023hnE2z9rhAGB/4g2ZWpKyD0nZDdvQ+4qbwqa8pYy/wZgKHvRp3WU7G lWfYsck0KfFK/Ry3LSPpsvarT60AZfpxHfmNwabQizAAJbEm7zyf9cWSC7ZYnYfuloLM BOV8GtCcKqRWrS54bfupAAjOZAGtkj7IkkzxWrwSiaqrIWZRcTeByPrDYGYiMFzUV5W8 SCW+W6h4yS9Mppk0zPi0OomNY2F1dbNJC5BEAZn3977U0x28ojj+b2FN6WXki+OjJnLp RrNJBmcFtuHoInUhGXagp4x7G1646vzzqL74j0CCRwsGfkzERuJ+mnF+XMJXTCApIYfh ZULg== X-Gm-Message-State: ANoB5pmKG6/LJqHMIzuvULyqCZEjLv6OUkR/6BYdT3oXxcRT8s7lNE8c MPGQTqS7G8ixsnLdVECKVmYWteVKqHQwCg== X-Google-Smtp-Source: AA0mqf4Cp1j5qyC9w9qm8WO5pNyx3MX1mD9zn2RXADfDU9BSFIqXeaasi9ObMav3eEUneg8s+nmwXA== X-Received: by 2002:aa7:8690:0:b0:577:501c:c154 with SMTP id d16-20020aa78690000000b00577501cc154mr3921211pfo.6.1670547798501; Thu, 08 Dec 2022 17:03:18 -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 z21-20020aa79495000000b005746c3b2445sm100253pfk.151.2022.12.08.17.03.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 17:03:17 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/5] shared/bap: Read PAC Sink/Source if respective location is found Date: Thu, 8 Dec 2022 17:03:12 -0800 Message-Id: <20221209010314.707606-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221209010314.707606-1-luiz.dentz@gmail.com> References: <20221209010314.707606-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 If PAC Sink/Source has been found but not record has been recovered it means an error must have occured so this attempt to read the records once again. --- src/shared/bap.c | 146 +++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 63 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index 04ef4f44c1dd..391838a96c55 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -2837,69 +2837,6 @@ static void read_sink_pac(struct bt_bap *bap, bool success, uint8_t att_ecode, bap_parse_pacs(bap, BT_BAP_SINK, bap->rdb->sinks, value, length); } -static void read_source_pac_loc(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) -{ - struct bt_pacs *pacs = bap_get_pacs(bap); - - if (!success) { - DBG(bap, "Unable to read Source PAC Location: error 0x%02x", - att_ecode); - return; - } - - gatt_db_attribute_write(pacs->source_loc, 0, value, length, 0, NULL, - NULL, NULL); -} - -static void read_sink_pac_loc(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) -{ - struct bt_pacs *pacs = bap_get_pacs(bap); - - if (!success) { - DBG(bap, "Unable to read Sink PAC Location: error 0x%02x", - att_ecode); - return; - } - - gatt_db_attribute_write(pacs->sink_loc, 0, value, length, 0, NULL, - NULL, NULL); -} - -static void read_pac_context(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) -{ - struct bt_pacs *pacs = bap_get_pacs(bap); - - if (!success) { - DBG(bap, "Unable to read PAC Context: error 0x%02x", att_ecode); - return; - } - - gatt_db_attribute_write(pacs->context, 0, value, length, 0, NULL, - NULL, NULL); -} - -static void read_pac_supported_context(struct bt_bap *bap, bool success, - uint8_t att_ecode, const uint8_t *value, - uint16_t length, void *user_data) -{ - struct bt_pacs *pacs = bap_get_pacs(bap); - - if (!success) { - DBG(bap, "Unable to read PAC Supproted Context: error 0x%02x", - att_ecode); - return; - } - - gatt_db_attribute_write(pacs->supported_context, 0, value, length, 0, - NULL, NULL, NULL); -} - static void bap_pending_destroy(void *data) { struct bt_bap_pending *pending = data; @@ -2944,6 +2881,89 @@ static void bap_read_value(struct bt_bap *bap, uint16_t value_handle, queue_push_tail(bap->pending, pending); } +static void read_source_pac_loc(struct bt_bap *bap, bool success, + uint8_t att_ecode, const uint8_t *value, + uint16_t length, void *user_data) +{ + struct bt_pacs *pacs = bap_get_pacs(bap); + + if (!success) { + DBG(bap, "Unable to read Source PAC Location: error 0x%02x", + att_ecode); + return; + } + + gatt_db_attribute_write(pacs->source_loc, 0, value, length, 0, NULL, + NULL, NULL); + + /* Resume reading sinks if supported but for some reason is empty */ + if (pacs->source && queue_isempty(bap->rdb->sources)) { + uint16_t value_handle; + + if (gatt_db_attribute_get_char_data(pacs->source, + NULL, &value_handle, + NULL, NULL, NULL)) + bap_read_value(bap, value_handle, read_source_pac, bap); + } +} + +static void read_sink_pac_loc(struct bt_bap *bap, bool success, + uint8_t att_ecode, const uint8_t *value, + uint16_t length, void *user_data) +{ + struct bt_pacs *pacs = bap_get_pacs(bap); + + if (!success) { + DBG(bap, "Unable to read Sink PAC Location: error 0x%02x", + att_ecode); + return; + } + + gatt_db_attribute_write(pacs->sink_loc, 0, value, length, 0, NULL, + NULL, NULL); + + /* Resume reading sinks if supported but for some reason is empty */ + if (pacs->sink && queue_isempty(bap->rdb->sinks)) { + uint16_t value_handle; + + if (gatt_db_attribute_get_char_data(pacs->sink, + NULL, &value_handle, + NULL, NULL, NULL)) + bap_read_value(bap, value_handle, read_sink_pac, bap); + } +} + +static void read_pac_context(struct bt_bap *bap, bool success, + uint8_t att_ecode, const uint8_t *value, + uint16_t length, void *user_data) +{ + struct bt_pacs *pacs = bap_get_pacs(bap); + + if (!success) { + DBG(bap, "Unable to read PAC Context: error 0x%02x", att_ecode); + return; + } + + gatt_db_attribute_write(pacs->context, 0, value, length, 0, NULL, + NULL, NULL); +} + +static void read_pac_supported_context(struct bt_bap *bap, bool success, + uint8_t att_ecode, const uint8_t *value, + uint16_t length, void *user_data) +{ + struct bt_pacs *pacs = bap_get_pacs(bap); + + if (!success) { + DBG(bap, "Unable to read PAC Supproted Context: error 0x%02x", + att_ecode); + return; + } + + gatt_db_attribute_write(pacs->supported_context, 0, value, length, 0, + NULL, NULL, NULL); +} + static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data) { struct bt_bap *bap = user_data; From patchwork Fri Dec 9 01:03:13 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: 13069111 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 A672FC4167B for ; Fri, 9 Dec 2022 01:03:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbiLIBDY (ORCPT ); Thu, 8 Dec 2022 20:03:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiLIBDV (ORCPT ); Thu, 8 Dec 2022 20:03:21 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBB3694192 for ; Thu, 8 Dec 2022 17:03:20 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id q1so2513754pgl.11 for ; Thu, 08 Dec 2022 17:03:20 -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=uIG1fSR1LOk0TcUreHrxo/p2PRAMeYSvgKLfpsnCyGw=; b=cuPTOIf3lqLXGwy0TSP7hKgJ4s+exdm/BzVrX/Z7s89t4YfWCUuypg/W1SWGAXZenu gvLtuLc9chBdj1vwkfHwPH1jYRsptvzcolLQzLv8ljdjwsB2ALIdkshr5cbQ/3DMFNMn IR0FOSh3pOkS1BCdoHEaosfTxAXMUVSzqRoy8a2rKEFEqtJklHgvBgF5UjSx+fNZjXRU jiWq1oOpfFzmhu9RK6rJ/MnwXqCXJb2ES+LfU1eGz5lvcLCpa91a7RLAGWZ76Is/DMAq RZio6JlIn/DzPRb8+MW+cktrZX5RelulFs/+R1Lh6iCQ04FzG4vjTRoYNvDqbYoS+jsh HBvA== 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=uIG1fSR1LOk0TcUreHrxo/p2PRAMeYSvgKLfpsnCyGw=; b=yKp2hqgb2UXqaO8YDH/4Zm1NtfpRO35p4y6j+eNdTP6Qyu53gsxE0ZAGF6RyGIJGM4 5aSqVHaQmBYeYf23kovXzQLGKHc5u2WsoJODJiKvddum3L1yjniYUPTCdSjx6CfcJTh0 Kf2KTbZO+FYCdgEsonpBGGooX/SVOY1h8U2CTW/DQOERewcpL/reyqZF100beS7lOiNw B0eBa8+13uAnljo09t9Fbyf0a/3Ok1w6kdeyppPulPj7M7qtJ80uXTrepPbOSwOJ2wyq gQXVB5n4cZnQ3jSj/9KD74qnxCO1qRzp2Xm8WI8EUfYPstbTogiA/TSrMCzj4lbbEBOO 9DXQ== X-Gm-Message-State: ANoB5plPdDqNRSxQ0EPlTmDVBOTpsHmOChxf+6Z7f/QJuXgJpLcZ/Tgr R3N3s3KU4ovzfXIOhHDTgoB1j0pE+gwTtw== X-Google-Smtp-Source: AA0mqf50ocySCxNQNi1ttwXmewu6G5J3ObgmTqSj2G/euGuUBxExEEnos+rV53BN+jXqgG3otAOUBg== X-Received: by 2002:aa7:8b4d:0:b0:56c:962:fe7e with SMTP id i13-20020aa78b4d000000b0056c0962fe7emr3763292pfd.32.1670547799784; Thu, 08 Dec 2022 17:03:19 -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 z21-20020aa79495000000b005746c3b2445sm100253pfk.151.2022.12.08.17.03.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 17:03:19 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/5] shared/gatt-db: Allow passing NULL to gatt_db_attribute_write Date: Thu, 8 Dec 2022 17:03:13 -0800 Message-Id: <20221209010314.707606-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221209010314.707606-1-luiz.dentz@gmail.com> References: <20221209010314.707606-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 gatt_db_attribute_write to accept NULL as a func when storing directly on the db itself. --- src/shared/gatt-db.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index ba47c75ff70c..9a92090ec493 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -2095,7 +2095,7 @@ bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset, { uint8_t err = 0; - if (!attrib || !func) + if (!attrib || (!func && attrib->write_func)) return false; if (attrib->write_func) { @@ -2158,7 +2158,8 @@ bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset, memcpy(&attrib->value[offset], value, len); done: - func(attrib, err, user_data); + if (func) + func(attrib, err, user_data); return true; } From patchwork Fri Dec 9 01:03:14 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: 13069112 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 7572FC4332F for ; Fri, 9 Dec 2022 01:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbiLIBD1 (ORCPT ); Thu, 8 Dec 2022 20:03:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbiLIBD0 (ORCPT ); Thu, 8 Dec 2022 20:03:26 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6292675BC4 for ; Thu, 8 Dec 2022 17:03:22 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id q71so2522391pgq.8 for ; Thu, 08 Dec 2022 17:03:22 -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=E5PlASqkr7V5M3LtKayydLxXeJu/Pfna+WsACAa6qH0=; b=iWtN931OzDh15WjagLyoxDYn644fhEQHNA07xQU7CzrkA5zVvilUeDCDqqoJLnlFRg ItvCELbuOqJOGqfKkCt0cLveMG8qsJnpD5/iIU0pvGvoJlDnw1Oyr2NlYldgOPnhJIG+ 1IiNazhiGE3RDsd60vcCNrQRqN/N9PFnJ/K52hFy1Wqg+V0P+Od7CzZHUFZTAx/nC/Qu 0jmfioiKWNG+ouOJ3pCR2HLOO4XgrfvobB97I+ibQkGizQPr4Ew7jvl6mzcop+WaD9Ff iCl84xuryWdsFINfbofF+dzh8oxsivMrKT/8t22kQ+YB6kGC6k9n9oxefQeHWuBw47s9 LWng== 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=E5PlASqkr7V5M3LtKayydLxXeJu/Pfna+WsACAa6qH0=; b=NAVsVq+bvghrRwb4WbFkGeqlhJJOLwTLowFhw5O/MBMtL0RBuAwpaj7SRrGKjwtWAR fHUOY/h4NAlvBVe0tTAtuvtkrxLakTWJzE4syLRUXvD7VABulSr9qvFxRXoyaeNW61sK RS15KFCFcOx9fc1nFAbo/pIfhew5mqM/HyOZ/qMTjezeF1LOc6mpXa4ohssyZ6iRJeFK lnutmqYtQ/e8oFnIasXljmGDOGq4entDKhUktOuKXKFwoBo6TgD5BEmq+omqtSMeQYOo hg3f0gQaQnVN1dvQsJucPoTlVviU47UlmlbwKkyAl+dyUYf8CMGyhKL3mO1z6Sx4GV1G 7FDg== X-Gm-Message-State: ANoB5pkzN3VP1ShQJr0p451ItQIN3vGRfXFq15smchRArW7DfTdTnO4E Xzy2wg2glLl6jsquo2PCmA5+Ljw4GPOypg== X-Google-Smtp-Source: AA0mqf6tmcJoxekSC4tqutN5tnBqtGU2JtIVnGlZulhxzNKYV/lWaLXCc7RkvresZmukVzP2mOpJAQ== X-Received: by 2002:a62:18c6:0:b0:575:fdb6:8e55 with SMTP id 189-20020a6218c6000000b00575fdb68e55mr3639974pfy.7.1670547801154; Thu, 08 Dec 2022 17:03:21 -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 z21-20020aa79495000000b005746c3b2445sm100253pfk.151.2022.12.08.17.03.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Dec 2022 17:03:20 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 5/5] shared/bap: Make bt_bap_pac_register to be per session Date: Thu, 8 Dec 2022 17:03:14 -0800 Message-Id: <20221209010314.707606-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221209010314.707606-1-luiz.dentz@gmail.com> References: <20221209010314.707606-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_bap_pac_register to be per session rather than global so the callback don't have to match the session by itself. --- profiles/audio/bap.c | 6 ++-- src/shared/bap.c | 66 +++++++++++++++++++++++++------------------- src/shared/bap.h | 11 ++++---- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index f28843ae6b38..ae944b617bb4 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -120,7 +120,7 @@ static void bap_data_free(struct bap_data *data) queue_destroy(data->streams, NULL); bt_bap_ready_unregister(data->bap, data->ready_id); bt_bap_state_unregister(data->bap, data->state_id); - bt_bap_pac_unregister(data->pac_id); + bt_bap_pac_unregister(data->bap, data->pac_id); bt_bap_unref(data->bap); free(data); } @@ -1265,8 +1265,8 @@ static int bap_probe(struct btd_service *service) NULL); data->state_id = bt_bap_state_register(data->bap, bap_state, bap_connecting, data, NULL); - data->pac_id = bt_bap_pac_register(pac_added, pac_removed, service, - NULL); + data->pac_id = bt_bap_pac_register(data->bap, pac_added, pac_removed, + service, NULL); bt_bap_set_user_data(data->bap, service); diff --git a/src/shared/bap.c b/src/shared/bap.c index 391838a96c55..2919f243f78a 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -47,6 +47,7 @@ #define BAP_PROCESS_TIMEOUT 10 struct bt_bap_pac_changed { + unsigned int id; bt_bap_pac_func_t added; bt_bap_pac_func_t removed; bt_bap_destroy_func_t destroy; @@ -165,6 +166,7 @@ struct bt_bap { struct queue *notify; struct queue *streams; + struct queue *pac_cbs; struct queue *ready_cbs; struct queue *state_cbs; @@ -250,7 +252,6 @@ struct bt_pacs_context { /* Contains local bt_bap_db */ static struct queue *bap_db; -static struct queue *pac_cbs; static struct queue *bap_cbs; static struct queue *sessions; @@ -268,24 +269,26 @@ static void *iov_append(struct iovec *iov, size_t len, const void *d) return util_iov_push_mem(iov, len, d); } -unsigned int bt_bap_pac_register(bt_bap_pac_func_t added, +unsigned int bt_bap_pac_register(struct bt_bap *bap, bt_bap_pac_func_t added, bt_bap_pac_func_t removed, void *user_data, bt_bap_destroy_func_t destroy) { struct bt_bap_pac_changed *changed; + static unsigned int id; + + if (!bap) + return 0; changed = new0(struct bt_bap_pac_changed, 1); + changed->id = ++id ? id : ++id; changed->added = added; changed->removed = removed; changed->destroy = destroy; changed->data = user_data; - if (!pac_cbs) - pac_cbs = queue_new(); + queue_push_tail(bap->pac_cbs, changed); - queue_push_tail(pac_cbs, changed); - - return queue_length(pac_cbs); + return changed->id; } static void pac_changed_free(void *data) @@ -298,39 +301,28 @@ static void pac_changed_free(void *data) free(changed); } -struct match_pac_id { - unsigned int id; - unsigned int index; -}; - -static bool match_index(const void *data, const void *match_data) +static bool match_pac_changed_id(const void *data, const void *match_data) { - struct match_pac_id *match = (void *)match_data; + const struct bt_bap_pac_changed *changed = data; + unsigned int id = PTR_TO_UINT(match_data); - match->index++; - - return match->id == match->index; + return (changed->id == id); } -bool bt_bap_pac_unregister(unsigned int id) +bool bt_bap_pac_unregister(struct bt_bap *bap, unsigned int id) { struct bt_bap_pac_changed *changed; - struct match_pac_id match; - memset(&match, 0, sizeof(match)); - match.id = id; + if (!bap) + return false; - changed = queue_remove_if(pac_cbs, match_index, &match); + changed = queue_remove_if(bap->pac_cbs, match_pac_changed_id, + UINT_TO_PTR(id)); if (!changed) return false; pac_changed_free(changed); - if (queue_isempty(pac_cbs)) { - queue_destroy(pac_cbs, NULL); - pac_cbs = NULL; - } - return true; } @@ -2366,6 +2358,13 @@ static void notify_pac_added(void *data, void *user_data) changed->added(pac, changed->data); } +static void notify_session_pac_added(void *data, void *user_data) +{ + struct bt_bap *bap = data; + + queue_foreach(bap->pac_cbs, notify_pac_added, user_data); +} + struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db, const char *name, uint8_t type, uint8_t id, uint16_t cid, uint16_t vid, @@ -2402,7 +2401,7 @@ struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db, return NULL; } - queue_foreach(pac_cbs, notify_pac_added, pac); + queue_foreach(sessions, notify_session_pac_added, pac); return pac; } @@ -2434,6 +2433,13 @@ static void notify_pac_removed(void *data, void *user_data) changed->removed(pac, changed->data); } +static void notify_session_pac_removed(void *data, void *user_data) +{ + struct bt_bap *bap = data; + + queue_foreach(bap->pac_cbs, notify_pac_removed, user_data); +} + bool bt_bap_pac_set_ops(struct bt_bap_pac *pac, struct bt_bap_pac_ops *ops, void *user_data) { @@ -2480,7 +2486,7 @@ bool bt_bap_remove_pac(struct bt_bap_pac *pac) found: queue_foreach(sessions, remove_streams, pac); - queue_foreach(pac_cbs, notify_pac_removed, pac); + queue_foreach(sessions, notify_session_pac_removed, pac); bap_pac_free(pac); return true; } @@ -2552,6 +2558,7 @@ static void bap_free(void *data) bap_db_free(bap->rdb); + queue_destroy(bap->pac_cbs, pac_changed_free); queue_destroy(bap->ready_cbs, bap_ready_free); queue_destroy(bap->state_cbs, bap_state_free); @@ -2632,6 +2639,7 @@ struct bt_bap *bt_bap_new(struct gatt_db *ldb, struct gatt_db *rdb) bap->reqs = queue_new(); bap->pending = queue_new(); bap->notify = queue_new(); + bap->pac_cbs = queue_new(); bap->ready_cbs = queue_new(); bap->streams = queue_new(); bap->state_cbs = queue_new(); diff --git a/src/shared/bap.h b/src/shared/bap.h index 7b9f88c8320c..3558d0445486 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -87,12 +87,6 @@ typedef void (*bt_bap_stream_func_t)(struct bt_bap_stream *stream, typedef void (*bt_bap_func_t)(struct bt_bap *bap, void *user_data); /* Local PAC related functions */ - -unsigned int bt_bap_pac_register(bt_bap_pac_func_t added, - bt_bap_pac_func_t removed, void *user_data, - bt_bap_destroy_func_t destroy); -bool bt_bap_pac_unregister(unsigned int id); - struct bt_bap_pac_qos { uint8_t framing; uint8_t phy; @@ -161,6 +155,11 @@ bool bt_bap_set_debug(struct bt_bap *bap, bt_bap_debug_func_t cb, bool bap_print_cc(void *data, size_t len, util_debug_func_t func, void *user_data); +unsigned int bt_bap_pac_register(struct bt_bap *bap, bt_bap_pac_func_t added, + bt_bap_pac_func_t removed, void *user_data, + bt_bap_destroy_func_t destroy); +bool bt_bap_pac_unregister(struct bt_bap *bap, unsigned int id); + unsigned int bt_bap_ready_register(struct bt_bap *bap, bt_bap_ready_func_t func, void *user_data, bt_bap_destroy_func_t destroy);