]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - net/wireless/reg.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[linux-2.6.git] / net / wireless / reg.c
index b64596fe7363d197d914337b3cded17931e5d9fb..58d69959ab28c033741a61ef836e88a16be11791 100644 (file)
@@ -32,6 +32,9 @@
  * rely on some SHA1 checksum of the regdomain for example.
  *
  */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/list.h>
@@ -48,7 +51,7 @@
 #ifdef CONFIG_CFG80211_REG_DEBUG
 #define REG_DBG_PRINT(format, args...) \
        do { \
-               printk(KERN_DEBUG format , ## args); \
+               printk(KERN_DEBUG pr_fmt(format), ##args);      \
        } while (0)
 #else
 #define REG_DBG_PRINT(args...)
@@ -60,6 +63,10 @@ static struct regulatory_request *last_request;
 /* To trigger userspace events */
 static struct platform_device *reg_pdev;
 
+static struct device_type reg_device_type = {
+       .uevent = reg_device_uevent,
+};
+
 /*
  * Central wireless core regulatory domains, we only need two,
  * the current one and a world regulatory domain in case we have no
@@ -96,6 +103,12 @@ struct reg_beacon {
        struct ieee80211_channel chan;
 };
 
+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,
@@ -356,30 +369,21 @@ static inline void reg_regdb_query(const char *alpha2) {}
 
 /*
  * This lets us keep regulatory code which is updated on a regulatory
- * basis in userspace.
+ * basis in userspace. Country information is filled in by
+ * reg_device_uevent
  */
 static int call_crda(const char *alpha2)
 {
-       char country_env[9 + 2] = "COUNTRY=";
-       char *envp[] = {
-               country_env,
-               NULL
-       };
-
        if (!is_world_regdom((char *) alpha2))
-               printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n",
+               pr_info("Calling CRDA for country: %c%c\n",
                        alpha2[0], alpha2[1]);
        else
-               printk(KERN_INFO "cfg80211: Calling CRDA to update world "
-                       "regulatory domain\n");
+               pr_info("Calling CRDA to update world regulatory domain\n");
 
        /* query internal regulatory database (if it exists) */
        reg_regdb_query(alpha2);
 
-       country_env[8] = alpha2[0];
-       country_env[9] = alpha2[1];
-
-       return kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, envp);
+       return kobject_uevent(&reg_pdev->dev.kobj, KOBJ_CHANGE);
 }
 
 /* Used by nl80211 before kmalloc'ing our regulatory domain */
@@ -656,7 +660,8 @@ static int freq_reg_info_regd(struct wiphy *wiphy,
         * Follow the driver's regulatory domain, if present, unless a country
         * IE has been processed or a user wants to help complaince further
         */
-       if (last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
+       if (!custom_regd &&
+           last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
            last_request->initiator != NL80211_REGDOM_SET_BY_USER &&
            wiphy->regd)
                regd = wiphy->regd;
@@ -711,6 +716,60 @@ int freq_reg_info(struct wiphy *wiphy,
 }
 EXPORT_SYMBOL(freq_reg_info);
 
+#ifdef CONFIG_CFG80211_REG_DEBUG
+static const char *reg_initiator_name(enum nl80211_reg_initiator initiator)
+{
+       switch (initiator) {
+       case NL80211_REGDOM_SET_BY_CORE:
+               return "Set by core";
+       case NL80211_REGDOM_SET_BY_USER:
+               return "Set by user";
+       case NL80211_REGDOM_SET_BY_DRIVER:
+               return "Set by driver";
+       case NL80211_REGDOM_SET_BY_COUNTRY_IE:
+               return "Set by country IE";
+       default:
+               WARN_ON(1);
+               return "Set by bug";
+       }
+}
+
+static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
+                                   u32 desired_bw_khz,
+                                   const struct ieee80211_reg_rule *reg_rule)
+{
+       const struct ieee80211_power_rule *power_rule;
+       const struct ieee80211_freq_range *freq_range;
+       char max_antenna_gain[32];
+
+       power_rule = &reg_rule->power_rule;
+       freq_range = &reg_rule->freq_range;
+
+       if (!power_rule->max_antenna_gain)
+               snprintf(max_antenna_gain, 32, "N/A");
+       else
+               snprintf(max_antenna_gain, 32, "%d", power_rule->max_antenna_gain);
+
+       REG_DBG_PRINT("Updating information on frequency %d MHz "
+                     "for a %d MHz width channel with regulatory rule:\n",
+                     chan->center_freq,
+                     KHZ_TO_MHZ(desired_bw_khz));
+
+       REG_DBG_PRINT("%d KHz - %d KHz @  KHz), (%s mBi, %d mBm)\n",
+                     freq_range->start_freq_khz,
+                     freq_range->end_freq_khz,
+                     max_antenna_gain,
+                     power_rule->max_eirp);
+}
+#else
+static void chan_reg_rule_print_dbg(struct ieee80211_channel *chan,
+                                   u32 desired_bw_khz,
+                                   const struct ieee80211_reg_rule *reg_rule)
+{
+       return;
+}
+#endif
+
 /*
  * Note that right now we assume the desired channel bandwidth
  * is always 20 MHz for each individual channel (HT40 uses 20 MHz
@@ -750,8 +809,27 @@ static void handle_channel(struct wiphy *wiphy,
                          desired_bw_khz,
                          &reg_rule);
 
-       if (r)
+       if (r) {
+               /*
+                * We will disable all channels that do not match our
+                * 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,
+                * so an AP in the US that only supports 2.4 GHz may only send
+                * a country IE with information for the 2.4 GHz band
+                * while 5 GHz is still supported.
+                */
+               if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE &&
+                   r == -ERANGE)
+                       return;
+
+               REG_DBG_PRINT("Disabling freq %d MHz\n", chan->center_freq);
+               chan->flags = IEEE80211_CHAN_DISABLED;
                return;
+       }
+
+       chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule);
 
        power_rule = &reg_rule->power_rule;
        freq_range = &reg_rule->freq_range;
@@ -763,7 +841,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
                 */
@@ -803,18 +881,36 @@ static void handle_band(struct wiphy *wiphy,
 static bool ignore_reg_update(struct wiphy *wiphy,
                              enum nl80211_reg_initiator initiator)
 {
-       if (!last_request)
+       if (!last_request) {
+               REG_DBG_PRINT("Ignoring regulatory request %s since "
+                             "last_request is not set\n",
+                             reg_initiator_name(initiator));
                return true;
+       }
+
        if (initiator == NL80211_REGDOM_SET_BY_CORE &&
-           wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
+           wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY) {
+               REG_DBG_PRINT("Ignoring regulatory request %s "
+                             "since the driver uses its own custom "
+                             "regulatory domain ",
+                             reg_initiator_name(initiator));
                return true;
+       }
+
        /*
         * wiphy->regd will be set once the device has its own
         * desired regulatory domain set
         */
        if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd &&
-           !is_world_regdom(last_request->alpha2))
+           initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
+           !is_world_regdom(last_request->alpha2)) {
+               REG_DBG_PRINT("Ignoring regulatory request %s "
+                             "since the driver requires its own regulaotry "
+                             "domain to be set first",
+                             reg_initiator_name(initiator));
                return true;
+       }
+
        return false;
 }
 
@@ -1070,10 +1166,17 @@ static void handle_channel_custom(struct wiphy *wiphy,
                               regd);
 
        if (r) {
+               REG_DBG_PRINT("Disabling freq %d MHz as custom "
+                             "regd has no rule that fits a %d MHz "
+                             "wide channel\n",
+                             chan->center_freq,
+                             KHZ_TO_MHZ(desired_bw_khz));
                chan->flags = IEEE80211_CHAN_DISABLED;
                return;
        }
 
+       chan_reg_rule_print_dbg(chan, desired_bw_khz, reg_rule);
+
        power_rule = &reg_rule->power_rule;
        freq_range = &reg_rule->freq_range;
 
@@ -1219,6 +1322,24 @@ static int ignore_request(struct wiphy *wiphy,
        return -EINVAL;
 }
 
+static void reg_set_request_processed(void)
+{
+       bool need_more_processing = false;
+
+       last_request->processed = true;
+
+       spin_lock(&reg_requests_lock);
+       if (!list_empty(&reg_requests_list))
+               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);
+}
+
 /**
  * __regulatory_hint - hint to the wireless core a regulatory domain
  * @wiphy: if the hint comes from country information from an AP, this
@@ -1294,8 +1415,10 @@ new_request:
                 * have applied the requested regulatory domain before we just
                 * inform userspace we have processed the request
                 */
-               if (r == -EALREADY)
+               if (r == -EALREADY) {
                        nl80211_send_reg_change_event(last_request);
+                       reg_set_request_processed();
+               }
                return r;
        }
 
@@ -1311,45 +1434,69 @@ 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);
 
        if (reg_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
            !wiphy) {
                kfree(reg_request);
-               goto out;
+               return;
        }
 
        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);
-out:
-       mutex_unlock(&reg_mutex);
-       mutex_unlock(&cfg80211_mutex);
+               return;
+       }
+
+       /*
+        * We only time out user hints, given that they should be the only
+        * source of bogus requests.
+        */
+       if (reg_request->initiator == NL80211_REGDOM_SET_BY_USER)
+               schedule_delayed_work(&reg_timeout, msecs_to_jiffies(3142));
 }
 
-/* Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_* */
+/*
+ * Processes regulatory hints, this is all the NL80211_REGDOM_SET_BY_*
+ * Regulatory hints come on a first come first serve basis and we
+ * must process each one atomically.
+ */
 static void reg_process_pending_hints(void)
-       {
+{
        struct regulatory_request *reg_request;
 
+       mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
+
+       /* When last_request->processed becomes true this will be rescheduled */
+       if (last_request && !last_request->processed) {
+               REG_DBG_PRINT("Pending regulatory request, waiting "
+                             "for it to be processed...");
+               goto out;
+       }
+
        spin_lock(&reg_requests_lock);
-       while (!list_empty(&reg_requests_list)) {
-               reg_request = list_first_entry(&reg_requests_list,
-                                              struct regulatory_request,
-                                              list);
-               list_del_init(&reg_request->list);
 
+       if (list_empty(&reg_requests_list)) {
                spin_unlock(&reg_requests_lock);
-               reg_process_hint(reg_request);
-               spin_lock(&reg_requests_lock);
+               goto out;
        }
+
+       reg_request = list_first_entry(&reg_requests_list,
+                                      struct regulatory_request,
+                                      list);
+       list_del_init(&reg_request->list);
+
        spin_unlock(&reg_requests_lock);
+
+       reg_process_hint(reg_request);
+
+out:
+       mutex_unlock(&reg_mutex);
+       mutex_unlock(&cfg80211_mutex);
 }
 
 /* Processes beacon hints -- this has nothing to do with country IEs */
@@ -1396,8 +1543,6 @@ static void reg_todo(struct work_struct *work)
        reg_process_pending_beacon_hints();
 }
 
-static DECLARE_WORK(reg_work, reg_todo);
-
 static void queue_regulatory_request(struct regulatory_request *request)
 {
        if (isalpha(request->alpha2[0]))
@@ -1432,12 +1577,7 @@ static int regulatory_hint_core(const char *alpha2)
        request->alpha2[1] = alpha2[1];
        request->initiator = NL80211_REGDOM_SET_BY_CORE;
 
-       /*
-        * This ensures last_request is populated once modules
-        * come swinging in and calling regulatory hints and
-        * wiphy_apply_custom_regulatory().
-        */
-       reg_process_hint(request);
+       queue_regulatory_request(request);
 
        return 0;
 }
@@ -1563,7 +1703,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
        if (is_user_regdom_saved()) {
                /* Unless we're asked to ignore it and reset it */
                if (reset_user) {
-                       REG_DBG_PRINT("cfg80211: Restoring regulatory settings "
+                       REG_DBG_PRINT("Restoring regulatory settings "
                               "including user preference\n");
                        user_alpha2[0] = '9';
                        user_alpha2[1] = '7';
@@ -1574,7 +1714,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
                         * back as they were for a full restore.
                         */
                        if (!is_world_regdom(ieee80211_regdom)) {
-                               REG_DBG_PRINT("cfg80211: Keeping preference on "
+                               REG_DBG_PRINT("Keeping preference on "
                                       "module parameter ieee80211_regdom: %c%c\n",
                                       ieee80211_regdom[0],
                                       ieee80211_regdom[1]);
@@ -1582,7 +1722,7 @@ static void restore_alpha2(char *alpha2, bool reset_user)
                                alpha2[1] = ieee80211_regdom[1];
                        }
                } else {
-                       REG_DBG_PRINT("cfg80211: Restoring regulatory settings "
+                       REG_DBG_PRINT("Restoring regulatory settings "
                               "while preserving user preference for: %c%c\n",
                               user_alpha2[0],
                               user_alpha2[1]);
@@ -1590,14 +1730,14 @@ static void restore_alpha2(char *alpha2, bool reset_user)
                        alpha2[1] = user_alpha2[1];
                }
        } else if (!is_world_regdom(ieee80211_regdom)) {
-               REG_DBG_PRINT("cfg80211: Keeping preference on "
+               REG_DBG_PRINT("Keeping preference on "
                       "module parameter ieee80211_regdom: %c%c\n",
                       ieee80211_regdom[0],
                       ieee80211_regdom[1]);
                alpha2[0] = ieee80211_regdom[0];
                alpha2[1] = ieee80211_regdom[1];
        } else
-               REG_DBG_PRINT("cfg80211: Restoring regulatory settings\n");
+               REG_DBG_PRINT("Restoring regulatory settings\n");
 }
 
 /*
@@ -1619,6 +1759,8 @@ static void restore_regulatory_settings(bool reset_user)
 {
        char alpha2[2];
        struct reg_beacon *reg_beacon, *btmp;
+       struct regulatory_request *reg_request, *tmp;
+       LIST_HEAD(tmp_reg_req_list);
 
        mutex_lock(&cfg80211_mutex);
        mutex_lock(&reg_mutex);
@@ -1626,6 +1768,25 @@ static void restore_regulatory_settings(bool reset_user)
        reset_regdomains();
        restore_alpha2(alpha2, reset_user);
 
+       /*
+        * If there's any pending requests we simply
+        * stash them to a temporary pending queue and
+        * add then after we've restored regulatory
+        * settings.
+        */
+       spin_lock(&reg_requests_lock);
+       if (!list_empty(&reg_requests_list)) {
+               list_for_each_entry_safe(reg_request, tmp,
+                                        &reg_requests_list, list) {
+                       if (reg_request->initiator !=
+                           NL80211_REGDOM_SET_BY_USER)
+                               continue;
+                       list_del(&reg_request->list);
+                       list_add_tail(&reg_request->list, &tmp_reg_req_list);
+               }
+       }
+       spin_unlock(&reg_requests_lock);
+
        /* Clear beacon hints */
        spin_lock_bh(&reg_pending_beacons_lock);
        if (!list_empty(&reg_pending_beacons)) {
@@ -1660,21 +1821,44 @@ static void restore_regulatory_settings(bool reset_user)
         */
        if (is_an_alpha2(alpha2))
                regulatory_hint_user(user_alpha2);
-}
 
+       if (list_empty(&tmp_reg_req_list))
+               return;
+
+       mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
+
+       spin_lock(&reg_requests_lock);
+       list_for_each_entry_safe(reg_request, tmp, &tmp_reg_req_list, list) {
+               REG_DBG_PRINT("Adding request for country %c%c back "
+                             "into the queue\n",
+                             reg_request->alpha2[0],
+                             reg_request->alpha2[1]);
+               list_del(&reg_request->list);
+               list_add_tail(&reg_request->list, &reg_requests_list);
+       }
+       spin_unlock(&reg_requests_lock);
+
+       mutex_unlock(&reg_mutex);
+       mutex_unlock(&cfg80211_mutex);
+
+       REG_DBG_PRINT("Kicking the queue\n");
+
+       schedule_work(&reg_work);
+}
 
 void regulatory_hint_disconnect(void)
 {
-       REG_DBG_PRINT("cfg80211: All devices are disconnected, going to "
+       REG_DBG_PRINT("All devices are disconnected, going to "
                      "restore regulatory settings\n");
        restore_regulatory_settings(false);
 }
 
 static bool freq_is_chan_12_13_14(u16 freq)
 {
-       if (freq == ieee80211_channel_to_frequency(12) ||
-           freq == ieee80211_channel_to_frequency(13) ||
-           freq == ieee80211_channel_to_frequency(14))
+       if (freq == ieee80211_channel_to_frequency(12, IEEE80211_BAND_2GHZ) ||
+           freq == ieee80211_channel_to_frequency(13, IEEE80211_BAND_2GHZ) ||
+           freq == ieee80211_channel_to_frequency(14, IEEE80211_BAND_2GHZ))
                return true;
        return false;
 }
@@ -1695,7 +1879,7 @@ int regulatory_hint_found_beacon(struct wiphy *wiphy,
        if (!reg_beacon)
                return -ENOMEM;
 
-       REG_DBG_PRINT("cfg80211: Found new beacon on "
+       REG_DBG_PRINT("Found new beacon on "
                      "frequency: %d MHz (Ch %d) on %s\n",
                      beacon_chan->center_freq,
                      ieee80211_frequency_to_channel(beacon_chan->center_freq),
@@ -1725,8 +1909,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
        const struct ieee80211_freq_range *freq_range = NULL;
        const struct ieee80211_power_rule *power_rule = NULL;
 
-       printk(KERN_INFO "    (start_freq - end_freq @ bandwidth), "
-               "(max_antenna_gain, max_eirp)\n");
+       pr_info("    (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)\n");
 
        for (i = 0; i < rd->n_reg_rules; i++) {
                reg_rule = &rd->reg_rules[i];
@@ -1738,16 +1921,14 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
                 * in certain regions
                 */
                if (power_rule->max_antenna_gain)
-                       printk(KERN_INFO "    (%d KHz - %d KHz @ %d KHz), "
-                               "(%d mBi, %d mBm)\n",
+                       pr_info("    (%d KHz - %d KHz @ %d KHz), (%d mBi, %d mBm)\n",
                                freq_range->start_freq_khz,
                                freq_range->end_freq_khz,
                                freq_range->max_bandwidth_khz,
                                power_rule->max_antenna_gain,
                                power_rule->max_eirp);
                else
-                       printk(KERN_INFO "    (%d KHz - %d KHz @ %d KHz), "
-                               "(N/A, %d mBm)\n",
+                       pr_info("    (%d KHz - %d KHz @ %d KHz), (N/A, %d mBm)\n",
                                freq_range->start_freq_khz,
                                freq_range->end_freq_khz,
                                freq_range->max_bandwidth_khz,
@@ -1766,27 +1947,20 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
                        rdev = cfg80211_rdev_by_wiphy_idx(
                                last_request->wiphy_idx);
                        if (rdev) {
-                               printk(KERN_INFO "cfg80211: Current regulatory "
-                                       "domain updated by AP to: %c%c\n",
+                               pr_info("Current regulatory domain updated by AP to: %c%c\n",
                                        rdev->country_ie_alpha2[0],
                                        rdev->country_ie_alpha2[1]);
                        } else
-                               printk(KERN_INFO "cfg80211: Current regulatory "
-                                       "domain intersected:\n");
+                               pr_info("Current regulatory domain intersected:\n");
                } else
-                       printk(KERN_INFO "cfg80211: Current regulatory "
-                               "domain intersected:\n");
+                       pr_info("Current regulatory domain intersected:\n");
        } else if (is_world_regdom(rd->alpha2))
-               printk(KERN_INFO "cfg80211: World regulatory "
-                       "domain updated:\n");
+               pr_info("World regulatory domain updated:\n");
        else {
                if (is_unknown_alpha2(rd->alpha2))
-                       printk(KERN_INFO "cfg80211: Regulatory domain "
-                               "changed to driver built-in settings "
-                               "(unknown country)\n");
+                       pr_info("Regulatory domain changed to driver built-in settings (unknown country)\n");
                else
-                       printk(KERN_INFO "cfg80211: Regulatory domain "
-                               "changed to country: %c%c\n",
+                       pr_info("Regulatory domain changed to country: %c%c\n",
                                rd->alpha2[0], rd->alpha2[1]);
        }
        print_rd_rules(rd);
@@ -1794,8 +1968,7 @@ static void print_regdomain(const struct ieee80211_regdomain *rd)
 
 static void print_regdomain_info(const struct ieee80211_regdomain *rd)
 {
-       printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
-               rd->alpha2[0], rd->alpha2[1]);
+       pr_info("Regulatory domain: %c%c\n", rd->alpha2[0], rd->alpha2[1]);
        print_rd_rules(rd);
 }
 
@@ -1846,8 +2019,7 @@ static int __set_regdom(const struct ieee80211_regdomain *rd)
                return -EINVAL;
 
        if (!is_valid_rd(rd)) {
-               printk(KERN_ERR "cfg80211: Invalid "
-                       "regulatory domain detected:\n");
+               pr_err("Invalid regulatory domain detected:\n");
                print_regdomain_info(rd);
                return -EINVAL;
        }
@@ -1963,11 +2135,32 @@ int set_regdom(const struct ieee80211_regdomain *rd)
 
        nl80211_send_reg_change_event(last_request);
 
+       reg_set_request_processed();
+
        mutex_unlock(&reg_mutex);
 
        return r;
 }
 
+#ifdef CONFIG_HOTPLUG
+int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+       if (last_request && !last_request->processed) {
+               if (add_uevent_var(env, "COUNTRY=%c%c",
+                                  last_request->alpha2[0],
+                                  last_request->alpha2[1]))
+                       return -ENOMEM;
+       }
+
+       return 0;
+}
+#else
+int reg_device_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+       return -ENODEV;
+}
+#endif /* CONFIG_HOTPLUG */
+
 /* Caller must hold cfg80211_mutex */
 void reg_device_remove(struct wiphy *wiphy)
 {
@@ -1991,6 +2184,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;
@@ -1999,6 +2199,8 @@ int __init regulatory_init(void)
        if (IS_ERR(reg_pdev))
                return PTR_ERR(reg_pdev);
 
+       reg_pdev->dev.type = &reg_device_type;
+
        spin_lock_init(&reg_requests_lock);
        spin_lock_init(&reg_pending_beacons_lock);
 
@@ -2019,8 +2221,7 @@ int __init regulatory_init(void)
                 * early boot for call_usermodehelper(). For now treat these
                 * errors as non-fatal.
                 */
-               printk(KERN_ERR "cfg80211: kobject_uevent_env() was unable "
-                       "to call CRDA during init");
+               pr_err("kobject_uevent_env() was unable to call CRDA during init\n");
 #ifdef CONFIG_CFG80211_REG_DEBUG
                /* We want to find out exactly why when debugging */
                WARN_ON(err);
@@ -2043,6 +2244,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);