mac80211: fix handling of frag and rts options, thanks stintel!
[openwrt/staging/wigyori.git] / package / mac80211 / files / lib / wifi / mac80211.sh
index c871cbe7328419a75440e4a2b63434bb17a8f819..f022e262d94c7655e5b755a43e009c54339717c2 100644 (file)
@@ -165,6 +165,14 @@ scan_mac80211() {
        config_set "$device" vifs "${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }${monitor:+$monitor }${mesh:+$mesh}"
 }
 
+list_phy_interfaces() {
+       local phy="$1"
+       if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then
+               ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev/null;
+       else
+               ls "/sys/class/ieee80211/${phy}/device" 2>/dev/null | grep net: | sed -e 's,net:,,g'
+       fi
+}
 
 disable_mac80211() (
        local device="$1"
@@ -181,7 +189,7 @@ disable_mac80211() (
        done
 
        include /lib/network
-       for wdev in $(ls /sys/class/ieee80211/${phy}/device/net 2>/dev/null); do
+       for wdev in $(list_phy_interfaces "$phy"); do
                [ -f "/var/run/$wdev.pid" ] && kill $(cat /var/run/$wdev.pid) >&/dev/null 2>&1
                for pid in `pidof wpa_supplicant`; do
                        grep "$wdev" /proc/$pid/cmdline >/dev/null && \
@@ -206,6 +214,8 @@ enable_mac80211() {
        config_get txpower "$device" txpower
        config_get country "$device" country
        config_get distance "$device" distance
+       config_get frag "$device" frag
+       config_get rts "$device" rts
        find_mac80211_phy "$device" || return 0
        config_get phy "$device" phy
        local i=0
@@ -219,6 +229,8 @@ enable_mac80211() {
        }
 
        [ -n "$distance" ] && iw phy "$phy" set distance "$distance"
+       [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
+       [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
 
        export channel fixed
        # convert channel to frequency
@@ -310,16 +322,6 @@ enable_mac80211() {
                # wifi-device) if the latter doesn't exist
                txpower="${txpower:-$vif_txpower}"
                [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
-
-               config_get frag "$vif" frag
-               if [ -n "$frag" ]; then
-                       iw phy "$phy" set frag "${frag%%.*}"
-               fi
-
-               config_get rts "$vif" rts
-               if [ -n "$rts" ]; then
-                       iw phy "$phy" set rts "${rts%%.*}"
-               fi
        done
 
        local start_hostapd=
@@ -362,7 +364,7 @@ enable_mac80211() {
                                ;;
                                sta)
                                        if eval "type wpa_supplicant_setup_vif" 2>/dev/null >/dev/null; then
-                                               wpa_supplicant_setup_vif "$vif" wext || {
+                                               wpa_supplicant_setup_vif "$vif" nl80211 || {
                                                        echo "enable_mac80211($device): Failed to set up wpa_supplicant for interface $ifname" >&2
                                                        # make sure this wifi interface won't accidentally stay open without encryption
                                                        ifconfig "$ifname" down