Bluetooth: Mesh: Add a flag for DevKey-only based models

This prevents a Configuration Client from binding an app key to a model
that only supports DevKey-based security.

Signed-off-by: Michał Narajowski <michal.narajowski@codecoup.pl>
This commit is contained in:
Michał Narajowski 2021-01-21 14:47:19 +01:00 committed by Carles Cufí
commit 08f0d1c742
4 changed files with 15 additions and 11 deletions

View file

@ -29,14 +29,6 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_mesh_access);
/* bt_mesh_model.flags */
enum {
BT_MESH_MOD_BIND_PENDING = BIT(0),
BT_MESH_MOD_SUB_PENDING = BIT(1),
BT_MESH_MOD_PUB_PENDING = BIT(2),
BT_MESH_MOD_EXTENDED = BIT(3),
};
/* Model publication information for persistent storage. */
struct mod_pub_val {
uint16_t addr;

View file

@ -10,6 +10,15 @@ enum bt_mesh_walk {
BT_MESH_WALK_CONTINUE,
};
/* bt_mesh_model.flags */
enum {
BT_MESH_MOD_BIND_PENDING = BIT(0),
BT_MESH_MOD_SUB_PENDING = BIT(1),
BT_MESH_MOD_PUB_PENDING = BIT(2),
BT_MESH_MOD_EXTENDED = BIT(3),
BT_MESH_MOD_DEVKEY_ONLY = BIT(4),
};
void bt_mesh_elem_register(struct bt_mesh_elem *elem, uint8_t count);
uint8_t bt_mesh_elem_count(void);

View file

@ -19,6 +19,7 @@
#include "common/bt_str.h"
#include "access.h"
#include "net.h"
#include "foundation.h"
#include "msg.h"
@ -996,6 +997,7 @@ static int cfg_cli_init(struct bt_mesh_model *model)
* and remote keys are allowed to access this model.
*/
model->keys[0] = BT_MESH_KEY_DEV_ANY;
model->flags |= BT_MESH_MOD_DEVKEY_ONLY;
bt_mesh_msg_ack_ctx_init(&cli->ack_ctx);

View file

@ -1893,9 +1893,9 @@ static int mod_app_bind(struct bt_mesh_model *model,
goto send_status;
}
/* Configuration Server only allows device key based access */
if (model == mod) {
LOG_ERR("Client tried to bind AppKey to Configuration Model");
/* Some models only allow device key based access */
if (mod->flags & BT_MESH_MOD_DEVKEY_ONLY) {
LOG_ERR("Client tried to bind AppKey to DevKey based model");
status = STATUS_CANNOT_BIND;
goto send_status;
}
@ -2535,6 +2535,7 @@ static int cfg_srv_init(struct bt_mesh_model *model)
* device-key is allowed to access this model.
*/
model->keys[0] = BT_MESH_KEY_DEV_LOCAL;
model->flags |= BT_MESH_MOD_DEVKEY_ONLY;
return 0;
}