From patchwork Wed Mar 1 01:38:38 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: 13155414 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 0184BC64EC7 for ; Wed, 1 Mar 2023 01:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbjCABir (ORCPT ); Tue, 28 Feb 2023 20:38:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbjCABiq (ORCPT ); Tue, 28 Feb 2023 20:38:46 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D493B72B4 for ; Tue, 28 Feb 2023 17:38:45 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id c4so4090797pfl.0 for ; Tue, 28 Feb 2023 17:38:45 -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=4YaGfX2wY7SgSpQy9OYBDc4VfC7LIGHh5xnF/v8hf1c=; b=SkCxE2n6IwyBS8JJXtuMCtta+0qBUOj1/At+vTPbAX2jTeMGKMU8QxE/Rowq8MTse+ OgZ+sk8lfGVO0K2okjMx2NX/V8Ns/H0kr/xVXd0y/xR3I+zwyJ0Q+jCxrsHxU+duC4La tbwMQV42zAeVQQ8blzqLxDjbuqGsyHniR67j7zt6O/Lbb9O6Zu7NOrd05xxl46QRp/Yp bYoqVvoforPRxSB+mIiMM+Ayk3L8Bmup0/sg4OpHTJ9Ppk6w7e74u8+ILujDcAxxu/f7 paouFmdXkdr1Q8QbLJTOefsayyk991ZdBEVjrYnjGpsnqbU/8gTzRFJCBeZeJABTPZz3 pptg== 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=4YaGfX2wY7SgSpQy9OYBDc4VfC7LIGHh5xnF/v8hf1c=; b=XpFAm94vj3cqw/MZFkBBGLQ3W6CQ7FQWfu6nBm4VF55tMQvkkT6nE1tJdb6WdCCyBs p7eVxOtPp6QsefYV0Chfhci6+XyhgL5hSHkBZrfv0bwRXfbNOLGOfjIXo2q7tFSDYvgI beePPi+0p9ucRoijtnCItcec/AizQWZRhCoxa9ehYk0/3tmlcWJpGlraGt49xMlYx0A5 IAxWY+8XK+wrYhsyQTycg0u2cw+13hSZkEvAUStpS6aSlKU26pd/7WRxs94u2W5+sgYa ErnMRI2Zkp29EKwhPYz0pomuONjJWlGM2sJm8B7y8y4F8bwyawUrtTFo7uaQJn2fG+b9 z4dg== X-Gm-Message-State: AO0yUKUp8CyjWc3WyTz1+fr06qy4sc420mEleIhtEEP3rZ3aFOIQNK43 QTOnjkKVmsAz3TUh3vaBI6/qWw+JBiM= X-Google-Smtp-Source: AK7set/EwpXj4ZuTHkqfj5t+F/slcmRtoYOzAMzKpIgu9oIoL1zMpA1UMFce3VQcytBuNPFpvhDQNA== X-Received: by 2002:a05:6a00:18a4:b0:594:26a7:cbd2 with SMTP id x36-20020a056a0018a400b0059426a7cbd2mr6285475pfh.8.1677634724669; Tue, 28 Feb 2023 17:38:44 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id c1-20020aa78801000000b005d866d184b5sm6627797pfo.46.2023.02.28.17.38.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 17:38:44 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/5] device: Don't attempt to connect LE if ATT is already connected Date: Tue, 28 Feb 2023 17:38:38 -0800 Message-Id: <20230301013842.718438-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This checks if an att instance already exists before attempting to connect it once again. --- src/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index d270421cc7c9..cb16d37c1ae1 100644 --- a/src/device.c +++ b/src/device.c @@ -5422,7 +5422,7 @@ int device_connect_le(struct btd_device *dev) char addr[18]; /* There is one connection attempt going on */ - if (dev->att_io) + if (dev->att_io || dev->att) return -EALREADY; ba2str(&dev->bdaddr, addr); From patchwork Wed Mar 1 01:38:39 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: 13155415 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 C9CCAC7EE30 for ; Wed, 1 Mar 2023 01:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbjCABit (ORCPT ); Tue, 28 Feb 2023 20:38:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbjCABir (ORCPT ); Tue, 28 Feb 2023 20:38:47 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F22EA6EA5 for ; Tue, 28 Feb 2023 17:38:46 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id u20so6984375pfm.7 for ; Tue, 28 Feb 2023 17:38:46 -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=5GAZV8ATK33ceYZSpnWzTqubtZsqMxwwDBkcdr8J4Ew=; b=JNOdNbjsDITAvaaCazMn03Z/Drv7FZuM30dvu7QeS6EnuTaH/KNUunIjrujmrkPWIJ m/G1NxxfBZtW9fWBcuVnn6isGXNYtbjYYcGlAnOXJZijWcZ2PsSRMdeTU+LF/qVDekeO MkRYNsoLCWesnMq4qTiB3t9UCqmM1jRyHy/YwlDOC2rkMwHq2S//v3qdwwNyWxZoiyb/ m5HaZLgg7W3LUmDAc7fxlN5QHDwVqxMo7v2BaID/izgK8eR0UUrLhStb5igkX9247IWC oJWh/IbqgZSTsnM9m+eBi44VDe0yWcgr1oGeyaym0so4zYCrW6zJNVlLSLSD20XDGwEd GNfA== 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=5GAZV8ATK33ceYZSpnWzTqubtZsqMxwwDBkcdr8J4Ew=; b=Ullac8o3kjfECIbnpYsm3UXIiwgoIqlHXqUVe4ssVVznrqwouN/OZdJcbswBKZoHbL 3dlubWKP2KyMWRyb6X9VFFyQvccd9g77YIJKs61ghb2MlRJCIE2dUW3MzPKFUnhFFlWE dX1TlV5OTqU32+TRMnnI8zormMtsWOMd8vn30xNPOxZUd6Mf9bUVedqrJMzMZ8aP7h6i o9kXpEribBt6RXLA2lXAN+jKtYBM5WL1cR8Nz6ee0vV1NrdXIJC/sg2mY61bW7wyh4up gaBZy/u+6Ke9K8aU49BeTtPdvakfuo8bmezVBjWHC+75JYAr2lhg/juDLIM15RQOzjx2 s2Sg== X-Gm-Message-State: AO0yUKX0QCBvY5F06xoa3BsZPXqGWkwapQ5aIfyZDcjqBpTtw6k3SkLo EubyMC5szwtbNWy7YCHDuF+MzYxwkm8= X-Google-Smtp-Source: AK7set8di9jOGG756nvla8AApMS0vHMHC9xOdetUemok9fpydn0xAS8JuznymggU5VHhF2YQI09Ytw== X-Received: by 2002:aa7:8bc7:0:b0:5a8:4861:af7d with SMTP id s7-20020aa78bc7000000b005a84861af7dmr4614275pfd.20.1677634725967; Tue, 28 Feb 2023 17:38:45 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id c1-20020aa78801000000b005d866d184b5sm6627797pfo.46.2023.02.28.17.38.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 17:38:45 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/5] client: Allow transport.send command to work with multiple transports Date: Tue, 28 Feb 2023 17:38:39 -0800 Message-Id: <20230301013842.718438-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301013842.718438-1-luiz.dentz@gmail.com> References: <20230301013842.718438-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 enables transport.send to work with multiple transports instead of sending one by one which can create synchronization problems. --- client/player.c | 71 +++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/client/player.c b/client/player.c index 65cac3b50376..767304b567b6 100644 --- a/client/player.c +++ b/client/player.c @@ -3566,48 +3566,54 @@ static void cmd_send_transport(int argc, char *argv[]) { GDBusProxy *proxy; struct transport *transport; - int fd, err; + int fd = -1, err; struct bt_iso_qos qos; socklen_t len; + int i; - proxy = g_dbus_proxy_lookup(transports, NULL, argv[1], + for (i = 1; i < argc; i++) { + proxy = g_dbus_proxy_lookup(transports, NULL, argv[i], BLUEZ_MEDIA_TRANSPORT_INTERFACE); - if (!proxy) { - bt_shell_printf("Transport %s not found\n", argv[1]); - return bt_shell_noninteractive_quit(EXIT_FAILURE); - } + if (!proxy) { + bt_shell_printf("Transport %s not found\n", argv[i]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } - transport = find_transport(proxy); - if (!transport) { - bt_shell_printf("Transport %s not acquired\n", argv[1]); - return bt_shell_noninteractive_quit(EXIT_FAILURE); - } + transport = find_transport(proxy); + if (!transport) { + bt_shell_printf("Transport %s not acquired\n", argv[i]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } - if (transport->sk < 0) { - bt_shell_printf("No Transport Socked found\n"); - return bt_shell_noninteractive_quit(EXIT_FAILURE); - } + if (transport->sk < 0) { + bt_shell_printf("No Transport Socked found\n"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } - fd = open_file(argv[2], O_RDONLY); - if (fd < 0) - return bt_shell_noninteractive_quit(EXIT_FAILURE); + if (i + 1 < argc) { + fd = open_file(argv[++i], O_RDONLY); + if (fd < 0) + return bt_shell_noninteractive_quit( + EXIT_FAILURE); + } - bt_shell_printf("Sending ...\n"); + bt_shell_printf("Sending ...\n"); - /* Read QoS if available */ - memset(&qos, 0, sizeof(qos)); - len = sizeof(qos); - if (getsockopt(transport->sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, + /* Read QoS if available */ + memset(&qos, 0, sizeof(qos)); + len = sizeof(qos); + if (getsockopt(transport->sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, &len) < 0) - err = transport_send(transport, fd, NULL); - else - err = transport_send(transport, fd, &qos); + err = transport_send(transport, fd, NULL); + else + err = transport_send(transport, fd, &qos); - if (err < 0) { - bt_shell_printf("Unable to send: %s (%d)", strerror(-err), - -err); - close(fd); - return bt_shell_noninteractive_quit(EXIT_FAILURE); + if (err < 0) { + bt_shell_printf("Unable to send: %s (%d)", + strerror(-err), -err); + close(fd); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } } return bt_shell_noninteractive_quit(EXIT_SUCCESS); @@ -3710,7 +3716,8 @@ static const struct bt_shell_menu transport_menu = { { "release", " [transport1...]", cmd_release_transport, "Release Transport", transport_generator }, - { "send", " ", cmd_send_transport, + { "send", " [transport1...]", + cmd_send_transport, "Send contents of a file", transport_generator }, { "receive", " [filename]", cmd_receive_transport, From patchwork Wed Mar 1 01:38:40 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: 13155416 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 80E83C64EC7 for ; Wed, 1 Mar 2023 01:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229616AbjCABiu (ORCPT ); Tue, 28 Feb 2023 20:38:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjCABis (ORCPT ); Tue, 28 Feb 2023 20:38:48 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4459172B4 for ; Tue, 28 Feb 2023 17:38:48 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id n5so6970372pfv.11 for ; Tue, 28 Feb 2023 17:38:48 -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=W04EP7uIcNCXxKLzunaMiIGbxjY2vfSCOWRxtUUUARQ=; b=EIMYmanidK916bc+UEDy3mtbFzfZ+Mdu+BSMMFK9Ror4hZxE4asZn6+ZSTzeabPrJD +N6pYPMaFIYVCvRXGc5MwC+CG0Y6L3PNyLOWHLylsvOADCF7MLdL4zIsgqJRrsLndaHn mk5w6Osu87klrkeoTdZtZwGlP46FDqwk+34V+JaM3EonSSYc+xnMfDvHQEAgyE0+8JN+ o7LZrpGDMrgZGwcYFUjvF/eJ2EcMLarHQSIXUUJHleWwkOgzCMOFh+EN+SXJyQuedGbn /VYSElvyVEP34fSK29+2gA4EbX5pYiJwOZ0Rv97TNYm3XRoEqzPh9GAnETzgrQaMmPoR RWlQ== 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=W04EP7uIcNCXxKLzunaMiIGbxjY2vfSCOWRxtUUUARQ=; b=UU2uwQIvAclF3YUOQsj5Wc7kKxsF60Eg62QtwqNVfIQEZXWCoP6GL1K+7Z/jjqcys2 UISnxQ8MwP0fRmOe1WwvulfXs/u6ty1kSgMoJzslK6zGrS5h0GMitdOzM4vv+W5n8azH ofPtoNvuUuocdtmwdssU/O/c9fNcsKXAQSRzxxDdgyCn1TA5v9vOztBYf+mAa+EybPzb nqfvm7mpXIH72D6NsOieq5xjF5NkHRTuXQrA2dWOeWB6+8bS26Zwe8aJiTcBh6ErqLO5 tEUR3tKMZjxKnbV8E9ktog+fAhfGpYm60UfP3FovQRi/VSoGk2iU1R9KcfW3MqycaTgs oCBQ== X-Gm-Message-State: AO0yUKWhW2XUaWN/gqm06jHhVaJHD7nnEhW56fM8b8LCwUSMSoV8TtmC JuIoN9b75+wdTEAWRiPlKF8Z04ayH4U= X-Google-Smtp-Source: AK7set85vr7yull9L64dDgntAkFBPPgMg7EPOHrpUO2AdynDDXSVaFEDOyVIQiIJZ13t2XQd3wd4rw== X-Received: by 2002:a62:8406:0:b0:5f1:468b:c88 with SMTP id k6-20020a628406000000b005f1468b0c88mr5105256pfd.27.1677634727195; Tue, 28 Feb 2023 17:38:47 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id c1-20020aa78801000000b005d866d184b5sm6627797pfo.46.2023.02.28.17.38.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 17:38:46 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/5] shared/bap: Cleanup requests on detach Date: Tue, 28 Feb 2023 17:38:40 -0800 Message-Id: <20230301013842.718438-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301013842.718438-1-luiz.dentz@gmail.com> References: <20230301013842.718438-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 session is being detached any ongoing/queue request shall be cancelled as well otherwise when the session is attach again they would be invalid. --- src/shared/bap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/shared/bap.c b/src/shared/bap.c index f16ba1832aaa..c63612f0da47 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -3820,6 +3820,13 @@ static void stream_foreach_detach(void *data, void *user_data) stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE); } +static void bap_req_detach(void *data) +{ + struct bt_bap_req *req = data; + + bap_req_complete(req, NULL); +} + void bt_bap_detach(struct bt_bap *bap) { DBG(bap, "%p", bap); @@ -3827,6 +3834,15 @@ void bt_bap_detach(struct bt_bap *bap) if (!queue_remove(sessions, bap)) return; + /* Cancel ongoing request */ + if (bap->req) { + bap_req_detach(bap->req); + bap->req = NULL; + } + + /* Cancel queued requests */ + queue_remove_all(bap->reqs, NULL, NULL, bap_req_detach); + bt_gatt_client_unref(bap->client); bap->client = NULL; From patchwork Wed Mar 1 01:38: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: 13155417 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 4D911C64EC4 for ; Wed, 1 Mar 2023 01:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbjCABiw (ORCPT ); Tue, 28 Feb 2023 20:38:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbjCABiv (ORCPT ); Tue, 28 Feb 2023 20:38:51 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5E7772B4 for ; Tue, 28 Feb 2023 17:38:49 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id ay18so7009007pfb.2 for ; Tue, 28 Feb 2023 17:38: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=tuL7x06KCUAGT/baTjZciPSIQaAnLSWSJeDKCUgKR/0=; b=Mwz1L4C9ConoRAA9+CDKlO85jQvea1w3EuA1QLRwEZ5B3xeNDu5oNoVlGT+nsepCcj u4M+HmOcEvtA/Vp1MIOMC/dleFkn7aB6bdjRQoUDxCDIOXgKXjz9CrHQmx75bOj06AAV L5pDjeZLTek3hx3ezYgqWoMzQ9K/DgdtLIYR4/yRfaRpdJNlXVq2EMveb2CByAlCp2f5 hnTwYw2jKj4sRJ+uR4GqtCPi5Yb1w/JHf4QdFFfkTnY4W3jm0ZVH0IJC5G/ZpYxl8/pi F2JPYMdfqRpvj2O6T6y2A+Oy7ARQhBLHtrEXl6Nu956FggfJBH8zTuyguBCCQsvZuMKX tliA== 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=tuL7x06KCUAGT/baTjZciPSIQaAnLSWSJeDKCUgKR/0=; b=n9BGFDRqTzdAbM5FSYPY+SlpIx5/DCmLDwqzIJzebz+g4pK8mjoDpYy31DEov9EsCv U2B4bJmNW7b3LgplcS3jU8M5qroKa9wf391kD7lS+lDWwK4CT1mqtWuEo+9Ec8A66IX2 45hbRei1io32m0/ReuhwzOhntfa8Sm+fLjpdyBcLNYjNQ5SKUAyw95l/K8ic+7CUeMCG YAvRA1C/e73pG+ZKM7ADgxmjEjjhd35fIqbXFKgbCFW9fwIEqfSrr2UYL3zq435SpNU8 SbapMPjgLdAdXwfzXyRd0yYOlzJQAeIXBiy0BYMJ+YB3b8ZWU5I0AAhNnmqPKBCztUdJ 7kwg== X-Gm-Message-State: AO0yUKWAGaP3CPCCqs77zI0QbXgvCq3xv9kDuUI9jUw0/wj01Srt6rsV dpDfVTSteCPo1rv0gFzwE9kKL2mbi4U= X-Google-Smtp-Source: AK7set8HntpBJ8Rj/mpY1GHC0Xy/VqmNNVRV1bP9pkKxZxSvSPsAKq4dgqFk6LmI5wDHpFhhJvgCAQ== X-Received: by 2002:aa7:93c8:0:b0:5a9:cc1f:b2ef with SMTP id y8-20020aa793c8000000b005a9cc1fb2efmr4380118pff.26.1677634728775; Tue, 28 Feb 2023 17:38:48 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id c1-20020aa78801000000b005d866d184b5sm6627797pfo.46.2023.02.28.17.38.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 17:38:47 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/5] share/gatt-client: Introduce idle callback Date: Tue, 28 Feb 2023 17:38:41 -0800 Message-Id: <20230301013842.718438-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301013842.718438-1-luiz.dentz@gmail.com> References: <20230301013842.718438-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 the concept of idle callback which can be used to get notified when there is no more pending requests by the client. --- src/shared/gatt-client.c | 78 ++++++++++++++++++++++++++++++++++++++-- src/shared/gatt-client.h | 8 +++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index baff68f28c65..f885076913dc 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -47,6 +47,12 @@ struct ready_cb { void *data; }; +struct idle_cb { + bt_gatt_client_idle_callback_t callback; + bt_gatt_client_destroy_func_t destroy; + void *data; +}; + struct bt_gatt_client { struct bt_att *att; int ref_count; @@ -56,6 +62,7 @@ struct bt_gatt_client { struct queue *clones; struct queue *ready_cbs; + struct queue *idle_cbs; bt_gatt_client_service_changed_callback_t svc_chngd_callback; bt_gatt_client_destroy_func_t svc_chngd_destroy; @@ -147,9 +154,38 @@ static struct request *request_create(struct bt_gatt_client *client) return request_ref(req); } +static void idle_destroy(void *data) +{ + struct idle_cb *idle = data; + + if (idle->destroy) + idle->destroy(idle->data); + + free(idle); +} + +static bool idle_notify(const void *data, const void *user_data) +{ + const struct idle_cb *idle = data; + + idle->callback(idle->data); + + return true; +} + +static void notify_client_idle(struct bt_gatt_client *client) +{ + bt_gatt_client_ref(client); + + queue_remove_all(client->idle_cbs, idle_notify, NULL, idle_destroy); + + bt_gatt_client_unref(client); +} + static void request_unref(void *data) { struct request *req = data; + struct bt_gatt_client *client = req->client; if (__sync_sub_and_fetch(&req->ref_count, 1)) return; @@ -157,8 +193,11 @@ static void request_unref(void *data) if (req->destroy) req->destroy(req->data); - if (!req->removed) - queue_remove(req->client->pending_requests, req); + if (!req->removed) { + queue_remove(client->pending_requests, req); + if (queue_isempty(client->pending_requests)) + notify_client_idle(client); + } free(req); } @@ -2234,6 +2273,7 @@ static void bt_gatt_client_free(struct bt_gatt_client *client) queue_destroy(client->notify_list, notify_data_cleanup); queue_destroy(client->ready_cbs, ready_destroy); + queue_destroy(client->idle_cbs, idle_destroy); if (client->debug_destroy) client->debug_destroy(client->debug_data); @@ -2292,6 +2332,7 @@ static struct bt_gatt_client *gatt_client_new(struct gatt_db *db, client->clones = queue_new(); client->ready_cbs = queue_new(); + client->idle_cbs = queue_new(); client->long_write_queue = queue_new(); client->svc_chngd_queue = queue_new(); client->notify_list = queue_new(); @@ -3727,3 +3768,36 @@ int bt_gatt_client_get_security(struct bt_gatt_client *client) return bt_att_get_security(client->att, NULL); } + +unsigned int bt_gatt_client_idle_register(struct bt_gatt_client *client, + bt_gatt_client_idle_callback_t callback, + void *user_data, + bt_gatt_client_destroy_func_t destroy) +{ + struct idle_cb *idle; + + if (!client) + return 0; + + idle = new0(struct idle_cb, 1); + idle->callback = callback; + idle->destroy = destroy; + idle->data = user_data; + + queue_push_tail(client->idle_cbs, idle); + + return PTR_TO_UINT(idle); +} + +bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client, + unsigned int id) +{ + struct idle_cb *idle = UINT_TO_PTR(id); + + if (queue_remove(client->idle_cbs, idle)) { + idle_destroy(idle); + return true; + } + + return false; +} diff --git a/src/shared/gatt-client.h b/src/shared/gatt-client.h index dc51023942ca..bccd04a62003 100644 --- a/src/shared/gatt-client.h +++ b/src/shared/gatt-client.h @@ -26,6 +26,7 @@ struct bt_gatt_client *bt_gatt_client_ref(struct bt_gatt_client *client); void bt_gatt_client_unref(struct bt_gatt_client *client); typedef void (*bt_gatt_client_destroy_func_t)(void *user_data); +typedef void (*bt_gatt_client_idle_callback_t)(void *user_data); typedef void (*bt_gatt_client_callback_t)(bool success, uint8_t att_ecode, void *user_data); typedef void (*bt_gatt_client_debug_func_t)(const char *str, void *user_data); @@ -126,3 +127,10 @@ bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client, bool bt_gatt_client_set_security(struct bt_gatt_client *client, int level); int bt_gatt_client_get_security(struct bt_gatt_client *client); + +unsigned int bt_gatt_client_idle_register(struct bt_gatt_client *client, + bt_gatt_client_idle_callback_t callback, + void *user_data, + bt_gatt_client_destroy_func_t destroy); +bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client, + unsigned int id); From patchwork Wed Mar 1 01:38: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: 13155418 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 5CE68C64EC7 for ; Wed, 1 Mar 2023 01:38:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229644AbjCABix (ORCPT ); Tue, 28 Feb 2023 20:38:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjCABiw (ORCPT ); Tue, 28 Feb 2023 20:38:52 -0500 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB496EA5 for ; Tue, 28 Feb 2023 17:38:51 -0800 (PST) Received: by mail-pg1-x532.google.com with SMTP id 16so6817756pge.11 for ; Tue, 28 Feb 2023 17:38: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=OA9iervL+7rtsaNKFx0KRJgwvjRozbQf+1ydxaKazE8=; b=bTBCewro6mHwK47123uHXTXY1dxXFRO/qZkfuiriL9Wkwze3F5zVtOqbZsvAc+VV/c 1msdGBfp7JTuAjn48cDzsxUeDylxj+Rt/Rz4BN9zomgg9xjf5DVlgQG4esqrZMA6Mszl Ve4DInsaKQaTww//1yGw0X+w+mbvUtMhzvRn5pebN3RC29u8P8PQu7Im4O7E5hfpq5zp S2iOkNypMSNyr/0L8t69yL71O3ODTGK2mg/oT+/Olwas321zpVSBALGdWh/DdL5GVA/N nU5hLPt/JH14hz1h++ktGjNvkKDW0oJUGfJLmZO5G2/AIylD3K5E787do32BtiO85gF3 O5Tg== 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=OA9iervL+7rtsaNKFx0KRJgwvjRozbQf+1ydxaKazE8=; b=6AxnY6rcF+grT/lq76ZDO9yiE6gwUujFA+73HkFmNHC3MFzubVEnbhiawXEJVKDZM3 JT05G/wEw26V27uZVcVSLBjZSpsxFPa34RWoAeLMGPfvTdm+eK0itzqK5dUGveM4UySt fpGEamzb/iP8CmfTRNGYdIRtuvafsh1gNIX1fOHPyM226Ys91r7WFGNS+C6BFf5U07WC NJXG+BQLWNKvhSlFsFFkO7WCDceT0mnJenHHKO4SGyy5i9KJVadDPS+NQtAftrUi5XGH zEf4hlN55AHRculSPQHaanWbpjV3KrmKWcXvHMtPValUHMWf34wNveudAXhyELM3/7G8 Rh1Q== X-Gm-Message-State: AO0yUKV72r4n5L8+i+cyCY/M6ij2l7mKS5Cv7xhtEQf1fbne47BwfGvE OGOqHWeEE39DVpmoqPfkaq5i9AtYKP0= X-Google-Smtp-Source: AK7set8xEotOnOtvbAMSA+DlN7ofLaNOgp16kuUKq4wYN12cRtwGtGiKytSgVYoRmThf67ixYrW8Mw== X-Received: by 2002:a62:1bd2:0:b0:5ab:bf5d:a0d1 with SMTP id b201-20020a621bd2000000b005abbf5da0d1mr3986637pfb.7.1677634730100; Tue, 28 Feb 2023 17:38:50 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id c1-20020aa78801000000b005d866d184b5sm6627797pfo.46.2023.02.28.17.38.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 17:38:49 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 5/5] media: Fix not checking BREDR support for A2DP Date: Tue, 28 Feb 2023 17:38:42 -0800 Message-Id: <20230301013842.718438-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230301013842.718438-1-luiz.dentz@gmail.com> References: <20230301013842.718438-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 A2DP shall depend on MGMT_SETTING_BREDR setting so the likes of bluetoothctl -e don't attempt to register A2DP with controller that are on LE only mode. --- profiles/audio/media.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 326e50a0925b..540e91bc6706 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -1269,8 +1269,11 @@ static bool endpoint_properties_get(const char *uuid, return true; } -static bool endpoint_supported(struct btd_adapter *adapter) +static bool a2dp_endpoint_supported(struct btd_adapter *adapter) { + if (!btd_adapter_has_settings(adapter, MGMT_SETTING_BREDR)) + return false; + return true; } @@ -1291,8 +1294,10 @@ static struct media_endpoint_init { bool (*func)(struct media_endpoint *endpoint, int *err); bool (*supported)(struct btd_adapter *adapter); } init_table[] = { - { A2DP_SOURCE_UUID, endpoint_init_a2dp_source, endpoint_supported }, - { A2DP_SINK_UUID, endpoint_init_a2dp_sink, endpoint_supported }, + { A2DP_SOURCE_UUID, endpoint_init_a2dp_source, + a2dp_endpoint_supported }, + { A2DP_SINK_UUID, endpoint_init_a2dp_sink, + a2dp_endpoint_supported }, { PAC_SINK_UUID, endpoint_init_pac_sink, experimental_endpoint_supported }, { PAC_SOURCE_UUID, endpoint_init_pac_source,