[kernel] Add the generic PWM api from Bill Gatliff (experimental). Ignore the leds...
[openwrt.git] / package / hostapd / files / hostapd.sh
1 hostapd_set_bss_options() {
2 local var="$1"
3 local vif="$2"
4 local enc wpa_group_rekey
5
6 config_get enc "$vif" encryption
7 config_get wpa_group_rekey "$vif" wpa_group_rekey
8 config_get_bool ap_isolate "$vif" isolate 0
9
10 if [ "$ap_isolate" -gt 0 ]; then
11 append "$var" "ap_isolate=$ap_isolate" "$N"
12 fi
13
14 # Examples:
15 # psk-mixed/tkip => WPA1+2 PSK, TKIP
16 # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP
17 # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP
18 # ...
19
20 # TODO: move this parsing function somewhere generic, so that
21 # later it can be reused by drivers that don't use hostapd
22
23 # crypto defaults: WPA2 vs WPA1
24 case "$enc" in
25 wpa2*|*psk2*)
26 wpa=2
27 crypto="CCMP"
28 ;;
29 *mixed*)
30 wpa=3
31 crypto="CCMP TKIP"
32 ;;
33 *)
34 wpa=1
35 crypto="TKIP"
36 ;;
37 esac
38
39 # explicit override for crypto setting
40 case "$enc" in
41 *tkip+aes|*tkip+ccmp) crypto="CCMP TKIP";;
42 *aes|*ccmp) crypto="CCMP";;
43 *tkip) crypto="TKIP";;
44 esac
45
46 # use crypto/auth settings for building the hostapd config
47 case "$enc" in
48 *psk*)
49 config_get psk "$vif" key
50 if [ ${#psk} -eq 64 ]; then
51 append "$var" "wpa_psk=$psk" "$N"
52 else
53 append "$var" "wpa_passphrase=$psk" "$N"
54 fi
55 ;;
56 *wpa*)
57 # required fields? formats?
58 # hostapd is particular, maybe a default configuration for failures
59 config_get server "$vif" server
60 append "$var" "auth_server_addr=$server" "$N"
61 config_get port "$vif" port
62 port=${port:-1812}
63 append "$var" "auth_server_port=$port" "$N"
64 config_get secret "$vif" key
65 append "$var" "auth_server_shared_secret=$secret" "$N"
66 config_get nasid "$vif" nasid
67 append "$var" "nas_identifier=$nasid" "$N"
68 append "$var" "eapol_key_index_workaround=1" "$N"
69 append "$var" "radius_acct_interim_interval=300" "$N"
70 append "$var" "ieee8021x=1" "$N"
71 append "$var" "auth_algs=1" "$N"
72 append "$var" "wpa_key_mgmt=WPA-EAP" "$N"
73 append "$var" "wpa_group_rekey=300" "$N"
74 append "$var" "wpa_gmk_rekey=640" "$N"
75 ;;
76 *wep*)
77 config_get key "$vif" key
78 key="${key:-1}"
79 case "$key" in
80 [1234])
81 for idx in 1 2 3 4; do
82 local zidx
83 zidx=$(($idx - 1))
84 config_get ckey "$vif" "key${idx}"
85 [ -n "$ckey" ] && \
86 append "$var" "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N"
87 done
88 append "$var" "wep_default_key=$((key - 1))" "$N"
89 ;;
90 *)
91 append "$var" "wep_key0=$(prepare_key_wep "$key")" "$N"
92 append "$var" "wep_default_key=0" "$N"
93 ;;
94 esac
95 wpa=0
96 crypto=
97 ;;
98 *)
99 wpa=0
100 crypto=
101 ;;
102 esac
103 append "$var" "wpa=$wpa" "$N"
104 [ -n "$crypto" ] && append "$var" "wpa_pairwise=$crypto" "$N"
105 [ -n "$wpa_group_rekey" ] && append "$var" "wpa_group_rekey=$wpa_group_rekey" "$N"
106
107 config_get ssid "$vif" ssid
108 config_get bridge "$vif" bridge
109 config_get ieee80211d "$vif" ieee80211d
110
111 append "$var" "ssid=$ssid" "$N"
112 [ -n "$bridge" ] && append "$var" "bridge=$bridge" "$N"
113 [ -n "$ieee80211d" ] && append "$var" "ieee80211d=$ieee80211d" "$N"
114
115 [ "$wpa" -ge "2" ] && config_get ieee80211w "$vif" ieee80211w
116 case "$ieee80211w" in
117 [012])
118 append "$var" "ieee80211w=$ieee80211w" "$N"
119 [ "$ieee80211w" -gt "0" ] && {
120 config_get ieee80211w_max_timeout "$vif" ieee80211w_max_timeout
121 config_get ieee80211w_retry_timeout "$vif" ieee80211w_retry_timeout
122 [ -n "$ieee80211w_max_timeout" ] && \
123 append "$var" "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
124 [ -n "$ieee80211w_retry_timeout" ] && \
125 append "$var" "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
126 }
127 ;;
128 esac
129 }
130
131 hostapd_setup_vif() {
132 local vif="$1"
133 local driver="$2"
134 hostapd_cfg=
135
136 hostapd_set_bss_options hostapd_cfg "$vif"
137 config_get ifname "$vif" ifname
138 config_get device "$vif" device
139 config_get channel "$device" channel
140 config_get hwmode "$device" hwmode
141 case "$hwmode" in
142 *bg|*gdt|*gst|*fh) hwmode=g;;
143 *adt|*ast) hwmode=a;;
144 esac
145 [ "$channel" = auto ] && channel=
146 [ -n "$channel" -a -z "$hwmode" ] && wifi_fixup_hwmode "$device"
147 cat > /var/run/hostapd-$ifname.conf <<EOF
148 ctrl_interface=/var/run/hostapd-$ifname
149 driver=$driver
150 interface=$ifname
151 ${hwmode:+hw_mode=${hwmode#11}}
152 ${channel:+channel=$channel}
153 $hostapd_cfg
154 EOF
155 hostapd -P /var/run/wifi-$ifname.pid -B /var/run/hostapd-$ifname.conf
156 }
157
This page took 0.054295 seconds and 5 git commands to generate.