From patchwork Wed May 15 20:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Raghavan X-Patchwork-Id: 797080 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 DD45315B0E3 for ; Wed, 15 May 2024 20:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715804182; cv=none; b=qZkdyCcuhULk4sCp1sZie4sc/t6Vvde+uxjvDFseKiz092bbY1PIvPm2+AV01smYs9hEtIdvsed4hpiH4pFiBEcSNzgpfv66CR9vQkmixP6JNza7W03iNT74zoZ60O48QaJj5IFp1zgYJz8s4RU9CpNIc5tkeXRassVwezpleZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715804182; c=relaxed/simple; bh=kPRqvrS1fQPfAsIcvSDx+b30AhKIEIdRO1PTvjks4Hc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=swiHFtIVOKGWB064Tc2GjNS7zOw6VuZhFRrjYGb5sVst9T0XWu9Kt5PHGsXsZ/GsEKFcC7ABFQgYTwfmH/BQX6LY2TY064kFTU+xnHF3ccZOyUtCs6wJ21GsB09QsyfCAyhr2gSxDd82WSFMTU9MvbIkC57O2co4gwgoaoOSRVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=asymptotic.io; spf=pass smtp.mailfrom=asymptotic.io; dkim=pass (2048-bit key) header.d=asymptotic.io header.i=@asymptotic.io header.b=sx+/Hzah; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=asymptotic.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asymptotic.io Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=asymptotic.io header.i=@asymptotic.io header.b="sx+/Hzah" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-574ea5184abso2565075a12.3 for ; Wed, 15 May 2024 13:16:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asymptotic.io; s=google; t=1715804178; x=1716408978; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bj3fQ6lonCcZcxh958qwO+m3waPBciwo6Q7d+/hYtRU=; b=sx+/HzahoEiQyLvhSd8NjqsJnpzCOKuRMOlINriFev6WCzEjmp4Xo36+LCDCFUB6Av 2GE9EZEFkUmEvEAhiVa+VBwGkUoqZ8yM3a2IX2ERnahSws+R3cSRxOX6k314Pu22r8Z4 yoewRmPCIXHpAt2sjBK1m9W6g82Qy3K8i8U4LwJpoiniUqaK1+hx6HxZDMK4fviFLz0s 0E64rmGbTQ7Po9s/bdcj+cY//aHpVbhSa6vuvf6KFMMi/rvYMER4y9N8mpK3R3wVkrlD KnzVvkwGjHFPCCl4YNB1nM2u/pfNbtX+JrBQTmYFmYN2V0dmvBCOlFcTcRNS8M1gFrTS abZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715804178; x=1716408978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bj3fQ6lonCcZcxh958qwO+m3waPBciwo6Q7d+/hYtRU=; b=KrLlrYXDLaqGpm4RpdhbpObHKnhJnk1wCTo4omp4iUcfkIoO9QQ+Ko2K78XrtNm4r5 48qnt1NxJRaMgSD63bQN7xByKvRW0N95bQR5neCz/I5LJjHVJooz6FdwZHXteFSwsN1N Vduwsu5Mwx3soB1HVeIMi28AKpy1GaiXmFyWXRL/uCCTdKnD5/03yvObr22RnwLKwRQl 676unHR10LIPifAvo5h2yHp2xcfmd0v++5U+HGb0m0cziuZzV6F8YplVOutR9N2GA44Y 4Sl2pw8WJCd2RhPbCP7u1PgmJO2lidLbzJRQk9qJz7vwfGitGCUWG0MXgfTOShkiRcuN 6eQw== X-Gm-Message-State: AOJu0YwDDJOO4+XdBeP93VUN8CD6rT6PRoQWLYI27IXD12BpBWXRZEzO 6Htk1dVRGBCoa/tw/3stKydm+ikau8C1ji8OX7Ee1S9mIwCVbXyhhSZfcTl37mjIgWiI3tts3hr r X-Google-Smtp-Source: AGHT+IFVJj9D7toovRek4aHSrGH/UaK99Mp/VtClU7GTfNCn3g1Gn/eMJ+6VfJkYPwt9L311lTk7SA== X-Received: by 2002:a50:cdd5:0:b0:572:f71:8030 with SMTP id 4fb4d7f45d1cf-5734d590400mr11741405a12.8.1715804177750; Wed, 15 May 2024 13:16:17 -0700 (PDT) Received: from andromeda.lan ([74.15.47.99]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5743065dd09sm7457142a12.64.2024.05.15.13.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 13:16:17 -0700 (PDT) From: Arun Raghavan To: linux-bluetooth@vger.kernel.org Cc: Arun Raghavan Subject: [PATCH BlueZ,v3 2/5] profiles/audio: Add an ASHA plugin Date: Wed, 15 May 2024 16:15:49 -0400 Message-ID: <20240515201552.1831618-3-arun@asymptotic.io> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240515201552.1831618-1-arun@asymptotic.io> References: <20240515201552.1831618-1-arun@asymptotic.io> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This exposes the ASHA profile implementation in the previous commit as an audio profile. The implementation registers a remote endpoint using a subset of the MediaEndpoint1 interface, without any mechanism for setting/selecting a configuration, as this is all static in the spec for now. Also exposed on connection is a MediaTransport1 object, which can be used to obtain an fd to stream to the device. --- Makefile.plugins | 5 + profiles/audio/asha.c | 336 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 341 insertions(+) create mode 100644 profiles/audio/asha.c diff --git a/Makefile.plugins b/Makefile.plugins index 4aa2c9c92..e196e1d2e 100644 --- a/Makefile.plugins +++ b/Makefile.plugins @@ -147,3 +147,8 @@ if CSIP builtin_modules += csip builtin_sources += profiles/audio/csip.c endif + +if ASHA +builtin_modules += asha +builtin_sources += profiles/audio/asha.c +endif diff --git a/profiles/audio/asha.c b/profiles/audio/asha.c new file mode 100644 index 000000000..40871d707 --- /dev/null +++ b/profiles/audio/asha.c @@ -0,0 +1,336 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2024 Asymptotic Inc. + * + * Author: Arun Raghavan + * + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define _GNU_SOURCE + +#include +#include + +#include +#include + +#include "gdbus/gdbus.h" +#include "lib/bluetooth.h" +#include "lib/uuid.h" + +#include "src/dbus-common.h" +#include "src/adapter.h" +#include "src/device.h" +#include "src/log.h" +#include "src/plugin.h" +#include "src/profile.h" +#include "src/service.h" +#include "src/shared/asha.h" +#include "src/shared/util.h" + +#include "profiles/audio/media.h" +#include "profiles/audio/transport.h" + +#define MEDIA_ENDPOINT_INTERFACE "org.bluez.MediaEndpoint1" + +static char *make_endpoint_path(struct bt_asha_device *asha) +{ + char *path; + int err; + + err = asprintf(&path, "%s/asha", device_get_path(asha->device)); + if (err < 0) { + error("Could not allocate path for remote %s", + device_get_path(asha->device)); + return NULL; + } + + return path; + +} + +static gboolean get_uuid(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + const char *uuid; + + uuid = ASHA_PROFILE_UUID; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid); + + return TRUE; +} + +static gboolean get_side(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct bt_asha_device *asha = data; + const char *side = asha->right_side ? "right" : "left"; + + /* Use a string in case we want to support more types in the future */ + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &side); + + return TRUE; +} + + +static gboolean get_binaural(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct bt_asha_device *asha = data; + dbus_bool_t binaural = asha->binaural; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &binaural); + + return TRUE; +} + +static gboolean get_hisyncid(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct bt_asha_device *asha = data; + DBusMessageIter array; + uint8_t *hisyncid = asha->hisyncid; + + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, + DBUS_TYPE_BYTE_AS_STRING, &array); + + dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE, + &hisyncid, sizeof(asha->hisyncid)); + + dbus_message_iter_close_container(iter, &array); + + return TRUE; +} + +static gboolean get_codecs(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct bt_asha_device *asha = data; + dbus_uint16_t codecs = asha->codec_ids; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &codecs); + + return TRUE; +} + +static gboolean get_device(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct bt_asha_device *asha = data; + const char *path; + + path = device_get_path(asha->device); + + dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); + + return TRUE; +} + +static gboolean get_transport(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct bt_asha_device *asha = data; + const char *path; + + path = media_transport_get_path(asha->transport); + + dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path); + + return TRUE; +} + +static int asha_source_device_probe(struct btd_service *service) +{ + struct bt_asha_device *asha; + struct btd_device *device = btd_service_get_device(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("Probing ASHA device %s", addr); + + asha = bt_asha_device_new(); + asha->device = device; + + btd_service_set_user_data(service, asha); + + return 0; +} + +static void asha_source_device_remove(struct btd_service *service) +{ + struct bt_asha_device *asha; + struct btd_device *device = btd_service_get_device(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("Removing ASHA device %s", addr); + + asha = btd_service_get_user_data(service); + if (!asha) { + /* Can this actually happen? */ + DBG("Not handlihng ASHA profile"); + return; + } + + bt_asha_device_free(asha); +} + +static const GDBusMethodTable asha_ep_methods[] = { + { }, +}; + +static const GDBusPropertyTable asha_ep_properties[] = { + { "UUID", "s", get_uuid, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL }, + { "Side", "s", get_side, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL }, + { "Binaural", "b", get_binaural, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL }, + { "HiSyncId", "ay", get_hisyncid, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL }, + { "Codecs", "q", get_codecs, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL }, + { "Device", "o", get_device, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL }, + { "Transport", "o", get_transport, NULL, NULL, + G_DBUS_PROPERTY_FLAG_EXPERIMENTAL }, + { } +}; + +static void asha_source_endpoint_register(struct bt_asha_device *asha) +{ + char *path; + const struct media_endpoint *asha_ep; + + path = make_endpoint_path(asha); + if (!path) + goto error; + + if (g_dbus_register_interface(btd_get_dbus_connection(), + path, MEDIA_ENDPOINT_INTERFACE, + asha_ep_methods, NULL, + asha_ep_properties, + asha, NULL) == FALSE) { + error("Could not register remote ep %s", path); + goto error; + } + + asha_ep = media_endpoint_get_asha(); + asha->transport = media_transport_create(asha->device, path, NULL, 0, + (void *) asha_ep, asha); + +error: + if (path) + free(path); +} + +static void asha_source_endpoint_unregister(struct bt_asha_device *asha) +{ + char *path; + + path = make_endpoint_path(asha); + if (!path) + goto error; + + g_dbus_unregister_interface(btd_get_dbus_connection(), + path, MEDIA_ENDPOINT_INTERFACE); + + if (asha->transport) { + media_transport_destroy(asha->transport); + asha->transport = NULL; + } + +error: + if (path) + free(path); +} + +static int asha_source_accept(struct btd_service *service) +{ + struct btd_device *device = btd_service_get_device(service); + struct bt_asha_device *asha = btd_service_get_user_data(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("Accepting ASHA connection on %s", addr); + + if (!asha) { + /* Can this actually happen? */ + DBG("Not handling ASHA profile"); + return -1; + } + + if (!bt_asha_device_probe(asha)) + return -1; + + asha_source_endpoint_register(asha); + + btd_service_connecting_complete(service, 0); + + return 0; +} + +static int asha_source_disconnect(struct btd_service *service) +{ + struct btd_device *device = btd_service_get_device(service); + struct bt_asha_device *asha = btd_service_get_user_data(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("Disconnecting ASHA on %s", addr); + + if (!asha) { + /* Can this actually happen? */ + DBG("Not handlihng ASHA profile"); + return -1; + } + + asha_source_endpoint_unregister(asha); + bt_asha_device_reset(asha); + + btd_service_disconnecting_complete(service, 0); + + return 0; +} + +static struct btd_profile asha_source_profile = { + .name = "asha-source", + .priority = BTD_PROFILE_PRIORITY_MEDIUM, + .remote_uuid = ASHA_PROFILE_UUID, + .experimental = true, + + .device_probe = asha_source_device_probe, + .device_remove = asha_source_device_remove, + + .auto_connect = true, + .accept = asha_source_accept, + .disconnect = asha_source_disconnect, +}; + +static int asha_init(void) +{ + int err; + + err = btd_profile_register(&asha_source_profile); + if (err) + return err; + + return 0; +} + +static void asha_exit(void) +{ + btd_profile_unregister(&asha_source_profile); +} + +BLUETOOTH_PLUGIN_DEFINE(asha, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, + asha_init, asha_exit)