Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: BAP: Broadcast source state checks for ID and BASE #62438

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/zephyr/bluetooth/audio/bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ int bt_bap_broadcast_source_delete(struct bt_bap_broadcast_source *source);
*
* @return Zero on success or (negative) error code otherwise.
*/
int bt_bap_broadcast_source_get_id(const struct bt_bap_broadcast_source *source,
int bt_bap_broadcast_source_get_id(struct bt_bap_broadcast_source *source,
uint32_t *const broadcast_id);

/**
Expand Down
18 changes: 17 additions & 1 deletion subsys/bluetooth/audio/bap_broadcast_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,11 @@ int bt_bap_broadcast_source_delete(struct bt_bap_broadcast_source *source)
return 0;
}

int bt_bap_broadcast_source_get_id(const struct bt_bap_broadcast_source *source,
int bt_bap_broadcast_source_get_id(struct bt_bap_broadcast_source *source,
uint32_t *const broadcast_id)
{
enum bt_bap_ep_state broadcast_state;

CHECKIF(source == NULL) {
LOG_DBG("source is NULL");
return -EINVAL;
Expand All @@ -969,6 +971,12 @@ int bt_bap_broadcast_source_get_id(const struct bt_bap_broadcast_source *source,
return -EINVAL;
}

broadcast_state = broadcast_source_get_state(source);
if (broadcast_state == BT_BAP_EP_STATE_IDLE) {
LOG_DBG("Broadcast source invalid state: %u", broadcast_state);
return -EBADMSG;
}

*broadcast_id = source->broadcast_id;

return 0;
Expand All @@ -977,6 +985,8 @@ int bt_bap_broadcast_source_get_id(const struct bt_bap_broadcast_source *source,
int bt_bap_broadcast_source_get_base(struct bt_bap_broadcast_source *source,
struct net_buf_simple *base_buf)
{
enum bt_bap_ep_state broadcast_state;

CHECKIF(source == NULL) {
LOG_DBG("source is NULL");
return -EINVAL;
Expand All @@ -987,6 +997,12 @@ int bt_bap_broadcast_source_get_base(struct bt_bap_broadcast_source *source,
return -EINVAL;
}

broadcast_state = broadcast_source_get_state(source);
if (broadcast_state == BT_BAP_EP_STATE_IDLE) {
LOG_DBG("Broadcast source invalid state: %u", broadcast_state);
return -EBADMSG;
}

if (!encode_base(source, base_buf)) {
LOG_DBG("base_buf %p with size %u not large enough", base_buf, base_buf->size);

Expand Down
Loading