madwifi: only set the desired mode for the first vap
[openwrt/svn-archive/archive.git] / package / madwifi / files / lib / wifi / madwifi.sh
index 1b86c2603b731a07bbf9cfbc0e1cb9ad97359b70..0124285d08bb24b8a14098827e1f580ab858b808 100755 (executable)
@@ -67,14 +67,24 @@ disable_atheros() (
 
 enable_atheros() {
        local device="$1"
+       # Can only set the country code to one setting for the entire system. The last country code is the one that will be applied.
+       config_get country "$device" country
+       [ -z "$country" ] && country="0"
+       local cc="0"
+       [ -e /proc/sys/dev/$device/countrycode ] && cc="$(cat /proc/sys/dev/$device/countrycode)"
+       if [ ! "$cc" = "$country" ] ; then
+               rmmod ath_pci
+               insmod ath_pci countrycode=$country
+       fi
        config_get channel "$device" channel
        config_get vifs "$device" vifs
+       config_get txpower "$device" txpower
 
        [ auto = "$channel" ] && channel=0
 
        local first=1
        for vif in $vifs; do
-               local start_hostapd
+               local start_hostapd vif_txpower
                nosbeacon=
                config_get ifname "$vif" ifname
                config_get enc "$vif" encryption
@@ -110,10 +120,10 @@ enable_atheros() {
                        *fh) hwmode=fh;;
                        *) hwmode=auto;;
                esac
-               iwpriv "$ifname" mode "$hwmode"
                iwpriv "$ifname" pureg "$pureg"
 
                [ "$first" = 1 ] && {
+                       iwpriv "$ifname" mode "$hwmode"
                        iwconfig "$ifname" channel "$channel" >/dev/null 2>/dev/null 
                }
        
@@ -247,9 +257,15 @@ enable_atheros() {
                config_get_bool turbo "$vif" turbo
                [ -n "$turbo" ] && iwpriv "$ifname" turbo "$turbo"
 
+               config_get_bool beacon_power "$vif" beacon_power
+               [ -n "$beacon_power" ] && iwpriv "$ifname" beacon_pwr "$beacon_power"
+
                config_get_bool doth "$vif" doth 0
                [ -n "$doth" ] && iwpriv "$ifname" doth "$doth"
 
+               config_get_bool probereq "$vif" probereq
+               [ -n "$probereq" ] && iwpriv "$ifname" probereq "$probereq"
+
                config_get maclist "$vif" maclist
                [ -n "$maclist" ] && {
                        # flush MAC list
@@ -275,10 +291,6 @@ enable_atheros() {
 
                ifconfig "$ifname" up
 
-               # TXPower settings only work if device is up already
-               config_get txpwr "$vif" txpower
-               [ -n "$txpwr" ] && iwconfig "$ifname" txpower "${txpwr%%.*}"
-
                local net_cfg bridge
                net_cfg="$(find_net_config "$vif")"
                [ -z "$net_cfg" ] || {
@@ -289,6 +301,17 @@ enable_atheros() {
                [ -n "$ssid" ] && iwconfig "$ifname" essid on
                iwconfig "$ifname" essid "$ssid"
                set_wifi_up "$vif" "$ifname"
+
+               # TXPower settings only work if device is up already
+               # while atheros hardware theoretically is capable of per-vif (even per-packet) txpower
+               # adjustment it does not work with the current atheros hal/madwifi driver
+
+               config_get vif_txpower "$vif" txpower
+               # use vif_txpower (from wifi-iface) instead of txpower (from wifi-device) if
+               # the latter doesn't exist
+               txpower="${txpower:-$vif_txpower}"
+               [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
+
                case "$mode" in
                        ap)
                                config_get_bool isolate "$vif" isolate 0