Merge branch 'bugfix/ble_mesh_get_node_with_name_v4.1' into 'release/v4.1'

ble_mesh: Get node info with pre-configured node name (v4.1)

See merge request espressif/esp-idf!10145
This commit is contained in:
Island 2020-08-26 15:28:15 +08:00
commit ade43317ca
6 changed files with 157 additions and 77 deletions

View File

@ -326,6 +326,25 @@ esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicas
return btc_ble_mesh_provisioner_get_node_with_addr(unicast_addr); return btc_ble_mesh_provisioner_get_node_with_addr(unicast_addr);
} }
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_name(const char *name)
{
if (!name || (strlen(name) > ESP_BLE_MESH_NODE_NAME_MAX_LEN)) {
return NULL;
}
return btc_ble_mesh_provisioner_get_node_with_name(name);
}
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void)
{
return btc_ble_mesh_provisioner_get_prov_node_count();
}
const esp_ble_mesh_node_t **esp_ble_mesh_provisioner_get_node_table_entry(void)
{
return btc_ble_mesh_provisioner_get_node_table_entry();
}
esp_err_t esp_ble_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16]) esp_err_t esp_ble_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16])
{ {
btc_ble_mesh_prov_args_t arg = {0}; btc_ble_mesh_prov_args_t arg = {0};
@ -493,12 +512,6 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx)
{ {
return bt_mesh_provisioner_local_net_key_get(net_idx); return bt_mesh_provisioner_local_net_key_get(net_idx);
} }
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void)
{
return btc_ble_mesh_provisioner_get_prov_node_count();
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */ #endif /* CONFIG_BLE_MESH_PROVISIONER */
#if (CONFIG_BLE_MESH_FAST_PROV) #if (CONFIG_BLE_MESH_FAST_PROV)

View File

@ -250,6 +250,48 @@ esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_uuid(const uint8_t u
*/ */
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr); esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
/**
* @brief This function is called to get the provisioned node information
* with the node name.
*
* @param[in] name: Name of the node (end by '\0').
*
* @return Pointer of the node info struct or NULL on failure.
*
*/
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_name(const char *name);
/**
* @brief This function is called by Provisioner to get provisioned node count.
*
* @return Number of the provisioned nodes.
*
*/
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void);
/**
* @brief This function is called by Provisioner to get the entry of the node table.
*
* @note After invoking the function to get the entry of nodes, users can use the "for"
* loop combined with the macro CONFIG_BLE_MESH_MAX_PROV_NODES to get each node's
* information. Before trying to read the node's information, users need to check
* if the node exists, i.e. if the *(esp_ble_mesh_node_t **node) is NULL.
* For example:
* ```
* const esp_ble_mesh_node_t **entry = esp_ble_mesh_provisioner_get_node_table_entry();
* for (int i = 0; i < CONFIG_BLE_MESH_MAX_PROV_NODES; i++) {
* const esp_ble_mesh_node_t *node = entry[i];
* if (node) {
* ......
* }
* }
* ```
*
* @return Pointer to the start of the node table.
*
*/
const esp_ble_mesh_node_t **esp_ble_mesh_provisioner_get_node_table_entry(void);
/** /**
* @brief This function is called to delete the provisioned node information * @brief This function is called to delete the provisioned node information
* with the node device uuid. * with the node device uuid.
@ -366,14 +408,6 @@ esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16
*/ */
const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx); const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx);
/**
* @brief This function is called by Provisioner to get provisioned node count.
*
* @return Number of the provisioned nodes.
*
*/
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void);
/** /**
* @brief This function is called to get fast provisioning application key. * @brief This function is called to get fast provisioning application key.
* *

View File

@ -782,6 +782,20 @@ esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicas
return (esp_ble_mesh_node_t *)bt_mesh_provisioner_get_node_with_addr(unicast_addr); return (esp_ble_mesh_node_t *)bt_mesh_provisioner_get_node_with_addr(unicast_addr);
} }
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_name(const char *name)
{
return (esp_ble_mesh_node_t *)bt_mesh_provisioner_get_node_with_name(name);
}
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void)
{
return bt_mesh_provisioner_get_node_count();
}
const esp_ble_mesh_node_t **btc_ble_mesh_provisioner_get_node_table_entry(void)
{
return (const esp_ble_mesh_node_t **)bt_mesh_provisioner_get_node_table_entry();
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */ #endif /* CONFIG_BLE_MESH_PROVISIONER */
static void btc_ble_mesh_heartbeat_msg_recv_cb(u8_t hops, u16_t feature) static void btc_ble_mesh_heartbeat_msg_recv_cb(u8_t hops, u16_t feature)
@ -991,11 +1005,6 @@ const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void)
return (const esp_ble_mesh_comp_t *)bt_mesh_comp_get(); return (const esp_ble_mesh_comp_t *)bt_mesh_comp_get();
} }
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void)
{
return bt_mesh_provisioner_get_node_count();
}
/* Configuration Models */ /* Configuration Models */
extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[]; extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[];
extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[]; extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];

View File

@ -298,6 +298,12 @@ esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_uuid(const uint8_t u
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr); esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_name(const char *name);
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void);
const esp_ble_mesh_node_t **btc_ble_mesh_provisioner_get_node_table_entry(void);
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model); int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
int btc_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model); int btc_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model);
@ -320,8 +326,6 @@ esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem,
const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void); const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
u16_t btc_ble_mesh_provisioner_get_prov_node_count(void);
void btc_ble_mesh_model_call_handler(btc_msg_t *msg); void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg); void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);

View File

@ -550,57 +550,57 @@ int bt_mesh_provisioner_delete_node_with_dev_addr(const bt_mesh_addr_t *addr)
return -ENODEV; return -ENODEV;
} }
static int provisioner_check_node_index(u16_t index) static struct bt_mesh_node **provisioner_find_node_with_name(const char *name)
{ {
BT_DBG("%s", __func__); size_t length = 0U;
if (index >= ARRAY_SIZE(mesh_nodes)) {
BT_ERR("%s, Too big node index %d", __func__, index);
return -EINVAL;
}
if (mesh_nodes[index] == NULL) {
BT_ERR("%s, Node not exists, index %d", __func__, index);
return -ENODEV;
}
return 0;
}
int bt_mesh_provisioner_set_node_name(u16_t index, const char *name)
{
size_t length = 0U, name_len = 0U;
int i; int i;
BT_DBG("%s", __func__); BT_DBG("node name %s", name);
if (!name) { length = MIN(strlen(name), BLE_MESH_NODE_NAME_SIZE);
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
if (provisioner_check_node_index(index)) { bt_mesh_provisioner_lock();
return -EINVAL;
}
BT_DBG("len %d, name %s", strlen(name), name);
length = (strlen(name) <= BLE_MESH_NODE_NAME_SIZE) ? strlen(name) : BLE_MESH_NODE_NAME_SIZE;
for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) { for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) {
if (mesh_nodes[i]) { if (mesh_nodes[i]) {
name_len = strlen(mesh_nodes[i]->name); if (strlen(mesh_nodes[i]->name) != length) {
if (length != name_len) {
continue; continue;
} }
if (!strncmp(mesh_nodes[i]->name, name, length)) { if (!strncmp(mesh_nodes[i]->name, name, length)) {
BT_WARN("Node name %s exists", name); bt_mesh_provisioner_unlock();
return -EEXIST; return &mesh_nodes[i];
} }
} }
} }
bt_mesh_provisioner_unlock();
return NULL;
}
int bt_mesh_provisioner_set_node_name(u16_t index, const char *name)
{
if (index >= ARRAY_SIZE(mesh_nodes)) {
BT_ERR("Invalid node index %d", index);
return -EINVAL;
}
if (mesh_nodes[index] == NULL) {
BT_ERR("Node not exists, index %d", index);
return -EINVAL;
}
if (name == NULL) {
BT_ERR("Invalid node name");
return -EINVAL;
}
if (provisioner_find_node_with_name(name)) {
BT_WARN("Node name \"%s\" already exists", name);
return -EEXIST;
}
memset(mesh_nodes[index]->name, 0, sizeof(mesh_nodes[index]->name)); memset(mesh_nodes[index]->name, 0, sizeof(mesh_nodes[index]->name));
strncpy(mesh_nodes[index]->name, name, length); strncpy(mesh_nodes[index]->name, name, BLE_MESH_NODE_NAME_SIZE);
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_node_name(mesh_nodes[index]); bt_mesh_store_node_name(mesh_nodes[index]);
@ -611,9 +611,13 @@ int bt_mesh_provisioner_set_node_name(u16_t index, const char *name)
const char *bt_mesh_provisioner_get_node_name(u16_t index) const char *bt_mesh_provisioner_get_node_name(u16_t index)
{ {
BT_DBG("%s", __func__); if (index >= ARRAY_SIZE(mesh_nodes)) {
BT_ERR("Invalid node index %d", index);
return NULL;
}
if (provisioner_check_node_index(index)) { if (mesh_nodes[index] == NULL) {
BT_ERR("Node not exists, index %d", index);
return NULL; return NULL;
} }
@ -622,31 +626,43 @@ const char *bt_mesh_provisioner_get_node_name(u16_t index)
u16_t bt_mesh_provisioner_get_node_index(const char *name) u16_t bt_mesh_provisioner_get_node_index(const char *name)
{ {
size_t length = 0U, name_len = 0U; struct bt_mesh_node **node = NULL;
int i;
BT_DBG("%s", __func__); if (name == NULL) {
BT_ERR("Invalid node name");
if (!name) {
BT_ERR("%s, Invalid parameter", __func__);
return BLE_MESH_INVALID_NODE_INDEX; return BLE_MESH_INVALID_NODE_INDEX;
} }
length = (strlen(name) <= BLE_MESH_NODE_NAME_SIZE) ? strlen(name) : BLE_MESH_NODE_NAME_SIZE; node = provisioner_find_node_with_name(name);
for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) { if (node == NULL) {
if (mesh_nodes[i]) { BT_ERR("Node name \"%s\" not exists", name);
name_len = strlen(mesh_nodes[i]->name); return BLE_MESH_INVALID_NODE_INDEX;
if (length != name_len) {
continue;
}
if (!strncmp(mesh_nodes[i]->name, name, length)) {
return (u16_t)i;
}
}
} }
BT_ERR("Node name %s not exists", name); return (node - mesh_nodes);
return BLE_MESH_INVALID_NODE_INDEX; }
struct bt_mesh_node *bt_mesh_provisioner_get_node_with_name(const char *name)
{
struct bt_mesh_node **node = NULL;
if (name == NULL) {
BT_ERR("Invalid node name");
return NULL;
}
node = provisioner_find_node_with_name(name);
if (node == NULL) {
BT_ERR("Node name \"%s\" not exists", name);
return NULL;
}
return *node;
}
const struct bt_mesh_node **bt_mesh_provisioner_get_node_table_entry(void)
{
return (const struct bt_mesh_node **)mesh_nodes;
} }
#define COMP_DATA_PAGE_0_MIN_LEN 16 #define COMP_DATA_PAGE_0_MIN_LEN 16

View File

@ -85,6 +85,10 @@ const char *bt_mesh_provisioner_get_node_name(u16_t index);
u16_t bt_mesh_provisioner_get_node_index(const char *name); u16_t bt_mesh_provisioner_get_node_index(const char *name);
struct bt_mesh_node *bt_mesh_provisioner_get_node_with_name(const char *name);
const struct bt_mesh_node **bt_mesh_provisioner_get_node_table_entry(void);
int bt_mesh_provisioner_store_node_comp_data(u16_t addr, const u8_t *data, u16_t length); int bt_mesh_provisioner_store_node_comp_data(u16_t addr, const u8_t *data, u16_t length);
const u8_t *bt_mesh_provisioner_net_key_get(u16_t net_idx); const u8_t *bt_mesh_provisioner_net_key_get(u16_t net_idx);