summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2021-02-20 09:06:44 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2021-02-20 09:06:44 -0800
commit42d44ec2684eda8504e9a7b2ee2bc16892b6fc4d (patch)
treed015d8f3bf7f01309183f25d22754ab319765655
parent8383e7cd1dc3aef1613b16c7abb17d850030015d (diff)
downloadpsutil-wifi.tar.gz
convert Wlan* API error codes to stringwifi
-rw-r--r--psutil/arch/windows/wifi.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/psutil/arch/windows/wifi.c b/psutil/arch/windows/wifi.c
index 2d1165fe..827d52b4 100644
--- a/psutil/arch/windows/wifi.c
+++ b/psutil/arch/windows/wifi.c
@@ -97,7 +97,7 @@ convert_macaddr(unsigned char *ptr) {
}
-long
+static long
quality_perc_to_rssi(WLAN_SIGNAL_QUALITY value) {
// RSSI (signal quality) expressed in dBm
if (value == 0)
@@ -109,6 +109,19 @@ quality_perc_to_rssi(WLAN_SIGNAL_QUALITY value) {
}
+static char *
+wlan_error(DWORD dwResult) {
+ if (dwResult == ERROR_INVALID_PARAMETER)
+ return "ERROR_INVALID_PARAMETER";
+ else if (dwResult == ERROR_NOT_ENOUGH_MEMORY)
+ return "ERROR_NOT_ENOUGH_MEMORY";
+ else if (dwResult == ERROR_REMOTE_SESSION_LIMIT_EXCEEDED)
+ return "ERROR_REMOTE_SESSION_LIMIT_EXCEEDED";
+ else
+ return "UNKNOWN";
+}
+
+
// ---
@@ -148,13 +161,15 @@ psutil_wifi_ifaces(PyObject *self, PyObject *args) {
dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
- PyErr_SetFromOSErrnoWithSyscall("WlanOpenHandle");
- return NULL;
+ PyErr_Format(PyExc_RuntimeError, "WlanOpenHandle -> %s",
+ wlan_error(dwResult));
+ goto error;
}
dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS) {
- PyErr_SetFromOSErrnoWithSyscall("WlanEnumInterfaces");
+ PyErr_Format(PyExc_RuntimeError, "WlanEnumInterfaces -> %s",
+ wlan_error(dwResult));
goto error;
}
@@ -205,7 +220,8 @@ psutil_wifi_ifaces(PyObject *self, PyObject *args) {
&opCode);
if (dwResult != ERROR_SUCCESS) {
- PyErr_SetFromOSErrnoWithSyscall("WlanEnumInterfaces");
+ PyErr_Format(PyExc_RuntimeError, "WlanQueryInterface -> %s",
+ wlan_error(dwResult));
goto error;
}