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
33 [ ${device%[0-9]} = "wifi" ] && config_set
"$device" phy
"$device"
35 config_get vifs
"$device" vifs
38 config_get ifname
"$vif" ifname
39 config_set
"$vif" ifname
"${ifname:-ath}"
41 config_get mode
"$vif" mode
43 adhoc|ahdemo|sta|ap|monitor
)
47 config_get ssid
"$vif" ssid
48 [ -z "$ssid" ] && continue
50 config_set
"$vif" wds
1
51 config_set
"$vif" mode sta
54 ${addr:+append $mode "$vif"}
56 *) echo "$device($vif): Invalid mode, ignored."; continue;;
60 case "${adhoc:+1}:${sta:+1}:${ap:+1}" in
61 # valid mode combinations
64 :1:1)config_set
"$device" nosbeacon
1;; # AP+STA, can't use beacon timers for STA
68 *) echo "$device: Invalid mode combination in config"; return 1;;
71 config_set
"$device" vifs
"${sta:+$sta }${ap:+$ap }${adhoc:+$adhoc }${ahdemo:+$ahdemo }${wds:+$wds }${monitor:+$monitor}"
78 find_atheros_phy
"$device" ||
return 0
79 config_get phy
"$device" phy
81 set_wifi_down
"$device"
86 grep "$phy" "$dev/%parent" >/dev
/null
2>/dev
/null
&& {
87 [ -f "/var/run/wifi-${dev}.pid" ] &&
88 kill "$(cat "/var
/run
/wifi-
${dev}.pid
")"
91 wlanconfig
"$dev" destroy
100 find_atheros_phy
"$device" ||
return 0
101 config_get phy
"$device" phy
103 config_get regdomain
"$device" regdomain
104 [ -n "$regdomain" ] && echo "$regdomain" > /proc
/sys
/dev
/$phy/regdomain
106 config_get country
"$device" country
107 [ -z "$country" ] && country
="0"
108 echo "$country" > /proc
/sys
/dev
/$phy/countrycode
110 config_get_bool outdoor
"$device" outdoor
"0"
111 echo "$outdoor" > /proc
/sys
/dev
/$phy/outdoor
113 config_get channel
"$device" channel
114 config_get vifs
"$device" vifs
115 config_get txpower
"$device" txpower
117 [ auto
= "$channel" ] && channel
=0
119 config_get_bool antdiv
"$device" diversity
120 config_get antrx
"$device" rxantenna
121 config_get anttx
"$device" txantenna
122 config_get_bool softled
"$device" softled
123 config_get antenna
"$device" antenna
125 devname
="$(cat /proc/sys/dev/$phy/dev_name)"
129 NanoStation2
) antgpio
=7; invert
=1;;
130 NanoStation5
) antgpio
=1; invert
=1;;
131 "NanoStation Loco2") antgpio
=2;;
134 horizontal
) antdiv
=0; anttx
=1; antrx
=1;;
135 vertical
) antdiv
=0; anttx
=2; antrx
=2;;
136 *) antdiv
=1; anttx
=0; antrx
=0;;
140 if [ -n "$invert" ]; then
147 if [ -n "$antgpio" ]; then
155 horizontal
) gpioval
=0;;
161 external
) antdiv
=0; antrx
=1; anttx
=1; gpioval
=1;;
162 horizontal
) antdiv
=0; antrx
=1; anttx
=1; gpioval
=0;;
163 vertical
) antdiv
=0; antrx
=2; anttx
=2; gpioval
=0;;
164 auto
) antdiv
=1; antrx
=0; anttx
=0; gpioval
=0;;
169 [ -x "$(which gpioctl 2>/dev/null)" ] || antenna
=
170 gpioctl
"dirout" "$antgpio" >/dev
/null
2>&1
173 gpioctl
"$_clear" "$antgpio" >/dev
/null
2>&1
176 gpioctl
"$_set" "$antgpio" >/dev
/null
2>&1
181 [ -n "$antdiv" ] && sysctl
-w dev.
"$phy".diversity
="$antdiv" >&-
182 [ -n "$antrx" ] && sysctl
-w dev.
"$phy".rxantenna
="$antrx" >&-
183 [ -n "$anttx" ] && sysctl
-w dev.
"$phy".txantenna
="$anttx" >&-
184 [ -n "$softled" ] && sysctl
-w dev.
"$phy".softled
="$softled" >&-
186 config_get distance
"$device" distance
187 [ -n "$distance" ] && sysctl
-w dev.
"$phy".distance
="$distance" >&-
190 local start_hostapd
= vif_txpower
= nosbeacon
=
191 config_get ifname
"$vif" ifname
192 config_get enc
"$vif" encryption
193 config_get eap_type
"$vif" eap_type
194 config_get mode
"$vif" mode
197 sta
) config_get_bool nosbeacon
"$device" nosbeacon
;;
198 adhoc
) config_get_bool nosbeacon
"$vif" sw_merge
1;;
201 [ "$nosbeacon" = 1 ] || nosbeacon
=""
202 ifname
=$
(wlanconfig
"$ifname" create wlandev
"$phy" wlanmode
"$mode" ${nosbeacon:+nosbeacon})
204 echo "enable_atheros($device): Failed to set up $mode vif $ifname" >&2
207 config_set
"$vif" ifname
"$ifname"
209 config_get hwmode
"$device" hwmode
210 [ -z "$hwmode" ] && config_get hwmode
"$device" mode
216 *g
) hwmode
=11g
; pureg
=1;;
224 iwpriv
"$ifname" mode
"$hwmode"
225 iwpriv
"$ifname" pureg
"$pureg"
227 iwconfig
"$ifname" channel
"$channel" >/dev
/null
2>/dev
/null
229 config_get_bool hidden
"$vif" hidden
0
230 iwpriv
"$ifname" hide_ssid
"$hidden"
232 config_get ff
"$vif" ff
233 if [ -n "$ff" ]; then
234 iwpriv
"$ifname" ff
"$ff"
237 config_get wds
"$vif" wds
239 1|on|enabled
) wds
=1;;
242 iwpriv
"$ifname" wds
"$wds" >/dev
/null
2>&1
244 [ "$mode" = ap
-a "$wds" = 1 ] && {
245 config_get_bool wdssep
"$vif" wdssep
1
246 [ -n "$wdssep" ] && iwpriv
"$ifname" wdssep
"$wdssep"
252 *shared
*) iwpriv
"$ifname" authmode
2;;
253 *) iwpriv
"$ifname" authmode
1;;
255 for idx
in 1 2 3 4; do
256 config_get key
"$vif" "key${idx}"
257 iwconfig
"$ifname" enc
"[$idx]" "${key:-off}"
259 config_get key
"$vif" key
262 [1234]) iwconfig
"$ifname" enc
"[$key]";;
263 *) iwconfig
"$ifname" enc
"$key";;
268 config_get key
"$vif" key
274 config_get addr
"$vif" bssid
276 iwconfig
"$ifname" ap
"$addr"
281 config_get_bool uapsd
"$vif" uapsd
0
282 iwpriv
"$ifname" uapsd
"$uapsd"
284 config_get_bool bgscan
"$vif" bgscan
285 [ -n "$bgscan" ] && iwpriv
"$ifname" bgscan
"$bgscan"
287 config_get rate
"$vif" rate
288 [ -n "$rate" ] && iwconfig
"$ifname" rate
"${rate%%.*}"
290 config_get mcast_rate
"$vif" mcast_rate
291 [ -n "$mcast_rate" ] && iwpriv
"$ifname" mcast_rate
"${mcast_rate%%.*}"
293 config_get frag
"$vif" frag
294 [ -n "$frag" ] && iwconfig
"$ifname" frag
"${frag%%.*}"
296 config_get rts
"$vif" rts
297 [ -n "$rts" ] && iwconfig
"$ifname" rts
"${rts%%.*}"
299 config_get_bool comp
"$vif" compression
0
300 iwpriv
"$ifname" compression
"$comp" >/dev
/null
2>&1
302 config_get_bool minrate
"$vif" minrate
303 [ -n "$minrate" ] && iwpriv
"$ifname" minrate
"$minrate"
305 config_get_bool maxrate
"$vif" maxrate
306 [ -n "$maxrate" ] && iwpriv
"$ifname" maxrate
"$maxrate"
308 config_get_bool burst
"$vif" bursting
309 [ -n "$burst" ] && iwpriv
"$ifname" burst
"$burst"
311 config_get_bool wmm
"$vif" wmm
312 [ -n "$wmm" ] && iwpriv
"$ifname" wmm
"$wmm"
314 config_get_bool xr
"$vif" xr
315 [ -n "$xr" ] && iwpriv
"$ifname" xr
"$xr"
317 config_get_bool
ar "$vif" ar
318 [ -n "$ar" ] && iwpriv
"$ifname" ar "$ar"
320 config_get_bool beacon_power
"$vif" beacon_power
321 [ -n "$beacon_power" ] && iwpriv
"$ifname" beacon_pwr
"$beacon_power"
323 config_get_bool doth
"$vif" doth
0
324 [ -n "$doth" ] && iwpriv
"$ifname" doth
"$doth"
326 config_get_bool probereq
"$vif" probereq
327 [ -n "$probereq" ] && iwpriv
"$ifname" probereq
"$probereq"
329 config_get maclist
"$vif" maclist
330 [ -n "$maclist" ] && {
332 iwpriv
"$ifname" maccmd
3
333 for mac
in $maclist; do
334 iwpriv
"$ifname" addmac
"$mac"
338 config_get macpolicy
"$vif" macpolicy
341 iwpriv
"$ifname" maccmd
1
344 iwpriv
"$ifname" maccmd
2
347 # default deny policy if mac list exists
348 [ -n "$maclist" ] && iwpriv
"$ifname" maccmd
2
352 ifconfig
"$ifname" up
355 net_cfg
="$(find_net_config "$vif")"
356 [ -z "$net_cfg" ] ||
{
357 bridge
="$(bridge_interface "$net_cfg")"
358 config_set
"$vif" bridge
"$bridge"
359 start_net
"$ifname" "$net_cfg"
362 config_get ssid
"$vif" ssid
364 iwconfig
"$ifname" essid on
365 iwconfig
"$ifname" essid
"$ssid"
368 set_wifi_up
"$vif" "$ifname"
370 # TXPower settings only work if device is up already
371 # while atheros hardware theoretically is capable of per-vif (even per-packet) txpower
372 # adjustment it does not work with the current atheros hal/madwifi driver
374 config_get vif_txpower
"$vif" txpower
375 # use vif_txpower (from wifi-iface) instead of txpower (from wifi-device) if
376 # the latter doesn't exist
377 txpower
="${txpower:-$vif_txpower}"
378 [ -z "$txpower" ] || iwconfig
"$ifname" txpower
"${txpower%%.*}"
382 config_get_bool isolate
"$vif" isolate
0
383 iwpriv
"$ifname" ap_bridge
"$((isolate^1))"
385 if [ -n "$start_hostapd" ] && eval "type hostapd_setup_vif" 2>/dev
/null
>/dev
/null
; then
386 hostapd_setup_vif
"$vif" madwifi ||
{
387 echo "enable_atheros($device): Failed to set up hostapd for interface $ifname" >&2
388 # make sure this wifi interface won't accidentally stay open without encryption
389 ifconfig
"$ifname" down
390 wlanconfig
"$ifname" destroy
396 if eval "type wpa_supplicant_setup_vif" 2>/dev
/null
>/dev
/null
; then
397 wpa_supplicant_setup_vif
"$vif" madwifi ||
{
398 echo "enable_atheros($device): Failed to set up wpa_supplicant for interface $ifname" >&2
399 ifconfig
"$ifname" down
400 wlanconfig
"$ifname" destroy
409 check_atheros_device
() {
410 [ ${1%[0-9]} = "wifi" ] && config_set
"$1" phy
"$1"
411 config_get phy
"$1" phy
413 find_atheros_phy
"$1" >/dev
/null ||
return 0
414 config_get phy
"$1" phy
416 [ "$phy" = "$dev" ] && found
=1
424 config_get
type "radio$devidx" type
425 [ -n "$type" ] ||
break
426 devidx
=$
(($devidx + 1))
430 for dev
in $
(ls -d wifi
* 2>&-); do
432 config_foreach check_atheros_device wifi-device
433 [ "$found" -gt 0 ] && continue
435 devname
="$(cat /proc/sys/dev/$dev/dev_name)"
439 # Ubiquiti NanoStation Loco2 features
440 option antenna vertical # (horizontal|vertical)
445 # Ubiquiti NanoStation Loco5 features
446 option antenna auto # (auto|horizontal|vertical)
451 # Ubiquiti NanoStation features
452 option antenna auto # (auto|horizontal|vertical|external)
458 config wifi-device radio$devidx
461 option macaddr $(cat /sys/class/net/${dev}/address)
463 # REMOVE THIS LINE TO ENABLE WIFI:
467 option device radio$devidx
471 option encryption none
474 devidx
=$
(($devidx + 1))