Bluetooth: Mesh: Increase visibility of net & app key helpers
These app key and net key (subnet) helpers will soon be needed to be called from the persistent storage code. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
10fabcd04f
commit
f7e780a719
5 changed files with 40 additions and 28 deletions
|
@ -23,8 +23,8 @@
|
||||||
#include "../hci_core.h"
|
#include "../hci_core.h"
|
||||||
|
|
||||||
#include "adv.h"
|
#include "adv.h"
|
||||||
#include "foundation.h"
|
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
|
#include "foundation.h"
|
||||||
#include "beacon.h"
|
#include "beacon.h"
|
||||||
#include "prov.h"
|
#include "prov.h"
|
||||||
#include "proxy.h"
|
#include "proxy.h"
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
|
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
|
|
||||||
|
#include "net.h"
|
||||||
#include "foundation.h"
|
#include "foundation.h"
|
||||||
|
|
||||||
#define CID_NVAL 0xffff
|
#define CID_NVAL 0xffff
|
||||||
|
|
|
@ -354,7 +354,7 @@ static u8_t mod_unbind(struct bt_mesh_model *model, u16_t key_idx)
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct bt_mesh_app_key *app_key_alloc(u16_t app_idx)
|
struct bt_mesh_app_key *bt_mesh_app_key_alloc(u16_t app_idx)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ static u8_t app_key_set(u16_t net_idx, u16_t app_idx, const u8_t val[16],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
key = app_key_alloc(app_idx);
|
key = bt_mesh_app_key_alloc(app_idx);
|
||||||
if (!key) {
|
if (!key) {
|
||||||
return STATUS_INSUFF_RESOURCES;
|
return STATUS_INSUFF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
@ -511,7 +511,7 @@ static void _mod_unbind(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
|
||||||
mod_unbind(mod, *key_idx);
|
mod_unbind(mod, *key_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _app_key_del(struct bt_mesh_app_key *key)
|
void bt_mesh_app_key_del(struct bt_mesh_app_key *key)
|
||||||
{
|
{
|
||||||
bt_mesh_model_foreach(_mod_unbind, &key->app_idx);
|
bt_mesh_model_foreach(_mod_unbind, &key->app_idx);
|
||||||
|
|
||||||
|
@ -551,7 +551,7 @@ static void app_key_del(struct bt_mesh_model *model,
|
||||||
goto send_status;
|
goto send_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
_app_key_del(key);
|
bt_mesh_app_key_del(key);
|
||||||
status = STATUS_SUCCESS;
|
status = STATUS_SUCCESS;
|
||||||
|
|
||||||
send_status:
|
send_status:
|
||||||
|
@ -2095,9 +2095,8 @@ static void net_key_del(struct bt_mesh_model *model,
|
||||||
struct bt_mesh_msg_ctx *ctx,
|
struct bt_mesh_msg_ctx *ctx,
|
||||||
struct net_buf_simple *buf)
|
struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
|
||||||
struct bt_mesh_subnet *sub;
|
struct bt_mesh_subnet *sub;
|
||||||
u16_t del_idx, i;
|
u16_t del_idx;
|
||||||
u8_t status;
|
u8_t status;
|
||||||
|
|
||||||
del_idx = net_buf_simple_pull_le16(buf);
|
del_idx = net_buf_simple_pull_le16(buf);
|
||||||
|
@ -2125,26 +2124,7 @@ static void net_key_del(struct bt_mesh_model *model,
|
||||||
goto send_status;
|
goto send_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg->hb_pub.net_idx == del_idx) {
|
bt_mesh_subnet_del(sub);
|
||||||
hb_pub_disable(cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Delete any app keys bound to this NetKey index */
|
|
||||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) {
|
|
||||||
struct bt_mesh_app_key *key = &bt_mesh.app_keys[i];
|
|
||||||
|
|
||||||
if (key->net_idx == del_idx) {
|
|
||||||
_app_key_del(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
|
|
||||||
bt_mesh_friend_clear_net_idx(del_idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(sub, 0, sizeof(*sub));
|
|
||||||
sub->net_idx = BT_MESH_KEY_UNUSED;
|
|
||||||
|
|
||||||
status = STATUS_SUCCESS;
|
status = STATUS_SUCCESS;
|
||||||
|
|
||||||
send_status:
|
send_status:
|
||||||
|
@ -3148,7 +3128,7 @@ void bt_mesh_cfg_reset(void)
|
||||||
struct bt_mesh_app_key *key = &bt_mesh.app_keys[i];
|
struct bt_mesh_app_key *key = &bt_mesh.app_keys[i];
|
||||||
|
|
||||||
if (key->net_idx != BT_MESH_KEY_UNUSED) {
|
if (key->net_idx != BT_MESH_KEY_UNUSED) {
|
||||||
_app_key_del(key);
|
bt_mesh_app_key_del(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3280,3 +3260,28 @@ u8_t *bt_mesh_label_uuid_get(u16_t addr)
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bt_mesh_subnet_del(struct bt_mesh_subnet *sub)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (conf && conf->hb_pub.net_idx == sub->net_idx) {
|
||||||
|
hb_pub_disable(conf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete any app keys bound to this NetKey index */
|
||||||
|
for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) {
|
||||||
|
struct bt_mesh_app_key *key = &bt_mesh.app_keys[i];
|
||||||
|
|
||||||
|
if (key->net_idx == sub->net_idx) {
|
||||||
|
bt_mesh_app_key_del(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
|
||||||
|
bt_mesh_friend_clear_net_idx(sub->net_idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(sub, 0, sizeof(*sub));
|
||||||
|
sub->net_idx = BT_MESH_KEY_UNUSED;
|
||||||
|
}
|
||||||
|
|
|
@ -134,6 +134,11 @@ u8_t bt_mesh_beacon_get(void);
|
||||||
u8_t bt_mesh_gatt_proxy_get(void);
|
u8_t bt_mesh_gatt_proxy_get(void);
|
||||||
u8_t bt_mesh_default_ttl_get(void);
|
u8_t bt_mesh_default_ttl_get(void);
|
||||||
|
|
||||||
|
void bt_mesh_subnet_del(struct bt_mesh_subnet *sub);
|
||||||
|
|
||||||
|
struct bt_mesh_app_key *bt_mesh_app_key_alloc(u16_t app_idx);
|
||||||
|
void bt_mesh_app_key_del(struct bt_mesh_app_key *key);
|
||||||
|
|
||||||
#include <misc/byteorder.h>
|
#include <misc/byteorder.h>
|
||||||
|
|
||||||
static inline void key_idx_pack(struct net_buf_simple *buf,
|
static inline void key_idx_pack(struct net_buf_simple *buf,
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
|
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL)
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
|
|
||||||
|
#include "net.h"
|
||||||
#include "foundation.h"
|
#include "foundation.h"
|
||||||
|
|
||||||
static s32_t msg_timeout = K_SECONDS(2);
|
static s32_t msg_timeout = K_SECONDS(2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue