mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ble_mesh: Add ble mesh white list test function
Using the ble mesh white list test functions, a node can choose to only receive mesh messages from a specific node and relay the messages for it. Messages from other nodes will be ignored.
This commit is contained in:
parent
12c7aa9b57
commit
012b810d29
@ -2589,6 +2589,26 @@ if BLE_MESH
|
||||
This option adds extra self-tests which are run every time BLE Mesh
|
||||
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
|
||||
bool "Enable BLE Mesh shell"
|
||||
default n
|
||||
|
@ -837,7 +837,8 @@ int bt_mesh_scan_enable(void)
|
||||
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
|
||||
#endif
|
||||
.interval = MESH_SCAN_INTERVAL,
|
||||
.window = MESH_SCAN_WINDOW
|
||||
.window = MESH_SCAN_WINDOW,
|
||||
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
|
||||
};
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
@ -865,3 +866,32 @@ int bt_mesh_scan_disable(void)
|
||||
|
||||
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 */
|
||||
|
@ -97,4 +97,6 @@ int bt_mesh_scan_enable(void);
|
||||
|
||||
int bt_mesh_scan_disable(void);
|
||||
|
||||
int bt_mesh_scan_with_wl_enable(void);
|
||||
|
||||
#endif /* _ADV_H_ */
|
||||
|
@ -267,9 +267,8 @@ static bool valid_scan_param(const struct bt_mesh_scan_param *param)
|
||||
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 */
|
||||
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
|
||||
|
||||
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) {
|
||||
return err;
|
||||
}
|
||||
@ -470,6 +469,23 @@ int bt_le_scan_stop(void)
|
||||
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) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
|
@ -409,6 +409,9 @@ struct bt_mesh_scan_param {
|
||||
|
||||
/** Scan window (N * 0.625 ms) */
|
||||
u16_t window;
|
||||
|
||||
/** BLE scan filter policy */
|
||||
u8_t scan_fil_policy;
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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_deregister(void);
|
||||
|
||||
|
@ -908,6 +908,24 @@ int bt_le_scan_stop(void)
|
||||
bt_mesh_scan_dev_found_cb = NULL;
|
||||
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
|
||||
|
||||
void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb)
|
||||
|
@ -586,16 +586,6 @@ int bt_mesh_provisioner_restore_node_comp_data(u16_t addr, const u8_t *data, u16
|
||||
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])
|
||||
{
|
||||
return provisioner_find_node_with_uuid(uuid, NULL);
|
||||
@ -1552,6 +1542,38 @@ int bt_mesh_print_local_composition_data(void)
|
||||
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 */
|
||||
|
||||
/* The following APIs are for fast provisioning */
|
||||
|
@ -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_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_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 */
|
||||
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 */
|
||||
|
||||
const u8_t *bt_mesh_fast_prov_dev_key_get(u16_t dst);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "adv.h"
|
||||
#include "mesh.h"
|
||||
#include "test.h"
|
||||
#include "crypto.h"
|
||||
@ -23,8 +24,8 @@ int bt_mesh_test(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
#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 */
|
||||
|
@ -10,16 +10,9 @@
|
||||
#ifndef _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);
|
||||
#else
|
||||
static inline int bt_mesh_test(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct bt_mesh_device_network_info {
|
||||
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);
|
||||
|
||||
/* 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_ */
|
||||
|
@ -18,3 +18,4 @@ CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=3
|
||||
CONFIG_BLE_MESH_CFG_CLI=y
|
||||
CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
||||
|
@ -22,4 +22,4 @@ CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y
|
||||
CONFIG_BLE_MESH_MAX_STORED_NODES=40
|
||||
CONFIG_BLE_MESH_MSG_CACHE_SIZE=60
|
||||
CONFIG_BLE_MESH_ADV_BUF_COUNT=200
|
||||
|
||||
CONFIG_BLE_MESH_SELF_TEST=y
|
Loading…
Reference in New Issue
Block a user