cfg80211: Add new wireless regulatory infrastructure
[pandora-kernel.git] / include / net / wireless.h
1 #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>
13 #include <net/cfg80211.h>
14
15 /**
16  * enum ieee80211_band - supported frequency bands
17  *
18  * The bands are assigned this way because the supported
19  * bitrates differ in these bands.
20  *
21  * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
22  * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
23  */
24 enum ieee80211_band {
25         IEEE80211_BAND_2GHZ,
26         IEEE80211_BAND_5GHZ,
27
28         /* keep last */
29         IEEE80211_NUM_BANDS
30 };
31
32 /**
33  * enum ieee80211_channel_flags - channel flags
34  *
35  * Channel flags set by the regulatory control code.
36  *
37  * @IEEE80211_CHAN_DISABLED: This channel is disabled.
38  * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
39  *      on this channel.
40  * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
41  * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
42  * @IEEE80211_CHAN_NO_FAT_ABOVE: extension channel above this channel
43  *      is not permitted.
44  * @IEEE80211_CHAN_NO_FAT_BELOW: extension channel below this channel
45  *      is not permitted.
46  */
47 enum ieee80211_channel_flags {
48         IEEE80211_CHAN_DISABLED         = 1<<0,
49         IEEE80211_CHAN_PASSIVE_SCAN     = 1<<1,
50         IEEE80211_CHAN_NO_IBSS          = 1<<2,
51         IEEE80211_CHAN_RADAR            = 1<<3,
52         IEEE80211_CHAN_NO_FAT_ABOVE     = 1<<4,
53         IEEE80211_CHAN_NO_FAT_BELOW     = 1<<5,
54 };
55
56 /**
57  * struct ieee80211_channel - channel definition
58  *
59  * This structure describes a single channel for use
60  * with cfg80211.
61  *
62  * @center_freq: center frequency in MHz
63  * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
64  * @hw_value: hardware-specific value for the channel
65  * @flags: channel flags from &enum ieee80211_channel_flags.
66  * @orig_flags: channel flags at registration time, used by regulatory
67  *      code to support devices with additional restrictions
68  * @band: band this channel belongs to.
69  * @max_antenna_gain: maximum antenna gain in dBi
70  * @max_power: maximum transmission power (in dBm)
71  * @orig_mag: internal use
72  * @orig_mpwr: internal use
73  */
74 struct ieee80211_channel {
75         enum ieee80211_band band;
76         u16 center_freq;
77         u8 max_bandwidth;
78         u16 hw_value;
79         u32 flags;
80         int max_antenna_gain;
81         int max_power;
82         u32 orig_flags;
83         int orig_mag, orig_mpwr;
84 };
85
86 /**
87  * enum ieee80211_rate_flags - rate flags
88  *
89  * Hardware/specification flags for rates. These are structured
90  * in a way that allows using the same bitrate structure for
91  * different bands/PHY modes.
92  *
93  * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
94  *      preamble on this bitrate; only relevant in 2.4GHz band and
95  *      with CCK rates.
96  * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
97  *      when used with 802.11a (on the 5 GHz band); filled by the
98  *      core code when registering the wiphy.
99  * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
100  *      when used with 802.11b (on the 2.4 GHz band); filled by the
101  *      core code when registering the wiphy.
102  * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
103  *      when used with 802.11g (on the 2.4 GHz band); filled by the
104  *      core code when registering the wiphy.
105  * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
106  */
107 enum ieee80211_rate_flags {
108         IEEE80211_RATE_SHORT_PREAMBLE   = 1<<0,
109         IEEE80211_RATE_MANDATORY_A      = 1<<1,
110         IEEE80211_RATE_MANDATORY_B      = 1<<2,
111         IEEE80211_RATE_MANDATORY_G      = 1<<3,
112         IEEE80211_RATE_ERP_G            = 1<<4,
113 };
114
115 /**
116  * struct ieee80211_rate - bitrate definition
117  *
118  * This structure describes a bitrate that an 802.11 PHY can
119  * operate with. The two values @hw_value and @hw_value_short
120  * are only for driver use when pointers to this structure are
121  * passed around.
122  *
123  * @flags: rate-specific flags
124  * @bitrate: bitrate in units of 100 Kbps
125  * @hw_value: driver/hardware value for this rate
126  * @hw_value_short: driver/hardware value for this rate when
127  *      short preamble is used
128  */
129 struct ieee80211_rate {
130         u32 flags;
131         u16 bitrate;
132         u16 hw_value, hw_value_short;
133 };
134
135 /**
136  * struct ieee80211_ht_info - describing STA's HT capabilities
137  *
138  * This structure describes most essential parameters needed
139  * to describe 802.11n HT capabilities for an STA.
140  *
141  * @ht_supported: is HT supported by STA, 0: no, 1: yes
142  * @cap: HT capabilities map as described in 802.11n spec
143  * @ampdu_factor: Maximum A-MPDU length factor
144  * @ampdu_density: Minimum A-MPDU spacing
145  * @supp_mcs_set: Supported MCS set as described in 802.11n spec
146  */
147 struct ieee80211_ht_info {
148         u16 cap; /* use IEEE80211_HT_CAP_ */
149         u8 ht_supported;
150         u8 ampdu_factor;
151         u8 ampdu_density;
152         u8 supp_mcs_set[16];
153 };
154
155 /**
156  * struct ieee80211_supported_band - frequency band definition
157  *
158  * This structure describes a frequency band a wiphy
159  * is able to operate in.
160  *
161  * @channels: Array of channels the hardware can operate in
162  *      in this band.
163  * @band: the band this structure represents
164  * @n_channels: Number of channels in @channels
165  * @bitrates: Array of bitrates the hardware can operate with
166  *      in this band. Must be sorted to give a valid "supported
167  *      rates" IE, i.e. CCK rates first, then OFDM.
168  * @n_bitrates: Number of bitrates in @bitrates
169  */
170 struct ieee80211_supported_band {
171         struct ieee80211_channel *channels;
172         struct ieee80211_rate *bitrates;
173         enum ieee80211_band band;
174         int n_channels;
175         int n_bitrates;
176         struct ieee80211_ht_info ht_info;
177 };
178
179 /**
180  * struct wiphy - wireless hardware description
181  * @idx: the wiphy index assigned to this item
182  * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
183  * @reg_notifier: the driver's regulatory notification callback
184  */
185 struct wiphy {
186         /* assign these fields before you register the wiphy */
187
188         /* permanent MAC address */
189         u8 perm_addr[ETH_ALEN];
190
191         /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
192         u16 interface_modes;
193
194         /* If multiple wiphys are registered and you're handed e.g.
195          * a regular netdev with assigned ieee80211_ptr, you won't
196          * know whether it points to a wiphy your driver has registered
197          * or not. Assign this to something global to your driver to
198          * help determine whether you own this wiphy or not. */
199         void *privid;
200
201         struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
202
203         /* Lets us get back the wiphy on the callback */
204         int (*reg_notifier)(struct wiphy *wiphy, enum reg_set_by setby);
205
206         /* fields below are read-only, assigned by cfg80211 */
207
208         /* the item in /sys/class/ieee80211/ points to this,
209          * you need use set_wiphy_dev() (see below) */
210         struct device dev;
211
212         /* dir in debugfs: ieee80211/<wiphyname> */
213         struct dentry *debugfsdir;
214
215         char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
216 };
217
218 /** struct wireless_dev - wireless per-netdev state
219  *
220  * This structure must be allocated by the driver/stack
221  * that uses the ieee80211_ptr field in struct net_device
222  * (this is intentional so it can be allocated along with
223  * the netdev.)
224  *
225  * @wiphy: pointer to hardware description
226  */
227 struct wireless_dev {
228         struct wiphy *wiphy;
229
230         /* private to the generic wireless code */
231         struct list_head list;
232         struct net_device *netdev;
233 };
234
235 /**
236  * wiphy_priv - return priv from wiphy
237  */
238 static inline void *wiphy_priv(struct wiphy *wiphy)
239 {
240         BUG_ON(!wiphy);
241         return &wiphy->priv;
242 }
243
244 /**
245  * set_wiphy_dev - set device pointer for wiphy
246  */
247 static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
248 {
249         wiphy->dev.parent = dev;
250 }
251
252 /**
253  * wiphy_dev - get wiphy dev pointer
254  */
255 static inline struct device *wiphy_dev(struct wiphy *wiphy)
256 {
257         return wiphy->dev.parent;
258 }
259
260 /**
261  * wiphy_name - get wiphy name
262  */
263 static inline char *wiphy_name(struct wiphy *wiphy)
264 {
265         return wiphy->dev.bus_id;
266 }
267
268 /**
269  * wdev_priv - return wiphy priv from wireless_dev
270  */
271 static inline void *wdev_priv(struct wireless_dev *wdev)
272 {
273         BUG_ON(!wdev);
274         return wiphy_priv(wdev->wiphy);
275 }
276
277 /**
278  * wiphy_new - create a new wiphy for use with cfg80211
279  *
280  * create a new wiphy and associate the given operations with it.
281  * @sizeof_priv bytes are allocated for private use.
282  *
283  * the returned pointer must be assigned to each netdev's
284  * ieee80211_ptr for proper operation.
285  */
286 struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
287
288 /**
289  * wiphy_register - register a wiphy with cfg80211
290  *
291  * register the given wiphy
292  *
293  * Returns a non-negative wiphy index or a negative error code.
294  */
295 extern int wiphy_register(struct wiphy *wiphy);
296
297 /**
298  * wiphy_unregister - deregister a wiphy from cfg80211
299  *
300  * unregister a device with the given priv pointer.
301  * After this call, no more requests can be made with this priv
302  * pointer, but the call may sleep to wait for an outstanding
303  * request that is being handled.
304  */
305 extern void wiphy_unregister(struct wiphy *wiphy);
306
307 /**
308  * wiphy_free - free wiphy
309  */
310 extern void wiphy_free(struct wiphy *wiphy);
311
312 /**
313  * ieee80211_channel_to_frequency - convert channel number to frequency
314  */
315 extern int ieee80211_channel_to_frequency(int chan);
316
317 /**
318  * ieee80211_frequency_to_channel - convert frequency to channel number
319  */
320 extern int ieee80211_frequency_to_channel(int freq);
321
322 /*
323  * Name indirection necessary because the ieee80211 code also has
324  * a function named "ieee80211_get_channel", so if you include
325  * cfg80211's header file you get cfg80211's version, if you try
326  * to include both header files you'll (rightfully!) get a symbol
327  * clash.
328  */
329 extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
330                                                          int freq);
331 /**
332  * __regulatory_hint - hint to the wireless core a regulatory domain
333  * @wiphy: if a driver is providing the hint this is the driver's very
334  *      own &struct wiphy
335  * @alpha2: the ISO/IEC 3166 alpha2 being claimed the regulatory domain
336  *      should be in. If @rd is set this should be NULL
337  * @rd: a complete regulatory domain, if passed the caller need not worry
338  *      about freeing it
339  *
340  * The Wireless subsystem can use this function to hint to the wireless core
341  * what it believes should be the current regulatory domain by
342  * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
343  * domain should be in or by providing a completely build regulatory domain.
344  *
345  * Returns -EALREADY if *a regulatory domain* has already been set. Note that
346  * this could be by another driver. It is safe for drivers to continue if
347  * -EALREADY is returned, if drivers are not capable of world roaming they
348  * should not register more channels than they support. Right now we only
349  * support listening to the first driver hint. If the driver is capable
350  * of world roaming but wants to respect its own EEPROM mappings for
351  * specific regulatory domains it should register the @reg_notifier callback
352  * on the &struct wiphy. Returns 0 if the hint went through fine or through an
353  * intersection operation. Otherwise a standard error code is returned.
354  *
355  */
356 extern int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
357                 const char *alpha2, struct ieee80211_regdomain *rd);
358 /**
359  * regulatory_hint - driver hint to the wireless core a regulatory domain
360  * @wiphy: the driver's very own &struct wiphy
361  * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
362  *      should be in. If @rd is set this should be NULL. Note that if you
363  *      set this to NULL you should still set rd->alpha2 to some accepted
364  *      alpha2.
365  * @rd: a complete regulatory domain provided by the driver. If passed
366  *      the driver does not need to worry about freeing it.
367  *
368  * Wireless drivers can use this function to hint to the wireless core
369  * what it believes should be the current regulatory domain by
370  * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
371  * domain should be in or by providing a completely build regulatory domain.
372  * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
373  * for a regulatory domain structure for the respective country. If
374  * a regulatory domain is build and passed you should set the alpha2
375  * if possible, otherwise set it to the special value of "99" which tells
376  * the wireless core it is unknown. If you pass a built regulatory domain
377  * and we return non zero you are in charge of kfree()'ing the structure.
378  *
379  * See __regulatory_hint() documentation for possible return values.
380  */
381 extern int regulatory_hint(struct wiphy *wiphy,
382                 const char *alpha2, struct ieee80211_regdomain *rd);
383
384 /**
385  * ieee80211_get_channel - get channel struct from wiphy for specified frequency
386  */
387 static inline struct ieee80211_channel *
388 ieee80211_get_channel(struct wiphy *wiphy, int freq)
389 {
390         return __ieee80211_get_channel(wiphy, freq);
391 }
392 #endif /* __NET_WIRELESS_H */