shared/bass: Introduce Add Source opcode handler
Subsystems (2)
cover shared/bass: Introduce Add Source opcode handler
This patch series adds the BASS control point handler for the Add Source operation.
If instructed by a Client through the Add Source opcode, the BASS Server attempts to synchronize to a Broadcast Source, by opening a btio channel.
The BT_IO_OPT_ISO_BC_ADDR btio option has been added, to allow binding a socket to a broadcast address.
The BASS adapter_probe callback has been implemented, in order to automatically configure BASS into the adapter database. The adapter bdaddr is also stored along with the BASS database configuration, and this address will be used as the source address when binding the btio channel.
Iulia Tanasescu (2):
btio: Add option for binding iso broadcast address shared/bass: Introduce Add Source opcode handler
Makefile.am | 2 +- btio/btio.c | 56 +++++- btio/btio.h | 3 +- profiles/audio/bass.c | 26 ++- src/shared/bass.c | 424 ++++++++++++++++++++++++++++++++++++++++-- src/shared/bass.h | 14 +- unit/test-bass.c | 2 +- 7 files changed, 498 insertions(+), 29 deletions(-)
base-commit: 37042ca9c6ddcdbbb0899b3d62238935cd53f443
Signature · 1 line
2.34.1
PATCH 1/2 btio: Add option for binding iso broadcast address
This adds the BT_IO_OPT_ISO_BC_ADDR btio option, to allow the user to set the iso_bc field of an address at bind.
--- btio/btio.c | 56 +++++++++++++++++++++++++++++++++++++++++++---------- btio/btio.h | 3 ++- 2 files changed, 48 insertions(+), 11 deletions(-)
btio/btio.c +46 -10
@@ -16,6 +16,7 @@#include <stdarg.h> #include <stdlib.h> +#include <stdbool.h> #include <unistd.h> #include <errno.h> #include <poll.h>
@@ -71,6 +72,8 @@ struct set_opts {uint16_t voice;struct bt_iso_qos qos;struct bt_iso_base base; +struct sockaddr_iso_bc iso_bc_addr; +bool bc_addr_set; };struct connect {
@@ -771,21 +774,40 @@ static int sco_bind(int sock, const bdaddr_t *src, GError **err) }static int iso_bind (int sock,const bdaddr_t *src,uint8_t src_type, -GError **err) +struct sockaddr_iso_bc *bc_addr, +GError **err) { -struct sockaddr_iso addr; +struct sockaddr_iso *addr =NULL ; +size_t addr_len; +int ret =0 ; -memset (&addr,0 ,sizeof (addr)); - addr.iso_family =AF_BLUETOOTH ; -bacpy (&addr.iso_bdaddr, src); - addr.iso_bdaddr_type = src_type; +if (bc_addr) + addr_len =sizeof (*addr) +sizeof (*addr->iso_bc); +else + addr_len =sizeof (*addr); + + addr =malloc (addr_len); + +if (!addr) +return -ENOMEM ; -if (!bind (sock, (struct sockaddr *) &addr,sizeof (addr))) -return 0 ; +memset (addr,0 , addr_len); + addr->iso_family =AF_BLUETOOTH ; +bacpy (&addr->iso_bdaddr, src); + addr->iso_bdaddr_type = src_type; +if (bc_addr) +memcpy (addr->iso_bc, bc_addr,sizeof (*bc_addr)); + +if (!bind (sock, (struct sockaddr *)addr, addr_len)) + goto done; + + ret = -errno;ERROR_FAILED (err,"iso_bind" , errno); -return -errno; +done: +free (addr); +return ret; }static int sco_connect (int sock,const bdaddr_t *dst)
@@ -980,6 +1002,11 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,case BT_IO_OPT_BASE : opts->base = *va_arg(args, struct bt_iso_base *);break ; +case BT_IO_OPT_ISO_BC_ADDR : + opts->iso_bc_addr = *va_arg (args, + struct sockaddr_iso_bc *); + opts->bc_addr_set = true; +break ;case BT_IO_OPT_INVALID :case BT_IO_OPT_KEY_SIZE :case BT_IO_OPT_SOURCE_CHANNEL :
@@ -1305,6 +1332,7 @@ parse_opts:case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :case BT_IO_OPT_BASE : +case BT_IO_OPT_ISO_BC_ADDR :default :g_set_error (err,BT_IO_ERROR ,EINVAL ,"Unknown option %d" , opt);
@@ -1460,6 +1488,7 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1,case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :case BT_IO_OPT_BASE : +case BT_IO_OPT_ISO_BC_ADDR :case BT_IO_OPT_INVALID :default : g_set_error(err, BT_IO_ERROR, EINVAL,
@@ -1571,6 +1600,7 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args)case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :case BT_IO_OPT_BASE : +case BT_IO_OPT_ISO_BC_ADDR :case BT_IO_OPT_INVALID :default : g_set_error(err, BT_IO_ERROR, EINVAL,
@@ -1660,6 +1690,7 @@ static gboolean iso_get(int sock, GError **err, BtIOOption opt1, va_list args)case BT_IO_OPT_FLUSHABLE :case BT_IO_OPT_PRIORITY :case BT_IO_OPT_VOICE : +case BT_IO_OPT_ISO_BC_ADDR :case BT_IO_OPT_INVALID :default : g_set_error(err, BT_IO_ERROR, EINVAL,
@@ -1790,6 +1821,7 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts, {int sock;GIOChannel *io; +struct sockaddr_iso_bc *iso_bc_addr =NULL ;switch (opts->type) {case BT_IO_L2CAP :
@@ -1836,7 +1868,11 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts,ERROR_FAILED (err,"socket(SEQPACKET, ISO)" , errno);return NULL ; } -if (iso_bind (sock, &opts->src, opts->src_type, err) <0 ) +if (opts->bc_addr_set) + iso_bc_addr = &opts->iso_bc_addr; + +if (iso_bind (sock, &opts->src, opts->src_type, + iso_bc_addr, err) <0 ) goto failed;if (!iso_set_qos (sock, &opts->qos, err)) goto failed;
btio/btio.h +2 -1
@@ -46,7 +46,8 @@ typedef enum {BT_IO_OPT_VOICE ,BT_IO_OPT_PHY ,BT_IO_OPT_QOS , - BT_IO_OPT_BASE +BT_IO_OPT_BASE , +BT_IO_OPT_ISO_BC_ADDR , } BtIOOption; typedef enum {
Signature · 1 line
2.34.1
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=759717
---Test result---
Test Summary:
CheckPatch PASS 1.71 seconds GitLint PASS 0.77 seconds BuildEll PASS 31.78 seconds BluezMake PASS 1072.85 seconds MakeCheck PASS 12.32 seconds MakeDistcheck PASS 169.38 seconds CheckValgrind PASS 277.82 seconds CheckSmatch PASS 422.93 seconds bluezmakeextell PASS 119.27 seconds IncrementalBuild PASS 1911.14 seconds ScanBuild PASS 1314.19 seconds
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 1/2] btio: Add option for binding iso broadcast address
In reply to Iulia TanasescuHi Iulia,
Quoted 22 lines · Iulia Tanasescu
This adds the
BT_IO_OPT_ISO_BC_ADDRbtio option, to allow the user to set theiso_bcfield of an address at bind.--- btio/btio.c | 56 +++++++++++++++++++++++++++++++++++++++++++---------- btio/btio.h | 3 ++- 2 files changed, 48 insertions(+), 11 deletions(-)btio/btio.c +1
-0@@ -16,6 +16,7 @@#include <stdarg.h> #include <stdlib.h> +#include <stdbool.h> #include <unistd.h> #include <errno.h> #include <poll.h>
btio/btio.c struct set_opts { · line 76
Quoted 5 lines
btio/btio.c +2
-0@@ -71,6 +72,8 @@ struct set_opts {uint16_t voice;struct bt_iso_qos qos;struct bt_iso_base base; +struct sockaddr_iso_bc iso_bc_addr; +bool bc_addr_set;
I guess we could just check for BDADDR_ANY instead of using a dedicated field.
Quoted 135 lines
btio/btio.c +43
-10};struct connect {@@ -771,21 +774,40 @@ static int sco_bind(int sock, const bdaddr_t *src, GError **err) }static int iso_bind (int sock,const bdaddr_t *src,uint8_t src_type, -GError **err) +struct sockaddr_iso_bc *bc_addr, +GError **err) { -struct sockaddr_iso addr; +struct sockaddr_iso *addr =NULL ; +size_t addr_len; +int ret =0 ; -memset (&addr,0 ,sizeof (addr)); - addr.iso_family =AF_BLUETOOTH ; -bacpy (&addr.iso_bdaddr, src); - addr.iso_bdaddr_type = src_type; +if (bc_addr) + addr_len =sizeof (*addr) +sizeof (*addr->iso_bc); +else + addr_len =sizeof (*addr); + + addr =malloc (addr_len); + +if (!addr) +return -ENOMEM ; -if (!bind (sock, (struct sockaddr *) &addr,sizeof (addr))) -return 0 ; +memset (addr,0 , addr_len); + addr->iso_family =AF_BLUETOOTH ; +bacpy (&addr->iso_bdaddr, src); + addr->iso_bdaddr_type = src_type; +if (bc_addr) +memcpy (addr->iso_bc, bc_addr,sizeof (*bc_addr)); + +if (!bind (sock, (struct sockaddr *)addr, addr_len)) + goto done; + + ret = -errno;ERROR_FAILED (err,"iso_bind" , errno); -return -errno; +done: +free (addr); +return ret; }static int sco_connect (int sock,const bdaddr_t *dst)@@ -980,6 +1002,11 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,case BT_IO_OPT_BASE : opts->base = *va_arg(args, struct bt_iso_base *);break ; +case BT_IO_OPT_ISO_BC_ADDR : + opts->iso_bc_addr = *va_arg (args, + struct sockaddr_iso_bc *); + opts->bc_addr_set = true; +break ;case BT_IO_OPT_INVALID :case BT_IO_OPT_KEY_SIZE :case BT_IO_OPT_SOURCE_CHANNEL :@@ -1305,6 +1332,7 @@ parse_opts:case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :case BT_IO_OPT_BASE : +case BT_IO_OPT_ISO_BC_ADDR :default :g_set_error (err,BT_IO_ERROR ,EINVAL ,"Unknown option %d" , opt);@@ -1460,6 +1488,7 @@ static gboolean rfcomm_get(int sock, GError **err, BtIOOption opt1,case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :case BT_IO_OPT_BASE : +case BT_IO_OPT_ISO_BC_ADDR :case BT_IO_OPT_INVALID :default : g_set_error(err, BT_IO_ERROR, EINVAL,@@ -1571,6 +1600,7 @@ static gboolean sco_get(int sock, GError **err, BtIOOption opt1, va_list args)case BT_IO_OPT_VOICE :case BT_IO_OPT_QOS :case BT_IO_OPT_BASE : +case BT_IO_OPT_ISO_BC_ADDR :case BT_IO_OPT_INVALID :default : g_set_error(err, BT_IO_ERROR, EINVAL,@@ -1660,6 +1690,7 @@ static gboolean iso_get(int sock, GError **err, BtIOOption opt1, va_list args)case BT_IO_OPT_FLUSHABLE :case BT_IO_OPT_PRIORITY :case BT_IO_OPT_VOICE : +case BT_IO_OPT_ISO_BC_ADDR :case BT_IO_OPT_INVALID :default : g_set_error(err, BT_IO_ERROR, EINVAL,@@ -1790,6 +1821,7 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts, {int sock;GIOChannel *io; +struct sockaddr_iso_bc *iso_bc_addr =NULL ;switch (opts->type) {case BT_IO_L2CAP :@@ -1836,7 +1868,11 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts,ERROR_FAILED (err,"socket(SEQPACKET, ISO)" , errno);return NULL ; } -if (iso_bind (sock, &opts->src, opts->src_type, err) <0 ) +if (opts->bc_addr_set) + iso_bc_addr = &opts->iso_bc_addr; + +if (iso_bind (sock, &opts->src, opts->src_type, + iso_bc_addr, err) <0 ) goto failed;if (!iso_set_qos (sock, &opts->qos, err)) goto failed;btio/btio.h +2
-2@@ -46,7 +46,8 @@ typedef enum {BT_IO_OPT_VOICE ,BT_IO_OPT_PHY ,BT_IO_OPT_QOS , - BT_IO_OPT_BASE +BT_IO_OPT_BASE , +BT_IO_OPT_ISO_BC_ADDR , } BtIOOption; typedef enum { --2.34.1
Signature · 1 line
Luiz Augusto von Dentz
PATCH 2/2 shared/bass: Introduce Add Source opcode handler
In reply to Iulia TanasescuThis implements the Control Point handler for the Add Source operation.
--- Makefile.am | 2 +- profiles/audio/bass.c | 26 ++- src/shared/bass.c | 424 ++++++++++++++++++++++++++++++++++++++++-- src/shared/bass.h | 14 +- unit/test-bass.c | 2 +- 5 files changed, 450 insertions(+), 18 deletions(-)
Makefile.am +1 -1
@@ -580,7 +580,7 @@ unit_test_bap_LDADD = src/libshared-glib.la \ unit_tests += unit/test-bass -unit_test_bass_SOURCES = unit/test-bass.c +unit_test_bass_SOURCES = unit/test-bass.c $(btio_sources) unit_test_bass_LDADD = src/libshared-glib.la \ lib/libbluetooth-internal.la $(GLIB_LIBS)
profiles/audio/bass.c +24 -2
@@ -37,10 +37,10 @@#include "src/shared/gatt-db.h" #include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" +#include "src/adapter.h" #include "src/shared/bass.h" #include "src/plugin.h" -#include "src/adapter.h" #include "src/gatt-database.h" #include "src/device.h" #include "src/profile.h"
@@ -197,7 +197,8 @@ static int bass_probe(struct btd_service *service) data->service = service; data->bass =bt_bass_new (btd_gatt_database_get_db (database), -btd_device_get_gatt_db (device)); +btd_device_get_gatt_db (device), +btd_adapter_get_address (adapter));if (!data->bass) {error ("Unable to create BASS instance" );free (data);
@@ -268,6 +269,25 @@ static int bass_disconnect(struct btd_service *service)return 0 ; } +static int bass_server_probe (struct btd_profile *p, +struct btd_adapter *adapter) +{ +struct btd_gatt_database *database =btd_adapter_get_database (adapter); + +DBG ("BASS path %s" ,adapter_get_path (adapter)); + +bt_bass_add_db (btd_gatt_database_get_db (database), +btd_adapter_get_address (adapter)); + +return 0 ; +} + +static void bass_server_remove (struct btd_profile *p, +struct btd_adapter *adapter) +{ +DBG ("BASS remove Adapter" ); +} +static struct btd_profile bass_service = { .name ="bass" , .priority =BTD_PROFILE_PRIORITY_MEDIUM ,
@@ -276,6 +296,8 @@ static struct btd_profile bass_service = { .device_remove = bass_remove, .accept = bass_accept, .disconnect = bass_disconnect, + .adapter_probe = bass_server_probe, + .adapter_remove = bass_server_remove, .experimental = true, };
src/shared/bass.c +411 -13
575 lines not on this page · raw message
src/shared/bass.h +13 -1
@@ -56,6 +56,8 @@ struct bt_bcast_src {uint8_t bad_code[BT_BASS_BCAST_CODE_SIZE ];uint8_t num_subgroups;struct bt_bass_subgroup_data *subgroup_data; +GIOChannel *listen_io; +struct queue *bises; };/* Broadcast Audio Scan Control Point
@@ -71,6 +73,14 @@ struct bt_bass_bcast_audio_scan_cp_hdr {#define BT_BASS_ADD_SRC 0x02 +/* PA_Sync values */ +#define PA_SYNC_NO_SYNC 0x00 +#define PA_SYNC_PAST 0x01 +#define PA_SYNC_NO_PAST 0x02 + +/* BIS_Sync no preference bitmask */ +#define BIS_SYNC_NO_PREF 0xFFFFFFFF +struct bt_bass_add_src_params {uint8_t addr_type;bdaddr_t addr;
@@ -115,8 +125,10 @@ unsigned int bt_bass_register(bt_bass_func_t attached, bt_bass_func_t detached,bool bt_bass_unregister (unsigned int id);bool bt_bass_set_debug (struct bt_bass *bass,bt_bass_debug_func_t func,void *user_data,bt_bass_destroy_func_t destroy); -struct bt_bass *bt_bass_new (struct gatt_db *ldb,struct gatt_db *rdb); +struct bt_bass *bt_bass_new (struct gatt_db *ldb,struct gatt_db *rdb, +const bdaddr_t *adapter_bdaddr);bool bt_bass_set_user_data (struct bt_bass *bass,void *user_data);void bt_bass_unref (struct bt_bass *bass);bool bt_bass_attach (struct bt_bass *bass,struct bt_gatt_client *client);void bt_bass_detach (struct bt_bass *bass); +void bt_bass_add_db (struct gatt_db *db,const bdaddr_t *adapter_bdaddr);
unit/test-bass.c +1 -1
@@ -309,7 +309,7 @@ static void test_server(const void *user_data)gatt_db_ccc_register (data->db, gatt_ccc_read_cb,NULL ,NULL , data); - data->bass =bt_bass_new (data->db,NULL ); + data->bass =bt_bass_new (data->db,NULL ,BDADDR_ANY );g_assert (data->bass); data->server =bt_gatt_server_new (data->db, att,64 ,0 );
Signature · 1 line
2.34.1
Luiz Augusto von Dentz
maintainerHi Iulia,
Quoted 10 lines · Iulia Tanasescu
This patch series adds the BASS control point handler for the Add Source operation.
If instructed by a Client through the Add Source opcode, the BASS Server attempts to synchronize to a Broadcast Source, by opening a btio channel.
The
BT_IO_OPT_ISO_BC_ADDRbtio option has been added, to allow binding a socket to a broadcast address.
Im having second thoughts on this, Im not sure if it is a good idea to introduce BT_IO_OPT_ISO_BC_ADDR, there are already options to set the address and address type, perhaps we should add what is missing e.g. num of bis, etc. At least on iso-test the logic I used was that if a destination is given for listen then it must be a broadcast address.
Quoted 24 lines
The BASS
adapter_probecallback has been implemented, in order to automatically configure BASS into the adapter database. The adapter bdaddr is also stored along with the BASS database configuration, and this address will be used as the source address when binding the btio channel.Iulia Tanasescu (2):
btio: Add option for binding iso broadcast address shared/bass: Introduce Add Source opcode handlerMakefile.am | 2 +- btio/btio.c | 56 +++++- btio/btio.h | 3 +- profiles/audio/bass.c | 26 ++- src/shared/bass.c | 424 ++++++++++++++++++++++++++++++++++++++++-- src/shared/bass.h | 14 +- unit/test-bass.c | 2 +- 7 files changed, 498 insertions(+), 29 deletions(-)base-commit:
37042ca9c6ddcdbbb0899b3d62238935cd53f443--
2.34.1
Signature · 1 line
Luiz Augusto von Dentz