Просмотр исходного кода

ble_mesh: stack: Update some fast prov functions

lly 5 лет назад
Родитель
Сommit
8753fb359a

+ 13 - 20
components/bt/esp_ble_mesh/mesh_core/fast_prov.c

@@ -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)
 {
-    struct bt_mesh_subnet_keys *key = NULL;
-    struct bt_mesh_subnet *sub = NULL;
+    /* Set net_idx for fast provisioning */
+    bt_mesh_provisioner_set_fast_prov_net_idx(net_idx);
 
-    sub = bt_mesh_fast_prov_subnet_get(net_idx);
-    if (sub) {
-        key = BLE_MESH_KEY_REFRESH(sub->kr_flag) ? &sub->keys[1] : &sub->keys[0];
-        return bt_mesh_provisioner_set_fast_prov_net_idx(key->net, net_idx);
+    if (bt_mesh_fast_prov_subnet_get(net_idx) == NULL) {
+        /* If NetKey is not found, wait for NetKey to be added. */
+        BT_WARN("Wait for NetKey for fast provisioning");
+        return 0x01; /*status: Wait for NetKey */
     }
 
-    /* If NetKey is not found, set net_idx for fast provisioning,
-     * and wait for Primary Provisioner to add NetKey.
-     */
-    return bt_mesh_provisioner_set_fast_prov_net_idx(NULL, net_idx);
+    return 0x0; /* status: Succeed */
 }
 
-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;
     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);
     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);
-    if (!keys) {
-        return 0x01; /* status: add net_key fail */
-    }
-
-    return bt_mesh_provisioner_set_fast_prov_net_idx(keys, net_idx);
+    bt_mesh_provisioner_set_fast_prov_net_idx(net_idx);
+    return 0x0; /* status: Succeed */
 }
 
-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;
 

+ 2 - 2
components/bt/esp_ble_mesh/mesh_core/fast_prov.h

@@ -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_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);
 

+ 8 - 16
components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c

@@ -20,6 +20,7 @@
 #include "mesh.h"
 #include "access.h"
 #include "settings.h"
+#include "fast_prov.h"
 #include "mesh_common.h"
 #include "proxy_client.h"
 #include "provisioner_prov.h"
@@ -276,7 +277,6 @@ struct bt_mesh_prov_ctx {
     struct {
         bool  enable;
         u16_t net_idx;
-        const u8_t *net_key;
         u8_t  flags;
         u32_t iv_index;
         u16_t unicast_addr_min;
@@ -1280,17 +1280,9 @@ void bt_mesh_provisioner_fast_prov_enable(bool 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_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)
@@ -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
      * subnet will the device be provisioned later.
      */
-    if (FAST_PROV_ENABLE()) {
-        netkey = prov_ctx.fast_prov.net_key;
+    if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
+        netkey = bt_mesh_fast_prov_net_key_get(prov_ctx.fast_prov.net_idx);
         if (!netkey) {
-            BT_ERR("%s, Failed to get NetKey for fast provisioning", __func__);
+            BT_ERR("No NetKey for fast provisioning");
             goto fail;
         }
         memcpy(pdu, netkey, 16);
@@ -2469,7 +2461,7 @@ static void send_prov_data(const u8_t idx)
     } else {
         netkey = bt_mesh_provisioner_net_key_get(prov_ctx.curr_net_idx);
         if (!netkey) {
-            BT_ERR("%s, Failed to get NetKey for provisioning data", __func__);
+            BT_ERR("No NetKey for provisioning data");
             goto fail;
         }
         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].iv_index = prov_ctx.fast_prov.iv_index;
     } else {
@@ -2668,7 +2660,7 @@ static void prov_complete(const u8_t idx, const u8_t *data)
         return;
     }
 
-    if (FAST_PROV_ENABLE()) {
+    if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && FAST_PROV_ENABLE()) {
         net_idx = prov_ctx.fast_prov.net_idx;
     } else {
         net_idx = prov_ctx.curr_net_idx;

+ 2 - 3
components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h

@@ -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.
  *
- * @param[in] net_key: Netkey value
  * @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.