Simplify antenna selection and remove the need for gpioctl for the nanostation2.
[openwrt.git] / package / madwifi / files / lib / wifi / madwifi.sh
index e4e9982..4bb5be5 100755 (executable)
@@ -174,20 +174,56 @@ enable_atheros() {
                [ -n "$bgscan" ] && iwpriv "$ifname" bgscan "$bgscan"
 
                config_get_bool antdiv "$device" diversity
-               [ -n "$antdiv" ] && sysctl -w dev."$device".diversity="$antdiv" >&-
-
                config_get antrx "$device" rxantenna
-               [ -n "$antrx" ] && sysctl -w dev."$device".rxantenna="$antrx" >&-
-
                config_get anttx "$device" txantenna
+               config_get_bool softled "$device" softled 1
+               config_get_bool gpioctl "$device" gpioctl
+
+               devname="$(cat /proc/sys/dev/$device/dev_name)"
+               antgpio=
+               case "$devname" in
+                       NanoStation2) antgpio=wifi; [ -n "$gpioctl" ] && gpioctl=0;;
+                       NanoStation5) antgpio=1;;
+               esac
+               if [ -n "$antgpio" ]; then
+                       softled=0
+                       config_get antenna "$device" antenna
+                       case "$antenna" in
+                               external) antdiv=0; antrx=1; anttx=1 ;;
+                               horizontal) antdiv=0; antrx=1; anttx=1 ;;
+                               vertical) antdiv=0; antrx=2; anttx=2 ;;
+                               auto) antdiv=1; antrx=0; anttx=0 ;;
+                       esac
+                       
+                       [ -x "$(which gpioctl 2>/dev/null)" ] || antenna=
+                       case "$antenna" in
+                               horizontal|vertical|auto)
+                                       if [ "$gpioctl" = "0" ]; then
+                                               echo 0 >/sys/class/leds/$antgpio/brightness 2>&1
+                                       else
+                                               gpioctl "dirout" "$antgpio" >/dev/null 2>&1
+                                               gpioctl "set" "$antgpio" >/dev/null 2>&1
+                                       fi
+                               ;;
+                               external)
+                                       if [ "$gpioctl" = "0" ]; then
+                                               echo 0 >/sys/class/leds/$antgpio/brightness
+                                       else
+                                               gpioctl "dirout" "$antgpio" >/dev/null 2>&1
+                                               gpioctl "clear" "$antgpio" >/dev/null 2>&1
+                                       fi
+                               ;;
+                       esac
+               fi
+
+               [ -n "$antdiv" ] && sysctl -w dev."$device".diversity="$antdiv" >&-
+               [ -n "$antrx" ] && sysctl -w dev."$device".rxantenna="$antrx" >&-
                [ -n "$anttx" ] && sysctl -w dev."$device".txantenna="$anttx" >&-
+               [ -n "$softled" ] && sysctl -w dev."$device".softled="$softled" >&-
 
                config_get distance "$device" distance
                [ -n "$distance" ] && athctrl -i "$device" -d "$distance" >&-
 
-               config_get_bool softled "$device" softled 1
-               [ -n "$softled" ] && sysctl -w dev."$device".softled="$softled" >&-
-
                config_get txpwr "$vif" txpower
                [ -n "$txpwr" ] && iwconfig "$ifname" txpower "${txpwr%%.*}"
 
@@ -300,12 +336,22 @@ detect_atheros() {
        [ -d ath ] || return
        for dev in $(ls -d wifi* 2>&-); do
                config_get type "$dev" type
+               devname="$(cat /proc/sys/dev/$dev/dev_name)"
+               case "$devname" in
+                       NanoStation*)
+                               EXTRA_DEV="
+# Ubiquiti NanoStation features
+       option antenna  internal
+       option polarity auto # (auto|horizontal|vertical)
+"
+                       ;;
+               esac
                [ "$type" = atheros ] && return
                cat <<EOF
 config wifi-device  $dev
        option type     atheros
        option channel  auto
-
+$EXTRA_DEV
        # REMOVE THIS LINE TO ENABLE WIFI:
        option disabled 1
 
This page took 0.023946 seconds and 4 git commands to generate.