@@ -145,6 +145,78 @@ wl_status_t WiFiSTAClass::status()
145
145
return (wl_status_t )xEventGroupClearBits (_sta_status_group, 0 );
146
146
}
147
147
148
+
149
+ #ifdef ENABLE_WPA2_AUTHENTICATION
150
+ static WiFiClientSecure client_secure;
151
+
152
+ /* *
153
+ * Start Wifi connection with a WPA2 Enterprise AP
154
+ * if passphrase is set the most secure supported mode will be automatically selected
155
+ * @param ssid const char* Pointer to the SSID string.
156
+ * @param wpa2_identity const char* Pointer to the entity
157
+ * @param wpa2_username const char* Pointer to the username
158
+ * @param password const char * Pinter to the password.
159
+ * @param root_ca const char* Optional. Pointer to the root certificate string.
160
+ * @param client_cert const char* Optional. Pointer to the client certificate string.
161
+ * @param client_key const char* Optional. Pointer to the client key.
162
+ * @param bssid uint8_t[6] Optional. BSSID / MAC of AP
163
+ * @param channel Optional. Channel of AP
164
+ * @param connect Optional. call connect
165
+ * @return
166
+ */
167
+ 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)
168
+ {
169
+ if (!WiFi.enableSTA (true )) {
170
+ log_e (" STA enable failed!" );
171
+ return WL_CONNECT_FAILED;
172
+ }
173
+
174
+ if (!wpa2_ssid || *wpa2_ssid == 0x00 || strlen (wpa2_ssid) > 32 ) {
175
+ log_e (" SSID too long or missing!" );
176
+ return WL_CONNECT_FAILED;
177
+ }
178
+
179
+ if (wpa2_identity && strlen (wpa2_identity) > 64 ) {
180
+ log_e (" identity too long!" );
181
+ return WL_CONNECT_FAILED;
182
+ }
183
+
184
+ if (wpa2_username && strlen (wpa2_username) > 64 ) {
185
+ log_e (" username too long!" );
186
+ return WL_CONNECT_FAILED;
187
+ }
188
+
189
+ if (wpa2_password && strlen (wpa2_password) > 64 ) {
190
+ log_e (" password too long!" );
191
+ }
192
+
193
+ esp_wifi_sta_wpa2_ent_set_identity ((uint8_t *)wpa2_identity, strlen (wpa2_identity));
194
+ esp_wifi_sta_wpa2_ent_set_username ((uint8_t *)wpa2_username, strlen (wpa2_username));
195
+ esp_wifi_sta_wpa2_ent_set_password ((uint8_t *)wpa2_password, strlen (wpa2_password));
196
+ esp_wifi_sta_wpa2_ent_enable (); // set config settings to enable function
197
+ WiFi.begin (wpa2_ssid); // connect to wifi
198
+
199
+ int cert_count = (root_ca != NULL ) + (client_cert != NULL ) + (client_key != NULL );
200
+ if ( cert_count > 1 ) {
201
+ log_e (" only one cert method allowed!" );
202
+ return WL_CONNECT_FAILED;
203
+ }
204
+
205
+ if (root_ca != NULL ) {
206
+ client_secure.setCACert (root_ca);
207
+ }
208
+ else if (client_cert != NULL ) {
209
+ client_secure.setCertificate (client_cert);
210
+ }
211
+ else if (client_key != NULL ) {
212
+ client_secure.setPrivateKey (client_key);
213
+ }
214
+ return status ();
215
+ }
216
+ #endif
217
+
218
+
219
+
148
220
/* *
149
221
* Start Wifi connection
150
222
* if passphrase is set the most secure supported mode will be automatically selected
0 commit comments