2008-08-12 17:22:42 +03:00
|
|
|
wpa_supplicant_setup_vif() {
|
|
|
|
local vif="$1"
|
|
|
|
local driver="$2"
|
2009-12-05 17:09:20 +02:00
|
|
|
local key="$key"
|
|
|
|
|
2008-08-12 17:22:42 +03:00
|
|
|
# wpa_supplicant should use wext for mac80211 cards
|
|
|
|
[ "$driver" = "mac80211" ] && driver='wext'
|
|
|
|
|
2010-02-19 03:07:21 +02:00
|
|
|
# make sure we have the encryption type and the psk
|
|
|
|
[ -n "$enc" ] || {
|
|
|
|
config_get enc "$vif" encryption
|
|
|
|
}
|
2009-12-05 17:09:20 +02:00
|
|
|
[ -n "$key" ] || {
|
|
|
|
config_get key "$vif" key
|
|
|
|
}
|
|
|
|
|
2010-03-09 19:35:59 +02:00
|
|
|
local net_cfg bridge
|
|
|
|
config_get bridge "$vif" bridge
|
|
|
|
[ -z "$bridge" ] && {
|
|
|
|
net_cfg="$(find_net_config "$vif")"
|
|
|
|
[ -z "$net_cfg" ] || bridge="$(bridge_interface "$net_cfg")"
|
|
|
|
config_set "$vif" bridge "$bridge"
|
|
|
|
}
|
|
|
|
|
2008-08-12 17:22:42 +03:00
|
|
|
case "$enc" in
|
2010-02-08 15:42:14 +02:00
|
|
|
*none*)
|
|
|
|
key_mgmt='NONE'
|
|
|
|
;;
|
2010-01-13 21:31:47 +02: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 20:48:42 +02:00
|
|
|
[ -n "$ckey" ] && \
|
2010-01-13 21:31:47 +02: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 17:09:20 +02:00
|
|
|
*psk*)
|
2008-08-12 17:22:42 +03:00
|
|
|
key_mgmt='WPA-PSK'
|
|
|
|
config_get_bool usepassphrase "$vif" passphrase 1
|
2010-03-24 02:19:42 +02:00
|
|
|
if [ "$usepassphrase" = "1" ]; then
|
|
|
|
passphrase="psk=\"${key}\""
|
|
|
|
else
|
|
|
|
passphrase="psk=${key}"
|
|
|
|
fi
|
2008-08-12 17:22:42 +03:00
|
|
|
case "$enc" in
|
2009-12-05 17:09:20 +02:00
|
|
|
*psk2*)
|
2010-01-13 21:31:47 +02:00
|
|
|
proto='proto=RSN'
|
2010-03-24 02:21:28 +02:00
|
|
|
config_get ieee80211w "$vif" ieee80211w
|
2008-08-12 17:22:42 +03:00
|
|
|
;;
|
2009-12-05 17:09:20 +02:00
|
|
|
*psk*)
|
2010-01-13 21:31:47 +02:00
|
|
|
proto='proto=WPA'
|
2008-08-12 17:22:42 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
2009-12-05 17:09:20 +02:00
|
|
|
*wpa*|*8021x*)
|
2010-01-13 21:31:47 +02:00
|
|
|
proto='proto=WPA2'
|
2008-08-12 17:22:42 +03:00
|
|
|
key_mgmt='WPA-EAP'
|
2010-03-24 02:21:28 +02:00
|
|
|
config_get ieee80211w "$vif" ieee80211w
|
2008-08-12 17:22:42 +03:00
|
|
|
config_get ca_cert "$vif" ca_cert
|
2010-06-16 23:28:55 +03:00
|
|
|
config_get eap_type "$vif" eap_type
|
2009-03-28 23:30:07 +02:00
|
|
|
ca_cert=${ca_cert:+"ca_cert=\"$ca_cert\""}
|
2008-08-12 17:22:42 +03:00
|
|
|
case "$eap_type" in
|
2009-12-05 17:09:20 +02:00
|
|
|
tls)
|
2008-08-12 17:22:42 +03: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 17:09:20 +02:00
|
|
|
peap|ttls)
|
2008-08-12 17:22:42 +03: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 23:30:07 +02:00
|
|
|
eap_type="eap=$(echo $eap_type | tr 'a-z' 'A-Z')"
|
2008-08-12 17:22:42 +03:00
|
|
|
;;
|
|
|
|
esac
|
2010-03-24 02:21:28 +02:00
|
|
|
|
|
|
|
case "$ieee80211w" in
|
|
|
|
[012])
|
|
|
|
ieee80211w="ieee80211w=$ieee80211w"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2008-08-12 17:22:42 +03:00
|
|
|
config_get ifname "$vif" ifname
|
|
|
|
config_get bridge "$vif" bridge
|
|
|
|
config_get ssid "$vif" ssid
|
2009-03-28 23:30:07 +02:00
|
|
|
config_get bssid "$vif" bssid
|
|
|
|
bssid=${bssid:+"bssid=$bssid"}
|
2010-01-23 10:28:26 +02:00
|
|
|
rm -rf /var/run/wpa_supplicant-$ifname
|
2008-08-12 17:22:42 +03:00
|
|
|
cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
|
2009-01-15 09:50:11 +02:00
|
|
|
ctrl_interface=/var/run/wpa_supplicant-$ifname
|
2008-08-12 17:22:42 +03:00
|
|
|
network={
|
|
|
|
scan_ssid=1
|
|
|
|
ssid="$ssid"
|
2009-03-28 23:30:07 +02:00
|
|
|
$bssid
|
2008-08-12 17:22:42 +03:00
|
|
|
key_mgmt=$key_mgmt
|
2010-01-13 21:31:47 +02:00
|
|
|
$proto
|
2010-03-24 02:21:28 +02:00
|
|
|
$ieee80211w
|
2008-08-12 17:22:42 +03:00
|
|
|
$passphrase
|
|
|
|
$pairwise
|
|
|
|
$group
|
2008-08-13 16:30:27 +03:00
|
|
|
$eap_type
|
|
|
|
$ca_cert
|
2008-08-12 17:22:42 +03:00
|
|
|
$priv_key
|
|
|
|
$priv_key_pwd
|
|
|
|
$phase2
|
|
|
|
$identity
|
|
|
|
$password
|
2010-01-13 21:31:47 +02:00
|
|
|
$wep_key0
|
|
|
|
$wep_key1
|
|
|
|
$wep_key2
|
|
|
|
$wep_key3
|
|
|
|
$wep_tx_keyidx
|
2008-08-12 17:22:42 +03:00
|
|
|
}
|
|
|
|
EOF
|
2010-01-14 20:48:42 +02:00
|
|
|
[ -z "$proto" -a "$key_mgmt" != "NONE" ] || \
|
2010-01-13 21:31:47 +02: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 17:22:42 +03:00
|
|
|
}
|