From 3ef35e1b7839f374a1539a9aad6d61513614f248 Mon Sep 17 00:00:00 2001
From: Gunar Schorcht <gunar@schorcht.net>
Date: Sun, 13 Jan 2019 17:10:46 +0100
Subject: [PATCH] cpu/esp32: use static WiFi config in esp_wifi

The WiFi configuration has to be static to avoid memory access problems when WiFi AP is reconnected.
---
 cpu/esp32/esp-wifi/esp_wifi_netdev.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/cpu/esp32/esp-wifi/esp_wifi_netdev.c b/cpu/esp32/esp-wifi/esp_wifi_netdev.c
index 89efab343f..c3b8dc3d0e 100644
--- a/cpu/esp32/esp-wifi/esp_wifi_netdev.c
+++ b/cpu/esp32/esp-wifi/esp_wifi_netdev.c
@@ -137,6 +137,19 @@ static esp_err_t IRAM_ATTR _esp_system_event_handler(void *ctx, system_event_t *
 #define CONFIG_WIFI_STA_RSSI        -127
 #define CONFIG_WIFI_STA_AUTHMODE    WIFI_AUTH_WPA_WPA2_PSK
 
+/* we use predefined station configuration */
+static wifi_config_t wifi_config_sta = {
+    .sta = {
+        .ssid = CONFIG_WIFI_STA_SSID,
+        .password = CONFIG_WIFI_STA_PASSWORD,
+        .channel = CONFIG_WIFI_STA_CHANNEL,
+        .scan_method = CONFIG_WIFI_STA_SCAN_METHOD,
+        .sort_method = CONFIG_WIFI_STA_SORT_METHOD,
+        .threshold.rssi = CONFIG_WIFI_STA_RSSI,
+        .threshold.authmode = CONFIG_WIFI_STA_AUTHMODE
+    }
+};
+
 static void esp_wifi_setup (esp_wifi_netdev_t* dev)
 {
     DEBUG("%s: %p\n", __func__, dev);
@@ -171,19 +184,6 @@ static void esp_wifi_setup (esp_wifi_netdev_t* dev)
     /* TODO */
     #endif
 
-    /* we use predefined station configuration */
-    wifi_config_t wifi_config_sta = {
-        .sta = {
-            .ssid = CONFIG_WIFI_STA_SSID,
-            .password = CONFIG_WIFI_STA_PASSWORD,
-            .channel = CONFIG_WIFI_STA_CHANNEL,
-            .scan_method = CONFIG_WIFI_STA_SCAN_METHOD,
-            .sort_method = CONFIG_WIFI_STA_SORT_METHOD,
-            .threshold.rssi = CONFIG_WIFI_STA_RSSI,
-            .threshold.authmode = CONFIG_WIFI_STA_AUTHMODE
-        }
-    };
-
     result = esp_wifi_set_mode(WIFI_MODE_STA);
     if (result != ESP_OK) {
        LOG_TAG_ERROR("esp_wifi", "esp_wifi_set_mode failed with return value %d\n", result);
-- 
GitLab