blob: 00ad810eb883090add39c82b60fd130cf97452c0 [file] [log] [blame]
Johannes Berg4855d252006-01-12 21:12:59 +01001/*
2 * ieee80211softmac.h - public interface to the softmac
3 *
4 * Copyright (c) 2005 Johannes Berg <johannes@sipsolutions.net>
5 * Joseph Jezak <josejx@gentoo.org>
6 * Larry Finger <Larry.Finger@lwfinger.net>
7 * Danny van Dyk <kugelfang@gentoo.org>
8 * Michael Buesch <mbuesch@freenet.de>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 *
23 * The full GNU General Public License is included in this distribution in the
24 * file called COPYING.
25 */
26
Johannes Berg370121e2006-01-04 16:32:16 +010027#ifndef IEEE80211SOFTMAC_H_
28#define IEEE80211SOFTMAC_H_
29
30#include <linux/kernel.h>
31#include <linux/spinlock.h>
32#include <linux/workqueue.h>
33#include <linux/list.h>
34#include <net/ieee80211.h>
35
36/* Once the API is considered more or less stable,
37 * this should be incremented on API incompatible changes.
38 */
39#define IEEE80211SOFTMAC_API 0
40
41#define IEEE80211SOFTMAC_MAX_RATES_LEN 8
42#define IEEE80211SOFTMAC_MAX_EX_RATES_LEN 255
43
44struct ieee80211softmac_ratesinfo {
45 u8 count;
46 u8 rates[IEEE80211SOFTMAC_MAX_RATES_LEN + IEEE80211SOFTMAC_MAX_EX_RATES_LEN];
47};
48
49/* internal structures */
50struct ieee80211softmac_network;
51struct ieee80211softmac_scaninfo;
52
53struct ieee80211softmac_essid {
54 u8 len;
55 char data[IW_ESSID_MAX_SIZE+1];
56};
57
58struct ieee80211softmac_wpa {
59 char *IE;
60 int IElen;
61 int IEbuflen;
62};
63
64/*
65 * Information about association
66 *
67 * Do we need a lock for this?
68 * We only ever use this structure inlined
69 * into our global struct. I've used its lock,
70 * but maybe we need a local one here?
71 */
72struct ieee80211softmac_assoc_info {
73 /*
74 * This is the requested ESSID. It is written
75 * only by the WX handlers.
76 *
77 */
78 struct ieee80211softmac_essid req_essid;
79 /*
80 * the ESSID of the network we're currently
81 * associated (or trying) to. This is
82 * updated to the network's actual ESSID
83 * even if the requested ESSID was 'ANY'
84 */
85 struct ieee80211softmac_essid associate_essid;
86
87 /* BSSID we're trying to associate to */
88 char bssid[ETH_ALEN];
Daniel Drake8462fe32006-05-01 22:45:50 +010089
90 /* Rates supported by the network */
91 struct ieee80211softmac_ratesinfo supported_rates;
Johannes Berg370121e2006-01-04 16:32:16 +010092
93 /* some flags.
94 * static_essid is valid if the essid is constant,
95 * this is for use by the wx handlers only.
96 *
97 * associating is true, if the network has been
98 * auth'ed on and we are in the process of associating.
99 *
100 * bssvalid is true if we found a matching network
101 * and saved it's BSSID into the bssid above.
Johannes Berg818667f2006-04-20 20:02:03 +0200102 *
103 * bssfixed is used for SIOCSIWAP.
Johannes Berg370121e2006-01-04 16:32:16 +0100104 */
105 u8 static_essid:1,
106 associating:1,
Joseph Jezakcb74c432006-06-11 12:00:37 -0400107 assoc_wait:1,
Johannes Berg818667f2006-04-20 20:02:03 +0200108 bssvalid:1,
109 bssfixed:1;
Johannes Berg370121e2006-01-04 16:32:16 +0100110
111 /* Scan retries remaining */
112 int scan_retry;
113
114 struct work_struct work;
115 struct work_struct timeout;
116};
117
118enum {
119 IEEE80211SOFTMAC_AUTH_OPEN_REQUEST = 1,
120 IEEE80211SOFTMAC_AUTH_OPEN_RESPONSE = 2,
121};
122
123enum {
124 IEEE80211SOFTMAC_AUTH_SHARED_REQUEST = 1,
125 IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE = 2,
126 IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE = 3,
127 IEEE80211SOFTMAC_AUTH_SHARED_PASS = 4,
128};
129
130/* We should make these tunable
131 * AUTH_TIMEOUT seems really long, but that's what it is in BSD */
132#define IEEE80211SOFTMAC_AUTH_TIMEOUT (12 * HZ)
133#define IEEE80211SOFTMAC_AUTH_RETRY_LIMIT 5
134#define IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT 3
135
136struct ieee80211softmac_txrates {
137 /* The Bit-Rate to be used for multicast frames. */
138 u8 mcast_rate;
Daniel Drake8462fe32006-05-01 22:45:50 +0100139
140 /* The Bit-Rate to be used for multicast management frames. */
141 u8 mgt_mcast_rate;
142
Johannes Berg370121e2006-01-04 16:32:16 +0100143 /* The Bit-Rate to be used for any other (normal) data packet. */
144 u8 default_rate;
145 /* The Bit-Rate to be used for default fallback
146 * (If the device supports fallback and hardware-retry)
147 */
148 u8 default_fallback;
Daniel Drake8462fe32006-05-01 22:45:50 +0100149
150 /* This is the rate that the user asked for */
151 u8 user_rate;
Johannes Berg370121e2006-01-04 16:32:16 +0100152};
153
154/* Bits for txrates_change callback. */
155#define IEEE80211SOFTMAC_TXRATECHG_DEFAULT (1 << 0) /* default_rate */
156#define IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK (1 << 1) /* default_fallback */
157#define IEEE80211SOFTMAC_TXRATECHG_MCAST (1 << 2) /* mcast_rate */
Daniel Drake8462fe32006-05-01 22:45:50 +0100158#define IEEE80211SOFTMAC_TXRATECHG_MGT_MCAST (1 << 3) /* mgt_mcast_rate */
Johannes Berg370121e2006-01-04 16:32:16 +0100159
160struct ieee80211softmac_device {
161 /* 802.11 structure for data stuff */
162 struct ieee80211_device *ieee;
163 struct net_device *dev;
164
165 /* only valid if associated, then holds the Association ID */
166 u16 association_id;
167
168 /* the following methods are callbacks that the driver
169 * using this framework has to assign
170 */
171
172 /* always assign these */
173 void (*set_bssid_filter)(struct net_device *dev, const u8 *bssid);
174 void (*set_channel)(struct net_device *dev, u8 channel);
175
176 /* assign if you need it, informational only */
177 void (*link_change)(struct net_device *dev);
178
179 /* If the hardware can do scanning, assign _all_ three of these callbacks.
180 * When the scan finishes, call ieee80211softmac_scan_finished().
181 */
182
183 /* when called, start_scan is guaranteed to not be called again
184 * until you call ieee80211softmac_scan_finished.
185 * Return 0 if scanning could start, error otherwise.
186 * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_start_scan */
187 int (*start_scan)(struct net_device *dev);
188 /* this should block until after ieee80211softmac_scan_finished was called
189 * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_wait_for_scan */
190 void (*wait_for_scan)(struct net_device *dev);
191 /* stop_scan aborts a scan, but is asynchronous.
192 * if you want to wait for it too, use wait_for_scan
193 * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_stop_scan */
194 void (*stop_scan)(struct net_device *dev);
195
196 /* we'll need something about beacons here too, for AP or ad-hoc modes */
197
198 /* Transmission rates to be used by the driver.
199 * The SoftMAC figures out the best possible rates.
200 * The driver just needs to read them.
201 */
202 struct ieee80211softmac_txrates txrates;
203 /* If the driver needs to do stuff on TX rate changes, assign this callback. */
204 void (*txrates_change)(struct net_device *dev,
205 u32 changes, /* see IEEE80211SOFTMAC_TXRATECHG flags */
206 const struct ieee80211softmac_txrates *rates_before_change);
207
208 /* private stuff follows */
209 /* this lock protects this structure */
210 spinlock_t lock;
211
212 /* couple of flags */
213 u8 scanning:1, /* protects scanning from being done multiple times at once */
Daniel Draked57336e2006-04-30 22:09:07 +0100214 associated:1,
215 running:1;
Johannes Berg370121e2006-01-04 16:32:16 +0100216
Johannes Berg370121e2006-01-04 16:32:16 +0100217 struct ieee80211softmac_scaninfo *scaninfo;
218 struct ieee80211softmac_assoc_info associnfo;
219
220 struct list_head auth_queue;
221 struct list_head events;
222
223 struct ieee80211softmac_ratesinfo ratesinfo;
224 int txrate_badness;
225
226 /* WPA stuff */
227 struct ieee80211softmac_wpa wpa;
228
229 /* we need to keep a list of network structs we copied */
230 struct list_head network_list;
231
232 /* This must be the last item so that it points to the data
233 * allocated beyond this structure by alloc_ieee80211 */
234 u8 priv[0];
235};
236
237extern void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm);
238
239static inline void * ieee80211softmac_priv(struct net_device *dev)
240{
241 return ((struct ieee80211softmac_device *)ieee80211_priv(dev))->priv;
242}
243
244extern struct net_device * alloc_ieee80211softmac(int sizeof_priv);
245extern void free_ieee80211softmac(struct net_device *dev);
246
247/* Call this function if you detect a lost TX fragment.
248 * (If the device indicates failure of ACK RX, for example.)
249 * It is wise to call this function if you are able to detect lost packets,
250 * because it contributes to the TX Rates auto adjustment.
251 */
252extern void ieee80211softmac_fragment_lost(struct net_device *dev,
253 u16 wireless_sequence_number);
254/* Call this function before _start to tell the softmac what rates
255 * the hw supports. The rates parameter is copied, so you can
256 * free it right after calling this function.
257 * Note that the rates need to be sorted. */
258extern void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates);
259
Daniel Drake8462fe32006-05-01 22:45:50 +0100260/* Helper function which advises you the rate at which a frame should be
261 * transmitted at. */
262static inline u8 ieee80211softmac_suggest_txrate(struct ieee80211softmac_device *mac,
263 int is_multicast,
264 int is_mgt)
265{
266 struct ieee80211softmac_txrates *txrates = &mac->txrates;
267
268 if (!mac->associated)
269 return txrates->mgt_mcast_rate;
270
271 /* We are associated, sending unicast frame */
272 if (!is_multicast)
273 return txrates->default_rate;
274
275 /* We are associated, sending multicast frame */
276 if (is_mgt)
277 return txrates->mgt_mcast_rate;
278 else
279 return txrates->mcast_rate;
280}
281
Johannes Berg370121e2006-01-04 16:32:16 +0100282/* Start the SoftMAC. Call this after you initialized the device
283 * and it is ready to run.
284 */
285extern void ieee80211softmac_start(struct net_device *dev);
286/* Stop the SoftMAC. Call this before you shutdown the device. */
287extern void ieee80211softmac_stop(struct net_device *dev);
288
289/*
290 * Event system
291 */
292
293/* valid event types */
294#define IEEE80211SOFTMAC_EVENT_ANY -1 /*private use only*/
295#define IEEE80211SOFTMAC_EVENT_SCAN_FINISHED 0
296#define IEEE80211SOFTMAC_EVENT_ASSOCIATED 1
297#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED 2
298#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT 3
299#define IEEE80211SOFTMAC_EVENT_AUTHENTICATED 4
300#define IEEE80211SOFTMAC_EVENT_AUTH_FAILED 5
301#define IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT 6
302#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND 7
Johannes Bergfeeeaa82006-04-13 02:42:42 +0200303#define IEEE80211SOFTMAC_EVENT_DISASSOCIATED 8
Johannes Berg370121e2006-01-04 16:32:16 +0100304/* keep this updated! */
Johannes Bergfeeeaa82006-04-13 02:42:42 +0200305#define IEEE80211SOFTMAC_EVENT_LAST 8
Johannes Berg370121e2006-01-04 16:32:16 +0100306/*
307 * If you want to be notified of certain events, you can call
308 * ieee80211softmac_notify[_atomic] with
309 * - event set to one of the constants below
310 * - fun set to a function pointer of the appropriate type
311 * - context set to the context data you want passed
312 * The return value is 0, or an error.
313 */
Daniel Drake6ae15df2006-06-01 15:37:22 +0100314typedef void (*notify_function_ptr)(struct net_device *dev, int event_type, void *context);
Johannes Berg370121e2006-01-04 16:32:16 +0100315
316#define ieee80211softmac_notify(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_KERNEL);
317#define ieee80211softmac_notify_atomic(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_ATOMIC);
318
319extern int ieee80211softmac_notify_gfp(struct net_device *dev,
320 int event, notify_function_ptr fun, void *context, gfp_t gfp_mask);
321
322/* To clear pending work (for ifconfig down, etc.) */
323extern void
324ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm);
325
326#endif /* IEEE80211SOFTMAC_H_ */