Allow changing country code for madwifi driver. Thanks alisonken1
[openwrt/staging/yousong.git] / package / madwifi / files / lib / wifi / madwifi.sh
index db7f057940087a320754eb69f2385d6eb8ddba8c..550bba7e552af968e3996f004c21f0a8ce4bee4f 100755 (executable)
@@ -31,7 +31,7 @@ scan_atheros() {
                esac
        done
 
-       case "${adhoc:+1}:${sta:+1}:${ap+1}" in
+       case "${adhoc:+1}:${sta:+1}:${ap:+1}" in
                # valid mode combinations
                1::) wds="";;
                1::1);;
@@ -67,6 +67,15 @@ 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
 
@@ -250,6 +259,9 @@ enable_atheros() {
                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 +287,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 +297,11 @@ 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
+               config_get txpwr "$vif" txpower
+               [ -n "$txpwr" ] && iwconfig "$ifname" txpower "${txpwr%%.*}"
+
                case "$mode" in
                        ap)
                                config_get_bool isolate "$vif" isolate 0