Skip to content

Commit 06fa287

Browse files
0bijian0nashif
authored andcommitted
Bluetooth: Audio: Update audio location definitions
The meaning of bit0 in the audio location bitmap will change to mono audio, so we update the audio location macro and releated test cases. Refer to BT SIG ES-22266. Signed-off-by: Bi Jian <[email protected]>
1 parent dc9d5d9 commit 06fa287

File tree

7 files changed

+32
-53
lines changed

7 files changed

+32
-53
lines changed

include/zephyr/bluetooth/audio/audio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ enum bt_audio_metadata_type {
245245
* These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
246246
*/
247247
enum bt_audio_location {
248-
BT_AUDIO_LOCATION_PROHIBITED = 0,
248+
BT_AUDIO_LOCATION_MONO_AUDIO = 0,
249249
BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0),
250250
BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1),
251251
BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2),

subsys/bluetooth/audio/pacs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static ssize_t snk_loc_write(struct bt_conn *conn,
405405
}
406406

407407
location = (enum bt_audio_location)sys_get_le32(data);
408-
if (location > BT_AUDIO_LOCATION_MASK || location == 0) {
408+
if (location > BT_AUDIO_LOCATION_MASK) {
409409
LOG_DBG("Invalid location value: 0x%08X", location);
410410
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
411411
}
@@ -510,7 +510,7 @@ static ssize_t src_loc_write(struct bt_conn *conn,
510510
}
511511

512512
location = (enum bt_audio_location)sys_get_le32(data);
513-
if (location > BT_AUDIO_LOCATION_MASK || location == 0) {
513+
if (location > BT_AUDIO_LOCATION_MASK) {
514514
LOG_DBG("Invalid location value: 0x%08X", location);
515515
return BT_GATT_ERR(BT_ATT_ERR_WRITE_REQ_REJECTED);
516516
}

subsys/bluetooth/audio/shell/bap.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[])
993993

994994
static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
995995
{
996-
enum bt_audio_location location = BT_AUDIO_LOCATION_PROHIBITED;
996+
enum bt_audio_location location = BT_AUDIO_LOCATION_MONO_AUDIO;
997997
const struct named_lc3_preset *named_preset;
998998
struct shell_stream *uni_stream;
999999
struct bt_bap_stream *bap_stream;
@@ -1076,8 +1076,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
10761076
return -ENOEXEC;
10771077
}
10781078

1079-
if (loc_bits == BT_AUDIO_LOCATION_PROHIBITED ||
1080-
loc_bits > BT_AUDIO_LOCATION_ANY) {
1079+
if (loc_bits > BT_AUDIO_LOCATION_ANY) {
10811080
shell_error(sh, "Invalid loc_bits: %lu", loc_bits);
10821081

10831082
return -ENOEXEC;
@@ -1109,39 +1108,37 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
11091108
copy_unicast_stream_preset(uni_stream, named_preset);
11101109

11111110
/* If location has been modifed, we update the location in the codec configuration */
1112-
if (location != BT_AUDIO_LOCATION_PROHIBITED) {
1113-
struct bt_audio_codec_cfg *codec_cfg = &uni_stream->codec_cfg;
1114-
1115-
for (size_t i = 0U; i < codec_cfg->data_len;) {
1116-
const uint8_t len = codec_cfg->data[i++];
1117-
uint8_t *value;
1118-
uint8_t data_len;
1119-
uint8_t type;
1120-
1121-
if (len == 0 || len > codec_cfg->data_len - i) {
1122-
/* Invalid len field */
1123-
return false;
1124-
}
1111+
struct bt_audio_codec_cfg *codec_cfg = &uni_stream->codec_cfg;
11251112

1126-
type = codec_cfg->data[i++];
1127-
value = &codec_cfg->data[i];
1113+
for (size_t i = 0U; i < codec_cfg->data_len;) {
1114+
const uint8_t len = codec_cfg->data[i++];
1115+
uint8_t *value;
1116+
uint8_t data_len;
1117+
uint8_t type;
11281118

1129-
if (type == BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC) {
1130-
const uint32_t loc_32 = location;
1119+
if (len == 0 || len > codec_cfg->data_len - i) {
1120+
/* Invalid len field */
1121+
return false;
1122+
}
11311123

1132-
sys_put_le32(loc_32, value);
1124+
type = codec_cfg->data[i++];
1125+
value = &codec_cfg->data[i];
11331126

1134-
shell_print(sh, "Setting location to 0x%08X", location);
1135-
break;
1136-
}
1127+
if (type == BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC) {
1128+
const uint32_t loc_32 = location;
11371129

1138-
data_len = len - sizeof(type);
1130+
sys_put_le32(loc_32, value);
11391131

1140-
/* Since we are incrementing i by the value_len, we don't need to increment
1141-
* it further in the `for` statement
1142-
*/
1143-
i += data_len;
1132+
shell_print(sh, "Setting location to 0x%08X", location);
1133+
break;
11441134
}
1135+
1136+
data_len = len - sizeof(type);
1137+
1138+
/* Since we are incrementing i by the value_len, we don't need to increment
1139+
* it further in the `for` statement
1140+
*/
1141+
i += data_len;
11451142
}
11461143

11471144
if (bap_stream->ep == ep) {
@@ -2347,8 +2344,7 @@ static int cmd_set_loc(const struct shell *sh, size_t argc, char *argv[])
23472344
return -ENOEXEC;
23482345
}
23492346

2350-
if (loc_val == BT_AUDIO_LOCATION_PROHIBITED ||
2351-
loc_val > BT_AUDIO_LOCATION_ANY) {
2347+
if (loc_val > BT_AUDIO_LOCATION_ANY) {
23522348
shell_error(sh, "Invalid location: %lu", loc_val);
23532349

23542350
return -ENOEXEC;

subsys/bluetooth/audio/vocs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a
134134
}
135135

136136
new_location = sys_get_le32(buf);
137-
if (new_location == BT_AUDIO_LOCATION_PROHIBITED ||
138-
(new_location & BT_AUDIO_LOCATION_RFU) > 0) {
137+
if ((new_location & BT_AUDIO_LOCATION_RFU) > 0) {
139138
LOG_DBG("Invalid location %u", new_location);
140139

141140
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);

subsys/bluetooth/audio/vocs_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int bt_vocs_client_location_set(struct bt_vocs_client *inst, uint32_t location)
470470
return -EINVAL;
471471
}
472472

473-
CHECKIF(location == BT_AUDIO_LOCATION_PROHIBITED || location > BT_AUDIO_LOCATION_ANY) {
473+
CHECKIF(location > BT_AUDIO_LOCATION_ANY) {
474474
LOG_DBG("Invalid location 0x%08X", location);
475475
return -EINVAL;
476476
}

tests/bsim/bluetooth/audio/src/vcp_vol_ctlr_test.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -659,14 +659,6 @@ static void test_vocs_location_set(void)
659659
return;
660660
}
661661

662-
invalid_location = BT_AUDIO_LOCATION_PROHIBITED;
663-
664-
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);
665-
if (err == 0) {
666-
FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location);
667-
return;
668-
}
669-
670662
invalid_location = BT_AUDIO_LOCATION_ANY + 1;
671663

672664
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);

tests/bsim/bluetooth/audio/src/vcp_vol_rend_test.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,6 @@ static void test_vocs_location_set(void)
621621
return;
622622
}
623623

624-
invalid_location = BT_AUDIO_LOCATION_PROHIBITED;
625-
626-
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);
627-
if (err == 0) {
628-
FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location);
629-
return;
630-
}
631-
632624
invalid_location = BT_AUDIO_LOCATION_ANY + 1;
633625

634626
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);

0 commit comments

Comments
 (0)