#!/bin/bash
#
# Networking start script
#

# Source function library.
#. /etc/init.d/functions

RETVAL=0

umask 077

start() {
    echo -n $"Starting Networking: "
    ifconfig wlan0 down
    #ifconfig wlan1 down
    #ifconfig wlan2 down
    #rmmod hostap_pci
    #modprobe hostap_pci
    #modprobe prism54
    ifconfig lo 127.0.0.1 netmask 255.255.255.0
    ifconfig eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255

    # Prism54
    modprobe prism54
    ifconfig eth1 10.11.1.100 netmask 255.255.255.0 broadcast 10.11.1.255
    iwconfig eth1 essid "CZFree.Net.SH"
    sleep 0.4
    iwconfig eth1 mode Managed
    sleep 0.4
    iwconfig eth1 retry 20

    #iwconfig wlan0 txpower 200
    #iwconfig wlan0 sens 3
    #iwconfig wlan0 rate 5.5Mbit
    #iptables -t nat -A POSTROUTING -s 10.10.126.0/24 -o eth0 -m state --state NEW,ESTABLISHED,RELATED -j MASQUERADE
    #iptables -t nat -A POSTROUTING -s 10.10.126.0/24 -o wlan0 -m state --state NEW,ESTABLISHED,RELATED -j MASQUERADE
    route add default gw 10.11.1.1
    echo "1" > /proc/sys/net/ipv4/ip_forward

    return $RETVAL
}	
stop() {
	echo -n $"Stopping Networking: "
	#ifconfig wlan0 down
	rmmod hostap_pci
	return $RETVAL
}
restart() {
	stop
	start
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?
