espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.65k stars 7.41k forks source link

wpa2-enterprise does not work in recent versions. #1618

Closed vitcon-iot closed 6 years ago

vitcon-iot commented 6 years ago

Hardware:

Board: ESP32 Dev Module Core Installation/update date: 10/jul/2018 IDE name: Arduino IDE Flash Frequency: 80Mhz Upload Speed: 921600

Description:

The wpa2 enterprise feature is not working after the last update. Calling esp_wifi_sta_wpa2_ent_enable() before calling WiFi.mode() occurs Guru Meditation Error.

Sketch:

#include "esp_wpa2.h"
#include "esp_log.h"
#include <WiFi.h>

const char* ssid = "EngineeringBay"; // your ssid
#define EAP_ID "user1"
#define EAP_USERNAME "user1"
#define EAP_PASSWORD "pass1"

void setup() {
  esp_log_level_set("*", ESP_LOG_VERBOSE);
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  // WPA2 enterprise magic starts here
  WiFi.disconnect(true);

  int err = 0;
  /*
    esp_wifi_sta_wpa2_ent_clear_ca_cert();
    esp_wifi_sta_wpa2_ent_clear_cert_key();
    esp_wifi_sta_wpa2_ent_set_disable_time_check(true);
  */
  err = esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ID, strlen(EAP_ID));
  err = esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_USERNAME, strlen(EAP_USERNAME));
  err = esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD));

  esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
  err = esp_wifi_sta_wpa2_ent_enable(&config);

  // WPA2 enterprise magic ends here

  WiFi.begin(ssid);
  WiFi.mode(WIFI_STA); //call after esp_wifi_sta_wpa2_ent_enable()
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  //Do nothing.
}

Debug Messages:

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400e6b15  PS      : 0x00060530  A0      : 0x800d1bfe  A1      : 0x3ffb1f40  
A2      : 0x3ffb1f74  A3      : 0x3ffc5778  A4      : 0x00000000  A5      : 0x4baa1dcb  
A6      : 0x00000001  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3ffb1f40  
A10     : 0x3ffb23cc  A11     : 0x3f40109f  A12     : 0x00000005  A13     : 0x3ffb23d0  
A14     : 0x00000031  A15     : 0x31737361  SAR     : 0x00000018  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000138  LBEG    : 0x4000c349  LEND    : 0x4000c36b  LCOUNT  : 0xffffffff  

Backtrace: 0x400e6b15:0x3ffb1f40 0x400d1bfb:0x3ffb1f70 0x4012a8d3:0x3ffb1fa0

Rebooting...

Exception Decoder:

0x400e6b15: esp_wifi_sta_wpa2_ent_enable at ?? line ?
0x400e6b15: esp_wifi_sta_wpa2_ent_enable at ?? line ?
0x400d1bfb: setup() at C:\Users\JJH\Documents\Arduino\esp32_wap2_enterprise/esp32_wap2_enterprise.ino line 33
0x4012a8d3: loopTask(void*) at C:\Users\JJH\Documents\Arduino\hardware\espressif\esp32\cores\esp32/main.cpp line 15

If WiFi.mode() is called first, Guru Meditation Error does not occur, but Stack smashing protect failure occurs during Wifi connection.

Sketch:

#include "esp_wpa2.h"
#include "esp_log.h"
#include <WiFi.h>

const char* ssid = "EngineeringBay"; // your ssid
#define EAP_ID "user1"
#define EAP_USERNAME "user1"
#define EAP_PASSWORD "pass1"

void setup() {
  esp_log_level_set("*", ESP_LOG_VERBOSE);
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  // WPA2 enterprise magic starts here
  WiFi.disconnect(true);
  WiFi.mode(WIFI_STA); //call before esp_wif_ista_wpa2_ent_enable()
  int err = 0;
  /*
    esp_wifi_sta_wpa2_ent_clear_ca_cert();
    esp_wifi_sta_wpa2_ent_clear_cert_key();
    esp_wifi_sta_wpa2_ent_set_disable_time_check(true);
  */
  err = esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ID, strlen(EAP_ID));
  err = esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_USERNAME, strlen(EAP_USERNAME));
  err = esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD));

  esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
  err = esp_wifi_sta_wpa2_ent_enable(&config);

  // WPA2 enterprise magic ends here

  WiFi.begin(ssid);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  //Do nothing.
}

Debug Messages:

I (28) wifi: wifi driver task: 3ffb7240, prio:23, stack:4096, core=0
I (67) wifi: wifi firmware version: 4fd6a2c
I (68) wifi: config NVS flash: enabled
I (71) wifi: config nano formating: disabled
I (85) wifi: Init dynamic tx buffer num: 32
I (85) wifi: Init data frame dynamic rx buffer num: 10
I (85) wifi: Init management frame dynamic rx buffer num: 10
I (89) wifi: Init static rx buffer size: 1600
I (93) wifi: Init static rx buffer num: 4
I (97) wifi: Init dynamic rx buffer num: 10
I (163) wifi: mode : sta (30:ae:a4:08:93:ac)
I (164) wpa: WPA2 ENTERPRISE VERSION: [v2.0] enable

I (343) wifi: n:11 2, o:1 0, ap:255 255, sta:11 2, prof:1
.I (1074) wifi: state: init -> auth (b0)
I (1078) wifi: state: auth -> assoc (0)
I (1091) wifi: state: assoc -> run (10)
I (1091) wpa: wpa2_task prio:2, stack:6656

Stack smashing protect failure!

abort() was called at PC 0x400e8e1c on core 1

Backtrace: 0x4008f670:0x3ffbb880 0x4008f873:0x3ffbb8a0 0x400e8e1c:0x3ffbb8c0 0x400dd9fd:0x3ffbb8e0 0x400ddaaa:0x3ffbb9a0 0x400dbb8b:0x3ffbb9e0 0x400da91f:0x3ffbba00 0x400dad76:0x3ffbba40 0x400d9b5d:0x3ffbba60 0x400d9580:0x3ffbbab0 0x400d95ed:0x3ffbbaf0 0x400d7feb:0x3ffbbb10 0x400d81ed:0x3ffbbb50 0x400d7341:0x3ffbbb70 0x400e679e:0x3ffbbbf0 0x400e6a2a:0x3ffbbc20

Rebooting...

Exception Decoder:


Decoding 17 results
0x400e8e1c: __stack_chk_fail at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/stack_check.c line 36
0x4008f670: invoke_abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 649
0x4008f873: abort at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/panic.c line 649
0x400e8e1c: __stack_chk_fail at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/stack_check.c line 36
0x400dd9fd: x509_parse_tbs_certificate at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/x509v3.c line 1438
0x400ddaaa: x509_certificate_parse at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/x509v3.c line 1547
0x400dbb8b: tls_parse_cert at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/tlsv1_common.c line 321
0x400da91f: tls_process_certificate at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/tlsv1_client_read.c line 336
0x400dad76: tlsv1_client_process_handshake at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/tlsv1_client_read.c line 958
0x400d9b5d: tlsv1_client_handshake at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/tlsv1_client.c line 801
0x400d9580: tls_connection_handshake2 at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/tls_internal.c line 568
0x400d95ed: tls_connection_handshake at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/tls/tls_internal.c line 568
0x400d7feb: eap_tls_process_input at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/eap_peer/eap_tls_common.c line 482
0x400d81ed: eap_peer_tls_process_helper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/eap_peer/eap_tls_common.c line 630
0x400d7341: eap_peap_process at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/wpa_supplicant/src/wpa2/eap_peer/eap_peap.c line 1097
0x400e679e: eap_sm_process_request at ?? line ?
0x400e6a2a: wpa2Task at ?? line ?

In previous versions of the core in a different PC, both sketch is connected to the AP. (Installed on June 8, 2018) Can I get help with this issue?

me-no-dev commented 6 years ago

WiFi.mode() is now required in order to init the hardware (before it was initing even if WiFi is off and you call disconnect). So that part of the code is fine ;) you need to turn on the radio to use it. As for WPA2-Ent I advise you to file an issue in IDF's repository (that is where devs that deal with the stack are looking)