Start
yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh start
need ssid and pskyantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh start zhangshaoyan
need ssid and psk
yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh start zhangshaoyan beijing12345
Successfully initialized wpa_supplicant
yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin #
Check
yantai:/home/shell.albert # ps aux | grep "wpa"
root 948 0.0 0.0 30836 3772 ? Ss 08:37 0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root 13358 0.0 0.0 10524 1624 pts/3 S+ 15:44 0:00 grep --color=auto wpa
yantai:/home/shell.albert # ps aux | grep "wpa"
root 948 0.0 0.0 30836 3772 ? Ss 08:37 0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root 13419 0.0 0.0 30836 2168 ? Ss 15:45 0:00 wpa_supplicant -iwlp5s0 -czwpa.conf -P/var/run/zwpa.pid -B
root 13429 0.0 0.0 10524 1528 pts/3 S+ 15:45 0:00 grep --color=auto wpa
yantai:/home/shell.albert # cat /var/run/zwpa.pid
13419
yantai:/home/shell.albert #
Stop
yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh stopyantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin #
yantai:/home/shell.albert # cat /var/run/zwpa.pid
cat: /var/run/zwpa.pid: No such file or directory
yantai:/home/shell.albert # ps aux | grep "wpa"
root 948 0.0 0.0 30836 3772 ? Ss 08:37 0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root 13455 0.0 0.0 10524 1568 pts/3 S+ 15:45 0:00 grep --color=auto wpa
yantai:/home/shell.albert #
wpa_supplicant is also need dhcient to get IP from DHCP server.
yantai:/home/shell.albert # dhclient -v wlp5s0
Internet Systems Consortium DHCP Client 4.2.6
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/wlp5s0/00:26:c7:24:28:f4
Sending on LPF/wlp5s0/00:26:c7:24:28:f4
Sending on Socket/fallback
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 2 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 4 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 11 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 20 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 7 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 12 (xid=0x39b72d2e)
DHCPREQUEST on wlp5s0 to 255.255.255.255 port 67 (xid=0x39b72d2e)
DHCPOFFER from 192.168.0.1
DHCPACK from 192.168.0.1 (xid=0x39b72d2e)
bound to 192.168.0.148 -- renewal in 2921 seconds.
yantai:/home/shell.albert # echo $?
0
yantai:/home/shell.albert #
Come on baby,read the following script carefully! Enjoy it !
#!/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
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.