Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6 into lvs-next-2.6
[linux-2.6] / 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  * @hw_value: hardware-specific value for the channel
64  * @flags: channel flags from &enum ieee80211_channel_flags.
65  * @orig_flags: channel flags at registration time, used by regulatory
66  *      code to support devices with additional restrictions
67  * @band: band this channel belongs to.
68  * @max_antenna_gain: maximum antenna gain in dBi
69  * @max_power: maximum transmission power (in dBm)
70  * @orig_mag: internal use
71  * @orig_mpwr: internal use
72  */
73 struct ieee80211_channel {
74         enum ieee80211_band band;
75         u16 center_freq;
76         u16 hw_value;
77         u32 flags;
78         int max_antenna_gain;
79         int max_power;
80         u32 orig_flags;
81         int orig_mag, orig_mpwr;
82 };
83
84 /**
85  * enum ieee80211_rate_flags - rate flags
86  *
87  * Hardware/specification flags for rates. These are structured
88  * in a way that allows using the same bitrate structure for
89  * different bands/PHY modes.
90  *
91  * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
92  *      preamble on this bitrate; only relevant in 2.4GHz band and
93  *      with CCK rates.
94  * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
95  *      when used with 802.11a (on the 5 GHz band); filled by the
96  *      core code when registering the wiphy.
97  * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
98  *      when used with 802.11b (on the 2.4 GHz band); filled by the
99  *      core code when registering the wiphy.
100  * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
101  *      when used with 802.11g (on the 2.4 GHz band); filled by the
102  *      core code when registering the wiphy.
103  * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
104  */
105 enum ieee80211_rate_flags {
106         IEEE80211_RATE_SHORT_PREAMBLE   = 1<<0,
107         IEEE80211_RATE_MANDATORY_A      = 1<<1,
108         IEEE80211_RATE_MANDATORY_B      = 1<<2,
109         IEEE80211_RATE_MANDATORY_G      = 1<<3,
110         IEEE80211_RATE_ERP_G            = 1<<4,
111 };
112
113 /**
114  * struct ieee80211_rate - bitrate definition
115  *
116  * This structure describes a bitrate that an 802.11 PHY can
117  * operate with. The two values @hw_value and @hw_value_short
118  * are only for driver use when pointers to this structure are
119  * passed around.
120  *
121  * @flags: rate-specific flags
122  * @bitrate: bitrate in units of 100 Kbps
123  * @hw_value: driver/hardware value for this rate
124  * @hw_value_short: driver/hardware value for this rate when
125  *      short preamble is used
126  */
127 struct ieee80211_rate {
128         u32 flags;
129         u16 bitrate;
130         u16 hw_value, hw_value_short;
131 };
132
133 /**
134  * struct ieee80211_ht_info - describing STA's HT capabilities
135  *
136  * This structure describes most essential parameters needed
137  * to describe 802.11n HT capabilities for an STA.
138  *
139  * @ht_supported: is HT supported by STA, 0: no, 1: yes
140  * @cap: HT capabilities map as described in 802.11n spec
141  * @ampdu_factor: Maximum A-MPDU length factor
142  * @ampdu_density: Minimum A-MPDU spacing
143  * @supp_mcs_set: Supported MCS set as described in 802.11n spec
144  */
145 struct ieee80211_ht_info {
146         u16 cap; /* use IEEE80211_HT_CAP_ */
147         u8 ht_supported;
148         u8 ampdu_factor;
149         u8 ampdu_density;
150         u8 supp_mcs_set[16];
151 };
152
153 /**
154  * struct ieee80211_supported_band - frequency band definition
155  *
156  * This structure describes a frequency band a wiphy
157  * is able to operate in.
158  *
159  * @channels: Array of channels the hardware can operate in
160  *      in this band.
161  * @band: the band this structure represents
162  * @n_channels: Number of channels in @channels
163  * @bitrates: Array of bitrates the hardware can operate with
164  *      in this band. Must be sorted to give a valid "supported
165  *      rates" IE, i.e. CCK rates first, then OFDM.
166  * @n_bitrates: Number of bitrates in @bitrates
167  */
168 struct ieee80211_supported_band {
169         struct ieee80211_channel *channels;
170         struct ieee80211_rate *bitrates;
171         enum ieee80211_band band;
172         int n_channels;
173         int n_bitrates;
174         struct ieee80211_ht_info ht_info;
175 };
176
177 /**
178  * struct wiphy - wireless hardware description
179  * @idx: the wiphy index assigned to this item
180  * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
181  */
182 struct wiphy {
183         /* assign these fields before you register the wiphy */
184
185         /* permanent MAC address */
186         u8 perm_addr[ETH_ALEN];
187
188         /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
189         u16 interface_modes;
190
191         /* If multiple wiphys are registered and you're handed e.g.
192          * a regular netdev with assigned ieee80211_ptr, you won't
193          * know whether it points to a wiphy your driver has registered
194          * or not. Assign this to something global to your driver to
195          * help determine whether you own this wiphy or not. */
196         void *privid;
197
198         struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
199
200         /* fields below are read-only, assigned by cfg80211 */
201
202         /* the item in /sys/class/ieee80211/ points to this,
203          * you need use set_wiphy_dev() (see below) */
204         struct device dev;
205
206         /* dir in debugfs: ieee80211/<wiphyname> */
207         struct dentry *debugfsdir;
208
209         char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
210 };
211
212 /** struct wireless_dev - wireless per-netdev state
213  *
214  * This structure must be allocated by the driver/stack
215  * that uses the ieee80211_ptr field in struct net_device
216  * (this is intentional so it can be allocated along with
217  * the netdev.)
218  *
219  * @wiphy: pointer to hardware description
220  */
221 struct wireless_dev {
222         struct wiphy *wiphy;
223
224         /* private to the generic wireless code */
225         struct list_head list;
226         struct net_device *netdev;
227 };
228
229 /**
230  * wiphy_priv - return priv from wiphy
231  */
232 static inline void *wiphy_priv(struct wiphy *wiphy)
233 {
234         BUG_ON(!wiphy);
235         return &wiphy->priv;
236 }
237
238 /**
239  * set_wiphy_dev - set device pointer for wiphy
240  */
241 static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
242 {
243         wiphy->dev.parent = dev;
244 }
245
246 /**
247  * wiphy_dev - get wiphy dev pointer
248  */
249 static inline struct device *wiphy_dev(struct wiphy *wiphy)
250 {
251         return wiphy->dev.parent;
252 }
253
254 /**
255  * wiphy_name - get wiphy name
256  */
257 static inline char *wiphy_name(struct wiphy *wiphy)
258 {
259         return wiphy->dev.bus_id;
260 }
261
262 /**
263  * wdev_priv - return wiphy priv from wireless_dev
264  */
265 static inline void *wdev_priv(struct wireless_dev *wdev)
266 {
267         BUG_ON(!wdev);
268         return wiphy_priv(wdev->wiphy);
269 }
270
271 /**
272  * wiphy_new - create a new wiphy for use with cfg80211
273  *
274  * create a new wiphy and associate the given operations with it.
275  * @sizeof_priv bytes are allocated for private use.
276  *
277  * the returned pointer must be assigned to each netdev's
278  * ieee80211_ptr for proper operation.
279  */
280 struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
281
282 /**
283  * wiphy_register - register a wiphy with cfg80211
284  *
285  * register the given wiphy
286  *
287  * Returns a non-negative wiphy index or a negative error code.
288  */
289 extern int wiphy_register(struct wiphy *wiphy);
290
291 /**
292  * wiphy_unregister - deregister a wiphy from cfg80211
293  *
294  * unregister a device with the given priv pointer.
295  * After this call, no more requests can be made with this priv
296  * pointer, but the call may sleep to wait for an outstanding
297  * request that is being handled.
298  */
299 extern void wiphy_unregister(struct wiphy *wiphy);
300
301 /**
302  * wiphy_free - free wiphy
303  */
304 extern void wiphy_free(struct wiphy *wiphy);
305
306 /**
307  * ieee80211_channel_to_frequency - convert channel number to frequency
308  */
309 extern int ieee80211_channel_to_frequency(int chan);
310
311 /**
312  * ieee80211_frequency_to_channel - convert frequency to channel number
313  */
314 extern int ieee80211_frequency_to_channel(int freq);
315
316 /*
317  * Name indirection necessary because the ieee80211 code also has
318  * a function named "ieee80211_get_channel", so if you include
319  * cfg80211's header file you get cfg80211's version, if you try
320  * to include both header files you'll (rightfully!) get a symbol
321  * clash.
322  */
323 extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
324                                                          int freq);
325
326 /**
327  * ieee80211_get_channel - get channel struct from wiphy for specified frequency
328  */
329 static inline struct ieee80211_channel *
330 ieee80211_get_channel(struct wiphy *wiphy, int freq)
331 {
332         return __ieee80211_get_channel(wiphy, freq);
333 }
334 #endif /* __NET_WIRELESS_H */