I want to toggle the WIFI on my OpenWrt when I press the reset button, per default OpenWrt just halts the system.
Most information is from the OpenWrt WIKI
** EDIT, 1.10.2008 **
this was an openwrt bug, check #2774 and #2772.
1) edit /etc/hotplug2-init.rules
delete this section:
SUBSYSTEM ~~ button {
exec kill –USR1 1 ;
}
2) create a new file /etc/config/wifitoggle
config wifitoggle
option button ‘reset’
Now uci knows wifitoggle:
root@OpenWrt:/# uci show
…
wifitoggle.cfg1=wifitoggle
wifitoggle.cfg1.TYPE=wifitoggle
wifitoggle.cfg1.button=reset
…
3) create the event file /etc/hotplug.d/button/10-wifitoggle
#!/bin/sh
. /lib/config/uci.sh
. /etc/functions.sh
config_load “wifitoggle“
local section=“cfg1“
config_get “BUTTON_NAME” “$section” “button”
#you may debug your events, write stuff to the eventlog
logger seen: “$SEEN”
toggle_radio() {
logger toggle radio
local section=”$1″
config_get “WIFI_RADIOSTATUS” “$section” “disabled”
logger stati: “$WIFI_RADIOSTATUS“
case “$WIFI_RADIOSTATUS” in
0|””)
uci_set “wireless” “$section” “disabled” “1”
wifi
;;
1)
uci_set “wireless” “$section” “disabled” “0”
wifi
;;
esac
}
if [ “$BUTTON” = “$BUTTON_NAME” ] && [ $SEEN == “0” ] ; then
if [ “$ACTION” = “pressed” ] ; then
logger loop
config_load “wireless“
config_foreach toggle_radio wifi-device
fi
fi
4) test it and press a button
Press the button after logread is running:
root@OpenWrt:/# logread –f
Jan 1 00:02:51 OpenWrt user.notice root: seen: 0
Jan 1 00:02:51 OpenWrt user.notice root: loop
Jan 1 00:02:51 OpenWrt user.notice root: toggle radio
Jan 1 00:02:51 OpenWrt user.notice root: stati: 1
Jan 1 00:02:52 OpenWrt user.notice root: seen: 0
Jan 1 00:02:52 OpenWrt user.notice root: loop
Jan 1 00:02:52 OpenWrt user.notice root: toggle radio
Jan 1 00:02:52 OpenWrt user.notice root: stati: 0
5) additional information
The events are generated platform depended.
Broadcom:
Source: /trunk/package/broadcom-diag/src/diag.c
…
static int fill_event (struct event_t *event)
{
static char buf[128];
add_msg(event, “HOME=/”, 0);
add_msg(event, “PATH=/sbin:/bin:/usr/sbin:/usr/bin”, 0);
add_msg(event, “SUBSYSTEM=button”, 0);
snprintf(buf, 128, “ACTION=%s”, event->action);
add_msg(event, buf, 0);
snprintf(buf, 128, “BUTTON=%s”, event->name);
add_msg(event, buf, 0);
snprintf(buf, 128, “SEEN=%ld”, event->seen);
add_msg(event, buf, 0);
#ifndef LINUX_2_4
snprintf(buf, 128, “SEQNUM=%llu”, uevent_next_seqnum());
add_msg(event, buf, 0);
#endif
return 0;
}
Atheros:
Source: /target/linux/atheros/files/arch/mips/atheros/reset.c
/* copy keys to our continuous event payload buffer */
add_msg(skb, “HOME=/”);
add_msg(skb, “PATH=/sbin:/bin:/usr/sbin:/usr/bin”);
add_msg(skb, “SUBSYSTEM=button”);
add_msg(skb, “BUTTON=reset”);
add_msg(skb, (event->set ? “ACTION=pressed” : “ACTION=released”));
sprintf(buf, “SEEN=%ld”, (event->jiffies — seen)/HZ);
add_msg(skb, buf);
snprintf(buf, 128, “SEQNUM=%llu”, uevent_next_seqnum());
add_msg(skb, buf);