2023-08-08 16:46:25

by Claudia Draghicescu

[permalink] [raw]
Subject: [PATCH BlueZ v5 0/7] Add support for BAP broadcast sink

This series of patches adds support for BAP broadcast sink.
It consists in registering a broadcastsink endpoint using the
Basic Audio Announcement Service UUID,
discovering of broadcast advertisers that announce the
Broadcast Audio Announcement Service, synchronizes to the Periodic
advertisements of the source and synchronizes to the BIG advertised
in the PA train.
To retrieve the BASE info advertised in the PA train, the patch
Bluetooth: ISO: Add support for periodic adv reports processing
was used.

This feature was tested using bluetoothctl with the following commands:

[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[bluetooth]# scan on
[NEW] Endpoint /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
[bluetooth]# endpoint.config
/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
/local/endpoint/ep0 16_2_1

Claudia Draghicescu (7):
client/player: Add broadcast sink endpoint
btio: Add support for getsockopt(BT_ISO_BASE)
adapter: Do not filter out broadcast advertiser
profile: Add probe_on_discover flag
bap: Add support for BAP broadcast sink
media: Add broadcast sink media endpoint
transport: Update transport properties for a broadcast stream

btio/btio.c | 13 +-
client/player.c | 61 ++++++-
profiles/audio/bap.c | 334 +++++++++++++++++++++++++++++++++----
profiles/audio/media.c | 82 +++++++--
profiles/audio/media.h | 3 +-
profiles/audio/transport.c | 245 ++++++++++++++++++++++++++-
src/adapter.c | 10 ++
src/device.c | 22 ++-
src/profile.h | 5 +
src/shared/bap.c | 139 ++++++++++++---
src/shared/bap.h | 6 +-
11 files changed, 831 insertions(+), 89 deletions(-)


base-commit: 59569c1f947d648f1e0b9234dad3707f6c34739b
--
2.34.1



2023-08-08 16:46:35

by Claudia Draghicescu

[permalink] [raw]
Subject: [PATCH BlueZ v5 1/7] client/player: Add broadcast sink endpoint

Added support for broadcast sink registration using the 0x1851 UUID.
Added support for remote endpoint creation when a broadcast source
is discovered.
Added support for creating a local endpoint when the broadcast sink
endpoint was registered from an external application (Pipewire).
To test this feature use the following commands:

[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[bluetooth]# scan on
[NEW] Endpoint /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
[bluetooth]# endpoint.config
/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
/local/endpoint/ep0 16_2_1

---
client/player.c | 61 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 53 insertions(+), 8 deletions(-)

diff --git a/client/player.c b/client/player.c
index 9bc5f2a36..3611a8dfe 100644
--- a/client/player.c
+++ b/client/player.c
@@ -1183,6 +1183,17 @@ static const struct capabilities {
CODEC_CAPABILITIES(BCAA_SERVICE_UUID, LC3_ID,
LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY,
3u, 30, 240)),
+
+ /* Broadcast LC3 Sink:
+ *
+ * Frequencies: 8Khz 11Khz 16Khz 22Khz 24Khz 32Khz 44.1Khz 48Khz
+ * Duration: 7.5 ms 10 ms
+ * Channel count: 3
+ * Frame length: 30-240
+ */
+ CODEC_CAPABILITIES(BAA_SERVICE_UUID, LC3_ID,
+ LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY,
+ 3u, 30, 240)),
};

struct codec_qos {
@@ -1465,6 +1476,7 @@ static struct preset {
PRESET(PAC_SINK_UUID, LC3_ID, lc3_presets, 3),
PRESET(PAC_SOURCE_UUID, LC3_ID, lc3_presets, 3),
PRESET(BCAA_SERVICE_UUID, LC3_ID, lc3_presets, 3),
+ PRESET(BAA_SERVICE_UUID, LC3_ID, lc3_presets, 3),
};

static void parse_vendor_codec(const char *codec, uint16_t *vid, uint16_t *cid)
@@ -2285,6 +2297,9 @@ static void register_endpoint_setup(DBusMessageIter *iter, void *user_data)
bt_shell_hexdump(ep->meta->iov_base, ep->meta->iov_len);
}

+ g_dbus_dict_append_entry(&dict, "Broadcast", DBUS_TYPE_BOOLEAN,
+ &ep->broadcast);
+
dbus_message_iter_close_container(iter, &dict);
}

@@ -2455,7 +2470,8 @@ static void endpoint_auto_accept(const char *input, void *user_data)
{
struct endpoint *ep = user_data;

- if (!strcmp(ep->uuid, BCAA_SERVICE_UUID)) {
+ if (!strcmp(ep->uuid, BCAA_SERVICE_UUID) ||
+ !strcmp(ep->uuid, BAA_SERVICE_UUID)) {
ep->broadcast = true;
} else {
ep->broadcast = false;
@@ -2728,13 +2744,20 @@ static void endpoint_config(const char *input, void *user_data)
endpoint_set_config(cfg);
}

+static struct endpoint *endpoint_new(const struct capabilities *cap);
+
static void cmd_config_endpoint(int argc, char *argv[])
{
struct endpoint_config *cfg;
const struct codec_preset *preset;
+ const struct capabilities *cap;
+ char *uuid;
+ uint8_t codec_id;
+ bool broadcast = false;

cfg = new0(struct endpoint_config, 1);

+ /* Search for the remote endpoint name on DBUS */
cfg->proxy = g_dbus_proxy_lookup(endpoints, NULL, argv[1],
BLUEZ_MEDIA_ENDPOINT_INTERFACE);
if (!cfg->proxy) {
@@ -2742,16 +2765,36 @@ static void cmd_config_endpoint(int argc, char *argv[])
goto fail;
}

+ /* Search for the local endpoint */
cfg->ep = endpoint_find(argv[2]);
if (!cfg->ep) {
- bt_shell_printf("Local Endpoint %s not found\n", argv[2]);
- goto fail;
+
+ /* When the local endpoint was not found either we received
+ * UUID, or the provided local endpoint is not available
+ */
+ uuid = argv[2];
+ codec_id = strtol(argv[3], NULL, 0);
+ cap = find_capabilities(uuid, codec_id);
+ if (cap) {
+ broadcast = true;
+ cfg->ep = endpoint_new(cap);
+ cfg->ep->preset = find_presets_name(uuid, argv[3]);
+ if (!cfg->ep->preset)
+ bt_shell_printf("Preset not found\n");
+ } else {
+ bt_shell_printf("Local Endpoint %s,"
+ "or capabilities not found\n", uuid);
+ goto fail;
+ }
}

- if (argc > 3) {
- preset = preset_find_name(cfg->ep->preset, argv[3]);
+ if (((broadcast == false) && (argc > 3)) ||
+ ((broadcast == true) && (argc > 4))) {
+ char *preset_name = (broadcast == false)?argv[3]:argv[4];
+
+ preset = preset_find_name(cfg->ep->preset, preset_name);
if (!preset) {
- bt_shell_printf("Preset %s not found\n", argv[3]);
+ bt_shell_printf("Preset %s not found\n", preset_name);
goto fail;
}

@@ -3172,7 +3215,8 @@ static const struct bt_shell_menu endpoint_menu = {
{ "unregister", "<UUID/object>", cmd_unregister_endpoint,
"Register Endpoint",
local_endpoint_generator },
- { "config", "<endpoint> <local endpoint> [preset]",
+ { "config",
+ "<endpoint> [local endpoint/UUID] [preset/codec id] [preset]",
cmd_config_endpoint,
"Configure Endpoint",
endpoint_generator },
@@ -3189,7 +3233,8 @@ static struct endpoint *endpoint_new(const struct capabilities *cap)

ep = new0(struct endpoint, 1);
ep->uuid = g_strdup(cap->uuid);
- ep->broadcast = strcmp(cap->uuid, BCAA_SERVICE_UUID) ? false : true;
+ 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));
--
2.34.1


2023-08-08 16:46:42

by Claudia Draghicescu

[permalink] [raw]
Subject: [PATCH BlueZ v5 2/7] btio: Add support for getsockopt(BT_ISO_BASE)

This adds the posibility for a broadcast sink to retrieve the
BASE information received from a source afeter a PA synchronization,
using the getsockopt(BT_ISO_BASE) function.
This needs the patch from bluetooth-next:
Bluetooth: ISO: Add support for periodic adv reports processing

---
btio/btio.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/btio/btio.c b/btio/btio.c
index 179be6289..8178250d2 100644
--- a/btio/btio.c
+++ b/btio/btio.c
@@ -1638,6 +1638,7 @@ static gboolean iso_get(int sock, GError **err, BtIOOption opt1, va_list args)
BtIOOption opt = opt1;
struct sockaddr_iso src, dst;
struct bt_iso_qos qos;
+ struct bt_iso_base base;
socklen_t len;
uint32_t phy;

@@ -1648,6 +1649,11 @@ static gboolean iso_get(int sock, GError **err, BtIOOption opt1, va_list args)
return FALSE;
}

+ if (getsockopt(sock, SOL_BLUETOOTH, BT_ISO_BASE, &base, &len) < 0) {
+ ERROR_FAILED(err, "getsockopt(BT_ISO_BASE)", errno);
+ return FALSE;
+ }
+
if (!get_src(sock, &src, sizeof(src), err))
return FALSE;

@@ -1694,6 +1700,8 @@ static gboolean iso_get(int sock, GError **err, BtIOOption opt1, va_list args)
*(va_arg(args, struct bt_iso_qos *)) = qos;
break;
case BT_IO_OPT_BASE:
+ *(va_arg(args, struct bt_iso_base *)) = base;
+ break;
case BT_IO_OPT_HANDLE:
case BT_IO_OPT_CLASS:
case BT_IO_OPT_DEFER_TIMEOUT:
@@ -1896,8 +1904,9 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts,
goto failed;
if (!iso_set_qos(sock, &opts->qos, err))
goto failed;
- if (!iso_set_base(sock, &opts->base, err))
- goto failed;
+ if (opts->base.base_len)
+ if (!iso_set_base(sock, &opts->base, err))
+ goto failed;
break;
case BT_IO_INVALID:
default:
--
2.34.1


2023-08-08 17:00:06

by Claudia Draghicescu

[permalink] [raw]
Subject: [PATCH BlueZ v5 5/7] bap: Add support for BAP broadcast sink

This adds support for BAP broadcast sink, creates a remote endpoint when a
broadcast source is discovered and synchronizes with the source upon
endpoint configuration.
This feature was tested using bluetoothctl with the following commands:

[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
[bluetooth]# scan on
[NEW] Endpoint /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
[bluetooth]# endpoint.config
/org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
/local/endpoint/ep0 16_2_1
---
profiles/audio/bap.c | 334 ++++++++++++++++++++++++++++++++++++++-----
src/shared/bap.c | 139 +++++++++++++++---
src/shared/bap.h | 6 +-
3 files changed, 424 insertions(+), 55 deletions(-)

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 8cbb238ef..a0ac642f3 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -34,6 +34,7 @@
#include "lib/hci.h"
#include "lib/sdp.h"
#include "lib/uuid.h"
+#include "lib/iso.h"

#include "src/btd.h"
#include "src/dbus-common.h"
@@ -57,7 +58,9 @@

#define ISO_SOCKET_UUID "6fbaf188-05e0-496a-9885-d6ddfdb4e03e"
#define PACS_UUID_STR "00001850-0000-1000-8000-00805f9b34fb"
+#define BCAAS_UUID_STR "00001852-0000-1000-8000-00805f9b34fb"
#define MEDIA_ENDPOINT_INTERFACE "org.bluez.MediaEndpoint1"
+#define MEDIA_INTERFACE "org.bluez.Media1"

struct bap_ep {
char *path;
@@ -186,8 +189,11 @@ static gboolean get_uuid(const GDBusPropertyTable *property,
uuid = PAC_SINK_UUID;
else if (queue_find(ep->data->srcs, NULL, ep))
uuid = PAC_SOURCE_UUID;
- else
+ else if ((queue_find(ep->data->bcast, NULL, ep)
+ && (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK)))
uuid = BAA_SERVICE_UUID;
+ else
+ uuid = BCAA_SERVICE_UUID;

dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid);

@@ -341,15 +347,18 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps,
} else if (!strcasecmp(key, "PHY")) {
const char *str;

- if (var != DBUS_TYPE_STRING)
- goto fail;
-
- dbus_message_iter_get_basic(&value, &str);
-
- if (!strcasecmp(str, "1M"))
- io_qos.phy = 0x01;
- else if (!strcasecmp(str, "2M"))
- io_qos.phy = 0x02;
+ if (var == DBUS_TYPE_STRING) {
+ dbus_message_iter_get_basic(&value, &str);
+
+ if (!strcasecmp(str, "1M"))
+ io_qos.phy = 0x01;
+ else if (!strcasecmp(str, "2M"))
+ io_qos.phy = 0x02;
+ else
+ goto fail;
+ } else if (var == DBUS_TYPE_BYTE)
+ dbus_message_iter_get_basic(&value,
+ &io_qos.phy);
else
goto fail;
} else if (!strcasecmp(key, "SDU")) {
@@ -556,7 +565,7 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
}

if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SOURCE) {
- /* Mark CIG and CIS to be auto assigned */
+ /* Mark BIG and BIS to be auto assigned */
ep->qos.bcast.big = BT_ISO_QOS_BIG_UNSET;
ep->qos.bcast.bis = BT_ISO_QOS_BIS_UNSET;
} else {
@@ -577,8 +586,12 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
ep->stream = bt_bap_stream_new(ep->data->bap, ep->lpac,
ep->rpac, &ep->qos, ep->caps);

- ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps,
- config_cb, ep);
+ if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK)
+ ep->id = bt_bap_stream_config(ep->stream, &ep->qos, NULL,
+ config_cb, ep);
+ else
+ ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps,
+ config_cb, ep);
if (!ep->id) {
DBG("Unable to config stream");
free(ep->caps);
@@ -597,13 +610,120 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
break;
case BT_BAP_STREAM_TYPE_BCAST:
/* No message sent over the air for broadcast */
- ep->id = 0;
+ if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK)
+ ep->msg = dbus_message_ref(msg);
+ else
+ ep->id = 0;
+
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}

return NULL;
}

+static void update_bcast_qos(struct bt_iso_qos *qos,
+ struct bt_bap_qos *bap_qos)
+{
+ bap_qos->bcast.big = qos->bcast.big;
+ bap_qos->bcast.bis = qos->bcast.bis;
+ bap_qos->bcast.sync_interval = qos->bcast.sync_interval;
+ bap_qos->bcast.packing = qos->bcast.packing;
+ bap_qos->bcast.framing = qos->bcast.framing;
+ bap_qos->bcast.encryption = qos->bcast.encryption;
+ bap_qos->bcast.options = qos->bcast.options;
+ bap_qos->bcast.skip = qos->bcast.skip;
+ bap_qos->bcast.sync_timeout = qos->bcast.sync_timeout;
+ bap_qos->bcast.sync_cte_type = qos->bcast.sync_cte_type;
+ bap_qos->bcast.mse = qos->bcast.mse;
+ bap_qos->bcast.timeout = qos->bcast.timeout;
+ bap_qos->bcast.io_qos.interval = qos->bcast.in.interval;
+ bap_qos->bcast.io_qos.latency = qos->bcast.in.latency;
+ bap_qos->bcast.io_qos.phy = qos->bcast.in.phy;
+ bap_qos->bcast.io_qos.sdu = qos->bcast.in.sdu;
+ bap_qos->bcast.io_qos.rtn = qos->bcast.in.rtn;
+
+ bap_qos->bcast.bcode = new0(struct iovec, 1);
+ util_iov_memcpy(bap_qos->bcast.bcode, qos->bcast.bcode,
+ sizeof(qos->bcast.bcode));
+}
+
+static bool match_ep_type(const void *data, const void *user_data)
+{
+ const struct bap_ep *ep = data;
+
+ return (bt_bap_pac_get_type(ep->lpac) == PTR_TO_INT(user_data));
+}
+
+static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data)
+{
+ struct bap_data *data = user_data;
+ struct bt_iso_qos qos;
+ struct bt_iso_base base;
+ char address[18];
+ struct bap_ep *ep;
+ int fd;
+ struct iovec *base_io;
+
+ bt_io_get(io, &err,
+ BT_IO_OPT_DEST, address,
+ BT_IO_OPT_QOS, &qos,
+ BT_IO_OPT_BASE, &base,
+ BT_IO_OPT_INVALID);
+ if (err) {
+ error("%s", err->message);
+ g_error_free(err);
+ goto drop;
+ }
+
+ g_io_channel_ref(io);
+ btd_service_connecting_complete(data->service, 0);
+ DBG("BCAST ISO: sync with %s (BIG 0x%02x BIS 0x%02x)",
+ address, qos.bcast.big, qos.bcast.bis);
+
+ ep = queue_find(data->bcast, match_ep_type,
+ INT_TO_PTR(BT_BAP_BCAST_SINK));
+ if (!ep) {
+ DBG("ep not found");
+ return;
+ }
+
+ update_bcast_qos(&qos, &ep->qos);
+
+ base_io = new0(struct iovec, 1);
+ util_iov_memcpy(base_io, base.base, base.base_len);
+
+ if (ep->stream == NULL)
+ DBG("stream is null");
+ ep->id = bt_bap_stream_config(ep->stream, &ep->qos,
+ base_io, NULL, NULL);
+ data->listen_io = io;
+
+ bt_bap_stream_set_user_data(ep->stream, ep->path);
+
+ fd = g_io_channel_unix_get_fd(io);
+
+ if (bt_bap_stream_set_io(ep->stream, fd)) {
+ bt_bap_stream_enable(ep->stream, true, NULL, NULL, NULL);
+ g_io_channel_set_close_on_unref(io, FALSE);
+ return;
+ }
+
+
+ return;
+
+drop:
+ g_io_channel_shutdown(io, TRUE, NULL);
+
+}
+
+static bool match_data_bap_data(const void *data, const void *match_data)
+{
+ const struct bap_data *bdata = data;
+ const struct btd_adapter *adapter = match_data;
+
+ return bdata->user_data == adapter;
+}
+
static const GDBusMethodTable ep_methods[] = {
{ GDBUS_EXPERIMENTAL_ASYNC_METHOD("SetConfiguration",
GDBUS_ARGS({ "endpoint", "o" },
@@ -649,15 +769,23 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data,
struct bt_bap_pac *lpac,
struct bt_bap_pac *rpac)
{
- struct btd_adapter *adapter = data->user_data;
+ struct btd_adapter *adapter = data->adapter;
+ struct btd_device *device = data->device;
struct bap_ep *ep;
struct queue *queue;
- int i, err;
+ int i, err = 0;
const char *suffix;
struct match_ep match = { lpac, rpac };

+ if (!adapter)
+ DBG("adapter is null");
+
+ if (!device)
+ DBG("device is null");
+
switch (bt_bap_pac_get_type(rpac)) {
case BT_BAP_BCAST_SOURCE:
+ case BT_BAP_BCAST_SINK:
queue = data->bcast;
i = queue_length(data->bcast);
suffix = "bcast";
@@ -675,8 +803,24 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data,
ep->lpac = lpac;
ep->rpac = rpac;

- err = asprintf(&ep->path, "%s/pac_%s%d", adapter_get_path(adapter),
- suffix, i);
+ if (device)
+ ep->data->device = device;
+
+ switch (bt_bap_pac_get_type(rpac)) {
+ case BT_BAP_BCAST_SINK:
+ DBG("sink");
+ err = asprintf(&ep->path, "%s/pac_%s%d",
+ adapter_get_path(adapter), suffix, i);
+ DBG("sink path %s", ep->path);
+ break;
+ case BT_BAP_BCAST_SOURCE:
+ DBG("source");
+ err = asprintf(&ep->path, "%s/pac_%s%d",
+ device_get_path(device), suffix, i);
+ DBG("source path %s", ep->path);
+ break;
+ }
+
if (err < 0) {
error("Could not allocate path for remote pac %s/pac%d",
adapter_get_path(adapter), i);
@@ -685,14 +829,13 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data,
}

if (g_dbus_register_interface(btd_get_dbus_connection(),
- ep->path, MEDIA_ENDPOINT_INTERFACE,
- ep_methods, NULL, ep_properties,
- ep, ep_free) == FALSE) {
+ ep->path, MEDIA_ENDPOINT_INTERFACE,
+ ep_methods, NULL, ep_properties,
+ ep, ep_free) == FALSE) {
error("Could not register remote ep %s", ep->path);
ep_free(ep);
return NULL;
}
-
bt_bap_pac_set_user_data(rpac, ep->path);

DBG("ep %p lpac %p rpac %p path %s", ep, ep->lpac, ep->rpac, ep->path);
@@ -824,6 +967,7 @@ done:

queue_foreach(ep->data->srcs, bap_config, NULL);
queue_foreach(ep->data->snks, bap_config, NULL);
+ queue_foreach(ep->data->bcast, bap_config, NULL);
}

static bool pac_found(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac,
@@ -1310,6 +1454,46 @@ static void bap_listen_io(struct bap_data *data, struct bt_bap_stream *stream,
data->listen_io = io;
}

+static void bap_listen_io_broadcast(struct bap_data *data, struct bap_ep *ep,
+ struct bt_bap_stream *stream, struct bt_iso_qos *qos)
+{
+ GIOChannel *io;
+ GError *err = NULL;
+ struct sockaddr_iso_bc iso_bc_addr;
+
+ iso_bc_addr.bc_bdaddr_type = btd_device_get_bdaddr_type(data->device);
+ memcpy(&iso_bc_addr.bc_bdaddr, device_get_address(data->device),
+ sizeof(bdaddr_t));
+ iso_bc_addr.bc_bis[0] = 1;
+ iso_bc_addr.bc_num_bis = 1;
+
+ DBG("stream %p", stream);
+
+ /* If IO already set skip creating it again */
+ if (bt_bap_stream_get_io(stream) || data->listen_io)
+ return;
+
+ io = bt_io_listen(iso_bcast_confirm_cb, NULL, ep->data, NULL, &err,
+ BT_IO_OPT_SOURCE_BDADDR,
+ btd_adapter_get_address(ep->data->adapter),
+ BT_IO_OPT_DEST_BDADDR,
+ device_get_address(data->device),
+ BT_IO_OPT_DEST_TYPE,
+ btd_device_get_bdaddr_type(data->device),
+ BT_IO_OPT_MODE, BT_IO_MODE_ISO,
+ BT_IO_OPT_QOS, &qos->bcast,
+ BT_IO_OPT_ISO_BC_NUM_BIS, iso_bc_addr.bc_num_bis,
+ BT_IO_OPT_ISO_BC_BIS, iso_bc_addr.bc_bis,
+ BT_IO_OPT_INVALID);
+ if (!io) {
+ error("%s", err->message);
+ g_error_free(err);
+ } else
+ DBG("io created");
+
+ ep->data->listen_io = io;
+
+}
static void bap_create_ucast_io(struct bap_data *data, struct bap_ep *ep,
struct bt_bap_stream *stream, int defer)
{
@@ -1364,10 +1548,10 @@ static void bap_create_bcast_io(struct bap_data *data, struct bap_ep *ep,
memcpy(&iso_qos.bcast.out, &ep->qos.bcast.io_qos,
sizeof(struct bt_iso_io_qos));
done:
- if (ep)
+ if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SOURCE)
bap_connect_io_broadcast(data, ep, stream, &iso_qos);
else
- bap_listen_io(data, stream, &iso_qos);
+ bap_listen_io_broadcast(data, ep, stream, &iso_qos);
}

static void bap_create_io(struct bap_data *data, struct bap_ep *ep,
@@ -1417,6 +1601,11 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
break;
case BT_BAP_STREAM_STATE_CONFIG:
if (ep && !ep->id) {
+ if
+ (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK) {
+ bap_create_bcast_io(data, ep, stream, true);
+ return;
+ }
bap_create_io(data, ep, stream, true);
if (!ep->io) {
error("Unable to create io");
@@ -1424,7 +1613,6 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
return;
}

-
if (bt_bap_stream_get_type(stream) ==
BT_BAP_STREAM_TYPE_UCAST) {
/* Wait QoS response to respond */
@@ -1480,6 +1668,10 @@ static void pac_added_broadcast(struct bt_bap_pac *pac, void *user_data)

bt_bap_foreach_pac(data->bap, BT_BAP_BCAST_SOURCE,
pac_found_bcast, data);
+ } else if (bt_bap_pac_get_type(pac) == BT_BAP_BCAST_SINK) {
+ DBG("sink pac %p", pac);
+ bt_bap_foreach_pac(data->bap, BT_BAP_BCAST_SINK,
+ pac_found_bcast, data);
}
}

@@ -1596,14 +1788,6 @@ static bool match_data(const void *data, const void *match_data)
return bdata->bap == bap;
}

-static bool match_data_bap_data(const void *data, const void *match_data)
-{
- const struct bap_data *bdata = data;
- const struct btd_adapter *adapter = match_data;
-
- return bdata->user_data == adapter;
-}
-
static bool io_get_qos(GIOChannel *io, struct bt_iso_qos *qos)
{
GError *err = NULL;
@@ -1733,6 +1917,73 @@ static void bap_detached(struct bt_bap *bap, void *user_data)
bap_data_remove(data);
}

+static int bap_bcast_probe(struct btd_service *service)
+{
+ struct btd_device *device = btd_service_get_device(service);
+ struct btd_adapter *adapter = device_get_adapter(device);
+ struct btd_gatt_database *database = btd_adapter_get_database(adapter);
+ struct bap_data *data = btd_service_get_user_data(service);
+ char addr[18];
+
+ ba2str(device_get_address(device), addr);
+ DBG("Device %s is a BAP broadcast source", addr);
+
+ if (!btd_adapter_has_exp_feature(adapter, EXP_FEAT_ISO_SOCKET)) {
+ error("BAP requires ISO Socket which is not enabled");
+ return -ENOTSUP;
+ }
+
+ /* Ignore, if we were probed for this device already */
+ if (data) {
+ error("Profile probed twice for the same device!");
+ return -EINVAL;
+ }
+
+ data = bap_data_new(device);
+ data->service = service;
+ data->adapter = adapter;
+ data->device = device;
+
+ data->bap = bt_bap_new(btd_gatt_database_get_db(database),
+ btd_gatt_database_get_db(database));
+ if (!data->bap) {
+ error("Unable to create BAP instance");
+ free(data);
+ return -EINVAL;
+ }
+
+ bap_data_add(data);
+
+ data->ready_id = bt_bap_ready_register(data->bap, bap_ready, service,
+ NULL);
+ data->state_id = bt_bap_state_register(data->bap, bap_state,
+ bap_connecting, data, NULL);
+ data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast,
+ pac_removed_broadcast, data, NULL);
+
+ bt_bap_set_user_data(data->bap, service);
+ bt_bap_new_bcast_source(data->bap, device_get_path(device));
+ return 0;
+}
+
+static void bap_bcast_remove(struct btd_service *service)
+{
+ struct btd_device *device = btd_service_get_device(service);
+ struct bap_data *data;
+ char addr[18];
+
+ ba2str(device_get_address(device), addr);
+ DBG("%s", addr);
+
+ data = btd_service_get_user_data(service);
+ if (!data) {
+ error("BAP service not handled by profile");
+ return;
+ }
+
+ bap_data_remove(data);
+}
+
static int bap_probe(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
@@ -1854,7 +2105,7 @@ static int bap_adapter_probe(struct btd_profile *p,

bap_data_add(data);

- if (!bt_bap_attach_broadcast(data->bap)) {
+ if (!bt_bap_attach_broadcast(data->bap, BT_BAP_BCAST_SOURCE)) {
error("BAP unable to attach");
return -EINVAL;
}
@@ -1901,6 +2152,17 @@ static struct btd_profile bap_profile = {
.experimental = true,
};

+static struct btd_profile bap_bcast_profile = {
+ .name = "bapbcast",
+ .priority = BTD_PROFILE_PRIORITY_MEDIUM,
+ .remote_uuid = BCAAS_UUID_STR,
+ .device_probe = bap_bcast_probe,
+ .device_remove = bap_bcast_remove,
+ .auto_connect = false,
+ .experimental = true,
+ .probe_on_discover = true,
+};
+
static unsigned int bap_id = 0;

static int bap_init(void)
@@ -1911,6 +2173,10 @@ static int bap_init(void)
if (err)
return err;

+ err = btd_profile_register(&bap_bcast_profile);
+ if (err)
+ return err;
+
bap_id = bt_bap_register(bap_attached, bap_detached, NULL);

return 0;
diff --git a/src/shared/bap.c b/src/shared/bap.c
index 72ce67c08..ebeb713d5 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -633,14 +633,18 @@ static struct bt_bap_endpoint *bap_endpoint_new(struct bt_bap_db *bdb,
return ep;
}

-static struct bt_bap_endpoint *bap_endpoint_new_broacast(struct bt_bap_db *bdb)
+static struct bt_bap_endpoint *bap_endpoint_new_broadcast(struct bt_bap_db *bdb,
+ uint8_t type)
{
struct bt_bap_endpoint *ep;

ep = new0(struct bt_bap_endpoint, 1);
ep->bdb = bdb;
ep->attr = NULL;
- ep->dir = BT_BAP_BCAST_SOURCE;
+ if (type == BT_BAP_BCAST_SINK)
+ ep->dir = BT_BAP_BCAST_SOURCE;
+ else
+ ep->dir = BT_BAP_BCAST_SINK;

return ep;
}
@@ -667,22 +671,27 @@ static struct bt_bap_endpoint *bap_get_endpoint(struct queue *endpoints,
return ep;
}

+static bool match_ep_type(const void *data, const void *match_data)
+{
+ const struct bt_bap_endpoint *ep = data;
+ const uint8_t type = PTR_TO_INT(match_data);
+
+ return (ep->dir == type);
+}
+
static struct bt_bap_endpoint *bap_get_endpoint_bcast(struct queue *endpoints,
- struct bt_bap_db *db)
+ struct bt_bap_db *db, uint8_t type)
{
struct bt_bap_endpoint *ep;

if (!db)
return NULL;
- /*
- * We have support for only one stream so we will have
- * only one endpoint.
- * TO DO add support for more then one stream
- */
- if (queue_length(endpoints) > 0)
- return queue_peek_head(endpoints);

- ep = bap_endpoint_new_broacast(db);
+ ep = queue_find(endpoints, match_ep_type, INT_TO_PTR(type));
+ if (ep)
+ return ep;
+
+ ep = bap_endpoint_new_broadcast(db, type);
if (!ep)
return NULL;

@@ -1317,6 +1326,8 @@ static void stream_set_state_broadcast(struct bt_bap_stream *stream,
struct bt_bap *bap = stream->bap;
const struct queue_entry *entry;

+ if (ep->old_state == state)
+ return;
ep->old_state = ep->state;
ep->state = state;

@@ -1348,6 +1359,9 @@ static void stream_set_state(struct bt_bap_stream *stream, uint8_t state)
ep->old_state = ep->state;
ep->state = state;

+ if (stream->lpac->type == BT_BAP_BCAST_SINK)
+ goto done;
+
if (stream->client)
goto done;

@@ -2379,6 +2393,10 @@ static struct bt_bap_pac *bap_pac_find(struct bt_bap_db *bdb, uint8_t type,
return queue_find(bdb->sources, match_codec, codec);
case BT_BAP_SINK:
return queue_find(bdb->sinks, match_codec, codec);
+ case BT_BAP_BCAST_SOURCE:
+ return queue_find(bdb->broadcast_sources, match_codec, codec);
+ case BT_BAP_BCAST_SINK:
+ return queue_find(bdb->broadcast_sinks, match_codec, codec);
}

return NULL;
@@ -2518,7 +2536,7 @@ struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db,
struct iovec *metadata)
{
struct bt_bap_db *bdb;
- struct bt_bap_pac *pac, *pac_brodcast_sink;
+ struct bt_bap_pac *pac, *pac_broadcast_sink;
struct bt_bap_codec codec;

if (!db)
@@ -2545,11 +2563,19 @@ struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db,
bap_add_source(pac);
break;
case BT_BAP_BCAST_SOURCE:
- // For broadcast add local pac and remote pac
bap_add_broadcast_source(pac);
- pac_brodcast_sink = bap_pac_new(bdb, name, type, &codec, qos,
+ if (queue_isempty(bdb->broadcast_sinks)) {
+ /* When adding a local broadcast source, add also a
+ * local broadcast sink
+ */
+ pac_broadcast_sink = bap_pac_new(bdb, name,
+ BT_BAP_BCAST_SINK, &codec, qos,
data, metadata);
- bap_add_broadcast_sink(pac_brodcast_sink);
+ bap_add_broadcast_sink(pac_broadcast_sink);
+ }
+ break;
+ case BT_BAP_BCAST_SINK:
+ bap_add_broadcast_sink(pac);
break;
default:
bap_pac_free(pac);
@@ -3996,7 +4022,7 @@ clone:
return true;
}

-bool bt_bap_attach_broadcast(struct bt_bap *bap)
+bool bt_bap_attach_broadcast(struct bt_bap *bap, uint8_t type)
{
struct bt_bap_endpoint *ep;

@@ -4008,7 +4034,7 @@ bool bt_bap_attach_broadcast(struct bt_bap *bap)

queue_push_tail(sessions, bap);

- ep = bap_get_endpoint_bcast(bap->remote_eps, bap->ldb);
+ ep = bap_get_endpoint_bcast(bap->remote_eps, bap->ldb, type);
if (ep)
ep->bap = bap;

@@ -4221,9 +4247,19 @@ void bt_bap_foreach_pac(struct bt_bap *bap, uint8_t type,
return bap_foreach_pac(bap->ldb->sinks, bap->rdb->sources,
func, user_data);
case BT_BAP_BCAST_SOURCE:
- return bap_foreach_pac(bap->ldb->broadcast_sources,
+ if (queue_isempty(bap->rdb->broadcast_sources)
+ && queue_isempty(bap->rdb->broadcast_sinks))
+ return bap_foreach_pac(bap->ldb->broadcast_sources,
bap->ldb->broadcast_sinks,
func, user_data);
+
+ return bap_foreach_pac(bap->ldb->broadcast_sinks,
+ bap->rdb->broadcast_sources,
+ func, user_data);
+ case BT_BAP_BCAST_SINK:
+ return bap_foreach_pac(bap->ldb->broadcast_sinks,
+ bap->rdb->broadcast_sources,
+ func, user_data);
}
}

@@ -4382,6 +4418,11 @@ unsigned int bt_bap_stream_config(struct bt_bap_stream *stream,
return req->id;
case BT_BAP_STREAM_TYPE_BCAST:
stream->qos = *qos;
+ if (stream->lpac->type == BT_BAP_BCAST_SINK) {
+ if (data)
+ stream_config(stream, data, NULL);
+ stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
+ }
return 1;
}

@@ -4446,13 +4487,19 @@ struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap,
if (rpac)
type = rpac->type;
else if (lpac) {
- switch(lpac->type) {
+ switch (lpac->type) {
case BT_BAP_SINK:
type = BT_BAP_SOURCE;
break;
case BT_BAP_SOURCE:
type = BT_BAP_SINK;
break;
+ case BT_BAP_BCAST_SOURCE:
+ type = BT_BAP_BCAST_SINK;
+ break;
+ case BT_BAP_BCAST_SINK:
+ type = BT_BAP_BCAST_SOURCE;
+ break;
default:
return NULL;
}
@@ -4913,6 +4960,13 @@ struct io *bt_bap_stream_get_io(struct bt_bap_stream *stream)
return io->io;
}

+bool bt_bap_match_bcast_sink_stream(const void *data, const void *user_data)
+{
+ const struct bt_bap_stream *stream = data;
+
+ return stream->lpac->type == BT_BAP_BCAST_SINK;
+}
+
static bool stream_io_disconnected(struct io *io, void *user_data)
{
struct bt_bap_stream *stream = user_data;
@@ -4944,6 +4998,14 @@ static bool match_req_id(const void *data, const void *match_data)
return (req->id == id);
}

+static bool match_name(const void *data, const void *match_data)
+{
+ const struct bt_bap_pac *pac = data;
+ const char *name = match_data;
+
+ return (!strcmp(pac->name, name));
+}
+
int bt_bap_stream_cancel(struct bt_bap_stream *stream, unsigned int id)
{
struct bt_bap_req *req;
@@ -5132,3 +5194,42 @@ bool bt_bap_stream_io_is_connecting(struct bt_bap_stream *stream, int *fd)

return io->connecting;
}
+
+bool bt_bap_new_bcast_source(struct bt_bap *bap, const char *name)
+{
+ struct bt_bap_endpoint *ep;
+ struct bt_bap_pac *pac_broadcast_source, *local_sink;
+ struct bt_bap_codec bap_codec;
+
+ bap_codec.id = 0x06;
+ bap_codec.cid = 0;
+ bap_codec.vid = 0;
+
+ /* Add remote source endpoint */
+ if (!bap->rdb->broadcast_sources)
+ bap->rdb->broadcast_sources = queue_new();
+
+ if (queue_find(bap->rdb->broadcast_sources, match_name, name)) {
+ DBG(bap, "broadcast source already registered");
+ return true;
+ }
+
+ local_sink = queue_peek_head(bap->ldb->broadcast_sinks);
+ pac_broadcast_source = bap_pac_new(bap->rdb, name, BT_BAP_BCAST_SOURCE,
+ &bap_codec, NULL, local_sink->data, NULL);
+ queue_push_tail(bap->rdb->broadcast_sources, pac_broadcast_source);
+
+ if (!pac_broadcast_source) {
+ DBG(bap, "No broadcast source could be created");
+ return false;
+ }
+ queue_foreach(bap->pac_cbs, notify_pac_added, pac_broadcast_source);
+
+ /* Push remote endpoint with direction sink */
+ ep = bap_endpoint_new_broadcast(bap->rdb, BT_BAP_BCAST_SINK);
+
+ if (ep)
+ queue_push_tail(bap->remote_eps, ep);
+
+ return true;
+}
diff --git a/src/shared/bap.h b/src/shared/bap.h
index 50b567663..fcacfcbed 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
@@ -186,7 +186,7 @@ struct bt_bap *bt_bap_ref(struct bt_bap *bap);
void bt_bap_unref(struct bt_bap *bap);

bool bt_bap_attach(struct bt_bap *bap, struct bt_gatt_client *client);
-bool bt_bap_attach_broadcast(struct bt_bap *bap);
+bool bt_bap_attach_broadcast(struct bt_bap *bap, uint8_t type);
void bt_bap_detach(struct bt_bap *bap);

bool bt_bap_set_debug(struct bt_bap *bap, bt_bap_debug_func_t cb,
@@ -289,7 +289,7 @@ struct bt_bap_qos *bt_bap_stream_get_qos(struct bt_bap_stream *stream);
struct iovec *bt_bap_stream_get_metadata(struct bt_bap_stream *stream);

struct io *bt_bap_stream_get_io(struct bt_bap_stream *stream);
-
+bool bt_bap_match_bcast_sink_stream(const void *data, const void *user_data);
bool bt_bap_stream_set_io(struct bt_bap_stream *stream, int fd);

int bt_bap_stream_cancel(struct bt_bap_stream *stream, unsigned int id);
@@ -305,3 +305,5 @@ uint8_t bt_bap_stream_io_dir(struct bt_bap_stream *stream);

int bt_bap_stream_io_connecting(struct bt_bap_stream *stream, int fd);
bool bt_bap_stream_io_is_connecting(struct bt_bap_stream *stream, int *fd);
+
+bool bt_bap_new_bcast_source(struct bt_bap *bap, const char *name);
--
2.34.1


2023-08-08 17:35:03

by Claudia Draghicescu

[permalink] [raw]
Subject: [PATCH BlueZ v5 7/7] transport: Update transport properties for a broadcast stream

This patch gets the QOS broadcast stream parameters and passes them
to upper layers.
---
profiles/audio/transport.c | 245 ++++++++++++++++++++++++++++++++++++-
1 file changed, 243 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index cf5662d1d..107339520 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -552,6 +552,8 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg,
owner = media_owner_create(msg);

if (!strcmp(media_endpoint_get_uuid(transport->endpoint),
+ BAA_SERVICE_UUID)
+ || !strcmp(media_endpoint_get_uuid(transport->endpoint),
BCAA_SERVICE_UUID)) {
req = media_request_create(msg, 0x00);
media_owner_add(owner, req);
@@ -853,6 +855,9 @@ static gboolean qos_exists(const GDBusPropertyTable *property, void *data)
struct media_transport *transport = data;
struct bap_transport *bap = transport->data;

+ if (media_endpoint_is_broadcast(transport->endpoint))
+ return bap->qos.bcast.io_qos.sdu != 0x00;
+
return bap->qos.ucast.io_qos.phy != 0x00;
}

@@ -868,6 +873,18 @@ static gboolean get_cig(const GDBusPropertyTable *property,
return TRUE;
}

+static gboolean get_big(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.big);
+
+ return TRUE;
+}
+
static gboolean get_cis(const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
{
@@ -880,6 +897,18 @@ static gboolean get_cis(const GDBusPropertyTable *property,
return TRUE;
}

+static gboolean get_bis(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.bis);
+
+ return TRUE;
+}
+
static gboolean get_interval(const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
{
@@ -899,6 +928,9 @@ static gboolean get_framing(const GDBusPropertyTable *property,
struct bap_transport *bap = transport->data;
dbus_bool_t val = bap->qos.ucast.framing;

+ if (media_endpoint_is_broadcast(transport->endpoint))
+ val = bap->qos.bcast.framing;
+
dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &val);

return TRUE;
@@ -910,6 +942,12 @@ static gboolean get_phy(const GDBusPropertyTable *property,
struct media_transport *transport = data;
struct bap_transport *bap = transport->data;

+ if (media_endpoint_is_broadcast(transport->endpoint)) {
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.io_qos.phy);
+ return TRUE;
+ }
+
dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
&bap->qos.ucast.io_qos.phy);

@@ -922,6 +960,12 @@ static gboolean get_sdu(const GDBusPropertyTable *property,
struct media_transport *transport = data;
struct bap_transport *bap = transport->data;

+ if (media_endpoint_is_broadcast(transport->endpoint)) {
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
+ &bap->qos.bcast.io_qos.sdu);
+ return TRUE;
+ }
+
dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
&bap->qos.ucast.io_qos.sdu);

@@ -1040,6 +1084,121 @@ static gboolean get_links(const GDBusPropertyTable *property,
return TRUE;
}

+static gboolean get_sync_interval(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.sync_interval);
+
+ return TRUE;
+}
+
+static gboolean get_packing(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.packing);
+
+ return TRUE;
+}
+
+static gboolean get_bcode(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+ DBusMessageIter array;
+
+ dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_BYTE_AS_STRING, &array);
+
+ if (bap->qos.bcast.bcode && bap->qos.bcast.bcode->iov_len)
+ dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.bcode->iov_base,
+ bap->qos.bcast.bcode->iov_len);
+
+ dbus_message_iter_close_container(iter, &array);
+ return TRUE;
+}
+
+static gboolean get_options(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.options);
+
+ return TRUE;
+}
+
+static gboolean get_skip(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
+ &bap->qos.bcast.skip);
+
+ return TRUE;
+}
+
+static gboolean get_sync_timeout(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
+ &bap->qos.bcast.sync_timeout);
+
+ return TRUE;
+}
+
+static gboolean get_sync_cte_type(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.sync_cte_type);
+
+ return TRUE;
+}
+
+static gboolean get_mse(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
+ &bap->qos.bcast.mse);
+
+ return TRUE;
+}
+
+static gboolean get_timeout(const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct media_transport *transport = data;
+ struct bap_transport *bap = transport->data;
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
+ &bap->qos.bcast.timeout);
+
+ return TRUE;
+}
+
static const GDBusPropertyTable bap_properties[] = {
{ "Device", "o", get_device },
{ "UUID", "s", get_uuid },
@@ -1059,6 +1218,17 @@ static const GDBusPropertyTable bap_properties[] = {
{ "Location", "u", get_location },
{ "Metadata", "ay", get_metadata },
{ "Links", "ao", get_links, NULL, links_exists },
+ { "BIG", "y", get_big, NULL, qos_exists },
+ { "BIS", "y", get_bis, NULL, qos_exists },
+ { "SyncInterval", "y", get_sync_interval, NULL, qos_exists },
+ { "Packing", "y", get_packing, NULL, qos_exists },
+ { "BCode", "ay", get_bcode, NULL, qos_exists },
+ { "Options", "y", get_options, NULL, qos_exists },
+ { "Skip", "q", get_skip, NULL, qos_exists },
+ { "SyncTimeout", "q", get_sync_timeout, NULL, qos_exists },
+ { "SyncCteType", "y", get_sync_cte_type, NULL, qos_exists },
+ { "MSE", "y", get_mse, NULL, qos_exists },
+ { "Timeout", "q", get_timeout, NULL, qos_exists },
{ }
};

@@ -1341,6 +1511,71 @@ static gboolean bap_resume_wait_cb(void *data)
return FALSE;
}

+static void bap_update_bcast_qos(const struct media_transport *transport)
+{
+ struct bap_transport *bap = transport->data;
+ struct bt_bap_qos *qos;
+
+ qos = bt_bap_stream_get_qos(bap->stream);
+
+ if (!memcmp(qos, &bap->qos, sizeof(struct bt_bap_qos)))
+ return;
+
+ bap->qos = *qos;
+
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "BIG");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "BIS");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "SyncInterval");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "Packing");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "Framing");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "BCode");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "Options");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "Skip");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "SyncTimeout");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "SyncCteType");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "MSE");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "Timeout");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "Interval");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "Latency");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "PHY");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "SDU");
+ g_dbus_emit_property_changed(btd_get_dbus_connection(),
+ transport->path, MEDIA_TRANSPORT_INTERFACE,
+ "RTN");
+}
+
static guint resume_bap(struct media_transport *transport,
struct media_owner *owner)
{
@@ -1493,7 +1728,10 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
if (owner && owner->pending)
return;
bap_update_links(transport);
- bap_update_qos(transport);
+ if (!media_endpoint_is_broadcast(transport->endpoint))
+ bap_update_qos(transport);
+ else if (bt_bap_stream_io_dir(stream) != BT_BAP_BCAST_SOURCE)
+ bap_update_bcast_qos(transport);
transport_update_playing(transport, FALSE);
return;
case BT_BAP_STREAM_STATE_DISABLING:
@@ -1503,6 +1741,8 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
return;
break;
case BT_BAP_STREAM_STATE_STREAMING:
+ if (bt_bap_stream_io_dir(stream) == BT_BAP_BCAST_SOURCE)
+ bap_update_bcast_qos(transport);
break;
}

@@ -1631,7 +1871,8 @@ struct media_transport *media_transport_create(struct btd_device *device,
properties = a2dp_properties;
} else if (!strcasecmp(uuid, PAC_SINK_UUID) ||
!strcasecmp(uuid, PAC_SOURCE_UUID) ||
- !strcasecmp(uuid, BCAA_SERVICE_UUID)) {
+ !strcasecmp(uuid, BCAA_SERVICE_UUID) ||
+ !strcasecmp(uuid, BAA_SERVICE_UUID)) {
if (media_transport_init_bap(transport, stream) < 0)
goto fail;
properties = bap_properties;
--
2.34.1


2023-08-08 21:43:33

by bluez.test.bot

[permalink] [raw]
Subject: RE: Add support for BAP broadcast sink

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=774119

---Test result---

Test Summary:
CheckPatch PASS 3.15 seconds
GitLint PASS 1.55 seconds
BuildEll PASS 34.44 seconds
BluezMake PASS 1220.65 seconds
MakeCheck PASS 13.61 seconds
MakeDistcheck PASS 204.75 seconds
CheckValgrind PASS 322.59 seconds
CheckSmatch PASS 429.83 seconds
bluezmakeextell PASS 125.12 seconds
IncrementalBuild PASS 6150.64 seconds
ScanBuild PASS 1404.48 seconds



---
Regards,
Linux Bluetooth

2023-08-09 17:40:49

by patchwork-bot+bluetooth

[permalink] [raw]
Subject: Re: [PATCH BlueZ v5 0/7] Add support for BAP broadcast sink

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <[email protected]>:

On Tue, 8 Aug 2023 14:50:33 +0300 you wrote:
> This series of patches adds support for BAP broadcast sink.
> It consists in registering a broadcastsink endpoint using the
> Basic Audio Announcement Service UUID,
> discovering of broadcast advertisers that announce the
> Broadcast Audio Announcement Service, synchronizes to the Periodic
> advertisements of the source and synchronizes to the BIG advertised
> in the PA train.
> To retrieve the BASE info advertised in the PA train, the patch
> Bluetooth: ISO: Add support for periodic adv reports processing
> was used.
>
> [...]

Here is the summary with links:
- [BlueZ,v5,1/7] client/player: Add broadcast sink endpoint
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=4352a42ec1e2
- [BlueZ,v5,2/7] btio: Add support for getsockopt(BT_ISO_BASE)
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7b3aa05323f2
- [BlueZ,v5,3/7] adapter: Do not filter out broadcast advertiser
(no matching commit)
- [BlueZ,v5,4/7] profile: Add probe_on_discover flag
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=67a26abe53bf
- [BlueZ,v5,5/7] bap: Add support for BAP broadcast sink
(no matching commit)
- [BlueZ,v5,6/7] media: Add broadcast sink media endpoint
(no matching commit)
- [BlueZ,v5,7/7] transport: Update transport properties for a broadcast stream
(no matching commit)

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



2023-08-09 18:06:27

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v5 5/7] bap: Add support for BAP broadcast sink

Hi Claudia,

On Tue, Aug 8, 2023 at 10:00 AM Claudia Draghicescu
<[email protected]> wrote:
>
> This adds support for BAP broadcast sink, creates a remote endpoint when a
> broadcast source is discovered and synchronizes with the source upon
> endpoint configuration.
> This feature was tested using bluetoothctl with the following commands:
>
> [bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06
> [bluetooth]# scan on
> [NEW] Endpoint /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
> [bluetooth]# endpoint.config
> /org/bluez/hci0/dev_XX_XX_XX_XX_XX_XX/pac_bcast0
> /local/endpoint/ep0 16_2_1
> ---
> profiles/audio/bap.c | 334 ++++++++++++++++++++++++++++++++++++++-----
> src/shared/bap.c | 139 +++++++++++++++---
> src/shared/bap.h | 6 +-
> 3 files changed, 424 insertions(+), 55 deletions(-)
>
> diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
> index 8cbb238ef..a0ac642f3 100644
> --- a/profiles/audio/bap.c
> +++ b/profiles/audio/bap.c
> @@ -34,6 +34,7 @@
> #include "lib/hci.h"
> #include "lib/sdp.h"
> #include "lib/uuid.h"
> +#include "lib/iso.h"
>
> #include "src/btd.h"
> #include "src/dbus-common.h"
> @@ -57,7 +58,9 @@
>
> #define ISO_SOCKET_UUID "6fbaf188-05e0-496a-9885-d6ddfdb4e03e"
> #define PACS_UUID_STR "00001850-0000-1000-8000-00805f9b34fb"
> +#define BCAAS_UUID_STR "00001852-0000-1000-8000-00805f9b34fb"
> #define MEDIA_ENDPOINT_INTERFACE "org.bluez.MediaEndpoint1"
> +#define MEDIA_INTERFACE "org.bluez.Media1"
>
> struct bap_ep {
> char *path;
> @@ -186,8 +189,11 @@ static gboolean get_uuid(const GDBusPropertyTable *property,
> uuid = PAC_SINK_UUID;
> else if (queue_find(ep->data->srcs, NULL, ep))
> uuid = PAC_SOURCE_UUID;
> - else
> + else if ((queue_find(ep->data->bcast, NULL, ep)
> + && (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK)))
> uuid = BAA_SERVICE_UUID;
> + else
> + uuid = BCAA_SERVICE_UUID;
>
> dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid);
>
> @@ -341,15 +347,18 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps,
> } else if (!strcasecmp(key, "PHY")) {
> const char *str;
>
> - if (var != DBUS_TYPE_STRING)
> - goto fail;
> -
> - dbus_message_iter_get_basic(&value, &str);
> -
> - if (!strcasecmp(str, "1M"))
> - io_qos.phy = 0x01;
> - else if (!strcasecmp(str, "2M"))
> - io_qos.phy = 0x02;
> + if (var == DBUS_TYPE_STRING) {
> + dbus_message_iter_get_basic(&value, &str);
> +
> + if (!strcasecmp(str, "1M"))
> + io_qos.phy = 0x01;
> + else if (!strcasecmp(str, "2M"))
> + io_qos.phy = 0x02;
> + else
> + goto fail;
> + } else if (var == DBUS_TYPE_BYTE)
> + dbus_message_iter_get_basic(&value,
> + &io_qos.phy);

We shouldn't be accepting different types for PHY, and afaik the PHY
are the same for broadcast, if the problem is that this could be
confusing to the likes of bluetoothctl we could instead make it
support both byte and string formats, but over D-Bus we normally
prefer string format as that is easier to debug.

> else
> goto fail;
> } else if (!strcasecmp(key, "SDU")) {
> @@ -556,7 +565,7 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
> }
>
> if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SOURCE) {
> - /* Mark CIG and CIS to be auto assigned */
> + /* Mark BIG and BIS to be auto assigned */
> ep->qos.bcast.big = BT_ISO_QOS_BIG_UNSET;
> ep->qos.bcast.bis = BT_ISO_QOS_BIS_UNSET;
> } else {
> @@ -577,8 +586,12 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
> ep->stream = bt_bap_stream_new(ep->data->bap, ep->lpac,
> ep->rpac, &ep->qos, ep->caps);
>
> - ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps,
> - config_cb, ep);
> + if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK)
> + ep->id = bt_bap_stream_config(ep->stream, &ep->qos, NULL,
> + config_cb, ep);
> + else
> + ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps,
> + config_cb, ep);

I guess we can do this internally in bt_bap_stream_config since it is
probably going to discard the capabilities anyway.

> if (!ep->id) {
> DBG("Unable to config stream");
> free(ep->caps);
> @@ -597,13 +610,120 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg,
> break;
> case BT_BAP_STREAM_TYPE_BCAST:
> /* No message sent over the air for broadcast */
> - ep->id = 0;
> + if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK)
> + ep->msg = dbus_message_ref(msg);
> + else
> + ep->id = 0;
> +
> return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
> }
>
> return NULL;
> }
>
> +static void update_bcast_qos(struct bt_iso_qos *qos,
> + struct bt_bap_qos *bap_qos)
> +{
> + bap_qos->bcast.big = qos->bcast.big;
> + bap_qos->bcast.bis = qos->bcast.bis;
> + bap_qos->bcast.sync_interval = qos->bcast.sync_interval;
> + bap_qos->bcast.packing = qos->bcast.packing;
> + bap_qos->bcast.framing = qos->bcast.framing;
> + bap_qos->bcast.encryption = qos->bcast.encryption;
> + bap_qos->bcast.options = qos->bcast.options;
> + bap_qos->bcast.skip = qos->bcast.skip;
> + bap_qos->bcast.sync_timeout = qos->bcast.sync_timeout;
> + bap_qos->bcast.sync_cte_type = qos->bcast.sync_cte_type;
> + bap_qos->bcast.mse = qos->bcast.mse;
> + bap_qos->bcast.timeout = qos->bcast.timeout;
> + bap_qos->bcast.io_qos.interval = qos->bcast.in.interval;
> + bap_qos->bcast.io_qos.latency = qos->bcast.in.latency;
> + bap_qos->bcast.io_qos.phy = qos->bcast.in.phy;
> + bap_qos->bcast.io_qos.sdu = qos->bcast.in.sdu;
> + bap_qos->bcast.io_qos.rtn = qos->bcast.in.rtn;
> +
> + bap_qos->bcast.bcode = new0(struct iovec, 1);
> + util_iov_memcpy(bap_qos->bcast.bcode, qos->bcast.bcode,
> + sizeof(qos->bcast.bcode));
> +}
> +
> +static bool match_ep_type(const void *data, const void *user_data)
> +{
> + const struct bap_ep *ep = data;
> +
> + return (bt_bap_pac_get_type(ep->lpac) == PTR_TO_INT(user_data));
> +}
> +
> +static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data)
> +{
> + struct bap_data *data = user_data;
> + struct bt_iso_qos qos;
> + struct bt_iso_base base;
> + char address[18];
> + struct bap_ep *ep;
> + int fd;
> + struct iovec *base_io;
> +
> + bt_io_get(io, &err,
> + BT_IO_OPT_DEST, address,
> + BT_IO_OPT_QOS, &qos,
> + BT_IO_OPT_BASE, &base,
> + BT_IO_OPT_INVALID);
> + if (err) {
> + error("%s", err->message);
> + g_error_free(err);
> + goto drop;
> + }
> +
> + g_io_channel_ref(io);
> + btd_service_connecting_complete(data->service, 0);
> + DBG("BCAST ISO: sync with %s (BIG 0x%02x BIS 0x%02x)",
> + address, qos.bcast.big, qos.bcast.bis);
> +
> + ep = queue_find(data->bcast, match_ep_type,
> + INT_TO_PTR(BT_BAP_BCAST_SINK));
> + if (!ep) {
> + DBG("ep not found");
> + return;
> + }
> +
> + update_bcast_qos(&qos, &ep->qos);
> +
> + base_io = new0(struct iovec, 1);
> + util_iov_memcpy(base_io, base.base, base.base_len);
> +
> + if (ep->stream == NULL)
> + DBG("stream is null");
> + ep->id = bt_bap_stream_config(ep->stream, &ep->qos,
> + base_io, NULL, NULL);
> + data->listen_io = io;
> +
> + bt_bap_stream_set_user_data(ep->stream, ep->path);
> +
> + fd = g_io_channel_unix_get_fd(io);
> +
> + if (bt_bap_stream_set_io(ep->stream, fd)) {
> + bt_bap_stream_enable(ep->stream, true, NULL, NULL, NULL);
> + g_io_channel_set_close_on_unref(io, FALSE);
> + return;
> + }
> +
> +
> + return;
> +
> +drop:
> + g_io_channel_shutdown(io, TRUE, NULL);
> +
> +}
> +
> +static bool match_data_bap_data(const void *data, const void *match_data)
> +{
> + const struct bap_data *bdata = data;
> + const struct btd_adapter *adapter = match_data;
> +
> + return bdata->user_data == adapter;
> +}
> +
> static const GDBusMethodTable ep_methods[] = {
> { GDBUS_EXPERIMENTAL_ASYNC_METHOD("SetConfiguration",
> GDBUS_ARGS({ "endpoint", "o" },
> @@ -649,15 +769,23 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data,
> struct bt_bap_pac *lpac,
> struct bt_bap_pac *rpac)
> {
> - struct btd_adapter *adapter = data->user_data;
> + struct btd_adapter *adapter = data->adapter;
> + struct btd_device *device = data->device;
> struct bap_ep *ep;
> struct queue *queue;
> - int i, err;
> + int i, err = 0;
> const char *suffix;
> struct match_ep match = { lpac, rpac };
>
> + if (!adapter)
> + DBG("adapter is null");
> +
> + if (!device)
> + DBG("device is null");

I assume the above are just leftovers to debug possible errors, we
probably don't need them if this code has been tested properly.

> switch (bt_bap_pac_get_type(rpac)) {
> case BT_BAP_BCAST_SOURCE:
> + case BT_BAP_BCAST_SINK:
> queue = data->bcast;
> i = queue_length(data->bcast);
> suffix = "bcast";
> @@ -675,8 +803,24 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data,
> ep->lpac = lpac;
> ep->rpac = rpac;
>
> - err = asprintf(&ep->path, "%s/pac_%s%d", adapter_get_path(adapter),
> - suffix, i);
> + if (device)
> + ep->data->device = device;
> +
> + switch (bt_bap_pac_get_type(rpac)) {
> + case BT_BAP_BCAST_SINK:
> + DBG("sink");
> + err = asprintf(&ep->path, "%s/pac_%s%d",
> + adapter_get_path(adapter), suffix, i);
> + DBG("sink path %s", ep->path);
> + break;
> + case BT_BAP_BCAST_SOURCE:
> + DBG("source");
> + err = asprintf(&ep->path, "%s/pac_%s%d",
> + device_get_path(device), suffix, i);
> + DBG("source path %s", ep->path);

Ditto, we can probably just leave the asprintf line and remove the DBG
statements.

> + break;
> + }
> +
> if (err < 0) {
> error("Could not allocate path for remote pac %s/pac%d",
> adapter_get_path(adapter), i);
> @@ -685,14 +829,13 @@ static struct bap_ep *ep_register_bcast(struct bap_data *data,
> }
>
> if (g_dbus_register_interface(btd_get_dbus_connection(),
> - ep->path, MEDIA_ENDPOINT_INTERFACE,
> - ep_methods, NULL, ep_properties,
> - ep, ep_free) == FALSE) {
> + ep->path, MEDIA_ENDPOINT_INTERFACE,
> + ep_methods, NULL, ep_properties,
> + ep, ep_free) == FALSE) {
> error("Could not register remote ep %s", ep->path);
> ep_free(ep);
> return NULL;
> }
> -
> bt_bap_pac_set_user_data(rpac, ep->path);
>
> DBG("ep %p lpac %p rpac %p path %s", ep, ep->lpac, ep->rpac, ep->path);
> @@ -824,6 +967,7 @@ done:
>
> queue_foreach(ep->data->srcs, bap_config, NULL);
> queue_foreach(ep->data->snks, bap_config, NULL);
> + queue_foreach(ep->data->bcast, bap_config, NULL);
> }
>
> static bool pac_found(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac,
> @@ -1310,6 +1454,46 @@ static void bap_listen_io(struct bap_data *data, struct bt_bap_stream *stream,
> data->listen_io = io;
> }
>
> +static void bap_listen_io_broadcast(struct bap_data *data, struct bap_ep *ep,
> + struct bt_bap_stream *stream, struct bt_iso_qos *qos)
> +{
> + GIOChannel *io;
> + GError *err = NULL;
> + struct sockaddr_iso_bc iso_bc_addr;
> +
> + iso_bc_addr.bc_bdaddr_type = btd_device_get_bdaddr_type(data->device);
> + memcpy(&iso_bc_addr.bc_bdaddr, device_get_address(data->device),
> + sizeof(bdaddr_t));
> + iso_bc_addr.bc_bis[0] = 1;
> + iso_bc_addr.bc_num_bis = 1;
> +
> + DBG("stream %p", stream);
> +
> + /* If IO already set skip creating it again */
> + if (bt_bap_stream_get_io(stream) || data->listen_io)
> + return;
> +
> + io = bt_io_listen(iso_bcast_confirm_cb, NULL, ep->data, NULL, &err,
> + BT_IO_OPT_SOURCE_BDADDR,
> + btd_adapter_get_address(ep->data->adapter),
> + BT_IO_OPT_DEST_BDADDR,
> + device_get_address(data->device),
> + BT_IO_OPT_DEST_TYPE,
> + btd_device_get_bdaddr_type(data->device),
> + BT_IO_OPT_MODE, BT_IO_MODE_ISO,
> + BT_IO_OPT_QOS, &qos->bcast,
> + BT_IO_OPT_ISO_BC_NUM_BIS, iso_bc_addr.bc_num_bis,
> + BT_IO_OPT_ISO_BC_BIS, iso_bc_addr.bc_bis,
> + BT_IO_OPT_INVALID);
> + if (!io) {
> + error("%s", err->message);
> + g_error_free(err);
> + } else
> + DBG("io created");
> +
> + ep->data->listen_io = io;
> +
> +}
> static void bap_create_ucast_io(struct bap_data *data, struct bap_ep *ep,
> struct bt_bap_stream *stream, int defer)
> {
> @@ -1364,10 +1548,10 @@ static void bap_create_bcast_io(struct bap_data *data, struct bap_ep *ep,
> memcpy(&iso_qos.bcast.out, &ep->qos.bcast.io_qos,
> sizeof(struct bt_iso_io_qos));
> done:
> - if (ep)
> + if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SOURCE)
> bap_connect_io_broadcast(data, ep, stream, &iso_qos);
> else
> - bap_listen_io(data, stream, &iso_qos);
> + bap_listen_io_broadcast(data, ep, stream, &iso_qos);
> }
>
> static void bap_create_io(struct bap_data *data, struct bap_ep *ep,
> @@ -1417,6 +1601,11 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
> break;
> case BT_BAP_STREAM_STATE_CONFIG:
> if (ep && !ep->id) {
> + if
> + (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK) {
> + bap_create_bcast_io(data, ep, stream, true);
> + return;
> + }
> bap_create_io(data, ep, stream, true);
> if (!ep->io) {
> error("Unable to create io");
> @@ -1424,7 +1613,6 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state,
> return;
> }
>
> -
> if (bt_bap_stream_get_type(stream) ==
> BT_BAP_STREAM_TYPE_UCAST) {
> /* Wait QoS response to respond */
> @@ -1480,6 +1668,10 @@ static void pac_added_broadcast(struct bt_bap_pac *pac, void *user_data)
>
> bt_bap_foreach_pac(data->bap, BT_BAP_BCAST_SOURCE,
> pac_found_bcast, data);
> + } else if (bt_bap_pac_get_type(pac) == BT_BAP_BCAST_SINK) {
> + DBG("sink pac %p", pac);

Ditto.

> + bt_bap_foreach_pac(data->bap, BT_BAP_BCAST_SINK,
> + pac_found_bcast, data);
> }
> }
>
> @@ -1596,14 +1788,6 @@ static bool match_data(const void *data, const void *match_data)
> return bdata->bap == bap;
> }
>
> -static bool match_data_bap_data(const void *data, const void *match_data)
> -{
> - const struct bap_data *bdata = data;
> - const struct btd_adapter *adapter = match_data;
> -
> - return bdata->user_data == adapter;
> -}
> -
> static bool io_get_qos(GIOChannel *io, struct bt_iso_qos *qos)
> {
> GError *err = NULL;
> @@ -1733,6 +1917,73 @@ static void bap_detached(struct bt_bap *bap, void *user_data)
> bap_data_remove(data);
> }
>
> +static int bap_bcast_probe(struct btd_service *service)
> +{
> + struct btd_device *device = btd_service_get_device(service);
> + struct btd_adapter *adapter = device_get_adapter(device);
> + struct btd_gatt_database *database = btd_adapter_get_database(adapter);
> + struct bap_data *data = btd_service_get_user_data(service);
> + char addr[18];
> +
> + ba2str(device_get_address(device), addr);
> + DBG("Device %s is a BAP broadcast source", addr);
> +
> + if (!btd_adapter_has_exp_feature(adapter, EXP_FEAT_ISO_SOCKET)) {
> + error("BAP requires ISO Socket which is not enabled");
> + return -ENOTSUP;
> + }
> +
> + /* Ignore, if we were probed for this device already */
> + if (data) {
> + error("Profile probed twice for the same device!");
> + return -EINVAL;
> + }
> +
> + data = bap_data_new(device);
> + data->service = service;
> + data->adapter = adapter;
> + data->device = device;
> +
> + data->bap = bt_bap_new(btd_gatt_database_get_db(database),
> + btd_gatt_database_get_db(database));
> + if (!data->bap) {
> + error("Unable to create BAP instance");
> + free(data);
> + return -EINVAL;
> + }
> +
> + bap_data_add(data);
> +
> + data->ready_id = bt_bap_ready_register(data->bap, bap_ready, service,
> + NULL);
> + data->state_id = bt_bap_state_register(data->bap, bap_state,
> + bap_connecting, data, NULL);
> + data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast,
> + pac_removed_broadcast, data, NULL);
> +
> + bt_bap_set_user_data(data->bap, service);
> + bt_bap_new_bcast_source(data->bap, device_get_path(device));
> + return 0;
> +}
> +
> +static void bap_bcast_remove(struct btd_service *service)
> +{
> + struct btd_device *device = btd_service_get_device(service);
> + struct bap_data *data;
> + char addr[18];
> +
> + ba2str(device_get_address(device), addr);
> + DBG("%s", addr);
> +
> + data = btd_service_get_user_data(service);
> + if (!data) {
> + error("BAP service not handled by profile");
> + return;
> + }
> +
> + bap_data_remove(data);
> +}
> +
> static int bap_probe(struct btd_service *service)
> {
> struct btd_device *device = btd_service_get_device(service);
> @@ -1854,7 +2105,7 @@ static int bap_adapter_probe(struct btd_profile *p,
>
> bap_data_add(data);
>
> - if (!bt_bap_attach_broadcast(data->bap)) {
> + if (!bt_bap_attach_broadcast(data->bap, BT_BAP_BCAST_SOURCE)) {
> error("BAP unable to attach");
> return -EINVAL;
> }
> @@ -1901,6 +2152,17 @@ static struct btd_profile bap_profile = {
> .experimental = true,
> };
>
> +static struct btd_profile bap_bcast_profile = {
> + .name = "bapbcast",

Id suggest using "bcaa" as name instead.

> + .priority = BTD_PROFILE_PRIORITY_MEDIUM,
> + .remote_uuid = BCAAS_UUID_STR,
> + .device_probe = bap_bcast_probe,
> + .device_remove = bap_bcast_remove,
> + .auto_connect = false,
> + .experimental = true,
> + .probe_on_discover = true,
> +};
> +
> static unsigned int bap_id = 0;
>
> static int bap_init(void)
> @@ -1911,6 +2173,10 @@ static int bap_init(void)
> if (err)
> return err;
>
> + err = btd_profile_register(&bap_bcast_profile);
> + if (err)
> + return err;
> +
> bap_id = bt_bap_register(bap_attached, bap_detached, NULL);
>
> return 0;
> diff --git a/src/shared/bap.c b/src/shared/bap.c
> index 72ce67c08..ebeb713d5 100644
> --- a/src/shared/bap.c
> +++ b/src/shared/bap.c
> @@ -633,14 +633,18 @@ static struct bt_bap_endpoint *bap_endpoint_new(struct bt_bap_db *bdb,
> return ep;
> }

Changes to shared shall normally be split in their own commits.

> -static struct bt_bap_endpoint *bap_endpoint_new_broacast(struct bt_bap_db *bdb)
> +static struct bt_bap_endpoint *bap_endpoint_new_broadcast(struct bt_bap_db *bdb,
> + uint8_t type)
> {
> struct bt_bap_endpoint *ep;
>
> ep = new0(struct bt_bap_endpoint, 1);
> ep->bdb = bdb;
> ep->attr = NULL;
> - ep->dir = BT_BAP_BCAST_SOURCE;
> + if (type == BT_BAP_BCAST_SINK)
> + ep->dir = BT_BAP_BCAST_SOURCE;
> + else
> + ep->dir = BT_BAP_BCAST_SINK;
>
> return ep;
> }
> @@ -667,22 +671,27 @@ static struct bt_bap_endpoint *bap_get_endpoint(struct queue *endpoints,
> return ep;
> }
>
> +static bool match_ep_type(const void *data, const void *match_data)
> +{
> + const struct bt_bap_endpoint *ep = data;
> + const uint8_t type = PTR_TO_INT(match_data);
> +
> + return (ep->dir == type);
> +}
> +
> static struct bt_bap_endpoint *bap_get_endpoint_bcast(struct queue *endpoints,
> - struct bt_bap_db *db)
> + struct bt_bap_db *db, uint8_t type)
> {
> struct bt_bap_endpoint *ep;
>
> if (!db)
> return NULL;
> - /*
> - * We have support for only one stream so we will have
> - * only one endpoint.
> - * TO DO add support for more then one stream
> - */
> - if (queue_length(endpoints) > 0)
> - return queue_peek_head(endpoints);
>
> - ep = bap_endpoint_new_broacast(db);
> + ep = queue_find(endpoints, match_ep_type, INT_TO_PTR(type));
> + if (ep)
> + return ep;
> +
> + ep = bap_endpoint_new_broadcast(db, type);
> if (!ep)
> return NULL;
>
> @@ -1317,6 +1326,8 @@ static void stream_set_state_broadcast(struct bt_bap_stream *stream,
> struct bt_bap *bap = stream->bap;
> const struct queue_entry *entry;
>
> + if (ep->old_state == state)
> + return;
> ep->old_state = ep->state;
> ep->state = state;
>
> @@ -1348,6 +1359,9 @@ static void stream_set_state(struct bt_bap_stream *stream, uint8_t state)
> ep->old_state = ep->state;
> ep->state = state;
>
> + if (stream->lpac->type == BT_BAP_BCAST_SINK)
> + goto done;
> +
> if (stream->client)
> goto done;
>
> @@ -2379,6 +2393,10 @@ static struct bt_bap_pac *bap_pac_find(struct bt_bap_db *bdb, uint8_t type,
> return queue_find(bdb->sources, match_codec, codec);
> case BT_BAP_SINK:
> return queue_find(bdb->sinks, match_codec, codec);
> + case BT_BAP_BCAST_SOURCE:
> + return queue_find(bdb->broadcast_sources, match_codec, codec);
> + case BT_BAP_BCAST_SINK:
> + return queue_find(bdb->broadcast_sinks, match_codec, codec);
> }
>
> return NULL;
> @@ -2518,7 +2536,7 @@ struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db,
> struct iovec *metadata)
> {
> struct bt_bap_db *bdb;
> - struct bt_bap_pac *pac, *pac_brodcast_sink;
> + struct bt_bap_pac *pac, *pac_broadcast_sink;
> struct bt_bap_codec codec;
>
> if (!db)
> @@ -2545,11 +2563,19 @@ struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db,
> bap_add_source(pac);
> break;
> case BT_BAP_BCAST_SOURCE:
> - // For broadcast add local pac and remote pac
> bap_add_broadcast_source(pac);
> - pac_brodcast_sink = bap_pac_new(bdb, name, type, &codec, qos,
> + if (queue_isempty(bdb->broadcast_sinks)) {
> + /* When adding a local broadcast source, add also a
> + * local broadcast sink
> + */
> + pac_broadcast_sink = bap_pac_new(bdb, name,
> + BT_BAP_BCAST_SINK, &codec, qos,
> data, metadata);
> - bap_add_broadcast_sink(pac_brodcast_sink);
> + bap_add_broadcast_sink(pac_broadcast_sink);
> + }
> + break;
> + case BT_BAP_BCAST_SINK:
> + bap_add_broadcast_sink(pac);
> break;
> default:
> bap_pac_free(pac);
> @@ -3996,7 +4022,7 @@ clone:
> return true;
> }
>
> -bool bt_bap_attach_broadcast(struct bt_bap *bap)
> +bool bt_bap_attach_broadcast(struct bt_bap *bap, uint8_t type)
> {
> struct bt_bap_endpoint *ep;
>
> @@ -4008,7 +4034,7 @@ bool bt_bap_attach_broadcast(struct bt_bap *bap)
>
> queue_push_tail(sessions, bap);
>
> - ep = bap_get_endpoint_bcast(bap->remote_eps, bap->ldb);
> + ep = bap_get_endpoint_bcast(bap->remote_eps, bap->ldb, type);
> if (ep)
> ep->bap = bap;
>
> @@ -4221,9 +4247,19 @@ void bt_bap_foreach_pac(struct bt_bap *bap, uint8_t type,
> return bap_foreach_pac(bap->ldb->sinks, bap->rdb->sources,
> func, user_data);
> case BT_BAP_BCAST_SOURCE:
> - return bap_foreach_pac(bap->ldb->broadcast_sources,
> + if (queue_isempty(bap->rdb->broadcast_sources)
> + && queue_isempty(bap->rdb->broadcast_sinks))
> + return bap_foreach_pac(bap->ldb->broadcast_sources,
> bap->ldb->broadcast_sinks,
> func, user_data);
> +
> + return bap_foreach_pac(bap->ldb->broadcast_sinks,
> + bap->rdb->broadcast_sources,
> + func, user_data);
> + case BT_BAP_BCAST_SINK:
> + return bap_foreach_pac(bap->ldb->broadcast_sinks,
> + bap->rdb->broadcast_sources,
> + func, user_data);
> }
> }
>
> @@ -4382,6 +4418,11 @@ unsigned int bt_bap_stream_config(struct bt_bap_stream *stream,
> return req->id;
> case BT_BAP_STREAM_TYPE_BCAST:
> stream->qos = *qos;
> + if (stream->lpac->type == BT_BAP_BCAST_SINK) {
> + if (data)
> + stream_config(stream, data, NULL);
> + stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG);
> + }
> return 1;
> }
>
> @@ -4446,13 +4487,19 @@ struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap,
> if (rpac)
> type = rpac->type;
> else if (lpac) {
> - switch(lpac->type) {
> + switch (lpac->type) {
> case BT_BAP_SINK:
> type = BT_BAP_SOURCE;
> break;
> case BT_BAP_SOURCE:
> type = BT_BAP_SINK;
> break;
> + case BT_BAP_BCAST_SOURCE:
> + type = BT_BAP_BCAST_SINK;
> + break;
> + case BT_BAP_BCAST_SINK:
> + type = BT_BAP_BCAST_SOURCE;
> + break;
> default:
> return NULL;
> }
> @@ -4913,6 +4960,13 @@ struct io *bt_bap_stream_get_io(struct bt_bap_stream *stream)
> return io->io;
> }
>
> +bool bt_bap_match_bcast_sink_stream(const void *data, const void *user_data)
> +{
> + const struct bt_bap_stream *stream = data;
> +
> + return stream->lpac->type == BT_BAP_BCAST_SINK;
> +}
> +
> static bool stream_io_disconnected(struct io *io, void *user_data)
> {
> struct bt_bap_stream *stream = user_data;
> @@ -4944,6 +4998,14 @@ static bool match_req_id(const void *data, const void *match_data)
> return (req->id == id);
> }
>
> +static bool match_name(const void *data, const void *match_data)
> +{
> + const struct bt_bap_pac *pac = data;
> + const char *name = match_data;
> +
> + return (!strcmp(pac->name, name));
> +}
> +
> int bt_bap_stream_cancel(struct bt_bap_stream *stream, unsigned int id)
> {
> struct bt_bap_req *req;
> @@ -5132,3 +5194,42 @@ bool bt_bap_stream_io_is_connecting(struct bt_bap_stream *stream, int *fd)
>
> return io->connecting;
> }
> +
> +bool bt_bap_new_bcast_source(struct bt_bap *bap, const char *name)
> +{
> + struct bt_bap_endpoint *ep;
> + struct bt_bap_pac *pac_broadcast_source, *local_sink;
> + struct bt_bap_codec bap_codec;
> +
> + bap_codec.id = 0x06;
> + bap_codec.cid = 0;
> + bap_codec.vid = 0;
> +
> + /* Add remote source endpoint */
> + if (!bap->rdb->broadcast_sources)
> + bap->rdb->broadcast_sources = queue_new();
> +
> + if (queue_find(bap->rdb->broadcast_sources, match_name, name)) {
> + DBG(bap, "broadcast source already registered");
> + return true;
> + }
> +
> + local_sink = queue_peek_head(bap->ldb->broadcast_sinks);
> + pac_broadcast_source = bap_pac_new(bap->rdb, name, BT_BAP_BCAST_SOURCE,
> + &bap_codec, NULL, local_sink->data, NULL);
> + queue_push_tail(bap->rdb->broadcast_sources, pac_broadcast_source);
> +
> + if (!pac_broadcast_source) {
> + DBG(bap, "No broadcast source could be created");
> + return false;
> + }
> + queue_foreach(bap->pac_cbs, notify_pac_added, pac_broadcast_source);
> +
> + /* Push remote endpoint with direction sink */
> + ep = bap_endpoint_new_broadcast(bap->rdb, BT_BAP_BCAST_SINK);
> +
> + if (ep)
> + queue_push_tail(bap->remote_eps, ep);
> +
> + return true;
> +}
> diff --git a/src/shared/bap.h b/src/shared/bap.h
> index 50b567663..fcacfcbed 100644
> --- a/src/shared/bap.h
> +++ b/src/shared/bap.h
> @@ -186,7 +186,7 @@ struct bt_bap *bt_bap_ref(struct bt_bap *bap);
> void bt_bap_unref(struct bt_bap *bap);
>
> bool bt_bap_attach(struct bt_bap *bap, struct bt_gatt_client *client);
> -bool bt_bap_attach_broadcast(struct bt_bap *bap);
> +bool bt_bap_attach_broadcast(struct bt_bap *bap, uint8_t type);
> void bt_bap_detach(struct bt_bap *bap);
>
> bool bt_bap_set_debug(struct bt_bap *bap, bt_bap_debug_func_t cb,
> @@ -289,7 +289,7 @@ struct bt_bap_qos *bt_bap_stream_get_qos(struct bt_bap_stream *stream);
> struct iovec *bt_bap_stream_get_metadata(struct bt_bap_stream *stream);
>
> struct io *bt_bap_stream_get_io(struct bt_bap_stream *stream);
> -
> +bool bt_bap_match_bcast_sink_stream(const void *data, const void *user_data);
> bool bt_bap_stream_set_io(struct bt_bap_stream *stream, int fd);
>
> int bt_bap_stream_cancel(struct bt_bap_stream *stream, unsigned int id);
> @@ -305,3 +305,5 @@ uint8_t bt_bap_stream_io_dir(struct bt_bap_stream *stream);
>
> int bt_bap_stream_io_connecting(struct bt_bap_stream *stream, int fd);
> bool bt_bap_stream_io_is_connecting(struct bt_bap_stream *stream, int *fd);
> +
> +bool bt_bap_new_bcast_source(struct bt_bap *bap, const char *name);

Not really getting the purpose of this function, it seems to be adding
a new pac record but I assume that shall be done when we had
discovered the BASE, also we shall probably use the Broadcast ID
instead of an arbitrary name and probably set a NULL codec since we
haven't discovered that either.

> --
> 2.34.1
>


--
Luiz Augusto von Dentz

2023-08-09 18:37:31

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH BlueZ v5 7/7] transport: Update transport properties for a broadcast stream

Hi Claudia,

On Tue, Aug 8, 2023 at 10:35 AM Claudia Draghicescu
<[email protected]> wrote:
>
> This patch gets the QOS broadcast stream parameters and passes them
> to upper layers.
> ---
> profiles/audio/transport.c | 245 ++++++++++++++++++++++++++++++++++++-
> 1 file changed, 243 insertions(+), 2 deletions(-)
>
> diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
> index cf5662d1d..107339520 100644
> --- a/profiles/audio/transport.c
> +++ b/profiles/audio/transport.c
> @@ -552,6 +552,8 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg,
> owner = media_owner_create(msg);
>
> if (!strcmp(media_endpoint_get_uuid(transport->endpoint),
> + BAA_SERVICE_UUID)
> + || !strcmp(media_endpoint_get_uuid(transport->endpoint),
> BCAA_SERVICE_UUID)) {

This code above is probably what media_endpoint_is_broadcast should be
doing, so it matches by uuid.

> req = media_request_create(msg, 0x00);
> media_owner_add(owner, req);
> @@ -853,6 +855,9 @@ static gboolean qos_exists(const GDBusPropertyTable *property, void *data)
> struct media_transport *transport = data;
> struct bap_transport *bap = transport->data;
>
> + if (media_endpoint_is_broadcast(transport->endpoint))
> + return bap->qos.bcast.io_qos.sdu != 0x00;
> +
> return bap->qos.ucast.io_qos.phy != 0x00;
> }
>
> @@ -868,6 +873,18 @@ static gboolean get_cig(const GDBusPropertyTable *property,
> return TRUE;
> }
>
> +static gboolean get_big(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.big);
> +
> + return TRUE;
> +}
> +
> static gboolean get_cis(const GDBusPropertyTable *property,
> DBusMessageIter *iter, void *data)
> {
> @@ -880,6 +897,18 @@ static gboolean get_cis(const GDBusPropertyTable *property,
> return TRUE;
> }
>
> +static gboolean get_bis(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.bis);
> +
> + return TRUE;
> +}
> +
> static gboolean get_interval(const GDBusPropertyTable *property,
> DBusMessageIter *iter, void *data)
> {
> @@ -899,6 +928,9 @@ static gboolean get_framing(const GDBusPropertyTable *property,
> struct bap_transport *bap = transport->data;
> dbus_bool_t val = bap->qos.ucast.framing;
>
> + if (media_endpoint_is_broadcast(transport->endpoint))
> + val = bap->qos.bcast.framing;
> +
> dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &val);
>
> return TRUE;
> @@ -910,6 +942,12 @@ static gboolean get_phy(const GDBusPropertyTable *property,
> struct media_transport *transport = data;
> struct bap_transport *bap = transport->data;
>
> + if (media_endpoint_is_broadcast(transport->endpoint)) {
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.io_qos.phy);
> + return TRUE;
> + }
> +
> dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> &bap->qos.ucast.io_qos.phy);
>
> @@ -922,6 +960,12 @@ static gboolean get_sdu(const GDBusPropertyTable *property,
> struct media_transport *transport = data;
> struct bap_transport *bap = transport->data;
>
> + if (media_endpoint_is_broadcast(transport->endpoint)) {
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
> + &bap->qos.bcast.io_qos.sdu);
> + return TRUE;
> + }
> +
> dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
> &bap->qos.ucast.io_qos.sdu);
>
> @@ -1040,6 +1084,121 @@ static gboolean get_links(const GDBusPropertyTable *property,
> return TRUE;
> }
>
> +static gboolean get_sync_interval(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.sync_interval);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_packing(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.packing);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_bcode(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> + DBusMessageIter array;
> +
> + dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
> + DBUS_TYPE_BYTE_AS_STRING, &array);
> +
> + if (bap->qos.bcast.bcode && bap->qos.bcast.bcode->iov_len)
> + dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.bcode->iov_base,
> + bap->qos.bcast.bcode->iov_len);
> +
> + dbus_message_iter_close_container(iter, &array);
> + return TRUE;
> +}
> +
> +static gboolean get_options(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.options);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_skip(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
> + &bap->qos.bcast.skip);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_sync_timeout(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
> + &bap->qos.bcast.sync_timeout);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_sync_cte_type(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.sync_cte_type);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_mse(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
> + &bap->qos.bcast.mse);
> +
> + return TRUE;
> +}
> +
> +static gboolean get_timeout(const GDBusPropertyTable *property,
> + DBusMessageIter *iter, void *data)
> +{
> + struct media_transport *transport = data;
> + struct bap_transport *bap = transport->data;
> +
> + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
> + &bap->qos.bcast.timeout);
> +
> + return TRUE;
> +}
> +
> static const GDBusPropertyTable bap_properties[] = {
> { "Device", "o", get_device },
> { "UUID", "s", get_uuid },
> @@ -1059,6 +1218,17 @@ static const GDBusPropertyTable bap_properties[] = {
> { "Location", "u", get_location },
> { "Metadata", "ay", get_metadata },
> { "Links", "ao", get_links, NULL, links_exists },
> + { "BIG", "y", get_big, NULL, qos_exists },
> + { "BIS", "y", get_bis, NULL, qos_exists },
> + { "SyncInterval", "y", get_sync_interval, NULL, qos_exists },
> + { "Packing", "y", get_packing, NULL, qos_exists },
> + { "BCode", "ay", get_bcode, NULL, qos_exists },
> + { "Options", "y", get_options, NULL, qos_exists },
> + { "Skip", "q", get_skip, NULL, qos_exists },
> + { "SyncTimeout", "q", get_sync_timeout, NULL, qos_exists },
> + { "SyncCteType", "y", get_sync_cte_type, NULL, qos_exists },
> + { "MSE", "y", get_mse, NULL, qos_exists },
> + { "Timeout", "q", get_timeout, NULL, qos_exists },
> { }
> };
>
> @@ -1341,6 +1511,71 @@ static gboolean bap_resume_wait_cb(void *data)
> return FALSE;
> }
>
> +static void bap_update_bcast_qos(const struct media_transport *transport)
> +{
> + struct bap_transport *bap = transport->data;
> + struct bt_bap_qos *qos;
> +
> + qos = bt_bap_stream_get_qos(bap->stream);
> +
> + if (!memcmp(qos, &bap->qos, sizeof(struct bt_bap_qos)))
> + return;
> +
> + bap->qos = *qos;
> +
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "BIG");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "BIS");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "SyncInterval");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "Packing");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "Framing");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "BCode");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "Options");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "Skip");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "SyncTimeout");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "SyncCteType");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "MSE");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "Timeout");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "Interval");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "Latency");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "PHY");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "SDU");
> + g_dbus_emit_property_changed(btd_get_dbus_connection(),
> + transport->path, MEDIA_TRANSPORT_INTERFACE,
> + "RTN");
> +}
> +
> static guint resume_bap(struct media_transport *transport,
> struct media_owner *owner)
> {
> @@ -1493,7 +1728,10 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
> if (owner && owner->pending)
> return;
> bap_update_links(transport);
> - bap_update_qos(transport);
> + if (!media_endpoint_is_broadcast(transport->endpoint))
> + bap_update_qos(transport);
> + else if (bt_bap_stream_io_dir(stream) != BT_BAP_BCAST_SOURCE)
> + bap_update_bcast_qos(transport);
> transport_update_playing(transport, FALSE);
> return;
> case BT_BAP_STREAM_STATE_DISABLING:
> @@ -1503,6 +1741,8 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
> return;
> break;
> case BT_BAP_STREAM_STATE_STREAMING:
> + if (bt_bap_stream_io_dir(stream) == BT_BAP_BCAST_SOURCE)
> + bap_update_bcast_qos(transport);
> break;
> }
>
> @@ -1631,7 +1871,8 @@ struct media_transport *media_transport_create(struct btd_device *device,
> properties = a2dp_properties;
> } else if (!strcasecmp(uuid, PAC_SINK_UUID) ||
> !strcasecmp(uuid, PAC_SOURCE_UUID) ||
> - !strcasecmp(uuid, BCAA_SERVICE_UUID)) {
> + !strcasecmp(uuid, BCAA_SERVICE_UUID) ||
> + !strcasecmp(uuid, BAA_SERVICE_UUID)) {
> if (media_transport_init_bap(transport, stream) < 0)
> goto fail;
> properties = bap_properties;
> --
> 2.34.1
>


--
Luiz Augusto von Dentz