2 append DRIVERS "atheros"
7 local adhoc ahdemo sta ap monitor
9 config_get vifs "$device" vifs
12 config_get ifname "$vif" ifname
13 config_set "$vif" ifname "${ifname:-ath}"
15 config_get mode "$vif" mode
17 adhoc|ahdemo|sta|ap|monitor)
21 config_get ssid "$vif" ssid
22 [ -z "$ssid" ] && continue
24 config_set "$vif" wds 1
25 config_set "$vif" mode sta
28 ${addr:+append $mode "$vif"}
30 *) echo "$device($vif): Invalid mode, ignored."; continue;;
34 case "${adhoc:+1}:${sta:+1}:${ap:+1}" in
35 # valid mode combinations
38 :1:1)config_set "$device" nosbeacon 1;; # AP+STA, can't use beacon timers for STA
42 *) echo "$device: Invalid mode combination in config"; return 1;;
45 config_set "$device" vifs "${sta:+$sta }${ap:+$ap }${adhoc:+$adhoc }${ahdemo:+$ahdemo }${wds:+$wds }${monitor:+$monitor}"
52 set_wifi_down "$device"
57 grep "$device" "$dev/%parent" >/dev/null 2>/dev/null && {
58 [ -f "/var/run/wifi-${dev}.pid" ] &&
59 kill "$(cat "/var/run/wifi-${dev}.pid")"
62 wlanconfig "$dev" destroy
71 config_get regdomain "$device" regdomain
72 [ -n "$regdomain" ] && echo "$regdomain" > /proc/sys/dev/$device/regdomain
74 config_get country "$device" country
75 [ -z "$country" ] && country="0"
76 echo "$country" > /proc/sys/dev/$device/countrycode
78 config_get_bool outdoor "$device" outdoor "0"
79 echo "$outdoor" > /proc/sys/dev/$device/outdoor
81 config_get channel "$device" channel
82 config_get vifs "$device" vifs
83 config_get txpower "$device" txpower
85 [ auto = "$channel" ] && channel=0
87 config_get_bool antdiv "$device" diversity
88 config_get antrx "$device" rxantenna
89 config_get anttx "$device" txantenna
90 config_get_bool softled "$device" softled 1
92 devname="$(cat /proc/sys/dev/$device/dev_name)"
96 NanoStation2) antgpio=7; invert=1;;
97 NanoStation5) antgpio=1; invert=1;;
98 "NanoStation Loco2") antgpio=2;;
100 if [ -n "$invert" ]; then
107 if [ -n "$antgpio" ]; then
109 config_get antenna "$device" antenna
111 external) antdiv=0; antrx=1; anttx=1 ;;
112 horizontal) antdiv=0; antrx=1; anttx=1 ;;
113 vertical) antdiv=0; antrx=2; anttx=2 ;;
114 auto) antdiv=1; antrx=0; anttx=0 ;;
117 [ -x "$(which gpioctl 2>/dev/null)" ] || antenna=
118 gpioctl "dirout" "$antgpio" >/dev/null 2>&1
120 horizontal|vertical|auto)
121 gpioctl "$_clear" "$antgpio" >/dev/null 2>&1
124 gpioctl "$_set" "$antgpio" >/dev/null 2>&1
129 [ -n "$antdiv" ] && sysctl -w dev."$device".diversity="$antdiv" >&-
130 [ -n "$antrx" ] && sysctl -w dev."$device".rxantenna="$antrx" >&-
131 [ -n "$anttx" ] && sysctl -w dev."$device".txantenna="$anttx" >&-
132 [ -n "$softled" ] && sysctl -w dev."$device".softled="$softled" >&-
134 config_get distance "$device" distance
135 [ -n "$distance" ] && sysctl -w dev."$device".distance="$distance" >&-
138 local start_hostapd= vif_txpower= nosbeacon=
139 config_get ifname "$vif" ifname
140 config_get enc "$vif" encryption
141 config_get eap_type "$vif" eap_type
142 config_get mode "$vif" mode
145 sta) config_get_bool nosbeacon "$device" nosbeacon;;
146 adhoc) config_get_bool nosbeacon "$vif" sw_merge 1;;
149 [ "$nosbeacon" = 1 ] || nosbeacon=""
150 ifname=$(wlanconfig "$ifname" create wlandev "$device" wlanmode "$mode" ${nosbeacon:+nosbeacon})
152 echo "enable_atheros($device): Failed to set up $mode vif $ifname" >&2
155 config_set "$vif" ifname "$ifname"
157 config_get hwmode "$device" hwmode
158 [ -z "$hwmode" ] && config_get hwmode "$device" mode
164 *g) hwmode=11g; pureg=1;;
172 iwpriv "$ifname" mode "$hwmode"
173 iwpriv "$ifname" pureg "$pureg"
175 iwconfig "$ifname" channel "$channel" >/dev/null 2>/dev/null
177 config_get_bool hidden "$vif" hidden 0
178 iwpriv "$ifname" hide_ssid "$hidden"
180 config_get ff "$vif" ff
181 if [ -n "$ff" ]; then
182 iwpriv "$ifname" ff "$ff"
185 config_get wds "$vif" wds
187 1|on|enabled) wds=1;;
190 iwpriv "$ifname" wds "$wds" >/dev/null 2>&1
192 [ "$mode" = ap -a "$wds" = 1 ] && {
193 config_get_bool wdssep "$vif" wdssep 1
194 [ -n "$wdssep" ] && iwpriv "$ifname" wdssep "$wdssep"
199 for idx in 1 2 3 4; do
200 config_get key "$vif" "key${idx}"
201 iwconfig "$ifname" enc "[$idx]" "${key:-off}"
203 config_get key "$vif" key
206 [1234]) iwconfig "$ifname" enc "[$key]";;
207 *) iwconfig "$ifname" enc "$key";;
212 config_get key "$vif" key
218 config_get addr "$vif" bssid
220 iwconfig "$ifname" ap "$addr"
225 config_get_bool uapsd "$vif" uapsd 0
226 iwpriv "$ifname" uapsd "$uapsd"
228 config_get_bool bgscan "$vif" bgscan
229 [ -n "$bgscan" ] && iwpriv "$ifname" bgscan "$bgscan"
231 config_get rate "$vif" rate
232 [ -n "$rate" ] && iwconfig "$ifname" rate "${rate%%.*}"
234 config_get mcast_rate "$vif" mcast_rate
235 [ -n "$mcast_rate" ] && iwpriv "$ifname" mcast_rate "${mcast_rate%%.*}"
237 config_get frag "$vif" frag
238 [ -n "$frag" ] && iwconfig "$ifname" frag "${frag%%.*}"
240 config_get rts "$vif" rts
241 [ -n "$rts" ] && iwconfig "$ifname" rts "${rts%%.*}"
243 config_get_bool comp "$vif" compression 0
244 iwpriv "$ifname" compression "$comp" >/dev/null 2>&1
246 config_get_bool minrate "$vif" minrate
247 [ -n "$minrate" ] && iwpriv "$ifname" minrate "$minrate"
249 config_get_bool maxrate "$vif" maxrate
250 [ -n "$maxrate" ] && iwpriv "$ifname" maxrate "$maxrate"
252 config_get_bool burst "$vif" bursting
253 [ -n "$burst" ] && iwpriv "$ifname" burst "$burst"
255 config_get_bool wmm "$vif" wmm
256 [ -n "$wmm" ] && iwpriv "$ifname" wmm "$wmm"
258 config_get_bool xr "$vif" xr
259 [ -n "$xr" ] && iwpriv "$ifname" xr "$xr"
261 config_get_bool ar "$vif" ar
262 [ -n "$ar" ] && iwpriv "$ifname" ar "$ar"
264 config_get_bool beacon_power "$vif" beacon_power
265 [ -n "$beacon_power" ] && iwpriv "$ifname" beacon_pwr "$beacon_power"
267 config_get_bool doth "$vif" doth 0
268 [ -n "$doth" ] && iwpriv "$ifname" doth "$doth"
270 config_get_bool probereq "$vif" probereq
271 [ -n "$probereq" ] && iwpriv "$ifname" probereq "$probereq"
273 config_get maclist "$vif" maclist
274 [ -n "$maclist" ] && {
276 iwpriv "$ifname" maccmd 3
277 for mac in $maclist; do
278 iwpriv "$ifname" addmac "$mac"
282 config_get macpolicy "$vif" macpolicy
285 iwpriv "$ifname" maccmd 1
288 iwpriv "$ifname" maccmd 2
291 # default deny policy if mac list exists
292 [ -n "$maclist" ] && iwpriv "$ifname" maccmd 2
296 ifconfig "$ifname" up
299 net_cfg="$(find_net_config "$vif")"
300 [ -z "$net_cfg" ] || {
301 bridge="$(bridge_interface "$net_cfg")"
302 config_set "$vif" bridge "$bridge"
303 start_net "$ifname" "$net_cfg"
306 config_get ssid "$vif" ssid
308 iwconfig "$ifname" essid on
309 iwconfig "$ifname" essid "$ssid"
312 set_wifi_up "$vif" "$ifname"
314 # TXPower settings only work if device is up already
315 # while atheros hardware theoretically is capable of per-vif (even per-packet) txpower
316 # adjustment it does not work with the current atheros hal/madwifi driver
318 config_get vif_txpower "$vif" txpower
319 # use vif_txpower (from wifi-iface) instead of txpower (from wifi-device) if
320 # the latter doesn't exist
321 txpower="${txpower:-$vif_txpower}"
322 [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
326 config_get_bool isolate "$vif" isolate 0
327 iwpriv "$ifname" ap_bridge "$((isolate^1))"
329 if [ -n "$start_hostapd" ] && eval "type hostapd_setup_vif" 2>/dev/null >/dev/null; then
330 hostapd_setup_vif "$vif" madwifi || {
331 echo "enable_atheros($device): Failed to set up hostapd for interface $ifname" >&2
332 # make sure this wifi interface won't accidentally stay open without encryption
333 ifconfig "$ifname" down
334 wlanconfig "$ifname" destroy
340 if eval "type wpa_supplicant_setup_vif" 2>/dev/null >/dev/null; then
341 wpa_supplicant_setup_vif "$vif" madwifi || {
342 echo "enable_atheros($device): Failed to set up wpa_supplicant for interface $ifname" >&2
343 ifconfig "$ifname" down
344 wlanconfig "$ifname" destroy
357 for dev in $(ls -d wifi* 2>&-); do
358 config_get type "$dev" type
359 devname="$(cat /proc/sys/dev/$dev/dev_name)"
363 # Ubiquiti NanoStation features
364 option antenna auto # (auto|horizontal|vertical|external)
368 [ "$type" = atheros ] && continue
370 config wifi-device $dev
374 # REMOVE THIS LINE TO ENABLE WIFI:
382 option encryption none