From patchwork Thu Jul 25 21:36:24 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: 814448 Received: from mail-vs1-f41.google.com (mail-vs1-f41.google.com [209.85.217.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 616681C6BE for ; Thu, 25 Jul 2024 21:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721943391; cv=none; b=DO0H1FnXZiRxfR9RvNsgfnz5VUJqIUJOcpjsH6nqkJWYYz5vv7YJUzclUECzRx17/5V1dpzf0dPQaPnRYx4oZOoRr+E23AGlWrFSc5CsFChl+sWHibJ9MO3sChIXweAnp86xoFfR1FX/pUwvKukZVyFRVweoMYCLsQnXh02Zolk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721943391; c=relaxed/simple; bh=7GRCKYgoXagAflSyyDQsc2HgTuleIPQw1HHl4LRElIE=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=Ejgaey0UY9/5TJECZIzQSXmSjoDm27wVr5GbC10DEk3ygdPsdydjI8RwPH2HHuL2ewcdO/HU6Pfu1PAVFP8Cn8++b5quMo5BYCt9ED+ENfB2EOALhjudPceHtR3QnqUn40Tmfeo71qhzPWCLSfAZikSgiux54S7TBR507qZPzU4= 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=Icuxfgaz; arc=none smtp.client-ip=209.85.217.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="Icuxfgaz" Received: by mail-vs1-f41.google.com with SMTP id ada2fe7eead31-4929540f38dso457779137.2 for ; Thu, 25 Jul 2024 14:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721943388; x=1722548188; 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=IcuxfgazSFPAOx06THGCQV5TBZ/+QN6XN7yEDJA3MkZo7+0lboHZpUKzmeKw+6t3dt kj9snM310xlouRYZAb+n83EzC7riAtBYFHNeFVe5/MlPkZdElJYr+X4cowDauE/GoUoZ L+KZQkzLQqqohA81RcHHx2hGLMpFELruHPfnmLDk8IfwBMNu81WvqARgMSZApMwvv+au kHAbXWvujx440O2l0yPj4PbKdZFbYHR2hDFvbFpCHodzMEwPJ9AD7DiXvNqePBpvxBiS GSNEmqXxwyPpm0QWOTkvJAexuZ3ddE7lPXTYbb2lXU7lc7/8x3R2tQB/HmNTqGNZid0x 4U9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721943388; x=1722548188; 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=VuhMkFTshmpDwpDPLtF2lnJSVNrTp4dAUsfeYi1lE+SpclRQmCOcJomCvcmHKLaWFG yAcP56d/A/VxTJtPujBQO9XCrgrd72+ollJ9eD9zWGgOnkrZDEYW3ERTvgvJWXCBP/zB DhKVc/AlwI94rH3wcLPlcaP8uPAaBCRkF9O5P4wBX6F3s/i/sKHa1fVTirXsSnmC3pYm /w08NnSUMTlJ+feFIDNQ3+VwmbhJBdoJP09XmFWh6LUctoFTfWCJuBDfRmUmxLQzz+sk GEgooI1yPMg6mI3FGKlI9U6MLWZUi2Qe7Sb86BRpWros2LM4P5RpISM+wUKvmCR9kpPD iA1g== X-Gm-Message-State: AOJu0Yx20zVUrllRkLm/uoV/MJFoJw2pHX0IC6aEIOczPSS6zMPzpRul jOiaFIfyDZOvyvhp1fnHl39k6L1iTJPm2PIwVJHlxVCh4YQx8DC/4csvbg== X-Google-Smtp-Source: AGHT+IFFBYjuOnd+0gdWYkzot3q/euuyFD2Oucsn5vo0XVmgaIOWFlWGPDkmVPWMms2BQ0nFpFS+nA== X-Received: by 2002:a05:6102:151b:b0:491:f22:3a8 with SMTP id ada2fe7eead31-493d650da91mr6367547137.29.1721943388437; Thu, 25 Jul 2024 14:36:28 -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 ada2fe7eead31-493d95f313csm377007137.7.2024.07.25.14.36.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 14:36:27 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v4 1/3] client/player: Set number of channels based on locations Date: Thu, 25 Jul 2024 17:36:24 -0400 Message-ID: <20240725213626.3183962-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 Thu Jul 25 21:36:25 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: 814648 Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) (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 2B67C1C6BE for ; Thu, 25 Jul 2024 21:36:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721943394; cv=none; b=DwJ+rvBzemDobSsqjDtxOEX0CX3uW3laz+ThLX66M/uIDUWzCNJV6ES5PkLqPy8FYgaZdEAiV+++4qzYwqlZ806UoRlIiFyF7EaYwrxivnrapAFbsUCw9msQyicqnS9dI0cbx2x/anDGZsQOT61u2odnJZlKxe1V8ENETz3BtHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721943394; c=relaxed/simple; bh=78DRbvvElNg50EZGo7EhjzmqreVGeOhp4E/+ZBX3Pag=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ITGCryq8U+MB3SJqX6hjH0afsmNJVC0p9oYELMdyfB6T2T6l+Fhiy3lg45/80hkpTHwws4b86lGGU+0IcsV/v4wrNWu1WrCGUz8hTuDgAbyv0BAoDa+GXpq4oGobNT3hdpETzYmccPaQWAOHGDVpcdIODWCP3zQzKsmZbACblh4= 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=kGnon+f7; arc=none smtp.client-ip=209.85.222.50 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="kGnon+f7" Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-826fee202d3so8055241.1 for ; Thu, 25 Jul 2024 14:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721943391; x=1722548191; 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=EDy8S5K89VmDk2Pa45J8DVWlCCyH4oTbtgprjf3wtio=; b=kGnon+f7tEXBZ+NHpWkhLJhgEU7KyS04cHJubuheSv3b7AKrrxu2tbxOCrzxvvce8n VP7ob1d9I2XtHGnSfc1Qtq7PfMvEtI+jnBeBNLGrP/U/8zYoyN1RbYnJP5X7KfgziGSf zelAP0b9cTr+HSeqFNnnz8JmoPnW4alHF53vo/+pE5WryHsejWvdloMEpP6kOjbuOpBV L+Ck+5pF0r+ZWb0+vL0SUHv+k1WUHBmousJNvY4hrjMHcpfBVUX41DoE7+YSN/CteHsv kygUtPZNKy6bMrXDoBO/Zk0dppsfp0+knUdYbah0SMePuU+EjztC9BJR9FfBWhDwIdYk Zv9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721943391; x=1722548191; 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=EDy8S5K89VmDk2Pa45J8DVWlCCyH4oTbtgprjf3wtio=; b=DgHB/dBukEYeYIReYgPiGkju+4LYy9Y1Av5Q+MZG2xRMSQ55Gr/RaIaLm0uz+LcNyh JtTz0CwhaR4FwBrvkyoVJSVod2h1QLbNgn7o0mnk6CV+k+QvgNtsN/PPvgYuHRURD89w h4ve5RicIjyQwkMPZ6Jse91HtXd3ZPDgJyV3Qxbpnppl3X+OTHLbLWE/bWo4jv4D0BW7 wOrStxYbD2ZWp1duzAwqufdCUyqEkkSwfxXvU/xJkdZG6DX4K/uqPIoLsbgrCT4Vpn+b BuHhUHV8nVejLfvtFMf+L9ATQg9bMI3pIW8nRUhKnugEFW0hmjTZjWuCGIiY2D98Zz19 Gi6w== X-Gm-Message-State: AOJu0YyGMeD/yKvmDPZB+Hb1MWT5RGPnkMWGr6lzKzCoFGzDfPtRVdIB 2A7Xv0rNWYCsRO4ZNV8lhxFl76wtVW1G2IbFWFM6b19xTQ6rlXk9oNrU0w== X-Google-Smtp-Source: AGHT+IGD5Bd/bJO09pJIm7FYf+zb6kcXBz9fMU4ITKpcKMFTUQCg9cePn+wyglDHIueiZZRxQsUx3A== X-Received: by 2002:a05:6102:5111:b0:493:b1b2:4da9 with SMTP id ada2fe7eead31-493d9afad5amr3845125137.25.1721943390564; Thu, 25 Jul 2024 14:36:30 -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 ada2fe7eead31-493d95f313csm377007137.7.2024.07.25.14.36.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 14:36:29 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v4 2/3] client/player: Add support to enter alternative preset Date: Thu, 25 Jul 2024 17:36:25 -0400 Message-ID: <20240725213626.3183962-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240725213626.3183962-1-luiz.dentz@gmail.com> References: <20240725213626.3183962-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 | 120 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 19 deletions(-) diff --git a/client/player.c b/client/player.c index 9334a053d34d..3c3587f2ca3a 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,31 @@ 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 void ltv_find(size_t i, uint8_t l, uint8_t t, uint8_t *v, + void *user_data) +{ + bool *found = user_data; + + *found = true; } static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, @@ -1985,7 +2007,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) @@ -2006,13 +2028,44 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, dbus_message_iter_recurse(&iter, &props); if (!parse_chan_alloc(&props, &location, &channels)) { - uint8_t chan_alloc_ltv[] = { - 0x05, LC3_CONFIG_CHAN_ALLOC, location & 0xff, - location >> 8, location >> 16, location >> 24 - }; + uint32_t chan_alloc = 0; + uint8_t type = LC3_CONFIG_CHAN_ALLOC; + bool found = false; - util_iov_append(cfg->caps, &chan_alloc_ltv, + 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; + } else + chan_alloc = location; + + /* Check if Channel Allocation is present in caps */ + util_ltv_foreach(cfg->caps->iov_base, cfg->caps->iov_len, + &type, ltv_find, &found); + + /* If Channel Allocation has not been set directly via + * preset->data then attempt to set it if chan_alloc has been + * set. + */ + if (!found && chan_alloc) { + uint8_t chan_alloc_ltv[] = { + 0x05, LC3_CONFIG_CHAN_ALLOC, chan_alloc & 0xff, + chan_alloc >> 8, chan_alloc >> 16, + chan_alloc >> 24 + }; + + put_le32(chan_alloc, &chan_alloc_ltv[2]); + util_iov_append(cfg->caps, &chan_alloc_ltv, sizeof(chan_alloc_ltv)); + } } /* Copy metadata */ @@ -2035,6 +2088,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 +2153,6 @@ static DBusMessage *endpoint_select_properties(DBusConnection *conn, if (!reply) return NULL; - bt_shell_printf("Auto Accepting using %s...\n", p->name); - return reply; } @@ -3621,14 +3674,6 @@ add_meta: endpoint_set_metadata_cfg, cfg); } -static void ltv_find(size_t i, uint8_t l, uint8_t t, uint8_t *v, - void *user_data) -{ - bool *found = user_data; - - *found = true; -} - static void config_endpoint_iso_group(const char *input, void *user_data) { struct endpoint_config *cfg = user_data; @@ -4106,13 +4151,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 +4203,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", From patchwork Thu Jul 25 21:36:26 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: 814447 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (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 65DBB143875 for ; Thu, 25 Jul 2024 21:36:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721943396; cv=none; b=XIhjlRQBlvwAaGZsqJ/JzGPKF3sdQC7/eV9Fk/2g6o64tMkprgZ5LBNepEXbcnds8gpRaAJjvHe1kNk+bvCV6h0FiI7wUDbBzUB8zgUo1wIrs9WT1RVrf/cDrDZigZhKUITM9czFOfRK+esz8VXpI4/jbwAi1idBPsdkTtk4pU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721943396; c=relaxed/simple; bh=/6fiaFYPGk52pE8tMW6E5oD/V34jl1mdATom7PA/2pI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G2FTiZT8p8l17jhfFoOqCBZzjlb+Ybq7zYORU4k4beEkAwlX3/N0SsgjcfsRf1zUJXXkwE5nio/aVTboM5QPRVb5WGkRsodpZiMtNkB/vWMC4kZj+YWQRbsN4iWtZW8XLHl3iHYdIbw6INhMLFvB8DiOc/m8CzBrspp+gJSR9rI= 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=byN/Y1fB; arc=none smtp.client-ip=209.85.217.43 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="byN/Y1fB" Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-49299adf8adso401817137.2 for ; Thu, 25 Jul 2024 14:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721943393; x=1722548193; 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=Ab3bkBfJ2vSs/Qdq8D4EzRJujCBT4LBhdXhndOigMgg=; b=byN/Y1fBGt+UlXqHMNdy/1/cvOsNtPUDjHU0NmnalaZfdjJ6B2YIiNo8r1BO0qRvCy p8QM8CgeNHoctF0D6X3S6PoP9rjiXks/wBWBjk4Uiz6dcuQNEoS+J1mBnytcYMTwcmdE kZzoApYruHVg4qTnlW/huGb6eOQLcrjunxFji1LPH3W/QB3XCQoENuhE9x62YCvbpTk/ J5dCTkP4UjdnGv74miBqkrPYiq1LOuQNdb4S++TzF8Wepp8A2nwNFUJBG30oRUrq8gw5 n7M9GSM6yXPFKzkq+hHo5KA2jWQAzDogyNls+49u2P/WXOuY8NH6qTv4E0MQp4KJckab 3kKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721943393; x=1722548193; 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=Ab3bkBfJ2vSs/Qdq8D4EzRJujCBT4LBhdXhndOigMgg=; b=AjkA4V0hH6jnYE3e+/Quj3QucLneeVZmzq/YAkYl9IkI0pdiEyPIdS/hitflUUlext 4e9HYSnwYbKQ6MvEf9mfOQKFFkX8fv3YYaeuj5oZ7WmhY3yd8KWUH7L8kMCO0N19ana2 qFRwiilb0xNbUrPZHhxIunkinabG6dNx3eMsobJBmF0nta6N2ZA8Hbmg5SNKqKsqVVSP BPp8G0TreUAwjuFDjx4GeQPF3IyxxbMjtTf8SCePR41GvNK5yLBQ0cBB3pYSpC7afdUL yON2euQ+sO8Vdjfb0eiIDQC5CBcN6Gy0VPeiyKu7yh4eeAliQe72tBxgUsyYRwL4bOvZ BRdA== X-Gm-Message-State: AOJu0YySuRQqzGXQSzrUPpmAlm7KZ02h5FdMGWlQFXmdq0hY8LiXXw/j i5L7hysWMLJYs3My1UPOuw+T4j938xDyy48trSD1ovdzvTJsuRES2u2q1Q== X-Google-Smtp-Source: AGHT+IEiCAkcRrzYzc1AcwxRwG+4/gz6MtI1a52YaObDJ9g8n1j+Y9Bk9IJNLcUE4qIO10fBsGG7Pw== X-Received: by 2002:a05:6102:800b:b0:493:c3b2:b5ba with SMTP id ada2fe7eead31-493d99b419cmr4598067137.6.1721943393156; Thu, 25 Jul 2024 14:36:33 -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 ada2fe7eead31-493d95f313csm377007137.7.2024.07.25.14.36.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jul 2024 14:36:31 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v4 3/3] shared/bap: Fix bt_bap_select with multiple lpacs Date: Thu, 25 Jul 2024 17:36:26 -0400 Message-ID: <20240725213626.3183962-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240725213626.3183962-1-luiz.dentz@gmail.com> References: <20240725213626.3183962-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 | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index 0aa89c2781ba..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,