Skip to content

Commit cff2a18

Browse files
authored
Add option to specify AP auth mode and cipher (#9454)
1 parent 78820f2 commit cff2a18

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ bool APClass::end(){
200200
return true;
201201
}
202202

203-
bool APClass::create(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder){
203+
bool APClass::create(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder, wifi_auth_mode_t auth_mode, wifi_cipher_type_t cipher){
204204
if(!ssid || *ssid == 0) {
205205
log_e("SSID missing!");
206206
return false;
@@ -226,8 +226,8 @@ bool APClass::create(const char* ssid, const char* passphrase, int channel, int
226226
_wifi_strncpy((char*)conf.ap.ssid, ssid, 32);
227227
conf.ap.ssid_len = strlen(ssid);
228228
if(passphrase != NULL && passphrase[0] != 0){
229-
conf.ap.authmode = WIFI_AUTH_WPA2_PSK;
230-
conf.ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP; // Disable by default enabled insecure TKIP and use just CCMP.
229+
conf.ap.authmode = auth_mode;
230+
conf.ap.pairwise_cipher = cipher;
231231
_wifi_strncpy((char*)conf.ap.password, passphrase, 64);
232232
}
233233
}
@@ -318,15 +318,15 @@ size_t APClass::printDriverInfo(Print & out) const{
318318

319319
if(info.ap.authmode == WIFI_AUTH_OPEN){ bytes += out.print(",OPEN"); }
320320
else if(info.ap.authmode == WIFI_AUTH_WEP){ bytes += out.print(",WEP"); }
321-
else if(info.ap.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WWPA_PSK"); }
322-
else if(info.ap.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WWPA2_PSK"); }
323-
else if(info.ap.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WWPA_WPA2_PSK"); }
321+
else if(info.ap.authmode == WIFI_AUTH_WPA_PSK){ bytes += out.print(",WPA_PSK"); }
322+
else if(info.ap.authmode == WIFI_AUTH_WPA2_PSK){ bytes += out.print(",WPA2_PSK"); }
323+
else if(info.ap.authmode == WIFI_AUTH_WPA_WPA2_PSK){ bytes += out.print(",WPA_WPA2_PSK"); }
324324
else if(info.ap.authmode == WIFI_AUTH_ENTERPRISE){ bytes += out.print(",WEAP"); }
325-
else if(info.ap.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WWPA3_PSK"); }
326-
else if(info.ap.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WWPA2_WPA3_PSK"); }
327-
else if(info.ap.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WWAPI_PSK"); }
328-
else if(info.ap.authmode == WIFI_AUTH_OWE){ bytes += out.print(",WOWE"); }
329-
else if(info.ap.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WWPA3_ENT_SUITE_B_192_BIT"); }
325+
else if(info.ap.authmode == WIFI_AUTH_WPA3_PSK){ bytes += out.print(",WPA3_PSK"); }
326+
else if(info.ap.authmode == WIFI_AUTH_WPA2_WPA3_PSK){ bytes += out.print(",WPA2_WPA3_PSK"); }
327+
else if(info.ap.authmode == WIFI_AUTH_WAPI_PSK){ bytes += out.print(",WAPI_PSK"); }
328+
else if(info.ap.authmode == WIFI_AUTH_OWE){ bytes += out.print(",OWE"); }
329+
else if(info.ap.authmode == WIFI_AUTH_WPA3_ENT_192){ bytes += out.print(",WPA3_ENT_SUITE_B_192_BIT"); }
330330

331331
if(esp_wifi_ap_get_sta_list(&clients) == ESP_OK) {
332332
bytes += out.print(",STA:");

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
* @param ssid_hidden Network cloaking (0 = broadcast SSID, 1 = hide SSID)
4848
* @param max_connection Max simultaneous connected clients, 1 - 4.
4949
*/
50-
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder)
50+
bool WiFiAPClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden, int max_connection, bool ftm_responder, wifi_auth_mode_t auth_mode, wifi_cipher_type_t cipher)
5151
{
52-
return AP.begin() && AP.create(ssid, passphrase, channel, ssid_hidden, max_connection, ftm_responder);
52+
return AP.begin() && AP.create(ssid, passphrase, channel, ssid_hidden, max_connection, ftm_responder, auth_mode, cipher);
5353
}
5454

5555
/**

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
#include "soc/soc_caps.h"
2626
#if SOC_WIFI_SUPPORTED
2727

28-
28+
#include "esp_wifi_types.h"
2929
#include "WiFiType.h"
3030
#include "WiFiGeneric.h"
3131

32-
32+
#define WIFI_AP_DEFAULT_AUTH_MODE WIFI_AUTH_WPA2_PSK
33+
#define WIFI_AP_DEFAULT_CIPHER WIFI_CIPHER_TYPE_CCMP // Disable by default enabled insecure TKIP and use just CCMP.
3334

3435
// ----------------------------------------------------------------------------------------------
3536
// ------------------------------------ NEW AP Implementation ----------------------------------
@@ -43,7 +44,7 @@ class APClass: public NetworkInterface {
4344
bool begin();
4445
bool end();
4546

46-
bool create(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
47+
bool create(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false, wifi_auth_mode_t auth_mode = WIFI_AP_DEFAULT_AUTH_MODE, wifi_cipher_type_t cipher = WIFI_AP_DEFAULT_CIPHER);
4748
bool clear();
4849

4950
bool bandwidth(wifi_bandwidth_t bandwidth);
@@ -71,9 +72,9 @@ class WiFiAPClass
7172
public:
7273
APClass AP;
7374

74-
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
75-
bool softAP(const String& ssid, const String& passphrase = emptyString, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false) {
76-
return softAP(ssid.c_str(), passphrase.c_str(), channel, ssid_hidden, max_connection, ftm_responder);
75+
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false, wifi_auth_mode_t auth_mode = WIFI_AP_DEFAULT_AUTH_MODE, wifi_cipher_type_t cipher = WIFI_AP_DEFAULT_CIPHER);
76+
bool softAP(const String& ssid, const String& passphrase = emptyString, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false, wifi_auth_mode_t auth_mode = WIFI_AP_DEFAULT_AUTH_MODE, wifi_cipher_type_t cipher = WIFI_AP_DEFAULT_CIPHER) {
77+
return softAP(ssid.c_str(), passphrase.c_str(), channel, ssid_hidden, max_connection, ftm_responder, auth_mode, cipher);
7778
}
7879

7980
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = (uint32_t) 0);

0 commit comments

Comments
 (0)