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 | |
Luis R. Rodriguez | 5166ccd | 2008-10-30 13:33:56 -0700 | [diff] [blame] | 45 | /* Receipt of information from last regulatory request */ |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 46 | static struct regulatory_request *last_request; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 47 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 48 | /* To trigger userspace events */ |
| 49 | static struct platform_device *reg_pdev; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 50 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 51 | /* Keep the ordering from large to small */ |
| 52 | static u32 supported_bandwidths[] = { |
| 53 | MHZ_TO_KHZ(40), |
| 54 | MHZ_TO_KHZ(20), |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 55 | }; |
| 56 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 57 | /* Central wireless core regulatory domains, we only need two, |
| 58 | * the current one and a world regulatory domain in case we have no |
| 59 | * information to give us an alpha2 */ |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 60 | const struct ieee80211_regdomain *cfg80211_regdomain; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 61 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 62 | /* We use this as a place for the rd structure built from the |
| 63 | * last parsed country IE to rest until CRDA gets back to us with |
| 64 | * what it thinks should apply for the same country */ |
| 65 | static const struct ieee80211_regdomain *country_ie_regdomain; |
| 66 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 67 | /* We keep a static world regulatory domain in case of the absence of CRDA */ |
| 68 | static const struct ieee80211_regdomain world_regdom = { |
| 69 | .n_reg_rules = 1, |
| 70 | .alpha2 = "00", |
| 71 | .reg_rules = { |
| 72 | REG_RULE(2412-10, 2462+10, 40, 6, 20, |
| 73 | NL80211_RRF_PASSIVE_SCAN | |
| 74 | NL80211_RRF_NO_IBSS), |
| 75 | } |
| 76 | }; |
| 77 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 78 | static const struct ieee80211_regdomain *cfg80211_world_regdom = |
| 79 | &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 80 | |
| 81 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 82 | static char *ieee80211_regdom = "US"; |
| 83 | module_param(ieee80211_regdom, charp, 0444); |
| 84 | MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code"); |
| 85 | |
| 86 | /* We assume 40 MHz bandwidth for the old regulatory work. |
| 87 | * We make emphasis we are using the exact same frequencies |
| 88 | * as before */ |
| 89 | |
| 90 | static const struct ieee80211_regdomain us_regdom = { |
| 91 | .n_reg_rules = 6, |
| 92 | .alpha2 = "US", |
| 93 | .reg_rules = { |
| 94 | /* IEEE 802.11b/g, channels 1..11 */ |
| 95 | REG_RULE(2412-10, 2462+10, 40, 6, 27, 0), |
| 96 | /* IEEE 802.11a, channel 36 */ |
| 97 | REG_RULE(5180-10, 5180+10, 40, 6, 23, 0), |
| 98 | /* IEEE 802.11a, channel 40 */ |
| 99 | REG_RULE(5200-10, 5200+10, 40, 6, 23, 0), |
| 100 | /* IEEE 802.11a, channel 44 */ |
| 101 | REG_RULE(5220-10, 5220+10, 40, 6, 23, 0), |
| 102 | /* IEEE 802.11a, channels 48..64 */ |
| 103 | REG_RULE(5240-10, 5320+10, 40, 6, 23, 0), |
| 104 | /* IEEE 802.11a, channels 149..165, outdoor */ |
| 105 | REG_RULE(5745-10, 5825+10, 40, 6, 30, 0), |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | static const struct ieee80211_regdomain jp_regdom = { |
| 110 | .n_reg_rules = 3, |
| 111 | .alpha2 = "JP", |
| 112 | .reg_rules = { |
| 113 | /* IEEE 802.11b/g, channels 1..14 */ |
| 114 | REG_RULE(2412-10, 2484+10, 40, 6, 20, 0), |
| 115 | /* IEEE 802.11a, channels 34..48 */ |
| 116 | REG_RULE(5170-10, 5240+10, 40, 6, 20, |
| 117 | NL80211_RRF_PASSIVE_SCAN), |
| 118 | /* IEEE 802.11a, channels 52..64 */ |
| 119 | REG_RULE(5260-10, 5320+10, 40, 6, 20, |
| 120 | NL80211_RRF_NO_IBSS | |
| 121 | NL80211_RRF_DFS), |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | static const struct ieee80211_regdomain eu_regdom = { |
| 126 | .n_reg_rules = 6, |
| 127 | /* This alpha2 is bogus, we leave it here just for stupid |
| 128 | * backward compatibility */ |
| 129 | .alpha2 = "EU", |
| 130 | .reg_rules = { |
| 131 | /* IEEE 802.11b/g, channels 1..13 */ |
| 132 | REG_RULE(2412-10, 2472+10, 40, 6, 20, 0), |
| 133 | /* IEEE 802.11a, channel 36 */ |
| 134 | REG_RULE(5180-10, 5180+10, 40, 6, 23, |
| 135 | NL80211_RRF_PASSIVE_SCAN), |
| 136 | /* IEEE 802.11a, channel 40 */ |
| 137 | REG_RULE(5200-10, 5200+10, 40, 6, 23, |
| 138 | NL80211_RRF_PASSIVE_SCAN), |
| 139 | /* IEEE 802.11a, channel 44 */ |
| 140 | REG_RULE(5220-10, 5220+10, 40, 6, 23, |
| 141 | NL80211_RRF_PASSIVE_SCAN), |
| 142 | /* IEEE 802.11a, channels 48..64 */ |
| 143 | REG_RULE(5240-10, 5320+10, 40, 6, 20, |
| 144 | NL80211_RRF_NO_IBSS | |
| 145 | NL80211_RRF_DFS), |
| 146 | /* IEEE 802.11a, channels 100..140 */ |
| 147 | REG_RULE(5500-10, 5700+10, 40, 6, 30, |
| 148 | NL80211_RRF_NO_IBSS | |
| 149 | NL80211_RRF_DFS), |
| 150 | } |
| 151 | }; |
| 152 | |
| 153 | static const struct ieee80211_regdomain *static_regdom(char *alpha2) |
| 154 | { |
| 155 | if (alpha2[0] == 'U' && alpha2[1] == 'S') |
| 156 | return &us_regdom; |
| 157 | if (alpha2[0] == 'J' && alpha2[1] == 'P') |
| 158 | return &jp_regdom; |
| 159 | if (alpha2[0] == 'E' && alpha2[1] == 'U') |
| 160 | return &eu_regdom; |
| 161 | /* Default, as per the old rules */ |
| 162 | return &us_regdom; |
| 163 | } |
| 164 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 165 | static bool is_old_static_regdom(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 166 | { |
| 167 | if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom) |
| 168 | return true; |
| 169 | return false; |
| 170 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 171 | #else |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 172 | static inline bool is_old_static_regdom(const struct ieee80211_regdomain *rd) |
| 173 | { |
| 174 | return false; |
| 175 | } |
| 176 | #endif |
| 177 | |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 178 | static void reset_regdomains(void) |
| 179 | { |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 180 | /* avoid freeing static information or freeing something twice */ |
| 181 | if (cfg80211_regdomain == cfg80211_world_regdom) |
| 182 | cfg80211_regdomain = NULL; |
| 183 | if (cfg80211_world_regdom == &world_regdom) |
| 184 | cfg80211_world_regdom = NULL; |
| 185 | if (cfg80211_regdomain == &world_regdom) |
| 186 | cfg80211_regdomain = NULL; |
| 187 | if (is_old_static_regdom(cfg80211_regdomain)) |
| 188 | cfg80211_regdomain = NULL; |
| 189 | |
| 190 | kfree(cfg80211_regdomain); |
| 191 | kfree(cfg80211_world_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 192 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 193 | cfg80211_world_regdom = &world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 194 | cfg80211_regdomain = NULL; |
| 195 | } |
| 196 | |
| 197 | /* Dynamic world regulatory domain requested by the wireless |
| 198 | * core upon initialization */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 199 | static void update_world_regdomain(const struct ieee80211_regdomain *rd) |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 200 | { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 201 | BUG_ON(!last_request); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 202 | |
| 203 | reset_regdomains(); |
| 204 | |
| 205 | cfg80211_world_regdom = rd; |
| 206 | cfg80211_regdomain = rd; |
| 207 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 208 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 209 | bool is_world_regdom(const char *alpha2) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 210 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 211 | if (!alpha2) |
| 212 | return false; |
| 213 | if (alpha2[0] == '0' && alpha2[1] == '0') |
| 214 | return true; |
| 215 | return false; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 216 | } |
| 217 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 218 | static bool is_alpha2_set(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 219 | { |
| 220 | if (!alpha2) |
| 221 | return false; |
| 222 | if (alpha2[0] != 0 && alpha2[1] != 0) |
| 223 | return true; |
| 224 | return false; |
| 225 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 226 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 227 | static bool is_alpha_upper(char letter) |
| 228 | { |
| 229 | /* ASCII A - Z */ |
| 230 | if (letter >= 65 && letter <= 90) |
| 231 | return true; |
| 232 | return false; |
| 233 | } |
| 234 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 235 | static bool is_unknown_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 236 | { |
| 237 | if (!alpha2) |
| 238 | return false; |
| 239 | /* Special case where regulatory domain was built by driver |
| 240 | * but a specific alpha2 cannot be determined */ |
| 241 | if (alpha2[0] == '9' && alpha2[1] == '9') |
| 242 | return true; |
| 243 | return false; |
| 244 | } |
| 245 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 246 | static bool is_intersected_alpha2(const char *alpha2) |
| 247 | { |
| 248 | if (!alpha2) |
| 249 | return false; |
| 250 | /* Special case where regulatory domain is the |
| 251 | * result of an intersection between two regulatory domain |
| 252 | * structures */ |
| 253 | if (alpha2[0] == '9' && alpha2[1] == '8') |
| 254 | return true; |
| 255 | return false; |
| 256 | } |
| 257 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 258 | static bool is_an_alpha2(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 259 | { |
| 260 | if (!alpha2) |
| 261 | return false; |
| 262 | if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1])) |
| 263 | return true; |
| 264 | return false; |
| 265 | } |
| 266 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 267 | 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] | 268 | { |
| 269 | if (!alpha2_x || !alpha2_y) |
| 270 | return false; |
| 271 | if (alpha2_x[0] == alpha2_y[0] && |
| 272 | alpha2_x[1] == alpha2_y[1]) |
| 273 | return true; |
| 274 | return false; |
| 275 | } |
| 276 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 277 | static bool regdom_changed(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 278 | { |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 279 | assert_cfg80211_lock(); |
| 280 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 281 | if (!cfg80211_regdomain) |
| 282 | return true; |
| 283 | if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) |
| 284 | return false; |
| 285 | return true; |
| 286 | } |
| 287 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 288 | /** |
| 289 | * country_ie_integrity_changes - tells us if the country IE has changed |
| 290 | * @checksum: checksum of country IE of fields we are interested in |
| 291 | * |
| 292 | * If the country IE has not changed you can ignore it safely. This is |
| 293 | * useful to determine if two devices are seeing two different country IEs |
| 294 | * even on the same alpha2. Note that this will return false if no IE has |
| 295 | * been set on the wireless core yet. |
| 296 | */ |
| 297 | static bool country_ie_integrity_changes(u32 checksum) |
| 298 | { |
| 299 | /* If no IE has been set then the checksum doesn't change */ |
| 300 | if (unlikely(!last_request->country_ie_checksum)) |
| 301 | return false; |
| 302 | if (unlikely(last_request->country_ie_checksum != checksum)) |
| 303 | return true; |
| 304 | return false; |
| 305 | } |
| 306 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 307 | /* This lets us keep regulatory code which is updated on a regulatory |
| 308 | * basis in userspace. */ |
| 309 | static int call_crda(const char *alpha2) |
| 310 | { |
| 311 | char country_env[9 + 2] = "COUNTRY="; |
| 312 | char *envp[] = { |
| 313 | country_env, |
| 314 | NULL |
| 315 | }; |
| 316 | |
| 317 | if (!is_world_regdom((char *) alpha2)) |
| 318 | printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n", |
| 319 | alpha2[0], alpha2[1]); |
| 320 | else |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 321 | printk(KERN_INFO "cfg80211: Calling CRDA to update world " |
| 322 | "regulatory domain\n"); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 323 | |
| 324 | country_env[8] = alpha2[0]; |
| 325 | country_env[9] = alpha2[1]; |
| 326 | |
| 327 | return kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, envp); |
| 328 | } |
| 329 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 330 | /* Used by nl80211 before kmalloc'ing our regulatory domain */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 331 | bool reg_is_valid_request(const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 332 | { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 333 | if (!last_request) |
| 334 | return false; |
| 335 | |
| 336 | return alpha2_equal(last_request->alpha2, alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* Sanity check on a regulatory rule */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 340 | 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] | 341 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 342 | const struct ieee80211_freq_range *freq_range = &rule->freq_range; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 343 | u32 freq_diff; |
| 344 | |
Luis R. Rodriguez | 91e9900 | 2008-11-12 14:21:55 -0800 | [diff] [blame] | 345 | if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 346 | return false; |
| 347 | |
| 348 | if (freq_range->start_freq_khz > freq_range->end_freq_khz) |
| 349 | return false; |
| 350 | |
| 351 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 352 | |
Luis R. Rodriguez | d71aaf6 | 2008-10-30 13:33:52 -0700 | [diff] [blame] | 353 | if (freq_diff <= 0 || freq_range->max_bandwidth_khz > freq_diff) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 354 | return false; |
| 355 | |
| 356 | return true; |
| 357 | } |
| 358 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 359 | static bool is_valid_rd(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 360 | { |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 361 | const struct ieee80211_reg_rule *reg_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 362 | unsigned int i; |
| 363 | |
| 364 | if (!rd->n_reg_rules) |
| 365 | return false; |
| 366 | |
Luis R. Rodriguez | 88dc1c3 | 2008-11-12 14:22:01 -0800 | [diff] [blame] | 367 | if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES)) |
| 368 | return false; |
| 369 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 370 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 371 | reg_rule = &rd->reg_rules[i]; |
| 372 | if (!is_valid_reg_rule(reg_rule)) |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | return true; |
| 377 | } |
| 378 | |
| 379 | /* Returns value in KHz */ |
| 380 | static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range, |
| 381 | u32 freq) |
| 382 | { |
| 383 | unsigned int i; |
| 384 | for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) { |
| 385 | u32 start_freq_khz = freq - supported_bandwidths[i]/2; |
| 386 | u32 end_freq_khz = freq + supported_bandwidths[i]/2; |
| 387 | if (start_freq_khz >= freq_range->start_freq_khz && |
| 388 | end_freq_khz <= freq_range->end_freq_khz) |
| 389 | return supported_bandwidths[i]; |
| 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 394 | /** |
| 395 | * freq_in_rule_band - tells us if a frequency is in a frequency band |
| 396 | * @freq_range: frequency rule we want to query |
| 397 | * @freq_khz: frequency we are inquiring about |
| 398 | * |
| 399 | * This lets us know if a specific frequency rule is or is not relevant to |
| 400 | * a specific frequency's band. Bands are device specific and artificial |
| 401 | * definitions (the "2.4 GHz band" and the "5 GHz band"), however it is |
| 402 | * safe for now to assume that a frequency rule should not be part of a |
| 403 | * frequency's band if the start freq or end freq are off by more than 2 GHz. |
| 404 | * This resolution can be lowered and should be considered as we add |
| 405 | * regulatory rule support for other "bands". |
| 406 | **/ |
| 407 | static bool freq_in_rule_band(const struct ieee80211_freq_range *freq_range, |
| 408 | u32 freq_khz) |
| 409 | { |
| 410 | #define ONE_GHZ_IN_KHZ 1000000 |
| 411 | if (abs(freq_khz - freq_range->start_freq_khz) <= (2 * ONE_GHZ_IN_KHZ)) |
| 412 | return true; |
| 413 | if (abs(freq_khz - freq_range->end_freq_khz) <= (2 * ONE_GHZ_IN_KHZ)) |
| 414 | return true; |
| 415 | return false; |
| 416 | #undef ONE_GHZ_IN_KHZ |
| 417 | } |
| 418 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 419 | /* Converts a country IE to a regulatory domain. A regulatory domain |
| 420 | * structure has a lot of information which the IE doesn't yet have, |
| 421 | * so for the other values we use upper max values as we will intersect |
| 422 | * with our userspace regulatory agent to get lower bounds. */ |
| 423 | static struct ieee80211_regdomain *country_ie_2_rd( |
| 424 | u8 *country_ie, |
| 425 | u8 country_ie_len, |
| 426 | u32 *checksum) |
| 427 | { |
| 428 | struct ieee80211_regdomain *rd = NULL; |
| 429 | unsigned int i = 0; |
| 430 | char alpha2[2]; |
| 431 | u32 flags = 0; |
| 432 | u32 num_rules = 0, size_of_regd = 0; |
| 433 | u8 *triplets_start = NULL; |
| 434 | u8 len_at_triplet = 0; |
| 435 | /* the last channel we have registered in a subband (triplet) */ |
| 436 | int last_sub_max_channel = 0; |
| 437 | |
| 438 | *checksum = 0xDEADBEEF; |
| 439 | |
| 440 | /* Country IE requirements */ |
| 441 | BUG_ON(country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN || |
| 442 | country_ie_len & 0x01); |
| 443 | |
| 444 | alpha2[0] = country_ie[0]; |
| 445 | alpha2[1] = country_ie[1]; |
| 446 | |
| 447 | /* |
| 448 | * Third octet can be: |
| 449 | * 'I' - Indoor |
| 450 | * 'O' - Outdoor |
| 451 | * |
| 452 | * anything else we assume is no restrictions |
| 453 | */ |
| 454 | if (country_ie[2] == 'I') |
| 455 | flags = NL80211_RRF_NO_OUTDOOR; |
| 456 | else if (country_ie[2] == 'O') |
| 457 | flags = NL80211_RRF_NO_INDOOR; |
| 458 | |
| 459 | country_ie += 3; |
| 460 | country_ie_len -= 3; |
| 461 | |
| 462 | triplets_start = country_ie; |
| 463 | len_at_triplet = country_ie_len; |
| 464 | |
| 465 | *checksum ^= ((flags ^ alpha2[0] ^ alpha2[1]) << 8); |
| 466 | |
| 467 | /* We need to build a reg rule for each triplet, but first we must |
| 468 | * calculate the number of reg rules we will need. We will need one |
| 469 | * for each channel subband */ |
| 470 | while (country_ie_len >= 3) { |
Luis R. Rodriguez | 615aab4 | 2009-01-22 15:05:46 -0800 | [diff] [blame] | 471 | int end_channel = 0; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 472 | struct ieee80211_country_ie_triplet *triplet = |
| 473 | (struct ieee80211_country_ie_triplet *) country_ie; |
| 474 | int cur_sub_max_channel = 0, cur_channel = 0; |
| 475 | |
| 476 | if (triplet->ext.reg_extension_id >= |
| 477 | IEEE80211_COUNTRY_EXTENSION_ID) { |
| 478 | country_ie += 3; |
| 479 | country_ie_len -= 3; |
| 480 | continue; |
| 481 | } |
| 482 | |
Luis R. Rodriguez | 615aab4 | 2009-01-22 15:05:46 -0800 | [diff] [blame] | 483 | /* 2 GHz */ |
| 484 | if (triplet->chans.first_channel <= 14) |
| 485 | end_channel = triplet->chans.first_channel + |
| 486 | triplet->chans.num_channels; |
| 487 | else |
| 488 | /* |
| 489 | * 5 GHz -- For example in country IEs if the first |
| 490 | * channel given is 36 and the number of channels is 4 |
| 491 | * then the individual channel numbers defined for the |
| 492 | * 5 GHz PHY by these parameters are: 36, 40, 44, and 48 |
| 493 | * and not 36, 37, 38, 39. |
| 494 | * |
| 495 | * See: http://tinyurl.com/11d-clarification |
| 496 | */ |
| 497 | end_channel = triplet->chans.first_channel + |
| 498 | (4 * (triplet->chans.num_channels - 1)); |
| 499 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 500 | cur_channel = triplet->chans.first_channel; |
Luis R. Rodriguez | 615aab4 | 2009-01-22 15:05:46 -0800 | [diff] [blame] | 501 | cur_sub_max_channel = end_channel; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 502 | |
| 503 | /* Basic sanity check */ |
| 504 | if (cur_sub_max_channel < cur_channel) |
| 505 | return NULL; |
| 506 | |
| 507 | /* Do not allow overlapping channels. Also channels |
| 508 | * passed in each subband must be monotonically |
| 509 | * increasing */ |
| 510 | if (last_sub_max_channel) { |
| 511 | if (cur_channel <= last_sub_max_channel) |
| 512 | return NULL; |
| 513 | if (cur_sub_max_channel <= last_sub_max_channel) |
| 514 | return NULL; |
| 515 | } |
| 516 | |
| 517 | /* When dot11RegulatoryClassesRequired is supported |
| 518 | * we can throw ext triplets as part of this soup, |
| 519 | * for now we don't care when those change as we |
| 520 | * don't support them */ |
| 521 | *checksum ^= ((cur_channel ^ cur_sub_max_channel) << 8) | |
| 522 | ((cur_sub_max_channel ^ cur_sub_max_channel) << 16) | |
| 523 | ((triplet->chans.max_power ^ cur_sub_max_channel) << 24); |
| 524 | |
| 525 | last_sub_max_channel = cur_sub_max_channel; |
| 526 | |
| 527 | country_ie += 3; |
| 528 | country_ie_len -= 3; |
| 529 | num_rules++; |
| 530 | |
| 531 | /* Note: this is not a IEEE requirement but |
| 532 | * simply a memory requirement */ |
| 533 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
| 534 | return NULL; |
| 535 | } |
| 536 | |
| 537 | country_ie = triplets_start; |
| 538 | country_ie_len = len_at_triplet; |
| 539 | |
| 540 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 541 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 542 | |
| 543 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 544 | if (!rd) |
| 545 | return NULL; |
| 546 | |
| 547 | rd->n_reg_rules = num_rules; |
| 548 | rd->alpha2[0] = alpha2[0]; |
| 549 | rd->alpha2[1] = alpha2[1]; |
| 550 | |
| 551 | /* This time around we fill in the rd */ |
| 552 | while (country_ie_len >= 3) { |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 553 | int end_channel = 0; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 554 | struct ieee80211_country_ie_triplet *triplet = |
| 555 | (struct ieee80211_country_ie_triplet *) country_ie; |
| 556 | struct ieee80211_reg_rule *reg_rule = NULL; |
| 557 | struct ieee80211_freq_range *freq_range = NULL; |
| 558 | struct ieee80211_power_rule *power_rule = NULL; |
| 559 | |
| 560 | /* Must parse if dot11RegulatoryClassesRequired is true, |
| 561 | * we don't support this yet */ |
| 562 | if (triplet->ext.reg_extension_id >= |
| 563 | IEEE80211_COUNTRY_EXTENSION_ID) { |
| 564 | country_ie += 3; |
| 565 | country_ie_len -= 3; |
| 566 | continue; |
| 567 | } |
| 568 | |
| 569 | reg_rule = &rd->reg_rules[i]; |
| 570 | freq_range = ®_rule->freq_range; |
| 571 | power_rule = ®_rule->power_rule; |
| 572 | |
| 573 | reg_rule->flags = flags; |
| 574 | |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 575 | /* 2 GHz */ |
| 576 | if (triplet->chans.first_channel <= 14) |
| 577 | end_channel = triplet->chans.first_channel + |
| 578 | triplet->chans.num_channels; |
| 579 | else |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 580 | end_channel = triplet->chans.first_channel + |
| 581 | (4 * (triplet->chans.num_channels - 1)); |
| 582 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 583 | /* The +10 is since the regulatory domain expects |
| 584 | * the actual band edge, not the center of freq for |
| 585 | * its start and end freqs, assuming 20 MHz bandwidth on |
| 586 | * the channels passed */ |
| 587 | freq_range->start_freq_khz = |
| 588 | MHZ_TO_KHZ(ieee80211_channel_to_frequency( |
| 589 | triplet->chans.first_channel) - 10); |
| 590 | freq_range->end_freq_khz = |
| 591 | MHZ_TO_KHZ(ieee80211_channel_to_frequency( |
Luis R. Rodriguez | 02e68a3 | 2009-01-07 17:43:37 -0800 | [diff] [blame] | 592 | end_channel) + 10); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 593 | |
| 594 | /* Large arbitrary values, we intersect later */ |
| 595 | /* Increment this if we ever support >= 40 MHz channels |
| 596 | * in IEEE 802.11 */ |
| 597 | freq_range->max_bandwidth_khz = MHZ_TO_KHZ(40); |
| 598 | power_rule->max_antenna_gain = DBI_TO_MBI(100); |
| 599 | power_rule->max_eirp = DBM_TO_MBM(100); |
| 600 | |
| 601 | country_ie += 3; |
| 602 | country_ie_len -= 3; |
| 603 | i++; |
| 604 | |
| 605 | BUG_ON(i > NL80211_MAX_SUPP_REG_RULES); |
| 606 | } |
| 607 | |
| 608 | return rd; |
| 609 | } |
| 610 | |
| 611 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 612 | /* Helper for regdom_intersect(), this does the real |
| 613 | * mathematical intersection fun */ |
| 614 | static int reg_rules_intersect( |
| 615 | const struct ieee80211_reg_rule *rule1, |
| 616 | const struct ieee80211_reg_rule *rule2, |
| 617 | struct ieee80211_reg_rule *intersected_rule) |
| 618 | { |
| 619 | const struct ieee80211_freq_range *freq_range1, *freq_range2; |
| 620 | struct ieee80211_freq_range *freq_range; |
| 621 | const struct ieee80211_power_rule *power_rule1, *power_rule2; |
| 622 | struct ieee80211_power_rule *power_rule; |
| 623 | u32 freq_diff; |
| 624 | |
| 625 | freq_range1 = &rule1->freq_range; |
| 626 | freq_range2 = &rule2->freq_range; |
| 627 | freq_range = &intersected_rule->freq_range; |
| 628 | |
| 629 | power_rule1 = &rule1->power_rule; |
| 630 | power_rule2 = &rule2->power_rule; |
| 631 | power_rule = &intersected_rule->power_rule; |
| 632 | |
| 633 | freq_range->start_freq_khz = max(freq_range1->start_freq_khz, |
| 634 | freq_range2->start_freq_khz); |
| 635 | freq_range->end_freq_khz = min(freq_range1->end_freq_khz, |
| 636 | freq_range2->end_freq_khz); |
| 637 | freq_range->max_bandwidth_khz = min(freq_range1->max_bandwidth_khz, |
| 638 | freq_range2->max_bandwidth_khz); |
| 639 | |
| 640 | freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; |
| 641 | if (freq_range->max_bandwidth_khz > freq_diff) |
| 642 | freq_range->max_bandwidth_khz = freq_diff; |
| 643 | |
| 644 | power_rule->max_eirp = min(power_rule1->max_eirp, |
| 645 | power_rule2->max_eirp); |
| 646 | power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, |
| 647 | power_rule2->max_antenna_gain); |
| 648 | |
| 649 | intersected_rule->flags = (rule1->flags | rule2->flags); |
| 650 | |
| 651 | if (!is_valid_reg_rule(intersected_rule)) |
| 652 | return -EINVAL; |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * regdom_intersect - do the intersection between two regulatory domains |
| 659 | * @rd1: first regulatory domain |
| 660 | * @rd2: second regulatory domain |
| 661 | * |
| 662 | * Use this function to get the intersection between two regulatory domains. |
| 663 | * Once completed we will mark the alpha2 for the rd as intersected, "98", |
| 664 | * as no one single alpha2 can represent this regulatory domain. |
| 665 | * |
| 666 | * Returns a pointer to the regulatory domain structure which will hold the |
| 667 | * resulting intersection of rules between rd1 and rd2. We will |
| 668 | * kzalloc() this structure for you. |
| 669 | */ |
| 670 | static struct ieee80211_regdomain *regdom_intersect( |
| 671 | const struct ieee80211_regdomain *rd1, |
| 672 | const struct ieee80211_regdomain *rd2) |
| 673 | { |
| 674 | int r, size_of_regd; |
| 675 | unsigned int x, y; |
| 676 | unsigned int num_rules = 0, rule_idx = 0; |
| 677 | const struct ieee80211_reg_rule *rule1, *rule2; |
| 678 | struct ieee80211_reg_rule *intersected_rule; |
| 679 | struct ieee80211_regdomain *rd; |
| 680 | /* This is just a dummy holder to help us count */ |
| 681 | struct ieee80211_reg_rule irule; |
| 682 | |
| 683 | /* Uses the stack temporarily for counter arithmetic */ |
| 684 | intersected_rule = &irule; |
| 685 | |
| 686 | memset(intersected_rule, 0, sizeof(struct ieee80211_reg_rule)); |
| 687 | |
| 688 | if (!rd1 || !rd2) |
| 689 | return NULL; |
| 690 | |
| 691 | /* First we get a count of the rules we'll need, then we actually |
| 692 | * build them. This is to so we can malloc() and free() a |
| 693 | * regdomain once. The reason we use reg_rules_intersect() here |
| 694 | * is it will return -EINVAL if the rule computed makes no sense. |
| 695 | * All rules that do check out OK are valid. */ |
| 696 | |
| 697 | for (x = 0; x < rd1->n_reg_rules; x++) { |
| 698 | rule1 = &rd1->reg_rules[x]; |
| 699 | for (y = 0; y < rd2->n_reg_rules; y++) { |
| 700 | rule2 = &rd2->reg_rules[y]; |
| 701 | if (!reg_rules_intersect(rule1, rule2, |
| 702 | intersected_rule)) |
| 703 | num_rules++; |
| 704 | memset(intersected_rule, 0, |
| 705 | sizeof(struct ieee80211_reg_rule)); |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | if (!num_rules) |
| 710 | return NULL; |
| 711 | |
| 712 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 713 | ((num_rules + 1) * sizeof(struct ieee80211_reg_rule)); |
| 714 | |
| 715 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 716 | if (!rd) |
| 717 | return NULL; |
| 718 | |
| 719 | for (x = 0; x < rd1->n_reg_rules; x++) { |
| 720 | rule1 = &rd1->reg_rules[x]; |
| 721 | for (y = 0; y < rd2->n_reg_rules; y++) { |
| 722 | rule2 = &rd2->reg_rules[y]; |
| 723 | /* This time around instead of using the stack lets |
| 724 | * write to the target rule directly saving ourselves |
| 725 | * a memcpy() */ |
| 726 | intersected_rule = &rd->reg_rules[rule_idx]; |
| 727 | r = reg_rules_intersect(rule1, rule2, |
| 728 | intersected_rule); |
| 729 | /* No need to memset here the intersected rule here as |
| 730 | * we're not using the stack anymore */ |
| 731 | if (r) |
| 732 | continue; |
| 733 | rule_idx++; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | if (rule_idx != num_rules) { |
| 738 | kfree(rd); |
| 739 | return NULL; |
| 740 | } |
| 741 | |
| 742 | rd->n_reg_rules = num_rules; |
| 743 | rd->alpha2[0] = '9'; |
| 744 | rd->alpha2[1] = '8'; |
| 745 | |
| 746 | return rd; |
| 747 | } |
| 748 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 749 | /* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may |
| 750 | * want to just have the channel structure use these */ |
| 751 | static u32 map_regdom_flags(u32 rd_flags) |
| 752 | { |
| 753 | u32 channel_flags = 0; |
| 754 | if (rd_flags & NL80211_RRF_PASSIVE_SCAN) |
| 755 | channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
| 756 | if (rd_flags & NL80211_RRF_NO_IBSS) |
| 757 | channel_flags |= IEEE80211_CHAN_NO_IBSS; |
| 758 | if (rd_flags & NL80211_RRF_DFS) |
| 759 | channel_flags |= IEEE80211_CHAN_RADAR; |
| 760 | return channel_flags; |
| 761 | } |
| 762 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 763 | static int freq_reg_info_regd(struct wiphy *wiphy, |
| 764 | u32 center_freq, |
| 765 | u32 *bandwidth, |
| 766 | const struct ieee80211_reg_rule **reg_rule, |
| 767 | const struct ieee80211_regdomain *custom_regd) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 768 | { |
| 769 | int i; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 770 | bool band_rule_found = false; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 771 | const struct ieee80211_regdomain *regd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 772 | u32 max_bandwidth = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 773 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 774 | regd = custom_regd ? custom_regd : cfg80211_regdomain; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 775 | |
| 776 | /* Follow the driver's regulatory domain, if present, unless a country |
Luis R. Rodriguez | 24ed1da | 2009-01-22 15:05:54 -0800 | [diff] [blame] | 777 | * IE has been processed or a user wants to help complaince further */ |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 778 | if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE && |
Luis R. Rodriguez | 24ed1da | 2009-01-22 15:05:54 -0800 | [diff] [blame] | 779 | last_request->initiator != REGDOM_SET_BY_USER && |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 780 | wiphy->regd) |
| 781 | regd = wiphy->regd; |
| 782 | |
| 783 | if (!regd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 784 | return -EINVAL; |
| 785 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 786 | for (i = 0; i < regd->n_reg_rules; i++) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 787 | const struct ieee80211_reg_rule *rr; |
| 788 | const struct ieee80211_freq_range *fr = NULL; |
| 789 | const struct ieee80211_power_rule *pr = NULL; |
| 790 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 791 | rr = ®d->reg_rules[i]; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 792 | fr = &rr->freq_range; |
| 793 | pr = &rr->power_rule; |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 794 | |
| 795 | /* We only need to know if one frequency rule was |
| 796 | * was in center_freq's band, that's enough, so lets |
| 797 | * not overwrite it once found */ |
| 798 | if (!band_rule_found) |
| 799 | band_rule_found = freq_in_rule_band(fr, center_freq); |
| 800 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 801 | max_bandwidth = freq_max_bandwidth(fr, center_freq); |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 802 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 803 | if (max_bandwidth && *bandwidth <= max_bandwidth) { |
| 804 | *reg_rule = rr; |
| 805 | *bandwidth = max_bandwidth; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 806 | break; |
| 807 | } |
| 808 | } |
| 809 | |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 810 | if (!band_rule_found) |
| 811 | return -ERANGE; |
| 812 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 813 | return !max_bandwidth; |
| 814 | } |
Luis R. Rodriguez | 34f5734 | 2009-01-22 15:05:45 -0800 | [diff] [blame] | 815 | EXPORT_SYMBOL(freq_reg_info); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 816 | |
Luis R. Rodriguez | 34f5734 | 2009-01-22 15:05:45 -0800 | [diff] [blame] | 817 | int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth, |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 818 | const struct ieee80211_reg_rule **reg_rule) |
| 819 | { |
| 820 | return freq_reg_info_regd(wiphy, center_freq, |
| 821 | bandwidth, reg_rule, NULL); |
| 822 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 823 | |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 824 | static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band, |
| 825 | unsigned int chan_idx) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 826 | { |
| 827 | int r; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 828 | u32 flags; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 829 | u32 max_bandwidth = 0; |
| 830 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 831 | const struct ieee80211_power_rule *power_rule = NULL; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 832 | struct ieee80211_supported_band *sband; |
| 833 | struct ieee80211_channel *chan; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 834 | struct wiphy *request_wiphy; |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 835 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 836 | assert_cfg80211_lock(); |
| 837 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 838 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 839 | |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 840 | sband = wiphy->bands[band]; |
| 841 | BUG_ON(chan_idx >= sband->n_channels); |
| 842 | chan = &sband->channels[chan_idx]; |
| 843 | |
| 844 | flags = chan->orig_flags; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 845 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 846 | r = freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq), |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 847 | &max_bandwidth, ®_rule); |
| 848 | |
| 849 | if (r) { |
Luis R. Rodriguez | 0c7dc45 | 2009-01-07 17:43:36 -0800 | [diff] [blame] | 850 | /* This means no regulatory rule was found in the country IE |
| 851 | * with a frequency range on the center_freq's band, since |
| 852 | * IEEE-802.11 allows for a country IE to have a subset of the |
| 853 | * regulatory information provided in a country we ignore |
| 854 | * disabling the channel unless at least one reg rule was |
| 855 | * found on the center_freq's band. For details see this |
| 856 | * clarification: |
| 857 | * |
| 858 | * http://tinyurl.com/11d-clarification |
| 859 | */ |
| 860 | if (r == -ERANGE && |
| 861 | last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) { |
| 862 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 863 | printk(KERN_DEBUG "cfg80211: Leaving channel %d MHz " |
| 864 | "intact on %s - no rule found in band on " |
| 865 | "Country IE\n", |
| 866 | chan->center_freq, wiphy_name(wiphy)); |
| 867 | #endif |
| 868 | } else { |
| 869 | /* In this case we know the country IE has at least one reg rule |
| 870 | * for the band so we respect its band definitions */ |
| 871 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 872 | if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) |
| 873 | printk(KERN_DEBUG "cfg80211: Disabling " |
| 874 | "channel %d MHz on %s due to " |
| 875 | "Country IE\n", |
| 876 | chan->center_freq, wiphy_name(wiphy)); |
| 877 | #endif |
| 878 | flags |= IEEE80211_CHAN_DISABLED; |
| 879 | chan->flags = flags; |
| 880 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 881 | return; |
| 882 | } |
| 883 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 884 | power_rule = ®_rule->power_rule; |
| 885 | |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 886 | if (last_request->initiator == REGDOM_SET_BY_DRIVER && |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 887 | request_wiphy && request_wiphy == wiphy && |
| 888 | request_wiphy->strict_regulatory) { |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 889 | /* This gaurantees the driver's requested regulatory domain |
| 890 | * will always be used as a base for further regulatory |
| 891 | * settings */ |
| 892 | chan->flags = chan->orig_flags = |
| 893 | map_regdom_flags(reg_rule->flags); |
| 894 | chan->max_antenna_gain = chan->orig_mag = |
| 895 | (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
| 896 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); |
| 897 | chan->max_power = chan->orig_mpwr = |
| 898 | (int) MBM_TO_DBM(power_rule->max_eirp); |
| 899 | return; |
| 900 | } |
| 901 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 902 | chan->flags = flags | map_regdom_flags(reg_rule->flags); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 903 | chan->max_antenna_gain = min(chan->orig_mag, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 904 | (int) MBI_TO_DBI(power_rule->max_antenna_gain)); |
| 905 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); |
John W. Linville | 253898c | 2008-04-03 15:32:54 -0400 | [diff] [blame] | 906 | if (chan->orig_mpwr) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 907 | chan->max_power = min(chan->orig_mpwr, |
| 908 | (int) MBM_TO_DBM(power_rule->max_eirp)); |
John W. Linville | 253898c | 2008-04-03 15:32:54 -0400 | [diff] [blame] | 909 | else |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 910 | chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 911 | } |
| 912 | |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 913 | static void handle_band(struct wiphy *wiphy, enum ieee80211_band band) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 914 | { |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 915 | unsigned int i; |
| 916 | struct ieee80211_supported_band *sband; |
| 917 | |
| 918 | BUG_ON(!wiphy->bands[band]); |
| 919 | sband = wiphy->bands[band]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 920 | |
| 921 | for (i = 0; i < sband->n_channels; i++) |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 922 | handle_channel(wiphy, band, i); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 923 | } |
| 924 | |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 925 | static bool ignore_reg_update(struct wiphy *wiphy, enum reg_set_by setby) |
| 926 | { |
| 927 | if (!last_request) |
| 928 | return true; |
| 929 | if (setby == REGDOM_SET_BY_CORE && |
Luis R. Rodriguez | 2a44f91 | 2009-01-22 15:05:49 -0800 | [diff] [blame] | 930 | wiphy->custom_regulatory) |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 931 | return true; |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 932 | /* wiphy->regd will be set once the device has its own |
| 933 | * desired regulatory domain set */ |
| 934 | if (wiphy->strict_regulatory && !wiphy->regd && |
| 935 | !is_world_regdom(last_request->alpha2)) |
Luis R. Rodriguez | 14b9815 | 2008-11-12 14:22:03 -0800 | [diff] [blame] | 936 | return true; |
| 937 | return false; |
| 938 | } |
| 939 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 940 | static void update_all_wiphy_regulatory(enum reg_set_by setby) |
| 941 | { |
| 942 | struct cfg80211_registered_device *drv; |
| 943 | |
| 944 | list_for_each_entry(drv, &cfg80211_drv_list, list) |
Luis R. Rodriguez | d46e5b1 | 2009-01-22 15:05:50 -0800 | [diff] [blame] | 945 | wiphy_update_regulatory(&drv->wiphy, setby); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 949 | { |
| 950 | enum ieee80211_band band; |
Luis R. Rodriguez | d46e5b1 | 2009-01-22 15:05:50 -0800 | [diff] [blame] | 951 | |
| 952 | if (ignore_reg_update(wiphy, setby)) |
| 953 | return; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 954 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 955 | if (wiphy->bands[band]) |
Luis R. Rodriguez | a92a3ce | 2009-01-07 17:43:33 -0800 | [diff] [blame] | 956 | handle_band(wiphy, band); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 957 | } |
Luis R. Rodriguez | 560e28e | 2009-01-07 17:43:32 -0800 | [diff] [blame] | 958 | if (wiphy->reg_notifier) |
Luis R. Rodriguez | 716f939 | 2009-01-22 15:05:51 -0800 | [diff] [blame] | 959 | wiphy->reg_notifier(wiphy, last_request); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Luis R. Rodriguez | 1fa25e4 | 2009-01-22 15:05:44 -0800 | [diff] [blame] | 962 | static void handle_channel_custom(struct wiphy *wiphy, |
| 963 | enum ieee80211_band band, |
| 964 | unsigned int chan_idx, |
| 965 | const struct ieee80211_regdomain *regd) |
| 966 | { |
| 967 | int r; |
| 968 | u32 max_bandwidth = 0; |
| 969 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 970 | const struct ieee80211_power_rule *power_rule = NULL; |
| 971 | struct ieee80211_supported_band *sband; |
| 972 | struct ieee80211_channel *chan; |
| 973 | |
| 974 | sband = wiphy->bands[band]; |
| 975 | BUG_ON(chan_idx >= sband->n_channels); |
| 976 | chan = &sband->channels[chan_idx]; |
| 977 | |
| 978 | r = freq_reg_info_regd(wiphy, MHZ_TO_KHZ(chan->center_freq), |
| 979 | &max_bandwidth, ®_rule, regd); |
| 980 | |
| 981 | if (r) { |
| 982 | chan->flags = IEEE80211_CHAN_DISABLED; |
| 983 | return; |
| 984 | } |
| 985 | |
| 986 | power_rule = ®_rule->power_rule; |
| 987 | |
| 988 | chan->flags |= map_regdom_flags(reg_rule->flags); |
| 989 | chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); |
| 990 | chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth); |
| 991 | chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp); |
| 992 | } |
| 993 | |
| 994 | static void handle_band_custom(struct wiphy *wiphy, enum ieee80211_band band, |
| 995 | const struct ieee80211_regdomain *regd) |
| 996 | { |
| 997 | unsigned int i; |
| 998 | struct ieee80211_supported_band *sband; |
| 999 | |
| 1000 | BUG_ON(!wiphy->bands[band]); |
| 1001 | sband = wiphy->bands[band]; |
| 1002 | |
| 1003 | for (i = 0; i < sband->n_channels; i++) |
| 1004 | handle_channel_custom(wiphy, band, i, regd); |
| 1005 | } |
| 1006 | |
| 1007 | /* Used by drivers prior to wiphy registration */ |
| 1008 | void wiphy_apply_custom_regulatory(struct wiphy *wiphy, |
| 1009 | const struct ieee80211_regdomain *regd) |
| 1010 | { |
| 1011 | enum ieee80211_band band; |
| 1012 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 1013 | if (wiphy->bands[band]) |
| 1014 | handle_band_custom(wiphy, band, regd); |
| 1015 | } |
| 1016 | } |
| 1017 | EXPORT_SYMBOL(wiphy_apply_custom_regulatory); |
| 1018 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1019 | static int reg_copy_regd(const struct ieee80211_regdomain **dst_regd, |
| 1020 | const struct ieee80211_regdomain *src_regd) |
| 1021 | { |
| 1022 | struct ieee80211_regdomain *regd; |
| 1023 | int size_of_regd = 0; |
| 1024 | unsigned int i; |
| 1025 | |
| 1026 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 1027 | ((src_regd->n_reg_rules + 1) * sizeof(struct ieee80211_reg_rule)); |
| 1028 | |
| 1029 | regd = kzalloc(size_of_regd, GFP_KERNEL); |
| 1030 | if (!regd) |
| 1031 | return -ENOMEM; |
| 1032 | |
| 1033 | memcpy(regd, src_regd, sizeof(struct ieee80211_regdomain)); |
| 1034 | |
| 1035 | for (i = 0; i < src_regd->n_reg_rules; i++) |
| 1036 | memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], |
| 1037 | sizeof(struct ieee80211_reg_rule)); |
| 1038 | |
| 1039 | *dst_regd = regd; |
| 1040 | return 0; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1043 | /* Return value which can be used by ignore_request() to indicate |
| 1044 | * it has been determined we should intersect two regulatory domains */ |
| 1045 | #define REG_INTERSECT 1 |
| 1046 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1047 | /* This has the logic which determines when a new request |
| 1048 | * should be ignored. */ |
| 1049 | static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by, |
| 1050 | const char *alpha2) |
| 1051 | { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1052 | struct wiphy *last_wiphy = NULL; |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1053 | |
| 1054 | assert_cfg80211_lock(); |
| 1055 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1056 | /* All initial requests are respected */ |
| 1057 | if (!last_request) |
| 1058 | return 0; |
| 1059 | |
| 1060 | switch (set_by) { |
| 1061 | case REGDOM_SET_BY_INIT: |
| 1062 | return -EINVAL; |
| 1063 | case REGDOM_SET_BY_CORE: |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1064 | return -EINVAL; |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1065 | case REGDOM_SET_BY_COUNTRY_IE: |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1066 | |
| 1067 | last_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 1068 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1069 | if (unlikely(!is_an_alpha2(alpha2))) |
| 1070 | return -EINVAL; |
| 1071 | if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1072 | if (last_wiphy != wiphy) { |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1073 | /* |
| 1074 | * Two cards with two APs claiming different |
| 1075 | * different Country IE alpha2s. We could |
| 1076 | * intersect them, but that seems unlikely |
| 1077 | * to be correct. Reject second one for now. |
| 1078 | */ |
| 1079 | if (!alpha2_equal(alpha2, |
| 1080 | cfg80211_regdomain->alpha2)) |
| 1081 | return -EOPNOTSUPP; |
| 1082 | return -EALREADY; |
| 1083 | } |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1084 | /* Two consecutive Country IE hints on the same wiphy. |
| 1085 | * This should be picked up early by the driver/stack */ |
| 1086 | if (WARN_ON(!alpha2_equal(cfg80211_regdomain->alpha2, |
| 1087 | alpha2))) |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1088 | return 0; |
| 1089 | return -EALREADY; |
| 1090 | } |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1091 | return REG_INTERSECT; |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1092 | case REGDOM_SET_BY_DRIVER: |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1093 | if (last_request->initiator == REGDOM_SET_BY_CORE) { |
| 1094 | if (is_old_static_regdom(cfg80211_regdomain)) |
| 1095 | return 0; |
| 1096 | if (!alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) |
| 1097 | return 0; |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1098 | return -EALREADY; |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1099 | } |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1100 | return REG_INTERSECT; |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1101 | case REGDOM_SET_BY_USER: |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1102 | if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1103 | return REG_INTERSECT; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1104 | /* If the user knows better the user should set the regdom |
| 1105 | * to their country before the IE is picked up */ |
| 1106 | if (last_request->initiator == REGDOM_SET_BY_USER && |
| 1107 | last_request->intersect) |
| 1108 | return -EOPNOTSUPP; |
Luis R. Rodriguez | 5eebade | 2009-01-22 15:05:47 -0800 | [diff] [blame] | 1109 | /* Process user requests only after previous user/driver/core |
| 1110 | * requests have been processed */ |
| 1111 | if (last_request->initiator == REGDOM_SET_BY_CORE || |
| 1112 | last_request->initiator == REGDOM_SET_BY_DRIVER || |
| 1113 | last_request->initiator == REGDOM_SET_BY_USER) { |
| 1114 | if (!alpha2_equal(last_request->alpha2, |
| 1115 | cfg80211_regdomain->alpha2)) |
| 1116 | return -EAGAIN; |
| 1117 | } |
| 1118 | |
Luis R. Rodriguez | e74b1e7 | 2009-01-22 15:05:48 -0800 | [diff] [blame] | 1119 | if (!is_old_static_regdom(cfg80211_regdomain) && |
| 1120 | alpha2_equal(cfg80211_regdomain->alpha2, alpha2)) |
| 1121 | return -EALREADY; |
| 1122 | |
Johannes Berg | 84fa4f4 | 2008-10-24 20:32:23 +0200 | [diff] [blame] | 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | return -EINVAL; |
| 1127 | } |
| 1128 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1129 | /* Caller must hold &cfg80211_mutex */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1130 | int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by, |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1131 | const char *alpha2, |
| 1132 | u32 country_ie_checksum, |
| 1133 | enum environment_cap env) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1134 | { |
| 1135 | struct regulatory_request *request; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1136 | bool intersect = false; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1137 | int r = 0; |
| 1138 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1139 | assert_cfg80211_lock(); |
| 1140 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 1141 | r = ignore_request(wiphy, set_by, alpha2); |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1142 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1143 | if (r == REG_INTERSECT) { |
| 1144 | if (set_by == REGDOM_SET_BY_DRIVER) { |
| 1145 | r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); |
| 1146 | if (r) |
| 1147 | return r; |
| 1148 | } |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1149 | intersect = true; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1150 | } else if (r) { |
| 1151 | /* If the regulatory domain being requested by the |
| 1152 | * driver has already been set just copy it to the |
| 1153 | * wiphy */ |
| 1154 | if (r == -EALREADY && set_by == REGDOM_SET_BY_DRIVER) { |
| 1155 | r = reg_copy_regd(&wiphy->regd, cfg80211_regdomain); |
| 1156 | if (r) |
| 1157 | return r; |
| 1158 | r = -EALREADY; |
| 1159 | goto new_request; |
| 1160 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1161 | return r; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1162 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1163 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1164 | new_request: |
Luis R. Rodriguez | 5203cdb | 2008-11-12 14:21:56 -0800 | [diff] [blame] | 1165 | request = kzalloc(sizeof(struct regulatory_request), |
| 1166 | GFP_KERNEL); |
| 1167 | if (!request) |
| 1168 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1169 | |
Luis R. Rodriguez | 5203cdb | 2008-11-12 14:21:56 -0800 | [diff] [blame] | 1170 | request->alpha2[0] = alpha2[0]; |
| 1171 | request->alpha2[1] = alpha2[1]; |
| 1172 | request->initiator = set_by; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1173 | request->wiphy_idx = get_wiphy_idx(wiphy); |
Luis R. Rodriguez | 5203cdb | 2008-11-12 14:21:56 -0800 | [diff] [blame] | 1174 | request->intersect = intersect; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1175 | request->country_ie_checksum = country_ie_checksum; |
| 1176 | request->country_ie_env = env; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1177 | |
Luis R. Rodriguez | 5203cdb | 2008-11-12 14:21:56 -0800 | [diff] [blame] | 1178 | kfree(last_request); |
| 1179 | last_request = request; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1180 | |
| 1181 | /* When r == REG_INTERSECT we do need to call CRDA */ |
| 1182 | if (r < 0) |
| 1183 | return r; |
| 1184 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1185 | /* |
| 1186 | * Note: When CONFIG_WIRELESS_OLD_REGULATORY is enabled |
| 1187 | * AND if CRDA is NOT present nothing will happen, if someone |
| 1188 | * wants to bother with 11d with OLD_REG you can add a timer. |
| 1189 | * If after x amount of time nothing happens you can call: |
| 1190 | * |
| 1191 | * return set_regdom(country_ie_regdomain); |
| 1192 | * |
| 1193 | * to intersect with the static rd |
| 1194 | */ |
Luis R. Rodriguez | 02ba0b3 | 2008-11-12 14:22:00 -0800 | [diff] [blame] | 1195 | return call_crda(alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1196 | } |
| 1197 | |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1198 | static int regulatory_hint_core(const char *alpha2) |
| 1199 | { |
| 1200 | struct regulatory_request *request; |
| 1201 | |
| 1202 | BUG_ON(last_request); |
| 1203 | |
| 1204 | request = kzalloc(sizeof(struct regulatory_request), |
| 1205 | GFP_KERNEL); |
| 1206 | if (!request) |
| 1207 | return -ENOMEM; |
| 1208 | |
| 1209 | request->alpha2[0] = alpha2[0]; |
| 1210 | request->alpha2[1] = alpha2[1]; |
| 1211 | request->initiator = REGDOM_SET_BY_CORE; |
| 1212 | |
| 1213 | last_request = request; |
| 1214 | |
| 1215 | return call_crda(alpha2); |
| 1216 | } |
| 1217 | |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 1218 | void regulatory_hint(struct wiphy *wiphy, const char *alpha2) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1219 | { |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1220 | int r; |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 1221 | BUG_ON(!alpha2); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1222 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1223 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f976376 | 2009-01-22 15:05:52 -0800 | [diff] [blame] | 1224 | r = __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER, |
| 1225 | alpha2, 0, ENVIRON_ANY); |
| 1226 | /* This is required so that the orig_* parameters are saved */ |
| 1227 | if (r == -EALREADY && wiphy->strict_regulatory) |
| 1228 | wiphy_update_regulatory(wiphy, REGDOM_SET_BY_DRIVER); |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1229 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1230 | } |
| 1231 | EXPORT_SYMBOL(regulatory_hint); |
| 1232 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1233 | static bool reg_same_country_ie_hint(struct wiphy *wiphy, |
| 1234 | u32 country_ie_checksum) |
| 1235 | { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1236 | struct wiphy *request_wiphy; |
| 1237 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1238 | assert_cfg80211_lock(); |
| 1239 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1240 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 1241 | |
| 1242 | if (!request_wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1243 | return false; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1244 | |
| 1245 | if (likely(request_wiphy != wiphy)) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1246 | return !country_ie_integrity_changes(country_ie_checksum); |
| 1247 | /* We should not have let these through at this point, they |
| 1248 | * should have been picked up earlier by the first alpha2 check |
| 1249 | * on the device */ |
| 1250 | if (WARN_ON(!country_ie_integrity_changes(country_ie_checksum))) |
| 1251 | return true; |
| 1252 | return false; |
| 1253 | } |
| 1254 | |
| 1255 | void regulatory_hint_11d(struct wiphy *wiphy, |
| 1256 | u8 *country_ie, |
| 1257 | u8 country_ie_len) |
| 1258 | { |
| 1259 | struct ieee80211_regdomain *rd = NULL; |
| 1260 | char alpha2[2]; |
| 1261 | u32 checksum = 0; |
| 1262 | enum environment_cap env = ENVIRON_ANY; |
| 1263 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1264 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1265 | |
Luis R. Rodriguez | d335fe6 | 2009-02-21 00:04:27 -0500 | [diff] [blame] | 1266 | if (unlikely(!last_request)) { |
| 1267 | mutex_unlock(&cfg80211_mutex); |
| 1268 | return; |
| 1269 | } |
| 1270 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1271 | /* IE len must be evenly divisible by 2 */ |
| 1272 | if (country_ie_len & 0x01) |
| 1273 | goto out; |
| 1274 | |
| 1275 | if (country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) |
| 1276 | goto out; |
| 1277 | |
| 1278 | /* Pending country IE processing, this can happen after we |
| 1279 | * call CRDA and wait for a response if a beacon was received before |
| 1280 | * we were able to process the last regulatory_hint_11d() call */ |
| 1281 | if (country_ie_regdomain) |
| 1282 | goto out; |
| 1283 | |
| 1284 | alpha2[0] = country_ie[0]; |
| 1285 | alpha2[1] = country_ie[1]; |
| 1286 | |
| 1287 | if (country_ie[2] == 'I') |
| 1288 | env = ENVIRON_INDOOR; |
| 1289 | else if (country_ie[2] == 'O') |
| 1290 | env = ENVIRON_OUTDOOR; |
| 1291 | |
| 1292 | /* We will run this for *every* beacon processed for the BSSID, so |
| 1293 | * we optimize an early check to exit out early if we don't have to |
| 1294 | * do anything */ |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1295 | if (likely(wiphy_idx_valid(last_request->wiphy_idx))) { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1296 | struct cfg80211_registered_device *drv_last_ie; |
| 1297 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1298 | drv_last_ie = |
| 1299 | cfg80211_drv_by_wiphy_idx(last_request->wiphy_idx); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1300 | |
| 1301 | /* Lets keep this simple -- we trust the first AP |
| 1302 | * after we intersect with CRDA */ |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1303 | if (likely(&drv_last_ie->wiphy == wiphy)) { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1304 | /* Ignore IEs coming in on this wiphy with |
| 1305 | * the same alpha2 and environment cap */ |
| 1306 | if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, |
| 1307 | alpha2) && |
| 1308 | env == drv_last_ie->env)) { |
| 1309 | goto out; |
| 1310 | } |
| 1311 | /* the wiphy moved on to another BSSID or the AP |
| 1312 | * was reconfigured. XXX: We need to deal with the |
| 1313 | * case where the user suspends and goes to goes |
| 1314 | * to another country, and then gets IEs from an |
| 1315 | * AP with different settings */ |
| 1316 | goto out; |
| 1317 | } else { |
| 1318 | /* Ignore IEs coming in on two separate wiphys with |
| 1319 | * the same alpha2 and environment cap */ |
| 1320 | if (likely(alpha2_equal(drv_last_ie->country_ie_alpha2, |
| 1321 | alpha2) && |
| 1322 | env == drv_last_ie->env)) { |
| 1323 | goto out; |
| 1324 | } |
| 1325 | /* We could potentially intersect though */ |
| 1326 | goto out; |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | rd = country_ie_2_rd(country_ie, country_ie_len, &checksum); |
| 1331 | if (!rd) |
| 1332 | goto out; |
| 1333 | |
Luis R. Rodriguez | 915278e | 2009-02-21 00:04:28 -0500 | [diff] [blame^] | 1334 | /* |
| 1335 | * This will not happen right now but we leave it here for the |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1336 | * the future when we want to add suspend/resume support and having |
| 1337 | * the user move to another country after doing so, or having the user |
Luis R. Rodriguez | 915278e | 2009-02-21 00:04:28 -0500 | [diff] [blame^] | 1338 | * move to another AP. Right now we just trust the first AP. |
| 1339 | * |
| 1340 | * If we hit this before we add this support we want to be informed of |
| 1341 | * it as it would indicate a mistake in the current design |
| 1342 | */ |
| 1343 | if (WARN_ON(reg_same_country_ie_hint(wiphy, checksum))) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1344 | goto out; |
| 1345 | |
| 1346 | /* We keep this around for when CRDA comes back with a response so |
| 1347 | * we can intersect with that */ |
| 1348 | country_ie_regdomain = rd; |
| 1349 | |
| 1350 | __regulatory_hint(wiphy, REGDOM_SET_BY_COUNTRY_IE, |
| 1351 | country_ie_regdomain->alpha2, checksum, env); |
| 1352 | |
| 1353 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1354 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1355 | } |
| 1356 | EXPORT_SYMBOL(regulatory_hint_11d); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1357 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1358 | static void print_rd_rules(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1359 | { |
| 1360 | unsigned int i; |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1361 | const struct ieee80211_reg_rule *reg_rule = NULL; |
| 1362 | const struct ieee80211_freq_range *freq_range = NULL; |
| 1363 | const struct ieee80211_power_rule *power_rule = NULL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1364 | |
| 1365 | printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), " |
| 1366 | "(max_antenna_gain, max_eirp)\n"); |
| 1367 | |
| 1368 | for (i = 0; i < rd->n_reg_rules; i++) { |
| 1369 | reg_rule = &rd->reg_rules[i]; |
| 1370 | freq_range = ®_rule->freq_range; |
| 1371 | power_rule = ®_rule->power_rule; |
| 1372 | |
| 1373 | /* There may not be documentation for max antenna gain |
| 1374 | * in certain regions */ |
| 1375 | if (power_rule->max_antenna_gain) |
| 1376 | printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " |
| 1377 | "(%d mBi, %d mBm)\n", |
| 1378 | freq_range->start_freq_khz, |
| 1379 | freq_range->end_freq_khz, |
| 1380 | freq_range->max_bandwidth_khz, |
| 1381 | power_rule->max_antenna_gain, |
| 1382 | power_rule->max_eirp); |
| 1383 | else |
| 1384 | printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), " |
| 1385 | "(N/A, %d mBm)\n", |
| 1386 | freq_range->start_freq_khz, |
| 1387 | freq_range->end_freq_khz, |
| 1388 | freq_range->max_bandwidth_khz, |
| 1389 | power_rule->max_eirp); |
| 1390 | } |
| 1391 | } |
| 1392 | |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1393 | static void print_regdomain(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1394 | { |
| 1395 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1396 | if (is_intersected_alpha2(rd->alpha2)) { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1397 | |
| 1398 | if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE) { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1399 | struct cfg80211_registered_device *drv; |
| 1400 | drv = cfg80211_drv_by_wiphy_idx( |
| 1401 | last_request->wiphy_idx); |
| 1402 | if (drv) { |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1403 | printk(KERN_INFO "cfg80211: Current regulatory " |
| 1404 | "domain updated by AP to: %c%c\n", |
| 1405 | drv->country_ie_alpha2[0], |
| 1406 | drv->country_ie_alpha2[1]); |
| 1407 | } else |
| 1408 | printk(KERN_INFO "cfg80211: Current regulatory " |
| 1409 | "domain intersected: \n"); |
| 1410 | } else |
| 1411 | printk(KERN_INFO "cfg80211: Current regulatory " |
Luis R. Rodriguez | 039498c | 2009-01-07 17:43:35 -0800 | [diff] [blame] | 1412 | "domain intersected: \n"); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1413 | } else if (is_world_regdom(rd->alpha2)) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1414 | printk(KERN_INFO "cfg80211: World regulatory " |
| 1415 | "domain updated:\n"); |
| 1416 | else { |
| 1417 | if (is_unknown_alpha2(rd->alpha2)) |
| 1418 | printk(KERN_INFO "cfg80211: Regulatory domain " |
| 1419 | "changed to driver built-in settings " |
| 1420 | "(unknown country)\n"); |
| 1421 | else |
| 1422 | printk(KERN_INFO "cfg80211: Regulatory domain " |
| 1423 | "changed to country: %c%c\n", |
| 1424 | rd->alpha2[0], rd->alpha2[1]); |
| 1425 | } |
| 1426 | print_rd_rules(rd); |
| 1427 | } |
| 1428 | |
Johannes Berg | 2df7816 | 2008-10-28 16:49:41 +0100 | [diff] [blame] | 1429 | static void print_regdomain_info(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1430 | { |
| 1431 | printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n", |
| 1432 | rd->alpha2[0], rd->alpha2[1]); |
| 1433 | print_rd_rules(rd); |
| 1434 | } |
| 1435 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1436 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 1437 | static void reg_country_ie_process_debug( |
| 1438 | const struct ieee80211_regdomain *rd, |
| 1439 | const struct ieee80211_regdomain *country_ie_regdomain, |
| 1440 | const struct ieee80211_regdomain *intersected_rd) |
| 1441 | { |
| 1442 | printk(KERN_DEBUG "cfg80211: Received country IE:\n"); |
| 1443 | print_regdomain_info(country_ie_regdomain); |
| 1444 | printk(KERN_DEBUG "cfg80211: CRDA thinks this should applied:\n"); |
| 1445 | print_regdomain_info(rd); |
| 1446 | if (intersected_rd) { |
| 1447 | printk(KERN_DEBUG "cfg80211: We intersect both of these " |
| 1448 | "and get:\n"); |
Luis R. Rodriguez | 667ecd0 | 2009-01-22 15:05:43 -0800 | [diff] [blame] | 1449 | print_regdomain_info(intersected_rd); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1450 | return; |
| 1451 | } |
| 1452 | printk(KERN_DEBUG "cfg80211: Intersection between both failed\n"); |
| 1453 | } |
| 1454 | #else |
| 1455 | static inline void reg_country_ie_process_debug( |
| 1456 | const struct ieee80211_regdomain *rd, |
| 1457 | const struct ieee80211_regdomain *country_ie_regdomain, |
| 1458 | const struct ieee80211_regdomain *intersected_rd) |
| 1459 | { |
| 1460 | } |
| 1461 | #endif |
| 1462 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 1463 | /* Takes ownership of rd only if it doesn't fail */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1464 | static int __set_regdom(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1465 | { |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1466 | const struct ieee80211_regdomain *intersected_rd = NULL; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1467 | struct cfg80211_registered_device *drv = NULL; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1468 | struct wiphy *request_wiphy; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1469 | /* Some basic sanity checks first */ |
| 1470 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1471 | if (is_world_regdom(rd->alpha2)) { |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1472 | if (WARN_ON(!reg_is_valid_request(rd->alpha2))) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1473 | return -EINVAL; |
| 1474 | update_world_regdomain(rd); |
| 1475 | return 0; |
| 1476 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1477 | |
| 1478 | if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && |
| 1479 | !is_unknown_alpha2(rd->alpha2)) |
| 1480 | return -EINVAL; |
| 1481 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1482 | if (!last_request) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1483 | return -EINVAL; |
| 1484 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1485 | /* Lets only bother proceeding on the same alpha2 if the current |
| 1486 | * rd is non static (it means CRDA was present and was used last) |
| 1487 | * and the pending request came in from a country IE */ |
| 1488 | if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) { |
| 1489 | /* If someone else asked us to change the rd lets only bother |
| 1490 | * checking if the alpha2 changes if CRDA was already called */ |
| 1491 | if (!is_old_static_regdom(cfg80211_regdomain) && |
| 1492 | !regdom_changed(rd->alpha2)) |
| 1493 | return -EINVAL; |
| 1494 | } |
| 1495 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1496 | /* Now lets set the regulatory domain, update all driver channels |
| 1497 | * and finally inform them of what we have done, in case they want |
| 1498 | * to review or adjust their own settings based on their own |
| 1499 | * internal EEPROM data */ |
| 1500 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1501 | if (WARN_ON(!reg_is_valid_request(rd->alpha2))) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1502 | return -EINVAL; |
| 1503 | |
Luis R. Rodriguez | 8375af3 | 2008-11-12 14:21:57 -0800 | [diff] [blame] | 1504 | if (!is_valid_rd(rd)) { |
| 1505 | printk(KERN_ERR "cfg80211: Invalid " |
| 1506 | "regulatory domain detected:\n"); |
| 1507 | print_regdomain_info(rd); |
| 1508 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1511 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 1512 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 1513 | if (!last_request->intersect) { |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1514 | int r; |
| 1515 | |
| 1516 | if (last_request->initiator != REGDOM_SET_BY_DRIVER) { |
| 1517 | reset_regdomains(); |
| 1518 | cfg80211_regdomain = rd; |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
| 1522 | /* For a driver hint, lets copy the regulatory domain the |
| 1523 | * driver wanted to the wiphy to deal with conflicts */ |
| 1524 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1525 | BUG_ON(request_wiphy->regd); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1526 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1527 | r = reg_copy_regd(&request_wiphy->regd, rd); |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1528 | if (r) |
| 1529 | return r; |
| 1530 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 1531 | reset_regdomains(); |
| 1532 | cfg80211_regdomain = rd; |
| 1533 | return 0; |
| 1534 | } |
| 1535 | |
| 1536 | /* Intersection requires a bit more work */ |
| 1537 | |
| 1538 | if (last_request->initiator != REGDOM_SET_BY_COUNTRY_IE) { |
| 1539 | |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1540 | intersected_rd = regdom_intersect(rd, cfg80211_regdomain); |
| 1541 | if (!intersected_rd) |
| 1542 | return -EINVAL; |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 1543 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1544 | /* We can trash what CRDA provided now. |
| 1545 | * However if a driver requested this specific regulatory |
| 1546 | * domain we keep it for its private use */ |
| 1547 | if (last_request->initiator == REGDOM_SET_BY_DRIVER) |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1548 | request_wiphy->regd = rd; |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1549 | else |
| 1550 | kfree(rd); |
| 1551 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 1552 | rd = NULL; |
| 1553 | |
| 1554 | reset_regdomains(); |
| 1555 | cfg80211_regdomain = intersected_rd; |
| 1556 | |
| 1557 | return 0; |
Luis R. Rodriguez | 9c96477 | 2008-10-30 13:33:53 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1560 | /* |
| 1561 | * Country IE requests are handled a bit differently, we intersect |
| 1562 | * the country IE rd with what CRDA believes that country should have |
| 1563 | */ |
| 1564 | |
| 1565 | BUG_ON(!country_ie_regdomain); |
| 1566 | |
| 1567 | if (rd != country_ie_regdomain) { |
| 1568 | /* Intersect what CRDA returned and our what we |
| 1569 | * had built from the Country IE received */ |
| 1570 | |
| 1571 | intersected_rd = regdom_intersect(rd, country_ie_regdomain); |
| 1572 | |
| 1573 | reg_country_ie_process_debug(rd, country_ie_regdomain, |
| 1574 | intersected_rd); |
| 1575 | |
| 1576 | kfree(country_ie_regdomain); |
| 1577 | country_ie_regdomain = NULL; |
| 1578 | } else { |
| 1579 | /* This would happen when CRDA was not present and |
| 1580 | * OLD_REGULATORY was enabled. We intersect our Country |
| 1581 | * IE rd and what was set on cfg80211 originally */ |
| 1582 | intersected_rd = regdom_intersect(rd, cfg80211_regdomain); |
| 1583 | } |
| 1584 | |
| 1585 | if (!intersected_rd) |
| 1586 | return -EINVAL; |
| 1587 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1588 | drv = wiphy_to_dev(request_wiphy); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1589 | |
| 1590 | drv->country_ie_alpha2[0] = rd->alpha2[0]; |
| 1591 | drv->country_ie_alpha2[1] = rd->alpha2[1]; |
| 1592 | drv->env = last_request->country_ie_env; |
| 1593 | |
| 1594 | BUG_ON(intersected_rd == rd); |
| 1595 | |
| 1596 | kfree(rd); |
| 1597 | rd = NULL; |
| 1598 | |
Luis R. Rodriguez | b8295ac | 2008-11-12 14:21:58 -0800 | [diff] [blame] | 1599 | reset_regdomains(); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1600 | cfg80211_regdomain = intersected_rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1601 | |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | |
| 1606 | /* Use this call to set the current regulatory domain. Conflicts with |
| 1607 | * multiple drivers can be ironed out later. Caller must've already |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1608 | * kmalloc'd the rd structure. Caller must hold cfg80211_mutex */ |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1609 | int set_regdom(const struct ieee80211_regdomain *rd) |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1610 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1611 | int r; |
| 1612 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1613 | assert_cfg80211_lock(); |
| 1614 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1615 | /* Note that this doesn't update the wiphys, this is done below */ |
| 1616 | r = __set_regdom(rd); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 1617 | if (r) { |
| 1618 | kfree(rd); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1619 | return r; |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 1620 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1621 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1622 | /* This would make this whole thing pointless */ |
Luis R. Rodriguez | a01ddaf | 2008-11-12 14:21:59 -0800 | [diff] [blame] | 1623 | if (!last_request->intersect) |
| 1624 | BUG_ON(rd != cfg80211_regdomain); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1625 | |
| 1626 | /* update all wiphys now with the new established regulatory domain */ |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1627 | update_all_wiphy_regulatory(last_request->initiator); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1628 | |
Luis R. Rodriguez | a01ddaf | 2008-11-12 14:21:59 -0800 | [diff] [blame] | 1629 | print_regdomain(cfg80211_regdomain); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1630 | |
| 1631 | return r; |
| 1632 | } |
| 1633 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1634 | /* Caller must hold cfg80211_mutex */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1635 | void reg_device_remove(struct wiphy *wiphy) |
| 1636 | { |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1637 | struct wiphy *request_wiphy; |
| 1638 | |
Luis R. Rodriguez | 761cf7e | 2009-02-21 00:04:25 -0500 | [diff] [blame] | 1639 | assert_cfg80211_lock(); |
| 1640 | |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1641 | request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx); |
| 1642 | |
Luis R. Rodriguez | 3e0c3ff | 2009-01-07 17:43:34 -0800 | [diff] [blame] | 1643 | kfree(wiphy->regd); |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1644 | if (!last_request || !request_wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1645 | return; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1646 | if (request_wiphy != wiphy) |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1647 | return; |
Luis R. Rodriguez | 806a9e3 | 2009-02-21 00:04:26 -0500 | [diff] [blame] | 1648 | last_request->wiphy_idx = WIPHY_IDX_STALE; |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1649 | last_request->country_ie_env = ENVIRON_ANY; |
| 1650 | } |
| 1651 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1652 | int regulatory_init(void) |
| 1653 | { |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 1654 | int err = 0; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1655 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1656 | reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0); |
| 1657 | if (IS_ERR(reg_pdev)) |
| 1658 | return PTR_ERR(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1659 | |
| 1660 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1661 | cfg80211_regdomain = static_regdom(ieee80211_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1662 | |
Johannes Berg | 942b25c | 2008-09-15 11:26:47 +0200 | [diff] [blame] | 1663 | printk(KERN_INFO "cfg80211: Using static regulatory domain info\n"); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1664 | print_regdomain_info(cfg80211_regdomain); |
| 1665 | /* The old code still requests for a new regdomain and if |
| 1666 | * you have CRDA you get it updated, otherwise you get |
| 1667 | * stuck with the static values. We ignore "EU" code as |
| 1668 | * that is not a valid ISO / IEC 3166 alpha2 */ |
Johannes Berg | ac9440a | 2008-10-21 11:08:27 +0200 | [diff] [blame] | 1669 | if (ieee80211_regdom[0] != 'E' || ieee80211_regdom[1] != 'U') |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1670 | err = regulatory_hint_core(ieee80211_regdom); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1671 | #else |
Johannes Berg | a3d2eaf | 2008-09-15 11:10:52 +0200 | [diff] [blame] | 1672 | cfg80211_regdomain = cfg80211_world_regdom; |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1673 | |
Luis R. Rodriguez | ba25c14 | 2009-02-21 00:04:23 -0500 | [diff] [blame] | 1674 | err = regulatory_hint_core("00"); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1675 | #endif |
Luis R. Rodriguez | bcf4f99 | 2009-02-21 00:04:24 -0500 | [diff] [blame] | 1676 | if (err) { |
| 1677 | if (err == -ENOMEM) |
| 1678 | return err; |
| 1679 | /* |
| 1680 | * N.B. kobject_uevent_env() can fail mainly for when we're out |
| 1681 | * memory which is handled and propagated appropriately above |
| 1682 | * but it can also fail during a netlink_broadcast() or during |
| 1683 | * early boot for call_usermodehelper(). For now treat these |
| 1684 | * errors as non-fatal. |
| 1685 | */ |
| 1686 | printk(KERN_ERR "cfg80211: kobject_uevent_env() was unable " |
| 1687 | "to call CRDA during init"); |
| 1688 | #ifdef CONFIG_CFG80211_REG_DEBUG |
| 1689 | /* We want to find out exactly why when debugging */ |
| 1690 | WARN_ON(err); |
| 1691 | #endif |
| 1692 | } |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1693 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1694 | return 0; |
| 1695 | } |
| 1696 | |
| 1697 | void regulatory_exit(void) |
| 1698 | { |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1699 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1700 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1701 | reset_regdomains(); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1702 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1703 | kfree(country_ie_regdomain); |
| 1704 | country_ie_regdomain = NULL; |
| 1705 | |
Johannes Berg | f6037d0 | 2008-10-21 11:01:33 +0200 | [diff] [blame] | 1706 | kfree(last_request); |
| 1707 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1708 | platform_device_unregister(reg_pdev); |
Johannes Berg | 734366d | 2008-09-15 10:56:48 +0200 | [diff] [blame] | 1709 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 1710 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1711 | } |