Skip to content

Commit

Permalink
btio: Bind listener to bcaster addr based on dst opt
Browse files Browse the repository at this point in the history
This updates the btio module to decide whether to bind a listening socket
to a broadcaster address or not, by looking at the dst address.
  • Loading branch information
iulia-tanasescu authored and Vudentz committed Oct 5, 2023
1 parent 90af802 commit 769268f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions btio/btio.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,16 +774,21 @@ static int sco_bind(int sock, const bdaddr_t *src, GError **err)
return 0;
}

static int iso_bind(int sock, const bdaddr_t *src, uint8_t src_type,
const bdaddr_t *dst, uint8_t dst_type,
uint8_t bc_sid, uint8_t num_bis,
uint8_t *bis, GError **err)
static int iso_bind(int sock, bool server, const bdaddr_t *src,
uint8_t src_type, const bdaddr_t *dst,
uint8_t dst_type, uint8_t bc_sid,
uint8_t num_bis, uint8_t *bis,
GError **err)
{
struct sockaddr_iso *addr = NULL;
size_t addr_len;
int ret = 0;

if (num_bis)
/* If this is an ISO listener and the destination address
* is not BDADDR_ANY, the listener should be bound to the
* broadcaster address
*/
if (server && bacmp(dst, BDADDR_ANY))
addr_len = sizeof(*addr) + sizeof(*addr->iso_bc);
else
addr_len = sizeof(*addr);
Expand All @@ -798,7 +803,7 @@ static int iso_bind(int sock, const bdaddr_t *src, uint8_t src_type,
bacpy(&addr->iso_bdaddr, src);
addr->iso_bdaddr_type = src_type;

if (num_bis) {
if (addr_len > sizeof(*addr)) {
bacpy(&addr->iso_bc->bc_bdaddr, dst);
addr->iso_bc->bc_bdaddr_type = dst_type;
addr->iso_bc->bc_sid = bc_sid;
Expand Down Expand Up @@ -1930,10 +1935,9 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts,
return NULL;
}

if (iso_bind(sock, &opts->src, opts->src_type,
&opts->dst, opts->dst_type,
opts->bc_sid, opts->bc_num_bis,
opts->bc_bis, err) < 0)
if (iso_bind(sock, server, &opts->src, opts->src_type,
&opts->dst, opts->dst_type, opts->bc_sid,
opts->bc_num_bis, opts->bc_bis, err) < 0)
goto failed;
if (!iso_set_qos(sock, &opts->qos, err))
goto failed;
Expand Down
4 changes: 2 additions & 2 deletions profiles/audio/bap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1705,9 +1705,9 @@ static void bap_listen_io(struct bap_data *data, struct bt_bap_stream *stream,
BT_IO_OPT_SOURCE_BDADDR,
btd_adapter_get_address(adapter),
BT_IO_OPT_DEST_BDADDR,
device_get_address(data->device),
BDADDR_ANY,
BT_IO_OPT_DEST_TYPE,
device_get_le_address_type(data->device),
BDADDR_LE_PUBLIC,
BT_IO_OPT_MODE, BT_IO_MODE_ISO,
BT_IO_OPT_QOS, qos,
BT_IO_OPT_INVALID);
Expand Down

0 comments on commit 769268f

Please sign in to comment.