找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 1595|回复: 4

qca9531wifi ap切换成sta

[复制链接]
发表于 2018-12-7 10:29 | 显示全部楼层 |阅读模式
自己写了个脚本,但是却发现,即使uci set了mode为sta,但是实际上并没有改变成sta,有没有知道是什么原因的?
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2018-12-7 10:31 | 显示全部楼层
#!/bin/sh

wpa_supplicant_conf="/var/run/wpa_supplicant-ath0.conf"

#check input arg
if [ $# -ne 3 ];then
    echo "Usage: $0 SSID PASSWORD ENCRYPTION_TYPE(WPA/WPA2/WPAMIX)"
    exit 0
fi

#debug:
echo "SSID=$1"
echo "PASSWD=$2"
echo "ENCRYPTION_TYPE=$3"

SCAN_SSID=" scan_ssid=1"
SSID="  ssid=\"$1\""
KEY_MGMT="  key_mgmt=WPA-PSK"

case  "$3"  in
    "WPA" )
    PROTO=" proto=WPA"
    PROTO_UCI="psk"
    ;;
   
    "WPA2" )
    PROTO=" proto=RSN"
    PROTO_UCI="psk2"
    ;;
   
    "WPAMIX" )
    PROTO=" proto=RSN WPA"
    PROTO_UCI="psk-mixed"
    ;;
esac

PSK="   psk=\"$2\""

#check file exist
if [ ! -f "$wpa_supplicant_conf" ]; then
    echo "$wpa_supplicant_conf is empty"
else
    #if file exist
    #1)modify wpa_supplicant-ath0.conf
    mv $wpa_supplicant_conf $wpa_supplicant_conf".old"
    touch $wpa_supplicant_conf
    echo "ctrl_interface=/var/run/wpa_supplicant-ath01" >> $wpa_supplicant_conf
    echo "network={" >> $wpa_supplicant_conf
    echo $SCAN_SSID >> $wpa_supplicant_conf
    echo $SSID >> $wpa_supplicant_conf
    echo $KEY_MGMT >> $wpa_supplicant_conf
    echo $PROTO >> $wpa_supplicant_conf
    echo $PSK >> $wpa_supplicant_conf
    echo "}" >> $wpa_supplicant_conf
   
   
    #2)restart wpa_supplicant process:wpa_supplicant -B -P /var/run/wifi-ath0.pid -D athr -i ath0 -c /var/run/wpa_supplicant-ath0.conf
    if [ -n "`ps |grep 'wpa_supplicant -B -P /var/run/wifi-ath0.pid'|grep -v 'grep'|awk '{print $1}'`" ]; then
        kill "$(cat "/var/run/wifi-ath0.pid")"
    fi
                  
    wpa_supplicant -B -P /var/run/wifi-ath0.pid -D athr -i ath0 -c /var/run/wpa_supplicant-ath0.conf &
   
   
    #3)kill the ath0 dhcp client, it will restart automatically by /lib/netifd/proto/dhcp.sh
    DHCPID=`ps |grep udhcpc-ath0|grep -v 'grep'|awk '{print $1}'`
    if [ ! -n "$DHCPID" ]; then
        echo "No udhcpc-ath0 process."
    else
        kill $DHCPID
    fi
   
   
    #4)update /etc/config/wireless
    for i in 0 1; do
        STA=`uci get wireless.@wifi-iface[$i].mode`
        
        
        if [ "sta" = $STA ]; then
            uci set wireless.@wifi-iface[$i].ssid=$1
            uci set wireless.@wifi-iface[$i].encryption=$PROTO_UCI
            uci set wireless.@wifi-iface[$i].key=$2
            uci commit wireless
            echo "uci commit over"
        fi
    done
fi                    
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2018-12-7 11:06 来自手机 | 显示全部楼层
因为你并没有重启 WiFi 服务

点评

奇怪的是,假如我只有ap的时候,是没有wpa_supplicant的守护进程,然而sta要连接ap好像需要认证,我猜可能是没有这个守护进程,所以验证不了,故即使uci set了mode,还是起不了作用  详情 回复 发表于 2018-12-7 11:14
bingo,但是我的网卡找不到驱动 = , = root@OpenWrt:~# wifi up phy for wifi device wifi0 not found wifi0(qcawifi): disable failed Configuration file: /var/run/hostapd-ath0.conf ath0: Could not conne  详情 回复 发表于 2018-12-7 11:10
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2018-12-7 11:10 | 显示全部楼层
LGA1150 发表于 2018-12-7 11:06
因为你并没有重启 WiFi 服务

bingo,但是我的网卡连接不到驱动 = , =
root@OpenWrt:~# wifi up
phy for wifi device wifi0 not found
wifi0(qcawifi): disable failed
Configuration file: /var/run/hostapd-ath0.conf
ath0: Could not connect to kernel driver
Using interface ath0 with hwaddr 78:a3:51:f0:00:f1 and ssid '9531juzi'
random: Only 17/20 bytes of strong random data available from /dev/random
random: Not enough entropy pool available for secure operations
WPA: Not enough entropy in random pool for secure operations - update keys later when the first station connects
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2018-12-7 11:14 | 显示全部楼层
本帖最后由 Zihol 于 2018-12-7 11:18 编辑
LGA1150 发表于 2018-12-7 11:06
因为你并没有重启 WiFi 服务

奇怪的是,假如我只有ap的时候,是没有wpa_supplicant的守护进程wpa_supplicant -B -P /var/run/wifi-ath0.pid -D athr -i ath0 -c /var/run/wpa_supplicant-ath0.conf ,然而sta要连接ap好像需要认证,我猜可能是没有这个守护进程,所以验证不了,故即使uci set了mode,还是起不了作用。所以说,要怎么解决?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-17 03:26

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表