Lines Matching +full:freq +full:- +full:domain

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 - 2024 Intel Corporation
28 * determine which regulatory domain it should be operating under, then
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
65 #include "rdev-ops.h"
70 * channels allowed by the current regulatory domain.
75 * enum reg_request_treatment - regulatory request treatment
79 * @REG_REQ_INTERSECT: the regulatory domain resulting from this request should
112 * the current one and a world regulatory domain in case we have no
146 * Returns the regulatory domain associated with the wiphy.
152 return rcu_dereference_check(wiphy->regd, in get_wiphy_regdom()
153 lockdep_is_held(&wiphy->mtx) || in get_wiphy_regdom()
181 dfs_region = regd->dfs_region; in reg_get_dfs_region()
190 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { in reg_get_dfs_region()
191 dfs_region = wiphy_regd->dfs_region; in reg_get_dfs_region()
195 if (wiphy_regd->dfs_region == regd->dfs_region) in reg_get_dfs_region()
199 dev_name(&wiphy->dev), in reg_get_dfs_region()
200 reg_dfs_region_str(wiphy_regd->dfs_region), in reg_get_dfs_region()
201 reg_dfs_region_str(regd->dfs_region)); in reg_get_dfs_region()
243 /* We keep a static world regulatory domain in case of the absence of CRDA */
249 REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
251 REG_RULE(2467-10, 2472+10, 20, 6, 20,
253 /* IEEE 802.11 channel 14 - Only JP enables
255 REG_RULE(2484-10, 2484+10, 20, 6, 20,
259 REG_RULE(5180-10, 5240+10, 80, 6, 20,
263 /* IEEE 802.11a, channel 52..64 - DFS required */
264 REG_RULE(5260-10, 5320+10, 80, 6, 20,
269 /* IEEE 802.11a, channel 100..144 - DFS required */
270 REG_RULE(5500-10, 5720+10, 160, 6, 20,
275 REG_RULE(5745-10, 5825+10, 80, 6, 20,
279 REG_RULE(56160+2160*1-1080, 56160+2160*3+1080, 2160, 0, 0, 0),
292 MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
353 * Dynamic world regulatory domain requested by the wireless
388 * Special case where regulatory domain was built by driver in is_unknown_alpha2()
399 * Special case where regulatory domain is the in is_intersected_alpha2()
400 * result of an intersection between two regulatory domain in is_intersected_alpha2()
427 return !alpha2_equal(r->alpha2, alpha2); in regdom_changes()
455 regd = kzalloc(struct_size(regd, reg_rules, src_regd->n_reg_rules), in reg_copy_regd()
458 return ERR_PTR(-ENOMEM); in reg_copy_regd()
462 for (i = 0; i < src_regd->n_reg_rules; i++) in reg_copy_regd()
463 memcpy(&regd->reg_rules[i], &src_regd->reg_rules[i], in reg_copy_regd()
497 list_del(&request->list); in reg_regdb_apply()
499 set_regdom(request->regdom, REGD_SOURCE_INTERNAL_DB); in reg_regdb_apply()
516 return -ENOMEM; in reg_schedule_apply()
519 request->regdom = regdom; in reg_schedule_apply()
522 list_add_tail(&request->list, &reg_regdb_apply_list); in reg_schedule_apply()
577 return -EINVAL; in call_crda()
584 pr_debug("Calling CRDA to update world regulatory domain\n"); in call_crda()
586 ret = kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, env); in call_crda()
600 return -ENODATA; in call_crda()
661 return (1 << ecw) - 1; in ecw2cw()
688 if ((u8 *)rule + sizeof(rule->len) > data + size) in valid_rule()
692 if (rule->len < offsetofend(struct fwdb_rule, max_bw)) in valid_rule()
694 if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) { in valid_rule()
695 u32 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; in valid_rule()
712 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; in valid_country()
722 if ((u8 *)coll + ALIGN(coll->len, 2) + in valid_country()
723 (coll->n_rules * 2) > data + size) in valid_country()
727 if (coll->len < offsetofend(struct fwdb_collection, dfs_region)) in valid_country()
730 rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); in valid_country()
732 for (i = 0; i < coll->n_rules; i++) { in valid_country()
743 #include <keys/asymmetric-type.h>
758 pr_notice("Loading compiled-in X.509 certificates for regulatory database\n"); in load_builtin_regdb_keys()
782 if (request_firmware(&sig, "regulatory.db.p7s", &reg_pdev->dev)) in regdb_has_valid_signature()
785 result = verify_pkcs7_signature(data, size, sig->data, sig->size, in regdb_has_valid_signature()
823 if (hdr->magic != cpu_to_be32(FWDB_MAGIC)) in valid_regdb()
826 if (hdr->version != cpu_to_be32(FWDB_VERSION)) in valid_regdb()
832 country = &hdr->country[0]; in valid_regdb()
834 if (!country->coll_ptr) in valid_regdb()
849 struct ieee80211_wmm_rule *wmm_rule = &rrule->wmm_rule; in set_wmm_rule()
853 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2; in set_wmm_rule()
857 pr_err("Invalid regulatory WMM rule %u-%u in domain %c%c\n", in set_wmm_rule()
858 be32_to_cpu(rule->start), be32_to_cpu(rule->end), in set_wmm_rule()
859 country->alpha2[0], country->alpha2[1]); in set_wmm_rule()
864 wmm_rule->client[i].cw_min = in set_wmm_rule()
865 ecw2cw((wmm->client[i].ecw & 0xf0) >> 4); in set_wmm_rule()
866 wmm_rule->client[i].cw_max = ecw2cw(wmm->client[i].ecw & 0x0f); in set_wmm_rule()
867 wmm_rule->client[i].aifsn = wmm->client[i].aifsn; in set_wmm_rule()
868 wmm_rule->client[i].cot = in set_wmm_rule()
869 1000 * be16_to_cpu(wmm->client[i].cot); in set_wmm_rule()
870 wmm_rule->ap[i].cw_min = ecw2cw((wmm->ap[i].ecw & 0xf0) >> 4); in set_wmm_rule()
871 wmm_rule->ap[i].cw_max = ecw2cw(wmm->ap[i].ecw & 0x0f); in set_wmm_rule()
872 wmm_rule->ap[i].aifsn = wmm->ap[i].aifsn; in set_wmm_rule()
873 wmm_rule->ap[i].cot = 1000 * be16_to_cpu(wmm->ap[i].cot); in set_wmm_rule()
876 rrule->has_wmm = true; in set_wmm_rule()
880 const struct fwdb_country *country, int freq, in __regdb_query_wmm() argument
883 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; in __regdb_query_wmm()
887 for (i = 0; i < coll->n_rules; i++) { in __regdb_query_wmm()
888 __be16 *rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); in __regdb_query_wmm()
892 if (rule->len < offsetofend(struct fwdb_rule, wmm_ptr)) in __regdb_query_wmm()
895 if (freq >= KHZ_TO_MHZ(be32_to_cpu(rule->start)) && in __regdb_query_wmm()
896 freq <= KHZ_TO_MHZ(be32_to_cpu(rule->end))) { in __regdb_query_wmm()
902 return -ENODATA; in __regdb_query_wmm()
905 int reg_query_regdb_wmm(char *alpha2, int freq, struct ieee80211_reg_rule *rule) in reg_query_regdb_wmm() argument
911 return -ENODATA; in reg_query_regdb_wmm()
916 country = &hdr->country[0]; in reg_query_regdb_wmm()
917 while (country->coll_ptr) { in reg_query_regdb_wmm()
918 if (alpha2_equal(alpha2, country->alpha2)) in reg_query_regdb_wmm()
919 return __regdb_query_wmm(regdb, country, freq, rule); in reg_query_regdb_wmm()
924 return -ENODATA; in reg_query_regdb_wmm()
931 unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2; in regdb_query_country()
936 regdom = kzalloc(struct_size(regdom, reg_rules, coll->n_rules), in regdb_query_country()
939 return -ENOMEM; in regdb_query_country()
941 regdom->n_reg_rules = coll->n_rules; in regdb_query_country()
942 regdom->alpha2[0] = country->alpha2[0]; in regdb_query_country()
943 regdom->alpha2[1] = country->alpha2[1]; in regdb_query_country()
944 regdom->dfs_region = coll->dfs_region; in regdb_query_country()
946 for (i = 0; i < regdom->n_reg_rules; i++) { in regdb_query_country()
947 __be16 *rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2)); in regdb_query_country()
950 struct ieee80211_reg_rule *rrule = &regdom->reg_rules[i]; in regdb_query_country()
952 rrule->freq_range.start_freq_khz = be32_to_cpu(rule->start); in regdb_query_country()
953 rrule->freq_range.end_freq_khz = be32_to_cpu(rule->end); in regdb_query_country()
954 rrule->freq_range.max_bandwidth_khz = be32_to_cpu(rule->max_bw); in regdb_query_country()
956 rrule->power_rule.max_antenna_gain = 0; in regdb_query_country()
957 rrule->power_rule.max_eirp = be16_to_cpu(rule->max_eirp); in regdb_query_country()
959 rrule->flags = 0; in regdb_query_country()
960 if (rule->flags & FWDB_FLAG_NO_OFDM) in regdb_query_country()
961 rrule->flags |= NL80211_RRF_NO_OFDM; in regdb_query_country()
962 if (rule->flags & FWDB_FLAG_NO_OUTDOOR) in regdb_query_country()
963 rrule->flags |= NL80211_RRF_NO_OUTDOOR; in regdb_query_country()
964 if (rule->flags & FWDB_FLAG_DFS) in regdb_query_country()
965 rrule->flags |= NL80211_RRF_DFS; in regdb_query_country()
966 if (rule->flags & FWDB_FLAG_NO_IR) in regdb_query_country()
967 rrule->flags |= NL80211_RRF_NO_IR; in regdb_query_country()
968 if (rule->flags & FWDB_FLAG_AUTO_BW) in regdb_query_country()
969 rrule->flags |= NL80211_RRF_AUTO_BW; in regdb_query_country()
971 rrule->dfs_cac_ms = 0; in regdb_query_country()
974 if (rule->len >= offsetofend(struct fwdb_rule, cac_timeout)) in regdb_query_country()
975 rrule->dfs_cac_ms = in regdb_query_country()
976 1000 * be16_to_cpu(rule->cac_timeout); in regdb_query_country()
977 if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) in regdb_query_country()
994 country = &hdr->country[0]; in query_regdb()
995 while (country->coll_ptr) { in query_regdb()
996 if (alpha2_equal(alpha2, country->alpha2)) in query_regdb()
1001 return -ENODATA; in query_regdb()
1012 set_error = -ENODATA; in regdb_fw_cb()
1013 } else if (!valid_regdb(fw->data, fw->size)) { in regdb_fw_cb()
1015 set_error = -EINVAL; in regdb_fw_cb()
1020 /* negative case - a bug in regdb_fw_cb()
1021 * positive case - can happen due to race in case of multiple cb's in in regdb_fw_cb()
1029 db = kmemdup(fw->data, fw->size, GFP_KERNEL); in regdb_fw_cb()
1061 return -ENOMEM; in query_regdb_file()
1064 &reg_pdev->dev, GFP_KERNEL, in query_regdb_file()
1080 err = request_firmware(&fw, "regulatory.db", &reg_pdev->dev); in reg_reload_regdb()
1084 if (!valid_regdb(fw->data, fw->size)) { in reg_reload_regdb()
1085 err = -ENODATA; in reg_reload_regdb()
1089 db = kmemdup(fw->data, fw->size, GFP_KERNEL); in reg_reload_regdb()
1091 err = -ENOMEM; in reg_reload_regdb()
1100 /* reset regulatory domain */ in reg_reload_regdb()
1105 err = -ENOMEM; in reg_reload_regdb()
1109 request->wiphy_idx = WIPHY_IDX_INVALID; in reg_reload_regdb()
1110 request->alpha2[0] = current_regdomain->alpha2[0]; in reg_reload_regdb()
1111 request->alpha2[1] = current_regdomain->alpha2[1]; in reg_reload_regdb()
1112 request->initiator = NL80211_REGDOM_SET_BY_CORE; in reg_reload_regdb()
1113 request->user_reg_hint_type = NL80211_USER_REG_HINT_USER; in reg_reload_regdb()
1126 if (query_regdb_file(request->alpha2) == 0) in reg_query_database()
1129 if (call_crda(request->alpha2) == 0) in reg_query_database()
1139 if (!lr || lr->processed) in reg_is_valid_request()
1142 return alpha2_equal(lr->alpha2, alpha2); in reg_is_valid_request()
1150 * Follow the driver's regulatory domain, if present, unless a country in reg_get_regdomain()
1153 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && in reg_get_regdomain()
1154 lr->initiator != NL80211_REGDOM_SET_BY_USER && in reg_get_regdomain()
1155 wiphy->regd) in reg_get_regdomain()
1165 const struct ieee80211_freq_range *freq_range = &rule->freq_range; in reg_get_max_bandwidth_from_range()
1170 for (idx = 0; idx < rd->n_reg_rules; idx++) in reg_get_max_bandwidth_from_range()
1171 if (rule == &rd->reg_rules[idx]) in reg_get_max_bandwidth_from_range()
1174 if (idx == rd->n_reg_rules) in reg_get_max_bandwidth_from_range()
1181 tmp = &rd->reg_rules[--no]; in reg_get_max_bandwidth_from_range()
1182 freq_range_tmp = &tmp->freq_range; in reg_get_max_bandwidth_from_range()
1184 if (freq_range_tmp->end_freq_khz < freq_range->start_freq_khz) in reg_get_max_bandwidth_from_range()
1190 start_freq = freq_range->start_freq_khz; in reg_get_max_bandwidth_from_range()
1193 freq_range = &rule->freq_range; in reg_get_max_bandwidth_from_range()
1196 while (no < rd->n_reg_rules - 1) { in reg_get_max_bandwidth_from_range()
1197 tmp = &rd->reg_rules[++no]; in reg_get_max_bandwidth_from_range()
1198 freq_range_tmp = &tmp->freq_range; in reg_get_max_bandwidth_from_range()
1200 if (freq_range_tmp->start_freq_khz > freq_range->end_freq_khz) in reg_get_max_bandwidth_from_range()
1206 end_freq = freq_range->end_freq_khz; in reg_get_max_bandwidth_from_range()
1208 return end_freq - start_freq; in reg_get_max_bandwidth_from_range()
1216 if (rule->flags & NL80211_RRF_NO_320MHZ) in reg_get_max_bandwidth()
1218 if (rule->flags & NL80211_RRF_NO_160MHZ) in reg_get_max_bandwidth()
1220 if (rule->flags & NL80211_RRF_NO_80MHZ) in reg_get_max_bandwidth()
1224 * HT40+/HT40- limits are handled per-channel. Only limit BW if both in reg_get_max_bandwidth()
1227 if (rule->flags & NL80211_RRF_NO_HT40MINUS && in reg_get_max_bandwidth()
1228 rule->flags & NL80211_RRF_NO_HT40PLUS) in reg_get_max_bandwidth()
1237 const struct ieee80211_freq_range *freq_range = &rule->freq_range; in is_valid_reg_rule()
1240 if (freq_range->start_freq_khz <= 0 || freq_range->end_freq_khz <= 0) in is_valid_reg_rule()
1243 if (freq_range->start_freq_khz > freq_range->end_freq_khz) in is_valid_reg_rule()
1246 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; in is_valid_reg_rule()
1248 if (freq_range->end_freq_khz <= freq_range->start_freq_khz || in is_valid_reg_rule()
1249 freq_range->max_bandwidth_khz > freq_diff) in is_valid_reg_rule()
1260 if (!rd->n_reg_rules) in is_valid_rd()
1263 if (WARN_ON(rd->n_reg_rules > NL80211_MAX_SUPP_REG_RULES)) in is_valid_rd()
1266 for (i = 0; i < rd->n_reg_rules; i++) { in is_valid_rd()
1267 reg_rule = &rd->reg_rules[i]; in is_valid_rd()
1276 * freq_in_rule_band - tells us if a frequency is in a frequency band
1284 * part of a frequency's band if the start freq or end freq are off by more
1296 * From 802.11ad: directional multi-gigabit (DMG): in freq_in_rule_band()
1301 if (abs(freq_khz - freq_range->start_freq_khz) <= limit) in freq_in_rule_band()
1303 if (abs(freq_khz - freq_range->end_freq_khz) <= limit) in freq_in_rule_band()
1326 intersect->cw_min = max_t(u16, wmm_ac1->cw_min, wmm_ac2->cw_min); in reg_wmm_rules_intersect()
1327 intersect->cw_max = max_t(u16, wmm_ac1->cw_max, wmm_ac2->cw_max); in reg_wmm_rules_intersect()
1328 intersect->cot = min_t(u16, wmm_ac1->cot, wmm_ac2->cot); in reg_wmm_rules_intersect()
1329 intersect->aifsn = max_t(u8, wmm_ac1->aifsn, wmm_ac2->aifsn); in reg_wmm_rules_intersect()
1350 freq_range1 = &rule1->freq_range; in reg_rules_intersect()
1351 freq_range2 = &rule2->freq_range; in reg_rules_intersect()
1352 freq_range = &intersected_rule->freq_range; in reg_rules_intersect()
1354 power_rule1 = &rule1->power_rule; in reg_rules_intersect()
1355 power_rule2 = &rule2->power_rule; in reg_rules_intersect()
1356 power_rule = &intersected_rule->power_rule; in reg_rules_intersect()
1358 wmm_rule1 = &rule1->wmm_rule; in reg_rules_intersect()
1359 wmm_rule2 = &rule2->wmm_rule; in reg_rules_intersect()
1360 wmm_rule = &intersected_rule->wmm_rule; in reg_rules_intersect()
1362 freq_range->start_freq_khz = max(freq_range1->start_freq_khz, in reg_rules_intersect()
1363 freq_range2->start_freq_khz); in reg_rules_intersect()
1364 freq_range->end_freq_khz = min(freq_range1->end_freq_khz, in reg_rules_intersect()
1365 freq_range2->end_freq_khz); in reg_rules_intersect()
1367 max_bandwidth1 = freq_range1->max_bandwidth_khz; in reg_rules_intersect()
1368 max_bandwidth2 = freq_range2->max_bandwidth_khz; in reg_rules_intersect()
1370 if (rule1->flags & NL80211_RRF_AUTO_BW) in reg_rules_intersect()
1372 if (rule2->flags & NL80211_RRF_AUTO_BW) in reg_rules_intersect()
1375 freq_range->max_bandwidth_khz = min(max_bandwidth1, max_bandwidth2); in reg_rules_intersect()
1377 intersected_rule->flags = rule1->flags | rule2->flags; in reg_rules_intersect()
1387 if ((rule1->flags & NL80211_RRF_AUTO_BW) && in reg_rules_intersect()
1388 (rule2->flags & NL80211_RRF_AUTO_BW)) in reg_rules_intersect()
1389 intersected_rule->flags |= NL80211_RRF_AUTO_BW; in reg_rules_intersect()
1391 intersected_rule->flags &= ~NL80211_RRF_AUTO_BW; in reg_rules_intersect()
1393 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz; in reg_rules_intersect()
1394 if (freq_range->max_bandwidth_khz > freq_diff) in reg_rules_intersect()
1395 freq_range->max_bandwidth_khz = freq_diff; in reg_rules_intersect()
1397 power_rule->max_eirp = min(power_rule1->max_eirp, in reg_rules_intersect()
1398 power_rule2->max_eirp); in reg_rules_intersect()
1399 power_rule->max_antenna_gain = min(power_rule1->max_antenna_gain, in reg_rules_intersect()
1400 power_rule2->max_antenna_gain); in reg_rules_intersect()
1402 intersected_rule->dfs_cac_ms = max(rule1->dfs_cac_ms, in reg_rules_intersect()
1403 rule2->dfs_cac_ms); in reg_rules_intersect()
1405 if (rule1->has_wmm && rule2->has_wmm) { in reg_rules_intersect()
1409 reg_wmm_rules_intersect(&wmm_rule1->client[ac], in reg_rules_intersect()
1410 &wmm_rule2->client[ac], in reg_rules_intersect()
1411 &wmm_rule->client[ac]); in reg_rules_intersect()
1412 reg_wmm_rules_intersect(&wmm_rule1->ap[ac], in reg_rules_intersect()
1413 &wmm_rule2->ap[ac], in reg_rules_intersect()
1414 &wmm_rule->ap[ac]); in reg_rules_intersect()
1417 intersected_rule->has_wmm = true; in reg_rules_intersect()
1418 } else if (rule1->has_wmm) { in reg_rules_intersect()
1420 intersected_rule->has_wmm = true; in reg_rules_intersect()
1421 } else if (rule2->has_wmm) { in reg_rules_intersect()
1423 intersected_rule->has_wmm = true; in reg_rules_intersect()
1425 intersected_rule->has_wmm = false; in reg_rules_intersect()
1429 return -EINVAL; in reg_rules_intersect()
1439 if (r1->flags != r2->flags) in rule_contains()
1443 if ((r1->power_rule.max_antenna_gain > in rule_contains()
1444 r2->power_rule.max_antenna_gain) || in rule_contains()
1445 r1->power_rule.max_eirp > r2->power_rule.max_eirp) in rule_contains()
1449 if (r1->freq_range.start_freq_khz > r2->freq_range.start_freq_khz || in rule_contains()
1450 r1->freq_range.end_freq_khz < r2->freq_range.end_freq_khz) in rule_contains()
1454 if (r1->freq_range.max_bandwidth_khz < in rule_contains()
1455 r2->freq_range.max_bandwidth_khz) in rule_contains()
1470 /* rule is already contained - do nothing */ in add_rule()
1486 * regdom_intersect - do the intersection between two regulatory domains
1487 * @rd1: first regulatory domain
1488 * @rd2: second regulatory domain
1492 * as no one single alpha2 can represent this regulatory domain.
1494 * Returns a pointer to the regulatory domain structure which will hold the
1518 * is it will return -EINVAL if the rule computed makes no sense. in regdom_intersect()
1522 for (x = 0; x < rd1->n_reg_rules; x++) { in regdom_intersect()
1523 rule1 = &rd1->reg_rules[x]; in regdom_intersect()
1524 for (y = 0; y < rd2->n_reg_rules; y++) { in regdom_intersect()
1525 rule2 = &rd2->reg_rules[y]; in regdom_intersect()
1539 for (x = 0; x < rd1->n_reg_rules; x++) { in regdom_intersect()
1540 rule1 = &rd1->reg_rules[x]; in regdom_intersect()
1541 for (y = 0; y < rd2->n_reg_rules; y++) { in regdom_intersect()
1542 rule2 = &rd2->reg_rules[y]; in regdom_intersect()
1552 add_rule(&intersected_rule, rd->reg_rules, in regdom_intersect()
1553 &rd->n_reg_rules); in regdom_intersect()
1557 rd->alpha2[0] = '9'; in regdom_intersect()
1558 rd->alpha2[1] = '8'; in regdom_intersect()
1559 rd->dfs_region = reg_intersect_dfs_region(rd1->dfs_region, in regdom_intersect()
1560 rd2->dfs_region); in regdom_intersect()
1618 return ERR_PTR(-EINVAL); in freq_reg_info_regd()
1620 for (i = 0; i < regd->n_reg_rules; i++) { in freq_reg_info_regd()
1624 rr = &regd->reg_rules[i]; in freq_reg_info_regd()
1625 fr = &rr->freq_range; in freq_reg_info_regd()
1642 return ERR_PTR(-ERANGE); in freq_reg_info_regd()
1644 return ERR_PTR(-EINVAL); in freq_reg_info_regd()
1652 const struct ieee80211_reg_rule *reg_rule = ERR_PTR(-ERANGE); in __freq_reg_info()
1653 int i = ARRAY_SIZE(bws) - 1; in __freq_reg_info()
1656 for (bw = MHZ_TO_KHZ(bws[i]); bw >= min_bw; bw = MHZ_TO_KHZ(bws[i--])) { in __freq_reg_info()
1698 bool is_s1g = chan->band == NL80211_BAND_S1GHZ; in reg_rule_to_chan_bw_flags()
1700 freq_range = &reg_rule->freq_range; in reg_rule_to_chan_bw_flags()
1702 max_bandwidth_khz = freq_range->max_bandwidth_khz; in reg_rule_to_chan_bw_flags()
1705 if (reg_rule->flags & NL80211_RRF_AUTO_BW) in reg_rule_to_chan_bw_flags()
1727 edge_offset = (center_freq_khz - ch_bw / 2) - in reg_rule_to_chan_bw_flags()
1728 freq_range->start_freq_khz; in reg_rule_to_chan_bw_flags()
1788 power_rule = &reg_rule->power_rule; in handle_channel_single_rule()
1791 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in handle_channel_single_rule()
1793 request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in handle_channel_single_rule()
1795 * This guarantees the driver's requested regulatory domain in handle_channel_single_rule()
1799 chan->flags = chan->orig_flags = in handle_channel_single_rule()
1800 map_regdom_flags(reg_rule->flags) | bw_flags; in handle_channel_single_rule()
1801 chan->max_antenna_gain = chan->orig_mag = in handle_channel_single_rule()
1802 (int) MBI_TO_DBI(power_rule->max_antenna_gain); in handle_channel_single_rule()
1803 chan->max_reg_power = chan->max_power = chan->orig_mpwr = in handle_channel_single_rule()
1804 (int) MBM_TO_DBM(power_rule->max_eirp); in handle_channel_single_rule()
1806 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_single_rule()
1807 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_single_rule()
1808 if (reg_rule->dfs_cac_ms) in handle_channel_single_rule()
1809 chan->dfs_cac_ms = reg_rule->dfs_cac_ms; in handle_channel_single_rule()
1812 if (chan->flags & IEEE80211_CHAN_PSD) in handle_channel_single_rule()
1813 chan->psd = reg_rule->psd; in handle_channel_single_rule()
1818 chan->dfs_state = NL80211_DFS_USABLE; in handle_channel_single_rule()
1819 chan->dfs_state_entered = jiffies; in handle_channel_single_rule()
1821 chan->beacon_found = false; in handle_channel_single_rule()
1822 chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags); in handle_channel_single_rule()
1823 chan->max_antenna_gain = in handle_channel_single_rule()
1824 min_t(int, chan->orig_mag, in handle_channel_single_rule()
1825 MBI_TO_DBI(power_rule->max_antenna_gain)); in handle_channel_single_rule()
1826 chan->max_reg_power = (int) MBM_TO_DBM(power_rule->max_eirp); in handle_channel_single_rule()
1828 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_single_rule()
1829 if (reg_rule->dfs_cac_ms) in handle_channel_single_rule()
1830 chan->dfs_cac_ms = reg_rule->dfs_cac_ms; in handle_channel_single_rule()
1832 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_single_rule()
1835 if (chan->flags & IEEE80211_CHAN_PSD) in handle_channel_single_rule()
1836 chan->psd = reg_rule->psd; in handle_channel_single_rule()
1838 if (chan->orig_mpwr) { in handle_channel_single_rule()
1844 wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_FOLLOW_POWER) in handle_channel_single_rule()
1845 chan->max_power = chan->max_reg_power; in handle_channel_single_rule()
1847 chan->max_power = min(chan->orig_mpwr, in handle_channel_single_rule()
1848 chan->max_reg_power); in handle_channel_single_rule()
1850 chan->max_power = chan->max_reg_power; in handle_channel_single_rule()
1871 power_rule1 = &rrule1->power_rule; in handle_channel_adjacent_rules()
1872 power_rule2 = &rrule2->power_rule; in handle_channel_adjacent_rules()
1876 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in handle_channel_adjacent_rules()
1878 request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in handle_channel_adjacent_rules()
1879 /* This guarantees the driver's requested regulatory domain in handle_channel_adjacent_rules()
1883 chan->flags = in handle_channel_adjacent_rules()
1884 map_regdom_flags(rrule1->flags) | in handle_channel_adjacent_rules()
1885 map_regdom_flags(rrule2->flags) | in handle_channel_adjacent_rules()
1888 chan->orig_flags = chan->flags; in handle_channel_adjacent_rules()
1889 chan->max_antenna_gain = in handle_channel_adjacent_rules()
1890 min_t(int, MBI_TO_DBI(power_rule1->max_antenna_gain), in handle_channel_adjacent_rules()
1891 MBI_TO_DBI(power_rule2->max_antenna_gain)); in handle_channel_adjacent_rules()
1892 chan->orig_mag = chan->max_antenna_gain; in handle_channel_adjacent_rules()
1893 chan->max_reg_power = in handle_channel_adjacent_rules()
1894 min_t(int, MBM_TO_DBM(power_rule1->max_eirp), in handle_channel_adjacent_rules()
1895 MBM_TO_DBM(power_rule2->max_eirp)); in handle_channel_adjacent_rules()
1896 chan->max_power = chan->max_reg_power; in handle_channel_adjacent_rules()
1897 chan->orig_mpwr = chan->max_reg_power; in handle_channel_adjacent_rules()
1899 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_adjacent_rules()
1900 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_adjacent_rules()
1901 if (rrule1->dfs_cac_ms || rrule2->dfs_cac_ms) in handle_channel_adjacent_rules()
1902 chan->dfs_cac_ms = max_t(unsigned int, in handle_channel_adjacent_rules()
1903 rrule1->dfs_cac_ms, in handle_channel_adjacent_rules()
1904 rrule2->dfs_cac_ms); in handle_channel_adjacent_rules()
1907 if ((rrule1->flags & NL80211_RRF_PSD) && in handle_channel_adjacent_rules()
1908 (rrule2->flags & NL80211_RRF_PSD)) in handle_channel_adjacent_rules()
1909 chan->psd = min_t(s8, rrule1->psd, rrule2->psd); in handle_channel_adjacent_rules()
1911 chan->flags &= ~NL80211_RRF_PSD; in handle_channel_adjacent_rules()
1916 chan->dfs_state = NL80211_DFS_USABLE; in handle_channel_adjacent_rules()
1917 chan->dfs_state_entered = jiffies; in handle_channel_adjacent_rules()
1919 chan->beacon_found = false; in handle_channel_adjacent_rules()
1920 chan->flags = flags | bw_flags1 | bw_flags2 | in handle_channel_adjacent_rules()
1921 map_regdom_flags(rrule1->flags) | in handle_channel_adjacent_rules()
1922 map_regdom_flags(rrule2->flags); in handle_channel_adjacent_rules()
1930 chan->flags &= ~IEEE80211_CHAN_NO_10MHZ; in handle_channel_adjacent_rules()
1934 chan->flags &= ~IEEE80211_CHAN_NO_20MHZ; in handle_channel_adjacent_rules()
1936 chan->max_antenna_gain = in handle_channel_adjacent_rules()
1937 min_t(int, chan->orig_mag, in handle_channel_adjacent_rules()
1939 MBI_TO_DBI(power_rule1->max_antenna_gain), in handle_channel_adjacent_rules()
1940 MBI_TO_DBI(power_rule2->max_antenna_gain))); in handle_channel_adjacent_rules()
1941 chan->max_reg_power = min_t(int, in handle_channel_adjacent_rules()
1942 MBM_TO_DBM(power_rule1->max_eirp), in handle_channel_adjacent_rules()
1943 MBM_TO_DBM(power_rule2->max_eirp)); in handle_channel_adjacent_rules()
1945 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_adjacent_rules()
1946 if (rrule1->dfs_cac_ms || rrule2->dfs_cac_ms) in handle_channel_adjacent_rules()
1947 chan->dfs_cac_ms = max_t(unsigned int, in handle_channel_adjacent_rules()
1948 rrule1->dfs_cac_ms, in handle_channel_adjacent_rules()
1949 rrule2->dfs_cac_ms); in handle_channel_adjacent_rules()
1951 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_adjacent_rules()
1954 if (chan->orig_mpwr) { in handle_channel_adjacent_rules()
1959 wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_FOLLOW_POWER) in handle_channel_adjacent_rules()
1960 chan->max_power = chan->max_reg_power; in handle_channel_adjacent_rules()
1962 chan->max_power = min(chan->orig_mpwr, in handle_channel_adjacent_rules()
1963 chan->max_reg_power); in handle_channel_adjacent_rules()
1965 chan->max_power = chan->max_reg_power; in handle_channel_adjacent_rules()
1979 struct wiphy *request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); in handle_channel()
1984 u32 flags = chan->orig_flags; in handle_channel()
1989 * chan - 20 MHz and chan + 20 MHz and test in handle_channel()
1993 orig_chan_freq - MHZ_TO_KHZ(20)); in handle_channel()
1999 if (rrule1->freq_range.end_freq_khz != in handle_channel()
2000 rrule2->freq_range.start_freq_khz) in handle_channel()
2004 rrule1->freq_range.start_freq_khz; in handle_channel()
2006 rrule2->freq_range.end_freq_khz; in handle_channel()
2009 rrule1->freq_range.max_bandwidth_khz, in handle_channel()
2010 rrule2->freq_range.max_bandwidth_khz); in handle_channel()
2035 PTR_ERR(rrule) == -ERANGE) in handle_channel()
2038 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in handle_channel()
2040 request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in handle_channel()
2041 pr_debug("Disabling freq %d.%03d MHz for good\n", in handle_channel()
2042 chan->center_freq, chan->freq_offset); in handle_channel()
2043 chan->orig_flags |= IEEE80211_CHAN_DISABLED; in handle_channel()
2044 chan->flags = chan->orig_flags; in handle_channel()
2046 pr_debug("Disabling freq %d.%03d MHz\n", in handle_channel()
2047 chan->center_freq, chan->freq_offset); in handle_channel()
2048 chan->flags |= IEEE80211_CHAN_DISABLED; in handle_channel()
2066 for (i = 0; i < sband->n_channels; i++) in handle_band()
2067 handle_channel(wiphy, initiator, &sband->channels[i]); in handle_band()
2072 if (request->initiator != NL80211_REGDOM_SET_BY_USER) in reg_request_cell_base()
2074 return request->user_reg_hint_type == NL80211_USER_REG_HINT_CELL_BASE; in reg_request_cell_base()
2093 !regdom_changes(pending_request->alpha2)) in reg_ignore_cell_hint()
2102 return !(wiphy->features & NL80211_FEATURE_CELL_BASE_REG_HINTS); in reg_dev_ignore_cell_hint()
2119 if (wiphy->regulatory_flags & REGULATORY_STRICT_REG && in wiphy_strict_alpha2_regd()
2120 !(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG)) in wiphy_strict_alpha2_regd()
2130 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) in ignore_reg_update()
2140 wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) { in ignore_reg_update()
2141 …g("Ignoring regulatory request set by %s since the driver uses its own custom regulatory domain\n", in ignore_reg_update()
2147 * wiphy->regd will be set once the device has its own in ignore_reg_update()
2148 * desired regulatory domain set in ignore_reg_update()
2150 if (wiphy_strict_alpha2_regd(wiphy) && !wiphy->regd && in ignore_reg_update()
2152 !is_world_regdom(lr->alpha2)) { in ignore_reg_update()
2153 …egulatory request set by %s since the driver requires its own regulatory domain to be set first\n", in ignore_reg_update()
2170 if (is_world_regdom(cr->alpha2) || (wr && is_world_regdom(wr->alpha2))) in reg_is_world_roaming()
2173 if (lr && lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE && in reg_is_world_roaming()
2174 wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) in reg_is_world_roaming()
2183 if (wiphy->reg_notifier) in reg_call_notifier()
2184 wiphy->reg_notifier(wiphy, request); in reg_call_notifier()
2196 sband = wiphy->bands[reg_beacon->chan.band]; in handle_reg_beacon()
2197 chan = &sband->channels[chan_idx]; in handle_reg_beacon()
2199 if (likely(!ieee80211_channel_equal(chan, &reg_beacon->chan))) in handle_reg_beacon()
2202 if (chan->beacon_found) in handle_reg_beacon()
2205 chan->beacon_found = true; in handle_reg_beacon()
2210 if (wiphy->regulatory_flags & REGULATORY_DISABLE_BEACON_HINTS) in handle_reg_beacon()
2215 if (chan->flags & IEEE80211_CHAN_NO_IR) { in handle_reg_beacon()
2216 chan->flags &= ~IEEE80211_CHAN_NO_IR; in handle_reg_beacon()
2222 if (wiphy->flags & WIPHY_FLAG_CHANNEL_CHANGE_ON_BEACON) in handle_reg_beacon()
2237 if (!wiphy->bands[reg_beacon->chan.band]) in wiphy_update_new_beacon()
2240 sband = wiphy->bands[reg_beacon->chan.band]; in wiphy_update_new_beacon()
2242 for (i = 0; i < sband->n_channels; i++) in wiphy_update_new_beacon()
2256 if (!wiphy->bands[reg_beacon->chan.band]) in wiphy_update_beacon_reg()
2258 sband = wiphy->bands[reg_beacon->chan.band]; in wiphy_update_beacon_reg()
2259 for (i = 0; i < sband->n_channels; i++) in wiphy_update_beacon_reg()
2280 if (chan->flags & IEEE80211_CHAN_DISABLED) in is_ht40_allowed()
2283 if ((chan->flags & IEEE80211_CHAN_NO_HT40) == IEEE80211_CHAN_NO_HT40) in is_ht40_allowed()
2291 struct ieee80211_supported_band *sband = wiphy->bands[channel->band]; in reg_process_ht_flags_channel()
2298 channel->flags |= IEEE80211_CHAN_NO_HT40; in reg_process_ht_flags_channel()
2304 * be able to use HT40- or HT40+, this finds them (or not) in reg_process_ht_flags_channel()
2306 for (i = 0; i < sband->n_channels; i++) { in reg_process_ht_flags_channel()
2307 struct ieee80211_channel *c = &sband->channels[i]; in reg_process_ht_flags_channel()
2309 if (c->center_freq == (channel->center_freq - 20)) in reg_process_ht_flags_channel()
2311 if (c->center_freq == (channel->center_freq + 20)) in reg_process_ht_flags_channel()
2319 freq_reg_info_regd(MHZ_TO_KHZ(channel->center_freq), in reg_process_ht_flags_channel()
2323 flags = reg_rule->flags; in reg_process_ht_flags_channel()
2333 channel->flags |= IEEE80211_CHAN_NO_HT40MINUS; in reg_process_ht_flags_channel()
2335 channel->flags &= ~IEEE80211_CHAN_NO_HT40MINUS; in reg_process_ht_flags_channel()
2339 channel->flags |= IEEE80211_CHAN_NO_HT40PLUS; in reg_process_ht_flags_channel()
2341 channel->flags &= ~IEEE80211_CHAN_NO_HT40PLUS; in reg_process_ht_flags_channel()
2352 for (i = 0; i < sband->n_channels; i++) in reg_process_ht_flags_band()
2353 reg_process_ht_flags_channel(wiphy, &sband->channels[i]); in reg_process_ht_flags_band()
2364 reg_process_ht_flags_band(wiphy, wiphy->bands[band]); in reg_process_ht_flags()
2375 iftype = wdev->iftype; in reg_wdev_chan_valid()
2378 if (!wdev->netdev || !netif_running(wdev->netdev)) in reg_wdev_chan_valid()
2381 for (link = 0; link < ARRAY_SIZE(wdev->links); link++) { in reg_wdev_chan_valid()
2384 if (!wdev->valid_links && link > 0) in reg_wdev_chan_valid()
2386 if (wdev->valid_links && !(wdev->valid_links & BIT(link))) in reg_wdev_chan_valid()
2391 if (!wdev->links[link].ap.beacon_interval) in reg_wdev_chan_valid()
2393 chandef = wdev->links[link].ap.chandef; in reg_wdev_chan_valid()
2396 if (!wdev->u.mesh.beacon_interval) in reg_wdev_chan_valid()
2398 chandef = wdev->u.mesh.chandef; in reg_wdev_chan_valid()
2401 if (!wdev->u.ibss.ssid_len) in reg_wdev_chan_valid()
2403 chandef = wdev->u.ibss.chandef; in reg_wdev_chan_valid()
2408 if (!wdev->links[link].client.current_bss) in reg_wdev_chan_valid()
2411 chan = wdev->links[link].client.current_bss->pub.channel; in reg_wdev_chan_valid()
2415 if (!rdev->ops->get_channel || in reg_wdev_chan_valid()
2426 if (!wdev->u.ocb.chandef.chan) in reg_wdev_chan_valid()
2428 chandef = wdev->u.ocb.chandef; in reg_wdev_chan_valid()
2471 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) in reg_leave_invalid_chans()
2484 reg_leave_invalid_chans(&rdev->wiphy); in reg_check_chans_work()
2510 * as some drivers used this to restore its orig_* reg domain. in wiphy_update_regulatory()
2513 wiphy->regulatory_flags & REGULATORY_CUSTOM_REG && in wiphy_update_regulatory()
2514 !(wiphy->regulatory_flags & in wiphy_update_regulatory()
2520 lr->dfs_region = get_cfg80211_regdom()->dfs_region; in wiphy_update_regulatory()
2523 handle_band(wiphy, initiator, wiphy->bands[band]); in wiphy_update_regulatory()
2538 wiphy = &rdev->wiphy; in update_all_wiphy_regulatory()
2563 pr_debug("Disabling freq %d.%03d MHz as custom regd has no rule that fits it\n", in handle_channel_custom()
2564 chan->center_freq, chan->freq_offset); in handle_channel_custom()
2565 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { in handle_channel_custom()
2566 chan->flags |= IEEE80211_CHAN_DISABLED; in handle_channel_custom()
2568 chan->orig_flags |= IEEE80211_CHAN_DISABLED; in handle_channel_custom()
2569 chan->flags = chan->orig_flags; in handle_channel_custom()
2574 power_rule = &reg_rule->power_rule; in handle_channel_custom()
2577 chan->dfs_state_entered = jiffies; in handle_channel_custom()
2578 chan->dfs_state = NL80211_DFS_USABLE; in handle_channel_custom()
2580 chan->beacon_found = false; in handle_channel_custom()
2582 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) in handle_channel_custom()
2583 chan->flags = chan->orig_flags | bw_flags | in handle_channel_custom()
2584 map_regdom_flags(reg_rule->flags); in handle_channel_custom()
2586 chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags; in handle_channel_custom()
2588 chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain); in handle_channel_custom()
2589 chan->max_reg_power = chan->max_power = in handle_channel_custom()
2590 (int) MBM_TO_DBM(power_rule->max_eirp); in handle_channel_custom()
2592 if (chan->flags & IEEE80211_CHAN_RADAR) { in handle_channel_custom()
2593 if (reg_rule->dfs_cac_ms) in handle_channel_custom()
2594 chan->dfs_cac_ms = reg_rule->dfs_cac_ms; in handle_channel_custom()
2596 chan->dfs_cac_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; in handle_channel_custom()
2599 if (chan->flags & IEEE80211_CHAN_PSD) in handle_channel_custom()
2600 chan->psd = reg_rule->psd; in handle_channel_custom()
2602 chan->max_power = chan->max_reg_power; in handle_channel_custom()
2617 * compatible to US, which permits 2402 - 2472 MHz. in handle_band_custom()
2619 for (i = 0; i < sband->n_channels; i++) in handle_band_custom()
2620 handle_channel_custom(wiphy, &sband->channels[i], regd, in handle_band_custom()
2632 WARN(!(wiphy->regulatory_flags & REGULATORY_CUSTOM_REG), in wiphy_apply_custom_regulatory()
2634 wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; in wiphy_apply_custom_regulatory()
2637 if (!wiphy->bands[band]) in wiphy_apply_custom_regulatory()
2639 handle_band_custom(wiphy, wiphy->bands[band], regd); in wiphy_apply_custom_regulatory()
2655 rcu_assign_pointer(wiphy->regd, new_regd); in wiphy_apply_custom_regulatory()
2667 lr->processed = true; in reg_set_request_processed()
2681 * reg_process_hint_core - process core regulatory requests
2694 core_request->intersect = false; in reg_process_hint_core()
2695 core_request->processed = false; in reg_process_hint_core()
2714 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) in __reg_process_hint_user()
2720 if (lr->initiator == NL80211_REGDOM_SET_BY_USER && in __reg_process_hint_user()
2721 lr->intersect) in __reg_process_hint_user()
2727 if ((lr->initiator == NL80211_REGDOM_SET_BY_CORE || in __reg_process_hint_user()
2728 lr->initiator == NL80211_REGDOM_SET_BY_DRIVER || in __reg_process_hint_user()
2729 lr->initiator == NL80211_REGDOM_SET_BY_USER) && in __reg_process_hint_user()
2730 regdom_changes(lr->alpha2)) in __reg_process_hint_user()
2733 if (!regdom_changes(user_request->alpha2)) in __reg_process_hint_user()
2740 * reg_process_hint_user - process user regulatory requests
2759 user_request->intersect = treatment == REG_REQ_INTERSECT; in reg_process_hint_user()
2760 user_request->processed = false; in reg_process_hint_user()
2764 user_alpha2[0] = user_request->alpha2[0]; in reg_process_hint_user()
2765 user_alpha2[1] = user_request->alpha2[1]; in reg_process_hint_user()
2777 if (lr->initiator == NL80211_REGDOM_SET_BY_CORE) { in __reg_process_hint_driver()
2778 if (regdom_changes(driver_request->alpha2)) in __reg_process_hint_driver()
2786 * loaded card also agrees on the regulatory domain. in __reg_process_hint_driver()
2788 if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && in __reg_process_hint_driver()
2789 !regdom_changes(driver_request->alpha2)) in __reg_process_hint_driver()
2796 * reg_process_hint_driver - process driver regulatory requests
2828 rcu_assign_pointer(wiphy->regd, regd); in reg_process_hint_driver()
2834 driver_request->intersect = treatment == REG_REQ_INTERSECT; in reg_process_hint_driver()
2835 driver_request->processed = false; in reg_process_hint_driver()
2839 * have applied the requested regulatory domain before we just in reg_process_hint_driver()
2866 if (regdom_changes(country_ie_request->alpha2)) in __reg_process_hint_country_ie()
2870 if (wiphy->regulatory_flags & REGULATORY_COUNTRY_IE_IGNORE) in __reg_process_hint_country_ie()
2874 if (unlikely(!is_an_alpha2(country_ie_request->alpha2))) in __reg_process_hint_country_ie()
2875 return -EINVAL; in __reg_process_hint_country_ie()
2877 if (lr->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE) in __reg_process_hint_country_ie()
2880 last_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); in __reg_process_hint_country_ie()
2889 if (regdom_changes(country_ie_request->alpha2)) in __reg_process_hint_country_ie()
2894 if (regdom_changes(country_ie_request->alpha2)) in __reg_process_hint_country_ie()
2900 * reg_process_hint_country_ie - process regulatory requests from country IEs
2934 country_ie_request->intersect = false; in reg_process_hint_country_ie()
2935 country_ie_request->processed = false; in reg_process_hint_country_ie()
2955 wiphy1_regd = rcu_dereference(wiphy1->regd); in reg_dfs_domain_same()
2959 wiphy2_regd = rcu_dereference(wiphy2->regd); in reg_dfs_domain_same()
2963 dfs_domain_same = wiphy1_regd->dfs_region == wiphy2_regd->dfs_region; in reg_dfs_domain_same()
2973 if (!(dst_chan->flags & IEEE80211_CHAN_RADAR) || in reg_copy_dfs_chan_state()
2974 !(src_chan->flags & IEEE80211_CHAN_RADAR)) in reg_copy_dfs_chan_state()
2977 if (dst_chan->flags & IEEE80211_CHAN_DISABLED || in reg_copy_dfs_chan_state()
2978 src_chan->flags & IEEE80211_CHAN_DISABLED) in reg_copy_dfs_chan_state()
2981 if (src_chan->center_freq == dst_chan->center_freq && in reg_copy_dfs_chan_state()
2982 dst_chan->dfs_state == NL80211_DFS_USABLE) { in reg_copy_dfs_chan_state()
2983 dst_chan->dfs_state = src_chan->dfs_state; in reg_copy_dfs_chan_state()
2984 dst_chan->dfs_state_entered = src_chan->dfs_state_entered; in reg_copy_dfs_chan_state()
2999 dst_sband = dst_wiphy->bands[band]; in wiphy_share_dfs_chan_state()
3000 src_sband = src_wiphy->bands[band]; in wiphy_share_dfs_chan_state()
3004 for (i = 0; i < dst_sband->n_channels; i++) { in wiphy_share_dfs_chan_state()
3005 dst_chan = &dst_sband->channels[i]; in wiphy_share_dfs_chan_state()
3006 for (j = 0; j < src_sband->n_channels; j++) { in wiphy_share_dfs_chan_state()
3007 src_chan = &src_sband->channels[j]; in wiphy_share_dfs_chan_state()
3021 if (wiphy == &rdev->wiphy) in wiphy_all_share_dfs_chan_state()
3023 wiphy_share_dfs_chan_state(wiphy, &rdev->wiphy); in wiphy_all_share_dfs_chan_state()
3032 enum nl80211_reg_initiator initiator = reg_request->initiator; in reg_process_hint()
3034 if (reg_request->wiphy_idx != WIPHY_IDX_INVALID) in reg_process_hint()
3035 wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx); in reg_process_hint()
3069 wiphy->regulatory_flags & REGULATORY_STRICT_REG) { in reg_process_hint()
3087 wiphy = &rdev->wiphy; in notify_self_managed_wiphys()
3088 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && in notify_self_managed_wiphys()
3089 request->initiator == NL80211_REGDOM_SET_BY_USER) in notify_self_managed_wiphys()
3105 /* When last_request->processed becomes true this will be rescheduled */ in reg_process_pending_hints()
3106 if (lr && !lr->processed) { in reg_process_pending_hints()
3121 list_del_init(&reg_request->list); in reg_process_pending_hints()
3132 if (!list_empty(&reg_requests_list) && lr && lr->processed) in reg_process_pending_hints()
3137 /* Processes beacon hints -- this has nothing to do with country IEs */
3148 list_del_init(&pending_beacon->list); in reg_process_pending_beacon_hints()
3152 wiphy_update_new_beacon(&rdev->wiphy, pending_beacon); in reg_process_pending_beacon_hints()
3155 list_add_tail(&pending_beacon->list, &reg_beacon_list); in reg_process_pending_beacon_hints()
3173 regd = rdev->requested_regd; in reg_process_self_managed_hint()
3174 rdev->requested_regd = NULL; in reg_process_self_managed_hint()
3181 rcu_assign_pointer(wiphy->regd, regd); in reg_process_self_managed_hint()
3185 handle_band_custom(wiphy, wiphy->bands[band], regd); in reg_process_self_managed_hint()
3190 request.alpha2[0] = regd->alpha2[0]; in reg_process_self_managed_hint()
3191 request.alpha2[1] = regd->alpha2[1]; in reg_process_self_managed_hint()
3194 if (wiphy->flags & WIPHY_FLAG_NOTIFY_REGDOM_BY_DRIVER) in reg_process_self_managed_hint()
3207 guard(wiphy)(&rdev->wiphy); in reg_process_self_managed_hints()
3209 reg_process_self_managed_hint(&rdev->wiphy); in reg_process_self_managed_hints()
3226 request->alpha2[0] = toupper(request->alpha2[0]); in queue_regulatory_request()
3227 request->alpha2[1] = toupper(request->alpha2[1]); in queue_regulatory_request()
3230 list_add_tail(&request->list, &reg_requests_list); in queue_regulatory_request()
3237 * Core regulatory hint -- happens during cfg80211_init()
3246 return -ENOMEM; in regulatory_hint_core()
3248 request->alpha2[0] = alpha2[0]; in regulatory_hint_core()
3249 request->alpha2[1] = alpha2[1]; in regulatory_hint_core()
3250 request->initiator = NL80211_REGDOM_SET_BY_CORE; in regulatory_hint_core()
3251 request->wiphy_idx = WIPHY_IDX_INVALID; in regulatory_hint_core()
3265 return -EINVAL; in regulatory_hint_user()
3268 return -EINVAL; in regulatory_hint_user()
3272 return -ENOMEM; in regulatory_hint_user()
3274 request->wiphy_idx = WIPHY_IDX_INVALID; in regulatory_hint_user()
3275 request->alpha2[0] = alpha2[0]; in regulatory_hint_user()
3276 request->alpha2[1] = alpha2[1]; in regulatory_hint_user()
3277 request->initiator = NL80211_REGDOM_SET_BY_USER; in regulatory_hint_user()
3278 request->user_reg_hint_type = user_reg_hint_type; in regulatory_hint_user()
3336 return -EINVAL; in regulatory_hint()
3338 wiphy->regulatory_flags &= ~REGULATORY_CUSTOM_REG; in regulatory_hint()
3342 return -ENOMEM; in regulatory_hint()
3344 request->wiphy_idx = get_wiphy_idx(wiphy); in regulatory_hint()
3346 request->alpha2[0] = alpha2[0]; in regulatory_hint()
3347 request->alpha2[1] = alpha2[1]; in regulatory_hint()
3348 request->initiator = NL80211_REGDOM_SET_BY_DRIVER; in regulatory_hint()
3396 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && in regulatory_hint_country_ie()
3397 lr->wiphy_idx != WIPHY_IDX_INVALID) in regulatory_hint_country_ie()
3400 request->wiphy_idx = get_wiphy_idx(wiphy); in regulatory_hint_country_ie()
3401 request->alpha2[0] = alpha2[0]; in regulatory_hint_country_ie()
3402 request->alpha2[1] = alpha2[1]; in regulatory_hint_country_ie()
3403 request->initiator = NL80211_REGDOM_SET_BY_COUNTRY_IE; in regulatory_hint_country_ie()
3404 request->country_ie_env = env; in regulatory_hint_country_ie()
3464 sband = wiphy->bands[band]; in restore_custom_reg_settings()
3467 for (i = 0; i < sband->n_channels; i++) { in restore_custom_reg_settings()
3468 chan = &sband->channels[i]; in restore_custom_reg_settings()
3469 chan->flags = chan->orig_flags; in restore_custom_reg_settings()
3470 chan->max_antenna_gain = chan->orig_mag; in restore_custom_reg_settings()
3471 chan->max_power = chan->orig_mpwr; in restore_custom_reg_settings()
3472 chan->beacon_found = false; in restore_custom_reg_settings()
3485 * - send a core regulatory hint
3486 * - send a user regulatory hint if applicable
3489 * keep their own regulatory domain on wiphy->regd so that does
3530 list_del(&reg_beacon->list); in restore_regulatory_settings()
3536 list_del(&reg_beacon->list); in restore_regulatory_settings()
3541 world_alpha2[0] = cfg80211_world_regdom->alpha2[0]; in restore_regulatory_settings()
3542 world_alpha2[1] = cfg80211_world_regdom->alpha2[1]; in restore_regulatory_settings()
3545 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) in restore_regulatory_settings()
3547 if (rdev->wiphy.regulatory_flags & REGULATORY_CUSTOM_REG) in restore_regulatory_settings()
3548 restore_custom_reg_settings(&rdev->wiphy); in restore_regulatory_settings()
3567 list_del(&ureq->list); in restore_regulatory_settings()
3602 guard(wiphy)(&rdev->wiphy); in is_wiphy_all_set_reg_flag()
3604 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { in is_wiphy_all_set_reg_flag()
3605 if (!(wdev->wiphy->regulatory_flags & flag)) in is_wiphy_all_set_reg_flag()
3628 list_del(&reg_beacon->list); in regulatory_hint_disconnect()
3635 list_del(&reg_beacon->list); in regulatory_hint_disconnect()
3646 static bool freq_is_chan_12_13_14(u32 freq) in freq_is_chan_12_13_14() argument
3648 if (freq == ieee80211_channel_to_frequency(12, NL80211_BAND_2GHZ) || in freq_is_chan_12_13_14()
3649 freq == ieee80211_channel_to_frequency(13, NL80211_BAND_2GHZ) || in freq_is_chan_12_13_14()
3650 freq == ieee80211_channel_to_frequency(14, NL80211_BAND_2GHZ)) in freq_is_chan_12_13_14()
3661 &pending_beacon->chan)) in pending_reg_beacon()
3673 if (beacon_chan->beacon_found || in regulatory_hint_found_beacon()
3674 beacon_chan->flags & IEEE80211_CHAN_RADAR || in regulatory_hint_found_beacon()
3675 (beacon_chan->band == NL80211_BAND_2GHZ && in regulatory_hint_found_beacon()
3676 !freq_is_chan_12_13_14(beacon_chan->center_freq))) in regulatory_hint_found_beacon()
3691 beacon_chan->center_freq, beacon_chan->freq_offset, in regulatory_hint_found_beacon()
3696 memcpy(&reg_beacon->chan, beacon_chan, in regulatory_hint_found_beacon()
3700 * Since we can be called from BH or and non-BH context in regulatory_hint_found_beacon()
3704 list_add_tail(&reg_beacon->list, &reg_pending_beacons); in regulatory_hint_found_beacon()
3718 pr_debug(" (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp), (dfs_cac_time)\n"); in print_rd_rules()
3720 for (i = 0; i < rd->n_reg_rules; i++) { in print_rd_rules()
3721 reg_rule = &rd->reg_rules[i]; in print_rd_rules()
3722 freq_range = &reg_rule->freq_range; in print_rd_rules()
3723 power_rule = &reg_rule->power_rule; in print_rd_rules()
3725 if (reg_rule->flags & NL80211_RRF_AUTO_BW) in print_rd_rules()
3727 freq_range->max_bandwidth_khz, in print_rd_rules()
3731 freq_range->max_bandwidth_khz); in print_rd_rules()
3733 if (reg_rule->flags & NL80211_RRF_DFS) in print_rd_rules()
3735 reg_rule->dfs_cac_ms/1000); in print_rd_rules()
3744 if (power_rule->max_antenna_gain) in print_rd_rules()
3745 pr_debug(" (%d KHz - %d KHz @ %s), (%d mBi, %d mBm), (%s)\n", in print_rd_rules()
3746 freq_range->start_freq_khz, in print_rd_rules()
3747 freq_range->end_freq_khz, in print_rd_rules()
3749 power_rule->max_antenna_gain, in print_rd_rules()
3750 power_rule->max_eirp, in print_rd_rules()
3753 pr_debug(" (%d KHz - %d KHz @ %s), (N/A, %d mBm), (%s)\n", in print_rd_rules()
3754 freq_range->start_freq_khz, in print_rd_rules()
3755 freq_range->end_freq_khz, in print_rd_rules()
3757 power_rule->max_eirp, in print_rd_rules()
3780 if (is_intersected_alpha2(rd->alpha2)) { in print_regdomain()
3781 if (lr->initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE) { in print_regdomain()
3783 rdev = cfg80211_rdev_by_wiphy_idx(lr->wiphy_idx); in print_regdomain()
3785 pr_debug("Current regulatory domain updated by AP to: %c%c\n", in print_regdomain()
3786 rdev->country_ie_alpha2[0], in print_regdomain()
3787 rdev->country_ie_alpha2[1]); in print_regdomain()
3789 pr_debug("Current regulatory domain intersected:\n"); in print_regdomain()
3791 pr_debug("Current regulatory domain intersected:\n"); in print_regdomain()
3792 } else if (is_world_regdom(rd->alpha2)) { in print_regdomain()
3793 pr_debug("World regulatory domain updated:\n"); in print_regdomain()
3795 if (is_unknown_alpha2(rd->alpha2)) in print_regdomain()
3796 pr_debug("Regulatory domain changed to driver built-in settings (unknown country)\n"); in print_regdomain()
3799 pr_debug("Regulatory domain changed to country: %c%c by Cell Station\n", in print_regdomain()
3800 rd->alpha2[0], rd->alpha2[1]); in print_regdomain()
3802 pr_debug("Regulatory domain changed to country: %c%c\n", in print_regdomain()
3803 rd->alpha2[0], rd->alpha2[1]); in print_regdomain()
3807 pr_debug(" DFS Master region: %s", reg_dfs_region_str(rd->dfs_region)); in print_regdomain()
3813 pr_debug("Regulatory domain: %c%c\n", rd->alpha2[0], rd->alpha2[1]); in print_regdomain_info()
3819 if (!is_world_regdom(rd->alpha2)) in reg_set_rd_core()
3820 return -EINVAL; in reg_set_rd_core()
3830 if (!regdom_changes(rd->alpha2)) in reg_set_rd_user()
3831 return -EALREADY; in reg_set_rd_user()
3834 pr_err("Invalid regulatory domain detected: %c%c\n", in reg_set_rd_user()
3835 rd->alpha2[0], rd->alpha2[1]); in reg_set_rd_user()
3837 return -EINVAL; in reg_set_rd_user()
3840 if (!user_request->intersect) { in reg_set_rd_user()
3847 return -EINVAL; in reg_set_rd_user()
3864 if (is_world_regdom(rd->alpha2)) in reg_set_rd_driver()
3865 return -EINVAL; in reg_set_rd_driver()
3867 if (!regdom_changes(rd->alpha2)) in reg_set_rd_driver()
3868 return -EALREADY; in reg_set_rd_driver()
3871 pr_err("Invalid regulatory domain detected: %c%c\n", in reg_set_rd_driver()
3872 rd->alpha2[0], rd->alpha2[1]); in reg_set_rd_driver()
3874 return -EINVAL; in reg_set_rd_driver()
3877 request_wiphy = wiphy_idx_to_wiphy(driver_request->wiphy_idx); in reg_set_rd_driver()
3879 return -ENODEV; in reg_set_rd_driver()
3881 if (!driver_request->intersect) { in reg_set_rd_driver()
3884 if (request_wiphy->regd) in reg_set_rd_driver()
3891 rcu_assign_pointer(request_wiphy->regd, regd); in reg_set_rd_driver()
3901 return -EINVAL; in reg_set_rd_driver()
3906 * domain we keep it for its private use in reg_set_rd_driver()
3909 rcu_assign_pointer(request_wiphy->regd, rd); in reg_set_rd_driver()
3924 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) && in reg_set_rd_country_ie()
3925 !is_unknown_alpha2(rd->alpha2)) in reg_set_rd_country_ie()
3926 return -EINVAL; in reg_set_rd_country_ie()
3935 pr_err("Invalid regulatory domain detected: %c%c\n", in reg_set_rd_country_ie()
3936 rd->alpha2[0], rd->alpha2[1]); in reg_set_rd_country_ie()
3938 return -EINVAL; in reg_set_rd_country_ie()
3941 request_wiphy = wiphy_idx_to_wiphy(country_ie_request->wiphy_idx); in reg_set_rd_country_ie()
3943 return -ENODEV; in reg_set_rd_country_ie()
3945 if (country_ie_request->intersect) in reg_set_rd_country_ie()
3946 return -EINVAL; in reg_set_rd_country_ie()
3953 * Use this call to set the current regulatory domain. Conflicts with
3965 return -ENODATA; in set_regdom()
3967 if (!reg_is_valid_request(rd->alpha2)) { in set_regdom()
3969 return -EINVAL; in set_regdom()
3978 switch (lr->initiator) { in set_regdom()
3994 WARN(1, "invalid initiator %d\n", lr->initiator); in set_regdom()
3996 return -EINVAL; in set_regdom()
4001 case -EALREADY: in set_regdom()
4014 if (WARN_ON(!lr->intersect && rd != get_cfg80211_regdom())) in set_regdom()
4015 return -EINVAL; in set_regdom()
4017 /* update all wiphys now with the new established regulatory domain */ in set_regdom()
4018 update_all_wiphy_regulatory(lr->initiator); in set_regdom()
4037 return -EINVAL; in __regulatory_set_wiphy_regd()
4039 if (WARN(!(wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED), in __regulatory_set_wiphy_regd()
4041 return -EPERM; in __regulatory_set_wiphy_regd()
4044 "Invalid regulatory domain detected: %c%c\n", in __regulatory_set_wiphy_regd()
4045 rd->alpha2[0], rd->alpha2[1])) { in __regulatory_set_wiphy_regd()
4047 return -EINVAL; in __regulatory_set_wiphy_regd()
4057 prev_regd = rdev->requested_regd; in __regulatory_set_wiphy_regd()
4058 rdev->requested_regd = regd; in __regulatory_set_wiphy_regd()
4100 /* self-managed devices ignore beacon hints and country IE */ in wiphy_regulatory_register()
4101 if (wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) { in wiphy_regulatory_register()
4102 wiphy->regulatory_flags |= REGULATORY_DISABLE_BEACON_HINTS | in wiphy_regulatory_register()
4110 if (lr->initiator == NL80211_REGDOM_SET_BY_USER) in wiphy_regulatory_register()
4117 wiphy_update_regulatory(wiphy, lr->initiator); in wiphy_regulatory_register()
4130 reg_num_devs_support_basehint--; in wiphy_regulatory_deregister()
4133 RCU_INIT_POINTER(wiphy->regd, NULL); in wiphy_regulatory_deregister()
4136 request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); in wiphy_regulatory_deregister()
4141 lr->wiphy_idx = WIPHY_IDX_INVALID; in wiphy_regulatory_deregister()
4142 lr->country_ie_env = ENVIRON_ANY; in wiphy_regulatory_deregister()
4147 * 5GHz: https://www.fcc.gov/document/5-ghz-unlicensed-spectrum-unii
4148 * 6GHz: https://www.fcc.gov/document/fcc-proposes-more-spectrum-unlicensed-use-0
4150 int cfg80211_get_unii(int freq) in cfg80211_get_unii() argument
4152 /* UNII-1 */ in cfg80211_get_unii()
4153 if (freq >= 5150 && freq <= 5250) in cfg80211_get_unii()
4156 /* UNII-2A */ in cfg80211_get_unii()
4157 if (freq > 5250 && freq <= 5350) in cfg80211_get_unii()
4160 /* UNII-2B */ in cfg80211_get_unii()
4161 if (freq > 5350 && freq <= 5470) in cfg80211_get_unii()
4164 /* UNII-2C */ in cfg80211_get_unii()
4165 if (freq > 5470 && freq <= 5725) in cfg80211_get_unii()
4168 /* UNII-3 */ in cfg80211_get_unii()
4169 if (freq > 5725 && freq <= 5825) in cfg80211_get_unii()
4172 /* UNII-5 */ in cfg80211_get_unii()
4173 if (freq > 5925 && freq <= 6425) in cfg80211_get_unii()
4176 /* UNII-6 */ in cfg80211_get_unii()
4177 if (freq > 6425 && freq <= 6525) in cfg80211_get_unii()
4180 /* UNII-7 */ in cfg80211_get_unii()
4181 if (freq > 6525 && freq <= 6875) in cfg80211_get_unii()
4184 /* UNII-8 */ in cfg80211_get_unii()
4185 if (freq > 6875 && freq <= 7125) in cfg80211_get_unii()
4188 return -EINVAL; in cfg80211_get_unii()
4205 wiphy_regd = rcu_dereference(wiphy->regd); in regulatory_pre_cac_allowed()
4207 if (regd->dfs_region == NL80211_DFS_ETSI) in regulatory_pre_cac_allowed()
4215 if (regd->dfs_region == wiphy_regd->dfs_region && in regulatory_pre_cac_allowed()
4216 wiphy_regd->dfs_region == NL80211_DFS_ETSI) in regulatory_pre_cac_allowed()
4233 * either all channels are available - those the CAC_FINISHED in cfg80211_check_and_end_cac()
4235 * in unavailable state in wdev chandef - those the RADAR_DETECTED in cfg80211_check_and_end_cac()
4239 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { in cfg80211_check_and_end_cac()
4243 if (!wdev->links[link_id].cac_started) in cfg80211_check_and_end_cac()
4250 if (!cfg80211_chandef_dfs_usable(&rdev->wiphy, chandef)) in cfg80211_check_and_end_cac()
4251 rdev_end_cac(rdev, wdev->netdev, link_id); in cfg80211_check_and_end_cac()
4269 if (wiphy == &rdev->wiphy) in regulatory_propagate_dfs_state()
4272 if (!reg_dfs_domain_same(wiphy, &rdev->wiphy)) in regulatory_propagate_dfs_state()
4275 if (!ieee80211_get_channel(&rdev->wiphy, in regulatory_propagate_dfs_state()
4276 chandef->chan->center_freq)) in regulatory_propagate_dfs_state()
4279 cfg80211_set_dfs_state(&rdev->wiphy, chandef, dfs_state); in regulatory_propagate_dfs_state()
4296 * It's possible that - due to other bugs/issues - cfg80211 in regulatory_init_db()
4302 return -EINVAL; in regulatory_init_db()
4311 err = regulatory_hint_core(cfg80211_world_regdom->alpha2); in regulatory_init_db()
4313 if (err == -ENOMEM) { in regulatory_init_db()
4322 * errors as non-fatal. in regulatory_init_db()
4373 dev_set_uevent_suppress(&reg_pdev->dev, true); in regulatory_exit()
4378 list_del(&reg_beacon->list); in regulatory_exit()
4383 list_del(&reg_beacon->list); in regulatory_exit()
4388 list_del(&reg_request->list); in regulatory_exit()