Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 5 | * Copyright 2008 Luis R. Rodriguez <lrodriguz@atheros.com> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 12 | /** |
| 13 | * DOC: Wireless regulatory infrastructure |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 14 | * |
| 15 | * The usual implementation is for a driver to read a device EEPROM to |
| 16 | * determine which regulatory domain it should be operating under, then |
| 17 | * looking up the allowable channels in a driver-local table and finally |
| 18 | * registering those channels in the wiphy structure. |
| 19 | * |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 20 | * Another set of compliance enforcement is for drivers to use their |
| 21 | * own compliance limits which can be stored on the EEPROM. The host |
| 22 | * driver or firmware may ensure these are used. |
| 23 | * |
| 24 | * In addition to all this we provide an extra layer of regulatory |
| 25 | * conformance. For drivers which do not have any regulatory |
| 26 | * information CRDA provides the complete regulatory solution. |
| 27 | * For others it provides a community effort on further restrictions |
| 28 | * to enhance compliance. |
| 29 | * |
| 30 | * Note: When number of rules --> infinity we will not be able to |
| 31 | * index on alpha2 any more, instead we'll probably have to |
| 32 | * rely on some SHA1 checksum of the regdomain for example. |
| 33 | * |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 34 | */ |
| 35 | #include <linux/kernel.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 36 | #include <linux/list.h> |
| 37 | #include <linux/random.h> |
| 38 | #include <linux/nl80211.h> |
| 39 | #include <linux/platform_device.h> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 40 | #include <net/wireless.h> |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 41 | #include <net/cfg80211.h> |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 42 | #include "core.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 43 | #include "reg.h" |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 44 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 45 | /* |
| 46 | * wiphy is set if this request's initiator is |
| 47 | * REGDOM_SET_BY_COUNTRY_IE or _DRIVER |
| 48 | */ |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 49 | struct regulatory_request { |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 50 | struct wiphy *wiphy; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 51 | enum reg_set_by initiator; |
| 52 | char alpha2[2]; |
| 53 | }; |
| 54 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 55 | static struct regulatory_request *last_request; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 56 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 57 | /* To trigger userspace events */ |
| 58 | static struct platform_device *reg_pdev; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 59 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 60 | /* Keep the ordering from large to small */ |
| 61 | static u32 supported_bandwidths[] = { |
| 62 | MHZ_TO_KHZ(40), |
| 63 | MHZ_TO_KHZ(20), |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 64 | }; |
| 65 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 66 | /* Central wireless core regulatory domains, we only need two, |
| 67 | * the current one and a world regulatory domain in case we have no |
| 68 | * information to give us an alpha2 */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 69 | static const struct ieee80211_regdomain *cfg80211_regdomain; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 70 | |
| 71 | /* We keep a static world regulatory domain in case of the absence of CRDA */ |
| 72 | static const struct ieee80211_regdomain world_regdom = { |
| 73 | .n_reg_rules = 1, |
| 74 | .alpha2 = "00", |
| 75 | .reg_rules = { |
| 76 | REG_RULE(2412-10, 2462+10, 40, 6, 20, |
| 77 | NL80211_RRF_PASSIVE_SCAN | |
| 78 | NL80211_RRF_NO_IBSS), |
| 79 | } |
| 80 | }; |
| 81 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 82 | static const struct ieee80211_regdomain *cfg80211_world_regdom = |
| 83 | &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 84 | |
| 85 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 86 | static char *ieee80211_regdom = "US"; |
| 87 | module_param(ieee80211_regdom, charp, 0444); |
| 88 | MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); |
| 89 | |
| 90 | /* We assume 40 MHz bandwidth for the old regulatory work. |
| 91 | * We make emphasis we are using the exact same frequencies |
| 92 | * as before */ |
| 93 | |
| 94 | static const struct ieee80211_regdomain us_regdom = { |
| 95 | .n_reg_rules = 6, |
| 96 | .alpha2 = "US", |
| 97 | .reg_rules = { |
| 98 | /* IEEE 802.11b/g, channels 1..11 */ |
| 99 | REG_RULE(2412-10, 2462+10, 40, 6, 27, 0), |
| 100 | /* IEEE 802.11a, channel 36 */ |
| 101 | REG_RULE(5180-10, 5180+10, 40, 6, 23, 0), |
| 102 | /* IEEE 802.11a, channel 40 */ |
| 103 | REG_RULE(5200-10, 5200+10, 40, 6, 23, 0), |
| 104 | /* IEEE 802.11a, channel 44 */ |
| 105 | REG_RULE(5220-10, 5220+10, 40, 6, 23, 0), |
| 106 | /* IEEE 802.11a, channels 48..64 */ |
| 107 | REG_RULE(5240-10, 5320+10, 40, 6, 23, 0), |
| 108 | /* IEEE 802.11a, channels 149..165, outdoor */ |
| 109 | REG_RULE(5745-10, 5825+10, 40, 6, 30, 0), |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | static const struct ieee80211_regdomain jp_regdom = { |
| 114 | .n_reg_rules = 3, |
| 115 | .alpha2 = "JP", |
| 116 | .reg_rules = { |
| 117 | /* IEEE 802.11b/g, channels 1..14 */ |
| 118 | REG_RULE(2412-10, 2484+10, 40, 6, 20, 0), |
| 119 | /* IEEE 802.11a, channels 34..48 */ |
| 120 | REG_RULE(5170-10, 5240+10, 40, 6, 20, |
| 121 | NL80211_RRF_PASSIVE_SCAN), |
| 122 | /* IEEE 802.11a, channels 52..64 */ |
| 123 | REG_RULE(5260-10, 5320+10, 40, 6, 20, |
| 124 | NL80211_RRF_NO_IBSS | |
| 125 | NL80211_RRF_DFS), |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | static const struct ieee80211_regdomain eu_regdom = { |
| 130 | .n_reg_rules = 6, |
| 131 | /* This alpha2 is bogus, we leave it here just for stupid |
| 132 | * backward compatibility */ |
| 133 | .alpha2 = "EU", |
| 134 | .reg_rules = { |
| 135 | /* IEEE 802.11b/g, channels 1..13 */ |
| 136 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 137 | /* IEEE 802.11a, channel 36 */ |
| 138 | REG_RULE(5180-10, 5180+10, 40, 6, 23, |
| 139 | NL80211_RRF_PASSIVE_SCAN), |
| 140 | /* IEEE 802.11a, channel 40 */ |
| 141 | REG_RULE(5200-10, 5200+10, 40, 6, 23, |
| 142 | NL80211_RRF_PASSIVE_SCAN), |
| 143 | /* IEEE 802.11a, channel 44 */ |
| 144 | REG_RULE(5220-10, 5220+10, 40, 6, 23, |
| 145 | NL80211_RRF_PASSIVE_SCAN), |
| 146 | /* IEEE 802.11a, channels 48..64 */ |
| 147 | REG_RULE(5240-10, 5320+10, 40, 6, 20, |
| 148 | NL80211_RRF_NO_IBSS | |
| 149 | NL80211_RRF_DFS), |
| 150 | /* IEEE 802.11a, channels 100..140 */ |
| 151 | REG_RULE(5500-10, 5700+10, 40, 6, 30, |
| 152 | NL80211_RRF_NO_IBSS | |
| 153 | NL80211_RRF_DFS), |
| 154 | } |
| 155 | }; |
| 156 | |
| 157 | static const struct ieee80211_regdomain *static_regdom(char *alpha2) |
| 158 | { |
| 159 | if (alpha2[0] == 'U' && alpha2[1] == 'S') |
| 160 | return &us_regdom; |
| 161 | if (alpha2[0] == 'J' && alpha2[1] == 'P') |
| 162 | return &jp_regdom; |
| 163 | if (alpha2[0] == 'E' && alpha2[1] == 'U') |
| 164 | return &eu_regdom; |
| 165 | /* Default, as per the old rules */ |
| 166 | return &us_regdom; |
| 167 | } |
| 168 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 169 | static bool is_old_static_regdom(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 170 | { |
| 171 | if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom) |
| 172 | return true; |
| 173 | return false; |
| 174 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 175 | #else |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 176 | static inline bool is_old_static_regdom(const struct ieee80211_regdomain *rd) |
| 177 | { |
| 178 | return false; |
| 179 | } |
| 180 | #endif |
| 181 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 182 | static void reset_regdomains(void) |
| 183 | { |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 184 | /* avoid freeing static information or freeing something twice */ |
| 185 | if (cfg80211_regdomain == cfg80211_world_regdom) |
| 186 | cfg80211_regdomain = NULL; |
| 187 | if (cfg80211_world_regdom == &world_regdom) |
| 188 | cfg80211_world_regdom = NULL; |
| 189 | if (cfg80211_regdomain == &world_regdom) |
| 190 | cfg80211_regdomain = NULL; |
| 191 | if (is_old_static_regdom(cfg80211_regdomain)) |
| 192 | cfg80211_regdomain = NULL; |
| 193 | |
| 194 | kfree(cfg80211_regdomain); |
| 195 | kfree(cfg80211_world_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 196 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 197 | cfg80211_world_regdom = &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 198 | cfg80211_regdomain = NULL; |
| 199 | } |
| 200 | |
| 201 | /* Dynamic world regulatory domain requested by the wireless |
| 202 | * core upon initialization */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 203 | static void update_world_regdomain(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 204 | { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 205 | BUG_ON(!last_request); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 206 | |
| 207 | reset_regdomains(); |
| 208 | |
| 209 | cfg80211_world_regdom = rd; |
| 210 | cfg80211_regdomain = rd; |
| 211 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 212 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 213 | bool is_world_regdom(const char *alpha2) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 214 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 215 | if (!alpha2) |
| 216 | return false; |
| 217 | if (alpha2[0] == '0' && alpha2[1] == '0') |
| 218 | return true; |
| 219 | return false; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 220 | } |
| 221 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 222 | static bool is_alpha2_set(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 223 | { |
| 224 | if (!alpha2) |
| 225 | return false; |
| 226 | if (alpha2[0] != 0 && alpha2[1] != 0) |
| 227 | return true; |
| 228 | return false; |
| 229 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 230 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 231 | static bool is_alpha_upper(char letter) |
| 232 | { |
| 233 | /* ASCII A - Z */ |
| 234 | if (letter >= 65 && letter <= 90) |
| 235 | return true; |
| 236 | return false; |
| 237 | } |
| 238 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 239 | static bool is_unknown_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 240 | { |
| 241 | if (!alpha2) |
| 242 | return false; |
| 243 | /* Special case where regulatory domain was built by driver |
| 244 | * but a specific alpha2 cannot be determined */ |
| 245 | if (alpha2[0] == '9' && alpha2[1] == '9') |
| 246 | return true; |
| 247 | return false; |
| 248 | } |
| 249 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 250 | static bool is_an_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 251 | { |
| 252 | if (!alpha2) |
| 253 | return false; |
| 254 | if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1])) |
| 255 | return true; |
| 256 | return false; |
| 257 | } |
| 258 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 259 | static bool alpha2_equal(const char *alpha2_x, const char *alpha2_y) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 260 | { |
| 261 | if (!alpha2_x || !alpha2_y) |
| 262 | return false; |
| 263 | if (alpha2_x[0] == alpha2_y[0] && |
| 264 | alpha2_x[1] == alpha2_y[1]) |
| 265 | return true; |
| 266 | return false; |
| 267 | } |
| 268 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 269 | static bool regdom_changed(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 270 | { |
| 271 | if (!cfg80211_regdomain) |
| 272 | return true; |
| 273 | if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) |
| 274 | return false; |
| 275 | return true; |
| 276 | } |
| 277 | |
| 278 | /* This lets us keep regulatory code which is updated on a regulatory |
| 279 | * basis in userspace. */ |
| 280 | static int call_crda(const char *alpha2) |
| 281 | { |
| 282 | char country_env[9 + 2] = "COUNTRY="; |
| 283 | char *envp[] = { |
| 284 | country_env, |
| 285 | NULL |
| 286 | }; |
| 287 | |
| 288 | if (!is_world_regdom((char *) alpha2)) |
| 289 | printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n", |
| 290 | alpha2[0], alpha2[1]); |
| 291 | else |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 292 | printk(KERN_INFO "cfg80211: Calling CRDA to update world " |
| 293 | "regulatory domain\n"); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 294 | |
| 295 | country_env[8] = alpha2[0]; |
| 296 | country_env[9] = alpha2[1]; |
| 297 | |
| 298 | return kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, envp); |
| 299 | } |
| 300 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 301 | /* Used by nl80211 before kmalloc'ing our regulatory domain */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 302 | bool reg_is_valid_request(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 303 | { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 304 | if (!last_request) |
| 305 | return false; |
| 306 | |
| 307 | return alpha2_equal(last_request->alpha2, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* Sanity check on a regulatory rule */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 311 | static bool is_valid_reg_rule(const struct ieee80211_reg_rule *rule) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 312 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 313 | const struct ieee80211_freq_range *freq_range = &rule->freq_range; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 314 | u32 freq_diff; |
| 315 | |
| 316 | if (freq_range->start_freq_khz == 0 || freq_range->end_freq_khz == 0) |
| 317 | return false; |
| 318 | |
| 319 | if (freq_range->start_freq_khz > freq_range->end_freq_khz) |
| 320 | return false; |
| 321 | |
| 322 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 323 | |
Luis R. Rodriguez | d71aaf6 | 2008-10-30 13:33:52 -0700 | [diff] [blame^] | 324 | if (freq_diff <= 0 || freq_range->max_bandwidth_khz > freq_diff) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 325 | return false; |
| 326 | |
| 327 | return true; |
| 328 | } |
| 329 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 330 | static bool is_valid_rd(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 331 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 332 | const struct ieee80211_reg_rule *reg_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 333 | unsigned int i; |
| 334 | |
| 335 | if (!rd->n_reg_rules) |
| 336 | return false; |
| 337 | |
| 338 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 339 | reg_rule = &rd->reg_rules[i]; |
| 340 | if (!is_valid_reg_rule(reg_rule)) |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | /* Returns value in KHz */ |
| 348 | static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range, |
| 349 | u32 freq) |
| 350 | { |
| 351 | unsigned int i; |
| 352 | for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) { |
| 353 | u32 start_freq_khz = freq - supported_bandwidths[i]/2; |
| 354 | u32 end_freq_khz = freq + supported_bandwidths[i]/2; |
| 355 | if (start_freq_khz >= freq_range->start_freq_khz && |
| 356 | end_freq_khz <= freq_range->end_freq_khz) |
| 357 | return supported_bandwidths[i]; |
| 358 | } |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may |
| 363 | * want to just have the channel structure use these */ |
| 364 | static u32 map_regdom_flags(u32 rd_flags) |
| 365 | { |
| 366 | u32 channel_flags = 0; |
| 367 | if (rd_flags & NL80211_RRF_PASSIVE_SCAN) |
| 368 | channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
| 369 | if (rd_flags & NL80211_RRF_NO_IBSS) |
| 370 | channel_flags |= IEEE80211_CHAN_NO_IBSS; |
| 371 | if (rd_flags & NL80211_RRF_DFS) |
| 372 | channel_flags |= IEEE80211_CHAN_RADAR; |
| 373 | return channel_flags; |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * freq_reg_info - get regulatory information for the given frequency |
| 378 | * @center_freq: Frequency in KHz for which we want regulatory information for |
| 379 | * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one |
| 380 | * you can set this to 0. If this frequency is allowed we then set |
| 381 | * this value to the maximum allowed bandwidth. |
| 382 | * @reg_rule: the regulatory rule which we have for this frequency |
| 383 | * |
| 384 | * Use this function to get the regulatory rule for a specific frequency. |
| 385 | */ |
| 386 | static int freq_reg_info(u32 center_freq, u32 *bandwidth, |
| 387 | const struct ieee80211_reg_rule **reg_rule) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 388 | { |
| 389 | int i; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 390 | u32 max_bandwidth = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 391 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 392 | if (!cfg80211_regdomain) |
| 393 | return -EINVAL; |
| 394 | |
| 395 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 396 | const struct ieee80211_reg_rule *rr; |
| 397 | const struct ieee80211_freq_range *fr = NULL; |
| 398 | const struct ieee80211_power_rule *pr = NULL; |
| 399 | |
| 400 | rr = &cfg80211_regdomain->reg_rules[i]; |
| 401 | fr = &rr->freq_range; |
| 402 | pr = &rr->power_rule; |
| 403 | max_bandwidth = freq_max_bandwidth(fr, center_freq); |
| 404 | if (max_bandwidth && *bandwidth <= max_bandwidth) { |
| 405 | *reg_rule = rr; |
| 406 | *bandwidth = max_bandwidth; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | } |
| 410 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 411 | return !max_bandwidth; |
| 412 | } |
| 413 | |
| 414 | static void handle_channel(struct ieee80211_channel *chan) |
| 415 | { |
| 416 | int r; |
| 417 | u32 flags = chan->orig_flags; |
| 418 | u32 max_bandwidth = 0; |
| 419 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 420 | const struct ieee80211_power_rule *power_rule = NULL; |
| 421 | |
| 422 | r = freq_reg_info(MHZ_TO_KHZ(chan->center_freq), |
| 423 | &max_bandwidth, ®_rule); |
| 424 | |
| 425 | if (r) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 426 | flags |= IEEE80211_CHAN_DISABLED; |
| 427 | chan->flags = flags; |
| 428 | return; |
| 429 | } |
| 430 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 431 | power_rule = ®_rule->power_rule; |
| 432 | |
| 433 | chan->flags = flags | map_regdom_flags(reg_rule->flags); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 434 | chan->max_antenna_gain = min(chan->orig_mag, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 435 | (int) MBI_TO_DBI(power_rule->max_antenna_gain)); |
| 436 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); |
John W. Linville | 253898c | 2008-04-03 15:32:54 -0400 | [diff] [blame] | 437 | if (chan->orig_mpwr) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 438 | chan->max_power = min(chan->orig_mpwr, |
| 439 | (int) MBM_TO_DBM(power_rule->max_eirp)); |
John W. Linville | 253898c | 2008-04-03 15:32:54 -0400 | [diff] [blame] | 440 | else |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 441 | chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 444 | static void handle_band(struct ieee80211_supported_band *sband) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 445 | { |
| 446 | int i; |
| 447 | |
| 448 | for (i = 0; i < sband->n_channels; i++) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 449 | handle_channel(&sband->channels[i]); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 450 | } |
| 451 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 452 | static void update_all_wiphy_regulatory(enum reg_set_by setby) |
| 453 | { |
| 454 | struct cfg80211_registered_device *drv; |
| 455 | |
| 456 | list_for_each_entry(drv, &cfg80211_drv_list, list) |
| 457 | wiphy_update_regulatory(&drv->wiphy, setby); |
| 458 | } |
| 459 | |
| 460 | void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 461 | { |
| 462 | enum ieee80211_band band; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 463 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 464 | if (wiphy->bands[band]) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 465 | handle_band(wiphy->bands[band]); |
| 466 | if (wiphy->reg_notifier) |
| 467 | wiphy->reg_notifier(wiphy, setby); |
| 468 | } |
| 469 | } |
| 470 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 471 | /* This has the logic which determines when a new request |
| 472 | * should be ignored. */ |
| 473 | static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by, |
| 474 | const char *alpha2) |
| 475 | { |
| 476 | /* All initial requests are respected */ |
| 477 | if (!last_request) |
| 478 | return 0; |
| 479 | |
| 480 | switch (set_by) { |
| 481 | case REGDOM_SET_BY_INIT: |
| 482 | return -EINVAL; |
| 483 | case REGDOM_SET_BY_CORE: |
| 484 | /* |
| 485 | * Always respect new wireless core hints, should only happen |
| 486 | * when updating the world regulatory domain at init. |
| 487 | */ |
| 488 | return 0; |
| 489 | case REGDOM_SET_BY_COUNTRY_IE: |
| 490 | if (unlikely(!is_an_alpha2(alpha2))) |
| 491 | return -EINVAL; |
| 492 | if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) { |
| 493 | if (last_request->wiphy != wiphy) { |
| 494 | /* |
| 495 | * Two cards with two APs claiming different |
| 496 | * different Country IE alpha2s. We could |
| 497 | * intersect them, but that seems unlikely |
| 498 | * to be correct. Reject second one for now. |
| 499 | */ |
| 500 | if (!alpha2_equal(alpha2, |
| 501 | cfg80211_regdomain->alpha2)) |
| 502 | return -EOPNOTSUPP; |
| 503 | return -EALREADY; |
| 504 | } |
| 505 | /* Two consecutive Country IE hints on the same wiphy */ |
| 506 | if (!alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) |
| 507 | return 0; |
| 508 | return -EALREADY; |
| 509 | } |
| 510 | /* |
| 511 | * Ignore Country IE hints for now, need to think about |
| 512 | * what we need to do to support multi-domain operation. |
| 513 | */ |
| 514 | return -EOPNOTSUPP; |
| 515 | case REGDOM_SET_BY_DRIVER: |
| 516 | if (last_request->initiator == REGDOM_SET_BY_DRIVER) |
| 517 | return -EALREADY; |
| 518 | return 0; |
| 519 | case REGDOM_SET_BY_USER: |
| 520 | /* |
| 521 | * If the user wants to override the AP's hint, we may |
| 522 | * need to follow both and use the intersection. For now, |
| 523 | * reject any such attempt (but we don't support country |
| 524 | * IEs right now anyway.) |
| 525 | */ |
| 526 | if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) |
| 527 | return -EOPNOTSUPP; |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | return -EINVAL; |
| 532 | } |
| 533 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 534 | /* Caller must hold &cfg80211_drv_mutex */ |
| 535 | int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by, |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 536 | const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 537 | { |
| 538 | struct regulatory_request *request; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 539 | int r = 0; |
| 540 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 541 | r = ignore_request(wiphy, set_by, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 542 | if (r) |
| 543 | return r; |
| 544 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 545 | switch (set_by) { |
| 546 | case REGDOM_SET_BY_CORE: |
| 547 | case REGDOM_SET_BY_COUNTRY_IE: |
| 548 | case REGDOM_SET_BY_DRIVER: |
| 549 | case REGDOM_SET_BY_USER: |
| 550 | request = kzalloc(sizeof(struct regulatory_request), |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 551 | GFP_KERNEL); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 552 | if (!request) |
| 553 | return -ENOMEM; |
| 554 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 555 | request->alpha2[0] = alpha2[0]; |
| 556 | request->alpha2[1] = alpha2[1]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 557 | request->initiator = set_by; |
| 558 | request->wiphy = wiphy; |
| 559 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 560 | kfree(last_request); |
| 561 | last_request = request; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 562 | r = call_crda(alpha2); |
| 563 | #ifndef CONFIG_WIRELESS_OLD_REGULATORY |
| 564 | if (r) |
| 565 | printk(KERN_ERR "cfg80211: Failed calling CRDA\n"); |
| 566 | #endif |
| 567 | break; |
| 568 | default: |
| 569 | r = -ENOTSUPP; |
| 570 | break; |
| 571 | } |
| 572 | |
| 573 | return r; |
| 574 | } |
| 575 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 576 | void regulatory_hint(struct wiphy *wiphy, const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 577 | { |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 578 | BUG_ON(!alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 579 | |
| 580 | mutex_lock(&cfg80211_drv_mutex); |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 581 | __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 582 | mutex_unlock(&cfg80211_drv_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 583 | } |
| 584 | EXPORT_SYMBOL(regulatory_hint); |
| 585 | |
| 586 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 587 | static void print_rd_rules(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 588 | { |
| 589 | unsigned int i; |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 590 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 591 | const struct ieee80211_freq_range *freq_range = NULL; |
| 592 | const struct ieee80211_power_rule *power_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 593 | |
| 594 | printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), " |
| 595 | "(max_antenna_gain, max_eirp)\n"); |
| 596 | |
| 597 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 598 | reg_rule = &rd->reg_rules[i]; |
| 599 | freq_range = ®_rule->freq_range; |
| 600 | power_rule = ®_rule->power_rule; |
| 601 | |
| 602 | /* There may not be documentation for max antenna gain |
| 603 | * in certain regions */ |
| 604 | if (power_rule->max_antenna_gain) |
| 605 | printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " |
| 606 | "(%d mBi, %d mBm)\n", |
| 607 | freq_range->start_freq_khz, |
| 608 | freq_range->end_freq_khz, |
| 609 | freq_range->max_bandwidth_khz, |
| 610 | power_rule->max_antenna_gain, |
| 611 | power_rule->max_eirp); |
| 612 | else |
| 613 | printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " |
| 614 | "(N/A, %d mBm)\n", |
| 615 | freq_range->start_freq_khz, |
| 616 | freq_range->end_freq_khz, |
| 617 | freq_range->max_bandwidth_khz, |
| 618 | power_rule->max_eirp); |
| 619 | } |
| 620 | } |
| 621 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 622 | static void print_regdomain(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 623 | { |
| 624 | |
| 625 | if (is_world_regdom(rd->alpha2)) |
| 626 | printk(KERN_INFO "cfg80211: World regulatory " |
| 627 | "domain updated:\n"); |
| 628 | else { |
| 629 | if (is_unknown_alpha2(rd->alpha2)) |
| 630 | printk(KERN_INFO "cfg80211: Regulatory domain " |
| 631 | "changed to driver built-in settings " |
| 632 | "(unknown country)\n"); |
| 633 | else |
| 634 | printk(KERN_INFO "cfg80211: Regulatory domain " |
| 635 | "changed to country: %c%c\n", |
| 636 | rd->alpha2[0], rd->alpha2[1]); |
| 637 | } |
| 638 | print_rd_rules(rd); |
| 639 | } |
| 640 | |
Johannes Berg | 2df7816 | 2008-10-28 16:49:41 +0100 | [diff] [blame] | 641 | static void print_regdomain_info(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 642 | { |
| 643 | printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n", |
| 644 | rd->alpha2[0], rd->alpha2[1]); |
| 645 | print_rd_rules(rd); |
| 646 | } |
| 647 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 648 | /* Takes ownership of rd only if it doesn't fail */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 649 | static int __set_regdom(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 650 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 651 | /* Some basic sanity checks first */ |
| 652 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 653 | if (is_world_regdom(rd->alpha2)) { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 654 | if (WARN_ON(!reg_is_valid_request(rd->alpha2))) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 655 | return -EINVAL; |
| 656 | update_world_regdomain(rd); |
| 657 | return 0; |
| 658 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 659 | |
| 660 | if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && |
| 661 | !is_unknown_alpha2(rd->alpha2)) |
| 662 | return -EINVAL; |
| 663 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 664 | if (!last_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 665 | return -EINVAL; |
| 666 | |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 667 | /* allow overriding the static definitions if CRDA is present */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 668 | if (!is_old_static_regdom(cfg80211_regdomain) && |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 669 | !regdom_changed(rd->alpha2)) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 670 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 671 | |
| 672 | /* Now lets set the regulatory domain, update all driver channels |
| 673 | * and finally inform them of what we have done, in case they want |
| 674 | * to review or adjust their own settings based on their own |
| 675 | * internal EEPROM data */ |
| 676 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 677 | if (WARN_ON(!reg_is_valid_request(rd->alpha2))) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 678 | return -EINVAL; |
| 679 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 680 | reset_regdomains(); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 681 | |
| 682 | /* Country IE parsing coming soon */ |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 683 | switch (last_request->initiator) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 684 | case REGDOM_SET_BY_CORE: |
| 685 | case REGDOM_SET_BY_DRIVER: |
| 686 | case REGDOM_SET_BY_USER: |
| 687 | if (!is_valid_rd(rd)) { |
| 688 | printk(KERN_ERR "cfg80211: Invalid " |
| 689 | "regulatory domain detected:\n"); |
| 690 | print_regdomain_info(rd); |
| 691 | return -EINVAL; |
| 692 | } |
| 693 | break; |
| 694 | case REGDOM_SET_BY_COUNTRY_IE: /* Not yet */ |
| 695 | WARN_ON(1); |
| 696 | default: |
| 697 | return -EOPNOTSUPP; |
| 698 | } |
| 699 | |
| 700 | /* Tada! */ |
| 701 | cfg80211_regdomain = rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | |
| 707 | /* Use this call to set the current regulatory domain. Conflicts with |
| 708 | * multiple drivers can be ironed out later. Caller must've already |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 709 | * kmalloc'd the rd structure. Caller must hold cfg80211_drv_mutex */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 710 | int set_regdom(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 711 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 712 | int r; |
| 713 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 714 | /* Note that this doesn't update the wiphys, this is done below */ |
| 715 | r = __set_regdom(rd); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 716 | if (r) { |
| 717 | kfree(rd); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 718 | return r; |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 719 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 720 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 721 | /* This would make this whole thing pointless */ |
| 722 | BUG_ON(rd != cfg80211_regdomain); |
| 723 | |
| 724 | /* update all wiphys now with the new established regulatory domain */ |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 725 | update_all_wiphy_regulatory(last_request->initiator); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 726 | |
| 727 | print_regdomain(rd); |
| 728 | |
| 729 | return r; |
| 730 | } |
| 731 | |
| 732 | int regulatory_init(void) |
| 733 | { |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 734 | int err; |
| 735 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 736 | reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0); |
| 737 | if (IS_ERR(reg_pdev)) |
| 738 | return PTR_ERR(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 739 | |
| 740 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 741 | cfg80211_regdomain = static_regdom(ieee80211_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 742 | |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 743 | printk(KERN_INFO "cfg80211: Using static regulatory domain info\n"); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 744 | print_regdomain_info(cfg80211_regdomain); |
| 745 | /* The old code still requests for a new regdomain and if |
| 746 | * you have CRDA you get it updated, otherwise you get |
| 747 | * stuck with the static values. We ignore "EU" code as |
| 748 | * that is not a valid ISO / IEC 3166 alpha2 */ |
Johannes Berg | ac9440a | 2008-10-21 11:08:27 +0200 | [diff] [blame] | 749 | if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U') |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 750 | err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 751 | ieee80211_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 752 | #else |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 753 | cfg80211_regdomain = cfg80211_world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 754 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 755 | err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, "00"); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 756 | if (err) |
| 757 | printk(KERN_ERR "cfg80211: calling CRDA failed - " |
| 758 | "unable to update world regulatory domain, " |
| 759 | "using static definition\n"); |
| 760 | #endif |
| 761 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | void regulatory_exit(void) |
| 766 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 767 | mutex_lock(&cfg80211_drv_mutex); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 768 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 769 | reset_regdomains(); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 770 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 771 | kfree(last_request); |
| 772 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 773 | platform_device_unregister(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 774 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 775 | mutex_unlock(&cfg80211_drv_mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 776 | } |