openwrt: attach a wifi/eth toggle and return to network defaults to the reset button
This commit is contained in:
parent
06318eea07
commit
7856a4bb5e
|
@ -0,0 +1,17 @@
|
||||||
|
config system
|
||||||
|
option hostname flukso
|
||||||
|
option timezone UTC
|
||||||
|
|
||||||
|
config button
|
||||||
|
option button reset
|
||||||
|
option action released
|
||||||
|
option handler net_toggle
|
||||||
|
option min 2
|
||||||
|
option max 5
|
||||||
|
|
||||||
|
config button
|
||||||
|
option button reset
|
||||||
|
option action released
|
||||||
|
option handler net_defaults
|
||||||
|
option min 10
|
||||||
|
option max 30
|
|
@ -0,0 +1,38 @@
|
||||||
|
# Copyright (c) 2010 flukso.net
|
||||||
|
|
||||||
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
|
PKG_NAME:=button
|
||||||
|
PKG_VERSION:=1.0
|
||||||
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
|
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||||
|
|
||||||
|
include $(INCLUDE_DIR)/package.mk
|
||||||
|
|
||||||
|
define Package/flukso
|
||||||
|
SECTION:=utils
|
||||||
|
CATEGORY:=Utilities
|
||||||
|
DEPENDS:=
|
||||||
|
TITLE:=Button
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/button/description
|
||||||
|
Helper bash scripts used as a callback for hotplug button events. net_toggle toggles between ethernet and wifi mode. net_defaults reverts all firewall, network and wireless settings to factory defaults.
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Prepare
|
||||||
|
mkdir -p $(PKG_BUILD_DIR)
|
||||||
|
$(CP) ./src/* $(PKG_BUILD_DIR)/
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Build/Compile
|
||||||
|
endef
|
||||||
|
|
||||||
|
define Package/flukso/install
|
||||||
|
$(INSTALL_DIR) $(1)/usr/sbin
|
||||||
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/net_toggle $(1)/usr/sbin/
|
||||||
|
$(INSTALL_BIN) $(PKG_BUILD_DIR)/net_defaults $(1)/usr/sbin/
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call BuildPackage,button))
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright (c) 2010 flukso.net
|
||||||
|
|
||||||
|
cd /rom/etc/config
|
||||||
|
cp firewall network wireless /etc/config
|
||||||
|
|
||||||
|
logger 'returning to firewall, network and wireless defaults'
|
||||||
|
|
||||||
|
gpioctl dirout 4
|
||||||
|
|
||||||
|
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
||||||
|
do
|
||||||
|
gpioctl clear 4
|
||||||
|
gpioctl set 4
|
||||||
|
done
|
||||||
|
|
||||||
|
/etc/init.d/network restart
|
|
@ -0,0 +1,47 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Copyright (c) 2010 flukso.net
|
||||||
|
|
||||||
|
to_wifi ()
|
||||||
|
{
|
||||||
|
uci set firewall.@zone[1].input=REJECT
|
||||||
|
uci set network.wan.ifname=ath0
|
||||||
|
uci set network.lan.ifname=eth0
|
||||||
|
uci set wireless.wifi0.disabled=0
|
||||||
|
uci set wireless.@wifi-iface[0].network=wan
|
||||||
|
uci set wireless.@wifi-iface[0].mode=sta
|
||||||
|
uci commit
|
||||||
|
logger 'toggled to wifi mode'
|
||||||
|
}
|
||||||
|
|
||||||
|
to_eth ()
|
||||||
|
{
|
||||||
|
uci set firewall.@zone[1].input=ACCEPT
|
||||||
|
uci set network.wan.ifname=eth0
|
||||||
|
uci set network.lan.ifname=ath0
|
||||||
|
uci set wireless.wifi0.disabled=1
|
||||||
|
uci set wireless.@wifi-iface[0].network=lan
|
||||||
|
uci set wireless.@wifi-iface[0].mode=ap
|
||||||
|
uci commit
|
||||||
|
logger 'toggled to eth mode'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MODE=$(uci get network.wan.ifname)
|
||||||
|
|
||||||
|
if [ $MODE == eth0 ]
|
||||||
|
then
|
||||||
|
to_wifi
|
||||||
|
elif [ $MODE == ath0 ]
|
||||||
|
then
|
||||||
|
to_eth
|
||||||
|
fi
|
||||||
|
|
||||||
|
gpioctl dirout 4
|
||||||
|
|
||||||
|
for i in 1 2 3 4 5
|
||||||
|
do
|
||||||
|
gpioctl clear 4
|
||||||
|
gpioctl set 4
|
||||||
|
done
|
||||||
|
|
||||||
|
/etc/init.d/network restart
|
Loading…
Reference in New Issue