Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[cascardo/linux.git] / net / wireless / reg.c
index 7b1a89b..1ad0f39 100644 (file)
@@ -106,6 +106,9 @@ struct reg_beacon {
 static void reg_todo(struct work_struct *work);
 static DECLARE_WORK(reg_work, reg_todo);
 
+static void reg_timeout_work(struct work_struct *work);
+static DECLARE_DELAYED_WORK(reg_timeout, reg_timeout_work);
+
 /* We keep a static world regulatory domain in case of the absence of CRDA */
 static const struct ieee80211_regdomain world_regdom = {
        .n_reg_rules = 5,
@@ -669,11 +672,9 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
        for (i = 0; i < regd->n_reg_rules; i++) {
                const struct ieee80211_reg_rule *rr;
                const struct ieee80211_freq_range *fr = NULL;
-               const struct ieee80211_power_rule *pr = NULL;
 
                rr = &regd->reg_rules[i];
                fr = &rr->freq_range;
-               pr = &rr->power_rule;
 
                /*
                 * We only need to know if one frequency rule was
@@ -809,7 +810,7 @@ static void handle_channel(struct wiphy *wiphy,
        if (r) {
                /*
                 * We will disable all channels that do not match our
-                * recieved regulatory rule unless the hint is coming
+                * received regulatory rule unless the hint is coming
                 * from a Country IE and the Country IE had no information
                 * about a band. The IEEE 802.11 spec allows for an AP
                 * to send only a subset of the regulatory rules allowed,
@@ -838,7 +839,7 @@ static void handle_channel(struct wiphy *wiphy,
            request_wiphy && request_wiphy == wiphy &&
            request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
                /*
-                * This gaurantees the driver's requested regulatory domain
+                * This guarantees the driver's requested regulatory domain
                 * will always be used as a base for further regulatory
                 * settings
                 */
@@ -1330,6 +1331,9 @@ static void reg_set_request_processed(void)
                need_more_processing = true;
        spin_unlock(&reg_requests_lock);
 
+       if (last_request->initiator == NL80211_REGDOM_SET_BY_USER)
+               cancel_delayed_work_sync(&reg_timeout);
+
        if (need_more_processing)
                schedule_work(&reg_work);
 }
@@ -1440,8 +1444,18 @@ static void reg_process_hint(struct regulatory_request *reg_request)
        r = __regulatory_hint(wiphy, reg_request);
        /* This is required so that the orig_* parameters are saved */
        if (r == -EALREADY && wiphy &&
-           wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY)
+           wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
                wiphy_update_regulatory(wiphy, initiator);
+               return;
+       }
+
+       /*
+        * We only time out user hints, given that they should be the only
+        * source of bogus requests.
+        */
+       if (r != -EALREADY &&
+           reg_request->initiator == NL80211_REGDOM_SET_BY_USER)
+               schedule_delayed_work(&reg_timeout, msecs_to_jiffies(3142));
 }
 
 /*
@@ -2169,6 +2183,13 @@ out:
        mutex_unlock(&reg_mutex);
 }
 
+static void reg_timeout_work(struct work_struct *work)
+{
+       REG_DBG_PRINT("Timeout while waiting for CRDA to reply, "
+                     "restoring regulatory settings");
+       restore_regulatory_settings(true);
+}
+
 int __init regulatory_init(void)
 {
        int err = 0;
@@ -2222,6 +2243,7 @@ void /* __init_or_exit */ regulatory_exit(void)
        struct reg_beacon *reg_beacon, *btmp;
 
        cancel_work_sync(&reg_work);
+       cancel_delayed_work_sync(&reg_timeout);
 
        mutex_lock(&cfg80211_mutex);
        mutex_lock(&reg_mutex);