changeset 461:261ba8d412dd

Add script which start UPGRADE mode if WPS button hold during rc stage.
author Aleksandr Rybalko <ray@ddteam.net>
date Mon, 24 Sep 2012 14:01:14 +0300
parents bf8653674ede
children 42ab78ecd342
files profiles/lua_web_ui/files/etc/rc.d/UPGRADE_MODE
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/profiles/lua_web_ui/files/etc/rc.d/UPGRADE_MODE	Mon Sep 24 14:01:14 2012 +0300
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# PROVIDE: UPGRADE_MODE
+# BEFORE: MAIN
+# REQUIRE: ADAPTATION FILESYSTEMS
+
+. /etc/rc.subr
+. /etc/network.subr
+
+name="UPGRADE_MODE"
+start_cmd="upgrade_mode_start"
+
+upgrade_mode_start()
+{
+	WPS_PIN=$(kenv WPS_PIN)
+	WPS_PIN_INVERT=$(kenv WPS_PIN_INVERT)
+	if [ ! -z "${WPS_PIN}" ] ; then
+		WPS_PIN_VAL=$(gpioctl -f /dev/gpioc0 -q -g ${WPS_PIN});
+		if [ -z "${WPS_PIN_INVERT}" -o "${WPS_PIN_INVERT}" != "1" ] ; then
+			WPS_PIN_INVERT=0;
+		fi
+		WPS_PIN_VAL=$(( ${WPS_PIN_VAL} ^ ${WPS_PIN_INVERT} ));
+		echo "UPGRADE_MODE: WPS pin[${WPS_PIN}]^${WPS_PIN_INVERT} value = \"${WPS_PIN_VAL}\"";
+		if [ "${WPS_PIN_VAL}" = "1" ] ; then
+			if [ -c /dev/led/wps  ]; then
+				echo m---... > /dev/led/wps
+			fi
+			/etc/rc.d/switchctl enablelan;
+			sleep 5; # Wait for linkup event # XXX better to read devctl
+			echo "RUN UPGRADE MODE";
+			# XXX: Run shell for now
+			ifconfig lan0 192.168.0.1/24
+			ifconfig lan0 down
+			ifconfig lan0 up
+			MD_DEV=$(mdconfig -a -t malloc -o reserve -s8M)
+			printf "http\tstream\ttcp\tnowait\troot\t\
+/sbin/upgrade\t\
+upgrade -l /dev/console -h \
+-H YWRtaW46YWRtaW4= -M \"Secure Area\" \
+-f /dev/%s -d /dev/map/upgrade\n" ${MD_DEV} >> /etc/inetd.conf
+			inetd -wW;
+			sh
+		fi
+	fi
+
+}
+
+load_rc_config $name
+
+run_rc_command $*