Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2893342rdh; Wed, 27 Sep 2023 16:46:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELoLrpIe2Sehh5OGssEY44Ob87CyoVW/g2yq9urDwkuwOHswCS5cTxVhZu9pgDUKuMTlR1 X-Received: by 2002:a05:620a:2901:b0:774:3147:4251 with SMTP id m1-20020a05620a290100b0077431474251mr3987477qkp.6.1695858371904; Wed, 27 Sep 2023 16:46:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695858371; cv=none; d=google.com; s=arc-20160816; b=KkpVXouUwmTSYcyhIMCILDJVKiJM1fizhH2ku7e2mIeTgOvq8Nv76TTRtuiEQToOV5 sOiPWTqauRp3SKSVQAevfG7XrFzyfSLzPbKYhV0vlr5jIpYba0fYkvfMy0BUM3jqdPH4 MIH9MKmSH2DDwDqofb48VI6DHd3SGdpIA3dD7GjgjGt/7ibSmFnaQAqz4buoTREgjbBd SeetRd1GTQmzmQhFoim+uygZ9m6+5GJZuLnGrCyl2HiDonDX+M8FEdAdh+CrDWNLC+Hr MZm3lW8cUKfx6d5yZ061I6ETjdAF6rHZCEE+UWmEAcE0mWXMMReq1I9G+VTxGgNDl2kD QB6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=jwjHUPbdhZ0jdDmdOXswQrPccCOLqfWqLeXxUdDF1vI=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=GqjzJZUo6UyqggBibGT/nBPjyoTcRXq7C6cKKaXfgkiysLCLS4KXJFgKg9dqUTFw23 0ErdBS2Eb2h/VmLM2hcanT8wf7bBsnKvLnaLIFaVEyEfIoqgL0UbqFvY4xE9+NCp4wjU CFyG7picvMLP063u6dQfCeN4coyEgKlmcDUdkxbq3vPYWTD8T3nzvHx2syU6HKPeUfd5 m2HX65s+YXtvJx0WAaj9aTZcenlrt+XFZkq1n7M8BmiMP8M11javLA2VTfPo+TVOeXKT HT3aU66bGK/D8G2K0CzhqQC2DJPd5fqrS7LmbH6b9keF0+NnZNyJKvwrUH8CMwLvUsAk yxMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZkHjZCKF; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id fo10-20020a056a00600a00b00690f74dd2cesi16664445pfb.354.2023.09.27.16.46.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 16:46:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZkHjZCKF; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C54DD804C667; Wed, 27 Sep 2023 14:54:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229710AbjI0VyM (ORCPT + 99 others); Wed, 27 Sep 2023 17:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229511AbjI0VyL (ORCPT ); Wed, 27 Sep 2023 17:54:11 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E2211F for ; Wed, 27 Sep 2023 14:54:08 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-79fb64b5265so317310439f.1 for ; Wed, 27 Sep 2023 14:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695851647; x=1696456447; 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=jwjHUPbdhZ0jdDmdOXswQrPccCOLqfWqLeXxUdDF1vI=; b=ZkHjZCKFw+XHeVxbpIkOwMZNSxvAF6nPRV6hiA5bVm4jgOsjuVXRTvExEla2s2+idU Je9DkRa470HvYVtgxZmiJ4Wa01kVY0tWYvOz1cbR8s7JKi0l7uFgIO6+DChl+4xTwmri /FtFMidJrw4O1/NodP4JRYFRPAovaV8XVzH5knCChFdYh0dyYK+6wntnl3dsGoqrANfe BCaYXBMFKwTE4EGdipRyoyRp11i7cPFrvm9iJ3HW1+GDcRD/jD6x+8SXe/xSFlE4nCqJ piMtEHO7WCwXEmpnnXpEbFim5KTM9/+5bTUrEmrhhEgyD38sBM9hwdLvb51fewEshuJd 8kwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695851647; x=1696456447; 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=jwjHUPbdhZ0jdDmdOXswQrPccCOLqfWqLeXxUdDF1vI=; b=Z532YeZMQ0N0d0iwkt/ks3biSLRvuYWAhjD5BTiBrs6dvqzbVOO33pCmNYMM7eEcTI mHjmuTyPjYAv6nNatZbKdGiuCEoF0FJcKp0phWl5QNu1A+DaVRN9aj3jDiEnffn+CGau d+n1TTGJZHTuDKoL+43Xj6GhZbFgDDTLX1Lv0X1Ot9Vf9QM8ZfOkC8g2GhyXWcrGydew U7GmKROEYtf0CrYBR1S9NikXxTnrxUuIkxBmTsOyHtoXgj1RLdet1Irx5r4gH6pQ8BQd GXr+TfpTr6TDu7ze8xOcpz8nlvx76aQ/DGJZ9jCiF9abVkp+K9FlLL4+cGhkClx/SgRO Tqqg== X-Gm-Message-State: AOJu0YyRKjRsv/n1+KH/nSWOhS/ax6cgMiaFk/gcw4SlmoTf0zJxUfDV qI2V8FI6ya3TEHySW7FSh1loK/3nkzEctc9M X-Received: by 2002:a6b:e015:0:b0:790:f866:d717 with SMTP id z21-20020a6be015000000b00790f866d717mr3822401iog.10.1695851647518; Wed, 27 Sep 2023 14:54:07 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id g15-20020a02cd0f000000b0042bbfe3dc42sm4225331jaq.173.2023.09.27.14.54.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 14:54:06 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v4 07/12] shared/bap: Add support content and contexts to bt_bap_pac_qos Date: Wed, 27 Sep 2023 14:53:49 -0700 Message-ID: <20230927215354.1874835-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230927215354.1874835-1-luiz.dentz@gmail.com> References: <20230927215354.1874835-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 27 Sep 2023 14:54:13 -0700 (PDT) From: Luiz Augusto von Dentz This adds support for setting supported content and contexts on a per PAC record basis which then is carried over to their respective PACS attribute and notified properly when changed (added/removed). --- src/shared/bap.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++- src/shared/bap.h | 3 + 2 files changed, 170 insertions(+), 1 deletion(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index 1c43680c2457..6400d1d69221 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -2468,6 +2468,80 @@ static void bap_pac_free(void *data) free(pac); } +static void pacs_sink_location_changed(struct bt_pacs *pacs) +{ + uint32_t location = cpu_to_le32(pacs->sink_loc_value); + + gatt_db_attribute_notify(pacs->sink_loc, (void *)&location, + sizeof(location), NULL); +} + +static void pacs_add_sink_location(struct bt_pacs *pacs, uint32_t location) +{ + location |= pacs->sink_loc_value; + + /* Check if location value needs updating */ + if (location == pacs->sink_loc_value) + return; + + pacs->sink_loc_value = location; + + pacs_sink_location_changed(pacs); +} + +static void pacs_supported_context_changed(struct bt_pacs *pacs) +{ + struct bt_pacs_context ctx; + + memset(&ctx, 0, sizeof(ctx)); + + ctx.snk = cpu_to_le16(pacs->supported_sink_context_value); + ctx.src = cpu_to_le16(pacs->supported_source_context_value); + + gatt_db_attribute_notify(pacs->supported_context, (void *)&ctx, + sizeof(ctx), NULL); +} + +static void pacs_add_sink_supported_context(struct bt_pacs *pacs, + uint16_t context) +{ + context |= pacs->supported_sink_context_value; + + /* Check if context value needs updating */ + if (context == pacs->supported_sink_context_value) + return; + + pacs->supported_sink_context_value = context; + + pacs_supported_context_changed(pacs); +} + +static void pacs_context_changed(struct bt_pacs *pacs) +{ + struct bt_pacs_context ctx; + + memset(&ctx, 0, sizeof(ctx)); + + ctx.snk = cpu_to_le16(pacs->sink_context_value); + ctx.src = cpu_to_le16(pacs->source_context_value); + + gatt_db_attribute_notify(pacs->context, (void *)&ctx, sizeof(ctx), + NULL); +} + +static void pacs_add_sink_context(struct bt_pacs *pacs, uint16_t context) +{ + context |= pacs->supported_sink_context_value; + + /* Check if context value needs updating */ + if (context == pacs->sink_context_value) + return; + + pacs->sink_context_value = context; + + pacs_context_changed(pacs); +} + static void bap_add_sink(struct bt_bap_pac *pac) { struct iovec iov; @@ -2482,10 +2556,62 @@ static void bap_add_sink(struct bt_bap_pac *pac) queue_foreach(pac->bdb->sinks, pac_foreach, &iov); + pacs_add_sink_location(pac->bdb->pacs, pac->qos.location); + pacs_add_sink_supported_context(pac->bdb->pacs, + pac->qos.supported_context); + pacs_add_sink_context(pac->bdb->pacs, pac->qos.context); gatt_db_attribute_notify(pac->bdb->pacs->sink, iov.iov_base, iov.iov_len, NULL); } +static void pacs_source_location_changed(struct bt_pacs *pacs) +{ + uint32_t location = cpu_to_le32(pacs->source_loc_value); + + gatt_db_attribute_notify(pacs->source_loc, (void *)&location, + sizeof(location), NULL); +} + +static void pacs_add_source_location(struct bt_pacs *pacs, uint32_t location) +{ + location |= pacs->source_loc_value; + + /* Check if location value needs updating */ + if (location == pacs->source_loc_value) + return; + + pacs->source_loc_value = location; + + pacs_source_location_changed(pacs); +} + +static void pacs_add_source_supported_context(struct bt_pacs *pacs, + uint16_t context) +{ + context |= pacs->supported_source_context_value; + + /* Check if context value needs updating */ + if (context == pacs->supported_source_context_value) + return; + + pacs->supported_source_context_value = context; + + pacs_supported_context_changed(pacs); +} + +static void pacs_add_source_context(struct bt_pacs *pacs, uint16_t context) +{ + context |= pacs->supported_sink_context_value; + + /* Check if context value needs updating */ + if (context == pacs->sink_context_value) + return; + + pacs->sink_context_value = context; + + pacs_context_changed(pacs); +} + static void bap_add_source(struct bt_bap_pac *pac) { struct iovec iov; @@ -2500,6 +2626,11 @@ static void bap_add_source(struct bt_bap_pac *pac) queue_foreach(pac->bdb->sinks, pac_foreach, &iov); + pacs_add_source_location(pac->bdb->pacs, pac->qos.location); + pacs_add_source_supported_context(pac->bdb->pacs, + pac->qos.supported_context); + pacs_add_source_context(pac->bdb->pacs, pac->qos.context); + gatt_db_attribute_notify(pac->bdb->pacs->source, iov.iov_base, iov.iov_len, NULL); } @@ -2685,13 +2816,48 @@ static void remove_streams(void *data, void *user_data) bt_bap_stream_release(stream, NULL, NULL); } +static void bap_pac_sink_removed(void *data, void *user_data) +{ + struct bt_bap_pac *pac = data; + struct bt_bap_pac_qos *qos = user_data; + + qos->location |= pac->qos.location; + qos->supported_context |= pac->qos.supported_context; + qos->context |= pac->qos.context; +} + bool bt_bap_remove_pac(struct bt_bap_pac *pac) { if (!pac) return false; - if (queue_remove_if(pac->bdb->sinks, NULL, pac)) + if (queue_remove_if(pac->bdb->sinks, NULL, pac)) { + struct bt_pacs *pacs = pac->bdb->pacs; + struct bt_bap_pac_qos qos; + + memset(&qos, 0, sizeof(qos)); + queue_foreach(pac->bdb->sinks, bap_pac_sink_removed, &qos); + + if (pacs->sink_loc_value != qos.location) { + pacs->sink_loc_value = qos.location; + pacs_sink_location_changed(pacs); + } + + if (pacs->supported_sink_context_value != + qos.supported_context) { + pacs->supported_sink_context_value = + qos.supported_context; + pacs_supported_context_changed(pacs); + } + + if (pacs->sink_context_value != qos.context) { + pacs->sink_context_value = qos.context; + pacs_context_changed(pacs); + } + + goto found; + } if (queue_remove_if(pac->bdb->sources, NULL, pac)) goto found; diff --git a/src/shared/bap.h b/src/shared/bap.h index e4eae86502f3..72d6022a32ec 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -131,6 +131,9 @@ struct bt_bap_pac_qos { uint32_t pd_max; uint32_t ppd_min; uint32_t ppd_max; + uint32_t location; + uint16_t supported_context; + uint16_t context; }; struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db, -- 2.41.0