blob: 0de7fde9f336870983ef42ae151512dc2ddaf80e [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>
13#include <net/cfg80211.h>
14
15/**
Johannes Berg8318d782008-01-24 19:38:38 +010016 * 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 */
24enum 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.
Emmanuel Grumbach93061022008-05-29 16:35:23 +080042 * @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.
Johannes Berg8318d782008-01-24 19:38:38 +010046 */
47enum 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,
Emmanuel Grumbach93061022008-05-29 16:35:23 +080052 IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4,
53 IEEE80211_CHAN_NO_FAT_BELOW = 1<<5,
Johannes Berg8318d782008-01-24 19:38:38 +010054};
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
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070063 * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
Johannes Berg8318d782008-01-24 19:38:38 +010064 * @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 */
74struct ieee80211_channel {
75 enum ieee80211_band band;
76 u16 center_freq;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070077 u8 max_bandwidth;
Johannes Berg8318d782008-01-24 19:38:38 +010078 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 */
107enum 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 */
129struct 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 */
147struct 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 */
170struct 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/**
Johannes Berg704232c2007-04-23 12:20:05 -0700180 * 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>
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700183 * @reg_notifier: the driver's regulatory notification callback
Johannes Berg704232c2007-04-23 12:20:05 -0700184 */
185struct wiphy {
186 /* assign these fields before you register the wiphy */
187
188 /* permanent MAC address */
189 u8 perm_addr[ETH_ALEN];
190
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700191 /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
192 u16 interface_modes;
193
Johannes Berg704232c2007-04-23 12:20:05 -0700194 /* 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
Johannes Berg8318d782008-01-24 19:38:38 +0100201 struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
202
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700203 /* Lets us get back the wiphy on the callback */
204 int (*reg_notifier)(struct wiphy *wiphy, enum reg_set_by setby);
205
Johannes Berg704232c2007-04-23 12:20:05 -0700206 /* 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 */
227struct 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 */
238static 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 */
247static 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 */
255static inline struct device *wiphy_dev(struct wiphy *wiphy)
256{
257 return wiphy->dev.parent;
258}
259
260/**
261 * wiphy_name - get wiphy name
262 */
263static 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 */
271static 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 */
286struct 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 */
295extern 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 */
305extern void wiphy_unregister(struct wiphy *wiphy);
306
307/**
308 * wiphy_free - free wiphy
309 */
310extern void wiphy_free(struct wiphy *wiphy);
311
Johannes Berg8318d782008-01-24 19:38:38 +0100312/**
313 * ieee80211_channel_to_frequency - convert channel number to frequency
314 */
315extern int ieee80211_channel_to_frequency(int chan);
316
317/**
318 * ieee80211_frequency_to_channel - convert frequency to channel number
319 */
320extern int ieee80211_frequency_to_channel(int freq);
321
Johannes Berg6c507cd2008-03-26 14:14:55 +0100322/*
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 */
329extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
330 int freq);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700331/**
Johannes Berge07aa372008-09-15 13:11:19 +0200332 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
333 */
334static inline struct ieee80211_channel *
335ieee80211_get_channel(struct wiphy *wiphy, int freq)
336{
337 return __ieee80211_get_channel(wiphy, freq);
338}
339
340/**
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700341 * __regulatory_hint - hint to the wireless core a regulatory domain
342 * @wiphy: if a driver is providing the hint this is the driver's very
343 * own &struct wiphy
344 * @alpha2: the ISO/IEC 3166 alpha2 being claimed the regulatory domain
345 * should be in. If @rd is set this should be NULL
346 * @rd: a complete regulatory domain, if passed the caller need not worry
347 * about freeing it
348 *
349 * The Wireless subsystem can use this function to hint to the wireless core
350 * what it believes should be the current regulatory domain by
351 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
352 * domain should be in or by providing a completely build regulatory domain.
353 *
354 * Returns -EALREADY if *a regulatory domain* has already been set. Note that
355 * this could be by another driver. It is safe for drivers to continue if
356 * -EALREADY is returned, if drivers are not capable of world roaming they
357 * should not register more channels than they support. Right now we only
358 * support listening to the first driver hint. If the driver is capable
359 * of world roaming but wants to respect its own EEPROM mappings for
360 * specific regulatory domains it should register the @reg_notifier callback
361 * on the &struct wiphy. Returns 0 if the hint went through fine or through an
362 * intersection operation. Otherwise a standard error code is returned.
363 *
364 */
365extern int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
366 const char *alpha2, struct ieee80211_regdomain *rd);
367/**
368 * regulatory_hint - driver hint to the wireless core a regulatory domain
369 * @wiphy: the driver's very own &struct wiphy
370 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
371 * should be in. If @rd is set this should be NULL. Note that if you
372 * set this to NULL you should still set rd->alpha2 to some accepted
373 * alpha2.
374 * @rd: a complete regulatory domain provided by the driver. If passed
375 * the driver does not need to worry about freeing it.
376 *
377 * Wireless drivers can use this function to hint to the wireless core
378 * what it believes should be the current regulatory domain by
379 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
380 * domain should be in or by providing a completely build regulatory domain.
381 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
382 * for a regulatory domain structure for the respective country. If
383 * a regulatory domain is build and passed you should set the alpha2
384 * if possible, otherwise set it to the special value of "99" which tells
385 * the wireless core it is unknown. If you pass a built regulatory domain
386 * and we return non zero you are in charge of kfree()'ing the structure.
387 *
388 * See __regulatory_hint() documentation for possible return values.
389 */
390extern int regulatory_hint(struct wiphy *wiphy,
391 const char *alpha2, struct ieee80211_regdomain *rd);
Johannes Berg704232c2007-04-23 12:20:05 -0700392#endif /* __NET_WIRELESS_H */