From 7856a4bb5efff073318680790428de75c9b9a7c0 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Mon, 30 Aug 2010 21:08:38 +0200 Subject: [PATCH] openwrt: attach a wifi/eth toggle and return to network defaults to the reset button --- mote/v2/openwrt/files/etc/config/system | 17 +++++++ mote/v2/openwrt/package/button/Makefile | 38 +++++++++++++++ .../openwrt/package/button/src/net_defaults | 17 +++++++ mote/v2/openwrt/package/button/src/net_toggle | 47 +++++++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 mote/v2/openwrt/files/etc/config/system create mode 100644 mote/v2/openwrt/package/button/Makefile create mode 100755 mote/v2/openwrt/package/button/src/net_defaults create mode 100755 mote/v2/openwrt/package/button/src/net_toggle diff --git a/mote/v2/openwrt/files/etc/config/system b/mote/v2/openwrt/files/etc/config/system new file mode 100644 index 0000000..1716d5f --- /dev/null +++ b/mote/v2/openwrt/files/etc/config/system @@ -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 diff --git a/mote/v2/openwrt/package/button/Makefile b/mote/v2/openwrt/package/button/Makefile new file mode 100644 index 0000000..44b275b --- /dev/null +++ b/mote/v2/openwrt/package/button/Makefile @@ -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)) diff --git a/mote/v2/openwrt/package/button/src/net_defaults b/mote/v2/openwrt/package/button/src/net_defaults new file mode 100755 index 0000000..8efb631 --- /dev/null +++ b/mote/v2/openwrt/package/button/src/net_defaults @@ -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 diff --git a/mote/v2/openwrt/package/button/src/net_toggle b/mote/v2/openwrt/package/button/src/net_toggle new file mode 100755 index 0000000..2d45a42 --- /dev/null +++ b/mote/v2/openwrt/package/button/src/net_toggle @@ -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