Add Scan Delegator support for Add Source op
v2 cover Add Scan Delegator support for Add Source op
This adds support for the BAP Scan Delegator role to handle the Add Source command received from a Broadcast Assistant.
The Broadcast Assistant informs a Scan Delegator about a Broadcaster by sending a GATT write command for the BASS Broadcast Audio Scan Control Point characteristic with the "Add Source" opcode. Using the parameters received through GATT, the Scan Delegator creates a device for the Broadcaster and probes it with BAP. The BAP plugin will then perform long-lived PA sync and it will create streams for each BIS required by the Assistant. The transports can then be acquired/released, and the Assistant will be notified about each change in the state of the streams.
The bluetoothctl and btmon logs below show an example of this scenario:
client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06 [/local/endpoint/ep0] Auto Accept (yes/no): y [/local/endpoint/ep0] Max Transports (auto/value): a [/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1 [bluetooth]# Endpoint /local/endpoint/ep0 registered [bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F [00-60-37-31-7E-3F]# [NEW] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA [00-60-37-31-7E-3F]# [NEW] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Endpoint: SetConfiguration
[00-60-37-31-7E-3F]# Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Properties.Device:
/org/bluez/hci1/dev_03_E2_C0_11_57_DA
[00-60-37-31-7E-3F]# Auto Accepting...
[00-60-37-31-7E-3F]# transport.select
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# [CHG] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: broadcasting
[00-60-37-31-7E-3F]# transport.acquire
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
auto acquiring...
Transport /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 acquiring
[00-60-37-31-7E-3F]# Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 acquiring complete
[00-60-37-31-7E-3F]# Acquire successful: fd 8 MTU 40:0
[00-60-37-31-7E-3F]# [CHG] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: active
[00-60-37-31-7E-3F]# transport.release
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Transport fd disconnected
[00-60-37-31-7E-3F]# [CHG] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: idle[00-60-37-31-7E-3F]# Release successful
Quoted 1 line
ACL Data RX: Handle 0 flags
0x01dlen 1
ATT: Write Command (0x52) len 23
Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
Data[21]: 0201da5711c0e203001a2d5602ffff010100000000
Opcode: Add Source (0x02)
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronize to PA - PAST not available
PA_Interval: 0xffff
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000001
< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044)
Options: 0x0000
Use advertising SID, Advertiser Address Type and address
Reporting initially enabled
SID: 0x00
Adv address type: Random (0x01)
Adv address: 03:E2:C0:11:57:DA (Non-Resolvable)
Skip: 0x0000
Sync timeout: 20000 msec (0x07d0)
Sync CTE type: 0x0000Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
Status: Success (0x00)Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 16
LE Periodic Advertising Sync Established (0x0e)
Status: Success (0x00)
Sync handle: 0
Advertising SID: 0x00
Advertiser address type: Random (0x01)
Advertiser address: 03:E2:C0:11:57:DA (Non-Resolvable)
Advertiser PHY: LE 2M (0x02)
Periodic advertising interval: 10.00 msec (0x0008)
Advertiser clock accuracy: 0x07Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 42
LE Periodic Advertising Report (0x0f)
Sync handle: 0
TX power: 127 dbm (0x7f)
RSSI: -64 dBm (0xc0)
CTE Type: No Constant Tone Extension (0xff)
Data status: Complete
Data length: 0x22
Service Data: Basic Audio Announcement (0x1851)
Presetation Delay: 40000
Number of Subgroups: 1
Subgroup #0:
Number of BIS(s): 1
Codec: LC3 (0x06)
Codec Specific Configuration: #0: len 0x02 type 0x01
Codec Specific Configuration: Sampling Frequency: 16 Khz
Codec Specific Configuration: #1: len 0x02 type 0x02
Codec Specific Configuration: Frame Duration: 10 ms (0x01)
Codec Specific Configuration: #2: len 0x03 type 0x04
Codec Specific Configuration: Frame Length: 40 (0x0028)
Codec Specific Configuration: #3: len 0x05 type 0x03
Codec Specific Configuration: Location: 0x00000001
Codec Specific Configuration: Location: Front Left
BIS #0:
Index: 1Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 20
LE Broadcast Isochronous Group Info Advertising Report (0x22)
Sync Handle: 0x0000
Number BIS: 1
NSE: 3
ISO Interval: 10.00 msec (0x0008)
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
SDU Interval: 10000 us (0x002710)
Maximum SDU: 40
PHY: LE 2M (0x02)
Framing: Unframed (0x00)
Encryption: 0x00
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101da5711c0e203001a2d560200010000000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000000
< HCI Command: LE Broadcast Isochronous Group Create Sync (0x08|0x006b)
BIG Handle: 0x00
BIG Sync Handle: 0x0000
Encryption: Unencrypted (0x00)
Broadcast Code[16]: 00000000000000000000000000000000
Maximum Number Subevents: 0x00
Timeout: 20000 ms (0x07d0)
Number of BIS: 1
BIS ID: 0x01Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Broadcast Isochronous Group Create Sync (0x08|0x006b) ncmd 1
Status: Success (0x00Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 17
LE Broadcast Isochronous Group Sync Estabilished (0x1d)
Status: Success (0x00)
BIG Handle: 0x00
Transport Latency: 912 us (0x000390)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Output (Controller to Host) (0x01)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration[0]:Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101da5711c0e203001a2d560200010100000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000001
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101da5711c0e203001a2d560200010000000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000000
< HCI Command: LE Broadcast Isochronous Group Terminate Sync (0x08|0x006c)
BIG Handle: 0x00Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 5
LE Broadcast Isochronous Group Terminate Sync (0x08|0x006c) ncmd 1
Status: Success (0x00)Iulia Tanasescu (16):
shared/bass: Register ATT disconnect cb shared/bass: Make bt_bcast_src private shared/bass: Remove io handling shared/bass: Add support to register cp handlers shared/bass: Call cp handler for the Add Source cmd
bap: Add support for long-lived PA sync
bap: Add API for Scan Delegator probe
bass: Register cp handler for Add Source cmd shared/bass: Add API to set PA sync state
bass: Add APIs to probe/remove Broadcasters
bap: Probe Broadcasters with BASS shared/bass: Add APIs to set/clear BIS sync bits
bass: Register BAP state changed cb shared/bass: Add API to check BIS required for sync
bass: Add API to check BIS required for sync
bap: Create streams for required BISes
profiles/audio/bap.c | 124 +++++++-- profiles/audio/bap.h | 1 + profiles/audio/bass.c | 202 +++++++++++++++ profiles/audio/bass.h | 5 + src/shared/bass.c | 587 +++++++++++++++++++----------------------- src/shared/bass.h | 43 +--- 6 files changed, 590 insertions(+), 372 deletions(-)
base-commit: 32a0811685c5dd290f1152bef2dfbde3b2848446
Signature · 1 line
2.39.2
PATCH v2 1/16 shared/bass: Register ATT disconnect cb
This registers an ATT disconnect callback with bass, to properly clean uo the session if the ATT connection is removed.
--- src/shared/bass.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
src/shared/bass.c +45 -1
@@ -73,6 +73,8 @@ struct bt_bass {struct queue *src_cbs; +unsigned int disconn_id; +void *user_data; };
@@ -1579,6 +1581,32 @@ static void bass_attached(void *data, void *user_data) cb->attached (bass, cb->user_data); } +static void bass_disconnected (int err,void *user_data) +{ +struct bt_bass *bass = user_data; + + bass->disconn_id =0 ; + +DBG (bass,"bass %p disconnected err %d" , bass, err); + +bt_bass_detach (bass); +} + +static void bass_attach_att (struct bt_bass *bass,struct bt_att *att) +{ +if (bass->disconn_id) { +if (att ==bt_bass_get_att (bass)) +return ; + +bt_att_unregister_disconnect (bt_bass_get_att (bass), + bass->disconn_id); + } + + bass->disconn_id =bt_att_register_disconnect (att, + bass_disconnected, + bass,NULL ); +} +bool bt_bass_attach (struct bt_bass *bass,struct bt_gatt_client *client) {bt_uuid_t uuid;
@@ -1590,8 +1618,11 @@ bool bt_bass_attach(struct bt_bass *bass, struct bt_gatt_client *client)queue_foreach (bass_cbs, bass_attached, bass); -if (!client) +if (!client) { +if (bass->att) +bass_attach_att (bass, bass->att);return true; + }if (bass->client)return false;
@@ -1600,6 +1631,8 @@ bool bt_bass_attach(struct bt_bass *bass, struct bt_gatt_client *client)if (!bass->client)return false; +bass_attach_att (bass,bt_gatt_client_get_att (client)); +bt_uuid16_create (&uuid,BASS_UUID );gatt_db_foreach_service (bass->rdb->db, &uuid, foreach_bass_service, bass);
@@ -1626,12 +1659,23 @@ static void bass_detached(void *data, void *user_data)void bt_bass_detach (struct bt_bass *bass) { +struct bt_att *att; +if (!queue_remove (sessions, bass))return ; +if (bass->client) + att =bt_gatt_client_get_att (bass->client); +else + att = bass->att; + +bt_att_unregister_disconnect (att, bass->disconn_id); +bt_gatt_client_unref (bass->client); bass->client =NULL ; + bass->att =NULL ; +queue_foreach (bass_cbs, bass_detached, bass); }
Signature · 1 line
2.39.2
PATCH v2 2/16 shared/bass: Make bt_bcast_src private
In reply to Iulia TanasescuThe bt_bcast_src structure holds information for the BASS Broadcast Audio Receive State characteristic. This commit makes this structure private for shared/bass, since this is the only place where GATT characteristics should be handled.
--- src/shared/bass.c | 29 +++++++++++++++++++++++++++++ src/shared/bass.h | 30 +----------------------------- 2 files changed, 30 insertions(+), 29 deletions(-)
src/shared/bass.c +29 -0
@@ -78,6 +78,35 @@ struct bt_bass {void *user_data; }; +/* BASS subgroup field of the Broadcast +* Receive State characteristic +*/ +struct bt_bass_subgroup_data { +uint32_t bis_sync; +uint32_t pending_bis_sync; +uint8_t meta_len; +uint8_t *meta; +}; + +/* BASS Broadcast Source structure */ +struct bt_bcast_src { +struct bt_bass *bass; +struct gatt_db_attribute *attr; +uint8_t id; +uint8_t addr_type; +bdaddr_t addr; +uint8_t sid; +uint32_t bid; +uint8_t sync_state; +uint8_t enc; +uint8_t bad_code[BT_BASS_BCAST_CODE_SIZE ]; +uint8_t num_subgroups; +struct bt_bass_subgroup_data *subgroup_data; +GIOChannel *listen_io; +GIOChannel *pa_sync_io; +struct queue *bises; +}; +typedef void (*bass_notify_t )(struct bt_bass *bass,uint16_t value_handle,const uint8_t *value,uint16_t length,void *user_data);
src/shared/bass.h +1 -29
@@ -8,6 +8,7 @@*/ struct bt_bass ; +struct bt_bcast_src ;#define NUM_BCAST_RECV_STATES 2#define BT_BASS_BCAST_CODE_SIZE 16
@@ -32,35 +33,6 @@ struct bt_bass;#define BT_BASS_BIG_ENC_STATE_DEC 0x02#define BT_BASS_BIG_ENC_STATE_BAD_CODE 0x03 -/* BASS subgroup field of the Broadcast -* Receive State characteristic -*/ -struct bt_bass_subgroup_data { -uint32_t bis_sync; -uint32_t pending_bis_sync; -uint8_t meta_len; -uint8_t *meta; -}; - -/* BASS Broadcast Source structure */ -struct bt_bcast_src { -struct bt_bass *bass; -struct gatt_db_attribute *attr; -uint8_t id; -uint8_t addr_type; -bdaddr_t addr; -uint8_t sid; -uint32_t bid; -uint8_t sync_state; -uint8_t enc; -uint8_t bad_code[BT_BASS_BCAST_CODE_SIZE ]; -uint8_t num_subgroups; -struct bt_bass_subgroup_data *subgroup_data; -GIOChannel *listen_io; -GIOChannel *pa_sync_io; -struct queue *bises; -}; -/* Broadcast Audio Scan Control Point * header structure */
Signature · 1 line
2.39.2
PATCH v2 3/16 shared/bass: Remove io handling
In reply to Iulia TanasescuSocket connect/listen procedures should not be handled inside src/shared. The BASS plugin should be the one to handle these socket operations. This removes IO handling from shared/bass.
--- src/shared/bass.c | 315 +--------------------------------------------- 1 file changed, 2 insertions(+), 313 deletions(-)
src/shared/bass.c +2 -313
@@ -14,13 +14,9 @@#include <stdbool.h> #include <unistd.h> #include <errno.h> -#include <poll.h> #include "lib/bluetooth.h" #include "lib/uuid.h" -#include "lib/iso.h" - -#include "btio/btio.h" #include "src/shared/queue.h" #include "src/shared/util.h"
@@ -29,8 +25,6 @@#include "src/shared/gatt-client.h" #include "src/shared/bass.h" -#define MAX_BIS_BITMASK_IDX 31 - #define DBG(_bass, fmt, arg...) \ bass_debug(_bass, "%s:%s() " fmt, __FILE__, __func__, ## arg)
@@ -102,9 +96,6 @@ 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; -GIOChannel *pa_sync_io; -struct queue *bises; }; typedef void (*bass_notify_t)(struct bt_bass *bass, uint16_t value_handle,
@@ -122,35 +113,6 @@ static struct queue *bass_db;static struct queue *bass_cbs;static struct queue *sessions; -#define DEFAULT_IO_QOS \ -{ \ - .interval = 10000, \ - .latency = 10, \ - .sdu = 40, \ - .phy = 0x02, \ - .rtn = 2, \ -} - -static struct bt_iso_qos default_qos = { - .bcast = { - .big =BT_ISO_QOS_BIG_UNSET , - .bis =BT_ISO_QOS_BIS_UNSET , - .sync_factor =0x07 , - .packing =0x00 , - .framing =0x00 , - .in =DEFAULT_IO_QOS , - .out =DEFAULT_IO_QOS , - .encryption =0x00 , - .bcode = {0x00 }, - .options =0x00 , - .skip =0x0000 , - .sync_timeout =BT_ISO_SYNC_TIMEOUT , - .sync_cte_type =0x00 , - .mse =0x00 , - .timeout =BT_ISO_SYNC_TIMEOUT , - } -}; -struct bt_bass_src_changed {unsigned int id;bt_bass_src_func_t cb;
@@ -646,115 +608,6 @@ static bool bass_src_attr_match(const void *data, const void *match_data)return (bcast_src->attr == attr); } -static gboolean check_io_err (GIOChannel *io) -{ -struct pollfd fds; - -memset (&fds,0 ,sizeof (fds)); - fds.fd =g_io_channel_unix_get_fd (io); - fds.events =POLLERR ; - -if (poll (&fds,1 ,0 ) >0 && (fds.revents &POLLERR )) -return TRUE; - -return FALSE; -} - -static void bass_bis_unref (void *data) -{ -GIOChannel *io = data; - -g_io_channel_unref (io); -} - -static void connect_cb (GIOChannel *io,GError *gerr, -gpointer user_data) -{ -struct bt_bcast_src *bcast_src = user_data; -struct iovec *notif; -int bis_idx; -int i; - -/* Keep io reference */ -g_io_channel_ref (io); -queue_push_tail (bcast_src->bises, io); - -for (i =0 ; i < bcast_src->num_subgroups; i++) { -struct bt_bass_subgroup_data *data = - &bcast_src->subgroup_data[i]; - -for (bis_idx =0 ; bis_idx <MAX_BIS_BITMASK_IDX ; bis_idx++) { -if (data->pending_bis_sync & (1 << bis_idx)) { - data->bis_sync |= (1 << bis_idx); - data->pending_bis_sync &= ~(1 << bis_idx); -break ; - } - } - -if (bis_idx <MAX_BIS_BITMASK_IDX ) -break ; - } - -for (i =0 ; i < bcast_src->num_subgroups; i++) { -if (bcast_src->subgroup_data[i].pending_bis_sync) -break ; - } - -/* If there are still pending bises, wait for their -* notifications also before sending notification to -* client -*/ -if (i != bcast_src->num_subgroups) -return ; - -/* All connections have been notified */ -if (check_io_err (io)) { -DBG (bcast_src->bass,"BIG sync failed" ); - -/* Close all connected bises */ -queue_destroy (bcast_src->bises, bass_bis_unref); - bcast_src->bises =NULL ; - -/* Close listen io */ -g_io_channel_shutdown (bcast_src->listen_io, TRUE,NULL ); -g_io_channel_unref (bcast_src->listen_io); - bcast_src->listen_io =NULL ; - -/* Close pa sync io */ -if (bcast_src->pa_sync_io) { -g_io_channel_shutdown (bcast_src->pa_sync_io, - TRUE,NULL ); -g_io_channel_unref (bcast_src->pa_sync_io); - bcast_src->pa_sync_io =NULL ; - } - -for (i =0 ; i < bcast_src->num_subgroups; i++) - bcast_src->subgroup_data[i].bis_sync = -BT_BASS_BIG_SYNC_FAILED_BITMASK ; - -/* If BIG sync failed because of an incorrect broadcast code, -* inform client -*/ -if (bcast_src->enc ==BT_BASS_BIG_ENC_STATE_BCODE_REQ ) - bcast_src->enc =BT_BASS_BIG_ENC_STATE_BAD_CODE ; - }else { -if (bcast_src->enc ==BT_BASS_BIG_ENC_STATE_BCODE_REQ ) - bcast_src->enc =BT_BASS_BIG_ENC_STATE_DEC ; - } - -/* Send notification to client */ - notif =bass_parse_bcast_src (bcast_src); -if (!notif) -return ; - -gatt_db_attribute_notify (bcast_src->attr, - notif->iov_base, notif->iov_len, -bt_bass_get_att (bcast_src->bass)); - -free (notif->iov_base); -free (notif); -} -static bool bass_trigger_big_sync (struct bt_bcast_src *bcast_src) {for (int i =0 ; i < bcast_src->num_subgroups; i++) {
@@ -769,73 +622,6 @@ static bool bass_trigger_big_sync(struct bt_bcast_src *bcast_src)return false; } - -static void confirm_cb (GIOChannel *io,gpointer user_data) -{ -struct bt_bcast_src *bcast_src = user_data; -int sk, err; -socklen_t len; -struct bt_iso_qos qos; -struct iovec *notif; -GError *gerr =NULL ; - -if (check_io_err (io)) { -DBG (bcast_src->bass,"PA sync failed" ); - -/* Mark PA sync as failed and notify client */ - bcast_src->sync_state =BT_BASS_FAILED_TO_SYNCHRONIZE_TO_PA ; - goto notify; - } - - bcast_src->sync_state =BT_BASS_SYNCHRONIZED_TO_PA ; - bcast_src->pa_sync_io = io; -g_io_channel_ref (bcast_src->pa_sync_io); - - len =sizeof (qos); -memset (&qos,0 , len); - - sk =g_io_channel_unix_get_fd (io); - - err =getsockopt (sk,SOL_BLUETOOTH ,BT_ISO_QOS , &qos, &len); -if (err <0 ) { -DBG (bcast_src->bass,"Failed to get iso qos" ); -return ; - } - -if (!qos.bcast.encryption) { -/* BIG is not encrypted. Try to synchronize */ - bcast_src->enc =BT_BASS_BIG_ENC_STATE_NO_ENC ; - -if (bass_trigger_big_sync (bcast_src)) { -if (!bt_io_bcast_accept (bcast_src->pa_sync_io, - 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); - } -return ; - } - - goto notify; - } - -/* BIG is encrypted. Wait for Client to provide the Broadcast_Code */ - bcast_src->enc =BT_BASS_BIG_ENC_STATE_BCODE_REQ ; - -notify: - notif =bass_parse_bcast_src (bcast_src); -if (!notif) -return ; - -gatt_db_attribute_notify (bcast_src->attr, - notif->iov_base, notif->iov_len, -bt_bass_get_att (bcast_src->bass)); - -free (notif->iov_base); -free (notif); -} -static struct bt_bass *bass_get_session (struct bt_att *att,struct gatt_db *db,const bdaddr_t *adapter_bdaddr) {
@@ -922,13 +708,7 @@ static void bass_handle_add_src_op(struct bt_bass *bass,uint8_t src_id =0 ;struct gatt_db_attribute *attr;uint8_t pa_sync; -GIOChannel *io; -GError *err =NULL ; -struct bt_iso_qos iso_qos = default_qos; -uint8_t num_bis =0 ; -uint8_t bis[ISO_MAX_NUM_BIS ];struct iovec *notif; -uint8_t addr_type;gatt_db_attribute_write_result (attrib, id,0x00 );
@@ -945,8 +725,6 @@ static void bass_handle_add_src_op(struct bt_bass *bass,queue_push_tail (bass->ldb->bcast_srcs, bcast_src); -memset (bis,0 ,ISO_MAX_NUM_BIS ); - bcast_src->bass = bass;/* Map the source to a Broadcast Receive State characteristic */
@@ -1028,18 +806,6 @@ static void bass_handle_add_src_op(struct bt_bass *bass,util_iov_pull_le32 (iov, &data->pending_bis_sync); -if (data->pending_bis_sync !=BIS_SYNC_NO_PREF ) -/* Iterate through the bis sync bitmask written -* by the client and store the bis indexes that -* the BASS server will try to synchronize to -*/ -for (int bis_idx =0 ; bis_idx <31 ; bis_idx++) { -if (data->pending_bis_sync & (1 << bis_idx)) { - bis[num_bis] = bis_idx +1 ; - num_bis++; - } - } - data->meta_len = *(uint8_t *)util_iov_pull_mem (iov,sizeof (data->meta_len));if (!data->meta_len)
@@ -1054,38 +820,7 @@ static void bass_handle_add_src_op(struct bt_bass *bass, }if (pa_sync !=PA_SYNC_NO_SYNC ) { -/* Convert to three-value type */ -if (bcast_src->addr_type) - addr_type =BDADDR_LE_RANDOM ; -else - addr_type =BDADDR_LE_PUBLIC ; - -/* If requested by client, try to synchronize to the source */ - io =bt_io_listen (NULL , confirm_cb, bcast_src,NULL , &err, -BT_IO_OPT_SOURCE_BDADDR , - &bass->ldb->adapter_bdaddr, -BT_IO_OPT_DEST_BDADDR , - &bcast_src->addr, -BT_IO_OPT_DEST_TYPE , - addr_type, -BT_IO_OPT_MODE ,BT_IO_MODE_ISO , -BT_IO_OPT_QOS , &iso_qos, -BT_IO_OPT_ISO_BC_SID , bcast_src->sid, -BT_IO_OPT_ISO_BC_NUM_BIS , num_bis, -BT_IO_OPT_ISO_BC_BIS , bis, -BT_IO_OPT_INVALID ); - -if (!io) { -DBG (bass,"%s" , err->message); -g_error_free (err); - goto err; - } - - bcast_src->listen_io = io; -g_io_channel_ref (bcast_src->listen_io); - -if (num_bis >0 && !bcast_src->bises) - bcast_src->bises =queue_new (); +/* TODO: call BASS plugin callback to establish PA/BIG sync */ }else {for (int i =0 ; i < bcast_src->num_subgroups; i++) bcast_src->subgroup_data[i].bis_sync =
@@ -1125,10 +860,6 @@ static void bass_handle_set_bcast_code_op(struct bt_bass *bass, {struct bt_bass_set_bcast_code_params *params;struct bt_bcast_src *bcast_src; -int sk, err; -socklen_t len; -struct bt_iso_qos qos; -GError *gerr =NULL ;struct iovec *notif;/* Get Set Broadcast Code command parameters */
@@ -1164,37 +895,7 @@ static void bass_handle_set_bcast_code_op(struct bt_bass *bass,return ; } -/* Try to sync to the source using the -* received broadcast code -*/ - len =sizeof (qos); -memset (&qos,0 , len); - -if (!bcast_src->pa_sync_io) -return ; - - sk =g_io_channel_unix_get_fd (bcast_src->pa_sync_io); - - err =getsockopt (sk,SOL_BLUETOOTH ,BT_ISO_QOS , &qos, &len); -if (err <0 ) { -DBG (bcast_src->bass,"Failed to get iso qos" ); -return ; - } - -/* Update socket QoS with Broadcast Code */ -memcpy (qos.bcast.bcode, params->bcast_code,BT_BASS_BCAST_CODE_SIZE ); - -if (setsockopt (sk,SOL_BLUETOOTH ,BT_ISO_QOS , &qos, -sizeof (qos)) <0 ) { -DBG (bcast_src->bass,"Failed to set iso qos" ); -return ; - } - -if (!bt_io_bcast_accept (bcast_src->pa_sync_io, 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); - } +/* TODO: Call BASS plugin callback to sync with required BIS */ }#define BASS_OP (_str, _op, _size, _func) \
@@ -1378,18 +1079,6 @@ static void bass_bcast_src_free(void *data)free (bcast_src->subgroup_data); -if (bcast_src->listen_io) { -g_io_channel_shutdown (bcast_src->listen_io, TRUE,NULL ); -g_io_channel_unref (bcast_src->listen_io); - } - -if (bcast_src->pa_sync_io) { -g_io_channel_shutdown (bcast_src->pa_sync_io, TRUE,NULL ); -g_io_channel_unref (bcast_src->pa_sync_io); - } - -queue_destroy (bcast_src->bises, bass_bis_unref); -free (bcast_src); }
Signature · 1 line
2.39.2
PATCH v2 4/16 shared/bass: Add support to register cp handlers
In reply to Iulia TanasescuThe BASS Broadcast Audio Scan Control Point characteristic defines a number of commands that require the BASS Server to sync to Broadcasters. This should be handled inside the BASS plugin.
This commit adds shared/bass APIs to register control point handlers with bt_bass. The BASS plugin will use these APIs to register a control point callback to handle each operation based on opcode and parameters.
--- src/shared/bass.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/bass.h | 9 +++++++ 2 files changed, 77 insertions(+)
src/shared/bass.c +68 -0
@@ -66,12 +66,20 @@ struct bt_bass {void *debug_data;struct queue *src_cbs; +struct queue *cp_handlers;unsigned int disconn_id;void *user_data; }; +struct bt_bass_cp_handler { +unsigned int id; +bt_bass_cp_handler_func_t handler; +bt_bass_destroy_func_t destroy; +void *data; +}; +/* BASS subgroup field of the Broadcast * Receive State characteristic */
@@ -134,6 +142,64 @@ static void bass_debug(struct bt_bass *bass, const char *format, ...)va_end (ap); } +unsigned int bt_bass_cp_handler_register (struct bt_bass *bass, +bt_bass_cp_handler_func_t handler, +bt_bass_destroy_func_t destroy, +void *user_data) +{ +struct bt_bass_cp_handler *cb; +static unsigned int id; + +if (!bass) +return 0 ; + + cb = new0(struct bt_bass_cp_handler, 1); + cb->id = ++id ? id : ++id; + cb->handler = handler; + cb->destroy = destroy; + cb->data = user_data; + +queue_push_tail (bass->cp_handlers, cb); + +return cb->id; +} + +static void bass_cp_handler_free (void *data) +{ +struct bt_bass_cp_handler *cb = data; + +if (cb->destroy) + cb->destroy (cb->data); + +free (cb); +} + +static bool match_cb_id (const void *data,const void *match_data) +{ +const struct bt_bass_cp_handler *cb = data; +unsigned int id =PTR_TO_UINT (match_data); + +return (cb->id == id); +} + +bool bt_bass_cp_handler_unregister (struct bt_bass *bass, +unsigned int id) +{ +struct bt_bass_cp_handler *cb; + +if (!bass) +return false; + + cb =queue_remove_if (bass->cp_handlers, match_cb_id, +UINT_TO_PTR (id)); +if (!cb) +return false; + +bass_cp_handler_free (cb); + +return true; +} +unsigned int bt_bass_src_register (struct bt_bass *bass,bt_bass_src_func_t cb,void *user_data,bt_bass_destroy_func_t destroy) {
@@ -1418,6 +1484,7 @@ static void bass_free(void *data)bass_db_free (bass->rdb);queue_destroy (bass->notify,NULL );queue_destroy (bass->src_cbs, bass_src_changed_free); +queue_destroy (bass->cp_handlers, bass_cp_handler_free);free (bass); }
@@ -1513,6 +1580,7 @@ struct bt_bass *bt_bass_new(struct gatt_db *ldb, struct gatt_db *rdb, bass->ldb = db; bass->notify =queue_new (); bass->src_cbs =queue_new (); + bass->cp_handlers =queue_new ();if (!rdb) goto done;
src/shared/bass.h +9 -0
@@ -99,6 +99,9 @@ typedef void (*bt_bass_debug_func_t)(const char *str, void *user_data);typedef void (*bt_bass_src_func_t )(uint8_t id,uint32_t bid,uint8_t enc,uint32_t bis_sync,void *user_data); +typedef int (*bt_bass_cp_handler_func_t )(struct bt_bcast_src *bcast_src, +uint8_t op,void *params,void *user_data); +struct bt_att *bt_bass_get_att (struct bt_bass *bass);struct bt_gatt_client *bt_bass_get_client (struct bt_bass *bass); unsigned int bt_bass_register(bt_bass_func_t attached, bt_bass_func_t detached,
@@ -120,3 +123,9 @@ int bt_bass_send(struct bt_bass *bass,unsigned int bt_bass_src_register (struct bt_bass *bass,bt_bass_src_func_t cb,void *user_data,bt_bass_destroy_func_t destroy);bool bt_bass_src_unregister (struct bt_bass *bass,unsigned int id); +unsigned int bt_bass_cp_handler_register (struct bt_bass *bass, +bt_bass_cp_handler_func_t handler, +bt_bass_destroy_func_t destroy, +void *user_data); +bool bt_bass_cp_handler_unregister (struct bt_bass *bass, +unsigned int id);
Signature · 1 line
2.39.2
PATCH v2 5/16 shared/bass: Call cp handler for the Add Source cmd
In reply to Iulia TanasescuThis updates the Add Source control point handler inside shared/bass to call the handlers queued inside bt_bass, so the required sync operations will be properly handled by the plugins that registered callbacks.
--- src/shared/bass.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-)
src/shared/bass.c +28 -11
@@ -775,6 +775,9 @@ static void bass_handle_add_src_op(struct bt_bass *bass,struct gatt_db_attribute *attr;uint8_t pa_sync;struct iovec *notif; +int ret; +const struct queue_entry *entry; +struct bt_bass_add_src_params *params;gatt_db_attribute_write_result (attrib, id,0x00 );
@@ -839,22 +842,25 @@ static void bass_handle_add_src_op(struct bt_bass *bass, bcast_src->id = src_id; + params =util_iov_pull_mem (iov,sizeof (*params)); +/* Populate broadcast source fields from command parameters */ -util_iov_pull_u8 (iov, &bcast_src->addr_type); + bcast_src->addr_type = params->addr_type; -bacpy (&bcast_src->addr, (bdaddr_t *)util_iov_pull_mem (iov, -sizeof (bdaddr_t))); +/* Convert to three-value type */ +if (bcast_src->addr_type) + params->addr_type =BDADDR_LE_RANDOM ; +else + params->addr_type =BDADDR_LE_PUBLIC ; -util_iov_pull_u8 (iov, &bcast_src->sid); -util_iov_pull_le24 (iov, &bcast_src->bid); +bacpy (&bcast_src->addr, ¶ms->addr); + bcast_src->sid = params->sid; +memcpy (&bcast_src->bid, params->bid,sizeof (params->bid)); -util_iov_pull_u8 (iov, &pa_sync); + pa_sync = params->pa_sync; bcast_src->sync_state =BT_BASS_NOT_SYNCHRONIZED_TO_PA ; -/* TODO: Use the pa_interval field for the sync transfer procedure */ -util_iov_pull_mem (iov,sizeof (uint16_t )); - -util_iov_pull_u8 (iov, &bcast_src->num_subgroups); + bcast_src->num_subgroups = params->num_subgroups;if (!bcast_src->num_subgroups)return ;
@@ -886,7 +892,18 @@ static void bass_handle_add_src_op(struct bt_bass *bass, }if (pa_sync !=PA_SYNC_NO_SYNC ) { -/* TODO: call BASS plugin callback to establish PA/BIG sync */ +for (entry =queue_get_entries (bass->cp_handlers); entry; + entry = entry->next) { +struct bt_bass_cp_handler *cb = entry->data; + +if (cb->handler) { + ret = cb->handler (bcast_src, +BT_BASS_ADD_SRC , + params, cb->data); +if (ret) + goto err; + } + } }else {for (int i =0 ; i < bcast_src->num_subgroups; i++) bcast_src->subgroup_data[i].bis_sync =
Signature · 1 line
2.39.2
PATCH v2 6/16 bap: Add support for long-lived PA sync
In reply to Iulia TanasescuThis adds BAP support for long-lived PA sync.
A BAP Broadcast Sink might probe Broadcasters autonomoulsy (by performing short-lived PA sync to parse the BASE and discover streams), or it might act as a Scan Delegator, probing Broadcasters added by a Broadcast Assistant. If the Assistant requested the Delegator to establish PA sync with a Broadcaster, the PA sync should be long-lived (it should remain active until requested otherwise by the Assistant).
--- profiles/audio/bap.c | 64 +++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 16 deletions(-)
profiles/audio/bap.c +48 -16
@@ -127,6 +127,7 @@ struct bap_data {enum {BAP_PA_SHORT_REQ =0 ,/* Request for short PA sync */ +BAP_PA_LONG_REQ ,/* Request for long PA sync */ BAP_PA_BIG_SYNC_REQ ,/* Request for PA Sync and BIG Sync */ };
@@ -1004,9 +1005,11 @@ static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data)DBG ("BIG Sync completed" ); -g_io_channel_unref (setup->io); -g_io_channel_shutdown (setup->io, TRUE,NULL ); - setup->io =NULL ; +if (setup->io) { +g_io_channel_unref (setup->io); +g_io_channel_shutdown (setup->io, TRUE,NULL ); + setup->io =NULL ; + }/* This device is no longer needed */ btd_service_connecting_complete (bap_data->service,0 );
@@ -1255,12 +1258,24 @@ static gboolean big_info_report_cb(GIOChannel *io, GIOCondition cond,return FALSE; } -/* Close the io and remove the queue request for another PA Sync */ +/* Close the listen io */ g_io_channel_shutdown (data->listen_io, TRUE,NULL );g_io_channel_unref (data->listen_io); -g_io_channel_shutdown (io, TRUE,NULL ); data->listen_io =NULL ; +if (req->type ==BAP_PA_LONG_REQ ) { +/* If long-lived PA sync was requested, keep a reference +* to the PA sync io to keep the sync active. +*/ + data->listen_io = io; +g_io_channel_ref (io); + }else { +/* For short-lived PA, the sync is no longer needed at +* this point, so the io can be closed. +*/ +g_io_channel_shutdown (io, TRUE,NULL ); + } +/* Analyze received BASE data and create remote media endpoints for each * BIS matching our capabilities */
@@ -2192,7 +2207,7 @@ static void check_pa_req_in_progress(void *data, void *user_data) *((bool *)user_data) = TRUE; } -static int short_lived_pa_sync (struct bap_bcast_pa_req *req); +static int pa_sync (struct bap_bcast_pa_req *req);static void pa_and_big_sync (struct bap_bcast_pa_req *req);static gboolean pa_idle_timer (gpointer user_data)
@@ -2210,7 +2225,11 @@ static gboolean pa_idle_timer(gpointer user_data)switch (req->type) {case BAP_PA_SHORT_REQ :DBG ("do short lived PA Sync" ); -short_lived_pa_sync (req); +pa_sync (req); +break ; +case BAP_PA_LONG_REQ : +DBG ("do long lived PA Sync" ); +pa_sync (req);break ;case BAP_PA_BIG_SYNC_REQ :DBG ("do PA Sync and BIG Sync" );
@@ -2236,8 +2255,8 @@ static void setup_accept_io_broadcast(struct bap_data *data, struct bap_bcast_pa_req *req = new0(struct bap_bcast_pa_req, 1);struct bap_adapter *adapter = data->adapter; -/* Timer could be stopped if all the short lived requests were treated. -* Check the state of the timer and turn it on so that this requests +/* Timer could be stopped if all other requests were treated. +* Check the state of the timer and turn it on so that this request * can also be treated. */ if (adapter->pa_timer_id ==0 )
@@ -2980,7 +2999,7 @@ static void bap_detached(struct bt_bap *bap, void *user_data)bap_data_remove (data); } -static int short_lived_pa_sync (struct bap_bcast_pa_req *req) +static int pa_sync (struct bap_bcast_pa_req *req) {struct btd_service *service = req->data.service;struct bap_data *data =btd_service_get_user_data (service);
@@ -3030,10 +3049,13 @@ static void iso_do_big_sync(GIOChannel *io, void *user_data)const char *strbis =NULL ;DBG ("PA Sync done" ); -g_io_channel_unref (setup->io); -g_io_channel_shutdown (setup->io, TRUE,NULL ); - setup->io = io; -g_io_channel_ref (setup->io); + +if (setup->io) { +g_io_channel_unref (setup->io); +g_io_channel_shutdown (setup->io, TRUE,NULL ); + setup->io = io; +g_io_channel_ref (setup->io); + }/* TODO * We can only synchronize with a single BIS to a BIG.
@@ -3086,14 +3108,14 @@ static void iso_do_big_sync(GIOChannel *io, void *user_data)memcpy (&qos.bcast.out, &setup->qos.bcast.io_qos,sizeof (struct bt_iso_io_qos )); -if (!bt_io_set (setup->io, &err, +if (!bt_io_set (io, &err,BT_IO_OPT_QOS , &qos,BT_IO_OPT_INVALID )) {error ("bt_io_set: %s" , err->message);g_error_free (err); } - if (!bt_io_bcast_accept(setup->io, + if (!bt_io_bcast_accept(io, iso_bcast_confirm_cb, req, NULL, &err, BT_IO_OPT_ISO_BC_NUM_BIS,
@@ -3114,6 +3136,16 @@ static void pa_and_big_sync(struct bap_bcast_pa_req *req) req->in_progress = TRUE; +if (bap_data->listen_io) { +/* If there is an active listen io for the BAP session +* with the Broadcast Source, it means that PA sync is +* already established. Go straight to establishing BIG +* sync. +*/ +iso_do_big_sync (bap_data->listen_io, req); +return ; + } +DBG ("Create PA sync with this source" ); setup->io = bt_io_listen(NULL, iso_do_big_sync, req, NULL, &err,
Signature · 1 line
2.39.2
PATCH v2 7/16 bap: Add API for Scan Delegator probe
In reply to Iulia TanasescuSince a BAP Broadcast Sink might probe Broadcasters autonomously or with the help of a Broadcast Assistant, BAP needs to support 2 types of Broadcaster probing: short-lived and long-lived.
This adds a BAP API for Scan Delegators probe Broadcaster devices long-lived.
--- profiles/audio/bap.c | 45 +++++++++++++++++++++++++++++++++++++------- profiles/audio/bap.h | 1 + 2 files changed, 39 insertions(+), 7 deletions(-)
profiles/audio/bap.c +38 -7
@@ -3171,12 +3171,29 @@ static bool match_bap_adapter(const void *data, const void *match_data)return adapter->adapter == match_data; } +void bap_scan_delegator_probe (struct btd_device *device) +{ +struct bap_data *data; + +/* Create BAP session for the Broadcaster device */ + data =bap_data_new (device); + data->device = device; + +bap_data_add (data); + +/* Add Broadcast Audio Announcement Service UUID +* to device and probe service. +*/ +btd_device_add_uuid (device,BCAAS_UUID_STR ); +} +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_bcast_pa_req *req; +uint8_t type =BAP_PA_LONG_REQ ;struct bap_data *data;if (!btd_adapter_has_exp_feature (adapter,EXP_FEAT_ISO_SOCKET )) {
@@ -3184,10 +3201,27 @@ static int bap_bcast_probe(struct btd_service *service)return -ENOTSUP ; } - data =bap_data_new (device); + data =queue_find (sessions, match_device, device); +if (data && data->service) { +error ("Profile probed twice for the same device!" ); +return -EINVAL ; + } + +if (!data) { + data =bap_data_new (device); + data->device = device; +bap_data_add (data); + +/* The Broadcaster was scanned autonomously, +* so it should be probed short-lived. +*/ + type =BAP_PA_SHORT_REQ ; + } + data->service = service; +btd_service_set_user_data (service, data); + data->adapter =queue_find (adapters, match_bap_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) {
@@ -3202,8 +3236,6 @@ static int bap_bcast_probe(struct btd_service *service)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_bcast_sink,
@@ -3220,11 +3252,10 @@ static int bap_bcast_probe(struct btd_service *service) pa_idle_timer, data->adapter); -/* Enqueue this device advertisement so that we can do short-lived -*/ +/* Enqueue this device advertisement so that we can create PA sync. */ DBG ("enqueue service: %p" , service); req = new0(struct bap_bcast_pa_req, 1); - req->type =BAP_PA_SHORT_REQ ; + req->type = type; req->in_progress = FALSE; req->data.service = service;queue_push_tail (data->adapter->bcast_pa_requests, req);
profiles/audio/bap.h +1 -0
@@ -8,3 +8,4 @@*/ struct bt_bap *bap_get_session (struct btd_device *device); +void bap_scan_delegator_probe (struct btd_device *device);
Signature · 1 line
2.39.2
PATCH v2 8/16 bass: Register cp handler for Add Source cmd
In reply to Iulia TanasescuThis registers a control point handler with shared/bass, for each eastablished BASS session. For now, only the Add Source opcode is handled.
Using the parameters provided from shared/bass, a device is created for the Broadcaster address. The device is then probed with BAP, where long-lived PA sync will be established. After parsing the BASE, transports are created for each BIS, as if the Broadcast Sink scanned the Broadacaster autonomously.
Below is a bluetoothctl log which shows a Scan Delegator starting to advertise, connecting to a Broadcast Assistant, receiving the Add Source command for a Broadcaster streaming one BIS, creating a device for the Broadcaster and then creating a transport for the BIS:
client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06 [/local/endpoint/ep0] Auto Accept (yes/no): y [/local/endpoint/ep0] Max Transports (auto/value): a [/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1 [bluetooth]# Endpoint /local/endpoint/ep0 registered [bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F [00-60-37-31-7E-3F]# [NEW] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA [00-60-37-31-7E-3F]# [NEW] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
The btmon log below shows the GATT write command with the Add Source opcode, which was received from the Broadcast Assistant. It also shows the long-lived PA sync performed by BAP:
Quoted 1 line
ACL Data RX: Handle 0 flags
0x01dlen 1
ATT: Write Command (0x52) len 23
Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
Data[21]: 0201da5711c0e203001a2d5602ffff010100000000
Opcode: Add Source (0x02)
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronize to PA - PAST not available
PA_Interval: 0xffff
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000001
< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044)
Options: 0x0000
Use advertising SID, Advertiser Address Type and address
Reporting initially enabled
SID: 0x00
Adv address type: Random (0x01)
Adv address: 03:E2:C0:11:57:DA (Non-Resolvable)
Skip: 0x0000
Sync timeout: 20000 msec (0x07d0)
Sync CTE type: 0x0000Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
Status: Success (0x00)Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 16
LE Periodic Advertising Sync Established (0x0e)
Status: Success (0x00)
Sync handle: 0
Advertising SID: 0x00
Advertiser address type: Random (0x01)
Advertiser address: 03:E2:C0:11:57:DA (Non-Resolvable)
Advertiser PHY: LE 2M (0x02)
Periodic advertising interval: 10.00 msec (0x0008)
Advertiser clock accuracy: 0x07Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 42
LE Periodic Advertising Report (0x0f)
Sync handle: 0
TX power: 127 dbm (0x7f)
RSSI: -64 dBm (0xc0)
CTE Type: No Constant Tone Extension (0xff)
Data status: Complete
Data length: 0x22
Service Data: Basic Audio Announcement (0x1851)
Presetation Delay: 40000
Number of Subgroups: 1
Subgroup #0:
Number of BIS(s): 1
Codec: LC3 (0x06)
Codec Specific Configuration: #0: len 0x02 type 0x01
Codec Specific Configuration: Sampling Frequency: 16 Khz
Codec Specific Configuration: #1: len 0x02 type 0x02
Codec Specific Configuration: Frame Duration: 10 ms (0x01)
Codec Specific Configuration: #2: len 0x03 type 0x04
Codec Specific Configuration: Frame Length: 40 (0x0028)
Codec Specific Configuration: #3: len 0x05 type 0x03
Codec Specific Configuration: Location: 0x00000001
Codec Specific Configuration: Location: Front Left
BIS #0:
Index: 1Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 20
LE Broadcast Isochronous Group Info Advertising Report (0x22)
Sync Handle: 0x0000
Number BIS: 1
NSE: 3
ISO Interval: 10.00 msec (0x0008)
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
SDU Interval: 10000 us (0x002710)
Maximum SDU: 40
PHY: LE 2M (0x02)
Framing: Unframed (0x00)
Encryption: 0x00
---
profiles/audio/bass.c | 79 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)profiles/audio/bass.c +79 -0
@@ -54,6 +54,7 @@#include "bap.h" #define BASS_UUID_STR "0000184f-0000-1000-8000-00805f9b34fb" +#define BCAAS_UUID_STR "00001852-0000-1000-8000-00805f9b34fb"#define MEDIA_ASSISTANT_INTERFACE "org.bluez.MediaAssistant1"
@@ -82,6 +83,7 @@ struct bass_data {struct btd_service *service;struct bt_bass *bass;unsigned int src_id; +unsigned int cp_id; };struct bass_assistant {
@@ -97,8 +99,14 @@ struct bass_assistant {char *path; }; +struct bass_delegator { +struct btd_device *device;/* Broadcast source device */ +struct bt_bcast_src *src; +}; +static struct queue *sessions;static struct queue *assistants; +static struct queue *delegators;static const char *state2str (enum assistant_state state);
@@ -582,6 +590,7 @@ static void bass_data_free(struct bass_data *data) }bt_bass_src_unregister (data->bass, data->src_id); +bt_bass_cp_handler_unregister (data->bass, data->cp_id);bt_bass_unref (data->bass);
@@ -627,6 +636,70 @@ static void bass_detached(struct bt_bass *bass, void *user_data)bass_data_remove (data); } +static int handle_add_src_req (struct bt_bcast_src *bcast_src, +struct bt_bass_add_src_params *params, +struct bass_data *data) +{ +struct btd_adapter *adapter =device_get_adapter (data->device); +struct btd_device *device; +struct bass_delegator *dg; + +/* Create device for Broadcast Source using the parameters +* provided by Broadcast Assistant. +*/ + device =btd_adapter_get_device (adapter, ¶ms->addr, + params->addr_type); +if (!device) { +DBG ("Unable to get device" ); +return -EINVAL ; + } + +DBG ("device %p" , device); + +/* Probe Broadcast Source, if it has not already been +* autonomously probed inside BAP. +*/ +if (!btd_device_get_service (device,BCAAS_UUID_STR )) + goto probe; + +return 0 ; + +probe: + dg = new0(struct bass_delegator, 1); +if (!dg) +return -ENOMEM ; + + dg->device = device; + dg->src = bcast_src; + +if (!delegators) + delegators =queue_new (); + +queue_push_tail (delegators, dg); + +DBG ("delegator %p" , dg); + +/* Probe device with BAP. */ +bap_scan_delegator_probe (device); + +return 0 ; +} + +static int cp_handler (struct bt_bcast_src *bcast_src,uint8_t op,void *params, +void *user_data) +{ +struct bass_data *data = user_data; +int err =0 ; + +switch (op) { +case BT_BASS_ADD_SRC : + err =handle_add_src_req (bcast_src, params, data); +break ; + } + +return err; +} +static void bass_attached (struct bt_bass *bass,void *user_data) {struct bass_data *data;
@@ -652,6 +725,9 @@ static void bass_attached(struct bt_bass *bass, void *user_data) data =bass_data_new (device); data->bass = bass; + data->cp_id =bt_bass_cp_handler_register (data->bass, + cp_handler,NULL , data); +bass_data_add (data); }
@@ -780,6 +856,9 @@ static int bass_probe(struct btd_service *service) data->src_id =bt_bass_src_register (data->bass, bass_src_changed, data,NULL ); + data->cp_id =bt_bass_cp_handler_register (data->bass, + cp_handler,NULL , data); +return 0 ; }
Signature · 1 line
2.39.2
PATCH v2 9/16 shared/bass: Add API to set PA sync state
In reply to Iulia TanasescuThis adds a shared/bass API to set the PA sync state field inside a Broadcast Receive State characteristic. Notifications are then sent, to inform all peers about the update.
--- src/shared/bass.c | 34 ++++++++++++++++++++++++++++++++++ src/shared/bass.h | 1 + 2 files changed, 35 insertions(+)
src/shared/bass.c +34 -0
@@ -1732,3 +1732,37 @@ done:return err; } + +static void bt_bass_notify_all (struct gatt_db_attribute *attr, +struct iovec *iov) +{ +const struct queue_entry *entry; + +for (entry =queue_get_entries (sessions); entry; entry = entry->next) { +struct bt_bass *bass = entry->data; + +gatt_db_attribute_notify (attr, iov->iov_base, + iov->iov_len,bt_bass_get_att (bass)); + } +} + +int bt_bass_set_pa_sync (struct bt_bcast_src *bcast_src,uint8_t sync_state) +{ +struct iovec *iov; + +if (!bcast_src) +return -EINVAL ; + + bcast_src->sync_state = sync_state; + + iov =bass_parse_bcast_src (bcast_src); +if (!iov) +return -ENOMEM ; + +bt_bass_notify_all (bcast_src->attr, iov); + +free (iov->iov_base); +free (iov); + +return 0 ; +}
src/shared/bass.h +1 -0
@@ -129,3 +129,4 @@ unsigned int bt_bass_cp_handler_register(struct bt_bass *bass, void *user_data);bool bt_bass_cp_handler_unregister (struct bt_bass *bass,unsigned int id); +int bt_bass_set_pa_sync (struct bt_bcast_src *bcast_src,uint8_t sync_state);
Signature · 1 line
2.39.2
PATCH v2 10/16 bass: Add APIs to probe/remove Broadcasters
In reply to Iulia TanasescuThis adds BASS APIs to probe/remove Broadcasters probed by BAP.
The BAP plugin might probe Broadcasters that were either scanned autonomously, or that were added by a Broadcast Assistant through BASS.
After performing long-lived PA sync with a Broadcaster added by a Broadcast Assistant, the BAP plugin will call the BASS probe API, to inform BASS that PA has been established with the Broadcast Source and to provide a reference to the created bt_bap session. Once a Broadcaster has been probed, BASS will update the PA sync state inside the corresponding Broadcast Receive State characteristic and the peer Broadcast Assistant will be notified about the update.
Once the BAP session with a Broadcaster is deleted, the BASS remove API will be called, to inform BASS that the Source is no longer active. The BASS plugin will update the PA sync field of the corresponding Broadcast Receive State characteristic and it will notify the peer Broadcast Assistant that PA sync is no longer established with the Source.
--- profiles/audio/bass.c | 51 +++++++++++++++++++++++++++++++++++++++++++ profiles/audio/bass.h | 3 +++ 2 files changed, 54 insertions(+)
profiles/audio/bass.c +51 -0
@@ -102,6 +102,7 @@ struct bass_assistant {struct bass_delegator {struct btd_device *device;/* Broadcast source device */ struct bt_bcast_src *src; +struct bt_bap *bap; };static struct queue *sessions;
@@ -115,6 +116,56 @@ static void bass_debug(const char *str, void *user_data)DBG_IDX (0xffff ,"%s" , str); } +static bool delegator_match_device (const void *data,const void *match_data) +{ +const struct bass_delegator *dg = data; +const struct btd_device *device = match_data; + +return dg->device == device; +} + +bool bass_bcast_probe (struct btd_device *device,struct bt_bap *bap) +{ +struct bass_delegator *dg; + + dg =queue_find (delegators, delegator_match_device, device); +if (!dg) +return false; + +DBG ("%p" , dg); + + dg->bap = bap; + +/* Update Broadcast Receive State characteristic value and notify +* peers. +*/ +if (bt_bass_set_pa_sync (dg->src,BT_BASS_SYNCHRONIZED_TO_PA )) +DBG ("Failed to update Broadcast Receive State characteristic" ); + +return true; +} + +bool bass_bcast_remove (struct btd_device *device) +{ +struct bass_delegator *dg; + + dg =queue_remove_if (delegators, delegator_match_device, device); +if (!dg) +return false; + +DBG ("%p" , dg); + +/* Update Broadcast Receive State characteristic value and notify +* peers. +*/ +if (bt_bass_set_pa_sync (dg->src,BT_BASS_NOT_SYNCHRONIZED_TO_PA )) +DBG ("Failed to update Broadcast Receive State characteristic" ); + +free (dg); + +return true; +} +static void assistant_set_state (struct bass_assistant *assistant,enum assistant_state state) {
profiles/audio/bass.h +3 -0
@@ -11,3 +11,6 @@ void bass_add_stream(struct btd_device *device, struct iovec *meta, struct iovec *caps, struct bt_iso_qos *qos, uint8_t sgrp, uint8_t bis);void bass_remove_stream (struct btd_device *device); + +bool bass_bcast_probe (struct btd_device *device,struct bt_bap *bap); +bool bass_bcast_remove (struct btd_device *device);
Signature · 1 line
2.39.2
PATCH v2 11/16 bap: Probe Broadcasters with BASS
In reply to Iulia TanasescuAfter long-lived PA sync, this adds a call to probe the bap session with the Broadcaster with BASS.
This also adds a call to notify BASS about a session with a Broadcaster being removed, in bap_bcast_remove.
The bluetoothctl log below shows a Scan Delegator creating a media transport for a BIS added by a Broadcast Assistant through the Add Source command, and then disconnecting from the Broadcaster:
client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06 [/local/endpoint/ep0] Auto Accept (yes/no): y [/local/endpoint/ep0] Max Transports (auto/value): a [/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1 [bluetooth]# Endpoint /local/endpoint/ep0 registered [bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F [00-60-37-31-7E-3F]# [NEW] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA [00-60-37-31-7E-3F]# [NEW] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# disconnect 03:E2:C0:11:57:DA
Attempting to disconnect from 03:E2:C0:11:57:DA
[00-60-37-31-7E-3F]# [DEL] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0[00-60-37-31-7E-3F]# [DEL] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA
The btmon log below shows that after PA sync is established inside the BAP plugin, the Scan Delegator sends a GATT notification to inform the Broadcast Assistant that PA sync has been established. Once the Broadcaster device is deleted, PA sync is terminated and the Scan Delegator once again notifies the peer about the update:
Quoted 1 line
ACL Data RX: Handle 0 flags
0x01dlen 1
ATT: Write Command (0x52) len 23
Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
Data[21]: 0201da5711c0e203001a2d5602ffff010100000000
Opcode: Add Source (0x02)
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronize to PA - PAST not available
PA_Interval: 0xffff
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000001
< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044)
Options: 0x0000
Use advertising SID, Advertiser Address Type and address
Reporting initially enabled
SID: 0x00
Adv address type: Random (0x01)
Adv address: 03:E2:C0:11:57:DA (Non-Resolvable)
Skip: 0x0000
Sync timeout: 20000 msec (0x07d0)
Sync CTE type: 0x0000Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
Status: Success (0x00)Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 16
LE Periodic Advertising Sync Established (0x0e)
Status: Success (0x00)
Sync handle: 0
Advertising SID: 0x00
Advertiser address type: Random (0x01)
Advertiser address: 03:E2:C0:11:57:DA (Non-Resolvable)
Advertiser PHY: LE 2M (0x02)
Periodic advertising interval: 10.00 msec (0x0008)
Advertiser clock accuracy: 0x07Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 42
LE Periodic Advertising Report (0x0f)
Sync handle: 0
TX power: 127 dbm (0x7f)
RSSI: -64 dBm (0xc0)
CTE Type: No Constant Tone Extension (0xff)
Data status: Complete
Data length: 0x22
Service Data: Basic Audio Announcement (0x1851)
Presetation Delay: 40000
Number of Subgroups: 1
Subgroup #0:
Number of BIS(s): 1
Codec: LC3 (0x06)
Codec Specific Configuration: #0: len 0x02 type 0x01
Codec Specific Configuration: Sampling Frequency: 16 Khz
Codec Specific Configuration: #1: len 0x02 type 0x02
Codec Specific Configuration: Frame Duration: 10 ms (0x01)
Codec Specific Configuration: #2: len 0x03 type 0x04
Codec Specific Configuration: Frame Length: 40 (0x0028)
Codec Specific Configuration: #3: len 0x05 type 0x03
Codec Specific Configuration: Location: 0x00000001
Codec Specific Configuration: Location: Front Left
BIS #0:
Index: 1Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 20
LE Broadcast Isochronous Group Info Advertising Report (0x22)
Sync Handle: 0x0000
Number BIS: 1
NSE: 3
ISO Interval: 10.00 msec (0x0008)
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
SDU Interval: 10000 us (0x002710)
Maximum SDU: 40
PHY: LE 2M (0x02)
Framing: Unframed (0x00)
Encryption: 0x00
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101da5711c0e203001a2d560200010000000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000000
bluetoothd[70621]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101dd7c8046f72a00f863f00000010000000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 2A:F7:46:80:7C:DD
Source_Adv_SID: 0
Broadcast_ID: 0xf063f8
PA_Sync_State: Not synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000000
< HCI Command: LE Periodic Advertising Terminate Sync (0x08|0x0046) plen 2
Sync handle: 0x0000Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 4
LE Periodic Advertising Terminate Sync (0x08|0x0046) ncmd 1
Status: Success (0x00
---
profiles/audio/bap.c | 6 ++++++
1 file changed, 6 insertions(+)profiles/audio/bap.c +6 -0
@@ -1276,6 +1276,9 @@ static gboolean big_info_report_cb(GIOChannel *io, GIOCondition cond,g_io_channel_shutdown (io, TRUE,NULL ); } +/* Notify the BASS plugin about the session. */ +bass_bcast_probe (data->device, data->bap); +/* Analyze received BASE data and create remote media endpoints for each * BIS matching our capabilities */
@@ -3297,6 +3300,9 @@ static void bap_bcast_remove(struct btd_service *service) }free (req); +/* Notify the BASS plugin about the removed session. */ +bass_bcast_remove (device); +bap_data_remove (data);bass_remove_stream (device);
Signature · 1 line
2.39.2
PATCH v2 12/16 shared/bass: Add APIs to set/clear BIS sync bits
In reply to Iulia TanasescuThis adds shared/bass APIs to set/clear bits inside the BIS sync bitmask of Broadcast Receive State characteristics. Notifications are sent to the peers each time the characteristic is updated.
--- src/shared/bass.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/bass.h | 2 ++ 2 files changed, 54 insertions(+)
src/shared/bass.c +52 -0
@@ -1766,3 +1766,55 @@ int bt_bass_set_pa_sync(struct bt_bcast_src *bcast_src, uint8_t sync_state)return 0 ; } + +int bt_bass_set_bis_sync (struct bt_bcast_src *bcast_src,uint8_t bis) +{ +struct iovec *iov; + +for (uint8_t i =0 ; i < bcast_src->num_subgroups; i++) { +struct bt_bass_subgroup_data *sgrp = + &bcast_src->subgroup_data[i]; +uint32_t bitmask =1 << (bis -1 ); + +if (sgrp->pending_bis_sync & bitmask) { + sgrp->bis_sync |= bitmask; + + iov =bass_parse_bcast_src (bcast_src); +if (!iov) +return -ENOMEM ; + +bt_bass_notify_all (bcast_src->attr, iov); + +free (iov->iov_base); +free (iov); + } + } + +return 0 ; +} + +int bt_bass_clear_bis_sync (struct bt_bcast_src *bcast_src,uint8_t bis) +{ +struct iovec *iov; + +for (uint8_t i =0 ; i < bcast_src->num_subgroups; i++) { +struct bt_bass_subgroup_data *sgrp = + &bcast_src->subgroup_data[i]; +uint32_t bitmask =1 << (bis -1 ); + +if (sgrp->pending_bis_sync & bitmask) { + sgrp->bis_sync &= ~bitmask; + + iov =bass_parse_bcast_src (bcast_src); +if (!iov) +return -ENOMEM ; + +bt_bass_notify_all (bcast_src->attr, iov); + +free (iov->iov_base); +free (iov); + } + } + +return 0 ; +}
src/shared/bass.h +2 -0
@@ -130,3 +130,5 @@ unsigned int bt_bass_cp_handler_register(struct bt_bass *bass,bool bt_bass_cp_handler_unregister (struct bt_bass *bass,unsigned int id);int bt_bass_set_pa_sync (struct bt_bcast_src *bcast_src,uint8_t sync_state); +int bt_bass_set_bis_sync (struct bt_bcast_src *bcast_src,uint8_t bis); +int bt_bass_clear_bis_sync (struct bt_bcast_src *bcast_src,uint8_t bis);
Signature · 1 line
2.39.2
PATCH v2 13/16 bass: Register BAP state changed cb
In reply to Iulia TanasescuThis registers a BAP stream state changed callback inside BASS, to monitor the state of BAP streams created by the Scan Delegator and to notify the peer Broadcast Assistants about updates.
The bluetoothctl log below shows a Scan Delegator creating a media transport for a BIS added by a Broadcast Assistant through the Add Source operation. The transport is then acquired and then released:
client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06 [/local/endpoint/ep0] Auto Accept (yes/no): y [/local/endpoint/ep0] Max Transports (auto/value): a [/local/endpoint/ep0] Locations: 1
[/local/endpoint/ep0] Supported Context (value): 1 [bluetooth]# Endpoint /local/endpoint/ep0 registered [bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F [00-60-37-31-7E-3F]# [NEW] Device 03:E2:C0:11:57:DA 03-E2-C0-11-57-DA [00-60-37-31-7E-3F]# [NEW] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Endpoint: SetConfiguration
[00-60-37-31-7E-3F]# Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Properties.Device:
/org/bluez/hci1/dev_03_E2_C0_11_57_DA
[00-60-37-31-7E-3F]# Auto Accepting...
[00-60-37-31-7E-3F]# transport.select
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# [CHG] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: broadcasting
[00-60-37-31-7E-3F]# transport.acquire
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
auto acquiring...
Transport /org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 acquiring
[00-60-37-31-7E-3F]# Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 acquiring complete
[00-60-37-31-7E-3F]# Acquire successful: fd 8 MTU 40:0
[00-60-37-31-7E-3F]# [CHG] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: active
[00-60-37-31-7E-3F]# transport.release
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0
[00-60-37-31-7E-3F]# Transport fd disconnected
[00-60-37-31-7E-3F]# [CHG] Transport
/org/bluez/hci1/dev_03_E2_C0_11_57_DA/bis1/fd0 State: idle[00-60-37-31-7E-3F]# Release successful
The btmon log below shows the Scan Delegator notifying the peer each time the state of the stream changes:
Quoted 1 line
ACL Data RX: Handle 0 flags
0x01dlen 1
ATT: Write Command (0x52) len 23
Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
Data[21]: 0201da5711c0e203001a2d5602ffff010100000000
Opcode: Add Source (0x02)
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronize to PA - PAST not available
PA_Interval: 0xffff
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000001
< HCI Command: LE Periodic Advertising Create Sync (0x08|0x0044)
Options: 0x0000
Use advertising SID, Advertiser Address Type and address
Reporting initially enabled
SID: 0x00
Adv address type: Random (0x01)
Adv address: 03:E2:C0:11:57:DA (Non-Resolvable)
Skip: 0x0000
Sync timeout: 20000 msec (0x07d0)
Sync CTE type: 0x0000Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Periodic Advertising Create Sync (0x08|0x0044) ncmd 1
Status: Success (0x00)Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 16
LE Periodic Advertising Sync Established (0x0e)
Status: Success (0x00)
Sync handle: 0
Advertising SID: 0x00
Advertiser address type: Random (0x01)
Advertiser address: 03:E2:C0:11:57:DA (Non-Resolvable)
Advertiser PHY: LE 2M (0x02)
Periodic advertising interval: 10.00 msec (0x0008)
Advertiser clock accuracy: 0x07Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 42
LE Periodic Advertising Report (0x0f)
Sync handle: 0
TX power: 127 dbm (0x7f)
RSSI: -64 dBm (0xc0)
CTE Type: No Constant Tone Extension (0xff)
Data status: Complete
Data length: 0x22
Service Data: Basic Audio Announcement (0x1851)
Presetation Delay: 40000
Number of Subgroups: 1
Subgroup #0:
Number of BIS(s): 1
Codec: LC3 (0x06)
Codec Specific Configuration: #0: len 0x02 type 0x01
Codec Specific Configuration: Sampling Frequency: 16 Khz
Codec Specific Configuration: #1: len 0x02 type 0x02
Codec Specific Configuration: Frame Duration: 10 ms (0x01)
Codec Specific Configuration: #2: len 0x03 type 0x04
Codec Specific Configuration: Frame Length: 40 (0x0028)
Codec Specific Configuration: #3: len 0x05 type 0x03
Codec Specific Configuration: Location: 0x00000001
Codec Specific Configuration: Location: Front Left
BIS #0:
Index: 1Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 20
LE Broadcast Isochronous Group Info Advertising Report (0x22)
Sync Handle: 0x0000
Number BIS: 1
NSE: 3
ISO Interval: 10.00 msec (0x0008)
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
SDU Interval: 10000 us (0x002710)
Maximum SDU: 40
PHY: LE 2M (0x02)
Framing: Unframed (0x00)
Encryption: 0x00
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101da5711c0e203001a2d560200010000000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000000
< HCI Command: LE Broadcast Isochronous Group Create Sync (0x08|0x006b)
BIG Handle: 0x00
BIG Sync Handle: 0x0000
Encryption: Unencrypted (0x00)
Broadcast Code[16]: 00000000000000000000000000000000
Maximum Number Subevents: 0x00
Timeout: 20000 ms (0x07d0)
Number of BIS: 1
BIS ID: 0x01Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Broadcast Isochronous Group Create Sync (0x08|0x006b) ncmd 1
Status: Success (0x00Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 17
LE Broadcast Isochronous Group Sync Estabilished (0x1d)
Status: Success (0x00)
BIG Handle: 0x00
Transport Latency: 912 us (0x000390)
NSE: 3
BN: 1
PTO: 1
IRC: 3
Maximum PDU: 40
ISO Interval: 10.00 msec (0x0008)
Connection Handle #0: 10
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e) plen 13
Handle: 10
Data Path Direction: Output (Controller to Host) (0x01)
Data Path: HCI (0x00)
Coding Format: Transparent (0x03)
Company Codec ID: Ericsson Technology Licensing (0)
Vendor Codec ID: 0
Controller Delay: 0 us (0x000000)
Codec Configuration Length: 0
Codec Configuration[0]:Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 6
LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1
Status: Success (0x00)
Handle: 10
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101da5711c0e203001a2d560200010100000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000001
bluetoothd[4636]: < ACL Data TX: Handle 0 flags 0x00 dlen 29
ATT: Handle Multiple Value Notification (0x23) len 24
Length: 0x0014
Handle: 0x003a Type: Broadcast Receive State (0x2bc8)
Data[20]: 0101da5711c0e203001a2d560200010000000000
Source_ID: 1
Source_Address_Type: 1
Source_Address: 03:E2:C0:11:57:DA
Source_Adv_SID: 0
Broadcast_ID: 0x562d1a
PA_Sync_State: Synchronized to PA
BIG_Encryption: Not encrypted
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000000
< HCI Command: LE Broadcast Isochronous Group Terminate Sync (0x08|0x006c)
BIG Handle: 0x00Quoted 1 line
HCI Event: Command Complete (
0x0e) plen 5
LE Broadcast Isochronous Group Terminate Sync (0x08|0x006c) ncmd 1
Status: Success (0x00)
---
profiles/audio/bass.c | 58 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)profiles/audio/bass.c +58 -0
@@ -103,6 +103,7 @@ struct bass_delegator {struct btd_device *device;/* Broadcast source device */ struct bt_bcast_src *src;struct bt_bap *bap; +unsigned int state_id; };static struct queue *sessions;
@@ -124,6 +125,54 @@ static bool delegator_match_device(const void *data, const void *match_data)return dg->device == device; } +static void bap_state_changed (struct bt_bap_stream *stream,uint8_t old_state, +uint8_t new_state,void *user_data) +{ +struct bass_delegator *dg = user_data; +int bis; +char *path =bt_bap_stream_get_user_data (stream); +struct bt_bap *bap =bt_bap_stream_get_session (stream); +const char *strbis; +int err; + +if (dg->bap != bap) +return ; + + strbis =strstr (path,"/bis" ); +if (strbis ==NULL ) { +DBG ("bis index cannot be found" ); +return ; + } + + err =sscanf (strbis,"/bis%d" , &bis); +if (err <0 ) { +DBG ("sscanf error" ); +return ; + } + +DBG ("stream %p: %s(%u) -> %s(%u)" , stream, +bt_bap_stream_statestr (old_state), old_state, +bt_bap_stream_statestr (new_state), new_state); + +switch (new_state) { +case BT_BAP_STREAM_STATE_STREAMING : +/* BAP stream was started. Mark BIS index as synced inside the +* Broadcast Receive State characteristic and notify peers about +* the update. +*/ +bt_bass_set_bis_sync (dg->src, bis); +break ; +case BT_BAP_STREAM_STATE_CONFIG : +if (old_state ==BT_BAP_STREAM_STATE_STREAMING ) +/* BAP stream was disabled. Clear BIS index from the +* bitmask inside the Broadcast Receive State +* characteristic and notify peers about the update. +*/ +bt_bass_clear_bis_sync (dg->src, bis); +break ; + } +} +bool bass_bcast_probe (struct btd_device *device,struct bt_bap *bap) {struct bass_delegator *dg;
@@ -142,6 +191,12 @@ bool bass_bcast_probe(struct btd_device *device, struct bt_bap *bap)if (bt_bass_set_pa_sync (dg->src,BT_BASS_SYNCHRONIZED_TO_PA ))DBG ("Failed to update Broadcast Receive State characteristic" ); +/* Register BAP stream state changed callback, to keep up to +* date with BIG/PA sync state. +*/ + dg->state_id =bt_bap_state_register (bap, bap_state_changed, +NULL , dg,NULL ); +return true; }
@@ -161,6 +216,9 @@ bool bass_bcast_remove(struct btd_device *device)if (bt_bass_set_pa_sync (dg->src,BT_BASS_NOT_SYNCHRONIZED_TO_PA ))DBG ("Failed to update Broadcast Receive State characteristic" ); +/* Unregister BAP stream state changed callback. */ +bt_bap_state_unregister (dg->bap, dg->state_id); +free (dg);return true;
Signature · 1 line
2.39.2
PATCH v2 14/16 shared/bass: Add API to check BIS required for sync
In reply to Iulia TanasescuThis adds a shared/bass API to check if a BIS index of a Broadcast Source has been requested by the Broadcast Assistant to be synced with. This will be used by BAP after parsing the BASE, to filter out the streams that don't need to be created.
--- src/shared/bass.c | 14 ++++++++++++++ src/shared/bass.h | 1 + 2 files changed, 15 insertions(+)
src/shared/bass.c +14 -0
@@ -1818,3 +1818,17 @@ int bt_bass_clear_bis_sync(struct bt_bcast_src *bcast_src, uint8_t bis)return 0 ; } + +bool bt_bass_check_bis (struct bt_bcast_src *bcast_src,uint8_t bis) +{ +for (uint8_t i =0 ; i < bcast_src->num_subgroups; i++) { +struct bt_bass_subgroup_data *sgrp = + &bcast_src->subgroup_data[i]; +uint32_t bitmask =1 << (bis -1 ); + +if (sgrp->pending_bis_sync & bitmask) +return true; + } + +return false; +}
src/shared/bass.h +1 -0
@@ -132,3 +132,4 @@ bool bt_bass_cp_handler_unregister(struct bt_bass *bass,int bt_bass_set_pa_sync (struct bt_bcast_src *bcast_src,uint8_t sync_state);int bt_bass_set_bis_sync (struct bt_bcast_src *bcast_src,uint8_t bis);int bt_bass_clear_bis_sync (struct bt_bcast_src *bcast_src,uint8_t bis); +bool bt_bass_check_bis (struct bt_bcast_src *bcast_src,uint8_t bis);
Signature · 1 line
2.39.2
PATCH v2 15/16 bass: Add API to check BIS required for sync
In reply to Iulia TanasescuThis adds a wrapper over bt_bass_check_bis, which receives a Broadcaster device and a BIS index and checks is the Delegator has been instructed to sync with the specific BIS transmitted by the Source.
--- profiles/audio/bass.c | 14 ++++++++++++++ profiles/audio/bass.h | 2 ++ 2 files changed, 16 insertions(+)
profiles/audio/bass.c +14 -0
@@ -125,6 +125,20 @@ static bool delegator_match_device(const void *data, const void *match_data)return dg->device == device; } +bool bass_check_bis (struct btd_device *device,uint8_t bis) +{ +struct bass_delegator *dg; + + dg =queue_find (delegators, delegator_match_device, device); +if (!dg) +return true; + +if (!bt_bass_check_bis (dg->src, bis)) +return false; + +return true; +} +static void bap_state_changed (struct bt_bap_stream *stream,uint8_t old_state,uint8_t new_state,void *user_data) {
profiles/audio/bass.h +2 -0
@@ -14,3 +14,5 @@ void bass_remove_stream(struct btd_device *device);bool bass_bcast_probe (struct btd_device *device,struct bt_bap *bap);bool bass_bcast_remove (struct btd_device *device); + +bool bass_check_bis (struct btd_device *device,uint8_t bis);
Signature · 1 line
2.39.2
PATCH v2 16/16 bap: Create streams for required BISes
In reply to Iulia TanasescuIf a BAP Broadcast Sink is acting as a Scan Delegator and it has performed long-lived PA sync with a Broadcaster added by a Broadcast Assistant, the BASE should be parsed and streams need to be created only for BISes requested by the Assistant.
This adds a BASS check inside parse_base, to filter out BISes that do not require streams.
The bluetoothctl log below shows a Scan Delegator registering a Broadcast Sink PAC and connecting to a Broadcast Assistant:
client/bluetoothctl
[bluetooth]# endpoint.register 00001851-0000-1000-8000-00805f9b34fb 0x06 [/local/endpoint/ep0] Auto Accept (yes/no): y [/local/endpoint/ep0] Max Transports (auto/value): a [/local/endpoint/ep0] Locations: 3
[/local/endpoint/ep0] Supported Context (value): 1 [bluetooth]# Endpoint /local/endpoint/ep0 registered [bluetooth]# advertise on
[bluetooth]# [NEW] Device 00:60:37:31:7E:3F 00-60-37-31-7E-3F
The btmon log shows the Scan Delegator receiving the Add Source command from a Broadcast Assistant, requesting to sync to BIS index 2 of the provided Broadcaster. After PA sync, the BASE shows that the Broadcaster is streaming 2 BISes, both matching the audio capabilities supported by the Scan Delegator:
Quoted 1 line
ACL Data RX: Handle 0 flags
0x01dlen 1
ATT: Write Command (0x52) len 23
Handle: 0x0040 Type: Broadcast Audio Scan Control Point (0x2bc7)
Data[21]: 02014605638ad50e004dda9b02ffff010200000000
Opcode: Add Source (0x02)
Source_Address_Type: 1
Source_Address: 0E:D5:8A:63:05:46
Source_Adv_SID: 0
Broadcast_ID: 0x9bda4d
PA_Sync_State: Synchronize to PA - PAST not available
PA_Interval: 0xffff
Num_Subgroups: 1
Subgroup #0:
BIS_Sync State: 0x00000002Quoted 1 line
HCI Event: LE Meta Event (
0x3e) plen 50
LE Periodic Advertising Report (0x0f)
Sync handle: 0
TX power: 127 dbm (0x7f)
RSSI: -60 dBm (0xc4)
CTE Type: No Constant Tone Extension (0xff)
Data status: Complete
Data length: 0x2a
Service Data: Basic Audio Announcement (0x1851)
Presetation Delay: 40000
Number of Subgroups: 1
Subgroup #0:
Number of BIS(s): 2
Codec: LC3 (0x06)
Codec Specific Configuration: #0: len 0x02 type 0x01
Codec Specific Configuration: Sampling Frequency: 16 Khz
(0x03)
Codec Specific Configuration: #1: len 0x02 type 0x02
Codec Specific Configuration: Frame Duration: 10 ms (0x01)
Codec Specific Configuration: #2: len 0x03 type 0x04
Codec Specific Configuration: Frame Length: 40 (0x0028)
Codec Specific Configuration: #3: len 0x05 type 0x03
Codec Specific Configuration: Location: 0x00000001
Codec Specific Configuration: Location: Front Left
(0x00000001)
BIS #0:
Index: 1
BIS #1:
Index: 2
Codec Specific Configuration: #0: len 0x05 type 0x03
Codec Specific Configuration: Location: 0x00000002
Codec Specific Configuration: Location: Front Right
(0x00000002)Only one transport will be created, for BIS index 2, since it was the only one requested in the Add Source command:
[00-60-37-31-7E-3F]# [NEW] Device 0E:D5:8A:63:05:46 0E-D5-8A-63-05-46 [00-60-37-31-7E-3F]# [NEW] Transport
/org/bluez/hci0/dev_0E_D5_8A_63_05_46/bis2/fd0 --- profiles/audio/bap.c | 9 +++++++++ 1 file changed, 9 insertions(+)
profiles/audio/bap.c +9 -0
@@ -1206,6 +1206,15 @@ static bool parse_base(struct bap_data *bap_data, struct bt_iso_base *base,bass_add_stream (bap_data->device, meta, merged_caps, qos, idx, bis_index); +if (!bass_check_bis (bap_data->device, bis_index)) { +/* If this Broadcast Sink is acting as a Scan +* Delegator, only attempt to create streams +* for the BISes required by the peer Broadcast +* Assistant. +*/ +continue ; + } +/* Check if this BIS matches any local PAC */ bt_bap_verify_bis (bap_data->bap, bis_index, merged_caps, &matched_lpac);
Signature · 1 line
2.39.2
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This series was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 13 lines · On Thu, 29 Aug 2024 15:49:02 +0300 you wrote:
This adds support for the BAP Scan Delegator role to handle the Add Source command received from a Broadcast Assistant.
The Broadcast Assistant informs a Scan Delegator about a Broadcaster by sending a GATT write command for the BASS Broadcast Audio Scan Control Point characteristic with the "Add Source" opcode. Using the parameters received through GATT, the Scan Delegator creates a device for the Broadcaster and probes it with BAP. The BAP plugin will then perform long-lived PA sync and it will create streams for each BIS required by the Assistant. The transports can then be acquired/released, and the Assistant will be notified about each change in the state of the streams.
Quoted 1 line
[...]
Here is the summary with links:
- [BlueZ,v2,01/16] shared/bass: Register ATT disconnect cb
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=38b7dc7d17b4 - [BlueZ,v2,02/16] shared/bass: Make bt_bcast_src private https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=25119b6a72aa - [BlueZ,v2,03/16] shared/bass: Remove io handling https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=8abcfd7028e8 - [BlueZ,v2,04/16] shared/bass: Add support to register cp handlers https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=30c190089ffe - [BlueZ,v2,05/16] shared/bass: Call cp handler for the Add Source cmd https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=0446d1eef9ef - [BlueZ,v2,06/16] bap: Add support for long-lived PA sync https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=b65767c5dab5 - [BlueZ,v2,07/16] bap: Add API for Scan Delegator probe https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=b8530f0d2672 - [BlueZ,v2,08/16] bass: Register cp handler for Add Source cmd https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=4191ff1c4045 - [BlueZ,v2,09/16] shared/bass: Add API to set PA sync state https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=06d20a80249b - [BlueZ,v2,10/16] bass: Add APIs to probe/remove Broadcasters https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f3a43bd0e4af - [BlueZ,v2,11/16] bap: Probe Broadcasters with BASS https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ea7b69102434 - [BlueZ,v2,12/16] shared/bass: Add APIs to set/clear BIS sync bits https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=c6278d24d9d2 - [BlueZ,v2,13/16] bass: Register BAP state changed cb https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=a032a570489b - [BlueZ,v2,14/16] shared/bass: Add API to check BIS required for sync https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=7c3821f822f8 - [BlueZ,v2,15/16] bass: Add API to check BIS required for sync https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=df4e11fab68b - [BlueZ,v2,16/16] bap: Create streams for required BISes https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=dfcbc2d3c011
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html