SmartAudio/package/testtools/tinatest/testcase/base/wifi/wifiscan/wifi_scan.sh

48 lines
1009 B
Bash
Executable File

#!/bin/sh
WLANDEV=wlan0
WPA_CLI="wpa_cli -i $WLANDEV -p /etc/wifi/sockets/"
wpa_up()
{
wpa=`ps | grep wpa_supplicant | grep -v grep`
[ "$wpa" == "" ] && \
{
echo "start wpa_suplicant!!!!!!!!!!!!!!!!!"
wpa_supplicant -iwlan0 -Dnl80211 -c/etc/wifi/wpa_supplicant.conf -O/etc/wifi/sockets -B
}
}
wifi_scan()
{
[ ! "$(${WPA_CLI} scan)" = "OK" ] \
&& echo "failed:wlan0 can not do scaning" \
&& echo "====== CHECKING scan FAILED ======" \
&& continue
sleep 1 #wait for scaning
aps=`${WPA_CLI} scan_results`
sleep 1 #wait for scaning
if [ -n "${aps}" ]; then
echo "==============SCAN RESULTS================="
echo "Scanned APs:"
echo "${aps}"
echo "==============SCAN Success=================="
return 0
fi
echo "scan nothing. Make sure there are APs around"
echo "====== CHECKING scan FAILED ======"
exit 1
}
check_wlan(){
ifconfig -a | grep wlan0 || {
echo "===========Not Found wlan0========="
exit 1
}
}
check_wlan
wpa_up
wifi_scan