ble_mesh: stack: Update some fast prov functions
This commit is contained in:
parent
64e76ee019
commit
6ca4ea1a1f
4 changed files with 25 additions and 41 deletions
|
@ -92,24 +92,20 @@ struct bt_mesh_app_key *bt_mesh_fast_prov_app_key_find(u16_t app_idx)
|
||||||
|
|
||||||
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx)
|
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx)
|
||||||
{
|
{
|
||||||
struct bt_mesh_subnet_keys *key = NULL;
|
/* Set net_idx for fast provisioning */
|
||||||
struct bt_mesh_subnet *sub = NULL;
|
bt_mesh_provisioner_set_fast_prov_net_idx(net_idx);
|
||||||
|
|
||||||
sub = bt_mesh_fast_prov_subnet_get(net_idx);
|
if (bt_mesh_fast_prov_subnet_get(net_idx) == NULL) {
|
||||||
if (sub) {
|
/* If NetKey is not found, wait for NetKey to be added. */
|
||||||
key = BLE_MESH_KEY_REFRESH(sub->kr_flag) ? &sub->keys[1] : &sub->keys[0];
|
BT_WARN("Wait for NetKey for fast provisioning");
|
||||||
return bt_mesh_provisioner_set_fast_prov_net_idx(key->net, net_idx);
|
return 0x01; /*status: Wait for NetKey */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If NetKey is not found, set net_idx for fast provisioning,
|
return 0x0; /* status: Succeed */
|
||||||
* and wait for Primary Provisioner to add NetKey.
|
|
||||||
*/
|
|
||||||
return bt_mesh_provisioner_set_fast_prov_net_idx(NULL, net_idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u8_t bt_mesh_add_fast_prov_net_key(const u8_t net_key[16])
|
u8_t bt_mesh_fast_prov_net_key_add(const u8_t net_key[16])
|
||||||
{
|
{
|
||||||
const u8_t *keys = NULL;
|
|
||||||
u16_t net_idx = 0U;
|
u16_t net_idx = 0U;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
@ -118,18 +114,15 @@ u8_t bt_mesh_add_fast_prov_net_key(const u8_t net_key[16])
|
||||||
|
|
||||||
err = bt_mesh_provisioner_local_net_key_add(net_key, &net_idx);
|
err = bt_mesh_provisioner_local_net_key_add(net_key, &net_idx);
|
||||||
if (err) {
|
if (err) {
|
||||||
return 0x01; /* status: add net_key fail */
|
BT_ERR("%s, Failed to add NetKey 0x%04x", __func__, net_idx);
|
||||||
|
return 0x01; /* status: Add NetKey failed */
|
||||||
};
|
};
|
||||||
|
|
||||||
keys = bt_mesh_provisioner_local_net_key_get(net_idx);
|
bt_mesh_provisioner_set_fast_prov_net_idx(net_idx);
|
||||||
if (!keys) {
|
return 0x0; /* status: Succeed */
|
||||||
return 0x01; /* status: add net_key fail */
|
|
||||||
}
|
|
||||||
|
|
||||||
return bt_mesh_provisioner_set_fast_prov_net_idx(keys, net_idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const u8_t *bt_mesh_get_fast_prov_net_key(u16_t net_idx)
|
const u8_t *bt_mesh_fast_prov_net_key_get(u16_t net_idx)
|
||||||
{
|
{
|
||||||
struct bt_mesh_subnet *sub = NULL;
|
struct bt_mesh_subnet *sub = NULL;
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ struct bt_mesh_app_key *bt_mesh_fast_prov_app_key_find(u16_t app_idx);
|
||||||
|
|
||||||
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx);
|
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx);
|
||||||
|
|
||||||
u8_t bt_mesh_add_fast_prov_net_key(const u8_t net_key[16]);
|
u8_t bt_mesh_fast_prov_net_key_add(const u8_t net_key[16]);
|
||||||
|
|
||||||
const u8_t *bt_mesh_get_fast_prov_net_key(u16_t net_idx);
|
const u8_t *bt_mesh_fast_prov_net_key_get(u16_t net_idx);
|
||||||
|
|
||||||
const u8_t *bt_mesh_get_fast_prov_app_key(u16_t net_idx, u16_t app_idx);
|
const u8_t *bt_mesh_get_fast_prov_app_key(u16_t net_idx, u16_t app_idx);
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "access.h"
|
#include "access.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include "fast_prov.h"
|
||||||
#include "mesh_common.h"
|
#include "mesh_common.h"
|
||||||
#include "proxy_client.h"
|
#include "proxy_client.h"
|
||||||
#include "provisioner_prov.h"
|
#include "provisioner_prov.h"
|
||||||
|
@ -276,7 +277,6 @@ struct bt_mesh_prov_ctx {
|
||||||
struct {
|
struct {
|
||||||
bool enable;
|
bool enable;
|
||||||
u16_t net_idx;
|
u16_t net_idx;
|
||||||
const u8_t *net_key;
|
|
||||||
u8_t flags;
|
u8_t flags;
|
||||||
u32_t iv_index;
|
u32_t iv_index;
|
||||||
u16_t unicast_addr_min;
|
u16_t unicast_addr_min;
|
||||||
|
@ -1280,17 +1280,9 @@ void bt_mesh_provisioner_fast_prov_enable(bool enable)
|
||||||
prov_ctx.fast_prov.enable = enable;
|
prov_ctx.fast_prov.enable = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8_t bt_mesh_provisioner_set_fast_prov_net_idx(const u8_t *net_key, u16_t net_idx)
|
void bt_mesh_provisioner_set_fast_prov_net_idx(u16_t net_idx)
|
||||||
{
|
{
|
||||||
prov_ctx.fast_prov.net_idx = net_idx;
|
prov_ctx.fast_prov.net_idx = net_idx;
|
||||||
prov_ctx.fast_prov.net_key = net_key;
|
|
||||||
|
|
||||||
if (!net_key) {
|
|
||||||
BT_WARN("Wait for NetKey for fast provisioning");
|
|
||||||
return 0x01; /*status: wait for net_key */
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0x0; /* status: success */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u16_t bt_mesh_provisioner_get_fast_prov_net_idx(void)
|
u16_t bt_mesh_provisioner_get_fast_prov_net_idx(void)
|
||||||
|
@ -2456,10 +2448,10 @@ static void send_prov_data(const u8_t idx)
|
||||||
* will be added to the primary subnet, and may add an API to choose to which
|
* will be added to the primary subnet, and may add an API to choose to which
|
||||||
* subnet will the device be provisioned later.
|
* subnet will the device be provisioned later.
|
||||||
*/
|
*/
|
||||||
if (FAST_PROV_ENABLE()) {
|
if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
|
||||||
netkey = prov_ctx.fast_prov.net_key;
|
netkey = bt_mesh_fast_prov_net_key_get(prov_ctx.fast_prov.net_idx);
|
||||||
if (!netkey) {
|
if (!netkey) {
|
||||||
BT_ERR("%s, Failed to get NetKey for fast provisioning", __func__);
|
BT_ERR("No NetKey for fast provisioning");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
memcpy(pdu, netkey, 16);
|
memcpy(pdu, netkey, 16);
|
||||||
|
@ -2469,7 +2461,7 @@ static void send_prov_data(const u8_t idx)
|
||||||
} else {
|
} else {
|
||||||
netkey = bt_mesh_provisioner_net_key_get(prov_ctx.curr_net_idx);
|
netkey = bt_mesh_provisioner_net_key_get(prov_ctx.curr_net_idx);
|
||||||
if (!netkey) {
|
if (!netkey) {
|
||||||
BT_ERR("%s, Failed to get NetKey for provisioning data", __func__);
|
BT_ERR("No NetKey for provisioning data");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
memcpy(pdu, netkey, 16);
|
memcpy(pdu, netkey, 16);
|
||||||
|
@ -2580,7 +2572,7 @@ static void send_prov_data(const u8_t idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAST_PROV_ENABLE()) {
|
if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
|
||||||
link[idx].ki_flags = prov_ctx.fast_prov.flags;
|
link[idx].ki_flags = prov_ctx.fast_prov.flags;
|
||||||
link[idx].iv_index = prov_ctx.fast_prov.iv_index;
|
link[idx].iv_index = prov_ctx.fast_prov.iv_index;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2668,7 +2660,7 @@ static void prov_complete(const u8_t idx, const u8_t *data)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FAST_PROV_ENABLE()) {
|
if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
|
||||||
net_idx = prov_ctx.fast_prov.net_idx;
|
net_idx = prov_ctx.fast_prov.net_idx;
|
||||||
} else {
|
} else {
|
||||||
net_idx = prov_ctx.curr_net_idx;
|
net_idx = prov_ctx.curr_net_idx;
|
||||||
|
|
|
@ -386,12 +386,11 @@ void bt_mesh_provisioner_fast_prov_enable(bool enable);
|
||||||
/**
|
/**
|
||||||
* @brief This function is called to set netkey index used for fast provisioning.
|
* @brief This function is called to set netkey index used for fast provisioning.
|
||||||
*
|
*
|
||||||
* @param[in] net_key: Netkey value
|
|
||||||
* @param[in] net_idx: Netkey index
|
* @param[in] net_idx: Netkey index
|
||||||
*
|
*
|
||||||
* @return status for set netkey index msg
|
* @return None
|
||||||
*/
|
*/
|
||||||
u8_t bt_mesh_provisioner_set_fast_prov_net_idx(const u8_t *net_key, u16_t net_idx);
|
void bt_mesh_provisioner_set_fast_prov_net_idx(u16_t net_idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is called to get netkey index used for fast provisioning.
|
* @brief This function is called to get netkey index used for fast provisioning.
|
||||||
|
|
Loading…
Reference in a new issue