Bluetooth: BAP: Broadcast source state checks for ID and BASE
Add state checks for the get_id and get_base functions, as the ID and base are not valid when the state of the broadcast source is BT_BAP_EP_STATE_IDLE. Since the broadcast_source_get_state uses the slist functions, the broadcast source object for bt_bap_broadcast_source_get_id can no longer be `const`. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
994558ef8e
commit
9d62bef3ac
2 changed files with 18 additions and 2 deletions
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue