2022-04-29 13:58:25 +02:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Shell APIs for Bluetooth CAP initiator
|
|
|
|
*
|
2023-02-27 13:01:17 +01:00
|
|
|
* Copyright (c) 2022-2023 Nordic Semiconductor ASA
|
2022-04-29 13:58:25 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <zephyr/types.h>
|
|
|
|
#include <zephyr/shell/shell.h>
|
|
|
|
#include <zephyr/bluetooth/conn.h>
|
|
|
|
#include <zephyr/bluetooth/gatt.h>
|
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
#include <zephyr/bluetooth/audio/cap.h>
|
|
|
|
|
2023-03-16 17:18:08 +01:00
|
|
|
#include "shell/bt.h"
|
2022-04-29 13:58:25 +02:00
|
|
|
|
2023-02-27 13:01:17 +01:00
|
|
|
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT)
|
2022-04-29 13:58:25 +02:00
|
|
|
|
2022-05-04 11:38:26 +02:00
|
|
|
static void cap_discover_cb(struct bt_conn *conn, int err,
|
2022-10-11 13:53:49 +02:00
|
|
|
const struct bt_csip_set_coordinator_csis_inst *csis_inst)
|
2022-04-29 13:58:25 +02:00
|
|
|
{
|
|
|
|
if (err != 0) {
|
|
|
|
shell_error(ctx_shell, "discover failed (%d)", err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-04 11:38:26 +02:00
|
|
|
shell_print(ctx_shell, "discovery completed%s",
|
|
|
|
csis_inst == NULL ? "" : " with CSIS");
|
2022-04-29 13:58:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct bt_cap_initiator_cb cbs = {
|
|
|
|
.unicast_discovery_complete = cap_discover_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cmd_cap_initiator_discover(const struct shell *sh, size_t argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
static bool cbs_registered;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (default_conn == NULL) {
|
|
|
|
shell_error(sh, "Not connected");
|
|
|
|
return -ENOEXEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx_shell == NULL) {
|
|
|
|
ctx_shell = sh;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cbs_registered) {
|
|
|
|
bt_cap_initiator_register_cb(&cbs);
|
|
|
|
cbs_registered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = bt_cap_initiator_unicast_discover(default_conn);
|
|
|
|
if (err != 0) {
|
|
|
|
shell_error(sh, "Fail: %d", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2023-02-27 13:01:17 +01:00
|
|
|
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */
|
2022-04-29 13:58:25 +02:00
|
|
|
|
|
|
|
static int cmd_cap_initiator(const struct shell *sh, size_t argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc > 1) {
|
|
|
|
shell_error(sh, "%s unknown parameter: %s",
|
|
|
|
argv[0], argv[1]);
|
|
|
|
} else {
|
|
|
|
shell_error(sh, "%s Missing subcommand", argv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOEXEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHELL_STATIC_SUBCMD_SET_CREATE(cap_initiator_cmds,
|
2023-02-27 13:01:17 +01:00
|
|
|
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT)
|
|
|
|
SHELL_CMD_ARG(discover, NULL, "Discover CAS",
|
|
|
|
cmd_cap_initiator_discover, 1, 0),
|
|
|
|
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */
|
|
|
|
SHELL_SUBCMD_SET_END);
|
2022-04-29 13:58:25 +02:00
|
|
|
|
|
|
|
SHELL_CMD_ARG_REGISTER(cap_initiator, &cap_initiator_cmds,
|
|
|
|
"Bluetooth CAP initiator shell commands",
|
|
|
|
cmd_cap_initiator, 1, 1);
|