Unify approach for presenting security modes across esp32 and esp8266
This commit is contained in:
parent
cc7acab37c
commit
83451e7d47
@ -1,23 +1,26 @@
|
||||
export const WIFI_SECURITY_WPA_TKIP = 2;
|
||||
export const WIFI_SECURITY_WEP = 5;
|
||||
export const WIFI_SECURITY_WPA_CCMP = 4;
|
||||
export const WIFI_SECURITY_NONE = 7;
|
||||
export const WIFI_SECURITY_AUTO = 8;
|
||||
export const WIFI_AUTH_OPEN = 0;
|
||||
export const WIFI_AUTH_WEP = 1;
|
||||
export const WIFI_AUTH_WEP_PSK = 2;
|
||||
export const WIFI_AUTH_WEP2_PSK = 3;
|
||||
export const WIFI_AUTH_WPA_WPA2_PSK = 4;
|
||||
export const WIFI_AUTH_WPA2_ENTERPRISE = 5;
|
||||
|
||||
export const isNetworkOpen = selectedNetwork => selectedNetwork && selectedNetwork.encryption_type === WIFI_SECURITY_NONE;
|
||||
export const isNetworkOpen = selectedNetwork => selectedNetwork && selectedNetwork.encryption_type === WIFI_AUTH_OPEN;
|
||||
|
||||
export const networkSecurityMode = selectedNetwork => {
|
||||
switch (selectedNetwork.encryption_type){
|
||||
case WIFI_SECURITY_WPA_TKIP:
|
||||
case WIFI_SECURITY_WPA_CCMP:
|
||||
return "WPA";
|
||||
case WIFI_SECURITY_WEP:
|
||||
case WIFI_AUTH_WEP:
|
||||
case WIFI_AUTH_WEP_PSK:
|
||||
return "WEP";
|
||||
case WIFI_SECURITY_AUTO:
|
||||
return "Auto";
|
||||
case WIFI_SECURITY_NONE:
|
||||
case WIFI_AUTH_WEP2_PSK:
|
||||
return "WEP2";
|
||||
case WIFI_AUTH_WPA_WPA2_PSK:
|
||||
return "WPA/WEP2";
|
||||
case WIFI_AUTH_WPA2_ENTERPRISE:
|
||||
return "WEP2 Enterprise";
|
||||
case WIFI_AUTH_OPEN:
|
||||
return "None";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
}
|
@ -26,7 +26,7 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
|
||||
network["bssid"] = WiFi.BSSIDstr(i);
|
||||
network["channel"] = WiFi.channel(i);
|
||||
#if defined(ESP8266)
|
||||
network["encryption_type"] = WiFi.encryptionType(i);
|
||||
network["encryption_type"] = convertEncryptionType(WiFi.encryptionType(i));
|
||||
#elif defined(ESP_PLATFORM)
|
||||
network["encryption_type"] = (uint8_t) WiFi.encryptionType(i);
|
||||
#endif
|
||||
@ -39,3 +39,24 @@ void WiFiScanner::listNetworks(AsyncWebServerRequest *request) {
|
||||
scanNetworks(request);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert encryption type to standard used by ESP32 rather than the translated form which the esp8266 libaries expose.
|
||||
*
|
||||
* This allows us to use a single set of mappings in the UI.
|
||||
*/
|
||||
uint8_t convertEncryptionType(uint8_t encryptionType){
|
||||
switch (encryptionType){
|
||||
case ENC_TYPE_NONE:
|
||||
return AUTH_OPEN;
|
||||
case ENC_TYPE_WEP:
|
||||
return AUTH_WEP;
|
||||
case ENC_TYPE_TKIP:
|
||||
return AUTH_WPA_PSK;
|
||||
case ENC_TYPE_CCMP:
|
||||
return AUTH_WPA2_PSK;
|
||||
case ENC_TYPE_AUTO:
|
||||
return AUTH_WPA_WPA2_PSK;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -30,6 +30,10 @@ class WiFiScanner {
|
||||
void scanNetworks(AsyncWebServerRequest *request);
|
||||
void listNetworks(AsyncWebServerRequest *request);
|
||||
|
||||
#if defined(ESP8266)
|
||||
uint8_t convertEncryptionType(uint8_t encryptionType);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif // end WiFiScanner_h
|
||||
|
Loading…
Reference in New Issue
Block a user