ipv4: flush route cache after change accept_local
[linux-2.6.git] / net / wireless / wext-compat.c
index 2fa8de1..0bf169b 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/nl80211.h>
 #include <linux/if_arp.h>
 #include <linux/etherdevice.h>
+#include <linux/slab.h>
 #include <net/iw_handler.h>
 #include <net/cfg80211.h>
 #include "wext-compat.h"
@@ -266,9 +267,12 @@ int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)
         * -EINVAL for impossible things.
         */
        if (freq->e == 0) {
+               enum ieee80211_band band = IEEE80211_BAND_2GHZ;
                if (freq->m < 0)
                        return 0;
-               return ieee80211_channel_to_frequency(freq->m);
+               if (freq->m > 14)
+                       band = IEEE80211_BAND_5GHZ;
+               return ieee80211_channel_to_frequency(freq->m, band);
        } else {
                int i, div = 1000000;
                for (i = 0; i < freq->e; i++)
@@ -431,14 +435,17 @@ int cfg80211_wext_giwretry(struct net_device *dev,
 EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);
 
 static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
-                                    struct net_device *dev, const u8 *addr,
-                                    bool remove, bool tx_key, int idx,
-                                    struct key_params *params)
+                                    struct net_device *dev, bool pairwise,
+                                    const u8 *addr, bool remove, bool tx_key,
+                                    int idx, struct key_params *params)
 {
        struct wireless_dev *wdev = dev->ieee80211_ptr;
        int err, i;
        bool rejoin = false;
 
+       if (pairwise && !addr)
+               return -EINVAL;
+
        if (!wdev->wext.keys) {
                wdev->wext.keys = kzalloc(sizeof(*wdev->wext.keys),
                                              GFP_KERNEL);
@@ -477,8 +484,15 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
                                __cfg80211_leave_ibss(rdev, wdev->netdev, true);
                                rejoin = true;
                        }
-                       err = rdev->ops->del_key(&rdev->wiphy, dev, idx, addr);
+
+                       if (!pairwise && addr &&
+                           !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
+                               err = -ENOENT;
+                       else
+                               err = rdev->ops->del_key(&rdev->wiphy, dev, idx,
+                                                        pairwise, addr);
                }
+               wdev->wext.connect.privacy = false;
                /*
                 * Applications using wireless extensions expect to be
                 * able to delete keys that don't exist, so allow that.
@@ -505,12 +519,13 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
        if (addr)
                tx_key = false;
 
-       if (cfg80211_validate_key_settings(rdev, params, idx, addr))
+       if (cfg80211_validate_key_settings(rdev, params, idx, pairwise, addr))
                return -EINVAL;
 
        err = 0;
        if (wdev->current_bss)
-               err = rdev->ops->add_key(&rdev->wiphy, dev, idx, addr, params);
+               err = rdev->ops->add_key(&rdev->wiphy, dev, idx,
+                                        pairwise, addr, params);
        if (err)
                return err;
 
@@ -536,8 +551,8 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
                                __cfg80211_leave_ibss(rdev, wdev->netdev, true);
                                rejoin = true;
                        }
-                       err = rdev->ops->set_default_key(&rdev->wiphy,
-                                                        dev, idx);
+                       err = rdev->ops->set_default_key(&rdev->wiphy, dev,
+                                                        idx, true, true);
                }
                if (!err) {
                        wdev->wext.default_key = idx;
@@ -561,17 +576,17 @@ static int __cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
 }
 
 static int cfg80211_set_encryption(struct cfg80211_registered_device *rdev,
-                                  struct net_device *dev, const u8 *addr,
-                                  bool remove, bool tx_key, int idx,
-                                  struct key_params *params)
+                                  struct net_device *dev, bool pairwise,
+                                  const u8 *addr, bool remove, bool tx_key,
+                                  int idx, struct key_params *params)
 {
        int err;
 
        /* devlist mutex needed for possible IBSS re-join */
        mutex_lock(&rdev->devlist_mtx);
        wdev_lock(dev->ieee80211_ptr);
-       err = __cfg80211_set_encryption(rdev, dev, addr, remove,
-                                       tx_key, idx, params);
+       err = __cfg80211_set_encryption(rdev, dev, pairwise, addr,
+                                       remove, tx_key, idx, params);
        wdev_unlock(dev->ieee80211_ptr);
        mutex_unlock(&rdev->devlist_mtx);
 
@@ -615,8 +630,8 @@ int cfg80211_wext_siwencode(struct net_device *dev,
                err = 0;
                wdev_lock(wdev);
                if (wdev->current_bss)
-                       err = rdev->ops->set_default_key(&rdev->wiphy,
-                                                        dev, idx);
+                       err = rdev->ops->set_default_key(&rdev->wiphy, dev,
+                                                        idx, true, true);
                if (!err)
                        wdev->wext.default_key = idx;
                wdev_unlock(wdev);
@@ -633,7 +648,7 @@ int cfg80211_wext_siwencode(struct net_device *dev,
        else if (!remove)
                return -EINVAL;
 
-       return cfg80211_set_encryption(rdev, dev, NULL, remove,
+       return cfg80211_set_encryption(rdev, dev, false, NULL, remove,
                                       wdev->wext.default_key == -1,
                                       idx, &params);
 }
@@ -723,7 +738,9 @@ int cfg80211_wext_siwencodeext(struct net_device *dev,
        }
 
        return cfg80211_set_encryption(
-                       rdev, dev, addr, remove,
+                       rdev, dev,
+                       !(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY),
+                       addr, remove,
                        ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
                        idx, &params);
 }
@@ -780,16 +797,22 @@ int cfg80211_wext_siwfreq(struct net_device *dev,
                return cfg80211_mgd_wext_siwfreq(dev, info, wextfreq, extra);
        case NL80211_IFTYPE_ADHOC:
                return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
-       default:
+       case NL80211_IFTYPE_MONITOR:
+       case NL80211_IFTYPE_WDS:
+       case NL80211_IFTYPE_MESH_POINT:
                freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
                if (freq < 0)
                        return freq;
                if (freq == 0)
                        return -EINVAL;
                mutex_lock(&rdev->devlist_mtx);
-               err = rdev_set_freq(rdev, NULL, freq, NL80211_CHAN_NO_HT);
+               wdev_lock(wdev);
+               err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT);
+               wdev_unlock(wdev);
                mutex_unlock(&rdev->devlist_mtx);
                return err;
+       default:
+               return -EOPNOTSUPP;
        }
 }
 EXPORT_SYMBOL_GPL(cfg80211_wext_siwfreq);
@@ -799,7 +822,6 @@ int cfg80211_wext_giwfreq(struct net_device *dev,
                          struct iw_freq *freq, char *extra)
 {
        struct wireless_dev *wdev = dev->ieee80211_ptr;
-       struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
 
        switch (wdev->iftype) {
        case NL80211_IFTYPE_STATION:
@@ -807,9 +829,9 @@ int cfg80211_wext_giwfreq(struct net_device *dev,
        case NL80211_IFTYPE_ADHOC:
                return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
        default:
-               if (!rdev->channel)
+               if (!wdev->channel)
                        return -EINVAL;
-               freq->m = rdev->channel->center_freq;
+               freq->m = wdev->channel->center_freq;
                freq->e = 6;
                return 0;
        }
@@ -822,7 +844,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
 {
        struct wireless_dev *wdev = dev->ieee80211_ptr;
        struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
-       enum tx_power_setting type;
+       enum nl80211_tx_power_setting type;
        int dbm = 0;
 
        if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
@@ -845,7 +867,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
                        if (data->txpower.value < 0)
                                return -EINVAL;
                        dbm = data->txpower.value;
-                       type = TX_POWER_FIXED;
+                       type = NL80211_TX_POWER_FIXED;
                        /* TODO: do regulatory check! */
                } else {
                        /*
@@ -853,10 +875,10 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
                         * passed in from userland.
                         */
                        if (data->txpower.value < 0) {
-                               type = TX_POWER_AUTOMATIC;
+                               type = NL80211_TX_POWER_AUTOMATIC;
                        } else {
                                dbm = data->txpower.value;
-                               type = TX_POWER_LIMITED;
+                               type = NL80211_TX_POWER_LIMITED;
                        }
                }
        } else {
@@ -865,7 +887,7 @@ int cfg80211_wext_siwtxpower(struct net_device *dev,
                return 0;
        }
 
-       return rdev->ops->set_tx_power(wdev->wiphy, type, dbm);
+       return rdev->ops->set_tx_power(wdev->wiphy, type, DBM_TO_MBM(dbm));
 }
 EXPORT_SYMBOL_GPL(cfg80211_wext_siwtxpower);
 
@@ -1098,8 +1120,8 @@ int cfg80211_wext_siwpower(struct net_device *dev,
 {
        struct wireless_dev *wdev = dev->ieee80211_ptr;
        struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
-       bool ps = wdev->wext.ps;
-       int timeout = wdev->wext.ps_timeout;
+       bool ps = wdev->ps;
+       int timeout = wdev->ps_timeout;
        int err;
 
        if (wdev->iftype != NL80211_IFTYPE_STATION)
@@ -1132,8 +1154,8 @@ int cfg80211_wext_siwpower(struct net_device *dev,
        if (err)
                return err;
 
-       wdev->wext.ps = ps;
-       wdev->wext.ps_timeout = timeout;
+       wdev->ps = ps;
+       wdev->ps_timeout = timeout;
 
        return 0;
 
@@ -1146,7 +1168,7 @@ int cfg80211_wext_giwpower(struct net_device *dev,
 {
        struct wireless_dev *wdev = dev->ieee80211_ptr;
 
-       wrq->disabled = !wdev->wext.ps;
+       wrq->disabled = !wdev->ps;
 
        return 0;
 }
@@ -1203,21 +1225,47 @@ int cfg80211_wext_siwrate(struct net_device *dev,
        struct wireless_dev *wdev = dev->ieee80211_ptr;
        struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
        struct cfg80211_bitrate_mask mask;
+       u32 fixed, maxrate;
+       struct ieee80211_supported_band *sband;
+       int band, ridx;
+       bool match = false;
 
        if (!rdev->ops->set_bitrate_mask)
                return -EOPNOTSUPP;
 
-       mask.fixed = 0;
-       mask.maxrate = 0;
+       memset(&mask, 0, sizeof(mask));
+       fixed = 0;
+       maxrate = (u32)-1;
 
        if (rate->value < 0) {
                /* nothing */
        } else if (rate->fixed) {
-               mask.fixed = rate->value / 1000; /* kbps */
+               fixed = rate->value / 100000;
        } else {
-               mask.maxrate = rate->value / 1000; /* kbps */
+               maxrate = rate->value / 100000;
        }
 
+       for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
+               sband = wdev->wiphy->bands[band];
+               if (sband == NULL)
+                       continue;
+               for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
+                       struct ieee80211_rate *srate = &sband->bitrates[ridx];
+                       if (fixed == srate->bitrate) {
+                               mask.control[band].legacy = 1 << ridx;
+                               match = true;
+                               break;
+                       }
+                       if (srate->bitrate <= maxrate) {
+                               mask.control[band].legacy |= 1 << ridx;
+                               match = true;
+                       }
+               }
+       }
+
+       if (!match)
+               return -EINVAL;
+
        return rdev->ops->set_bitrate_mask(wdev->wiphy, dev, NULL, &mask);
 }
 EXPORT_SYMBOL_GPL(cfg80211_wext_siwrate);
@@ -1321,6 +1369,10 @@ struct iw_statistics *cfg80211_wireless_stats(struct net_device *dev)
        }
 
        wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
+       if (sinfo.filled & STATION_INFO_RX_DROP_MISC)
+               wstats.discard.misc = sinfo.rx_dropped_misc;
+       if (sinfo.filled & STATION_INFO_TX_FAILED)
+               wstats.discard.retries = sinfo.tx_failed;
 
        return &wstats;
 }
@@ -1387,6 +1439,9 @@ int cfg80211_wext_giwessid(struct net_device *dev,
 {
        struct wireless_dev *wdev = dev->ieee80211_ptr;
 
+       data->flags = 0;
+       data->length = 0;
+
        switch (wdev->iftype) {
        case NL80211_IFTYPE_ADHOC:
                return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
@@ -1438,6 +1493,7 @@ int cfg80211_wext_siwpmksa(struct net_device *dev,
                return -EOPNOTSUPP;
        }
 }
+EXPORT_SYMBOL_GPL(cfg80211_wext_siwpmksa);
 
 static const iw_handler cfg80211_handlers[] = {
        [IW_IOCTL_IDX(SIOCGIWNAME)]     = (iw_handler) cfg80211_wext_giwname,