ble_mesh: stack: Fix storing next net_idx and app_idx

This commit is contained in:
lly 2020-05-27 11:27:20 +08:00
parent d7c2d66d55
commit 3940ab80a3
4 changed files with 8 additions and 4 deletions

View file

@ -1132,6 +1132,7 @@ typedef union {
*/ */
struct ble_mesh_provisioner_add_local_app_key_comp_param { struct ble_mesh_provisioner_add_local_app_key_comp_param {
int err_code; /*!< Indicate the result of adding local AppKey by the Provisioner */ int err_code; /*!< Indicate the result of adding local AppKey by the Provisioner */
uint16_t net_idx; /*!< NetKey Index */
uint16_t app_idx; /*!< AppKey Index */ uint16_t app_idx; /*!< AppKey Index */
} provisioner_add_app_key_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT */ } provisioner_add_app_key_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT */
/** /**

View file

@ -1823,10 +1823,11 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
app_key = arg->add_local_app_key.app_key; app_key = arg->add_local_app_key.app_key;
} }
act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT; act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT;
param.provisioner_add_app_key_comp.app_idx = arg->add_local_app_key.app_idx;
param.provisioner_add_app_key_comp.err_code = param.provisioner_add_app_key_comp.err_code =
bt_mesh_provisioner_local_app_key_add(app_key, arg->add_local_app_key.net_idx, bt_mesh_provisioner_local_app_key_add(app_key, arg->add_local_app_key.net_idx,
&arg->add_local_app_key.app_idx); &arg->add_local_app_key.app_idx);
param.provisioner_add_app_key_comp.net_idx = arg->add_local_app_key.net_idx;
param.provisioner_add_app_key_comp.app_idx = arg->add_local_app_key.app_idx;
break; break;
} }
case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY: case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY:
@ -1856,9 +1857,9 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
net_key = arg->add_local_net_key.net_key; net_key = arg->add_local_net_key.net_key;
} }
act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT; act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT;
param.provisioner_add_net_key_comp.net_idx = arg->add_local_net_key.net_idx;
param.provisioner_add_net_key_comp.err_code = param.provisioner_add_net_key_comp.err_code =
bt_mesh_provisioner_local_net_key_add(net_key, &arg->add_local_net_key.net_idx); bt_mesh_provisioner_local_net_key_add(net_key, &arg->add_local_net_key.net_idx);
param.provisioner_add_net_key_comp.net_idx = arg->add_local_net_key.net_idx;
break; break;
} }
case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY: case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY:

View file

@ -1027,6 +1027,7 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16],
} }
} }
*app_idx = key->app_idx; *app_idx = key->app_idx;
bt_mesh.p_app_idx_next++;
} }
key->updated = false; key->updated = false;
@ -1283,6 +1284,7 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx
} }
} }
*net_idx = sub->net_idx; *net_idx = sub->net_idx;
bt_mesh.p_net_idx_next++;
} }
sub->kr_phase = BLE_MESH_KR_NORMAL; sub->kr_phase = BLE_MESH_KR_NORMAL;
sub->kr_flag = false; sub->kr_flag = false;

View file

@ -2389,7 +2389,7 @@ static void store_p_app_key(struct bt_mesh_app_key *app)
void bt_mesh_store_p_net_idx(void) void bt_mesh_store_p_net_idx(void)
{ {
BT_DBG("p_net_idx_next 0x%03x", bt_mesh.p_net_idx_next); BT_DBG("Store, p_net_idx_next 0x%03x", bt_mesh.p_net_idx_next);
bt_mesh_save_core_settings("mesh/p_netidx", bt_mesh_save_core_settings("mesh/p_netidx",
(const u8_t *)&bt_mesh.p_net_idx_next, sizeof(bt_mesh.p_net_idx_next)); (const u8_t *)&bt_mesh.p_net_idx_next, sizeof(bt_mesh.p_net_idx_next));
@ -2403,7 +2403,7 @@ void bt_mesh_clear_p_net_idx(void)
void bt_mesh_store_p_app_idx(void) void bt_mesh_store_p_app_idx(void)
{ {
BT_DBG("p_app_idx_next 0x%03x", bt_mesh.p_app_idx_next); BT_DBG("Store, p_app_idx_next 0x%03x", bt_mesh.p_app_idx_next);
bt_mesh_save_core_settings("mesh/p_appidx", bt_mesh_save_core_settings("mesh/p_appidx",
(const u8_t *)&bt_mesh.p_app_idx_next, sizeof(bt_mesh.p_app_idx_next)); (const u8_t *)&bt_mesh.p_app_idx_next, sizeof(bt_mesh.p_app_idx_next));