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:
parent
7f1b296a0c
commit
08f0d1c742
4 changed files with 15 additions and 11 deletions
|
@ -29,14 +29,6 @@
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(bt_mesh_access);
|
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. */
|
/* Model publication information for persistent storage. */
|
||||||
struct mod_pub_val {
|
struct mod_pub_val {
|
||||||
uint16_t addr;
|
uint16_t addr;
|
||||||
|
|
|
@ -10,6 +10,15 @@ enum bt_mesh_walk {
|
||||||
BT_MESH_WALK_CONTINUE,
|
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);
|
void bt_mesh_elem_register(struct bt_mesh_elem *elem, uint8_t count);
|
||||||
|
|
||||||
uint8_t bt_mesh_elem_count(void);
|
uint8_t bt_mesh_elem_count(void);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "common/bt_str.h"
|
#include "common/bt_str.h"
|
||||||
|
|
||||||
|
#include "access.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "foundation.h"
|
#include "foundation.h"
|
||||||
#include "msg.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.
|
* and remote keys are allowed to access this model.
|
||||||
*/
|
*/
|
||||||
model->keys[0] = BT_MESH_KEY_DEV_ANY;
|
model->keys[0] = BT_MESH_KEY_DEV_ANY;
|
||||||
|
model->flags |= BT_MESH_MOD_DEVKEY_ONLY;
|
||||||
|
|
||||||
bt_mesh_msg_ack_ctx_init(&cli->ack_ctx);
|
bt_mesh_msg_ack_ctx_init(&cli->ack_ctx);
|
||||||
|
|
||||||
|
|
|
@ -1893,9 +1893,9 @@ static int mod_app_bind(struct bt_mesh_model *model,
|
||||||
goto send_status;
|
goto send_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Configuration Server only allows device key based access */
|
/* Some models only allow device key based access */
|
||||||
if (model == mod) {
|
if (mod->flags & BT_MESH_MOD_DEVKEY_ONLY) {
|
||||||
LOG_ERR("Client tried to bind AppKey to Configuration Model");
|
LOG_ERR("Client tried to bind AppKey to DevKey based model");
|
||||||
status = STATUS_CANNOT_BIND;
|
status = STATUS_CANNOT_BIND;
|
||||||
goto send_status;
|
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.
|
* device-key is allowed to access this model.
|
||||||
*/
|
*/
|
||||||
model->keys[0] = BT_MESH_KEY_DEV_LOCAL;
|
model->keys[0] = BT_MESH_KEY_DEV_LOCAL;
|
||||||
|
model->flags |= BT_MESH_MOD_DEVKEY_ONLY;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue