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