mac80211: remove max_bandwidth
[pandora-kernel.git] / net / wireless / reg.c
index fb40428..fc7a484 100644 (file)
@@ -62,6 +62,16 @@ const struct ieee80211_regdomain *cfg80211_regdomain;
  */
 static const struct ieee80211_regdomain *country_ie_regdomain;
 
+/*
+ * Protects static reg.c components:
+ *     - cfg80211_world_regdom
+ *     - cfg80211_regdom
+ *     - country_ie_regdomain
+ *     - last_request
+ */
+DEFINE_MUTEX(reg_mutex);
+#define assert_reg_lock() WARN_ON(!mutex_is_locked(&reg_mutex))
+
 /* Used to queue up regulatory hints */
 static LIST_HEAD(reg_requests_list);
 static spinlock_t reg_requests_lock;
@@ -1008,7 +1018,6 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
                        map_regdom_flags(reg_rule->flags) | bw_flags;
                chan->max_antenna_gain = chan->orig_mag =
                        (int) MBI_TO_DBI(power_rule->max_antenna_gain);
-               chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz);
                chan->max_power = chan->orig_mpwr =
                        (int) MBM_TO_DBM(power_rule->max_eirp);
                return;
@@ -1017,7 +1026,6 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
        chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags);
        chan->max_antenna_gain = min(chan->orig_mag,
                (int) MBI_TO_DBI(power_rule->max_antenna_gain));
-       chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz);
        if (chan->orig_mpwr)
                chan->max_power = min(chan->orig_mpwr,
                        (int) MBM_TO_DBM(power_rule->max_eirp));
@@ -1085,17 +1093,18 @@ static void handle_reg_beacon(struct wiphy *wiphy,
 
        chan->beacon_found = true;
 
+       if (wiphy->disable_beacon_hints)
+               return;
+
        chan_before.center_freq = chan->center_freq;
        chan_before.flags = chan->flags;
 
-       if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
-           !(chan->orig_flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
+       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
                chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
                channel_changed = true;
        }
 
-       if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
-           !(chan->orig_flags & IEEE80211_CHAN_NO_IBSS)) {
+       if (chan->flags & IEEE80211_CHAN_NO_IBSS) {
                chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
                channel_changed = true;
        }
@@ -1293,7 +1302,7 @@ static void handle_channel_custom(struct wiphy *wiphy,
        struct ieee80211_supported_band *sband;
        struct ieee80211_channel *chan;
 
-       assert_cfg80211_lock();
+       assert_reg_lock();
 
        sband = wiphy->bands[band];
        BUG_ON(chan_idx >= sband->n_channels);
@@ -1318,7 +1327,6 @@ static void handle_channel_custom(struct wiphy *wiphy,
 
        chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags;
        chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain);
-       chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz);
        chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
 }
 
@@ -1342,14 +1350,14 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
        enum ieee80211_band band;
        unsigned int bands_set = 0;
 
-       mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
        for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
                if (!wiphy->bands[band])
                        continue;
                handle_band_custom(wiphy, band, regd);
                bands_set++;
        }
-       mutex_unlock(&cfg80211_mutex);
+       mutex_unlock(&reg_mutex);
 
        /*
         * no point in calling this if it won't have any effect
@@ -1495,7 +1503,7 @@ static int ignore_request(struct wiphy *wiphy,
  * Returns zero if all went fine, %-EALREADY if a regulatory domain had
  * already been set or other standard error codes.
  *
- * Caller must hold &cfg80211_mutex
+ * Caller must hold &cfg80211_mutex and &reg_mutex
  */
 static int __regulatory_hint(struct wiphy *wiphy,
                             struct regulatory_request *pending_request)
@@ -1570,6 +1578,7 @@ static void reg_process_hint(struct regulatory_request *reg_request)
        BUG_ON(!reg_request->alpha2);
 
        mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
 
        if (wiphy_idx_valid(reg_request->wiphy_idx))
                wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
@@ -1585,6 +1594,7 @@ static void reg_process_hint(struct regulatory_request *reg_request)
        if (r == -EALREADY && wiphy && wiphy->strict_regulatory)
                wiphy_update_regulatory(wiphy, reg_request->initiator);
 out:
+       mutex_unlock(&reg_mutex);
        mutex_unlock(&cfg80211_mutex);
 }
 
@@ -1613,6 +1623,10 @@ static void reg_process_pending_beacon_hints(void)
        struct cfg80211_registered_device *rdev;
        struct reg_beacon *pending_beacon, *tmp;
 
+       /*
+        * No need to hold the reg_mutex here as we just touch wiphys
+        * and do not read or access regulatory variables.
+        */
        mutex_lock(&cfg80211_mutex);
 
        /* This goes through the _pending_ beacon list */
@@ -1734,12 +1748,13 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
 }
 EXPORT_SYMBOL(regulatory_hint);
 
+/* Caller must hold reg_mutex */
 static bool reg_same_country_ie_hint(struct wiphy *wiphy,
                        u32 country_ie_checksum)
 {
        struct wiphy *request_wiphy;
 
-       assert_cfg80211_lock();
+       assert_reg_lock();
 
        if (unlikely(last_request->initiator !=
            NL80211_REGDOM_SET_BY_COUNTRY_IE))
@@ -1762,6 +1777,10 @@ static bool reg_same_country_ie_hint(struct wiphy *wiphy,
        return false;
 }
 
+/*
+ * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and
+ * therefore cannot iterate over the rdev list here.
+ */
 void regulatory_hint_11d(struct wiphy *wiphy,
                        u8 *country_ie,
                        u8 country_ie_len)
@@ -1772,12 +1791,10 @@ void regulatory_hint_11d(struct wiphy *wiphy,
        enum environment_cap env = ENVIRON_ANY;
        struct regulatory_request *request;
 
-       mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
 
-       if (unlikely(!last_request)) {
-               mutex_unlock(&cfg80211_mutex);
-               return;
-       }
+       if (unlikely(!last_request))
+               goto out;
 
        /* IE len must be evenly divisible by 2 */
        if (country_ie_len & 0x01)
@@ -1803,54 +1820,14 @@ void regulatory_hint_11d(struct wiphy *wiphy,
                env = ENVIRON_OUTDOOR;
 
        /*
-        * We will run this for *every* beacon processed for the BSSID, so
-        * we optimize an early check to exit out early if we don't have to
-        * do anything
+        * We will run this only upon a successful connection on cfg80211.
+        * We leave conflict resolution to the workqueue, where can hold
+        * cfg80211_mutex.
         */
        if (likely(last_request->initiator ==
            NL80211_REGDOM_SET_BY_COUNTRY_IE &&
-           wiphy_idx_valid(last_request->wiphy_idx))) {
-               struct cfg80211_registered_device *rdev_last_ie;
-
-               rdev_last_ie =
-                       cfg80211_rdev_by_wiphy_idx(last_request->wiphy_idx);
-
-               /*
-                * Lets keep this simple -- we trust the first AP
-                * after we intersect with CRDA
-                */
-               if (likely(&rdev_last_ie->wiphy == wiphy)) {
-                       /*
-                        * Ignore IEs coming in on this wiphy with
-                        * the same alpha2 and environment cap
-                        */
-                       if (likely(alpha2_equal(rdev_last_ie->country_ie_alpha2,
-                                 alpha2) &&
-                                 env == rdev_last_ie->env)) {
-                               goto out;
-                       }
-                       /*
-                        * the wiphy moved on to another BSSID or the AP
-                        * was reconfigured. XXX: We need to deal with the
-                        * case where the user suspends and goes to goes
-                        * to another country, and then gets IEs from an
-                        * AP with different settings
-                        */
-                       goto out;
-               } else {
-                       /*
-                        * Ignore IEs coming in on two separate wiphys with
-                        * the same alpha2 and environment cap
-                        */
-                       if (likely(alpha2_equal(rdev_last_ie->country_ie_alpha2,
-                                 alpha2) &&
-                                 env == rdev_last_ie->env)) {
-                               goto out;
-                       }
-                       /* We could potentially intersect though */
-                       goto out;
-               }
-       }
+           wiphy_idx_valid(last_request->wiphy_idx)))
+               goto out;
 
        rd = country_ie_2_rd(country_ie, country_ie_len, &checksum);
        if (!rd)
@@ -1885,7 +1862,7 @@ void regulatory_hint_11d(struct wiphy *wiphy,
        request->country_ie_checksum = checksum;
        request->country_ie_env = env;
 
-       mutex_unlock(&cfg80211_mutex);
+       mutex_unlock(&reg_mutex);
 
        queue_regulatory_request(request);
 
@@ -1894,9 +1871,8 @@ void regulatory_hint_11d(struct wiphy *wiphy,
 free_rd_out:
        kfree(rd);
 out:
-       mutex_unlock(&cfg80211_mutex);
+       mutex_unlock(&reg_mutex);
 }
-EXPORT_SYMBOL(regulatory_hint_11d);
 
 static bool freq_is_chan_12_13_14(u16 freq)
 {
@@ -2227,10 +2203,13 @@ int set_regdom(const struct ieee80211_regdomain *rd)
 
        assert_cfg80211_lock();
 
+       mutex_lock(&reg_mutex);
+
        /* Note that this doesn't update the wiphys, this is done below */
        r = __set_regdom(rd);
        if (r) {
                kfree(rd);
+               mutex_unlock(&reg_mutex);
                return r;
        }
 
@@ -2245,6 +2224,8 @@ int set_regdom(const struct ieee80211_regdomain *rd)
 
        nl80211_send_reg_change_event(last_request);
 
+       mutex_unlock(&reg_mutex);
+
        return r;
 }
 
@@ -2255,16 +2236,20 @@ void reg_device_remove(struct wiphy *wiphy)
 
        assert_cfg80211_lock();
 
+       mutex_lock(&reg_mutex);
+
        kfree(wiphy->regd);
 
        if (last_request)
                request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
 
        if (!request_wiphy || request_wiphy != wiphy)
-               return;
+               goto out;
 
        last_request->wiphy_idx = WIPHY_IDX_STALE;
        last_request->country_ie_env = ENVIRON_ANY;
+out:
+       mutex_unlock(&reg_mutex);
 }
 
 int regulatory_init(void)
@@ -2325,6 +2310,7 @@ void regulatory_exit(void)
        cancel_work_sync(&reg_work);
 
        mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
 
        reset_regdomains();
 
@@ -2363,5 +2349,6 @@ void regulatory_exit(void)
        }
        spin_unlock(&reg_requests_lock);
 
+       mutex_unlock(&reg_mutex);
        mutex_unlock(&cfg80211_mutex);
 }