Commit | Line | Data |
---|---|---|
704232c2 JB |
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> | |
d9fe60de | 13 | #include <linux/ieee80211.h> |
704232c2 JB |
14 | #include <net/cfg80211.h> |
15 | ||
8318d78a JB |
16 | /** |
17 | * 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 | */ | |
25 | enum 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. | |
9306102e EG |
43 | * @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. | |
8318d78a JB |
47 | */ |
48 | enum 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, | |
9306102e EG |
53 | IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4, |
54 | IEEE80211_CHAN_NO_FAT_BELOW = 1<<5, | |
8318d78a JB |
55 | }; |
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 | |
b2e1b302 | 64 | * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz |
8318d78a JB |
65 | * @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 | */ | |
75 | struct ieee80211_channel { | |
76 | enum ieee80211_band band; | |
77 | u16 center_freq; | |
b2e1b302 | 78 | u8 max_bandwidth; |
8318d78a JB |
79 | 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 | */ | |
108 | enum 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 | */ | |
130 | struct ieee80211_rate { | |
131 | u32 flags; | |
132 | u16 bitrate; | |
133 | u16 hw_value, hw_value_short; | |
134 | }; | |
135 | ||
136 | /** | |
d9fe60de | 137 | * struct ieee80211_sta_ht_cap - STA's HT capabilities |
8318d78a JB |
138 | * |
139 | * This structure describes most essential parameters needed | |
140 | * to describe 802.11n HT capabilities for an STA. | |
141 | * | |
d9fe60de | 142 | * @ht_supported: is HT supported by the STA |
8318d78a JB |
143 | * @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 | |
d9fe60de | 146 | * @mcs: Supported MCS rates |
8318d78a | 147 | */ |
d9fe60de | 148 | struct ieee80211_sta_ht_cap { |
8318d78a | 149 | u16 cap; /* use IEEE80211_HT_CAP_ */ |
d9fe60de | 150 | bool ht_supported; |
8318d78a JB |
151 | u8 ampdu_factor; |
152 | u8 ampdu_density; | |
d9fe60de | 153 | struct ieee80211_mcs_info mcs; |
8318d78a JB |
154 | }; |
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 | */ | |
171 | struct 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; | |
d9fe60de | 177 | struct ieee80211_sta_ht_cap ht_cap; |
8318d78a JB |
178 | }; |
179 | ||
704232c2 JB |
180 | /** |
181 | * 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> | |
14b9815a LR |
184 | * @fw_handles_regulatory: tells us the firmware for this device |
185 | * has its own regulatory solution and cannot identify the | |
186 | * ISO / IEC 3166 alpha2 it belongs to. When this is enabled | |
187 | * we will disregard the first regulatory hint (when the | |
188 | * initiator is %REGDOM_SET_BY_CORE). | |
b2e1b302 | 189 | * @reg_notifier: the driver's regulatory notification callback |
704232c2 JB |
190 | */ |
191 | struct wiphy { | |
192 | /* assign these fields before you register the wiphy */ | |
193 | ||
194 | /* permanent MAC address */ | |
195 | u8 perm_addr[ETH_ALEN]; | |
196 | ||
f59ac048 LR |
197 | /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */ |
198 | u16 interface_modes; | |
199 | ||
14b9815a LR |
200 | bool fw_handles_regulatory; |
201 | ||
704232c2 JB |
202 | /* If multiple wiphys are registered and you're handed e.g. |
203 | * a regular netdev with assigned ieee80211_ptr, you won't | |
204 | * know whether it points to a wiphy your driver has registered | |
205 | * or not. Assign this to something global to your driver to | |
206 | * help determine whether you own this wiphy or not. */ | |
207 | void *privid; | |
208 | ||
8318d78a JB |
209 | struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS]; |
210 | ||
b2e1b302 LR |
211 | /* Lets us get back the wiphy on the callback */ |
212 | int (*reg_notifier)(struct wiphy *wiphy, enum reg_set_by setby); | |
213 | ||
704232c2 JB |
214 | /* fields below are read-only, assigned by cfg80211 */ |
215 | ||
216 | /* the item in /sys/class/ieee80211/ points to this, | |
217 | * you need use set_wiphy_dev() (see below) */ | |
218 | struct device dev; | |
219 | ||
220 | /* dir in debugfs: ieee80211/<wiphyname> */ | |
221 | struct dentry *debugfsdir; | |
222 | ||
223 | char priv[0] __attribute__((__aligned__(NETDEV_ALIGN))); | |
224 | }; | |
225 | ||
226 | /** struct wireless_dev - wireless per-netdev state | |
227 | * | |
228 | * This structure must be allocated by the driver/stack | |
229 | * that uses the ieee80211_ptr field in struct net_device | |
230 | * (this is intentional so it can be allocated along with | |
231 | * the netdev.) | |
232 | * | |
233 | * @wiphy: pointer to hardware description | |
60719ffd | 234 | * @iftype: interface type |
704232c2 JB |
235 | */ |
236 | struct wireless_dev { | |
237 | struct wiphy *wiphy; | |
60719ffd | 238 | enum nl80211_iftype iftype; |
704232c2 JB |
239 | |
240 | /* private to the generic wireless code */ | |
241 | struct list_head list; | |
242 | struct net_device *netdev; | |
243 | }; | |
244 | ||
245 | /** | |
246 | * wiphy_priv - return priv from wiphy | |
247 | */ | |
248 | static inline void *wiphy_priv(struct wiphy *wiphy) | |
249 | { | |
250 | BUG_ON(!wiphy); | |
251 | return &wiphy->priv; | |
252 | } | |
253 | ||
254 | /** | |
255 | * set_wiphy_dev - set device pointer for wiphy | |
256 | */ | |
257 | static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev) | |
258 | { | |
259 | wiphy->dev.parent = dev; | |
260 | } | |
261 | ||
262 | /** | |
263 | * wiphy_dev - get wiphy dev pointer | |
264 | */ | |
265 | static inline struct device *wiphy_dev(struct wiphy *wiphy) | |
266 | { | |
267 | return wiphy->dev.parent; | |
268 | } | |
269 | ||
270 | /** | |
271 | * wiphy_name - get wiphy name | |
272 | */ | |
fb28ad35 | 273 | static inline const char *wiphy_name(struct wiphy *wiphy) |
704232c2 | 274 | { |
fb28ad35 | 275 | return dev_name(&wiphy->dev); |
704232c2 JB |
276 | } |
277 | ||
278 | /** | |
279 | * wdev_priv - return wiphy priv from wireless_dev | |
280 | */ | |
281 | static inline void *wdev_priv(struct wireless_dev *wdev) | |
282 | { | |
283 | BUG_ON(!wdev); | |
284 | return wiphy_priv(wdev->wiphy); | |
285 | } | |
286 | ||
287 | /** | |
288 | * wiphy_new - create a new wiphy for use with cfg80211 | |
289 | * | |
290 | * create a new wiphy and associate the given operations with it. | |
291 | * @sizeof_priv bytes are allocated for private use. | |
292 | * | |
293 | * the returned pointer must be assigned to each netdev's | |
294 | * ieee80211_ptr for proper operation. | |
295 | */ | |
296 | struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv); | |
297 | ||
298 | /** | |
299 | * wiphy_register - register a wiphy with cfg80211 | |
300 | * | |
301 | * register the given wiphy | |
302 | * | |
303 | * Returns a non-negative wiphy index or a negative error code. | |
304 | */ | |
305 | extern int wiphy_register(struct wiphy *wiphy); | |
306 | ||
307 | /** | |
308 | * wiphy_unregister - deregister a wiphy from cfg80211 | |
309 | * | |
310 | * unregister a device with the given priv pointer. | |
311 | * After this call, no more requests can be made with this priv | |
312 | * pointer, but the call may sleep to wait for an outstanding | |
313 | * request that is being handled. | |
314 | */ | |
315 | extern void wiphy_unregister(struct wiphy *wiphy); | |
316 | ||
317 | /** | |
318 | * wiphy_free - free wiphy | |
319 | */ | |
320 | extern void wiphy_free(struct wiphy *wiphy); | |
321 | ||
8318d78a JB |
322 | /** |
323 | * ieee80211_channel_to_frequency - convert channel number to frequency | |
324 | */ | |
325 | extern int ieee80211_channel_to_frequency(int chan); | |
326 | ||
327 | /** | |
328 | * ieee80211_frequency_to_channel - convert frequency to channel number | |
329 | */ | |
330 | extern int ieee80211_frequency_to_channel(int freq); | |
331 | ||
6c507cd0 JB |
332 | /* |
333 | * Name indirection necessary because the ieee80211 code also has | |
334 | * a function named "ieee80211_get_channel", so if you include | |
335 | * cfg80211's header file you get cfg80211's version, if you try | |
336 | * to include both header files you'll (rightfully!) get a symbol | |
337 | * clash. | |
338 | */ | |
339 | extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy, | |
340 | int freq); | |
e07aa378 JB |
341 | /** |
342 | * ieee80211_get_channel - get channel struct from wiphy for specified frequency | |
343 | */ | |
344 | static inline struct ieee80211_channel * | |
345 | ieee80211_get_channel(struct wiphy *wiphy, int freq) | |
346 | { | |
347 | return __ieee80211_get_channel(wiphy, freq); | |
348 | } | |
349 | ||
bd815252 JB |
350 | /** |
351 | * ieee80211_get_response_rate - get basic rate for a given rate | |
352 | * | |
353 | * @sband: the band to look for rates in | |
354 | * @basic_rates: bitmap of basic rates | |
355 | * @bitrate: the bitrate for which to find the basic rate | |
356 | * | |
357 | * This function returns the basic rate corresponding to a given | |
358 | * bitrate, that is the next lower bitrate contained in the basic | |
359 | * rate map, which is, for this function, given as a bitmap of | |
360 | * indices of rates in the band's bitrate table. | |
361 | */ | |
362 | struct ieee80211_rate * | |
363 | ieee80211_get_response_rate(struct ieee80211_supported_band *sband, | |
364 | u64 basic_rates, int bitrate); | |
365 | ||
b2e1b302 LR |
366 | /** |
367 | * regulatory_hint - driver hint to the wireless core a regulatory domain | |
be3d4810 JB |
368 | * @wiphy: the wireless device giving the hint (used only for reporting |
369 | * conflicts) | |
b2e1b302 LR |
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. | |
b2e1b302 LR |
374 | * |
375 | * Wireless drivers can use this function to hint to the wireless core | |
376 | * what it believes should be the current regulatory domain by | |
377 | * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory | |
378 | * domain should be in or by providing a completely build regulatory domain. | |
379 | * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried | |
be3d4810 | 380 | * for a regulatory domain structure for the respective country. |
b2e1b302 | 381 | */ |
be3d4810 | 382 | extern void regulatory_hint(struct wiphy *wiphy, const char *alpha2); |
3f2355cb LR |
383 | |
384 | /** | |
385 | * regulatory_hint_11d - hints a country IE as a regulatory domain | |
386 | * @wiphy: the wireless device giving the hint (used only for reporting | |
387 | * conflicts) | |
388 | * @country_ie: pointer to the country IE | |
389 | * @country_ie_len: length of the country IE | |
390 | * | |
391 | * We will intersect the rd with the what CRDA tells us should apply | |
392 | * for the alpha2 this country IE belongs to, this prevents APs from | |
393 | * sending us incorrect or outdated information against a country. | |
394 | */ | |
395 | extern void regulatory_hint_11d(struct wiphy *wiphy, | |
396 | u8 *country_ie, | |
397 | u8 country_ie_len); | |
704232c2 | 398 | #endif /* __NET_WIRELESS_H */ |