ソースを参照

Merge branch 'bugfix/ble_mesh_add_test_function_v3.3' into 'release/v3.3'

ble_mesh: Add ble mesh white list test function (v3.3)

See merge request espressif/esp-idf!8160
Island 5 年 前
コミット
e8c034c24d

+ 20 - 0
components/bt/Kconfig

@@ -2589,6 +2589,26 @@ if BLE_MESH
                 This option adds extra self-tests which are run every time BLE Mesh
                 This option adds extra self-tests which are run every time BLE Mesh
                 networking is initialized.
                 networking is initialized.
 
 
+        if BLE_MESH_SELF_TEST
+
+            config BLE_MESH_TEST_AUTO_ENTER_NETWORK
+                bool "Unprovisioned device enters mesh network automatically"
+                default y
+                help
+                    With this option enabled, an unprovisioned device can automatically
+                    enters mesh network using a specific test function without the pro-
+                    visioning procedure. And on the Provisioner side, a test function
+                    needs to be invoked to add the node information into the mesh stack.
+
+            config BLE_MESH_TEST_USE_WHITE_LIST
+                bool "Use white list to filter mesh advertising packets"
+                default n
+                help
+                    With this option enabled, users can use whilte list to filter mesh
+                    advertising packets while scanning.
+
+        endif # BLE_MESH_SELF_TEST
+
         config BLE_MESH_SHELL
         config BLE_MESH_SHELL
             bool "Enable BLE Mesh shell"
             bool "Enable BLE Mesh shell"
             default n
             default n

+ 31 - 1
components/bt/esp_ble_mesh/mesh_core/adv.c

@@ -837,7 +837,8 @@ int bt_mesh_scan_enable(void)
         .filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
         .filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
 #endif
 #endif
         .interval   = MESH_SCAN_INTERVAL,
         .interval   = MESH_SCAN_INTERVAL,
-        .window     = MESH_SCAN_WINDOW
+        .window     = MESH_SCAN_WINDOW,
+        .scan_fil_policy = BLE_MESH_SP_ADV_ALL,
     };
     };
 
 
     BT_DBG("%s", __func__);
     BT_DBG("%s", __func__);
@@ -865,3 +866,32 @@ int bt_mesh_scan_disable(void)
 
 
     return 0;
     return 0;
 }
 }
+
+#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
+int bt_mesh_scan_with_wl_enable(void)
+{
+    int err = 0;
+
+    struct bt_mesh_scan_param scan_param = {
+        .type       = BLE_MESH_SCAN_PASSIVE,
+#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
+        .filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
+#else
+        .filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
+#endif
+        .interval   = MESH_SCAN_INTERVAL,
+        .window     = MESH_SCAN_WINDOW,
+        .scan_fil_policy = BLE_MESH_SP_ADV_WL,
+    };
+
+    BT_DBG("%s", __func__);
+
+    err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
+    if (err) {
+        BT_ERR("starting scan failed (err %d)", err);
+        return err;
+    }
+
+    return 0;
+}
+#endif /* CONFIG_BLE_MESH_TEST_USE_WHITE_LIST */

+ 2 - 0
components/bt/esp_ble_mesh/mesh_core/adv.h

@@ -97,4 +97,6 @@ int bt_mesh_scan_enable(void);
 
 
 int bt_mesh_scan_disable(void);
 int bt_mesh_scan_disable(void);
 
 
+int bt_mesh_scan_with_wl_enable(void);
+
 #endif /* _ADV_H_ */
 #endif /* _ADV_H_ */

+ 19 - 3
components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c

@@ -267,9 +267,8 @@ static bool valid_scan_param(const struct bt_mesh_scan_param *param)
     return true;
     return true;
 }
 }
 
 
-static int start_le_scan(u8_t scan_type, u16_t interval, u16_t window, u8_t filter_dup)
+static int start_le_scan(u8_t scan_type, u16_t interval, u16_t window, u8_t filter_dup, u8_t scan_fil_policy)
 {
 {
-    UINT8 scan_fil_policy = BLE_MESH_SP_ADV_ALL; /* No whitelist for BLE Mesh */
     UINT8 addr_type_own = BLE_MESH_ADDR_PUBLIC;  /* Currently only support Public Address */
     UINT8 addr_type_own = BLE_MESH_ADDR_PUBLIC;  /* Currently only support Public Address */
     tGATT_IF client_if = 0xFF; /* Default GATT interface id */
     tGATT_IF client_if = 0xFF; /* Default GATT interface id */
 
 
@@ -442,7 +441,7 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c
     }
     }
 #endif
 #endif
 
 
-    err = start_le_scan(param->type, param->interval, param->window, param->filter_dup);
+    err = start_le_scan(param->type, param->interval, param->window, param->filter_dup, param->scan_fil_policy);
     if (err) {
     if (err) {
         return err;
         return err;
     }
     }
@@ -470,6 +469,23 @@ int bt_le_scan_stop(void)
     return 0;
     return 0;
 }
 }
 
 
+#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
+int bt_le_update_white_list(struct bt_mesh_white_list *wl)
+{
+    if (wl == NULL) {
+        BT_ERR("%s, Invalid parameter", __func__);
+        return -EINVAL;
+    }
+
+    if (BTM_BleUpdateAdvWhitelist(wl->add_remove, wl->remote_bda,
+            (tBTM_ADD_WHITELIST_CBACK *)wl->update_wl_comp_cb) == false) {
+        return -EIO;
+    }
+
+    return 0;
+}
+#endif
+
 #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
 #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
     CONFIG_BLE_MESH_GATT_PROXY_SERVER
     CONFIG_BLE_MESH_GATT_PROXY_SERVER
 static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
 static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)

+ 20 - 0
components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h

@@ -409,6 +409,9 @@ struct bt_mesh_scan_param {
 
 
     /** Scan window (N * 0.625 ms) */
     /** Scan window (N * 0.625 ms) */
     u16_t window;
     u16_t window;
+
+    /** BLE scan filter policy */
+    u8_t  scan_fil_policy;
 };
 };
 
 
 struct bt_mesh_conn {
 struct bt_mesh_conn {
@@ -655,6 +658,23 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c
 
 
 int bt_le_scan_stop(void);
 int bt_le_scan_stop(void);
 
 
+typedef enum {
+    BLE_MESH_WHITELIST_REMOVE,
+    BLE_MESH_WHITELIST_ADD,
+} bt_mesh_wl_operation;
+
+struct bt_mesh_white_list {
+    bool add_remove;
+    u8_t remote_bda[BLE_MESH_ADDR_LEN];
+    u8_t addr_type;
+    /* For Bluedroid host, this callback is used to notify the
+     * result of updating white list.
+     */
+    void (*update_wl_comp_cb)(u8_t status, bt_mesh_wl_operation wl_operation);
+};
+
+int bt_le_update_white_list(struct bt_mesh_white_list *wl);
+
 void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb);
 void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb);
 void bt_mesh_gatts_conn_cb_deregister(void);
 void bt_mesh_gatts_conn_cb_deregister(void);
 
 

+ 18 - 0
components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c

@@ -908,6 +908,24 @@ int bt_le_scan_stop(void)
     bt_mesh_scan_dev_found_cb = NULL;
     bt_mesh_scan_dev_found_cb = NULL;
     return 0;
     return 0;
 }
 }
+
+#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
+int bt_le_update_white_list(struct bt_mesh_white_list *wl)
+{
+    ble_addr_t addr = {0};
+
+    if (wl == NULL || wl->add_remove == false) {
+        BT_ERR("%s, Invalid parameter", __func__);
+        return -EINVAL;
+    }
+
+    addr.type = wl->addr_type;
+    memcpy(addr.val, wl->remote_bda, BLE_MESH_ADDR_LEN);
+
+    return ble_gap_wl_set(&addr, 1);
+}
+#endif
+
 #if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
 #if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
 
 
 void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb)
 void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb)

+ 32 - 10
components/bt/esp_ble_mesh/mesh_core/provisioner_main.c

@@ -586,16 +586,6 @@ int bt_mesh_provisioner_restore_node_comp_data(u16_t addr, const u8_t *data, u16
     return 0;
     return 0;
 }
 }
 
 
-int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node)
-{
-    if (!node) {
-        BT_ERR("%s, Invalid parameter", __func__);
-        return -EINVAL;
-    }
-
-    return provisioner_store_node(node, false, true, NULL);
-}
-
 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_uuid(const u8_t uuid[16])
 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_uuid(const u8_t uuid[16])
 {
 {
     return provisioner_find_node_with_uuid(uuid, NULL);
     return provisioner_find_node_with_uuid(uuid, NULL);
@@ -1552,6 +1542,38 @@ int bt_mesh_print_local_composition_data(void)
     return 0;
     return 0;
 }
 }
 
 
+#if CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK
+int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node)
+{
+    if (!node) {
+        BT_ERR("%s, Invalid parameter", __func__);
+        return -EINVAL;
+    }
+
+    if (!BLE_MESH_ADDR_IS_UNICAST(node->unicast_addr)) {
+        BT_ERR("%s, Not a unicast address 0x%04x", __func__, node->unicast_addr);
+        return -EINVAL;
+    }
+
+    if (node->element_num == 0) {
+        BT_ERR("%s, Invalid element count %d", __func__, node->element_num);
+        return -EINVAL;
+    }
+
+    if (bt_mesh_provisioner_check_is_addr_dup(node->unicast_addr, node->element_num, true)) {
+        BT_ERR("%s, Unicast address 0x%04x is duplicated", __func__, node->unicast_addr);
+        return -EINVAL;
+    }
+
+    if (bt_mesh_provisioner_net_key_get(node->net_idx) == NULL) {
+        BT_ERR("%s, Invalid NetKey Index 0x%03x", __func__, node->net_idx);
+        return -EINVAL;
+    }
+
+    return provisioner_store_node(node, false, true, NULL);
+}
+#endif /* CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK */
+
 #endif /* CONFIG_BLE_MESH_PROVISIONER */
 #endif /* CONFIG_BLE_MESH_PROVISIONER */
 
 
 /* The following APIs are for fast provisioning */
 /* The following APIs are for fast provisioning */

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

@@ -71,8 +71,6 @@ int bt_mesh_provisioner_restore_node_name(u16_t addr, const char *name);
 
 
 int bt_mesh_provisioner_restore_node_comp_data(u16_t addr, const u8_t *data, u16_t length, bool prov);
 int bt_mesh_provisioner_restore_node_comp_data(u16_t addr, const u8_t *data, u16_t length, bool prov);
 
 
-int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node);
-
 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_uuid(const u8_t uuid[16]);
 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_uuid(const u8_t uuid[16]);
 
 
 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_addr(u16_t unicast_addr);
 struct bt_mesh_node *bt_mesh_provisioner_get_node_with_addr(u16_t unicast_addr);
@@ -122,6 +120,8 @@ int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id,
 /* Provisioner print own element information */
 /* Provisioner print own element information */
 int bt_mesh_print_local_composition_data(void);
 int bt_mesh_print_local_composition_data(void);
 
 
+int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node);
+
 /* The following APIs are for fast provisioning */
 /* The following APIs are for fast provisioning */
 
 
 const u8_t *bt_mesh_fast_prov_dev_key_get(u16_t dst);
 const u8_t *bt_mesh_fast_prov_dev_key_get(u16_t dst);

+ 43 - 1
components/bt/esp_ble_mesh/mesh_core/test.c

@@ -10,6 +10,7 @@
 #include <string.h>
 #include <string.h>
 #include <errno.h>
 #include <errno.h>
 
 
+#include "adv.h"
 #include "mesh.h"
 #include "mesh.h"
 #include "test.h"
 #include "test.h"
 #include "crypto.h"
 #include "crypto.h"
@@ -23,8 +24,8 @@ int bt_mesh_test(void)
 {
 {
     return 0;
     return 0;
 }
 }
-#endif /* #if defined(CONFIG_BLE_MESH_SELF_TEST) */
 
 
+#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK
 int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info)
 int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info)
 {
 {
     const struct bt_mesh_comp *comp = NULL;
     const struct bt_mesh_comp *comp = NULL;
@@ -125,3 +126,44 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info)
 
 
     return 0;
     return 0;
 }
 }
+#endif /* CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK */
+
+#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
+int bt_mesh_test_update_white_list(struct bt_mesh_white_list *wl)
+{
+    int err = 0;
+
+    if (wl == NULL) {
+        BT_ERR("%s, Invalid parameter", __func__);
+        return -EINVAL;
+    }
+
+    BT_INFO("%s, addr %s, addr_type 0x%02x", wl->add_remove ? "Add" : "Remove",
+        bt_hex(wl->remote_bda, BLE_MESH_ADDR_LEN), wl->addr_type);
+
+    err = bt_le_update_white_list(wl);
+    if (err) {
+        BT_ERR("Failed to update white list");
+    }
+
+    return err;
+}
+
+int bt_mesh_test_start_scanning(bool wl_en)
+{
+    BT_INFO("Scan with filter policy %s", wl_en ? "enabled" : "disabled");
+
+    if (wl_en) {
+        return bt_mesh_scan_with_wl_enable();
+    } else {
+        return bt_mesh_scan_enable();
+    }
+}
+
+int bt_mesh_test_stop_scanning(void)
+{
+    return bt_mesh_scan_disable();
+}
+#endif /* CONFIG_BLE_MESH_TEST_USE_WHITE_LIST */
+
+#endif /* CONFIG_BLE_MESH_SELF_TEST */

+ 14 - 8
components/bt/esp_ble_mesh/mesh_core/test.h

@@ -10,16 +10,9 @@
 #ifndef _BLE_MESH_TEST_H_
 #ifndef _BLE_MESH_TEST_H_
 #define _BLE_MESH_TEST_H_
 #define _BLE_MESH_TEST_H_
 
 
-#include "mesh_types.h"
+#include "mesh_bearer_adapt.h"
 
 
-#if defined(CONFIG_BLE_MESH_SELF_TEST)
 int bt_mesh_test(void);
 int bt_mesh_test(void);
-#else
-static inline int bt_mesh_test(void)
-{
-    return 0;
-}
-#endif
 
 
 struct bt_mesh_device_network_info {
 struct bt_mesh_device_network_info {
     u8_t  net_key[16];
     u8_t  net_key[16];
@@ -35,4 +28,17 @@ struct bt_mesh_device_network_info {
 
 
 int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info);
 int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info);
 
 
+/* Before trying to update the white list, users need to make sure that
+ * one of the following conditions is satisfied:
+ * 1. BLE scanning is disabled;
+ * 2. BLE scanning is enabled with scan filter policy disabled;
+ * If BLE scanning is enabled with scan filter policy enabled, users need
+ * to stop BLE scanning firstly, then the white list can be updated.
+ */
+int bt_mesh_test_update_white_list(struct bt_mesh_white_list *wl);
+
+int bt_mesh_test_start_scanning(bool wl_en);
+
+int bt_mesh_test_stop_scanning(void);
+
 #endif /* _BLE_MESH_TEST_H_ */
 #endif /* _BLE_MESH_TEST_H_ */

+ 1 - 0
examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults

@@ -18,3 +18,4 @@ CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
 CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
 CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
 CONFIG_BLE_MESH_CFG_CLI=y
 CONFIG_BLE_MESH_CFG_CLI=y
 CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
 CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
+CONFIG_BLE_MESH_SELF_TEST=y

+ 1 - 1
examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults

@@ -22,4 +22,4 @@ CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
 CONFIG_BLE_MESH_MAX_STORED_NODES=40
 CONFIG_BLE_MESH_MAX_STORED_NODES=40
 CONFIG_BLE_MESH_MSG_CACHE_SIZE=60
 CONFIG_BLE_MESH_MSG_CACHE_SIZE=60
 CONFIG_BLE_MESH_ADV_BUF_COUNT=200
 CONFIG_BLE_MESH_ADV_BUF_COUNT=200
-
+CONFIG_BLE_MESH_SELF_TEST=y