Lines Matching +full:country +full:- +full:code
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
5 * Copyright 2008-2011 Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
6 * Copyright 2013-2014 Intel Mobile Communications GmbH
8 * Copyright (C) 2018 - 2023 Intel Corporation
29 * looking up the allowable channels in a driver-local table and finally
42 * Note: When number of rules --> infinity we will not be able to
63 #include "rdev-ops.h"
73 * enum reg_request_treatment - regulatory request treatment
150 return rcu_dereference_check(wiphy->regd, in get_wiphy_regdom()
151 lockdep_is_held(&wiphy->mtx) || in get_wiphy_regdom()
179 dfs_region = regd->dfs_region; in reg_get_dfs_region()
188 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { in reg_get_dfs_region()
189 dfs_region = wiphy_regd->dfs_region; in reg_get_dfs_region()
193 if (wiphy_regd->dfs_region == regd->dfs_region) in reg_get_dfs_region()
197 dev_name(&wiphy->dev), in reg_get_dfs_region()
198 reg_dfs_region_str(wiphy_regd->dfs_region), in reg_get_dfs_region()
199 reg_dfs_region_str(regd->dfs_region)); in reg_get_dfs_region()
247 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
249 REG_RULE(2467-10, 2472+10, 20, 6, 20,
251 /* IEEE 802.11 channel 14 - Only JP enables
253 REG_RULE(2484-10, 2484+10, 20, 6, 20,
257 REG_RULE(5180-10, 5240+10, 80, 6, 20,
261 /* IEEE 802.11a, channel 52..64 - DFS required */
262 REG_RULE(5260-10, 5320+10, 80, 6, 20,
267 /* IEEE 802.11a, channel 100..144 - DFS required */
268 REG_RULE(5500-10, 5720+10, 160, 6, 20,
273 REG_RULE(5745-10, 5825+10, 80, 6, 20,
277 REG_RULE(56160+2160*1-1080, 56160+2160*3+1080, 2160, 0, 0, 0),
290 MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
424 return !alpha2_equal(r->alpha2, alpha2); in regdom_changes()
452 regd = kzalloc(struct_size(regd, reg_rules, src_regd->n_reg_rules), in reg_copy_regd()
455 return ERR_PTR(-ENOMEM); in reg_copy_regd()
459 for (i = 0; i < src_regd->n_reg_rules; i++) in reg_copy_regd()
460 memcpy(®d->reg_rules[i], &src_regd->reg_rules[i], in reg_copy_regd()
494 list_del(&request->list); in reg_regdb_apply()
496 set_regdom(request->regdom, REGD_SOURCE_INTERNAL_DB); in reg_regdb_apply()
513 return -ENOMEM; in reg_schedule_apply()
516 request->regdom = regdom; in reg_schedule_apply()
519 list_add_tail(&request->list, ®_regdb_apply_list); in reg_schedule_apply()
560 * This lets us keep regulatory code which is updated on a regulatory
565 char country[12]; in call_crda() local
566 char *env[] = { country, NULL }; in call_crda()
569 snprintf(country, sizeof(country), "COUNTRY=%c%c", in call_crda()
574 return -EINVAL; in call_crda()
578 pr_debug("Calling CRDA for country: %c%c\n", in call_crda()
583 ret = kobject_uevent_env(®_pdev->dev.kobj, KOBJ_CHANGE, env); in call_crda()
597 return -ENODATA; in call_crda()
601 /* code to directly load a firmware database through request_firmware */
653 struct fwdb_country country[]; member
658 return (1 << ecw) - 1; in ecw2cw()
685 if ((u8 *)rule + sizeof(rule->len) > data + size) in valid_rule()
689 if (rule->len < offsetofend(struct fwdb_rule, max_bw)) in valid_rule()
691 if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) { in valid_rule()
692 u32 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; in valid_rule()
707 const struct fwdb_country *country) in valid_country() argument
709 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; in valid_country()
719 if ((u8 *)coll + ALIGN(coll->len, 2) + in valid_country()
720 (coll->n_rules * 2) > data + size) in valid_country()
724 if (coll->len < offsetofend(struct fwdb_collection, dfs_region)) in valid_country()
727 rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); in valid_country()
729 for (i = 0; i < coll->n_rules; i++) { in valid_country()
740 #include <keys/asymmetric-type.h>
755 pr_notice("Loading compiled-in X.509 certificates for regulatory database\n"); in load_builtin_regdb_keys()
779 if (request_firmware(&sig, "regulatory.db.p7s", ®_pdev->dev)) in regdb_has_valid_signature()
782 result = verify_pkcs7_signature(data, size, sig->data, sig->size, in regdb_has_valid_signature()
815 const struct fwdb_country *country; in valid_regdb() local
820 if (hdr->magic != cpu_to_be32(FWDB_MAGIC)) in valid_regdb()
823 if (hdr->version != cpu_to_be32(FWDB_VERSION)) in valid_regdb()
829 country = &hdr->country[0]; in valid_regdb()
830 while ((u8 *)(country + 1) <= data + size) { in valid_regdb()
831 if (!country->coll_ptr) in valid_regdb()
833 if (!valid_country(data, size, country)) in valid_regdb()
835 country++; in valid_regdb()
842 const struct fwdb_country *country, in set_wmm_rule() argument
846 struct ieee80211_wmm_rule *wmm_rule = &rrule->wmm_rule; in set_wmm_rule()
850 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; in set_wmm_rule()
854 pr_err("Invalid regulatory WMM rule %u-%u in domain %c%c\n", in set_wmm_rule()
855 be32_to_cpu(rule->start), be32_to_cpu(rule->end), in set_wmm_rule()
856 country->alpha2[0], country->alpha2[1]); in set_wmm_rule()
861 wmm_rule->client[i].cw_min = in set_wmm_rule()
862 ecw2cw((wmm->client[i].ecw & 0xf0) >> 4); in set_wmm_rule()
863 wmm_rule->client[i].cw_max = ecw2cw(wmm->client[i].ecw & 0x0f); in set_wmm_rule()
864 wmm_rule->client[i].aifsn = wmm->client[i].aifsn; in set_wmm_rule()
865 wmm_rule->client[i].cot = in set_wmm_rule()
866 1000 * be16_to_cpu(wmm->client[i].cot); in set_wmm_rule()
867 wmm_rule->ap[i].cw_min = ecw2cw((wmm->ap[i].ecw & 0xf0) >> 4); in set_wmm_rule()
868 wmm_rule->ap[i].cw_max = ecw2cw(wmm->ap[i].ecw & 0x0f); in set_wmm_rule()
869 wmm_rule->ap[i].aifsn = wmm->ap[i].aifsn; in set_wmm_rule()
870 wmm_rule->ap[i].cot = 1000 * be16_to_cpu(wmm->ap[i].cot); in set_wmm_rule()
873 rrule->has_wmm = true; in set_wmm_rule()
877 const struct fwdb_country *country, int freq, in __regdb_query_wmm() argument
880 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; in __regdb_query_wmm()
884 for (i = 0; i < coll->n_rules; i++) { in __regdb_query_wmm()
885 __be16 *rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); in __regdb_query_wmm()
889 if (rule->len < offsetofend(struct fwdb_rule, wmm_ptr)) in __regdb_query_wmm()
892 if (freq >= KHZ_TO_MHZ(be32_to_cpu(rule->start)) && in __regdb_query_wmm()
893 freq <= KHZ_TO_MHZ(be32_to_cpu(rule->end))) { in __regdb_query_wmm()
894 set_wmm_rule(db, country, rule, rrule); in __regdb_query_wmm()
899 return -ENODATA; in __regdb_query_wmm()
905 const struct fwdb_country *country; in reg_query_regdb_wmm() local
908 return -ENODATA; in reg_query_regdb_wmm()
913 country = &hdr->country[0]; in reg_query_regdb_wmm()
914 while (country->coll_ptr) { in reg_query_regdb_wmm()
915 if (alpha2_equal(alpha2, country->alpha2)) in reg_query_regdb_wmm()
916 return __regdb_query_wmm(regdb, country, freq, rule); in reg_query_regdb_wmm()
918 country++; in reg_query_regdb_wmm()
921 return -ENODATA; in reg_query_regdb_wmm()
926 const struct fwdb_country *country) in regdb_query_country() argument
928 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; in regdb_query_country()
933 regdom = kzalloc(struct_size(regdom, reg_rules, coll->n_rules), in regdb_query_country()
936 return -ENOMEM; in regdb_query_country()
938 regdom->n_reg_rules = coll->n_rules; in regdb_query_country()
939 regdom->alpha2[0] = country->alpha2[0]; in regdb_query_country()
940 regdom->alpha2[1] = country->alpha2[1]; in regdb_query_country()
941 regdom->dfs_region = coll->dfs_region; in regdb_query_country()
943 for (i = 0; i < regdom->n_reg_rules; i++) { in regdb_query_country()
944 __be16 *rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); in regdb_query_country()
947 struct ieee80211_reg_rule *rrule = ®dom->reg_rules[i]; in regdb_query_country()
949 rrule->freq_range.start_freq_khz = be32_to_cpu(rule->start); in regdb_query_country()
950 rrule->freq_range.end_freq_khz = be32_to_cpu(rule->end); in regdb_query_country()
951 rrule->freq_range.max_bandwidth_khz = be32_to_cpu(rule->max_bw); in regdb_query_country()
953 rrule->power_rule.max_antenna_gain = 0; in regdb_query_country()
954 rrule->power_rule.max_eirp = be16_to_cpu(rule->max_eirp); in regdb_query_country()
956 rrule->flags = 0; in regdb_query_country()
957 if (rule->flags & FWDB_FLAG_NO_OFDM) in regdb_query_country()
958 rrule->flags |= NL80211_RRF_NO_OFDM; in regdb_query_country()
959 if (rule->flags & FWDB_FLAG_NO_OUTDOOR) in regdb_query_country()
960 rrule->flags |= NL80211_RRF_NO_OUTDOOR; in regdb_query_country()
961 if (rule->flags & FWDB_FLAG_DFS) in regdb_query_country()
962 rrule->flags |= NL80211_RRF_DFS; in regdb_query_country()
963 if (rule->flags & FWDB_FLAG_NO_IR) in regdb_query_country()
964 rrule->flags |= NL80211_RRF_NO_IR; in regdb_query_country()
965 if (rule->flags & FWDB_FLAG_AUTO_BW) in regdb_query_country()
966 rrule->flags |= NL80211_RRF_AUTO_BW; in regdb_query_country()
968 rrule->dfs_cac_ms = 0; in regdb_query_country()
971 if (rule->len >= offsetofend(struct fwdb_rule, cac_timeout)) in regdb_query_country()
972 rrule->dfs_cac_ms = in regdb_query_country()
973 1000 * be16_to_cpu(rule->cac_timeout); in regdb_query_country()
974 if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) in regdb_query_country()
975 set_wmm_rule(db, country, rule, rrule); in regdb_query_country()
984 const struct fwdb_country *country; in query_regdb() local
991 country = &hdr->country[0]; in query_regdb()
992 while (country->coll_ptr) { in query_regdb()
993 if (alpha2_equal(alpha2, country->alpha2)) in query_regdb()
994 return regdb_query_country(regdb, country); in query_regdb()
995 country++; in query_regdb()
998 return -ENODATA; in query_regdb()
1009 set_error = -ENODATA; in regdb_fw_cb()
1010 } else if (!valid_regdb(fw->data, fw->size)) { in regdb_fw_cb()
1012 set_error = -EINVAL; in regdb_fw_cb()
1017 /* negative case - a bug in regdb_fw_cb()
1018 * positive case - can happen due to race in case of multiple cb's in in regdb_fw_cb()
1026 db = kmemdup(fw->data, fw->size, GFP_KERNEL); in regdb_fw_cb()
1058 return -ENOMEM; in query_regdb_file()
1061 ®_pdev->dev, GFP_KERNEL, in query_regdb_file()
1077 err = request_firmware(&fw, "regulatory.db", ®_pdev->dev); in reg_reload_regdb()
1081 if (!valid_regdb(fw->data, fw->size)) { in reg_reload_regdb()
1082 err = -ENODATA; in reg_reload_regdb()
1086 db = kmemdup(fw->data, fw->size, GFP_KERNEL); in reg_reload_regdb()
1088 err = -ENOMEM; in reg_reload_regdb()
1102 err = -ENOMEM; in reg_reload_regdb()
1106 request->wiphy_idx = WIPHY_IDX_INVALID; in reg_reload_regdb()
1107 request->alpha2[0] = current_regdomain->alpha2[0]; in reg_reload_regdb()
1108 request->alpha2[1] = current_regdomain->alpha2[1]; in reg_reload_regdb()
1109 request->initiator = NL80211_REGDOM_SET_BY_CORE; in reg_reload_regdb()
1110 request->user_reg_hint_type = NL80211_USER_REG_HINT_USER; in reg_reload_regdb()
1123 if (query_regdb_file(request->alpha2) == 0) in reg_query_database()
1126 if (call_crda(request->alpha2) == 0) in reg_query_database()
1136 if (!lr || lr->processed) in reg_is_valid_request()
1139 return alpha2_equal(lr->alpha2, alpha2); in reg_is_valid_request()
1147 * Follow the driver's regulatory domain, if present, unless a country in reg_get_regdomain()
1150 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && in reg_get_regdomain()
1151 lr->initiator != NL80211_REGDOM_SET_BY_USER && in reg_get_regdomain()
1152 wiphy->regd) in reg_get_regdomain()
1162 const struct ieee80211_freq_range *freq_range = &rule->freq_range; in reg_get_max_bandwidth_from_range()
1167 for (idx = 0; idx < rd->n_reg_rules; idx++) in reg_get_max_bandwidth_from_range()
1168 if (rule == &rd->reg_rules[idx]) in reg_get_max_bandwidth_from_range()
1171 if (idx == rd->n_reg_rules) in reg_get_max_bandwidth_from_range()
1178 tmp = &rd->reg_rules[--no]; in reg_get_max_bandwidth_from_range()
1179 freq_range_tmp = &tmp->freq_range; in reg_get_max_bandwidth_from_range()
1181 if (freq_range_tmp->end_freq_khz < freq_range->start_freq_khz) in reg_get_max_bandwidth_from_range()
1187 start_freq = freq_range->start_freq_khz; in reg_get_max_bandwidth_from_range()
1190 freq_range = &rule->freq_range; in reg_get_max_bandwidth_from_range()
1193 while (no < rd->n_reg_rules - 1) { in reg_get_max_bandwidth_from_range()
1194 tmp = &rd->reg_rules[++no]; in reg_get_max_bandwidth_from_range()
1195 freq_range_tmp = &tmp->freq_range; in reg_get_max_bandwidth_from_range()
1197 if (freq_range_tmp->start_freq_khz > freq_range->end_freq_khz) in reg_get_max_bandwidth_from_range()
1203 end_freq = freq_range->end_freq_khz; in reg_get_max_bandwidth_from_range()
1205 return end_freq - start_freq; in reg_get_max_bandwidth_from_range()
1213 if (rule->flags & NL80211_RRF_NO_320MHZ) in reg_get_max_bandwidth()
1215 if (rule->flags & NL80211_RRF_NO_160MHZ) in reg_get_max_bandwidth()
1217 if (rule->flags & NL80211_RRF_NO_80MHZ) in reg_get_max_bandwidth()
1221 * HT40+/HT40- limits are handled per-channel. Only limit BW if both in reg_get_max_bandwidth()
1224 if (rule->flags & NL80211_RRF_NO_HT40MINUS && in reg_get_max_bandwidth()
1225 rule->flags & NL80211_RRF_NO_HT40PLUS) in reg_get_max_bandwidth()
1234 const struct ieee80211_freq_range *freq_range = &rule->freq_range; in is_valid_reg_rule()
1237 if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0) in is_valid_reg_rule()
1240 if (freq_range->start_freq_khz > freq_range->end_freq_khz) in is_valid_reg_rule()
1243 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; in is_valid_reg_rule()
1245 if (freq_range->end_freq_khz <= freq_range->start_freq_khz || in is_valid_reg_rule()
1246 freq_range->max_bandwidth_khz > freq_diff) in is_valid_reg_rule()
1257 if (!rd->n_reg_rules) in is_valid_rd()
1260 if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES)) in is_valid_rd()
1263 for (i = 0; i < rd->n_reg_rules; i++) { in is_valid_rd()
1264 reg_rule = &rd->reg_rules[i]; in is_valid_rd()
1273 * freq_in_rule_band - tells us if a frequency is in a frequency band
1292 * From 802.11ad: directional multi-gigabit (DMG): in freq_in_rule_band()
1298 if (abs(freq_khz - freq_range->start_freq_khz) <= limit) in freq_in_rule_band()
1300 if (abs(freq_khz - freq_range->end_freq_khz) <= limit) in freq_in_rule_band()
1324 intersect->cw_min = max_t(u16, wmm_ac1->cw_min, wmm_ac2->cw_min); in reg_wmm_rules_intersect()
1325 intersect->cw_max = max_t(u16, wmm_ac1->cw_max, wmm_ac2->cw_max); in reg_wmm_rules_intersect()
1326 intersect->cot = min_t(u16, wmm_ac1->cot, wmm_ac2->cot); in reg_wmm_rules_intersect()
1327 intersect->aifsn = max_t(u8, wmm_ac1->aifsn, wmm_ac2->aifsn); in reg_wmm_rules_intersect()
1348 freq_range1 = &rule1->freq_range; in reg_rules_intersect()
1349 freq_range2 = &rule2->freq_range; in reg_rules_intersect()
1350 freq_range = &intersected_rule->freq_range; in reg_rules_intersect()
1352 power_rule1 = &rule1->power_rule; in reg_rules_intersect()
1353 power_rule2 = &rule2->power_rule; in reg_rules_intersect()
1354 power_rule = &intersected_rule->power_rule; in reg_rules_intersect()
1356 wmm_rule1 = &rule1->wmm_rule; in reg_rules_intersect()
1357 wmm_rule2 = &rule2->wmm_rule; in reg_rules_intersect()
1358 wmm_rule = &intersected_rule->wmm_rule; in reg_rules_intersect()
1360 freq_range->start_freq_khz = max(freq_range1->start_freq_khz, in reg_rules_intersect()
1361 freq_range2->start_freq_khz); in reg_rules_intersect()
1362 freq_range->end_freq_khz = min(freq_range1->end_freq_khz, in reg_rules_intersect()
1363 freq_range2->end_freq_khz); in reg_rules_intersect()
1365 max_bandwidth1 = freq_range1->max_bandwidth_khz; in reg_rules_intersect()
1366 max_bandwidth2 = freq_range2->max_bandwidth_khz; in reg_rules_intersect()
1368 if (rule1->flags & NL80211_RRF_AUTO_BW) in reg_rules_intersect()
1370 if (rule2->flags & NL80211_RRF_AUTO_BW) in reg_rules_intersect()
1373 freq_range->max_bandwidth_khz = min(max_bandwidth1, max_bandwidth2); in reg_rules_intersect()
1375 intersected_rule->flags = rule1->flags | rule2->flags; in reg_rules_intersect()
1385 if ((rule1->flags & NL80211_RRF_AUTO_BW) && in reg_rules_intersect()
1386 (rule2->flags & NL80211_RRF_AUTO_BW)) in reg_rules_intersect()
1387 intersected_rule->flags |= NL80211_RRF_AUTO_BW; in reg_rules_intersect()
1389 intersected_rule->flags &= ~NL80211_RRF_AUTO_BW; in reg_rules_intersect()
1391 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; in reg_rules_intersect()
1392 if (freq_range->max_bandwidth_khz > freq_diff) in reg_rules_intersect()
1393 freq_range->max_bandwidth_khz = freq_diff; in reg_rules_intersect()
1395 power_rule->max_eirp = min(power_rule1->max_eirp, in reg_rules_intersect()
1396 power_rule2->max_eirp); in reg_rules_intersect()
1397 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, in reg_rules_intersect()
1398 power_rule2->max_antenna_gain); in reg_rules_intersect()
1400 intersected_rule->dfs_cac_ms = max(rule1->dfs_cac_ms, in reg_rules_intersect()
1401 rule2->dfs_cac_ms); in reg_rules_intersect()
1403 if (rule1->has_wmm && rule2->has_wmm) { in reg_rules_intersect()
1407 reg_wmm_rules_intersect(&wmm_rule1->client[ac], in reg_rules_intersect()
1408 &wmm_rule2->client[ac], in reg_rules_intersect()
1409 &wmm_rule->client[ac]); in reg_rules_intersect()
1410 reg_wmm_rules_intersect(&wmm_rule1->ap[ac], in reg_rules_intersect()
1411 &wmm_rule2->ap[ac], in reg_rules_intersect()
1412 &wmm_rule->ap[ac]); in reg_rules_intersect()
1415 intersected_rule->has_wmm = true; in reg_rules_intersect()
1416 } else if (rule1->has_wmm) { in reg_rules_intersect()
1418 intersected_rule->has_wmm = true; in reg_rules_intersect()
1419 } else if (rule2->has_wmm) { in reg_rules_intersect()
1421 intersected_rule->has_wmm = true; in reg_rules_intersect()
1423 intersected_rule->has_wmm = false; in reg_rules_intersect()
1427 return -EINVAL; in reg_rules_intersect()
1437 if (r1->flags != r2->flags) in rule_contains()
1441 if ((r1->power_rule.max_antenna_gain > in rule_contains()
1442 r2->power_rule.max_antenna_gain) || in rule_contains()
1443 r1->power_rule.max_eirp > r2->power_rule.max_eirp) in rule_contains()
1447 if (r1->freq_range.start_freq_khz > r2->freq_range.start_freq_khz || in rule_contains()
1448 r1->freq_range.end_freq_khz < r2->freq_range.end_freq_khz) in rule_contains()
1452 if (r1->freq_range.max_bandwidth_khz < in rule_contains()
1453 r2->freq_range.max_bandwidth_khz) in rule_contains()
1468 /* rule is already contained - do nothing */ in add_rule()
1484 * regdom_intersect - do the intersection between two regulatory domains
1514 * is it will return -EINVAL if the rule computed makes no sense. in regdom_intersect()
1518 for (x = 0; x < rd1->n_reg_rules; x++) { in regdom_intersect()
1519 rule1 = &rd1->reg_rules[x]; in regdom_intersect()
1520 for (y = 0; y < rd2->n_reg_rules; y++) { in regdom_intersect()
1521 rule2 = &rd2->reg_rules[y]; in regdom_intersect()
1535 for (x = 0; x < rd1->n_reg_rules; x++) { in regdom_intersect()
1536 rule1 = &rd1->reg_rules[x]; in regdom_intersect()
1537 for (y = 0; y < rd2->n_reg_rules; y++) { in regdom_intersect()
1538 rule2 = &rd2->reg_rules[y]; in regdom_intersect()
1548 add_rule(&intersected_rule, rd->reg_rules, in regdom_intersect()
1549 &rd->n_reg_rules); in regdom_intersect()
1553 rd->alpha2[0] = '9'; in regdom_intersect()
1554 rd->alpha2[1] = '8'; in regdom_intersect()
1555 rd->dfs_region = reg_intersect_dfs_region(rd1->dfs_region, in regdom_intersect()
1556 rd2->dfs_region); in regdom_intersect()
1604 return ERR_PTR(-EINVAL); in freq_reg_info_regd()
1606 for (i = 0; i < regd->n_reg_rules; i++) { in freq_reg_info_regd()
1610 rr = ®d->reg_rules[i]; in freq_reg_info_regd()
1611 fr = &rr->freq_range; in freq_reg_info_regd()
1628 return ERR_PTR(-ERANGE); in freq_reg_info_regd()
1630 return ERR_PTR(-EINVAL); in freq_reg_info_regd()
1638 const struct ieee80211_reg_rule *reg_rule = ERR_PTR(-ERANGE); in __freq_reg_info()
1639 int i = ARRAY_SIZE(bws) - 1; in __freq_reg_info()
1642 for (bw = MHZ_TO_KHZ(bws[i]); bw >= min_bw; bw = MHZ_TO_KHZ(bws[i--])) { in __freq_reg_info()
1670 return "country element"; in reg_initiator_name()
1684 bool is_s1g = chan->band == NL80211_BAND_S1GHZ; in reg_rule_to_chan_bw_flags()
1686 freq_range = ®_rule->freq_range; in reg_rule_to_chan_bw_flags()
1688 max_bandwidth_khz = freq_range->max_bandwidth_khz; in reg_rule_to_chan_bw_flags()
1691 if (reg_rule->flags & NL80211_RRF_AUTO_BW) in reg_rule_to_chan_bw_flags()
1713 edge_offset = (center_freq_khz - ch_bw / 2) - in reg_rule_to_chan_bw_flags()
1714 freq_range->start_freq_khz; in reg_rule_to_chan_bw_flags()
1774 power_rule = ®_rule->power_rule; in handle_channel_single_rule()
1777 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in handle_channel_single_rule()
1779 request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in handle_channel_single_rule()
1785 chan->flags = chan->orig_flags = in handle_channel_single_rule()
1786 map_regdom_flags(reg_rule->flags) | bw_flags; in handle_channel_single_rule()
1787 chan->max_antenna_gain = chan->orig_mag = in handle_channel_single_rule()
1788 (int) MBI_TO_DBI(power_rule->max_antenna_gain); in handle_channel_single_rule()
1789 chan->max_reg_power = chan->max_power = chan->orig_mpwr = in handle_channel_single_rule()
1790 (int) MBM_TO_DBM(power_rule->max_eirp); in handle_channel_single_rule()
1792 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_single_rule()
1793 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_single_rule()
1794 if (reg_rule->dfs_cac_ms) in handle_channel_single_rule()
1795 chan->dfs_cac_ms = reg_rule->dfs_cac_ms; in handle_channel_single_rule()
1801 chan->dfs_state = NL80211_DFS_USABLE; in handle_channel_single_rule()
1802 chan->dfs_state_entered = jiffies; in handle_channel_single_rule()
1804 chan->beacon_found = false; in handle_channel_single_rule()
1805 chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags); in handle_channel_single_rule()
1806 chan->max_antenna_gain = in handle_channel_single_rule()
1807 min_t(int, chan->orig_mag, in handle_channel_single_rule()
1808 MBI_TO_DBI(power_rule->max_antenna_gain)); in handle_channel_single_rule()
1809 chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp); in handle_channel_single_rule()
1811 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_single_rule()
1812 if (reg_rule->dfs_cac_ms) in handle_channel_single_rule()
1813 chan->dfs_cac_ms = reg_rule->dfs_cac_ms; in handle_channel_single_rule()
1815 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_single_rule()
1818 if (chan->orig_mpwr) { in handle_channel_single_rule()
1821 * will always follow the passed country IE power settings. in handle_channel_single_rule()
1824 wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_FOLLOW_POWER) in handle_channel_single_rule()
1825 chan->max_power = chan->max_reg_power; in handle_channel_single_rule()
1827 chan->max_power = min(chan->orig_mpwr, in handle_channel_single_rule()
1828 chan->max_reg_power); in handle_channel_single_rule()
1830 chan->max_power = chan->max_reg_power; in handle_channel_single_rule()
1851 power_rule1 = &rrule1->power_rule; in handle_channel_adjacent_rules()
1852 power_rule2 = &rrule2->power_rule; in handle_channel_adjacent_rules()
1856 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in handle_channel_adjacent_rules()
1858 request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in handle_channel_adjacent_rules()
1863 chan->flags = in handle_channel_adjacent_rules()
1864 map_regdom_flags(rrule1->flags) | in handle_channel_adjacent_rules()
1865 map_regdom_flags(rrule2->flags) | in handle_channel_adjacent_rules()
1868 chan->orig_flags = chan->flags; in handle_channel_adjacent_rules()
1869 chan->max_antenna_gain = in handle_channel_adjacent_rules()
1870 min_t(int, MBI_TO_DBI(power_rule1->max_antenna_gain), in handle_channel_adjacent_rules()
1871 MBI_TO_DBI(power_rule2->max_antenna_gain)); in handle_channel_adjacent_rules()
1872 chan->orig_mag = chan->max_antenna_gain; in handle_channel_adjacent_rules()
1873 chan->max_reg_power = in handle_channel_adjacent_rules()
1874 min_t(int, MBM_TO_DBM(power_rule1->max_eirp), in handle_channel_adjacent_rules()
1875 MBM_TO_DBM(power_rule2->max_eirp)); in handle_channel_adjacent_rules()
1876 chan->max_power = chan->max_reg_power; in handle_channel_adjacent_rules()
1877 chan->orig_mpwr = chan->max_reg_power; in handle_channel_adjacent_rules()
1879 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_adjacent_rules()
1880 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_adjacent_rules()
1881 if (rrule1->dfs_cac_ms || rrule2->dfs_cac_ms) in handle_channel_adjacent_rules()
1882 chan->dfs_cac_ms = max_t(unsigned int, in handle_channel_adjacent_rules()
1883 rrule1->dfs_cac_ms, in handle_channel_adjacent_rules()
1884 rrule2->dfs_cac_ms); in handle_channel_adjacent_rules()
1890 chan->dfs_state = NL80211_DFS_USABLE; in handle_channel_adjacent_rules()
1891 chan->dfs_state_entered = jiffies; in handle_channel_adjacent_rules()
1893 chan->beacon_found = false; in handle_channel_adjacent_rules()
1894 chan->flags = flags | bw_flags1 | bw_flags2 | in handle_channel_adjacent_rules()
1895 map_regdom_flags(rrule1->flags) | in handle_channel_adjacent_rules()
1896 map_regdom_flags(rrule2->flags); in handle_channel_adjacent_rules()
1904 chan->flags &= ~IEEE80211_CHAN_NO_10MHZ; in handle_channel_adjacent_rules()
1908 chan->flags &= ~IEEE80211_CHAN_NO_20MHZ; in handle_channel_adjacent_rules()
1910 chan->max_antenna_gain = in handle_channel_adjacent_rules()
1911 min_t(int, chan->orig_mag, in handle_channel_adjacent_rules()
1913 MBI_TO_DBI(power_rule1->max_antenna_gain), in handle_channel_adjacent_rules()
1914 MBI_TO_DBI(power_rule2->max_antenna_gain))); in handle_channel_adjacent_rules()
1915 chan->max_reg_power = min_t(int, in handle_channel_adjacent_rules()
1916 MBM_TO_DBM(power_rule1->max_eirp), in handle_channel_adjacent_rules()
1917 MBM_TO_DBM(power_rule2->max_eirp)); in handle_channel_adjacent_rules()
1919 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_adjacent_rules()
1920 if (rrule1->dfs_cac_ms || rrule2->dfs_cac_ms) in handle_channel_adjacent_rules()
1921 chan->dfs_cac_ms = max_t(unsigned int, in handle_channel_adjacent_rules()
1922 rrule1->dfs_cac_ms, in handle_channel_adjacent_rules()
1923 rrule2->dfs_cac_ms); in handle_channel_adjacent_rules()
1925 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_adjacent_rules()
1928 if (chan->orig_mpwr) { in handle_channel_adjacent_rules()
1930 * will always follow the passed country IE power settings. in handle_channel_adjacent_rules()
1933 wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_FOLLOW_POWER) in handle_channel_adjacent_rules()
1934 chan->max_power = chan->max_reg_power; in handle_channel_adjacent_rules()
1936 chan->max_power = min(chan->orig_mpwr, in handle_channel_adjacent_rules()
1937 chan->max_reg_power); in handle_channel_adjacent_rules()
1939 chan->max_power = chan->max_reg_power; in handle_channel_adjacent_rules()
1953 struct wiphy *request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); in handle_channel()
1958 u32 flags = chan->orig_flags; in handle_channel()
1963 * chan - 20 MHz and chan + 20 MHz and test in handle_channel()
1967 orig_chan_freq - MHZ_TO_KHZ(20)); in handle_channel()
1973 if (rrule1->freq_range.end_freq_khz != in handle_channel()
1974 rrule2->freq_range.start_freq_khz) in handle_channel()
1978 rrule1->freq_range.start_freq_khz; in handle_channel()
1980 rrule2->freq_range.end_freq_khz; in handle_channel()
1983 rrule1->freq_range.max_bandwidth_khz, in handle_channel()
1984 rrule2->freq_range.max_bandwidth_khz); in handle_channel()
2001 * from a Country IE and the Country IE had no information in handle_channel()
2005 * a country IE with information for the 2.4 GHz band in handle_channel()
2009 PTR_ERR(rrule) == -ERANGE) in handle_channel()
2012 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in handle_channel()
2014 request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in handle_channel()
2016 chan->center_freq, chan->freq_offset); in handle_channel()
2017 chan->orig_flags |= IEEE80211_CHAN_DISABLED; in handle_channel()
2018 chan->flags = chan->orig_flags; in handle_channel()
2021 chan->center_freq, chan->freq_offset); in handle_channel()
2022 chan->flags |= IEEE80211_CHAN_DISABLED; in handle_channel()
2040 for (i = 0; i < sband->n_channels; i++) in handle_band()
2041 handle_channel(wiphy, initiator, &sband->channels[i]); in handle_band()
2046 if (request->initiator != NL80211_REGDOM_SET_BY_USER) in reg_request_cell_base()
2048 return request->user_reg_hint_type == NL80211_USER_REG_HINT_CELL_BASE; in reg_request_cell_base()
2067 !regdom_changes(pending_request->alpha2)) in reg_ignore_cell_hint()
2076 return !(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS); in reg_dev_ignore_cell_hint()
2093 if (wiphy->regulatory_flags & REGULATORY_STRICT_REG && in wiphy_strict_alpha2_regd()
2094 !(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG)) in wiphy_strict_alpha2_regd()
2104 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) in ignore_reg_update()
2114 wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) { in ignore_reg_update()
2121 * wiphy->regd will be set once the device has its own in ignore_reg_update()
2124 if (wiphy_strict_alpha2_regd(wiphy) && !wiphy->regd && in ignore_reg_update()
2126 !is_world_regdom(lr->alpha2)) { in ignore_reg_update()
2144 if (is_world_regdom(cr->alpha2) || (wr && is_world_regdom(wr->alpha2))) in reg_is_world_roaming()
2147 if (lr && lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && in reg_is_world_roaming()
2148 wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) in reg_is_world_roaming()
2162 sband = wiphy->bands[reg_beacon->chan.band]; in handle_reg_beacon()
2163 chan = &sband->channels[chan_idx]; in handle_reg_beacon()
2165 if (likely(!ieee80211_channel_equal(chan, ®_beacon->chan))) in handle_reg_beacon()
2168 if (chan->beacon_found) in handle_reg_beacon()
2171 chan->beacon_found = true; in handle_reg_beacon()
2176 if (wiphy->regulatory_flags & REGULATORY_DISABLE_BEACON_HINTS) in handle_reg_beacon()
2181 if (chan->flags & IEEE80211_CHAN_NO_IR) { in handle_reg_beacon()
2182 chan->flags &= ~IEEE80211_CHAN_NO_IR; in handle_reg_beacon()
2200 if (!wiphy->bands[reg_beacon->chan.band]) in wiphy_update_new_beacon()
2203 sband = wiphy->bands[reg_beacon->chan.band]; in wiphy_update_new_beacon()
2205 for (i = 0; i < sband->n_channels; i++) in wiphy_update_new_beacon()
2219 if (!wiphy->bands[reg_beacon->chan.band]) in wiphy_update_beacon_reg()
2221 sband = wiphy->bands[reg_beacon->chan.band]; in wiphy_update_beacon_reg()
2222 for (i = 0; i < sband->n_channels; i++) in wiphy_update_beacon_reg()
2243 if (chan->flags & IEEE80211_CHAN_DISABLED) in is_ht40_allowed()
2246 if ((chan->flags & IEEE80211_CHAN_NO_HT40) == IEEE80211_CHAN_NO_HT40) in is_ht40_allowed()
2254 struct ieee80211_supported_band *sband = wiphy->bands[channel->band]; in reg_process_ht_flags_channel()
2261 channel->flags |= IEEE80211_CHAN_NO_HT40; in reg_process_ht_flags_channel()
2267 * be able to use HT40- or HT40+, this finds them (or not) in reg_process_ht_flags_channel()
2269 for (i = 0; i < sband->n_channels; i++) { in reg_process_ht_flags_channel()
2270 struct ieee80211_channel *c = &sband->channels[i]; in reg_process_ht_flags_channel()
2272 if (c->center_freq == (channel->center_freq - 20)) in reg_process_ht_flags_channel()
2274 if (c->center_freq == (channel->center_freq + 20)) in reg_process_ht_flags_channel()
2282 freq_reg_info_regd(MHZ_TO_KHZ(channel->center_freq), in reg_process_ht_flags_channel()
2286 flags = reg_rule->flags; in reg_process_ht_flags_channel()
2296 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; in reg_process_ht_flags_channel()
2298 channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS; in reg_process_ht_flags_channel()
2302 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; in reg_process_ht_flags_channel()
2304 channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS; in reg_process_ht_flags_channel()
2315 for (i = 0; i < sband->n_channels; i++) in reg_process_ht_flags_band()
2316 reg_process_ht_flags_channel(wiphy, &sband->channels[i]); in reg_process_ht_flags_band()
2327 reg_process_ht_flags_band(wiphy, wiphy->bands[band]); in reg_process_ht_flags()
2333 if (wiphy->reg_notifier) in reg_call_notifier()
2334 wiphy->reg_notifier(wiphy, request); in reg_call_notifier()
2346 iftype = wdev->iftype; in reg_wdev_chan_valid()
2349 if (!wdev->netdev || !netif_running(wdev->netdev)) in reg_wdev_chan_valid()
2352 for (link = 0; link < ARRAY_SIZE(wdev->links); link++) { in reg_wdev_chan_valid()
2355 if (!wdev->valid_links && link > 0) in reg_wdev_chan_valid()
2357 if (wdev->valid_links && !(wdev->valid_links & BIT(link))) in reg_wdev_chan_valid()
2362 if (!wdev->links[link].ap.beacon_interval) in reg_wdev_chan_valid()
2364 chandef = wdev->links[link].ap.chandef; in reg_wdev_chan_valid()
2367 if (!wdev->u.mesh.beacon_interval) in reg_wdev_chan_valid()
2369 chandef = wdev->u.mesh.chandef; in reg_wdev_chan_valid()
2372 if (!wdev->u.ibss.ssid_len) in reg_wdev_chan_valid()
2374 chandef = wdev->u.ibss.chandef; in reg_wdev_chan_valid()
2379 if (!wdev->links[link].client.current_bss) in reg_wdev_chan_valid()
2382 chan = wdev->links[link].client.current_bss->pub.channel; in reg_wdev_chan_valid()
2386 if (!rdev->ops->get_channel || in reg_wdev_chan_valid()
2397 if (!wdev->u.ocb.chandef.chan) in reg_wdev_chan_valid()
2399 chandef = wdev->u.ocb.chandef; in reg_wdev_chan_valid()
2451 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) in reg_leave_invalid_chans()
2465 reg_leave_invalid_chans(&rdev->wiphy); in reg_check_chans_work()
2494 wiphy->regulatory_flags & REGULATORY_CUSTOM_REG && in wiphy_update_regulatory()
2495 !(wiphy->regulatory_flags & in wiphy_update_regulatory()
2501 lr->dfs_region = get_cfg80211_regdom()->dfs_region; in wiphy_update_regulatory()
2504 handle_band(wiphy, initiator, wiphy->bands[band]); in wiphy_update_regulatory()
2519 wiphy = &rdev->wiphy; in update_all_wiphy_regulatory()
2545 chan->center_freq, chan->freq_offset); in handle_channel_custom()
2546 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { in handle_channel_custom()
2547 chan->flags |= IEEE80211_CHAN_DISABLED; in handle_channel_custom()
2549 chan->orig_flags |= IEEE80211_CHAN_DISABLED; in handle_channel_custom()
2550 chan->flags = chan->orig_flags; in handle_channel_custom()
2555 power_rule = ®_rule->power_rule; in handle_channel_custom()
2558 chan->dfs_state_entered = jiffies; in handle_channel_custom()
2559 chan->dfs_state = NL80211_DFS_USABLE; in handle_channel_custom()
2561 chan->beacon_found = false; in handle_channel_custom()
2563 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) in handle_channel_custom()
2564 chan->flags = chan->orig_flags | bw_flags | in handle_channel_custom()
2565 map_regdom_flags(reg_rule->flags); in handle_channel_custom()
2567 chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags; in handle_channel_custom()
2569 chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); in handle_channel_custom()
2570 chan->max_reg_power = chan->max_power = in handle_channel_custom()
2571 (int) MBM_TO_DBM(power_rule->max_eirp); in handle_channel_custom()
2573 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_custom()
2574 if (reg_rule->dfs_cac_ms) in handle_channel_custom()
2575 chan->dfs_cac_ms = reg_rule->dfs_cac_ms; in handle_channel_custom()
2577 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_custom()
2580 chan->max_power = chan->max_reg_power; in handle_channel_custom()
2595 * compatible to US, which permits 2402 - 2472 MHz. in handle_band_custom()
2597 for (i = 0; i < sband->n_channels; i++) in handle_band_custom()
2598 handle_channel_custom(wiphy, &sband->channels[i], regd, in handle_band_custom()
2610 WARN(!(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG), in wiphy_apply_custom_regulatory()
2612 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; in wiphy_apply_custom_regulatory()
2615 if (!wiphy->bands[band]) in wiphy_apply_custom_regulatory()
2617 handle_band_custom(wiphy, wiphy->bands[band], regd); in wiphy_apply_custom_regulatory()
2634 rcu_assign_pointer(wiphy->regd, new_regd); in wiphy_apply_custom_regulatory()
2647 lr->processed = true; in reg_set_request_processed()
2661 * reg_process_hint_core - process core regulatory requests
2671 core_request->intersect = false; in reg_process_hint_core()
2672 core_request->processed = false; in reg_process_hint_core()
2691 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) in __reg_process_hint_user()
2695 * to their country before the IE is picked up in __reg_process_hint_user()
2697 if (lr->initiator == NL80211_REGDOM_SET_BY_USER && in __reg_process_hint_user()
2698 lr->intersect) in __reg_process_hint_user()
2704 if ((lr->initiator == NL80211_REGDOM_SET_BY_CORE || in __reg_process_hint_user()
2705 lr->initiator == NL80211_REGDOM_SET_BY_DRIVER || in __reg_process_hint_user()
2706 lr->initiator == NL80211_REGDOM_SET_BY_USER) && in __reg_process_hint_user()
2707 regdom_changes(lr->alpha2)) in __reg_process_hint_user()
2710 if (!regdom_changes(user_request->alpha2)) in __reg_process_hint_user()
2717 * reg_process_hint_user - process user regulatory requests
2733 user_request->intersect = treatment == REG_REQ_INTERSECT; in reg_process_hint_user()
2734 user_request->processed = false; in reg_process_hint_user()
2738 user_alpha2[0] = user_request->alpha2[0]; in reg_process_hint_user()
2739 user_alpha2[1] = user_request->alpha2[1]; in reg_process_hint_user()
2751 if (lr->initiator == NL80211_REGDOM_SET_BY_CORE) { in __reg_process_hint_driver()
2752 if (regdom_changes(driver_request->alpha2)) in __reg_process_hint_driver()
2762 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in __reg_process_hint_driver()
2763 !regdom_changes(driver_request->alpha2)) in __reg_process_hint_driver()
2770 * reg_process_hint_driver - process driver regulatory requests
2802 rcu_assign_pointer(wiphy->regd, regd); in reg_process_hint_driver()
2808 driver_request->intersect = treatment == REG_REQ_INTERSECT; in reg_process_hint_driver()
2809 driver_request->processed = false; in reg_process_hint_driver()
2839 /* Trust a Cell base station over the AP's country IE */ in __reg_process_hint_country_ie()
2840 if (regdom_changes(country_ie_request->alpha2)) in __reg_process_hint_country_ie()
2844 if (wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_IGNORE) in __reg_process_hint_country_ie()
2848 if (unlikely(!is_an_alpha2(country_ie_request->alpha2))) in __reg_process_hint_country_ie()
2849 return -EINVAL; in __reg_process_hint_country_ie()
2851 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) in __reg_process_hint_country_ie()
2854 last_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); in __reg_process_hint_country_ie()
2859 * Country IE alpha2s. We could in __reg_process_hint_country_ie()
2863 if (regdom_changes(country_ie_request->alpha2)) in __reg_process_hint_country_ie()
2868 if (regdom_changes(country_ie_request->alpha2)) in __reg_process_hint_country_ie()
2874 * reg_process_hint_country_ie - process regulatory requests from country IEs
2876 * @country_ie_request: a regulatory request from a country IE
2879 * a regulatory request issued by a country Information Element.
2904 WARN_ONCE(1, "Unexpected intersection for country elements"); in reg_process_hint_country_ie()
2908 country_ie_request->intersect = false; in reg_process_hint_country_ie()
2909 country_ie_request->processed = false; in reg_process_hint_country_ie()
2929 wiphy1_regd = rcu_dereference(wiphy1->regd); in reg_dfs_domain_same()
2933 wiphy2_regd = rcu_dereference(wiphy2->regd); in reg_dfs_domain_same()
2937 dfs_domain_same = wiphy1_regd->dfs_region == wiphy2_regd->dfs_region; in reg_dfs_domain_same()
2947 if (!(dst_chan->flags & IEEE80211_CHAN_RADAR) || in reg_copy_dfs_chan_state()
2948 !(src_chan->flags & IEEE80211_CHAN_RADAR)) in reg_copy_dfs_chan_state()
2951 if (dst_chan->flags & IEEE80211_CHAN_DISABLED || in reg_copy_dfs_chan_state()
2952 src_chan->flags & IEEE80211_CHAN_DISABLED) in reg_copy_dfs_chan_state()
2955 if (src_chan->center_freq == dst_chan->center_freq && in reg_copy_dfs_chan_state()
2956 dst_chan->dfs_state == NL80211_DFS_USABLE) { in reg_copy_dfs_chan_state()
2957 dst_chan->dfs_state = src_chan->dfs_state; in reg_copy_dfs_chan_state()
2958 dst_chan->dfs_state_entered = src_chan->dfs_state_entered; in reg_copy_dfs_chan_state()
2973 dst_sband = dst_wiphy->bands[band]; in wiphy_share_dfs_chan_state()
2974 src_sband = src_wiphy->bands[band]; in wiphy_share_dfs_chan_state()
2978 for (i = 0; i < dst_sband->n_channels; i++) { in wiphy_share_dfs_chan_state()
2979 dst_chan = &dst_sband->channels[i]; in wiphy_share_dfs_chan_state()
2980 for (j = 0; j < src_sband->n_channels; j++) { in wiphy_share_dfs_chan_state()
2981 src_chan = &src_sband->channels[j]; in wiphy_share_dfs_chan_state()
2995 if (wiphy == &rdev->wiphy) in wiphy_all_share_dfs_chan_state()
2997 wiphy_share_dfs_chan_state(wiphy, &rdev->wiphy); in wiphy_all_share_dfs_chan_state()
3006 enum nl80211_reg_initiator initiator = reg_request->initiator; in reg_process_hint()
3008 if (reg_request->wiphy_idx != WIPHY_IDX_INVALID) in reg_process_hint()
3009 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); in reg_process_hint()
3043 wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in reg_process_hint()
3061 wiphy = &rdev->wiphy; in notify_self_managed_wiphys()
3062 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && in notify_self_managed_wiphys()
3063 request->initiator == NL80211_REGDOM_SET_BY_USER) in notify_self_managed_wiphys()
3079 /* When last_request->processed becomes true this will be rescheduled */ in reg_process_pending_hints()
3080 if (lr && !lr->processed) { in reg_process_pending_hints()
3095 list_del_init(®_request->list); in reg_process_pending_hints()
3106 if (!list_empty(®_requests_list) && lr && lr->processed) in reg_process_pending_hints()
3111 /* Processes beacon hints -- this has nothing to do with country IEs */
3122 list_del_init(&pending_beacon->list); in reg_process_pending_beacon_hints()
3126 wiphy_update_new_beacon(&rdev->wiphy, pending_beacon); in reg_process_pending_beacon_hints()
3129 list_add_tail(&pending_beacon->list, ®_beacon_list); in reg_process_pending_beacon_hints()
3147 regd = rdev->requested_regd; in reg_process_self_managed_hint()
3148 rdev->requested_regd = NULL; in reg_process_self_managed_hint()
3155 rcu_assign_pointer(wiphy->regd, regd); in reg_process_self_managed_hint()
3159 handle_band_custom(wiphy, wiphy->bands[band], regd); in reg_process_self_managed_hint()
3164 request.alpha2[0] = regd->alpha2[0]; in reg_process_self_managed_hint()
3165 request.alpha2[1] = regd->alpha2[1]; in reg_process_self_managed_hint()
3168 if (wiphy->flags & WIPHY_FLAG_NOTIFY_REGDOM_BY_DRIVER) in reg_process_self_managed_hint()
3181 wiphy_lock(&rdev->wiphy); in reg_process_self_managed_hints()
3182 reg_process_self_managed_hint(&rdev->wiphy); in reg_process_self_managed_hints()
3183 wiphy_unlock(&rdev->wiphy); in reg_process_self_managed_hints()
3200 request->alpha2[0] = toupper(request->alpha2[0]); in queue_regulatory_request()
3201 request->alpha2[1] = toupper(request->alpha2[1]); in queue_regulatory_request()
3204 list_add_tail(&request->list, ®_requests_list); in queue_regulatory_request()
3211 * Core regulatory hint -- happens during cfg80211_init()
3220 return -ENOMEM; in regulatory_hint_core()
3222 request->alpha2[0] = alpha2[0]; in regulatory_hint_core()
3223 request->alpha2[1] = alpha2[1]; in regulatory_hint_core()
3224 request->initiator = NL80211_REGDOM_SET_BY_CORE; in regulatory_hint_core()
3225 request->wiphy_idx = WIPHY_IDX_INVALID; in regulatory_hint_core()
3239 return -EINVAL; in regulatory_hint_user()
3242 return -EINVAL; in regulatory_hint_user()
3246 return -ENOMEM; in regulatory_hint_user()
3248 request->wiphy_idx = WIPHY_IDX_INVALID; in regulatory_hint_user()
3249 request->alpha2[0] = alpha2[0]; in regulatory_hint_user()
3250 request->alpha2[1] = alpha2[1]; in regulatory_hint_user()
3251 request->initiator = NL80211_REGDOM_SET_BY_USER; in regulatory_hint_user()
3252 request->user_reg_hint_type = user_reg_hint_type; in regulatory_hint_user()
3312 return -EINVAL; in regulatory_hint()
3314 wiphy->regulatory_flags &= ~REGULATORY_CUSTOM_REG; in regulatory_hint()
3318 return -ENOMEM; in regulatory_hint()
3320 request->wiphy_idx = get_wiphy_idx(wiphy); in regulatory_hint()
3322 request->alpha2[0] = alpha2[0]; in regulatory_hint()
3323 request->alpha2[1] = alpha2[1]; in regulatory_hint()
3324 request->initiator = NL80211_REGDOM_SET_BY_DRIVER; in regulatory_hint()
3372 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && in regulatory_hint_country_ie()
3373 lr->wiphy_idx != WIPHY_IDX_INVALID) in regulatory_hint_country_ie()
3376 request->wiphy_idx = get_wiphy_idx(wiphy); in regulatory_hint_country_ie()
3377 request->alpha2[0] = alpha2[0]; in regulatory_hint_country_ie()
3378 request->alpha2[1] = alpha2[1]; in regulatory_hint_country_ie()
3379 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE; in regulatory_hint_country_ie()
3380 request->country_ie_env = env; in regulatory_hint_country_ie()
3440 sband = wiphy->bands[band]; in restore_custom_reg_settings()
3443 for (i = 0; i < sband->n_channels; i++) { in restore_custom_reg_settings()
3444 chan = &sband->channels[i]; in restore_custom_reg_settings()
3445 chan->flags = chan->orig_flags; in restore_custom_reg_settings()
3446 chan->max_antenna_gain = chan->orig_mag; in restore_custom_reg_settings()
3447 chan->max_power = chan->orig_mpwr; in restore_custom_reg_settings()
3448 chan->beacon_found = false; in restore_custom_reg_settings()
3455 * possibly stale country IE information and user regulatory
3457 * learned as we could have traveled outside to another country
3461 * - send a core regulatory hint
3462 * - send a user regulatory hint if applicable
3464 * Device drivers that send a regulatory hint for a specific country
3465 * keep their own regulatory domain on wiphy->regd so that does
3506 list_del(®_beacon->list); in restore_regulatory_settings()
3512 list_del(®_beacon->list); in restore_regulatory_settings()
3517 world_alpha2[0] = cfg80211_world_regdom->alpha2[0]; in restore_regulatory_settings()
3518 world_alpha2[1] = cfg80211_world_regdom->alpha2[1]; in restore_regulatory_settings()
3521 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) in restore_regulatory_settings()
3523 if (rdev->wiphy.regulatory_flags & REGULATORY_CUSTOM_REG) in restore_regulatory_settings()
3524 restore_custom_reg_settings(&rdev->wiphy); in restore_regulatory_settings()
3543 list_del(&ureq->list); in restore_regulatory_settings()
3578 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { in is_wiphy_all_set_reg_flag()
3580 if (!(wdev->wiphy->regulatory_flags & flag)) { in is_wiphy_all_set_reg_flag()
3606 list_del(®_beacon->list); in regulatory_hint_disconnect()
3613 list_del(®_beacon->list); in regulatory_hint_disconnect()
3639 &pending_beacon->chan)) in pending_reg_beacon()
3651 if (beacon_chan->beacon_found || in regulatory_hint_found_beacon()
3652 beacon_chan->flags & IEEE80211_CHAN_RADAR || in regulatory_hint_found_beacon()
3653 (beacon_chan->band == NL80211_BAND_2GHZ && in regulatory_hint_found_beacon()
3654 !freq_is_chan_12_13_14(beacon_chan->center_freq))) in regulatory_hint_found_beacon()
3666 return -ENOMEM; in regulatory_hint_found_beacon()
3669 beacon_chan->center_freq, beacon_chan->freq_offset, in regulatory_hint_found_beacon()
3674 memcpy(®_beacon->chan, beacon_chan, in regulatory_hint_found_beacon()
3678 * Since we can be called from BH or and non-BH context in regulatory_hint_found_beacon()
3682 list_add_tail(®_beacon->list, ®_pending_beacons); in regulatory_hint_found_beacon()
3698 pr_debug(" (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)\n"); in print_rd_rules()
3700 for (i = 0; i < rd->n_reg_rules; i++) { in print_rd_rules()
3701 reg_rule = &rd->reg_rules[i]; in print_rd_rules()
3702 freq_range = ®_rule->freq_range; in print_rd_rules()
3703 power_rule = ®_rule->power_rule; in print_rd_rules()
3705 if (reg_rule->flags & NL80211_RRF_AUTO_BW) in print_rd_rules()
3707 freq_range->max_bandwidth_khz, in print_rd_rules()
3711 freq_range->max_bandwidth_khz); in print_rd_rules()
3713 if (reg_rule->flags & NL80211_RRF_DFS) in print_rd_rules()
3715 reg_rule->dfs_cac_ms/1000); in print_rd_rules()
3724 if (power_rule->max_antenna_gain) in print_rd_rules()
3725 pr_debug(" (%d KHz - %d KHz @ %s), (%d mBi, %d mBm), (%s)\n", in print_rd_rules()
3726 freq_range->start_freq_khz, in print_rd_rules()
3727 freq_range->end_freq_khz, in print_rd_rules()
3729 power_rule->max_antenna_gain, in print_rd_rules()
3730 power_rule->max_eirp, in print_rd_rules()
3733 pr_debug(" (%d KHz - %d KHz @ %s), (N/A, %d mBm), (%s)\n", in print_rd_rules()
3734 freq_range->start_freq_khz, in print_rd_rules()
3735 freq_range->end_freq_khz, in print_rd_rules()
3737 power_rule->max_eirp, in print_rd_rules()
3760 if (is_intersected_alpha2(rd->alpha2)) { in print_regdomain()
3761 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { in print_regdomain()
3763 rdev = cfg80211_rdev_by_wiphy_idx(lr->wiphy_idx); in print_regdomain()
3766 rdev->country_ie_alpha2[0], in print_regdomain()
3767 rdev->country_ie_alpha2[1]); in print_regdomain()
3772 } else if (is_world_regdom(rd->alpha2)) { in print_regdomain()
3775 if (is_unknown_alpha2(rd->alpha2)) in print_regdomain()
3776 pr_debug("Regulatory domain changed to driver built-in settings (unknown country)\n"); in print_regdomain()
3779 pr_debug("Regulatory domain changed to country: %c%c by Cell Station\n", in print_regdomain()
3780 rd->alpha2[0], rd->alpha2[1]); in print_regdomain()
3782 pr_debug("Regulatory domain changed to country: %c%c\n", in print_regdomain()
3783 rd->alpha2[0], rd->alpha2[1]); in print_regdomain()
3787 pr_debug(" DFS Master region: %s", reg_dfs_region_str(rd->dfs_region)); in print_regdomain()
3793 pr_debug("Regulatory domain: %c%c\n", rd->alpha2[0], rd->alpha2[1]); in print_regdomain_info()
3799 if (!is_world_regdom(rd->alpha2)) in reg_set_rd_core()
3800 return -EINVAL; in reg_set_rd_core()
3810 if (!regdom_changes(rd->alpha2)) in reg_set_rd_user()
3811 return -EALREADY; in reg_set_rd_user()
3815 rd->alpha2[0], rd->alpha2[1]); in reg_set_rd_user()
3817 return -EINVAL; in reg_set_rd_user()
3820 if (!user_request->intersect) { in reg_set_rd_user()
3827 return -EINVAL; in reg_set_rd_user()
3844 if (is_world_regdom(rd->alpha2)) in reg_set_rd_driver()
3845 return -EINVAL; in reg_set_rd_driver()
3847 if (!regdom_changes(rd->alpha2)) in reg_set_rd_driver()
3848 return -EALREADY; in reg_set_rd_driver()
3852 rd->alpha2[0], rd->alpha2[1]); in reg_set_rd_driver()
3854 return -EINVAL; in reg_set_rd_driver()
3857 request_wiphy = wiphy_idx_to_wiphy(driver_request->wiphy_idx); in reg_set_rd_driver()
3859 return -ENODEV; in reg_set_rd_driver()
3861 if (!driver_request->intersect) { in reg_set_rd_driver()
3864 if (request_wiphy->regd) { in reg_set_rd_driver()
3866 return -EALREADY; in reg_set_rd_driver()
3875 rcu_assign_pointer(request_wiphy->regd, regd); in reg_set_rd_driver()
3883 return -EINVAL; in reg_set_rd_driver()
3891 rcu_assign_pointer(request_wiphy->regd, rd); in reg_set_rd_driver()
3906 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && in reg_set_rd_country_ie()
3907 !is_unknown_alpha2(rd->alpha2)) in reg_set_rd_country_ie()
3908 return -EINVAL; in reg_set_rd_country_ie()
3913 * and the pending request came in from a country IE in reg_set_rd_country_ie()
3918 rd->alpha2[0], rd->alpha2[1]); in reg_set_rd_country_ie()
3920 return -EINVAL; in reg_set_rd_country_ie()
3923 request_wiphy = wiphy_idx_to_wiphy(country_ie_request->wiphy_idx); in reg_set_rd_country_ie()
3925 return -ENODEV; in reg_set_rd_country_ie()
3927 if (country_ie_request->intersect) in reg_set_rd_country_ie()
3928 return -EINVAL; in reg_set_rd_country_ie()
3947 return -ENODATA; in set_regdom()
3949 if (!reg_is_valid_request(rd->alpha2)) { in set_regdom()
3951 return -EINVAL; in set_regdom()
3960 switch (lr->initiator) { in set_regdom()
3976 WARN(1, "invalid initiator %d\n", lr->initiator); in set_regdom()
3978 return -EINVAL; in set_regdom()
3983 case -EALREADY: in set_regdom()
3996 if (WARN_ON(!lr->intersect && rd != get_cfg80211_regdom())) in set_regdom()
3997 return -EINVAL; in set_regdom()
4000 update_all_wiphy_regulatory(lr->initiator); in set_regdom()
4019 return -EINVAL; in __regulatory_set_wiphy_regd()
4021 if (WARN(!(wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED), in __regulatory_set_wiphy_regd()
4023 return -EPERM; in __regulatory_set_wiphy_regd()
4027 rd->alpha2[0], rd->alpha2[1])) { in __regulatory_set_wiphy_regd()
4029 return -EINVAL; in __regulatory_set_wiphy_regd()
4039 prev_regd = rdev->requested_regd; in __regulatory_set_wiphy_regd()
4040 rdev->requested_regd = regd; in __regulatory_set_wiphy_regd()
4082 /* self-managed devices ignore beacon hints and country IE */ in wiphy_regulatory_register()
4083 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { in wiphy_regulatory_register()
4084 wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | in wiphy_regulatory_register()
4092 if (lr->initiator == NL80211_REGDOM_SET_BY_USER) in wiphy_regulatory_register()
4099 wiphy_update_regulatory(wiphy, lr->initiator); in wiphy_regulatory_register()
4112 reg_num_devs_support_basehint--; in wiphy_regulatory_deregister()
4115 RCU_INIT_POINTER(wiphy->regd, NULL); in wiphy_regulatory_deregister()
4118 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); in wiphy_regulatory_deregister()
4123 lr->wiphy_idx = WIPHY_IDX_INVALID; in wiphy_regulatory_deregister()
4124 lr->country_ie_env = ENVIRON_ANY; in wiphy_regulatory_deregister()
4129 * 5GHz: https://www.fcc.gov/document/5-ghz-unlicensed-spectrum-unii
4130 * 6GHz: https://www.fcc.gov/document/fcc-proposes-more-spectrum-unlicensed-use-0
4134 /* UNII-1 */ in cfg80211_get_unii()
4138 /* UNII-2A */ in cfg80211_get_unii()
4142 /* UNII-2B */ in cfg80211_get_unii()
4146 /* UNII-2C */ in cfg80211_get_unii()
4150 /* UNII-3 */ in cfg80211_get_unii()
4154 /* UNII-5 */ in cfg80211_get_unii()
4158 /* UNII-6 */ in cfg80211_get_unii()
4162 /* UNII-7 */ in cfg80211_get_unii()
4166 /* UNII-8 */ in cfg80211_get_unii()
4170 return -EINVAL; in cfg80211_get_unii()
4187 wiphy_regd = rcu_dereference(wiphy->regd); in regulatory_pre_cac_allowed()
4189 if (regd->dfs_region == NL80211_DFS_ETSI) in regulatory_pre_cac_allowed()
4197 if (regd->dfs_region == wiphy_regd->dfs_region && in regulatory_pre_cac_allowed()
4198 wiphy_regd->dfs_region == NL80211_DFS_ETSI) in regulatory_pre_cac_allowed()
4213 * either all channels are available - those the CAC_FINISHED in cfg80211_check_and_end_cac()
4215 * in unavailable state in wdev chandef - those the RADAR_DETECTED in cfg80211_check_and_end_cac()
4219 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { in cfg80211_check_and_end_cac()
4222 if (!wdev->cac_started) in cfg80211_check_and_end_cac()
4230 if (!cfg80211_chandef_dfs_usable(&rdev->wiphy, chandef)) in cfg80211_check_and_end_cac()
4231 rdev_end_cac(rdev, wdev->netdev); in cfg80211_check_and_end_cac()
4248 if (wiphy == &rdev->wiphy) in regulatory_propagate_dfs_state()
4251 if (!reg_dfs_domain_same(wiphy, &rdev->wiphy)) in regulatory_propagate_dfs_state()
4254 if (!ieee80211_get_channel(&rdev->wiphy, in regulatory_propagate_dfs_state()
4255 chandef->chan->center_freq)) in regulatory_propagate_dfs_state()
4258 cfg80211_set_dfs_state(&rdev->wiphy, chandef, dfs_state); in regulatory_propagate_dfs_state()
4275 * It's possible that - due to other bugs/issues - cfg80211 in regulatory_init_db()
4281 return -EINVAL; in regulatory_init_db()
4290 err = regulatory_hint_core(cfg80211_world_regdom->alpha2); in regulatory_init_db()
4292 if (err == -ENOMEM) { in regulatory_init_db()
4301 * errors as non-fatal. in regulatory_init_db()
4352 dev_set_uevent_suppress(®_pdev->dev, true); in regulatory_exit()
4357 list_del(®_beacon->list); in regulatory_exit()
4362 list_del(®_beacon->list); in regulatory_exit()
4367 list_del(®_request->list); in regulatory_exit()