Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7901448rdb; Thu, 4 Jan 2024 11:08:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlzhi8zyybidEWq5tyHrFv8pVhQ4KX5GEA62luw2QXGIUuqPVPmIMFG59MgPCt6EWlvHEY X-Received: by 2002:a17:903:1208:b0:1d0:6ffd:6e80 with SMTP id l8-20020a170903120800b001d06ffd6e80mr909671plh.120.1704395322516; Thu, 04 Jan 2024 11:08:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704395322; cv=none; d=google.com; s=arc-20160816; b=rp00AqNCkN2bbjH5b91xL+GVtXzvedsmXw8ZDHS0J8qmOgCxylrpZ/H7e0zl8ZGvWK xl+C+a6Ofqov7Ed8rtEL5uhjYa2al9sTlPJgfIbXDag0cE0PgcyKMIDKt91ovZ6xLg8L N9NuWNIvaZJ3uqO1uvXi+n5j9RREdcV0ER1gt5qpk1t9Q/PeEjjTHerU9nWL2dAoVHCM yxKxSRB1vBvd36bmPqsx2zYx2HBpOqbYeydY8e5odCjHUEvCnw8pw1vPL8hsB+xNj1uM siaqutMEkXIbOsQ+nn28yEkb02IrOtXVXl8uXif96WXMZIn6ieYAMWFIvG23weM8t2Z2 bAPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=UNzqOAPiSbhAqNGSIw4qIUZwwB4ssRONcopXO5fU1ww=; fh=Kkdo6RP4xFxpyJV6VUEp6MSqXt9r8SNk1QQupulNhj8=; b=YhcSeFa0a/2uWEu7J5KH8IJ3zshJvL05NywnsmjVLWmWRQiyAID4sUeCSa0rSm7lKB kmPWfVYFrN0t9Fc0Tq0qW1xeFiQFeyaMYcllMUKXlJwf+eGDAJbqh93sWl41SbFrjvbo YcBH4ziOQZzPjpoLV2Tw+RNtqC8/GCI3ifcMTQ64jAZaUnLPgcJRWp3diormlkTMfW2i qluEdvHmIGD3Uvd5FGVpMngS5cVIcKD/Z3NCamWa+pZl5wjoTn1j8dLwBwr/TKx5Fi0Q TxN+htzE9JKobWYygm5c/YwrVoC75mvEDaD2WB6oKlXs18yTO5kK1TePFxRCMB99/8jJ vulQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=W67xHYvN; spf=pass (google.com: domain of linux-bluetooth+bounces-897-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-897-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v8-20020a170902b7c800b001cfd66f31ccsi23802751plz.55.2024.01.04.11.08.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 11:08:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-897-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=W67xHYvN; spf=pass (google.com: domain of linux-bluetooth+bounces-897-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-897-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 54C3528178E for ; Thu, 4 Jan 2024 19:08:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1985828E3C; Thu, 4 Jan 2024 19:08:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W67xHYvN" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D95AB28E3B for ; Thu, 4 Jan 2024 19:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2cce6c719caso10044681fa.2 for ; Thu, 04 Jan 2024 11:08:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704395313; x=1705000113; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UNzqOAPiSbhAqNGSIw4qIUZwwB4ssRONcopXO5fU1ww=; b=W67xHYvNHSF3wjlw48GdUtfhguNXNrXcZj01F+gzvjXUoGSImj68TL77rkUkRXEKoE 1a8qxm3XYiePIetjmRSyN5Hb93JtwRGmJ3FSa0EogBfDwv/TyzpqX8iMoeUH/Wwc+SeZ h7QqucnFu76uFW7nEyOAZGRzfjKXpaAKdDyqgb+UxX5qZzvrvC5z7/ZrwTyD3cUvjPeq nM0KtR3lfnJmHHXWNaoODd+jQTEUzjVIxERXerl3nxL10V7mFU62GbCFoFGinBTRbyJw CrCElNGbEu9Zg7edpG81jiH2LVbWwyAhzdWQ5UMtOaf3tSG+3RhoWufa2bdzedgB7chV 6JIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704395313; x=1705000113; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UNzqOAPiSbhAqNGSIw4qIUZwwB4ssRONcopXO5fU1ww=; b=a/bQrYvvDDlnS5qk9W9d53FqNptEU6dpLGEqPvtxXX04LO+7UF0H9708KQeu2YgW/7 yFbFCv4Gca+FXibpPqRFkQGXI7sxZ2goMXZO5WyW0SuIsNQJpn4+UUAz2k3F01sFKyKh zKolhW4+4M5F7BkHtCKLYw9e8+ZL/dqXk1DhzH4uqSqPsIu+5MYc+5FxNUNJCC1tAjF+ QCAjebre4BzXurIbKvjkr8z1467gCohMcMd8XDPaux1Ehb16zqBmMDwjujweqgP14kEi /jC5JqoeVyK8UkheAiwY2kk4YwxSRVoimt4qA5W6+Ep2pWoA0UKlJubh9QntfmFvt9VD q3kw== X-Gm-Message-State: AOJu0YziYNoHZqiuw+HcEOsYCokk06lS11mwXcRmHlvXq3Vx7Iww6CXl tpAowEN41tk5SGu2LZkDGYVYjXZFysVJRTB6K6M= X-Received: by 2002:a2e:9851:0:b0:2cc:d616:ff9b with SMTP id e17-20020a2e9851000000b002ccd616ff9bmr482017ljj.46.1704395312646; Thu, 04 Jan 2024 11:08:32 -0800 (PST) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240104171400.124128-1-xiaokeqinhealth@126.com> In-Reply-To: <20240104171400.124128-1-xiaokeqinhealth@126.com> From: Luiz Augusto von Dentz Date: Thu, 4 Jan 2024 14:08:19 -0500 Message-ID: Subject: Re: [PATCH BlueZ v4 1/2] a2dp: fix incorrect transaction label in setconf phase To: Xiao Yao Cc: linux-bluetooth@vger.kernel.org, Xiao Yao Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Xiao, On Thu, Jan 4, 2024 at 12:16=E2=80=AFPM Xiao Yao = wrote: > > From: Xiao Yao > > BLUETOOTH SPECIFICATION Page 61 of 140 > Audio/Video Distribution Transport Protocol Specification (V13) > 8.4.6 Message integrity verification at receiver side > > - The receiver of an AVDTP signaling message shall not interpret corrupte= d > messages. Those messages are discarded and no signaling message is return= ed > to the sender if no error code is applicable. Possible corrupted messages > are: > > * Response messages where the transaction label cannot match a previous > command sent to the remote device > > Consider the following scenario: > btmon log: > AVDTP: Discover (0x01) Command (0x00) type 0x00 label 5 nosp 0 > ... ... > < AVDTP: Set Configuration (0x03) Command (0x00) type 0x00 label 8 nosp 0 > //Currently, a 'set configuration' message has been received from the > //sender, which contains a transaction label valued at 8. This message > //was then relayed to A2DP backend(PulseAudio/PipeWire) using the dbus > //interface. > set_configuration()(media.c) > dbus_message_new_method_call(..., "SetConfiguration", ...); > g_dbus_send_message_with_reply(btd_get_dbus_connection(), ...); > dbus_pending_call_set_notify(request->call, endpoint_reply, ...); > ... > > //The commit "02877c5e9" introduces a reverse discovery logic, resulting > //in a small probability that the discovery command is issued before the > //setconfig accept command. > //Tip: If an artificial delay is added to the audio backend, this issue > //will invariably occur." > > AVDTP: Discover (0x01) Command (0x00) type 0x00 label 0 nosp 0 > //After receiving the discover reply, the session->in.transaction is > //changed to 0 > < AVDTP: Discover (0x01) Response Accept (0x02) type 0x00 label 0 nosp 0 > > > AVDTP: Set Configuration (0x03) Resp Accept (0x02) type 0 label 0 nosp = 0 > //The audio backend reply the dbus message > endpoint_reply (media.c) > setconf_cb (avdtp.c) > //Here avdtp_send sends an incorrect transaction value, causing > //the sender to discard the message. (The correct transaction > //value is 8) > avdtp_send(session, session->in.transaction, AVDTP_MSG_TYPE_ACCEPT, > AVDTP_SET_CONFIGURATION, NULL, 0) > > AVDTP: Delay Report (0x0d) Command (0x00) type 0x00 label 1 nosp 0 > ... ... > > Therefore, the reverse discovery logic was adjusted to the back of > setconfig accept to avoid two transmission transactions at the same > time and fixed the problem. > > Signed-off-by: Xiao Yao > --- > v1 -> v2: Fixed "session->in.transaction" logic err. > v2 -> v3: Fixed some compile warnings > v3 -> v4: Adjust the timing of reverse discovery logic > --- > profiles/audio/a2dp.c | 27 ++++++++++++++------------- > 1 file changed, 14 insertions(+), 13 deletions(-) > > diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c > index b43161a13..f4ef8aec2 100644 > --- a/profiles/audio/a2dp.c > +++ b/profiles/audio/a2dp.c > @@ -586,6 +586,12 @@ done: > return FALSE; > } > > +static void reverse_discover(struct avdtp *session, GSList *seps, int er= r, > + void *user_data) > +{ > + DBG("err %d", err); > +} > + > static void endpoint_setconf_cb(struct a2dp_setup *setup, gboolean ret) > { > if (ret =3D=3D FALSE) { > @@ -595,6 +601,13 @@ static void endpoint_setconf_cb(struct a2dp_setup *s= etup, gboolean ret) > } > > auto_config(setup); > + > + /* Attempt to reverse discover if there are no remote > + * SEPs. > + */ > + if (queue_isempty(setup->chan->seps)) > + a2dp_discover(setup->session, reverse_discover, NULL); > + > setup_unref(setup); > } > > @@ -634,12 +647,6 @@ static gboolean endpoint_match_codec_ind(struct avdt= p *session, > return TRUE; > } > > -static void reverse_discover(struct avdtp *session, GSList *seps, int er= r, > - void *user_data) > -{ > - DBG("err %d", err); > -} > - > static gboolean endpoint_setconf_ind(struct avdtp *session, > struct avdtp_local_sep *s= ep, > struct avdtp_stream *stre= am, > @@ -695,14 +702,8 @@ static gboolean endpoint_setconf_ind(struct avdtp *s= ession, > setup_ref(setup), > endpoint_setconf_cb, > a2dp_sep->user_data); > - if (ret =3D=3D 0) { > - /* Attempt to reverse discover if there are no re= mote > - * SEPs. > - */ > - if (queue_isempty(setup->chan->seps)) > - a2dp_discover(session, reverse_discover, = NULL); Have you actually test these changes with read devices? I would be really surprised if this works because you are essentially changing the reverse discover to when we do initiate AVDTP_SetConfiguration rather when we receive, which shall never need a reverse discover to begin with since we are initiating we always perform a discover anyway, so that most likely is dead code that will never going to executed. The real culprit here is that both commands and responses are stored in the session.in while we should probably have a session.cmd and session.rsp to be able to handle outstanding requests in each direction. > + if (ret =3D=3D 0) > return TRUE; > - } > > setup_unref(setup); > setup->err =3D g_new(struct avdtp_error, 1); > -- > 2.34.1 > > --=20 Luiz Augusto von Dentz