Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[cascardo/linux.git] / net / wireless / reg.c
index c01470e..dc13c3f 100644 (file)
@@ -40,6 +40,7 @@
 #include <net/cfg80211.h>
 #include "core.h"
 #include "reg.h"
+#include "regdb.h"
 #include "nl80211.h"
 
 /* Receipt of information from last regulatory request */
@@ -141,62 +142,35 @@ static const struct ieee80211_regdomain us_regdom = {
        .reg_rules = {
                /* IEEE 802.11b/g, channels 1..11 */
                REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
-               /* IEEE 802.11a, channel 36 */
-               REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
-               /* IEEE 802.11a, channel 40 */
-               REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
-               /* IEEE 802.11a, channel 44 */
-               REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
+               /* IEEE 802.11a, channel 36..48 */
+               REG_RULE(5180-10, 5240+10, 40, 6, 17, 0),
                /* IEEE 802.11a, channels 48..64 */
-               REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
+               REG_RULE(5260-10, 5320+10, 40, 6, 20, NL80211_RRF_DFS),
+               /* IEEE 802.11a, channels 100..124 */
+               REG_RULE(5500-10, 5590+10, 40, 6, 20, NL80211_RRF_DFS),
+               /* IEEE 802.11a, channels 132..144 */
+               REG_RULE(5660-10, 5700+10, 40, 6, 20, NL80211_RRF_DFS),
                /* IEEE 802.11a, channels 149..165, outdoor */
                REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
        }
 };
 
 static const struct ieee80211_regdomain jp_regdom = {
-       .n_reg_rules = 3,
+       .n_reg_rules = 6,
        .alpha2 =  "JP",
        .reg_rules = {
-               /* IEEE 802.11b/g, channels 1..14 */
-               REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
-               /* IEEE 802.11a, channels 34..48 */
-               REG_RULE(5170-10, 5240+10, 40, 6, 20,
-                       NL80211_RRF_PASSIVE_SCAN),
+               /* IEEE 802.11b/g, channels 1..11 */
+               REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
+               /* IEEE 802.11b/g, channels 12..13 */
+               REG_RULE(2467-10, 2472+10, 20, 6, 20, 0),
+               /* IEEE 802.11b/g, channel 14 */
+               REG_RULE(2484-10, 2484+10, 20, 6, 20, NL80211_RRF_NO_OFDM),
+               /* IEEE 802.11a, channels 36..48 */
+               REG_RULE(5180-10, 5240+10, 40, 6, 20, 0),
                /* IEEE 802.11a, channels 52..64 */
-               REG_RULE(5260-10, 5320+10, 40, 6, 20,
-                       NL80211_RRF_NO_IBSS |
-                       NL80211_RRF_DFS),
-       }
-};
-
-static const struct ieee80211_regdomain eu_regdom = {
-       .n_reg_rules = 6,
-       /*
-        * This alpha2 is bogus, we leave it here just for stupid
-        * backward compatibility
-        */
-       .alpha2 =  "EU",
-       .reg_rules = {
-               /* IEEE 802.11b/g, channels 1..13 */
-               REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
-               /* IEEE 802.11a, channel 36 */
-               REG_RULE(5180-10, 5180+10, 40, 6, 23,
-                       NL80211_RRF_PASSIVE_SCAN),
-               /* IEEE 802.11a, channel 40 */
-               REG_RULE(5200-10, 5200+10, 40, 6, 23,
-                       NL80211_RRF_PASSIVE_SCAN),
-               /* IEEE 802.11a, channel 44 */
-               REG_RULE(5220-10, 5220+10, 40, 6, 23,
-                       NL80211_RRF_PASSIVE_SCAN),
-               /* IEEE 802.11a, channels 48..64 */
-               REG_RULE(5240-10, 5320+10, 40, 6, 20,
-                       NL80211_RRF_NO_IBSS |
-                       NL80211_RRF_DFS),
-               /* IEEE 802.11a, channels 100..140 */
-               REG_RULE(5500-10, 5700+10, 40, 6, 30,
-                       NL80211_RRF_NO_IBSS |
-                       NL80211_RRF_DFS),
+               REG_RULE(5260-10, 5320+10, 40, 6, 20, NL80211_RRF_DFS),
+               /* IEEE 802.11a, channels 100..144 */
+               REG_RULE(5500-10, 5700+10, 40, 6, 23, NL80211_RRF_DFS),
        }
 };
 
@@ -206,15 +180,17 @@ static const struct ieee80211_regdomain *static_regdom(char *alpha2)
                return &us_regdom;
        if (alpha2[0] == 'J' && alpha2[1] == 'P')
                return &jp_regdom;
+       /* Use world roaming rules for "EU", since it was a pseudo
+          domain anyway... */
        if (alpha2[0] == 'E' && alpha2[1] == 'U')
-               return &eu_regdom;
-       /* Default, as per the old rules */
-       return &us_regdom;
+               return &world_regdom;
+       /* Default, world roaming rules */
+       return &world_regdom;
 }
 
 static bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
 {
-       if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom)
+       if (rd == &us_regdom || rd == &jp_regdom || rd == &world_regdom)
                return true;
        return false;
 }
@@ -360,6 +336,98 @@ static bool country_ie_integrity_changes(u32 checksum)
        return false;
 }
 
+static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
+                        const struct ieee80211_regdomain *src_regd)
+{
+       struct ieee80211_regdomain *regd;
+       int size_of_regd = 0;
+       unsigned int i;
+
+       size_of_regd = sizeof(struct ieee80211_regdomain) +
+         ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule));
+
+       regd = kzalloc(size_of_regd, GFP_KERNEL);
+       if (!regd)
+               return -ENOMEM;
+
+       memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
+
+       for (i = 0; i < src_regd->n_reg_rules; i++)
+               memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
+                       sizeof(struct ieee80211_reg_rule));
+
+       *dst_regd = regd;
+       return 0;
+}
+
+#ifdef CONFIG_CFG80211_INTERNAL_REGDB
+struct reg_regdb_search_request {
+       char alpha2[2];
+       struct list_head list;
+};
+
+static LIST_HEAD(reg_regdb_search_list);
+static DEFINE_SPINLOCK(reg_regdb_search_lock);
+
+static void reg_regdb_search(struct work_struct *work)
+{
+       struct reg_regdb_search_request *request;
+       const struct ieee80211_regdomain *curdom, *regdom;
+       int i, r;
+
+       spin_lock(&reg_regdb_search_lock);
+       while (!list_empty(&reg_regdb_search_list)) {
+               request = list_first_entry(&reg_regdb_search_list,
+                                          struct reg_regdb_search_request,
+                                          list);
+               list_del(&request->list);
+
+               for (i=0; i<reg_regdb_size; i++) {
+                       curdom = reg_regdb[i];
+
+                       if (!memcmp(request->alpha2, curdom->alpha2, 2)) {
+                               r = reg_copy_regd(&regdom, curdom);
+                               if (r)
+                                       break;
+                               spin_unlock(&reg_regdb_search_lock);
+                               mutex_lock(&cfg80211_mutex);
+                               set_regdom(regdom);
+                               mutex_unlock(&cfg80211_mutex);
+                               spin_lock(&reg_regdb_search_lock);
+                               break;
+                       }
+               }
+
+               kfree(request);
+       }
+       spin_unlock(&reg_regdb_search_lock);
+}
+
+static DECLARE_WORK(reg_regdb_work, reg_regdb_search);
+
+static void reg_regdb_query(const char *alpha2)
+{
+       struct reg_regdb_search_request *request;
+
+       if (!alpha2)
+               return;
+
+       request = kzalloc(sizeof(struct reg_regdb_search_request), GFP_KERNEL);
+       if (!request)
+               return;
+
+       memcpy(request->alpha2, alpha2, 2);
+
+       spin_lock(&reg_regdb_search_lock);
+       list_add_tail(&request->list, &reg_regdb_search_list);
+       spin_unlock(&reg_regdb_search_lock);
+
+       schedule_work(&reg_regdb_work);
+}
+#else
+static inline void reg_regdb_query(const char *alpha2) {}
+#endif /* CONFIG_CFG80211_INTERNAL_REGDB */
+
 /*
  * This lets us keep regulatory code which is updated on a regulatory
  * basis in userspace.
@@ -379,6 +447,9 @@ static int call_crda(const char *alpha2)
                printk(KERN_INFO "cfg80211: 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];
 
@@ -1367,30 +1438,6 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
 }
 EXPORT_SYMBOL(wiphy_apply_custom_regulatory);
 
-static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd,
-                        const struct ieee80211_regdomain *src_regd)
-{
-       struct ieee80211_regdomain *regd;
-       int size_of_regd = 0;
-       unsigned int i;
-
-       size_of_regd = sizeof(struct ieee80211_regdomain) +
-         ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule));
-
-       regd = kzalloc(size_of_regd, GFP_KERNEL);
-       if (!regd)
-               return -ENOMEM;
-
-       memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain));
-
-       for (i = 0; i < src_regd->n_reg_rules; i++)
-               memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i],
-                       sizeof(struct ieee80211_reg_rule));
-
-       *dst_regd = regd;
-       return 0;
-}
-
 /*
  * Return value which can be used by ignore_request() to indicate
  * it has been determined we should intersect two regulatory domains