2008-08-12 14:22:42 +00:00
|
|
|
wpa_supplicant_setup_vif() {
|
|
|
|
local vif="$1"
|
|
|
|
local driver="$2"
|
2009-12-05 15:09:20 +00:00
|
|
|
local key="$key"
|
|
|
|
|
2008-08-12 14:22:42 +00:00
|
|
|
# wpa_supplicant should use wext for mac80211 cards
|
|
|
|
[ "$driver" = "mac80211" ] && driver='wext'
|
|
|
|
|
2010-02-19 01:07:21 +00:00
|
|
|
# make sure we have the encryption type and the psk
|
|
|
|
[ -n "$enc" ] || {
|
|
|
|
config_get enc "$vif" encryption
|
|
|
|
}
|
2009-12-05 15:09:20 +00:00
|
|
|
[ -n "$key" ] || {
|
|
|
|
config_get key "$vif" key
|
|
|
|
}
|
|
|
|
|
2008-08-12 14:22:42 +00:00
|
|
|
case "$enc" in
|
2010-02-08 13:42:14 +00:00
|
|
|
*none*)
|
|
|
|
key_mgmt='NONE'
|
|
|
|
;;
|
2010-01-13 19:31:47 +00:00
|
|
|
*wep*)
|
|
|
|
key_mgmt='NONE'
|
|
|
|
config_get key "$vif" key
|
|
|
|
key="${key:-1}"
|
|
|
|
case "$key" in
|
|
|
|
[1234])
|
|
|
|
for idx in 1 2 3 4; do
|
|
|
|
local zidx
|
|
|
|
zidx=$(($idx - 1))
|
|
|
|
config_get ckey "$vif" "key${idx}"
|
2010-01-14 18:48:42 +00:00
|
|
|
[ -n "$ckey" ] && \
|
2010-01-13 19:31:47 +00:00
|
|
|
append "wep_key${zidx}" "wep_key${zidx}=$(prepare_key_wep "$ckey")"
|
|
|
|
done
|
|
|
|
wep_tx_keyidx="wep_tx_keyidx=$((key - 1))"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
wep_key0="wep_key0=$(prepare_key_wep "$key")"
|
|
|
|
wep_tx_keyidx="wep_tx_keyidx=0"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2009-12-05 15:09:20 +00:00
|
|
|
*psk*)
|
2008-08-12 14:22:42 +00:00
|
|
|
key_mgmt='WPA-PSK'
|
|
|
|
config_get_bool usepassphrase "$vif" passphrase 1
|
|
|
|
case "$enc" in
|
2009-12-05 15:09:20 +00:00
|
|
|
*psk2*)
|
2010-01-13 19:31:47 +00:00
|
|
|
proto='proto=RSN'
|
2008-08-12 14:22:42 +00:00
|
|
|
if [ "$usepassphrase" = "1" ]; then
|
|
|
|
passphrase="psk=\"${key}\""
|
|
|
|
else
|
|
|
|
passphrase="psk=${key}"
|
|
|
|
fi
|
|
|
|
;;
|
2009-12-05 15:09:20 +00:00
|
|
|
*psk*)
|
2010-01-13 19:31:47 +00:00
|
|
|
proto='proto=WPA'
|
2008-08-12 14:22:42 +00:00
|
|
|
if [ "$usepassphrase" = "1" ]; then
|
|
|
|
passphrase="psk=\"${key}\""
|
|
|
|
else
|
|
|
|
passphrase="psk=${key}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2009-12-05 15:09:20 +00:00
|
|
|
*wpa*|*8021x*)
|
2010-01-13 19:31:47 +00:00
|
|
|
proto='proto=WPA2'
|
2008-08-12 14:22:42 +00:00
|
|
|
key_mgmt='WPA-EAP'
|
|
|
|
config_get ca_cert "$vif" ca_cert
|
2009-03-28 21:30:07 +00:00
|
|
|
ca_cert=${ca_cert:+"ca_cert=\"$ca_cert\""}
|
2008-08-12 14:22:42 +00:00
|
|
|
case "$eap_type" in
|
2009-12-05 15:09:20 +00:00
|
|
|
tls)
|
2008-08-12 14:22:42 +00:00
|
|
|
pairwise='pairwise=CCMP'
|
|
|
|
group='group=CCMP'
|
|
|
|
config_get priv_key "$vif" priv_key
|
|
|
|
config_get priv_key_pwd "$vif" priv_key_pwd
|
|
|
|
priv_key="private_key=\"$priv_key\""
|
|
|
|
priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
|
|
|
|
;;
|
2009-12-05 15:09:20 +00:00
|
|
|
peap|ttls)
|
2008-08-12 14:22:42 +00:00
|
|
|
config_get auth "$vif" auth
|
|
|
|
config_get identity "$vif" identity
|
|
|
|
config_get password "$vif" password
|
|
|
|
phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
|
|
|
|
identity="identity=\"$identity\""
|
|
|
|
password="password=\"$password\""
|
|
|
|
;;
|
|
|
|
esac
|
2009-03-28 21:30:07 +00:00
|
|
|
eap_type="eap=$(echo $eap_type | tr 'a-z' 'A-Z')"
|
2008-08-12 14:22:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
config_get ifname "$vif" ifname
|
|
|
|
config_get bridge "$vif" bridge
|
|
|
|
config_get ssid "$vif" ssid
|
2009-03-28 21:30:07 +00:00
|
|
|
config_get bssid "$vif" bssid
|
|
|
|
bssid=${bssid:+"bssid=$bssid"}
|
2010-01-23 08:28:26 +00:00
|
|
|
rm -rf /var/run/wpa_supplicant-$ifname
|
2008-08-12 14:22:42 +00:00
|
|
|
cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
|
2009-01-15 07:50:11 +00:00
|
|
|
ctrl_interface=/var/run/wpa_supplicant-$ifname
|
2008-08-12 14:22:42 +00:00
|
|
|
network={
|
|
|
|
scan_ssid=1
|
|
|
|
ssid="$ssid"
|
2009-03-28 21:30:07 +00:00
|
|
|
$bssid
|
2008-08-12 14:22:42 +00:00
|
|
|
key_mgmt=$key_mgmt
|
2010-01-13 19:31:47 +00:00
|
|
|
$proto
|
2008-08-12 14:22:42 +00:00
|
|
|
$passphrase
|
|
|
|
$pairwise
|
|
|
|
$group
|
2008-08-13 13:30:27 +00:00
|
|
|
$eap_type
|
|
|
|
$ca_cert
|
2008-08-12 14:22:42 +00:00
|
|
|
$priv_key
|
|
|
|
$priv_key_pwd
|
|
|
|
$phase2
|
|
|
|
$identity
|
|
|
|
$password
|
2010-01-13 19:31:47 +00:00
|
|
|
$wep_key0
|
|
|
|
$wep_key1
|
|
|
|
$wep_key2
|
|
|
|
$wep_key3
|
|
|
|
$wep_tx_keyidx
|
2008-08-12 14:22:42 +00:00
|
|
|
}
|
|
|
|
EOF
|
2010-01-14 18:48:42 +00:00
|
|
|
[ -z "$proto" -a "$key_mgmt" != "NONE" ] || \
|
2010-01-13 19:31:47 +00:00
|
|
|
wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf
|
2008-08-12 14:22:42 +00:00
|
|
|
}
|