Skip to content

Commit

Permalink
Bluetooth: CAP: Commander API and skeleton
Browse files Browse the repository at this point in the history
Adds the CAP Commendar API and skeleton that can
implemented.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley committed Oct 31, 2023
1 parent 67676d8 commit 58bc7c7
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 0 deletions.
223 changes: 223 additions & 0 deletions include/zephyr/bluetooth/audio/cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,229 @@ struct bt_cap_broadcast_to_unicast_param {
int bt_cap_initiator_broadcast_to_unicast(const struct bt_cap_broadcast_to_unicast_param *param,
struct bt_bap_unicast_group **unicast_group);

/**
* @brief Discovers audio support on a remote device.
*
* This will discover the Common Audio Service (CAS) on the remote device, to
* verify if the remote device supports the Common Audio Profile.
*
* @note @kconfig{CONFIG_BT_CAP_COMMANDER} must be enabled for this function. If
* @kconfig{CONFIG_BT_CAP_INITIATOR} is also enabled, it does not matter if
* bt_cap_commander_unicast_discover() or bt_cap_initiator_unicast_discover() is used.
*
* @param conn Connection to a remote server.
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_unicast_discover(struct bt_conn *conn);

/** Parameters for starting broadcast reception */
struct bt_cap_commander_broadcast_reception_start_param {
/** The type of the set. */
enum bt_cap_set_type type;

/** Coordinated or ad-hoc set member. */
union bt_cap_set_member *members;

/** The number of members in @p members */
size_t count;

/** Address of the advertiser. */
bt_addr_le_t addr;

/** SID of the advertising set. */
uint8_t adv_sid;

/**
* @brief Periodic advertising interval in milliseconds.
*
* BT_BAP_PA_INTERVAL_UNKNOWN if unknown.
*/
uint16_t pa_interval;

/** 24-bit broadcast ID */
uint32_t broadcast_id;

/**
* @brief Pointer to array of subgroups
*
* At least one bit in one of the subgroups bis_sync parameters shall be set.
*/
struct bt_bap_scan_delegator_subgroup *subgroups;

/** Number of subgroups */
size_t num_subgroups;
};

/**
* @brief Starts the reception of broadcast audio on one or more remote Common Audio Profile
* Acceptors
*
* @param param The parameters to start the broadcast audio
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_broadcast_reception_start(
const struct bt_cap_commander_broadcast_reception_start_param *param);

/** Parameters for stopping broadcast reception */
struct bt_cap_commander_broadcast_reception_stop_param {
/** The type of the set. */
enum bt_cap_set_type type;

/** Coordinated or ad-hoc set member. */
union bt_cap_set_member *members;

/** The number of members in @p members */
size_t count;
};

/**
* @brief Stops the reception of broadcast audio on one or more remote Common Audio Profile
* Acceptors
*
* @param param The parameters to stop the broadcast audio
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_broadcast_reception_stop(
const struct bt_cap_commander_broadcast_reception_stop_param *param);

/** Parameters for changing absolute volume */
struct bt_cap_commander_change_volume_param {
/** The type of the set. */
enum bt_cap_set_type type;

/** Coordinated or ad-hoc set member. */
union bt_cap_set_member *members;

/** The number of members in @p members */
size_t count;

/** The absolute volume to set */
uint8_t volume;
};

/**
* @brief Change the volume on one or more Common Audio Profile Acceptors
*
* @param param The parameters for the volume change
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_change_volume(const struct bt_cap_commander_change_volume_param *param);

/** Parameters for changing volume offset */
struct bt_cap_commander_change_volume_offset_param {
/** The type of the set. */
enum bt_cap_set_type type;

/** Coordinated or ad-hoc set member. */
union bt_cap_set_member *members;

/** The number of members in @p members */
size_t count;

/**
* @brief The offset to set
*
* Value shall be between @ref BT_VOCS_MIN_OFFSET and @ref BT_VOCS_MAX_OFFSET
*/
int16_t offset;
};

/**
* @brief Change the volume offset on one or more Common Audio Profile Acceptors
*
* @param param The parameters for the volume offset change
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_change_volume_offset(
const struct bt_cap_commander_change_volume_offset_param *param);

/** Parameters for changing volume mute state */
struct bt_cap_commander_change_volume_mute_state_param {
/** The type of the set. */
enum bt_cap_set_type type;

/** Coordinated or ad-hoc set member. */
union bt_cap_set_member *members;

/** The number of members in @p members */
size_t count;

/**
* @brief The volume mute state to set
*
* true to mute, and false to unmute
*/
bool mute;
};

/**
* @brief Change the volume mute state on one or more Common Audio Profile Acceptors
*
* @param param The parameters for the volume mute state change
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_change_volume_mute_state(
const struct bt_cap_commander_change_volume_mute_state_param *param);

/** Parameters for changing microphone mute state */
struct bt_cap_commander_change_microphone_mute_state_param {
/** The type of the set. */
enum bt_cap_set_type type;

/** Coordinated or ad-hoc set member. */
union bt_cap_set_member *members;

/** The number of members in @p members */
size_t count;

/**
* @brief The microphone mute state to set
*
* true to mute, and false to unmute
*/
bool mute;
};

/**
* @brief Change the microphone mute state on one or more Common Audio Profile Acceptors
*
* @param param The parameters for the microphone mute state change
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_change_microphone_mute_state(
const struct bt_cap_commander_change_microphone_mute_state_param *param);

/** Parameters for changing microphone mute state */
struct bt_cap_commander_change_microphone_gain_setting_param {
/** The type of the set. */
enum bt_cap_set_type type;

/** Coordinated or ad-hoc set member. */
union bt_cap_set_member *members;

/** The number of members in @p members */
size_t count;

/** @brief The microphone gain setting to set */
int8_t gain;
};

/**
* @brief Change the microphone gain setting on one or more Common Audio Profile Acceptors
*
* @param param The parameters for the microphone gain setting change
*
* @return 0 on success or negative error value on failure.
*/
int bt_cap_commander_change_microphone_gain_setting(
const struct bt_cap_commander_change_microphone_gain_setting_param *param);
#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions subsys/bluetooth/Kconfig.logging
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,11 @@ legacy-debug-sym = BT_DEBUG_CAP_INITIATOR
module-str = "Common Audio Profile Initiator"
source "subsys/bluetooth/common/Kconfig.template.log_config_bt"

parent-module = BT
module = BT_CAP_COMMANDER
module-str = "Common Audio Profile Commander"
source "subsys/logging/Kconfig.template.log_config_inherit"

parent-module = BT
module = BT_CAP_STREAM
module-str = "Common Audio Profile Stream"
Expand Down
1 change: 1 addition & 0 deletions subsys/bluetooth/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,5 @@ zephyr_library_sources_ifdef(CONFIG_BT_HAS_CLIENT has_client.c)
zephyr_library_sources_ifdef(CONFIG_BT_CAP cap_stream.c)
zephyr_library_sources_ifdef(CONFIG_BT_CAP_ACCEPTOR cap_acceptor.c)
zephyr_library_sources_ifdef(CONFIG_BT_CAP_INITIATOR cap_initiator.c)
zephyr_library_sources_ifdef(CONFIG_BT_CAP_COMMANDER cap_commander.c)
zephyr_library_sources_ifdef(CONFIG_BT_TMAP tmap.c)
13 changes: 13 additions & 0 deletions subsys/bluetooth/audio/Kconfig.cap
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@ config BT_CAP_INITIATOR
select EXPERIMENTAL
help
Enabling this will enable the CAP Initiator role.


config BT_CAP_COMMANDER
bool "Common Audio Profile Initiator Role Support [EXPERIMENTAL]"
depends on (BT_BAP_BROADCAST_ASSISTANT && BT_BAP_SCAN_DELEGATOR && BT_CSIP_SET_COORDINATOR) || \
(BT_BAP_SCAN_DELEGATOR && BT_CSIP_SET_COORDINATOR) || \
(BT_VCP_VOL_CTLR && BT_CSIP_SET_COORDINATOR) || \
(BT_MICP_MIC_CTLR && BT_CSIP_SET_COORDINATOR) || \
BT_TBS_CLIENT || \
BT_MCC
select EXPERIMENTAL
help
Enabling this will enable the CAP Initiator role.
68 changes: 68 additions & 0 deletions subsys/bluetooth/audio/cap_commander.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2022-2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/check.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/bluetooth/audio/audio.h>
#include <zephyr/bluetooth/audio/cap.h>
#include <zephyr/bluetooth/audio/tbs.h>
#include "cap_internal.h"
#include "ccid_internal.h"
#include "csip_internal.h"
#include "bap_endpoint.h"

#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(bt_cap_commander, CONFIG_BT_CAP_COMMANDER_LOG_LEVEL);

#include "common/bt_str.h"

int bt_cap_commander_unicast_discover(struct bt_conn *conn)
{
return -ENOSYS;
}

int bt_cap_commander_broadcast_reception_start(
const struct bt_cap_commander_broadcast_reception_start_param *param)
{
return -ENOSYS;
}

int bt_cap_commander_broadcast_reception_stop(
const struct bt_cap_commander_broadcast_reception_stop_param *param)
{
return -ENOSYS;
}

int bt_cap_commander_change_volume(const struct bt_cap_commander_change_volume_param *param)
{
return -ENOSYS;
}

int bt_cap_commander_change_volume_offset(
const struct bt_cap_commander_change_volume_offset_param *param)
{
return -ENOSYS;
}

int bt_cap_commander_change_volume_mute_state(
const struct bt_cap_commander_change_volume_mute_state_param *param)
{
return -ENOSYS;
}

int bt_cap_commander_change_microphone_mute_state(
const struct bt_cap_commander_change_microphone_mute_state_param *param)
{
return -ENOSYS;
}

int bt_cap_commander_change_microphone_gain_setting(
const struct bt_cap_commander_change_microphone_gain_setting_param *param)
{

return -ENOSYS;
}
2 changes: 2 additions & 0 deletions tests/bluetooth/shell/audio.conf
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ CONFIG_BT_HAS_PRESET_CONTROL_POINT_NOTIFIABLE=y
CONFIG_BT_CAP_ACCEPTOR=y
CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER=y
CONFIG_BT_CAP_INITIATOR=y
CONFIG_BT_CAP_COMMANDER=y

# Telephone and Media Audio Profile
CONFIG_BT_TMAP=y
Expand Down Expand Up @@ -201,4 +202,5 @@ CONFIG_BT_CSIP_SET_COORDINATOR_LOG_LEVEL_DBG=y
CONFIG_BT_CSIP_SET_MEMBER_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_ACCEPTOR_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_INITIATOR_LOG_LEVEL_DBG=y
CONFIG_BT_CAP_COMMANDER_LOG_LEVEL_DBG=y
CONFIG_BT_TMAP_LOG_LEVEL_DBG=y

0 comments on commit 58bc7c7

Please sign in to comment.