From eb22e1fc983d2d1b2c5e318d96151d66500da621 Mon Sep 17 00:00:00 2001 From: Emil Gydesen Date: Wed, 10 Jul 2024 15:10:39 +0200 Subject: [PATCH] Bluetooth: TBS: Make GTBS mandatory Any places that checked for GTBS is now always enabled as GTBS is mandatory to support, and the Kconfig option was removed. Also removed a duplicate Kconfig option for TBS, BT_TBS_SERVICE_COUNT, as it was unused. The other Kconfig option BT_TBS_BEARER_COUNT is used instead exclusively to set it if needed. Since GTBS can now exist alone, it must also support having its own calls and other values. This means that the GTBS and TBS instances now share the same underlying struct. Signed-off-by: Emil Gydesen --- .../bluetooth/api/audio/shell/ccp.rst | 4 +- samples/bluetooth/tmap_central/prj.conf | 1 - subsys/bluetooth/audio/Kconfig.tbs | 28 +- subsys/bluetooth/audio/shell/bap.c | 4 +- subsys/bluetooth/audio/shell/tbs.c | 14 +- subsys/bluetooth/audio/tbs.c | 950 ++++++++---------- tests/bluetooth/shell/audio.conf | 1 + tests/bluetooth/shell/testcase.yaml | 6 + tests/bluetooth/tester/overlay-le-audio.conf | 4 +- .../bluetooth/tester/src/audio/CMakeLists.txt | 2 +- tests/bluetooth/tester/src/btp_core.c | 4 +- tests/bsim/bluetooth/audio/prj.conf | 1 + 12 files changed, 444 insertions(+), 575 deletions(-) diff --git a/doc/connectivity/bluetooth/api/audio/shell/ccp.rst b/doc/connectivity/bluetooth/api/audio/shell/ccp.rst index 023e8515aa9c79..b03a46aeeba2d7 100644 --- a/doc/connectivity/bluetooth/api/audio/shell/ccp.rst +++ b/doc/connectivity/bluetooth/api/audio/shell/ccp.rst @@ -31,7 +31,7 @@ Since a server may have multiple TBS instances, most of the tbs_client commands will take an index (starting from 0) as input. Joining calls require at least 2 call IDs, and all call indexes shall be on the same TBS instance. -A server may also have a GTBS instance, which is an abstraction layer for all +A server will also have a GTBS instance, which is an abstraction layer for all the telephone bearers on the server. If the server has both GTBS and TBS, the client may subscribe and use either when sending requests if :code:`BT_TBS_CLIENT_GTBS` is enabled. @@ -169,6 +169,8 @@ TBS can be controlled locally, or by a remote device (when in a call). For example a remote device may initiate a call to the device with the TBS server, or the TBS server may initiate a call to remote device, without a TBS_CLIENT client. The TBS implementation is capable of fully controlling any call. +Omitting an index for commands where a :code:`` can be supplied, defaults to the +GTBS bearer. .. code-block:: console diff --git a/samples/bluetooth/tmap_central/prj.conf b/samples/bluetooth/tmap_central/prj.conf index a9a5c02eca3052..d9c67f30b764ac 100644 --- a/samples/bluetooth/tmap_central/prj.conf +++ b/samples/bluetooth/tmap_central/prj.conf @@ -32,7 +32,6 @@ CONFIG_MCTL=y # CCP support CONFIG_BT_TBS=y -CONFIG_BT_GTBS=y CONFIG_BT_TBS_SUPPORTED_FEATURES=3 # Support an ISO channel per ASE diff --git a/subsys/bluetooth/audio/Kconfig.tbs b/subsys/bluetooth/audio/Kconfig.tbs index 2958d134366fb6..01de630df7631e 100644 --- a/subsys/bluetooth/audio/Kconfig.tbs +++ b/subsys/bluetooth/audio/Kconfig.tbs @@ -1,6 +1,7 @@ # Bluetooth Audio - Call control configuration options # # Copyright (c) 2020 Bose Corporation +# Copyright (c) 2024 Nordic Semiconductor ASA # # SPDX-License-Identifier: Apache-2.0 # @@ -15,18 +16,12 @@ config BT_TBS select BT_GATT_DYNAMIC_DB depends on UTF8 help - This option enables support for Telephone Bearer Service. + This option enables support for Telephone Bearer Service. By default this only + initializes the GTBS service. If specific TBS services are wanted, they need to be + enabled by setting BT_TBS_BEARER_COUNT to a non-zero value. if BT_TBS -# TODO: BT_GTBS is mandatory if you support the call control server role. -# Need to enforce this. -config BT_GTBS - bool "Generic Telephone Bearer Service Support" - default y - help - This option enables support for Generic Telephone Bearer Service. - config BT_TBS_PROVIDER_NAME string "Telephone Bearer Service Provider Name" default "Unknown" @@ -101,26 +96,17 @@ config BT_TBS_MAX_CALLS config BT_TBS_BEARER_COUNT int "How many bearer instances the device instantiates" - default 1 - range 1 $(UINT8_MAX) + default 0 + range 0 $(UINT8_MAX) help Sets the number of TBS instances that are instantiated -config BT_TBS_SERVICE_COUNT - int "Number of instantiated bearer service instances" - default BT_TBS_BEARER_COUNT - range 0 BT_TBS_BEARER_COUNT if BT_GTBS - range BT_TBS_BEARER_COUNT BT_TBS_BEARER_COUNT - help - Sets the number of TBS service instances that are instantiated - config BT_TBS_MAX_SCHEME_LIST_LENGTH int "The maximum length of the URI scheme list" default 30 range 0 512 help - Sets the maximum length of the URI scheme list. If BT_GTBS is enabled, - then the maximum length should be maximum 512 / BT_TBS_BEARER_COUNT. + Sets the maximum length of the URI scheme list. config BT_TBS_AUTHORIZATION bool "TBS authorization requirement" diff --git a/subsys/bluetooth/audio/shell/bap.c b/subsys/bluetooth/audio/shell/bap.c index 0cb175ec2eed83..f442dd512dace2 100644 --- a/subsys/bluetooth/audio/shell/bap.c +++ b/subsys/bluetooth/audio/shell/bap.c @@ -4136,8 +4136,8 @@ static ssize_t connectable_ad_data_add(struct bt_data *data_array, IF_ENABLED(CONFIG_BT_ASCS, (BT_UUID_16_ENCODE(BT_UUID_ASCS_VAL),)) IF_ENABLED(CONFIG_BT_BAP_SCAN_DELEGATOR, (BT_UUID_16_ENCODE(BT_UUID_BASS_VAL),)) IF_ENABLED(CONFIG_BT_PACS, (BT_UUID_16_ENCODE(BT_UUID_PACS_VAL),)) - IF_ENABLED(CONFIG_BT_GTBS, (BT_UUID_16_ENCODE(BT_UUID_GTBS_VAL),)) - IF_ENABLED(CONFIG_BT_TBS, (BT_UUID_16_ENCODE(BT_UUID_TBS_VAL),)) + IF_ENABLED(CONFIG_BT_TBS, (BT_UUID_16_ENCODE(BT_UUID_GTBS_VAL),)) + IF_ENABLED(CONFIG_BT_TBS_BEARER_COUNT, (BT_UUID_16_ENCODE(BT_UUID_TBS_VAL),)) IF_ENABLED(CONFIG_BT_VCP_VOL_REND, (BT_UUID_16_ENCODE(BT_UUID_VCS_VAL),)) IF_ENABLED(CONFIG_BT_HAS, (BT_UUID_16_ENCODE(BT_UUID_HAS_VAL),)) /* Shall be last */ }; diff --git a/subsys/bluetooth/audio/shell/tbs.c b/subsys/bluetooth/audio/shell/tbs.c index fb8e2c63954496..479422dc2b4cbe 100644 --- a/subsys/bluetooth/audio/shell/tbs.c +++ b/subsys/bluetooth/audio/shell/tbs.c @@ -209,7 +209,7 @@ static int cmd_tbs_originate(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } } else { - service_index = 0U; + service_index = BT_TBS_GTBS_INDEX; } result = bt_tbs_originate((uint8_t)service_index, argv[argc - 1], @@ -402,7 +402,7 @@ static int cmd_tbs_incoming(const struct shell *sh, size_t argc, char *argv[]) } } } else { - service_index = 0U; + service_index = BT_TBS_GTBS_INDEX; } result = bt_tbs_remote_incoming((uint8_t)service_index, @@ -445,7 +445,7 @@ static int cmd_tbs_set_bearer_provider_name(const struct shell *sh, size_t argc, } } } else { - service_index = 0U; + service_index = BT_TBS_GTBS_INDEX; } result = bt_tbs_set_bearer_provider_name((uint8_t)service_index, @@ -485,7 +485,7 @@ static int cmd_tbs_set_bearer_technology(const struct shell *sh, size_t argc, } } } else { - service_index = 0U; + service_index = BT_TBS_GTBS_INDEX; } technology = shell_strtoul(argv[argc - 1], 0, &result); @@ -538,7 +538,7 @@ static int cmd_tbs_set_bearer_signal_strength(const struct shell *sh, } } } else { - service_index = 0U; + service_index = BT_TBS_GTBS_INDEX; } signal_strength = shell_strtoul(argv[argc - 1], 0, &result); @@ -592,7 +592,7 @@ static int cmd_tbs_set_status_flags(const struct shell *sh, size_t argc, } } } else { - service_index = 0U; + service_index = BT_TBS_GTBS_INDEX; } status_flags = shell_strtoul(argv[argc - 1], 0, &result); @@ -644,7 +644,7 @@ static int cmd_tbs_set_uri_scheme_list(const struct shell *sh, size_t argc, } } } else { - service_index = 0U; + service_index = BT_TBS_GTBS_INDEX; } result = bt_tbs_set_uri_scheme_list((uint8_t)service_index, diff --git a/subsys/bluetooth/audio/tbs.c b/subsys/bluetooth/audio/tbs.c index c34810ecf9ccd0..af958bd0462f2e 100644 --- a/subsys/bluetooth/audio/tbs.c +++ b/subsys/bluetooth/audio/tbs.c @@ -1,7 +1,7 @@ /* Bluetooth TBS - Telephone Bearer Service * * Copyright (c) 2020 Bose Corporation - * Copyright (c) 2021 Nordic Semiconductor ASA + * Copyright (c) 2021-2024 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ @@ -36,9 +36,10 @@ LOG_MODULE_REGISTER(bt_tbs, CONFIG_BT_TBS_LOG_LEVEL); -#define BT_TBS_VALID_STATUS_FLAGS(val) ((val) <= (BIT(0) | BIT(1))) +#define BT_TBS_VALID_STATUS_FLAGS(val) ((val) <= (BIT(0) | BIT(1))) -struct service_inst { +/* A service instance can either be a GTBS or a TBS instance */ +struct tbs_inst { /* Attribute values */ char provider_name[CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH]; char uci[BT_TBS_MAX_UCI_SIZE]; @@ -51,6 +52,9 @@ struct service_inst { struct bt_tbs_in_uri incoming_uri; struct bt_tbs_in_uri friendly_name; struct bt_tbs_in_uri in_call; + char uri_scheme_list[CONFIG_BT_TBS_MAX_SCHEME_LIST_LENGTH]; + struct bt_tbs_terminate_reason terminate_reason; + struct bt_tbs_call calls[CONFIG_BT_TBS_MAX_CALLS]; bool notify_current_calls; bool notify_call_states; @@ -63,48 +67,32 @@ struct service_inst { size_t attr_count; }; -struct tbs_service_inst { - struct service_inst inst; - - /* Attribute values */ - char uri_scheme_list[CONFIG_BT_TBS_MAX_SCHEME_LIST_LENGTH]; - struct bt_tbs_terminate_reason terminate_reason; - - /* Instance values */ - struct bt_tbs_call calls[CONFIG_BT_TBS_MAX_CALLS]; -}; +static struct tbs_inst svc_insts[CONFIG_BT_TBS_BEARER_COUNT]; +static struct tbs_inst gtbs_inst; -struct gtbs_service_inst { - struct service_inst inst; -}; - -#if defined(CONFIG_BT_GTBS) -#define READ_BUF_SIZE (CONFIG_BT_TBS_MAX_CALLS * \ - sizeof(struct bt_tbs_current_call_item) * \ - CONFIG_BT_TBS_BEARER_COUNT) -#else -#define READ_BUF_SIZE (CONFIG_BT_TBS_MAX_CALLS * \ - sizeof(struct bt_tbs_current_call_item)) -#endif /* defined(CONFIG_BT_GTBS) */ +#define READ_BUF_SIZE \ + MAX(BT_ATT_MAX_ATTRIBUTE_LEN, \ + (CONFIG_BT_TBS_MAX_CALLS * sizeof(struct bt_tbs_current_call_item) * \ + (1U + ARRAY_SIZE(svc_insts)))) NET_BUF_SIMPLE_DEFINE_STATIC(read_buf, READ_BUF_SIZE); -static struct tbs_service_inst svc_insts[CONFIG_BT_TBS_BEARER_COUNT]; -static struct gtbs_service_inst gtbs_inst; - /* Used to notify app with held calls in case of join */ static struct bt_tbs_call *held_calls[CONFIG_BT_TBS_MAX_CALLS]; static uint8_t held_calls_cnt; static struct bt_tbs_cb *tbs_cbs; -static bool inst_is_gtbs(const struct service_inst *inst) +static bool inst_is_gtbs(const struct tbs_inst *inst) { - return IS_ENABLED(CONFIG_BT_GTBS) && inst == >bs_inst.inst; + if (CONFIG_BT_TBS_BEARER_COUNT > 0) { + return inst == >bs_inst; + } else { + return true; + } } -static uint8_t inst_index(const struct service_inst *inst) +static uint8_t inst_index(const struct tbs_inst *inst) { - const struct tbs_service_inst *tbs; ptrdiff_t index = 0; __ASSERT_NO_MSG(inst); @@ -113,29 +101,26 @@ static uint8_t inst_index(const struct service_inst *inst) return BT_TBS_GTBS_INDEX; } - tbs = CONTAINER_OF(inst, struct tbs_service_inst, inst); - - index = tbs - svc_insts; + index = inst - svc_insts; __ASSERT(index >= 0 && index < ARRAY_SIZE(svc_insts), "Invalid tbs_inst pointer"); return (uint8_t)index; } -static struct service_inst *inst_lookup_index(uint8_t index) +static struct tbs_inst *inst_lookup_index(uint8_t index) { - if (IS_ENABLED(CONFIG_BT_GTBS) && index == BT_TBS_GTBS_INDEX) { - return >bs_inst.inst; + if (index == BT_TBS_GTBS_INDEX) { + return >bs_inst; } - if (index < CONFIG_BT_TBS_BEARER_COUNT) { - return &svc_insts[index].inst; + if (ARRAY_SIZE(svc_insts) > 0U && index < ARRAY_SIZE(svc_insts)) { + return &svc_insts[index]; } return NULL; } -static struct bt_tbs_call *lookup_call_in_inst(struct tbs_service_inst *inst, - uint8_t call_index) +static struct bt_tbs_call *lookup_call_in_inst(struct tbs_inst *inst, uint8_t call_index) { if (call_index == BT_TBS_FREE_CALL_INDEX) { return NULL; @@ -158,15 +143,19 @@ static struct bt_tbs_call *lookup_call_in_inst(struct tbs_service_inst *inst, */ static struct bt_tbs_call *lookup_call(uint8_t call_index) { + struct bt_tbs_call *call; if (call_index == BT_TBS_FREE_CALL_INDEX) { return NULL; } - for (int i = 0; i < ARRAY_SIZE(svc_insts); i++) { - struct bt_tbs_call *call = lookup_call_in_inst(&svc_insts[i], - call_index); + call = lookup_call_in_inst(>bs_inst, call_index); + if (call != NULL) { + return call; + } + for (size_t i = 0; i < ARRAY_SIZE(svc_insts); i++) { + call = lookup_call_in_inst(&svc_insts[i], call_index); if (call != NULL) { return call; } @@ -175,7 +164,7 @@ static struct bt_tbs_call *lookup_call(uint8_t call_index) return NULL; } -static bool inst_check_attr(struct service_inst *inst, const struct bt_gatt_attr *attr) +static bool inst_check_attr(struct tbs_inst *inst, const struct bt_gatt_attr *attr) { for (size_t j = 0; j < inst->attr_count; j++) { if (&inst->attrs[j] == attr) { @@ -186,31 +175,35 @@ static bool inst_check_attr(struct service_inst *inst, const struct bt_gatt_attr return false; } -static struct service_inst *lookup_inst_by_attr(const struct bt_gatt_attr *attr) +static struct tbs_inst *lookup_inst_by_attr(const struct bt_gatt_attr *attr) { if (attr == NULL) { return NULL; } for (int i = 0; i < ARRAY_SIZE(svc_insts); i++) { - if (inst_check_attr(&svc_insts[i].inst, attr)) { - return &svc_insts[i].inst; + if (inst_check_attr(&svc_insts[i], attr)) { + return &svc_insts[i]; } } - if (IS_ENABLED(CONFIG_BT_GTBS) && inst_check_attr(>bs_inst.inst, attr)) { - return >bs_inst.inst; + if (inst_check_attr(>bs_inst, attr)) { + return >bs_inst; } return NULL; } -static struct tbs_service_inst *lookup_inst_by_call_index(uint8_t call_index) +static struct tbs_inst *lookup_inst_by_call_index(uint8_t call_index) { if (call_index == BT_TBS_FREE_CALL_INDEX) { return NULL; } + if (lookup_call_in_inst(>bs_inst, call_index) != NULL) { + return >bs_inst; + } + for (size_t i = 0; i < ARRAY_SIZE(svc_insts); i++) { if (lookup_call_in_inst(&svc_insts[i], call_index) != NULL) { return &svc_insts[i]; @@ -233,8 +226,7 @@ static bool is_authorized(struct bt_conn *conn) return true; } -static bool uri_scheme_in_list(const char *uri_scheme, - const char *uri_scheme_list) +static bool uri_scheme_in_list(const char *uri_scheme, const char *uri_scheme_list) { const size_t scheme_len = strlen(uri_scheme); const size_t scheme_list_len = strlen(uri_scheme_list); @@ -262,9 +254,9 @@ static bool uri_scheme_in_list(const char *uri_scheme, return false; } -static struct tbs_service_inst *lookup_inst_by_uri_scheme(const uint8_t *uri, uint8_t uri_len) +static struct tbs_inst *lookup_inst_by_uri_scheme(const uint8_t *uri, uint8_t uri_len) { - char uri_scheme[CONFIG_BT_TBS_MAX_URI_LENGTH] = { 0 }; + char uri_scheme[CONFIG_BT_TBS_MAX_URI_LENGTH] = {0}; if (uri_len == 0) { return NULL; @@ -285,35 +277,29 @@ static struct tbs_service_inst *lookup_inst_by_uri_scheme(const uint8_t *uri, ui for (size_t i = 0; i < ARRAY_SIZE(svc_insts); i++) { for (size_t j = 0; j < ARRAY_SIZE(svc_insts[i].calls); j++) { - if (uri_scheme_in_list(uri_scheme, - svc_insts[i].uri_scheme_list)) { + if (uri_scheme_in_list(uri_scheme, svc_insts[i].uri_scheme_list)) { return &svc_insts[i]; } } } + /* If not found in any TBS instance, check GTBS */ + if (uri_scheme_in_list(uri_scheme, gtbs_inst.uri_scheme_list)) { + return >bs_inst; + } + return NULL; } -static void tbs_set_terminate_reason(struct tbs_service_inst *inst, - uint8_t call_index, uint8_t reason) +static void tbs_set_terminate_reason(struct tbs_inst *inst, uint8_t call_index, uint8_t reason) { inst->terminate_reason.call_index = call_index; inst->terminate_reason.reason = reason; - LOG_DBG("Index %u: call index 0x%02x, reason %s", inst_index(&inst->inst), call_index, + LOG_DBG("Index %u: call index 0x%02x, reason %s", inst_index(inst), call_index, bt_tbs_term_reason_str(reason)); - bt_gatt_notify_uuid(NULL, BT_UUID_TBS_TERMINATE_REASON, - inst->inst.attrs, - (void *)&inst->terminate_reason, - sizeof(inst->terminate_reason)); - - if (IS_ENABLED(CONFIG_BT_GTBS)) { - bt_gatt_notify_uuid(NULL, BT_UUID_TBS_TERMINATE_REASON, - gtbs_inst.inst.attrs, - (void *)&inst->terminate_reason, - sizeof(inst->terminate_reason)); - } + bt_gatt_notify_uuid(NULL, BT_UUID_TBS_TERMINATE_REASON, inst->attrs, + (void *)&inst->terminate_reason, sizeof(inst->terminate_reason)); } /** @@ -322,6 +308,9 @@ static void tbs_set_terminate_reason(struct tbs_service_inst *inst, * For each new call, the call index should be incremented and wrap at 255. * However, the index = 0 is reserved for outgoing calls * + * Call indexes are shared among all bearers, so there is always a 1:1 between a call index and a + * bearer + * * @return uint8_t The next free call index */ static uint8_t next_free_call_index(void) @@ -349,8 +338,8 @@ static uint8_t next_free_call_index(void) return BT_TBS_FREE_CALL_INDEX; } -static struct bt_tbs_call *call_alloc(struct tbs_service_inst *inst, uint8_t state, - const uint8_t *uri, uint16_t uri_len) +static struct bt_tbs_call *call_alloc(struct tbs_inst *inst, uint8_t state, const uint8_t *uri, + uint16_t uri_len) { struct bt_tbs_call *free_call = NULL; @@ -385,8 +374,7 @@ static void call_free(struct bt_tbs_call *call) call->index = BT_TBS_FREE_CALL_INDEX; } -static void net_buf_put_call_states_by_inst(const struct tbs_service_inst *inst, - struct net_buf_simple *buf) +static void net_buf_put_call_states_by_inst(const struct tbs_inst *inst, struct net_buf_simple *buf) { const struct bt_tbs_call *call; const struct bt_tbs_call *calls; @@ -401,30 +389,34 @@ static void net_buf_put_call_states_by_inst(const struct tbs_service_inst *inst, continue; } + if (buf->len + 3U > buf->size) { + LOG_WRN("Not able to store all call states in buffer"); + return; + } + net_buf_simple_add_u8(buf, call->index); net_buf_simple_add_u8(buf, call->state); net_buf_simple_add_u8(buf, call->flags); } } -static void net_buf_put_call_states(const struct service_inst *inst, struct net_buf_simple *buf) +static void net_buf_put_call_states(const struct tbs_inst *inst, struct net_buf_simple *buf) { net_buf_simple_reset(buf); + net_buf_put_call_states_by_inst(inst, buf); + + /* For GTBS we add all the calls the GTBS bearer has itself, as well as all the other + * bearers + */ if (inst_is_gtbs(inst)) { for (size_t i = 0; i < ARRAY_SIZE(svc_insts); i++) { net_buf_put_call_states_by_inst(&svc_insts[i], buf); } - } else { - struct tbs_service_inst *service_inst; - - service_inst = CONTAINER_OF(inst, struct tbs_service_inst, inst); - - net_buf_put_call_states_by_inst(service_inst, buf); } } -static void net_buf_put_current_calls_by_inst(const struct tbs_service_inst *inst, +static void net_buf_put_current_calls_by_inst(const struct tbs_inst *inst, struct net_buf_simple *buf) { const struct bt_tbs_call *call; @@ -445,7 +437,15 @@ static void net_buf_put_current_calls_by_inst(const struct tbs_service_inst *ins uri_length = strlen(call->remote_uri); item_len = sizeof(call->index) + sizeof(call->state) + sizeof(call->flags) + uri_length; - net_buf_simple_add_u8(buf, item_len); + + __ASSERT_NO_MSG(item_len <= UINT8_MAX); + + if (buf->len + sizeof(uint8_t) + item_len > buf->size) { + LOG_WRN("Not able to store all calls in buffer"); + return; + } + + net_buf_simple_add_u8(buf, (uint8_t)item_len); net_buf_simple_add_u8(buf, call->index); net_buf_simple_add_u8(buf, call->state); net_buf_simple_add_u8(buf, call->flags); @@ -453,32 +453,31 @@ static void net_buf_put_current_calls_by_inst(const struct tbs_service_inst *ins } } -static void net_buf_put_current_calls(const struct service_inst *inst, struct net_buf_simple *buf) +static void net_buf_put_current_calls(const struct tbs_inst *inst, struct net_buf_simple *buf) { net_buf_simple_reset(buf); + net_buf_put_current_calls_by_inst(inst, buf); + + /* For GTBS we add all the calls the GTBS bearer has itself, as well as all the other + * bearers + */ if (inst_is_gtbs(inst)) { for (size_t i = 0; i < ARRAY_SIZE(svc_insts); i++) { net_buf_put_current_calls_by_inst(&svc_insts[i], buf); } - } else { - struct tbs_service_inst *service_inst; - - service_inst = CONTAINER_OF(inst, struct tbs_service_inst, inst); - - net_buf_put_current_calls_by_inst(service_inst, buf); } } -static int inst_notify_calls(const struct service_inst *inst) +static int inst_notify_calls(const struct tbs_inst *inst) { int err; if (inst->notify_call_states) { net_buf_put_call_states(inst, &read_buf); - err = bt_gatt_notify_uuid(NULL, BT_UUID_TBS_CALL_STATE, inst->attrs, - read_buf.data, read_buf.len); + err = bt_gatt_notify_uuid(NULL, BT_UUID_TBS_CALL_STATE, inst->attrs, read_buf.data, + read_buf.len); if (err != 0) { return err; } @@ -497,87 +496,91 @@ static int inst_notify_calls(const struct service_inst *inst) return 0; } -static int notify_calls(const struct tbs_service_inst *inst) +static int notify_calls(const struct tbs_inst *inst) { + int err; + if (inst == NULL) { return -EINVAL; } - if (IS_ENABLED(CONFIG_BT_GTBS)) { - int err; + /* Notify TBS */ + err = inst_notify_calls(inst); + if (err != 0) { + return err; + } - err = inst_notify_calls(>bs_inst.inst); + if (!inst_is_gtbs(inst)) { + /* If the instance is different than the GTBS notify on the GTBS instance as well */ + err = inst_notify_calls(>bs_inst); if (err != 0) { return err; } } - return inst_notify_calls(&inst->inst); + return 0; } -static ssize_t read_provider_name(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_provider_name(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); LOG_DBG("Index %u, Provider name %s", inst_index(inst), inst->provider_name); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - inst->provider_name, strlen(inst->provider_name)); + return bt_gatt_attr_read(conn, attr, buf, len, offset, inst->provider_name, + strlen(inst->provider_name)); } -static void provider_name_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void provider_name_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_uci(struct bt_conn *conn, const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_uci(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); LOG_DBG("Index %u: UCI %s", inst_index(inst), inst->uci); return bt_gatt_attr_read(conn, attr, buf, len, offset, inst->uci, strlen(inst->uci)); } -static ssize_t read_technology(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_technology(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); LOG_DBG("Index %u: Technology 0x%02x", inst_index(inst), inst->technology); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &inst->technology, sizeof(inst->technology)); + return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->technology, + sizeof(inst->technology)); } -static void technology_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void technology_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_uri_scheme_list(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +static ssize_t read_uri_scheme_list(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { - const struct service_inst *inst_p = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); net_buf_simple_reset(&read_buf); - if (inst_is_gtbs(inst_p)) { + net_buf_simple_add_mem(&read_buf, inst->uri_scheme_list, strlen(inst->uri_scheme_list)); + + if (inst_is_gtbs(inst)) { /* TODO: Make uri schemes unique */ for (size_t i = 0; i < ARRAY_SIZE(svc_insts); i++) { size_t uri_len = strlen(svc_insts[i].uri_scheme_list); @@ -588,85 +591,67 @@ static ssize_t read_uri_scheme_list(struct bt_conn *conn, break; } - net_buf_simple_add_mem(&read_buf, - svc_insts[i].uri_scheme_list, - uri_len); + net_buf_simple_add_mem(&read_buf, svc_insts[i].uri_scheme_list, uri_len); } LOG_DBG("GTBS: URI scheme %.*s", read_buf.len, read_buf.data); } else { - const struct tbs_service_inst *inst; - - inst = CONTAINER_OF(inst_p, struct tbs_service_inst, inst); - - net_buf_simple_add_mem(&read_buf, inst->uri_scheme_list, - strlen(inst->uri_scheme_list)); - - LOG_DBG("Index %u: URI scheme %.*s", - inst_index(inst_p), read_buf.len, read_buf.data); + LOG_DBG("Index %u: URI scheme %.*s", inst_index(inst), read_buf.len, read_buf.data); } - return bt_gatt_attr_read(conn, attr, buf, len, offset, - read_buf.data, read_buf.len); + return bt_gatt_attr_read(conn, attr, buf, len, offset, read_buf.data, read_buf.len); } -static void uri_scheme_list_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void uri_scheme_list_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_signal_strength(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +static ssize_t read_signal_strength(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); LOG_DBG("Index %u: Signal strength 0x%02x", inst_index(inst), inst->signal_strength); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &inst->signal_strength, sizeof(inst->signal_strength)); + return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->signal_strength, + sizeof(inst->signal_strength)); } -static void signal_strength_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void signal_strength_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_signal_strength_interval(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, - uint16_t offset) +static ssize_t read_signal_strength_interval(struct bt_conn *conn, const struct bt_gatt_attr *attr, + void *buf, uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); if (!is_authorized(conn)) { return BT_GATT_ERR(BT_ATT_ERR_AUTHORIZATION); } - LOG_DBG("Index %u: Signal strength interval 0x%02x", - inst_index(inst), inst->signal_strength_interval); + LOG_DBG("Index %u: Signal strength interval 0x%02x", inst_index(inst), + inst->signal_strength_interval); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - &inst->signal_strength_interval, + return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->signal_strength_interval, sizeof(inst->signal_strength_interval)); } -static ssize_t write_signal_strength_interval(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) +static ssize_t write_signal_strength_interval(struct bt_conn *conn, const struct bt_gatt_attr *attr, + const void *buf, uint16_t len, uint16_t offset, + uint8_t flags) { - struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); struct net_buf_simple net_buf; uint8_t signal_strength_interval; @@ -691,10 +676,9 @@ static ssize_t write_signal_strength_interval(struct bt_conn *conn, return len; } -static void current_calls_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void current_calls_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - struct service_inst *inst = lookup_inst_by_attr(attr); + struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); @@ -702,11 +686,10 @@ static void current_calls_cfg_changed(const struct bt_gatt_attr *attr, } } -static ssize_t read_current_calls(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_current_calls(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); LOG_DBG("Index %u", inst_index(inst)); @@ -716,26 +699,23 @@ static ssize_t read_current_calls(struct bt_conn *conn, LOG_HEXDUMP_DBG(read_buf.data, read_buf.len, "Current calls"); } - return bt_gatt_attr_read(conn, attr, buf, len, offset, - read_buf.data, read_buf.len); + return bt_gatt_attr_read(conn, attr, buf, len, offset, read_buf.data, read_buf.len); } -static ssize_t read_ccid(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_ccid(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); LOG_DBG("Index %u: CCID 0x%02x", inst_index(inst), inst->ccid); return bt_gatt_attr_read(conn, attr, buf, len, offset, &inst->ccid, sizeof(inst->ccid)); } -static ssize_t read_status_flags(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_status_flags(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const uint16_t status_flags_le = sys_cpu_to_le16(inst->optional_opcodes); LOG_DBG("Index %u: status_flags 0x%04x", inst_index(inst), inst->status_flags); @@ -744,22 +724,19 @@ static ssize_t read_status_flags(struct bt_conn *conn, sizeof(status_flags_le)); } -static void status_flags_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void status_flags_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_incoming_uri(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, - uint16_t offset) +static ssize_t read_incoming_uri(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct bt_tbs_in_uri *inc_call_target; size_t val_len; @@ -774,28 +751,24 @@ static ssize_t read_incoming_uri(struct bt_conn *conn, return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); } - val_len = sizeof(inc_call_target->call_index) + - strlen(inc_call_target->uri); + val_len = sizeof(inc_call_target->call_index) + strlen(inc_call_target->uri); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - inc_call_target, val_len); + return bt_gatt_attr_read(conn, attr, buf, len, offset, inc_call_target, val_len); } -static void incoming_uri_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void incoming_uri_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_call_state(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_call_state(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); LOG_DBG("Index %u", inst_index(inst)); @@ -805,14 +778,12 @@ static ssize_t read_call_state(struct bt_conn *conn, LOG_HEXDUMP_DBG(read_buf.data, read_buf.len, "Call state"); } - return bt_gatt_attr_read(conn, attr, buf, len, offset, - read_buf.data, read_buf.len); + return bt_gatt_attr_read(conn, attr, buf, len, offset, read_buf.data, read_buf.len); } -static void call_state_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void call_state_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - struct service_inst *inst = lookup_inst_by_attr(attr); + struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); @@ -820,14 +791,11 @@ static void call_state_cfg_changed(const struct bt_gatt_attr *attr, } } -static int notify_ccp(struct bt_conn *conn, const struct bt_gatt_attr *attr, - uint8_t call_index, uint8_t opcode, uint8_t status) +static int notify_ccp(struct bt_conn *conn, const struct bt_gatt_attr *attr, uint8_t call_index, + uint8_t opcode, uint8_t status) { const struct bt_tbs_call_cp_notify ccp_not = { - .call_index = call_index, - .opcode = opcode, - .status = status - }; + .call_index = call_index, .opcode = opcode, .status = status}; LOG_DBG("Notifying CCP: Call index %u, %s opcode and status %s", call_index, bt_tbs_opcode_str(opcode), bt_tbs_status_str(status)); @@ -835,8 +803,7 @@ static int notify_ccp(struct bt_conn *conn, const struct bt_gatt_attr *attr, return bt_gatt_notify(conn, attr, &ccp_not, sizeof(ccp_not)); } -static void hold_other_calls(struct tbs_service_inst *inst, - uint8_t call_index_cnt, +static void hold_other_calls(struct tbs_inst *inst, uint8_t call_index_cnt, const uint8_t *call_indexes) { held_calls_cnt = 0; @@ -861,15 +828,13 @@ static void hold_other_calls(struct tbs_service_inst *inst, inst->calls[i].state = BT_TBS_CALL_STATE_LOCALLY_HELD; held_calls[held_calls_cnt++] = &inst->calls[i]; } else if (call_state == BT_TBS_CALL_STATE_REMOTELY_HELD) { - inst->calls[i].state = - BT_TBS_CALL_STATE_LOCALLY_AND_REMOTELY_HELD; + inst->calls[i].state = BT_TBS_CALL_STATE_LOCALLY_AND_REMOTELY_HELD; held_calls[held_calls_cnt++] = &inst->calls[i]; } } } -static uint8_t accept_call(struct tbs_service_inst *inst, - const struct bt_tbs_call_cp_acc *ccp) +static uint8_t accept_call(struct tbs_inst *inst, const struct bt_tbs_call_cp_acc *ccp) { struct bt_tbs_call *call = lookup_call_in_inst(inst, ccp->call_index); @@ -888,8 +853,7 @@ static uint8_t accept_call(struct tbs_service_inst *inst, } } -static uint8_t terminate_call(struct tbs_service_inst *inst, - const struct bt_tbs_call_cp_term *ccp, +static uint8_t terminate_call(struct tbs_inst *inst, const struct bt_tbs_call_cp_term *ccp, uint8_t reason) { struct bt_tbs_call *call = lookup_call_in_inst(inst, ccp->call_index); @@ -901,15 +865,21 @@ static uint8_t terminate_call(struct tbs_service_inst *inst, call_free(call); tbs_set_terminate_reason(inst, ccp->call_index, reason); + if (!inst_is_gtbs(inst)) { + /* If the instance is different than the GTBS we set the termination reason and + * notify on the GTBS instance as well + */ + tbs_set_terminate_reason(>bs_inst, ccp->call_index, reason); + } + return BT_TBS_RESULT_CODE_SUCCESS; } -static uint8_t tbs_hold_call(struct tbs_service_inst *inst, - const struct bt_tbs_call_cp_hold *ccp) +static uint8_t tbs_hold_call(struct tbs_inst *inst, const struct bt_tbs_call_cp_hold *ccp) { struct bt_tbs_call *call = lookup_call_in_inst(inst, ccp->call_index); - if ((inst->inst.optional_opcodes & BT_TBS_FEATURE_HOLD) == 0) { + if ((inst->optional_opcodes & BT_TBS_FEATURE_HOLD) == 0) { return BT_TBS_RESULT_CODE_OPCODE_NOT_SUPPORTED; } @@ -930,12 +900,11 @@ static uint8_t tbs_hold_call(struct tbs_service_inst *inst, return BT_TBS_RESULT_CODE_SUCCESS; } -static uint8_t retrieve_call(struct tbs_service_inst *inst, - const struct bt_tbs_call_cp_retrieve *ccp) +static uint8_t retrieve_call(struct tbs_inst *inst, const struct bt_tbs_call_cp_retrieve *ccp) { struct bt_tbs_call *call = lookup_call_in_inst(inst, ccp->call_index); - if ((inst->inst.optional_opcodes & BT_TBS_FEATURE_HOLD) == 0) { + if ((inst->optional_opcodes & BT_TBS_FEATURE_HOLD) == 0) { return BT_TBS_RESULT_CODE_OPCODE_NOT_SUPPORTED; } @@ -956,8 +925,7 @@ static uint8_t retrieve_call(struct tbs_service_inst *inst, return BT_TBS_RESULT_CODE_SUCCESS; } -static int originate_call(struct tbs_service_inst *inst, - const struct bt_tbs_call_cp_originate *ccp, +static int originate_call(struct tbs_inst *inst, const struct bt_tbs_call_cp_originate *ccp, uint16_t uri_len, uint8_t *call_index) { struct bt_tbs_call *call; @@ -992,14 +960,13 @@ static int originate_call(struct tbs_service_inst *inst, return BT_TBS_RESULT_CODE_SUCCESS; } -static uint8_t join_calls(struct tbs_service_inst *inst, - const struct bt_tbs_call_cp_join *ccp, +static uint8_t join_calls(struct tbs_inst *inst, const struct bt_tbs_call_cp_join *ccp, uint16_t call_index_cnt) { struct bt_tbs_call *joined_calls[CONFIG_BT_TBS_MAX_CALLS]; uint8_t call_state; - if ((inst->inst.optional_opcodes & BT_TBS_FEATURE_JOIN) == 0) { + if ((inst->optional_opcodes & BT_TBS_FEATURE_JOIN) == 0) { return BT_TBS_RESULT_CODE_OPCODE_NOT_SUPPORTED; } @@ -1019,8 +986,7 @@ static uint8_t join_calls(struct tbs_service_inst *inst, /* Validate that all calls are in a joinable state */ for (int i = 0; i < call_index_cnt; i++) { - joined_calls[i] = lookup_call_in_inst(inst, - ccp->call_indexes[i]); + joined_calls[i] = lookup_call_in_inst(inst, ccp->call_indexes[i]); if (joined_calls[i] == NULL) { return BT_TBS_RESULT_CODE_INVALID_CALL_INDEX; } @@ -1044,10 +1010,8 @@ static uint8_t join_calls(struct tbs_service_inst *inst, if (call_state == BT_TBS_CALL_STATE_LOCALLY_HELD) { joined_calls[i]->state = BT_TBS_CALL_STATE_ACTIVE; - } else if (call_state == - BT_TBS_CALL_STATE_LOCALLY_AND_REMOTELY_HELD) { - joined_calls[i]->state = - BT_TBS_CALL_STATE_REMOTELY_HELD; + } else if (call_state == BT_TBS_CALL_STATE_LOCALLY_AND_REMOTELY_HELD) { + joined_calls[i]->state = BT_TBS_CALL_STATE_REMOTELY_HELD; } else if (call_state == BT_TBS_CALL_STATE_INCOMING) { joined_calls[i]->state = BT_TBS_CALL_STATE_ACTIVE; } @@ -1059,7 +1023,7 @@ static uint8_t join_calls(struct tbs_service_inst *inst, return BT_TBS_RESULT_CODE_SUCCESS; } -static void notify_app(struct bt_conn *conn, struct tbs_service_inst *inst, uint16_t len, +static void notify_app(struct bt_conn *conn, struct tbs_inst *inst, uint16_t len, const union bt_tbs_call_cp_t *ccp, uint8_t status, uint8_t call_index) { if (tbs_cbs == NULL) { @@ -1074,8 +1038,7 @@ static void notify_app(struct bt_conn *conn, struct tbs_service_inst *inst, uint break; case BT_TBS_CALL_OPCODE_TERMINATE: if (tbs_cbs->terminate_call != NULL) { - tbs_cbs->terminate_call(conn, call_index, - inst->terminate_reason.reason); + tbs_cbs->terminate_call(conn, call_index, inst->terminate_reason.reason); } break; case BT_TBS_CALL_OPCODE_HOLD: @@ -1088,8 +1051,7 @@ static void notify_app(struct bt_conn *conn, struct tbs_service_inst *inst, uint tbs_cbs->retrieve_call(conn, call_index); } break; - case BT_TBS_CALL_OPCODE_ORIGINATE: - { + case BT_TBS_CALL_OPCODE_ORIGINATE: { char uri[CONFIG_BT_TBS_MAX_URI_LENGTH + 1]; const uint16_t uri_len = len - sizeof(ccp->originate); bool remote_party_alerted = false; @@ -1105,18 +1067,14 @@ static void notify_app(struct bt_conn *conn, struct tbs_service_inst *inst, uint (void)memcpy(uri, ccp->originate.uri, uri_len); uri[uri_len] = '\0'; if (tbs_cbs->originate_call != NULL) { - remote_party_alerted = tbs_cbs->originate_call(conn, - call_index, - uri); + remote_party_alerted = tbs_cbs->originate_call(conn, call_index, uri); } if (remote_party_alerted) { call->state = BT_TBS_CALL_STATE_ALERTING; } else { const struct bt_tbs_call_cp_term term = { - .call_index = call_index, - .opcode = BT_TBS_CALL_OPCODE_TERMINATE - }; + .call_index = call_index, .opcode = BT_TBS_CALL_OPCODE_TERMINATE}; /* Terminate and remove call */ terminate_call(inst, &term, BT_TBS_REASON_CALL_FAILED); @@ -1126,14 +1084,12 @@ static void notify_app(struct bt_conn *conn, struct tbs_service_inst *inst, uint break; } - case BT_TBS_CALL_OPCODE_JOIN: - { + case BT_TBS_CALL_OPCODE_JOIN: { const uint16_t call_index_cnt = len - sizeof(ccp->join); /* Let the app know about joined calls */ if (tbs_cbs->join_calls != NULL) { - tbs_cbs->join_calls(conn, call_index_cnt, - ccp->join.call_indexes); + tbs_cbs->join_calls(conn, call_index_cnt, ccp->join.call_indexes); } break; } @@ -1149,14 +1105,12 @@ static void notify_app(struct bt_conn *conn, struct tbs_service_inst *inst, uint } } -static ssize_t write_call_cp(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, uint16_t len, - uint16_t offset, uint8_t flags) +static ssize_t write_call_cp(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, + uint16_t len, uint16_t offset, uint8_t flags) { - struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const union bt_tbs_call_cp_t *ccp = (union bt_tbs_call_cp_t *)buf; - struct tbs_service_inst *tbs = NULL; + struct tbs_inst *tbs = NULL; uint8_t status; uint8_t call_index = 0; const bool is_gtbs = inst_is_gtbs(inst); @@ -1173,8 +1127,8 @@ static ssize_t write_call_cp(struct bt_conn *conn, return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); } - LOG_DBG("Index %u: Processing the %s opcode", - inst_index(inst), bt_tbs_opcode_str(ccp->opcode)); + LOG_DBG("Index %u: Processing the %s opcode", inst_index(inst), + bt_tbs_opcode_str(ccp->opcode)); switch (ccp->opcode) { case BT_TBS_CALL_OPCODE_ACCEPT: @@ -1191,7 +1145,7 @@ static ssize_t write_call_cp(struct bt_conn *conn, break; } } else { - tbs = CONTAINER_OF(inst, struct tbs_service_inst, inst); + tbs = inst; } status = accept_call(tbs, &ccp->accept); @@ -1210,7 +1164,7 @@ static ssize_t write_call_cp(struct bt_conn *conn, break; } } else { - tbs = CONTAINER_OF(inst, struct tbs_service_inst, inst); + tbs = inst; } status = terminate_call(tbs, &ccp->terminate, BT_TBS_REASON_CLIENT_TERMINATED); @@ -1229,7 +1183,7 @@ static ssize_t write_call_cp(struct bt_conn *conn, break; } } else { - tbs = CONTAINER_OF(inst, struct tbs_service_inst, inst); + tbs = inst; } status = tbs_hold_call(tbs, &ccp->hold); @@ -1248,13 +1202,12 @@ static ssize_t write_call_cp(struct bt_conn *conn, break; } } else { - tbs = CONTAINER_OF(inst, struct tbs_service_inst, inst); + tbs = inst; } status = retrieve_call(tbs, &ccp->retrieve); break; - case BT_TBS_CALL_OPCODE_ORIGINATE: - { + case BT_TBS_CALL_OPCODE_ORIGINATE: { const uint16_t uri_len = len - sizeof(ccp->originate); if (len < sizeof(ccp->originate) + BT_TBS_MIN_URI_LEN) { @@ -1264,22 +1217,17 @@ static ssize_t write_call_cp(struct bt_conn *conn, if (is_gtbs) { tbs = lookup_inst_by_uri_scheme(ccp->originate.uri, uri_len); if (tbs == NULL) { - /* TODO: Couldn't find fitting TBS instance; - * use the first. If we want to be - * restrictive about URIs, return - * Invalid Caller ID instead - */ - tbs = &svc_insts[0]; + status = BT_TBS_RESULT_CODE_INVALID_URI; + break; } } else { - tbs = CONTAINER_OF(inst, struct tbs_service_inst, inst); + tbs = inst; } status = originate_call(tbs, &ccp->originate, uri_len, &call_index); break; } - case BT_TBS_CALL_OPCODE_JOIN: - { + case BT_TBS_CALL_OPCODE_JOIN: { const uint16_t call_index_cnt = len - sizeof(ccp->join); if (len < sizeof(ccp->join) + 1) { /* at least 1 call index */ @@ -1295,7 +1243,7 @@ static ssize_t write_call_cp(struct bt_conn *conn, break; } } else { - tbs = CONTAINER_OF(inst, struct tbs_service_inst, inst); + tbs = inst; } status = join_calls(tbs, &ccp->join, call_index_cnt); @@ -1342,18 +1290,17 @@ static ssize_t write_call_cp(struct bt_conn *conn, static void call_cp_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_optional_opcodes(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +static ssize_t read_optional_opcodes(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const uint16_t optional_opcodes_le = sys_cpu_to_le16(inst->optional_opcodes); LOG_DBG("Index %u: Supported opcodes 0x%02x", inst_index(inst), inst->optional_opcodes); @@ -1362,59 +1309,53 @@ static ssize_t read_optional_opcodes(struct bt_conn *conn, sizeof(optional_opcodes_le)); } -static void terminate_reason_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void terminate_reason_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_friendly_name(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_friendly_name(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct bt_tbs_in_uri *friendly_name = &inst->friendly_name; size_t val_len; - LOG_DBG("Index: 0x%02x call index 0x%02x, URI %s", - inst_index(inst), friendly_name->call_index, friendly_name->uri); + LOG_DBG("Index: 0x%02x call index 0x%02x, URI %s", inst_index(inst), + friendly_name->call_index, friendly_name->uri); if (friendly_name->call_index == BT_TBS_FREE_CALL_INDEX) { LOG_DBG("URI not set"); return bt_gatt_attr_read(conn, attr, buf, len, offset, NULL, 0); } - val_len = sizeof(friendly_name->call_index) + - strlen(friendly_name->uri); + val_len = sizeof(friendly_name->call_index) + strlen(friendly_name->uri); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - friendly_name, val_len); + return bt_gatt_attr_read(conn, attr, buf, len, offset, friendly_name, val_len); } -static void friendly_name_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void friendly_name_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -static ssize_t read_incoming_call(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, uint16_t len, uint16_t offset) +static ssize_t read_incoming_call(struct bt_conn *conn, const struct bt_gatt_attr *attr, void *buf, + uint16_t len, uint16_t offset) { - const struct service_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); + const struct tbs_inst *inst = BT_AUDIO_CHRC_USER_DATA(attr); const struct bt_tbs_in_uri *remote_uri = &inst->in_call; size_t val_len; - LOG_DBG("Index: 0x%02x call index 0x%02x, URI %s", - inst_index(inst), remote_uri->call_index, remote_uri->uri); + LOG_DBG("Index: 0x%02x call index 0x%02x, URI %s", inst_index(inst), remote_uri->call_index, + remote_uri->uri); if (remote_uri->call_index == BT_TBS_FREE_CALL_INDEX) { LOG_DBG("URI not set"); @@ -1424,159 +1365,116 @@ static ssize_t read_incoming_call(struct bt_conn *conn, val_len = sizeof(remote_uri->call_index) + strlen(remote_uri->uri); - return bt_gatt_attr_read(conn, attr, buf, len, offset, - remote_uri, val_len); + return bt_gatt_attr_read(conn, attr, buf, len, offset, remote_uri, val_len); } -static void in_call_cfg_changed(const struct bt_gatt_attr *attr, - uint16_t value) +static void in_call_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) { - const struct service_inst *inst = lookup_inst_by_attr(attr); + const struct tbs_inst *inst = lookup_inst_by_attr(attr); if (inst != NULL) { LOG_DBG("Index %u: value 0x%04x", inst_index(inst), value); } } -#define BT_TBS_CHR_PROVIDER_NAME(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_PROVIDER_NAME, \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_provider_name, NULL, inst), \ - BT_AUDIO_CCC(provider_name_cfg_changed) - -#define BT_TBS_CHR_UCI(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_UCI, \ - BT_GATT_CHRC_READ, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_uci, NULL, inst) - -#define BT_TBS_CHR_TECHNOLOGY(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_TECHNOLOGY, \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_technology, NULL, inst), \ - BT_AUDIO_CCC(technology_cfg_changed) - -#define BT_TBS_CHR_URI_LIST(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_URI_LIST, \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_uri_scheme_list, NULL, inst), \ - BT_AUDIO_CCC(uri_scheme_list_cfg_changed) - -#define BT_TBS_CHR_SIGNAL_STRENGTH(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_SIGNAL_STRENGTH, /* Optional */ \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_signal_strength, NULL, inst), \ - BT_AUDIO_CCC(signal_strength_cfg_changed) - -#define BT_TBS_CHR_SIGNAL_INTERVAL(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_SIGNAL_INTERVAL, /* Conditional */ \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP, \ - BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT, \ +#define BT_TBS_CHR_PROVIDER_NAME(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_PROVIDER_NAME, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, read_provider_name, NULL, inst), \ + BT_AUDIO_CCC(provider_name_cfg_changed) + +#define BT_TBS_CHR_UCI(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_UCI, BT_GATT_CHRC_READ, BT_GATT_PERM_READ_ENCRYPT, read_uci, \ + NULL, inst) + +#define BT_TBS_CHR_TECHNOLOGY(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_TECHNOLOGY, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, read_technology, NULL, inst), \ + BT_AUDIO_CCC(technology_cfg_changed) + +#define BT_TBS_CHR_URI_LIST(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_URI_LIST, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, read_uri_scheme_list, NULL, inst), \ + BT_AUDIO_CCC(uri_scheme_list_cfg_changed) + +#define BT_TBS_CHR_SIGNAL_STRENGTH(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_SIGNAL_STRENGTH, /* Optional */ \ + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_ENCRYPT, \ + read_signal_strength, NULL, inst), \ + BT_AUDIO_CCC(signal_strength_cfg_changed) + +#define BT_TBS_CHR_SIGNAL_INTERVAL(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_SIGNAL_INTERVAL, /* Conditional */ \ + BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE | BT_GATT_CHRC_WRITE_WITHOUT_RESP, \ + BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT, \ read_signal_strength_interval, write_signal_strength_interval, inst) -#define BT_TBS_CHR_CURRENT_CALLS(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_LIST_CURRENT_CALLS, \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_current_calls, NULL, inst), \ - BT_AUDIO_CCC(current_calls_cfg_changed) - -#define BT_TBS_CHR_CCID(inst) \ - BT_AUDIO_CHRC(BT_UUID_CCID, \ - BT_GATT_CHRC_READ, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_ccid, NULL, inst) - -#define BT_TBS_CHR_STATUS_FLAGS(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_STATUS_FLAGS, \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_status_flags, NULL, inst), \ - BT_AUDIO_CCC(status_flags_cfg_changed) - -#define BT_TBS_CHR_INCOMING_URI(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_INCOMING_URI, /* Optional */ \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_incoming_uri, NULL, inst), \ - BT_AUDIO_CCC(incoming_uri_cfg_changed) - -#define BT_TBS_CHR_CALL_STATE(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_CALL_STATE, \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_call_state, NULL, inst), \ - BT_AUDIO_CCC(call_state_cfg_changed) - -#define BT_TBS_CHR_CONTROL_POINT(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_CALL_CONTROL_POINT, \ - BT_GATT_CHRC_WRITE | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE_WITHOUT_RESP, \ - BT_GATT_PERM_WRITE_ENCRYPT, \ - NULL, write_call_cp, inst), \ - BT_AUDIO_CCC(call_cp_cfg_changed) - -#define BT_TBS_CHR_OPTIONAL_OPCODES(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_OPTIONAL_OPCODES, \ - BT_GATT_CHRC_READ, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_optional_opcodes, NULL, inst) \ - -#define BT_TBS_CHR_TERMINATE_REASON(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_TERMINATE_REASON, \ - BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - NULL, NULL, inst), \ - BT_AUDIO_CCC(terminate_reason_cfg_changed) - -#define BT_TBS_CHR_INCOMING_CALL(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_INCOMING_CALL, \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_incoming_call, NULL, inst), \ - BT_AUDIO_CCC(in_call_cfg_changed) - -#define BT_TBS_CHR_FRIENDLY_NAME(inst) \ - BT_AUDIO_CHRC(BT_UUID_TBS_FRIENDLY_NAME, /* Optional */ \ - BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ - BT_GATT_PERM_READ_ENCRYPT, \ - read_friendly_name, NULL, inst), \ - BT_AUDIO_CCC(friendly_name_cfg_changed) +#define BT_TBS_CHR_CURRENT_CALLS(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_LIST_CURRENT_CALLS, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, read_current_calls, NULL, inst), \ + BT_AUDIO_CCC(current_calls_cfg_changed) + +#define BT_TBS_CHR_CCID(inst) \ + BT_AUDIO_CHRC(BT_UUID_CCID, BT_GATT_CHRC_READ, BT_GATT_PERM_READ_ENCRYPT, read_ccid, NULL, \ + inst) + +#define BT_TBS_CHR_STATUS_FLAGS(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_STATUS_FLAGS, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, read_status_flags, NULL, inst), \ + BT_AUDIO_CCC(status_flags_cfg_changed) + +#define BT_TBS_CHR_INCOMING_URI(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_INCOMING_URI, /* Optional */ \ + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_ENCRYPT, \ + read_incoming_uri, NULL, inst), \ + BT_AUDIO_CCC(incoming_uri_cfg_changed) + +#define BT_TBS_CHR_CALL_STATE(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_CALL_STATE, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, read_call_state, NULL, inst), \ + BT_AUDIO_CCC(call_state_cfg_changed) + +#define BT_TBS_CHR_CONTROL_POINT(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_CALL_CONTROL_POINT, \ + BT_GATT_CHRC_WRITE | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE_WITHOUT_RESP, \ + BT_GATT_PERM_WRITE_ENCRYPT, NULL, write_call_cp, inst), \ + BT_AUDIO_CCC(call_cp_cfg_changed) + +#define BT_TBS_CHR_OPTIONAL_OPCODES(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_OPTIONAL_OPCODES, BT_GATT_CHRC_READ, BT_GATT_PERM_READ_ENCRYPT, \ + read_optional_opcodes, NULL, inst) + +#define BT_TBS_CHR_TERMINATE_REASON(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_TERMINATE_REASON, BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, NULL, NULL, inst), \ + BT_AUDIO_CCC(terminate_reason_cfg_changed) + +#define BT_TBS_CHR_INCOMING_CALL(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_INCOMING_CALL, BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, \ + BT_GATT_PERM_READ_ENCRYPT, read_incoming_call, NULL, inst), \ + BT_AUDIO_CCC(in_call_cfg_changed) + +#define BT_TBS_CHR_FRIENDLY_NAME(inst) \ + BT_AUDIO_CHRC(BT_UUID_TBS_FRIENDLY_NAME, /* Optional */ \ + BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ_ENCRYPT, \ + read_friendly_name, NULL, inst), \ + BT_AUDIO_CCC(friendly_name_cfg_changed) #define BT_TBS_SERVICE_DEFINE(_uuid, _inst) \ - BT_GATT_PRIMARY_SERVICE(_uuid), \ - BT_TBS_CHR_PROVIDER_NAME(_inst), \ - BT_TBS_CHR_UCI(_inst), \ - BT_TBS_CHR_TECHNOLOGY(_inst), \ - BT_TBS_CHR_URI_LIST(_inst), \ - BT_TBS_CHR_SIGNAL_STRENGTH(_inst), \ - BT_TBS_CHR_SIGNAL_INTERVAL(_inst), \ - BT_TBS_CHR_CURRENT_CALLS(_inst), \ - BT_TBS_CHR_CCID(_inst), \ - BT_TBS_CHR_STATUS_FLAGS(_inst), \ - BT_TBS_CHR_INCOMING_URI(_inst), \ - BT_TBS_CHR_CALL_STATE(_inst), \ - BT_TBS_CHR_CONTROL_POINT(_inst), \ - BT_TBS_CHR_OPTIONAL_OPCODES(_inst), \ - BT_TBS_CHR_TERMINATE_REASON(_inst), \ - BT_TBS_CHR_INCOMING_CALL(_inst), \ - BT_TBS_CHR_FRIENDLY_NAME(_inst) - -#define BT_TBS_SERVICE_DEFINITION(_inst) { BT_TBS_SERVICE_DEFINE(BT_UUID_TBS, &(_inst).inst) } - -/* - * Defining this as extern make it possible to link code that otherwise would - * give "unknown identifier" linking errors. - */ -extern const struct bt_gatt_service_static gtbs_svc; + BT_GATT_PRIMARY_SERVICE(_uuid), BT_TBS_CHR_PROVIDER_NAME(_inst), BT_TBS_CHR_UCI(_inst), \ + BT_TBS_CHR_TECHNOLOGY(_inst), BT_TBS_CHR_URI_LIST(_inst), \ + BT_TBS_CHR_SIGNAL_STRENGTH(_inst), BT_TBS_CHR_SIGNAL_INTERVAL(_inst), \ + BT_TBS_CHR_CURRENT_CALLS(_inst), BT_TBS_CHR_CCID(_inst), \ + BT_TBS_CHR_STATUS_FLAGS(_inst), BT_TBS_CHR_INCOMING_URI(_inst), \ + BT_TBS_CHR_CALL_STATE(_inst), BT_TBS_CHR_CONTROL_POINT(_inst), \ + BT_TBS_CHR_OPTIONAL_OPCODES(_inst), BT_TBS_CHR_TERMINATE_REASON(_inst), \ + BT_TBS_CHR_INCOMING_CALL(_inst), BT_TBS_CHR_FRIENDLY_NAME(_inst) + +#define BT_TBS_SERVICE_DEFINITION(_inst) \ + { \ + BT_TBS_SERVICE_DEFINE(BT_UUID_TBS, &(_inst)) \ + } -/* TODO: Can we make the multiple service instance more generic? */ -#if CONFIG_BT_GTBS -BT_GATT_SERVICE_DEFINE(gtbs_svc, BT_TBS_SERVICE_DEFINE(BT_UUID_GTBS, >bs_inst.inst)); -#endif /* CONFIG_BT_GTBS */ +BT_GATT_SERVICE_DEFINE(gtbs_svc, BT_TBS_SERVICE_DEFINE(BT_UUID_GTBS, >bs_inst)); BT_GATT_SERVICE_INSTANCE_DEFINE(tbs_service_list, svc_insts, CONFIG_BT_TBS_BEARER_COUNT, BT_TBS_SERVICE_DEFINITION); @@ -1584,8 +1482,7 @@ BT_GATT_SERVICE_INSTANCE_DEFINE(tbs_service_list, svc_insts, CONFIG_BT_TBS_BEARE static void signal_interval_timeout(struct k_work *work) { struct k_work_delayable *dwork = k_work_delayable_from_work(work); - struct service_inst *inst = CONTAINER_OF(dwork, struct service_inst, - reporting_interval_work); + struct tbs_inst *inst = CONTAINER_OF(dwork, struct tbs_inst, reporting_interval_work); if (!inst->pending_signal_strength_notification) { return; @@ -1602,7 +1499,7 @@ static void signal_interval_timeout(struct k_work *work) inst->pending_signal_strength_notification = false; } -static void tbs_inst_init(struct service_inst *inst, const struct bt_gatt_attr *attrs, +static void tbs_inst_init(struct tbs_inst *inst, const struct bt_gatt_attr *attrs, size_t attr_count, const char *provider_name) { LOG_DBG("inst %p index 0x%02x provider_name %s", inst, inst_index(inst), provider_name); @@ -1620,22 +1517,23 @@ static void tbs_inst_init(struct service_inst *inst, const struct bt_gatt_attr * k_work_init_delayable(&inst->reporting_interval_work, signal_interval_timeout); } -static void gtbs_service_inst_init(struct gtbs_service_inst *inst, +static void gtbs_service_inst_init(struct tbs_inst *inst, const struct bt_gatt_service_static *service) { - tbs_inst_init(&inst->inst, service->attrs, service->attr_count, "Generic TBS"); + tbs_inst_init(inst, service->attrs, service->attr_count, "Generic TBS"); } -static void tbs_service_inst_init(struct tbs_service_inst *inst, struct bt_gatt_service *service) +static void tbs_service_inst_init(struct tbs_inst *inst, struct bt_gatt_service *service) { - tbs_inst_init(&inst->inst, service->attrs, service->attr_count, - CONFIG_BT_TBS_PROVIDER_NAME); + tbs_inst_init(inst, service->attrs, service->attr_count, CONFIG_BT_TBS_PROVIDER_NAME); (void)utf8_lcpy(inst->uri_scheme_list, CONFIG_BT_TBS_URI_SCHEMES_LIST, sizeof(inst->uri_scheme_list)); } static int bt_tbs_init(void) { + gtbs_service_inst_init(>bs_inst, >bs_svc); + for (size_t i = 0; i < ARRAY_SIZE(svc_insts); i++) { int err; @@ -1647,10 +1545,6 @@ static int bt_tbs_init(void) tbs_service_inst_init(&svc_insts[i], &tbs_service_list[i]); } - if (IS_ENABLED(CONFIG_BT_GTBS)) { - gtbs_service_inst_init(>bs_inst, >bs_svc); - } - return 0; } @@ -1659,12 +1553,10 @@ SYS_INIT(bt_tbs_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); /***************************** Profile API *****************************/ int bt_tbs_accept(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); int status = -EINVAL; - const struct bt_tbs_call_cp_acc ccp = { - .call_index = call_index, - .opcode = BT_TBS_CALL_OPCODE_ACCEPT - }; + const struct bt_tbs_call_cp_acc ccp = {.call_index = call_index, + .opcode = BT_TBS_CALL_OPCODE_ACCEPT}; if (inst != NULL) { status = accept_call(inst, &ccp); @@ -1679,12 +1571,10 @@ int bt_tbs_accept(uint8_t call_index) int bt_tbs_hold(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); int status = -EINVAL; - const struct bt_tbs_call_cp_hold ccp = { - .call_index = call_index, - .opcode = BT_TBS_CALL_OPCODE_HOLD - }; + const struct bt_tbs_call_cp_hold ccp = {.call_index = call_index, + .opcode = BT_TBS_CALL_OPCODE_HOLD}; if (inst != NULL) { status = tbs_hold_call(inst, &ccp); @@ -1697,12 +1587,10 @@ int bt_tbs_hold(uint8_t call_index) int bt_tbs_retrieve(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); int status = -EINVAL; - const struct bt_tbs_call_cp_retrieve ccp = { - .call_index = call_index, - .opcode = BT_TBS_CALL_OPCODE_RETRIEVE - }; + const struct bt_tbs_call_cp_retrieve ccp = {.call_index = call_index, + .opcode = BT_TBS_CALL_OPCODE_RETRIEVE}; if (inst != NULL) { status = retrieve_call(inst, &ccp); @@ -1715,16 +1603,13 @@ int bt_tbs_retrieve(uint8_t call_index) int bt_tbs_terminate(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); int status = -EINVAL; - const struct bt_tbs_call_cp_term ccp = { - .call_index = call_index, - .opcode = BT_TBS_CALL_OPCODE_TERMINATE - }; + const struct bt_tbs_call_cp_term ccp = {.call_index = call_index, + .opcode = BT_TBS_CALL_OPCODE_TERMINATE}; if (inst != NULL) { - status = terminate_call(inst, &ccp, - BT_TBS_REASON_SERVER_ENDED_CALL); + status = terminate_call(inst, &ccp, BT_TBS_REASON_SERVER_ENDED_CALL); } notify_calls(inst); @@ -1732,18 +1617,15 @@ int bt_tbs_terminate(uint8_t call_index) return status; } -int bt_tbs_originate(uint8_t bearer_index, char *remote_uri, - uint8_t *call_index) +int bt_tbs_originate(uint8_t bearer_index, char *remote_uri, uint8_t *call_index) { - struct service_inst *tbs = inst_lookup_index(bearer_index); - struct tbs_service_inst *inst; - uint8_t buf[CONFIG_BT_TBS_MAX_URI_LENGTH + - sizeof(struct bt_tbs_call_cp_originate)]; - struct bt_tbs_call_cp_originate *ccp = - (struct bt_tbs_call_cp_originate *)buf; + struct tbs_inst *tbs = inst_lookup_index(bearer_index); + uint8_t buf[CONFIG_BT_TBS_MAX_URI_LENGTH + sizeof(struct bt_tbs_call_cp_originate)]; + struct bt_tbs_call_cp_originate *ccp = (struct bt_tbs_call_cp_originate *)buf; size_t uri_len; - if (tbs == NULL || inst_is_gtbs(tbs)) { + if (tbs == NULL) { + LOG_DBG("Could not find TBS instance from index %u", bearer_index); return -EINVAL; } else if (!bt_tbs_valid_uri((uint8_t *)remote_uri, strlen(remote_uri))) { LOG_DBG("Invalid URI %s", remote_uri); @@ -1752,19 +1634,16 @@ int bt_tbs_originate(uint8_t bearer_index, char *remote_uri, uri_len = strlen(remote_uri); - inst = CONTAINER_OF(tbs, struct tbs_service_inst, inst); - ccp->opcode = BT_TBS_CALL_OPCODE_ORIGINATE; (void)memcpy(ccp->uri, remote_uri, uri_len); - return originate_call(inst, ccp, uri_len, call_index); + return originate_call(tbs, ccp, uri_len, call_index); } int bt_tbs_join(uint8_t call_index_cnt, uint8_t *call_indexes) { - struct tbs_service_inst *inst; - uint8_t buf[CONFIG_BT_TBS_MAX_CALLS + - sizeof(struct bt_tbs_call_cp_join)]; + struct tbs_inst *inst; + uint8_t buf[CONFIG_BT_TBS_MAX_CALLS + sizeof(struct bt_tbs_call_cp_join)]; struct bt_tbs_call_cp_join *ccp = (struct bt_tbs_call_cp_join *)buf; int status = -EINVAL; @@ -1777,7 +1656,7 @@ int bt_tbs_join(uint8_t call_index_cnt, uint8_t *call_indexes) if (inst != NULL) { ccp->opcode = BT_TBS_CALL_OPCODE_JOIN; (void)memcpy(ccp->call_indexes, call_indexes, - MIN(call_index_cnt, CONFIG_BT_TBS_MAX_CALLS)); + MIN(call_index_cnt, CONFIG_BT_TBS_MAX_CALLS)); status = join_calls(inst, ccp, call_index_cnt); } @@ -1787,7 +1666,7 @@ int bt_tbs_join(uint8_t call_index_cnt, uint8_t *call_indexes) int bt_tbs_remote_answer(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); struct bt_tbs_call *call; if (inst == NULL) { @@ -1811,7 +1690,7 @@ int bt_tbs_remote_answer(uint8_t call_index) int bt_tbs_remote_hold(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); struct bt_tbs_call *call; uint8_t status; @@ -1844,7 +1723,7 @@ int bt_tbs_remote_hold(uint8_t call_index) int bt_tbs_remote_retrieve(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); struct bt_tbs_call *call; int status; @@ -1877,16 +1756,13 @@ int bt_tbs_remote_retrieve(uint8_t call_index) int bt_tbs_remote_terminate(uint8_t call_index) { - struct tbs_service_inst *inst = lookup_inst_by_call_index(call_index); + struct tbs_inst *inst = lookup_inst_by_call_index(call_index); int status = -EINVAL; - const struct bt_tbs_call_cp_term ccp = { - .call_index = call_index, - .opcode = BT_TBS_CALL_OPCODE_TERMINATE - }; + const struct bt_tbs_call_cp_term ccp = {.call_index = call_index, + .opcode = BT_TBS_CALL_OPCODE_TERMINATE}; if (inst != NULL) { - status = terminate_call(inst, &ccp, - BT_TBS_REASON_REMOTE_ENDED_CALL); + status = terminate_call(inst, &ccp, BT_TBS_REASON_REMOTE_ENDED_CALL); } notify_calls(inst); @@ -1894,7 +1770,7 @@ int bt_tbs_remote_terminate(uint8_t call_index) return status; } -static void tbs_inst_remote_incoming(struct service_inst *inst, const char *to, const char *from, +static void tbs_inst_remote_incoming(struct tbs_inst *inst, const char *to, const char *from, const char *friendly_name, const struct bt_tbs_call *call) { size_t local_uri_ind_len; @@ -1932,14 +1808,14 @@ static void tbs_inst_remote_incoming(struct service_inst *inst, const char *to, } } -int bt_tbs_remote_incoming(uint8_t bearer_index, const char *to, - const char *from, const char *friendly_name) +int bt_tbs_remote_incoming(uint8_t bearer_index, const char *to, const char *from, + const char *friendly_name) { - struct service_inst *inst = inst_lookup_index(bearer_index); - struct tbs_service_inst *service_inst; + struct tbs_inst *inst = inst_lookup_index(bearer_index); struct bt_tbs_call *call = NULL; - if (inst == NULL || inst_is_gtbs(inst)) { + if (inst == NULL) { + LOG_DBG("Could not find TBS instance from index %u", bearer_index); return -EINVAL; } else if (!bt_tbs_valid_uri((uint8_t *)to, strlen(to))) { LOG_DBG("Invalid \"to\" URI: %s", to); @@ -1949,22 +1825,24 @@ int bt_tbs_remote_incoming(uint8_t bearer_index, const char *to, return -EINVAL; } - service_inst = CONTAINER_OF(inst, struct tbs_service_inst, inst); - - call = call_alloc(service_inst, BT_TBS_CALL_STATE_INCOMING, (uint8_t *)from, strlen(from)); + call = call_alloc(inst, BT_TBS_CALL_STATE_INCOMING, (uint8_t *)from, strlen(from)); if (call == NULL) { return -ENOMEM; } BT_TBS_CALL_FLAG_SET_INCOMING(call->flags); + /* Notify TBS*/ tbs_inst_remote_incoming(inst, to, from, friendly_name, call); - if (IS_ENABLED(CONFIG_BT_GTBS)) { - tbs_inst_remote_incoming(>bs_inst.inst, to, from, friendly_name, call); + if (!inst_is_gtbs(inst)) { + /* If the instance is different than the GTBS we set the remote incoming and + * notify on the GTBS instance as well + */ + tbs_inst_remote_incoming(>bs_inst, to, from, friendly_name, call); } - notify_calls(service_inst); + notify_calls(inst); LOG_DBG("New call with call index %u", call->index); @@ -1973,7 +1851,7 @@ int bt_tbs_remote_incoming(uint8_t bearer_index, const char *to, int bt_tbs_set_bearer_provider_name(uint8_t bearer_index, const char *name) { - struct service_inst *inst = inst_lookup_index(bearer_index); + struct tbs_inst *inst = inst_lookup_index(bearer_index); const size_t len = strlen(name); if (len >= CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH || len == 0) { @@ -1995,7 +1873,7 @@ int bt_tbs_set_bearer_provider_name(uint8_t bearer_index, const char *name) int bt_tbs_set_bearer_technology(uint8_t bearer_index, uint8_t new_technology) { - struct service_inst *inst = inst_lookup_index(bearer_index); + struct tbs_inst *inst = inst_lookup_index(bearer_index); if (new_technology < BT_TBS_TECHNOLOGY_3G || new_technology > BT_TBS_TECHNOLOGY_WCDMA) { return -EINVAL; @@ -2015,10 +1893,9 @@ int bt_tbs_set_bearer_technology(uint8_t bearer_index, uint8_t new_technology) return 0; } -int bt_tbs_set_signal_strength(uint8_t bearer_index, - uint8_t new_signal_strength) +int bt_tbs_set_signal_strength(uint8_t bearer_index, uint8_t new_signal_strength) { - struct service_inst *inst = inst_lookup_index(bearer_index); + struct tbs_inst *inst = inst_lookup_index(bearer_index); uint32_t timer_status; if (new_signal_strength > BT_TBS_SIGNAL_STRENGTH_MAX && @@ -2047,7 +1924,7 @@ int bt_tbs_set_signal_strength(uint8_t bearer_index, int bt_tbs_set_status_flags(uint8_t bearer_index, uint16_t status_flags) { - struct service_inst *inst = inst_lookup_index(bearer_index); + struct tbs_inst *inst = inst_lookup_index(bearer_index); if (!BT_TBS_VALID_STATUS_FLAGS(status_flags)) { return -EINVAL; @@ -2061,19 +1938,20 @@ int bt_tbs_set_status_flags(uint8_t bearer_index, uint16_t status_flags) inst->status_flags = status_flags; - bt_gatt_notify_uuid(NULL, BT_UUID_TBS_STATUS_FLAGS, - inst->attrs, &status_flags, sizeof(status_flags)); + bt_gatt_notify_uuid(NULL, BT_UUID_TBS_STATUS_FLAGS, inst->attrs, &status_flags, + sizeof(status_flags)); return 0; } -int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list, - uint8_t uri_count) +int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list, uint8_t uri_count) { char uri_scheme_list[CONFIG_BT_TBS_MAX_SCHEME_LIST_LENGTH]; size_t len = 0; - struct tbs_service_inst *inst; + struct tbs_inst *inst; - if (bearer_index >= CONFIG_BT_TBS_BEARER_COUNT) { + NET_BUF_SIMPLE_DEFINE(uri_scheme_buf, READ_BUF_SIZE); + + if (bearer_index >= ARRAY_SIZE(svc_insts)) { return -EINVAL; } @@ -2083,7 +1961,7 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list, for (int i = 0; i < uri_count; i++) { if (len) { len++; - if (len > sizeof(uri_scheme_list) - 1) { + if (len > sizeof(uri_scheme_list) - 1) { return -ENOMEM; } @@ -2091,7 +1969,7 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list, } len += strlen(uri_list[i]); - if (len > sizeof(uri_scheme_list) - 1) { + if (len > sizeof(uri_scheme_list) - 1) { return -ENOMEM; } @@ -2109,15 +1987,16 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list, LOG_DBG("TBS instance %u uri prefix list is now %s", bearer_index, inst->uri_scheme_list); - bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST, - inst->inst.attrs, &inst->uri_scheme_list, + bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST, inst->attrs, &inst->uri_scheme_list, strlen(inst->uri_scheme_list)); - if (IS_ENABLED(CONFIG_BT_GTBS)) { - NET_BUF_SIMPLE_DEFINE(uri_scheme_buf, READ_BUF_SIZE); + if (!inst_is_gtbs(inst)) { + /* If the instance is different than the GTBS notify on the GTBS instance as well */ + net_buf_simple_add_mem(&uri_scheme_buf, gtbs_inst.uri_scheme_list, + strlen(gtbs_inst.uri_scheme_list)); /* TODO: Make uri schemes unique */ - for (int i = 0; i < ARRAY_SIZE(svc_insts); i++) { + for (size_t i = 0U; i < ARRAY_SIZE(svc_insts); i++) { const size_t uri_len = strlen(svc_insts[i].uri_scheme_list); if (uri_scheme_buf.len + uri_len >= uri_scheme_buf.size) { @@ -2126,18 +2005,15 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list, break; } - net_buf_simple_add_mem(&uri_scheme_buf, - svc_insts[i].uri_scheme_list, + net_buf_simple_add_mem(&uri_scheme_buf, svc_insts[i].uri_scheme_list, uri_len); } LOG_DBG("GTBS: URI scheme %.*s", uri_scheme_buf.len, uri_scheme_buf.data); - bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST, - inst->inst.attrs, + bt_gatt_notify_uuid(NULL, BT_UUID_TBS_URI_LIST, gtbs_inst.attrs, uri_scheme_buf.data, uri_scheme_buf.len); } - return 0; } @@ -2149,7 +2025,7 @@ void bt_tbs_register_cb(struct bt_tbs_cb *cbs) #if defined(CONFIG_BT_TBS_LOG_LEVEL_DBG) void bt_tbs_dbg_print_calls(void) { - for (int i = 0; i < CONFIG_BT_TBS_BEARER_COUNT; i++) { + for (size_t i = 0U; i < ARRAY_SIZE(svc_insts); i++) { LOG_DBG("Bearer #%u", i); for (int j = 0; j < ARRAY_SIZE(svc_insts[i].calls); j++) { struct bt_tbs_call *call = &svc_insts[i].calls[j]; diff --git a/tests/bluetooth/shell/audio.conf b/tests/bluetooth/shell/audio.conf index 404a04c885279b..6998b335ea10d2 100644 --- a/tests/bluetooth/shell/audio.conf +++ b/tests/bluetooth/shell/audio.conf @@ -122,6 +122,7 @@ CONFIG_BT_MPL_TRACK_MAX_SIZE=50 # Telephone bearer service CONFIG_BT_TBS=y +CONFIG_BT_TBS_BEARER_COUNT=1 CONFIG_BT_TBS_SUPPORTED_FEATURES=3 CONFIG_BT_TBS_CLIENT_TBS=y CONFIG_BT_TBS_CLIENT_GTBS=y diff --git a/tests/bluetooth/shell/testcase.yaml b/tests/bluetooth/shell/testcase.yaml index 129792ee63f047..a19dfa3f4560e3 100644 --- a/tests/bluetooth/shell/testcase.yaml +++ b/tests/bluetooth/shell/testcase.yaml @@ -325,6 +325,12 @@ tests: extra_configs: - CONFIG_BT_TBS=n tags: bluetooth + bluetooth.shell.audio.only_gtbs: + extra_args: CONF_FILE="audio.conf" + build_only: true + extra_configs: + - CONFIG_BT_TBS_BEARER_COUNT=0 + tags: bluetooth bluetooth.shell.audio.no_tbs_client: extra_args: CONF_FILE="audio.conf" build_only: true diff --git a/tests/bluetooth/tester/overlay-le-audio.conf b/tests/bluetooth/tester/overlay-le-audio.conf index d0c40206f0a8c0..a4a88dd941ab69 100644 --- a/tests/bluetooth/tester/overlay-le-audio.conf +++ b/tests/bluetooth/tester/overlay-le-audio.conf @@ -25,8 +25,6 @@ CONFIG_BT_L2CAP_TX_BUF_COUNT=10 # CAP CONFIG_BT_CAP_INITIATOR=y -# To have multiple CCIDs -CONFIG_BT_TBS=y # MICP CONFIG_BT_MICP_MIC_DEV=y @@ -142,8 +140,8 @@ CONFIG_BT_MPL=y CONFIG_UTF8=y #TBS -CONFIG_BT_GTBS=y CONFIG_BT_TBS=y +CONFIG_BT_TBS_BEARER_COUNT=1 CONFIG_BT_TBS_MAX_CALLS=10 CONFIG_BT_TBS_SUPPORTED_FEATURES=3 diff --git a/tests/bluetooth/tester/src/audio/CMakeLists.txt b/tests/bluetooth/tester/src/audio/CMakeLists.txt index 38b4cac11cbe4d..072819eeca4fe0 100644 --- a/tests/bluetooth/tester/src/audio/CMakeLists.txt +++ b/tests/bluetooth/tester/src/audio/CMakeLists.txt @@ -60,7 +60,7 @@ if(CONFIG_BT_CAP_INITIATOR) target_sources(app PRIVATE btp_cap.c) endif() -if(CONFIG_BT_TBS OR CONFIG_BT_GTBS) +if(CONFIG_BT_TBS) target_sources(app PRIVATE btp_ccp.c) endif() diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index f89f08c782096d..8b1b571792d6d6 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -101,7 +101,7 @@ static uint8_t supported_services(const void *cmd, uint16_t cmd_len, #if defined(CONFIG_BT_HAS) tester_set_bit(rp->data, BTP_SERVICE_ID_HAP); #endif /* CONFIG_BT_HAS */ -#if defined(CONFIG_BT_TBS) || defined(CONFIG_BT_GTBS) +#if defined(CONFIG_BT_TBS) tester_set_bit(rp->data, BTP_SERVICE_ID_TBS); #endif /*CONFIG_BT_TBS */ #if defined(CONFIG_BT_TMAP) @@ -235,7 +235,7 @@ static uint8_t register_service(const void *cmd, uint16_t cmd_len, status = tester_init_hap(); break; #endif /* CONFIG_BT_HAS */ -#if defined(CONFIG_BT_TBS) || defined(CONFIG_BT_GTBS) +#if defined(CONFIG_BT_TBS) case BTP_SERVICE_ID_TBS: status = tester_init_tbs(); break; diff --git a/tests/bsim/bluetooth/audio/prj.conf b/tests/bsim/bluetooth/audio/prj.conf index f10854441e2332..27749c09a95232 100644 --- a/tests/bsim/bluetooth/audio/prj.conf +++ b/tests/bsim/bluetooth/audio/prj.conf @@ -80,6 +80,7 @@ CONFIG_BT_CSIP_SET_COORDINATOR_TEST_SAMPLE_DATA=y # Telephone bearer service CONFIG_BT_TBS=y +CONFIG_BT_TBS_BEARER_COUNT=1 CONFIG_BT_TBS_CLIENT_TBS=y CONFIG_BT_TBS_CLIENT_GTBS=y CONFIG_BT_TBS_CLIENT_MAX_CALLS=4