WPA2 Enterprise

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
capitek
Posts: 3
Joined: Thu May 20, 2021 7:46 am

WPA2 Enterprise

Post by capitek » Thu May 20, 2021 7:49 am

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?

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: WPA2 Enterprise

Post by davef » Thu May 20, 2021 9:17 am

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

PM-TPI
Posts: 75
Joined: Fri Jun 28, 2019 3:09 pm

Re: WPA2 Enterprise

Post by PM-TPI » Thu May 20, 2021 9:46 am

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.
Attachments
2021-05-20 07_06_06-RFC_ cc3200_ Support WPA-Enterprise networks (802.1x auth) by noahwilliamsson · .png
2021-05-20 07_06_06-RFC_ cc3200_ Support WPA-Enterprise networks (802.1x auth) by noahwilliamsson · .png (67.47 KiB) Viewed 12709 times

capitek
Posts: 3
Joined: Thu May 20, 2021 7:46 am

Re: WPA2 Enterprise

Post by capitek » Fri May 21, 2021 2:41 am

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.

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: WPA2 Enterprise

Post by chibill » Fri May 21, 2021 11:36 am

Yep, probably during the move to CMake it was removed. (I asked around in the IRC last night and got the answer.)

PM-TPI
Posts: 75
Joined: Fri Jun 28, 2019 3:09 pm

Re: WPA2 Enterprise

Post by PM-TPI » Fri May 21, 2021 2:11 pm

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??

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: WPA2 Enterprise

Post by chibill » Fri May 21, 2021 7:14 pm

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.

capitek
Posts: 3
Joined: Thu May 20, 2021 7:46 am

Re: WPA2 Enterprise

Post by capitek » Sat May 22, 2021 12:59 pm

Thanks again to everyone's help! Hopefully Micropython gets updated with WPA2 enterprise support in the next release.

ptal
Posts: 1
Joined: Thu Jul 22, 2021 5:52 am

Re: WPA2 Enterprise

Post by ptal » Thu Jul 22, 2021 5:55 am

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

chibill
Posts: 47
Joined: Thu Oct 31, 2019 10:44 pm

Re: WPA2 Enterprise

Post by chibill » Tue Jul 27, 2021 7:17 pm

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.

Post Reply