blob: 0b5f2df29f0287f5f1bef916e17143ccae467ad4 [file] [log] [blame]
Johannes Berg370121e2006-01-04 16:32:16 +01001#ifndef IEEE80211SOFTMAC_H_
2#define IEEE80211SOFTMAC_H_
3
4#include <linux/kernel.h>
5#include <linux/spinlock.h>
6#include <linux/workqueue.h>
7#include <linux/list.h>
8#include <net/ieee80211.h>
9
10/* Once the API is considered more or less stable,
11 * this should be incremented on API incompatible changes.
12 */
13#define IEEE80211SOFTMAC_API 0
14
15#define IEEE80211SOFTMAC_MAX_RATES_LEN 8
16#define IEEE80211SOFTMAC_MAX_EX_RATES_LEN 255
17
18struct ieee80211softmac_ratesinfo {
19 u8 count;
20 u8 rates[IEEE80211SOFTMAC_MAX_RATES_LEN + IEEE80211SOFTMAC_MAX_EX_RATES_LEN];
21};
22
23/* internal structures */
24struct ieee80211softmac_network;
25struct ieee80211softmac_scaninfo;
26
27struct ieee80211softmac_essid {
28 u8 len;
29 char data[IW_ESSID_MAX_SIZE+1];
30};
31
32struct ieee80211softmac_wpa {
33 char *IE;
34 int IElen;
35 int IEbuflen;
36};
37
38/*
39 * Information about association
40 *
41 * Do we need a lock for this?
42 * We only ever use this structure inlined
43 * into our global struct. I've used its lock,
44 * but maybe we need a local one here?
45 */
46struct ieee80211softmac_assoc_info {
47 /*
48 * This is the requested ESSID. It is written
49 * only by the WX handlers.
50 *
51 */
52 struct ieee80211softmac_essid req_essid;
53 /*
54 * the ESSID of the network we're currently
55 * associated (or trying) to. This is
56 * updated to the network's actual ESSID
57 * even if the requested ESSID was 'ANY'
58 */
59 struct ieee80211softmac_essid associate_essid;
60
61 /* BSSID we're trying to associate to */
62 char bssid[ETH_ALEN];
63
64 /* some flags.
65 * static_essid is valid if the essid is constant,
66 * this is for use by the wx handlers only.
67 *
68 * associating is true, if the network has been
69 * auth'ed on and we are in the process of associating.
70 *
71 * bssvalid is true if we found a matching network
72 * and saved it's BSSID into the bssid above.
73 */
74 u8 static_essid:1,
75 associating:1,
76 bssvalid:1;
77
78 /* Scan retries remaining */
79 int scan_retry;
80
81 struct work_struct work;
82 struct work_struct timeout;
83};
84
85enum {
86 IEEE80211SOFTMAC_AUTH_OPEN_REQUEST = 1,
87 IEEE80211SOFTMAC_AUTH_OPEN_RESPONSE = 2,
88};
89
90enum {
91 IEEE80211SOFTMAC_AUTH_SHARED_REQUEST = 1,
92 IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE = 2,
93 IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE = 3,
94 IEEE80211SOFTMAC_AUTH_SHARED_PASS = 4,
95};
96
97/* We should make these tunable
98 * AUTH_TIMEOUT seems really long, but that's what it is in BSD */
99#define IEEE80211SOFTMAC_AUTH_TIMEOUT (12 * HZ)
100#define IEEE80211SOFTMAC_AUTH_RETRY_LIMIT 5
101#define IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT 3
102
103struct ieee80211softmac_txrates {
104 /* The Bit-Rate to be used for multicast frames. */
105 u8 mcast_rate;
106 /* The Bit-Rate to be used for multicast fallback
107 * (If the device supports fallback and hardware-retry)
108 */
109 u8 mcast_fallback;
110 /* The Bit-Rate to be used for any other (normal) data packet. */
111 u8 default_rate;
112 /* The Bit-Rate to be used for default fallback
113 * (If the device supports fallback and hardware-retry)
114 */
115 u8 default_fallback;
116};
117
118/* Bits for txrates_change callback. */
119#define IEEE80211SOFTMAC_TXRATECHG_DEFAULT (1 << 0) /* default_rate */
120#define IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK (1 << 1) /* default_fallback */
121#define IEEE80211SOFTMAC_TXRATECHG_MCAST (1 << 2) /* mcast_rate */
122#define IEEE80211SOFTMAC_TXRATECHG_MCAST_FBACK (1 << 3) /* mcast_fallback */
123
124struct ieee80211softmac_device {
125 /* 802.11 structure for data stuff */
126 struct ieee80211_device *ieee;
127 struct net_device *dev;
128
129 /* only valid if associated, then holds the Association ID */
130 u16 association_id;
131
132 /* the following methods are callbacks that the driver
133 * using this framework has to assign
134 */
135
136 /* always assign these */
137 void (*set_bssid_filter)(struct net_device *dev, const u8 *bssid);
138 void (*set_channel)(struct net_device *dev, u8 channel);
139
140 /* assign if you need it, informational only */
141 void (*link_change)(struct net_device *dev);
142
143 /* If the hardware can do scanning, assign _all_ three of these callbacks.
144 * When the scan finishes, call ieee80211softmac_scan_finished().
145 */
146
147 /* when called, start_scan is guaranteed to not be called again
148 * until you call ieee80211softmac_scan_finished.
149 * Return 0 if scanning could start, error otherwise.
150 * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_start_scan */
151 int (*start_scan)(struct net_device *dev);
152 /* this should block until after ieee80211softmac_scan_finished was called
153 * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_wait_for_scan */
154 void (*wait_for_scan)(struct net_device *dev);
155 /* stop_scan aborts a scan, but is asynchronous.
156 * if you want to wait for it too, use wait_for_scan
157 * SOFTMAC AUTHORS: don't call this, use ieee80211softmac_stop_scan */
158 void (*stop_scan)(struct net_device *dev);
159
160 /* we'll need something about beacons here too, for AP or ad-hoc modes */
161
162 /* Transmission rates to be used by the driver.
163 * The SoftMAC figures out the best possible rates.
164 * The driver just needs to read them.
165 */
166 struct ieee80211softmac_txrates txrates;
167 /* If the driver needs to do stuff on TX rate changes, assign this callback. */
168 void (*txrates_change)(struct net_device *dev,
169 u32 changes, /* see IEEE80211SOFTMAC_TXRATECHG flags */
170 const struct ieee80211softmac_txrates *rates_before_change);
171
172 /* private stuff follows */
173 /* this lock protects this structure */
174 spinlock_t lock;
175
176 /* couple of flags */
177 u8 scanning:1, /* protects scanning from being done multiple times at once */
178 associated:1;
179
180 /* workquere for scannning, ... */
181 struct workqueue_struct *workqueue;
182
183 struct ieee80211softmac_scaninfo *scaninfo;
184 struct ieee80211softmac_assoc_info associnfo;
185
186 struct list_head auth_queue;
187 struct list_head events;
188
189 struct ieee80211softmac_ratesinfo ratesinfo;
190 int txrate_badness;
191
192 /* WPA stuff */
193 struct ieee80211softmac_wpa wpa;
194
195 /* we need to keep a list of network structs we copied */
196 struct list_head network_list;
197
198 /* This must be the last item so that it points to the data
199 * allocated beyond this structure by alloc_ieee80211 */
200 u8 priv[0];
201};
202
203extern void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm);
204
205static inline void * ieee80211softmac_priv(struct net_device *dev)
206{
207 return ((struct ieee80211softmac_device *)ieee80211_priv(dev))->priv;
208}
209
210extern struct net_device * alloc_ieee80211softmac(int sizeof_priv);
211extern void free_ieee80211softmac(struct net_device *dev);
212
213/* Call this function if you detect a lost TX fragment.
214 * (If the device indicates failure of ACK RX, for example.)
215 * It is wise to call this function if you are able to detect lost packets,
216 * because it contributes to the TX Rates auto adjustment.
217 */
218extern void ieee80211softmac_fragment_lost(struct net_device *dev,
219 u16 wireless_sequence_number);
220/* Call this function before _start to tell the softmac what rates
221 * the hw supports. The rates parameter is copied, so you can
222 * free it right after calling this function.
223 * Note that the rates need to be sorted. */
224extern void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates);
225
226/* Start the SoftMAC. Call this after you initialized the device
227 * and it is ready to run.
228 */
229extern void ieee80211softmac_start(struct net_device *dev);
230/* Stop the SoftMAC. Call this before you shutdown the device. */
231extern void ieee80211softmac_stop(struct net_device *dev);
232
233/*
234 * Event system
235 */
236
237/* valid event types */
238#define IEEE80211SOFTMAC_EVENT_ANY -1 /*private use only*/
239#define IEEE80211SOFTMAC_EVENT_SCAN_FINISHED 0
240#define IEEE80211SOFTMAC_EVENT_ASSOCIATED 1
241#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED 2
242#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT 3
243#define IEEE80211SOFTMAC_EVENT_AUTHENTICATED 4
244#define IEEE80211SOFTMAC_EVENT_AUTH_FAILED 5
245#define IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT 6
246#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND 7
247/* keep this updated! */
248#define IEEE80211SOFTMAC_EVENT_LAST 7
249/*
250 * If you want to be notified of certain events, you can call
251 * ieee80211softmac_notify[_atomic] with
252 * - event set to one of the constants below
253 * - fun set to a function pointer of the appropriate type
254 * - context set to the context data you want passed
255 * The return value is 0, or an error.
256 */
257typedef void (*notify_function_ptr)(struct net_device *dev, void *context);
258
259#define ieee80211softmac_notify(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_KERNEL);
260#define ieee80211softmac_notify_atomic(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_ATOMIC);
261
262extern int ieee80211softmac_notify_gfp(struct net_device *dev,
263 int event, notify_function_ptr fun, void *context, gfp_t gfp_mask);
264
265/* To clear pending work (for ifconfig down, etc.) */
266extern void
267ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm);
268
269#endif /* IEEE80211SOFTMAC_H_ */