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 <bi_jian@qq.com>
This commit is contained in:
Bi Jian 2023-09-29 11:11:34 +08:00 committed by Anas Nashif
commit 06fa287d45
7 changed files with 36 additions and 57 deletions

View file

@ -245,7 +245,7 @@ enum bt_audio_metadata_type {
* These values are defined by the Generic Audio Assigned Numbers, bluetooth.com * These values are defined by the Generic Audio Assigned Numbers, bluetooth.com
*/ */
enum bt_audio_location { enum bt_audio_location {
BT_AUDIO_LOCATION_PROHIBITED = 0, BT_AUDIO_LOCATION_MONO_AUDIO = 0,
BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0), BT_AUDIO_LOCATION_FRONT_LEFT = BIT(0),
BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1), BT_AUDIO_LOCATION_FRONT_RIGHT = BIT(1),
BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2), BT_AUDIO_LOCATION_FRONT_CENTER = BIT(2),

View file

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

View file

@ -993,7 +993,7 @@ static int cmd_discover(const struct shell *sh, size_t argc, char *argv[])
static int cmd_config(const struct shell *sh, size_t argc, char *argv[]) static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
{ {
enum bt_audio_location location = BT_AUDIO_LOCATION_PROHIBITED; enum bt_audio_location location = BT_AUDIO_LOCATION_MONO_AUDIO;
const struct named_lc3_preset *named_preset; const struct named_lc3_preset *named_preset;
struct shell_stream *uni_stream; struct shell_stream *uni_stream;
struct bt_bap_stream *bap_stream; struct bt_bap_stream *bap_stream;
@ -1076,8 +1076,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
return -ENOEXEC; return -ENOEXEC;
} }
if (loc_bits == BT_AUDIO_LOCATION_PROHIBITED || if (loc_bits > BT_AUDIO_LOCATION_ANY) {
loc_bits > BT_AUDIO_LOCATION_ANY) {
shell_error(sh, "Invalid loc_bits: %lu", loc_bits); shell_error(sh, "Invalid loc_bits: %lu", loc_bits);
return -ENOEXEC; return -ENOEXEC;
@ -1109,39 +1108,37 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
copy_unicast_stream_preset(uni_stream, named_preset); copy_unicast_stream_preset(uni_stream, named_preset);
/* If location has been modifed, we update the location in the codec configuration */ /* If location has been modifed, we update the location in the codec configuration */
if (location != BT_AUDIO_LOCATION_PROHIBITED) { struct bt_audio_codec_cfg *codec_cfg = &uni_stream->codec_cfg;
struct bt_audio_codec_cfg *codec_cfg = &uni_stream->codec_cfg;
for (size_t i = 0U; i < codec_cfg->data_len;) { for (size_t i = 0U; i < codec_cfg->data_len;) {
const uint8_t len = codec_cfg->data[i++]; const uint8_t len = codec_cfg->data[i++];
uint8_t *value; uint8_t *value;
uint8_t data_len; uint8_t data_len;
uint8_t type; uint8_t type;
if (len == 0 || len > codec_cfg->data_len - i) { if (len == 0 || len > codec_cfg->data_len - i) {
/* Invalid len field */ /* Invalid len field */
return false; return false;
}
type = codec_cfg->data[i++];
value = &codec_cfg->data[i];
if (type == BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC) {
const uint32_t loc_32 = location;
sys_put_le32(loc_32, value);
shell_print(sh, "Setting location to 0x%08X", location);
break;
}
data_len = len - sizeof(type);
/* Since we are incrementing i by the value_len, we don't need to increment
* it further in the `for` statement
*/
i += data_len;
} }
type = codec_cfg->data[i++];
value = &codec_cfg->data[i];
if (type == BT_AUDIO_CODEC_CONFIG_LC3_CHAN_ALLOC) {
const uint32_t loc_32 = location;
sys_put_le32(loc_32, value);
shell_print(sh, "Setting location to 0x%08X", location);
break;
}
data_len = len - sizeof(type);
/* Since we are incrementing i by the value_len, we don't need to increment
* it further in the `for` statement
*/
i += data_len;
} }
if (bap_stream->ep == ep) { if (bap_stream->ep == ep) {
@ -2347,8 +2344,7 @@ static int cmd_set_loc(const struct shell *sh, size_t argc, char *argv[])
return -ENOEXEC; return -ENOEXEC;
} }
if (loc_val == BT_AUDIO_LOCATION_PROHIBITED || if (loc_val > BT_AUDIO_LOCATION_ANY) {
loc_val > BT_AUDIO_LOCATION_ANY) {
shell_error(sh, "Invalid location: %lu", loc_val); shell_error(sh, "Invalid location: %lu", loc_val);
return -ENOEXEC; return -ENOEXEC;

View file

@ -134,8 +134,7 @@ static ssize_t write_location(struct bt_conn *conn, const struct bt_gatt_attr *a
} }
new_location = sys_get_le32(buf); new_location = sys_get_le32(buf);
if (new_location == BT_AUDIO_LOCATION_PROHIBITED || if ((new_location & BT_AUDIO_LOCATION_RFU) > 0) {
(new_location & BT_AUDIO_LOCATION_RFU) > 0) {
LOG_DBG("Invalid location %u", new_location); LOG_DBG("Invalid location %u", new_location);
return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED); return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);

View file

@ -470,7 +470,7 @@ int bt_vocs_client_location_set(struct bt_vocs_client *inst, uint32_t location)
return -EINVAL; return -EINVAL;
} }
CHECKIF(location == BT_AUDIO_LOCATION_PROHIBITED || location > BT_AUDIO_LOCATION_ANY) { CHECKIF(location > BT_AUDIO_LOCATION_ANY) {
LOG_DBG("Invalid location 0x%08X", location); LOG_DBG("Invalid location 0x%08X", location);
return -EINVAL; return -EINVAL;
} }

View file

@ -659,14 +659,6 @@ static void test_vocs_location_set(void)
return; return;
} }
invalid_location = BT_AUDIO_LOCATION_PROHIBITED;
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);
if (err == 0) {
FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location);
return;
}
invalid_location = BT_AUDIO_LOCATION_ANY + 1; invalid_location = BT_AUDIO_LOCATION_ANY + 1;
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);

View file

@ -621,14 +621,6 @@ static void test_vocs_location_set(void)
return; return;
} }
invalid_location = BT_AUDIO_LOCATION_PROHIBITED;
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);
if (err == 0) {
FAIL("bt_vocs_location_set with location 0x%08X did not fail", invalid_location);
return;
}
invalid_location = BT_AUDIO_LOCATION_ANY + 1; invalid_location = BT_AUDIO_LOCATION_ANY + 1;
err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location); err = bt_vocs_location_set(vcp_included.vocs[0], invalid_location);