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
108 [A-Za-z]*) country=`grep -i "$country" /lib/wifi/madwifi_countrycodes.txt |cut -d " " -f 2`;;
112 [ -n "$country" ] && echo "$country" > /proc/sys/dev/$phy/countrycode
114 config_get_bool outdoor "$device" outdoor "0"
115 echo "$outdoor" > /proc/sys/dev/$phy/outdoor
117 config_get channel "$device" channel
118 config_get vifs "$device" vifs
119 config_get txpower "$device" txpower
121 [ auto = "$channel" ] && channel=0
123 config_get_bool antdiv "$device" diversity
124 config_get antrx "$device" rxantenna
125 config_get anttx "$device" txantenna
126 config_get_bool softled "$device" softled
127 config_get antenna "$device" antenna
129 devname="$(cat /proc/sys/dev/$phy/dev_name)"
133 NanoStation2) antgpio=7; invert=1;;
134 NanoStation5) antgpio=1; invert=1;;
135 "NanoStation Loco2") antgpio=2;;
138 horizontal) antdiv=0; anttx=1; antrx=1;;
139 vertical) antdiv=0; anttx=2; antrx=2;;
140 *) antdiv=1; anttx=0; antrx=0;;
144 if [ -n "$invert" ]; then
151 if [ -n "$antgpio" ]; then
159 horizontal) gpioval=0;;
165 external) antdiv=0; antrx=1; anttx=1; gpioval=1;;
166 horizontal) antdiv=0; antrx=1; anttx=1; gpioval=0;;
167 vertical) antdiv=0; antrx=2; anttx=2; gpioval=0;;
168 auto) antdiv=1; antrx=0; anttx=0; gpioval=0;;
173 [ -x "$(which gpioctl 2>/dev/null)" ] || antenna=
174 gpioctl "dirout" "$antgpio" >/dev/null 2>&1
177 gpioctl "$_clear" "$antgpio" >/dev/null 2>&1
180 gpioctl "$_set" "$antgpio" >/dev/null 2>&1
185 [ -n "$antdiv" ] && sysctl -w dev."$phy".diversity="$antdiv" >&-
186 [ -n "$antrx" ] && sysctl -w dev."$phy".rxantenna="$antrx" >&-
187 [ -n "$anttx" ] && sysctl -w dev."$phy".txantenna="$anttx" >&-
188 [ -n "$softled" ] && sysctl -w dev."$phy".softled="$softled" >&-
190 config_get distance "$device" distance
191 [ -n "$distance" ] && sysctl -w dev."$phy".distance="$distance" >&-
194 local start_hostapd= vif_txpower= nosbeacon=
195 config_get ifname "$vif" ifname
196 config_get enc "$vif" encryption
197 config_get eap_type "$vif" eap_type
198 config_get mode "$vif" mode
201 sta) config_get_bool nosbeacon "$device" nosbeacon;;
202 adhoc) config_get_bool nosbeacon "$vif" sw_merge 1;;
205 [ "$nosbeacon" = 1 ] || nosbeacon=""
206 ifname=$(wlanconfig "$ifname" create wlandev "$phy" wlanmode "$mode" ${nosbeacon:+nosbeacon})
208 echo "enable_atheros($device): Failed to set up $mode vif $ifname" >&2
211 config_set "$vif" ifname "$ifname"
213 config_get hwmode "$device" hwmode
214 [ -z "$hwmode" ] && config_get hwmode "$device" mode
220 *g) hwmode=11g; pureg=1;;
228 iwpriv "$ifname" mode "$hwmode"
229 iwpriv "$ifname" pureg "$pureg"
231 iwconfig "$ifname" channel "$channel" >/dev/null 2>/dev/null
233 config_get_bool hidden "$vif" hidden 0
234 iwpriv "$ifname" hide_ssid "$hidden"
236 config_get ff "$vif" ff
237 if [ -n "$ff" ]; then
238 iwpriv "$ifname" ff "$ff"
241 config_get wds "$vif" wds
243 1|on|enabled) wds=1;;
246 iwpriv "$ifname" wds "$wds" >/dev/null 2>&1
248 [ "$mode" = ap -a "$wds" = 1 ] && {
249 config_get_bool wdssep "$vif" wdssep 1
250 [ -n "$wdssep" ] && iwpriv "$ifname" wdssep "$wdssep"
256 *shared*) iwpriv "$ifname" authmode 2;;
257 *) iwpriv "$ifname" authmode 1;;
259 for idx in 1 2 3 4; do
260 config_get key "$vif" "key${idx}"
261 iwconfig "$ifname" enc "[$idx]" "${key:-off}"
263 config_get key "$vif" key
266 [1234]) iwconfig "$ifname" enc "[$key]";;
267 *) iwconfig "$ifname" enc "$key";;
272 config_get key "$vif" key
278 config_get addr "$vif" bssid
280 iwconfig "$ifname" ap "$addr"
285 config_get_bool uapsd "$vif" uapsd 0
286 iwpriv "$ifname" uapsd "$uapsd"
288 config_get_bool bgscan "$vif" bgscan
289 [ -n "$bgscan" ] && iwpriv "$ifname" bgscan "$bgscan"
291 config_get rate "$vif" rate
292 [ -n "$rate" ] && iwconfig "$ifname" rate "${rate%%.*}"
294 config_get mcast_rate "$vif" mcast_rate
295 [ -n "$mcast_rate" ] && iwpriv "$ifname" mcast_rate "${mcast_rate%%.*}"
297 config_get frag "$vif" frag
298 [ -n "$frag" ] && iwconfig "$ifname" frag "${frag%%.*}"
300 config_get rts "$vif" rts
301 [ -n "$rts" ] && iwconfig "$ifname" rts "${rts%%.*}"
303 config_get_bool comp "$vif" compression 0
304 iwpriv "$ifname" compression "$comp" >/dev/null 2>&1
306 config_get minrate "$vif" minrate
307 [ -n "$minrate" ] && iwpriv "$ifname" minrate "$minrate"
309 config_get maxrate "$vif" maxrate
310 [ -n "$maxrate" ] && iwpriv "$ifname" maxrate "$maxrate"
312 config_get_bool burst "$vif" bursting
313 [ -n "$burst" ] && iwpriv "$ifname" burst "$burst"
315 config_get_bool wmm "$vif" wmm
316 [ -n "$wmm" ] && iwpriv "$ifname" wmm "$wmm"
318 config_get_bool xr "$vif" xr
319 [ -n "$xr" ] && iwpriv "$ifname" xr "$xr"
321 config_get_bool ar "$vif" ar
322 [ -n "$ar" ] && iwpriv "$ifname" ar "$ar"
324 config_get_bool beacon_power "$vif" beacon_power
325 [ -n "$beacon_power" ] && iwpriv "$ifname" beacon_pwr "$beacon_power"
327 config_get_bool doth "$vif" doth 0
328 [ -n "$doth" ] && iwpriv "$ifname" doth "$doth"
330 config_get_bool probereq "$vif" probereq
331 [ -n "$probereq" ] && iwpriv "$ifname" probereq "$probereq"
333 config_get maclist "$vif" maclist
334 [ -n "$maclist" ] && {
336 iwpriv "$ifname" maccmd 3
337 for mac in $maclist; do
338 iwpriv "$ifname" addmac "$mac"
342 config_get macpolicy "$vif" macpolicy
345 iwpriv "$ifname" maccmd 1
348 iwpriv "$ifname" maccmd 2
351 # default deny policy if mac list exists
352 [ -n "$maclist" ] && iwpriv "$ifname" maccmd 2
356 ifconfig "$ifname" up
359 net_cfg="$(find_net_config "$vif")"
360 [ -z "$net_cfg" ] || {
361 bridge="$(bridge_interface "$net_cfg")"
362 config_set "$vif" bridge "$bridge"
363 start_net "$ifname" "$net_cfg"
366 config_get ssid "$vif" ssid
368 iwconfig "$ifname" essid on
369 iwconfig "$ifname" essid ${ssid:+-- }"$ssid"
372 set_wifi_up "$vif" "$ifname"
374 # TXPower settings only work if device is up already
375 # while atheros hardware theoretically is capable of per-vif (even per-packet) txpower
376 # adjustment it does not work with the current atheros hal/madwifi driver
378 config_get vif_txpower "$vif" txpower
379 # use vif_txpower (from wifi-iface) instead of txpower (from wifi-device) if
380 # the latter doesn't exist
381 txpower="${txpower:-$vif_txpower}"
382 [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
386 config_get_bool isolate "$vif" isolate 0
387 iwpriv "$ifname" ap_bridge "$((isolate^1))"
389 if [ -n "$start_hostapd" ] && eval "type hostapd_setup_vif" 2>/dev/null >/dev/null; then
390 hostapd_setup_vif "$vif" madwifi || {
391 echo "enable_atheros($device): Failed to set up hostapd for interface $ifname" >&2
392 # make sure this wifi interface won't accidentally stay open without encryption
393 ifconfig "$ifname" down
394 wlanconfig "$ifname" destroy
400 if eval "type wpa_supplicant_setup_vif" 2>/dev/null >/dev/null; then
401 wpa_supplicant_setup_vif "$vif" madwifi || {
402 echo "enable_atheros($device): Failed to set up wpa_supplicant for interface $ifname" >&2
403 ifconfig "$ifname" down
404 wlanconfig "$ifname" destroy
413 check_atheros_device() {
414 [ ${1%[0-9]} = "wifi" ] && config_set "$1" phy "$1"
415 config_get phy "$1" phy
417 find_atheros_phy "$1" >/dev/null || return 0
418 config_get phy "$1" phy
420 [ "$phy" = "$dev" ] && found=1
428 config_get type "radio$devidx" type
429 [ -n "$type" ] || break
430 devidx=$(($devidx + 1))
434 for dev in $(ls -d wifi* 2>&-); do
436 config_foreach check_atheros_device wifi-device
437 [ "$found" -gt 0 ] && continue
439 devname="$(cat /proc/sys/dev/$dev/dev_name)"
443 # Ubiquiti NanoStation Loco2 features
444 option antenna vertical # (horizontal|vertical)
449 # Ubiquiti NanoStation Loco5 features
450 option antenna auto # (auto|horizontal|vertical)
455 # Ubiquiti NanoStation features
456 option antenna auto # (auto|horizontal|vertical|external)
462 config wifi-device radio$devidx
465 option macaddr $(cat /sys/class/net/${dev}/address)
467 # REMOVE THIS LINE TO ENABLE WIFI:
471 option device radio$devidx
475 option encryption none
478 devidx=$(($devidx + 1))