@@ -42,6 +42,7 @@ extern "C" {
42
42
#include " lwip/dns.h"
43
43
#include < esp_smartconfig.h>
44
44
#include < esp_netif.h>
45
+ #include " esp_wpa2.h"
45
46
}
46
47
47
48
// -----------------------------------------------------------------------------------------------------------------------
@@ -145,6 +146,67 @@ wl_status_t WiFiSTAClass::status()
145
146
return (wl_status_t )xEventGroupClearBits (_sta_status_group, 0 );
146
147
}
147
148
149
+ /* *
150
+ * Start Wifi connection with a WPA2 Enterprise AP
151
+ * if passphrase is set the most secure supported mode will be automatically selected
152
+ * @param ssid const char* Pointer to the SSID string.
153
+ * @param method wpa2_method_t The authentication method of WPA2 (WPA2_AUTH_TLS, WPA2_AUTH_PEAP, WPA2_AUTH_TTLS)
154
+ * @param wpa2_identity const char* Pointer to the entity
155
+ * @param wpa2_username const char* Pointer to the username
156
+ * @param password const char * Pointer to the password.
157
+ * @param ca_pem const char* Pointer to a string with the contents of a .pem file with CA cert
158
+ * @param client_crt const char* Pointer to a string with the contents of a .crt file with client cert
159
+ * @param client_key const char* Pointer to a string with the contants of a .key file with client key
160
+ * @param bssid uint8_t[6] Optional. BSSID / MAC of AP
161
+ * @param channel Optional. Channel of AP
162
+ * @param connect Optional. call connect
163
+ * @return
164
+ */
165
+ wl_status_t WiFiSTAClass::begin (const char * wpa2_ssid, wpa2_auth_method_t method, const char * wpa2_identity, const char * wpa2_username, const char *wpa2_password, const char * ca_pem, const char * client_crt, const char * client_key, int32_t channel, const uint8_t * bssid, bool connect)
166
+ {
167
+ if (!WiFi.enableSTA (true )) {
168
+ log_e (" STA enable failed!" );
169
+ return WL_CONNECT_FAILED;
170
+ }
171
+
172
+ if (!wpa2_ssid || *wpa2_ssid == 0x00 || strlen (wpa2_ssid) > 32 ) {
173
+ log_e (" SSID too long or missing!" );
174
+ return WL_CONNECT_FAILED;
175
+ }
176
+
177
+ if (wpa2_identity && strlen (wpa2_identity) > 64 ) {
178
+ log_e (" identity too long!" );
179
+ return WL_CONNECT_FAILED;
180
+ }
181
+
182
+ if (wpa2_username && strlen (wpa2_username) > 64 ) {
183
+ log_e (" username too long!" );
184
+ return WL_CONNECT_FAILED;
185
+ }
186
+
187
+ if (wpa2_password && strlen (wpa2_password) > 64 ) {
188
+ log_e (" password too long!" );
189
+ }
190
+
191
+ if (ca_pem) {
192
+ esp_wifi_sta_wpa2_ent_set_ca_cert ((uint8_t *)ca_pem, strlen (ca_pem));
193
+ }
194
+
195
+ if (client_crt) {
196
+ esp_wifi_sta_wpa2_ent_set_cert_key ((uint8_t *)client_crt, strlen (client_crt), (uint8_t *)client_key, strlen (client_key), NULL , 0 );
197
+ }
198
+
199
+ esp_wifi_sta_wpa2_ent_set_identity ((uint8_t *)wpa2_identity, strlen (wpa2_identity));
200
+ if (method == WPA2_AUTH_PEAP || method == WPA2_AUTH_TTLS) {
201
+ esp_wifi_sta_wpa2_ent_set_username ((uint8_t *)wpa2_username, strlen (wpa2_username));
202
+ esp_wifi_sta_wpa2_ent_set_password ((uint8_t *)wpa2_password, strlen (wpa2_password));
203
+ }
204
+ esp_wifi_sta_wpa2_ent_enable (); // set config settings to enable function
205
+ WiFi.begin (wpa2_ssid); // connect to wifi
206
+
207
+ return status ();
208
+ }
209
+
148
210
/* *
149
211
* Start Wifi connection
150
212
* if passphrase is set the most secure supported mode will be automatically selected
0 commit comments