mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
Merge branch 'bugfix/ble_mesh_prov_iv_index_v4.2' into 'release/v4.2'
ble_mesh: stack: Using the latest iv_index for provisioning (v4.2) See merge request espressif/esp-idf!10416
This commit is contained in:
@ -383,14 +383,6 @@ int bt_mesh_prov_input_string(const char *str);
|
|||||||
*/
|
*/
|
||||||
int bt_mesh_prov_input_number(u32_t num);
|
int bt_mesh_prov_input_number(u32_t num);
|
||||||
|
|
||||||
/** @brief Enable Provisioner corresponding functionalities, e.g. scan, etc.
|
|
||||||
*
|
|
||||||
* @param bearers Bit-wise OR of provisioning bearers.
|
|
||||||
*
|
|
||||||
* @return Zero on success or (negative) error code otherwise.
|
|
||||||
*/
|
|
||||||
int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers);
|
|
||||||
|
|
||||||
/** @brief Enable specific provisioning bearers
|
/** @brief Enable specific provisioning bearers
|
||||||
*
|
*
|
||||||
* Enable one or more provisioning bearers.
|
* Enable one or more provisioning bearers.
|
||||||
|
@ -514,10 +514,41 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BLE_MESH_PROVISIONER)
|
#if defined(CONFIG_BLE_MESH_PROVISIONER)
|
||||||
int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers)
|
int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
|
||||||
{
|
{
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
if (bt_mesh_is_provisioner_en()) {
|
||||||
|
BT_WARN("%s, Already", __func__);
|
||||||
|
return -EALREADY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prov_bearers_valid(bearers) == false) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = bt_mesh_provisioner_net_create();
|
||||||
|
if (err) {
|
||||||
|
BT_ERR("Failed to create network");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = bt_mesh_provisioner_init_prov_info();
|
||||||
|
if (err) {
|
||||||
|
BT_ERR("Failed to init prov info");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
bt_mesh_provisioner_set_prov_bearer(bearers, false);
|
bt_mesh_provisioner_set_prov_bearer(bearers, false);
|
||||||
|
|
||||||
|
bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr());
|
||||||
|
|
||||||
|
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_PROVISIONER);
|
||||||
|
|
||||||
|
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||||
|
bt_mesh_store_role();
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
|
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
|
||||||
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||||
(bearers & BLE_MESH_PROV_ADV)) {
|
(bearers & BLE_MESH_PROV_ADV)) {
|
||||||
@ -552,40 +583,6 @@ int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
|
|
||||||
{
|
|
||||||
int err = 0;
|
|
||||||
|
|
||||||
if (bt_mesh_is_provisioner_en()) {
|
|
||||||
BT_WARN("%s, Already", __func__);
|
|
||||||
return -EALREADY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prov_bearers_valid(bearers) == false) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = bt_mesh_provisioner_set_prov_info();
|
|
||||||
if (err) {
|
|
||||||
BT_ERR("Failed to set provisioning info");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = bt_mesh_provisioner_net_create();
|
|
||||||
if (err) {
|
|
||||||
BT_ERR("Failed to create network");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_PROVISIONER);
|
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
|
||||||
bt_mesh_store_role();
|
|
||||||
}
|
|
||||||
|
|
||||||
return bt_mesh_provisioner_net_start(bearers);
|
|
||||||
}
|
|
||||||
|
|
||||||
int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
|
int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
|
||||||
{
|
{
|
||||||
bt_mesh_prov_bearer_t enable = 0U;
|
bt_mesh_prov_bearer_t enable = 0U;
|
||||||
|
@ -83,11 +83,6 @@ int bt_mesh_provisioner_net_create(void)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the device only acts as a Provisioner, need to initialize
|
|
||||||
* each element's address.
|
|
||||||
*/
|
|
||||||
bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr());
|
|
||||||
|
|
||||||
if (bt_mesh.p_sub[0]) {
|
if (bt_mesh.p_sub[0]) {
|
||||||
/* Provisioner is already enabled (enable -> disable -> enable),
|
/* Provisioner is already enabled (enable -> disable -> enable),
|
||||||
* or Provisioner is restored from flash.
|
* or Provisioner is restored from flash.
|
||||||
|
@ -237,7 +237,7 @@ struct bt_mesh_prov_ctx {
|
|||||||
u16_t curr_net_idx;
|
u16_t curr_net_idx;
|
||||||
|
|
||||||
/* Current flags going to be used in provisioning data */
|
/* Current flags going to be used in provisioning data */
|
||||||
u16_t curr_flags;
|
u8_t curr_flags;
|
||||||
|
|
||||||
/* Current iv_index going to be used in provisioning data */
|
/* Current iv_index going to be used in provisioning data */
|
||||||
u16_t curr_iv_index;
|
u16_t curr_iv_index;
|
||||||
@ -1128,10 +1128,8 @@ int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_mesh_provisioner_set_prov_info(void)
|
int bt_mesh_provisioner_init_prov_info(void)
|
||||||
{
|
{
|
||||||
const struct bt_mesh_comp *comp = NULL;
|
|
||||||
|
|
||||||
if (prov_ctx.primary_addr == BLE_MESH_ADDR_UNASSIGNED) {
|
if (prov_ctx.primary_addr == BLE_MESH_ADDR_UNASSIGNED) {
|
||||||
/* If unicast address of primary element of Provisioner has not been set
|
/* If unicast address of primary element of Provisioner has not been set
|
||||||
* before, then the following initialization procedure will be used.
|
* before, then the following initialization procedure will be used.
|
||||||
@ -1143,7 +1141,7 @@ int bt_mesh_provisioner_set_prov_info(void)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
comp = bt_mesh_comp_get();
|
const struct bt_mesh_comp *comp = bt_mesh_comp_get();
|
||||||
if (!comp) {
|
if (!comp) {
|
||||||
BT_ERR("Invalid composition data");
|
BT_ERR("Invalid composition data");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@ -1156,15 +1154,19 @@ int bt_mesh_provisioner_set_prov_info(void)
|
|||||||
} else {
|
} else {
|
||||||
prov_ctx.curr_alloc_addr = prov->prov_start_address;
|
prov_ctx.curr_alloc_addr = prov->prov_start_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update primary element address with the initialized value here. */
|
||||||
prov_ctx.primary_addr = prov->prov_unicast_addr;
|
prov_ctx.primary_addr = prov->prov_unicast_addr;
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||||
bt_mesh_store_prov_info(prov_ctx.primary_addr, prov_ctx.curr_alloc_addr);
|
bt_mesh_store_prov_info(prov_ctx.primary_addr, prov_ctx.curr_alloc_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prov_ctx.curr_net_idx = BLE_MESH_KEY_PRIMARY;
|
prov_ctx.curr_net_idx = BLE_MESH_KEY_PRIMARY;
|
||||||
prov_ctx.curr_flags = prov->flags;
|
struct bt_mesh_subnet *sub = bt_mesh_provisioner_subnet_get(BLE_MESH_KEY_PRIMARY);
|
||||||
prov_ctx.curr_iv_index = prov->iv_index;
|
prov_ctx.curr_flags = bt_mesh_net_flags(sub);
|
||||||
|
prov_ctx.curr_iv_index = bt_mesh.iv_index;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1241,7 +1243,8 @@ int bt_mesh_provisioner_set_primary_elem_addr(u16_t addr)
|
|||||||
if (addr + comp->elem_count > prov_ctx.curr_alloc_addr) {
|
if (addr + comp->elem_count > prov_ctx.curr_alloc_addr) {
|
||||||
prov_ctx.curr_alloc_addr = addr + comp->elem_count;
|
prov_ctx.curr_alloc_addr = addr + comp->elem_count;
|
||||||
}
|
}
|
||||||
BT_INFO("Provisioner primary address updated, old 0x%04x, new 0x%04x", prov_ctx.primary_addr, addr);
|
|
||||||
|
BT_INFO("Primary address updated, old 0x%04x, new 0x%04x", prov_ctx.primary_addr, addr);
|
||||||
prov_ctx.primary_addr = addr;
|
prov_ctx.primary_addr = addr;
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
|
||||||
|
@ -277,12 +277,12 @@ int bt_mesh_provisioner_adv_pkt_cb_register(unprov_adv_pkt_cb_t cb);
|
|||||||
int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info);
|
int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function sets the provisioning information needed by Provisioner,
|
* @brief This function initializes the provisioning information needed by Provisioner,
|
||||||
* including unicast address, IV Index, etc.
|
* including NetKey Index, flags, IV Index, etc.
|
||||||
*
|
*
|
||||||
* @return Zero - success, otherwise - fail
|
* @return Zero - success, otherwise - fail
|
||||||
*/
|
*/
|
||||||
int bt_mesh_provisioner_set_prov_info(void);
|
int bt_mesh_provisioner_init_prov_info(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function sets the provisioning bearer type used by Provisioner.
|
* @brief This function sets the provisioning bearer type used by Provisioner.
|
||||||
|
@ -249,7 +249,7 @@ static int iv_set(const char *name)
|
|||||||
bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS, iv.iv_update);
|
bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS, iv.iv_update);
|
||||||
bt_mesh.ivu_duration = iv.iv_duration;
|
bt_mesh.ivu_duration = iv.iv_duration;
|
||||||
|
|
||||||
BT_INFO("Restored IV Index 0x%04x (IV Update Flag %u) duration %u hours",
|
BT_INFO("Restored IV Index 0x%08x (IV Update Flag %u) duration %u hours",
|
||||||
iv.iv_index, iv.iv_update, iv.iv_duration);
|
iv.iv_index, iv.iv_update, iv.iv_duration);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1365,8 +1365,6 @@ int settings_core_commit(void)
|
|||||||
|
|
||||||
BT_INFO("p_sub[0]->net_idx 0x%03x", bt_mesh.p_sub[0]->net_idx);
|
BT_INFO("p_sub[0]->net_idx 0x%03x", bt_mesh.p_sub[0]->net_idx);
|
||||||
|
|
||||||
bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr());
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
|
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
|
||||||
sub = bt_mesh.p_sub[i];
|
sub = bt_mesh.p_sub[i];
|
||||||
|
|
||||||
@ -1378,7 +1376,6 @@ int settings_core_commit(void)
|
|||||||
if (err) {
|
if (err) {
|
||||||
BT_ERR("Failed to init subnet 0x%03x", sub->net_idx);
|
BT_ERR("Failed to init subnet 0x%03x", sub->net_idx);
|
||||||
}
|
}
|
||||||
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||||
@ -1417,12 +1414,6 @@ int settings_core_commit(void)
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_BLE_MESH_NODE */
|
#endif /* CONFIG_BLE_MESH_NODE */
|
||||||
|
|
||||||
#if defined(CONFIG_BLE_MESH_PROVISIONER)
|
|
||||||
if (bt_mesh_is_provisioner()) {
|
|
||||||
bt_mesh_provisioner_net_start(BLE_MESH_PROV_ADV | BLE_MESH_PROV_GATT);
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user