#!/bin/sh

KERNEL_EVENT_TAIL=/proc/buffalo/kernevnt
MICONAPL=/usr/local/sbin/miconapl

do_kern_event ()
{
	case $1 in
lanact)
		if [ "$3" = "full" ] ; then
			FULL_HALF="f"
		else
			FULL_HALF="h"
		fi

		case $2 in
		0)
			LINKSPEED="nolink"
			;;
		10)
			LINKSPEED="10${FULL_HALF}"
			;;
		100)
			LINKSPEED="100${FULL_HALF}"
			;;
		1000)
			LINKSPEED="1000"
			;;
		*)
			;;
		esac

	;;
micon_interrupts)
		INT_DETAIL=`${MICONAPL} -a int_get_switch_status |grep "int=" |sed -e "s/int=//"`
		case ${INT_DETAIL} in
		power_sw)
			${MICONAPL} -b -a bz_on button
			/sbin/poweroff
			;;
		init_sw_front)
			${MICONAPL} -b -a bz_on button
			/sbin/reboot
			;;
		*)
			;;
		esac
        	cat /proc/buffalo/miconint_en
		;;
	*)
		echo "Unknown(or not supported) event driven."
		;;
	esac
}


if [ ! -e ${KERNEL_EVENT_TAIL} ] ; then
	exit 0
fi

while :
do
	while :
	do
		LINE=`cat ${KERNEL_EVENT_TAIL}`
		do_kern_event ${LINE}	
	done
done
