Skip to content

Commit 2455612

Browse files
committed
Bluetooth: CAP: Implement unicast to broadcast handover
Implement the unicast to broadcast handover procedure, as per the Bluetooth CAP specificiation. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent e4c16b5 commit 2455612

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

doc/zephyr.doxyfile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ ALIASES = "kconfig{1}=\c \1" \
286286
"kconfig_dep{1}=\attention Available only when the following Kconfig option is enabled: \kconfig{\1}." \
287287
"kconfig_dep{2}=\attention Available only when the following Kconfig options are enabled: \kconfig{\1}, \kconfig{\2}." \
288288
"kconfig_dep{3}=\attention Available only when the following Kconfig options are enabled: \kconfig{\1}, \kconfig{\2}, \kconfig{\3}." \
289+
"kconfig_dep{4}=\attention Available only when the following Kconfig options are enabled: \kconfig{\1}, \kconfig{\2}, \kconfig{\3}, \kconfig{\4}." \
290+
"kconfig_dep{5}=\attention Available only when the following Kconfig options are enabled: \kconfig{\1}, \kconfig{\2}, \kconfig{\3}, \kconfig{\4}, \kconfig{\5}." \
289291
"funcprops=\par \"Function properties (list may not be complete)\"" \
290292
"reschedule=\qualifier reschedule" \
291293
"sleep=\qualifier sleep" \

include/zephyr/bluetooth/audio/cap.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -639,21 +639,24 @@ int bt_cap_initiator_broadcast_get_base(struct bt_cap_broadcast_source *broadcas
639639

640640
/** Parameters for bt_cap_initiator_unicast_to_broadcast() */
641641
struct bt_cap_unicast_to_broadcast_param {
642+
/** The type of the set. */
643+
enum bt_cap_set_type type;
644+
642645
/** The source unicast group with the streams. */
643646
struct bt_bap_unicast_group *unicast_group;
644647

645648
/**
646649
* @brief Whether or not to encrypt the streams.
647650
*
648-
* If set to true, then the broadcast code in @p broadcast_code
649-
* will be used to encrypt the streams.
651+
* If set to true, then the broadcast code in
652+
* @p bt_cap_unicast_to_broadcast_param.broadcast_code will be used to encrypt the streams.
650653
*/
651654
bool encrypt;
652655

653656
/**
654657
* @brief 16-octet broadcast code.
655658
*
656-
* Only valid if @p encrypt is true.
659+
* Only valid if @p bt_cap_unicast_to_broadcast_param.encrypt is true.
657660
*
658661
* If the value is a string or a the value is less than 16 octets,
659662
* the remaining octets shall be 0.
@@ -671,10 +674,7 @@ struct bt_cap_unicast_to_broadcast_param {
671674
* The streams in the unicast group will be stopped and the unicast group
672675
* will be deleted. This can only be done for source streams.
673676
*
674-
* @note @kconfig{CONFIG_BT_CAP_INITIATOR},
675-
* @kconfig{CONFIG_BT_BAP_UNICAST_CLIENT} and
676-
* @kconfig{CONFIG_BT_BAP_BROADCAST_SOURCE} must be enabled for this function
677-
* to be enabled.
677+
* @kconfig_dep{CONFIG_BT_CAP_INITIATOR,CONFIG_BT_CAP_COMMANDER,CONFIG_BT_BAP_BROADCAST_ASSISTANT,CONFIG_BT_BAP_BROADCAST_SOURCE,CONFIG_BT_BAP_UNICAST_CLIENT}
678678
*
679679
* @param param The parameters for the handover.
680680
* @param source The resulting broadcast source.
@@ -715,10 +715,7 @@ struct bt_cap_broadcast_to_unicast_param {
715715
* The streams in the broadcast source will be stopped and the broadcast source
716716
* will be deleted.
717717
*
718-
* @note @kconfig{CONFIG_BT_CAP_INITIATOR},
719-
* @kconfig{CONFIG_BT_BAP_UNICAST_CLIENT} and
720-
* @kconfig{CONFIG_BT_BAP_BROADCAST_SOURCE} must be enabled for this function
721-
* to be enabled.
718+
* @kconfig_dep{CONFIG_BT_CAP_INITIATOR,CONFIG_BT_BAP_UNICAST_CLIENT,CONFIG_BT_BAP_BROADCAST_SOURCE}
722719
*
723720
* @param[in] param The parameters for the handover.
724721
* @param[out] unicast_group The resulting broadcast source.

subsys/bluetooth/audio/cap_initiator.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,12 +2232,56 @@ void bt_cap_initiator_released(struct bt_cap_stream *cap_stream)
22322232

22332233
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT */
22342234

2235-
#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE) && defined(CONFIG_BT_BAP_UNICAST_CLIENT)
2235+
#if defined(CONFIG_BT_CAP_COMMANDER) && defined(CONFIG_BT_BAP_BROADCAST_SOURCE) && \
2236+
defined(CONFIG_BT_BAP_UNICAST_CLIENT) && defined(CONFIG_BT_BAP_BROADCAST_ASSISTANT)
2237+
2238+
static bool valid_unicast_to_broadcast_param(const struct bt_cap_unicast_to_broadcast_param *param)
2239+
{
2240+
const struct bt_bap_unicast_group *unicast_group;
2241+
2242+
if (param == NULL) {
2243+
LOG_DBG("param is NULL");
2244+
return false;
2245+
}
2246+
2247+
unicast_group = param->unicast_group;
2248+
if (unicast_group == NULL) {
2249+
LOG_DBG("param->unicast_group is NULL");
2250+
return false;
2251+
}
2252+
2253+
if (unicast_group->cig == NULL) {
2254+
LOG_DBG("param->unicast_group is not configured");
2255+
return false;
2256+
}
2257+
2258+
return true;
2259+
}
22362260

22372261
int bt_cap_initiator_unicast_to_broadcast(
22382262
const struct bt_cap_unicast_to_broadcast_param *param,
22392263
struct bt_cap_broadcast_source **source)
22402264
{
2265+
struct bt_cap_unicast_audio_stop_param stop_param = {0};
2266+
int err;
2267+
2268+
if (source == NULL) {
2269+
LOG_DBG("source is NULL");
2270+
return -EINVAL;
2271+
}
2272+
2273+
if (!valid_unicast_to_broadcast_param(param)) {
2274+
return -EINVAL;
2275+
}
2276+
2277+
stop_param.type = param->type;
2278+
stop_param.release = true;
2279+
/* TODO: Populate array of streams
2280+
* Since input is a BAP group, how do we ensure they are CAP streams?
2281+
*/
2282+
2283+
err = bt_cap_initiator_unicast_audio_stop(&stop_param);
2284+
22412285
return -ENOSYS;
22422286
}
22432287

@@ -2247,4 +2291,6 @@ int bt_cap_initiator_broadcast_to_unicast(const struct bt_cap_broadcast_to_unica
22472291
return -ENOSYS;
22482292
}
22492293

2250-
#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE && CONFIG_BT_BAP_UNICAST_CLIENT */
2294+
#endif /* CONFIG_BT_CAP_COMMANDER && CONFIG_BT_BAP_BROADCAST_SOURCE && \
2295+
* CONFIG_BT_BAP_UNICAST_CLIENT && CONFIG_BT_BAP_BROADCAST_ASSISTANT \
2296+
*/

0 commit comments

Comments
 (0)