summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Cohen <bencoh@notk.org>2021-07-06 23:20:14 +0300
committerBenjamin Cohen <bencoh@notk.org>2021-07-06 23:20:14 +0300
commitbac38a3410c5cb6d8f11382880e00e4eadcbe25c (patch)
tree9837da0509f0262d17176693bc177a7763d5d08f
parent121e8e4c9eb06629991db936aab11f8659faa259 (diff)
Down wlan0 instead of unloading wifi module
Wireless drivers should handle down state properly and powerdown hardware accordingly, without unloading module. Use ifconfig to turn interface down, and report interface status in applet.
-rwxr-xr-xsrc/wifi-switcher-statusbar.c32
-rwxr-xr-xsrc/wifi.sh23
2 files changed, 30 insertions, 25 deletions
diff --git a/src/wifi-switcher-statusbar.c b/src/wifi-switcher-statusbar.c
index f57187e..6930ab2 100755
--- a/src/wifi-switcher-statusbar.c
+++ b/src/wifi-switcher-statusbar.c
@@ -1,8 +1,9 @@
/*
*
* Wifi switcher for N900 Copyright (C) 2010 by Tito Ragusa <farmatito@tiscali.it>
+* Modified for Maemo Leste Copyright (C) 2021 Benjamin Cohen <bencoh@notk.org>
*
-* Wifi switicher is a tool to tenable/disable wifi on the Nokia N900
+* Wifi switcher / status applet for Maemo Leste
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -20,14 +21,14 @@
*
* Please read the COPYING and README file!!!
*
-* Report bugs to <farmatito@tiscali.it>
-*
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/types.h>
+#include <fcntl.h>
#include <sys/wait.h>
#include <gtk/gtk.h>
#include <hildon/hildon.h>
@@ -55,6 +56,7 @@ static void wifi_switcher_class_init (WifiSwitcherClass *klass)
g_type_class_add_private (klass, sizeof (WifiSwitcherPrivate));
}
+#if 0 /* properly written driver should not need to be unloaded */
/** Check if wifi module is loaded
@return One if wifi module is loaded, zero otherwise
*/
@@ -77,13 +79,33 @@ static int check_wifi_module_loaded()
}
return module_loaded;
}
+#else
+/** Check if wlan interface is up
+ @return One if wlan interface is up, zero otherwise
+*/
+static int check_wifi_up()
+{
+ int wifi_up = 0;
+ char str[16];
+ int fd = open("/sys/class/net/wlan0/flags", O_RDONLY);
+ if (fd) {
+ if (read(fd, &str, sizeof(str))) {
+ /* check UP bit (0x0001) */
+ wifi_up = !!(strtoul(str, NULL, 16) & 0x1);
+ }
+ close(fd);
+ }
+
+ return wifi_up;
+}
+#endif
-/** Set Wifi button text according to wifi module state
+/** Set Wifi button text according to wlan interface state
@param priv Pointer to WifiSwitcherPrivate structure
*/
static void set_wifi_button_text(WifiSwitcherPrivate *priv)
{
- const char *subtext = check_wifi_module_loaded() ? "On" : "Off";
+ const char *subtext = check_wifi_up() ? "On" : "Off";
hildon_button_set_text (HILDON_BUTTON (priv->button),
"Wireless LAN",
subtext);
diff --git a/src/wifi.sh b/src/wifi.sh
index 0460f72..0defe95 100755
--- a/src/wifi.sh
+++ b/src/wifi.sh
@@ -1,8 +1,9 @@
#!/bin/sh
#
# Wifi switcher for N900 Copyright (C) 2010 by Tito Ragusa <farmatito@tiscali.it>
+# Modified for Maemo Leste Copyright (C) 2021 Benjamin Cohen <bencoh@notk.org>
#
-# Wifi switicher is a tool to tenable/disable wifi on the Nokia N900
+# Wifi switcher / status applet for Maemo Leste
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
@@ -20,8 +21,6 @@
#
# Please read the COPYING and README file!!!
#
-# Report bugs to <farmatito@tiscali.it>
-#
print_msg()
{
@@ -39,7 +38,7 @@ if_failed_print_and_die()
fi;
}
-out=`ifconfig wlan0`
+out=`ifconfig wlan0 | grep UP`
if [ "x$?" = "x0" ] ; then
# wlan is up
action="DISABLE";
@@ -52,27 +51,11 @@ if [ "x$?" = "x0" ] ; then
# Setting ip to 0.0.0.0 is needed to reset ip-monitoring widgets.
# Put Down the interface to run hooks in /etc/network/if-*down.d, ignore errors if any.
ifconfig wlan0 0.0.0.0 down;
- # Remove the module
- step="RMMOD";
- rmmod wl12xx;
- if_failed_print_and_die;
- # No need to stop/start/restart wlancond here.
print_msg "WIRELESS LAN DISABLED" "OK";
exit 2
else
# wlan is not configured, reload modules
action="ENABLE";
- step="MODPROBE";
- modprobe wl12xx;
- if_failed_print_and_die;
- # Calibrate: do not remove this. It is needed even if 'start wlancond'
- # triggers one more calibration later
- step="CALIBRATION";
- wl1251-cal;
- if_failed_print_and_die;
- # Restart wlancond properly
- stop wlancond;
- start wlancond;
# Up the interface, to run hooks in /etc/network/if*/
step="'IFCONFIG WLAN0 UP'";
ifconfig wlan0 up;