I wanted to make the OpenWrt build for WNDR3700 more "feature-complete", so I searched for information enabling the two buttons on the WNDR3700. Here are short explanations, how to enable the WiFi button and the WPS button. I have done the work on Backfire 10.03.1-SVN branch, but there shouldn't be difference to Kamikaze/trunk.
Based on SVN revision: r25261 Backfire
Build examples and SVN diffs: http://koti.welho.com/hnyman1/Openwrt/
Build process and included features explained here: https://forum.openwrt.org/viewtopic.php?id=28392
Buttons have different names in Backfire and in Kamikaze/trunk:
Backfire: reset=BTN_0, wps=BTN_1, wifi=BTN_2
trunk: reset=reset, wps=wps, wifi=BTN_2
Note: I added a logger line to the scripts, so that each button event gets noted in Syslog.
WiFi button:
The button automatics is pretty much already in place. It only requires hotplugging the button event to the '/sbin/wifi' script.
- The button toggles WiFi off, it at least one radio was on.
- And if both radios were off, it toggles WiFi on according to the specs set in normal Wifi config.
The simple button script just requires adding a file '/etc/hotplug.d/button/10-radio-toggle'.
root@OpenWrt:/# cat /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
WPS button:
If you have a WPS-enabled network device (like a modern USB dongle) supporting Wi-Fi Protected Setup (WPS), you can negotiate joining the router's Wifi network without manually entering SSID & passkey. You just initiate "WPS authentication" by pushing the similar WPS button on the device (or launching the process by its driver/control software). After the device has initiated the authentication process, you can accept the transaction by using the WPS button on WNDR3700. The connection should then get negotiated, and in most cases in future your PC should remember the received network settings from then on.
After finding the information and browsing the hostapd package sourcecode, the needed actions for enabling the WPS button are pretty simple:
1) Using WPS authentication requires replacing the default 'wpad-mini' package with 'wpad' and 'hostapd-utils'. The reason is that the tool "hostapd_cli" and some needed support functions are not included in 'wpad-mini'.
WPS authentication itself is launched with a command: hostapd_cli -p /var/run/hostapd-phy0 wps_pbc
It tells the running hostapd daemon to participate in ongoing WPS authentication sequence. It needs to be run separately for each radio (= each existing hostapd process).
2) And it only works if the '/etc/config/wireless' has been modified to include info about WPS authentication being allowed by adding the option 'wps_pushbutton' '1' to the wifi-iface section of (each) radio. Additionally, the encryption should be WPA2-PSK (or maybe WPA-PSK is enough, I haven't tested).
(Looks like the version of hostapd scripts in OpenWrt does not support the full scope of hostapd's capabilities, so many of the config options documented in hostapd docs are left unused.)
That config file is read when radios are turned on, so after editing the config, restart the radios in WNDR3700.
At this point, you should be able to test it by running it from command line. If the message gets passed to hostapd, you should see there result 'OK' there. Otherwise the result is 'FAIL'.
> root@OpenWrt:~# hostapd_cli -p /var/run/hostapd-phy0 wps_pbc
> Selected interface 'wlan0'
> OK
> root@OpenWrt:~#
3) Add a hotplug button event script to launch the process.
I modified directly the hostapd package source ( /package/hostapd/files/wps-hotplug.sh ), as the hotplug script gets automatically installed to '/etc/hotplug.d/button/50-wps' with the package. See below.
The script launches hostapd_cli for each radio and lights the WPS led for 10 seconds. There is no monitoring of the result, or anything like that. It is just a dumb script using the hostapd_cli command to pass the message to the hostapd daemon.
Remember to check the button name: Backfire: wps="BTN_1", trunk: wps="wps"
root@OpenWrt:/# cat /etc/hotplug.d/button/50-wps
if [ "$ACTION" = "pressed" -a "$BUTTON" = "BTN_1" ]; then
echo "255" > /sys/devices/platform/leds-gpio/leds/wndr3700:green:wps/brightness
for dir in /var/run/hostapd-*; do
[ -d "$dir" ] || continue
logger "WPS button active: $dir"
hostapd_cli -p "$dir" wps_pbc
done
sleep 10
echo "0" > /sys/devices/platform/leds-gpio/leds/wndr3700:green:wps/brightness
fi
root@OpenWrt:/# cat /etc/config/wireless
...
config 'wifi-iface'
option 'device' 'radio0'
option 'network' 'lan'
option 'mode' 'ap'
option 'ssid' 'public'
option 'encryption' 'psk2'
option 'key' 'SecretKey'
option 'wps_pushbutton' '1'
...
If everything goes ok, you should see in Syslog not only the button events, but also succesful WPS authentication:
Jan 31 21:11:09 OpenWrt user.notice root: WiFi button used: WiFi up
Jan 31 21:11:09 OpenWrt user.info kernel: ADDRCONF(NETDEV_UP): wlan0: link is not ready
Jan 31 21:11:09 OpenWrt user.info kernel: device wlan0 entered promiscuous mode
Jan 31 21:11:09 OpenWrt user.info kernel: br-lan: port 2(wlan0) entering forwarding state
...
Jan 31 21:12:00 OpenWrt user.notice root: WPS button active: /var/run/hostapd-phy0
Jan 31 21:12:00 OpenWrt user.notice root: WPS button active: /var/run/hostapd-phy1
Jan 31 21:12:03 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.11: authenticated
Jan 31 21:12:03 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.11: associated (aid 1)
Jan 31 21:12:04 OpenWrt daemon.warn hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.1X: authentication failed - EAP type: 0 ((null))
Jan 31 21:12:04 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.1X: Supplicant used different EAP type: 254 ((null))
Jan 31 21:12:04 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.11: disassociated
Jan 31 21:12:05 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.11: deauthenticated due to inactivity
Jan 31 21:12:17 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.11: authenticated
Jan 31 21:12:17 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc IEEE 802.11: associated (aid 1)
Jan 31 21:12:17 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc RADIUS: starting accounting session 4D47094D-00000000
Jan 31 21:12:17 OpenWrt daemon.info hostapd: wlan0: STA 1c:af:f7:f6:11:dc WPA: pairwise key handshake completed (RSN)
Jan 31 21:12:29 OpenWrt daemon.info dnsmasq-dhcp[1855]: DHCPREQUEST(br-lan) 192.168.1.190 1c:af:f7:f6:11:dc
Jan 31 21:12:29 OpenWrt daemon.info dnsmasq-dhcp[1855]: DHCPACK(br-lan) 192.168.1.190 1c:af:f7:f6:11:dc HNH57JG
EDIT: added a note about the correct button names in Backfire and trunk.
If you want to check the button names on your system, you can use the following hotplug script that just logs the button 'pressed' actions into system log:
root@OpenWrt:/etc/config# cat /etc/hotplug.d/button/02-log
#!/bin/sh
if [ "$ACTION" = "pressed" ]; then
logger "button: "$BUTTON
fi