Bluetooth: Audio: Add BT_MCS_VALID_OBJ_ID

Add macro BT_MCS_VALID_OBJ_ID to verify the OTS Object
ID before attempting any OTS operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2023-02-10 13:20:10 +01:00 committed by Carles Cufí
commit 32cd16cfac
3 changed files with 17 additions and 9 deletions

View file

@ -22,6 +22,7 @@
#include <zephyr/bluetooth/services/ots.h> #include <zephyr/bluetooth/services/ots.h>
#include "../services/ots/ots_client_internal.h" #include "../services/ots/ots_client_internal.h"
#include "mcs_internal.h"
/* TODO: Temporarily copied here from media_proxy_internal.h - clean up */ /* TODO: Temporarily copied here from media_proxy_internal.h - clean up */
/* Debug output of 48 bit Object ID value */ /* Debug output of 48 bit Object ID value */
@ -2305,7 +2306,7 @@ int bt_mcc_set_current_track_obj_id(struct bt_conn *conn, uint64_t obj_id)
return -EINVAL; return -EINVAL;
} }
CHECKIF(obj_id < BT_OTS_OBJ_ID_MIN || obj_id > BT_OTS_OBJ_ID_MAX) { CHECKIF(!BT_MCS_VALID_OBJ_ID(obj_id)) {
LOG_DBG("Object ID 0x%016llx invalid", obj_id); LOG_DBG("Object ID 0x%016llx invalid", obj_id);
return -EINVAL; return -EINVAL;
} }
@ -2390,7 +2391,7 @@ int bt_mcc_set_next_track_obj_id(struct bt_conn *conn, uint64_t obj_id)
return -EINVAL; return -EINVAL;
} }
CHECKIF(obj_id < BT_OTS_OBJ_ID_MIN || obj_id > BT_OTS_OBJ_ID_MAX) { CHECKIF(!BT_MCS_VALID_OBJ_ID(obj_id)) {
LOG_DBG("Object ID 0x%016llx invalid", obj_id); LOG_DBG("Object ID 0x%016llx invalid", obj_id);
return -EINVAL; return -EINVAL;
} }
@ -2513,7 +2514,7 @@ int bt_mcc_set_current_group_obj_id(struct bt_conn *conn, uint64_t obj_id)
return -EINVAL; return -EINVAL;
} }
CHECKIF(obj_id < BT_OTS_OBJ_ID_MIN || obj_id > BT_OTS_OBJ_ID_MAX) { CHECKIF(!BT_MCS_VALID_OBJ_ID(obj_id)) {
LOG_DBG("Object ID 0x%016llx invalid", obj_id); LOG_DBG("Object ID 0x%016llx invalid", obj_id);
return -EINVAL; return -EINVAL;
} }

View file

@ -16,6 +16,9 @@
extern "C" { extern "C" {
#endif #endif
/* This differs from BT_OTS_VALID_OBJ_ID as MCS does not use the directory list object */
#define BT_MCS_VALID_OBJ_ID(id) (IN_RANGE((id), BT_OTS_OBJ_ID_MIN, BT_OTS_OBJ_ID_MAX))
int bt_mcs_init(struct bt_ots_cb *ots_cbs); int bt_mcs_init(struct bt_ots_cb *ots_cbs);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -13,6 +13,7 @@
#include <zephyr/bluetooth/audio/mcc.h> #include <zephyr/bluetooth/audio/mcc.h>
#include "media_proxy_internal.h" #include "media_proxy_internal.h"
#include "mcs_internal.h"
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
@ -1159,8 +1160,9 @@ int media_proxy_ctrl_set_current_track_id(struct media_player *player, uint64_t
} }
#if defined(CONFIG_MCTL_LOCAL_PLAYER_LOCAL_CONTROL) #if defined(CONFIG_MCTL_LOCAL_PLAYER_LOCAL_CONTROL)
CHECKIF(id < BT_OTS_OBJ_ID_MIN || id > BT_OTS_OBJ_ID_MAX) { CHECKIF(!BT_MCS_VALID_OBJ_ID(id)) {
LOG_DBG("Object ID invalid"); LOG_DBG("Object ID 0x%016llx invalid", id);
return -EINVAL; return -EINVAL;
} }
@ -1235,8 +1237,9 @@ int media_proxy_ctrl_set_next_track_id(struct media_player *player, uint64_t id)
} }
#if defined(CONFIG_MCTL_LOCAL_PLAYER_LOCAL_CONTROL) #if defined(CONFIG_MCTL_LOCAL_PLAYER_LOCAL_CONTROL)
CHECKIF(id < BT_OTS_OBJ_ID_MIN || id > BT_OTS_OBJ_ID_MAX) { CHECKIF(!BT_MCS_VALID_OBJ_ID(id)) {
LOG_DBG("Object ID invalid"); LOG_DBG("Object ID 0x%016llx invalid", id);
return -EINVAL; return -EINVAL;
} }
@ -1346,8 +1349,9 @@ int media_proxy_ctrl_set_current_group_id(struct media_player *player, uint64_t
} }
#if defined(CONFIG_MCTL_LOCAL_PLAYER_LOCAL_CONTROL) #if defined(CONFIG_MCTL_LOCAL_PLAYER_LOCAL_CONTROL)
CHECKIF(id < BT_OTS_OBJ_ID_MIN || id > BT_OTS_OBJ_ID_MAX) { CHECKIF(!BT_MCS_VALID_OBJ_ID(id)) {
LOG_DBG("Object ID invalid"); LOG_DBG("Object ID 0x%016llx invalid", id);
return -EINVAL; return -EINVAL;
} }