bluetooth: ots: Add object write procedure

Add the ability to perform an OTS Write Procedure with only Patch
support configuration.

Signed-off-by: Abe Kohandel <abe.kohandel@gmail.com>
This commit is contained in:
Abe Kohandel 2021-07-31 17:03:03 -07:00 committed by Christopher Friedt
commit 997bbcb000
10 changed files with 400 additions and 21 deletions

View file

@ -36,8 +36,23 @@ LOG_MODULE_REGISTER(bt_ots, CONFIG_BT_OTS_LOG_LEVEL);
#define OACP_FEAT_BIT_READ 0
#endif
#if defined(CONFIG_BT_OTS_OACP_WRITE_SUPPORT)
#define OACP_FEAT_BIT_WRITE BIT(BT_OTS_OACP_FEAT_WRITE)
#else
#define OACP_FEAT_BIT_WRITE 0
#endif
#if defined(CONFIG_BT_OTS_OACP_PATCH_SUPPORT)
#define OACP_FEAT_BIT_PATCH BIT(BT_OTS_OACP_FEAT_PATCH)
#else
#define OACP_FEAT_BIT_PATCH 0
#endif
/* OACP features supported by Kconfig */
#define OACP_FEAT OACP_FEAT_BIT_READ
#define OACP_FEAT ( \
OACP_FEAT_BIT_READ | \
OACP_FEAT_BIT_WRITE | \
OACP_FEAT_BIT_PATCH)
#if defined(CONFIG_BT_OTS_OLCP_GO_TO_SUPPORT)
#define OLCP_FEAT_BIT_GOTO BIT(BT_OTS_OLCP_FEAT_GO_TO)
@ -48,6 +63,39 @@ LOG_MODULE_REGISTER(bt_ots, CONFIG_BT_OTS_LOG_LEVEL);
/* OLCP features supported by Kconfig */
#define OLCP_FEAT OLCP_FEAT_BIT_GOTO
static bool ots_obj_validate_prop_against_oacp(uint32_t prop, uint32_t oacp)
{
if (BT_OTS_OBJ_GET_PROP_DELETE(prop) > 0 && BT_OTS_OACP_GET_FEAT_DELETE(oacp) == 0) {
return false;
}
if (BT_OTS_OBJ_GET_PROP_EXECUTE(prop) > 0 && BT_OTS_OACP_GET_FEAT_EXECUTE(oacp) == 0) {
return false;
}
if (BT_OTS_OBJ_GET_PROP_READ(prop) > 0 && BT_OTS_OACP_GET_FEAT_READ(oacp) == 0) {
return false;
}
if (BT_OTS_OBJ_GET_PROP_WRITE(prop) > 0 && BT_OTS_OACP_GET_FEAT_WRITE(oacp) == 0) {
return false;
}
if (BT_OTS_OBJ_GET_PROP_APPEND(prop) > 0 && BT_OTS_OACP_GET_FEAT_APPEND(oacp) == 0) {
return false;
}
if (BT_OTS_OBJ_GET_PROP_TRUNCATE(prop) > 0 && BT_OTS_OACP_GET_FEAT_TRUNCATE(oacp) == 0) {
return false;
}
if (BT_OTS_OBJ_GET_PROP_PATCH(prop) > 0 && BT_OTS_OACP_GET_FEAT_PATCH(oacp) == 0) {
return false;
}
return true;
}
static ssize_t ots_feature_read(struct bt_conn *conn,
const struct bt_gatt_attr *attr, void *buf,
uint16_t len, uint16_t offset)
@ -243,6 +291,12 @@ int bt_ots_obj_add(struct bt_ots *ots,
return -EINVAL;
}
CHECKIF(!ots_obj_validate_prop_against_oacp(obj_init->props, ots->features.oacp)) {
LOG_DBG("Object properties (0x%04X) are not a subset of OACP (0x%04X)",
obj_init->props, ots->features.oacp);
return -ENOTSUP;
}
err = bt_gatt_ots_obj_manager_obj_add(ots->obj_manager, &obj);
if (err) {
LOG_ERR("No space available in the object manager");
@ -334,6 +388,9 @@ int bt_ots_init(struct bt_ots *ots,
__ASSERT(ots_init->cb->obj_read ||
!BT_OTS_OACP_GET_FEAT_READ(ots_init->features.oacp),
"Callback for object reading is not set");
__ASSERT(ots_init->cb->obj_write ||
!BT_OTS_OACP_GET_FEAT_WRITE(ots_init->features.oacp),
"Callback for object write is not set");
/* Set callback structure. */
ots->cb = ots_init->cb;