diff --git a/components/bt/Kconfig b/components/bt/Kconfig index 1815990bad..2267059b1a 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -1644,6 +1644,13 @@ if BLE_MESH option in the Bluetooth Controller section in menuconfig, which is "Scan Duplicate By Device Address and Advertising Data". + config BLE_MESH_ALLOC_FROM_PSRAM_FIRST + bool "BLE Mesh will first allocate memory from PSRAM" + default n + help + When this option is enabled, BLE Mesh stack will try to allocate memory + from PSRAM firstly. This will save the internal RAM if PSRAM exists. + config BLE_MESH_FAST_PROV bool "Enable BLE Mesh Fast Provisioning" select BLE_MESH_NODE diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c index 20289ff5c8..b0b29edfea 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c @@ -71,8 +71,12 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp return ESP_OK; } -esp_err_t esp_ble_mesh_deinit(void) +esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param) { - return btc_ble_mesh_deinit(); + if (param == NULL) { + return ESP_ERR_INVALID_ARG; + } + + return btc_ble_mesh_deinit(param); } diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c index c0edbac814..9c4cd8d8bb 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c @@ -85,7 +85,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model, bt_mesh_model_msg_init(model->pub->msg, opcode); net_buf_simple_add_mem(model->pub->msg, data, length); } else { - msg_data = (uint8_t *)osi_malloc(op_len + length); + msg_data = (uint8_t *)bt_mesh_malloc(op_len + length); if (msg_data == NULL) { return ESP_ERR_NO_MEM; } @@ -114,7 +114,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model, status = (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_model_args_t), btc_ble_mesh_model_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); - osi_free(msg_data); + bt_mesh_free(msg_data); return status; } diff --git a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_common_api.h b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_common_api.h index 618059444e..e218c51b74 100644 --- a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_common_api.h +++ b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_common_api.h @@ -39,9 +39,11 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp * * @note This function shall be invoked after esp_ble_mesh_client_model_deinit(). * + * @param[in] param: Pointer to the structure of BLE Mesh deinit parameters. + * * @return ESP_OK on success or error code otherwise. * */ -esp_err_t esp_ble_mesh_deinit(void); +esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param); #endif /* _ESP_BLE_MESH_COMMON_API_H_ */ diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index 6f178dc6eb..9ddc31ccb1 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -323,6 +323,11 @@ typedef uint8_t esp_ble_mesh_bd_addr_t[BD_ADDR_LEN]; /// BLE device address type typedef uint8_t esp_ble_mesh_addr_type_t; +/*!< BLE Mesh deinit parameters */ +typedef struct { + bool erase_flash; /*!< Indicate if erasing flash when deinit mesh stack */ +} esp_ble_mesh_deinit_param_t; + typedef struct esp_ble_mesh_model esp_ble_mesh_model_t; /** Abstraction that describes a BLE Mesh Element. diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index bead771228..20a86c8fa6 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -50,7 +50,7 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void switch (msg->act) { case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: { - dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->cfg_client_get_state.params) { memcpy(dst->cfg_client_get_state.params, src->cfg_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -59,7 +59,7 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } if (src->cfg_client_get_state.get_state) { - dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t)); + dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t)); if (dst->cfg_client_get_state.get_state) { memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state, sizeof(esp_ble_mesh_cfg_client_get_state_t)); @@ -70,7 +70,7 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: { - dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->cfg_client_set_state.params) { memcpy(dst->cfg_client_set_state.params, src->cfg_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -79,7 +79,7 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } if (src->cfg_client_set_state.set_state) { - dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t)); + dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t)); if (dst->cfg_client_set_state.set_state) { memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state, sizeof(esp_ble_mesh_cfg_client_set_state_t)); @@ -109,18 +109,18 @@ static void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: if (arg->cfg_client_get_state.params) { - osi_free(arg->cfg_client_get_state.params); + bt_mesh_free(arg->cfg_client_get_state.params); } if (arg->cfg_client_get_state.get_state) { - osi_free(arg->cfg_client_get_state.get_state); + bt_mesh_free(arg->cfg_client_get_state.get_state); } break; case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: if (arg->cfg_client_set_state.params) { - osi_free(arg->cfg_client_set_state.params); + bt_mesh_free(arg->cfg_client_set_state.params); } if (arg->cfg_client_set_state.set_state) { - osi_free(arg->cfg_client_set_state.set_state); + bt_mesh_free(arg->cfg_client_set_state.set_state); } break; default: @@ -140,7 +140,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des } if (p_src_data->params) { - p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; @@ -287,7 +287,7 @@ static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg) } case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT: if (arg->params) { - osi_free(arg->params); + bt_mesh_free(arg->params); } break; default: diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c index bd2f49fad9..a9e0d90493 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -46,7 +46,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi switch (msg->act) { case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: { - dst->generic_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->generic_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->generic_client_get_state.params) { memcpy(dst->generic_client_get_state.params, src->generic_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -55,7 +55,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi break; } if (src->generic_client_get_state.get_state) { - dst->generic_client_get_state.get_state = (esp_ble_mesh_generic_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_generic_client_get_state_t)); + dst->generic_client_get_state.get_state = (esp_ble_mesh_generic_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_get_state_t)); if (dst->generic_client_get_state.get_state) { memcpy(dst->generic_client_get_state.get_state, src->generic_client_get_state.get_state, sizeof(esp_ble_mesh_generic_client_get_state_t)); @@ -66,8 +66,8 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi break; } case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: { - dst->generic_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); - dst->generic_client_set_state.set_state = (esp_ble_mesh_generic_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_generic_client_set_state_t)); + dst->generic_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->generic_client_set_state.set_state = (esp_ble_mesh_generic_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_set_state_t)); if (dst->generic_client_set_state.params && dst->generic_client_set_state.set_state) { memcpy(dst->generic_client_set_state.params, src->generic_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -129,10 +129,10 @@ static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: if (arg->generic_client_get_state.params) { - osi_free(arg->generic_client_get_state.params); + bt_mesh_free(arg->generic_client_get_state.params); } if (arg->generic_client_get_state.get_state) { - osi_free(arg->generic_client_get_state.get_state); + bt_mesh_free(arg->generic_client_get_state.get_state); } break; case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: @@ -149,10 +149,10 @@ static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg) break; } } - osi_free(arg->generic_client_set_state.set_state); + bt_mesh_free(arg->generic_client_set_state.set_state); } if (arg->generic_client_set_state.params) { - osi_free(arg->generic_client_set_state.params); + bt_mesh_free(arg->generic_client_set_state.params); } break; default: @@ -172,7 +172,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de } if (p_src_data->params) { - p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; @@ -353,7 +353,7 @@ static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg) } case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT: if (arg->params) { - osi_free(arg->params); + bt_mesh_free(arg->params); } break; default: diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index a078c7fd47..769d2e3f65 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -49,7 +49,7 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void switch (msg->act) { case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: { - dst->health_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->health_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->health_client_get_state.params) { memcpy(dst->health_client_get_state.params, src->health_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -58,7 +58,7 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } if (src->health_client_get_state.get_state) { - dst->health_client_get_state.get_state = (esp_ble_mesh_health_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_health_client_get_state_t)); + dst->health_client_get_state.get_state = (esp_ble_mesh_health_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_get_state_t)); if (dst->health_client_get_state.get_state) { memcpy(dst->health_client_get_state.get_state, src->health_client_get_state.get_state, sizeof(esp_ble_mesh_health_client_get_state_t)); @@ -69,8 +69,8 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: { - dst->health_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); - dst->health_client_set_state.set_state = (esp_ble_mesh_health_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_health_client_set_state_t)); + dst->health_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->health_client_set_state.set_state = (esp_ble_mesh_health_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_set_state_t)); if (dst->health_client_set_state.params && dst->health_client_set_state.set_state) { memcpy(dst->health_client_set_state.params, src->health_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -101,18 +101,18 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: if (arg->health_client_get_state.params) { - osi_free(arg->health_client_get_state.params); + bt_mesh_free(arg->health_client_get_state.params); } if (arg->health_client_get_state.get_state) { - osi_free(arg->health_client_get_state.get_state); + bt_mesh_free(arg->health_client_get_state.get_state); } break; case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: if (arg->health_client_set_state.params) { - osi_free(arg->health_client_set_state.params); + bt_mesh_free(arg->health_client_set_state.params); } if (arg->health_client_set_state.set_state) { - osi_free(arg->health_client_set_state.set_state); + bt_mesh_free(arg->health_client_set_state.set_state); } break; default: @@ -132,7 +132,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des } if (p_src_data->params) { - p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; @@ -219,7 +219,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg) } case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT: if (arg->params) { - osi_free(arg->params); + bt_mesh_free(arg->params); } break; default: diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c index 3a408f2189..7737f2bfdd 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -45,7 +45,7 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo switch (msg->act) { case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: { - dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->light_client_get_state.params) { memcpy(dst->light_client_get_state.params, src->light_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -54,7 +54,7 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo break; } if (src->light_client_get_state.get_state) { - dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_get_state_t)); + dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_get_state_t)); if (dst->light_client_get_state.get_state) { memcpy(dst->light_client_get_state.get_state, src->light_client_get_state.get_state, sizeof(esp_ble_mesh_light_client_get_state_t)); @@ -65,8 +65,8 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo break; } case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: { - dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); - dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_set_state_t)); + dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_set_state_t)); if (dst->light_client_set_state.params && dst->light_client_set_state.set_state) { memcpy(dst->light_client_set_state.params, src->light_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -97,18 +97,18 @@ static void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: if (arg->light_client_get_state.params) { - osi_free(arg->light_client_get_state.params); + bt_mesh_free(arg->light_client_get_state.params); } if (arg->light_client_get_state.get_state) { - osi_free(arg->light_client_get_state.get_state); + bt_mesh_free(arg->light_client_get_state.get_state); } break; case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: if (arg->light_client_set_state.params) { - osi_free(arg->light_client_set_state.params); + bt_mesh_free(arg->light_client_set_state.params); } if (arg->light_client_set_state.set_state) { - osi_free(arg->light_client_set_state.set_state); + bt_mesh_free(arg->light_client_set_state.set_state); } break; default: @@ -128,7 +128,7 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d } if (p_src_data->params) { - p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; @@ -197,7 +197,7 @@ static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg) } case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT: if (arg->params) { - osi_free(arg->params); + bt_mesh_free(arg->params); } break; default: diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index f61a3f3cdb..5f6fbaa0af 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -84,7 +84,7 @@ void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) switch (msg->act) { case BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR: BT_DBG("%s, BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR", __func__); - dst->proxy_client_add_filter_addr.addr = (uint16_t *)osi_calloc(src->proxy_client_add_filter_addr.addr_num << 1); + dst->proxy_client_add_filter_addr.addr = (uint16_t *)bt_mesh_calloc(src->proxy_client_add_filter_addr.addr_num << 1); if (dst->proxy_client_add_filter_addr.addr) { memcpy(dst->proxy_client_add_filter_addr.addr, src->proxy_client_add_filter_addr.addr, src->proxy_client_add_filter_addr.addr_num << 1); @@ -94,7 +94,7 @@ void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) break; case BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR: BT_DBG("%s, BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR", __func__); - dst->proxy_client_remove_filter_addr.addr = osi_calloc(src->proxy_client_remove_filter_addr.addr_num << 1); + dst->proxy_client_remove_filter_addr.addr = bt_mesh_calloc(src->proxy_client_remove_filter_addr.addr_num << 1); if (dst->proxy_client_remove_filter_addr.addr) { memcpy(dst->proxy_client_remove_filter_addr.addr, src->proxy_client_remove_filter_addr.addr, src->proxy_client_remove_filter_addr.addr_num << 1); @@ -104,7 +104,7 @@ void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) break; case BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA: BT_DBG("%s, BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA", __func__); - dst->store_node_comp_data.data = osi_calloc(src->store_node_comp_data.length); + dst->store_node_comp_data.data = bt_mesh_calloc(src->store_node_comp_data.length); if (dst->store_node_comp_data.data) { memcpy(dst->store_node_comp_data.data, src->store_node_comp_data.data, src->store_node_comp_data.length); } else { @@ -131,17 +131,17 @@ static void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR: if (arg->proxy_client_add_filter_addr.addr) { - osi_free(arg->proxy_client_add_filter_addr.addr); + bt_mesh_free(arg->proxy_client_add_filter_addr.addr); } break; case BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR: if (arg->proxy_client_remove_filter_addr.addr) { - osi_free(arg->proxy_client_remove_filter_addr.addr); + bt_mesh_free(arg->proxy_client_remove_filter_addr.addr); } break; case BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA: if (arg->store_node_comp_data.data) { - osi_free(arg->store_node_comp_data.data); + bt_mesh_free(arg->store_node_comp_data.data); } break; default: @@ -163,8 +163,8 @@ void btc_ble_mesh_model_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) case BTC_BLE_MESH_ACT_SERVER_MODEL_SEND: case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: { BT_DBG("%s, BTC_BLE_MESH_ACT_MODEL_SEND, src->model_send.length = %d", __func__, src->model_send.length); - dst->model_send.data = src->model_send.length ? (uint8_t *)osi_malloc(src->model_send.length) : NULL; - dst->model_send.ctx = osi_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); + dst->model_send.data = src->model_send.length ? (uint8_t *)bt_mesh_malloc(src->model_send.length) : NULL; + dst->model_send.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); if (src->model_send.length) { if (dst->model_send.data) { memcpy(dst->model_send.data, src->model_send.data, src->model_send.length); @@ -181,7 +181,7 @@ void btc_ble_mesh_model_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) } case BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE: BT_DBG("%s, BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE", __func__); - dst->model_update_state.value = osi_malloc(sizeof(esp_ble_mesh_server_state_value_t)); + dst->model_update_state.value = bt_mesh_malloc(sizeof(esp_ble_mesh_server_state_value_t)); if (dst->model_update_state.value) { memcpy(dst->model_update_state.value, src->model_update_state.value, sizeof(esp_ble_mesh_server_state_value_t)); @@ -210,15 +210,15 @@ static void btc_ble_mesh_model_arg_deep_free(btc_msg_t *msg) case BTC_BLE_MESH_ACT_SERVER_MODEL_SEND: case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: if (arg->model_send.data) { - osi_free(arg->model_send.data); + bt_mesh_free(arg->model_send.data); } if (arg->model_send.ctx) { - osi_free(arg->model_send.ctx); + bt_mesh_free(arg->model_send.ctx); } break; case BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE: if (arg->model_update_state.value) { - osi_free(arg->model_update_state.value); + bt_mesh_free(arg->model_update_state.value); } break; default: @@ -241,8 +241,8 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void switch (msg->act) { case ESP_BLE_MESH_MODEL_OPERATION_EVT: { if (p_src_data->model_operation.ctx && p_src_data->model_operation.msg) { - p_dest_data->model_operation.ctx = osi_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); - p_dest_data->model_operation.msg = p_src_data->model_operation.length ? (uint8_t *)osi_malloc(p_src_data->model_operation.length) : NULL; + p_dest_data->model_operation.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); + p_dest_data->model_operation.msg = p_src_data->model_operation.length ? (uint8_t *)bt_mesh_malloc(p_src_data->model_operation.length) : NULL; if (p_dest_data->model_operation.ctx) { memcpy(p_dest_data->model_operation.ctx, p_src_data->model_operation.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { @@ -260,8 +260,8 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void } case ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT: { if (p_src_data->client_recv_publish_msg.ctx && p_src_data->client_recv_publish_msg.msg) { - p_dest_data->client_recv_publish_msg.ctx = osi_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); - p_dest_data->client_recv_publish_msg.msg = p_src_data->client_recv_publish_msg.length ? (uint8_t *)osi_malloc(p_src_data->client_recv_publish_msg.length) : NULL; + p_dest_data->client_recv_publish_msg.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); + p_dest_data->client_recv_publish_msg.msg = p_src_data->client_recv_publish_msg.length ? (uint8_t *)bt_mesh_malloc(p_src_data->client_recv_publish_msg.length) : NULL; if (p_dest_data->client_recv_publish_msg.ctx) { memcpy(p_dest_data->client_recv_publish_msg.ctx, p_src_data->client_recv_publish_msg.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { @@ -279,7 +279,7 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void } case ESP_BLE_MESH_MODEL_SEND_COMP_EVT: { if (p_src_data->model_send_comp.ctx) { - p_dest_data->model_send_comp.ctx = osi_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); + p_dest_data->model_send_comp.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); if (p_dest_data->model_send_comp.ctx) { memcpy(p_dest_data->model_send_comp.ctx, p_src_data->model_send_comp.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { @@ -290,7 +290,7 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void } case ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT: { if (p_src_data->client_send_timeout.ctx) { - p_dest_data->client_send_timeout.ctx = osi_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); + p_dest_data->client_send_timeout.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); if (p_dest_data->client_send_timeout.ctx) { memcpy(p_dest_data->client_send_timeout.ctx, p_src_data->client_send_timeout.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { @@ -318,31 +318,31 @@ static void btc_ble_mesh_model_free_req_data(btc_msg_t *msg) switch (msg->act) { case ESP_BLE_MESH_MODEL_OPERATION_EVT: { if (arg->model_operation.msg) { - osi_free(arg->model_operation.msg); + bt_mesh_free(arg->model_operation.msg); } if (arg->model_operation.ctx) { - osi_free(arg->model_operation.ctx); + bt_mesh_free(arg->model_operation.ctx); } break; } case ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT: { if (arg->client_recv_publish_msg.msg) { - osi_free(arg->client_recv_publish_msg.msg); + bt_mesh_free(arg->client_recv_publish_msg.msg); } if (arg->client_recv_publish_msg.ctx) { - osi_free(arg->client_recv_publish_msg.ctx); + bt_mesh_free(arg->client_recv_publish_msg.ctx); } break; } case ESP_BLE_MESH_MODEL_SEND_COMP_EVT: { if (arg->model_send_comp.ctx) { - osi_free(arg->model_send_comp.ctx); + bt_mesh_free(arg->model_send_comp.ctx); } break; } case ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT: { if (arg->client_send_timeout.ctx) { - osi_free(arg->client_send_timeout.ctx); + bt_mesh_free(arg->client_send_timeout.ctx); } break; } @@ -934,9 +934,9 @@ static void btc_ble_mesh_proxy_client_filter_status_recv_cb(u8_t conn_handle, } #endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */ -int btc_ble_mesh_deinit(void) +int btc_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param) { - return bt_mesh_deinit(); + return bt_mesh_deinit((struct bt_mesh_deinit_param *)param); } int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c index dfc981753b..cc906d76dd 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -46,8 +46,8 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void switch (msg->act) { case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: { - dst->sensor_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); - dst->sensor_client_get_state.get_state = (esp_ble_mesh_sensor_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_sensor_client_get_state_t)); + dst->sensor_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->sensor_client_get_state.get_state = (esp_ble_mesh_sensor_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_get_state_t)); if (dst->sensor_client_get_state.params && dst->sensor_client_get_state.get_state) { memcpy(dst->sensor_client_get_state.params, src->sensor_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -101,8 +101,8 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: { - dst->sensor_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); - dst->sensor_client_set_state.set_state = (esp_ble_mesh_sensor_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_sensor_client_set_state_t)); + dst->sensor_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->sensor_client_set_state.set_state = (esp_ble_mesh_sensor_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_set_state_t)); if (dst->sensor_client_set_state.params && dst->sensor_client_set_state.set_state) { memcpy(dst->sensor_client_set_state.params, src->sensor_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -210,10 +210,10 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg) break; } } - osi_free(arg->sensor_client_get_state.get_state); + bt_mesh_free(arg->sensor_client_get_state.get_state); } if (arg->sensor_client_get_state.params) { - osi_free(arg->sensor_client_get_state.params); + bt_mesh_free(arg->sensor_client_get_state.params); } break; case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: @@ -233,10 +233,10 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg) break; } } - osi_free(arg->sensor_client_set_state.set_state); + bt_mesh_free(arg->sensor_client_set_state.set_state); } if (arg->sensor_client_set_state.params) { - osi_free(arg->sensor_client_set_state.params); + bt_mesh_free(arg->sensor_client_set_state.params); } break; default: @@ -256,7 +256,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des } if (p_src_data->params) { - p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; @@ -435,7 +435,7 @@ static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg) } case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT: if (arg->params) { - osi_free(arg->params); + bt_mesh_free(arg->params); } break; default: diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c index 89963a693e..d33702edd5 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -45,7 +45,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, switch (msg->act) { case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: { - dst->time_scene_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->time_scene_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->time_scene_client_get_state.params) { memcpy(dst->time_scene_client_get_state.params, src->time_scene_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -54,7 +54,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, break; } if (src->time_scene_client_get_state.get_state) { - dst->time_scene_client_get_state.get_state = (esp_ble_mesh_time_scene_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_time_scene_client_get_state_t)); + dst->time_scene_client_get_state.get_state = (esp_ble_mesh_time_scene_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_get_state_t)); if (dst->time_scene_client_get_state.get_state) { memcpy(dst->time_scene_client_get_state.get_state, src->time_scene_client_get_state.get_state, sizeof(esp_ble_mesh_time_scene_client_get_state_t)); @@ -65,8 +65,8 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, break; } case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: { - dst->time_scene_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); - dst->time_scene_client_set_state.set_state = (esp_ble_mesh_time_scene_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_time_scene_client_set_state_t)); + dst->time_scene_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + dst->time_scene_client_set_state.set_state = (esp_ble_mesh_time_scene_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_set_state_t)); if (dst->time_scene_client_set_state.params && dst->time_scene_client_set_state.set_state) { memcpy(dst->time_scene_client_set_state.params, src->time_scene_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); @@ -97,18 +97,18 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: if (arg->time_scene_client_get_state.params) { - osi_free(arg->time_scene_client_get_state.params); + bt_mesh_free(arg->time_scene_client_get_state.params); } if (arg->time_scene_client_get_state.get_state) { - osi_free(arg->time_scene_client_get_state.get_state); + bt_mesh_free(arg->time_scene_client_get_state.get_state); } break; case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: if (arg->time_scene_client_set_state.params) { - osi_free(arg->time_scene_client_set_state.params); + bt_mesh_free(arg->time_scene_client_set_state.params); } if (arg->time_scene_client_set_state.set_state) { - osi_free(arg->time_scene_client_set_state.set_state); + bt_mesh_free(arg->time_scene_client_set_state.set_state); } break; default: @@ -128,7 +128,7 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p } if (p_src_data->params) { - p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t)); + p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; @@ -199,7 +199,7 @@ static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg) } case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT: if (arg->params) { - osi_free(arg->params); + bt_mesh_free(arg->params); } break; default: diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h index 9410f0109e..dac671ec53 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h @@ -266,7 +266,7 @@ 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); -int btc_ble_mesh_deinit(void); +int btc_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param); int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model); diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h index 749b18095a..737b8394e7 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h @@ -19,9 +19,27 @@ #ifndef _BLE_MESH_COMMON_H_ #define _BLE_MESH_COMMON_H_ -#include "osi/allocator.h" +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" + +#include "esp_heap_caps.h" + #include "mesh_access.h" +#if CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST +#define bt_mesh_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) +#define bt_mesh_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) +#else +#define bt_mesh_malloc(size) malloc((size)) +#define bt_mesh_calloc(size) calloc(1, (size)) +#endif /* CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST */ +#define bt_mesh_free(p) free((p)) + /** * @brief This function allocates memory to store outgoing message. * @@ -54,4 +72,19 @@ void bt_mesh_free_buf(struct net_buf_simple *buf); */ u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send); +typedef struct { + SemaphoreHandle_t mutex; +#if CONFIG_SPIRAM_USE_MALLOC + StaticQueue_t *buffer; +#endif +} bt_mesh_mutex_t; + +void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex); + +void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex); + +void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex); + +void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex); + #endif /* _BLE_MESH_COMMON_H_ */ \ No newline at end of file diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h index c1843d4d7d..e0052e5289 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h @@ -8,7 +8,6 @@ #ifndef _BLE_MESH_KERNEL_H_ #define _BLE_MESH_KERNEL_H_ -#include "osi/mutex.h" #include "mesh_types.h" #include "mesh_slist.h" #include "mesh_atomic.h" diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c index 5bca0c8a7c..5aa4a13253 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c @@ -24,7 +24,7 @@ struct net_buf_simple *bt_mesh_alloc_buf(u16_t size) struct net_buf_simple *buf = NULL; u8_t *data = NULL; - buf = (struct net_buf_simple *)osi_calloc(sizeof(struct net_buf_simple) + size); + buf = (struct net_buf_simple *)bt_mesh_calloc(sizeof(struct net_buf_simple) + size); if (!buf) { BT_ERR("%s, Failed to allocate memory", __func__); return NULL; @@ -43,7 +43,7 @@ struct net_buf_simple *bt_mesh_alloc_buf(u16_t size) void bt_mesh_free_buf(struct net_buf_simple *buf) { if (buf) { - osi_free(buf); + bt_mesh_free(buf); } } @@ -65,3 +65,62 @@ u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send) return client->msg_role; } + +void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex) +{ + if (!mutex) { + BT_ERR("%s, Invalid mutex", __func__); + return; + } + +#if CONFIG_SPIRAM_USE_MALLOC + mutex->buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); + __ASSERT(mutex->buffer, "%s, Failed to create queue buffer", __func__); + mutex->mutex = xSemaphoreCreateMutexStatic(mutex->buffer); + __ASSERT(mutex->mutex, "%s, Failed to create static mutex", __func__); +#else + mutex->mutex = xSemaphoreCreateMutex(); + __ASSERT(mutex->mutex, "%s, Failed to create mutex", __func__); +#endif +} + +void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex) +{ + if (!mutex) { + BT_ERR("%s, Invalid mutex", __func__); + return; + } + + if (mutex->mutex) { + vSemaphoreDelete(mutex->mutex); + mutex->mutex = NULL; +#if CONFIG_SPIRAM_USE_MALLOC + heap_caps_free(mutex->buffer); + mutex->buffer = NULL; +#endif + } +} + +void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex) +{ + if (!mutex) { + BT_ERR("%s, Invalid mutex", __func__); + return; + } + + if (mutex->mutex) { + xSemaphoreTake(mutex->mutex, portMAX_DELAY); + } +} + +void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex) +{ + if (!mutex) { + BT_ERR("%s, Invalid mutex", __func__); + return; + } + + if (mutex->mutex) { + xSemaphoreGive(mutex->mutex); + } +} diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c b/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c index 02cac1e2ec..d4597d8184 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_kernel.c @@ -12,14 +12,13 @@ #include "osi/alarm.h" #include "osi/hash_functions.h" -#include "mesh_kernel.h" -#include "mesh_trace.h" +#include "mesh_common.h" #include "provisioner_prov.h" -static osi_mutex_t bm_alarm_lock; -static osi_mutex_t bm_list_lock; -static osi_mutex_t bm_buf_lock; -static osi_mutex_t bm_atomic_lock; +static bt_mesh_mutex_t bm_alarm_lock; +static bt_mesh_mutex_t bm_list_lock; +static bt_mesh_mutex_t bm_buf_lock; +static bt_mesh_mutex_t bm_atomic_lock; static hash_map_t *bm_alarm_hash_map; static const size_t BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE = 20 + CONFIG_BLE_MESH_PBA_SAME_TIME + \ CONFIG_BLE_MESH_PBG_SAME_TIME; @@ -34,122 +33,90 @@ typedef struct alarm_t { static void bt_mesh_alarm_mutex_new(void) { - if (!bm_alarm_lock) { - osi_mutex_new(&bm_alarm_lock); - __ASSERT(bm_alarm_lock, "%s, fail", __func__); + if (!bm_alarm_lock.mutex) { + bt_mesh_mutex_create(&bm_alarm_lock); } } static void bt_mesh_alarm_mutex_free(void) { - if (bm_alarm_lock) { - osi_mutex_free(&bm_alarm_lock); - bm_alarm_lock = NULL; - } + bt_mesh_mutex_free(&bm_alarm_lock); } static void bt_mesh_alarm_lock(void) { - if (bm_alarm_lock) { - osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&bm_alarm_lock); } static void bt_mesh_alarm_unlock(void) { - if (bm_alarm_lock) { - osi_mutex_unlock(&bm_alarm_lock); - } + bt_mesh_mutex_unlock(&bm_alarm_lock); } static void bt_mesh_list_mutex_new(void) { - if (!bm_list_lock) { - osi_mutex_new(&bm_list_lock); - __ASSERT(bm_list_lock, "%s, fail", __func__); + if (!bm_list_lock.mutex) { + bt_mesh_mutex_create(&bm_list_lock); } } static void bt_mesh_list_mutex_free(void) { - if (bm_list_lock) { - osi_mutex_free(&bm_list_lock); - bm_list_lock = NULL; - } + bt_mesh_mutex_free(&bm_list_lock); } void bt_mesh_list_lock(void) { - if (bm_list_lock) { - osi_mutex_lock(&bm_list_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&bm_list_lock); } void bt_mesh_list_unlock(void) { - if (bm_list_lock) { - osi_mutex_unlock(&bm_list_lock); - } + bt_mesh_mutex_unlock(&bm_list_lock); } static void bt_mesh_buf_mutex_new(void) { - if (!bm_buf_lock) { - osi_mutex_new(&bm_buf_lock); - __ASSERT(bm_buf_lock, "%s, fail", __func__); + if (!bm_buf_lock.mutex) { + bt_mesh_mutex_create(&bm_buf_lock); } } static void bt_mesh_buf_mutex_free(void) { - if (bm_buf_lock) { - osi_mutex_free(&bm_buf_lock); - bm_buf_lock = NULL; - } + bt_mesh_mutex_free(&bm_buf_lock); } void bt_mesh_buf_lock(void) { - if (bm_buf_lock) { - osi_mutex_lock(&bm_buf_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&bm_buf_lock); } void bt_mesh_buf_unlock(void) { - if (bm_buf_lock) { - osi_mutex_unlock(&bm_buf_lock); - } + bt_mesh_mutex_unlock(&bm_buf_lock); } static void bt_mesh_atomic_mutex_new(void) { - if (!bm_atomic_lock) { - osi_mutex_new(&bm_atomic_lock); - __ASSERT(bm_atomic_lock, "%s, fail", __func__); + if (!bm_atomic_lock.mutex) { + bt_mesh_mutex_create(&bm_atomic_lock); } } static void bt_mesh_atomic_mutex_free(void) { - if (bm_atomic_lock) { - osi_mutex_free(&bm_atomic_lock); - bm_atomic_lock = NULL; - } + bt_mesh_mutex_free(&bm_atomic_lock); } void bt_mesh_atomic_lock(void) { - if (bm_atomic_lock) { - osi_mutex_lock(&bm_atomic_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&bm_atomic_lock); } void bt_mesh_atomic_unlock(void) { - if (bm_atomic_lock) { - osi_mutex_unlock(&bm_atomic_lock); - } + bt_mesh_mutex_unlock(&bm_atomic_lock); } s64_t k_uptime_get(void) @@ -183,7 +150,7 @@ void bt_mesh_k_init(void) bm_alarm_hash_map = hash_map_new(BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE, hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL); - assert(bm_alarm_hash_map != NULL); + __ASSERT(bm_alarm_hash_map, "%s, Failed to create hash map", __func__); } void bt_mesh_k_deinit(void) @@ -202,7 +169,10 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) { osi_alarm_t *alarm = NULL; - assert(work != NULL && bm_alarm_hash_map != NULL); + if (!work || !bm_alarm_hash_map) { + BT_ERR("%s, Invalid parameter", __func__); + return; + } k_work_init(&work->work, handler); @@ -233,7 +203,10 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay) { - assert(work != NULL && bm_alarm_hash_map != NULL); + if (!work || !bm_alarm_hash_map) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { @@ -249,7 +222,10 @@ int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay) int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period) { - assert(work != NULL && bm_alarm_hash_map != NULL); + if (!work || !bm_alarm_hash_map) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { @@ -266,7 +242,10 @@ int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period) int k_delayed_work_cancel(struct k_delayed_work *work) { - assert(work != NULL && bm_alarm_hash_map != NULL); + if (!work || !bm_alarm_hash_map) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { @@ -281,7 +260,10 @@ int k_delayed_work_cancel(struct k_delayed_work *work) int k_delayed_work_free(struct k_delayed_work *work) { - assert(work != NULL && bm_alarm_hash_map != NULL); + if (!work || !bm_alarm_hash_map) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work); if (alarm == NULL) { @@ -296,7 +278,10 @@ int k_delayed_work_free(struct k_delayed_work *work) s32_t k_delayed_work_remaining_get(struct k_delayed_work *work) { - assert(work != NULL && bm_alarm_hash_map != NULL); + if (!work || !bm_alarm_hash_map) { + BT_ERR("%s, Invalid parameter", __func__); + return 0; + } osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index 5b5544acf0..4448feab4b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -67,7 +67,15 @@ NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME]; -static QueueHandle_t xBleMeshQueue; +struct bt_mesh_queue { + QueueHandle_t queue; +#if CONFIG_SPIRAM_USE_MALLOC + StaticQueue_t *buffer; + u8_t *storage; +#endif +}; + +static struct bt_mesh_queue xBleMeshQueue; #define BLE_MESH_QUEUE_SIZE 150 #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) @@ -76,7 +84,7 @@ NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT, static struct bt_mesh_adv relay_adv_pool[CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT]; -static QueueHandle_t xBleMeshRelayQueue; +static struct bt_mesh_queue xBleMeshRelayQueue; #define BLE_MESH_RELAY_QUEUE_SIZE 150 static QueueSetHandle_t xBleMeshQueueSet; @@ -88,7 +96,15 @@ static QueueSetHandle_t xBleMeshQueueSet; static bool ignore_relay_packet(u32_t timestamp); #endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ -static TaskHandle_t adv_task_handle; +struct bt_mesh_adv_task { + TaskHandle_t handle; +#if CONFIG_SPIRAM_USE_MALLOC + StaticTask_t *task; + StackType_t *stack; +#endif +}; + +static struct bt_mesh_adv_task adv_task; static struct bt_mesh_adv *adv_alloc(int id) { @@ -190,28 +206,28 @@ static void adv_thread(void *p) #if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER - xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT); + xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); while (!(*buf)) { s32_t timeout; BT_DBG("Mesh Proxy Advertising start"); timeout = bt_mesh_proxy_adv_start(); BT_DBG("Mesh Proxy Advertising up to %d ms", timeout); - xQueueReceive(xBleMeshQueue, &msg, timeout); + xQueueReceive(xBleMeshQueue.queue, &msg, timeout); BT_DBG("Mesh Proxy Advertising stop"); bt_mesh_proxy_adv_stop(); } #else - xQueueReceive(xBleMeshQueue, &msg, portMAX_DELAY); + xQueueReceive(xBleMeshQueue.queue, &msg, portMAX_DELAY); #endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */ #else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT); if (handle) { - if (uxQueueMessagesWaiting(xBleMeshQueue)) { - xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT); - } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) { - xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT); + if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) { + xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); + } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { + xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT); } } else { while (!(*buf)) { @@ -223,10 +239,10 @@ static void adv_thread(void *p) BT_DBG("Mesh Proxy Advertising stop"); bt_mesh_proxy_adv_stop(); if (handle) { - if (uxQueueMessagesWaiting(xBleMeshQueue)) { - xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT); - } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) { - xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT); + if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) { + xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); + } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { + xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT); } } } @@ -234,10 +250,10 @@ static void adv_thread(void *p) #else handle = xQueueSelectFromSet(xBleMeshQueueSet, portMAX_DELAY); if (handle) { - if (uxQueueMessagesWaiting(xBleMeshQueue)) { - xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT); - } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) { - xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT); + if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) { + xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); + } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { + xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT); } } #endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */ @@ -374,7 +390,13 @@ static void bt_mesh_unref_buf(bt_mesh_msg_t *msg) static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout) { BT_DBG("%s", __func__); - if (xQueueSend(xBleMeshQueue, msg, timeout) != pdTRUE) { + + if (xBleMeshQueue.queue == NULL) { + BT_ERR("%s, Invalid queue", __func__); + return; + } + + if (xQueueSend(xBleMeshQueue.queue, msg, timeout) != pdTRUE) { BT_ERR("%s, Failed to send item to queue", __func__); bt_mesh_unref_buf(msg); } @@ -446,7 +468,12 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) BT_DBG("%s", __func__); - if (xQueueSend(xBleMeshRelayQueue, msg, timeout) == pdTRUE) { + if (xBleMeshRelayQueue.queue == NULL) { + BT_ERR("%s, Invalid relay queue", __func__); + return; + } + + if (xQueueSend(xBleMeshRelayQueue.queue, msg, timeout) == pdTRUE) { return; } @@ -455,10 +482,10 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) * remove the oldest packet in the queue and put the new one into it. */ handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT); - if (handle && uxQueueMessagesWaiting(xBleMeshRelayQueue)) { + if (handle && uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { BT_INFO("%s, Full queue, remove the oldest relay packet", __func__); /* Remove the oldest relay packet from queue */ - if (xQueueReceive(xBleMeshRelayQueue, &old_msg, K_NO_WAIT) != pdTRUE) { + if (xQueueReceive(xBleMeshRelayQueue.queue, &old_msg, K_NO_WAIT) != pdTRUE) { BT_ERR("%s, Failed to remove item from queue", __func__); bt_mesh_unref_buf(msg); return; @@ -466,7 +493,7 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) /* Unref buf used for the oldest relay packet */ bt_mesh_unref_buf(&old_msg); /* Send the latest relay packet to queue */ - if (xQueueSend(xBleMeshRelayQueue, msg, K_NO_WAIT) != pdTRUE) { + if (xQueueSend(xBleMeshRelayQueue.queue, msg, K_NO_WAIT) != pdTRUE) { BT_ERR("%s, Failed to send item to relay queue", __func__); bt_mesh_unref_buf(msg); return; @@ -501,7 +528,7 @@ void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *c u16_t bt_mesh_get_stored_relay_count(void) { - return (u16_t)uxQueueMessagesWaiting(xBleMeshRelayQueue); + return (u16_t)uxQueueMessagesWaiting(xBleMeshRelayQueue.queue); } #endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ @@ -709,39 +736,105 @@ extern bool lld_evt_adv_delay_time(uint8_t time); void bt_mesh_adv_init(void) { lld_evt_adv_delay_time(0); /* disable adv random delay */ - xBleMeshQueue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); - configASSERT(xBleMeshQueue); + +#if !CONFIG_SPIRAM_USE_MALLOC + xBleMeshQueue.queue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); + __ASSERT(xBleMeshQueue.queue, "%s, Failed to create queue", __func__); +#else + xBleMeshQueue.buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); + __ASSERT(xBleMeshQueue.buffer, "%s, Failed to create queue buffer", __func__); + xBleMeshQueue.storage = heap_caps_calloc(1, (BLE_MESH_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); + __ASSERT(xBleMeshQueue.storage, "%s, Failed to create queue storage", __func__); + xBleMeshQueue.queue = xQueueCreateStatic(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshQueue.storage, xBleMeshQueue.buffer); + __ASSERT(xBleMeshQueue.queue, "%s, Failed to create static queue", __func__); +#endif + #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) - xBleMeshRelayQueue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); - configASSERT(xBleMeshRelayQueue); +#if !CONFIG_SPIRAM_USE_MALLOC + xBleMeshRelayQueue.queue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); + __ASSERT(xBleMeshRelayQueue.queue, "%s, Failed to create relay queue", __func__); +#else + xBleMeshRelayQueue.buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); + __ASSERT(xBleMeshRelayQueue.buffer, "%s, Failed to create relay queue buffer", __func__); + xBleMeshRelayQueue.storage = heap_caps_calloc(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); + __ASSERT(xBleMeshRelayQueue.storage, "%s, Failed to create relay queue storage", __func__); + xBleMeshRelayQueue.queue = xQueueCreateStatic(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshRelayQueue.storage, xBleMeshRelayQueue.buffer); + __ASSERT(xBleMeshRelayQueue.queue, "%s, Failed to create static relay queue", __func__); +#endif + xBleMeshQueueSet = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE); - configASSERT(xBleMeshQueueSet); - xQueueAddToSet(xBleMeshQueue, xBleMeshQueueSet); - xQueueAddToSet(xBleMeshRelayQueue, xBleMeshQueueSet); + __ASSERT(xBleMeshQueueSet, "%s, Failed to create queue set", __func__); + xQueueAddToSet(xBleMeshQueue.queue, xBleMeshQueueSet); + xQueueAddToSet(xBleMeshRelayQueue.queue, xBleMeshQueueSet); #endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ - int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL, - configMAX_PRIORITIES - 5, &adv_task_handle, ADV_TASK_CORE); - configASSERT(ret == pdTRUE); + +#if !CONFIG_SPIRAM_USE_MALLOC + int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL, + configMAX_PRIORITIES - 5, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); + __ASSERT(ret == pdTRUE, "%s, Failed to create adv thread", __func__); +#else + adv_task.task = heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + __ASSERT(adv_task.task, "%s, Failed to create adv thread task", __func__); +#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY + adv_task.stack = heap_caps_calloc(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); +#else + adv_task.stack = heap_caps_calloc(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#endif + __ASSERT(adv_task.stack, "%s, Failed to create adv thread stack", __func__); + adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL, + configMAX_PRIORITIES - 5, adv_task.stack, adv_task.task, BLE_MESH_ADV_TASK_CORE); + __ASSERT(adv_task.stack, "%s, Failed to create static adv thread stack", __func__); +#endif } void bt_mesh_adv_deinit(void) { - if (xBleMeshQueue == NULL) { + if (xBleMeshQueue.queue == NULL) { return; } #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) - xQueueRemoveFromSet(xBleMeshQueue, xBleMeshQueueSet); - xQueueRemoveFromSet(xBleMeshRelayQueue, xBleMeshQueueSet); - vQueueDelete(xBleMeshRelayQueue); + xQueueRemoveFromSet(xBleMeshQueue.queue, xBleMeshQueueSet); + xQueueRemoveFromSet(xBleMeshRelayQueue.queue, xBleMeshQueueSet); + + vQueueDelete(xBleMeshRelayQueue.queue); + xBleMeshRelayQueue.queue = NULL; +#if CONFIG_SPIRAM_USE_MALLOC + heap_caps_free(xBleMeshRelayQueue.buffer); + xBleMeshRelayQueue.buffer = NULL; + heap_caps_free(xBleMeshRelayQueue.storage); + xBleMeshRelayQueue.storage = NULL; +#endif + bt_mesh_unref_buf_from_pool(&relay_adv_buf_pool); memset(relay_adv_pool, 0, sizeof(relay_adv_pool)); + vQueueDelete(xBleMeshQueueSet); + xBleMeshQueueSet = NULL; #endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ - vQueueDelete(xBleMeshQueue); + + vQueueDelete(xBleMeshQueue.queue); + xBleMeshQueue.queue = NULL; +#if CONFIG_SPIRAM_USE_MALLOC + heap_caps_free(xBleMeshQueue.buffer); + xBleMeshQueue.buffer = NULL; + heap_caps_free(xBleMeshQueue.storage); + xBleMeshQueue.storage = NULL; +#endif + bt_mesh_unref_buf_from_pool(&adv_buf_pool); memset(adv_pool, 0, sizeof(adv_pool)); - vTaskDelete(adv_task_handle); + + vTaskDelete(adv_task.handle); + adv_task.handle = NULL; +#if CONFIG_SPIRAM_USE_MALLOC + heap_caps_free(adv_task.stack); + adv_task.stack = NULL; + /* Delay certain period for free adv_task.task */ + vTaskDelay(10 / portTICK_PERIOD_MS); + heap_caps_free(adv_task.task); + adv_task.task = NULL; +#endif } int bt_mesh_scan_enable(void) diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index 5abadf7362..80998d2024 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -316,7 +316,7 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC if (bt_mesh_scan_dev_found_cb != NULL) { bt_mesh_scan_dev_found_cb(&addr, rssi, adv_type, buf); } - osi_free(buf); + bt_mesh_free(buf); } else if (event == BTA_DM_INQ_CMPL_EVT) { BT_INFO("%s, Scan completed, number of scan response %d", __func__, p_data->inq_cmpl.num_resps); } else { @@ -1369,28 +1369,28 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (num != 1) { - osi_free(result); + bt_mesh_free(result); bt_mesh_gattc_disconnect(conn); return; } if (!j) { if (!(result[0].properties & BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP)) { - osi_free(result); + bt_mesh_free(result); bt_mesh_gattc_disconnect(conn); return; } bt_mesh_gattc_info[i].data_in_handle = result[0].attribute_handle; } else { if (!(result[0].properties & BLE_MESH_GATT_CHRC_NOTIFY)) { - osi_free(result); + bt_mesh_free(result); bt_mesh_gattc_disconnect(conn); return; } bt_mesh_gattc_info[i].data_out_handle = result[0].attribute_handle; } - osi_free(result); + bt_mesh_free(result); result = NULL; } @@ -1424,7 +1424,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (num != 1) { - osi_free(result); + bt_mesh_free(result); bt_mesh_gattc_disconnect(conn); return; } @@ -1439,7 +1439,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) BTA_GATTC_WriteCharDescr(p_data->search_cmpl.conn_id, result[0].attribute_handle, BTA_GATTC_TYPE_WRITE, &write, BTA_GATT_AUTH_REQ_NONE); - osi_free(result); + bt_mesh_free(result); result = NULL; } break; @@ -1709,11 +1709,28 @@ void bt_mesh_gatt_deinit(void) #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER BTA_GATTS_AppDeregister(bt_mesh_gatts_if); + memset(bt_mesh_gatts_addr, 0, BLE_MESH_ADDR_LEN); + bt_mesh_gatts_if = 0U; + svc_handle = 0U; + char_handle = 0U; #endif #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_CLIENT BTA_GATTC_AppDeregister(bt_mesh_gattc_if); + bt_mesh_gattc_if = 0U; + for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { + bt_mesh_gattc_info[i].conn.handle = 0xFFFF; + memset(&bt_mesh_gattc_info[i].addr, 0, sizeof(bt_mesh_addr_t)); + bt_mesh_gattc_info[i].service_uuid = 0U; + bt_mesh_gattc_info[i].mtu = GATT_DEF_BLE_MTU_SIZE; /* Default MTU_SIZE 23 */ + bt_mesh_gattc_info[i].wr_desc_done = false; + bt_mesh_gattc_info[i].start_handle = 0U; + bt_mesh_gattc_info[i].end_handle = 0U; + bt_mesh_gattc_info[i].data_in_handle = 0U; + bt_mesh_gattc_info[i].data_out_handle = 0U; + bt_mesh_gattc_info[i].ccc_handle = 0U; + } #endif } diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index c741fc56af..9ca4c2e32d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -79,36 +79,28 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = { { OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS }, }; -static osi_mutex_t cfg_client_lock; +static bt_mesh_mutex_t cfg_client_lock; static void bt_mesh_cfg_client_mutex_new(void) { - if (!cfg_client_lock) { - osi_mutex_new(&cfg_client_lock); - __ASSERT(cfg_client_lock, "%s, fail", __func__); + if (!cfg_client_lock.mutex) { + bt_mesh_mutex_create(&cfg_client_lock); } } static void bt_mesh_cfg_client_mutex_free(void) { - if (cfg_client_lock) { - osi_mutex_free(&cfg_client_lock); - cfg_client_lock = NULL; - } + bt_mesh_mutex_free(&cfg_client_lock); } static void bt_mesh_cfg_client_lock(void) { - if (cfg_client_lock) { - osi_mutex_lock(&cfg_client_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&cfg_client_lock); } static void bt_mesh_cfg_client_unlock(void) { - if (cfg_client_lock) { - osi_mutex_unlock(&cfg_client_lock); - } + bt_mesh_mutex_unlock(&cfg_client_lock); } static void timeout_handler(struct k_work *work) @@ -1659,7 +1651,7 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) } if (!client->internal_data) { - internal = osi_calloc(sizeof(config_internal_data_t)); + internal = bt_mesh_calloc(sizeof(config_internal_data_t)); if (!internal) { BT_ERR("Allocate memory for Configuration Client internal data fail"); return -ENOMEM; @@ -1710,7 +1702,7 @@ int bt_mesh_cfg_cli_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ - osi_free(client->internal_data); + bt_mesh_free(client->internal_data); cli->internal_data = NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index b6fcc775bf..75a025bfda 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -32,36 +32,28 @@ static const bt_mesh_client_op_pair_t health_op_pair[] = { { OP_ATTENTION_SET, OP_ATTENTION_STATUS }, }; -static osi_mutex_t health_client_lock; +static bt_mesh_mutex_t health_client_lock; static void bt_mesh_health_client_mutex_new(void) { - if (!health_client_lock) { - osi_mutex_new(&health_client_lock); - __ASSERT(health_client_lock, "%s, fail", __func__); + if (!health_client_lock.mutex) { + bt_mesh_mutex_create(&health_client_lock); } } static void bt_mesh_health_client_mutex_free(void) { - if (health_client_lock) { - osi_mutex_free(&health_client_lock); - health_client_lock = NULL; - } + bt_mesh_mutex_free(&health_client_lock); } static void bt_mesh_health_client_lock(void) { - if (health_client_lock) { - osi_mutex_lock(&health_client_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&health_client_lock); } static void bt_mesh_health_client_unlock(void) { - if (health_client_lock) { - osi_mutex_unlock(&health_client_lock); - } + bt_mesh_mutex_unlock(&health_client_lock); } static void timeout_handler(struct k_work *work) @@ -464,7 +456,7 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) } if (!client->internal_data) { - internal = osi_calloc(sizeof(health_internal_data_t)); + internal = bt_mesh_calloc(sizeof(health_internal_data_t)); if (!internal) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -510,7 +502,7 @@ int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ - osi_free(client->internal_data); + bt_mesh_free(client->internal_data); client->internal_data = NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h index 8fc440be63..7c3ead1d0a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h @@ -20,20 +20,22 @@ #define BLE_MESH_MAX_CONN \ MIN(CONFIG_BT_ACL_CONNECTIONS, CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN) -#define ADV_TASK_CORE TASK_PINNED_TO_CORE +#define BLE_MESH_ADV_TASK_CORE TASK_PINNED_TO_CORE #endif #ifdef CONFIG_BT_NIMBLE_ENABLED #define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS #ifdef CONFIG_BT_NIMBLE_PINNED_TO_CORE -#define ADV_TASK_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY) +#define BLE_MESH_ADV_TASK_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY) #else -#define ADV_TASK_CORE (0) +#define BLE_MESH_ADV_TASK_CORE (0) #endif #endif +#define BLE_MESH_ADV_TASK_STACK_SIZE 3072 + #define BLE_MESH_GAP_ADV_MAX_LEN 31 #define BLE_MESH_GATT_DEF_MTU_SIZE 23 diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h index 58b82535d5..688c3a8a68 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h @@ -471,11 +471,18 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers); int bt_mesh_init(const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp); +/* BLE Mesh deinit parameters */ +struct bt_mesh_deinit_param { + bool erase; /* Indicate if erasing flash when deinit mesh stack */ +}; + /** @brief De-initialize Mesh support + * + * @param param BLE Mesh deinit parameters. * * @return Zero on success or (negative) error code otherwise. */ -int bt_mesh_deinit(void); +int bt_mesh_deinit(struct bt_mesh_deinit_param *param); /** @brief Reset the state of the local Mesh node. * diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index 9dfb2d27ee..dcec933db3 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -23,6 +23,7 @@ #include "settings.h" #include "mesh.h" #include "mesh_hci.h" +#include "mesh_common.h" #include "proxy_client.h" #include "proxy_server.h" #include "provisioner_prov.h" @@ -376,10 +377,15 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, return 0; } -int bt_mesh_deinit(void) +int bt_mesh_deinit(struct bt_mesh_deinit_param *param) { int err = 0; + if (param == NULL) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } + if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) { if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV)) { bt_mesh_beacon_disable(); @@ -408,15 +414,15 @@ int bt_mesh_deinit(void) } } if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) { - err = bt_mesh_provisioner_prov_deinit(); + err = bt_mesh_provisioner_prov_deinit(param->erase); if (err) { return err; } } } - bt_mesh_trans_deinit(); - bt_mesh_net_deinit(); + bt_mesh_trans_deinit(param->erase); + bt_mesh_net_deinit(param->erase); if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) { bt_mesh_beacon_deinit(); @@ -437,7 +443,7 @@ int bt_mesh_deinit(void) bt_mesh_gatt_deinit(); if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) { - err = bt_mesh_provisioner_deinit(); + err = bt_mesh_provisioner_deinit(param->erase); if (err) { return err; } @@ -459,6 +465,9 @@ int bt_mesh_deinit(void) } if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + if (param->erase) { + bt_mesh_clear_role(); + } bt_mesh_settings_deinit(); } @@ -633,6 +642,7 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action) if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { bt_mesh_provisioner_pb_gatt_enable(); } + bt_mesh_provisioner_set_prov_bearer(BLE_MESH_PROV_ADV, false); bt_mesh_provisioner_fast_prov_enable(true); bt_mesh_atomic_or(bt_mesh.flags, BIT(BLE_MESH_PROVISIONER) | BIT(BLE_MESH_VALID_PROV)); } else { diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index e7b84303b9..a06d62e5ae 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -1525,7 +1525,7 @@ void bt_mesh_net_init(void) k_work_init(&bt_mesh.local_work, bt_mesh_net_local); } -void bt_mesh_net_deinit(void) +void bt_mesh_net_deinit(bool erase) { k_delayed_work_free(&bt_mesh.ivu_timer); @@ -1549,4 +1549,9 @@ void bt_mesh_net_deinit(void) bt_mesh.seq = 0U; memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags)); + + if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + bt_mesh_clear_seq(); + bt_mesh_clear_iv(); + } } diff --git a/components/bt/esp_ble_mesh/mesh_core/net.h b/components/bt/esp_ble_mesh/mesh_core/net.h index 9d3847e20f..abdb57450f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.h +++ b/components/bt/esp_ble_mesh/mesh_core/net.h @@ -371,7 +371,7 @@ u32_t bt_mesh_next_seq(void); void bt_mesh_net_start(void); void bt_mesh_net_init(void); -void bt_mesh_net_deinit(void); +void bt_mesh_net_deinit(bool erase); void bt_mesh_net_header_parse(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx); diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index 9c9608984a..54aa439e4c 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -396,7 +396,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg) if (bt_mesh_scan_dev_found_cb) { bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, buf); } - osi_free(buf); + bt_mesh_free(buf); break; #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_CLIENT diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.c b/components/bt/esp_ble_mesh/mesh_core/prov.c index eed16726de..4a0538931f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/prov.c @@ -202,36 +202,28 @@ static struct prov_link link; static const struct bt_mesh_prov *prov; #if defined(CONFIG_BLE_MESH_PB_ADV) -static osi_mutex_t pb_buf_lock; +static bt_mesh_mutex_t pb_buf_lock; static void bt_mesh_pb_buf_mutex_new(void) { - if (!pb_buf_lock) { - osi_mutex_new(&pb_buf_lock); - __ASSERT(pb_buf_lock, "%s, fail", __func__); + if (!pb_buf_lock.mutex) { + bt_mesh_mutex_create(&pb_buf_lock); } } static void bt_mesh_pb_buf_mutex_free(void) { - if (pb_buf_lock) { - osi_mutex_free(&pb_buf_lock); - pb_buf_lock = NULL; - } + bt_mesh_mutex_free(&pb_buf_lock); } static void bt_mesh_pb_buf_lock(void) { - if (pb_buf_lock) { - osi_mutex_lock(&pb_buf_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&pb_buf_lock); } static void bt_mesh_pb_buf_unlock(void) { - if (pb_buf_lock) { - osi_mutex_unlock(&pb_buf_lock); - } + bt_mesh_mutex_unlock(&pb_buf_lock); } #endif /* CONFIG_BLE_MESH_PB_ADV */ diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c index 995ab7b963..dcf3421f45 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c @@ -29,40 +29,32 @@ #if CONFIG_BLE_MESH_PROVISIONER static struct bt_mesh_node *mesh_nodes[CONFIG_BLE_MESH_MAX_STORED_NODES]; -static osi_mutex_t provisioner_lock; +static bt_mesh_mutex_t provisioner_lock; static u16_t all_node_count; static u16_t prov_node_count; -static int provisioner_remove_node(u16_t index); +static int provisioner_remove_node(u16_t index, bool erase); static void bt_mesh_provisioner_mutex_new(void) { - if (!provisioner_lock) { - osi_mutex_new(&provisioner_lock); - __ASSERT(provisioner_lock, "%s, fail", __func__); + if (!provisioner_lock.mutex) { + bt_mesh_mutex_create(&provisioner_lock); } } static void bt_mesh_provisioner_mutex_free(void) { - if (provisioner_lock) { - osi_mutex_free(&provisioner_lock); - provisioner_lock = NULL; - } + bt_mesh_mutex_free(&provisioner_lock); } static void bt_mesh_provisioner_lock(void) { - if (provisioner_lock) { - osi_mutex_lock(&provisioner_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&provisioner_lock); } static void bt_mesh_provisioner_unlock(void) { - if (provisioner_lock) { - osi_mutex_unlock(&provisioner_lock); - } + bt_mesh_mutex_unlock(&provisioner_lock); } int bt_mesh_provisioner_init(void) @@ -111,7 +103,7 @@ int bt_mesh_provisioner_net_create(void) return -EIO; } - sub = osi_calloc(sizeof(struct bt_mesh_subnet)); + sub = bt_mesh_calloc(sizeof(struct bt_mesh_subnet)); if (!sub) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -121,7 +113,7 @@ int bt_mesh_provisioner_net_create(void) if (sub->kr_flag) { if (bt_mesh_net_keys_create(&sub->keys[1], p_key)) { BT_ERR("%s, Failed to generate net-related keys", __func__); - osi_free(sub); + bt_mesh_free(sub); return -EIO; } sub->kr_phase = BLE_MESH_KR_PHASE_2; @@ -129,7 +121,7 @@ int bt_mesh_provisioner_net_create(void) /* Currently provisioner only use keys[0] */ if (bt_mesh_net_keys_create(&sub->keys[0], p_key)) { BT_ERR("%s, Failed to create net-related keys", __func__); - osi_free(sub); + bt_mesh_free(sub); return -EIO; } sub->kr_phase = BLE_MESH_KR_NORMAL; @@ -171,39 +163,39 @@ done: return 0; } -int bt_mesh_provisioner_deinit(void) +int bt_mesh_provisioner_deinit(bool erase) { int i; for (i = 0; i < CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT; i++) { if (bt_mesh.p_sub[i]) { - if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_clear_p_subnet(bt_mesh.p_sub[i]); } - osi_free(bt_mesh.p_sub[i]); + bt_mesh_free(bt_mesh.p_sub[i]); bt_mesh.p_sub[i] = NULL; } } for (i = 0; i < CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT; i++) { if (bt_mesh.p_app_keys[i]) { - if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_clear_p_app_key(bt_mesh.p_app_keys[i]); } - osi_free(bt_mesh.p_app_keys[i]); + bt_mesh_free(bt_mesh.p_app_keys[i]); bt_mesh.p_app_keys[i] = NULL; } } bt_mesh.p_net_idx_next = 0U; bt_mesh.p_app_idx_next = 0U; - if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_clear_p_net_idx(); bt_mesh_clear_p_app_idx(); } for (i = 0; i < CONFIG_BLE_MESH_MAX_STORED_NODES; i++) { - provisioner_remove_node(i); + provisioner_remove_node(i, erase); } all_node_count = 0U; @@ -316,7 +308,7 @@ static int provisioner_store_node(struct bt_mesh_node *node, bool prov, bool sto for (i = min; i < max; i++) { if (mesh_nodes[i] == NULL) { - mesh_nodes[i] = osi_calloc(sizeof(struct bt_mesh_node)); + mesh_nodes[i] = bt_mesh_calloc(sizeof(struct bt_mesh_node)); if (!mesh_nodes[i]) { BT_ERR("%s, Failed to allocate memory", __func__); bt_mesh_provisioner_unlock(); @@ -385,7 +377,7 @@ int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16 return provisioner_store_node(&node, true, true, index); } -static int provisioner_remove_node(u16_t index) +static int provisioner_remove_node(u16_t index, bool erase) { struct bt_mesh_node *node = NULL; struct bt_mesh_rpl *rpl = NULL; @@ -425,14 +417,14 @@ static int provisioner_remove_node(u16_t index) is_prov = index < CONFIG_BLE_MESH_MAX_PROV_NODES ? true : false; - if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_clear_node_info(node->unicast_addr, is_prov); } if (mesh_nodes[index]->comp_data) { - osi_free(mesh_nodes[index]->comp_data); + bt_mesh_free(mesh_nodes[index]->comp_data); } - osi_free(mesh_nodes[index]); + bt_mesh_free(mesh_nodes[index]); mesh_nodes[index] = NULL; provisioner_node_count_dec(is_prov); @@ -479,7 +471,7 @@ bool bt_mesh_provisioner_find_node_with_uuid(const u8_t uuid[16], bool reset) } if (reset) { - provisioner_remove_node(index); + provisioner_remove_node(index, true); } return true; } @@ -493,7 +485,7 @@ bool bt_mesh_provisioner_find_node_with_addr(const bt_mesh_addr_t *addr, bool re if (!memcmp(mesh_nodes[i]->addr, addr->val, BLE_MESH_ADDR_LEN) && mesh_nodes[i]->addr_type == addr->type) { if (reset) { - provisioner_remove_node(i); + provisioner_remove_node(i, true); } return true; } @@ -512,7 +504,7 @@ int bt_mesh_provisioner_remove_node(const u8_t uuid[16]) if (uuid == NULL) { for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) { if (mesh_nodes[i]) { - provisioner_remove_node(i); + provisioner_remove_node(i, true); } } return 0; @@ -524,7 +516,7 @@ int bt_mesh_provisioner_remove_node(const u8_t uuid[16]) return -ENODEV; } - provisioner_remove_node(index); + provisioner_remove_node(index, true); return 0; } @@ -576,13 +568,18 @@ int bt_mesh_provisioner_restore_node_comp_data(u16_t addr, const u8_t *data, u16 { struct bt_mesh_node *node = NULL; + if (!data || length == 0U) { + BT_ERR("%s, Invalid comp data info", __func__); + return -EINVAL; + } + node = provisioner_find_node_with_addr(addr, NULL); if (node == NULL) { BT_ERR("%s, Node 0x%04x not exist", __func__, addr); return -ENODEV; } - node->comp_data = osi_calloc(length); + node->comp_data = bt_mesh_calloc(length); if (!node->comp_data) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -625,7 +622,7 @@ int bt_mesh_provisioner_delete_node_with_uuid(const u8_t uuid[16]) return -ENODEV; } - provisioner_remove_node(index); + provisioner_remove_node(index, true); return 0; } @@ -640,7 +637,7 @@ int bt_mesh_provisioner_delete_node_with_addr(u16_t unicast_addr) return -ENODEV; } - provisioner_remove_node(index); + provisioner_remove_node(index, true); return 0; } @@ -749,6 +746,7 @@ u16_t bt_mesh_provisioner_get_node_index(const char *name) int bt_mesh_provisioner_store_node_comp_data(u16_t addr, const u8_t *data, u16_t length) { struct bt_mesh_node *node = NULL; + u16_t index = 0U; if (!BLE_MESH_ADDR_IS_UNICAST(addr) || !data || (length % 2) || length <= 14) { @@ -756,24 +754,26 @@ int bt_mesh_provisioner_store_node_comp_data(u16_t addr, const u8_t *data, u16_t return -EINVAL; } - node = provisioner_find_node_with_addr(addr, NULL); + node = provisioner_find_node_with_addr(addr, &index); if (node == NULL) { BT_ERR("%s, Node 0x%04x not exist", __func__, addr); return -ENODEV; } - node->comp_data = osi_calloc(length); + node->comp_data = bt_mesh_calloc(length); if (node->comp_data == NULL) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } + BT_DBG("%s, index %d", __func__, index); + memcpy(node->comp_data, data, length); node->comp_length = length; if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_node_comp_data(node, - (node - mesh_nodes[0]) < CONFIG_BLE_MESH_MAX_PROV_NODES ? true : false); + index < CONFIG_BLE_MESH_MAX_PROV_NODES ? true : false); } return 0; @@ -1063,7 +1063,7 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, memcpy(p_key, app_key, 16); } - key = osi_calloc(sizeof(struct bt_mesh_app_key)); + key = bt_mesh_calloc(sizeof(struct bt_mesh_app_key)); if (!key) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -1072,7 +1072,7 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, keys = &key->keys[0]; if (bt_mesh_app_id(p_key, &keys->id)) { BT_ERR("%s, Failed to generate AID", __func__); - osi_free(key); + bt_mesh_free(key); return -EIO; } @@ -1087,7 +1087,7 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, key->app_idx = (++bt_mesh.p_app_idx_next); if (key->app_idx >= 0x1000) { BT_ERR("%s, No AppKey Index available", __func__); - osi_free(key); + bt_mesh_free(key); return -EIO; } } else { @@ -1268,7 +1268,7 @@ int bt_mesh_provisioner_local_app_key_delete(u16_t net_idx, u16_t app_idx) bt_mesh_clear_p_app_key(key); } - osi_free(bt_mesh.p_app_keys[i]); + bt_mesh_free(bt_mesh.p_app_keys[i]); bt_mesh.p_app_keys[i] = NULL; return 0; } @@ -1321,7 +1321,7 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx memcpy(p_key, net_key, 16); } - sub = osi_calloc(sizeof(struct bt_mesh_subnet)); + sub = bt_mesh_calloc(sizeof(struct bt_mesh_subnet)); if (!sub) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -1329,7 +1329,7 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx if (bt_mesh_net_keys_create(&sub->keys[0], p_key)) { BT_ERR("%s, Failed to generate NID", __func__); - osi_free(sub); + bt_mesh_free(sub); return -EIO; } @@ -1342,7 +1342,7 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx sub->net_idx = (++bt_mesh.p_net_idx_next); if (sub->net_idx >= 0x1000) { BT_ERR("%s, No NetKey Index available", __func__); - osi_free(sub); + bt_mesh_free(sub); return -EIO; } } else { @@ -1461,7 +1461,7 @@ int bt_mesh_provisioner_local_net_key_delete(u16_t net_idx) bt_mesh_clear_p_subnet(sub); } - osi_free(bt_mesh.p_sub[i]); + bt_mesh_free(bt_mesh.p_sub[i]); bt_mesh.p_sub[i] = NULL; return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h index 2c1a200a1a..fabe9399eb 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h @@ -47,7 +47,7 @@ int bt_mesh_provisioner_init(void); int bt_mesh_provisioner_net_create(void); -int bt_mesh_provisioner_deinit(void); +int bt_mesh_provisioner_deinit(bool erase); bool bt_mesh_provisioner_check_is_addr_dup(u16_t addr, u8_t elem_num, bool comp_with_own); diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index ef9e0f4431..33203f2e3b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -265,15 +265,15 @@ struct bt_mesh_prov_ctx { #if defined(CONFIG_BLE_MESH_PB_ADV) /* Mutex used to protect the PB-ADV procedure */ - osi_mutex_t pb_adv_lock; + bt_mesh_mutex_t pb_adv_lock; /* Mutex used to protect the adv buf during PB-ADV procedure */ - osi_mutex_t pb_buf_lock; + bt_mesh_mutex_t pb_buf_lock; #endif #if defined(CONFIG_BLE_MESH_PB_GATT) /* Mutex used to protect the PB-GATT procedure */ - osi_mutex_t pb_gatt_lock; + bt_mesh_mutex_t pb_gatt_lock; #endif /* Fast provisioning related information */ @@ -358,7 +358,7 @@ static u8_t adv_buf_data[ADV_BUF_SIZE * CONFIG_BLE_MESH_PBA_SAME_TIME]; #define PROV_FREE_MEM(_idx, member) \ { \ if (link[_idx].member) { \ - osi_free(link[_idx].member); \ + bt_mesh_free(link[_idx].member); \ link[_idx].member = NULL; \ } \ } @@ -366,94 +366,70 @@ static u8_t adv_buf_data[ADV_BUF_SIZE * CONFIG_BLE_MESH_PBA_SAME_TIME]; #if defined(CONFIG_BLE_MESH_PB_ADV) static void bt_mesh_pb_adv_mutex_new(void) { - if (!prov_ctx.pb_adv_lock) { - osi_mutex_new(&prov_ctx.pb_adv_lock); - __ASSERT(prov_ctx.pb_adv_lock, "%s, fail", __func__); + if (!prov_ctx.pb_adv_lock.mutex) { + bt_mesh_mutex_create(&prov_ctx.pb_adv_lock); } } static void bt_mesh_pb_adv_mutex_free(void) { - if (prov_ctx.pb_adv_lock) { - osi_mutex_free(&prov_ctx.pb_adv_lock); - prov_ctx.pb_adv_lock = NULL; - } + bt_mesh_mutex_free(&prov_ctx.pb_adv_lock); } static void bt_mesh_pb_adv_lock(void) { - if (prov_ctx.pb_adv_lock) { - osi_mutex_lock(&prov_ctx.pb_adv_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&prov_ctx.pb_adv_lock); } static void bt_mesh_pb_adv_unlock(void) { - if (prov_ctx.pb_adv_lock) { - osi_mutex_unlock(&prov_ctx.pb_adv_lock); - } + bt_mesh_mutex_unlock(&prov_ctx.pb_adv_lock); } static void bt_mesh_pb_buf_mutex_new(void) { - if (!prov_ctx.pb_buf_lock) { - osi_mutex_new(&prov_ctx.pb_buf_lock); - __ASSERT(prov_ctx.pb_buf_lock, "%s, fail", __func__); + if (!prov_ctx.pb_buf_lock.mutex) { + bt_mesh_mutex_create(&prov_ctx.pb_buf_lock); } } static void bt_mesh_pb_buf_mutex_free(void) { - if (prov_ctx.pb_buf_lock) { - osi_mutex_free(&prov_ctx.pb_buf_lock); - prov_ctx.pb_buf_lock = NULL; - } + bt_mesh_mutex_free(&prov_ctx.pb_buf_lock); } static void bt_mesh_pb_buf_lock(void) { - if (prov_ctx.pb_buf_lock) { - osi_mutex_lock(&prov_ctx.pb_buf_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&prov_ctx.pb_buf_lock); } static void bt_mesh_pb_buf_unlock(void) { - if (prov_ctx.pb_buf_lock) { - osi_mutex_unlock(&prov_ctx.pb_buf_lock); - } + bt_mesh_mutex_unlock(&prov_ctx.pb_buf_lock); } #endif /* CONFIG_BLE_MESH_PB_ADV */ #if defined(CONFIG_BLE_MESH_PB_GATT) static void bt_mesh_pb_gatt_mutex_new(void) { - if (!prov_ctx.pb_gatt_lock) { - osi_mutex_new(&prov_ctx.pb_gatt_lock); - __ASSERT(prov_ctx.pb_gatt_lock, "%s, fail", __func__); + if (!prov_ctx.pb_gatt_lock.mutex) { + bt_mesh_mutex_create(&prov_ctx.pb_gatt_lock); } } static void bt_mesh_pb_gatt_mutex_free(void) { - if (prov_ctx.pb_gatt_lock) { - osi_mutex_free(&prov_ctx.pb_gatt_lock); - prov_ctx.pb_gatt_lock = NULL; - } + bt_mesh_mutex_free(&prov_ctx.pb_gatt_lock); } static void bt_mesh_pb_gatt_lock(void) { - if (prov_ctx.pb_gatt_lock) { - osi_mutex_lock(&prov_ctx.pb_gatt_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&prov_ctx.pb_gatt_lock); } static void bt_mesh_pb_gatt_unlock(void) { - if (prov_ctx.pb_gatt_lock) { - osi_mutex_unlock(&prov_ctx.pb_gatt_lock); - } + bt_mesh_mutex_unlock(&prov_ctx.pb_gatt_lock); } #endif /* CONFIG_BLE_MESH_PB_GATT */ @@ -1998,7 +1974,7 @@ static int prov_auth(const u8_t idx, u8_t method, u8_t action, u8_t size) bt_mesh_output_action_t output = 0U; bt_mesh_input_action_t input = 0U; - link[idx].auth = (u8_t *)osi_calloc(PROV_AUTH_VAL_SIZE); + link[idx].auth = (u8_t *)bt_mesh_calloc(PROV_AUTH_VAL_SIZE); if (!link[idx].auth) { BT_ERR("%s, Failed to allocate memory", __func__); close_link(idx, CLOSE_REASON_FAILED); @@ -2019,7 +1995,7 @@ static int prov_auth(const u8_t idx, u8_t method, u8_t action, u8_t size) } memcpy(link[idx].auth + 16 - prov_ctx.static_oob_len, prov_ctx.static_oob_val, prov_ctx.static_oob_len); - memset(link[idx].auth, 0, 16 - prov->prov_static_oob_len); + memset(link[idx].auth, 0, 16 - prov_ctx.static_oob_len); return 0; case AUTH_METHOD_OUTPUT: @@ -2087,13 +2063,13 @@ static void send_confirm(const u8_t idx) BT_DBG("ConfInputs[64] %s", bt_hex(link[idx].conf_inputs + 64, 64)); BT_DBG("ConfInputs[128] %s", bt_hex(link[idx].conf_inputs + 128, 17)); - link[idx].conf_salt = (u8_t *)osi_calloc(PROV_CONF_SALT_SIZE); + link[idx].conf_salt = (u8_t *)bt_mesh_calloc(PROV_CONF_SALT_SIZE); if (!link[idx].conf_salt) { BT_ERR("%s, Failed to allocate memory", __func__); goto fail; } - link[idx].conf_key = (u8_t *)osi_calloc(PROV_CONF_KEY_SIZE); + link[idx].conf_key = (u8_t *)bt_mesh_calloc(PROV_CONF_KEY_SIZE); if (!link[idx].conf_key) { BT_ERR("%s, Failed to allocate memory", __func__); goto fail; @@ -2246,7 +2222,7 @@ static void prov_dh_key_cb(const u8_t key[32], const u8_t idx) goto fail; } - link[idx].dhkey = (u8_t *)osi_calloc(PROV_DH_KEY_SIZE); + link[idx].dhkey = (u8_t *)bt_mesh_calloc(PROV_DH_KEY_SIZE); if (!link[idx].dhkey) { BT_ERR("%s, Failed to allocate memory", __func__); goto fail; @@ -2409,7 +2385,7 @@ static void prov_confirm(const u8_t idx, const u8_t *data) k_delayed_work_cancel(&link[idx].timeout); } - link[idx].conf = (u8_t *)osi_calloc(PROV_CONFIRM_SIZE); + link[idx].conf = (u8_t *)bt_mesh_calloc(PROV_CONFIRM_SIZE); if (!link[idx].conf) { BT_ERR("%s, Failed to allocate memory", __func__); close_link(idx, CLOSE_REASON_FAILED); @@ -2637,11 +2613,11 @@ static void prov_random(const u8_t idx, const u8_t *data) /** After provisioner receives provisioning random from device, * and successfully check the confirmation, the following * should be done: - * 1. osi_calloc memory for prov_salt + * 1. bt_mesh_calloc memory for prov_salt * 2. calculate prov_salt * 3. prepare provisioning data and send */ - link[idx].prov_salt = (u8_t *)osi_calloc(PROV_PROV_SALT_SIZE); + link[idx].prov_salt = (u8_t *)bt_mesh_calloc(PROV_PROV_SALT_SIZE); if (!link[idx].prov_salt) { BT_ERR("%s, Failed to allocate memory", __func__); goto fail; @@ -2849,7 +2825,7 @@ static void link_ack(const u8_t idx, struct prov_rx *rx, struct net_buf_simple * return; } - link[idx].conf_inputs = (u8_t *)osi_calloc(PROV_CONF_INPUTS_SIZE); + link[idx].conf_inputs = (u8_t *)bt_mesh_calloc(PROV_CONF_INPUTS_SIZE); if (!link[idx].conf_inputs) { BT_ERR("%s, Failed to allocate memory", __func__); close_link(idx, CLOSE_REASON_FAILED); @@ -3280,7 +3256,7 @@ int bt_mesh_provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr) prov->prov_link_open(BLE_MESH_PROV_GATT); } - link[idx].conf_inputs = (u8_t *)osi_calloc(PROV_CONF_INPUTS_SIZE); + link[idx].conf_inputs = (u8_t *)bt_mesh_calloc(PROV_CONF_INPUTS_SIZE); if (!link[idx].conf_inputs) { /* Disconnect this connection, clear corresponding informations */ BT_ERR("%s, Failed to allocate memory", __func__); @@ -3378,7 +3354,7 @@ int bt_mesh_provisioner_prov_init(const struct bt_mesh_prov *prov_info) return 0; } -int bt_mesh_provisioner_prov_deinit(void) +int bt_mesh_provisioner_prov_deinit(bool erase) { int i; @@ -3420,6 +3396,10 @@ int bt_mesh_provisioner_prov_deinit(void) #endif memset(unprov_dev, 0, sizeof(unprov_dev)); + if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + bt_mesh_clear_prov_info(); + } + prov = NULL; return 0; diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h index a9690da972..7642e2c8ef 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h @@ -151,9 +151,11 @@ int bt_mesh_provisioner_prov_init(const struct bt_mesh_prov *prov_info); * @brief This function deinitializes provisioner's PB-GATT and PB-ADV * related information. * + * @param[in] erase: Indicate if erasing provisioning information from flash. + * * @return Zero - success, otherwise - fail */ -int bt_mesh_provisioner_prov_deinit(void); +int bt_mesh_provisioner_prov_deinit(bool erase); /** * @brief This function parses the received unprovisioned device diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index 4360498027..2792d893d0 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -879,7 +879,7 @@ static struct bt_mesh_subnet *p_subnet_alloc(void) for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) { if (bt_mesh.p_sub[i] == NULL) { - bt_mesh.p_sub[i] = osi_calloc(sizeof(struct bt_mesh_subnet)); + bt_mesh.p_sub[i] = bt_mesh_calloc(sizeof(struct bt_mesh_subnet)); if (!bt_mesh.p_sub[i]) { BT_ERR("%s, Failed to allocate memory", __func__); return NULL; @@ -898,7 +898,7 @@ static struct bt_mesh_app_key *p_appkey_alloc(void) for (i = 0; i < ARRAY_SIZE(bt_mesh.p_app_keys); i++) { if (bt_mesh.p_app_keys[i] == NULL) { - bt_mesh.p_app_keys[i] = osi_calloc(sizeof(struct bt_mesh_app_key)); + bt_mesh.p_app_keys[i] = bt_mesh_calloc(sizeof(struct bt_mesh_app_key)); if (!bt_mesh.p_app_keys[i]) { BT_ERR("%s, Failed to allocate memory", __func__); return NULL; @@ -1522,6 +1522,11 @@ void bt_mesh_store_iv(bool only_duration) } } +void bt_mesh_clear_iv(void) +{ + clear_iv(); +} + static void store_pending_seq(void) { struct seq_val seq = {0}; @@ -1543,6 +1548,11 @@ void bt_mesh_store_seq(void) schedule_store(BLE_MESH_SEQ_PENDING); } +void bt_mesh_clear_seq(void) +{ + bt_mesh_save_core_settings("mesh/seq", NULL, 0); +} + static void store_rpl(struct bt_mesh_rpl *entry) { struct rpl_val rpl = {0}; @@ -2263,6 +2273,11 @@ void bt_mesh_store_prov_info(u16_t primary_addr, u16_t alloc_addr) bt_mesh_save_core_settings("mesh/p_prov", (const u8_t *)&val, sizeof(val)); } +void bt_mesh_clear_prov_info(void) +{ + bt_mesh_save_core_settings("mesh/p_prov", NULL, 0); +} + static void clear_p_net_key(u16_t net_idx) { char name[16] = {'\0'}; @@ -2527,29 +2542,18 @@ void bt_mesh_store_node_name(struct bt_mesh_node *node, bool prov) void bt_mesh_store_node_comp_data(struct bt_mesh_node *node, bool prov) { char name[16] = {'\0'}; - u8_t *data = NULL; int err = 0; - if (node == NULL) { - BT_ERR("%s, Invalid node", __func__); + if (!node || !node->comp_data || node->comp_length == 0U) { + BT_ERR("%s, Invalid node info", __func__); return; } - data = osi_calloc(node->comp_length); - if (!data) { - BT_ERR("%s, Failed to allocate memory", __func__); - return; - } - - memcpy(data, node->comp_data, node->comp_length); - sprintf(name, prov ? "mesh/pn/%04x/c" : "mesh/sn/%04x/c", node->unicast_addr); - err = bt_mesh_save_core_settings(name, (const u8_t *)data, node->comp_length); + err = bt_mesh_save_core_settings(name, (const u8_t *)node->comp_data, node->comp_length); if (err) { BT_ERR("%s, Failed to save node comp data %s", __func__, name); } - - osi_free(data); } #endif /* CONFIG_BLE_MESH_PROVISIONER */ diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.h b/components/bt/esp_ble_mesh/mesh_core/settings.h index 557b69939a..a02db9e550 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.h +++ b/components/bt/esp_ble_mesh/mesh_core/settings.h @@ -18,7 +18,9 @@ int settings_core_deinit(void); void bt_mesh_store_role(void); void bt_mesh_store_net(void); void bt_mesh_store_iv(bool only_duration); +void bt_mesh_clear_iv(void); void bt_mesh_store_seq(void); +void bt_mesh_clear_seq(void); void bt_mesh_store_rpl(struct bt_mesh_rpl *rpl); void bt_mesh_store_subnet(struct bt_mesh_subnet *sub); void bt_mesh_store_app_key(struct bt_mesh_app_key *key); @@ -37,6 +39,7 @@ void bt_mesh_clear_rpl(void); #if CONFIG_BLE_MESH_PROVISIONER void bt_mesh_store_prov_info(u16_t primary_addr, u16_t alloc_addr); +void bt_mesh_clear_prov_info(void); void bt_mesh_store_p_net_idx(void); void bt_mesh_clear_p_net_idx(void); void bt_mesh_store_p_app_idx(void); diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index f3e1079cc3..54ac29d5a6 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -101,36 +101,28 @@ static u8_t seg_rx_buf_data[(CONFIG_BLE_MESH_RX_SEG_MSG_COUNT * static u16_t hb_sub_dst = BLE_MESH_ADDR_UNASSIGNED; -static osi_mutex_t tx_seg_lock; +static bt_mesh_mutex_t tx_seg_lock; static void bt_mesh_tx_seg_mutex_new(void) { - if (!tx_seg_lock) { - osi_mutex_new(&tx_seg_lock); - __ASSERT(tx_seg_lock, "%s, fail", __func__); + if (!tx_seg_lock.mutex) { + bt_mesh_mutex_create(&tx_seg_lock); } } static void bt_mesh_tx_seg_mutex_free(void) { - if (tx_seg_lock) { - osi_mutex_free(&tx_seg_lock); - tx_seg_lock = NULL; - } + bt_mesh_mutex_free(&tx_seg_lock); } static void bt_mesh_tx_seg_lock(void) { - if (tx_seg_lock) { - osi_mutex_lock(&tx_seg_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&tx_seg_lock); } static void bt_mesh_tx_seg_unlock(void) { - if (tx_seg_lock) { - osi_mutex_unlock(&tx_seg_lock); - } + bt_mesh_mutex_unlock(&tx_seg_lock); } void bt_mesh_set_hb_sub_dst(u16_t addr) @@ -1610,11 +1602,20 @@ void bt_mesh_trans_init(void) bt_mesh_tx_seg_mutex_new(); } -void bt_mesh_trans_deinit(void) +void bt_mesh_trans_deinit(bool erase) { int i; - bt_mesh_rx_reset(); + for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { + seg_rx_reset(&seg_rx[i], true); + } + + if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + bt_mesh_clear_rpl(); + } else { + bt_mesh_rpl_clear(); + } + bt_mesh_tx_reset(); for (i = 0; i < ARRAY_SIZE(seg_tx); i++) { diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.h b/components/bt/esp_ble_mesh/mesh_core/transport.h index bde56889a8..028b62be85 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.h +++ b/components/bt/esp_ble_mesh/mesh_core/transport.h @@ -99,7 +99,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx); void bt_mesh_trans_init(void); -void bt_mesh_trans_deinit(void); +void bt_mesh_trans_deinit(bool erase); void bt_mesh_rpl_clear(void); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index 659a76c7ce..182983b453 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -190,7 +190,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, err = -EBUSY; } else { /* Don't forget to free the node in the timeout (timer_handler) function. */ - node = (bt_mesh_client_node_t *)osi_calloc(sizeof(bt_mesh_client_node_t)); + node = (bt_mesh_client_node_t *)bt_mesh_calloc(sizeof(bt_mesh_client_node_t)); if (!node) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -200,11 +200,11 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, node->opcode = opcode; if ((node->op_pending = bt_mesh_client_get_status_op(cli->op_pair, cli->op_pair_size, opcode)) == 0) { BT_ERR("%s, Not found the status opcode in the op_pair list", __func__); - osi_free(node); + bt_mesh_free(node); return -EINVAL; } if ((err = bt_mesh_model_send(model, ctx, msg, cb, cb_data)) != 0) { - osi_free(node); + bt_mesh_free(node); } else { bt_mesh_list_lock(); sys_slist_append(&internal->queue, &node->client_node); @@ -226,36 +226,28 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return err; } -static osi_mutex_t client_model_lock; +static bt_mesh_mutex_t client_model_lock; static void bt_mesh_client_model_mutex_new(void) { - if (!client_model_lock) { - osi_mutex_new(&client_model_lock); - __ASSERT(client_model_lock, "%s, fail", __func__); + if (!client_model_lock.mutex) { + bt_mesh_mutex_create(&client_model_lock); } } static void bt_mesh_client_model_mutex_free(void) { - if (client_model_lock) { - osi_mutex_free(&client_model_lock); - client_model_lock = NULL; - } + bt_mesh_mutex_free(&client_model_lock); } void bt_mesh_client_model_lock(void) { - if (client_model_lock) { - osi_mutex_lock(&client_model_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&client_model_lock); } void bt_mesh_client_model_unlock(void) { - if (client_model_lock) { - osi_mutex_unlock(&client_model_lock); - } + bt_mesh_mutex_unlock(&client_model_lock); } int bt_mesh_client_init(struct bt_mesh_model *model) @@ -280,7 +272,7 @@ int bt_mesh_client_init(struct bt_mesh_model *model) } if (!cli->internal_data) { - data = osi_calloc(sizeof(bt_mesh_client_internal_data_t)); + data = bt_mesh_calloc(sizeof(bt_mesh_client_internal_data_t)); if (!data) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -320,7 +312,7 @@ int bt_mesh_client_deinit(struct bt_mesh_model *model) bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ - osi_free(client->internal_data); + bt_mesh_free(client->internal_data); client->internal_data = NULL; } @@ -356,7 +348,7 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node) sys_slist_find_and_remove(&internal->queue, &node->client_node); bt_mesh_list_unlock(); // Free the node - osi_free(node); + bt_mesh_free(node); return 0; } @@ -376,7 +368,7 @@ int bt_mesh_client_clear_list(void *data) bt_mesh_list_lock(); while (!sys_slist_is_empty(&internal->queue)) { node = (void *)sys_slist_get_not_empty(&internal->queue); - osi_free(node); + bt_mesh_free(node); } bt_mesh_list_unlock(); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index 1de65a55e6..3ccb43a79c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -109,36 +109,28 @@ static const bt_mesh_client_op_pair_t gen_op_pair[] = { { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS }, }; -static osi_mutex_t generic_client_lock; +static bt_mesh_mutex_t generic_client_lock; static void bt_mesh_generic_client_mutex_new(void) { - if (!generic_client_lock) { - osi_mutex_new(&generic_client_lock); - __ASSERT(generic_client_lock, "%s, fail", __func__); + if (!generic_client_lock.mutex) { + bt_mesh_mutex_create(&generic_client_lock); } } static void bt_mesh_generic_client_mutex_free(void) { - if (generic_client_lock) { - osi_mutex_free(&generic_client_lock); - generic_client_lock = NULL; - } + bt_mesh_mutex_free(&generic_client_lock); } static void bt_mesh_generic_client_lock(void) { - if (generic_client_lock) { - osi_mutex_lock(&generic_client_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&generic_client_lock); } static void bt_mesh_generic_client_unlock(void) { - if (generic_client_lock) { - osi_mutex_unlock(&generic_client_lock); - } + bt_mesh_mutex_unlock(&generic_client_lock); } static void timeout_handler(struct k_work *work) @@ -188,7 +180,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic OnOff Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_onoff_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onoff_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -209,7 +201,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Level Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_level_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_level_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -230,7 +222,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Default Trans Time Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -246,7 +238,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic OnPowerUp Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_onpowerup_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onpowerup_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -262,7 +254,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Power Level Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_power_level_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_level_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -283,7 +275,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Power Last Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_power_last_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_last_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -299,7 +291,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Power Default Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_power_default_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_default_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -315,7 +307,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Power Range Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_power_range_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_range_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -333,7 +325,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Battery Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_battery_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_battery_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -355,7 +347,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Location Global Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_loc_global_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_global_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -373,7 +365,7 @@ static void generic_status(struct bt_mesh_model *model, BT_ERR("Invalid Generic Location Local Status length %d", buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_gen_loc_local_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_local_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -389,7 +381,7 @@ static void generic_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { struct bt_mesh_gen_user_properties_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_gen_user_properties_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_properties_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -397,7 +389,7 @@ static void generic_status(struct bt_mesh_model *model, status->user_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->user_property_ids) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->user_property_ids, buf->data, buf->len); @@ -407,7 +399,7 @@ static void generic_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: { struct bt_mesh_gen_user_property_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_gen_user_property_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_property_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -419,7 +411,7 @@ static void generic_status(struct bt_mesh_model *model, status->user_property_value = bt_mesh_alloc_buf(buf->len); if (!status->user_property_value) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->user_property_value, buf->data, buf->len); @@ -430,7 +422,7 @@ static void generic_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: { struct bt_mesh_gen_admin_properties_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_gen_admin_properties_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_properties_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -438,7 +430,7 @@ static void generic_status(struct bt_mesh_model *model, status->admin_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->admin_property_ids) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->admin_property_ids, buf->data, buf->len); @@ -448,7 +440,7 @@ static void generic_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: { struct bt_mesh_gen_admin_property_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_gen_admin_property_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_property_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -460,7 +452,7 @@ static void generic_status(struct bt_mesh_model *model, status->admin_property_value = bt_mesh_alloc_buf(buf->len); if (!status->admin_property_value) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->admin_property_value, buf->data, buf->len); @@ -471,7 +463,7 @@ static void generic_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: { struct bt_mesh_gen_manu_properties_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_gen_manu_properties_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_properties_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -479,7 +471,7 @@ static void generic_status(struct bt_mesh_model *model, status->manu_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->manu_property_ids) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->manu_property_ids, buf->data, buf->len); @@ -489,7 +481,7 @@ static void generic_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: { struct bt_mesh_gen_manu_property_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_gen_manu_property_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_property_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -501,7 +493,7 @@ static void generic_status(struct bt_mesh_model *model, status->manu_property_value = bt_mesh_alloc_buf(buf->len); if (!status->manu_property_value) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->manu_property_value, buf->data, buf->len); @@ -512,7 +504,7 @@ static void generic_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: { struct bt_mesh_gen_client_properties_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_gen_client_properties_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_client_properties_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -520,7 +512,7 @@ static void generic_status(struct bt_mesh_model *model, status->client_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->client_property_ids) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->client_property_ids, buf->data, buf->len); @@ -639,7 +631,7 @@ static void generic_status(struct bt_mesh_model *model, break; } - osi_free(val); + bt_mesh_free(val); return; } @@ -1175,7 +1167,7 @@ static int generic_client_init(struct bt_mesh_model *model, bool primary) } if (!client->internal_data) { - internal = osi_calloc(sizeof(generic_internal_data_t)); + internal = bt_mesh_calloc(sizeof(generic_internal_data_t)); if (!internal) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -1256,7 +1248,7 @@ static int generic_client_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ - osi_free(client->internal_data); + bt_mesh_free(client->internal_data); client->internal_data = NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index 283f7eb130..ff693cf882 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -118,36 +118,28 @@ static const bt_mesh_client_op_pair_t light_op_pair[] = { { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS }, }; -static osi_mutex_t light_client_lock; +static bt_mesh_mutex_t light_client_lock; static void bt_mesh_light_client_mutex_new(void) { - if (!light_client_lock) { - osi_mutex_new(&light_client_lock); - __ASSERT(light_client_lock, "%s, fail", __func__); + if (!light_client_lock.mutex) { + bt_mesh_mutex_create(&light_client_lock); } } static void bt_mesh_light_client_mutex_free(void) { - if (light_client_lock) { - osi_mutex_free(&light_client_lock); - light_client_lock = NULL; - } + bt_mesh_mutex_free(&light_client_lock); } static void bt_mesh_light_client_lock(void) { - if (light_client_lock) { - osi_mutex_lock(&light_client_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&light_client_lock); } static void bt_mesh_light_client_unlock(void) { - if (light_client_lock) { - osi_mutex_unlock(&light_client_lock); - } + bt_mesh_mutex_unlock(&light_client_lock); } static void timeout_handler(struct k_work *work) @@ -197,7 +189,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light Lightness Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lightness_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -218,7 +210,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light Lightness Linear Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lightness_linear_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_linear_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -239,7 +231,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light Lightness Last Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lightness_last_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_last_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -255,7 +247,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light Lightness Default Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lightness_default_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_default_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -271,7 +263,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light Lightness Range Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lightness_range_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_range_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -289,7 +281,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light CTL Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_ctl_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -312,7 +304,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light CTL Temperature Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_ctl_temperature_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_temperature_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -335,7 +327,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light CTL Temperature Range Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_ctl_temperature_range_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_temperature_range_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -353,7 +345,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light CTL Default Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_ctl_default_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_default_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -371,7 +363,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light HSL Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_hsl_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -393,7 +385,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light HSL Target Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_hsl_target_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_target_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -415,7 +407,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light HSL Hue Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_hsl_hue_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_hue_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -436,7 +428,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light HSL Saturation Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_hsl_saturation_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_saturation_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -457,7 +449,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light HSL Default Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_hsl_default_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_default_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -475,7 +467,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light HSL Range Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_hsl_range_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_range_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -495,7 +487,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light xyL Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_xyl_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -517,7 +509,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light xyL Target Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_xyl_target_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_target_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -539,7 +531,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light xyL Default Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_xyl_default_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_default_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -557,7 +549,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light xyL Range Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_xyl_range_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_range_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -577,7 +569,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light LC Mode Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lc_mode_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_mode_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -593,7 +585,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light LC OM Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lc_om_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_om_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -609,7 +601,7 @@ static void light_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Light LC Light OnOff Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_light_lc_light_onoff_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_light_onoff_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -626,7 +618,7 @@ static void light_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: { struct bt_mesh_light_lc_property_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_light_lc_property_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_property_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -635,7 +627,7 @@ static void light_status(struct bt_mesh_model *model, status->light_lc_property_value = bt_mesh_alloc_buf(buf->len); if (!status->light_lc_property_value) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->light_lc_property_value, buf->data, buf->len); @@ -729,7 +721,7 @@ static void light_status(struct bt_mesh_model *model, break; } - osi_free(val); + bt_mesh_free(val); return; } @@ -1365,7 +1357,7 @@ static int light_client_init(struct bt_mesh_model *model, bool primary) } if (!client->internal_data) { - internal = osi_calloc(sizeof(light_internal_data_t)); + internal = bt_mesh_calloc(sizeof(light_internal_data_t)); if (!internal) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -1431,7 +1423,7 @@ static int light_client_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ - osi_free(client->internal_data); + bt_mesh_free(client->internal_data); client->internal_data = NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index bb61861a3c..9df2e25ae6 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -47,36 +47,28 @@ static const bt_mesh_client_op_pair_t sensor_op_pair[] = { { BLE_MESH_MODEL_OP_SENSOR_SERIES_GET, BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS }, }; -static osi_mutex_t sensor_client_lock; +static bt_mesh_mutex_t sensor_client_lock; static void bt_mesh_sensor_client_mutex_new(void) { - if (!sensor_client_lock) { - osi_mutex_new(&sensor_client_lock); - __ASSERT(sensor_client_lock, "%s, fail", __func__); + if (!sensor_client_lock.mutex) { + bt_mesh_mutex_create(&sensor_client_lock); } } static void bt_mesh_sensor_client_mutex_free(void) { - if (sensor_client_lock) { - osi_mutex_free(&sensor_client_lock); - sensor_client_lock = NULL; - } + bt_mesh_mutex_free(&sensor_client_lock); } static void bt_mesh_sensor_client_lock(void) { - if (sensor_client_lock) { - osi_mutex_lock(&sensor_client_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&sensor_client_lock); } static void bt_mesh_sensor_client_unlock(void) { - if (sensor_client_lock) { - osi_mutex_unlock(&sensor_client_lock); - } + bt_mesh_mutex_unlock(&sensor_client_lock); } static void timeout_handler(struct k_work *work) @@ -122,7 +114,7 @@ static void sensor_status(struct bt_mesh_model *model, switch (ctx->recv_op) { case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { struct bt_mesh_sensor_descriptor_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_sensor_descriptor_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_descriptor_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -130,7 +122,7 @@ static void sensor_status(struct bt_mesh_model *model, status->descriptor = bt_mesh_alloc_buf(buf->len); if (!status->descriptor) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->descriptor, buf->data, buf->len); @@ -140,7 +132,7 @@ static void sensor_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS: { struct bt_mesh_sensor_cadence_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_sensor_cadence_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_cadence_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -149,7 +141,7 @@ static void sensor_status(struct bt_mesh_model *model, status->sensor_cadence_value = bt_mesh_alloc_buf(buf->len); if (!status->sensor_cadence_value) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->sensor_cadence_value, buf->data, buf->len); @@ -159,7 +151,7 @@ static void sensor_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS: { struct bt_mesh_sensor_settings_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_sensor_settings_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_settings_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -168,7 +160,7 @@ static void sensor_status(struct bt_mesh_model *model, status->sensor_setting_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->sensor_setting_property_ids) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->sensor_setting_property_ids, buf->data, buf->len); @@ -178,7 +170,7 @@ static void sensor_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS: { struct bt_mesh_sensor_setting_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_sensor_setting_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_setting_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -191,7 +183,7 @@ static void sensor_status(struct bt_mesh_model *model, status->sensor_setting_raw = bt_mesh_alloc_buf(buf->len); if (!status->sensor_setting_raw) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->sensor_setting_raw, buf->data, buf->len); @@ -202,7 +194,7 @@ static void sensor_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_SENSOR_STATUS: { struct bt_mesh_sensor_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_sensor_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -210,7 +202,7 @@ static void sensor_status(struct bt_mesh_model *model, status->marshalled_sensor_data = bt_mesh_alloc_buf(buf->len); if (!status->marshalled_sensor_data) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->marshalled_sensor_data, buf->data, buf->len); @@ -220,7 +212,7 @@ static void sensor_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS: { struct bt_mesh_sensor_column_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_sensor_column_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_column_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -229,7 +221,7 @@ static void sensor_status(struct bt_mesh_model *model, status->sensor_column_value = bt_mesh_alloc_buf(buf->len); if (!status->sensor_column_value) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->sensor_column_value, buf->data, buf->len); @@ -239,7 +231,7 @@ static void sensor_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS: { struct bt_mesh_sensor_series_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_sensor_series_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_series_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -248,7 +240,7 @@ static void sensor_status(struct bt_mesh_model *model, status->sensor_series_value = bt_mesh_alloc_buf(buf->len); if (!status->sensor_series_value) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->sensor_series_value, buf->data, buf->len); @@ -344,7 +336,7 @@ static void sensor_status(struct bt_mesh_model *model, break; } - osi_free(val); + bt_mesh_free(val); return; } @@ -607,7 +599,7 @@ int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary) } if (!client->internal_data) { - internal = osi_calloc(sizeof(sensor_internal_data_t)); + internal = bt_mesh_calloc(sizeof(sensor_internal_data_t)); if (!internal) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -648,7 +640,7 @@ int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ - osi_free(client->internal_data); + bt_mesh_free(client->internal_data); client->internal_data = NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index ccedcb734c..15961d1eb2 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -63,36 +63,28 @@ static const bt_mesh_client_op_pair_t time_scene_op_pair[] = { { BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET, BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS }, }; -static osi_mutex_t time_scene_client_lock; +static bt_mesh_mutex_t time_scene_client_lock; static void bt_mesh_time_scene_client_mutex_new(void) { - if (!time_scene_client_lock) { - osi_mutex_new(&time_scene_client_lock); - __ASSERT(time_scene_client_lock, "%s, fail", __func__); + if (!time_scene_client_lock.mutex) { + bt_mesh_mutex_create(&time_scene_client_lock); } } static void bt_mesh_time_scene_client_mutex_free(void) { - if (time_scene_client_lock) { - osi_mutex_free(&time_scene_client_lock); - time_scene_client_lock = NULL; - } + bt_mesh_mutex_free(&time_scene_client_lock); } static void bt_mesh_time_scene_client_lock(void) { - if (time_scene_client_lock) { - osi_mutex_lock(&time_scene_client_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&time_scene_client_lock); } static void bt_mesh_time_scene_client_unlock(void) { - if (time_scene_client_lock) { - osi_mutex_unlock(&time_scene_client_lock); - } + bt_mesh_mutex_unlock(&time_scene_client_lock); } static void timeout_handler(struct k_work *work) @@ -142,7 +134,7 @@ static void time_scene_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Time Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_time_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_time_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -165,7 +157,7 @@ static void time_scene_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Time Zone Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_time_zone_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_time_zone_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -184,7 +176,7 @@ static void time_scene_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid TAI UTC Delta Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_tai_utc_delta_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_tai_utc_delta_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -207,7 +199,7 @@ static void time_scene_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Time Role Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_time_role_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_time_role_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -223,7 +215,7 @@ static void time_scene_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Scene Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_scene_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_scene_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -241,7 +233,7 @@ static void time_scene_status(struct bt_mesh_model *model, } case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: { struct bt_mesh_scene_register_status *status = NULL; - status = osi_calloc(sizeof(struct bt_mesh_scene_register_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_scene_register_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -251,7 +243,7 @@ static void time_scene_status(struct bt_mesh_model *model, status->scenes = bt_mesh_alloc_buf(buf->len); if (!status->scenes) { BT_ERR("%s, Failed to allocate memory", __func__); - osi_free(status); + bt_mesh_free(status); return; } net_buf_simple_add_mem(status->scenes, buf->data, buf->len); @@ -265,7 +257,7 @@ static void time_scene_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Scheduler Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_scheduler_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_scheduler_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -281,7 +273,7 @@ static void time_scene_status(struct bt_mesh_model *model, BT_ERR("%s, Invalid Scheduler Action Status length %d", __func__, buf->len); return; } - status = osi_calloc(sizeof(struct bt_mesh_scheduler_act_status)); + status = bt_mesh_calloc(sizeof(struct bt_mesh_scheduler_act_status)); if (!status) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -352,7 +344,7 @@ static void time_scene_status(struct bt_mesh_model *model, break; } - osi_free(val); + bt_mesh_free(val); return; } @@ -670,7 +662,7 @@ static int time_scene_client_init(struct bt_mesh_model *model, bool primary) } if (!client->internal_data) { - internal = osi_calloc(sizeof(time_scene_internal_data_t)); + internal = bt_mesh_calloc(sizeof(time_scene_internal_data_t)); if (!internal) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -726,7 +718,7 @@ static int time_scene_client_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ - osi_free(client->internal_data); + bt_mesh_free(client->internal_data); client->internal_data = NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c index 2bbdcd697d..79f7c08ebb 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c @@ -16,36 +16,28 @@ #include "btc_ble_mesh_generic_model.h" -static osi_mutex_t generic_server_lock; +static bt_mesh_mutex_t generic_server_lock; static void bt_mesh_generic_server_mutex_new(void) { - if (!generic_server_lock) { - osi_mutex_new(&generic_server_lock); - __ASSERT(generic_server_lock, "%s, fail", __func__); + if (!generic_server_lock.mutex) { + bt_mesh_mutex_create(&generic_server_lock); } } static void bt_mesh_generic_server_mutex_free(void) { - if (generic_server_lock) { - osi_mutex_free(&generic_server_lock); - generic_server_lock = NULL; - } + bt_mesh_mutex_free(&generic_server_lock); } void bt_mesh_generic_server_lock(void) { - if (generic_server_lock) { - osi_mutex_lock(&generic_server_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&generic_server_lock); } void bt_mesh_generic_server_unlock(void) { - if (generic_server_lock) { - osi_mutex_unlock(&generic_server_lock); - } + bt_mesh_mutex_unlock(&generic_server_lock); } /* message handlers (Start) */ diff --git a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c index a9f841c16d..a63de218ca 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c @@ -16,36 +16,28 @@ #include "btc_ble_mesh_lighting_model.h" -static osi_mutex_t light_server_lock; +static bt_mesh_mutex_t light_server_lock; static void bt_mesh_light_server_mutex_new(void) { - if (!light_server_lock) { - osi_mutex_new(&light_server_lock); - __ASSERT(light_server_lock, "%s, fail", __func__); + if (!light_server_lock.mutex) { + bt_mesh_mutex_create(&light_server_lock); } } static void bt_mesh_light_server_mutex_free(void) { - if (light_server_lock) { - osi_mutex_free(&light_server_lock); - light_server_lock = NULL; - } + bt_mesh_mutex_free(&light_server_lock); } void bt_mesh_light_server_lock(void) { - if (light_server_lock) { - osi_mutex_lock(&light_server_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&light_server_lock); } void bt_mesh_light_server_unlock(void) { - if (light_server_lock) { - osi_mutex_unlock(&light_server_lock); - } + bt_mesh_mutex_unlock(&light_server_lock); } /* message handlers (Start) */ diff --git a/components/bt/esp_ble_mesh/mesh_models/server/server_common.c b/components/bt/esp_ble_mesh/mesh_models/server/server_common.c index b3d1275a8e..ee698e2d74 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/server_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/server_common.c @@ -185,7 +185,7 @@ void bt_mesh_server_alloc_ctx(struct k_work *work) */ __ASSERT(work, "%s, Invalid parameter", __func__); if (!work->_reserved) { - work->_reserved = osi_calloc(sizeof(struct bt_mesh_msg_ctx)); + work->_reserved = bt_mesh_calloc(sizeof(struct bt_mesh_msg_ctx)); __ASSERT(work->_reserved, "%s, Failed to allocate memory", __func__); } } @@ -194,7 +194,7 @@ void bt_mesh_server_free_ctx(struct k_work *work) { __ASSERT(work, "%s, Invalid parameter", __func__); if (work->_reserved) { - osi_free(work->_reserved); + bt_mesh_free(work->_reserved); work->_reserved = NULL; } } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c index bfdac2b493..78caa680f8 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c @@ -21,36 +21,28 @@ #include "btc_ble_mesh_time_scene_model.h" -static osi_mutex_t time_scene_server_lock; +static bt_mesh_mutex_t time_scene_server_lock; static void bt_mesh_time_scene_server_mutex_new(void) { - if (!time_scene_server_lock) { - osi_mutex_new(&time_scene_server_lock); - __ASSERT(time_scene_server_lock, "%s, fail", __func__); + if (!time_scene_server_lock.mutex) { + bt_mesh_mutex_create(&time_scene_server_lock); } } static void bt_mesh_time_scene_server_mutex_free(void) { - if (time_scene_server_lock) { - osi_mutex_free(&time_scene_server_lock); - time_scene_server_lock = NULL; - } + bt_mesh_mutex_free(&time_scene_server_lock); } void bt_mesh_time_scene_server_lock(void) { - if (time_scene_server_lock) { - osi_mutex_lock(&time_scene_server_lock, OSI_MUTEX_MAX_TIMEOUT); - } + bt_mesh_mutex_lock(&time_scene_server_lock); } void bt_mesh_time_scene_server_unlock(void) { - if (time_scene_server_lock) { - osi_mutex_unlock(&time_scene_server_lock); - } + bt_mesh_mutex_unlock(&time_scene_server_lock); } /* message handlers (Start) */ diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/ble_mesh_demo_main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/ble_mesh_demo_main.c index 2ec53a4c1e..8c1732c15a 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/ble_mesh_demo_main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/ble_mesh_demo_main.c @@ -55,8 +55,8 @@ static uint8_t dev_uuid[16]; #define MSG_TIMEOUT 200000 /* msg resend interval */ #define MSG_INTERVAL 1000000 /* msg send interval */ #define MSG_MAX_RESEND 3 /* max resend count */ -#define MSG_TEST_COUNT 500 /* message test count */ -#define MSG_TEST_UNIT 500 /* message test unit */ +#define MSG_TEST_COUNT 10 /* message test count */ +#define MSG_TEST_UNIT 10 /* message test unit */ static esp_timer_handle_t retransmit_timer; static esp_timer_handle_t interval_timer; @@ -80,6 +80,9 @@ static SemaphoreHandle_t tx_rx_mutex; /* The following is BLE Mesh deinit test flag */ bool example_deinit_test; +/* The following is BLE Mesh client message timeout with internal timer flag */ +bool msg_to_internal; + typedef struct { uint8_t uuid[16]; uint16_t unicast; @@ -251,6 +254,8 @@ static esp_err_t example_ble_mesh_set_msg_common(esp_ble_mesh_client_common_para void example_ble_mesh_send_test_msg(bool resend) { esp_ble_mesh_msg_ctx_t ctx = {0}; + bool need_ack = false; + int32_t timeout; esp_err_t err; ctx.net_idx = prov_key.net_idx; @@ -259,9 +264,20 @@ void example_ble_mesh_send_test_msg(bool resend) ctx.send_ttl = MSG_SEND_TTL; ctx.send_rel = MSG_SEND_REL; + uint8_t data[8] = {0}; + memcpy(data, &trans_num, sizeof(trans_num)); + + if (msg_to_internal) { + need_ack = true; + timeout = 1000; + } else { + need_ack = false; + timeout = 0; + } + err = esp_ble_mesh_client_model_send_msg(test_client.model, &ctx, ESP_BLE_MESH_VND_MODEL_OP_TEST_SEND, - sizeof(trans_num), (uint8_t *)&trans_num, 0, false, MSG_ROLE); + sizeof(data), data, timeout, need_ack, MSG_ROLE); if (err) { ESP_LOGE(TAG, "%s, Failed to send test message", __func__); return; @@ -367,7 +383,9 @@ static void example_ble_mesh_provisioning_cb(esp_ble_mesh_prov_cb_event_t event, break; case ESP_BLE_MESH_PROVISIONER_PROV_ENABLE_COMP_EVT: ESP_LOGI(TAG, "ESP_BLE_MESH_PROVISIONER_PROV_ENABLE_COMP_EVT, err_code %d", param->provisioner_prov_enable_comp.err_code); - esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_STANDBY | ESP_COEX_BLE_ST_MESH_TRAFFIC | ESP_COEX_BLE_ST_MESH_CONFIG); + esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_CONFIG); + esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_TRAFFIC); + esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_STANDBY); if (iperf_test == true) { esp_coex_status_bit_set(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_STANDBY); ESP_LOGW(TAG, "BLE Mesh enters Standby mode"); @@ -597,6 +615,66 @@ static void example_tx_rx_unlock(void) } } +static void example_test_result_output(void) +{ + uint32_t count[MSG_MAX_RESEND + 1] = {0}; + uint8_t compare[MSG_MAX_RESEND + 1]; + /** + * Used to record if resend reaches max number, whether we have + * received corresponding response. + */ + uint32_t no_ack_count = 0; + int64_t total_time = 0; + size_t i, j, k; + + for (i = 0; i < sizeof(compare); i++) { + compare[i] = i; + } + + ESP_LOGI(TAG, "ble mesh tx rx test finished"); + + for (i = 0; i < MSG_TEST_COUNT / MSG_TEST_UNIT; i++) { + for (j = 0; j < MSG_TEST_UNIT; j++) { + for (k = 0; k < sizeof(compare); k++) { + if (msg_record[i * MSG_TEST_UNIT + j].resend == compare[k]) { + count[k]++; + if (msg_record[i * MSG_TEST_UNIT + j].resend == MSG_MAX_RESEND && + msg_record[i * MSG_TEST_UNIT + j].acked == false) { + /* If msg is not acked, use 1s for its time */ + msg_record[msg_index].time = 1000000; + no_ack_count++; + } + break; + } + } + total_time += msg_record[msg_index].time; + } + ESP_LOGW(TAG, "Send messages the %d time, total %lldus, average %lldus", i, total_time, total_time / MSG_TEST_UNIT); + ESP_LOGW(TAG, "0-resend %d, 1-resend %d, 2-resend %d, 3-resend %d, 3-resend-no-ack %d", + count[0], count[1], count[2], count[3], no_ack_count); + ESP_LOG_BUFFER_HEX("log", msg_record, MSG_TEST_COUNT * sizeof(msg_record[0])); + bzero(count, sizeof(count)); + no_ack_count = 0; + total_time = 0; + } +} + +static void example_ble_mesh_send_next(void) +{ + if (msg_index >= MSG_TEST_COUNT - 1) { + example_test_result_output(); + return; + } + + ++msg_index; + ++trans_num; + msg_record[msg_index].resend = 0; + msg_record[msg_index].acked = false; + msg_record[msg_index].time = 0; + + example_ble_mesh_send_test_msg(false); +} + static void example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_cb_param_t *param) { @@ -607,31 +685,50 @@ static void example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event ESP_LOGE(TAG, "%s, Invalid parameter", __func__); break; } + if (msg_to_internal && param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_STATUS) { + uint16_t value = *(uint16_t *)param->model_operation.msg; + ESP_LOGI(TAG, "response, %d %d %d", msg_index, value, trans_num); + if (value == trans_num) { + msg_record[msg_index].acked = true; + int64_t time = esp_timer_get_time(); + // ESP_LOGW(TAG, "End %lldus", time); + msg_record[msg_index].time = time - msg_record[msg_index].time; + + example_ble_mesh_send_next(); + } + } break; case ESP_BLE_MESH_MODEL_SEND_COMP_EVT: if (param->model_send_comp.err_code == ESP_OK) { + ESP_LOGI(TAG, "send, %d", msg_index); example_start_retransmit_timer(); if (msg_record[msg_index].resend == 0) { /* If send successfully in the first time, start the interval timer */ example_start_interval_timer(); msg_record[msg_index].time = esp_timer_get_time(); + // ESP_LOGW(TAG, "Start %lldus", msg_record[msg_index].time); } } break; case ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT: example_tx_rx_lock(); - if (param->client_recv_publish_msg.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_STATUS) { + if (msg_to_internal == false && param->client_recv_publish_msg.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_STATUS) { uint16_t value = *(uint16_t *)param->client_recv_publish_msg.msg; ESP_LOGI(TAG, "%d %d %d", msg_index, value, trans_num); if (value == trans_num && retrans_timer_start == true) { msg_record[msg_index].acked = true; esp_timer_stop(retransmit_timer); int64_t time = esp_timer_get_time(); + // ESP_LOGW(TAG, "End %lldus", time); msg_record[msg_index].time = time - msg_record[msg_index].time; } } example_tx_rx_unlock(); break; + case ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT: + ESP_LOGI(TAG, "timeout, %d", msg_index); + example_ble_mesh_send_test_msg(true); + break; default: break; } @@ -639,13 +736,19 @@ static void example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event void example_start_retransmit_timer(void) { - ESP_ERROR_CHECK(esp_timer_start_once(retransmit_timer, MSG_TIMEOUT)); + if (msg_to_internal) { + return; + } + esp_timer_start_once(retransmit_timer, MSG_TIMEOUT); retrans_timer_start = true; } static void example_start_interval_timer(void) { - ESP_ERROR_CHECK(esp_timer_start_once(interval_timer, MSG_INTERVAL)); + if (msg_to_internal) { + return; + } + esp_timer_start_once(interval_timer, MSG_INTERVAL); } static void retransmit_timer_callback(void* arg) @@ -661,57 +764,8 @@ static void retransmit_timer_callback(void* arg) static void interval_timer_callback(void* arg) { - /* Example timer timeout handler */ - if (msg_index >= MSG_TEST_COUNT - 1) { - uint32_t count[MSG_MAX_RESEND + 1] = {0}; - uint8_t compare[MSG_MAX_RESEND + 1]; - /** - * Used to record if resend reaches max number, whether we have - * received corresponding response. - */ - uint32_t no_ack_count = 0; - int64_t total_time = 0; - size_t i, j, k; - - for (i = 0; i < sizeof(compare); i++) { - compare[i] = i; - } - - ESP_LOGI(TAG, "ble mesh tx rx test finished"); - - for (i = 0; i < MSG_TEST_COUNT / MSG_TEST_UNIT; i++) { - for (j = 0; j < MSG_TEST_UNIT; j++) { - for (k = 0; k < sizeof(compare); k++) { - if (msg_record[i * MSG_TEST_UNIT + j].resend == compare[k]) { - count[k]++; - if (msg_record[i * MSG_TEST_UNIT + j].resend == MSG_MAX_RESEND && - msg_record[i * MSG_TEST_UNIT + j].acked == false) { - /* If msg is not acked, use 1s for its time */ - msg_record[msg_index].time = 1000000; - no_ack_count++; - } - break; - } - } - total_time += msg_record[msg_index].time; - } - ESP_LOGW(TAG, "Send messages the %d time, total %lldus, average %lldus", i, total_time, total_time / MSG_TEST_UNIT); - ESP_LOGW(TAG, "0-resend %d, 1-resend %d, 2-resend %d, 3-resend %d, 3-resend-no-ack %d", - count[0], count[1], count[2], count[3], no_ack_count); - ESP_LOG_BUFFER_HEX("log", msg_record, MSG_TEST_COUNT * sizeof(msg_record[0])); - bzero(count, sizeof(count)); - no_ack_count = 0; - total_time = 0; - } - return; - } - - ++msg_index; - ++trans_num; - msg_record[msg_index].resend = 0; - msg_record[msg_index].acked = false; - msg_record[msg_index].time = 0; - example_ble_mesh_send_test_msg(false); + /* Message interval timer timeout handler */ + example_ble_mesh_send_next(); } void example_ble_mesh_test_init(void) @@ -809,7 +863,10 @@ static esp_err_t ble_mesh_init(void) ESP_LOGE(TAG, "%s: Failed to deinitialize vnd client model", __func__); return err; } - err = esp_ble_mesh_deinit(); + esp_ble_mesh_deinit_param_t param = { + .erase_flash = false, + }; + err = esp_ble_mesh_deinit(¶m); if (err != ESP_OK) { ESP_LOGE(TAG, "%s: Failed to de-initialize BLE Mesh", __func__); return err; diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/board.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/board.c index 03dd9433c7..77f8a92056 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/board.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/coex_a2dp_mini/components/mesh_tx/board.c @@ -72,7 +72,10 @@ static void button_tap_cb(void* arg) if (example_deinit_test == true) { static uint8_t count; if (count++ % 2 == 0) { - if (esp_ble_mesh_deinit() != ESP_OK) { + esp_ble_mesh_deinit_param_t param = { + .erase_flash = false, + }; + if (esp_ble_mesh_deinit(¶m) != ESP_OK) { ESP_LOGE(TAG, "%s, BLE Mesh deinit failed", __func__); } else { ESP_LOGW(TAG, "BLE Mesh deinit"); @@ -83,7 +86,9 @@ static void button_tap_cb(void* arg) } } } else { - esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_STANDBY | ESP_COEX_BLE_ST_MESH_TRAFFIC | ESP_COEX_BLE_ST_MESH_CONFIG); + esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_CONFIG); + esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_TRAFFIC); + esp_coex_status_bit_clear(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_STANDBY); esp_coex_status_bit_set(ESP_COEX_ST_TYPE_BLE, ESP_COEX_BLE_ST_MESH_TRAFFIC); ESP_LOGW(TAG, "BLE Mesh enters Traffic mode"); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_init.h b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_init.h index fd21430efd..c7ba05f3b5 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_init.h +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_init.h @@ -9,7 +9,7 @@ #ifndef _BLE_MESH_DEMO_INIT_H_ #define _BLE_MESH_DEMO_INIT_H_ -#define TAG "ble_mesh_rx" +#define TAG "R" void ble_mesh_get_dev_uuid(uint8_t *dev_uuid); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_main.c index ad26893eda..91408a73d7 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_tx_rx_test/test_rx/main/ble_mesh_demo_main.c @@ -183,10 +183,10 @@ static void example_ble_mesh_custom_model_cb(esp_ble_mesh_model_cb_event_t event break; } if (param->model_operation.opcode == ESP_BLE_MESH_VND_MODEL_OP_TEST_SEND) { - // uint16_t value = *(uint16_t *)param->model_operation.msg; - // ESP_LOGI(TAG, "%d %d", value, trans_num); - err = esp_ble_mesh_server_model_send_msg(&vnd_models[0], param->model_operation.ctx, ESP_BLE_MESH_VND_MODEL_OP_TEST_STATUS, - param->model_operation.length, param->model_operation.msg); + uint16_t value = *(uint16_t *)param->model_operation.msg; + ESP_LOGI(TAG, "%d", value); + err = esp_ble_mesh_server_model_send_msg(&vnd_models[0], param->model_operation.ctx, + ESP_BLE_MESH_VND_MODEL_OP_TEST_STATUS, sizeof(value), (uint8_t *)&value); if (err) { ESP_LOGE(TAG, "Faild to send test status"); } diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.c index 198b4bb75b..d5dd42c0a4 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.c @@ -112,7 +112,7 @@ static void enable_gatt_proxy_cb(struct k_work *work) static void example_free_set_info(example_fast_prov_server_t *srv) { if (srv && srv->set_info) { - osi_free(srv->set_info); + bt_mesh_free(srv->set_info); srv->set_info = NULL; } } @@ -270,7 +270,7 @@ esp_err_t example_fast_prov_server_recv_msg(esp_ble_mesh_model_t *model, } memcpy(&srv->ctx, ctx, sizeof(esp_ble_mesh_msg_ctx_t)); - srv->set_info = osi_calloc(sizeof(struct fast_prov_info_set)); + srv->set_info = bt_mesh_calloc(sizeof(struct fast_prov_info_set)); if (!srv->set_info) { ESP_LOGE(TAG, "%s: Failed to allocate memory", __func__); bt_mesh_free_buf(msg);