include/kernel.mk: enhance built-in/missing modules detection when packaging kmods
[openwrt.git] / package / hostapd / files / wpa_supplicant.sh
1 wpa_supplicant_setup_vif() {
2 local vif="$1"
3 local driver="$2"
4 local key="$key"
5 local options="$3"
6
7 # wpa_supplicant should use wext for mac80211 cards
8 [ "$driver" = "mac80211" ] && driver='wext'
9
10 # make sure we have the encryption type and the psk
11 [ -n "$enc" ] || {
12 config_get enc "$vif" encryption
13 }
14 [ -n "$key" ] || {
15 config_get key "$vif" key
16 }
17
18 local net_cfg bridge
19 config_get bridge "$vif" bridge
20 [ -z "$bridge" ] && {
21 net_cfg="$(find_net_config "$vif")"
22 [ -z "$net_cfg" ] || bridge="$(bridge_interface "$net_cfg")"
23 config_set "$vif" bridge "$bridge"
24 }
25
26 case "$enc" in
27 *none*)
28 key_mgmt='NONE'
29 ;;
30 *wep*)
31 key_mgmt='NONE'
32 config_get key "$vif" key
33 key="${key:-1}"
34 case "$key" in
35 [1234])
36 for idx in 1 2 3 4; do
37 local zidx
38 zidx=$(($idx - 1))
39 config_get ckey "$vif" "key${idx}"
40 [ -n "$ckey" ] && \
41 append "wep_key${zidx}" "wep_key${zidx}=$(prepare_key_wep "$ckey")"
42 done
43 wep_tx_keyidx="wep_tx_keyidx=$((key - 1))"
44 ;;
45 *)
46 wep_key0="wep_key0=$(prepare_key_wep "$key")"
47 wep_tx_keyidx="wep_tx_keyidx=0"
48 ;;
49 esac
50 ;;
51 *psk*)
52 key_mgmt='WPA-PSK'
53 config_get_bool usepassphrase "$vif" passphrase 1
54 if [ "$usepassphrase" = "1" ]; then
55 passphrase="psk=\"${key}\""
56 else
57 passphrase="psk=${key}"
58 fi
59 case "$enc" in
60 *psk2*)
61 proto='proto=RSN'
62 config_get ieee80211w "$vif" ieee80211w
63 ;;
64 *psk*)
65 proto='proto=WPA'
66 ;;
67 esac
68 ;;
69 *wpa*|*8021x*)
70 proto='proto=WPA2'
71 key_mgmt='WPA-EAP'
72 config_get ieee80211w "$vif" ieee80211w
73 config_get ca_cert "$vif" ca_cert
74 config_get eap_type "$vif" eap_type
75 ca_cert=${ca_cert:+"ca_cert=\"$ca_cert\""}
76 case "$eap_type" in
77 tls)
78 pairwise='pairwise=CCMP'
79 group='group=CCMP'
80 config_get identity "$vif" identity
81 config_get priv_key "$vif" priv_key
82 config_get priv_key_pwd "$vif" priv_key_pwd
83 identity="identity=\"$identity\""
84 priv_key="private_key=\"$priv_key\""
85 priv_key_pwd="private_key_passwd=\"$priv_key_pwd\""
86 ;;
87 peap|ttls)
88 config_get auth "$vif" auth
89 config_get identity "$vif" identity
90 config_get password "$vif" password
91 phase2="phase2=\"auth=${auth:-MSCHAPV2}\""
92 identity="identity=\"$identity\""
93 password="password=\"$password\""
94 ;;
95 esac
96 eap_type="eap=$(echo $eap_type | tr 'a-z' 'A-Z')"
97 ;;
98 esac
99
100 case "$ieee80211w" in
101 [012])
102 ieee80211w="ieee80211w=$ieee80211w"
103 ;;
104 esac
105
106 config_get ifname "$vif" ifname
107 config_get bridge "$vif" bridge
108 config_get ssid "$vif" ssid
109 config_get bssid "$vif" bssid
110 bssid=${bssid:+"bssid=$bssid"}
111 rm -rf /var/run/wpa_supplicant-$ifname
112 cat > /var/run/wpa_supplicant-$ifname.conf <<EOF
113 ctrl_interface=/var/run/wpa_supplicant-$ifname
114 network={
115 scan_ssid=1
116 ssid="$ssid"
117 $bssid
118 key_mgmt=$key_mgmt
119 $proto
120 $ieee80211w
121 $passphrase
122 $pairwise
123 $group
124 $eap_type
125 $ca_cert
126 $priv_key
127 $priv_key_pwd
128 $phase2
129 $identity
130 $password
131 $wep_key0
132 $wep_key1
133 $wep_key2
134 $wep_key3
135 $wep_tx_keyidx
136 }
137 EOF
138 [ -z "$proto" -a "$key_mgmt" != "NONE" ] || \
139 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
140 }
This page took 0.062444 seconds and 5 git commands to generate.