Skip to content

Commit 83451e7

Browse files
committed
Unify approach for presenting security modes across esp32 and esp8266
1 parent cc7acab commit 83451e7

File tree

3 files changed

+43
-15
lines changed

3 files changed

+43
-15
lines changed
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
export const WIFI_SECURITY_WPA_TKIP = 2;
2-
export const WIFI_SECURITY_WEP = 5;
3-
export const WIFI_SECURITY_WPA_CCMP = 4;
4-
export const WIFI_SECURITY_NONE = 7;
5-
export const WIFI_SECURITY_AUTO = 8;
1+
export const WIFI_AUTH_OPEN = 0;
2+
export const WIFI_AUTH_WEP = 1;
3+
export const WIFI_AUTH_WEP_PSK = 2;
4+
export const WIFI_AUTH_WEP2_PSK = 3;
5+
export const WIFI_AUTH_WPA_WPA2_PSK = 4;
6+
export const WIFI_AUTH_WPA2_ENTERPRISE = 5;
67

7-
export const isNetworkOpen = selectedNetwork => selectedNetwork && selectedNetwork.encryption_type === WIFI_SECURITY_NONE;
8+
export const isNetworkOpen = selectedNetwork => selectedNetwork && selectedNetwork.encryption_type === WIFI_AUTH_OPEN;
89

910
export const networkSecurityMode = selectedNetwork => {
1011
switch (selectedNetwork.encryption_type){
11-
case WIFI_SECURITY_WPA_TKIP:
12-
case WIFI_SECURITY_WPA_CCMP:
13-
return "WPA";
14-
case WIFI_SECURITY_WEP:
12+
case WIFI_AUTH_WEP:
13+
case WIFI_AUTH_WEP_PSK:
1514
return "WEP";
16-
case WIFI_SECURITY_AUTO:
17-
return "Auto";
18-
case WIFI_SECURITY_NONE:
15+
case WIFI_AUTH_WEP2_PSK:
16+
return "WEP2";
17+
case WIFI_AUTH_WPA_WPA2_PSK:
18+
return "WPA/WEP2";
19+
case WIFI_AUTH_WPA2_ENTERPRISE:
20+
return "WEP2 Enterprise";
21+
case WIFI_AUTH_OPEN:
1922
return "None";
2023
default:
2124
return "Unknown";
2225
}
23-
}
26+
}

src/WiFiScanner.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
2626
network["bssid"] = WiFi.BSSIDstr(i);
2727
network["channel"] = WiFi.channel(i);
2828
#if defined(ESP8266)
29-
network["encryption_type"] = WiFi.encryptionType(i);
29+
network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i));
3030
#elif defined(ESP_PLATFORM)
3131
network["encryption_type"] = (uint8_t) WiFi.encryptionType(i);
3232
#endif
@@ -39,3 +39,24 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
3939
scanNetworks(request);
4040
}
4141
}
42+
43+
/*
44+
* Convert encryption type to standard used by ESP32 rather than the translated form which the esp8266 libaries expose.
45+
*
46+
* This allows us to use a single set of mappings in the UI.
47+
*/
48+
uint8_t convertEncryptionType(uint8_t encryptionType){
49+
switch (encryptionType){
50+
case ENC_TYPE_NONE:
51+
return AUTH_OPEN;
52+
case ENC_TYPE_WEP:
53+
return AUTH_WEP;
54+
case ENC_TYPE_TKIP:
55+
return AUTH_WPA_PSK;
56+
case ENC_TYPE_CCMP:
57+
return AUTH_WPA2_PSK;
58+
case ENC_TYPE_AUTO:
59+
return AUTH_WPA_WPA2_PSK;
60+
}
61+
return -1;
62+
}

src/WiFiScanner.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class WiFiScanner {
3030
void scanNetworks(AsyncWebServerRequest *request);
3131
void listNetworks(AsyncWebServerRequest *request);
3232

33+
#if defined(ESP8266)
34+
uint8_t convertEncryptionType(uint8_t encryptionType);
35+
#endif
36+
3337
};
3438

3539
#endif // end WiFiScanner_h

0 commit comments

Comments
 (0)