Skip to content

Commit

Permalink
Bluetooth: CCP: Client: Add get_bearers
Browse files Browse the repository at this point in the history
Add bt_ccp_client_get_bearers that will return the bearers of
a client so that the application can always retrieve them if they
do not store them from the discovery callback.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
  • Loading branch information
Thalley committed Oct 9, 2024
1 parent 65b8b61 commit 929b03d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/zephyr/bluetooth/audio/ccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ int bt_ccp_client_register_cb(struct bt_ccp_client_cb *cb);
* @retval -EALREADY @p cb is not registered
*/
int bt_ccp_client_unregister_cb(struct bt_ccp_client_cb *cb);

/**
* @brief Get the bearers of a client instance
*
* @param[in] client The client to get the bearers of.
* @param[out] bearers The bearers struct that will be populated with the bearers of @p inst.
* @retval -EINVAL @p inst or @p bearers is NULL
*/
int bt_ccp_client_get_bearers(struct bt_ccp_client *client, struct bt_ccp_client_bearers *bearers);

/** @} */ /* End of group bt_ccp_client */
#ifdef __cplusplus
}
Expand Down
18 changes: 18 additions & 0 deletions subsys/bluetooth/audio/ccp_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,21 @@ int bt_ccp_client_unregister_cb(struct bt_ccp_client_cb *cb)

return 0;
}

int bt_ccp_client_get_bearers(struct bt_ccp_client *client, struct bt_ccp_client_bearers *bearers)
{
CHECKIF(client == NULL) {
LOG_DBG("client is NULL");
return -EINVAL;
}

CHECKIF(bearers == NULL) {
LOG_DBG("bearers is NULL");
return -EINVAL;
}

memset(bearers, 0, sizeof(*bearers));
populate_bearers(client, bearers);

return 0;
}
24 changes: 24 additions & 0 deletions tests/bluetooth/audio/ccp_client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,27 @@ static ZTEST_F(ccp_client_test_suite, test_ccp_client_discover_inval_param_null_
err = bt_ccp_client_discover(&fixture->conn, NULL);
zassert_equal(-EINVAL, err, "Unexpected return value %d", err);
}

static ZTEST_F(ccp_client_test_suite, test_ccp_client_get_bearers)
{
struct bt_ccp_client_bearers bearers;
int err;

err = bt_ccp_client_register_cb(&mock_ccp_client_cb);
zassert_equal(0, err, "Unexpected return value %d", err);

err = bt_ccp_client_discover(&fixture->conn, &fixture->client_inst);
zassert_equal(0, err, "Unexpected return value %d", err);

err = bt_ccp_client_get_bearers(fixture->client_inst, &bearers);
zassert_equal(0, err, "Unexpected return value %d", err);

#if defined(CONFIG_BT_TBS_CLIENT_GTBS)
zassert_not_null(bearers.gtbs_bearer);
#endif /* CONFIG_BT_TBS_CLIENT_GTBS */

#if defined(CONFIG_BT_TBS_CLIENT_TBS)
zassert_equal(CONFIG_BT_TBS_CLIENT_MAX_TBS_INSTANCES, bearers.tbs_count);
zassert_not_null(bearers.tbs_bearers);
#endif /* CONFIG_BT_TBS_CLIENT_TBS */
}

0 comments on commit 929b03d

Please sign in to comment.