Skip to content

Commit 1406c54

Browse files
Thalleynashif
authored andcommitted
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 <[email protected]>
1 parent c0f71e9 commit 1406c54

File tree

6 files changed

+464
-131
lines changed

6 files changed

+464
-131
lines changed

include/zephyr/bluetooth/audio/tbs.h

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ extern "C" {
126126
#define BT_TBS_FEATURE_HOLD BIT(0)
127127
/** Join Call Control Point Opcode supported */
128128
#define BT_TBS_FEATURE_JOIN BIT(1)
129+
/** All Control Point Opcodes supported */
130+
#define BT_TBS_FEATURE_ALL (BT_TBS_FEATURE_HOLD | BT_TBS_FEATURE_JOIN)
129131
/** @} */
130132

131133
/**
@@ -247,8 +249,6 @@ typedef void (*bt_tbs_call_change_cb)(struct bt_conn *conn,
247249
/**
248250
* @brief Callback function for authorizing a client.
249251
*
250-
* Only used if BT_TBS_AUTHORIZATION is enabled.
251-
*
252252
* @param conn The connection used.
253253
*
254254
* @return true if authorized, false otherwise
@@ -462,6 +462,98 @@ int bt_tbs_set_uri_scheme_list(uint8_t bearer_index, const char **uri_list,
462462
*/
463463
void bt_tbs_register_cb(struct bt_tbs_cb *cbs);
464464

465+
struct bt_tbs_register_param {
466+
/** The name of the provider, for example a cellular service provider */
467+
char *provider_name;
468+
469+
/**
470+
* @brief The Uniform Caller Identifier of the bearer
471+
*
472+
* See the Uniform Caller Identifiers table in Bluetooth Assigned Numbers
473+
*/
474+
char *uci;
475+
476+
/**
477+
* The Uniform Resource Identifiers schemes supported by this bearer as an UTF-8 string
478+
*
479+
* See https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml for possible values.
480+
* If multiple values are used, these shall be comma separated, e.g. "tel,skype".
481+
*/
482+
char *uri_schemes_supported;
483+
484+
/**
485+
* @brief Whether this bearer shall be registered as a Generic Telephone Bearer server
486+
*
487+
* A GTBS shall be registered before any non-GTBS services. There can only be a single GTBS
488+
* registered.
489+
*/
490+
bool gtbs;
491+
492+
/**
493+
* @brief Whether the application will need to authorize changes to calls
494+
*
495+
* If set to false then the service will automatically accept write requests from clients.
496+
*/
497+
bool authorization_required;
498+
499+
/**
500+
* @brief The technology of the bearer
501+
*
502+
* See the BT_TBS_TECHNOLOGY_* values.
503+
*/
504+
uint8_t technology;
505+
506+
/**
507+
* @brief The optional supported features of the bearer
508+
*
509+
* See the BT_TBS_FEATURE_* values.
510+
*/
511+
uint8_t supported_features;
512+
};
513+
514+
/**
515+
* @brief Register a Telephone Bearer
516+
*
517+
* This will register a Telephone Bearer Service (TBS) (or a Generic Telephone Bearer service
518+
* (GTBS)) with the provided parameters.
519+
*
520+
* As per the TBS specification, the GTBS shall be instantiated for the feature, and as such a GTBS
521+
* shall always be registered before any TBS can be registered.
522+
* Similarly, all TBS shall be unregistered before the GTBS can be unregistered with
523+
* bt_tbs_unregister_bearer().
524+
*
525+
* @param param The parameters to initialize the bearer.
526+
527+
* @retval index The bearer index if return value is >= 0
528+
* @retval -EINVAL @p param contains invalid data
529+
* @retval -EALREADY @p param.gtbs is true and GTBS has already been registered
530+
* @retval -EAGAIN @p param.gtbs is false and GTBS has not been registered
531+
* @retval -ENOMEM @p param.gtbs is false and no more TBS can be registered (see
532+
* @kconfig{CONFIG_BT_TBS_BEARER_COUNT})
533+
* @retval -ENOEXEC The service failed to be registered
534+
*/
535+
int bt_tbs_register_bearer(const struct bt_tbs_register_param *param);
536+
537+
/**
538+
* @brief Unregister a Telephone Bearer
539+
*
540+
* This will unregister a Telephone Bearer Service (TBS) (or a Generic Telephone Bearer service
541+
* (GTBS)) with the provided parameters. The bearer shall be registered first by
542+
* bt_tbs_register_bearer() before it can be unregistered.
543+
*
544+
* Similarly, all TBS shall be unregistered before the GTBS can be unregistered with.
545+
*
546+
* @param bearer_index The index of the bearer to unregister.
547+
*
548+
* @retval 0 Success
549+
* @retval -EINVAL @p bearer_index is invalid
550+
* @retval -EALREADY The bearer identified by @p bearer_index is not registered
551+
* @retval -EAGAIN The bearer identified by @p bearer_index is GTBS and there are TBS instances
552+
* registered.
553+
* @retval -ENOEXEC The service failed to be unregistered
554+
*/
555+
int bt_tbs_unregister_bearer(uint8_t bearer_index);
556+
465557
/** @brief Prints all calls of all services to the debug log */
466558
void bt_tbs_dbg_print_calls(void);
467559

subsys/bluetooth/audio/Kconfig.tbs

Lines changed: 2 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,70 +22,14 @@ config BT_TBS
2222

2323
if BT_TBS
2424

25-
config BT_TBS_PROVIDER_NAME
26-
string "Telephone Bearer Service Provider Name"
27-
default "Unknown"
28-
help
29-
Sets the name of the service provider for the bearer.
30-
31-
config BT_TBS_UCI
32-
string "Telephone Bearer Service Uniform Caller Identifier (UCI)"
33-
default "un000"
34-
help
35-
Sets the UCI of the bearer. See
36-
https://www.bluetooth.com/specifications/assigned-numbers/uniform-caller-identifiers/
37-
for a table of valid UCIs.
38-
39-
config BT_TBS_TECHNOLOGY
40-
int "Telephone Bearer Service Technology"
41-
range 1 10
42-
help
43-
Sets the technology used for the bearer, e.g. GSM, LTE and 5G.
44-
1 : 3G
45-
2 : 4G
46-
3 : LTE
47-
4 : Wi-Fi
48-
5 : 5G
49-
6 : GSM
50-
7 : CDMA
51-
8 : 2G
52-
9 : WCDMA
53-
10: IP
54-
55-
config BT_TBS_URI_SCHEMES_LIST
56-
string "Telephone Bearer Service URI schemes Supported List"
57-
default "tel,skype"
58-
help
59-
Sets a list of URI schemes that are supported by the bearer,
60-
e.g. "tel" or "skype".
61-
Multiple values shall be comma (,) separated, e.g. "tel,skype".
62-
63-
config BT_TBS_SIGNAL_STRENGTH_INTERVAL
64-
int "Telephone Bearer Service Signal Strength Reporting Interval"
65-
default 0
66-
range 0 $(UINT8_MAX)
67-
help
68-
Sets the interval of reporting the signal strength in seconds.
69-
If the value is 0, the signal will not be reported.
70-
71-
config BT_TBS_STATUS_FLAGS
72-
int "Telephone Bearer Service Features and Status value"
73-
default 0
74-
range 0 3
75-
help
76-
Bitfield to set feature and status flags.
77-
Bit 0: In-band ringtone
78-
Bit 1: Silent mode
79-
Bits 2-15: Reserved for future use
80-
8125
config BT_TBS_SUPPORTED_FEATURES
8226
int "Telephone Bearer Service Supported Features"
8327
default 1
8428
range 0 3
8529
help
8630
Bitfield to set supported features of the bearer.
87-
Bit 0: Local Hold and Retrieve
88-
Bit 1: Join calls within Telephone Bearer Service
31+
Bit 0: Local Hold and Retrieve
32+
Bit 1: Join calls within Telephone Bearer Service
8933

9034
config BT_TBS_MAX_CALLS
9135
int "Telephone Bearer Service Maximum Number Of Calls Supported"
@@ -108,12 +52,6 @@ config BT_TBS_MAX_SCHEME_LIST_LENGTH
10852
help
10953
Sets the maximum length of the URI scheme list.
11054

111-
config BT_TBS_AUTHORIZATION
112-
bool "TBS authorization requirement"
113-
help
114-
If set to true, then any writable characteristics will require
115-
authorization per connection.
116-
11755
endif # BT_TBS
11856

11957

subsys/bluetooth/audio/shell/tbs.c

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdbool.h>
1313
#include <stddef.h>
1414
#include <stdint.h>
15+
#include <stdio.h>
1516
#include <string.h>
1617

1718
#include <zephyr/autoconf.h>
@@ -26,7 +27,6 @@
2627
#include "host/shell/bt.h"
2728

2829
static struct bt_conn *tbs_authorized_conn;
29-
static bool cbs_registered;
3030

3131
static bool tbs_authorize_cb(struct bt_conn *conn)
3232
{
@@ -59,13 +59,64 @@ static int cmd_tbs_authorize(const struct shell *sh, size_t argc, char *argv[])
5959
return 0;
6060
}
6161

62-
static int cmd_tbs_init(void)
62+
static int cmd_tbs_init(const struct shell *sh, size_t argc, char *argv[])
6363
{
64-
if (!cbs_registered) {
65-
bt_tbs_register_cb(&tbs_cbs);
66-
cbs_registered = true;
64+
static bool registered;
65+
66+
if (registered) {
67+
shell_info(sh, "Already initialized");
68+
69+
return -ENOEXEC;
70+
}
71+
72+
const struct bt_tbs_register_param gtbs_param = {
73+
.provider_name = "Generic TBS",
74+
.uci = "un000",
75+
.uri_schemes_supported = "tel,skype",
76+
.gtbs = true,
77+
.authorization_required = false,
78+
.technology = BT_TBS_TECHNOLOGY_3G,
79+
.supported_features = CONFIG_BT_TBS_SUPPORTED_FEATURES,
80+
};
81+
int err;
82+
83+
err = bt_tbs_register_bearer(&gtbs_param);
84+
if (err < 0) {
85+
shell_error(sh, "Failed to register GTBS: %d", err);
86+
87+
return -ENOEXEC;
88+
}
89+
90+
shell_info(sh, "Registered GTBS");
91+
92+
for (int i = 0; i < CONFIG_BT_TBS_BEARER_COUNT; i++) {
93+
char prov_name[22]; /* Enough to store "Telephone Bearer #255" */
94+
const struct bt_tbs_register_param tbs_param = {
95+
.provider_name = prov_name,
96+
.uci = "un000",
97+
.uri_schemes_supported = "tel,skype",
98+
.gtbs = false,
99+
.authorization_required = false,
100+
/* Set different technologies per bearer */
101+
.technology = (i % BT_TBS_TECHNOLOGY_WCDMA) + 1,
102+
.supported_features = CONFIG_BT_TBS_SUPPORTED_FEATURES,
103+
};
104+
105+
snprintf(prov_name, sizeof(prov_name), "Telephone Bearer #%d", i);
106+
107+
err = bt_tbs_register_bearer(&tbs_param);
108+
if (err < 0) {
109+
shell_error(sh, "Failed to register TBS[%d]: %d", i, err);
110+
111+
return -ENOEXEC;
112+
}
113+
114+
shell_info(sh, "Registered TBS[%d] with index %u", i, (uint8_t)err);
67115
}
68116

117+
bt_tbs_register_cb(&tbs_cbs);
118+
registered = true;
119+
69120
return 0;
70121
}
71122

0 commit comments

Comments
 (0)