regulatory.h 6.3 KB
Newer Older
J
Johannes Berg 已提交
1 2 3 4 5
#ifndef __NET_REGULATORY_H
#define __NET_REGULATORY_H
/*
 * regulatory support structures
 *
6
 * Copyright 2008-2009	Luis R. Rodriguez <mcgrof@qca.qualcomm.com>
J
Johannes Berg 已提交
7
 *
8 9 10 11 12 13 14 15 16 17 18
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
J
Johannes Berg 已提交
19 20
 */

21
#include <linux/rcupdate.h>
J
Johannes Berg 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

/**
 * enum environment_cap - Environment parsed from country IE
 * @ENVIRON_ANY: indicates country IE applies to both indoor and
 *	outdoor operation.
 * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
 * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
 */
enum environment_cap {
	ENVIRON_ANY,
	ENVIRON_INDOOR,
	ENVIRON_OUTDOOR,
};

/**
 * struct regulatory_request - used to keep track of regulatory requests
 *
39
 * @rcu_head: RCU head struct used to free the request
J
Johannes Berg 已提交
40
 * @wiphy_idx: this is set if this request's initiator is
41 42 43 44
 *	%REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
 *	can be used by the wireless core to deal with conflicts
 *	and potentially inform users of which devices specifically
 *	cased the conflicts.
J
Johannes Berg 已提交
45
 * @initiator: indicates who sent this request, could be any of
46
 *	of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
J
Johannes Berg 已提交
47
 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
48 49 50 51
 *	regulatory domain. We have a few special codes:
 *	00 - World regulatory domain
 *	99 - built by driver but a specific alpha2 cannot be determined
 *	98 - result of an intersection between two regulatory domains
52
 *	97 - regulatory domain has not yet been configured
53 54 55 56
 * @dfs_region: If CRDA responded with a regulatory domain that requires
 *	DFS master operation on a known DFS region (NL80211_DFS_*),
 *	dfs_region represents that region. Drivers can use this and the
 *	@alpha2 to adjust their device's DFS parameters as required.
57 58 59 60
 * @user_reg_hint_type: if the @initiator was of type
 *	%NL80211_REGDOM_SET_BY_USER, this classifies the type
 *	of hint passed. This could be any of the %NL80211_USER_REG_HINT_*
 *	types.
J
Johannes Berg 已提交
61
 * @intersect: indicates whether the wireless core should intersect
62 63
 *	the requested regulatory domain with the presently set regulatory
 *	domain.
64 65 66 67 68 69
 * @processed: indicates whether or not this requests has already been
 *	processed. When the last request is processed it means that the
 *	currently regulatory domain set on cfg80211 is updated from
 *	CRDA and can be used by other regulatory requests. When a
 *	the last request is not yet processed we must yield until it
 *	is processed before processing any new requests.
J
Johannes Berg 已提交
70
 * @country_ie_checksum: checksum of the last processed and accepted
71
 *	country IE
J
Johannes Berg 已提交
72
 * @country_ie_env: lets us know if the AP is telling us we are outdoor,
73
 *	indoor, or if it doesn't matter
J
Johannes Berg 已提交
74 75 76
 * @list: used to insert into the reg_requests_list linked list
 */
struct regulatory_request {
77
	struct rcu_head rcu_head;
J
Johannes Berg 已提交
78 79
	int wiphy_idx;
	enum nl80211_reg_initiator initiator;
80
	enum nl80211_user_reg_hint_type user_reg_hint_type;
J
Johannes Berg 已提交
81
	char alpha2[2];
82
	u8 dfs_region;
J
Johannes Berg 已提交
83
	bool intersect;
84
	bool processed;
J
Johannes Berg 已提交
85 86 87 88
	enum environment_cap country_ie_env;
	struct list_head list;
};

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
/**
 * enum ieee80211_regulatory_flags - device regulatory flags
 *
 * @REGULATORY_CUSTOM_REG: tells us the driver for this device
 *	has its own custom regulatory domain and cannot identify the
 *	ISO / IEC 3166 alpha2 it belongs to. When this is enabled
 *	we will disregard the first regulatory hint (when the
 *	initiator is %REGDOM_SET_BY_CORE). Drivers that use
 *	wiphy_apply_custom_regulatory() should have this flag set
 *	or the regulatory core will set it for the wiphy.
 * @REGULATORY_STRICT_REG: tells us the driver for this device will
 *	ignore regulatory domain settings until it gets its own regulatory
 *	domain via its regulatory_hint() unless the regulatory hint is
 *	from a country IE. After its gets its own regulatory domain it will
 *	only allow further regulatory domain settings to further enhance
 *	compliance. For example if channel 13 and 14 are disabled by this
 *	regulatory domain no user regulatory domain can enable these channels
 *	at a later time. This can be used for devices which do not have
 *	calibration information guaranteed for frequencies or settings
 *	outside of its regulatory domain. If used in combination with
 *	REGULATORY_FLAG_CUSTOM_REG the inspected country IE power settings
 *	will be followed.
 * @REGULATORY_DISABLE_BEACON_HINTS: enable this if your driver needs to
 *	ensure that passive scan flags and beaconing flags may not be lifted by
 *	cfg80211 due to regulatory beacon hints. For more information on beacon
 *	hints read the documenation for regulatory_hint_found_beacon()
 */
enum ieee80211_regulatory_flags {
	REGULATORY_CUSTOM_REG			= BIT(0),
	REGULATORY_STRICT_REG			= BIT(1),
	REGULATORY_DISABLE_BEACON_HINTS		= BIT(2),
};

J
Johannes Berg 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
struct ieee80211_freq_range {
	u32 start_freq_khz;
	u32 end_freq_khz;
	u32 max_bandwidth_khz;
};

struct ieee80211_power_rule {
	u32 max_antenna_gain;
	u32 max_eirp;
};

struct ieee80211_reg_rule {
	struct ieee80211_freq_range freq_range;
	struct ieee80211_power_rule power_rule;
	u32 flags;
};

struct ieee80211_regdomain {
140
	struct rcu_head rcu_head;
J
Johannes Berg 已提交
141 142
	u32 n_reg_rules;
	char alpha2[2];
143
	u8 dfs_region;
J
Johannes Berg 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
	struct ieee80211_reg_rule reg_rules[];
};

#define MHZ_TO_KHZ(freq) ((freq) * 1000)
#define KHZ_TO_MHZ(freq) ((freq) / 1000)
#define DBI_TO_MBI(gain) ((gain) * 100)
#define MBI_TO_DBI(gain) ((gain) / 100)
#define DBM_TO_MBM(gain) ((gain) * 100)
#define MBM_TO_DBM(gain) ((gain) / 100)

#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
{							\
	.freq_range.start_freq_khz = MHZ_TO_KHZ(start),	\
	.freq_range.end_freq_khz = MHZ_TO_KHZ(end),	\
	.freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw),	\
	.power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
	.power_rule.max_eirp = DBM_TO_MBM(eirp),	\
	.flags = reg_flags,				\
}

#endif