#!/bin/bash
#this script is used to control wpa_supplicant daemon server.
#for EAVCapture iMX6 project.
#by zhangshaoyan at May 26,2015.
WPABIN=wpa_supplicant
WIRELESSNAME=wlp5s0 #wlan0
CONFILE=zwpa.conf
PIDFILE=/var/run/zwpa.pid
DHCLIENT=dhclient
#usage:
#zwpactl.sh initial:install driver.
#zwpactl.sh start: start wpa_supplicant.
#zwpactl.sh stop: stop wpa_supplicant.
function usage()
{
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "Usage:$0 <commands>."
echo "supported commands:"
echo "initial: install WiFi driver module."
echo "start: start wpa_supplicant daemon server."
echo "stop: stop wpa_supplicant."
echo "by 13522296239"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
}
#generate .conf file.
#here is bug exist,do not keep space or Tab before EOF.
function generateConfFile()
{
cat<<EOF >zwpa.conf
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="$1"
psk="$2"
}
EOF
}
#at least need 1 parameter.
if [ $# -lt 1 ];then
usage
exit -1
fi
if [ $1 = "initial" ];then
#insmod wifi driver.
#this should be done at the OS starts before GUI starts.
insmod rtl8188.ko
elif [ $1 = "start" ];then
if [ $# -lt 3 ];then
echo "ZSY:need ssid and psk"
exit -1
fi
#dump out a config file.
generateConfFile $2 $3
#start the daemon server.
${WPABIN} -i${WIRELESSNAME} -c${CONFILE} -P${PIDFILE} -B
if [ $? -eq 0 ];then
echo "ZSY:start success"
#start dhcp client.
${DHCLIENT} -v ${WIRELESSNAME}
if [ $? -ne 0 ];then
echo "ZSY:dhclient fails"
exit -1
fi
else
echo "ZSY:start failed!"
exit -1
fi
elif [ $1 = "stop" ];then
if [ -x $PIDFILE ];then
kill `cat $PIDFILE`
rm -rf $PIDFILE
fi
rm -rf ${CONFILE}
else
echo "ZSY:Unknown command"
exit -1
fi
#success here.
echo "ZSY:wpa ctrl ends with success"
exit 0
#the end of file by zhangshaoyan.
beijing:/home/shell.albert/imx6/EAVCaptureX86/bin #
#this script is used to control wpa_supplicant daemon server.
#for EAVCapture iMX6 project.
#by zhangshaoyan at May 26,2015.
WPABIN=wpa_supplicant
WIRELESSNAME=wlp5s0 #wlan0
CONFILE=zwpa.conf
PIDFILE=/var/run/zwpa.pid
DHCLIENT=dhclient
#usage:
#zwpactl.sh initial:install driver.
#zwpactl.sh start: start wpa_supplicant.
#zwpactl.sh stop: stop wpa_supplicant.
function usage()
{
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "Usage:$0 <commands>."
echo "supported commands:"
echo "initial: install WiFi driver module."
echo "start: start wpa_supplicant daemon server."
echo "stop: stop wpa_supplicant."
echo "by 13522296239"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
}
#generate .conf file.
#here is bug exist,do not keep space or Tab before EOF.
function generateConfFile()
{
cat<<EOF >zwpa.conf
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="$1"
psk="$2"
}
EOF
}
#at least need 1 parameter.
if [ $# -lt 1 ];then
usage
exit -1
fi
if [ $1 = "initial" ];then
#insmod wifi driver.
#this should be done at the OS starts before GUI starts.
insmod rtl8188.ko
elif [ $1 = "start" ];then
if [ $# -lt 3 ];then
echo "ZSY:need ssid and psk"
exit -1
fi
#dump out a config file.
generateConfFile $2 $3
#start the daemon server.
${WPABIN} -i${WIRELESSNAME} -c${CONFILE} -P${PIDFILE} -B
if [ $? -eq 0 ];then
echo "ZSY:start success"
#start dhcp client.
${DHCLIENT} -v ${WIRELESSNAME}
if [ $? -ne 0 ];then
echo "ZSY:dhclient fails"
exit -1
fi
else
echo "ZSY:start failed!"
exit -1
fi
elif [ $1 = "stop" ];then
if [ -x $PIDFILE ];then
kill `cat $PIDFILE`
rm -rf $PIDFILE
fi
rm -rf ${CONFILE}
else
echo "ZSY:Unknown command"
exit -1
fi
#success here.
echo "ZSY:wpa ctrl ends with success"
exit 0
#the end of file by zhangshaoyan.
beijing:/home/shell.albert/imx6/EAVCaptureX86/bin #