fix(wpa_supplicant): Restructuring DPP init method to ensure cleanup

- Restructuring DPP init function to ensure cleanup of variables in case of
  init failure
This commit is contained in:
jgujarathi 2023-11-22 14:54:12 +05:30 committed by aditi_lonkar
parent 5e20319831
commit dcc14e8c15

View File

@ -647,6 +647,7 @@ bool is_dpp_enabled(void)
esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
{
esp_err_t ret = ESP_OK;
wifi_mode_t mode = 0;
if (esp_wifi_get_mode(&mode) || ((mode != WIFI_MODE_STA) && (mode != WIFI_MODE_APSTA))) {
wpa_printf(MSG_ERROR, "DPP: failed to init as not in station mode.");
@ -661,31 +662,42 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
wpa_printf(MSG_ERROR, "DPP: failed to init as init already done.");
return ESP_FAIL;
}
struct dpp_global_config cfg = {0};
int ret;
os_bzero(&s_dpp_ctx, sizeof(s_dpp_ctx));
s_dpp_ctx.dpp_event_cb = cb;
struct dpp_global_config cfg = {0};
cfg.cb_ctx = &s_dpp_ctx;
cfg.msg_ctx = &s_dpp_ctx;
s_dpp_ctx.dpp_global = dpp_global_init(&cfg);
s_dpp_listen_in_progress = false;
s_dpp_evt_queue = os_queue_create(3, sizeof(dpp_event_t));
ret = os_task_create(esp_dpp_task, "dppT", DPP_TASK_STACK_SIZE, NULL, 2, &s_dpp_task_hdl);
if (ret != TRUE) {
wpa_printf(MSG_ERROR, "DPP: failed to create task");
return ESP_FAIL;
if (!s_dpp_ctx.dpp_global) {
wpa_printf(MSG_ERROR, "DPP: failed to allocate memory for dpp_global");
ret = ESP_ERR_NO_MEM;
goto init_fail;
}
s_dpp_api_lock = os_recursive_mutex_create();
if (!s_dpp_api_lock) {
esp_supp_dpp_deinit();
wpa_printf(MSG_ERROR, "DPP: dpp_init: failed to create DPP API lock");
return ESP_ERR_NO_MEM;
ret = ESP_ERR_NO_MEM;
goto init_fail;
}
s_dpp_evt_queue = os_queue_create(3, sizeof(dpp_event_t));
if (!s_dpp_evt_queue) {
wpa_printf(MSG_ERROR, "DPP: dpp_init: failed to create DPP API queue");
ret = ESP_ERR_NO_MEM;
goto init_fail;
}
ret = os_task_create(esp_dpp_task, "dppT", DPP_TASK_STACK_SIZE, NULL, 2, &s_dpp_task_hdl);
if (ret != TRUE) {
wpa_printf(MSG_ERROR, "DPP: failed to create task");
ret = ESP_ERR_NO_MEM;
goto init_fail;
}
s_dpp_listen_in_progress = false;
s_dpp_ctx.dpp_event_cb = cb;
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_ACTION_TX_STATUS,
&offchan_event_handler, NULL);
esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_ROC_DONE,
@ -694,8 +706,21 @@ esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)
wpa_printf(MSG_INFO, "esp_dpp_task prio:%d, stack:%d", 2, DPP_TASK_STACK_SIZE);
return ESP_OK;
init_fail:
if (s_dpp_ctx.dpp_global) {
dpp_global_deinit(s_dpp_ctx.dpp_global);
s_dpp_ctx.dpp_global = NULL;
}
if (s_dpp_api_lock) {
os_mutex_delete(s_dpp_api_lock);
s_dpp_api_lock = NULL;
}
if (s_dpp_evt_queue) {
os_queue_delete(s_dpp_evt_queue);
s_dpp_evt_queue = NULL;
}
return ret;
}
void esp_supp_dpp_deinit(void)
{