blob: 6e3ea015904515a357e9ace887b0c19e9521ecc0 [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)
72 * @orig_mag: internal use
73 * @orig_mpwr: internal use
74 */
75struct ieee80211_channel {
76 enum ieee80211_band band;
77 u16 center_freq;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070078 u8 max_bandwidth;
Johannes Berg8318d782008-01-24 19:38:38 +010079 u16 hw_value;
80 u32 flags;
81 int max_antenna_gain;
82 int max_power;
83 u32 orig_flags;
84 int orig_mag, orig_mpwr;
85};
86
87/**
88 * enum ieee80211_rate_flags - rate flags
89 *
90 * Hardware/specification flags for rates. These are structured
91 * in a way that allows using the same bitrate structure for
92 * different bands/PHY modes.
93 *
94 * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
95 * preamble on this bitrate; only relevant in 2.4GHz band and
96 * with CCK rates.
97 * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
98 * when used with 802.11a (on the 5 GHz band); filled by the
99 * core code when registering the wiphy.
100 * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
101 * when used with 802.11b (on the 2.4 GHz band); filled by the
102 * core code when registering the wiphy.
103 * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
104 * when used with 802.11g (on the 2.4 GHz band); filled by the
105 * core code when registering the wiphy.
106 * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
107 */
108enum ieee80211_rate_flags {
109 IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
110 IEEE80211_RATE_MANDATORY_A = 1<<1,
111 IEEE80211_RATE_MANDATORY_B = 1<<2,
112 IEEE80211_RATE_MANDATORY_G = 1<<3,
113 IEEE80211_RATE_ERP_G = 1<<4,
114};
115
116/**
117 * struct ieee80211_rate - bitrate definition
118 *
119 * This structure describes a bitrate that an 802.11 PHY can
120 * operate with. The two values @hw_value and @hw_value_short
121 * are only for driver use when pointers to this structure are
122 * passed around.
123 *
124 * @flags: rate-specific flags
125 * @bitrate: bitrate in units of 100 Kbps
126 * @hw_value: driver/hardware value for this rate
127 * @hw_value_short: driver/hardware value for this rate when
128 * short preamble is used
129 */
130struct ieee80211_rate {
131 u32 flags;
132 u16 bitrate;
133 u16 hw_value, hw_value_short;
134};
135
136/**
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200137 * struct ieee80211_sta_ht_cap - STA's HT capabilities
Johannes Berg8318d782008-01-24 19:38:38 +0100138 *
139 * This structure describes most essential parameters needed
140 * to describe 802.11n HT capabilities for an STA.
141 *
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200142 * @ht_supported: is HT supported by the STA
Johannes Berg8318d782008-01-24 19:38:38 +0100143 * @cap: HT capabilities map as described in 802.11n spec
144 * @ampdu_factor: Maximum A-MPDU length factor
145 * @ampdu_density: Minimum A-MPDU spacing
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200146 * @mcs: Supported MCS rates
Johannes Berg8318d782008-01-24 19:38:38 +0100147 */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200148struct ieee80211_sta_ht_cap {
Johannes Berg8318d782008-01-24 19:38:38 +0100149 u16 cap; /* use IEEE80211_HT_CAP_ */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200150 bool ht_supported;
Johannes Berg8318d782008-01-24 19:38:38 +0100151 u8 ampdu_factor;
152 u8 ampdu_density;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200153 struct ieee80211_mcs_info mcs;
Johannes Berg8318d782008-01-24 19:38:38 +0100154};
155
156/**
157 * struct ieee80211_supported_band - frequency band definition
158 *
159 * This structure describes a frequency band a wiphy
160 * is able to operate in.
161 *
162 * @channels: Array of channels the hardware can operate in
163 * in this band.
164 * @band: the band this structure represents
165 * @n_channels: Number of channels in @channels
166 * @bitrates: Array of bitrates the hardware can operate with
167 * in this band. Must be sorted to give a valid "supported
168 * rates" IE, i.e. CCK rates first, then OFDM.
169 * @n_bitrates: Number of bitrates in @bitrates
170 */
171struct ieee80211_supported_band {
172 struct ieee80211_channel *channels;
173 struct ieee80211_rate *bitrates;
174 enum ieee80211_band band;
175 int n_channels;
176 int n_bitrates;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200177 struct ieee80211_sta_ht_cap ht_cap;
Johannes Berg8318d782008-01-24 19:38:38 +0100178};
179
180/**
Johannes Berg704232c2007-04-23 12:20:05 -0700181 * struct wiphy - wireless hardware description
182 * @idx: the wiphy index assigned to this item
183 * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700184 * @reg_notifier: the driver's regulatory notification callback
Johannes Berg704232c2007-04-23 12:20:05 -0700185 */
186struct wiphy {
187 /* assign these fields before you register the wiphy */
188
189 /* permanent MAC address */
190 u8 perm_addr[ETH_ALEN];
191
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700192 /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
193 u16 interface_modes;
194
Johannes Berg704232c2007-04-23 12:20:05 -0700195 /* If multiple wiphys are registered and you're handed e.g.
196 * a regular netdev with assigned ieee80211_ptr, you won't
197 * know whether it points to a wiphy your driver has registered
198 * or not. Assign this to something global to your driver to
199 * help determine whether you own this wiphy or not. */
200 void *privid;
201
Johannes Berg8318d782008-01-24 19:38:38 +0100202 struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
203
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700204 /* Lets us get back the wiphy on the callback */
205 int (*reg_notifier)(struct wiphy *wiphy, enum reg_set_by setby);
206
Johannes Berg704232c2007-04-23 12:20:05 -0700207 /* fields below are read-only, assigned by cfg80211 */
208
209 /* the item in /sys/class/ieee80211/ points to this,
210 * you need use set_wiphy_dev() (see below) */
211 struct device dev;
212
213 /* dir in debugfs: ieee80211/<wiphyname> */
214 struct dentry *debugfsdir;
215
216 char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
217};
218
219/** struct wireless_dev - wireless per-netdev state
220 *
221 * This structure must be allocated by the driver/stack
222 * that uses the ieee80211_ptr field in struct net_device
223 * (this is intentional so it can be allocated along with
224 * the netdev.)
225 *
226 * @wiphy: pointer to hardware description
Johannes Berg60719ff2008-09-16 14:55:09 +0200227 * @iftype: interface type
Johannes Berg704232c2007-04-23 12:20:05 -0700228 */
229struct wireless_dev {
230 struct wiphy *wiphy;
Johannes Berg60719ff2008-09-16 14:55:09 +0200231 enum nl80211_iftype iftype;
Johannes Berg704232c2007-04-23 12:20:05 -0700232
233 /* private to the generic wireless code */
234 struct list_head list;
235 struct net_device *netdev;
236};
237
238/**
239 * wiphy_priv - return priv from wiphy
240 */
241static inline void *wiphy_priv(struct wiphy *wiphy)
242{
243 BUG_ON(!wiphy);
244 return &wiphy->priv;
245}
246
247/**
248 * set_wiphy_dev - set device pointer for wiphy
249 */
250static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
251{
252 wiphy->dev.parent = dev;
253}
254
255/**
256 * wiphy_dev - get wiphy dev pointer
257 */
258static inline struct device *wiphy_dev(struct wiphy *wiphy)
259{
260 return wiphy->dev.parent;
261}
262
263/**
264 * wiphy_name - get wiphy name
265 */
266static inline char *wiphy_name(struct wiphy *wiphy)
267{
268 return wiphy->dev.bus_id;
269}
270
271/**
272 * wdev_priv - return wiphy priv from wireless_dev
273 */
274static inline void *wdev_priv(struct wireless_dev *wdev)
275{
276 BUG_ON(!wdev);
277 return wiphy_priv(wdev->wiphy);
278}
279
280/**
281 * wiphy_new - create a new wiphy for use with cfg80211
282 *
283 * create a new wiphy and associate the given operations with it.
284 * @sizeof_priv bytes are allocated for private use.
285 *
286 * the returned pointer must be assigned to each netdev's
287 * ieee80211_ptr for proper operation.
288 */
289struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
290
291/**
292 * wiphy_register - register a wiphy with cfg80211
293 *
294 * register the given wiphy
295 *
296 * Returns a non-negative wiphy index or a negative error code.
297 */
298extern int wiphy_register(struct wiphy *wiphy);
299
300/**
301 * wiphy_unregister - deregister a wiphy from cfg80211
302 *
303 * unregister a device with the given priv pointer.
304 * After this call, no more requests can be made with this priv
305 * pointer, but the call may sleep to wait for an outstanding
306 * request that is being handled.
307 */
308extern void wiphy_unregister(struct wiphy *wiphy);
309
310/**
311 * wiphy_free - free wiphy
312 */
313extern void wiphy_free(struct wiphy *wiphy);
314
Johannes Berg8318d782008-01-24 19:38:38 +0100315/**
316 * ieee80211_channel_to_frequency - convert channel number to frequency
317 */
318extern int ieee80211_channel_to_frequency(int chan);
319
320/**
321 * ieee80211_frequency_to_channel - convert frequency to channel number
322 */
323extern int ieee80211_frequency_to_channel(int freq);
324
Johannes Berg6c507cd2008-03-26 14:14:55 +0100325/*
326 * Name indirection necessary because the ieee80211 code also has
327 * a function named "ieee80211_get_channel", so if you include
328 * cfg80211's header file you get cfg80211's version, if you try
329 * to include both header files you'll (rightfully!) get a symbol
330 * clash.
331 */
332extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
333 int freq);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700334/**
Johannes Berge07aa372008-09-15 13:11:19 +0200335 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
336 */
337static inline struct ieee80211_channel *
338ieee80211_get_channel(struct wiphy *wiphy, int freq)
339{
340 return __ieee80211_get_channel(wiphy, freq);
341}
342
343/**
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700344 * regulatory_hint - driver hint to the wireless core a regulatory domain
345 * @wiphy: the driver's very own &struct wiphy
346 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
347 * should be in. If @rd is set this should be NULL. Note that if you
348 * set this to NULL you should still set rd->alpha2 to some accepted
349 * alpha2.
350 * @rd: a complete regulatory domain provided by the driver. If passed
351 * the driver does not need to worry about freeing it.
352 *
353 * Wireless drivers can use this function to hint to the wireless core
354 * what it believes should be the current regulatory domain by
355 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
356 * domain should be in or by providing a completely build regulatory domain.
357 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
358 * for a regulatory domain structure for the respective country. If
359 * a regulatory domain is build and passed you should set the alpha2
360 * if possible, otherwise set it to the special value of "99" which tells
Johannes Bergd2372b32008-10-24 20:32:20 +0200361 * the wireless core it is unknown.
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700362 *
Johannes Bergcf032682008-10-21 09:42:38 +0200363 * Returns -EALREADY if *a regulatory domain* has already been set. Note that
364 * this could be by another driver. It is safe for drivers to continue if
365 * -EALREADY is returned, if drivers are not capable of world roaming they
366 * should not register more channels than they support. Right now we only
367 * support listening to the first driver hint. If the driver is capable
368 * of world roaming but wants to respect its own EEPROM mappings for
369 * specific regulatory domains it should register the @reg_notifier callback
370 * on the &struct wiphy. Returns 0 if the hint went through fine or through an
371 * intersection operation. Otherwise a standard error code is returned.
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700372 */
373extern int regulatory_hint(struct wiphy *wiphy,
374 const char *alpha2, struct ieee80211_regdomain *rd);
Johannes Berg704232c2007-04-23 12:20:05 -0700375#endif /* __NET_WIRELESS_H */