blob: 64a76208580c66ec4d8f2bc3562f5b86287fd723 [file] [log] [blame]
Johannes Berg704232c2007-04-23 12:20:05 -07001#ifndef __NET_WIRELESS_H
2#define __NET_WIRELESS_H
3
4/*
5 * 802.11 device management
6 *
7 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
8 */
9
10#include <linux/netdevice.h>
11#include <linux/debugfs.h>
12#include <linux/list.h>
Johannes Bergd9fe60d2008-10-09 12:13:49 +020013#include <linux/ieee80211.h>
Johannes Berg704232c2007-04-23 12:20:05 -070014#include <net/cfg80211.h>
15
16/**
Johannes Berg8318d782008-01-24 19:38:38 +010017 * enum ieee80211_band - supported frequency bands
18 *
19 * The bands are assigned this way because the supported
20 * bitrates differ in these bands.
21 *
22 * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
23 * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
24 */
25enum ieee80211_band {
26 IEEE80211_BAND_2GHZ,
27 IEEE80211_BAND_5GHZ,
28
29 /* keep last */
30 IEEE80211_NUM_BANDS
31};
32
33/**
34 * enum ieee80211_channel_flags - channel flags
35 *
36 * Channel flags set by the regulatory control code.
37 *
38 * @IEEE80211_CHAN_DISABLED: This channel is disabled.
39 * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
40 * on this channel.
41 * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
42 * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
Emmanuel Grumbach93061022008-05-29 16:35:23 +080043 * @IEEE80211_CHAN_NO_FAT_ABOVE: extension channel above this channel
44 * is not permitted.
45 * @IEEE80211_CHAN_NO_FAT_BELOW: extension channel below this channel
46 * is not permitted.
Johannes Berg8318d782008-01-24 19:38:38 +010047 */
48enum 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,
Emmanuel Grumbach93061022008-05-29 16:35:23 +080053 IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4,
54 IEEE80211_CHAN_NO_FAT_BELOW = 1<<5,
Johannes Berg8318d782008-01-24 19:38:38 +010055};
56
57/**
58 * struct ieee80211_channel - channel definition
59 *
60 * This structure describes a single channel for use
61 * with cfg80211.
62 *
63 * @center_freq: center frequency in MHz
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070064 * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
Johannes Berg8318d782008-01-24 19:38:38 +010065 * @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)
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -050072 * @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.
Johannes Berg8318d782008-01-24 19:38:38 +010075 * @orig_mag: internal use
76 * @orig_mpwr: internal use
77 */
78struct ieee80211_channel {
79 enum ieee80211_band band;
80 u16 center_freq;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070081 u8 max_bandwidth;
Johannes Berg8318d782008-01-24 19:38:38 +010082 u16 hw_value;
83 u32 flags;
84 int max_antenna_gain;
85 int max_power;
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -050086 bool beacon_found;
Johannes Berg8318d782008-01-24 19:38:38 +010087 u32 orig_flags;
88 int orig_mag, orig_mpwr;
89};
90
91/**
92 * enum ieee80211_rate_flags - rate flags
93 *
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.
97 *
98 * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
99 * preamble on this bitrate; only relevant in 2.4GHz band and
100 * with CCK rates.
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.
111 */
112enum 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,
118};
119
120/**
121 * struct ieee80211_rate - bitrate definition
122 *
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
126 * passed around.
127 *
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
133 */
134struct ieee80211_rate {
135 u32 flags;
136 u16 bitrate;
137 u16 hw_value, hw_value_short;
138};
139
140/**
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200141 * struct ieee80211_sta_ht_cap - STA's HT capabilities
Johannes Berg8318d782008-01-24 19:38:38 +0100142 *
143 * This structure describes most essential parameters needed
144 * to describe 802.11n HT capabilities for an STA.
145 *
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200146 * @ht_supported: is HT supported by the STA
Johannes Berg8318d782008-01-24 19:38:38 +0100147 * @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
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200150 * @mcs: Supported MCS rates
Johannes Berg8318d782008-01-24 19:38:38 +0100151 */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200152struct ieee80211_sta_ht_cap {
Johannes Berg8318d782008-01-24 19:38:38 +0100153 u16 cap; /* use IEEE80211_HT_CAP_ */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200154 bool ht_supported;
Johannes Berg8318d782008-01-24 19:38:38 +0100155 u8 ampdu_factor;
156 u8 ampdu_density;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200157 struct ieee80211_mcs_info mcs;
Johannes Berg8318d782008-01-24 19:38:38 +0100158};
159
160/**
161 * struct ieee80211_supported_band - frequency band definition
162 *
163 * This structure describes a frequency band a wiphy
164 * is able to operate in.
165 *
166 * @channels: Array of channels the hardware can operate in
167 * in this band.
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
174 */
175struct ieee80211_supported_band {
176 struct ieee80211_channel *channels;
177 struct ieee80211_rate *bitrates;
178 enum ieee80211_band band;
179 int n_channels;
180 int n_bitrates;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200181 struct ieee80211_sta_ht_cap ht_cap;
Johannes Berg8318d782008-01-24 19:38:38 +0100182};
183
184/**
Johannes Berg704232c2007-04-23 12:20:05 -0700185 * 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>
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -0800188 * @custom_regulatory: tells us the driver for this device
189 * has its own custom regulatory domain and cannot identify the
Luis R. Rodriguez14b98152008-11-12 14:22:03 -0800190 * 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).
Luis R. Rodriguezf9763762009-01-22 15:05:52 -0800193 * @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.
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700202 * @reg_notifier: the driver's regulatory notification callback
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800203 * @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.
Johannes Berg77965c92009-02-18 18:45:06 +0100207 * @signal_type: signal type reported in &struct cfg80211_bss.
Johannes Berg704232c2007-04-23 12:20:05 -0700208 */
209struct wiphy {
210 /* assign these fields before you register the wiphy */
211
212 /* permanent MAC address */
213 u8 perm_addr[ETH_ALEN];
214
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700215 /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
216 u16 interface_modes;
217
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -0800218 bool custom_regulatory;
Luis R. Rodriguezf9763762009-01-22 15:05:52 -0800219 bool strict_regulatory;
Luis R. Rodriguez14b98152008-11-12 14:22:03 -0800220
Johannes Berg77965c92009-02-18 18:45:06 +0100221 enum cfg80211_signal_type signal_type;
222
Johannes Berg2a519312009-02-10 21:25:55 +0100223 int bss_priv_size;
224 u8 max_scan_ssids;
225
Johannes Berg704232c2007-04-23 12:20:05 -0700226 /* If multiple wiphys are registered and you're handed e.g.
227 * a regular netdev with assigned ieee80211_ptr, you won't
228 * know whether it points to a wiphy your driver has registered
229 * or not. Assign this to something global to your driver to
230 * help determine whether you own this wiphy or not. */
231 void *privid;
232
Johannes Berg8318d782008-01-24 19:38:38 +0100233 struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
234
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700235 /* Lets us get back the wiphy on the callback */
Luis R. Rodriguez716f9392009-01-22 15:05:51 -0800236 int (*reg_notifier)(struct wiphy *wiphy,
237 struct regulatory_request *request);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700238
Johannes Berg704232c2007-04-23 12:20:05 -0700239 /* fields below are read-only, assigned by cfg80211 */
240
Luis R. Rodriguez3e0c3ff2009-01-07 17:43:34 -0800241 const struct ieee80211_regdomain *regd;
242
Johannes Berg704232c2007-04-23 12:20:05 -0700243 /* the item in /sys/class/ieee80211/ points to this,
244 * you need use set_wiphy_dev() (see below) */
245 struct device dev;
246
247 /* dir in debugfs: ieee80211/<wiphyname> */
248 struct dentry *debugfsdir;
249
250 char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
251};
252
253/** struct wireless_dev - wireless per-netdev state
254 *
255 * This structure must be allocated by the driver/stack
256 * that uses the ieee80211_ptr field in struct net_device
257 * (this is intentional so it can be allocated along with
258 * the netdev.)
259 *
260 * @wiphy: pointer to hardware description
Johannes Berg60719ff2008-09-16 14:55:09 +0200261 * @iftype: interface type
Johannes Berg704232c2007-04-23 12:20:05 -0700262 */
263struct wireless_dev {
264 struct wiphy *wiphy;
Johannes Berg60719ff2008-09-16 14:55:09 +0200265 enum nl80211_iftype iftype;
Johannes Berg704232c2007-04-23 12:20:05 -0700266
267 /* private to the generic wireless code */
268 struct list_head list;
269 struct net_device *netdev;
270};
271
272/**
273 * wiphy_priv - return priv from wiphy
274 */
275static inline void *wiphy_priv(struct wiphy *wiphy)
276{
277 BUG_ON(!wiphy);
278 return &wiphy->priv;
279}
280
281/**
282 * set_wiphy_dev - set device pointer for wiphy
283 */
284static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
285{
286 wiphy->dev.parent = dev;
287}
288
289/**
290 * wiphy_dev - get wiphy dev pointer
291 */
292static inline struct device *wiphy_dev(struct wiphy *wiphy)
293{
294 return wiphy->dev.parent;
295}
296
297/**
298 * wiphy_name - get wiphy name
299 */
Kay Sieversfb28ad32008-11-10 13:55:14 -0800300static inline const char *wiphy_name(struct wiphy *wiphy)
Johannes Berg704232c2007-04-23 12:20:05 -0700301{
Kay Sieversfb28ad32008-11-10 13:55:14 -0800302 return dev_name(&wiphy->dev);
Johannes Berg704232c2007-04-23 12:20:05 -0700303}
304
305/**
306 * wdev_priv - return wiphy priv from wireless_dev
307 */
308static inline void *wdev_priv(struct wireless_dev *wdev)
309{
310 BUG_ON(!wdev);
311 return wiphy_priv(wdev->wiphy);
312}
313
314/**
315 * wiphy_new - create a new wiphy for use with cfg80211
316 *
317 * create a new wiphy and associate the given operations with it.
318 * @sizeof_priv bytes are allocated for private use.
319 *
320 * the returned pointer must be assigned to each netdev's
321 * ieee80211_ptr for proper operation.
322 */
323struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
324
325/**
326 * wiphy_register - register a wiphy with cfg80211
327 *
328 * register the given wiphy
329 *
330 * Returns a non-negative wiphy index or a negative error code.
331 */
332extern int wiphy_register(struct wiphy *wiphy);
333
334/**
335 * wiphy_unregister - deregister a wiphy from cfg80211
336 *
337 * unregister a device with the given priv pointer.
338 * After this call, no more requests can be made with this priv
339 * pointer, but the call may sleep to wait for an outstanding
340 * request that is being handled.
341 */
342extern void wiphy_unregister(struct wiphy *wiphy);
343
344/**
345 * wiphy_free - free wiphy
346 */
347extern void wiphy_free(struct wiphy *wiphy);
348
Johannes Berg8318d782008-01-24 19:38:38 +0100349/**
350 * ieee80211_channel_to_frequency - convert channel number to frequency
351 */
352extern int ieee80211_channel_to_frequency(int chan);
353
354/**
355 * ieee80211_frequency_to_channel - convert frequency to channel number
356 */
357extern int ieee80211_frequency_to_channel(int freq);
358
Johannes Berg6c507cd2008-03-26 14:14:55 +0100359/*
360 * Name indirection necessary because the ieee80211 code also has
361 * a function named "ieee80211_get_channel", so if you include
362 * cfg80211's header file you get cfg80211's version, if you try
363 * to include both header files you'll (rightfully!) get a symbol
364 * clash.
365 */
366extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
367 int freq);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700368/**
Johannes Berge07aa372008-09-15 13:11:19 +0200369 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
370 */
371static inline struct ieee80211_channel *
372ieee80211_get_channel(struct wiphy *wiphy, int freq)
373{
374 return __ieee80211_get_channel(wiphy, freq);
375}
376
377/**
Johannes Bergbd815252008-10-29 20:00:45 +0100378 * ieee80211_get_response_rate - get basic rate for a given rate
379 *
380 * @sband: the band to look for rates in
381 * @basic_rates: bitmap of basic rates
382 * @bitrate: the bitrate for which to find the basic rate
383 *
384 * This function returns the basic rate corresponding to a given
385 * bitrate, that is the next lower bitrate contained in the basic
386 * rate map, which is, for this function, given as a bitmap of
387 * indices of rates in the band's bitrate table.
388 */
389struct ieee80211_rate *
390ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +0100391 u32 basic_rates, int bitrate);
Johannes Bergbd815252008-10-29 20:00:45 +0100392
393/**
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700394 * regulatory_hint - driver hint to the wireless core a regulatory domain
Johannes Bergbe3d4812008-10-24 20:32:21 +0200395 * @wiphy: the wireless device giving the hint (used only for reporting
396 * conflicts)
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700397 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
398 * should be in. If @rd is set this should be NULL. Note that if you
399 * set this to NULL you should still set rd->alpha2 to some accepted
400 * alpha2.
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700401 *
402 * Wireless drivers can use this function to hint to the wireless core
403 * what it believes should be the current regulatory domain by
404 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
405 * domain should be in or by providing a completely build regulatory domain.
406 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
Johannes Bergbe3d4812008-10-24 20:32:21 +0200407 * for a regulatory domain structure for the respective country.
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -0500408 *
409 * The wiphy must have been registered to cfg80211 prior to this call.
410 * For cfg80211 drivers this means you must first use wiphy_register(),
411 * for mac80211 drivers you must first use ieee80211_register_hw().
412 *
413 * Drivers should check the return value, its possible you can get
414 * an -ENOMEM.
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700415 */
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -0500416extern int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -0800417
418/**
419 * regulatory_hint_11d - hints a country IE as a regulatory domain
420 * @wiphy: the wireless device giving the hint (used only for reporting
421 * conflicts)
422 * @country_ie: pointer to the country IE
423 * @country_ie_len: length of the country IE
424 *
425 * We will intersect the rd with the what CRDA tells us should apply
426 * for the alpha2 this country IE belongs to, this prevents APs from
427 * sending us incorrect or outdated information against a country.
428 */
429extern void regulatory_hint_11d(struct wiphy *wiphy,
430 u8 *country_ie,
431 u8 country_ie_len);
Luis R. Rodriguez1fa25e42009-01-22 15:05:44 -0800432/**
433 * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
434 * @wiphy: the wireless device we want to process the regulatory domain on
435 * @regd: the custom regulatory domain to use for this wiphy
436 *
437 * Drivers can sometimes have custom regulatory domains which do not apply
438 * to a specific country. Drivers can use this to apply such custom regulatory
439 * domains. This routine must be called prior to wiphy registration. The
440 * custom regulatory domain will be trusted completely and as such previous
441 * default channel settings will be disregarded. If no rule is found for a
442 * channel on the regulatory domain the channel will be disabled.
443 */
444extern void wiphy_apply_custom_regulatory(
445 struct wiphy *wiphy,
446 const struct ieee80211_regdomain *regd);
447
Luis R. Rodriguez34f57342009-01-22 15:05:45 -0800448/**
449 * freq_reg_info - get regulatory information for the given frequency
450 * @wiphy: the wiphy for which we want to process this rule for
451 * @center_freq: Frequency in KHz for which we want regulatory information for
452 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
453 * you can set this to 0. If this frequency is allowed we then set
454 * this value to the maximum allowed bandwidth.
455 * @reg_rule: the regulatory rule which we have for this frequency
456 *
457 * Use this function to get the regulatory rule for a specific frequency on
458 * a given wireless device. If the device has a specific regulatory domain
459 * it wants to follow we respect that unless a country IE has been received
460 * and processed already.
461 *
462 * Returns 0 if it was able to find a valid regulatory rule which does
463 * apply to the given center_freq otherwise it returns non-zero. It will
464 * also return -ERANGE if we determine the given center_freq does not even have
465 * a regulatory rule for a frequency range in the center_freq's band. See
466 * freq_in_rule_band() for our current definition of a band -- this is purely
467 * subjective and right now its 802.11 specific.
468 */
469extern int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth,
470 const struct ieee80211_reg_rule **reg_rule);
471
Johannes Berg704232c2007-04-23 12:20:05 -0700472#endif /* __NET_WIRELESS_H */