I want to tog­gle the WIFI on my Open­Wrt when I press the reset but­ton, per default Open­Wrt just halts the system.

Most infor­ma­tion is from the Open­Wrt WIKI

** EDIT, 1.10.2008 **
this was an open­wrt bug, check #2774 and #2772.

1) edit /etc/hotplug2-init.rules
delete this sec­tion:
SUBSYSTEM ~~ but­ton {
exec kill –USR1 1 ;
}

2) cre­ate a new file /etc/config/wifitoggle
con­fig wifi­tog­gle
option but­ton ‘reset’

Now uci knows wifi­tog­gle:
root@OpenWrt:/# uci show

wifitoggle.cfg1=wifitoggle
wifitoggle.cfg1.TYPE=wifitoggle
wifitoggle.cfg1.button=reset


3) cre­ate the event file /etc/hotplug.d/button/10-wifitoggle
#!/bin/sh

. /lib/config/uci.sh
. /etc/functions.sh

config_load “wifi­tog­gle“
local section=“cfg1“
config_get “BUTTON_NAME” “$sec­tion” “button”

#you may debug your events, write stuff to the event­log
log­ger seen: “$SEEN

toggle_radio() {
log­ger tog­gle radio
local section=”$1″
config_get “WIFI_RADIOSTATUS” “$sec­tion” “disabled”

log­ger stati: “$WIFI_RADIOSTATUS
case “$WIFI_RADIOSTATUS” in
0|””)
uci_set “wire­less” “$sec­tion” “dis­abled” “1”
wifi
;;
1)
uci_set “wire­less” “$sec­tion” “dis­abled” “0”
wifi
;;
esac
}

if [ “$BUTTON” = “$BUTTON_NAME” ] && [ $SEEN == “0” ] ; then
if [ “$ACTION” = “pressed” ] ; then
log­ger loop
config_load “wire­less“
config_foreach toggle_radio wifi-device
fi
fi

4) test it and press a but­ton
Press the but­ton after logread is running:

root@OpenWrt:/# logread –f
Jan  1 00:02:51 Open­Wrt user.notice root: seen: 0
Jan  1 00:02:51 Open­Wrt user.notice root: loop
Jan  1 00:02:51 Open­Wrt user.notice root: tog­gle radio
Jan  1 00:02:51 Open­Wrt user.notice root: stati: 1
Jan  1 00:02:52 Open­Wrt user.notice root: seen: 0
Jan  1 00:02:52 Open­Wrt user.notice root: loop
Jan  1 00:02:52 Open­Wrt user.notice root: tog­gle radio
Jan  1 00:02:52 Open­Wrt user.notice root: stati: 0

5) addi­tional infor­ma­tion
The events are gen­er­ated plat­form depended.

Broad­com:
Source: /trunk/package/broadcom-diag/src/diag.c

sta­tic int fill_event (struct event_t *event)
{
sta­tic 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);
#ifn­def LINUX_2_4
snprintf(buf, 128, “SEQNUM=%llu”, uevent_next_seqnum());
add_msg(event, buf, 0);
#endif

return 0;
}

Ath­eros:
Source: /target/linux/atheros/files/arch/mips/atheros/reset.c
/* copy keys to our con­tin­u­ous event pay­load 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);