1 #ifndef __NET_WIRELESS_H
2 #define __NET_WIRELESS_H
5 * 802.11 device management
7 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
10 #include <linux/netdevice.h>
11 #include <linux/debugfs.h>
12 #include <linux/list.h>
13 #include <linux/ieee80211.h>
14 #include <net/cfg80211.h>
17 * enum ieee80211_band - supported frequency bands
19 * The bands are assigned this way because the supported
20 * bitrates differ in these bands.
22 * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
23 * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
34 * enum ieee80211_channel_flags - channel flags
36 * Channel flags set by the regulatory control code.
38 * @IEEE80211_CHAN_DISABLED: This channel is disabled.
39 * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
41 * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
42 * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
43 * @IEEE80211_CHAN_NO_FAT_ABOVE: extension channel above this channel
45 * @IEEE80211_CHAN_NO_FAT_BELOW: extension channel below this channel
48 enum ieee80211_channel_flags {
49 IEEE80211_CHAN_DISABLED = 1<<0,
50 IEEE80211_CHAN_PASSIVE_SCAN = 1<<1,
51 IEEE80211_CHAN_NO_IBSS = 1<<2,
52 IEEE80211_CHAN_RADAR = 1<<3,
53 IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4,
54 IEEE80211_CHAN_NO_FAT_BELOW = 1<<5,
58 * struct ieee80211_channel - channel definition
60 * This structure describes a single channel for use
63 * @center_freq: center frequency in MHz
64 * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
65 * @hw_value: hardware-specific value for the channel
66 * @flags: channel flags from &enum ieee80211_channel_flags.
67 * @orig_flags: channel flags at registration time, used by regulatory
68 * code to support devices with additional restrictions
69 * @band: band this channel belongs to.
70 * @max_antenna_gain: maximum antenna gain in dBi
71 * @max_power: maximum transmission power (in dBm)
72 * @beacon_found: helper to regulatory code to indicate when a beacon
73 * has been found on this channel. Use regulatory_hint_found_beacon()
74 * to enable this, this is is useful only on 5 GHz band.
75 * @orig_mag: internal use
76 * @orig_mpwr: internal use
78 struct ieee80211_channel {
79 enum ieee80211_band band;
88 int orig_mag, orig_mpwr;
92 * enum ieee80211_rate_flags - rate flags
94 * Hardware/specification flags for rates. These are structured
95 * in a way that allows using the same bitrate structure for
96 * different bands/PHY modes.
98 * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
99 * preamble on this bitrate; only relevant in 2.4GHz band and
101 * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
102 * when used with 802.11a (on the 5 GHz band); filled by the
103 * core code when registering the wiphy.
104 * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
105 * when used with 802.11b (on the 2.4 GHz band); filled by the
106 * core code when registering the wiphy.
107 * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
108 * when used with 802.11g (on the 2.4 GHz band); filled by the
109 * core code when registering the wiphy.
110 * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
112 enum ieee80211_rate_flags {
113 IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
114 IEEE80211_RATE_MANDATORY_A = 1<<1,
115 IEEE80211_RATE_MANDATORY_B = 1<<2,
116 IEEE80211_RATE_MANDATORY_G = 1<<3,
117 IEEE80211_RATE_ERP_G = 1<<4,
121 * struct ieee80211_rate - bitrate definition
123 * This structure describes a bitrate that an 802.11 PHY can
124 * operate with. The two values @hw_value and @hw_value_short
125 * are only for driver use when pointers to this structure are
128 * @flags: rate-specific flags
129 * @bitrate: bitrate in units of 100 Kbps
130 * @hw_value: driver/hardware value for this rate
131 * @hw_value_short: driver/hardware value for this rate when
132 * short preamble is used
134 struct ieee80211_rate {
137 u16 hw_value, hw_value_short;
141 * struct ieee80211_sta_ht_cap - STA's HT capabilities
143 * This structure describes most essential parameters needed
144 * to describe 802.11n HT capabilities for an STA.
146 * @ht_supported: is HT supported by the STA
147 * @cap: HT capabilities map as described in 802.11n spec
148 * @ampdu_factor: Maximum A-MPDU length factor
149 * @ampdu_density: Minimum A-MPDU spacing
150 * @mcs: Supported MCS rates
152 struct ieee80211_sta_ht_cap {
153 u16 cap; /* use IEEE80211_HT_CAP_ */
157 struct ieee80211_mcs_info mcs;
161 * struct ieee80211_supported_band - frequency band definition
163 * This structure describes a frequency band a wiphy
164 * is able to operate in.
166 * @channels: Array of channels the hardware can operate in
168 * @band: the band this structure represents
169 * @n_channels: Number of channels in @channels
170 * @bitrates: Array of bitrates the hardware can operate with
171 * in this band. Must be sorted to give a valid "supported
172 * rates" IE, i.e. CCK rates first, then OFDM.
173 * @n_bitrates: Number of bitrates in @bitrates
175 struct ieee80211_supported_band {
176 struct ieee80211_channel *channels;
177 struct ieee80211_rate *bitrates;
178 enum ieee80211_band band;
181 struct ieee80211_sta_ht_cap ht_cap;
185 * struct wiphy - wireless hardware description
186 * @idx: the wiphy index assigned to this item
187 * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
188 * @custom_regulatory: tells us the driver for this device
189 * has its own custom regulatory domain and cannot identify the
190 * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
191 * we will disregard the first regulatory hint (when the
192 * initiator is %REGDOM_SET_BY_CORE).
193 * @strict_regulatory: tells us the driver for this device will ignore
194 * regulatory domain settings until it gets its own regulatory domain
195 * via its regulatory_hint(). After its gets its own regulatory domain
196 * it will only allow further regulatory domain settings to further
197 * enhance compliance. For example if channel 13 and 14 are disabled
198 * by this regulatory domain no user regulatory domain can enable these
199 * channels at a later time. This can be used for devices which do not
200 * have calibration information gauranteed for frequencies or settings
201 * outside of its regulatory domain.
202 * @reg_notifier: the driver's regulatory notification callback
203 * @regd: the driver's regulatory domain, if one was requested via
204 * the regulatory_hint() API. This can be used by the driver
205 * on the reg_notifier() if it chooses to ignore future
206 * regulatory domain changes caused by other drivers.
207 * @signal_type: signal type reported in &struct cfg80211_bss.
208 * @cipher_suites: supported cipher suites
209 * @n_cipher_suites: number of supported cipher suites
212 /* assign these fields before you register the wiphy */
214 /* permanent MAC address */
215 u8 perm_addr[ETH_ALEN];
217 /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
220 bool custom_regulatory;
221 bool strict_regulatory;
223 enum cfg80211_signal_type signal_type;
230 const u32 *cipher_suites;
232 /* If multiple wiphys are registered and you're handed e.g.
233 * a regular netdev with assigned ieee80211_ptr, you won't
234 * know whether it points to a wiphy your driver has registered
235 * or not. Assign this to something global to your driver to
236 * help determine whether you own this wiphy or not. */
239 struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
241 /* Lets us get back the wiphy on the callback */
242 int (*reg_notifier)(struct wiphy *wiphy,
243 struct regulatory_request *request);
245 /* fields below are read-only, assigned by cfg80211 */
247 const struct ieee80211_regdomain *regd;
249 /* the item in /sys/class/ieee80211/ points to this,
250 * you need use set_wiphy_dev() (see below) */
253 /* dir in debugfs: ieee80211/<wiphyname> */
254 struct dentry *debugfsdir;
256 char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
259 /** struct wireless_dev - wireless per-netdev state
261 * This structure must be allocated by the driver/stack
262 * that uses the ieee80211_ptr field in struct net_device
263 * (this is intentional so it can be allocated along with
266 * @wiphy: pointer to hardware description
267 * @iftype: interface type
271 struct wireless_dev {
273 enum nl80211_iftype iftype;
275 /* private to the generic wireless code */
276 struct list_head list;
277 struct net_device *netdev;
279 /* currently used for IBSS - might be rearranged in the future */
280 struct cfg80211_bss *current_bss;
282 u8 ssid[IEEE80211_MAX_SSID_LEN];
285 #ifdef CONFIG_WIRELESS_EXT
287 struct cfg80211_ibss_params wext;
288 u8 wext_bssid[ETH_ALEN];
293 * wiphy_priv - return priv from wiphy
295 static inline void *wiphy_priv(struct wiphy *wiphy)
302 * set_wiphy_dev - set device pointer for wiphy
304 static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
306 wiphy->dev.parent = dev;
310 * wiphy_dev - get wiphy dev pointer
312 static inline struct device *wiphy_dev(struct wiphy *wiphy)
314 return wiphy->dev.parent;
318 * wiphy_name - get wiphy name
320 static inline const char *wiphy_name(struct wiphy *wiphy)
322 return dev_name(&wiphy->dev);
326 * wdev_priv - return wiphy priv from wireless_dev
328 static inline void *wdev_priv(struct wireless_dev *wdev)
331 return wiphy_priv(wdev->wiphy);
335 * wiphy_new - create a new wiphy for use with cfg80211
337 * create a new wiphy and associate the given operations with it.
338 * @sizeof_priv bytes are allocated for private use.
340 * the returned pointer must be assigned to each netdev's
341 * ieee80211_ptr for proper operation.
343 struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
346 * wiphy_register - register a wiphy with cfg80211
348 * register the given wiphy
350 * Returns a non-negative wiphy index or a negative error code.
352 extern int wiphy_register(struct wiphy *wiphy);
355 * wiphy_unregister - deregister a wiphy from cfg80211
357 * unregister a device with the given priv pointer.
358 * After this call, no more requests can be made with this priv
359 * pointer, but the call may sleep to wait for an outstanding
360 * request that is being handled.
362 extern void wiphy_unregister(struct wiphy *wiphy);
365 * wiphy_free - free wiphy
367 extern void wiphy_free(struct wiphy *wiphy);
370 * ieee80211_channel_to_frequency - convert channel number to frequency
372 extern int ieee80211_channel_to_frequency(int chan);
375 * ieee80211_frequency_to_channel - convert frequency to channel number
377 extern int ieee80211_frequency_to_channel(int freq);
380 * Name indirection necessary because the ieee80211 code also has
381 * a function named "ieee80211_get_channel", so if you include
382 * cfg80211's header file you get cfg80211's version, if you try
383 * to include both header files you'll (rightfully!) get a symbol
386 extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
389 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
391 static inline struct ieee80211_channel *
392 ieee80211_get_channel(struct wiphy *wiphy, int freq)
394 return __ieee80211_get_channel(wiphy, freq);
398 * ieee80211_get_response_rate - get basic rate for a given rate
400 * @sband: the band to look for rates in
401 * @basic_rates: bitmap of basic rates
402 * @bitrate: the bitrate for which to find the basic rate
404 * This function returns the basic rate corresponding to a given
405 * bitrate, that is the next lower bitrate contained in the basic
406 * rate map, which is, for this function, given as a bitmap of
407 * indices of rates in the band's bitrate table.
409 struct ieee80211_rate *
410 ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
411 u32 basic_rates, int bitrate);
414 * regulatory_hint - driver hint to the wireless core a regulatory domain
415 * @wiphy: the wireless device giving the hint (used only for reporting
417 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
418 * should be in. If @rd is set this should be NULL. Note that if you
419 * set this to NULL you should still set rd->alpha2 to some accepted
422 * Wireless drivers can use this function to hint to the wireless core
423 * what it believes should be the current regulatory domain by
424 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
425 * domain should be in or by providing a completely build regulatory domain.
426 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
427 * for a regulatory domain structure for the respective country.
429 * The wiphy must have been registered to cfg80211 prior to this call.
430 * For cfg80211 drivers this means you must first use wiphy_register(),
431 * for mac80211 drivers you must first use ieee80211_register_hw().
433 * Drivers should check the return value, its possible you can get
436 extern int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
439 * regulatory_hint_11d - hints a country IE as a regulatory domain
440 * @wiphy: the wireless device giving the hint (used only for reporting
442 * @country_ie: pointer to the country IE
443 * @country_ie_len: length of the country IE
445 * We will intersect the rd with the what CRDA tells us should apply
446 * for the alpha2 this country IE belongs to, this prevents APs from
447 * sending us incorrect or outdated information against a country.
449 extern void regulatory_hint_11d(struct wiphy *wiphy,
453 * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
454 * @wiphy: the wireless device we want to process the regulatory domain on
455 * @regd: the custom regulatory domain to use for this wiphy
457 * Drivers can sometimes have custom regulatory domains which do not apply
458 * to a specific country. Drivers can use this to apply such custom regulatory
459 * domains. This routine must be called prior to wiphy registration. The
460 * custom regulatory domain will be trusted completely and as such previous
461 * default channel settings will be disregarded. If no rule is found for a
462 * channel on the regulatory domain the channel will be disabled.
464 extern void wiphy_apply_custom_regulatory(
466 const struct ieee80211_regdomain *regd);
469 * freq_reg_info - get regulatory information for the given frequency
470 * @wiphy: the wiphy for which we want to process this rule for
471 * @center_freq: Frequency in KHz for which we want regulatory information for
472 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
473 * you can set this to 0. If this frequency is allowed we then set
474 * this value to the maximum allowed bandwidth.
475 * @reg_rule: the regulatory rule which we have for this frequency
477 * Use this function to get the regulatory rule for a specific frequency on
478 * a given wireless device. If the device has a specific regulatory domain
479 * it wants to follow we respect that unless a country IE has been received
480 * and processed already.
482 * Returns 0 if it was able to find a valid regulatory rule which does
483 * apply to the given center_freq otherwise it returns non-zero. It will
484 * also return -ERANGE if we determine the given center_freq does not even have
485 * a regulatory rule for a frequency range in the center_freq's band. See
486 * freq_in_rule_band() for our current definition of a band -- this is purely
487 * subjective and right now its 802.11 specific.
489 extern int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth,
490 const struct ieee80211_reg_rule **reg_rule);
492 #endif /* __NET_WIRELESS_H */