Skip to content

Commit cd33cc8

Browse files
committed
fix(esp_hosted_ng): add support for scan in ap mode
Github PR #563
1 parent 85a95c9 commit cd33cc8

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

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

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,7 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base,
492492
switch (event_id) {
493493

494494
case WIFI_EVENT_STA_START:
495-
ESP_LOGI(TAG, "station started and disabled softap mode");
496-
softap_started = 0;
495+
ESP_LOGI(TAG, "station started");
497496
sta_init_flag = 1;
498497
break;
499498

@@ -1281,7 +1280,8 @@ int process_disconnect(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
12811280
esp_wifi_deauthenticate_internal(cmd_disconnect->reason_code);
12821281
}
12831282
} else if (if_type == ESP_AP_IF) {
1284-
if (softap_started && (wifi_mode == WIFI_MODE_AP || wifi_mode == WIFI_MODE_APSTA)) {
1283+
if (softap_started &&
1284+
(wifi_mode == WIFI_MODE_AP || wifi_mode == WIFI_MODE_APSTA)) {
12851285
ieee80211_delete_node(cmd_disconnect->mac);
12861286
}
12871287
}
@@ -1528,43 +1528,40 @@ int process_deinit_interface(uint8_t if_type, uint8_t *payload, uint16_t payload
15281528
int process_init_interface(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
15291529
{
15301530
esp_err_t ret = ESP_OK;
1531-
wifi_mode_t mode = WIFI_MODE_STA;
15321531
uint16_t cmd_status = CMD_RESPONSE_FAIL;
15331532

1534-
if (!sta_init_flag) {
1535-
1533+
if (!sta_init_flag || (if_type == ESP_AP_IF && !softap_started)) {
15361534
/* Register to get events from wifi driver */
15371535
esp_create_wifi_event_loop();
15381536

1539-
/* we will use this mac for both ap and station mode */
1537+
/* Use same MAC for AP and STA */
15401538
esp_read_mac(dev_mac, ESP_MAC_WIFI_STA);
1541-
if (if_type == ESP_STA_IF) {
1542-
mode = WIFI_MODE_STA;
1539+
1540+
if (if_type == ESP_AP_IF) {
1541+
ESP_GOTO_ON_ERROR(esp_wifi_disconnect(), done, TAG, "Station Disconnect failed");
1542+
ESP_GOTO_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_APSTA), done, TAG, "Setting mode to APSTA failed");
1543+
ESP_LOGI(TAG, "Setting APSTA mode");
1544+
wifi_config_t wifi_config = {0};
1545+
ESP_GOTO_ON_ERROR(esp_wifi_set_config(WIFI_IF_STA, &wifi_config), done, TAG, "Set config for sta failed");
1546+
} else if (if_type == ESP_STA_IF) {
1547+
ESP_LOGI(TAG, "Setting STA mode");
1548+
ESP_GOTO_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_STA), done, TAG, "Setting mode to STA failed");
15431549
} else {
1544-
mode = WIFI_MODE_APSTA;
1550+
ESP_LOGE(TAG, "Invalid interface type");
1551+
goto done;
15451552
}
15461553

1547-
ret = esp_wifi_set_mode(mode);
1554+
ESP_GOTO_ON_ERROR(esp_wifi_start(), done, TAG, "Failed to start Wi-Fi");
15481555

1549-
if (ret) {
1550-
ESP_LOGE(TAG, "Failed to set wifi mode\n");
1551-
goto DONE;
1552-
}
1553-
ret = esp_wifi_start();
1554-
if (ret) {
1555-
ESP_LOGE(TAG, "Failed to start wifi\n");
1556-
goto DONE;
1557-
}
15581556
}
15591557
cmd_status = CMD_RESPONSE_SUCCESS;
1560-
DONE:
1558+
done:
15611559
ret = send_command_resp(if_type, CMD_INIT_INTERFACE, cmd_status, NULL, 0, 0);
1562-
if (ret) {
1560+
if (ret != ESP_OK) {
15631561
deinitialize_wifi();
15641562
}
15651563

15661564
return ret;
1567-
15681565
}
15691566

15701567
int process_get_mac(uint8_t if_type)
@@ -1806,17 +1803,19 @@ int process_set_mode(uint8_t if_type, uint8_t *payload, uint16_t payload_len)
18061803
if (ret) {
18071804
ESP_LOGE(TAG, "Failed to stop wifi\n");
18081805
}
1809-
1806+
18101807
if (mode->mode == WIFI_MODE_AP || mode->mode == WIFI_MODE_APSTA) {
18111808
ESP_LOGI(TAG, "Setting APSTA mode");
18121809
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_STA, dummy_mac), send_err, TAG, "Setting MAC on STA failed");
18131810
ESP_GOTO_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_APSTA), send_err, TAG, "Setting mode to APSTA failed");
18141811
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_AP, dev_mac), send_err, TAG, "Setting MAC on AP failed");
1812+
wifi_config_t wifi_config = {0};
1813+
ESP_GOTO_ON_ERROR(esp_wifi_set_config(WIFI_IF_STA, &wifi_config), send_err, TAG, "Set config for sta failed");
18151814
} else if (mode->mode == WIFI_MODE_STA) {
18161815
ESP_LOGI(TAG, "Setting STA mode");
18171816
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_AP, dummy_mac2), send_err, TAG, "Setting MAC on AP failed");
18181817
ESP_GOTO_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_STA), send_err, TAG, "Setting mode to STA failed");
1819-
ESP_GOTO_ON_ERROR(esp_wifi_set_mac(WIFI_IF_STA, dev_mac), send_err, TAG, "Setting MAC on STA failed");
1818+
ESP_ERROR_CHECK(esp_wifi_set_mac(WIFI_IF_STA, dev_mac));
18201819
}
18211820

18221821
ESP_GOTO_ON_ERROR(esp_wifi_start(), send_err, TAG, "Cannot start wifi");
@@ -1949,8 +1948,8 @@ int process_set_ap_config(uint8_t if_type, uint8_t *payload, uint16_t payload_le
19491948

19501949
ret = esp_wifi_stop();
19511950

1952-
if (old_mode != WIFI_MODE_AP) {
1953-
ret = esp_wifi_set_mode(WIFI_MODE_AP);
1951+
if (old_mode != WIFI_MODE_APSTA) {
1952+
ret = esp_wifi_set_mode(WIFI_MODE_APSTA);
19541953
}
19551954
esp_wifi_set_config(WIFI_IF_AP, &wifi_config);
19561955

esp_hosted_ng/esp/esp_driver/network_adapter/main/include/esp_fw_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#define PROJECT_VERSION_MAJOR_2 0
1010
#define PROJECT_VERSION_MINOR 3
1111
#define PROJECT_REVISION_PATCH_1 0
12-
#define PROJECT_REVISION_PATCH_2 14
12+
#define PROJECT_REVISION_PATCH_2 15
1313

1414
#endif

esp_hosted_ng/host/esp_cfg80211.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "esp_cfg80211.h"
1313
#include "esp_cmd.h"
1414
#include "esp_kernel_port.h"
15+
#include "esp_utils.h"
1516

1617
/**
1718
* @brief WiFi PHY rate encodings
@@ -353,16 +354,13 @@ static int esp_nl_mode_to_esp_iface(enum nl80211_iftype type)
353354
return ESP_MAX_IF;
354355
}
355356

356-
static int8_t esp_get_mode_from_iface_type(int iface_type) {
357-
// Numbers returned bellow have the following meaning
358-
// 3 => WIFI_MODE_APSTA
359-
// 1 => WIFI_MODE_STA
360-
357+
static int8_t esp_get_mode_from_iface_type(int iface_type)
358+
{
361359
if (iface_type == ESP_AP_IF) {
362-
return 3;
360+
return WIFI_MODE_APSTA;
363361
}
364362

365-
return 1;
363+
return WIFI_MODE_STA;
366364
}
367365

368366
static int esp_cfg80211_change_iface(struct wiphy *wiphy,

esp_hosted_ng/host/include/esp_fw_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
#define PROJECT_VERSION_MAJOR_2 0
1010
#define PROJECT_VERSION_MINOR 3
1111
#define PROJECT_REVISION_PATCH_1 0
12-
#define PROJECT_REVISION_PATCH_2 14
12+
#define PROJECT_REVISION_PATCH_2 15
1313

1414
#endif

esp_hosted_ng/host/include/esp_utils.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ int wpa_cipher_to_alg(int cipher);
3939

4040
char * esp_chipname_from_id(int chipset_id);
4141

42+
typedef enum {
43+
WIFI_MODE_NULL = 0, /**< Null mode */
44+
WIFI_MODE_STA, /**< Wi-Fi station mode */
45+
WIFI_MODE_AP, /**< Wi-Fi soft-AP mode */
46+
WIFI_MODE_APSTA, /**< Wi-Fi station + soft-AP mode */
47+
WIFI_MODE_MAX
48+
} esp_wifi_mode_t;
49+
4250
#endif

0 commit comments

Comments
 (0)