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"
|
2010-10-24 02:39:54 +03:00
|
|
|
local options="$3"
|
2012-03-27 16:38:08 +03:00
|
|
|
local freq=""
|
2012-03-27 16:29:41 +03:00
|
|
|
[ -n "$4" ] && freq="frequency=$4"
|
2009-12-05 17:09:20 +02:00
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2012-03-27 16:38:08 +03:00
|
|
|
local mode ifname wds modestr=""
|
2011-11-08 16:22:56 +02:00
|
|
|
config_get mode "$vif" mode
|
|
|
|
config_get ifname "$vif" ifname
|
|
|
|
config_get_bool wds "$vif" wds 0
|
|
|
|
[ -z "$bridge" ] || [ "$mode" = ap ] || [ "$mode" = sta -a $wds -eq 1 ] || {
|
|
|
|
echo "wpa_supplicant_setup_vif($ifname): Refusing to bridge $mode mode interface"
|
|
|
|
return 1
|
|
|
|
}
|
2012-03-27 16:38:08 +03:00
|
|
|
[ "$mode" = "adhoc" ] && modestr="mode=1"
|
2011-11-08 16:22:56 +02:00
|
|
|
|
2012-03-29 19:30:13 +03:00
|
|
|
key_mgmt='NONE'
|
2008-08-12 17:22:42 +03:00
|
|
|
case "$enc" in
|
2012-03-29 19:30:13 +03:00
|
|
|
*none*) ;;
|
2010-01-13 21:31:47 +02:00
|
|
|
*wep*)
|
|
|
|
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'
|
2012-06-06 18:25:52 +03:00
|
|
|
# if you want to use PSK with a non-nl80211 driver you
|
|
|
|
# have to use WPA-NONE and wext driver for wpa_s
|
|
|
|
[ "$mode" = "adhoc" -a "$driver" != "nl80211" ] && {
|
|
|
|
key_mgmt='WPA-NONE'
|
|
|
|
driver='wext'
|
|
|
|
}
|
2012-02-13 18:07:53 +02:00
|
|
|
config_get_bool usepassphrase "$vif" usepassphrase 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:11 +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'
|
2010-11-03 12:39:29 +02:00
|
|
|
config_get identity "$vif" identity
|
2012-01-24 22:54:13 +02:00
|
|
|
config_get client_cert "$vif" client_cert
|
2008-08-12 17:22:42 +03:00
|
|
|
config_get priv_key "$vif" priv_key
|
|
|
|
config_get priv_key_pwd "$vif" priv_key_pwd
|
2010-11-03 12:39:29 +02:00
|
|
|
identity="identity=\"$identity\""
|
2012-01-24 22:54:13 +02:00
|
|
|
client_cert="client_cert=\"$client_cert\""
|
2008-08-12 17:22:42 +03:00
|
|
|
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={
|
2012-03-27 16:38:08 +03:00
|
|
|
$modestr
|
2008-08-12 17:22:42 +03:00
|
|
|
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
|
2012-03-27 16:29:41 +03:00
|
|
|
$freq
|
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
|
2012-01-24 22:54:13 +02:00
|
|
|
$client_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-10-24 02:39:54 +03: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 $options
|
2008-08-12 17:22:42 +03:00
|
|
|
}
|