Page 1 of 3

WPA2 Enterprise

Posted: Thu May 20, 2021 7:49 am
by capitek
Hi, I'm trying to connect to a WPA2 Enterprise network, but it seems like Micropython has yet to add support for this. I have seen people do custom builds of Micropython to overcome this issue, and I would like to try to as well. Could someone point me to how to do this?

Re: WPA2 Enterprise

Posted: Thu May 20, 2021 9:17 am
by davef
I checked on my ESP32 build using:

Code: Select all

>>> import network
>>> dir(network)
['__class__', '__init__', '__name__', 'AP_IF', 'AUTH_MAX', 'AUTH_OPEN', 'AUTH_WEP', 'AUTH_WPA2_ENTERPRISE', 'AUTH_WPA2_PSK', 'AUTH_WPA_PSK', 'AUTH_WPA_WPA2_PSK', 'MODE_11B', 'MODE_11G', 'MODE_11N', 'MODE_LR', 'PHY_IP101', 'PHY_LAN8720', 'PHY_TLK110', 'PPP', 'STAT_ASSOC_FAIL', 'STAT_BEACON_TIMEOUT', 'STAT_CONNECTING', 'STAT_GOT_IP', 'STAT_HANDSHAKE_TIMEOUT', 'STAT_IDLE', 'STAT_NO_AP_FOUND', 'STAT_WRONG_PASSWORD', 'STA_IF', 'WIFI_PS_MAX_MODEM', 'WIFI_PS_MIN_MODEM', 'WIFI_PS_NONE', 'WLAN', 'phy_mode']
>>>  
and it is there.

I was just given a hint about MODE_LR:

Code: Select all

(network.wlan(if).config(protocol=network.MODE_LR))
This doc may provide clues:
https://docs.espressif.com/projects/esp ... /wifi.html

Re: WPA2 Enterprise

Posted: Thu May 20, 2021 9:46 am
by PM-TPI
This method allows connecting with EAP-PEAP or EAP-TTLS:
client key and certificate are not necessary, only a username and password pair.

in file... ports\esp32\modnetwork.c

Code: Select all

#include "esp_wpa2.h" 

//then add...
//Set up EAP
STATIC mp_obj_t esp_seteap(mp_obj_t self_in,mp_obj_t username,mp_obj_t password){
    size_t Ilen;
    size_t Plen;
    const char *EAP_IDENTITY = mp_obj_str_get_data(username,&Ilen);
    const char *EAP_PASSWORD = mp_obj_str_get_data(password,&Plen);
    ESP_EXCEPTIONS(esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)));
    ESP_EXCEPTIONS(esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY)));
    //ESP_EXCEPTIONS(esp_wifi_sta_wpa2_ent_set_new_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)));
    ESP_EXCEPTIONS(esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD)));
    ESP_EXCEPTIONS(esp_wifi_sta_wpa2_ent_enable());
    return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_3(esp_seteap_obj, esp_seteap);

// then add to the wlan_if_locals_dict_table  ~line 754...
{ MP_ROM_QSTR(MP_QSTR_seteap), MP_ROM_PTR(&esp_seteap_obj) },

for main.py

Code: Select all

if not wlan.isconnected() :
	wlan.disconnect()
	wlan.config(dhcp_hostname = "hostname")

	#-------------------------------------------------------------------
	wlan.seteap("user name", "password")
	#-------------------------------------------------------------------

	wlan.connect("network") 

	utime.sleep(1)
	seconds=float(0)
	while not wlan.isconnected():
		seconds += 1
		utime.sleep(1)
		# need a time out if wifi can't connect
		if seconds > 15:
			print ("not able to connect")
			break

	if wlan.isconnected():
		print('wifi connection succeeded!')
		print('network config: ', wlan.ifconfig())
		print('gateway hostname:', wlan.config('dhcp_hostname'))
This worked for esp-idf 4.0.1 and mp v1.12-510-g1e6d18c91

NOW with esp-idf 4.2 and mp v1.14-121-g4fc2866f4
I get build error...
/micropython/ports/esp32/modnetwork.c:44:10: fatal error: esp_wpa2.h: No such file or directory

I posted in topic "No such file or directory" Tue May 18, 2021 10:22 am
No help as of now.

Re: WPA2 Enterprise

Posted: Fri May 21, 2021 2:41 am
by capitek
Ahh I see, thanks for the instructions. I was able to build just now with ESP-IDF 4.2 and MicroPython 1.15 with an edit to micropython/ports/esp32/main/CMakeLists.txt. It seems like somewhere along the line, the wpa_supplicant folder was removed from the MicroPython paths, so it had to be added in. Under set(IDF_COMPONENTS), I added wpa_supplicant underneath esp_wifi and it seems to have successfully built with the patch from viewtopic.php?f=18&t=7219 that you mentioned. I haven't tested whether WPA2 Enterprise works or not though. Hope this helped you as well.

Re: WPA2 Enterprise

Posted: Fri May 21, 2021 11:36 am
by chibill
Yep, probably during the move to CMake it was removed. (I asked around in the IRC last night and got the answer.)

Re: WPA2 Enterprise

Posted: Fri May 21, 2021 2:11 pm
by PM-TPI
Thank you very much for pointing me in the right direction !!!!!!!!!!!!!!

Added fix... built... and connected to Enterprise Network.
I am using a Raspberry Pi with radius server,
hope to test in a more commercial environment.

micropython really needs to add this connectivity
with all the appropriate protocols.

AGAIN THANK YOU !!

p.s. what IRC are you using chibill
do you get quick responses??

Re: WPA2 Enterprise

Posted: Fri May 21, 2021 7:14 pm
by chibill
Its #micropython on freenode. Although that might change at some point.

I am going to work on throwing together a PR now that I have had more experience with working on Micropython's internals in my free time.

Re: WPA2 Enterprise

Posted: Sat May 22, 2021 12:59 pm
by capitek
Thanks again to everyone's help! Hopefully Micropython gets updated with WPA2 enterprise support in the next release.

Re: WPA2 Enterprise

Posted: Thu Jul 22, 2021 5:55 am
by ptal
Has anyone got this working yet on a build of MicroPython for the ESP32? I need to get this solution going ASAP. I've never built micropython but is this something I need to do to get it going? I'm currently using 1.16 micropython.

Cheers

Re: WPA2 Enterprise

Posted: Tue Jul 27, 2021 7:17 pm
by chibill
I can provide a binary built with WPA2 support and also some information on how to use it. I am still working on figuring out how to properly make a PR for Micropython to get it into the main repo.