Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1333263rdb; Fri, 20 Oct 2023 16:08:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7JROM9W37jLpfz0CJ8JJNt3shL/Szm0hrsSso+9eXdDRq58hixhlcqg1BMb4GbHKFXxz5 X-Received: by 2002:a17:90a:540a:b0:277:5cd5:6f80 with SMTP id z10-20020a17090a540a00b002775cd56f80mr9528555pjh.16.1697843306094; Fri, 20 Oct 2023 16:08:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697843306; cv=none; d=google.com; s=arc-20160816; b=XXgmlrjs1GD+yDBtu+cPzbKtEnjE0TYt9zL31HpcGaHU1DBzL0nTeGve6BmebXesc0 EpHvLF6njRP5ln0Zw88hPQNM0qdjmnNeTgioD1fnNLGRan+Nqaa7rn+5gaSp16qo3IAx N+ypc8V19SKPZ4ce7tL1Y++jfMkuBloWh/7cDUQN6eiEN0AL+Z6Da2+pAN2oMhFZqj7c eZtWEsYi+2FDImuXSGqs8nYZMz7qi/4pxP0rvpntkUSa0si01Dc17NU0DHIqX43ZE29p T6GqDPRtyiKrt5H8Pi5aOLoBaC0MWDjg/jTtKkGpiZZSXqVNXgJTXoVsekVN3NaziStK jiOg== 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=QsOrKqa3IQ5XWO4puxqBUGOkCixUeKoEoDRJxiGt1+E=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=iGwdCYlZzqakRLd0NnwXz5V0d93cOyOgdxag5EtxgzXwa6AjtsXTItDU+9IfhgsSY8 6gNzZnachg44NGMOKFBffMmZ4D41Ye1BZCqBak5wsnGqEb61u4CBWN8NzOyvg+VI+Wnl C1ZHWE5w9Tg0X/LD3DWzTRf61GizcYygquM9T3tGMzRN66t7EpEI7O+rqqqiVCQUySsz Sp6QIa83mlyA/C0DWhKuUxvM3sFvMdVV6MPecGb3a3TfEZ1QO914/+F+2p8uycYqi7Q6 cxXk4eYiHMqes9upUDjiMtXNTGXcInnRFuPfKq2uhs2hBKgRNTvYRQ2VdJ8OrlErrsyY FkgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="lIjap/mU"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id h24-20020a17090aa89800b0027ced9acac0si5360941pjq.2.2023.10.20.16.08.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 16:08:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="lIjap/mU"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id D27D783383CB; Fri, 20 Oct 2023 16:08:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229473AbjJTXHz (ORCPT + 99 others); Fri, 20 Oct 2023 19:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbjJTXHy (ORCPT ); Fri, 20 Oct 2023 19:07:54 -0400 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 997AFD41 for ; Fri, 20 Oct 2023 16:07:52 -0700 (PDT) Received: by mail-io1-xd2e.google.com with SMTP id ca18e2360f4ac-7a689bd4928so51092239f.0 for ; Fri, 20 Oct 2023 16:07:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697843271; x=1698448071; 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=QsOrKqa3IQ5XWO4puxqBUGOkCixUeKoEoDRJxiGt1+E=; b=lIjap/mU7i0WsOridBmXQ+UbiNWnzQeUpKjXhjB6Cw0f8RiCzxJyEUfEq8zv+q+oPg tQATwj7xe4+NjniQbFRtUIoSVkVpsBtvawzFpF4WK7C2xVxSRejP/K8sjwKCPDLjyTef FUaKb+jc6OdmK1Py+AYtY0e9T0UM/tsvMZu6RJnMRIhLuOYp/sy0EEpt7z23htpMBxQk S4I52y+JdRqOdK5QHWJXpSLLc+o+9L0WF4zTliMaXOw77sUJMptVXlVw+PbiqaLpb8Uo rpLsA/qSu291JTLln4777h3lK9v/Al/IquhokpYRNcG0e7vC3oFy998q2+iQO+PYdgcI AC3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697843271; x=1698448071; 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=QsOrKqa3IQ5XWO4puxqBUGOkCixUeKoEoDRJxiGt1+E=; b=Fmk8iijV/DGBnZJImUX3WSo2D1YKj3MVbKkMoKnfXE+md+UF3SXISXuFD20v5gt+SA +9XpqBtcqGUbRzSaOHejdKNMZzj44PMT7tfx2fvsJXABOMF9hKj7NxPO3Rll9k8wIFpc taUg7VneGkyZazUDFKYwvIbuA7s5Capah5XI26Tuk5PsxGCX28jCG2xhqjvb1bStp9d4 JMYoNqOTsOZF5eXfccQ70E+s5MnXuSWhF+9XAbBoYrJ4cWu6qATMEXgdtzlh9nck5Y5E v0ArGDV7oJmf9wKukyn7b0Uxd1XBpiFLzgvu6Gwk7hunqoR8SNKOLiMIQELpGG0B06DJ MJbw== X-Gm-Message-State: AOJu0YyjzszI+EGocb3Z9pJpglLPa5lYsNOXoKkeHge8vYU0X3BVTJwB M1ghRl3JaJV1b4VNBtDLSsJkXcpILuLJ8r2D1zY= X-Received: by 2002:a05:6602:1481:b0:794:eb37:b0da with SMTP id a1-20020a056602148100b00794eb37b0damr3184543iow.2.1697843271108; Fri, 20 Oct 2023 16:07:51 -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 a2-20020a5e8e02000000b0079216d6f219sm855785ion.14.2023.10.20.16.07.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 16:07:49 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v1 2/2] client: Add support for setting Locations, SupportedContext and Context Date: Fri, 20 Oct 2023 16:07:46 -0700 Message-ID: <20231020230746.3084772-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020230746.3084772-1-luiz.dentz@gmail.com> References: <20231020230746.3084772-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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 20 Oct 2023 16:08:23 -0700 (PDT) From: Luiz Augusto von Dentz This adds proper defaults for Locations, SupportedContext and Context properties since bluetoothd no longer automatically set proper defaults. --- client/player.c | 179 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 165 insertions(+), 14 deletions(-) diff --git a/client/player.c b/client/player.c index 603447a9df46..24513977cc7a 100644 --- a/client/player.c +++ b/client/player.c @@ -64,6 +64,14 @@ #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_SNK_LOCATIONS 0x00000003 + +#define EP_SRC_CTXT 0x000f +#define EP_SUPPORTED_SRC_CTXT EP_SRC_CTXT +#define EP_SNK_CTXT 0x0fff +#define EP_SUPPORTED_SNK_CTXT EP_SNK_CTXT + struct endpoint { char *path; char *uuid; @@ -72,6 +80,9 @@ struct endpoint { uint16_t vid; struct iovec *caps; struct iovec *meta; + uint32_t locations; + uint16_t supported_context; + uint16_t context; bool auto_accept; uint8_t max_transports; uint8_t iso_group; @@ -2363,6 +2374,63 @@ static gboolean endpoint_metadata_exists(const GDBusPropertyTable *property, return ep->meta ? TRUE : FALSE; } +static gboolean endpoint_get_locations(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct endpoint *ep = data; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &ep->locations); + + return TRUE; +} + +static gboolean endpoint_locations_exists(const GDBusPropertyTable *property, + void *data) +{ + struct endpoint *ep = data; + + return ep->supported_context ? TRUE : FALSE; +} + +static gboolean +endpoint_get_supported_context(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct endpoint *ep = data; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, + &ep->supported_context); + + return TRUE; +} + +static gboolean +endpoint_supported_context_exists(const GDBusPropertyTable *property, + void *data) +{ + struct endpoint *ep = data; + + return ep->supported_context ? TRUE : FALSE; +} + +static gboolean endpoint_get_context(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct endpoint *ep = data; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &ep->context); + + return TRUE; +} + +static gboolean endpoint_context_exists(const GDBusPropertyTable *property, + void *data) +{ + struct endpoint *ep = data; + + return ep->context ? TRUE : FALSE; +} + static const GDBusPropertyTable endpoint_properties[] = { { "UUID", "s", endpoint_get_uuid, NULL, NULL }, { "Codec", "y", endpoint_get_codec, NULL, NULL }, @@ -2370,6 +2438,11 @@ static const GDBusPropertyTable endpoint_properties[] = { { "Metadata", "ay", endpoint_get_metadata, NULL, endpoint_metadata_exists }, { "Vendor", "u", endpoint_get_vendor, NULL, endpoint_vendor_exists }, + { "Locations", "u", endpoint_get_locations, NULL, + endpoint_locations_exists }, + { "SupportedContext", "q", endpoint_get_supported_context, NULL, + endpoint_supported_context_exists }, + { "Context", "q", endpoint_get_context, NULL, endpoint_context_exists }, { } }; @@ -2552,6 +2625,67 @@ static void endpoint_iso_group(const char *input, void *user_data) endpoint_iso_stream, ep); } +static void endpoint_context(const char *input, void *user_data) +{ + struct endpoint *ep = user_data; + char *endptr = NULL; + int value; + + value = strtol(input, &endptr, 0); + + if (!endptr || *endptr != '\0' || value > UINT16_MAX) { + bt_shell_printf("Invalid argument: %s\n", input); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + ep->context = value; + + if (ep->broadcast) + bt_shell_prompt_input(ep->path, "BIG (auto/value):", + endpoint_iso_group, ep); + else + bt_shell_prompt_input(ep->path, "CIG (auto/value):", + endpoint_iso_group, ep); +} + +static void endpoint_supported_context(const char *input, void *user_data) +{ + struct endpoint *ep = user_data; + char *endptr = NULL; + int value; + + value = strtol(input, &endptr, 0); + + if (!endptr || *endptr != '\0' || value > UINT16_MAX) { + bt_shell_printf("Invalid argument: %s\n", input); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + ep->supported_context = value; + + bt_shell_prompt_input(ep->path, "Context (value):", endpoint_context, + ep); +} + +static void endpoint_locations(const char *input, void *user_data) +{ + struct endpoint *ep = user_data; + char *endptr = NULL; + int value; + + value = strtol(input, &endptr, 0); + + if (!endptr || *endptr != '\0') { + bt_shell_printf("Invalid argument: %s\n", input); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + ep->locations = value; + + bt_shell_prompt_input(ep->path, "Supported Context (value):", + endpoint_supported_context, ep); +} + static void endpoint_max_transports(const char *input, void *user_data) { struct endpoint *ep = user_data; @@ -2571,12 +2705,7 @@ static void endpoint_max_transports(const char *input, void *user_data) ep->max_transports = value; } - if (ep->broadcast) - bt_shell_prompt_input(ep->path, "BIG (auto/value):", - endpoint_iso_group, ep); - else - bt_shell_prompt_input(ep->path, "CIG (auto/value):", - endpoint_iso_group, ep); + bt_shell_prompt_input(ep->path, "Locations:", endpoint_locations, ep); } static void endpoint_auto_accept(const char *input, void *user_data) @@ -3338,14 +3467,41 @@ static const struct bt_shell_menu endpoint_menu = { {} }, }; +static void endpoint_init_defaults(struct endpoint *ep) +{ + ep->preset = find_presets(ep->uuid, ep->codec, ep->vid, ep->cid); + ep->max_transports = UINT8_MAX; + ep->auto_accept = true; + + if (!strcmp(ep->uuid, A2DP_SOURCE_UUID) || + !strcmp(ep->uuid, A2DP_SOURCE_UUID)) + return; + + ep->iso_group = BT_ISO_QOS_GROUP_UNSET; + ep->iso_stream = BT_ISO_QOS_STREAM_UNSET; + + ep->broadcast = (strcmp(ep->uuid, BCAA_SERVICE_UUID) && + strcmp(ep->uuid, BAA_SERVICE_UUID)) ? false : true; + if (ep->broadcast) + return; + + if (!strcmp(ep->uuid, PAC_SINK_UUID)) { + ep->locations = EP_SNK_LOCATIONS; + ep->supported_context = EP_SUPPORTED_SNK_CTXT; + ep->context = EP_SNK_CTXT; + } else if (!strcmp(ep->uuid, PAC_SOURCE_UUID)) { + ep->locations = EP_SRC_LOCATIONS; + ep->supported_context = EP_SUPPORTED_SRC_CTXT; + ep->context = EP_SRC_CTXT; + } +} + static struct endpoint *endpoint_new(const struct capabilities *cap) { struct endpoint *ep; ep = new0(struct endpoint, 1); ep->uuid = g_strdup(cap->uuid); - ep->broadcast = (strcmp(cap->uuid, BCAA_SERVICE_UUID) && - strcmp(cap->uuid, BAA_SERVICE_UUID)) ? false : true; ep->codec = cap->codec_id; ep->path = g_strdup_printf("%s/ep%u", BLUEZ_MEDIA_ENDPOINT_PATH, g_list_length(local_endpoints)); @@ -3368,12 +3524,7 @@ static void register_endpoints(GDBusProxy *proxy) continue; ep = endpoint_new(cap); - ep->preset = find_presets(ep->uuid, ep->codec, ep->vid, - ep->cid); - ep->max_transports = UINT8_MAX; - ep->auto_accept = true; - ep->iso_group = BT_ISO_QOS_GROUP_UNSET; - ep->iso_stream = BT_ISO_QOS_STREAM_UNSET; + endpoint_init_defaults(ep); endpoint_register(ep); } } -- 2.41.0