diff --git a/examples/wifi/softap_sta/main/Kconfig.projbuild b/examples/wifi/softap_sta/main/Kconfig.projbuild index efe764a8c1..c7af159014 100644 --- a/examples/wifi/softap_sta/main/Kconfig.projbuild +++ b/examples/wifi/softap_sta/main/Kconfig.projbuild @@ -56,9 +56,9 @@ menu "Example Configuration" default ESP_WIFI_AUTH_WPA2_PSK help The weakest authmode to accept in the scan mode. - This value defaults to ESP_WIFI_AUTH_WPA2_PSK incase password is present + This value defaults to ESP_WIFI_AUTH_WPA2_PSK in case password is present and ESP_WIFI_AUTH_OPEN is used. Please select ESP_WIFI_AUTH_WEP / ESP_WIFI_AUTH_WPA_PSK - incase AP is operating in WEP / WPA mode. + in case AP is operating in WEP / WPA mode. config ESP_WIFI_AUTH_OPEN bool "OPEN" diff --git a/examples/wifi/softap_sta/main/softap_sta.c b/examples/wifi/softap_sta/main/softap_sta.c index e10b21ec8a..c6c5b5f688 100644 --- a/examples/wifi/softap_sta/main/softap_sta.c +++ b/examples/wifi/softap_sta/main/softap_sta.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -73,6 +73,9 @@ #define WIFI_CONNECTED_BIT BIT0 #define WIFI_FAIL_BIT BIT1 +/*DHCP server option*/ +#define DHCPS_OFFER_DNS 0x02 + static const char *TAG_AP = "WiFi SoftAP"; static const char *TAG_STA = "WiFi Sta"; @@ -162,6 +165,17 @@ esp_netif_t *wifi_init_sta(void) return esp_netif_sta; } +void softap_set_dns_addr(esp_netif_t *esp_netif_ap,esp_netif_t *esp_netif_sta) +{ + esp_netif_dns_info_t dns; + esp_netif_get_dns_info(esp_netif_sta,ESP_NETIF_DNS_MAIN,&dns); + uint8_t dhcps_offer_option = DHCPS_OFFER_DNS; + ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_stop(esp_netif_ap)); + ESP_ERROR_CHECK(esp_netif_dhcps_option(esp_netif_ap, ESP_NETIF_OP_SET, ESP_NETIF_DOMAIN_NAME_SERVER, &dhcps_offer_option, sizeof(dhcps_offer_option))); + ESP_ERROR_CHECK(esp_netif_set_dns_info(esp_netif_ap, ESP_NETIF_DNS_MAIN, &dns)); + ESP_ERROR_CHECK_WITHOUT_ABORT(esp_netif_dhcps_start(esp_netif_ap)); +} + void app_main(void) { ESP_ERROR_CHECK(esp_netif_init()); @@ -223,6 +237,7 @@ void app_main(void) if (bits & WIFI_CONNECTED_BIT) { ESP_LOGI(TAG_STA, "connected to ap SSID:%s password:%s", EXAMPLE_ESP_WIFI_STA_SSID, EXAMPLE_ESP_WIFI_STA_PASSWD); + softap_set_dns_addr(esp_netif_ap,esp_netif_sta); } else if (bits & WIFI_FAIL_BIT) { ESP_LOGI(TAG_STA, "Failed to connect to SSID:%s, password:%s", EXAMPLE_ESP_WIFI_STA_SSID, EXAMPLE_ESP_WIFI_STA_PASSWD);