ble_mesh: Update next alloc address when node info is added

This commit is contained in:
lly 2020-03-25 12:30:53 +08:00 committed by bot
parent 9cb7faf4bd
commit 80feb4e70a
3 changed files with 47 additions and 1 deletions

View file

@ -1512,6 +1512,8 @@ int bt_mesh_print_local_composition_data(void)
#if CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK
int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node)
{
int err = 0;
if (!node) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
@ -1532,12 +1534,24 @@ int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node)
return -EINVAL;
}
if (node->unicast_addr + node->element_num - 1 > 0x7FFF) {
BT_ERR("%s, Not enough unicast address for the node", __func__);
return -EIO;
}
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);
err = provisioner_store_node(node, true, NULL);
if (err) {
BT_ERR("%s, Failed to store node info", __func__);
return err;
}
bt_mesh_test_provisioner_update_alloc_addr(node->unicast_addr, node->element_num);
return 0;
}
#endif /* CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK */

View file

@ -1245,6 +1245,26 @@ int bt_mesh_provisioner_set_primary_elem_addr(u16_t addr)
return 0;
}
#if CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK
int bt_mesh_test_provisioner_update_alloc_addr(u16_t unicast_addr, u16_t element_num)
{
u16_t max_addr = FAST_PROV_ENABLE() ? prov_ctx.fast_prov.unicast_addr_max : PROV_MAX_ADDR_TO_ASSIGN;
if (unicast_addr + element_num > max_addr) {
BT_WARN("%s, Not enough unicast address to allocate", __func__);
prov_ctx.curr_alloc_addr = BLE_MESH_ADDR_UNASSIGNED;
} else {
prov_ctx.curr_alloc_addr = unicast_addr + element_num;
}
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_prov_info(prov_ctx.primary_addr, prov_ctx.curr_alloc_addr);
}
return 0;
}
#endif /* CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK */
/* The following APIs are for fast provisioning */
void bt_mesh_provisioner_fast_prov_enable(bool enable)

View file

@ -331,6 +331,18 @@ u16_t bt_mesh_provisioner_get_primary_elem_addr(void);
*/
int bt_mesh_provisioner_set_primary_elem_addr(u16_t addr);
/**
* @brief This function is used to update next allocated address by Provisioner.
*
* @note This function is used for mesh internal test.
*
* @param[in] unicast_addr: unicast address of the node
* @param[in] element_num: element count of the node
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_test_provisioner_update_alloc_addr(u16_t unicast_addr, u16_t element_num);
/**
* @brief This function is called to input number/string out-put by unprovisioned device.
*