Skip to content

Commit 6ca4ea1

Browse files
llyespressif-bot
authored andcommitted
ble_mesh: stack: Update some fast prov functions
1 parent 64e76ee commit 6ca4ea1

File tree

4 files changed

+25
-41
lines changed

4 files changed

+25
-41
lines changed

components/bt/esp_ble_mesh/mesh_core/fast_prov.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,20 @@ struct bt_mesh_app_key *bt_mesh_fast_prov_app_key_find(u16_t app_idx)
9292

9393
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx)
9494
{
95-
struct bt_mesh_subnet_keys *key = NULL;
96-
struct bt_mesh_subnet *sub = NULL;
95+
/* Set net_idx for fast provisioning */
96+
bt_mesh_provisioner_set_fast_prov_net_idx(net_idx);
9797

98-
sub = bt_mesh_fast_prov_subnet_get(net_idx);
99-
if (sub) {
100-
key = BLE_MESH_KEY_REFRESH(sub->kr_flag) ? &sub->keys[1] : &sub->keys[0];
101-
return bt_mesh_provisioner_set_fast_prov_net_idx(key->net, net_idx);
98+
if (bt_mesh_fast_prov_subnet_get(net_idx) == NULL) {
99+
/* If NetKey is not found, wait for NetKey to be added. */
100+
BT_WARN("Wait for NetKey for fast provisioning");
101+
return 0x01; /*status: Wait for NetKey */
102102
}
103103

104-
/* If NetKey is not found, set net_idx for fast provisioning,
105-
* and wait for Primary Provisioner to add NetKey.
106-
*/
107-
return bt_mesh_provisioner_set_fast_prov_net_idx(NULL, net_idx);
104+
return 0x0; /* status: Succeed */
108105
}
109106

110-
u8_t bt_mesh_add_fast_prov_net_key(const u8_t net_key[16])
107+
u8_t bt_mesh_fast_prov_net_key_add(const u8_t net_key[16])
111108
{
112-
const u8_t *keys = NULL;
113109
u16_t net_idx = 0U;
114110
int err = 0;
115111

@@ -118,18 +114,15 @@ u8_t bt_mesh_add_fast_prov_net_key(const u8_t net_key[16])
118114

119115
err = bt_mesh_provisioner_local_net_key_add(net_key, &net_idx);
120116
if (err) {
121-
return 0x01; /* status: add net_key fail */
117+
BT_ERR("%s, Failed to add NetKey 0x%04x", __func__, net_idx);
118+
return 0x01; /* status: Add NetKey failed */
122119
};
123120

124-
keys = bt_mesh_provisioner_local_net_key_get(net_idx);
125-
if (!keys) {
126-
return 0x01; /* status: add net_key fail */
127-
}
128-
129-
return bt_mesh_provisioner_set_fast_prov_net_idx(keys, net_idx);
121+
bt_mesh_provisioner_set_fast_prov_net_idx(net_idx);
122+
return 0x0; /* status: Succeed */
130123
}
131124

132-
const u8_t *bt_mesh_get_fast_prov_net_key(u16_t net_idx)
125+
const u8_t *bt_mesh_fast_prov_net_key_get(u16_t net_idx)
133126
{
134127
struct bt_mesh_subnet *sub = NULL;
135128

components/bt/esp_ble_mesh/mesh_core/fast_prov.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ struct bt_mesh_app_key *bt_mesh_fast_prov_app_key_find(u16_t app_idx);
2929

3030
u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx);
3131

32-
u8_t bt_mesh_add_fast_prov_net_key(const u8_t net_key[16]);
32+
u8_t bt_mesh_fast_prov_net_key_add(const u8_t net_key[16]);
3333

34-
const u8_t *bt_mesh_get_fast_prov_net_key(u16_t net_idx);
34+
const u8_t *bt_mesh_fast_prov_net_key_get(u16_t net_idx);
3535

3636
const u8_t *bt_mesh_get_fast_prov_app_key(u16_t net_idx, u16_t app_idx);
3737

components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "mesh.h"
2121
#include "access.h"
2222
#include "settings.h"
23+
#include "fast_prov.h"
2324
#include "mesh_common.h"
2425
#include "proxy_client.h"
2526
#include "provisioner_prov.h"
@@ -276,7 +277,6 @@ struct bt_mesh_prov_ctx {
276277
struct {
277278
bool enable;
278279
u16_t net_idx;
279-
const u8_t *net_key;
280280
u8_t flags;
281281
u32_t iv_index;
282282
u16_t unicast_addr_min;
@@ -1280,17 +1280,9 @@ void bt_mesh_provisioner_fast_prov_enable(bool enable)
12801280
prov_ctx.fast_prov.enable = enable;
12811281
}
12821282

1283-
u8_t bt_mesh_provisioner_set_fast_prov_net_idx(const u8_t *net_key, u16_t net_idx)
1283+
void bt_mesh_provisioner_set_fast_prov_net_idx(u16_t net_idx)
12841284
{
12851285
prov_ctx.fast_prov.net_idx = net_idx;
1286-
prov_ctx.fast_prov.net_key = net_key;
1287-
1288-
if (!net_key) {
1289-
BT_WARN("Wait for NetKey for fast provisioning");
1290-
return 0x01; /*status: wait for net_key */
1291-
}
1292-
1293-
return 0x0; /* status: success */
12941286
}
12951287

12961288
u16_t bt_mesh_provisioner_get_fast_prov_net_idx(void)
@@ -2456,10 +2448,10 @@ static void send_prov_data(const u8_t idx)
24562448
* will be added to the primary subnet, and may add an API to choose to which
24572449
* subnet will the device be provisioned later.
24582450
*/
2459-
if (FAST_PROV_ENABLE()) {
2460-
netkey = prov_ctx.fast_prov.net_key;
2451+
if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
2452+
netkey = bt_mesh_fast_prov_net_key_get(prov_ctx.fast_prov.net_idx);
24612453
if (!netkey) {
2462-
BT_ERR("%s, Failed to get NetKey for fast provisioning", __func__);
2454+
BT_ERR("No NetKey for fast provisioning");
24632455
goto fail;
24642456
}
24652457
memcpy(pdu, netkey, 16);
@@ -2469,7 +2461,7 @@ static void send_prov_data(const u8_t idx)
24692461
} else {
24702462
netkey = bt_mesh_provisioner_net_key_get(prov_ctx.curr_net_idx);
24712463
if (!netkey) {
2472-
BT_ERR("%s, Failed to get NetKey for provisioning data", __func__);
2464+
BT_ERR("No NetKey for provisioning data");
24732465
goto fail;
24742466
}
24752467
memcpy(pdu, netkey, 16);
@@ -2580,7 +2572,7 @@ static void send_prov_data(const u8_t idx)
25802572
}
25812573
}
25822574

2583-
if (FAST_PROV_ENABLE()) {
2575+
if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
25842576
link[idx].ki_flags = prov_ctx.fast_prov.flags;
25852577
link[idx].iv_index = prov_ctx.fast_prov.iv_index;
25862578
} else {
@@ -2668,7 +2660,7 @@ static void prov_complete(const u8_t idx, const u8_t *data)
26682660
return;
26692661
}
26702662

2671-
if (FAST_PROV_ENABLE()) {
2663+
if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
26722664
net_idx = prov_ctx.fast_prov.net_idx;
26732665
} else {
26742666
net_idx = prov_ctx.curr_net_idx;

components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,11 @@ void bt_mesh_provisioner_fast_prov_enable(bool enable);
386386
/**
387387
* @brief This function is called to set netkey index used for fast provisioning.
388388
*
389-
* @param[in] net_key: Netkey value
390389
* @param[in] net_idx: Netkey index
391390
*
392-
* @return status for set netkey index msg
391+
* @return None
393392
*/
394-
u8_t bt_mesh_provisioner_set_fast_prov_net_idx(const u8_t *net_key, u16_t net_idx);
393+
void bt_mesh_provisioner_set_fast_prov_net_idx(u16_t net_idx);
395394

396395
/**
397396
* @brief This function is called to get netkey index used for fast provisioning.

0 commit comments

Comments
 (0)