Bluetooth: TBS: Add support for dynamic TBS

The TBS and GTBS instances can now be dynamically registered
and unregistered, which fits better for the use cases of TBS
where specific bearers can come and go depending on the
features of the device.

For example if a SIM card is inserted, then a device can
register a TBS for the provider and remove it again if the
SIM card is removed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2024-07-19 14:43:08 +02:00 committed by Anas Nashif
commit 1406c547d6
6 changed files with 467 additions and 134 deletions

View file

@ -15,6 +15,7 @@
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/audio/bap.h>
#include <zephyr/bluetooth/audio/lc3.h>
#include <zephyr/bluetooth/audio/tbs.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/byteorder.h>
#include <zephyr/bluetooth/gap.h>
@ -24,6 +25,7 @@
#include <zephyr/net_buf.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/util.h>
#include <zephyr/sys/util_macro.h>
#include <zephyr/toolchain.h>
#include "bap_common.h"
@ -194,6 +196,27 @@ static void init(void)
cap_stream_from_audio_test_stream(&broadcast_source_streams[i]);
bt_cap_stream_ops_register(broadcast_streams[i], &broadcast_stream_ops);
}
if (IS_ENABLED(CONFIG_BT_TBS)) {
const struct bt_tbs_register_param gtbs_param = {
.provider_name = "Generic TBS",
.uci = "un000",
.uri_schemes_supported = "tel,skype",
.gtbs = true,
.authorization_required = false,
.technology = BT_TBS_TECHNOLOGY_3G,
.supported_features = CONFIG_BT_TBS_SUPPORTED_FEATURES,
};
err = bt_tbs_register_bearer(&gtbs_param);
if (err < 0) {
FAIL("Failed to register GTBS (err %d)\n", err);
return;
}
printk("Registered GTBS\n");
}
}
static void setup_extended_adv(struct bt_le_ext_adv **adv)
@ -449,14 +472,15 @@ static void test_broadcast_audio_start(struct bt_cap_broadcast_source *broadcast
static void test_broadcast_audio_update_inval(struct bt_cap_broadcast_source *broadcast_source)
{
const uint16_t mock_ccid = 0xAB;
const uint8_t new_metadata[] = {
BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_STREAM_CONTEXT,
BT_BYTES_LIST_LE16(BT_AUDIO_CONTEXT_TYPE_MEDIA)),
BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, mock_ccid),
BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
BT_AUDIO_PARENTAL_RATING_AGE_ANY),
};
const uint8_t invalid_metadata[] = {
BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_CCID_LIST, mock_ccid),
BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_PARENTAL_RATING,
BT_AUDIO_PARENTAL_RATING_AGE_ANY),
};
int err;

View file

@ -8,6 +8,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <zephyr/autoconf.h>
#include <zephyr/bluetooth/audio/tbs.h>
@ -327,22 +328,85 @@ static void test_tbs_server_only(void)
test_set_status_flags();
}
static void test_main(void)
static void init(void)
{
const struct bt_tbs_register_param gtbs_param = {
.provider_name = "Generic TBS",
.uci = "un000",
.uri_schemes_supported = "tel,skype",
.gtbs = true,
.authorization_required = false,
.technology = BT_TBS_TECHNOLOGY_3G,
.supported_features = CONFIG_BT_TBS_SUPPORTED_FEATURES,
};
int err;
err = bt_enable(NULL);
if (err != 0) {
printk("Bluetooth init failed (err %d)\n", err);
FAIL("Bluetooth enable failed (err %d)\n", err);
return;
}
printk("Audio Client: Bluetooth initialized\n");
printk("Bluetooth initialized\n");
err = bt_conn_cb_register(&conn_callbacks);
if (err != 0) {
FAIL("Failed to register conn CBs (err %d)\n", err);
return;
}
err = bt_le_scan_cb_register(&common_scan_cb);
if (err != 0) {
FAIL("Failed to register scan CBs (err %d)\n", err);
return;
}
bt_conn_cb_register(&conn_callbacks);
bt_le_scan_cb_register(&common_scan_cb);
bt_tbs_register_cb(&tbs_cbs);
err = bt_tbs_register_bearer(&gtbs_param);
if (err < 0) {
FAIL("Failed to register GTBS (err %d)\n", err);
return;
}
printk("Registered GTBS\n");
for (int i = 0; i < CONFIG_BT_TBS_BEARER_COUNT; i++) {
char prov_name[22]; /* Enough to store "Telephone Bearer #255" */
const struct bt_tbs_register_param tbs_param = {
.provider_name = prov_name,
.uci = "un000",
.uri_schemes_supported = "tel,skype",
.gtbs = false,
.authorization_required = false,
/* Set different technologies per bearer */
.technology = (i % BT_TBS_TECHNOLOGY_WCDMA) + 1,
.supported_features = CONFIG_BT_TBS_SUPPORTED_FEATURES,
};
snprintf(prov_name, sizeof(prov_name), "Telephone Bearer #%d", i);
err = bt_tbs_register_bearer(&tbs_param);
if (err < 0) {
FAIL("Failed to register TBS[%d]: %d", i, err);
return;
}
printk("Registered TBS[%d] with index %u\n", i, (uint8_t)err);
}
}
static void test_main(void)
{
int err;
init();
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, NULL);
if (err != 0) {
FAIL("Scanning failed to start (err %d)\n", err);
@ -382,14 +446,7 @@ static void test_main(void)
static void tbs_test_server_only(void)
{
int err;
err = bt_enable(NULL);
if (err != 0) {
FAIL("Bluetooth init failed (err %d)\n", err);
return;
}
init();
test_tbs_server_only();