Bluetooth: BAP: Move uni cli discover callback

Move the unicast client discover callback from the
parameters to the callback structure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2023-03-22 13:11:30 +01:00 committed by Carles Cufí
commit 39406a4843
6 changed files with 90 additions and 88 deletions

View file

@ -1076,6 +1076,8 @@ int bt_bap_unicast_group_add_streams(struct bt_bap_unicast_group *unicast_group,
*/
int bt_bap_unicast_group_delete(struct bt_bap_unicast_group *unicast_group);
struct bt_bap_unicast_client_discover_params;
/** Unicast Client callback structure */
struct bt_bap_unicast_client_cb {
/**
@ -1208,6 +1210,24 @@ struct bt_bap_unicast_client_cb {
*/
void (*release)(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code rsp_code,
enum bt_bap_ascs_reason reason);
/**
* @brief Discover Audio capabilities and endpoints callback function.
*
* If discovery procedure has complete both cap and ep are set to NULL.
*
* The @p codec is only valid while in the callback, so the values must be stored by the
* receiver if future use is wanted.
*
* @param conn Connection to the remote unicast server.
* @param codec Remote capabilities.
* @param ep Remote endpoint.
* @param params Pointer to the discover parameters.
*
* If discovery procedure has complete both @p codec and @p ep are set to NULL.
*/
void (*discover)(struct bt_conn *conn, struct bt_codec *codec, struct bt_bap_ep *ep,
struct bt_bap_unicast_client_discover_params *params);
};
/**
@ -1222,35 +1242,10 @@ struct bt_bap_unicast_client_cb {
*/
int bt_bap_unicast_client_register_cb(const struct bt_bap_unicast_client_cb *cb);
struct bt_bap_unicast_client_discover_params;
/**
* @typedef bt_bap_unicast_client_discover_func_t
* @brief Discover Audio capabilities and endpoints callback function.
*
* If discovery procedure has complete both cap and ep are set to NULL.
*
* The @p codec is only valid while in the callback, so the values must be stored by the receiver
* if future use is wanted.
*
* @param conn Connection to the remote unicast server.
* @param codec Remote capabilities.
* @param ep Remote endpoint.
* @param params Pointer to the discover parameters.
*
* If discovery procedure has complete both @p codec and @p ep are set to NULL.
*/
typedef void (*bt_bap_unicast_client_discover_func_t)(
struct bt_conn *conn, struct bt_codec *codec, struct bt_bap_ep *ep,
struct bt_bap_unicast_client_discover_params *params);
struct bt_bap_unicast_client_discover_params {
/** Capabilities type */
enum bt_audio_dir dir;
/** Callback function */
bt_bap_unicast_client_discover_func_t func;
/** Number of capabilities found */
uint8_t num_caps;

View file

@ -19,6 +19,7 @@
static void start_scan(void);
static struct bt_bap_unicast_client_cb unicast_client_cbs;
static struct bt_conn *default_conn;
static struct k_work_delayable audio_send_work;
static struct bt_bap_unicast_group *unicast_group;
@ -724,7 +725,7 @@ static void available_contexts_cb(struct bt_conn *conn,
printk("snk ctx %u src ctx %u\n", snk_ctx, src_ctx);
}
const struct bt_bap_unicast_client_cb unicast_client_cbs = {
static struct bt_bap_unicast_client_cb unicast_client_cbs = {
.location = unicast_client_location_cb,
.available_contexts = available_contexts_cb,
};
@ -792,7 +793,7 @@ static int discover_sinks(void)
static struct bt_bap_unicast_client_discover_params params;
int err;
params.func = discover_sinks_cb;
unicast_client_cbs.discover = discover_sinks_cb;
params.dir = BT_AUDIO_DIR_SINK;
err = bt_bap_unicast_client_discover(default_conn, &params);
@ -815,7 +816,7 @@ static int discover_sources(void)
static struct bt_bap_unicast_client_discover_params params;
int err;
params.func = discover_sources_cb;
unicast_client_cbs.discover = discover_sources_cb;
params.dir = BT_AUDIO_DIR_SOURCE;
err = bt_bap_unicast_client_discover(default_conn, &params);

View file

@ -1444,6 +1444,14 @@ static int unicast_client_ep_subscribe(struct bt_conn *conn, struct bt_bap_ep *e
return bt_gatt_subscribe(conn, &client_ep->subscribe);
}
static void discover_cb(struct bt_conn *conn, struct bt_codec *codec, struct bt_bap_ep *ep,
struct bt_bap_unicast_client_discover_params *params)
{
if (unicast_client_cbs != NULL && unicast_client_cbs->discover != NULL) {
unicast_client_cbs->discover(conn, codec, ep, params);
}
}
static void unicast_client_cp_sub_cb(struct bt_conn *conn, uint8_t err,
struct bt_gatt_subscribe_params *sub_params)
{
@ -1455,7 +1463,7 @@ static void unicast_client_cp_sub_cb(struct bt_conn *conn, uint8_t err,
discover);
params->err = err;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
static void unicast_client_ep_set_cp(struct bt_conn *conn,
@ -1507,13 +1515,13 @@ static void unicast_client_ep_set_cp(struct bt_conn *conn,
params->err = BT_ATT_ERR_UNLIKELY;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return;
}
} else { /* already subscribed */
params->err = 0;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
}
@ -2828,7 +2836,7 @@ static uint8_t unicast_client_cp_discover_func(struct bt_conn *conn,
if (params->err) {
LOG_ERR("Unable to find ASE Control Point");
}
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -2868,8 +2876,6 @@ static uint8_t unicast_client_ase_read_func(struct bt_conn *conn, uint8_t err,
params = CONTAINER_OF(read, struct bt_bap_unicast_client_discover_params, read);
__ASSERT(params->func != NULL, "params->func was NULL");
LOG_DBG("conn %p err 0x%02x len %u", conn, err, length);
if (err) {
@ -2923,7 +2929,7 @@ static uint8_t unicast_client_ase_read_func(struct bt_conn *conn, uint8_t err,
unicast_client_ep_set_status(ep, buf);
unicast_client_ep_subscribe(conn, ep);
params->func(conn, NULL, ep, params);
discover_cb(conn, NULL, ep, params);
params->num_eps++;
@ -2933,13 +2939,13 @@ static uint8_t unicast_client_ase_read_func(struct bt_conn *conn, uint8_t err,
params->err = err;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
fail:
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -2954,8 +2960,6 @@ static uint8_t unicast_client_ase_discover_cb(struct bt_conn *conn,
params = CONTAINER_OF(discover, struct bt_bap_unicast_client_discover_params,
discover);
__ASSERT(params->func != NULL, "params->func was NULL");
if (attr == NULL) {
if (params->num_eps == 0) {
LOG_DBG("Unable to find %s ASE",
@ -2963,7 +2967,7 @@ static uint8_t unicast_client_ase_discover_cb(struct bt_conn *conn,
params->err = BT_ATT_ERR_ATTRIBUTE_NOT_FOUND;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
} else {
/* Else we found all the ASEs */
err = unicast_client_ase_cp_discover(conn, params);
@ -2971,7 +2975,7 @@ static uint8_t unicast_client_ase_discover_cb(struct bt_conn *conn,
LOG_ERR("Unable to discover ASE Control Point");
params->err = BT_ATT_ERR_UNLIKELY;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
}
@ -2997,7 +3001,7 @@ static uint8_t unicast_client_ase_discover_cb(struct bt_conn *conn,
params->err = err;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3040,7 +3044,7 @@ static uint8_t unicast_client_pacs_avail_ctx_read_func(struct bt_conn *conn, uin
if (err || data == NULL || length != sizeof(context)) {
LOG_DBG("Could not read available context: %d, %p, %u", err, data, length);
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -3060,7 +3064,7 @@ static uint8_t unicast_client_pacs_avail_ctx_read_func(struct bt_conn *conn, uin
BT_ATT_FIRST_ATTRIBUTE_HANDLE) < 0) {
LOG_ERR("Unable to read ASE");
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3136,7 +3140,7 @@ static uint8_t unicast_client_pacs_avail_ctx_discover_cb(struct bt_conn *conn,
* the characteristic is mandatory
*/
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -3169,7 +3173,7 @@ static uint8_t unicast_client_pacs_avail_ctx_discover_cb(struct bt_conn *conn,
/* If the characteristic is not subscribable we terminate the
* discovery as BT_GATT_CHRC_NOTIFY is mandatory
*/
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -3179,7 +3183,7 @@ static uint8_t unicast_client_pacs_avail_ctx_discover_cb(struct bt_conn *conn,
LOG_DBG("Failed to read PACS avail_ctx: %d", err);
params->err = err;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3216,7 +3220,7 @@ static uint8_t unicast_client_pacs_location_read_func(struct bt_conn *conn, uint
LOG_DBG("Unable to read PACS location for dir %s: %u, %p, %u",
bt_audio_dir_str(params->dir), err, data, length);
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -3234,7 +3238,7 @@ static uint8_t unicast_client_pacs_location_read_func(struct bt_conn *conn, uint
if (unicast_client_pacs_avail_ctx_discover(conn, params) < 0) {
LOG_ERR("Unable to read available contexts");
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3322,7 +3326,7 @@ static uint8_t unicast_client_pacs_location_discover_cb(struct bt_conn *conn,
if (unicast_client_pacs_avail_ctx_discover(conn, params) < 0) {
LOG_ERR("Unable to read available contexts");
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3359,7 +3363,7 @@ static uint8_t unicast_client_pacs_location_discover_cb(struct bt_conn *conn,
LOG_DBG("Failed to read PACS location: %d", err);
params->err = err;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3414,7 +3418,7 @@ discover_loc:
if (unicast_client_pacs_location_discover(conn, params) < 0) {
LOG_ERR("Unable to read PACS location");
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3437,9 +3441,7 @@ static uint8_t unicast_client_pacs_context_discover_cb(struct bt_conn *conn,
params->err = BT_ATT_ERR_ATTRIBUTE_NOT_FOUND;
__ASSERT(params->func != NULL, "params->func was NULL");
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -3462,7 +3464,7 @@ static uint8_t unicast_client_pacs_context_discover_cb(struct bt_conn *conn,
params->err = err;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;
@ -3598,7 +3600,7 @@ static uint8_t unicast_client_read_func(struct bt_conn *conn, uint8_t err,
LOG_DBG("codec 0x%02x config count %u meta count %u ", codec.id, codec.data_count,
codec.meta_count);
params->func(conn, &codec, NULL, params);
discover_cb(conn, &codec, NULL, params);
rsp->num_pac--;
params->num_caps++;
@ -3617,7 +3619,7 @@ static uint8_t unicast_client_read_func(struct bt_conn *conn, uint8_t err,
return BT_GATT_ITER_STOP;
fail:
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -3636,9 +3638,7 @@ static uint8_t unicast_client_pac_discover_cb(struct bt_conn *conn,
params->err = BT_ATT_ERR_ATTRIBUTE_NOT_FOUND;
__ASSERT(params->func != NULL, "params->func was NULL");
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
return BT_GATT_ITER_STOP;
}
@ -3664,7 +3664,7 @@ static uint8_t unicast_client_pac_discover_cb(struct bt_conn *conn,
params->err = err;
params->func(conn, NULL, NULL, params);
discover_cb(conn, NULL, NULL, params);
}
return BT_GATT_ITER_STOP;

View file

@ -42,6 +42,7 @@ static const struct bt_codec_qos_pref qos_pref = BT_CODEC_QOS_PREF(true, BT_GAP_
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT)
struct bt_bap_unicast_group *default_unicast_group;
static struct bt_bap_unicast_client_cb unicast_client_cbs;
#if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0
struct bt_bap_ep *snks[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT];
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0 */
@ -788,7 +789,7 @@ static void discover_all(struct bt_conn *conn, struct bt_codec *codec, struct bt
if (params->dir == BT_AUDIO_DIR_SINK) {
int err;
params->func = discover_cb;
unicast_client_cbs.discover = discover_cb;
params->dir = BT_AUDIO_DIR_SOURCE;
err = bt_bap_unicast_client_discover(default_conn, params);
@ -869,7 +870,7 @@ static void release_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code r
stream, rsp_code, reason);
}
const struct bt_bap_unicast_client_cb unicast_client_cbs = {
static struct bt_bap_unicast_client_cb unicast_client_cbs = {
.location = unicast_client_location_cb,
.available_contexts = available_contexts_cb,
.config = config_cb,
@ -897,11 +898,6 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[])
return -ENOEXEC;
}
if (params.func) {
shell_error(sh, "Discover in progress");
return -ENOEXEC;
}
if (!cbs_registered) {
int err = bt_bap_unicast_client_register_cb(&unicast_client_cbs);
@ -913,14 +909,14 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[])
cbs_registered = true;
}
params.func = discover_all;
unicast_client_cbs.discover = discover_all;
params.dir = BT_AUDIO_DIR_SINK;
if (argc > 1) {
if (!strcmp(argv[1], "sink")) {
params.func = discover_cb;
unicast_client_cbs.discover = discover_cb;
} else if (!strcmp(argv[1], "source")) {
params.func = discover_cb;
unicast_client_cbs.discover = discover_cb;
params.dir = BT_AUDIO_DIR_SOURCE;
} else {
shell_error(sh, "Unsupported dir: %s", argv[1]);

View file

@ -198,19 +198,6 @@ static void release_cb(struct bt_bap_stream *stream, enum bt_bap_ascs_rsp_code r
}
}
const struct bt_bap_unicast_client_cb unicast_client_cbs = {
.location = unicast_client_location_cb,
.available_contexts = available_contexts_cb,
.config = config_cb,
.qos = qos_cb,
.enable = enable_cb,
.start = start_cb,
.stop = stop_cb,
.disable = disable_cb,
.metadata = metadata_cb,
.release = release_cb,
};
static void add_remote_sink(struct bt_bap_ep *ep, uint8_t index)
{
printk("Sink #%u: ep %p\n", index, ep);
@ -310,6 +297,19 @@ static void discover_sources_cb(struct bt_conn *conn, struct bt_codec *codec, st
}
}
static struct bt_bap_unicast_client_cb unicast_client_cbs = {
.location = unicast_client_location_cb,
.available_contexts = available_contexts_cb,
.config = config_cb,
.qos = qos_cb,
.enable = enable_cb,
.start = start_cb,
.stop = stop_cb,
.disable = disable_cb,
.metadata = metadata_cb,
.release = release_cb,
};
static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx)
{
printk("MTU exchanged\n");
@ -367,7 +367,8 @@ static void discover_sinks(void)
static struct bt_bap_unicast_client_discover_params params;
int err;
params.func = discover_sinks_cb;
unicast_client_cbs.discover = discover_sinks_cb;
params.dir = BT_AUDIO_DIR_SINK;
UNSET_FLAG(flag_sink_discovered);
@ -386,7 +387,7 @@ static void discover_sources(void)
static struct bt_bap_unicast_client_discover_params params;
int err;
params.func = discover_sources_cb;
unicast_client_cbs.discover = discover_sources_cb;
params.dir = BT_AUDIO_DIR_SOURCE;
UNSET_FLAG(flag_source_discovered);

View file

@ -296,6 +296,10 @@ static void discover_sink_cb(struct bt_conn *conn, struct bt_codec *codec, struc
}
}
static const struct bt_bap_unicast_client_cb unicast_client_cbs = {
.discover = discover_sink_cb,
};
static void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx)
{
printk("MTU exchanged\n");
@ -319,6 +323,12 @@ static void init(void)
if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT)) {
bt_gatt_cb_register(&gatt_callbacks);
err = bt_bap_unicast_client_register_cb(&unicast_client_cbs);
if (err != 0) {
FAIL("Failed to register BAP unicast client callbacks (err %d)\n", err);
return;
}
err = bt_cap_initiator_register_cb(&cap_cb);
if (err != 0) {
FAIL("Failed to register CAP callbacks (err %d)\n", err);
@ -362,7 +372,6 @@ static void discover_sink(void)
static struct bt_bap_unicast_client_discover_params params;
int err;
params.func = discover_sink_cb;
params.dir = BT_AUDIO_DIR_SINK;
err = bt_bap_unicast_client_discover(default_conn, &params);