25
25
#include " WiFi.h"
26
26
#include " WiFiGeneric.h"
27
27
#include " WiFiSTA.h"
28
- #include < WiFiClientSecure.h>
29
28
30
29
extern " C" {
31
30
#include < stdint.h>
@@ -147,25 +146,23 @@ wl_status_t WiFiSTAClass::status()
147
146
return (wl_status_t )xEventGroupClearBits (_sta_status_group, 0 );
148
147
}
149
148
150
-
151
- static WiFiClientSecure client_secure;
152
-
153
149
/* *
154
150
* Start Wifi connection with a WPA2 Enterprise AP
155
151
* if passphrase is set the most secure supported mode will be automatically selected
156
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)
157
154
* @param wpa2_identity const char* Pointer to the entity
158
155
* @param wpa2_username const char* Pointer to the username
159
- * @param password const char * Pinter to the password.
160
- * @param root_ca const char* Optional. Pointer to the root certificate string.
161
- * @param client_cert const char* Optional. Pointer to the client certificate string.
162
- * @param client_key const char* Optional. Pointer to the client key.
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
163
160
* @param bssid uint8_t[6] Optional. BSSID / MAC of AP
164
161
* @param channel Optional. Channel of AP
165
162
* @param connect Optional. call connect
166
163
* @return
167
164
*/
168
- wl_status_t WiFiSTAClass::begin (const char * wpa2_ssid, const char * wpa2_identity, const char * wpa2_username, const char *wpa2_password, const char * root_ca , const char * client_cert , const char * client_key, int32_t channel, const uint8_t * bssid, bool connect)
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)
169
166
{
170
167
if (!WiFi.enableSTA (true )) {
171
168
log_e (" STA enable failed!" );
@@ -191,27 +188,22 @@ wl_status_t WiFiSTAClass::begin(const char* wpa2_ssid, const char* wpa2_identity
191
188
log_e (" password too long!" );
192
189
}
193
190
194
- esp_wifi_sta_wpa2_ent_set_identity ((uint8_t *)wpa2_identity, strlen (wpa2_identity));
195
- esp_wifi_sta_wpa2_ent_set_username ((uint8_t *)wpa2_username, strlen (wpa2_username));
196
- esp_wifi_sta_wpa2_ent_set_password ((uint8_t *)wpa2_password, strlen (wpa2_password));
197
- esp_wifi_sta_wpa2_ent_enable (); // set config settings to enable function
198
- WiFi.begin (wpa2_ssid); // connect to wifi
199
-
200
- int cert_count = (root_ca != NULL ) + (client_cert != NULL ) + (client_key != NULL );
201
- if ( cert_count > 1 ) {
202
- log_e (" only one cert method allowed!" );
203
- return WL_CONNECT_FAILED;
191
+ if (ca_pem) {
192
+ esp_wifi_sta_wpa2_ent_set_ca_cert ((uint8_t *)ca_pem, strlen (ca_pem));
204
193
}
205
194
206
- if (root_ca != NULL ) {
207
- client_secure. setCACert (root_ca );
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 );
208
197
}
209
- else if (client_cert != NULL ) {
210
- client_secure. setCertificate (client_cert );
211
- }
212
- else if (client_key != NULL ) {
213
- client_secure. setPrivateKey (client_key );
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) );
214
203
}
204
+ esp_wifi_sta_wpa2_ent_enable (); // set config settings to enable function
205
+ WiFi.begin (wpa2_ssid); // connect to wifi
206
+
215
207
return status ();
216
208
}
217
209
0 commit comments