Merge branches 'topic/asoc', 'topic/misc-fixes' and 'topic/hda' into for-linus
[deliverable/linux.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 * @iftype: interface type
227 */
228 struct wireless_dev {
229 struct wiphy *wiphy;
230 enum nl80211_iftype iftype;
231
232 /* private to the generic wireless code */
233 struct list_head list;
234 struct net_device *netdev;
235 };
236
237 /**
238 * wiphy_priv - return priv from wiphy
239 */
240 static inline void *wiphy_priv(struct wiphy *wiphy)
241 {
242 BUG_ON(!wiphy);
243 return &wiphy->priv;
244 }
245
246 /**
247 * set_wiphy_dev - set device pointer for wiphy
248 */
249 static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
250 {
251 wiphy->dev.parent = dev;
252 }
253
254 /**
255 * wiphy_dev - get wiphy dev pointer
256 */
257 static inline struct device *wiphy_dev(struct wiphy *wiphy)
258 {
259 return wiphy->dev.parent;
260 }
261
262 /**
263 * wiphy_name - get wiphy name
264 */
265 static inline char *wiphy_name(struct wiphy *wiphy)
266 {
267 return wiphy->dev.bus_id;
268 }
269
270 /**
271 * wdev_priv - return wiphy priv from wireless_dev
272 */
273 static inline void *wdev_priv(struct wireless_dev *wdev)
274 {
275 BUG_ON(!wdev);
276 return wiphy_priv(wdev->wiphy);
277 }
278
279 /**
280 * wiphy_new - create a new wiphy for use with cfg80211
281 *
282 * create a new wiphy and associate the given operations with it.
283 * @sizeof_priv bytes are allocated for private use.
284 *
285 * the returned pointer must be assigned to each netdev's
286 * ieee80211_ptr for proper operation.
287 */
288 struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
289
290 /**
291 * wiphy_register - register a wiphy with cfg80211
292 *
293 * register the given wiphy
294 *
295 * Returns a non-negative wiphy index or a negative error code.
296 */
297 extern int wiphy_register(struct wiphy *wiphy);
298
299 /**
300 * wiphy_unregister - deregister a wiphy from cfg80211
301 *
302 * unregister a device with the given priv pointer.
303 * After this call, no more requests can be made with this priv
304 * pointer, but the call may sleep to wait for an outstanding
305 * request that is being handled.
306 */
307 extern void wiphy_unregister(struct wiphy *wiphy);
308
309 /**
310 * wiphy_free - free wiphy
311 */
312 extern void wiphy_free(struct wiphy *wiphy);
313
314 /**
315 * ieee80211_channel_to_frequency - convert channel number to frequency
316 */
317 extern int ieee80211_channel_to_frequency(int chan);
318
319 /**
320 * ieee80211_frequency_to_channel - convert frequency to channel number
321 */
322 extern int ieee80211_frequency_to_channel(int freq);
323
324 /*
325 * Name indirection necessary because the ieee80211 code also has
326 * a function named "ieee80211_get_channel", so if you include
327 * cfg80211's header file you get cfg80211's version, if you try
328 * to include both header files you'll (rightfully!) get a symbol
329 * clash.
330 */
331 extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
332 int freq);
333 /**
334 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
335 */
336 static inline struct ieee80211_channel *
337 ieee80211_get_channel(struct wiphy *wiphy, int freq)
338 {
339 return __ieee80211_get_channel(wiphy, freq);
340 }
341
342 /**
343 * __regulatory_hint - hint to the wireless core a regulatory domain
344 * @wiphy: if a driver is providing the hint this is the driver's very
345 * own &struct wiphy
346 * @alpha2: the ISO/IEC 3166 alpha2 being claimed the regulatory domain
347 * should be in. If @rd is set this should be NULL
348 * @rd: a complete regulatory domain, if passed the caller need not worry
349 * about freeing it
350 *
351 * The Wireless subsystem can use this function to hint to the wireless core
352 * what it believes should be the current regulatory domain by
353 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
354 * domain should be in or by providing a completely build regulatory domain.
355 *
356 * Returns -EALREADY if *a regulatory domain* has already been set. Note that
357 * this could be by another driver. It is safe for drivers to continue if
358 * -EALREADY is returned, if drivers are not capable of world roaming they
359 * should not register more channels than they support. Right now we only
360 * support listening to the first driver hint. If the driver is capable
361 * of world roaming but wants to respect its own EEPROM mappings for
362 * specific regulatory domains it should register the @reg_notifier callback
363 * on the &struct wiphy. Returns 0 if the hint went through fine or through an
364 * intersection operation. Otherwise a standard error code is returned.
365 *
366 */
367 extern int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
368 const char *alpha2, struct ieee80211_regdomain *rd);
369 /**
370 * regulatory_hint - driver hint to the wireless core a regulatory domain
371 * @wiphy: the driver's very own &struct wiphy
372 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
373 * should be in. If @rd is set this should be NULL. Note that if you
374 * set this to NULL you should still set rd->alpha2 to some accepted
375 * alpha2.
376 * @rd: a complete regulatory domain provided by the driver. If passed
377 * the driver does not need to worry about freeing it.
378 *
379 * Wireless drivers can use this function to hint to the wireless core
380 * what it believes should be the current regulatory domain by
381 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
382 * domain should be in or by providing a completely build regulatory domain.
383 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
384 * for a regulatory domain structure for the respective country. If
385 * a regulatory domain is build and passed you should set the alpha2
386 * if possible, otherwise set it to the special value of "99" which tells
387 * the wireless core it is unknown. If you pass a built regulatory domain
388 * and we return non zero you are in charge of kfree()'ing the structure.
389 *
390 * See __regulatory_hint() documentation for possible return values.
391 */
392 extern int regulatory_hint(struct wiphy *wiphy,
393 const char *alpha2, struct ieee80211_regdomain *rd);
394 #endif /* __NET_WIRELESS_H */
This page took 0.047419 seconds and 6 git commands to generate.