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"
|
2010-10-23 23:39:54 +00:00
|
|
|
local options="$3"
|
2012-03-27 13:38:08 +00:00
|
|
|
local freq=""
|
2012-07-24 23:07:25 +00:00
|
|
|
local ht="$5"
|
2012-07-24 23:07:15 +00:00
|
|
|
local ap_scan=""
|
|
|
|
local scan_ssid="1"
|
2012-03-27 13:29:41 +00:00
|
|
|
[ -n "$4" ] && freq="frequency=$4"
|
2009-12-05 15:09:20 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2010-03-09 17:35:59 +00: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 13:38:08 +00:00
|
|
|
local mode ifname wds modestr=""
|
2011-11-08 14:22:56 +00: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-07-24 23:07:15 +00:00
|
|
|
[ "$mode" = "adhoc" ] && {
|
|
|
|
modestr="mode=1"
|
|
|
|
scan_ssid="0"
|
|
|
|
ap_scan="ap_scan=2"
|
|
|
|
}
|
2011-11-08 14:22:56 +00:00
|
|
|
|
2012-03-29 16:30:13 +00:00
|
|
|
key_mgmt='NONE'
|
2008-08-12 14:22:42 +00:00
|
|
|
case "$enc" in
|
2012-03-29 16:30:13 +00:00
|
|
|
*none*) ;;
|
2010-01-13 19:31:47 +00: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 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'
|
2012-06-06 15:25:52 +00: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-07-05 12:25:29 +00:00
|
|
|
if [ ${#key} -eq 64 ]; then
|
2010-03-24 00:19:42 +00:00
|
|
|
passphrase="psk=${key}"
|
2012-07-05 12:25:29 +00:00
|
|
|
else
|
|
|
|
passphrase="psk=\"${key}\""
|
2010-03-24 00:19:42 +00:00
|
|
|
fi
|
2008-08-12 14:22:42 +00:00
|
|
|
case "$enc" in
|
2009-12-05 15:09:20 +00:00
|
|
|
*psk2*)
|
2010-01-13 19:31:47 +00:00
|
|
|
proto='proto=RSN'
|
2010-03-24 00:21:28 +00:00
|
|
|
config_get ieee80211w "$vif" ieee80211w
|
2008-08-12 14:22:42 +00:00
|
|
|
;;
|
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
|
|
|
;;
|
|
|
|
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'
|
2010-03-24 00:21:28 +00:00
|
|
|
config_get ieee80211w "$vif" ieee80211w
|
2008-08-12 14:22:42 +00:00
|
|
|
config_get ca_cert "$vif" ca_cert
|
2010-06-16 20:28:11 +00:00
|
|
|
config_get eap_type "$vif" eap_type
|
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'
|
2010-11-03 10:39:29 +00:00
|
|
|
config_get identity "$vif" identity
|
2012-01-24 20:54:13 +00:00
|
|
|
config_get client_cert "$vif" client_cert
|
2008-08-12 14:22:42 +00:00
|
|
|
config_get priv_key "$vif" priv_key
|
|
|
|
config_get priv_key_pwd "$vif" priv_key_pwd
|
2010-11-03 10:39:29 +00:00
|
|
|
identity="identity=\"$identity\""
|
2012-01-24 20:54:13 +00:00
|
|
|
client_cert="client_cert=\"$client_cert\""
|
2008-08-12 14:22:42 +00:00
|
|
|
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
|
2010-03-24 00:21:28 +00:00
|
|
|
|
|
|
|
case "$ieee80211w" in
|
|
|
|
[012])
|
|
|
|
ieee80211w="ieee80211w=$ieee80211w"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2012-07-24 23:07:15 +00:00
|
|
|
local fixed_freq bssid1 beacon_interval brates mrate
|
2008-08-12 14:22:42 +00:00
|
|
|
config_get ifname "$vif" ifname
|
|
|
|
config_get bridge "$vif" bridge
|
2012-08-08 11:13:12 +00:00
|
|
|
config_get ssid "$vif" ssid
|
|
|
|
config_get bssid "$vif" bssid
|
2012-07-24 23:07:15 +00:00
|
|
|
bssid1=${bssid:+"bssid=$bssid"}
|
|
|
|
beacon_interval=${beacon_int:+"beacon_interval=$beacon_int"}
|
|
|
|
|
|
|
|
local br brval brsub brstr
|
|
|
|
[ -n "$basic_rate_list" ] && {
|
|
|
|
for br in $basic_rate_list; do
|
|
|
|
brval="$(($br / 1000))"
|
|
|
|
brsub="$((($br / 100) % 10))"
|
|
|
|
[ "$brsub" -gt 0 ] && brval="$brval.$brsub"
|
|
|
|
[ -n "$brstr" ] && brstr="$brstr,"
|
|
|
|
brstr="$brstr$brval"
|
|
|
|
done
|
|
|
|
brates=${basic_rate_list:+"rates=$brstr"}
|
|
|
|
}
|
|
|
|
|
|
|
|
local mcval=""
|
|
|
|
[ -n "$mcast_rate" ] && {
|
|
|
|
mcval="$(($mcast_rate / 1000))"
|
|
|
|
mcsub="$(( ($mcast_rate / 100) % 10 ))"
|
|
|
|
[ "$mcsub" -gt 0 ] && mcval="$mcval.$mcsub"
|
|
|
|
mrate=${mcast_rate:+"mcast_rate=$mcval"}
|
|
|
|
}
|
|
|
|
|
2012-07-24 23:07:25 +00:00
|
|
|
local ht_str
|
|
|
|
[ -n "$ht" ] && ht_str="htmode=$ht"
|
|
|
|
|
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
|
2012-07-24 23:07:15 +00:00
|
|
|
$ap_scan
|
2008-08-12 14:22:42 +00:00
|
|
|
network={
|
2012-03-27 13:38:08 +00:00
|
|
|
$modestr
|
2012-07-24 23:07:15 +00:00
|
|
|
scan_ssid=$scan_ssid
|
2008-08-12 14:22:42 +00:00
|
|
|
ssid="$ssid"
|
2012-07-24 23:07:15 +00:00
|
|
|
$bssid1
|
2008-08-12 14:22:42 +00:00
|
|
|
key_mgmt=$key_mgmt
|
2010-01-13 19:31:47 +00:00
|
|
|
$proto
|
2012-03-27 13:29:41 +00:00
|
|
|
$freq
|
2012-07-24 23:07:15 +00:00
|
|
|
${fixed:+"fixed_freq=1"}
|
|
|
|
$beacon_interval
|
|
|
|
$brates
|
|
|
|
$mrate
|
2012-07-24 23:07:25 +00:00
|
|
|
$ht_str
|
2010-03-24 00:21:28 +00:00
|
|
|
$ieee80211w
|
2008-08-12 14:22:42 +00:00
|
|
|
$passphrase
|
|
|
|
$pairwise
|
|
|
|
$group
|
2008-08-13 13:30:27 +00:00
|
|
|
$eap_type
|
|
|
|
$ca_cert
|
2012-01-24 20:54:13 +00:00
|
|
|
$client_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-10-23 23:39:54 +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 $options
|
2008-08-12 14:22:42 +00:00
|
|
|
}
|