]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * This file implement the Wireless Extensions APIs. | |
3 | * | |
4 | * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com> | |
c2805fbb | 5 | * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved. |
1da177e4 LT |
6 | * |
7 | * (As all part of the Linux kernel, this file is GPL) | |
8 | */ | |
9 | ||
10 | /************************** DOCUMENTATION **************************/ | |
11 | /* | |
12 | * API definition : | |
13 | * -------------- | |
14 | * See <linux/wireless.h> for details of the APIs and the rest. | |
15 | * | |
16 | * History : | |
17 | * ------- | |
18 | * | |
19 | * v1 - 5.12.01 - Jean II | |
20 | * o Created this file. | |
21 | * | |
22 | * v2 - 13.12.01 - Jean II | |
23 | * o Move /proc/net/wireless stuff from net/core/dev.c to here | |
24 | * o Make Wireless Extension IOCTLs go through here | |
25 | * o Added iw_handler handling ;-) | |
26 | * o Added standard ioctl description | |
27 | * o Initial dumb commit strategy based on orinoco.c | |
28 | * | |
29 | * v3 - 19.12.01 - Jean II | |
30 | * o Make sure we don't go out of standard_ioctl[] in ioctl_standard_call | |
31 | * o Add event dispatcher function | |
32 | * o Add event description | |
33 | * o Propagate events as rtnetlink IFLA_WIRELESS option | |
34 | * o Generate event on selected SET requests | |
35 | * | |
36 | * v4 - 18.04.02 - Jean II | |
37 | * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1 | |
38 | * | |
39 | * v5 - 21.06.02 - Jean II | |
40 | * o Add IW_PRIV_TYPE_ADDR in priv_type_size (+cleanup) | |
41 | * o Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes | |
42 | * o Add IWEVCUSTOM for driver specific event/scanning token | |
43 | * o Turn on WE_STRICT_WRITE by default + kernel warning | |
44 | * o Fix WE_STRICT_WRITE in ioctl_export_private() (32 => iw_num) | |
45 | * o Fix off-by-one in test (extra_size <= IFNAMSIZ) | |
46 | * | |
47 | * v6 - 9.01.03 - Jean II | |
48 | * o Add common spy support : iw_handler_set_spy(), wireless_spy_update() | |
49 | * o Add enhanced spy support : iw_handler_set_thrspy() and event. | |
50 | * o Add WIRELESS_EXT version display in /proc/net/wireless | |
51 | * | |
52 | * v6 - 18.06.04 - Jean II | |
53 | * o Change get_spydata() method for added safety | |
54 | * o Remove spy #ifdef, they are always on -> cleaner code | |
55 | * o Allow any size GET request if user specifies length > max | |
56 | * and if request has IW_DESCR_FLAG_NOMAX flag or is SIOCGIWPRIV | |
57 | * o Start migrating get_wireless_stats to struct iw_handler_def | |
58 | * o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus | |
59 | * Based on patch from Pavel Roskin <proski@gnu.org> : | |
60 | * o Fix kernel data leak to user space in private handler handling | |
6582c164 JT |
61 | * |
62 | * v7 - 18.3.05 - Jean II | |
63 | * o Remove (struct iw_point *)->pointer from events and streams | |
64 | * o Remove spy_offset from struct iw_handler_def | |
65 | * o Start deprecating dev->get_wireless_stats, output a warning | |
66 | * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless | |
67 | * o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats) | |
711e2c33 JT |
68 | * |
69 | * v8 - 17.02.06 - Jean II | |
70 | * o RtNetlink requests support (SET/GET) | |
baef1865 JL |
71 | * |
72 | * v8b - 03.08.06 - Herbert Xu | |
73 | * o Fix Wireless Event locking issues. | |
74 | * | |
75 | * v9 - 14.3.06 - Jean II | |
76 | * o Change length in ESSID and NICK to strlen() instead of strlen()+1 | |
77 | * o Make standard_ioctl_num and standard_event_num unsigned | |
78 | * o Remove (struct net_device *)->get_wireless_stats() | |
c2805fbb JT |
79 | * |
80 | * v10 - 16.3.07 - Jean II | |
81 | * o Prevent leaking of kernel space in stream on 64 bits. | |
1da177e4 LT |
82 | */ |
83 | ||
84 | /***************************** INCLUDES *****************************/ | |
85 | ||
1da177e4 LT |
86 | #include <linux/module.h> |
87 | #include <linux/types.h> /* off_t */ | |
88 | #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */ | |
89 | #include <linux/proc_fs.h> | |
90 | #include <linux/rtnetlink.h> /* rtnetlink stuff */ | |
91 | #include <linux/seq_file.h> | |
92 | #include <linux/init.h> /* for __init */ | |
93 | #include <linux/if_arp.h> /* ARPHRD_ETHER */ | |
9819d85c | 94 | #include <linux/etherdevice.h> /* compare_ether_addr */ |
782a6675 | 95 | #include <linux/interrupt.h> |
1da177e4 LT |
96 | |
97 | #include <linux/wireless.h> /* Pretty obvious */ | |
98 | #include <net/iw_handler.h> /* New driver API */ | |
bd5785ba | 99 | #include <net/netlink.h> |
295f4a1f | 100 | #include <net/wext.h> |
1da177e4 LT |
101 | |
102 | #include <asm/uaccess.h> /* copy_to_user() */ | |
103 | ||
1da177e4 LT |
104 | /************************* GLOBAL VARIABLES *************************/ |
105 | /* | |
106 | * You should not use global variables, because of re-entrancy. | |
107 | * On our case, it's only const, so it's OK... | |
108 | */ | |
109 | /* | |
110 | * Meta-data about all the standard Wireless Extension request we | |
111 | * know about. | |
112 | */ | |
113 | static const struct iw_ioctl_description standard_ioctl[] = { | |
114 | [SIOCSIWCOMMIT - SIOCIWFIRST] = { | |
115 | .header_type = IW_HEADER_TYPE_NULL, | |
116 | }, | |
117 | [SIOCGIWNAME - SIOCIWFIRST] = { | |
118 | .header_type = IW_HEADER_TYPE_CHAR, | |
119 | .flags = IW_DESCR_FLAG_DUMP, | |
120 | }, | |
121 | [SIOCSIWNWID - SIOCIWFIRST] = { | |
122 | .header_type = IW_HEADER_TYPE_PARAM, | |
123 | .flags = IW_DESCR_FLAG_EVENT, | |
124 | }, | |
125 | [SIOCGIWNWID - SIOCIWFIRST] = { | |
126 | .header_type = IW_HEADER_TYPE_PARAM, | |
127 | .flags = IW_DESCR_FLAG_DUMP, | |
128 | }, | |
129 | [SIOCSIWFREQ - SIOCIWFIRST] = { | |
130 | .header_type = IW_HEADER_TYPE_FREQ, | |
131 | .flags = IW_DESCR_FLAG_EVENT, | |
132 | }, | |
133 | [SIOCGIWFREQ - SIOCIWFIRST] = { | |
134 | .header_type = IW_HEADER_TYPE_FREQ, | |
135 | .flags = IW_DESCR_FLAG_DUMP, | |
136 | }, | |
137 | [SIOCSIWMODE - SIOCIWFIRST] = { | |
138 | .header_type = IW_HEADER_TYPE_UINT, | |
139 | .flags = IW_DESCR_FLAG_EVENT, | |
140 | }, | |
141 | [SIOCGIWMODE - SIOCIWFIRST] = { | |
142 | .header_type = IW_HEADER_TYPE_UINT, | |
143 | .flags = IW_DESCR_FLAG_DUMP, | |
144 | }, | |
145 | [SIOCSIWSENS - SIOCIWFIRST] = { | |
146 | .header_type = IW_HEADER_TYPE_PARAM, | |
147 | }, | |
148 | [SIOCGIWSENS - SIOCIWFIRST] = { | |
149 | .header_type = IW_HEADER_TYPE_PARAM, | |
150 | }, | |
151 | [SIOCSIWRANGE - SIOCIWFIRST] = { | |
152 | .header_type = IW_HEADER_TYPE_NULL, | |
153 | }, | |
154 | [SIOCGIWRANGE - SIOCIWFIRST] = { | |
155 | .header_type = IW_HEADER_TYPE_POINT, | |
156 | .token_size = 1, | |
157 | .max_tokens = sizeof(struct iw_range), | |
158 | .flags = IW_DESCR_FLAG_DUMP, | |
159 | }, | |
160 | [SIOCSIWPRIV - SIOCIWFIRST] = { | |
161 | .header_type = IW_HEADER_TYPE_NULL, | |
162 | }, | |
163 | [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */ | |
711e2c33 JT |
164 | .header_type = IW_HEADER_TYPE_POINT, |
165 | .token_size = sizeof(struct iw_priv_args), | |
166 | .max_tokens = 16, | |
167 | .flags = IW_DESCR_FLAG_NOMAX, | |
1da177e4 LT |
168 | }, |
169 | [SIOCSIWSTATS - SIOCIWFIRST] = { | |
170 | .header_type = IW_HEADER_TYPE_NULL, | |
171 | }, | |
172 | [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */ | |
711e2c33 JT |
173 | .header_type = IW_HEADER_TYPE_POINT, |
174 | .token_size = 1, | |
175 | .max_tokens = sizeof(struct iw_statistics), | |
1da177e4 LT |
176 | .flags = IW_DESCR_FLAG_DUMP, |
177 | }, | |
178 | [SIOCSIWSPY - SIOCIWFIRST] = { | |
179 | .header_type = IW_HEADER_TYPE_POINT, | |
180 | .token_size = sizeof(struct sockaddr), | |
181 | .max_tokens = IW_MAX_SPY, | |
182 | }, | |
183 | [SIOCGIWSPY - SIOCIWFIRST] = { | |
184 | .header_type = IW_HEADER_TYPE_POINT, | |
185 | .token_size = sizeof(struct sockaddr) + | |
186 | sizeof(struct iw_quality), | |
187 | .max_tokens = IW_MAX_SPY, | |
188 | }, | |
189 | [SIOCSIWTHRSPY - SIOCIWFIRST] = { | |
190 | .header_type = IW_HEADER_TYPE_POINT, | |
191 | .token_size = sizeof(struct iw_thrspy), | |
192 | .min_tokens = 1, | |
193 | .max_tokens = 1, | |
194 | }, | |
195 | [SIOCGIWTHRSPY - SIOCIWFIRST] = { | |
196 | .header_type = IW_HEADER_TYPE_POINT, | |
197 | .token_size = sizeof(struct iw_thrspy), | |
198 | .min_tokens = 1, | |
199 | .max_tokens = 1, | |
200 | }, | |
201 | [SIOCSIWAP - SIOCIWFIRST] = { | |
202 | .header_type = IW_HEADER_TYPE_ADDR, | |
203 | }, | |
204 | [SIOCGIWAP - SIOCIWFIRST] = { | |
205 | .header_type = IW_HEADER_TYPE_ADDR, | |
206 | .flags = IW_DESCR_FLAG_DUMP, | |
207 | }, | |
fff9cfd9 JT |
208 | [SIOCSIWMLME - SIOCIWFIRST] = { |
209 | .header_type = IW_HEADER_TYPE_POINT, | |
210 | .token_size = 1, | |
211 | .min_tokens = sizeof(struct iw_mlme), | |
212 | .max_tokens = sizeof(struct iw_mlme), | |
213 | }, | |
1da177e4 LT |
214 | [SIOCGIWAPLIST - SIOCIWFIRST] = { |
215 | .header_type = IW_HEADER_TYPE_POINT, | |
216 | .token_size = sizeof(struct sockaddr) + | |
217 | sizeof(struct iw_quality), | |
218 | .max_tokens = IW_MAX_AP, | |
219 | .flags = IW_DESCR_FLAG_NOMAX, | |
220 | }, | |
221 | [SIOCSIWSCAN - SIOCIWFIRST] = { | |
fff9cfd9 JT |
222 | .header_type = IW_HEADER_TYPE_POINT, |
223 | .token_size = 1, | |
224 | .min_tokens = 0, | |
225 | .max_tokens = sizeof(struct iw_scan_req), | |
1da177e4 LT |
226 | }, |
227 | [SIOCGIWSCAN - SIOCIWFIRST] = { | |
228 | .header_type = IW_HEADER_TYPE_POINT, | |
229 | .token_size = 1, | |
230 | .max_tokens = IW_SCAN_MAX_DATA, | |
231 | .flags = IW_DESCR_FLAG_NOMAX, | |
232 | }, | |
233 | [SIOCSIWESSID - SIOCIWFIRST] = { | |
234 | .header_type = IW_HEADER_TYPE_POINT, | |
235 | .token_size = 1, | |
baef1865 | 236 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 LT |
237 | .flags = IW_DESCR_FLAG_EVENT, |
238 | }, | |
239 | [SIOCGIWESSID - SIOCIWFIRST] = { | |
240 | .header_type = IW_HEADER_TYPE_POINT, | |
241 | .token_size = 1, | |
baef1865 | 242 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 LT |
243 | .flags = IW_DESCR_FLAG_DUMP, |
244 | }, | |
245 | [SIOCSIWNICKN - SIOCIWFIRST] = { | |
246 | .header_type = IW_HEADER_TYPE_POINT, | |
247 | .token_size = 1, | |
baef1865 | 248 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 LT |
249 | }, |
250 | [SIOCGIWNICKN - SIOCIWFIRST] = { | |
251 | .header_type = IW_HEADER_TYPE_POINT, | |
252 | .token_size = 1, | |
baef1865 | 253 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 LT |
254 | }, |
255 | [SIOCSIWRATE - SIOCIWFIRST] = { | |
256 | .header_type = IW_HEADER_TYPE_PARAM, | |
257 | }, | |
258 | [SIOCGIWRATE - SIOCIWFIRST] = { | |
259 | .header_type = IW_HEADER_TYPE_PARAM, | |
260 | }, | |
261 | [SIOCSIWRTS - SIOCIWFIRST] = { | |
262 | .header_type = IW_HEADER_TYPE_PARAM, | |
263 | }, | |
264 | [SIOCGIWRTS - SIOCIWFIRST] = { | |
265 | .header_type = IW_HEADER_TYPE_PARAM, | |
266 | }, | |
267 | [SIOCSIWFRAG - SIOCIWFIRST] = { | |
268 | .header_type = IW_HEADER_TYPE_PARAM, | |
269 | }, | |
270 | [SIOCGIWFRAG - SIOCIWFIRST] = { | |
271 | .header_type = IW_HEADER_TYPE_PARAM, | |
272 | }, | |
273 | [SIOCSIWTXPOW - SIOCIWFIRST] = { | |
274 | .header_type = IW_HEADER_TYPE_PARAM, | |
275 | }, | |
276 | [SIOCGIWTXPOW - SIOCIWFIRST] = { | |
277 | .header_type = IW_HEADER_TYPE_PARAM, | |
278 | }, | |
279 | [SIOCSIWRETRY - SIOCIWFIRST] = { | |
280 | .header_type = IW_HEADER_TYPE_PARAM, | |
281 | }, | |
282 | [SIOCGIWRETRY - SIOCIWFIRST] = { | |
283 | .header_type = IW_HEADER_TYPE_PARAM, | |
284 | }, | |
285 | [SIOCSIWENCODE - SIOCIWFIRST] = { | |
286 | .header_type = IW_HEADER_TYPE_POINT, | |
287 | .token_size = 1, | |
288 | .max_tokens = IW_ENCODING_TOKEN_MAX, | |
289 | .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT, | |
290 | }, | |
291 | [SIOCGIWENCODE - SIOCIWFIRST] = { | |
292 | .header_type = IW_HEADER_TYPE_POINT, | |
293 | .token_size = 1, | |
294 | .max_tokens = IW_ENCODING_TOKEN_MAX, | |
295 | .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT, | |
296 | }, | |
297 | [SIOCSIWPOWER - SIOCIWFIRST] = { | |
298 | .header_type = IW_HEADER_TYPE_PARAM, | |
299 | }, | |
300 | [SIOCGIWPOWER - SIOCIWFIRST] = { | |
301 | .header_type = IW_HEADER_TYPE_PARAM, | |
302 | }, | |
fff9cfd9 JT |
303 | [SIOCSIWGENIE - SIOCIWFIRST] = { |
304 | .header_type = IW_HEADER_TYPE_POINT, | |
305 | .token_size = 1, | |
306 | .max_tokens = IW_GENERIC_IE_MAX, | |
307 | }, | |
308 | [SIOCGIWGENIE - SIOCIWFIRST] = { | |
309 | .header_type = IW_HEADER_TYPE_POINT, | |
310 | .token_size = 1, | |
311 | .max_tokens = IW_GENERIC_IE_MAX, | |
312 | }, | |
313 | [SIOCSIWAUTH - SIOCIWFIRST] = { | |
314 | .header_type = IW_HEADER_TYPE_PARAM, | |
315 | }, | |
316 | [SIOCGIWAUTH - SIOCIWFIRST] = { | |
317 | .header_type = IW_HEADER_TYPE_PARAM, | |
318 | }, | |
319 | [SIOCSIWENCODEEXT - SIOCIWFIRST] = { | |
320 | .header_type = IW_HEADER_TYPE_POINT, | |
321 | .token_size = 1, | |
322 | .min_tokens = sizeof(struct iw_encode_ext), | |
323 | .max_tokens = sizeof(struct iw_encode_ext) + | |
324 | IW_ENCODING_TOKEN_MAX, | |
325 | }, | |
326 | [SIOCGIWENCODEEXT - SIOCIWFIRST] = { | |
327 | .header_type = IW_HEADER_TYPE_POINT, | |
328 | .token_size = 1, | |
329 | .min_tokens = sizeof(struct iw_encode_ext), | |
330 | .max_tokens = sizeof(struct iw_encode_ext) + | |
331 | IW_ENCODING_TOKEN_MAX, | |
332 | }, | |
333 | [SIOCSIWPMKSA - SIOCIWFIRST] = { | |
334 | .header_type = IW_HEADER_TYPE_POINT, | |
335 | .token_size = 1, | |
336 | .min_tokens = sizeof(struct iw_pmksa), | |
337 | .max_tokens = sizeof(struct iw_pmksa), | |
338 | }, | |
1da177e4 | 339 | }; |
1ac58ee3 | 340 | static const unsigned standard_ioctl_num = ARRAY_SIZE(standard_ioctl); |
1da177e4 LT |
341 | |
342 | /* | |
343 | * Meta-data about all the additional standard Wireless Extension events | |
344 | * we know about. | |
345 | */ | |
346 | static const struct iw_ioctl_description standard_event[] = { | |
347 | [IWEVTXDROP - IWEVFIRST] = { | |
348 | .header_type = IW_HEADER_TYPE_ADDR, | |
349 | }, | |
350 | [IWEVQUAL - IWEVFIRST] = { | |
351 | .header_type = IW_HEADER_TYPE_QUAL, | |
352 | }, | |
353 | [IWEVCUSTOM - IWEVFIRST] = { | |
354 | .header_type = IW_HEADER_TYPE_POINT, | |
355 | .token_size = 1, | |
356 | .max_tokens = IW_CUSTOM_MAX, | |
357 | }, | |
358 | [IWEVREGISTERED - IWEVFIRST] = { | |
359 | .header_type = IW_HEADER_TYPE_ADDR, | |
360 | }, | |
361 | [IWEVEXPIRED - IWEVFIRST] = { | |
4ec93edb | 362 | .header_type = IW_HEADER_TYPE_ADDR, |
1da177e4 | 363 | }, |
fff9cfd9 JT |
364 | [IWEVGENIE - IWEVFIRST] = { |
365 | .header_type = IW_HEADER_TYPE_POINT, | |
366 | .token_size = 1, | |
367 | .max_tokens = IW_GENERIC_IE_MAX, | |
368 | }, | |
369 | [IWEVMICHAELMICFAILURE - IWEVFIRST] = { | |
4ec93edb | 370 | .header_type = IW_HEADER_TYPE_POINT, |
fff9cfd9 JT |
371 | .token_size = 1, |
372 | .max_tokens = sizeof(struct iw_michaelmicfailure), | |
373 | }, | |
374 | [IWEVASSOCREQIE - IWEVFIRST] = { | |
375 | .header_type = IW_HEADER_TYPE_POINT, | |
376 | .token_size = 1, | |
377 | .max_tokens = IW_GENERIC_IE_MAX, | |
378 | }, | |
379 | [IWEVASSOCRESPIE - IWEVFIRST] = { | |
380 | .header_type = IW_HEADER_TYPE_POINT, | |
381 | .token_size = 1, | |
382 | .max_tokens = IW_GENERIC_IE_MAX, | |
383 | }, | |
384 | [IWEVPMKIDCAND - IWEVFIRST] = { | |
385 | .header_type = IW_HEADER_TYPE_POINT, | |
386 | .token_size = 1, | |
387 | .max_tokens = sizeof(struct iw_pmkid_cand), | |
388 | }, | |
1da177e4 | 389 | }; |
1ac58ee3 | 390 | static const unsigned standard_event_num = ARRAY_SIZE(standard_event); |
1da177e4 LT |
391 | |
392 | /* Size (in bytes) of the various private data types */ | |
393 | static const char iw_priv_type_size[] = { | |
394 | 0, /* IW_PRIV_TYPE_NONE */ | |
395 | 1, /* IW_PRIV_TYPE_BYTE */ | |
396 | 1, /* IW_PRIV_TYPE_CHAR */ | |
397 | 0, /* Not defined */ | |
398 | sizeof(__u32), /* IW_PRIV_TYPE_INT */ | |
399 | sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */ | |
400 | sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */ | |
401 | 0, /* Not defined */ | |
402 | }; | |
403 | ||
404 | /* Size (in bytes) of various events */ | |
405 | static const int event_type_size[] = { | |
406 | IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */ | |
407 | 0, | |
408 | IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */ | |
409 | 0, | |
410 | IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */ | |
411 | IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */ | |
412 | IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */ | |
413 | 0, | |
414 | IW_EV_POINT_LEN, /* Without variable payload */ | |
415 | IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */ | |
416 | IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */ | |
417 | }; | |
418 | ||
c2805fbb JT |
419 | /* Size (in bytes) of various events, as packed */ |
420 | static const int event_type_pk_size[] = { | |
421 | IW_EV_LCP_PK_LEN, /* IW_HEADER_TYPE_NULL */ | |
422 | 0, | |
423 | IW_EV_CHAR_PK_LEN, /* IW_HEADER_TYPE_CHAR */ | |
424 | 0, | |
425 | IW_EV_UINT_PK_LEN, /* IW_HEADER_TYPE_UINT */ | |
426 | IW_EV_FREQ_PK_LEN, /* IW_HEADER_TYPE_FREQ */ | |
427 | IW_EV_ADDR_PK_LEN, /* IW_HEADER_TYPE_ADDR */ | |
428 | 0, | |
429 | IW_EV_POINT_PK_LEN, /* Without variable payload */ | |
430 | IW_EV_PARAM_PK_LEN, /* IW_HEADER_TYPE_PARAM */ | |
431 | IW_EV_QUAL_PK_LEN, /* IW_HEADER_TYPE_QUAL */ | |
432 | }; | |
433 | ||
1da177e4 LT |
434 | /************************ COMMON SUBROUTINES ************************/ |
435 | /* | |
436 | * Stuff that may be used in various place or doesn't fit in one | |
437 | * of the section below. | |
438 | */ | |
439 | ||
440 | /* ---------------------------------------------------------------- */ | |
441 | /* | |
442 | * Return the driver handler associated with a specific Wireless Extension. | |
443 | * Called from various place, so make sure it remains efficient. | |
444 | */ | |
445 | static inline iw_handler get_handler(struct net_device *dev, | |
446 | unsigned int cmd) | |
447 | { | |
448 | /* Don't "optimise" the following variable, it will crash */ | |
449 | unsigned int index; /* *MUST* be unsigned */ | |
450 | ||
451 | /* Check if we have some wireless handlers defined */ | |
e71a4783 | 452 | if (dev->wireless_handlers == NULL) |
1da177e4 LT |
453 | return NULL; |
454 | ||
455 | /* Try as a standard command */ | |
456 | index = cmd - SIOCIWFIRST; | |
e71a4783 | 457 | if (index < dev->wireless_handlers->num_standard) |
1da177e4 LT |
458 | return dev->wireless_handlers->standard[index]; |
459 | ||
460 | /* Try as a private command */ | |
461 | index = cmd - SIOCIWFIRSTPRIV; | |
e71a4783 | 462 | if (index < dev->wireless_handlers->num_private) |
1da177e4 LT |
463 | return dev->wireless_handlers->private[index]; |
464 | ||
465 | /* Not found */ | |
466 | return NULL; | |
467 | } | |
468 | ||
469 | /* ---------------------------------------------------------------- */ | |
470 | /* | |
471 | * Get statistics out of the driver | |
472 | */ | |
473 | static inline struct iw_statistics *get_wireless_stats(struct net_device *dev) | |
474 | { | |
475 | /* New location */ | |
e71a4783 | 476 | if ((dev->wireless_handlers != NULL) && |
1da177e4 LT |
477 | (dev->wireless_handlers->get_wireless_stats != NULL)) |
478 | return dev->wireless_handlers->get_wireless_stats(dev); | |
479 | ||
6582c164 JT |
480 | /* Not found */ |
481 | return (struct iw_statistics *) NULL; | |
1da177e4 LT |
482 | } |
483 | ||
484 | /* ---------------------------------------------------------------- */ | |
485 | /* | |
486 | * Call the commit handler in the driver | |
487 | * (if exist and if conditions are right) | |
488 | * | |
489 | * Note : our current commit strategy is currently pretty dumb, | |
490 | * but we will be able to improve on that... | |
491 | * The goal is to try to agreagate as many changes as possible | |
492 | * before doing the commit. Drivers that will define a commit handler | |
493 | * are usually those that need a reset after changing parameters, so | |
494 | * we want to minimise the number of reset. | |
495 | * A cool idea is to use a timer : at each "set" command, we re-set the | |
496 | * timer, when the timer eventually fires, we call the driver. | |
497 | * Hopefully, more on that later. | |
498 | * | |
499 | * Also, I'm waiting to see how many people will complain about the | |
500 | * netif_running(dev) test. I'm open on that one... | |
501 | * Hopefully, the driver will remember to do a commit in "open()" ;-) | |
502 | */ | |
503 | static inline int call_commit_handler(struct net_device * dev) | |
504 | { | |
e71a4783 | 505 | if ((netif_running(dev)) && |
1da177e4 LT |
506 | (dev->wireless_handlers->standard[0] != NULL)) { |
507 | /* Call the commit handler on the driver */ | |
508 | return dev->wireless_handlers->standard[0](dev, NULL, | |
509 | NULL, NULL); | |
510 | } else | |
511 | return 0; /* Command completed successfully */ | |
512 | } | |
513 | ||
514 | /* ---------------------------------------------------------------- */ | |
515 | /* | |
516 | * Calculate size of private arguments | |
517 | */ | |
518 | static inline int get_priv_size(__u16 args) | |
519 | { | |
520 | int num = args & IW_PRIV_SIZE_MASK; | |
521 | int type = (args & IW_PRIV_TYPE_MASK) >> 12; | |
522 | ||
523 | return num * iw_priv_type_size[type]; | |
524 | } | |
525 | ||
526 | /* ---------------------------------------------------------------- */ | |
527 | /* | |
528 | * Re-calculate the size of private arguments | |
529 | */ | |
530 | static inline int adjust_priv_size(__u16 args, | |
531 | union iwreq_data * wrqu) | |
532 | { | |
533 | int num = wrqu->data.length; | |
534 | int max = args & IW_PRIV_SIZE_MASK; | |
535 | int type = (args & IW_PRIV_TYPE_MASK) >> 12; | |
536 | ||
537 | /* Make sure the driver doesn't goof up */ | |
538 | if (max < num) | |
539 | num = max; | |
540 | ||
541 | return num * iw_priv_type_size[type]; | |
542 | } | |
543 | ||
711e2c33 JT |
544 | /* ---------------------------------------------------------------- */ |
545 | /* | |
546 | * Standard Wireless Handler : get wireless stats | |
547 | * Allow programatic access to /proc/net/wireless even if /proc | |
548 | * doesn't exist... Also more efficient... | |
549 | */ | |
550 | static int iw_handler_get_iwstats(struct net_device * dev, | |
551 | struct iw_request_info * info, | |
552 | union iwreq_data * wrqu, | |
553 | char * extra) | |
554 | { | |
555 | /* Get stats from the driver */ | |
556 | struct iw_statistics *stats; | |
557 | ||
558 | stats = get_wireless_stats(dev); | |
559 | if (stats != (struct iw_statistics *) NULL) { | |
560 | ||
561 | /* Copy statistics to extra */ | |
562 | memcpy(extra, stats, sizeof(struct iw_statistics)); | |
563 | wrqu->data.length = sizeof(struct iw_statistics); | |
564 | ||
565 | /* Check if we need to clear the updated flag */ | |
e71a4783 | 566 | if (wrqu->data.flags != 0) |
711e2c33 JT |
567 | stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; |
568 | return 0; | |
569 | } else | |
570 | return -EOPNOTSUPP; | |
571 | } | |
572 | ||
573 | /* ---------------------------------------------------------------- */ | |
574 | /* | |
575 | * Standard Wireless Handler : get iwpriv definitions | |
576 | * Export the driver private handler definition | |
577 | * They will be picked up by tools like iwpriv... | |
578 | */ | |
579 | static int iw_handler_get_private(struct net_device * dev, | |
580 | struct iw_request_info * info, | |
581 | union iwreq_data * wrqu, | |
582 | char * extra) | |
583 | { | |
584 | /* Check if the driver has something to export */ | |
e71a4783 | 585 | if ((dev->wireless_handlers->num_private_args == 0) || |
711e2c33 JT |
586 | (dev->wireless_handlers->private_args == NULL)) |
587 | return -EOPNOTSUPP; | |
588 | ||
589 | /* Check if there is enough buffer up there */ | |
e71a4783 | 590 | if (wrqu->data.length < dev->wireless_handlers->num_private_args) { |
711e2c33 JT |
591 | /* User space can't know in advance how large the buffer |
592 | * needs to be. Give it a hint, so that we can support | |
593 | * any size buffer we want somewhat efficiently... */ | |
594 | wrqu->data.length = dev->wireless_handlers->num_private_args; | |
595 | return -E2BIG; | |
596 | } | |
597 | ||
598 | /* Set the number of available ioctls. */ | |
599 | wrqu->data.length = dev->wireless_handlers->num_private_args; | |
600 | ||
601 | /* Copy structure to the user buffer. */ | |
602 | memcpy(extra, dev->wireless_handlers->private_args, | |
603 | sizeof(struct iw_priv_args) * wrqu->data.length); | |
604 | ||
605 | return 0; | |
606 | } | |
607 | ||
1da177e4 LT |
608 | |
609 | /******************** /proc/net/wireless SUPPORT ********************/ | |
610 | /* | |
611 | * The /proc/net/wireless file is a human readable user-space interface | |
612 | * exporting various wireless specific statistics from the wireless devices. | |
613 | * This is the most popular part of the Wireless Extensions ;-) | |
614 | * | |
615 | * This interface is a pure clone of /proc/net/dev (in net/core/dev.c). | |
616 | * The content of the file is basically the content of "struct iw_statistics". | |
617 | */ | |
618 | ||
619 | #ifdef CONFIG_PROC_FS | |
620 | ||
621 | /* ---------------------------------------------------------------- */ | |
622 | /* | |
623 | * Print one entry (line) of /proc/net/wireless | |
624 | */ | |
625 | static __inline__ void wireless_seq_printf_stats(struct seq_file *seq, | |
626 | struct net_device *dev) | |
627 | { | |
628 | /* Get stats from the driver */ | |
629 | struct iw_statistics *stats = get_wireless_stats(dev); | |
630 | ||
631 | if (stats) { | |
632 | seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d " | |
633 | "%6d %6d %6d\n", | |
634 | dev->name, stats->status, stats->qual.qual, | |
635 | stats->qual.updated & IW_QUAL_QUAL_UPDATED | |
636 | ? '.' : ' ', | |
4ec93edb | 637 | ((__s32) stats->qual.level) - |
6582c164 | 638 | ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0), |
1da177e4 LT |
639 | stats->qual.updated & IW_QUAL_LEVEL_UPDATED |
640 | ? '.' : ' ', | |
4ec93edb | 641 | ((__s32) stats->qual.noise) - |
6582c164 | 642 | ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0), |
1da177e4 LT |
643 | stats->qual.updated & IW_QUAL_NOISE_UPDATED |
644 | ? '.' : ' ', | |
645 | stats->discard.nwid, stats->discard.code, | |
646 | stats->discard.fragment, stats->discard.retries, | |
647 | stats->discard.misc, stats->miss.beacon); | |
6582c164 | 648 | stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; |
1da177e4 LT |
649 | } |
650 | } | |
651 | ||
652 | /* ---------------------------------------------------------------- */ | |
653 | /* | |
654 | * Print info for /proc/net/wireless (print all entries) | |
655 | */ | |
656 | static int wireless_seq_show(struct seq_file *seq, void *v) | |
657 | { | |
658 | if (v == SEQ_START_TOKEN) | |
659 | seq_printf(seq, "Inter-| sta-| Quality | Discarded " | |
660 | "packets | Missed | WE\n" | |
661 | " face | tus | link level noise | nwid " | |
662 | "crypt frag retry misc | beacon | %d\n", | |
663 | WIRELESS_EXT); | |
664 | else | |
665 | wireless_seq_printf_stats(seq, v); | |
666 | return 0; | |
667 | } | |
668 | ||
f690808e | 669 | static const struct seq_operations wireless_seq_ops = { |
1da177e4 LT |
670 | .start = dev_seq_start, |
671 | .next = dev_seq_next, | |
672 | .stop = dev_seq_stop, | |
673 | .show = wireless_seq_show, | |
674 | }; | |
675 | ||
676 | static int wireless_seq_open(struct inode *inode, struct file *file) | |
677 | { | |
678 | return seq_open(file, &wireless_seq_ops); | |
679 | } | |
680 | ||
9a32144e | 681 | static const struct file_operations wireless_seq_fops = { |
1da177e4 LT |
682 | .owner = THIS_MODULE, |
683 | .open = wireless_seq_open, | |
684 | .read = seq_read, | |
685 | .llseek = seq_lseek, | |
686 | .release = seq_release, | |
687 | }; | |
688 | ||
295f4a1f | 689 | int __init wext_proc_init(void) |
1da177e4 | 690 | { |
6582c164 | 691 | /* Create /proc/net/wireless entry */ |
1da177e4 LT |
692 | if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops)) |
693 | return -ENOMEM; | |
694 | ||
695 | return 0; | |
696 | } | |
697 | #endif /* CONFIG_PROC_FS */ | |
698 | ||
699 | /************************** IOCTL SUPPORT **************************/ | |
700 | /* | |
701 | * The original user space API to configure all those Wireless Extensions | |
702 | * is through IOCTLs. | |
703 | * In there, we check if we need to call the new driver API (iw_handler) | |
704 | * or just call the driver ioctl handler. | |
705 | */ | |
706 | ||
1da177e4 LT |
707 | /* ---------------------------------------------------------------- */ |
708 | /* | |
709 | * Wrapper to call a standard Wireless Extension handler. | |
710 | * We do various checks and also take care of moving data between | |
711 | * user space and kernel space. | |
712 | */ | |
711e2c33 JT |
713 | static int ioctl_standard_call(struct net_device * dev, |
714 | struct ifreq * ifr, | |
715 | unsigned int cmd, | |
716 | iw_handler handler) | |
1da177e4 LT |
717 | { |
718 | struct iwreq * iwr = (struct iwreq *) ifr; | |
719 | const struct iw_ioctl_description * descr; | |
720 | struct iw_request_info info; | |
721 | int ret = -EINVAL; | |
722 | ||
723 | /* Get the description of the IOCTL */ | |
e71a4783 | 724 | if ((cmd - SIOCIWFIRST) >= standard_ioctl_num) |
1da177e4 LT |
725 | return -EOPNOTSUPP; |
726 | descr = &(standard_ioctl[cmd - SIOCIWFIRST]); | |
727 | ||
1da177e4 LT |
728 | /* Prepare the call */ |
729 | info.cmd = cmd; | |
730 | info.flags = 0; | |
731 | ||
732 | /* Check if we have a pointer to user space data or not */ | |
e71a4783 | 733 | if (descr->header_type != IW_HEADER_TYPE_POINT) { |
1da177e4 LT |
734 | |
735 | /* No extra arguments. Trivial to handle */ | |
736 | ret = handler(dev, &info, &(iwr->u), NULL); | |
737 | ||
1da177e4 | 738 | /* Generate an event to notify listeners of the change */ |
e71a4783 | 739 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && |
1da177e4 LT |
740 | ((ret == 0) || (ret == -EIWCOMMIT))) |
741 | wireless_send_event(dev, cmd, &(iwr->u), NULL); | |
1da177e4 LT |
742 | } else { |
743 | char * extra; | |
744 | int extra_size; | |
745 | int user_length = 0; | |
746 | int err; | |
98978edb | 747 | int essid_compat = 0; |
1da177e4 LT |
748 | |
749 | /* Calculate space needed by arguments. Always allocate | |
750 | * for max space. Easier, and won't last long... */ | |
751 | extra_size = descr->max_tokens * descr->token_size; | |
752 | ||
98978edb JL |
753 | /* Check need for ESSID compatibility for WE < 21 */ |
754 | switch (cmd) { | |
755 | case SIOCSIWESSID: | |
756 | case SIOCGIWESSID: | |
757 | case SIOCSIWNICKN: | |
758 | case SIOCGIWNICKN: | |
759 | if (iwr->u.data.length == descr->max_tokens + 1) | |
760 | essid_compat = 1; | |
761 | else if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) { | |
762 | char essid[IW_ESSID_MAX_SIZE + 1]; | |
763 | ||
764 | err = copy_from_user(essid, iwr->u.data.pointer, | |
765 | iwr->u.data.length * | |
766 | descr->token_size); | |
767 | if (err) | |
768 | return -EFAULT; | |
769 | ||
770 | if (essid[iwr->u.data.length - 1] == '\0') | |
771 | essid_compat = 1; | |
772 | } | |
773 | break; | |
774 | default: | |
775 | break; | |
776 | } | |
777 | ||
778 | iwr->u.data.length -= essid_compat; | |
779 | ||
1da177e4 | 780 | /* Check what user space is giving us */ |
e71a4783 | 781 | if (IW_IS_SET(cmd)) { |
1da177e4 | 782 | /* Check NULL pointer */ |
e71a4783 | 783 | if ((iwr->u.data.pointer == NULL) && |
1da177e4 LT |
784 | (iwr->u.data.length != 0)) |
785 | return -EFAULT; | |
786 | /* Check if number of token fits within bounds */ | |
e71a4783 | 787 | if (iwr->u.data.length > descr->max_tokens) |
1da177e4 | 788 | return -E2BIG; |
e71a4783 | 789 | if (iwr->u.data.length < descr->min_tokens) |
1da177e4 LT |
790 | return -EINVAL; |
791 | } else { | |
792 | /* Check NULL pointer */ | |
e71a4783 | 793 | if (iwr->u.data.pointer == NULL) |
1da177e4 LT |
794 | return -EFAULT; |
795 | /* Save user space buffer size for checking */ | |
796 | user_length = iwr->u.data.length; | |
797 | ||
798 | /* Don't check if user_length > max to allow forward | |
799 | * compatibility. The test user_length < min is | |
800 | * implied by the test at the end. */ | |
801 | ||
802 | /* Support for very large requests */ | |
e71a4783 | 803 | if ((descr->flags & IW_DESCR_FLAG_NOMAX) && |
1da177e4 LT |
804 | (user_length > descr->max_tokens)) { |
805 | /* Allow userspace to GET more than max so | |
806 | * we can support any size GET requests. | |
807 | * There is still a limit : -ENOMEM. */ | |
808 | extra_size = user_length * descr->token_size; | |
809 | /* Note : user_length is originally a __u16, | |
810 | * and token_size is controlled by us, | |
811 | * so extra_size won't get negative and | |
812 | * won't overflow... */ | |
813 | } | |
814 | } | |
815 | ||
1da177e4 | 816 | /* Create the kernel buffer */ |
98978edb JL |
817 | /* kzalloc ensures NULL-termination for essid_compat */ |
818 | extra = kzalloc(extra_size, GFP_KERNEL); | |
1da177e4 LT |
819 | if (extra == NULL) { |
820 | return -ENOMEM; | |
821 | } | |
822 | ||
823 | /* If it is a SET, get all the extra data in here */ | |
e71a4783 | 824 | if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) { |
1da177e4 LT |
825 | err = copy_from_user(extra, iwr->u.data.pointer, |
826 | iwr->u.data.length * | |
827 | descr->token_size); | |
828 | if (err) { | |
829 | kfree(extra); | |
830 | return -EFAULT; | |
831 | } | |
1da177e4 LT |
832 | } |
833 | ||
834 | /* Call the handler */ | |
835 | ret = handler(dev, &info, &(iwr->u), extra); | |
836 | ||
98978edb JL |
837 | iwr->u.data.length += essid_compat; |
838 | ||
1da177e4 LT |
839 | /* If we have something to return to the user */ |
840 | if (!ret && IW_IS_GET(cmd)) { | |
841 | /* Check if there is enough buffer up there */ | |
e71a4783 | 842 | if (user_length < iwr->u.data.length) { |
1da177e4 LT |
843 | kfree(extra); |
844 | return -E2BIG; | |
845 | } | |
846 | ||
847 | err = copy_to_user(iwr->u.data.pointer, extra, | |
848 | iwr->u.data.length * | |
849 | descr->token_size); | |
850 | if (err) | |
4ec93edb | 851 | ret = -EFAULT; |
1da177e4 LT |
852 | } |
853 | ||
1da177e4 | 854 | /* Generate an event to notify listeners of the change */ |
e71a4783 | 855 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && |
1da177e4 | 856 | ((ret == 0) || (ret == -EIWCOMMIT))) { |
e71a4783 | 857 | if (descr->flags & IW_DESCR_FLAG_RESTRICT) |
1da177e4 LT |
858 | /* If the event is restricted, don't |
859 | * export the payload */ | |
860 | wireless_send_event(dev, cmd, &(iwr->u), NULL); | |
861 | else | |
862 | wireless_send_event(dev, cmd, &(iwr->u), | |
863 | extra); | |
864 | } | |
1da177e4 LT |
865 | |
866 | /* Cleanup - I told you it wasn't that long ;-) */ | |
867 | kfree(extra); | |
868 | } | |
869 | ||
870 | /* Call commit handler if needed and defined */ | |
e71a4783 | 871 | if (ret == -EIWCOMMIT) |
1da177e4 LT |
872 | ret = call_commit_handler(dev); |
873 | ||
874 | /* Here, we will generate the appropriate event if needed */ | |
875 | ||
876 | return ret; | |
877 | } | |
878 | ||
879 | /* ---------------------------------------------------------------- */ | |
880 | /* | |
881 | * Wrapper to call a private Wireless Extension handler. | |
882 | * We do various checks and also take care of moving data between | |
883 | * user space and kernel space. | |
884 | * It's not as nice and slimline as the standard wrapper. The cause | |
885 | * is struct iw_priv_args, which was not really designed for the | |
886 | * job we are going here. | |
887 | * | |
888 | * IMPORTANT : This function prevent to set and get data on the same | |
889 | * IOCTL and enforce the SET/GET convention. Not doing it would be | |
890 | * far too hairy... | |
891 | * If you need to set and get data at the same time, please don't use | |
892 | * a iw_handler but process it in your ioctl handler (i.e. use the | |
893 | * old driver API). | |
894 | */ | |
895 | static inline int ioctl_private_call(struct net_device * dev, | |
896 | struct ifreq * ifr, | |
897 | unsigned int cmd, | |
898 | iw_handler handler) | |
899 | { | |
900 | struct iwreq * iwr = (struct iwreq *) ifr; | |
901 | const struct iw_priv_args * descr = NULL; | |
902 | struct iw_request_info info; | |
903 | int extra_size = 0; | |
904 | int i; | |
905 | int ret = -EINVAL; | |
906 | ||
907 | /* Get the description of the IOCTL */ | |
e71a4783 SH |
908 | for (i = 0; i < dev->wireless_handlers->num_private_args; i++) |
909 | if (cmd == dev->wireless_handlers->private_args[i].cmd) { | |
1da177e4 LT |
910 | descr = &(dev->wireless_handlers->private_args[i]); |
911 | break; | |
912 | } | |
913 | ||
1da177e4 | 914 | /* Compute the size of the set/get arguments */ |
e71a4783 SH |
915 | if (descr != NULL) { |
916 | if (IW_IS_SET(cmd)) { | |
1da177e4 LT |
917 | int offset = 0; /* For sub-ioctls */ |
918 | /* Check for sub-ioctl handler */ | |
e71a4783 | 919 | if (descr->name[0] == '\0') |
1da177e4 LT |
920 | /* Reserve one int for sub-ioctl index */ |
921 | offset = sizeof(__u32); | |
922 | ||
923 | /* Size of set arguments */ | |
924 | extra_size = get_priv_size(descr->set_args); | |
925 | ||
926 | /* Does it fits in iwr ? */ | |
e71a4783 | 927 | if ((descr->set_args & IW_PRIV_SIZE_FIXED) && |
1da177e4 LT |
928 | ((extra_size + offset) <= IFNAMSIZ)) |
929 | extra_size = 0; | |
930 | } else { | |
931 | /* Size of get arguments */ | |
932 | extra_size = get_priv_size(descr->get_args); | |
933 | ||
934 | /* Does it fits in iwr ? */ | |
e71a4783 | 935 | if ((descr->get_args & IW_PRIV_SIZE_FIXED) && |
1da177e4 LT |
936 | (extra_size <= IFNAMSIZ)) |
937 | extra_size = 0; | |
938 | } | |
939 | } | |
940 | ||
941 | /* Prepare the call */ | |
942 | info.cmd = cmd; | |
943 | info.flags = 0; | |
944 | ||
945 | /* Check if we have a pointer to user space data or not. */ | |
e71a4783 | 946 | if (extra_size == 0) { |
1da177e4 LT |
947 | /* No extra arguments. Trivial to handle */ |
948 | ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u)); | |
949 | } else { | |
950 | char * extra; | |
951 | int err; | |
952 | ||
953 | /* Check what user space is giving us */ | |
e71a4783 | 954 | if (IW_IS_SET(cmd)) { |
1da177e4 | 955 | /* Check NULL pointer */ |
e71a4783 | 956 | if ((iwr->u.data.pointer == NULL) && |
1da177e4 LT |
957 | (iwr->u.data.length != 0)) |
958 | return -EFAULT; | |
959 | ||
960 | /* Does it fits within bounds ? */ | |
e71a4783 | 961 | if (iwr->u.data.length > (descr->set_args & |
1da177e4 LT |
962 | IW_PRIV_SIZE_MASK)) |
963 | return -E2BIG; | |
964 | } else { | |
965 | /* Check NULL pointer */ | |
e71a4783 | 966 | if (iwr->u.data.pointer == NULL) |
1da177e4 LT |
967 | return -EFAULT; |
968 | } | |
969 | ||
1da177e4 LT |
970 | /* Always allocate for max space. Easier, and won't last |
971 | * long... */ | |
972 | extra = kmalloc(extra_size, GFP_KERNEL); | |
973 | if (extra == NULL) { | |
974 | return -ENOMEM; | |
975 | } | |
976 | ||
977 | /* If it is a SET, get all the extra data in here */ | |
e71a4783 | 978 | if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) { |
1da177e4 LT |
979 | err = copy_from_user(extra, iwr->u.data.pointer, |
980 | extra_size); | |
981 | if (err) { | |
982 | kfree(extra); | |
983 | return -EFAULT; | |
984 | } | |
1da177e4 LT |
985 | } |
986 | ||
987 | /* Call the handler */ | |
988 | ret = handler(dev, &info, &(iwr->u), extra); | |
989 | ||
990 | /* If we have something to return to the user */ | |
991 | if (!ret && IW_IS_GET(cmd)) { | |
992 | ||
993 | /* Adjust for the actual length if it's variable, | |
994 | * avoid leaking kernel bits outside. */ | |
995 | if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) { | |
996 | extra_size = adjust_priv_size(descr->get_args, | |
997 | &(iwr->u)); | |
998 | } | |
999 | ||
1000 | err = copy_to_user(iwr->u.data.pointer, extra, | |
1001 | extra_size); | |
1002 | if (err) | |
4ec93edb | 1003 | ret = -EFAULT; |
1da177e4 LT |
1004 | } |
1005 | ||
1006 | /* Cleanup - I told you it wasn't that long ;-) */ | |
1007 | kfree(extra); | |
1008 | } | |
1009 | ||
1010 | ||
1011 | /* Call commit handler if needed and defined */ | |
e71a4783 | 1012 | if (ret == -EIWCOMMIT) |
1da177e4 LT |
1013 | ret = call_commit_handler(dev); |
1014 | ||
1015 | return ret; | |
1016 | } | |
1017 | ||
1018 | /* ---------------------------------------------------------------- */ | |
1019 | /* | |
295f4a1f | 1020 | * Main IOCTl dispatcher. |
1da177e4 LT |
1021 | * Check the type of IOCTL and call the appropriate wrapper... |
1022 | */ | |
295f4a1f | 1023 | static int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd) |
1da177e4 LT |
1024 | { |
1025 | struct net_device *dev; | |
1026 | iw_handler handler; | |
1027 | ||
1028 | /* Permissions are already checked in dev_ioctl() before calling us. | |
1029 | * The copy_to/from_user() of ifr is also dealt with in there */ | |
1030 | ||
1031 | /* Make sure the device exist */ | |
1032 | if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL) | |
1033 | return -ENODEV; | |
1034 | ||
1035 | /* A bunch of special cases, then the generic case... | |
1036 | * Note that 'cmd' is already filtered in dev_ioctl() with | |
1037 | * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */ | |
dd8ceabc JB |
1038 | if (cmd == SIOCGIWSTATS) |
1039 | return ioctl_standard_call(dev, ifr, cmd, | |
e71a4783 SH |
1040 | &iw_handler_get_iwstats); |
1041 | ||
dd8ceabc JB |
1042 | if (cmd == SIOCGIWPRIV && dev->wireless_handlers) |
1043 | return ioctl_standard_call(dev, ifr, cmd, | |
1044 | &iw_handler_get_private); | |
1045 | ||
1046 | /* Basic check */ | |
1047 | if (!netif_device_present(dev)) | |
1048 | return -ENODEV; | |
1049 | ||
1050 | /* New driver API : try to find the handler */ | |
1051 | handler = get_handler(dev, cmd); | |
1052 | if (handler) { | |
1053 | /* Standard and private are not the same */ | |
1054 | if (cmd < SIOCIWFIRSTPRIV) | |
1055 | return ioctl_standard_call(dev, ifr, cmd, handler); | |
1056 | else | |
1057 | return ioctl_private_call(dev, ifr, cmd, handler); | |
1da177e4 | 1058 | } |
dd8ceabc JB |
1059 | /* Old driver API : call driver ioctl handler */ |
1060 | if (dev->do_ioctl) | |
1061 | return dev->do_ioctl(dev, ifr, cmd); | |
1062 | return -EOPNOTSUPP; | |
1da177e4 LT |
1063 | } |
1064 | ||
295f4a1f JB |
1065 | /* entry point from dev ioctl */ |
1066 | int wext_handle_ioctl(struct ifreq *ifr, unsigned int cmd, | |
1067 | void __user *arg) | |
1068 | { | |
1069 | int ret; | |
1070 | ||
1071 | /* If command is `set a parameter', or | |
1072 | * `get the encoding parameters', check if | |
1073 | * the user has the right to do it */ | |
dd8ceabc JB |
1074 | if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT) |
1075 | && !capable(CAP_NET_ADMIN)) | |
1076 | return -EPERM; | |
1077 | ||
295f4a1f JB |
1078 | dev_load(ifr->ifr_name); |
1079 | rtnl_lock(); | |
1080 | ret = wireless_process_ioctl(ifr, cmd); | |
1081 | rtnl_unlock(); | |
1082 | if (IW_IS_GET(cmd) && copy_to_user(arg, ifr, sizeof(struct ifreq))) | |
1083 | return -EFAULT; | |
1084 | return ret; | |
1085 | } | |
711e2c33 | 1086 | |
1da177e4 LT |
1087 | /************************* EVENT PROCESSING *************************/ |
1088 | /* | |
1089 | * Process events generated by the wireless layer or the driver. | |
1090 | * Most often, the event will be propagated through rtnetlink | |
1091 | */ | |
1092 | ||
baef1865 JL |
1093 | /* ---------------------------------------------------------------- */ |
1094 | /* | |
1095 | * Locking... | |
1096 | * ---------- | |
1097 | * | |
1098 | * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing | |
1099 | * the locking issue in here and implementing this code ! | |
1100 | * | |
1101 | * The issue : wireless_send_event() is often called in interrupt context, | |
1102 | * while the Netlink layer can never be called in interrupt context. | |
1103 | * The fully formed RtNetlink events are queued, and then a tasklet is run | |
1104 | * to feed those to Netlink. | |
1105 | * The skb_queue is interrupt safe, and its lock is not held while calling | |
1106 | * Netlink, so there is no possibility of dealock. | |
1107 | * Jean II | |
1108 | */ | |
1109 | ||
782a6675 HX |
1110 | static struct sk_buff_head wireless_nlevent_queue; |
1111 | ||
baef1865 JL |
1112 | static int __init wireless_nlevent_init(void) |
1113 | { | |
1114 | skb_queue_head_init(&wireless_nlevent_queue); | |
1115 | return 0; | |
1116 | } | |
1117 | ||
1118 | subsys_initcall(wireless_nlevent_init); | |
1119 | ||
782a6675 HX |
1120 | static void wireless_nlevent_process(unsigned long data) |
1121 | { | |
1122 | struct sk_buff *skb; | |
1123 | ||
1124 | while ((skb = skb_dequeue(&wireless_nlevent_queue))) | |
bd5785ba | 1125 | rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC); |
782a6675 HX |
1126 | } |
1127 | ||
1128 | static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0); | |
1129 | ||
1da177e4 LT |
1130 | /* ---------------------------------------------------------------- */ |
1131 | /* | |
1132 | * Fill a rtnetlink message with our event data. | |
1133 | * Note that we propage only the specified event and don't dump the | |
1134 | * current wireless config. Dumping the wireless config is far too | |
1135 | * expensive (for each parameter, the driver need to query the hardware). | |
1136 | */ | |
1137 | static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb, | |
1138 | struct net_device * dev, | |
1139 | int type, | |
1140 | char * event, | |
1141 | int event_len) | |
1142 | { | |
1143 | struct ifinfomsg *r; | |
1144 | struct nlmsghdr *nlh; | |
27a884dc | 1145 | unsigned char *b = skb_tail_pointer(skb); |
1da177e4 LT |
1146 | |
1147 | nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r)); | |
1148 | r = NLMSG_DATA(nlh); | |
1149 | r->ifi_family = AF_UNSPEC; | |
9ef1d4c7 | 1150 | r->__ifi_pad = 0; |
1da177e4 LT |
1151 | r->ifi_type = dev->type; |
1152 | r->ifi_index = dev->ifindex; | |
711e2c33 | 1153 | r->ifi_flags = dev_get_flags(dev); |
1da177e4 LT |
1154 | r->ifi_change = 0; /* Wireless changes don't affect those flags */ |
1155 | ||
1156 | /* Add the wireless events in the netlink packet */ | |
711e2c33 | 1157 | RTA_PUT(skb, IFLA_WIRELESS, event_len, event); |
1da177e4 | 1158 | |
27a884dc | 1159 | nlh->nlmsg_len = skb_tail_pointer(skb) - b; |
1da177e4 LT |
1160 | return skb->len; |
1161 | ||
1162 | nlmsg_failure: | |
1163 | rtattr_failure: | |
dc5fc579 | 1164 | nlmsg_trim(skb, b); |
1da177e4 LT |
1165 | return -1; |
1166 | } | |
1167 | ||
1168 | /* ---------------------------------------------------------------- */ | |
1169 | /* | |
1170 | * Create and broadcast and send it on the standard rtnetlink socket | |
1171 | * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c | |
1172 | * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field | |
1173 | * within a RTM_NEWLINK event. | |
1174 | */ | |
1175 | static inline void rtmsg_iwinfo(struct net_device * dev, | |
1176 | char * event, | |
1177 | int event_len) | |
1178 | { | |
1179 | struct sk_buff *skb; | |
1180 | int size = NLMSG_GOODSIZE; | |
1181 | ||
1182 | skb = alloc_skb(size, GFP_ATOMIC); | |
1183 | if (!skb) | |
1184 | return; | |
1185 | ||
1186 | if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK, | |
1187 | event, event_len) < 0) { | |
1188 | kfree_skb(skb); | |
1189 | return; | |
1190 | } | |
ac6d439d | 1191 | NETLINK_CB(skb).dst_group = RTNLGRP_LINK; |
782a6675 HX |
1192 | skb_queue_tail(&wireless_nlevent_queue, skb); |
1193 | tasklet_schedule(&wireless_nlevent_tasklet); | |
1194 | } | |
1195 | ||
1da177e4 LT |
1196 | /* ---------------------------------------------------------------- */ |
1197 | /* | |
1198 | * Main event dispatcher. Called from other parts and drivers. | |
1199 | * Send the event on the appropriate channels. | |
1200 | * May be called from interrupt context. | |
1201 | */ | |
1202 | void wireless_send_event(struct net_device * dev, | |
1203 | unsigned int cmd, | |
1204 | union iwreq_data * wrqu, | |
1205 | char * extra) | |
1206 | { | |
1207 | const struct iw_ioctl_description * descr = NULL; | |
1208 | int extra_len = 0; | |
1209 | struct iw_event *event; /* Mallocated whole event */ | |
1210 | int event_len; /* Its size */ | |
1211 | int hdr_len; /* Size of the event header */ | |
6582c164 | 1212 | int wrqu_off = 0; /* Offset in wrqu */ |
1da177e4 LT |
1213 | /* Don't "optimise" the following variable, it will crash */ |
1214 | unsigned cmd_index; /* *MUST* be unsigned */ | |
1215 | ||
6582c164 | 1216 | /* Get the description of the Event */ |
e71a4783 | 1217 | if (cmd <= SIOCIWLAST) { |
1da177e4 | 1218 | cmd_index = cmd - SIOCIWFIRST; |
e71a4783 | 1219 | if (cmd_index < standard_ioctl_num) |
1da177e4 LT |
1220 | descr = &(standard_ioctl[cmd_index]); |
1221 | } else { | |
1222 | cmd_index = cmd - IWEVFIRST; | |
e71a4783 | 1223 | if (cmd_index < standard_event_num) |
1da177e4 LT |
1224 | descr = &(standard_event[cmd_index]); |
1225 | } | |
1226 | /* Don't accept unknown events */ | |
e71a4783 | 1227 | if (descr == NULL) { |
1da177e4 LT |
1228 | /* Note : we don't return an error to the driver, because |
1229 | * the driver would not know what to do about it. It can't | |
1230 | * return an error to the user, because the event is not | |
1231 | * initiated by a user request. | |
1232 | * The best the driver could do is to log an error message. | |
1233 | * We will do it ourselves instead... | |
1234 | */ | |
4ec93edb | 1235 | printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n", |
1da177e4 LT |
1236 | dev->name, cmd); |
1237 | return; | |
1238 | } | |
1da177e4 LT |
1239 | |
1240 | /* Check extra parameters and set extra_len */ | |
e71a4783 | 1241 | if (descr->header_type == IW_HEADER_TYPE_POINT) { |
1da177e4 | 1242 | /* Check if number of token fits within bounds */ |
e71a4783 | 1243 | if (wrqu->data.length > descr->max_tokens) { |
4ec93edb | 1244 | printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length); |
1da177e4 LT |
1245 | return; |
1246 | } | |
e71a4783 | 1247 | if (wrqu->data.length < descr->min_tokens) { |
4ec93edb | 1248 | printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length); |
1da177e4 LT |
1249 | return; |
1250 | } | |
1251 | /* Calculate extra_len - extra is NULL for restricted events */ | |
e71a4783 | 1252 | if (extra != NULL) |
1da177e4 | 1253 | extra_len = wrqu->data.length * descr->token_size; |
6582c164 JT |
1254 | /* Always at an offset in wrqu */ |
1255 | wrqu_off = IW_EV_POINT_OFF; | |
1da177e4 LT |
1256 | } |
1257 | ||
1258 | /* Total length of the event */ | |
1259 | hdr_len = event_type_size[descr->header_type]; | |
1260 | event_len = hdr_len + extra_len; | |
1261 | ||
1da177e4 LT |
1262 | /* Create temporary buffer to hold the event */ |
1263 | event = kmalloc(event_len, GFP_ATOMIC); | |
e71a4783 | 1264 | if (event == NULL) |
1da177e4 LT |
1265 | return; |
1266 | ||
1267 | /* Fill event */ | |
1268 | event->len = event_len; | |
1269 | event->cmd = cmd; | |
6582c164 | 1270 | memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN); |
e71a4783 | 1271 | if (extra != NULL) |
1da177e4 LT |
1272 | memcpy(((char *) event) + hdr_len, extra, extra_len); |
1273 | ||
711e2c33 | 1274 | /* Send via the RtNetlink event channel */ |
1da177e4 | 1275 | rtmsg_iwinfo(dev, (char *) event, event_len); |
1da177e4 LT |
1276 | |
1277 | /* Cleanup */ | |
1278 | kfree(event); | |
1279 | ||
1280 | return; /* Always success, I guess ;-) */ | |
1281 | } | |
7a9df167 | 1282 | EXPORT_SYMBOL(wireless_send_event); |
1da177e4 LT |
1283 | |
1284 | /********************** ENHANCED IWSPY SUPPORT **********************/ | |
1285 | /* | |
1286 | * In the old days, the driver was handling spy support all by itself. | |
1287 | * Now, the driver can delegate this task to Wireless Extensions. | |
1288 | * It needs to use those standard spy iw_handler in struct iw_handler_def, | |
1289 | * push data to us via wireless_spy_update() and include struct iw_spy_data | |
6582c164 | 1290 | * in its private part (and export it in net_device->wireless_data->spy_data). |
1da177e4 LT |
1291 | * One of the main advantage of centralising spy support here is that |
1292 | * it becomes much easier to improve and extend it without having to touch | |
1293 | * the drivers. One example is the addition of the Spy-Threshold events. | |
1294 | */ | |
1295 | ||
1296 | /* ---------------------------------------------------------------- */ | |
1297 | /* | |
1298 | * Return the pointer to the spy data in the driver. | |
1299 | * Because this is called on the Rx path via wireless_spy_update(), | |
1300 | * we want it to be efficient... | |
1301 | */ | |
1302 | static inline struct iw_spy_data * get_spydata(struct net_device *dev) | |
1303 | { | |
1304 | /* This is the new way */ | |
e71a4783 | 1305 | if (dev->wireless_data) |
1da177e4 | 1306 | return(dev->wireless_data->spy_data); |
6582c164 | 1307 | return NULL; |
1da177e4 LT |
1308 | } |
1309 | ||
1310 | /*------------------------------------------------------------------*/ | |
1311 | /* | |
1312 | * Standard Wireless Handler : set Spy List | |
1313 | */ | |
1314 | int iw_handler_set_spy(struct net_device * dev, | |
1315 | struct iw_request_info * info, | |
1316 | union iwreq_data * wrqu, | |
1317 | char * extra) | |
1318 | { | |
1319 | struct iw_spy_data * spydata = get_spydata(dev); | |
1320 | struct sockaddr * address = (struct sockaddr *) extra; | |
1321 | ||
1da177e4 | 1322 | /* Make sure driver is not buggy or using the old API */ |
e71a4783 | 1323 | if (!spydata) |
1da177e4 LT |
1324 | return -EOPNOTSUPP; |
1325 | ||
1326 | /* Disable spy collection while we copy the addresses. | |
1327 | * While we copy addresses, any call to wireless_spy_update() | |
1328 | * will NOP. This is OK, as anyway the addresses are changing. */ | |
1329 | spydata->spy_number = 0; | |
1330 | ||
1331 | /* We want to operate without locking, because wireless_spy_update() | |
1332 | * most likely will happen in the interrupt handler, and therefore | |
1333 | * have its own locking constraints and needs performance. | |
1334 | * The rtnl_lock() make sure we don't race with the other iw_handlers. | |
1335 | * This make sure wireless_spy_update() "see" that the spy list | |
1336 | * is temporarily disabled. */ | |
e16aa207 | 1337 | smp_wmb(); |
1da177e4 LT |
1338 | |
1339 | /* Are there are addresses to copy? */ | |
e71a4783 | 1340 | if (wrqu->data.length > 0) { |
1da177e4 LT |
1341 | int i; |
1342 | ||
1343 | /* Copy addresses */ | |
e71a4783 | 1344 | for (i = 0; i < wrqu->data.length; i++) |
1da177e4 LT |
1345 | memcpy(spydata->spy_address[i], address[i].sa_data, |
1346 | ETH_ALEN); | |
1347 | /* Reset stats */ | |
1348 | memset(spydata->spy_stat, 0, | |
1349 | sizeof(struct iw_quality) * IW_MAX_SPY); | |
1da177e4 LT |
1350 | } |
1351 | ||
1352 | /* Make sure above is updated before re-enabling */ | |
e16aa207 | 1353 | smp_wmb(); |
1da177e4 LT |
1354 | |
1355 | /* Enable addresses */ | |
1356 | spydata->spy_number = wrqu->data.length; | |
1357 | ||
1358 | return 0; | |
1359 | } | |
7a9df167 | 1360 | EXPORT_SYMBOL(iw_handler_set_spy); |
1da177e4 LT |
1361 | |
1362 | /*------------------------------------------------------------------*/ | |
1363 | /* | |
1364 | * Standard Wireless Handler : get Spy List | |
1365 | */ | |
1366 | int iw_handler_get_spy(struct net_device * dev, | |
1367 | struct iw_request_info * info, | |
1368 | union iwreq_data * wrqu, | |
1369 | char * extra) | |
1370 | { | |
1371 | struct iw_spy_data * spydata = get_spydata(dev); | |
1372 | struct sockaddr * address = (struct sockaddr *) extra; | |
1373 | int i; | |
1374 | ||
1375 | /* Make sure driver is not buggy or using the old API */ | |
e71a4783 | 1376 | if (!spydata) |
1da177e4 LT |
1377 | return -EOPNOTSUPP; |
1378 | ||
1379 | wrqu->data.length = spydata->spy_number; | |
1380 | ||
1381 | /* Copy addresses. */ | |
e71a4783 | 1382 | for (i = 0; i < spydata->spy_number; i++) { |
1da177e4 LT |
1383 | memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN); |
1384 | address[i].sa_family = AF_UNIX; | |
1385 | } | |
1386 | /* Copy stats to the user buffer (just after). */ | |
e71a4783 | 1387 | if (spydata->spy_number > 0) |
1da177e4 LT |
1388 | memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number), |
1389 | spydata->spy_stat, | |
1390 | sizeof(struct iw_quality) * spydata->spy_number); | |
1391 | /* Reset updated flags. */ | |
e71a4783 | 1392 | for (i = 0; i < spydata->spy_number; i++) |
6582c164 | 1393 | spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED; |
1da177e4 LT |
1394 | return 0; |
1395 | } | |
7a9df167 | 1396 | EXPORT_SYMBOL(iw_handler_get_spy); |
1da177e4 LT |
1397 | |
1398 | /*------------------------------------------------------------------*/ | |
1399 | /* | |
1400 | * Standard Wireless Handler : set spy threshold | |
1401 | */ | |
1402 | int iw_handler_set_thrspy(struct net_device * dev, | |
1403 | struct iw_request_info *info, | |
1404 | union iwreq_data * wrqu, | |
1405 | char * extra) | |
1406 | { | |
1407 | struct iw_spy_data * spydata = get_spydata(dev); | |
1408 | struct iw_thrspy * threshold = (struct iw_thrspy *) extra; | |
1409 | ||
1410 | /* Make sure driver is not buggy or using the old API */ | |
e71a4783 | 1411 | if (!spydata) |
1da177e4 LT |
1412 | return -EOPNOTSUPP; |
1413 | ||
1414 | /* Just do it */ | |
1415 | memcpy(&(spydata->spy_thr_low), &(threshold->low), | |
1416 | 2 * sizeof(struct iw_quality)); | |
1417 | ||
1418 | /* Clear flag */ | |
1419 | memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under)); | |
1420 | ||
1da177e4 LT |
1421 | return 0; |
1422 | } | |
7a9df167 | 1423 | EXPORT_SYMBOL(iw_handler_set_thrspy); |
1da177e4 LT |
1424 | |
1425 | /*------------------------------------------------------------------*/ | |
1426 | /* | |
1427 | * Standard Wireless Handler : get spy threshold | |
1428 | */ | |
1429 | int iw_handler_get_thrspy(struct net_device * dev, | |
1430 | struct iw_request_info *info, | |
1431 | union iwreq_data * wrqu, | |
1432 | char * extra) | |
1433 | { | |
1434 | struct iw_spy_data * spydata = get_spydata(dev); | |
1435 | struct iw_thrspy * threshold = (struct iw_thrspy *) extra; | |
1436 | ||
1437 | /* Make sure driver is not buggy or using the old API */ | |
e71a4783 | 1438 | if (!spydata) |
1da177e4 LT |
1439 | return -EOPNOTSUPP; |
1440 | ||
1441 | /* Just do it */ | |
1442 | memcpy(&(threshold->low), &(spydata->spy_thr_low), | |
1443 | 2 * sizeof(struct iw_quality)); | |
1444 | ||
1445 | return 0; | |
1446 | } | |
7a9df167 | 1447 | EXPORT_SYMBOL(iw_handler_get_thrspy); |
1da177e4 LT |
1448 | |
1449 | /*------------------------------------------------------------------*/ | |
1450 | /* | |
1451 | * Prepare and send a Spy Threshold event | |
1452 | */ | |
1453 | static void iw_send_thrspy_event(struct net_device * dev, | |
1454 | struct iw_spy_data * spydata, | |
1455 | unsigned char * address, | |
1456 | struct iw_quality * wstats) | |
1457 | { | |
1458 | union iwreq_data wrqu; | |
1459 | struct iw_thrspy threshold; | |
1460 | ||
1461 | /* Init */ | |
1462 | wrqu.data.length = 1; | |
1463 | wrqu.data.flags = 0; | |
1464 | /* Copy address */ | |
1465 | memcpy(threshold.addr.sa_data, address, ETH_ALEN); | |
1466 | threshold.addr.sa_family = ARPHRD_ETHER; | |
1467 | /* Copy stats */ | |
1468 | memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality)); | |
1469 | /* Copy also thresholds */ | |
1470 | memcpy(&(threshold.low), &(spydata->spy_thr_low), | |
1471 | 2 * sizeof(struct iw_quality)); | |
1472 | ||
1da177e4 LT |
1473 | /* Send event to user space */ |
1474 | wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold); | |
1475 | } | |
1476 | ||
1477 | /* ---------------------------------------------------------------- */ | |
1478 | /* | |
1479 | * Call for the driver to update the spy data. | |
1480 | * For now, the spy data is a simple array. As the size of the array is | |
1481 | * small, this is good enough. If we wanted to support larger number of | |
1482 | * spy addresses, we should use something more efficient... | |
1483 | */ | |
1484 | void wireless_spy_update(struct net_device * dev, | |
1485 | unsigned char * address, | |
1486 | struct iw_quality * wstats) | |
1487 | { | |
1488 | struct iw_spy_data * spydata = get_spydata(dev); | |
1489 | int i; | |
1490 | int match = -1; | |
1491 | ||
1492 | /* Make sure driver is not buggy or using the old API */ | |
e71a4783 | 1493 | if (!spydata) |
1da177e4 LT |
1494 | return; |
1495 | ||
1da177e4 | 1496 | /* Update all records that match */ |
e71a4783 SH |
1497 | for (i = 0; i < spydata->spy_number; i++) |
1498 | if (!compare_ether_addr(address, spydata->spy_address[i])) { | |
1da177e4 LT |
1499 | memcpy(&(spydata->spy_stat[i]), wstats, |
1500 | sizeof(struct iw_quality)); | |
1501 | match = i; | |
1502 | } | |
1503 | ||
1504 | /* Generate an event if we cross the spy threshold. | |
1505 | * To avoid event storms, we have a simple hysteresis : we generate | |
1506 | * event only when we go under the low threshold or above the | |
1507 | * high threshold. */ | |
e71a4783 SH |
1508 | if (match >= 0) { |
1509 | if (spydata->spy_thr_under[match]) { | |
1510 | if (wstats->level > spydata->spy_thr_high.level) { | |
1da177e4 LT |
1511 | spydata->spy_thr_under[match] = 0; |
1512 | iw_send_thrspy_event(dev, spydata, | |
1513 | address, wstats); | |
1514 | } | |
1515 | } else { | |
e71a4783 | 1516 | if (wstats->level < spydata->spy_thr_low.level) { |
1da177e4 LT |
1517 | spydata->spy_thr_under[match] = 1; |
1518 | iw_send_thrspy_event(dev, spydata, | |
1519 | address, wstats); | |
1520 | } | |
1521 | } | |
1522 | } | |
1523 | } | |
1da177e4 | 1524 | EXPORT_SYMBOL(wireless_spy_update); |