Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1185885rwb; Wed, 28 Sep 2022 14:37:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48Creu/b7GKCTX/Uc/N37J3jPGj0SFuimtrdGbTTx/hEmtcF5jtJ1PpqSzMYwnUoms+X89 X-Received: by 2002:a17:902:7009:b0:178:b9c9:979f with SMTP id y9-20020a170902700900b00178b9c9979fmr15796plk.39.1664401049823; Wed, 28 Sep 2022 14:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664401049; cv=none; d=google.com; s=arc-20160816; b=RmMYWyza3ICEA4yQwamB1iC4m5Su+zLAkaj7OY6okemjlnWUo+dJe1d9SbvssUiR4v IAlr0PpIbJR8e0Ibwz6/XqWIq8dZbDPFx5GNOUlAZRUeVXZ2IuWjdm5xfMOOUZZSTgcH tmsPrCF+6Sv8J4izsDTYZoVe8y7OQjVdel2NchpL9I5riafV5kNOgvRGP9gcyZgK63K9 UpgSY9UbhgJgd/DMZikzSmM24Sj1rU2WxorfuVzCTVwVHlUZNaYE1VYX2aQoOjUqyJ4+ JGt7Uy6ReAMfTJgZrqu3kKCu2lozPD/Q7GBqe/x79OkDVeTRU7pc/aXzCKDuUqhOStmU 4Xbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=K/koYjTIKng4CMvyXLwMuTWvexuMIhrGUzFRql4YZ4I=; b=u8cqFk6zY9fyTy0hJ5eWVfnB/DxGkKcVt2gQEjdWsILHhm2c++h1WNn6OPr6YfbE8X fhQq9GVnfu4PQEztB6+OEGOF5Rk1u4Xr3ASgjJP/sA4RAutL4iu1aag31YyeHKyupatj zVU7ETxeZEERPfQWhUSEWwadb9wiPFDLqch0hJ/1QdzkJ6YxZczEyreJQLfJ86XWBv7G iWrO9z4rLfWzqpXIyDKYVABXt2BMkqqTCXvkquDW0rDG5I5C2K3Hajb260urKQKvSyd7 NkQ/FaiUu+3Y20G/xeMOdUnRPap/4g0pJ7/Qs6pBb5htjrZxPeTPeDZj8//tRqYhPq64 oHGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iGYh4wbt; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i69-20020a636d48000000b0043962021951si6923437pgc.748.2022.09.28.14.37.05; Wed, 28 Sep 2022 14:37:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iGYh4wbt; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233785AbiI1V0y (ORCPT + 99 others); Wed, 28 Sep 2022 17:26:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233601AbiI1V0x (ORCPT ); Wed, 28 Sep 2022 17:26:53 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7747267453 for ; Wed, 28 Sep 2022 14:26:52 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id v4so13312471pgi.10 for ; Wed, 28 Sep 2022 14:26:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=K/koYjTIKng4CMvyXLwMuTWvexuMIhrGUzFRql4YZ4I=; b=iGYh4wbtGz0ZGH3HCDhIvQKX+TFmz0TwOJaRYem2WSxhqg9KbVtWJhJFV7+CdljOSJ AUpBEAFs681p7QQFixCX39LwsVsKLNXTxcou2+hG3yN3m1mecWHTa1WLJiGrJn5CO8x4 c/xAAMNND9DwJt3yzEMf9lGYlO73oC8vg/aMts/IW0YSk6EmX1OvbXYM1ilLxMRZAqUz dQsaTBcGGIv8W+KzWyaffkb/IQPA44r/drtF9VF1zxIBCF/KLkmDcR6+AQM3VnpDR7r4 niw39FHHgiOo0+IvgwbChS1f7twGfsS3rQt/+l9DvrHbz37/HUSRjqyIAWid9HEOaF4I SHJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=K/koYjTIKng4CMvyXLwMuTWvexuMIhrGUzFRql4YZ4I=; b=NyDs/+o6Y8zgMZoSqgbz3fUVp7j8Mf53GmvxMxdnHNUCfSr6ONb5G0zafYyWfgMq/4 Vu5tCmMjPH+7+EVssFbSd89ki8CGveIzlJmTI2YvvQwG+u1pUvZAiC5JX7B6vxLwihEI /1QdDlSQFvQSGdt7xMY5o/27U6pLahG08KaDyFi5OZ3CI5Ju1ih7vqZYagugH6H9T0oT CVL1Wop1PRr798Tz8aTQZu5BM0ARGGnrcHxThqeft2prj/xyE/PgxV05yq6sRY8AIzUW 5eIAsfMU2DUvPniTkwbnP4oqCtsb6HrxXFF1FXmPjS9ehs979oxfHf4hoUm3e9VUo9/V h95w== X-Gm-Message-State: ACrzQf30dvnIzw5GJynHRdtM6f5ooV6gC8+GrPv5j/7cHKK7zneCh5aK ysVyVS0fpgL2P3JAIPFaAHlOvzyZZrfOTw== X-Received: by 2002:aa7:8896:0:b0:556:cc53:3f43 with SMTP id z22-20020aa78896000000b00556cc533f43mr30162210pfe.19.1664400411364; Wed, 28 Sep 2022 14:26:51 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id s23-20020a170902b19700b00177f8f234cesm4176371plr.258.2022.09.28.14.26.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 14:26:50 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] client/player: Fix attempting to acquire already acquired transport Date: Wed, 28 Sep 2022 14:26:49 -0700 Message-Id: <20220928212649.3824261-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz If the transport has links check if the link is acquiring before attempting to call Acquire otherwise it may cause an error to be printed. --- client/player.c | 70 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/client/player.c b/client/player.c index 30ae263c8e41..4324089345c1 100644 --- a/client/player.c +++ b/client/player.c @@ -65,6 +65,7 @@ struct endpoint { uint8_t codec; struct iovec *caps; bool auto_accept; + bool acquiring; uint8_t cig; uint8_t cis; char *transport; @@ -2688,6 +2689,30 @@ static struct endpoint *find_ep_by_transport(const char *path) return NULL; } +static struct endpoint *find_link_by_proxy(GDBusProxy *proxy) +{ + DBusMessageIter iter, array; + + if (!g_dbus_proxy_get_property(proxy, "Links", &iter)) + return NULL; + + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == + DBUS_TYPE_OBJECT_PATH) { + const char *transport; + struct endpoint *link; + + dbus_message_iter_get_basic(&array, &transport); + + link = find_ep_by_transport(transport); + if (link) + return link; + } + + return NULL; +} + static void transport_close(struct transport *transport) { if (transport->fd < 0) @@ -2769,10 +2794,19 @@ static void transport_new(GDBusProxy *proxy, int sk, uint16_t mtu[2]) static void acquire_reply(DBusMessage *message, void *user_data) { GDBusProxy *proxy = user_data; + struct endpoint *ep, *link; DBusError error; int sk; uint16_t mtu[2]; + ep = find_ep_by_transport(g_dbus_proxy_get_path(proxy)); + if (ep) { + ep->acquiring = false; + link = find_link_by_proxy(proxy); + if (link) + link->acquiring = false; + } + dbus_error_init(&error); if (dbus_set_error_from_message(&error, message) == TRUE) { @@ -2803,11 +2837,22 @@ static void acquire_reply(DBusMessage *message, void *user_data) static void transport_acquire(const char *input, void *user_data) { GDBusProxy *proxy = user_data; + struct endpoint *ep, *link; if (!strcasecmp(input, "y") || !strcasecmp(input, "yes")) { - if (!g_dbus_proxy_method_call(proxy, "Acquire", NULL, + if (g_dbus_proxy_method_call(proxy, "Acquire", NULL, acquire_reply, proxy, NULL)) - bt_shell_printf("Failed acquire transport\n"); + return; + bt_shell_printf("Failed acquire transport\n"); + } + + /* Reset acquiring */ + ep = find_ep_by_transport(g_dbus_proxy_get_path(proxy)); + if (ep) { + ep->acquiring = false; + link = find_link_by_proxy(proxy); + if (link) + link->acquiring = false; } } @@ -2815,7 +2860,7 @@ static void transport_property_changed(GDBusProxy *proxy, const char *name, DBusMessageIter *iter) { char *str; - struct endpoint *ep; + struct endpoint *ep, *link; str = proxy_description(proxy, "Transport", COLORED_CHG); print_iter(str, name, iter); @@ -2833,14 +2878,29 @@ static void transport_property_changed(GDBusProxy *proxy, const char *name, * endpoint. */ ep = find_ep_by_transport(g_dbus_proxy_get_path(proxy)); - if (!ep) + if (!ep || ep->acquiring) return; + ep->acquiring = true; + + link = find_link_by_proxy(proxy); + if (link) { + bt_shell_printf("Link %s found\n", link->transport); + /* If link already acquiring wait it to be complete */ + if (link->acquiring) + return; + link->acquiring = true; + } + if (ep->auto_accept) { bt_shell_printf("Auto Acquiring...\n"); if (!g_dbus_proxy_method_call(proxy, "Acquire", NULL, - acquire_reply, proxy, NULL)) + acquire_reply, proxy, NULL)) { bt_shell_printf("Failed acquire transport\n"); + ep->acquiring = false; + if (link) + link->acquiring = false; + } return; } -- 2.37.3