Skip to content

Commit

Permalink
btio: Allow binding a bcast listener before accept
Browse files Browse the repository at this point in the history
This adds btio support for binding a PA sync io to a number of BISes,
before proceeding with BIG Create Sync.
  • Loading branch information
iulia-tanasescu authored and Vudentz committed Oct 24, 2023
1 parent a17455c commit 00fdb61
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 7 deletions.
55 changes: 54 additions & 1 deletion btio/btio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1796,14 +1796,67 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data,

gboolean bt_io_bcast_accept(GIOChannel *io, BtIOConnect connect,
gpointer user_data, GDestroyNotify destroy,
GError * *err)
GError * *err, BtIOOption opt1, ...)
{
int sock;
char c;
struct pollfd pfd;
va_list args;
struct sockaddr_iso *addr = NULL;
uint8_t bc_num_bis = 0;
uint8_t bc_bis[ISO_MAX_NUM_BIS] = {0};
BtIOOption opt = opt1;

va_start(args, opt1);

while (opt != BT_IO_OPT_INVALID) {
if (opt == BT_IO_OPT_ISO_BC_NUM_BIS) {
bc_num_bis = va_arg(args, int);
} else if (opt == BT_IO_OPT_ISO_BC_BIS) {
memcpy(bc_bis, va_arg(args, uint8_t *),
bc_num_bis);
} else {
g_set_error(err, BT_IO_ERROR, EINVAL,
"Invalid option %d", opt);
break;
}

opt = va_arg(args, int);
}

va_end(args);

if (*err)
return FALSE;

sock = g_io_channel_unix_get_fd(io);

if (bc_num_bis) {
addr = malloc(sizeof(*addr) + sizeof(*addr->iso_bc));

if (!addr) {
ERROR_FAILED(err, "poll", ENOMEM);
return FALSE;
}

memset(addr, 0, sizeof(*addr) + sizeof(*addr->iso_bc));
addr->iso_family = AF_BLUETOOTH;

addr->iso_bc->bc_num_bis = bc_num_bis;
memcpy(addr->iso_bc->bc_bis, bc_bis,
addr->iso_bc->bc_num_bis);

if (bind(sock, (struct sockaddr *)addr,
sizeof(*addr) + sizeof(*addr->iso_bc)) < 0) {
ERROR_FAILED(err, "bind", errno);
}

free(addr);

if (*err)
return FALSE;
}

memset(&pfd, 0, sizeof(pfd));
pfd.fd = sock;
pfd.events = POLLOUT;
Expand Down
2 changes: 1 addition & 1 deletion btio/btio.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data,

gboolean bt_io_bcast_accept(GIOChannel *io, BtIOConnect connect,
gpointer user_data, GDestroyNotify destroy,
GError **err);
GError **err, BtIOOption opt1, ...);

gboolean bt_io_set(GIOChannel *io, GError **err, BtIOOption opt1, ...);

Expand Down
2 changes: 1 addition & 1 deletion profiles/audio/bap.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ static void iso_pa_sync_confirm_cb(GIOChannel *io, void *user_data)
GError *err = NULL;

if (!bt_io_bcast_accept(io, iso_bcast_confirm_cb,
user_data, NULL, &err)) {
user_data, NULL, &err, BT_IO_OPT_INVALID)) {
error("bt_io_bcast_accept: %s", err->message);
g_error_free(err);
g_io_channel_shutdown(io, TRUE, NULL);
Expand Down
9 changes: 5 additions & 4 deletions src/shared/bass.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,9 @@ static void confirm_cb(GIOChannel *io, gpointer user_data)

if (bass_trigger_big_sync(bcast_src)) {
if (!bt_io_bcast_accept(bcast_src->pa_sync_io,
connect_cb, bcast_src, NULL, &gerr)) {
DBG(bcast_src->bass, "bt_io_accept: %s",
connect_cb, bcast_src, NULL, &gerr,
BT_IO_OPT_INVALID)) {
DBG(bcast_src->bass, "bt_io_bcast_accept: %s",
gerr->message);
g_error_free(gerr);
}
Expand Down Expand Up @@ -1129,8 +1130,8 @@ static void bass_handle_set_bcast_code_op(struct bt_bass *bass,
}

if (!bt_io_bcast_accept(bcast_src->pa_sync_io, connect_cb,
bcast_src, NULL, &gerr)) {
DBG(bcast_src->bass, "bt_io_accept: %s", gerr->message);
bcast_src, NULL, &gerr, BT_IO_OPT_INVALID)) {
DBG(bcast_src->bass, "bt_io_bcast_accept: %s", gerr->message);
g_error_free(gerr);
}
}
Expand Down

0 comments on commit 00fdb61

Please sign in to comment.