求助 车机Linux3.X 重启后不保存WIFI账号和密码

惊天或微笑 2019-09-08 09:20:31
文件名:ama-wifi-operate.sh
#!/bin/sh
wpa_cli_cmd="/usr/sbin/wpa_cli -p/tmp/wlan0 -iwlan0"
chmod -R 777 /tmp/wlan0
scan_wifi()
{
echo enter scan_wifi function
$wpa_cli_cmd scan
$wpa_cli_cmd scan_results >/tmp/wifi_scan_results
echo exit scan_wifi function
exit 1
}

connect_wifi()
{
echo enter connect_wifi funtion
network_id=`$wpa_cli_cmd add_network`
#echo $network_id>/tmp/network_id
#passwd=`echo $2`
echo The connecting wifi ssid=$1 auth_type=$2 network_id=$network_id priority=$4
if [ "$2" = "1" ] || [ "$2" = "2" ] || [ "$2" = "3" ] ; then
$wpa_cli_cmd<<EOF
set_network $network_id ssid "$1"
set_network $network_id psk "$3"
set_network $network_id priority $4
set_network $network_id scan_ssid 1
select_network $network_id
quit
EOF
elif [ "$2" = "0" ] ; then
$wpa_cli_cmd<<EOF
set_network $network_id ssid "$1"
set_network $network_id key_mgmt NONE
set_network $network_id priority $4
set_network $network_id scan_ssid 1
select_network $network_id
quit
EOF
elif [ "$2" = "4" ] ; then
$wpa_cli_cmd<<EOF
set_network $network_id ssid "$1"
set_network $network_id key_mgmt NONE
set_network $network_id priority $4
set_network $network_id wep_key0 $3
set_network $network_id scan_ssid 1
set_network $network_id wep_tx_keyidx 0
set_network $network_id auth_alg SHARED
select_network $network_id
quit
EOF

else
echo auth_type error

fi

echo exit connect_wifi funtion
exit 1
}

reconfig()
{
echo enter reconfigure
$wpa_cli_cmd reconfigure
echo exit reconfigure
exit 1
}


disconnect_wifi()
{
echo "enter disconnect_wifi fuction"

$wpa_cli_cmd disable_network $1

echo exit disconnect_wifi funtion
exit 1
}

usage()
{
echo "Usage: `basename $0` [s]scan wifi[c]connect wifi [r]remove network"
exit 1
}

remove_network()
{
echo "enter remove_network function"
#network_id=`$wpa_cli_cmd status|grep ^id|cut -d'=' -f2`
#if [ ! $network_id ] ; then
#network_id=`echo \`cat /tmp/network_id\``
#echo "get network_id again"
#fi
#echo remove network_id=$network_id
#$wpa_cli_cmd remove_network $network_id

$wpa_cli_cmd remove_network $1
$wpa_cli_cmd save_config
$wpa_cli_cmd reconfigure
echo "exit remove network function"
exit 1
}
list_networks()
{
echo "enter list_networks function"
$wpa_cli_cmd list_networks>/tmp/wifi_list_networks_results
echo "exit list_networks function"
exit 1
}

if [ "$1" = "s" ]; then
echo scan wifi
scan_wifi
exit 1
fi

if [ "$1" = "c" ]; then
ssid="$2"
auth_type="$3"
passwd="$4"
priority="$5"
connect_wifi "$ssid" "$auth_type" "$passwd" "$priority"
exit 1
fi

if [ "$1" = "d" ]; then
echo "Disable network:$2"
id="$2"
disconnect_wifi "$id"
exit 1
fi

if [ "$1" = "rm" ]; then
echo "Remove network:$2"
id="$2"
remove_network "$id"
exit 1
fi

if [ "$1" = "r" ]; then
reconfig
exit 1
fi

if [ "$1" = "ln" ]; then
echo list_networks
list_networks
exit 1
fi

input_param="s c d r rm ln"
for i in $input_param
do
if [ ! "$1" = "$i" ] && [ ! "r" = "$i" ]; then
echo "input param $1 error!!!"
usage
else
break
fi
done




文件:wpa_supplicant.conf
ctrl_interface=/tmp/wlan0
ap_scan=1
update_config=1
fast_reauth=1
device_name=HUACHEN_WIFI
auto_interworking=1



文件:wpa_supplicant.wpa.conf
#for WPA/WPA2 CCMP/TKIP

network={
ssid="TEST"
key_mgmt=WPA-PSK
proto=WPA RSN
pairwise=TKIP CCMP
psk="PASSWORD"
}


...全文
85 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

19,613

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧