Home > OS >  For car machine Linux3. X is not saved after restart WIFI account and password
For car machine Linux3. X is not saved after restart WIFI account and password

Time:09-29

File name: 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 & gt;/TMP/wifi_scan_results
Echo exit scan_wifi function
The exit 1
}

Connect_wifi ()
{
Echo enter connect_wifi funtion
Network_id=` $wpa_cli_cmd add_network `
# echo $network_id & gt;/TMP/network_id
# passwd=` echo $2 `
Echo The connecting The auth_type wifi ssid=$1=$2 network_id=$network_id priority=$4
If (" $2 "=" 1 ") | | (" $2 "=" 2 ") | | (" $2 "=" 3 "); Then
$wpa_cli_cmd & lt; 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
The quit
EOF
Elif (" $2 "=" 0 "); Then
$wpa_cli_cmd & lt; 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
The quit
EOF
Elif [" $2 "=" 4 "); Then
$wpa_cli_cmd & lt; 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
The quit
EOF

The else
Echo the auth_type error

Fi

Echo exit connect_wifi funtion
The exit 1
}

Reconfig ()
{
Echo enter to reconfigure
$wpa_cli_cmd reconfigure
Echo exit reconfigure
The exit 1
}


Disconnect_wifi ()
{
Echo "enter disconnect_wifi fuction
"
$wpa_cli_cmd disable_network $1

Echo exit disconnect_wifi funtion
The exit 1
}

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

Remove_network ()
{
Echo "enter remove_network function", "
# network_id=` $wpa_cli_cmd status | grep ^ id | the 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"
The exit 1
}
List_networks ()
{
Echo "enter list_networks function", "
$wpa_cli_cmd list_networks & gt;/TMP/wifi_list_networks_results
Echo "exit list_networks function", "
The exit 1
}

If (" $1 "=" s "); Then
Echo scan wifi
Scan_wifi
The exit 1
Fi

If (" $1 "=" c "); Then
Ssid="$2"
The auth_type="$3"
Passwd="$4"
Priority="$5"
Connect_wifi "$ssid" "$the auth_type" "$passwd" "$priority"
The exit 1
Fi

If (" $1 "=" d "); Then
Echo "Disable network: $2"
Id="$2"
Disconnect_wifi "$id"
The exit 1
Fi

If [" $1 "=" rm "]. Then
Echo "Remove network: $2"
Id="$2"
Remove_network "$id"
The exit 1
Fi

If (" $1 "=" r "); Then
Reconfig
The exit 1
Fi

If [" $1 "=" ln "]. Then
Echo list_networks
List_networks
The exit 1
Fi

Input_param="s c d r rm ln"
For I in $input_param
Do
If [! "$1"="$I"] & amp; & [! "r"="$I"]. Then
Echo "input param $1 error!!!!!! "
The usage
The else
Break
Fi
The done




File: wpa_supplicant. Conf
Ctrl_interface=/TMP/wlan0
Ap_scan=1
Update_config=1
Fast_reauth=1
Device_name=HUACHEN_WIFI
Auto_interworking=1



File: wpa_supplicant. Wpa. Conf
# for WPA/connected CCMP/TKIP

The network={
Ssid="TEST"
Key_mgmt=WPA wpa2-psk
Proto=WPA RSN
Pairwise=TKIP CCMP
PSK="PASSWORD"
}


  • Related