From patchwork Fri Dec 8 22:12:13 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: 13485878 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WA4Esl6j" Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7309D1723 for ; Fri, 8 Dec 2023 14:12:23 -0800 (PST) Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-589d4033e84so1316251eaf.1 for ; Fri, 08 Dec 2023 14:12:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702073541; x=1702678341; 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=aKrCIqNtifZgEzmFWurZkUt24Tu0FBrpZVFeJEQSHNE=; b=WA4Esl6j/cm4lAG4Z9mNij5kbbijdvXlzUzlqHIL/I+3U9xy3nm4gHfuwClP4PWbds dCCSLgBdUn9mT3vhkhNcKWqFp/sm+zeNG70mNnOlMtib+A3utsWEbYSDDfKjrIyuJSBo Dby7b6epqLiD2NXECJmgyZBA159NQ6nuKElKav0DOr7cIlBIuo3GnkEmDZeoexgnFotf NJwhDjuPrts9MBOzMm4tcYjMKR4gHJCHKZNTVu8IlafIBZXNKR7gt/3SdIfdUMthRrDF MuR0hdYUkxBCLpJBQV+tG3LfFsoNgf6257oMUhlKcIU2Elqx3rst7ZE450sHySCuV3eZ 25gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702073541; x=1702678341; 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=aKrCIqNtifZgEzmFWurZkUt24Tu0FBrpZVFeJEQSHNE=; b=OIJIl+IFpg2uL5m8J6B+1mQ1Fr18WslusjTXiPw37uHtgmwk5/Zx7uRGqVljMxYC07 QrpmfRPSJ7IXW8RPnK3Ymm4hcou5ygIFp3XE5etza9kPCQUv7NmlP9/KNiVh+RIPZYJL BC7bX6Cm5zpELfE3JT5FAsrc94AUxosPy4U0Avl5yHapibboLKjr8OhJWIlvymCwy2UU vMQ7Kn4gjWi2GLfncyZcTwF0FVW/dazDgwmrLH/Z94jxaUxGutQngUfapqRg3xvf2RUE TQDk2LTTvPQp+bpSUQwXRC3NEcMB+POb2LL3vKi+SgEbl4gtMTYdTtDWwYwE4FqU9O8Z hnsg== X-Gm-Message-State: AOJu0YyIvlbIuml0jhSNqySIWQamiwtLKgvmiFaIXvC42cBOYbHoEC8Y 5NxNljSHyEQviGdiC5c3LmBJGaWBTvE= X-Google-Smtp-Source: AGHT+IFY4d+xdMOgWlH54jRm6ak6XjkRFU7YjPbvaq9HkEgx/9BhA0WCDqFzSKqK9PNhEbCy5fWi1w== X-Received: by 2002:a05:6820:820:b0:58d:7171:c27 with SMTP id bg32-20020a056820082000b0058d71710c27mr989740oob.8.1702073541537; Fri, 08 Dec 2023 14:12:21 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id a44-20020a4a98af000000b0058df21de4fasm378195ooj.10.2023.12.08.14.12.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 14:12:20 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1] bap: Don't attempt to release if old state was releasing Date: Fri, 8 Dec 2023 17:12:13 -0500 Message-ID: <20231208221219.54529-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 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 If the old state was releasing there is no reason to call bt_bap_stream_release yet again when IO could not be created as that will likely create a loop situation when the remote stack caches the codec configuration. --- profiles/audio/bap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index c279b5b0e133..c530799915f3 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -1918,7 +1918,9 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state, bap_create_io(data, ep, stream, true); if (!ep->io) { error("Unable to create io"); - bt_bap_stream_release(stream, NULL, NULL); + if (old_state != BT_BAP_STREAM_STATE_RELEASING) + bt_bap_stream_release(stream, NULL, + NULL); return; } From patchwork Fri Dec 8 22:12:15 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: 13485880 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RIrIY9wX" Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FBA01710 for ; Fri, 8 Dec 2023 14:12:28 -0800 (PST) Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-58ce8513da1so1304549eaf.2 for ; Fri, 08 Dec 2023 14:12:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702073546; x=1702678346; 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=WXy0u66DcMLk54wElPB/ljBan/eg+yZkG4pRCMQV1qg=; b=RIrIY9wXqpqOKZ5yfSdFujSQOTg0c52uCQlVt+i2+WDdjSH2mBIAMJ00l3zi5jZq9S gZ6AL6aFI4wr84mHqiZpMuwUiyPeUDxTti8xnwaaie7KYoHBH/hXFkTG8Buq+u9RtqC9 xO8gxeAUjRwq3xx/2OLwc5Ffh5RqX0OyttbcDFDFgVfXmaLSyWkHrtguIO8nv4LVcLqb RhxdyvaZDey73tpv/uy0oYpq8aqREBBz0viprzn6lR1kZQbStKxKnivBzjGipVSuin0e D488MRAlituJchZ55LOivFPTKPo0JyAOtyXVp2Ft331vslgApHogY+v7crNBVWqfeLIB vJRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702073546; x=1702678346; 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=WXy0u66DcMLk54wElPB/ljBan/eg+yZkG4pRCMQV1qg=; b=Gtc22h3+ldaxoEs69+BwKxxoWZVXfaHTNcRkLjik3Z2mVf6JDEW+zUQoA69WdIYCIi BMTPoyuVL4yX6ZozKkHp2NCZicDITnnTIQb7wG8L7YnI6eg5BXJHKMZQg0On1+WuEzTp au9DJbw4aIA7Ow/U+bJQ0UC2CzyxnFBrhW8Joa0jp+k4EK8BIiQP0jcPnPyXKrccG5E9 kAnkJmS4kVt5821VO9lbI0s+9hJqi6O7UzpdQ+klRKMC5m6t8CiXsCumkqN+jaxtcfeP pzO+hL6H5FQ8rm9vdLy6bdEes0a6xwZTES90tVEy6xAVhqwpWc+Djw0xsJtGjiPbBIuz TFBg== X-Gm-Message-State: AOJu0YwyZiMKv6vpcihSyyx5cjVDyh5Mu9DFFBCRdVHTkSLwiLSUP4e3 vYj9LU9MA+87shZTCoKQiS/k++Vc58E= X-Google-Smtp-Source: AGHT+IG8d/3QWDZxxoMbGE09zPRY2I+AzAydsdr+xOOx3jikaMUGhi9iBylRlxPdfWS4fi+rzkoi8A== X-Received: by 2002:a4a:9c3:0:b0:590:a771:b5e6 with SMTP id 186-20020a4a09c3000000b00590a771b5e6mr475916ooa.18.1702073546294; Fri, 08 Dec 2023 14:12:26 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id a44-20020a4a98af000000b0058df21de4fasm378195ooj.10.2023.12.08.14.12.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 14:12:24 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 2/6] shared/bap: Make bt_bap_select match the channel map Date: Fri, 8 Dec 2023 17:12:15 -0500 Message-ID: <20231208221219.54529-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208221219.54529-1-luiz.dentz@gmail.com> References: <20231208221219.54529-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 bt_bap_pac may actually map to multiple PAC records and each may have a different channel count that needs to be matched separately, for instance when trying with EarFun Air Pro: < ACL Data TX: Handle 2048 flags 0x00 dlen 85 ATT: Write Command (0x52) len 80 Handle: 0x0098 Type: ASE Control Point (0x2bc6) Data: 010405020206000000000a020103020201030428000602020600000 0000a0201030202010304280001020206000000000a020103020201030428 0002020206000000000a02010302020103042800 Opcode: Codec Configuration (0x01) Number of ASE(s): 4 ASE: #0 ASE ID: 0x05 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) ASE: #1 ASE ID: 0x06 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) ASE: #2 ASE ID: 0x01 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) ASE: #3 ASE ID: 0x02 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Fixes: https://github.com/bluez/bluez/issues/612 --- profiles/audio/bap.c | 6 +-- src/shared/bap.c | 87 ++++++++++++++++++++++++++++++++++++++++---- src/shared/bap.h | 3 +- src/shared/util.c | 43 ++++++++++++++++++++++ src/shared/util.h | 6 +++ 5 files changed, 132 insertions(+), 13 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 38eaea055ed2..6fe45281150f 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -1290,10 +1290,8 @@ static bool pac_found(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, } /* TODO: Cache LRU? */ - if (btd_service_is_initiator(service)) { - if (!bt_bap_select(lpac, rpac, select_cb, ep)) - ep->data->selecting++; - } + if (btd_service_is_initiator(service)) + bt_bap_select(lpac, rpac, &ep->data->selecting, select_cb, ep); return true; } diff --git a/src/shared/bap.c b/src/shared/bap.c index a1495ca84bcc..2450b53232e3 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -185,6 +185,7 @@ struct bt_bap_pac { struct bt_bap_pac_qos qos; struct iovec *data; struct iovec *metadata; + struct queue *chan_map; struct bt_bap_pac_ops *ops; void *user_data; }; @@ -2417,6 +2418,33 @@ static void *ltv_merge(struct iovec *data, struct iovec *cont) return iov_append(data, cont->iov_len, cont->iov_base); } +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; + + if (!pac->chan_map) + pac->chan_map = queue_new(); + + printf("PAC %p chan_map 0x%02x\n", pac, *v); + + queue_push_tail(pac->chan_map, UINT_TO_PTR(*v)); +} + +static void bap_pac_update_chan_map(struct bt_bap_pac *pac, struct iovec *data) +{ + uint8_t type = 0x03; + + if (!data) + return; + + util_ltv_foreach(data->iov_base, data->iov_len, &type, + bap_pac_foreach_channel, pac); +} + static void bap_pac_merge(struct bt_bap_pac *pac, struct iovec *data, struct iovec *metadata) { @@ -2426,6 +2454,9 @@ static void bap_pac_merge(struct bt_bap_pac *pac, struct iovec *data, else pac->data = util_iov_dup(data, 1); + /* Update channel map */ + bap_pac_update_chan_map(pac, data); + /* Merge metadata into existing record */ if (pac->metadata) ltv_merge(pac->metadata, metadata); @@ -2448,10 +2479,9 @@ static struct bt_bap_pac *bap_pac_new(struct bt_bap_db *bdb, const char *name, pac->type = type; if (codec) pac->codec = *codec; - if (data) - pac->data = util_iov_dup(data, 1); - if (metadata) - pac->metadata = util_iov_dup(metadata, 1); + + bap_pac_merge(pac, data, metadata); + if (qos) pac->qos = *qos; @@ -2465,6 +2495,7 @@ static void bap_pac_free(void *data) free(pac->name); util_iov_free(pac->metadata, 1); util_iov_free(pac->data, 1); + queue_destroy(pac->chan_map, NULL); free(pac); } @@ -4505,7 +4536,16 @@ static bool find_ep_pacs(const void *data, const void *user_data) if (ep->stream->lpac != match->lpac) return false; - return ep->stream->rpac == match->rpac; + if (ep->stream->rpac != match->rpac) + return false; + + switch (ep->state) { + case BT_BAP_STREAM_STATE_CONFIG: + case BT_BAP_STREAM_STATE_QOS: + return true; + } + + return false; } static struct bt_bap_req *bap_req_new(struct bt_bap_stream *stream, @@ -4626,16 +4666,47 @@ static bool match_pac(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, } int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, - bt_bap_pac_select_t func, void *user_data) + int *count, bt_bap_pac_select_t func, + void *user_data) { + const struct queue_entry *lchan, *rchan; + if (!lpac || !rpac || !func) return -EINVAL; if (!lpac->ops || !lpac->ops->select) return -EOPNOTSUPP; - lpac->ops->select(lpac, rpac, &rpac->qos, - func, user_data, lpac->user_data); + for (lchan = queue_get_entries(lpac->chan_map); lchan; + lchan = lchan->next) { + uint8_t lmap = PTR_TO_UINT(lchan->data); + + for (rchan = queue_get_entries(rpac->chan_map); rchan; + rchan = rchan->next) { + uint8_t rmap = PTR_TO_UINT(rchan->data); + + printf("lmap 0x%02x rmap 0x%02x\n", lmap, rmap); + + /* Try matching the channel mapping */ + if (lmap & rmap) { + lpac->ops->select(lpac, rpac, &rpac->qos, + func, user_data, + lpac->user_data); + if (count) + (*count)++; + + /* Check if there are any channels left */ + lmap &= ~(lmap & rmap); + if (!lmap) + break; + + /* Check if device require AC*(i) settings */ + if (rmap == 0x01) + lmap = lmap >> 1; + } else + break; + } + } return 0; } diff --git a/src/shared/bap.h b/src/shared/bap.h index 2c8f9208e6ba..470313e66fc0 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -234,7 +234,8 @@ void *bt_bap_pac_get_user_data(struct bt_bap_pac *pac); /* Stream related functions */ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, - bt_bap_pac_select_t func, void *user_data); + int *count, bt_bap_pac_select_t func, + void *user_data); struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap, struct bt_bap_pac *lpac, diff --git a/src/shared/util.c b/src/shared/util.c index 34491f4e5a56..c0c2c4a17f12 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -175,6 +175,49 @@ ltv_debugger(const struct util_ltv_debugger *debugger, size_t num, uint8_t type) return NULL; } +/* Helper to itertate over LTV entries */ +bool util_ltv_foreach(const uint8_t *data, uint8_t len, uint8_t *type, + util_ltv_func_t func, void *user_data) +{ + struct iovec iov; + int i; + + if (!func) + return false; + + iov.iov_base = (void *) data; + iov.iov_len = len; + + for (i = 0; iov.iov_len; i++) { + uint8_t l, t, *v; + + if (!util_iov_pull_u8(&iov, &l)) + return false; + + if (!l) { + func(i, l, 0, NULL, user_data); + continue; + } + + if (!util_iov_pull_u8(&iov, &t)) + return false; + + l--; + + if (l) { + v = util_iov_pull_mem(&iov, l); + if (!v) + return false; + } else + v = NULL; + + if (!type || *type == t) + func(i, l, t, v, user_data); + } + + return true; +} + /* Helper to print debug information of LTV entries */ bool util_debug_ltv(const uint8_t *data, uint8_t len, const struct util_ltv_debugger *debugger, size_t num, diff --git a/src/shared/util.h b/src/shared/util.h index 6698d00415de..596663b8519c 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -138,6 +138,12 @@ bool util_debug_ltv(const uint8_t *data, uint8_t len, const struct util_ltv_debugger *debugger, size_t num, util_debug_func_t function, void *user_data); +typedef void (*util_ltv_func_t)(size_t i, uint8_t l, uint8_t t, uint8_t *v, + void *user_data); + +bool util_ltv_foreach(const uint8_t *data, uint8_t len, uint8_t *type, + util_ltv_func_t func, void *user_data); + unsigned char util_get_dt(const char *parent, const char *name); ssize_t util_getrandom(void *buf, size_t buflen, unsigned int flags); From patchwork Fri Dec 8 22:12:16 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: 13485879 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OT4uWci2" Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3E091712 for ; Fri, 8 Dec 2023 14:12:29 -0800 (PST) Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-59091e4a0f9so495955eaf.1 for ; Fri, 08 Dec 2023 14:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702073548; x=1702678348; 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=+vzaXJZMWcqXVLM/38ZU1rhtJvEz/oxxRs4GNt9sjWQ=; b=OT4uWci21XtDaOrvRK5HRreoyb5VYXd1C8T4Qydv0gE7aNmAsYpcAWXcw0dZKVZYto kCGlORimt914EwnAxMtnh6bbPx+x1PCckSlTqFhNvmHNIHaboqfQcz8ehAPAiFupHsyn e1XtYAcXlxTngSttvSFUxvn4I+z3opKmoYc6qJOIk4dpOdzkKhmyC4Sk+Y3t/ZcLRhsM hAv9Dto4ioyilc61iTCmOfc3abfUBWCVA9ef91XbIxjrz8yZx6TD64Ld4qr0rYrSBiiv Cuh7YtPioApN6xt/r7cX4V7uyWnWA5vL7328BbyJ5LIndLh34Ry9L9pQpi8VpP5cyAyG CpWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702073548; x=1702678348; 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=+vzaXJZMWcqXVLM/38ZU1rhtJvEz/oxxRs4GNt9sjWQ=; b=NXU1ei0rsohnBoDRwpWnUXciLGvuZCqomyJ5m3iIllytNMXALdNMlk74LQ5272dxtl JsAmjlNklrru1DqEmPaPnqqFIoHl6BygvGXkYnGJOmXrgzVFmmDkXEQB6gTcn1DU5fge oRhAbgH+aX3P+AjpFrI7zs+T8H8ot5tay8nP4Zc251iLRsuh5ED7snyZ1qQ0TqpUQAdw vmJ2KPMb9TS1g3UptY118Bi/Tirh7OfT9KV9z8OqipV2ppPonJ92w+Y1JrWgedH7+0YB G/1jQFJPcXjd2GLl9rYNzlXrrN8/o3ZcBAQb9y3bIN+Y4wWo7wqXbecqqm4Hr8CgFD2N 35Mg== X-Gm-Message-State: AOJu0YyiEcYikUGZc9ua1dyXo8Jur0TCcrGpP72hIIv128hab8V5rZhB Sx/oHFpKVvf3j1AFSGBdfP3AfKAqQYA= X-Google-Smtp-Source: AGHT+IEQpp9WkSrl9wJksWivgIl7sOmeulk5DrGOzNSz9UQQJvqQ2JPLnQCcIFZ+vQM5F81wP/79oA== X-Received: by 2002:a05:6820:47:b0:590:8cbd:5b39 with SMTP id v7-20020a056820004700b005908cbd5b39mr836005oob.15.1702073548431; Fri, 08 Dec 2023 14:12:28 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id a44-20020a4a98af000000b0058df21de4fasm378195ooj.10.2023.12.08.14.12.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 14:12:27 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 3/6] org.bluez.MediaEndpoint: Add ChannelAllocation to SelectProperties Date: Fri, 8 Dec 2023 17:12:16 -0500 Message-ID: <20231208221219.54529-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208221219.54529-1-luiz.dentz@gmail.com> References: <20231208221219.54529-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 ChannelAllocation to SelectProperties which when set can be used by Endpoint implementation in the response as part of Capabilities, note that it is not mandatory to use it so the Endpoint may have its on logic to allocate channels. --- doc/org.bluez.MediaEndpoint.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/org.bluez.MediaEndpoint.rst b/doc/org.bluez.MediaEndpoint.rst index 6754d6e3b7eb..f2b830ab0949 100644 --- a/doc/org.bluez.MediaEndpoint.rst +++ b/doc/org.bluez.MediaEndpoint.rst @@ -79,6 +79,8 @@ dict SelectProperties(dict capabilities) :uint32 Locations: + :uint32_t ChannelAllocation: + :dict QoS: :byte Framing: From patchwork Fri Dec 8 22:12:17 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: 13485881 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NpoKGDIc" Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47D1F10E0 for ; Fri, 8 Dec 2023 14:12:32 -0800 (PST) Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6d9de3d4b2dso860443a34.1 for ; Fri, 08 Dec 2023 14:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702073550; x=1702678350; 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=QKn6hj6o1vM2s8D/CTvanwFcrGlGzSdmAJ6XNSwgLVc=; b=NpoKGDIclqMIe9Gv36au9L8R3vvjVcfER+TL4+805+xX7vnUgvy/avYugWj0fgvUL4 mQZqu9a+DPb+KpYMqiH7wNdh0WTKNIXzzYnm7z1Nzo3PT3/aVR6ZKj5TpD9WJBBdC55/ uLHWB+vb/jdaSkye2zjYa3XKVCnJYo33A2dXOLketQ9dcI4cjv+NUrAN7bzNsJS1vvKs Sv7VgcWhjBzluByyGQ9eFxrPinB/5ANxpkkBytweXqWMYk/8GosQpJPzqfb68i53QZMZ QMGi8Y3HnmzDrk5yQmLYGFgtKBDtmzLcxkVgWD49QfwC51FnbjKhXctePGD+Ou4clHYa X0dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702073550; x=1702678350; 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=QKn6hj6o1vM2s8D/CTvanwFcrGlGzSdmAJ6XNSwgLVc=; b=HZWpHf8YTwitQhkCu2LMEv9Kk20M6jUVYLUoRvl7VIxWeSB+H6N+muw0JEyFDIyeEs k3mbx0xdcwV7pGY8CtUag96OwxrwuXQRbdXTDygGN0b+MKVAMfrkaT+YEZNDrhxs7DFg flt98kwMx2oL/ff2I5CpXFpn+hh7gmNUGL5vNE1FFdYpen8PNpDLrgexI49vuLh9QYQX /zZXD6VmrtnyoXH+TFP9keifaI1MJfI+2XxCw6nSoktED1guHSsISCpD70Y+UpxNdJSr wWHTpK7peE6aHFw6BzgBmFQ/sPdSv7XZ33CvUXYMCYhwjRj9QWT5UvVFyixbtxv9BwB0 1u1Q== X-Gm-Message-State: AOJu0YzoIvuSkLf2TgAkzFQxMiHVyCHeXvxn7bPTaI7UY8qP802q1Enz wbRhFclhQgIb1XgKgJIzHfDL9yNzvMM= X-Google-Smtp-Source: AGHT+IFnRrrtjAMGm0Nal8+ceW8DEND+QgjW8txs9pl/SgAoSWZEGzV8lW/y2FqirrFOp7oFiLgSaQ== X-Received: by 2002:a05:6808:8dc:b0:3b9:e13d:5d30 with SMTP id k28-20020a05680808dc00b003b9e13d5d30mr633128oij.26.1702073550297; Fri, 08 Dec 2023 14:12:30 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id a44-20020a4a98af000000b0058df21de4fasm378195ooj.10.2023.12.08.14.12.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 14:12:29 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 4/6] shared/bap: Make bt_bap_select select a location Date: Fri, 8 Dec 2023 17:12:17 -0500 Message-ID: <20231208221219.54529-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208221219.54529-1-luiz.dentz@gmail.com> References: <20231208221219.54529-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 makes bt_bap_select select a location based on the PAC channel count and PACS locations, this is then passed to the Endpoint as a recommended ChannelAllocation. --- profiles/audio/media.c | 6 ++- src/shared/bap.c | 88 +++++++++++++++++++++++++++--------------- src/shared/bap.h | 2 +- 3 files changed, 63 insertions(+), 33 deletions(-) diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 62f53defa7af..b17c555b63e4 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -921,7 +921,7 @@ done: } static int pac_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, - struct bt_bap_pac_qos *qos, + uint32_t chan_alloc, struct bt_bap_pac_qos *qos, bt_bap_pac_select_t cb, void *cb_data, void *user_data) { struct media_endpoint *endpoint = user_data; @@ -969,6 +969,10 @@ static int pac_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, g_dbus_dict_append_entry(&dict, "Locations", DBUS_TYPE_UINT32, &loc); + if (chan_alloc) + g_dbus_dict_append_entry(&dict, "ChannelAllocation", + DBUS_TYPE_UINT32, &chan_alloc); + if (metadata) { key = "Metadata"; g_dbus_dict_append_basic_array(&dict, DBUS_TYPE_STRING, &key, diff --git a/src/shared/bap.c b/src/shared/bap.c index 2450b53232e3..0beb35bbfccb 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -177,6 +177,11 @@ struct bt_bap { void *user_data; }; +struct bt_bap_chan { + uint8_t count; + uint32_t location; +}; + struct bt_bap_pac { struct bt_bap_db *bdb; char *name; @@ -185,7 +190,7 @@ struct bt_bap_pac { struct bt_bap_pac_qos qos; struct iovec *data; struct iovec *metadata; - struct queue *chan_map; + struct queue *channels; struct bt_bap_pac_ops *ops; void *user_data; }; @@ -2422,19 +2427,22 @@ 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; + struct bt_bap_chan *chan; if (!v) return; - if (!pac->chan_map) - pac->chan_map = queue_new(); + if (!pac->channels) + pac->channels = queue_new(); - printf("PAC %p chan_map 0x%02x\n", pac, *v); + chan = new0(struct bt_bap_chan, 1); + chan->count = *v; + chan->location = bt_bap_pac_get_locations(pac) ? : pac->qos.location; - queue_push_tail(pac->chan_map, UINT_TO_PTR(*v)); + queue_push_tail(pac->channels, chan); } -static void bap_pac_update_chan_map(struct bt_bap_pac *pac, struct iovec *data) +static void bap_pac_update_channels(struct bt_bap_pac *pac, struct iovec *data) { uint8_t type = 0x03; @@ -2454,8 +2462,8 @@ static void bap_pac_merge(struct bt_bap_pac *pac, struct iovec *data, else pac->data = util_iov_dup(data, 1); - /* Update channel map */ - bap_pac_update_chan_map(pac, data); + /* Update channels */ + bap_pac_update_channels(pac, data); /* Merge metadata into existing record */ if (pac->metadata) @@ -2495,7 +2503,7 @@ static void bap_pac_free(void *data) free(pac->name); util_iov_free(pac->metadata, 1); util_iov_free(pac->data, 1); - queue_destroy(pac->chan_map, NULL); + queue_destroy(pac->channels, free); free(pac); } @@ -4677,34 +4685,52 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, if (!lpac->ops || !lpac->ops->select) return -EOPNOTSUPP; - for (lchan = queue_get_entries(lpac->chan_map); lchan; + for (lchan = queue_get_entries(lpac->channels); lchan; lchan = lchan->next) { - uint8_t lmap = PTR_TO_UINT(lchan->data); + struct bt_bap_chan *lc = lchan->data; + uint8_t lmap = lc->count; + int i; - for (rchan = queue_get_entries(rpac->chan_map); rchan; - rchan = rchan->next) { - uint8_t rmap = PTR_TO_UINT(rchan->data); + printf("lmap 0x%02x\n", lmap); - printf("lmap 0x%02x rmap 0x%02x\n", lmap, rmap); + for (i = 0, rchan = queue_get_entries(rpac->channels); rchan; + rchan = rchan->next, i++) { + struct bt_bap_chan *rc = rchan->data; - /* Try matching the channel mapping */ - if (lmap & rmap) { - lpac->ops->select(lpac, rpac, &rpac->qos, - func, user_data, - lpac->user_data); - if (count) - (*count)++; + printf("rc->count 0x%02x\n", rc->count); - /* Check if there are any channels left */ - lmap &= ~(lmap & rmap); - if (!lmap) - break; - - /* Check if device require AC*(i) settings */ - if (rmap == 0x01) - lmap = lmap >> 1; - } else + /* Try matching the channel count */ + if (!(lmap & rc->count)) break; + + /* Check if location was set otherwise attempt to + * assign one based on the number of channels it + * supports. + */ + if (!rc->location) { + rc->location = bt_bap_pac_get_locations(rpac); + /* If channel count is 1 use a single + * location + */ + if (rc->count == 0x01) + rc->location &= BIT(i); + } + + lpac->ops->select(lpac, rpac, lc->location & + rc->location, &rpac->qos, + func, user_data, + lpac->user_data); + if (count) + (*count)++; + + /* Check if there are any channels left to select */ + lmap &= ~(lmap & rc->count); + if (!lmap) + break; + + /* Check if device require AC*(i) settings */ + if (rc->count == 0x01) + lmap = lmap >> 1; } } diff --git a/src/shared/bap.h b/src/shared/bap.h index 470313e66fc0..9be198cec72c 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -151,7 +151,7 @@ struct bt_bap_pac *bt_bap_add_pac(struct gatt_db *db, const char *name, struct bt_bap_pac_ops { int (*select)(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, - struct bt_bap_pac_qos *qos, + uint32_t chan_alloc, struct bt_bap_pac_qos *qos, bt_bap_pac_select_t cb, void *cb_data, void *user_data); int (*config)(struct bt_bap_stream *stream, struct iovec *cfg, struct bt_bap_qos *qos, bt_bap_pac_config_t cb, From patchwork Fri Dec 8 22:12:18 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: 13485884 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OVIOOTFU" Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6B271710 for ; Fri, 8 Dec 2023 14:12:34 -0800 (PST) Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-58de42d0ff7so1316502eaf.0 for ; Fri, 08 Dec 2023 14:12:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702073553; x=1702678353; 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=ZhazXA6FIrqiNe7ozrKftw7aqm3nBoPVdbR+V8s8ls4=; b=OVIOOTFUNchlJ0IK33/DvvgGWx/9QmaC7JFIyWpxIr5CJVd1QvbWEDBg/FBz5g2PLm gTYfFGKKeyd8YjyVPtR8TPZjnFg3EraLNokjtINJrcLNZF5Xs1071lLVQ/WMJquFVsjI OGNojcYPOjrEu3rCQ/0LKl9tgpZOroIxge4HHGVlTDfqYptxB6kPGDY3HYETIHN2nCFB T1tc0vIwbAXq/LdbaRwOvr6jKHly10MmuVPevGQaavQg4MYOAynxlpXy/B0bl1EioE6e eFFXwRplYs43u3EEjUcI/owOeKPMPGaKR8lTwqhXW/11ybXMeVirbN1N5k1uRaCDd9qR CkJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702073553; x=1702678353; 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=ZhazXA6FIrqiNe7ozrKftw7aqm3nBoPVdbR+V8s8ls4=; b=K8EwOo6T1+W7uyWy016nCAIVw9IeLUNfD710HaEQ6cg3iQi0/6EyznpYZ4j8X4Q0B2 dX0mJY3uRwRqrEvPl+LCxLqY/Zz6Vu6YqWHlDTFhzgu5Y+SY6aVx4rACwXip+8Wu/bT0 M0Mw7UvF8CYUz1BqbJnXr4pNkVtx0ecQsIP5KCOAel0TfvAF0Q8dOzMuzTm5s5UE/GGr nFung8eHcTYRKEXgy2EKh26XEmu1XrKA55MtST/fMCw8gkIQlWGdvbyw+0uLW6Ape6fF q2Znl3B+A8G3rD/Qo/2cfZMv6Evpec3saY3lDXhp/d+4iduDRGyDHBuFYHRWz3qhzAJ7 oFzg== X-Gm-Message-State: AOJu0YxwVat4j+R4JmcQESbPmS0xPwDVM5Ydr9Y41+wP7DXZMgxu9Wmq QfVsQXXAK2MxQxujLaHNGW7hWEKFcbM= X-Google-Smtp-Source: AGHT+IGTuZmxE++pQdYJwG2qVWodLMOZcc3CuofRx7+C38B02PDg1u4S6WTROOtGWDFWkOupDpWG0g== X-Received: by 2002:a05:6820:1ac9:b0:590:87c5:2b0c with SMTP id bu9-20020a0568201ac900b0059087c52b0cmr843808oob.7.1702073552676; Fri, 08 Dec 2023 14:12:32 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id a44-20020a4a98af000000b0058df21de4fasm378195ooj.10.2023.12.08.14.12.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 14:12:30 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 5/6] shared/bap: Fix stream IO linking Date: Fri, 8 Dec 2023 17:12:18 -0500 Message-ID: <20231208221219.54529-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208221219.54529-1-luiz.dentz@gmail.com> References: <20231208221219.54529-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 IO linking shall only be possible once, for the oposite direction as ISO channels are bidirection, and not many times as that means multiplexing would be used which is done within the transport payload, so this get rid of queue links list and just use single link point instead. --- profiles/audio/media.c | 6 +- profiles/audio/transport.c | 43 +++++++---- src/shared/bap.c | 149 ++++++++++++------------------------- src/shared/bap.h | 2 +- 4 files changed, 77 insertions(+), 123 deletions(-) diff --git a/profiles/audio/media.c b/profiles/audio/media.c index b17c555b63e4..1faa1c28969f 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -921,7 +921,7 @@ done: } static int pac_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, - uint32_t chan_alloc, struct bt_bap_pac_qos *qos, + uint32_t location, struct bt_bap_pac_qos *qos, bt_bap_pac_select_t cb, void *cb_data, void *user_data) { struct media_endpoint *endpoint = user_data; @@ -969,9 +969,9 @@ static int pac_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, g_dbus_dict_append_entry(&dict, "Locations", DBUS_TYPE_UINT32, &loc); - if (chan_alloc) + if (location) g_dbus_dict_append_entry(&dict, "ChannelAllocation", - DBUS_TYPE_UINT32, &chan_alloc); + DBUS_TYPE_UINT32, &location); if (metadata) { key = "Metadata"; diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c index 23ea267f6446..e2073451cc7a 100644 --- a/profiles/audio/transport.c +++ b/profiles/audio/transport.c @@ -312,9 +312,12 @@ static void media_transport_remove_owner(struct media_transport *transport) media_request_reply(owner->pending, EIO); transport->owner = NULL; - if (bap->linked) - queue_foreach(bt_bap_stream_io_get_links(bap->stream), - linked_transport_remove_owner, owner); + if (bap->linked) { + struct bt_bap_stream *link; + + link = bt_bap_stream_io_get_link(bap->stream); + linked_transport_remove_owner(link, owner); + } if (owner->watch) g_dbus_remove_watch(btd_get_dbus_connection(), owner->watch); @@ -496,9 +499,12 @@ static void media_transport_set_owner(struct media_transport *transport, DBG("Transport %s Owner %s", transport->path, owner->name); transport->owner = owner; - if (bap->linked) - queue_foreach(bt_bap_stream_io_get_links(bap->stream), - linked_transport_set_owner, owner); + if (bap->linked) { + struct bt_bap_stream *link; + + link = bt_bap_stream_io_get_link(bap->stream); + linked_transport_set_owner(link, owner); + } owner->transport = transport; owner->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(), @@ -962,12 +968,15 @@ static gboolean links_exists(const GDBusPropertyTable *property, void *data) return bap->linked; } -static void append_links(void *data, void *user_data) +static void append_link(void *data, void *user_data) { struct bt_bap_stream *stream = data; DBusMessageIter *array = user_data; struct media_transport *transport; + if (!stream) + return; + transport = find_transport_by_bap_stream(stream); if (!transport) { error("Unable to find transport"); @@ -983,14 +992,14 @@ static gboolean get_links(const GDBusPropertyTable *property, { struct media_transport *transport = data; struct bap_transport *bap = transport->data; - struct queue *links = bt_bap_stream_io_get_links(bap->stream); + struct bt_bap_stream *link = bt_bap_stream_io_get_link(bap->stream); DBusMessageIter array; dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, DBUS_TYPE_OBJECT_PATH_AS_STRING, &array); - queue_foreach(links, append_links, &array); + append_link(link, &array); dbus_message_iter_close_container(iter, &array); @@ -1280,15 +1289,15 @@ static bool match_link_transport(const void *data, const void *user_data) static void bap_update_links(const struct media_transport *transport) { struct bap_transport *bap = transport->data; - struct queue *links = bt_bap_stream_io_get_links(bap->stream); + struct bt_bap_stream *link = bt_bap_stream_io_get_link(bap->stream); - if (bap->linked == !queue_isempty(links)) + if (bap->linked == (!!link)) return; - bap->linked = !queue_isempty(links); + bap->linked = link ? true : false; /* Check if the links transport has been create yet */ - if (bap->linked && !queue_find(links, match_link_transport, NULL)) { + if (bap->linked && !match_link_transport(link, NULL)) { bap->linked = false; return; } @@ -1456,13 +1465,15 @@ static void set_state_bap(struct media_transport *transport, transport_state_t state) { struct bap_transport *bap = transport->data; + struct bt_bap_stream *link; if (!bap->linked) return; - /* Update links */ - queue_foreach(bt_bap_stream_io_get_links(bap->stream), link_set_state, - UINT_TO_PTR(state)); + link = bt_bap_stream_io_get_link(bap->stream); + + /* Update link */ + link_set_state(link, UINT_TO_PTR(state)); } static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state, diff --git a/src/shared/bap.c b/src/shared/bap.c index 0beb35bbfccb..7efdd7f5b508 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -222,7 +222,7 @@ struct bt_bap_stream { struct iovec *cc; struct iovec *meta; struct bt_bap_qos qos; - struct queue *links; + struct bt_bap_stream *link; struct bt_bap_stream_io *io; bool client; void *user_data; @@ -1010,14 +1010,6 @@ static void stream_io_unref(struct bt_bap_stream_io *io) stream_io_free(io); } -static void bap_stream_unlink(void *data, void *user_data) -{ - struct bt_bap_stream *link = data; - struct bt_bap_stream *stream = user_data; - - queue_remove(link->links, stream); -} - static void bap_stream_free(void *data) { struct bt_bap_stream *stream = data; @@ -1025,8 +1017,9 @@ static void bap_stream_free(void *data) if (stream->ep) stream->ep->stream = NULL; - queue_foreach(stream->links, bap_stream_unlink, stream); - queue_destroy(stream->links, NULL); + if (stream->link) + stream->link->link = NULL; + stream_io_unref(stream->io); util_iov_free(stream->cc, 1); util_iov_free(stream->meta, 1); @@ -1050,12 +1043,12 @@ static void bap_stream_detach(struct bt_bap_stream *stream) bap_stream_free(stream); } -static void bap_stream_io_link(void *data, void *user_data) +static bool bap_stream_io_link(const void *data, const void *user_data) { - struct bt_bap_stream *stream = data; - struct bt_bap_stream *link = user_data; + struct bt_bap_stream *stream = (void *)data; + struct bt_bap_stream *link = (void *)user_data; - bt_bap_stream_io_link(stream, link); + return !bt_bap_stream_io_link(stream, link); } static void bap_stream_update_io_links(struct bt_bap_stream *stream) @@ -1064,7 +1057,7 @@ static void bap_stream_update_io_links(struct bt_bap_stream *stream) DBG(bap, "stream %p", stream); - queue_foreach(bap->streams, bap_stream_io_link, stream); + queue_find(bap->streams, bap_stream_io_link, stream); } static struct bt_bap_stream_io *stream_io_ref(struct bt_bap_stream_io *io) @@ -1095,31 +1088,18 @@ static struct bt_bap_stream_io *stream_io_new(struct bt_bap *bap, int fd) return stream_io_ref(sio); } -static void stream_find_io(void *data, void *user_data) -{ - struct bt_bap_stream *stream = data; - struct bt_bap_stream_io **io = user_data; - - if (*io) - return; - - *io = stream->io; -} - static struct bt_bap_stream_io *stream_get_io(struct bt_bap_stream *stream) { - struct bt_bap_stream_io *io; - if (!stream) return NULL; if (stream->io) return stream->io; - io = NULL; - queue_foreach(stream->links, stream_find_io, &io); + if (stream->link) + return stream->link->io; - return io; + return NULL; } static bool stream_io_disconnected(struct io *io, void *user_data); @@ -1157,17 +1137,6 @@ static bool bap_stream_io_attach(struct bt_bap_stream *stream, int fd, return true; } -static bool match_stream_io(const void *data, const void *user_data) -{ - const struct bt_bap_stream *stream = data; - const struct bt_bap_stream_io *io = user_data; - - if (!stream->io) - return false; - - return stream->io == io; -} - static bool bap_stream_io_detach(struct bt_bap_stream *stream) { struct bt_bap_stream *link; @@ -1181,7 +1150,7 @@ static bool bap_stream_io_detach(struct bt_bap_stream *stream) io = stream->io; stream->io = NULL; - link = queue_find(stream->links, match_stream_io, io); + link = stream->link; if (link) { /* Detach link if in QoS state */ if (link->ep->state == BT_ASCS_ASE_STATE_QOS) @@ -2485,14 +2454,15 @@ static struct bt_bap_pac *bap_pac_new(struct bt_bap_db *bdb, const char *name, pac->bdb = bdb; pac->name = name ? strdup(name) : NULL; pac->type = type; + if (codec) pac->codec = *codec; - bap_pac_merge(pac, data, metadata); - if (qos) pac->qos = *qos; + bap_pac_merge(pac, data, metadata); + return pac; } @@ -4692,6 +4662,7 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, int i; printf("lmap 0x%02x\n", lmap); + printf("lc->location 0x%02x\n", lc->location); for (i = 0, rchan = queue_get_entries(rpac->channels); rchan; rchan = rchan->next, i++) { @@ -4714,6 +4685,8 @@ int bt_bap_select(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, */ if (rc->count == 0x01) rc->location &= BIT(i); + + printf("rc->location 0x%02x\n", rc->location); } lpac->ops->select(lpac, rpac, lc->location & @@ -4940,14 +4913,6 @@ static int bap_stream_metadata(struct bt_bap_stream *stream, uint8_t op, return req->id; } -static void bap_stream_enable_link(void *data, void *user_data) -{ - struct bt_bap_stream *stream = data; - struct iovec *metadata = user_data; - - bap_stream_metadata(stream, BT_ASCS_ENABLE, metadata, NULL, NULL); -} - unsigned int bt_bap_stream_enable(struct bt_bap_stream *stream, bool enable_links, struct iovec *metadata, @@ -4969,7 +4934,9 @@ unsigned int bt_bap_stream_enable(struct bt_bap_stream *stream, if (!ret || !enable_links) return ret; - queue_foreach(stream->links, bap_stream_enable_link, metadata); + if (stream->link) + bap_stream_metadata(stream->link, BT_ASCS_ENABLE, + metadata, NULL, NULL); break; case BT_BAP_STREAM_TYPE_BCAST: if (!bt_bap_stream_io_dir(stream)) @@ -5032,26 +4999,6 @@ unsigned int bt_bap_stream_start(struct bt_bap_stream *stream, return 0; } -static void bap_stream_disable_link(void *data, void *user_data) -{ - struct bt_bap_stream *stream = data; - struct bt_bap_req *req; - struct iovec iov; - struct bt_ascs_disable disable; - - memset(&disable, 0, sizeof(disable)); - - disable.ase = stream->ep->id; - - iov.iov_base = &disable; - iov.iov_len = sizeof(disable); - - req = bap_req_new(stream, BT_ASCS_DISABLE, &iov, 1, NULL, NULL); - - if (!bap_queue_req(stream->bap, req)) - bap_req_free(req); -} - unsigned int bt_bap_stream_disable(struct bt_bap_stream *stream, bool disable_links, bt_bap_stream_func_t func, @@ -5087,8 +5034,7 @@ unsigned int bt_bap_stream_disable(struct bt_bap_stream *stream, } if (disable_links) - queue_foreach(stream->links, bap_stream_disable_link, - NULL); + bt_bap_stream_disable(stream->link, false, NULL, NULL); return req->id; @@ -5295,7 +5241,8 @@ bool bt_bap_stream_set_io(struct bt_bap_stream *stream, int fd) bap_stream_set_io(stream, INT_TO_PTR(fd)); - queue_foreach(stream->links, bap_stream_set_io, INT_TO_PTR(fd)); + if (stream->link) + bap_stream_set_io(stream, INT_TO_PTR(fd)); return true; } @@ -5348,22 +5295,17 @@ int bt_bap_stream_io_link(struct bt_bap_stream *stream, if (!stream || !link || stream == link) return -EINVAL; - if (queue_find(stream->links, NULL, link)) + if (stream->link || link->link) return -EALREADY; if (stream->client != link->client || stream->qos.ucast.cig_id != link->qos.ucast.cig_id || - stream->qos.ucast.cis_id != link->qos.ucast.cis_id) + stream->qos.ucast.cis_id != link->qos.ucast.cis_id || + stream->ep->dir == link->ep->dir) return -EINVAL; - if (!stream->links) - stream->links = queue_new(); - - if (!link->links) - link->links = queue_new(); - - queue_push_tail(stream->links, link); - queue_push_tail(link->links, stream); + stream->link = link; + link->link = stream; /* Link IOs if already set on stream/link */ if (stream->io && !link->io) @@ -5376,12 +5318,12 @@ int bt_bap_stream_io_link(struct bt_bap_stream *stream, return 0; } -struct queue *bt_bap_stream_io_get_links(struct bt_bap_stream *stream) +struct bt_bap_stream *bt_bap_stream_io_get_link(struct bt_bap_stream *stream) { if (!stream) return NULL; - return stream->links; + return stream->link; } static void bap_stream_get_in_qos(void *data, void *user_data) @@ -5389,6 +5331,9 @@ static void bap_stream_get_in_qos(void *data, void *user_data) struct bt_bap_stream *stream = data; struct bt_bap_qos **qos = user_data; + if (!stream) + return; + if (!qos || *qos || stream->ep->dir != BT_BAP_SOURCE || !stream->qos.ucast.io_qos.sdu) return; @@ -5401,6 +5346,9 @@ static void bap_stream_get_out_qos(void *data, void *user_data) struct bt_bap_stream *stream = data; struct bt_bap_qos **qos = user_data; + if (!stream) + return; + if (!qos || *qos || stream->ep->dir != BT_BAP_SINK || !stream->qos.ucast.io_qos.sdu) return; @@ -5418,11 +5366,11 @@ bool bt_bap_stream_io_get_qos(struct bt_bap_stream *stream, switch (stream->ep->dir) { case BT_BAP_SOURCE: bap_stream_get_in_qos(stream, in); - queue_foreach(stream->links, bap_stream_get_out_qos, out); + bap_stream_get_out_qos(stream->link, out); break; case BT_BAP_SINK: bap_stream_get_out_qos(stream, out); - queue_foreach(stream->links, bap_stream_get_in_qos, in); + bap_stream_get_in_qos(stream->link, in); break; default: return false; @@ -5433,14 +5381,6 @@ bool bt_bap_stream_io_get_qos(struct bt_bap_stream *stream, return in && out; } -static void bap_stream_get_dir(void *data, void *user_data) -{ - struct bt_bap_stream *stream = data; - uint8_t *dir = user_data; - - *dir |= stream->ep->dir; -} - uint8_t bt_bap_stream_io_dir(struct bt_bap_stream *stream) { uint8_t dir; @@ -5450,7 +5390,8 @@ uint8_t bt_bap_stream_io_dir(struct bt_bap_stream *stream) dir = stream->ep->dir; - queue_foreach(stream->links, bap_stream_get_dir, &dir); + if (stream->link) + dir |= stream->link->ep->dir; return dir; } @@ -5461,6 +5402,9 @@ static void bap_stream_io_connecting(void *data, void *user_data) int fd = PTR_TO_INT(user_data); const struct queue_entry *entry; + if (!stream) + return; + if (fd >= 0) bap_stream_io_attach(stream, fd, true); else @@ -5482,8 +5426,7 @@ int bt_bap_stream_io_connecting(struct bt_bap_stream *stream, int fd) return -EINVAL; bap_stream_io_connecting(stream, INT_TO_PTR(fd)); - - queue_foreach(stream->links, bap_stream_io_connecting, INT_TO_PTR(fd)); + bap_stream_io_connecting(stream->link, INT_TO_PTR(fd)); return 0; } diff --git a/src/shared/bap.h b/src/shared/bap.h index 9be198cec72c..51edc08ab1ac 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -303,7 +303,7 @@ int bt_bap_stream_cancel(struct bt_bap_stream *stream, unsigned int id); int bt_bap_stream_io_link(struct bt_bap_stream *stream, struct bt_bap_stream *link); -struct queue *bt_bap_stream_io_get_links(struct bt_bap_stream *stream); +struct bt_bap_stream *bt_bap_stream_io_get_link(struct bt_bap_stream *stream); bool bt_bap_stream_io_get_qos(struct bt_bap_stream *stream, struct bt_bap_qos **in, struct bt_bap_qos **out); From patchwork Fri Dec 8 22:12:19 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: 13485883 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a6R+ZWEa" Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0FA81712 for ; Fri, 8 Dec 2023 14:12:36 -0800 (PST) Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-58cf894544cso1299303eaf.3 for ; Fri, 08 Dec 2023 14:12:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702073555; x=1702678355; 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=pfJH2vBFvTk3Ec7zxskcSmGRALcmbhg3NKo1nMNN3hI=; b=a6R+ZWEajhbc4w/Cy1k+5QyXjrQipwV578SIqFbQ+38kNmpKOOUBcISIe1kDkkU+0N EbeewpEKAAU8lYWbu62X7SrUG0G0JthIyYa5t6W6L2NhOcqYW615KOpq3TiHo0PkKdBK MeDBcMfcS/T81Pg3YBnzDIZj03eEysYiEF/URdjcDLyIyT4/UloKZG0Om/6znq337PMK odU8EvyBSig4ia/DX9wJctR+p6JbO/UVYXxcJXfgdaUtVJQ4tCNw40EQueC7hXBy7/gZ 4SxIWefnhwyTqJL83I3T0EB9OMqND6mdrjueYXW8gVJLBH15F8lgpua4Ss9MqMxM5PJ/ szCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702073555; x=1702678355; 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=pfJH2vBFvTk3Ec7zxskcSmGRALcmbhg3NKo1nMNN3hI=; b=RIAeTlgUwENNAHYpinhhuTJbyIWSVhZJmOUTRs+ddS+498JpMQU+Ku2+xqXePz+YVT cZb7BiaK13up6WNP5AbKLKHOMALu32RHdAg2qF3zYg/BL4DGKQS97Di7ugm3VIrkt8/I Q7memvd1qpD4PeTGLFZ79HSE7kHx9srl5eek84I/j554TH5oEkO09FxOLPu0EbECIqKE GgzNMCRCMhnSifteQC3WgsnyzTwbaU38+Uv5J67N1qqcEG5Ed72HmawsRLCgMP1pCRhx bCGtkveI139PHZApJiIe3DhTRVdWmkQ4y+e+fIT+qC8+sPT7Qn8ykKF3CD8tWQDWl+wy /REg== X-Gm-Message-State: AOJu0YyRmoxas7TKOEEOFJlcOesIFHx/sYrx1zgGseO1MLh9tZjdQ08V za2sA80fyEtVqDJuJBXzxTGpQOC33EU= X-Google-Smtp-Source: AGHT+IHEopiZgBY2STmdRottC5QXoWYJyIVIQI9cVoeeE5V70KfUx/+lIQdhoywCaGCZxDt5A1uRQQ== X-Received: by 2002:a05:6820:168b:b0:590:97ed:9d53 with SMTP id bc11-20020a056820168b00b0059097ed9d53mr922412oob.8.1702073555002; Fri, 08 Dec 2023 14:12:35 -0800 (PST) Received: from lvondent-mobl4.. (071-047-239-151.res.spectrum.com. [71.47.239.151]) by smtp.gmail.com with ESMTPSA id a44-20020a4a98af000000b0058df21de4fasm378195ooj.10.2023.12.08.14.12.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 14:12:33 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v2 6/6] client/player: Use ChannelAllocation given on SelectProperties Date: Fri, 8 Dec 2023 17:12:19 -0500 Message-ID: <20231208221219.54529-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231208221219.54529-1-luiz.dentz@gmail.com> References: <20231208221219.54529-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 makes use of ChannelAllocation when present on SelectProperties dictionary which is then passed on to bluetoothd and send over as part of Codec Configuration: < ACL Data TX: Handle 2048 flags 0x00 dlen 109 ATT: Write Command (0x52) len 104 Handle: 0x0098 Type: ASE Control Point (0x2bc6) Data: 0104050202060000000010020103020201030428000503010000000 6020206000000001002010302020103042800050302000000010202060000 0000100201030202010304280005030100000002020206000000001002010 302020103042800050302000000 Opcode: Codec Configuration (0x01) Number of ASE(s): 4 ASE: #0 ASE ID: 0x05 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000001 Front Left (0x00000001) ASE: #1 ASE ID: 0x06 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000002 Front Right (0x00000002) ASE: #2 ASE ID: 0x01 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000001 Front Left (0x00000001) ASE: #3 ASE ID: 0x02 Target Latency: Balance Latency/Reliability (0x02) PHY: 0x02 LE 2M PHY (0x02) Codec: LC3 (0x06) Codec Specific Configuration: #0: len 0x02 type 0x01 Sampling Frequency: 16 Khz (0x03) Codec Specific Configuration: #1: len 0x02 type 0x02 Frame Duration: 10 ms (0x01) Codec Specific Configuration: #2: len 0x03 type 0x04 Frame Length: 40 (0x0028) Codec Specific Configuration: #3: len 0x05 type 0x03 Location: 0x00000002 Front Right (0x00000002) --- client/player.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/client/player.c b/client/player.c index 4d49602c70d7..92fc91f920f3 100644 --- a/client/player.c +++ b/client/player.c @@ -64,7 +64,7 @@ #define SEC_USEC(_t) (_t * 1000000L) #define TS_USEC(_ts) (SEC_USEC((_ts)->tv_sec) + NSEC_USEC((_ts)->tv_nsec)) -#define EP_SRC_LOCATIONS 0x00000001 +#define EP_SRC_LOCATIONS 0x00000003 #define EP_SNK_LOCATIONS 0x00000003 #define EP_SRC_CTXT 0x000f @@ -2104,13 +2104,42 @@ static struct iovec *iov_append(struct iovec **iov, const void *data, return *iov; } +static int parse_chan_alloc(DBusMessageIter *iter, uint32_t *location) +{ + while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_DICT_ENTRY) { + const char *key; + DBusMessageIter value, entry; + int var; + + dbus_message_iter_recurse(iter, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &value); + + var = dbus_message_iter_get_arg_type(&value); + + if (!strcasecmp(key, "ChannelAllocation")) { + if (var != DBUS_TYPE_UINT32) + return -EINVAL; + dbus_message_iter_get_basic(&value, location); + return 0; + } + + dbus_message_iter_next(iter); + } + + return -EINVAL; +} + static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, DBusMessage *msg, struct codec_preset *preset) { DBusMessage *reply; - DBusMessageIter iter; + DBusMessageIter iter, props; struct endpoint_config *cfg; + uint32_t location = 0; if (!preset) return NULL; @@ -2126,6 +2155,18 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, iov_append(&cfg->caps, preset->data.iov_base, preset->data.iov_len); cfg->target_latency = preset->target_latency; + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &props); + + if (!parse_chan_alloc(&props, &location)) { + uint8_t chan_alloc_ltv[] = { + 0x05, LC3_CONFIG_CHAN_ALLOC, location & 0xff, + location >> 8, location >> 16, location >> 24 + }; + + iov_append(&cfg->caps, &chan_alloc_ltv, sizeof(chan_alloc_ltv)); + } + /* Copy metadata */ if (ep->meta) iov_append(&cfg->meta, ep->meta->iov_base, ep->meta->iov_len);