Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 1 | #ifndef __NET_REGULATORY_H |
| 2 | #define __NET_REGULATORY_H |
| 3 | /* |
| 4 | * regulatory support structures |
| 5 | * |
Luis R. Rodriguez | dde88b7 | 2011-08-23 15:03:34 -0700 | [diff] [blame] | 6 | * Copyright 2008-2009 Luis R. Rodriguez <mcgrof@qca.qualcomm.com> |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 7 | * |
Luis R. Rodriguez | dde88b7 | 2011-08-23 15:03:34 -0700 | [diff] [blame] | 8 | * Permission to use, copy, modify, and/or distribute this software for any |
| 9 | * purpose with or without fee is hereby granted, provided that the above |
| 10 | * copyright notice and this permission notice appear in all copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 13 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 14 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 15 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 16 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 18 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame^] | 21 | #include <linux/rcupdate.h> |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * enum environment_cap - Environment parsed from country IE |
| 25 | * @ENVIRON_ANY: indicates country IE applies to both indoor and |
| 26 | * outdoor operation. |
| 27 | * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation |
| 28 | * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation |
| 29 | */ |
| 30 | enum environment_cap { |
| 31 | ENVIRON_ANY, |
| 32 | ENVIRON_INDOOR, |
| 33 | ENVIRON_OUTDOOR, |
| 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * struct regulatory_request - used to keep track of regulatory requests |
| 38 | * |
| 39 | * @wiphy_idx: this is set if this request's initiator is |
| 40 | * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This |
| 41 | * can be used by the wireless core to deal with conflicts |
| 42 | * and potentially inform users of which devices specifically |
| 43 | * cased the conflicts. |
| 44 | * @initiator: indicates who sent this request, could be any of |
| 45 | * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*) |
| 46 | * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested |
| 47 | * regulatory domain. We have a few special codes: |
| 48 | * 00 - World regulatory domain |
| 49 | * 99 - built by driver but a specific alpha2 cannot be determined |
| 50 | * 98 - result of an intersection between two regulatory domains |
Luis R. Rodriguez | 09d989d | 2010-01-29 19:58:57 -0500 | [diff] [blame] | 51 | * 97 - regulatory domain has not yet been configured |
Luis R. Rodriguez | b68e6b3 | 2011-10-11 10:59:03 -0700 | [diff] [blame] | 52 | * @dfs_region: If CRDA responded with a regulatory domain that requires |
| 53 | * DFS master operation on a known DFS region (NL80211_DFS_*), |
| 54 | * dfs_region represents that region. Drivers can use this and the |
| 55 | * @alpha2 to adjust their device's DFS parameters as required. |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 56 | * @user_reg_hint_type: if the @initiator was of type |
| 57 | * %NL80211_REGDOM_SET_BY_USER, this classifies the type |
| 58 | * of hint passed. This could be any of the %NL80211_USER_REG_HINT_* |
| 59 | * types. |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 60 | * @intersect: indicates whether the wireless core should intersect |
| 61 | * the requested regulatory domain with the presently set regulatory |
| 62 | * domain. |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 63 | * @processed: indicates whether or not this requests has already been |
| 64 | * processed. When the last request is processed it means that the |
| 65 | * currently regulatory domain set on cfg80211 is updated from |
| 66 | * CRDA and can be used by other regulatory requests. When a |
| 67 | * the last request is not yet processed we must yield until it |
| 68 | * is processed before processing any new requests. |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 69 | * @country_ie_checksum: checksum of the last processed and accepted |
| 70 | * country IE |
| 71 | * @country_ie_env: lets us know if the AP is telling us we are outdoor, |
| 72 | * indoor, or if it doesn't matter |
| 73 | * @list: used to insert into the reg_requests_list linked list |
| 74 | */ |
| 75 | struct regulatory_request { |
| 76 | int wiphy_idx; |
| 77 | enum nl80211_reg_initiator initiator; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 78 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 79 | char alpha2[2]; |
Luis R. Rodriguez | b68e6b3 | 2011-10-11 10:59:03 -0700 | [diff] [blame] | 80 | u8 dfs_region; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 81 | bool intersect; |
Luis R. Rodriguez | b2e253c | 2010-11-17 21:46:09 -0800 | [diff] [blame] | 82 | bool processed; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 83 | enum environment_cap country_ie_env; |
| 84 | struct list_head list; |
| 85 | }; |
| 86 | |
| 87 | struct ieee80211_freq_range { |
| 88 | u32 start_freq_khz; |
| 89 | u32 end_freq_khz; |
| 90 | u32 max_bandwidth_khz; |
| 91 | }; |
| 92 | |
| 93 | struct ieee80211_power_rule { |
| 94 | u32 max_antenna_gain; |
| 95 | u32 max_eirp; |
| 96 | }; |
| 97 | |
| 98 | struct ieee80211_reg_rule { |
| 99 | struct ieee80211_freq_range freq_range; |
| 100 | struct ieee80211_power_rule power_rule; |
| 101 | u32 flags; |
| 102 | }; |
| 103 | |
| 104 | struct ieee80211_regdomain { |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame^] | 105 | struct rcu_head rcu_head; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 106 | u32 n_reg_rules; |
| 107 | char alpha2[2]; |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 108 | u8 dfs_region; |
Johannes Berg | d323655 | 2009-04-20 14:31:42 +0200 | [diff] [blame] | 109 | struct ieee80211_reg_rule reg_rules[]; |
| 110 | }; |
| 111 | |
| 112 | #define MHZ_TO_KHZ(freq) ((freq) * 1000) |
| 113 | #define KHZ_TO_MHZ(freq) ((freq) / 1000) |
| 114 | #define DBI_TO_MBI(gain) ((gain) * 100) |
| 115 | #define MBI_TO_DBI(gain) ((gain) / 100) |
| 116 | #define DBM_TO_MBM(gain) ((gain) * 100) |
| 117 | #define MBM_TO_DBM(gain) ((gain) / 100) |
| 118 | |
| 119 | #define REG_RULE(start, end, bw, gain, eirp, reg_flags) \ |
| 120 | { \ |
| 121 | .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \ |
| 122 | .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \ |
| 123 | .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \ |
| 124 | .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\ |
| 125 | .power_rule.max_eirp = DBM_TO_MBM(eirp), \ |
| 126 | .flags = reg_flags, \ |
| 127 | } |
| 128 | |
| 129 | #endif |