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