Skip to content

Commit

Permalink
Bluetooth: Audio: Shell: Fix BIS sync bit field validity check
Browse files Browse the repository at this point in the history
NO PREF (0xFFFFFFFF) and BIT(0) was wrongly rejected.

Signed-off-by: Lars Knudsen <LAKD@demant.com>
  • Loading branch information
larsgk committed Oct 9, 2024
1 parent ad2b1bf commit e60f0d5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
12 changes: 12 additions & 0 deletions include/zephyr/bluetooth/audio/bap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
extern "C" {
#endif

/**
* @brief Check if a BAP BASS BIS_Sync bitfield is valid
*
* Valid options are eiter a bitmask of valid BIS indices, including none (0x00000000)
* or @ref BT_BAP_BIS_SYNC_NO_PREF (0xFFFFFFFF).
*
* @param _bis_bitfield BIS_Sync bitfield (uint32)
*/
#define BT_BAP_BASS_VALID_BIT_BITFIELD(_bis_bitfield) \
((_bis_bitfield) == 0U || (_bis_bitfield) == BT_BAP_BIS_SYNC_NO_PREF || \
BT_ISO_VALID_BIS_BITFIELD(_bis_bitfield))

/**
* @brief Helper to declare elements of bt_bap_qos_cfg
*
Expand Down
3 changes: 0 additions & 3 deletions subsys/bluetooth/audio/shell/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
#define SHELL_PRINT_INDENT_LEVEL_SIZE 2
#define MAX_CODEC_FRAMES_PER_SDU 4U

/* BIS sync is a 32-bit bitfield where BIT(0) is not allowed */
#define VALID_BIS_SYNC(_bis_sync) ((bis_sync & BIT(0)) == 0U && bis_sync < UINT32_MAX)

extern struct bt_csip_set_member_svc_inst *svc_inst;

ssize_t audio_ad_data_add(struct bt_data *data, const size_t data_size, const bool discoverable,
Expand Down
8 changes: 4 additions & 4 deletions subsys/bluetooth/audio/shell/bap_broadcast_assistant.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ static int cmd_bap_broadcast_assistant_add_src(const struct shell *sh,
return -ENOEXEC;
}

if (!VALID_BIS_SYNC(bis_sync)) {
if (!BT_BAP_BASS_VALID_BIT_BITFIELD(bis_sync)) {
shell_error(sh, "Invalid bis_sync: %lu", bis_sync);

return -ENOEXEC;
Expand Down Expand Up @@ -667,7 +667,7 @@ static int cmd_bap_broadcast_assistant_add_broadcast_id(const struct shell *sh,
shell_error(sh, "failed to parse bis_sync: %d", err);

return -ENOEXEC;
} else if (!VALID_BIS_SYNC(bis_sync)) {
} else if (!BT_BAP_BASS_VALID_BIT_BITFIELD(bis_sync)) {
shell_error(sh, "Invalid bis_sync: %lu", bis_sync);

return -ENOEXEC;
Expand Down Expand Up @@ -735,7 +735,7 @@ static int cmd_bap_broadcast_assistant_add_broadcast_name(const struct shell *sh
shell_error(sh, "failed to parse bis_sync: %d", err);

return -ENOEXEC;
} else if (!VALID_BIS_SYNC(bis_sync)) {
} else if (!BT_BAP_BASS_VALID_BIT_BITFIELD(bis_sync)) {
shell_error(sh, "Invalid bis_sync: %lu", bis_sync);

return -ENOEXEC;
Expand Down Expand Up @@ -836,7 +836,7 @@ static int cmd_bap_broadcast_assistant_mod_src(const struct shell *sh,
return -ENOEXEC;
}

if (!VALID_BIS_SYNC(bis_sync)) {
if (!BT_BAP_BASS_VALID_BIT_BITFIELD(bis_sync)) {
shell_error(sh, "Invalid bis_sync: %lu", bis_sync);

return -ENOEXEC;
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/audio/shell/cap_commander.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ static int cmd_cap_commander_broadcast_reception_start(const struct shell *sh, s
return -ENOEXEC;
}

if (!VALID_BIS_SYNC(bis_sync)) {
if (!BT_BAP_BASS_VALID_BIT_BITFIELD(bis_sync)) {
shell_error(sh, "Invalid bis_sync: %lu", bis_sync);

return -ENOEXEC;
Expand Down

0 comments on commit e60f0d5

Please sign in to comment.