# ! /bin/sh
# write by w

TOPDIR=/ubi/local/apps/network
TMPDIR=/run/network


kill_process()
{
	local i local_pid 
	local_pid=`ps | grep "$1" | grep -v grep | awk '{ print $1 }'`
    for i in $local_pid; do
		kill -9 $i
    done
}


create_bridge()
{
	echo "Create bridge $1 with $2 $3..."
	
	ip link add name ${1} type bridge
	ip link set ${2} master ${1}
	ip link set ${3} master ${1}

	ifconfig ${2} 0.0.0.0
	ifconfig ${3} 0.0.0.0

	ifconfig ${1} up
}
	

unload_wifi_module()
{
	ifconfig wlan0 down
#	rmmod /opt/brcmfmac.ko 
#	rmmod /opt/brcmutil.ko 
}

dhcpd_server()
{
	local dhcpd_param dhcpd_conf
	dhcpd_conf="$TMPDIR/dhcpd.conf"
	dhcpd_param="$TMPDIR/ifcfg-dhcpd-$1"
	if [ -f $dhcpd_param ]; then
		. $dhcpd_param
		if [ ${ENABLE} == "true" ]; then
			cp $TOPDIR/udhcpd.conf $dhcpd_conf
			sed -i "s/^start[ \t]*.*/start \t $START/g" $dhcpd_conf
			sed -i "s/^end[ \t]*.*/end \t $END/g" $dhcpd_conf
			sed -i "s/^interface[ \t]*.*/interface \t $1/g" $dhcpd_conf
			sed -i "s/^option[ \t]*subnet[ \t]*.*/option subnet \t $NETMASK/g" $dhcpd_conf
			sed -i "s/^opt[ \t]*router[ \t]*.*/opt router \t $GATEWAY/g" $dhcpd_conf

			udhcpd $dhcpd_conf
		fi
	fi
}


