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

#### Demo environments.
IPADDR="192.168.8.123"
SSID=YOURSSID
PASS=yourpass

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

case $COMMAND in
    'start')
        wpa_passphrase $SSID $PASS > /Net/wpa_supplicant-mlan.conf
        wpa_supplicant -i $DEVNAME -D nl80211 -c /Net/wpa_supplicant-mlan.conf -B
        
        ifconfig $DEVNAME $IPADDR up
        if [ "${IPADDR}" == "" ] ; then
            dhcpcd $DEVNAME
        fi
    ;;
    
    'stop')
        if [ "${IPADDR}" == "" ] ; then
            dhcpcd -k -d $DEVNAME
        fi
        ifconfig $DEVNAME down
    ;;
    
    *)
        exit 1
    ;;

esac
exit 0

# EOF #
