From patchwork Wed Jul 24 16:06:06 2024 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: 814265 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 6F9AA33991 for ; Wed, 24 Jul 2024 16:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721837173; cv=none; b=mYAbX6AcPREJNr79HnEFQI+oXrYHwm4zeGlp9KaLMo1RfUuM1bWg+e2uSSo/352y8eY286+waQmCLj5zFBj+ccnwrIQkDbAalwg/x1+RnBQz6pDSD7i32fbu0xgMHikB2/ihP3yRqXYRlYlkvWYlLlMxSUcvEHs1FGAklRl8vtU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721837173; c=relaxed/simple; bh=7GRCKYgoXagAflSyyDQsc2HgTuleIPQw1HHl4LRElIE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=WatjL2UncFfr00wi+WXq/hU0Wym0DMSvSeTKsPC3qzOgb74jwrL7a7RYEf5++Elgr+5cM+YIfFkL9fAMPkejvW+GH9qqKVOyNcLPxvKpl+1yunviaWaQIW+rkraz4I6AJ0D8SGiB6u9vJ11FHM4g8RXEQR3f4InfstXPz9JwN68= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G2GT5v9R; arc=none smtp.client-ip=209.85.210.45 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G2GT5v9R" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-70446231242so3451349a34.1 for ; Wed, 24 Jul 2024 09:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721837171; x=1722441971; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=mAiYFKSRsQ/2TruribD2xPO+KLN4jbBOflIDN2+g6yQ=; b=G2GT5v9RPa4LQOAD8gNv+n+iHlOWjcnLAx6goW96q51wjVWSgBPPFFQFQbQfeCsWLE PDkIYeQlk/Zl8+Lt5beO9ZU6U9Oyi7VL9Vi7SESLMD/hHMmipjeOkoFQaZ9G13wTp2+s TwPfzLrt+v5aO6vf03Y8b2jVeHBXP3bAJpb/Qcxs7n/c31sYt/TBBgCT7KVYNj6sva4V 5Rb0YEb7EXFlltjcJISCUFkBhpawA4qKwehxT7+pVYFptFkIluN+I79Hrr44IZ0zVXFr 2TLVhmS2W4AVPQHxQcrvYIzP0JUaOn4CO5i/+JYl3YmExYHCpSluebpd855owkOmiuEq /yIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721837171; x=1722441971; 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=mAiYFKSRsQ/2TruribD2xPO+KLN4jbBOflIDN2+g6yQ=; b=R++Uklz2cykm0P4Vj7sdHj6n+qD0BuZyFQEX4MjFgZZG+6hpzhkv9TvSWY+5uaT4Gi vT4VP2kMvpWwRX3hZcB5kehk9GTrRKGIp98gqUwoKQwtwZFmKZ9t0BI+mnnpSQcraMuS d6gr0eqD6d5t3bTaGkNmBIW9+e3T6OKiFG/5LgOSIuz5uF5bAYO5Zx9ECKXZKAVjbTPH 17SFokMgAGjPRVsseywLKOmj+OkGoAx8UaN4KRnyUwS3pgp6qGNDvNafduS+cBvevxKI ep8NQ1I9QWjgC86MM4f6aUW3AI3LoqJFOzuMz7Lcp2k6NNYahYg2PMrMbKTDE0Lr5e7d CNrA== X-Gm-Message-State: AOJu0YyYBEMSLd2PMKb3T3PJ66hPghb+9tcA8SAHhnxbSnslB0TY43yp m4LUMNbrM/4X3QtS86tYuiqLKQEHzuoT8+gp9IwiWdT+LPconkxZh/3pUg== X-Google-Smtp-Source: AGHT+IFF7310Ll+0jSogNIXZ/pp7uHG0HC2ZbRpdsb/XReiB0NS8FFy86SnezMsiixYd7SEGbNNmkQ== X-Received: by 2002:a05:6830:6819:b0:708:b2c9:1a9e with SMTP id 46e09a7af769-7092e6d3120mr250216a34.12.1721837170549; Wed, 24 Jul 2024 09:06:10 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-826dcefcc28sm2445485241.10.2024.07.24.09.06.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 09:06:09 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 1/3] client/player: Set number of channels based on locations Date: Wed, 24 Jul 2024 12:06:06 -0400 Message-ID: <20240724160608.2779282-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.2 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This sets the number of channels based on the locations set rather than always hardcoding it to 3 which in certain case is incorrect and can lead for the same location to be configured multiple times. --- client/player.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/client/player.c b/client/player.c index 5b0b918fb8d7..9334a053d34d 100644 --- a/client/player.c +++ b/client/player.c @@ -1140,10 +1140,9 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn, .meta = _meta, \ } -#define LC3_DATA(_freq, _duration, _chan_count, _len_min, _len_max) \ +#define LC3_DATA(_freq, _duration, _len_min, _len_max) \ UTIL_IOV_INIT(0x03, LC3_FREQ, _freq, _freq >> 8, \ 0x02, LC3_DURATION, _duration, \ - 0x02, LC3_CHAN_COUNT, _chan_count, \ 0x05, LC3_FRAME_LEN, _len_min, _len_min >> 8, \ _len_max, _len_max >> 8) @@ -1182,11 +1181,10 @@ static const struct capabilities { * * Frequencies: 8Khz 11Khz 16Khz 22Khz 24Khz 32Khz 44.1Khz 48Khz * Duration: 7.5 ms 10 ms - * Channel count: 3 * Frame length: 26-240 */ CODEC_CAPABILITIES("pac_snk/lc3", PAC_SINK_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), @@ -1198,7 +1196,7 @@ static const struct capabilities { * Frame length: 26-240 */ CODEC_CAPABILITIES("pac_src/lc3", PAC_SOURCE_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), @@ -1210,7 +1208,7 @@ static const struct capabilities { * Frame length: 26-240 */ CODEC_CAPABILITIES("bcaa/lc3", BCAA_SERVICE_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), @@ -1222,7 +1220,7 @@ static const struct capabilities { * Frame length: 26-240 */ CODEC_CAPABILITIES("baa/lc3", BAA_SERVICE_UUID, LC3_ID, - LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 26, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 26, 240), UTIL_IOV_INIT()), }; @@ -3220,6 +3218,7 @@ static void endpoint_locations(const char *input, void *user_data) struct endpoint *ep = user_data; char *endptr = NULL; int value; + uint8_t channels; value = strtol(input, &endptr, 0); @@ -3230,6 +3229,12 @@ static void endpoint_locations(const char *input, void *user_data) ep->locations = value; + channels = __builtin_popcount(value); + /* Automatically set LC3_CHAN_COUNT if only 1 location is supported */ + if (channels == 1) + util_ltv_push(ep->caps, sizeof(channels), LC3_CHAN_COUNT, + &channels); + bt_shell_prompt_input(ep->path, "Supported Context (value):", endpoint_supported_context, ep); } From patchwork Wed Jul 24 16:06:07 2024 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: 814453 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.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 29DF115B0F9 for ; Wed, 24 Jul 2024 16:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721837175; cv=none; b=CW0g5KgxuQl4lWZqrdINx3JrD7zbqpTIUSOc5VyieSzEnYzaAz1SB4OfrVOEgRfkw+1kBeGS/LBi1jP4LSv1Pl8GUz2Oi0HrKTz9vjC9MhALk11djRJQ9cNOn2x76RqS3ZoaCb3xqNNozxGl48cDuTfUjxHnr+FaRa+g/iedYgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721837175; c=relaxed/simple; bh=v96mJj0ZaXkjngKwda1qWXSpgNHMnX5i4qplTEQQFfk=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ORV2pjOvcqShGenXG89wCclW3wyGeQKeIeYvXWF3QzjT67SY/eLHjTeZneH1tlTDVRBQf5602ADcA+okkTZm/1eBF/kmGBEtF0LUT122yc9GU0kpWi55YXCslrjt2/KI7PtdAz3qjQk5Qk5B50KEXWoEO6XMfIeMHWlt/VAH3JA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZLDx+7VF; arc=none smtp.client-ip=209.85.167.174 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZLDx+7VF" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3d9da46ca13so3792050b6e.2 for ; Wed, 24 Jul 2024 09:06:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721837172; x=1722441972; darn=vger.kernel.org; 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=sHIB6o9hz1FZQncnMgybUm0LYETx+cfTDdu9/UCopG4=; b=ZLDx+7VFFKgdgKQt1gpclAfpLoBXd8GA49iUFOBT3NoGJXxRLxROwEZ2qhBiONrKkz CuStCqPZuMLjzJF6ybCXdzVnS5HzP6VWIo4salTG5G/RceSlpES0UKB0NCPHoW++t1Nx 5kQ6mEpKr/EiX28T3hNUGmQjX+Emect7qBnnmUi+g0cW5vjayEaFKeRFHu/caw+TQ6l1 qXGYWHdWfdxkB0UcczbRO/iswgPiKQuzNGgQqo3pgtFsDrdqO8F5PVcaVRo0HXsPgzXe RtWUyH6g7c3SmzNF91s3STPkC8UmIzHS+BRe2G1Ngumw02cQNYEXagvx20o4bB8hL7sz H2lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721837172; x=1722441972; 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=sHIB6o9hz1FZQncnMgybUm0LYETx+cfTDdu9/UCopG4=; b=s73HkUcl2k8VE9z9KiamjryysYbW+p2CIPDEyxb3wLy5Ww90HSaysl/KO6XcNCEpku KQbFOdbpzFupi8G5ep4kyPmi+jzCxQCGfmROVYFQOCnCypQt8tRkKxVZ3bvKvVSGhUjZ vqTCBwitei7WdFiG1BE9a4dws2wckpc//yuqjKThkXwJM1t69iV9sdQeUbB/UkMhxgx9 oR0R/PtBYPJi9FbLdaDUHE8wG25ACpmbZwWjNmUk+vmRBFG6OlgQorz0M5Y+gVCYlLNg NBUfqy5H31n82zNPT1YQV9lEoFjnve+dpRtjE+PuF7yV0H111C0gdTgyohS0UQVXRyty faZg== X-Gm-Message-State: AOJu0Yyrnd1+DGFe//yzXrjsHL61KGDaXANxdnx+AlOSPaZYawAFXmKO R2hnTaOqDeJHcad9stL24hvGkSaLhWKQ6Ml8g9FpQ0cYH/GUjrHxK59Rvw== X-Google-Smtp-Source: AGHT+IGUbEQkLw2fF5k87dCBO6gsLErbF6pVC3bhWxZ1EO7NjI/n4EKuB20IhYIbdJlJzv9dAIQyFA== X-Received: by 2002:a05:6830:621b:b0:703:651b:382f with SMTP id 46e09a7af769-7092e695165mr270554a34.3.1721837172456; Wed, 24 Jul 2024 09:06:12 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-826dcefcc28sm2445485241.10.2024.07.24.09.06.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 09:06:11 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 2/3] client/player: Add support to enter alternative preset Date: Wed, 24 Jul 2024 12:06:07 -0400 Message-ID: <20240724160608.2779282-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240724160608.2779282-1-luiz.dentz@gmail.com> References: <20240724160608.2779282-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz This adds support for alternative preset to be entered so when auto accepting configuration a different preset can be selected following the order given to endpoint.presets. --- client/player.c | 81 ++++++++++++++++++++++++++++++++++++++++++++---- src/shared/bap.c | 2 +- 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/client/player.c b/client/player.c index 9334a053d34d..b9a4f1bf484d 100644 --- a/client/player.c +++ b/client/player.c @@ -1230,7 +1230,10 @@ struct codec_preset { const struct iovec data; struct bt_bap_qos qos; uint8_t target_latency; + uint32_t chan_alloc; bool custom; + bool alt; + struct codec_preset *alt_preset; }; #define SBC_PRESET(_name, _data) \ @@ -1969,12 +1972,23 @@ static int parse_chan_alloc(DBusMessageIter *iter, uint32_t *location, if (*channels) *channels = __builtin_popcount(*location); return 0; + } else if (!strcasecmp(key, "Locations")) { + uint32_t tmp; + + if (var != DBUS_TYPE_UINT32) + return -EINVAL; + + dbus_message_iter_get_basic(&value, &tmp); + *location &= tmp; + + if (*channels) + *channels = __builtin_popcount(*location); } dbus_message_iter_next(iter); } - return -EINVAL; + return *location ? 0 : -EINVAL; } static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, @@ -1985,7 +1999,7 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, DBusMessageIter iter, props; struct endpoint_config *cfg; struct bt_bap_io_qos *qos; - uint32_t location = 0; + uint32_t location = ep->locations; uint8_t channels = 1; if (!preset) @@ -2010,6 +2024,24 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, 0x05, LC3_CONFIG_CHAN_ALLOC, location & 0xff, location >> 8, location >> 16, location >> 24 }; + uint32_t chan_alloc = 0; + + if (preset->chan_alloc & location) + chan_alloc = preset->chan_alloc & location; + else if (preset->alt_preset && + preset->alt_preset->chan_alloc & + location) { + chan_alloc = preset->alt_preset->chan_alloc & location; + preset = preset->alt_preset; + + /* Copy alternate capabilities */ + util_iov_free(cfg->caps, 1); + cfg->caps = util_iov_dup(&preset->data, 1); + cfg->target_latency = preset->target_latency; + } + + if (chan_alloc) + put_le32(chan_alloc, &chan_alloc_ltv[2]); util_iov_append(cfg->caps, &chan_alloc_ltv, sizeof(chan_alloc_ltv)); @@ -2035,6 +2067,8 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, dbus_message_iter_init_append(reply, &iter); + bt_shell_printf("selecting %s...\n", preset->name); + append_properties(&iter, cfg); free(cfg); @@ -2098,8 +2132,6 @@ static DBusMessage *endpoint_select_properties(DBusConnection *conn, if (!reply) return NULL; - bt_shell_printf("Auto Accepting using %s...\n", p->name); - return reply; } @@ -4106,13 +4138,38 @@ static void print_presets(struct preset *preset) for (i = 0; i < preset->num_presets; i++) { p = &preset->presets[i]; - bt_shell_printf("%s%s\n", p == preset->default_preset ? - "*" : "", p->name); + + if (p == preset->default_preset) + bt_shell_printf("*%s\n", p->name); + else if (preset->default_preset && + p == preset->default_preset->alt_preset) + bt_shell_printf("**%s\n", p->name); + else + bt_shell_printf("%s\n", p->name); } queue_foreach(preset->custom, foreach_custom_preset_print, preset); } +static void custom_chan_alloc(const char *input, void *user_data) +{ + struct codec_preset *p = user_data; + char *endptr = NULL; + + p->chan_alloc = strtol(input, &endptr, 0); + if (!endptr || *endptr != '\0') { + bt_shell_printf("Invalid argument: %s\n", input); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + if (p->alt_preset) + bt_shell_prompt_input(p->alt_preset->name, + "Enter Channel Allocation: ", + custom_chan_alloc, p->alt_preset); + else + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + static void cmd_presets_endpoint(int argc, char *argv[]) { struct preset *preset; @@ -4133,8 +4190,20 @@ static void cmd_presets_endpoint(int argc, char *argv[]) preset->default_preset = default_preset; if (argc > 4) { + struct codec_preset *alt_preset; struct iovec *iov = (void *)&default_preset->data; + /* Check if and alternative preset was given */ + alt_preset = preset_find_name(preset, argv[4]); + if (alt_preset) { + default_preset->alt_preset = alt_preset; + bt_shell_prompt_input(default_preset->name, + "Enter Channel Allocation: ", + custom_chan_alloc, + default_preset); + return; + } + iov->iov_base = str2bytearray(argv[4], &iov->iov_len); if (!iov->iov_base) { bt_shell_printf("Invalid configuration %s\n", diff --git a/src/shared/bap.c b/src/shared/bap.c index 0aa89c2781ba..4bec51011469 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -5420,7 +5420,7 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, selected++; /* Check if there are any channels left to select */ - map.count &= ~(map.count & rc->count); + map.count &= ~(map.count & rc->count); /* Check if there are any locations left to select */ map.location &= ~(map.location & rc->location); From patchwork Wed Jul 24 16:06:08 2024 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: 814264 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) (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 860F215B0F9 for ; Wed, 24 Jul 2024 16:06:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721837178; cv=none; b=uWZ35qbFjgJr91aOaNHUVFwKK3xmcjEhPQjoKhJ4oPsROHTsUOVyKIVkh8rP9qgtS5pcvcScT3uy2CO0/Egoa8U2/f5rbuPNoOhxZFLMpOuw4S7JMcvJpHhvlKCVLYB2MWHuQjisxKR+jKbupe+BBn4wIfD+Xnu0AiuCSwfd9H0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721837178; c=relaxed/simple; bh=CO2ydq6Bonfbi+93zJp+cU9RGwyDIzmOoFozwAeCnyY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YykszidzkNBwELE+YBo8rgE1xMRb3tHTooEq+wKlVaqoTSoUxvRGE9BqGlKy3bidImggKUFunbv59hN/af6GyH6OYbuI1tITsvp3qPGaDxRzTmXTqDGZzQ+dUZEj9b99QD9BVSjvc7qohfH6IKRyNwFdcwwsFaSKXsdFjw4alO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=e0h7LHvc; arc=none smtp.client-ip=209.85.161.41 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e0h7LHvc" Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5c6661bca43so16124eaf.0 for ; Wed, 24 Jul 2024 09:06:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721837175; x=1722441975; darn=vger.kernel.org; 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=ynihtN8SdZyULuagk08lb8XUdipxxZ3D5lZogfn/TUs=; b=e0h7LHvcuxl9gsSZM5AXOVIPpRQKZQi0G5tG3bx6lL555CHDTt/loexYgT/8e+qPW8 XS0cM7bA5wTZQvDjVWC0K+8e3A3Lfh/QODImgVeplaRcjU0+huCPvz1SZBgSRTICsuO8 4hOi/V0wqUdd1RB+yZH39rsjdmAfHgFkiqAIeZDToXjoN8ygpnVehscKmy7OC3JYIm62 U3xxS4l4+SRef7ibpkaq8xlqW4HT8P3+9Fbrgr7/fP3oVTSmIDiaV/agyHi0kirN46dU Wvgvmm8tHNimuoep0a5BVykvkr2m97C1+o6s6synJ9RUNkfXyrYas05UaatHoa7PyXyn z3rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721837175; x=1722441975; 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=ynihtN8SdZyULuagk08lb8XUdipxxZ3D5lZogfn/TUs=; b=ZDfXhWh2Ko9g3JGnl3Pry94zDje7I5VF2jOV4QJC/iOPhH3jWb5S2Y0kmsM7HiHDe9 GmujQlvnN5P52ghGXzLHVNoQfRkz9Ixw6nShUOjXvQbyjUHamqEoa7+uZUAIqiYwwh4S TvpnfN2tzW1s+ZZPwTAxNMTyCsJdWbyn35ZDH/64CTSu7ds0Ksk8P/acPQ11PgAhFr6Q ayD2vJyfHg/WrQoVszZhLFzVvoQMnTHHwpXzDfqP9PQ1EyA6FA2ZqLbwweWEUFSXGnLb YhGzgtycSb+hyVjL9TPV4HEpUFntc28UqJeyg4HwUTJa/RI4JTR6xgaxN9GF0G99M7D/ 46zw== X-Gm-Message-State: AOJu0YxjdvLceeLya/hA2jc1QXye3/7xN6z7wT8b2LuvOyLst+5h7k1M PBDcHYEdcgvxyHRQgwRU7O63HOMtPB/Ff5Dgt3MSEV6iEZ/rIPLFtD+Nig== X-Google-Smtp-Source: AGHT+IH5giNAH2qOBE9d9wFhoeW6azyWpgHlNWm4pkL5Xc96Z1efX5Nl1vo2hOAdgR63/Z6EgA6cfg== X-Received: by 2002:a05:6358:7323:b0:1ac:660a:8a69 with SMTP id e5c5f4694b2df-1acf8a25558mr30772355d.18.1721837174449; Wed, 24 Jul 2024 09:06:14 -0700 (PDT) Received: from lvondent-mobl4.. (syn-107-146-107-067.res.spectrum.com. [107.146.107.67]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-826dcefcc28sm2445485241.10.2024.07.24.09.06.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jul 2024 09:06:13 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 3/3] shared/bap: Fix bt_bap_select with multiple lpacs Date: Wed, 24 Jul 2024 12:06:08 -0400 Message-ID: <20240724160608.2779282-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240724160608.2779282-1-luiz.dentz@gmail.com> References: <20240724160608.2779282-1-luiz.dentz@gmail.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Luiz Augusto von Dentz When there are multiple local PAC records of the same codec with different locations only the first was consider, also bt_bap_select would stop doing location matching early if the location don't match without considering there could be more remote channels. --- src/shared/bap.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index 4bec51011469..499e740c9162 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -3249,25 +3249,32 @@ static void *ltv_merge(struct iovec *data, struct iovec *cont) return util_iov_append(data, cont->iov_base, cont->iov_len); } -static void bap_pac_foreach_channel(size_t i, uint8_t l, uint8_t t, uint8_t *v, - void *user_data) +static void bap_pac_chan_add(struct bt_bap_pac *pac, uint8_t count, + uint32_t location) { - struct bt_bap_pac *pac = user_data; struct bt_bap_chan *chan; - if (!v) - return; - if (!pac->channels) pac->channels = queue_new(); chan = new0(struct bt_bap_chan, 1); - chan->count = *v; - chan->location = bt_bap_pac_get_locations(pac) ? : pac->qos.location; + chan->count = count; + chan->location = location; queue_push_tail(pac->channels, chan); } +static void bap_pac_foreach_channel(size_t i, uint8_t l, uint8_t t, uint8_t *v, + void *user_data) +{ + struct bt_bap_pac *pac = user_data; + + if (!v) + return; + + bap_pac_chan_add(pac, *v, bt_bap_pac_get_locations(pac)); +} + static void bap_pac_update_channels(struct bt_bap_pac *pac, struct iovec *data) { uint8_t type = 0x03; @@ -3277,6 +3284,13 @@ static void bap_pac_update_channels(struct bt_bap_pac *pac, struct iovec *data) util_ltv_foreach(data->iov_base, data->iov_len, &type, bap_pac_foreach_channel, pac); + + /* If record didn't set a channel count but set a location use that as + * channel count. + */ + if (queue_isempty(pac->channels) && pac->qos.location) + bap_pac_chan_add(pac, pac->qos.location, pac->qos.location); + } static void bap_pac_merge(struct bt_bap_pac *pac, struct iovec *data, @@ -3607,6 +3621,9 @@ uint32_t bt_bap_pac_get_locations(struct bt_bap_pac *pac) if (!pac) return 0; + if (pac->qos.location) + return pac->qos.location; + pacs = pac->bdb->pacs; switch (pac->type) { @@ -5411,7 +5428,7 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, /* Try matching the channel location */ if (!(map.location & rc->location)) - break; + continue; lpac->ops->select(lpac, rpac, map.location & rc->location, &rpac->qos, @@ -5420,7 +5437,7 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, selected++; /* Check if there are any channels left to select */ - map.count &= ~(map.count & rc->count); + map.count &= ~(map.count & rc->count); /* Check if there are any locations left to select */ map.location &= ~(map.location & rc->location);