You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2021/05/27 08:19:48 UTC
[mynewt-nimble] 10/31: mesh: Add CDB handle key refresh phase
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 83cf6da68cb8c49371875cc113d176f9cfe74f89
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Mar 29 12:58:17 2021 +0200
mesh: Add CDB handle key refresh phase
Fixed some undesired or incorrect macros, which
can cause build error.
this is port of 71fd8e1d0141096238aadb9ce20a14781cf50b7c
---
nimble/host/mesh/include/mesh/cdb.h | 1 -
nimble/host/mesh/include/mesh/cfg.h | 6 ++++++
nimble/host/mesh/src/cdb.c | 2 +-
nimble/host/mesh/src/provisioner.c | 2 +-
nimble/host/mesh/src/settings.c | 4 +---
nimble/host/mesh/src/shell.c | 10 +++++-----
nimble/host/mesh/src/testing.c | 4 ----
7 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/nimble/host/mesh/include/mesh/cdb.h b/nimble/host/mesh/include/mesh/cdb.h
index 8f9a6bc..440390c 100644
--- a/nimble/host/mesh/include/mesh/cdb.h
+++ b/nimble/host/mesh/include/mesh/cdb.h
@@ -40,7 +40,6 @@ struct bt_mesh_cdb_node {
struct bt_mesh_cdb_subnet {
uint16_t net_idx;
- bool kr_flag;
uint8_t kr_phase;
struct {
diff --git a/nimble/host/mesh/include/mesh/cfg.h b/nimble/host/mesh/include/mesh/cfg.h
index 378f0a0..6fd6926 100644
--- a/nimble/host/mesh/include/mesh/cfg.h
+++ b/nimble/host/mesh/include/mesh/cfg.h
@@ -35,6 +35,12 @@ enum bt_mesh_feat_state {
BT_MESH_FEATURE_NOT_SUPPORTED,
};
+/* Key Refresh Phase */
+#define BT_MESH_KR_NORMAL 0x00
+#define BT_MESH_KR_PHASE_1 0x01
+#define BT_MESH_KR_PHASE_2 0x02
+#define BT_MESH_KR_PHASE_3 0x03
+
/* Legacy feature defines */
#define BT_MESH_RELAY_DISABLED BT_MESH_FEATURE_DISABLED
#define BT_MESH_RELAY_ENABLED BT_MESH_FEATURE_ENABLED
diff --git a/nimble/host/mesh/src/cdb.c b/nimble/host/mesh/src/cdb.c
index f0c2e5f..60d47de 100644
--- a/nimble/host/mesh/src/cdb.c
+++ b/nimble/host/mesh/src/cdb.c
@@ -235,7 +235,7 @@ uint8_t bt_mesh_cdb_subnet_flags(const struct bt_mesh_cdb_subnet *sub)
{
uint8_t flags = 0x00;
- if (sub && sub->kr_flag) {
+ if (sub && SUBNET_KEY_TX_IDX(sub)) {
flags |= BT_MESH_NET_FLAG_KR;
}
diff --git a/nimble/host/mesh/src/provisioner.c b/nimble/host/mesh/src/provisioner.c
index e26efe7..265dbf2 100644
--- a/nimble/host/mesh/src/provisioner.c
+++ b/nimble/host/mesh/src/provisioner.c
@@ -503,7 +503,7 @@ static void send_prov_data(void)
#endif
bt_mesh_prov_buf_init(pdu, PROV_DATA);
#if MYNEWT_VAL(BLE_MESH_CDB)
- net_buf_simple_add_mem(pdu, sub->keys[sub->kr_flag].net_key, 16);
+ net_buf_simple_add_mem(&pdu, sub->keys[SUBNET_KEY_TX_IDX(sub)].net_key, 16);
net_buf_simple_add_be16(pdu, prov_device.node->net_idx);
net_buf_simple_add_u8(pdu, bt_mesh_cdb_subnet_flags(sub));
net_buf_simple_add_be32(pdu, bt_mesh_cdb.iv_index);
diff --git a/nimble/host/mesh/src/settings.c b/nimble/host/mesh/src/settings.c
index 193cc0b..1fb2b08 100644
--- a/nimble/host/mesh/src/settings.c
+++ b/nimble/host/mesh/src/settings.c
@@ -829,7 +829,6 @@ static int cdb_subnet_set(int argc, char *name)
if (sub) {
BT_DBG("Updating existing NetKeyIndex 0x%03x", net_idx);
- sub->kr_flag = key.kr_flag;
sub->kr_phase = key.kr_phase;
memcpy(sub->keys[0].net_key, &key.val[0], 16);
memcpy(sub->keys[1].net_key, &key.val[1], 16);
@@ -843,7 +842,6 @@ static int cdb_subnet_set(int argc, char *name)
return -ENOMEM;
}
- sub->kr_flag = key.kr_flag;
sub->kr_phase = key.kr_phase;
memcpy(sub->keys[0].net_key, &key.val[0], 16);
memcpy(sub->keys[1].net_key, &key.val[1], 16);
@@ -1608,7 +1606,7 @@ static void store_cdb_subnet(const struct bt_mesh_cdb_subnet *sub)
memcpy(&key.val[0], sub->keys[0].net_key, 16);
memcpy(&key.val[1], sub->keys[1].net_key, 16);
- key.kr_flag = sub->kr_flag;
+ key.kr_flag = 0U; /* Deprecated */
key.kr_phase = sub->kr_phase;
snprintk(path, sizeof(path), "bt/mesh/cdb/Subnet/%x", sub->net_idx);
diff --git a/nimble/host/mesh/src/shell.c b/nimble/host/mesh/src/shell.c
index 1ac4caf..ade9cd6 100644
--- a/nimble/host/mesh/src/shell.c
+++ b/nimble/host/mesh/src/shell.c
@@ -738,7 +738,7 @@ int cmd_mesh_init(int argc, char *argv[])
printk("Mesh initialized\n");
- if (IS_ENABLED(CONFIG_SETTINGS)) {
+ if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
settings_load();
}
@@ -2345,7 +2345,7 @@ static int cmd_provision(int argc, char *argv[])
return 0;
}
- net_key = sub->keys[sub->kr_flag].net_key;
+ net_key = sub->keys[SUBNET_KEY_TX_IDX(sub)].net_key;
}
err = bt_mesh_provision(net_key, net_idx, 0, iv_index, addr,
@@ -2905,7 +2905,7 @@ static int cmd_cdb_node_add(int argc, char *argv[])
memcpy(node->dev_key, dev_key, 16);
- if (IS_ENABLED(CONFIG_SETTINGS)) {
+ if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
bt_mesh_store_cdb_node(node);
}
@@ -2959,7 +2959,7 @@ static int cmd_cdb_subnet_add(int argc,
memcpy(sub->keys[0].net_key, net_key, 16);
- if (IS_ENABLED(CONFIG_SETTINGS)) {
+ if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
bt_mesh_store_cdb_subnet(sub);
}
@@ -3015,7 +3015,7 @@ static int cmd_cdb_app_key_add(int argc,
memcpy(key->keys[0].app_key, app_key, 16);
- if (IS_ENABLED(CONFIG_SETTINGS)) {
+ if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
bt_mesh_store_cdb_app_key(key);
}
diff --git a/nimble/host/mesh/src/testing.c b/nimble/host/mesh/src/testing.c
index dfe8d18..7ee11a1 100644
--- a/nimble/host/mesh/src/testing.c
+++ b/nimble/host/mesh/src/testing.c
@@ -135,8 +135,6 @@ void bt_test_print_credentials(void)
console_printf("Subnet: %d\n", i);
console_printf("\tNetKeyIdx: %04x\n",
sub->net_idx);
- console_printf("\tNetKey: %s\n",
- bt_hex(sub->keys[sub->kr_flag].net_key, 16));
}
for (i = 0; i < ARRAY_SIZE(bt_mesh_cdb.app_keys); ++i)
@@ -154,8 +152,6 @@ void bt_test_print_credentials(void)
app_key->net_idx);
console_printf("\tAppKeyIdx: %04x\n",
app_key->app_idx);
- console_printf("\tAppKey: %s\n",
- bt_hex(app_key->keys[sub->kr_flag].app_key, 16));
}
for (i = 0; i < ARRAY_SIZE(bt_mesh_cdb.subnets); ++i)