Wi-Fi fix again

This commit is contained in:
Nicolas Mailloux 2023-06-10 10:03:12 -04:00
parent fe0e62d672
commit 72322a7fe5

View file

@ -1102,30 +1102,33 @@ namespace {
} }
} }
global::wifi::wifiState checkWifiState() { global::wifi::wifiState checkWifiState() {
QString interfaceStateFileHead = "/sys/class/net/";
QString interfaceStateFileTail = "/operstate";
QString interfaceName; QString interfaceName;
QString interfaceStateFile;
if(global::deviceID == "n437\n" or global::deviceID == "kt\n") { if(global::deviceID == "n437\n" or global::deviceID == "kt\n") {
interfaceName = "wlan0"; interfaceName = "wlan0";
} }
else { else {
interfaceName = "eth0"; interfaceName = "eth0";
} }
interfaceStateFile = interfaceStateFileHead + interfaceName + interfaceStateFileTail;
QString state = readFile(interfaceStateFile); // Check if network interface has an IP address
if(state == "up\n") { QNetworkInterface iface = QNetworkInterface::interfaceFromName(interfaceName);
QList<QNetworkAddressEntry> entries = iface.addressEntries();
if(!entries.isEmpty()) {
// Interface is up and has an IP address
global::wifi::isConnected = true; global::wifi::isConnected = true;
return global::wifi::wifiState::configured; return global::wifi::wifiState::configured;
} }
else if(state == "unknown\n") {
global::wifi::isConnected = false;
return global::wifi::wifiState::enabled;
}
else { else {
global::wifi::isConnected = false; if(QFile::exists("/sys/class/net/" + interfaceName + "/operstate")) {
return global::wifi::wifiState::disabled; // Interface is up but doesn't have an IP address
global::wifi::isConnected = false;
return global::wifi::wifiState::enabled;
}
else {
// Interface is not up
global::wifi::isConnected = false;
return global::wifi::wifiState::disabled;
}
} }
} }
int testPing() { int testPing() {