Skip to content

Commit ab2add4

Browse files
committed
Fix set_mode mode handling
1 parent df87df6 commit ab2add4

File tree

1 file changed

+17
-24
lines changed
  • esp_hosted_ng/esp/esp_driver/network_adapter/main

1 file changed

+17
-24
lines changed

esp_hosted_ng/esp/esp_driver/network_adapter/main/cmd.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "esp_wifi_driver.h"
2424
#include "esp_event.h"
2525
#include "esp_mac.h"
26+
#include "esp_check.h"
2627
#include "wifi_defs.h"
2728
#include <time.h>
2829
#include <sys/time.h>
@@ -1759,7 +1760,7 @@ int process_add_key(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
17591760
int process_set_mode(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
17601761
{
17611762
esp_err_t ret = ESP_OK;
1762-
uint8_t cmd_status = CMD_RESPONSE_SUCCESS;
1763+
uint8_t cmd_status = CMD_RESPONSE_FAIL;
17631764
struct cmd_config_mode *mode = (struct cmd_config_mode *) payload;
17641765
wifi_mode_t old_mode;
17651766

@@ -1771,40 +1772,32 @@ int process_set_mode(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
17711772

17721773
if (old_mode == mode->mode) {
17731774
ESP_LOGI(TAG, "old mode and new modes are same, return");
1774-
goto send_resp;
1775+
goto send_ok;
17751776
}
17761777
ret = esp_wifi_stop();
17771778
if (ret) {
17781779
ESP_LOGE(TAG, "Failed to stop wifi\n");
17791780
}
17801781

1781-
if (mode->mode == WIFI_MODE_AP) {
1782-
ret = esp_wifi_set_mac(WIFI_IF_STA, dummy_mac);
1782+
if (mode->mode == WIFI_MODE_AP || mode->mode == WIFI_MODE_APSTA) {
1783+
ESP_LOGI(TAG, "Setting APSTA mode");
1784+
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_STA, dummy_mac), send_err, TAG, "Setting MAC on STA failed");
1785+
ESP_GOTO_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_APSTA), send_err, TAG, "Setting mode to APSTA failed");
1786+
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_AP, dev_mac), send_err, TAG, "Setting MAC on AP failed");
17831787
} else if (mode->mode == WIFI_MODE_STA){
1784-
ret = esp_wifi_set_mac(WIFI_IF_AP, dummy_mac2);
1788+
ESP_LOGI(TAG, "Setting STA mode");
1789+
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_AP, dummy_mac2), send_err, TAG, "Setting MAC on AP failed");
1790+
ESP_GOTO_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_STA), send_err, TAG, "Setting mode to STA failed");
1791+
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_STA, dev_mac), send_err, TAG, "Setting MAC on STA failed");
17851792
}
17861793

1787-
ESP_LOGI(TAG, "Setting mode=%d \n", mode->mode);
1788-
ret = esp_wifi_set_mode(mode->mode);
1789-
if (mode->mode == WIFI_MODE_AP) {
1790-
ret = esp_wifi_set_mac(WIFI_IF_AP, dev_mac);
1791-
} else if (mode->mode == WIFI_MODE_STA){
1792-
ret = esp_wifi_set_mac(WIFI_IF_STA, dev_mac);
1793-
}
1794-
1795-
ESP_ERROR_CHECK(esp_wifi_start());
1796-
1797-
if (ret) {
1798-
ESP_LOGE(TAG, "Failed to set mode\n");
1799-
cmd_status = CMD_RESPONSE_FAIL;
1800-
goto send_resp;
1801-
}
1794+
ESP_GOTO_ON_ERROR(esp_wifi_start(), send_err, TAG, "Cannot start wifi");
18021795

1803-
send_resp:
1804-
ret = send_command_resp(if_type, CMD_SET_MODE, cmd_status, (uint8_t *)&mode->mode,
1796+
send_ok:
1797+
cmd_status = CMD_RESPONSE_SUCCESS;
1798+
send_err:
1799+
return send_command_resp(if_type, CMD_SET_MODE, cmd_status, (uint8_t *)&mode->mode,
18051800
sizeof(uint16_t), sizeof(struct command_header));
1806-
1807-
return ret;
18081801
}
18091802

18101803
int process_set_ie(uint8_t if_type, uint8_t *payload, uint16_t payload_len)

0 commit comments

Comments
 (0)