Skip to content

Commit 356e738

Browse files
authored
Add support for specifying a WPA2 EAP-TTLS phase 2 method to WiFi.begin (#9639)
1 parent f6cbea1 commit 356e738

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Diff for: libraries/WiFi/src/STA.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ bool STAClass::connect(const char *ssid, const char *passphrase, int32_t channel
433433
*/
434434
bool STAClass::connect(
435435
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,
436-
const char *client_crt, const char *client_key, int32_t channel, const uint8_t *bssid, bool tryConnect
436+
const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool tryConnect
437437
) {
438438
if (_esp_netif == NULL) {
439439
log_e("STA not started! You must call begin() first.");
@@ -467,6 +467,14 @@ bool STAClass::connect(
467467
return false;
468468
}
469469

470+
if (ttls_phase2_type >= 0) {
471+
#if __has_include("esp_eap_client.h")
472+
esp_eap_client_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type);
473+
#else
474+
esp_wifi_sta_wpa2_ent_set_ttls_phase2_method((esp_eap_ttls_phase2_types)ttls_phase2_type);
475+
#endif
476+
}
477+
470478
if (ca_pem) {
471479
#if __has_include("esp_eap_client.h")
472480
esp_eap_client_set_ca_cert((uint8_t *)ca_pem, strlen(ca_pem));
@@ -503,7 +511,7 @@ bool STAClass::connect(
503511
esp_wifi_sta_wpa2_ent_enable(); //set config settings to enable function
504512
#endif
505513

506-
return connect(wpa2_ssid, NULL, 0, NULL, tryConnect); //connect to wifi
514+
return connect(wpa2_ssid, NULL, channel, bssid, tryConnect); //connect to wifi
507515
}
508516

509517
bool STAClass::disconnect(bool eraseap, unsigned long timeout) {

Diff for: libraries/WiFi/src/WiFiSTA.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ wl_status_t WiFiSTAClass::status() {
6565

6666
wl_status_t WiFiSTAClass::begin(
6767
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,
68-
const char *client_crt, const char *client_key, int32_t channel, const uint8_t *bssid, bool connect
68+
const char *client_crt, const char *client_key, int ttls_phase2_type, int32_t channel, const uint8_t *bssid, bool connect
6969
) {
7070
if (!STA.begin()) {
7171
return WL_CONNECT_FAILED;
7272
}
7373

74-
if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, channel, bssid, connect)) {
74+
if (!STA.connect(wpa2_ssid, method, wpa2_identity, wpa2_username, wpa2_password, ca_pem, client_crt, client_key, ttls_phase2_type, channel, bssid, connect)) {
7575
return WL_CONNECT_FAILED;
7676
}
7777

Diff for: libraries/WiFi/src/WiFiSTA.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class STAClass : public NetworkInterface {
5555
bool connect(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true);
5656
bool connect(
5757
const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL,
58-
const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true
58+
const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0,
59+
const uint8_t *bssid = 0, bool connect = true
5960
);
6061
bool disconnect(bool eraseap = false, unsigned long timeout = 0);
6162
bool reconnect();
@@ -109,16 +110,17 @@ class WiFiSTAClass {
109110

110111
wl_status_t begin(
111112
const char *wpa2_ssid, wpa2_auth_method_t method, const char *wpa2_identity = NULL, const char *wpa2_username = NULL, const char *wpa2_password = NULL,
112-
const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true
113+
const char *ca_pem = NULL, const char *client_crt = NULL, const char *client_key = NULL, int ttls_phase2_type = -1, int32_t channel = 0,
114+
const uint8_t *bssid = 0, bool connect = true
113115
);
114116
wl_status_t begin(
115117
const String &wpa2_ssid, wpa2_auth_method_t method, const String &wpa2_identity = (const char *)NULL, const String &wpa2_username = (const char *)NULL,
116118
const String &wpa2_password = (const char *)NULL, const String &ca_pem = (const char *)NULL, const String &client_crt = (const char *)NULL,
117-
const String &client_key = (const char *)NULL, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true
119+
const String &client_key = (const char *)NULL, int ttls_phase2_type = -1, int32_t channel = 0, const uint8_t *bssid = 0, bool connect = true
118120
) {
119121
return begin(
120122
wpa2_ssid.c_str(), method, wpa2_identity.c_str(), wpa2_username.c_str(), wpa2_password.c_str(), ca_pem.c_str(), client_crt.c_str(), client_key.c_str(),
121-
channel, bssid, connect
123+
ttls_phase2_type, channel, bssid, connect
122124
);
123125
}
124126
wl_status_t begin(const char *ssid, const char *passphrase = NULL, int32_t channel = 0, const uint8_t *bssid = NULL, bool connect = true);

0 commit comments

Comments
 (0)