#!/bin/sh
#### help
# * If you use Static IP
#IPADDR="xxx.xxx.xxx.xxx"
# * If you use DHCP
#IPADDR=

#### Eval environments.
IPADDR="192.168.231.155"
SSID=ICLPSAR1
PASS=HRI-JP.S99.p@ssw0rd

#### Demo environments.
#IPADDR="192.168.8.110"
#SSID=HW02E-4B9870
#PASS=g8454dfh

DEVNAME="$1"
COMMAND="$2"

case $COMMAND in
    'start')
        echo "country=JP" > /Net/wpa_supplicant-wlan.conf
        echo "ap_scan=1" >> /Net/wpa_supplicant-wlan.conf
        echo "fast_reauth=1" >> /Net/wpa_supplicant-wlan.conf
        wpa_passphrase $SSID $PASS >> /Net/wpa_supplicant-wlan.conf
        wpa_supplicant -i $DEVNAME -D wext -c /Net/wpa_supplicant-wlan.conf -P /tmp/wpa-pid -B
        
        ifconfig $DEVNAME $IPADDR up
        if [ "${IPADDR}" == "" ] ; then
            dhcpcd -t 180 $DEVNAME
        fi
    ;;
    
    'stop')
        if [ "${IPADDR}" == "" ] ; then
            dhcpcd -k -d $DEVNAME
        fi
        ifconfig $DEVNAME down
        kill `cat /tmp/wpa-pid`
    ;;
    
    *)
        exit 1
    ;;

esac
exit 0

# EOF #
