Bluetooth: Audio: Add get_by_ccid for TBS
This is needed for the CAP acceptor to properly verify the CCID_List in the metadata. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
539ffe296e
commit
e712a2462b
4 changed files with 245 additions and 83 deletions
|
@ -71,6 +71,9 @@
|
|||
*/
|
||||
#define BT_TBS_GTBS_INDEX 0xFF
|
||||
|
||||
/** @brief Opaque Telephone Bearer Service instance. */
|
||||
struct bt_tbs_instance;
|
||||
|
||||
/**
|
||||
* @brief Callback function for client originating a call.
|
||||
*
|
||||
|
@ -735,4 +738,15 @@ int bt_tbs_client_read_optional_opcodes(struct bt_conn *conn,
|
|||
*/
|
||||
void bt_tbs_client_register_cb(const struct bt_tbs_client_cb *cbs);
|
||||
|
||||
/**
|
||||
* @brief Look up Telephone Bearer Service instance by CCID
|
||||
*
|
||||
* @param conn The connection to the TBS server.
|
||||
* @param ccid The CCID to lookup a service instance for.
|
||||
*
|
||||
* @return Pointer to a Telephone Bearer Service instance if found else NULL.
|
||||
*/
|
||||
struct bt_tbs_instance *bt_tbs_client_get_by_ccid(const struct bt_conn *conn,
|
||||
uint8_t ccid);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_AUDIO_TBS_H_ */
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include <zephyr/zephyr.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <sys/check.h>
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/init.h>
|
||||
|
@ -32,61 +33,6 @@
|
|||
#endif /* IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) */
|
||||
#define GTBS_INDEX CONFIG_BT_TBS_CLIENT_MAX_TBS_INSTANCES
|
||||
|
||||
struct bt_tbs_instance {
|
||||
struct bt_tbs_client_call_state calls[CONFIG_BT_TBS_CLIENT_MAX_CALLS];
|
||||
|
||||
uint16_t start_handle;
|
||||
uint16_t end_handle;
|
||||
uint16_t provider_name_handle;
|
||||
uint16_t bearer_uci_handle;
|
||||
uint16_t technology_handle;
|
||||
uint16_t uri_list_handle;
|
||||
uint16_t signal_strength_handle;
|
||||
uint16_t signal_interval_handle;
|
||||
uint16_t current_calls_handle;
|
||||
uint16_t ccid_handle;
|
||||
uint16_t status_flags_handle;
|
||||
uint16_t in_uri_handle;
|
||||
uint16_t call_state_handle;
|
||||
uint16_t call_cp_handle;
|
||||
uint16_t optional_opcodes_handle;
|
||||
uint16_t termination_reason_handle;
|
||||
uint16_t friendly_name_handle;
|
||||
uint16_t in_call_handle;
|
||||
|
||||
bool busy;
|
||||
uint8_t subscribe_cnt;
|
||||
uint8_t index;
|
||||
bool gtbs;
|
||||
|
||||
struct bt_gatt_subscribe_params name_sub_params;
|
||||
struct bt_gatt_discover_params name_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params technology_sub_params;
|
||||
struct bt_gatt_discover_params technology_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params signal_strength_sub_params;
|
||||
struct bt_gatt_discover_params signal_strength_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params current_calls_sub_params;
|
||||
struct bt_gatt_discover_params current_calls_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params in_target_uri_sub_params;
|
||||
struct bt_gatt_discover_params in_target_uri_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params status_flags_sub_params;
|
||||
struct bt_gatt_discover_params status_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params call_state_sub_params;
|
||||
struct bt_gatt_discover_params call_state_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params call_cp_sub_params;
|
||||
struct bt_gatt_discover_params call_cp_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params termination_sub_params;
|
||||
struct bt_gatt_discover_params termination_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params incoming_call_sub_params;
|
||||
struct bt_gatt_discover_params incoming_call_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params friendly_name_sub_params;
|
||||
struct bt_gatt_discover_params friendly_name_sub_disc_params;
|
||||
|
||||
struct bt_gatt_read_params read_params;
|
||||
uint8_t read_buf[BT_ATT_MAX_ATTRIBUTE_LEN];
|
||||
struct net_buf_simple net_buf;
|
||||
};
|
||||
|
||||
struct bt_tbs_server_inst {
|
||||
struct bt_tbs_instance tbs_insts[BT_TBS_INSTANCE_MAX_CNT];
|
||||
struct bt_gatt_discover_params discover_params;
|
||||
|
@ -1259,6 +1205,93 @@ static uint8_t read_friendly_name_cb(struct bt_conn *conn, uint8_t err,
|
|||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
|
||||
static uint8_t disc_read_ccid_cb(struct bt_conn *conn, uint8_t err,
|
||||
struct bt_gatt_read_params *params,
|
||||
const void *data, uint16_t length)
|
||||
{
|
||||
struct bt_tbs_instance *inst = CONTAINER_OF(params, struct bt_tbs_instance, read_params);
|
||||
struct bt_tbs_server_inst *srv_inst = &srv_insts[bt_conn_index(conn)];
|
||||
int cb_err = err;
|
||||
|
||||
(void)memset(params, 0, sizeof(*params));
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) && inst->gtbs) {
|
||||
BT_DBG("GTBS");
|
||||
} else {
|
||||
BT_DBG("Index %u", inst->index);
|
||||
}
|
||||
|
||||
if (cb_err != 0) {
|
||||
BT_DBG("err: 0x%02X", cb_err);
|
||||
} else if (data != NULL) {
|
||||
if (length == sizeof(inst->ccid)) {
|
||||
inst->ccid = ((uint8_t *)data)[0];
|
||||
BT_DBG("0x%02x", inst->ccid);
|
||||
} else {
|
||||
BT_DBG("Invalid length");
|
||||
cb_err = BT_ATT_ERR_INVALID_ATTRIBUTE_LEN;
|
||||
}
|
||||
}
|
||||
|
||||
inst->busy = false;
|
||||
|
||||
if (cb_err != 0) {
|
||||
tbs_client_cbs->discover(conn, cb_err, 0U, false);
|
||||
} else {
|
||||
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) &&
|
||||
inst->index == GTBS_INDEX) {
|
||||
BT_DBG("Setup complete GTBS");
|
||||
} else {
|
||||
BT_DBG("Setup complete for %u / %u TBS",
|
||||
inst->index + 1U, srv_inst->inst_cnt);
|
||||
}
|
||||
|
||||
(void)memset(params, 0, sizeof(*params));
|
||||
|
||||
if (BT_TBS_INSTANCE_MAX_CNT > 1U &&
|
||||
(((inst->index + 1U) < srv_inst->inst_cnt) ||
|
||||
(IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) &&
|
||||
srv_inst->gtbs_found &&
|
||||
inst->index + 1U == GTBS_INDEX))) {
|
||||
discover_next_instance(conn, inst->index + 1U);
|
||||
} else {
|
||||
srv_inst->current_inst = NULL;
|
||||
if (tbs_client_cbs != NULL &&
|
||||
tbs_client_cbs->discover != NULL) {
|
||||
tbs_client_cbs->discover(conn, 0,
|
||||
srv_inst->inst_cnt,
|
||||
srv_inst->gtbs_found);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
|
||||
static void tbs_client_disc_read_ccid(struct bt_conn *conn)
|
||||
{
|
||||
const uint8_t conn_index = bt_conn_index(conn);
|
||||
struct bt_tbs_server_inst *srv_inst = &srv_insts[conn_index];
|
||||
struct bt_tbs_instance *inst = srv_inst->current_inst;
|
||||
int err;
|
||||
|
||||
inst->read_params.func = disc_read_ccid_cb;
|
||||
inst->read_params.handle_count = 1U;
|
||||
inst->read_params.single.handle = inst->ccid_handle;
|
||||
inst->read_params.single.offset = 0U;
|
||||
|
||||
err = bt_gatt_read(conn, &inst->read_params);
|
||||
if (err != 0) {
|
||||
(void)memset(&inst->read_params, 0, sizeof(inst->read_params));
|
||||
srv_inst->current_inst = NULL;
|
||||
if (tbs_client_cbs != NULL &&
|
||||
tbs_client_cbs->discover != NULL) {
|
||||
tbs_client_cbs->discover(conn, err, 0U, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This will discover all characteristics on the server, retrieving the
|
||||
* handles of the writeable characteristics and subscribing to all notify and
|
||||
|
@ -1273,32 +1306,8 @@ static uint8_t discover_func(struct bt_conn *conn,
|
|||
struct bt_tbs_instance *current_inst = srv_inst->current_inst;
|
||||
|
||||
if (attr == NULL) {
|
||||
if (IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) &&
|
||||
current_inst->index == GTBS_INDEX) {
|
||||
BT_DBG("Setup complete GTBS");
|
||||
} else {
|
||||
BT_DBG("Setup complete for %u / %u TBS",
|
||||
current_inst->index + 1,
|
||||
srv_inst->inst_cnt);
|
||||
}
|
||||
|
||||
(void)memset(params, 0, sizeof(*params));
|
||||
|
||||
if (BT_TBS_INSTANCE_MAX_CNT > 1 &&
|
||||
(((current_inst->index + 1) < srv_inst->inst_cnt) ||
|
||||
(IS_ENABLED(CONFIG_BT_TBS_CLIENT_GTBS) &&
|
||||
srv_inst->gtbs_found &&
|
||||
current_inst->index + 1 == GTBS_INDEX))) {
|
||||
discover_next_instance(conn, current_inst->index + 1);
|
||||
} else {
|
||||
srv_inst->current_inst = NULL;
|
||||
if (tbs_client_cbs != NULL &&
|
||||
tbs_client_cbs->discover != NULL) {
|
||||
tbs_client_cbs->discover(conn, 0,
|
||||
srv_inst->inst_cnt,
|
||||
srv_inst->gtbs_found);
|
||||
}
|
||||
}
|
||||
/* Read the CCID as the last part of discovering a TBS instance */
|
||||
tbs_client_disc_read_ccid(conn);
|
||||
|
||||
return BT_GATT_ITER_STOP;
|
||||
}
|
||||
|
@ -2178,3 +2187,24 @@ void bt_tbs_client_register_cb(const struct bt_tbs_client_cb *cbs)
|
|||
{
|
||||
tbs_client_cbs = cbs;
|
||||
}
|
||||
|
||||
struct bt_tbs_instance *bt_tbs_client_get_by_ccid(const struct bt_conn *conn,
|
||||
uint8_t ccid)
|
||||
{
|
||||
struct bt_tbs_server_inst *server;
|
||||
|
||||
CHECKIF(conn == NULL) {
|
||||
BT_DBG("conn was NULL");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
server = &srv_insts[bt_conn_index(conn)];
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(server->tbs_insts); i++) {
|
||||
if (server->tbs_insts[i].ccid == ccid) {
|
||||
return &server->tbs_insts[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -281,3 +281,61 @@ struct bt_tbs_in_uri {
|
|||
uint8_t call_index;
|
||||
char uri[CONFIG_BT_TBS_MAX_URI_LENGTH + 1];
|
||||
} __packed;
|
||||
|
||||
#if defined(CONFIG_BT_TBS_CLIENT)
|
||||
struct bt_tbs_instance {
|
||||
struct bt_tbs_client_call_state calls[CONFIG_BT_TBS_CLIENT_MAX_CALLS];
|
||||
|
||||
uint16_t start_handle;
|
||||
uint16_t end_handle;
|
||||
uint16_t provider_name_handle;
|
||||
uint16_t bearer_uci_handle;
|
||||
uint16_t technology_handle;
|
||||
uint16_t uri_list_handle;
|
||||
uint16_t signal_strength_handle;
|
||||
uint16_t signal_interval_handle;
|
||||
uint16_t current_calls_handle;
|
||||
uint16_t ccid_handle;
|
||||
uint16_t status_flags_handle;
|
||||
uint16_t in_uri_handle;
|
||||
uint16_t call_state_handle;
|
||||
uint16_t call_cp_handle;
|
||||
uint16_t optional_opcodes_handle;
|
||||
uint16_t termination_reason_handle;
|
||||
uint16_t friendly_name_handle;
|
||||
uint16_t in_call_handle;
|
||||
|
||||
bool busy;
|
||||
uint8_t subscribe_cnt;
|
||||
uint8_t index;
|
||||
bool gtbs;
|
||||
uint8_t ccid;
|
||||
|
||||
struct bt_gatt_subscribe_params name_sub_params;
|
||||
struct bt_gatt_discover_params name_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params technology_sub_params;
|
||||
struct bt_gatt_discover_params technology_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params signal_strength_sub_params;
|
||||
struct bt_gatt_discover_params signal_strength_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params current_calls_sub_params;
|
||||
struct bt_gatt_discover_params current_calls_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params in_target_uri_sub_params;
|
||||
struct bt_gatt_discover_params in_target_uri_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params status_flags_sub_params;
|
||||
struct bt_gatt_discover_params status_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params call_state_sub_params;
|
||||
struct bt_gatt_discover_params call_state_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params call_cp_sub_params;
|
||||
struct bt_gatt_discover_params call_cp_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params termination_sub_params;
|
||||
struct bt_gatt_discover_params termination_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params incoming_call_sub_params;
|
||||
struct bt_gatt_discover_params incoming_call_sub_disc_params;
|
||||
struct bt_gatt_subscribe_params friendly_name_sub_params;
|
||||
struct bt_gatt_discover_params friendly_name_sub_disc_params;
|
||||
|
||||
struct bt_gatt_read_params read_params;
|
||||
uint8_t read_buf[BT_ATT_MAX_ATTRIBUTE_LEN];
|
||||
struct net_buf_simple net_buf;
|
||||
};
|
||||
#endif /* CONFIG_BT_TBS_CLIENT */
|
||||
|
|
|
@ -21,6 +21,9 @@ static volatile bool read_complete;
|
|||
static volatile bool call_placed;
|
||||
static volatile uint8_t call_state;
|
||||
static volatile uint8_t call_index;
|
||||
static volatile uint8_t tbs_count;
|
||||
|
||||
CREATE_FLAG(ccid_read_flag);
|
||||
|
||||
static void tbs_client_call_states_cb(struct bt_conn *conn, int err,
|
||||
uint8_t index, uint8_t call_count,
|
||||
|
@ -58,7 +61,7 @@ static void tbs_client_read_bearer_provider_name(struct bt_conn *conn, int err,
|
|||
}
|
||||
|
||||
static void tbs_client_discover_cb(struct bt_conn *conn, int err,
|
||||
uint8_t tbs_count, bool gtbs_found)
|
||||
uint8_t count, bool gtbs_found)
|
||||
{
|
||||
printk("%s\n", __func__);
|
||||
if (err != 0) {
|
||||
|
@ -66,10 +69,32 @@ static void tbs_client_discover_cb(struct bt_conn *conn, int err,
|
|||
return;
|
||||
}
|
||||
|
||||
tbs_count = count;
|
||||
is_gtbs_found = true;
|
||||
discovery_complete = true;
|
||||
}
|
||||
|
||||
static void tbs_client_read_ccid_cb(struct bt_conn *conn, int err,
|
||||
uint8_t inst_index, uint32_t value)
|
||||
{
|
||||
struct bt_tbs_instance *inst;
|
||||
|
||||
if (value > UINT8_MAX) {
|
||||
FAIL("Invalid CCID: %u", value);
|
||||
return;
|
||||
}
|
||||
|
||||
printk("Read CCID %u on index %u\n", value, inst_index);
|
||||
|
||||
inst = bt_tbs_client_get_by_ccid(conn, (uint8_t)value);
|
||||
if (inst == NULL) {
|
||||
FAIL("Could not get instance by CCID: %u", value);
|
||||
return;
|
||||
}
|
||||
|
||||
SET_FLAG(ccid_read_flag);
|
||||
}
|
||||
|
||||
static const struct bt_tbs_client_cb tbs_client_cbs = {
|
||||
.discover = tbs_client_discover_cb,
|
||||
.originate_call = NULL,
|
||||
|
@ -85,7 +110,7 @@ static const struct bt_tbs_client_cb tbs_client_cbs = {
|
|||
.signal_strength = NULL,
|
||||
.signal_interval = NULL,
|
||||
.current_calls = NULL,
|
||||
.ccid = NULL,
|
||||
.ccid = tbs_client_read_ccid_cb,
|
||||
.status_flags = NULL,
|
||||
.call_uri = NULL,
|
||||
.call_state = tbs_client_call_states_cb,
|
||||
|
@ -123,6 +148,39 @@ static struct bt_conn_cb conn_callbacks = {
|
|||
.disconnected = disconnected,
|
||||
};
|
||||
|
||||
static void test_ccid(void)
|
||||
{
|
||||
if (is_gtbs_found) {
|
||||
int err;
|
||||
|
||||
UNSET_FLAG(ccid_read_flag);
|
||||
printk("Reading GTBS CCID\n");
|
||||
|
||||
err = bt_tbs_client_read_ccid(default_conn, BT_TBS_GTBS_INDEX);
|
||||
if (err != 0) {
|
||||
FAIL("Read GTBS CCID failed (%d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
WAIT_FOR_FLAG(ccid_read_flag);
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < tbs_count; i++) {
|
||||
int err;
|
||||
|
||||
UNSET_FLAG(ccid_read_flag);
|
||||
printk("Reading bearer CCID on index %u\n", i);
|
||||
|
||||
err = bt_tbs_client_read_ccid(default_conn, i);
|
||||
if (err != 0) {
|
||||
FAIL("Read bearer CCID failed (%d)\n", err);
|
||||
return;
|
||||
}
|
||||
|
||||
WAIT_FOR_FLAG(ccid_read_flag);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_main(void)
|
||||
{
|
||||
int err;
|
||||
|
@ -203,6 +261,8 @@ static void test_main(void)
|
|||
FAIL("Read bearer provider name failed (%d)\n", err);
|
||||
}
|
||||
|
||||
test_ccid();
|
||||
|
||||
WAIT_FOR_COND(read_complete);
|
||||
PASS("TBS_CLIENT Passed\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue