diff --git a/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_utils.c b/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_utils.c index fe12aa3588..df5388755e 100644 --- a/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_utils.c +++ b/arch/risc-v/src/esp32c3-legacy/esp32c3_wifi_utils.c @@ -87,7 +87,7 @@ static struct wifi_scan_result_s g_scan_priv = { .scan_signal = SEM_INITIALIZER(0), }; -static uint8_t g_channel_num = 0; +static uint8_t g_channel_num; static uint8_t g_channel_list[CHANNEL_MAX_NUM]; /**************************************************************************** @@ -199,10 +199,10 @@ int esp_wifi_start_scan(struct iwreq *iwr) esp_wifi_start(); ret = esp_wifi_scan_start(config, false); - g_scan_priv.scan_status = ESP_SCAN_RUN; if (ret != OK) { wlerr("ERROR: Scan error, ret: %d\n", ret); + ret = ERROR; } else { @@ -223,11 +223,16 @@ int esp_wifi_start_scan(struct iwreq *iwr) } } - if (config != NULL) + if (config) { kmm_free(config); config = NULL; + } + + if (ret == OK) + { wlinfo("INFO: start scan\n"); + g_scan_priv.scan_status = ESP_SCAN_RUN; } return ret; @@ -257,7 +262,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) if (g_scan_priv.scan_status == ESP_SCAN_RUN) { irqstate_t irqstate = enter_critical_section(); - if (scan_block == false) + if (!scan_block) { scan_block = true; leave_critical_section(irqstate); @@ -273,7 +278,8 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) } else if (g_scan_priv.scan_status == ESP_SCAN_DISABLED) { - return -EINVAL; + ret = -EINVAL; + goto exit_failed; } if ((iwr == NULL) || (g_scan_priv.scan_status != ESP_SCAN_DONE)) @@ -291,6 +297,13 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) goto exit_failed; } + if (priv->scan_result_size <= 0) + { + ret = OK; + iwr->u.data.length = 0; + goto exit_free_buffer; + } + if (iwr->u.data.pointer == NULL || iwr->u.data.length < priv->scan_result_size) { @@ -299,14 +312,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) ret = -E2BIG; iwr->u.data.pointer = NULL; iwr->u.data.length = priv->scan_result_size; - goto exit_failed; - } - - if (priv->scan_result_size <= 0) - { - ret = OK; - iwr->u.data.length = 0; - goto exit_free_buffer; + return ret; } /* Copy result to user buffer */ @@ -410,7 +416,7 @@ void esp_wifi_scan_event_parse(void) is_target_channel = true; } - if (is_target_channel == true) + if (is_target_channel) { result_size = WIFI_SCAN_RESULT_SIZE - priv->scan_result_size; @@ -544,7 +550,7 @@ scan_result_full: /* Continue instead of break to log dropped AP results */ - if (parse_done == false) + if (!parse_done) { wlerr("ERROR: No more space in scan_result buffer\n"); } diff --git a/arch/risc-v/src/esp32c3-legacy/esp32c3_wlan.c b/arch/risc-v/src/esp32c3-legacy/esp32c3_wlan.c index 590aadf404..d56ae4ac0b 100644 --- a/arch/risc-v/src/esp32c3-legacy/esp32c3_wlan.c +++ b/arch/risc-v/src/esp32c3-legacy/esp32c3_wlan.c @@ -146,7 +146,7 @@ struct wlan_priv_s /* Reference count of register Wi-Fi handler */ -static uint8_t g_callback_register_ref = 0; +static uint8_t g_callback_register_ref; static struct wlan_priv_s g_wlan_priv[ESP32C3_WLAN_DEVS]; @@ -1383,7 +1383,7 @@ int esp32c3_wlan_sta_set_linkstatus(bool linkstatus) { struct wlan_priv_s *priv = &g_wlan_priv[ESP32C3_WLAN_STA_DEVNO]; - if (linkstatus == true) + if (linkstatus) { netdev_carrier_on(&priv->dev); } diff --git a/arch/xtensa/src/esp32/esp32_wifi_utils.c b/arch/xtensa/src/esp32/esp32_wifi_utils.c index 200482d2f4..d6ae1317e1 100644 --- a/arch/xtensa/src/esp32/esp32_wifi_utils.c +++ b/arch/xtensa/src/esp32/esp32_wifi_utils.c @@ -95,7 +95,7 @@ static struct wifi_scan_result g_scan_priv = { .scan_signal = SEM_INITIALIZER(0), }; -static uint8_t g_channel_num = 0; +static uint8_t g_channel_num; static uint8_t g_channel_list[CHANNEL_MAX_NUM]; /**************************************************************************** @@ -209,6 +209,7 @@ int esp_wifi_start_scan(struct iwreq *iwr) if (ret != OK) { wlerr("ERROR: Scan error, ret: %d\n", ret); + ret = ERROR; } else { @@ -233,10 +234,13 @@ int esp_wifi_start_scan(struct iwreq *iwr) { kmm_free(config); config = NULL; - wlinfo("INFO: start scan\n"); } - g_scan_priv.scan_status = ESP_SCAN_RUN; + if (ret == OK) + { + wlinfo("INFO: start scan\n"); + g_scan_priv.scan_status = ESP_SCAN_RUN; + } return ret; } @@ -265,7 +269,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) if (g_scan_priv.scan_status == ESP_SCAN_RUN) { irqstate_t irqstate = enter_critical_section(); - if (scan_block == false) + if (!scan_block) { scan_block = true; leave_critical_section(irqstate); @@ -281,7 +285,8 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) } else if (g_scan_priv.scan_status == ESP_SCAN_DISABLED) { - return -EINVAL; + ret = -EINVAL; + goto exit_failed; } if ((iwr == NULL) || (g_scan_priv.scan_status != ESP_SCAN_DONE)) @@ -299,6 +304,13 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) goto exit_failed; } + if (priv->scan_result_size <= 0) + { + ret = OK; + iwr->u.data.length = 0; + goto exit_free_buffer; + } + if (iwr->u.data.pointer == NULL || iwr->u.data.length < priv->scan_result_size) { @@ -307,14 +319,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) ret = -E2BIG; iwr->u.data.pointer = NULL; iwr->u.data.length = priv->scan_result_size; - goto exit_failed; - } - - if (priv->scan_result_size <= 0) - { - ret = OK; - iwr->u.data.length = 0; - goto exit_free_buffer; + return ret; } /* Copy result to user buffer */ @@ -418,7 +423,7 @@ void esp_wifi_scan_event_parse(void) is_target_channel = true; } - if (is_target_channel == true) + if (is_target_channel) { result_size = WIFI_SCAN_RESULT_SIZE - priv->scan_result_size; @@ -552,7 +557,7 @@ scan_result_full: /* Continue instead of break to log dropped AP results */ - if (parse_done == false) + if (!parse_done) { wlerr("ERROR: No more space in scan_result buffer\n"); } diff --git a/arch/xtensa/src/esp32/esp32_wlan.c b/arch/xtensa/src/esp32/esp32_wlan.c index 9c8b2be0e9..c242db1906 100644 --- a/arch/xtensa/src/esp32/esp32_wlan.c +++ b/arch/xtensa/src/esp32/esp32_wlan.c @@ -201,7 +201,7 @@ struct wlan_priv_s /* Reference count of register Wi-Fi handler */ -static uint8_t g_callback_register_ref = 0; +static uint8_t g_callback_register_ref; static struct wlan_priv_s g_wlan_priv[ESP32_WLAN_DEVS]; diff --git a/arch/xtensa/src/esp32s3/esp32s3_wifi_utils.c b/arch/xtensa/src/esp32s3/esp32s3_wifi_utils.c index 5a418504ea..65d1704ccf 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_wifi_utils.c +++ b/arch/xtensa/src/esp32s3/esp32s3_wifi_utils.c @@ -96,7 +96,7 @@ static struct wifi_scan_result g_scan_priv = { .scan_signal = SEM_INITIALIZER(0), }; -static uint8_t g_channel_num = 0; +static uint8_t g_channel_num; static uint8_t g_channel_list[CHANNEL_MAX_NUM]; /**************************************************************************** @@ -210,6 +210,7 @@ int esp_wifi_start_scan(struct iwreq *iwr) if (ret != OK) { wlerr("ERROR: Scan error, ret: %d\n", ret); + ret = ERROR; } else { @@ -234,10 +235,13 @@ int esp_wifi_start_scan(struct iwreq *iwr) { kmm_free(config); config = NULL; - wlinfo("INFO: start scan\n"); } - g_scan_priv.scan_status = ESP_SCAN_RUN; + if (ret == OK) + { + wlinfo("INFO: start scan\n"); + g_scan_priv.scan_status = ESP_SCAN_RUN; + } return ret; } @@ -266,7 +270,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) if (g_scan_priv.scan_status == ESP_SCAN_RUN) { irqstate_t irqstate = enter_critical_section(); - if (scan_block == false) + if (!scan_block) { scan_block = true; leave_critical_section(irqstate); @@ -282,7 +286,8 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) } else if (g_scan_priv.scan_status == ESP_SCAN_DISABLED) { - return -EINVAL; + ret = -EINVAL; + goto exit_failed; } if ((iwr == NULL) || (g_scan_priv.scan_status != ESP_SCAN_DONE)) @@ -300,6 +305,13 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) goto exit_failed; } + if (priv->scan_result_size <= 0) + { + ret = OK; + iwr->u.data.length = 0; + goto exit_free_buffer; + } + if (iwr->u.data.pointer == NULL || iwr->u.data.length < priv->scan_result_size) { @@ -308,14 +320,7 @@ int esp_wifi_get_scan_results(struct iwreq *iwr) ret = -E2BIG; iwr->u.data.pointer = NULL; iwr->u.data.length = priv->scan_result_size; - goto exit_failed; - } - - if (priv->scan_result_size <= 0) - { - ret = OK; - iwr->u.data.length = 0; - goto exit_free_buffer; + return ret; } /* Copy result to user buffer */ @@ -419,7 +424,7 @@ void esp_wifi_scan_event_parse(void) is_target_channel = true; } - if (is_target_channel == true) + if (is_target_channel) { result_size = WIFI_SCAN_RESULT_SIZE - priv->scan_result_size; @@ -553,7 +558,7 @@ scan_result_full: /* Continue instead of break to log dropped AP results */ - if (parse_done == false) + if (!parse_done) { wlerr("ERROR: No more space in scan_result buffer\n"); } diff --git a/arch/xtensa/src/esp32s3/esp32s3_wlan.c b/arch/xtensa/src/esp32s3/esp32s3_wlan.c index 5ea2735738..92c37d74c3 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_wlan.c +++ b/arch/xtensa/src/esp32s3/esp32s3_wlan.c @@ -150,7 +150,7 @@ struct wlan_priv_s /* Reference count of register Wi-Fi handler */ -static uint8_t g_callback_register_ref = 0; +static uint8_t g_callback_register_ref; static struct wlan_priv_s g_wlan_priv[ESP32S3_WLAN_DEVS]; @@ -1373,7 +1373,7 @@ int esp32s3_wlan_sta_set_linkstatus(bool linkstatus) { struct wlan_priv_s *priv = &g_wlan_priv[ESP32S3_WLAN_STA_DEVNO]; - if (linkstatus == true) + if (linkstatus) { netdev_carrier_on(&priv->dev); }