2 append DRIVERS
"atheros"
7 local macaddr
="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
8 config_get phy
"$device" phy
9 [ -z "$phy" -a -n "$macaddr" ] && {
11 for phy
in $
(ls -d wifi
* 2>&-); do
12 [ "$macaddr" = "$(cat /sys/class/net/${phy}/address)" ] ||
continue
13 config_set
"$device" phy
"$phy"
16 config_get phy
"$device" phy
18 [ -n "$phy" -a -d "/proc/sys/dev/$phy" ] ||
{
19 echo "phy for wifi device $1 not found"
22 [ -z "$macaddr" ] && {
23 config_set
"$device" macaddr
"$(cat /sys/class/net/${phy}/address)"
31 local adhoc ahdemo sta ap monitor disabled
33 [ ${device%[0-9]} = "wifi" ] && config_set
"$device" phy
"$device"
35 config_get vifs
"$device" vifs
37 config_get_bool disabled
"$vif" disabled
0
38 [ $disabled = 0 ] ||
continue
40 config_get ifname
"$vif" ifname
41 config_set
"$vif" ifname
"${ifname:-ath}"
43 config_get mode
"$vif" mode
45 adhoc|ahdemo|sta|ap|monitor
)
49 config_get ssid
"$vif" ssid
50 [ -z "$ssid" ] && continue
52 config_set
"$vif" wds
1
53 config_set
"$vif" mode sta
56 ${addr:+append $mode "$vif"}
58 *) echo "$device($vif): Invalid mode, ignored."; continue;;
62 case "${adhoc:+1}:${sta:+1}:${ap:+1}" in
63 # valid mode combinations
66 :1:1)config_set
"$device" nosbeacon
1;; # AP+STA, can't use beacon timers for STA
70 *) echo "$device: Invalid mode combination in config"; return 1;;
73 config_set
"$device" vifs
"${sta:+$sta }${ap:+$ap }${adhoc:+$adhoc }${ahdemo:+$ahdemo }${wds:+$wds }${monitor:+$monitor}"
80 find_atheros_phy
"$device" ||
return 0
81 config_get phy
"$device" phy
83 set_wifi_down
"$device"
88 grep "$phy" "$dev/%parent" >/dev
/null
2>/dev
/null
&& {
89 [ -f "/var/run/wifi-${dev}.pid" ] &&
90 kill "$(cat "/var
/run
/wifi-
${dev}.pid
")"
93 wlanconfig
"$dev" destroy
102 find_atheros_phy
"$device" ||
return 0
103 config_get phy
"$device" phy
105 config_get regdomain
"$device" regdomain
106 [ -n "$regdomain" ] && echo "$regdomain" > /proc
/sys
/dev
/$phy/regdomain
108 config_get country
"$device" country
110 [A-Za-z
]*) country
=`grep -i "$country" /lib/wifi/madwifi_countrycodes.txt |cut -d " " -f 2`;;
114 [ -n "$country" ] && echo "$country" > /proc
/sys
/dev
/$phy/countrycode
116 config_get_bool outdoor
"$device" outdoor
"0"
117 echo "$outdoor" > /proc
/sys
/dev
/$phy/outdoor
119 config_get channel
"$device" channel
120 config_get vifs
"$device" vifs
121 config_get txpower
"$device" txpower
123 [ auto
= "$channel" ] && channel
=0
125 config_get_bool antdiv
"$device" diversity
126 config_get antrx
"$device" rxantenna
127 config_get anttx
"$device" txantenna
128 config_get_bool softled
"$device" softled
129 config_get antenna
"$device" antenna
131 devname
="$(cat /proc/sys/dev/$phy/dev_name)"
135 NanoStation2
) antgpio
=7; invert
=1;;
136 NanoStation5
) antgpio
=1; invert
=1;;
137 "NanoStation Loco2") antgpio
=2;;
140 horizontal
) antdiv
=0; anttx
=1; antrx
=1;;
141 vertical
) antdiv
=0; anttx
=2; antrx
=2;;
142 *) antdiv
=1; anttx
=0; antrx
=0;;
146 if [ -n "$invert" ]; then
153 if [ -n "$antgpio" ]; then
161 horizontal
) gpioval
=0;;
167 external
) antdiv
=0; antrx
=1; anttx
=1; gpioval
=1;;
168 horizontal
) antdiv
=0; antrx
=1; anttx
=1; gpioval
=0;;
169 vertical
) antdiv
=0; antrx
=2; anttx
=2; gpioval
=0;;
170 auto
) antdiv
=1; antrx
=0; anttx
=0; gpioval
=0;;
175 [ -x "$(which gpioctl 2>/dev/null)" ] || antenna
=
176 gpioctl
"dirout" "$antgpio" >/dev
/null
2>&1
179 gpioctl
"$_clear" "$antgpio" >/dev
/null
2>&1
182 gpioctl
"$_set" "$antgpio" >/dev
/null
2>&1
187 [ -n "$antdiv" ] && sysctl
-w dev.
"$phy".diversity
="$antdiv" >&-
188 [ -n "$antrx" ] && sysctl
-w dev.
"$phy".rxantenna
="$antrx" >&-
189 [ -n "$anttx" ] && sysctl
-w dev.
"$phy".txantenna
="$anttx" >&-
190 [ -n "$softled" ] && sysctl
-w dev.
"$phy".softled
="$softled" >&-
192 config_get distance
"$device" distance
193 [ -n "$distance" ] && sysctl
-w dev.
"$phy".distance
="$distance" >&-
196 local start_hostapd
= vif_txpower
= nosbeacon
=
197 config_get ifname
"$vif" ifname
198 config_get enc
"$vif" encryption
199 config_get eap_type
"$vif" eap_type
200 config_get mode
"$vif" mode
203 sta
) config_get_bool nosbeacon
"$device" nosbeacon
;;
204 adhoc
) config_get_bool nosbeacon
"$vif" sw_merge
1;;
207 [ "$nosbeacon" = 1 ] || nosbeacon
=""
208 ifname
=$
(wlanconfig
"$ifname" create wlandev
"$phy" wlanmode
"$mode" ${nosbeacon:+nosbeacon})
210 echo "enable_atheros($device): Failed to set up $mode vif $ifname" >&2
213 config_set
"$vif" ifname
"$ifname"
215 config_get hwmode
"$device" hwmode
216 [ -z "$hwmode" ] && config_get hwmode
"$device" mode
222 *g
) hwmode
=11g
; pureg
=1;;
230 iwpriv
"$ifname" mode
"$hwmode"
231 iwpriv
"$ifname" pureg
"$pureg"
233 iwconfig
"$ifname" channel
"$channel" >/dev
/null
2>/dev
/null
235 config_get_bool hidden
"$vif" hidden
0
236 iwpriv
"$ifname" hide_ssid
"$hidden"
238 config_get ff
"$vif" ff
239 if [ -n "$ff" ]; then
240 iwpriv
"$ifname" ff
"$ff"
243 config_get wds
"$vif" wds
245 1|on|enabled
) wds
=1;;
248 iwpriv
"$ifname" wds
"$wds" >/dev
/null
2>&1
250 [ "$mode" = ap
-a "$wds" = 1 ] && {
251 config_get_bool wdssep
"$vif" wdssep
1
252 [ -n "$wdssep" ] && iwpriv
"$ifname" wdssep
"$wdssep"
258 *shared
*) iwpriv
"$ifname" authmode
2;;
259 *) iwpriv
"$ifname" authmode
1;;
261 for idx
in 1 2 3 4; do
262 config_get key
"$vif" "key${idx}"
263 iwconfig
"$ifname" enc
"[$idx]" "${key:-off}"
265 config_get key
"$vif" key
268 [1234]) iwconfig
"$ifname" enc
"[$key]";;
269 *) iwconfig
"$ifname" enc
"$key";;
274 config_get key
"$vif" key
280 config_get addr
"$vif" bssid
282 iwconfig
"$ifname" ap
"$addr"
287 config_get_bool uapsd
"$vif" uapsd
0
288 iwpriv
"$ifname" uapsd
"$uapsd"
290 config_get_bool bgscan
"$vif" bgscan
291 [ -n "$bgscan" ] && iwpriv
"$ifname" bgscan
"$bgscan"
293 config_get rate
"$vif" rate
294 [ -n "$rate" ] && iwconfig
"$ifname" rate
"${rate%%.*}"
296 config_get mcast_rate
"$vif" mcast_rate
297 [ -n "$mcast_rate" ] && iwpriv
"$ifname" mcast_rate
"${mcast_rate%%.*}"
299 config_get frag
"$vif" frag
300 [ -n "$frag" ] && iwconfig
"$ifname" frag
"${frag%%.*}"
302 config_get rts
"$vif" rts
303 [ -n "$rts" ] && iwconfig
"$ifname" rts
"${rts%%.*}"
305 config_get_bool comp
"$vif" compression
0
306 iwpriv
"$ifname" compression
"$comp" >/dev
/null
2>&1
308 config_get minrate
"$vif" minrate
309 [ -n "$minrate" ] && iwpriv
"$ifname" minrate
"$minrate"
311 config_get maxrate
"$vif" maxrate
312 [ -n "$maxrate" ] && iwpriv
"$ifname" maxrate
"$maxrate"
314 config_get_bool burst
"$vif" bursting
315 [ -n "$burst" ] && iwpriv
"$ifname" burst
"$burst"
317 config_get_bool wmm
"$vif" wmm
318 [ -n "$wmm" ] && iwpriv
"$ifname" wmm
"$wmm"
320 config_get_bool xr
"$vif" xr
321 [ -n "$xr" ] && iwpriv
"$ifname" xr
"$xr"
323 config_get_bool
ar "$vif" ar
324 [ -n "$ar" ] && iwpriv
"$ifname" ar "$ar"
326 config_get_bool beacon_power
"$vif" beacon_power
327 [ -n "$beacon_power" ] && iwpriv
"$ifname" beacon_pwr
"$beacon_power"
329 config_get_bool doth
"$vif" doth
0
330 [ -n "$doth" ] && iwpriv
"$ifname" doth
"$doth"
332 config_get_bool probereq
"$vif" probereq
333 [ -n "$probereq" ] && iwpriv
"$ifname" probereq
"$probereq"
335 config_get maclist
"$vif" maclist
336 [ -n "$maclist" ] && {
338 iwpriv
"$ifname" maccmd
3
339 for mac
in $maclist; do
340 iwpriv
"$ifname" addmac
"$mac"
344 config_get macpolicy
"$vif" macpolicy
347 iwpriv
"$ifname" maccmd
1
350 iwpriv
"$ifname" maccmd
2
353 # default deny policy if mac list exists
354 [ -n "$maclist" ] && iwpriv
"$ifname" maccmd
2
358 ifconfig
"$ifname" up
361 net_cfg
="$(find_net_config "$vif")"
362 [ -z "$net_cfg" ] ||
{
363 bridge
="$(bridge_interface "$net_cfg")"
364 config_set
"$vif" bridge
"$bridge"
365 start_net
"$ifname" "$net_cfg"
368 config_get ssid
"$vif" ssid
370 iwconfig
"$ifname" essid on
371 iwconfig
"$ifname" essid
${ssid:+-- }"$ssid"
374 set_wifi_up
"$vif" "$ifname"
376 # TXPower settings only work if device is up already
377 # while atheros hardware theoretically is capable of per-vif (even per-packet) txpower
378 # adjustment it does not work with the current atheros hal/madwifi driver
380 config_get vif_txpower
"$vif" txpower
381 # use vif_txpower (from wifi-iface) instead of txpower (from wifi-device) if
382 # the latter doesn't exist
383 txpower
="${txpower:-$vif_txpower}"
384 [ -z "$txpower" ] || iwconfig
"$ifname" txpower
"${txpower%%.*}"
388 config_get_bool isolate
"$vif" isolate
0
389 iwpriv
"$ifname" ap_bridge
"$((isolate^1))"
391 if [ -n "$start_hostapd" ] && eval "type hostapd_setup_vif" 2>/dev
/null
>/dev
/null
; then
392 hostapd_setup_vif
"$vif" madwifi ||
{
393 echo "enable_atheros($device): Failed to set up hostapd for interface $ifname" >&2
394 # make sure this wifi interface won't accidentally stay open without encryption
395 ifconfig
"$ifname" down
396 wlanconfig
"$ifname" destroy
402 if eval "type wpa_supplicant_setup_vif" 2>/dev
/null
>/dev
/null
; then
403 wpa_supplicant_setup_vif
"$vif" madwifi ||
{
404 echo "enable_atheros($device): Failed to set up wpa_supplicant for interface $ifname" >&2
405 ifconfig
"$ifname" down
406 wlanconfig
"$ifname" destroy
415 check_atheros_device
() {
416 [ ${1%[0-9]} = "wifi" ] && config_set
"$1" phy
"$1"
417 config_get phy
"$1" phy
419 find_atheros_phy
"$1" >/dev
/null ||
return 0
420 config_get phy
"$1" phy
422 [ "$phy" = "$dev" ] && found
=1
430 config_get
type "radio$devidx" type
431 [ -n "$type" ] ||
break
432 devidx
=$
(($devidx + 1))
436 for dev
in $
(ls -d wifi
* 2>&-); do
438 config_foreach check_atheros_device wifi-device
439 [ "$found" -gt 0 ] && continue
441 devname
="$(cat /proc/sys/dev/$dev/dev_name)"
445 # Ubiquiti NanoStation Loco2 features
446 option antenna vertical # (horizontal|vertical)
451 # Ubiquiti NanoStation Loco5 features
452 option antenna auto # (auto|horizontal|vertical)
457 # Ubiquiti NanoStation features
458 option antenna auto # (auto|horizontal|vertical|external)
464 config wifi-device radio$devidx
467 option macaddr $(cat /sys/class/net/${dev}/address)
469 # REMOVE THIS LINE TO ENABLE WIFI:
473 option device radio$devidx
477 option encryption none
480 devidx
=$
(($devidx + 1))