I have restructured my button files and added support for a smart reset button in WNDR3700.
This is related to my OpenWrt build (discussed here: https://forum.openwrt.org/viewtopic.php?id=28392 ), built mostly for checking the IPv6 related stuff, but I wanted to highlight the more general button related stuff here.
Full config & source file diffs included, including Luci changes: http://koti.welho.com/hnyman1/Openwrt/
I hated the approach that you have to press the reset button for at least X seconds. The reset button is so well hidden in a hole in the bottom of the router, that I have no wish to try to press it for 10 seconds etc. So I figured out something else:
WNDR3700 has many buttons and many LEDs. I designed a smart reset button script, that requires you to first press 'reset' in the bottom of the router, and then during the next 20 seconds to press the WPS button. The time period is indicated by a flashing WPS LED.
The reset script works by first monitoring the reset button itself. If the button is pressed, then the script launches the WPS LED blinking process that has two functions:
- it runs for 20 seconds blinking the WPS LED every second
- it acts as a "reset enabled" flag for the reset script that also monitors WPS button. The existence of the flag process is evaluated when the WPS button pressed event is noticed.
If the script then notices that the WPS button is pressed during the period when that flag process is running (and LED is blinking), it restores the device to default firmware settings by deleting the jffs partition containing the modified config files, by running 'firstboot' and then 'reboot'. I am not 100% sure, if 'firstboot' is the 100% correct process for this, but it seems to work. I tested, it works. User returns to the situation after flashing firmware without saving config files.
This is not useful if the system is completely screwed and has crashed, but it might help if you forget password or otherwise lock yourself out of the router e.g. with disabling network interfaces.
The reset script is '/etc/hotplug.d/button/05-reset' and the blinking/flag script is '/sbin/blink_wps_20'. I made the script compatible with both Backfire and Trunk by using both button names for the buttons.
Note: The same approach could be used also for other routers with several buttons & LEDs.
The new '01-log-button-action' hotplug just records all button actions to system log, that can be seen both from Luci and from the console with the 'logread' command.
Additionally, I modified other button scripts too. Currently there are 4 button scripts and the flag helper script:
/etc/hotplug.d/button/01-log-button-actions : log all button activities, good for finding out what happens
/etc/hotplug.d/button/05-reset : Functionality for Reset button
/sbin/blink_wps_20 : Helper script for Reset (blink & flag), needs to be executable, chmod +x
/etc/hotplug.d/button/10-radio-toggle : WiFi button functionality
/etc/hotplug.d/button/50-wps : WPS button's normal functionality.
More info about WiFi and WPS buttons logic in WNDR3700: https://forum.openwrt.org/viewtopic.php … 10#p127010
(I have added the other files to the build using /files sub-directory in buildroot, but 50-wps alrady exists in feeds/packages 'hostapd', so I have modified source there.)
/etc/hotplug.d/button/01-log-button-actions
#!/bin/sh
logger "Button '$BUTTON' was '$ACTION'"
/etc/hotplug.d/button/05-reset
#!/bin/sh
# RESET button is 'reset' in trunk, 'BTN_0' in Backfire
# WPS button is 'wps' in trunk, 'BTN_1' in Backfire
if [ "$ACTION" = "pressed" ] && [ "$BUTTON" = "reset" -o "$BUTTON" = "BTN_0" ]; then
logger "RESET button: status active for 20 seconds"
#launch reset flag process and blink WPS LED for 20 seconds
/sbin/blink_wps_20 &
fi
if [ "$ACTION" = "pressed" ] && [ "$BUTTON" = "wps" -o "$BUTTON" = "BTN_1" ]; then
ps | grep -v grep | grep blink_wps
if [ $? == 0 ] ; then
# blinking reset flag process still alive, reset is possible
logger "WPS button when reset flag is active: go for RESET"
# RESET action here
firstboot && reboot &
else
logger "WPS button when no reset flag, no reset action"
fi
fi
/sbin/blink_wps_20 (Note: needs to be executable, chmod +x )
#!/bin/sh
# remember to chmod this file runnable
a=0
while [ "$a" -lt 10 ]
do
echo "255" > /sys/devices/platform/leds-gpio/leds/wndr3700:green:wps/brightness
sleep 1
echo "0" > /sys/devices/platform/leds-gpio/leds/wndr3700:green:wps/brightness
sleep 1
let "a += 1"
done
/etc/hotplug.d/button/10-radio-toggle
#!/bin/sh
if [ "$BUTTON" = "BTN_2" ] && [ "$ACTION" = "pressed" ]; then
if [ -d /var/run/hostapd-phy0 -o -d /var/run/hostapd-phy1 ]; then
logger "WiFi button used: WiFi down"
/sbin/wifi down
else
logger "WiFi button used: WiFi up"
/sbin/wifi up
fi
fi
/etc/hotplug.d/button/50-wps (Note: button is 'wps' in trunk, 'BTN_1' in Backfire)
if [ "$ACTION" = "pressed" -a "$BUTTON" = "wps" ]; then
logger "WPS button pressed, looking for active radios"
echo "255" > /sys/devices/platform/leds-gpio/leds/wndr3700:green:wps/brightness
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
logger "WPS activated for: $dir"
hostapd_cli -p "$dir" wps_pbc
done
sleep 10
echo "0" > /sys/devices/platform/leds-gpio/leds/wndr3700:green:wps/brightness
fi
(Last edited by hnyman on 6 Feb 2011, 19:20)