1609 lines
41 KiB
Bash
1609 lines
41 KiB
Bash
#!/bin/sh
|
||
export PATH=$PATH:/bin/vs/cgi-bin:/bin/vs:/komod
|
||
|
||
|
||
## 加载/卸载 wifi ko
|
||
wifiko()
|
||
{
|
||
if [ $1 = "load" ]
|
||
then
|
||
$drvload
|
||
elif [ $1 = "unload" ]
|
||
then
|
||
$drvunload
|
||
fi
|
||
|
||
}
|
||
|
||
wifiko_ap()
|
||
{
|
||
if [ $1 = "load" ]
|
||
then
|
||
$drvload_ap
|
||
elif [ $1 = "unload" ]
|
||
then
|
||
$drvunload_ap
|
||
fi
|
||
}
|
||
|
||
|
||
|
||
#$1 ssid
|
||
#$2 wifikeytype
|
||
#$3 wepid
|
||
#$4 wifikey
|
||
#$5 wpa_config filename
|
||
|
||
gen_wpa_config()
|
||
{
|
||
wifiessid=$1
|
||
wifikeytype=$2
|
||
wifiwhichkey=$3
|
||
wifikey=$4
|
||
wifi_wpa_conf=$5
|
||
show_dbg2 "gen_wpa_config $*"
|
||
show_info "gen wpa ssid:$wifiessid,keytype:$wifikeytype,keyidx:$wifiwhichkey,key:$wifikey,file:$wifi_wpa_conf"
|
||
|
||
##实时匹配当前ssid的加密类型,如果匹配不上就按原来文件里保存的类型去执行
|
||
##这样做的目的是防止用户改了加密类型但是ssid和pwd都没有改从而导致设备连不上route
|
||
if [ ! -z $customernum ] && [ $customernum == "123" ];then
|
||
echo -n "NOTFOUND" > /etc/network/wifista.conf
|
||
fi
|
||
rm -Rf $wpa_config_tmp 2>/dev/null
|
||
echo "ctrl_interface=/var/run/wpa_supplicant" > $wpa_config_tmp
|
||
|
||
echo "ap_scan=1" >> $wpa_config_tmp
|
||
echo "update_config=1" >> $wpa_config_tmp
|
||
|
||
#wifikeytype define in file $wifi_config
|
||
#wifikeytype =1: no key
|
||
#wifikeytype =2: wep
|
||
#wifikeytype =3:wpa
|
||
|
||
if [ $wifikeytype = 1 ]
|
||
then
|
||
echo "network={" >> $wpa_config_tmp
|
||
echo "ssid=${wifiessid} " >> $wpa_config_tmp
|
||
echo "key_mgmt=NONE" >> $wpa_config_tmp
|
||
echo "}" >> $wpa_config_tmp
|
||
elif [ $wifikeytype = 2 ]
|
||
then
|
||
echo "network={" >> $wpa_config_tmp
|
||
echo "ssid=${wifiessid} " >> $wpa_config_tmp
|
||
wifikeylen=`expr length "$wifikey"`
|
||
show_info wifikey $wifikey wifikeylen is $wifikeylen
|
||
|
||
if [ $wifikeylen -eq 5 ] || [ $wifikeylen -eq 13 ] || [ $wifikeylen -eq 16 ]
|
||
then
|
||
##字符
|
||
show_info "wepkey char"
|
||
echo "wep_key${wifiwhichkey}=\"${wifikey}\"" >> $wpa_config_tmp
|
||
elif [ $wifikeylen -eq 10 ] || [ $wifikeylen -eq 26 ] || [ $wifikeylen -eq 32 ]
|
||
then
|
||
show_info "wepkey hex"
|
||
echo "wep_key${wifiwhichkey}=${wifikey}" >> $wpa_config_tmp
|
||
else
|
||
show_info "wepkey err"
|
||
fi
|
||
####echo "wep_key${wifiwhichkey}=${wifikey}" >> $wpa_config_tmp
|
||
|
||
echo "key_mgmt=NONE" >> $wpa_config_tmp
|
||
echo "wep_tx_keyidx=${wifiwhichkey}" >> $wpa_config_tmp
|
||
echo "auth_alg=OPEN SHARED" >> $wpa_config_tmp
|
||
echo " }" >> $wpa_config_tmp
|
||
|
||
elif [ $wifikeytype = 3 ]
|
||
then
|
||
if [ x"$wifikey" = x ]
|
||
then
|
||
echo "ERROR. WifiKey is null"
|
||
wifikey="12345678"
|
||
fi
|
||
|
||
wifikeylen=`expr length "$wifikey"`
|
||
echo wifikey is $wifikey wifikeylen is $wifikeylen
|
||
if [ $wifikeylen -lt 8 ]
|
||
then
|
||
echo "ERROR. Wifikey length must large than 8"
|
||
wifikey="12345678"
|
||
fi
|
||
#wpa_passphrase "$wifiessid" "$wifikey" >> $wpa_config_tmp
|
||
wpaconf $wifiessid $wifikey >> $wpa_config_tmp
|
||
fi
|
||
|
||
#for hide ssid
|
||
networkline=`cat $wpa_config_tmp | grep "network={" -n | awk -F ":" '{print $1}'`
|
||
if [ -n "$networkline" ];then
|
||
networkline=`expr $networkline + 1`
|
||
sed -i "$networkline s/^/\tscan_ssid=1\n/" $wpa_config_tmp
|
||
fi
|
||
|
||
sync
|
||
}
|
||
|
||
wifi_sta_connect_ex()
|
||
{
|
||
show_dbg2 "XXXXXXXXXX DONNOTCALL wifi_sta_connect_ex"
|
||
return
|
||
sta_ssid=$1
|
||
sta_key=$2
|
||
sta_key_type=$3
|
||
wifiwhichkey=0
|
||
|
||
#if [ -e "$wpa_config_tmp" ];then
|
||
show_info "wifi_sta_connect_ex wifiessid:$sta_ssid wifikey:$sta_key wifikeytype:$sta_key_type"
|
||
|
||
show_dbg2 "wpa_config_tmp:$wpa_config_tmp"
|
||
gen_wpa_config "${sta_ssid}" ${sta_key_type} ${wifiwhichkey} "${sta_key}" "${wpa_config_tmp}"
|
||
#mv -f $wpa_config_tmp $wpa_config
|
||
#fi
|
||
|
||
####wifi_ledflash 4
|
||
|
||
##gen_wpa_config
|
||
## 重新启动wpa_supplicant
|
||
|
||
show_func "wifi_sta_connect_ex"
|
||
echo "">$tmpfs_path/wifi.disconnect
|
||
if [ ! -z `pidof wpa_supplicant` ]
|
||
then
|
||
show_info "wifi_sta_connect_ex, stop wpa_supplicant"
|
||
wpa_cli -i $wifidev disconnect >>$tmpfs_path/wifi.disconnect 2>&1
|
||
wpa_cli -i $wifidev terminate >>$tmpfs_path/wifi.disconnect 2>&1
|
||
fi
|
||
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
show_info "wifi_sta_connect_ex, start wpa_supplicant"
|
||
wpa_supplicant -B -d -D$wpa_driver -i $wifidev -c $wpa_config_tmp >$tmpfs_path/wifi.connect 2>&1
|
||
####wpa_cli -i $wifidev reconfigure
|
||
sleep 3
|
||
wpa_cli -i $wifidev disconnect >>$tmpfs_path/wifi.disconnect 2>&1
|
||
wpa_cli -i $wifidev select_network 0 >>$tmpfs_path/wifi.disconnect 2>&1
|
||
wpa_cli -i $wifidev enable_network 0 >>$tmpfs_path/wifi.disconnect 2>&1
|
||
|
||
}
|
||
|
||
#"$wifiessid=$1"
|
||
#"$wifikey=$2"
|
||
#"$wifikeytype=$3"
|
||
wifi_sta_save_info()
|
||
{
|
||
TmpFile=/tmpfs/wifi_config_tmp
|
||
#TmpFile=./wifi_config_tmp
|
||
. $wifi_config
|
||
|
||
###目的是兼容老分支的版本,老版本的wifi配置文件和新分支版本不一样
|
||
isIndexExist=0
|
||
if [ -z "$last_index" ]
|
||
then
|
||
isIndexExist=1
|
||
fi
|
||
|
||
#replace
|
||
case $1 in
|
||
$wifiessid)
|
||
last_index=0
|
||
wifiessid=wifiessid
|
||
wifikey=wifikey
|
||
wifikeytype=wifikeytype
|
||
;;
|
||
$wifiessid1)
|
||
last_index=1
|
||
wifiessid=wifiessid1
|
||
wifikey=wifikey1
|
||
wifikeytype=wifikeytype1
|
||
;;
|
||
$wifiessid2)
|
||
last_index=2
|
||
wifiessid=wifiessid2
|
||
wifikey=wifikey2
|
||
wifikeytype=wifikeytype2
|
||
;;
|
||
*)
|
||
if [ $group_index -eq 0 ];then
|
||
wifiessid=wifiessid
|
||
wifikey=wifikey
|
||
wifikeytype=wifikeytype
|
||
else
|
||
wifiessid=wifiessid$group_index
|
||
wifikey=wifikey$group_index
|
||
wifikeytype=wifikeytype$group_index
|
||
fi
|
||
|
||
last_index=$group_index
|
||
|
||
group_index=`expr $group_index + 1`
|
||
if [ $group_index -eq 3 ];then
|
||
group_index=0
|
||
fi
|
||
;;
|
||
esac
|
||
|
||
wifiessid_line=`cat $wifi_config | grep ^$wifiessid= -n | cut -d : -f 1`
|
||
wifikey_line=`cat $wifi_config | grep ^$wifikey= -n | cut -d : -f 1`
|
||
wifikeytype_line=`cat $wifi_config | grep ^$wifikeytype= -n | cut -d : -f 1`
|
||
group_index_line=`cat $wifi_config | grep ^group_index= -n | cut -d : -f 1`
|
||
last_index_line=`cat $wifi_config | grep ^last_index= -n | cut -d : -f 1`
|
||
|
||
sta_ssid="$wifiessid=\"$1\""
|
||
sta_key="$wifikey=\"$2\""
|
||
sta_key_type="$wifikeytype=$3"
|
||
sta_group_index="group_index=$group_index"
|
||
sta_last_index="last_index=$last_index"
|
||
|
||
if [ $isIndexExist == 1 ]
|
||
then
|
||
sed -e "${wifiessid_line}s/^.*$/$sta_ssid/" -e "${wifikeytype_line}s/^.*$/$sta_key_type/" -e "${wifikey_line}s/^.*$/$sta_key/" $wifi_config > $TmpFile
|
||
else
|
||
sed -e "${last_index_line}s/^.*$/$sta_last_index/" -e "${group_index_line}s/^.*$/$sta_group_index/" -e "${wifiessid_line}s/^.*$/$sta_ssid/" -e "${wifikeytype_line}s/^.*$/$sta_key_type/" -e "${wifikey_line}s/^.*$/$sta_key/" $wifi_config > $TmpFile
|
||
fi
|
||
|
||
sync
|
||
mv $TmpFile $wifi_config
|
||
}
|
||
|
||
get_last_ssid()
|
||
{
|
||
sta_ssid=
|
||
. $wifi_config
|
||
###老分支版本机器升级新分支版本时因为没有last_index会导致设备进ap,故在此做个判断
|
||
if [ -z "$last_index" ]
|
||
then
|
||
last_index=0
|
||
fi
|
||
|
||
case $last_index in
|
||
0)
|
||
sta_ssid=$wifiessid
|
||
;;
|
||
1)
|
||
sta_ssid=$wifiessid1
|
||
;;
|
||
*)
|
||
sta_ssid=$wifiessid2
|
||
;;
|
||
esac
|
||
|
||
echo "$sta_ssid"
|
||
}
|
||
|
||
gen_last_wpa_config()
|
||
{
|
||
sta_ssid=$(get_last_ssid)
|
||
sta_key=
|
||
sta_key_type=
|
||
|
||
. $wifi_config
|
||
|
||
case "$sta_ssid" in
|
||
"$wifiessid")
|
||
sta_key=$wifikey
|
||
sta_key_type=$wifikeytype
|
||
;;
|
||
"$wifiessid1")
|
||
sta_key=$wifikey1
|
||
sta_key_type=$wifikeytype1
|
||
;;
|
||
"$wifiessid2")
|
||
sta_key=$wifikey2
|
||
sta_key_type=$wifikeytype2
|
||
;;
|
||
*)
|
||
echo "err"
|
||
return
|
||
;;
|
||
esac
|
||
|
||
gen_wpa_config "${sta_ssid}" $sta_key_type $wifiwhichkey "${sta_key}" "${wpa_config_tmp}"
|
||
}
|
||
|
||
connect_last_sta_ssid()
|
||
{
|
||
sta_ssid=$(get_last_ssid)
|
||
|
||
#检查最新配置的ssid是否在搜索列表中
|
||
sta_ssid_tmp=`cat $wifiscanresult | grep -w "$sta_ssid" | cut -f5 | awk '{print $0}' | head -n 1 `
|
||
if [ -n "$sta_ssid_tmp" ];then
|
||
oldssidlen=`expr length "$sta_ssid"`
|
||
newssidlen=`expr length "$sta_ssid_tmp"`
|
||
##如果找到了,需要再比较长度,长度相同说明真正找到了该ssid
|
||
if [ $oldssidlen == $newssidlen ];then
|
||
echo "$sta_ssid"
|
||
show_info "find curr connect ssid"
|
||
else
|
||
echo ""
|
||
show_info "no match ssid"
|
||
fi;
|
||
|
||
else
|
||
echo ""
|
||
show_info "The match failed to use the user's current input wifi"
|
||
fi
|
||
}
|
||
|
||
wifi_sta_connect_ap_list()
|
||
{
|
||
wifi_scan
|
||
|
||
. $wifi_config
|
||
|
||
sta_ssid=$(connect_last_sta_ssid)
|
||
sta_key=
|
||
sta_key_type=
|
||
|
||
if [ -z "$sta_ssid" ];then
|
||
if [ "$#" -eq 0 ]
|
||
then
|
||
ssid_index=1
|
||
else
|
||
ssid_index=`expr $1 + 1`
|
||
fi
|
||
|
||
sta_ssid=`cat $wifiscanresult | grep -E "$wifiessid|$wifiessid1|$wifiessid2" | awk '{print $NF}' | head -n $ssid_index | tail -n 1`
|
||
|
||
#如所有sta记录都没有在热点列表中,默认用最新的一组进行连接
|
||
if [ -z "$sta_ssid" ];then
|
||
sta_ssid=$(get_last_ssid)
|
||
fi
|
||
fi
|
||
|
||
show_info "wifi_sta_connect_ap_list sta_ssid:$sta_ssid"
|
||
|
||
case "$sta_ssid" in
|
||
"$wifiessid")
|
||
sta_key=$wifikey
|
||
sta_key_type=$wifikeytype
|
||
;;
|
||
"$wifiessid1")
|
||
sta_key=$wifikey1
|
||
sta_key_type=$wifikeytype1
|
||
;;
|
||
"$wifiessid2")
|
||
sta_key=$wifikey2
|
||
sta_key_type=$wifikeytype2
|
||
;;
|
||
*)
|
||
echo "err"
|
||
return
|
||
;;
|
||
esac
|
||
|
||
wifi_sta_connect_ex "${sta_ssid}" "${sta_key}" $sta_key_type
|
||
|
||
echo "ok"
|
||
|
||
}
|
||
|
||
wifi_sta_connect()
|
||
{
|
||
echo "">$tmpfs_path/wifi.disconnect
|
||
## 重新启动wpa_supplicant
|
||
show_func "wifi_sta_connect"
|
||
echo "">$tmpfs_path/wifi.disconnect
|
||
if [ ! -z `pidof wpa_supplicant` ]
|
||
then
|
||
show_info "wifi_sta_connect, stop wpa_supplicant"
|
||
wpa_cli -i $wifidev disconnect >>$tmpfs_path/wifi.disconnect 2>&1
|
||
wpa_cli -i $wifidev terminate >>$tmpfs_path/wifi.disconnect 2>&1
|
||
fi
|
||
|
||
|
||
net_up $wifidev
|
||
show_info "wifi_sta_connect, start wpa_supplicant"
|
||
wpa_supplicant -B -d -D$wpa_driver -i $wifidev -c $wpa_config >$tmpfs_path/wifi.connect 2>&1
|
||
####wpa_cli -i $wifidev reconfigure
|
||
#sleep 1
|
||
#wpa_cli -i $wifidev disconnect >>$tmpfs_path/wifi.disconnect 2>&1
|
||
#wpa_cli -i $wifidev select_network 0 >>$tmpfs_path/wifi.disconnect 2>&1
|
||
#wpa_cli -i $wifidev enable_network 0 >>$tmpfs_path/wifi.disconnect 2>&1
|
||
|
||
}
|
||
|
||
wifi_sta_disconnect()
|
||
{
|
||
wpa_cli -i $wifidev disconnect >$tmpfs_path/wifi.disconnect1 2>&1
|
||
}
|
||
|
||
wifi_fixnet_connect()
|
||
{
|
||
####wifi_ledflash 4
|
||
|
||
##gen_wpa_config
|
||
## 重新启动wpa_supplicant
|
||
echo "">$tmpfs_path/wifi.disconnect
|
||
if [ ! -z `pidof wpa_supplicant` ]
|
||
then
|
||
wpa_cli -i $wifidev disconnect >>$tmpfs_path/wifi.disconnect 2>&1
|
||
wpa_cli -i $wifidev terminate >>$tmpfs_path/wifi.disconnect 2>&1
|
||
sleep 3
|
||
fi
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
wpa_supplicant -B -d -D$wpa_driver -i $wifidev -c $fixnet_config >$tmpfs_path/wifi.connect 2>&1
|
||
|
||
####wpa_cli -i $wifidev reconfigure
|
||
|
||
wpa_cli -i $wifidev disconnect >>$tmpfs_path/wifi.disconnect 2>&1
|
||
wpa_cli -i $wifidev select_network 0 >>$tmpfs_path/wifi.disconnect 2>&1
|
||
wpa_cli -i $wifidev enable_network 0 >>$tmpfs_path/wifi.disconnect 2>&1
|
||
|
||
|
||
}
|
||
|
||
outputwifiscanresult()
|
||
{
|
||
echo -e -n "Content-Type:text/plain\n\r\n\r"
|
||
#rt_llq,解决ssid为 "" 时,js报错
|
||
cat $wifiscanresult | cut -f5 | awk '{print "var ssid_"NR"=\""$0"\";"}' | sed 's/""""/"\\"\\""/'
|
||
cat $wifiscanresult | cut -f3 | awk '{print "var signal_"NR"=\""$1"\";"}'
|
||
cat $wifiscanresult | cut -f4 | awk '{print "var secret_"NR"=\""$1"\";"}'
|
||
#结果中, 有一个\n, 所以不需要再多一个\n cat /tmpfs/wifiaplist | cut -f5 | awk '{print "var ssid_"NR"=\""$0"\";"}'
|
||
echo -e -n "\r\n\r"
|
||
|
||
}
|
||
|
||
wifi_scan_old()
|
||
{
|
||
show_info "wifi_scan"
|
||
########如果正在搜索的则直接返回,以免造成搜索结果相互覆盖。
|
||
if [ -e /tmpfs/wifi_scan ];then
|
||
return ;
|
||
else
|
||
echo "" > /tmpfs/wifi_scan
|
||
fi
|
||
|
||
wpa_cli -i $wifidev scan > /dev/null 2>&1
|
||
sleep 1
|
||
wpa_cli -i $wifidev scan_result > $tmpfs_path/tmpresult.lst
|
||
echo "">>$tmpfs_path/tmpresult.lst
|
||
sleep 2
|
||
wpa_cli -i $wifidev scan_result > $tmpfs_path/tmpresult.lst
|
||
echo "">>$tmpfs_path/tmpresult.lst
|
||
|
||
##20140429 sort $tmpfs_path/tmpresult.lst -k1 | awk 'BEGIN{print "bssid signal ssid"}{ if ($1!=bss && $1 != "bssid" && $1 != "") {print $0}; bss=$1}' > $wifiscanresult
|
||
sort $tmpfs_path/tmpresult.lst -k1 | awk 'BEGIN{print "bssid signal ssid"}{ if ($1!=bss && $1 != "bssid" && $1 != "") {print $0}; bss=$1}' > $tmpfs_path/tmpresult2.lst
|
||
sort -r $tmpfs_path/tmpresult2.lst -k3 > $wifiscanresult
|
||
|
||
rm /tmpfs/wifi_scan -rf
|
||
|
||
show_info "wifi_scan exit"
|
||
}
|
||
|
||
wifi_scan()
|
||
{
|
||
show_info "wifi_scan"
|
||
########如果正在搜索的则直接返回,以免造成搜索结果相互覆盖。
|
||
if [ -e /tmpfs/wifi_scan ];then
|
||
return ;
|
||
else
|
||
echo "" > /tmpfs/wifi_scan
|
||
fi
|
||
|
||
echo "" > $wifiscanresult
|
||
|
||
iwlist $wifidev scan > /dev/null 2>&1
|
||
sleep 1
|
||
|
||
iwlist $wifidev scan > $tmpfs_path/tmpresult.lst
|
||
ret=`cat $tmpfs_path/tmpresult.lst | grep "No scan results" > /dev/null; echo $?`
|
||
if [ $ret"A" == "0A" ];then
|
||
rm $tmpfs_path/tmpresult.lst -rf
|
||
fi
|
||
echo "">>$tmpfs_path/tmpresult.lst
|
||
sleep 1
|
||
|
||
iwlist $wifidev scan > $tmpfs_path/tmpresult.lst
|
||
ret=`cat $tmpfs_path/tmpresult.lst | grep "No scan results" > /dev/null; echo $?`
|
||
if [ $ret"A" == "0A" ];then
|
||
rm $tmpfs_path/tmpresult.lst -rf
|
||
fi
|
||
echo "">>$tmpfs_path/tmpresult.lst
|
||
|
||
##20140429 sort $tmpfs_path/tmpresult.lst -k1 | awk 'BEGIN{print "bssid signal ssid"}{ if ($1!=bss && $1 != "bssid" && $1 != "") {print $0}; bss=$1}' > $wifiscanresult
|
||
sort $tmpfs_path/tmpresult.lst -k1 | awk 'BEGIN{print "bssid signal ssid"}{ if ($1!=bss && $1 != "bssid" && $1 != "") {print $0}; bss=$1}' > $tmpfs_path/tmpresult2.lst
|
||
sort -r $tmpfs_path/tmpresult2.lst -k3 > $wifiscanresult
|
||
|
||
rm /tmpfs/wifi_scan -rf
|
||
|
||
show_info "wifi_scan exit"
|
||
}
|
||
|
||
|
||
wifi_getstatus()
|
||
{
|
||
tmpname=$tmpfs_path/wifistatus.$$
|
||
wpa_cli -i $wifidev status 1>$tmpname 2>/dev/null
|
||
##chmod +x $tmpname
|
||
#. $tmpname
|
||
wpa_state=`cat /tmpfs/wifistatus.$$ | grep wpa_state | cut -d= -f2`
|
||
##COMPLETED ....
|
||
if [ -z $wpa_state ]
|
||
then
|
||
echo "ERROR"
|
||
else
|
||
echo $wpa_state
|
||
fi
|
||
rm $tmpname -f 2>/dev/null
|
||
}
|
||
|
||
wifi_wait_connect()
|
||
{
|
||
|
||
retry_times=10
|
||
retry_waittimes=4
|
||
cnt=0
|
||
|
||
##show_dbg2 "wifi_wait_connect retry_times $retry_times retry_waittimes $retry_waittimes"
|
||
while [ $cnt -lt $retry_times ]
|
||
do
|
||
linkstatus=$(wifi_getstatus)
|
||
if [ -z $linkstatus ]
|
||
then
|
||
linkstatus=ERROR
|
||
break
|
||
else
|
||
### 只有COMPLETED 才是链接成功, 可能的值为 SCANNING, ASSOCIATING,SCANNING
|
||
if [ ${linkstatus} = COMPLETED ]
|
||
then
|
||
linkstatus="COMPLETED"
|
||
break
|
||
else
|
||
sleep $retry_waittimes
|
||
cnt=`expr $cnt + 1`
|
||
fi
|
||
fi
|
||
done
|
||
echo $linkstatus
|
||
}
|
||
## return 1 offline
|
||
wifi_module_offline()
|
||
{
|
||
wifi_online=`/bin/vslocal/cgi-bin/getwifioffline.sh`
|
||
echo $wifi_online
|
||
}
|
||
|
||
wifi_getenable()
|
||
{
|
||
wifienable=0
|
||
if [ -e $wifi_config ]
|
||
then
|
||
#get wifienable
|
||
. $wifi_config
|
||
|
||
else
|
||
wifienable=0
|
||
fi
|
||
|
||
wifi_offline=$(wifi_module_offline)
|
||
if [ $wifi_offline == 1 ]
|
||
then
|
||
echo -1
|
||
else
|
||
echo $wifienable
|
||
fi
|
||
##ifconfig ra0 >$tmpfs_path/ra0status 2>&1
|
||
##ra0status=$?
|
||
##if [ $ra0status = 1 ]
|
||
##then
|
||
## echo -1
|
||
##else
|
||
## echo $wifienable
|
||
##fi
|
||
}
|
||
|
||
|
||
|
||
###BTTODO, get ap config from config file
|
||
wifi_ap_ipcfg()
|
||
{
|
||
killall -9 udhcpc
|
||
killall -9 udhcpd
|
||
killall -9 dnsd
|
||
|
||
|
||
show_info "AP ip config as $ap_ip"
|
||
hostapd_conf=$tmpfs_path/hostapd.conf
|
||
mkdir -p /var/run/hostapd
|
||
#wifi_module_type=`/bin/vslocal/cgi-bin/getwifimoduletype.sh`
|
||
if [ $wifi_module_type == "7601" ]
|
||
then
|
||
ap_ssid=`cat $tmpfs_path/RT2870AP.dat | grep SSID -w | cut -d= -f2`
|
||
elif [ $wifi_module_type == "8189" ]
|
||
then
|
||
ap_ssid=`cat /etc/network/wifi8189ap.conf | grep SSID -w | cut -d= -f2`
|
||
else
|
||
show_error "unknow wifi_module_type $wifi_module_type "
|
||
fi
|
||
|
||
ap_chn=1
|
||
if [ $ap_ssid"A" == "A" ];then
|
||
ap_ssid="IPCAM-AP"
|
||
fi
|
||
echo "interface=$wifidev" > $hostapd_conf
|
||
echo "ctrl_interface=/var/run/hostapd" >> $hostapd_conf
|
||
echo "driver=nl80211" >> $hostapd_conf
|
||
echo "hw_mode=g" >> $hostapd_conf
|
||
echo "channel=$ap_chn" >> $hostapd_conf
|
||
echo "ssid=$ap_ssid" >> $hostapd_conf
|
||
echo "beacon_int=100" >> $hostapd_conf
|
||
echo "dtim_period=2" >> $hostapd_conf
|
||
echo "max_num_sta=5" >> $hostapd_conf
|
||
|
||
wifiap_conf=/etc/network/wifiap.conf
|
||
authMode=`cat $wifiap_conf | grep auth_mode | cut -d "=" -f2`
|
||
if [ $authMode"A" == "WPA2PSK""A" ];then
|
||
echo wpa=2 >> $hostapd_conf
|
||
echo wpa_key_mgmt=WPA-PSK >> $hostapd_conf
|
||
echo wpa_pairwise=CCMP >> $hostapd_conf
|
||
wpaPsk=`cat $wifiap_conf | grep wpa_psk | cut -d "=" -f2`
|
||
echo wpa_passphrase=$wpaPsk >> $hostapd_conf
|
||
fi
|
||
|
||
hostapd $hostapd_conf -d -B
|
||
ifconfig $wifidev $ap_ip netmask $ap_mask
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
route add default gw $ap_gateway dev $wifidev
|
||
route add -net 239.0.0.0 netmask 255.0.0.0 $wifidev 2>/dev/null
|
||
udhcpd -S
|
||
dnsd -d
|
||
. $mac_lined_file
|
||
#$1 NETTYPE #$2 IP #$3 MASK #$4 GW #$5 MAC #$6 DHCPFlag #$7 DNSFlag(null for get from ifattr)
|
||
net_cache $wifidev $ap_ip $ap_mask $ap_gateway $macaddress "0" "specify"
|
||
/bin/vs/mcast.sh 5 &
|
||
|
||
wifi_scan
|
||
|
||
#BT#if [ ! -e $ip_cache1 ]
|
||
#BT#then
|
||
#BT# . $ip_config
|
||
#BT# . $mac_lined_file
|
||
#BT# if [ $dhcp = "n" ]
|
||
#BT# then
|
||
#BT# net_cache $wifidev $address $netmask $gateway $macaddress "0" "0"
|
||
#BT# else
|
||
#BT# net_cache $wifidev $address $netmask $gateway $macaddress "1" "1"
|
||
#BT# fi
|
||
#BT# #$1 NETTYPE #$2 IP #$3 MASK #$4 GW #$5 MAC #$6 DHCPFlag #$7 DNSFlag
|
||
#BT#fi
|
||
|
||
}
|
||
|
||
ap_name_set_7601()
|
||
{
|
||
APSSID=$1
|
||
|
||
APFile="/etc/Wireless/RT2870AP/RT2870AP.orig.dat"
|
||
TmpFile="$tmpfs_path/RT2870AP.dat"
|
||
APFileLink="/etc/Wireless/RT2870AP/RT2870AP.dat"
|
||
|
||
SSIDLine=`cat $APFile | grep ^SSID= -n | cut -d : -f 1`
|
||
#SSID=`cat $APFile | grep ^SSID= -n | cut -d : -f 2`
|
||
|
||
#SSID="SSID=IPCAM-AP-"$P2P_ID
|
||
SSID="SSID=$APSSID"
|
||
show_info "AP SSID=$APSSID"
|
||
sed "${SSIDLine}s/^.*$/$SSID/" $APFile > $TmpFile
|
||
|
||
if [ -e $APFileLink ]
|
||
then
|
||
echo "$APFileLink Exist"
|
||
if [ ! -L $APFileLink ]
|
||
then
|
||
echo "$APFileLink Exist. not link"
|
||
rm -f $APFileLink
|
||
ln -s $TmpFile $APFileLink
|
||
fi
|
||
else
|
||
echo "$APFileLink Not Exist"
|
||
ln -s $TmpFile $APFileLink
|
||
fi
|
||
}
|
||
|
||
ap_name_set_8189()
|
||
{
|
||
show_func "ap_name_set_8189 apname = $1"
|
||
APSSID=$1
|
||
APFile="/etc/network/wifi8189ap.conf"
|
||
|
||
SSID="SSID=$APSSID"
|
||
|
||
echo $SSID > $APFile
|
||
|
||
}
|
||
|
||
ap_ssid_update()
|
||
{
|
||
#####get_ap_ssid在ap_ssid.sh实现
|
||
APSSID=$(get_ap_ssid)
|
||
if [ $APSSID"A" = "null""A" ];then ###未烧录UID显示,默认前缀
|
||
APSSID="IPCAM"
|
||
fi
|
||
|
||
#根据wifi类型区分设置
|
||
#wifi_module_type=`/bin/vslocal/cgi-bin/getwifimoduletype.sh`
|
||
if [ $wifi_module_type == "7601" ]
|
||
then
|
||
ap_name_set_7601 $APSSID
|
||
elif [ $wifi_module_type == "8189" ]
|
||
then
|
||
ap_name_set_8189 $APSSID
|
||
else
|
||
show_info "unknow wifi_module_type $wifi_module_type"
|
||
fi
|
||
|
||
}
|
||
|
||
wifi_ap_start()
|
||
{
|
||
###AP模式下反复进入时得先stop
|
||
wifiM=`cat /tmpfs/wifimode`
|
||
if [ $wifiM == "AP" ];then
|
||
wifi_ap_stop
|
||
fi
|
||
show_func "wifi_ap_start"
|
||
wifiko_ap load
|
||
wifi_setmode "AP"
|
||
|
||
#声音播放去掉
|
||
#wifi_audio_to_ap
|
||
|
||
# 二维码扫描去掉
|
||
#if [ $customernum != "123" ];then
|
||
# /bin/vslocal/cgi-bin/netqrcodescan.sh &
|
||
#fi
|
||
}
|
||
|
||
wifi_ap_stop()
|
||
{
|
||
sleep 3
|
||
show_func "wifi_ap_stop"
|
||
killall -9 hostapd
|
||
#ifconfig $wifidev down
|
||
net_down $wifidev
|
||
wifiko_ap unload
|
||
wifi_setmode NONE
|
||
killall netqrcodescan.sh
|
||
}
|
||
|
||
### 加载STA
|
||
wifi_sta_start()
|
||
{
|
||
killall -9 wpa_supplicant
|
||
killall -9 hostapd
|
||
show_func "wifi_sta_start"
|
||
wifiko load
|
||
wifi_setmode "STA"
|
||
|
||
wpa_supplicant -B -d -D$wpa_driver -i $wifidev -c $wpa_config >$tmpfs_path/wifi.connect 2>&1
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
echo "wifimac=`cat /sys/class/net/${wifidev}/address`" > $mac_wifi_file
|
||
}
|
||
|
||
|
||
wifi_sta_stop()
|
||
{
|
||
show_func "wifi_sta_stop"
|
||
killall -9 wpa_supplicant
|
||
#ifconfig $wifidev down
|
||
net_down $wifidev
|
||
wifiko unload
|
||
wifi_setmode NONE
|
||
}
|
||
|
||
wifi_fixnet_start()
|
||
{
|
||
show_func "wifi_fixnet_start"
|
||
wifiko load
|
||
wifi_setmode "FIXNET"
|
||
sleep 1
|
||
wpa_supplicant -B -d -D$wpa_driver -i $wifidev -c $fixnet_config >$tmpfs_path/wifi.connect 2>&1
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
}
|
||
|
||
|
||
wifi_fixnet_stop()
|
||
{
|
||
show_func "wifi_fixnet_stop"
|
||
killall -9 wpa_supplicant
|
||
#ifconfig $wifidev down
|
||
net_down $wifidev
|
||
wifiko unload
|
||
wifi_setmode NONE
|
||
}
|
||
|
||
### 加载smart link
|
||
wifi_smtcn_start()
|
||
{
|
||
show_func "wifi_smtcn_start"
|
||
# wifiko load
|
||
wifi_setmode "SMTCN"
|
||
|
||
# sleep 3
|
||
smtcn_node=`get_smtcn_node`
|
||
show_func "smtcn_node:"$smtcn_node
|
||
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
|
||
##iwpriv $wifidev elian start
|
||
|
||
if [ -e $smtcn_node ];then
|
||
echo "stop" > $smtcn_node
|
||
# echo "clear" > $smtcn_node
|
||
echo "start" > $smtcn_node
|
||
else
|
||
show_error "Not support SMARTLINK"
|
||
fi
|
||
###/bin/vslocal/cgi-bin/netqrcodescan.sh &
|
||
}
|
||
|
||
|
||
wifi_smtcn_stop()
|
||
{
|
||
show_func "wifi_smtcn_stop"
|
||
smtcn_node=`get_smtcn_node`
|
||
|
||
if [ -e $smtcn_node ];then
|
||
echo "stop" > $smtcn_node
|
||
fi
|
||
####iwpriv $wifidev elian stop
|
||
###BTTODO. check it need??
|
||
wifiko unload
|
||
wifi_setmode NONE
|
||
killall netqrcodescan.sh
|
||
}
|
||
|
||
wifi_fatcn_stop()
|
||
{
|
||
show_func "wifi_fatcn_stop"
|
||
if [ -e /tmpfs/fastlink.conf ];then
|
||
rm /tmpfs/fastlink.conf -rf
|
||
fi
|
||
|
||
killall fastlink
|
||
}
|
||
###BTTODO, start with wpa_cli
|
||
wifi_wps_start()
|
||
{
|
||
show_func "wifi_wps_start"
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
wpa_cli -i $wifidev remove_network 0
|
||
wpa_cli -i $wifidev remove_network 1
|
||
wpa_cli -i $wifidev wps_pbc
|
||
}
|
||
|
||
###wifi_stop()
|
||
###{
|
||
### #ifconfig $wifidev 0.0.0.0
|
||
### net_off $wifidev
|
||
###}
|
||
###
|
||
wifi_stopall()
|
||
{
|
||
show_dbg2 "wifi_stop all"
|
||
wifi_sta_stop
|
||
wifi_ap_stop
|
||
wifi_smtcn_stop
|
||
}
|
||
|
||
|
||
wifi_wpsOK()
|
||
{
|
||
wpa_cli -i $wifidev status > $tmpfs_path/wifistatus.$$
|
||
chmod +x $tmpfs_path/wifistatus.$$
|
||
###. $tmpfs_path/wifistatus.$$ ###这个是以前老的获取ssid的方式现在屏蔽
|
||
|
||
wpa_cli save_config
|
||
###目前测试发现wps只有使用WPA加密NONE才能使用,wps连接成功后会在/tmpfs/下生产一个wpa_supp.conf文件
|
||
###以前方式取ssid会因为带空格获取不到完整的ssid字符串,现在将ssid截图加双引号写入文件再获取才能获取到完整的带空格的字符串
|
||
|
||
ssidtmp="`cat $tmpfs_path/wifistatus.$$ | grep ssid= | sed '1d,$d' | cut -d "=" -f2`"
|
||
keytmp=`cat /tmpfs/wpa_supp.conf | grep "psk=" | cut -d "=" -f2`
|
||
|
||
echo "ssid_tmp=\"${ssidtmp}\"" >> /tmpfs/wifi_tmp
|
||
echo "key_tmp=${keytmp}" >> /tmpfs/wifi_tmp
|
||
. /tmpfs/wifi_tmp
|
||
|
||
wifiessid=$ssid_tmp
|
||
wifikeytype=3
|
||
wifikey=$key_tmp
|
||
|
||
#wifi_sta_save_info "${wifiessid}" "${wifikey}" ${wifikeytype}
|
||
rm /tmpfs/wifi_tmp
|
||
|
||
#ssid get from wifistatus.$$
|
||
#wifiessid=$ssid
|
||
#wifiwhichkey=
|
||
#wifikeytype=
|
||
#wifikeyold=
|
||
#wifikey=
|
||
#enable=1
|
||
cat $wifidev_config > $wifi_config_tmp
|
||
echo "wifidev=\"${wifidev}\"" >> $wifi_config_tmp
|
||
echo "wifienable=\"${enable}\"" >> $wifi_config_tmp
|
||
echo "wifiessid=${wifiessid}" >> $wifi_config_tmp
|
||
echo "wifikeytype=$wifikeytype" >> $wifi_config_tmp
|
||
echo "wifiwhichkey=$wifiwhichkey" >> $wifi_config_tmp
|
||
echo "wifikey=\"$wifikey\"" >> $wifi_config_tmp
|
||
|
||
rm -f $wifi_config
|
||
cp -f $wifi_config_tmp $wifi_config
|
||
## when WPS, default dhcp
|
||
setinetattr.cgi "cmd=aa&-dhcp=on&-dnsstat=1"
|
||
sync
|
||
}
|
||
|
||
|
||
SMTCN_TLV_TYPE=""
|
||
SMTCN_TLV_LENGHT=""
|
||
SMTCN_TLV_VALUE=""
|
||
|
||
get_tlv_value()
|
||
{
|
||
TLV_HEX=$1
|
||
SMTCN_TLV_TYPE=""
|
||
SMTCN_TLV_LENGHT=""
|
||
SMTCN_TLV_VALUE=""
|
||
|
||
SMTCN_TLV_TYPE=`echo $TLV_HEX | cut -f1 -d-`
|
||
LENGHT1=`echo $TLV_HEX | cut -f2 -d-`
|
||
SMTCN_TLV_LENGHT=`printf "%d" "0x"$LENGHT1`
|
||
|
||
if [ $SMTCN_TLV_LENGHT == "2" ];then
|
||
return ;
|
||
fi
|
||
|
||
RepeatCnt=3
|
||
while [ 1 ]
|
||
do
|
||
if [ $RepeatCnt -gt $SMTCN_TLV_LENGHT ];then
|
||
break
|
||
fi
|
||
|
||
TLV_VALUE="0x"`echo $TLV_HEX | cut -f$RepeatCnt -d-`
|
||
SMTCN_TLV_VALUE=$SMTCN_TLV_VALUE`echo $TLV_VALUE | num2char `
|
||
RepeatCnt=$(( $RepeatCnt + 1 ))
|
||
|
||
done
|
||
}
|
||
|
||
GET_SMTCN_WKTYPE()
|
||
{
|
||
SMTCN_SSID=$1
|
||
SMTCN_WKTYPE="3"
|
||
SMTCN_SSID_LEN="${#SMTCN_SSID}"
|
||
|
||
echo "3" > /tmpfs/smtcn_wktype
|
||
|
||
cat $wifiscanresult | while read line
|
||
do
|
||
RESULT_SSID=`echo $line | grep "\<${SMTCN_SSID}\>" | awk '{print $5}'`
|
||
if [ "A""${RESULT_SSID}" == "A" ]
|
||
then
|
||
continue
|
||
fi
|
||
|
||
RESULT_SSID_LEN="${#RESULT_SSID}"
|
||
|
||
if [ "$SMTCN_SSID_LEN" == "$RESULT_SSID_LEN" ]
|
||
then
|
||
RESULT_WKTYPE=`echo $line | awk '{print $4}' | grep WPA`
|
||
if [ ! -z $RESULT_WKTYPE ];then
|
||
####wpa
|
||
SMTCN_WKTYPE="3"
|
||
echo "3" > /tmpfs/smtcn_wktype
|
||
else
|
||
RESULT_WKTYPE=`echo $line | awk '{print $4}' | grep [ESS]`
|
||
if [ ! -z $RESULT_WKTYPE ] && [ $RESULT_WKTYPE == "[ESS]" ];then
|
||
####no password
|
||
SMTCN_WKTYPE="1"
|
||
echo "1" > /tmpfs/smtcn_wktype
|
||
else
|
||
####wep
|
||
SMTCN_WKTYPE="2"
|
||
echo "2" > /tmpfs/smtcn_wktype
|
||
fi
|
||
fi
|
||
break;
|
||
fi
|
||
done
|
||
|
||
cat /tmpfs/smtcn_wktype
|
||
|
||
rm /tmpfs/smtcn_wktype -rf > /dev/null
|
||
}
|
||
|
||
|
||
wifi_smtcnOK()
|
||
{
|
||
smtcn_node=`get_smtcn_node`
|
||
|
||
if [ ! -e $smtcn_node ];then
|
||
return "1";
|
||
fi
|
||
|
||
cat $smtcn_node
|
||
|
||
SMTCN_SSID=`cat $smtcn_node | awk -F ", " '{printf $2}' | awk -F "=" '{printf $2}'`
|
||
SMTCN_PASSWORD=`cat $smtcn_node | awk -F ", " '{printf $3}' | awk -F "=" '{printf $2}'`
|
||
####SMTCN_AUTHMODE=`cat $smtcn_node | grep AUTHMODE | awk -F ": " '{printf $2}'`
|
||
SMTCN_TLV_HEX=`cat $smtcn_node | grep TLV_HEX | awk -F ": " '{printf $2}'`
|
||
|
||
# if [ -z $SMTCN_TLV_HEX ];then
|
||
# show_info "SMTCN_TLV_VALUE not set $smtcn_chk!!!!!!!!!!!"
|
||
# return "1";
|
||
# fi
|
||
#
|
||
# get_tlv_value $SMTCN_TLV_HEX
|
||
# show_info "TLV_HEX:"$SMTCN_TLV_HEX" SMTCN_TLV_TYPE:"$SMTCN_TLV_TYPE" SMTCN_TLV_LENGHT:"$SMTCN_TLV_LENGHT" SMTCN_TLV_VALUE:"$SMTCN_TLV_VALUE
|
||
#
|
||
# if [ -z $SMTCN_TLV_VALUE ];then
|
||
# show_info "SMTCN_TLV_VALUE not set $smtcn_chk!!!!!!!!!!!"
|
||
# return "1";
|
||
# fi
|
||
|
||
. $wifi_config
|
||
|
||
# if [ -z $smtcn_chk ];then
|
||
# smtcn_chk="RUNTOP"
|
||
# fi
|
||
#
|
||
# show_info "smtcn_chk:"$smtcn_chk" SMTCN_TLV_VALUE:"$SMTCN_TLV_VALUE
|
||
#
|
||
# if [ $SMTCN_TLV_VALUE != $smtcn_chk ];then
|
||
# show_info "SMTCN_TLV_VALUE not set $smtcn_chk!!!!!!!!!!!"
|
||
# return "1";
|
||
# fi
|
||
|
||
|
||
|
||
####根据之前搜索到wifi列表,找出SSID对应的加密类型
|
||
# SMTCN_WKTYPE="3"
|
||
# RESULT_SSID=`cat $wifiscanresult | grep "\<${SMTCN_SSID}\>" | cut -f5`
|
||
# if [ "${RESULT_SSID}""A" != "A" ];then
|
||
# RESULT_WKTYPE=`cat $wifiscanresult | grep "${SMTCN_SSID}" | cut -f4 | grep WPA`
|
||
# if [ ! -z $RESULT_WKTYPE ];then
|
||
# ####wpa
|
||
# SMTCN_WKTYPE="3"
|
||
# else
|
||
# RESULT_WKTYPE=`cat $wifiscanresult | grep "${SMTCN_SSID}" | cut -f4 | grep [ESS]`
|
||
# if [ ! -z $RESULT_WKTYPE ] && [ $RESULT_WKTYPE == "[ESS]" ];then
|
||
# ####no password
|
||
# SMTCN_WKTYPE="1"
|
||
# else
|
||
# ####wep
|
||
# SMTCN_WKTYPE="2"
|
||
# fi
|
||
# fi
|
||
# fi
|
||
SMTCN_WKTYPE=`GET_SMTCN_WKTYPE "$SMTCN_SSID"`
|
||
show_info "SSID:"$SMTCN_SSID" PASSWORD:"$SMTCN_PASSWORD" WKTYPE:"$SMTCN_WKTYPE
|
||
wifi_sta_save_info "${SMTCN_SSID}" "${SMTCN_PASSWORD}" ${SMTCN_WKTYPE}
|
||
|
||
#cat $wifidev_config > $wifi_config_tmp
|
||
#cat $wifidev_config > $wifi_config_tmp
|
||
#echo "wifidev=\"${wifidev}\"" >> $wifi_config_tmp
|
||
#echo "wifienable=\"1\"" >> $wifi_config_tmp
|
||
#echo "wifiessid=\"${SMTCN_SSID}\"" >> $wifi_config_tmp
|
||
#echo "wifikeytype=${SMTCN_WKTYPE}" >> $wifi_config_tmp
|
||
#echo "wifiwhichkey=$wifiwhichkey" >> $wifi_config_tmp
|
||
#echo "wifikey=\"${SMTCN_PASSWORD}\"" >> $wifi_config_tmp
|
||
#
|
||
#cat $wifi_config_tmp > $wifi_config
|
||
#gen_wpa_config "${SMTCN_SSID}" $SMTCN_WKTYPE $wifiwhichkey "${SMTCN_PASSWORD}" $wpa_config_tmp
|
||
#
|
||
#cp -f $wpa_config_tmp $wpa_config
|
||
wifi_smtcn_stop
|
||
|
||
return "0"
|
||
}
|
||
|
||
|
||
wifi_voiceOK()
|
||
{
|
||
if [ ! -e /tmpfs/voice_wifi ];then
|
||
return "1";
|
||
fi
|
||
|
||
cat /tmpfs/voice_wifi
|
||
|
||
SMTCN_SSID=`cat /tmpfs/voice_wifi | grep SSID | awk -F ": " '{printf $2}'`
|
||
SMTCN_PASSWORD=`cat /tmpfs/voice_wifi | grep PASSWORD | awk -F ": " '{printf $2}'`
|
||
####SMTCN_AUTHMODE=`cat /tmpfs/voice_wifi | grep AUTHMODE | awk -F ": " '{printf $2}'`
|
||
SMTCN_TLV_HEX=`cat /tmpfs/voice_wifi | grep TLV_HEX | awk -F ": " '{printf $2}'`
|
||
|
||
# if [ -z $SMTCN_TLV_HEX ];then
|
||
# show_info "SMTCN_TLV_VALUE not set $smtcn_chk!!!!!!!!!!!"
|
||
# return "1";
|
||
# fi
|
||
#
|
||
# get_tlv_value $SMTCN_TLV_HEX
|
||
# show_info "TLV_HEX:"$SMTCN_TLV_HEX" SMTCN_TLV_TYPE:"$SMTCN_TLV_TYPE" SMTCN_TLV_LENGHT:"$SMTCN_TLV_LENGHT" SMTCN_TLV_VALUE:"$SMTCN_TLV_VALUE
|
||
#
|
||
# if [ -z $SMTCN_TLV_VALUE ];then
|
||
# show_info "SMTCN_TLV_VALUE not set $smtcn_chk!!!!!!!!!!!"
|
||
# return "1";
|
||
# fi
|
||
|
||
. $wifi_config
|
||
|
||
# if [ -z $smtcn_chk ];then
|
||
# smtcn_chk="RUNTOP"
|
||
# fi
|
||
#
|
||
# show_info "smtcn_chk:"$smtcn_chk" SMTCN_TLV_VALUE:"$SMTCN_TLV_VALUE
|
||
#
|
||
# if [ $SMTCN_TLV_VALUE != $smtcn_chk ];then
|
||
# show_info "SMTCN_TLV_VALUE not set $smtcn_chk!!!!!!!!!!!"
|
||
# return "1";
|
||
# fi
|
||
|
||
|
||
|
||
####根据之前搜索到wifi列表,找出SSID对应的加密类型
|
||
# SMTCN_WKTYPE="3"
|
||
# RESULT_SSID=`cat $wifiscanresult | grep "\<${SMTCN_SSID}\>" | cut -f5`
|
||
# if [ "${RESULT_SSID}""A" != "A" ];then
|
||
# RESULT_WKTYPE=`cat $wifiscanresult | grep "${SMTCN_SSID}" | cut -f4 | grep WPA`
|
||
# if [ ! -z $RESULT_WKTYPE ];then
|
||
# ####wpa
|
||
# SMTCN_WKTYPE="3"
|
||
# else
|
||
# RESULT_WKTYPE=`cat $wifiscanresult | grep "${SMTCN_SSID}" | cut -f4 | grep [ESS]`
|
||
# if [ ! -z $RESULT_WKTYPE ] && [ $RESULT_WKTYPE == "[ESS]" ];then
|
||
# ####no password
|
||
# SMTCN_WKTYPE="1"
|
||
# else
|
||
# ####wep
|
||
# SMTCN_WKTYPE="2"
|
||
# fi
|
||
# fi
|
||
# fi
|
||
SMTCN_WKTYPE=`GET_SMTCN_WKTYPE "$SMTCN_SSID"`
|
||
show_info "SSID:"$SMTCN_SSID" PASSWORD:"$SMTCN_PASSWORD" WKTYPE:"$SMTCN_WKTYPE
|
||
wifi_sta_save_info "${SMTCN_SSID}" "${SMTCN_PASSWORD}" ${SMTCN_WKTYPE}
|
||
|
||
#cat $wifidev_config > $wifi_config_tmp
|
||
#cat $wifidev_config > $wifi_config_tmp
|
||
#echo "wifidev=\"${wifidev}\"" >> $wifi_config_tmp
|
||
#echo "wifienable=\"1\"" >> $wifi_config_tmp
|
||
#echo "wifiessid=\"${SMTCN_SSID}\"" >> $wifi_config_tmp
|
||
#echo "wifikeytype=${SMTCN_WKTYPE}" >> $wifi_config_tmp
|
||
#echo "wifiwhichkey=$wifiwhichkey" >> $wifi_config_tmp
|
||
#echo "wifikey=\"${SMTCN_PASSWORD}\"" >> $wifi_config_tmp
|
||
#
|
||
#cat $wifi_config_tmp > $wifi_config
|
||
#gen_wpa_config "${SMTCN_SSID}" $SMTCN_WKTYPE $wifiwhichkey "${SMTCN_PASSWORD}" $wpa_config_tmp
|
||
#
|
||
#cp -f $wpa_config_tmp $wpa_config
|
||
#rm /tmpfs/voice_wifi
|
||
|
||
return "0"
|
||
}
|
||
|
||
wifi_fatcnOK()
|
||
{
|
||
if [ ! -e /tmpfs/fastlink.conf ];then
|
||
return ;
|
||
fi
|
||
|
||
FATCN_SSID=`cat /tmpfs/fastlink.conf | grep SSID | awk -F ": " '{printf $2}'`
|
||
FATCN_PASSWORD=`cat /tmpfs/fastlink.conf | grep PASSWORD | awk -F ": " '{printf $2}'`
|
||
FATCN_AUTHMODE=`cat /tmpfs/fastlink.conf | grep AUTHMODE | awk -F ": " '{printf $2}'`
|
||
|
||
if [ $FATCN_AUTHMODE == "0" ];then
|
||
########no password
|
||
FATCN_WKTYPE="1"
|
||
elif [ $FATCN_AUTHMODE == "1" ]||[ $FATCN_AUTHMODE == "1" ];then
|
||
########wep
|
||
FATCN_WKTYPE="2"
|
||
else
|
||
########wpa
|
||
FATCN_WKTYPE="3"
|
||
fi
|
||
|
||
show_info "SSID:"$FATCN_SSID" PASSWORD:"$FATCN_PASSWORD" WKTYPE:"$FATCN_WKTYPE
|
||
wifi_sta_save_info ${FATCN_SSID} ${FATCN_PASSWORD} ${FATCN_WKTYPE}
|
||
|
||
#. $wifi_config
|
||
#
|
||
#cat $wifidev_config > $wifi_config_tmp
|
||
#cat $wifidev_config > $wifi_config_tmp
|
||
#echo "wifidev=\"${wifidev}\"" >> $wifi_config_tmp
|
||
#echo "wifienable=\"1\"" >> $wifi_config_tmp
|
||
#echo "wifiessid=\"${FATCN_SSID}\"" >> $wifi_config_tmp
|
||
#echo "wifikeytype=${FATCN_WKTYPE}" >> $wifi_config_tmp
|
||
#echo "wifiwhichkey=$wifiwhichkey" >> $wifi_config_tmp
|
||
#echo "wifikey=\"${FATCN_PASSWORD}\"" >> $wifi_config_tmp
|
||
#
|
||
#cat $wifi_config_tmp > $wifi_config
|
||
#
|
||
#gen_wpa_config $FATCN_SSID $FATCN_WKTYPE $wifiwhichkey $FATCN_PASSWORD $wpa_config_tmp
|
||
#cp -f $wpa_config_tmp $wpa_config
|
||
}
|
||
|
||
wifi_fixnetOK()
|
||
{
|
||
if [ ! -e $fixnet_config ];then
|
||
return ;
|
||
fi
|
||
|
||
FIXNET_SSID=`cat $fixnet_config | grep "ssid=\"" | awk -F "\"" '{print $2}'`
|
||
FIXNET_PASSWORD=`cat $fixnet_config | grep "#psk" | awk -F "\"" '{print $2}'`
|
||
FIXNET_WKTYPE="3"
|
||
|
||
show_info "SSID:"$FIXNET_SSID" PASSWORD:"$FIXNET_PASSWORD" WKTYPE:"$FIXNET_WKTYPE
|
||
|
||
. $wifi_config
|
||
|
||
cat $wifidev_config > $wifi_config_tmp
|
||
cat $wifidev_config > $wifi_config_tmp
|
||
echo "wifidev=\"${wifidev}\"" >> $wifi_config_tmp
|
||
echo "wifienable=\"1\"" >> $wifi_config_tmp
|
||
echo "wifiessid=\"${FIXNET_SSID}\"" >> $wifi_config_tmp
|
||
echo "wifikeytype=${FIXNET_WKTYPE}" >> $wifi_config_tmp
|
||
echo "wifiwhichkey=$wifiwhichkey" >> $wifi_config_tmp
|
||
echo "wifikey=\"${FIXNET_PASSWORD}\"" >> $wifi_config_tmp
|
||
|
||
cat $wifi_config_tmp > $wifi_config
|
||
}
|
||
|
||
|
||
####BTTODO, Get From config file
|
||
wifi_audio_connectsuccess()
|
||
{
|
||
return
|
||
# CustomNum=`cat /mnt/config/ipcamera/config_devm.ini | grep customernum= -m1 | cut -d = -f 2 `
|
||
if [ ! -z $CustomNum ] && [ $CustomNum == "47" ] || [ $CustomNum == "123" ] || [ $CustomNum == "44" ];#256044a-qks-mw7 不要任何提示音
|
||
then
|
||
return ;
|
||
fi
|
||
|
||
if [ ! -e /bin/vs/media/connectsuccess.g711a ]
|
||
then
|
||
show_error "Have no connectsuccess audio"
|
||
return
|
||
else
|
||
wget -O /tmpfs/wifiaudio.log "http://127.0.0.1/web/cgi-bin/hi3510/playaudio.cgi?&-playstate=1&-playfile=connectsuccess"
|
||
fi
|
||
|
||
}
|
||
####BTTODO, Get From config file
|
||
wifi_audio_connecting()
|
||
{
|
||
return
|
||
# CustomNum=`cat /mnt/config/ipcamera/config_devm.ini | grep customernum= -m1 | cut -d = -f 2 `
|
||
###hdx 225056客户要求摄像头开机无wifi声音提示
|
||
if [ ! -z $CustomNum ] && [ $CustomNum == "56" ] || [ $CustomNum == "47" ] || [ $CustomNum == "123" ] || [ $CustomNum == "44" ];
|
||
then
|
||
return ;
|
||
fi
|
||
|
||
if [ ! -e /bin/vs/media/connecting.g711a ]
|
||
then
|
||
show_error "Have no connecting audio"
|
||
return
|
||
else
|
||
wget -O /tmpfs/wifiaudio.log "http://127.0.0.1/web/cgi-bin/hi3510/playaudio.cgi?&-playstate=1&-playfile=connecting"
|
||
fi
|
||
|
||
}
|
||
####BTTODO, Get From config file
|
||
wifi_audio_connectfailure()
|
||
{
|
||
return
|
||
# CustomNum=`cat /mnt/config/ipcamera/config_devm.ini | grep customernum= -m1 | cut -d = -f 2 `
|
||
###hdx 225056客户要求摄像头开机无wifi声音提示
|
||
if [ ! -z $CustomNum ] && [ $CustomNum == "56" ] || [ $CustomNum == "123" ] || [ $CustomNum == "44" ];
|
||
then
|
||
return ;
|
||
fi
|
||
|
||
if [ ! -e /bin/vs/media/connectfailure.g711a ]
|
||
then
|
||
show_error "Have no connectfailure audio"
|
||
return
|
||
else
|
||
wget -O /tmpfs/wifiaudio.log "http://127.0.0.1/web/cgi-bin/hi3510/playaudio.cgi?&-playstate=1&-playfile=connectfailure"
|
||
fi
|
||
|
||
}
|
||
####BTTODO, Get From config file
|
||
wifi_audio_waitconnect()
|
||
{
|
||
return
|
||
# CustomNum=`cat /mnt/config/ipcamera/config_devm.ini | grep customernum= -m1 | cut -d = -f 2 `
|
||
###hdx 225056客户要求摄像头开机无wifi声音提示
|
||
if [ ! -z $CustomNum ] && [ $CustomNum == "56" ] || [ $CustomNum == "47" ] || [ $CustomNum == "123" ] || [ $CustomNum == "44" ];
|
||
then
|
||
return ;
|
||
fi
|
||
|
||
if [ ! -e /bin/vs/media/waitconnect.g711a ]
|
||
then
|
||
show_error "Have no waitconnect audio"
|
||
return
|
||
else
|
||
wget -O /tmpfs/wifiaudio.log "http://127.0.0.1/web/cgi-bin/hi3510/playaudio.cgi?&-playstate=1&-playfile=waitconnect"
|
||
fi
|
||
}
|
||
####BTTODO, Get From config file
|
||
wifi_audio_to_ap()
|
||
{
|
||
return
|
||
# CustomNum=`cat /mnt/config/ipcamera/config_devm.ini | grep customernum= -m1 | cut -d = -f 2 `
|
||
. $wifi_config
|
||
###hdx 225056客户要求摄像头开机无wifi声音提示
|
||
if [ ! -z $CustomNum ] && [ $CustomNum == "56" ] || [ $CustomNum == "123" ] || [ $CustomNum == "44" ];
|
||
then
|
||
return ;
|
||
fi
|
||
|
||
if [ ! -e /bin/vs/media/toap.g711a ]
|
||
then
|
||
show_error "Have no to_ap audio"
|
||
return
|
||
else
|
||
wget -O /tmpfs/wifiaudio.log "http://127.0.0.1/web/cgi-bin/hi3510/playaudio.cgi?&-playstate=1&-playfile=toap"
|
||
fi
|
||
}
|
||
|
||
#$1, 切换模式
|
||
#$2, 是否强制切换, 如果不输入, 默认为强制
|
||
|
||
wifi_modeswitch()
|
||
{
|
||
|
||
if [ -z $1 ]
|
||
then
|
||
wifimode_new=NONE
|
||
else
|
||
wifimode_new=$1
|
||
fi
|
||
|
||
if [ -z $2 ]
|
||
then
|
||
force=Y
|
||
else
|
||
force=$2
|
||
fi
|
||
|
||
show_dbg "CurrWifiMode $wifimode_curr switchto $wifimode_new, isforce:$force"
|
||
|
||
if [ $wifimode_new == $wifimode_curr -a $force = N ]
|
||
then
|
||
show_dbg "same wifimode and not force, do nothing"
|
||
return
|
||
fi
|
||
|
||
###BTTODO Why
|
||
|
||
if [ $wifimode_new == "LINED" ]
|
||
then
|
||
show_info "Enter LINED Mode"
|
||
if [ $wifimode_curr == "AP" ]
|
||
then
|
||
wifi_ap_stop
|
||
killall -9 udhcpd 2>/dev/null
|
||
killall -9 dnsd 2>/dev/null
|
||
elif [ $wifimode_curr == "SMTCN" ]
|
||
then
|
||
wifi_smtcn_stop
|
||
elif [ $wifimode_curr == "FATCN" ]
|
||
then
|
||
wifi_fatcn_stop
|
||
fi
|
||
|
||
wifi_setmode "NONE"
|
||
wifi_setstate "NONE"
|
||
|
||
elif [ $wifimode_new == "AP" ]
|
||
then
|
||
show_info "Enter AP Mode"
|
||
ap_ssid_update
|
||
if [ $wifimode_curr == "STA" ]
|
||
then
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
wifi_scan
|
||
wifi_sta_stop
|
||
elif [ $wifimode_curr == "FIXNET" ]
|
||
then
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
wifi_scan
|
||
wifi_fixnet_stop
|
||
elif [ $wifimode_curr == "AP" ]
|
||
then
|
||
show_info "Now is AP"
|
||
elif [ $wifimode_curr == "SMTCN" ]
|
||
then
|
||
wifi_smtcn_stop
|
||
wifi_sta_start
|
||
wifi_scan
|
||
wifi_sta_stop
|
||
elif [ $wifimode_curr == "FATCN" ]
|
||
then
|
||
wifi_fatcn_stop
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
wifi_scan
|
||
wifi_sta_stop
|
||
else
|
||
#wifi_sta_start
|
||
#wifi_scan
|
||
#wifi_sta_stop
|
||
show_info "Enter AP Mode"
|
||
fi
|
||
wifi_ap_start
|
||
wifi_ap_ipcfg
|
||
wifi_setmode "AP"
|
||
|
||
|
||
elif [ $wifimode_new == "STA" ]
|
||
then
|
||
show_info "Enter STA Mode"
|
||
rm $wifiscanresult -f 2>/dev/null
|
||
if [ $wifimode_curr == "AP" ]
|
||
then
|
||
wifi_ap_stop
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "NONE" ]
|
||
then
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "SMTCN" ]
|
||
then
|
||
wifi_smtcn_stop
|
||
elif [ $wifimode_curr == "FATCN" ]
|
||
then
|
||
wifi_fatcn_stop
|
||
elif [ $wifimode_curr == "FIXNET" ]
|
||
then
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "STA" ]
|
||
then
|
||
wifi_sta_connect
|
||
fi
|
||
|
||
#elif [ $wifimode_curr == "WPS" ]
|
||
#then
|
||
# wpa_cli -i $wifidev reconfig
|
||
#fi
|
||
wifi_setmode "STA"
|
||
#wifi_sta_connect
|
||
wifi_setstate STA_CONNECTING
|
||
elif [ $wifimode_new == "WPS" ]
|
||
then
|
||
show_info "enter WPS mode"
|
||
|
||
if [ $wifimode_curr == "AP" ]
|
||
then
|
||
wifi_ap_stop
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "NONE" ]
|
||
then
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "SMTCN" ]
|
||
then
|
||
wifi_smtcn_stop
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "FATCN" ]
|
||
then
|
||
wifi_fatcn_stop
|
||
fi
|
||
|
||
wifi_wps_start
|
||
#wpa_cli -i $wifidev remove_network 0
|
||
#wpa_cli -i $wifidev remove_network 1
|
||
#wpa_cli -i $wifidev wps_pbc
|
||
|
||
wifi_setmode WPS
|
||
wifi_setstate WPS_CONNECTING
|
||
|
||
elif [ $wifimode_new == "SMTCN" ]
|
||
then
|
||
if [ $wifimode_curr == "SMTCN" ]
|
||
then
|
||
show_info "Now is SMTCN Mode"
|
||
return ;
|
||
fi
|
||
|
||
if [ $wifimode_curr == "STA" ]
|
||
then
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
elif [ $wifimode_curr == "FIXNET" ]
|
||
then
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
elif [ $wifimode_curr == "AP" ]
|
||
then
|
||
wifi_ap_stop
|
||
wifi_sta_start
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
elif [ $wifimode_curr == "FATCN" ]
|
||
then
|
||
wifi_fatcn_stop
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
elif [ $wifimode_curr == "NONE" ]
|
||
then
|
||
wifi_sta_start
|
||
#ifconfig $wifidev up
|
||
net_up $wifidev
|
||
fi
|
||
|
||
show_info "Enter SMTCN Mode"
|
||
wifi_scan
|
||
## wifi_stopall
|
||
## sleep 1
|
||
|
||
wifi_setmode "SMTCN"
|
||
wifi_smtcn_start
|
||
wifi_setstate SMTCN_CONNECTING
|
||
|
||
wifi_audio_waitconnect
|
||
sleep 3; enter_voice_cfg_wifi_mode.sh
|
||
|
||
elif [ $wifimode_new == "FATCN" ]
|
||
then
|
||
show_info "Enter FATCN Mode"
|
||
rm $wifiscanresult -f 2>/dev/null
|
||
if [ $wifimode_curr == "AP" ]
|
||
then
|
||
wifi_ap_stop
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "NONE" ]
|
||
then
|
||
wifi_sta_start
|
||
elif [ $wifimode_curr == "SMTCN" ]
|
||
then
|
||
wifi_smtcn_stop
|
||
wifi_sta_start
|
||
fi
|
||
|
||
killall fastlink
|
||
rm -rf /tmpfs/fastlink.conf
|
||
/bin/vslocal/cgi-bin/fastlink &
|
||
wifi_setmode "FATCN"
|
||
wifi_setstate FATCN_CONNECTING
|
||
wifi_audio_waitconnect
|
||
elif [ $wifimode_new == "FIXNET" ]
|
||
then
|
||
show_info "Enter FIXNET Mode"
|
||
rm $wifiscanresult -f 2>/dev/null
|
||
if [ $wifimode_curr == "AP" ]
|
||
then
|
||
wifi_ap_stop
|
||
wifi_fixnet_start
|
||
elif [ $wifimode_curr == "NONE" ]
|
||
then
|
||
wifi_fixnet_start
|
||
elif [ $wifimode_curr == "SMTCN" ]
|
||
then
|
||
wifi_smtcn_stop
|
||
elif [ $wifimode_curr == "FATCN" ]
|
||
then
|
||
wifi_fatcn_stop
|
||
fi
|
||
wifi_setmode "FIXNET"
|
||
wifi_fixnet_connect
|
||
wifi_setstate FIXNET_CONNECTING
|
||
elif [ $wifimode_new == "NONE" ]
|
||
then
|
||
wifi_ap_stop
|
||
wifi_sta_stop
|
||
wifi_smtcn_stop
|
||
wifi_setmode "NONE"
|
||
fi
|
||
|
||
}
|
||
|
||
|