2 * This file implement the Wireless Extensions APIs.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
7 * (As all part of the Linux kernel, this file is GPL)
10 /************************** DOCUMENTATION **************************/
14 * See <linux/wireless.h> for details of the APIs and the rest.
19 * v1 - 5.12.01 - Jean II
20 * o Created this file.
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
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
36 * v4 - 18.04.02 - Jean II
37 * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1
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)
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
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
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)
69 * v8 - 17.02.06 - Jean II
70 * o RtNetlink requests support (SET/GET)
72 * v8b - 03.08.06 - Herbert Xu
73 * o Fix Wireless Event locking issues.
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()
80 * v10 - 16.3.07 - Jean II
81 * o Prevent leaking of kernel space in stream on 64 bits.
84 /***************************** INCLUDES *****************************/
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 */
94 #include <linux/etherdevice.h> /* compare_ether_addr */
95 #include <linux/interrupt.h>
97 #include <linux/wireless.h> /* Pretty obvious */
98 #include <net/iw_handler.h> /* New driver API */
99 #include <net/netlink.h>
100 #include <net/wext.h>
102 #include <asm/uaccess.h> /* copy_to_user() */
104 /************************* GLOBAL VARIABLES *************************/
106 * You should not use global variables, because of re-entrancy.
107 * On our case, it's only const, so it's OK...
110 * Meta-data about all the standard Wireless Extension request we
113 static const struct iw_ioctl_description standard_ioctl[] = {
114 [SIOCSIWCOMMIT - SIOCIWFIRST] = {
115 .header_type = IW_HEADER_TYPE_NULL,
117 [SIOCGIWNAME - SIOCIWFIRST] = {
118 .header_type = IW_HEADER_TYPE_CHAR,
119 .flags = IW_DESCR_FLAG_DUMP,
121 [SIOCSIWNWID - SIOCIWFIRST] = {
122 .header_type = IW_HEADER_TYPE_PARAM,
123 .flags = IW_DESCR_FLAG_EVENT,
125 [SIOCGIWNWID - SIOCIWFIRST] = {
126 .header_type = IW_HEADER_TYPE_PARAM,
127 .flags = IW_DESCR_FLAG_DUMP,
129 [SIOCSIWFREQ - SIOCIWFIRST] = {
130 .header_type = IW_HEADER_TYPE_FREQ,
131 .flags = IW_DESCR_FLAG_EVENT,
133 [SIOCGIWFREQ - SIOCIWFIRST] = {
134 .header_type = IW_HEADER_TYPE_FREQ,
135 .flags = IW_DESCR_FLAG_DUMP,
137 [SIOCSIWMODE - SIOCIWFIRST] = {
138 .header_type = IW_HEADER_TYPE_UINT,
139 .flags = IW_DESCR_FLAG_EVENT,
141 [SIOCGIWMODE - SIOCIWFIRST] = {
142 .header_type = IW_HEADER_TYPE_UINT,
143 .flags = IW_DESCR_FLAG_DUMP,
145 [SIOCSIWSENS - SIOCIWFIRST] = {
146 .header_type = IW_HEADER_TYPE_PARAM,
148 [SIOCGIWSENS - SIOCIWFIRST] = {
149 .header_type = IW_HEADER_TYPE_PARAM,
151 [SIOCSIWRANGE - SIOCIWFIRST] = {
152 .header_type = IW_HEADER_TYPE_NULL,
154 [SIOCGIWRANGE - SIOCIWFIRST] = {
155 .header_type = IW_HEADER_TYPE_POINT,
157 .max_tokens = sizeof(struct iw_range),
158 .flags = IW_DESCR_FLAG_DUMP,
160 [SIOCSIWPRIV - SIOCIWFIRST] = {
161 .header_type = IW_HEADER_TYPE_NULL,
163 [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */
164 .header_type = IW_HEADER_TYPE_POINT,
165 .token_size = sizeof(struct iw_priv_args),
167 .flags = IW_DESCR_FLAG_NOMAX,
169 [SIOCSIWSTATS - SIOCIWFIRST] = {
170 .header_type = IW_HEADER_TYPE_NULL,
172 [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */
173 .header_type = IW_HEADER_TYPE_POINT,
175 .max_tokens = sizeof(struct iw_statistics),
176 .flags = IW_DESCR_FLAG_DUMP,
178 [SIOCSIWSPY - SIOCIWFIRST] = {
179 .header_type = IW_HEADER_TYPE_POINT,
180 .token_size = sizeof(struct sockaddr),
181 .max_tokens = IW_MAX_SPY,
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,
189 [SIOCSIWTHRSPY - SIOCIWFIRST] = {
190 .header_type = IW_HEADER_TYPE_POINT,
191 .token_size = sizeof(struct iw_thrspy),
195 [SIOCGIWTHRSPY - SIOCIWFIRST] = {
196 .header_type = IW_HEADER_TYPE_POINT,
197 .token_size = sizeof(struct iw_thrspy),
201 [SIOCSIWAP - SIOCIWFIRST] = {
202 .header_type = IW_HEADER_TYPE_ADDR,
204 [SIOCGIWAP - SIOCIWFIRST] = {
205 .header_type = IW_HEADER_TYPE_ADDR,
206 .flags = IW_DESCR_FLAG_DUMP,
208 [SIOCSIWMLME - SIOCIWFIRST] = {
209 .header_type = IW_HEADER_TYPE_POINT,
211 .min_tokens = sizeof(struct iw_mlme),
212 .max_tokens = sizeof(struct iw_mlme),
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,
221 [SIOCSIWSCAN - SIOCIWFIRST] = {
222 .header_type = IW_HEADER_TYPE_POINT,
225 .max_tokens = sizeof(struct iw_scan_req),
227 [SIOCGIWSCAN - SIOCIWFIRST] = {
228 .header_type = IW_HEADER_TYPE_POINT,
230 .max_tokens = IW_SCAN_MAX_DATA,
231 .flags = IW_DESCR_FLAG_NOMAX,
233 [SIOCSIWESSID - SIOCIWFIRST] = {
234 .header_type = IW_HEADER_TYPE_POINT,
236 .max_tokens = IW_ESSID_MAX_SIZE,
237 .flags = IW_DESCR_FLAG_EVENT,
239 [SIOCGIWESSID - SIOCIWFIRST] = {
240 .header_type = IW_HEADER_TYPE_POINT,
242 .max_tokens = IW_ESSID_MAX_SIZE,
243 .flags = IW_DESCR_FLAG_DUMP,
245 [SIOCSIWNICKN - SIOCIWFIRST] = {
246 .header_type = IW_HEADER_TYPE_POINT,
248 .max_tokens = IW_ESSID_MAX_SIZE,
250 [SIOCGIWNICKN - SIOCIWFIRST] = {
251 .header_type = IW_HEADER_TYPE_POINT,
253 .max_tokens = IW_ESSID_MAX_SIZE,
255 [SIOCSIWRATE - SIOCIWFIRST] = {
256 .header_type = IW_HEADER_TYPE_PARAM,
258 [SIOCGIWRATE - SIOCIWFIRST] = {
259 .header_type = IW_HEADER_TYPE_PARAM,
261 [SIOCSIWRTS - SIOCIWFIRST] = {
262 .header_type = IW_HEADER_TYPE_PARAM,
264 [SIOCGIWRTS - SIOCIWFIRST] = {
265 .header_type = IW_HEADER_TYPE_PARAM,
267 [SIOCSIWFRAG - SIOCIWFIRST] = {
268 .header_type = IW_HEADER_TYPE_PARAM,
270 [SIOCGIWFRAG - SIOCIWFIRST] = {
271 .header_type = IW_HEADER_TYPE_PARAM,
273 [SIOCSIWTXPOW - SIOCIWFIRST] = {
274 .header_type = IW_HEADER_TYPE_PARAM,
276 [SIOCGIWTXPOW - SIOCIWFIRST] = {
277 .header_type = IW_HEADER_TYPE_PARAM,
279 [SIOCSIWRETRY - SIOCIWFIRST] = {
280 .header_type = IW_HEADER_TYPE_PARAM,
282 [SIOCGIWRETRY - SIOCIWFIRST] = {
283 .header_type = IW_HEADER_TYPE_PARAM,
285 [SIOCSIWENCODE - SIOCIWFIRST] = {
286 .header_type = IW_HEADER_TYPE_POINT,
288 .max_tokens = IW_ENCODING_TOKEN_MAX,
289 .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
291 [SIOCGIWENCODE - SIOCIWFIRST] = {
292 .header_type = IW_HEADER_TYPE_POINT,
294 .max_tokens = IW_ENCODING_TOKEN_MAX,
295 .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
297 [SIOCSIWPOWER - SIOCIWFIRST] = {
298 .header_type = IW_HEADER_TYPE_PARAM,
300 [SIOCGIWPOWER - SIOCIWFIRST] = {
301 .header_type = IW_HEADER_TYPE_PARAM,
303 [SIOCSIWGENIE - SIOCIWFIRST] = {
304 .header_type = IW_HEADER_TYPE_POINT,
306 .max_tokens = IW_GENERIC_IE_MAX,
308 [SIOCGIWGENIE - SIOCIWFIRST] = {
309 .header_type = IW_HEADER_TYPE_POINT,
311 .max_tokens = IW_GENERIC_IE_MAX,
313 [SIOCSIWAUTH - SIOCIWFIRST] = {
314 .header_type = IW_HEADER_TYPE_PARAM,
316 [SIOCGIWAUTH - SIOCIWFIRST] = {
317 .header_type = IW_HEADER_TYPE_PARAM,
319 [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
320 .header_type = IW_HEADER_TYPE_POINT,
322 .min_tokens = sizeof(struct iw_encode_ext),
323 .max_tokens = sizeof(struct iw_encode_ext) +
324 IW_ENCODING_TOKEN_MAX,
326 [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
327 .header_type = IW_HEADER_TYPE_POINT,
329 .min_tokens = sizeof(struct iw_encode_ext),
330 .max_tokens = sizeof(struct iw_encode_ext) +
331 IW_ENCODING_TOKEN_MAX,
333 [SIOCSIWPMKSA - SIOCIWFIRST] = {
334 .header_type = IW_HEADER_TYPE_POINT,
336 .min_tokens = sizeof(struct iw_pmksa),
337 .max_tokens = sizeof(struct iw_pmksa),
340 static const unsigned standard_ioctl_num = ARRAY_SIZE(standard_ioctl);
343 * Meta-data about all the additional standard Wireless Extension events
346 static const struct iw_ioctl_description standard_event[] = {
347 [IWEVTXDROP - IWEVFIRST] = {
348 .header_type = IW_HEADER_TYPE_ADDR,
350 [IWEVQUAL - IWEVFIRST] = {
351 .header_type = IW_HEADER_TYPE_QUAL,
353 [IWEVCUSTOM - IWEVFIRST] = {
354 .header_type = IW_HEADER_TYPE_POINT,
356 .max_tokens = IW_CUSTOM_MAX,
358 [IWEVREGISTERED - IWEVFIRST] = {
359 .header_type = IW_HEADER_TYPE_ADDR,
361 [IWEVEXPIRED - IWEVFIRST] = {
362 .header_type = IW_HEADER_TYPE_ADDR,
364 [IWEVGENIE - IWEVFIRST] = {
365 .header_type = IW_HEADER_TYPE_POINT,
367 .max_tokens = IW_GENERIC_IE_MAX,
369 [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
370 .header_type = IW_HEADER_TYPE_POINT,
372 .max_tokens = sizeof(struct iw_michaelmicfailure),
374 [IWEVASSOCREQIE - IWEVFIRST] = {
375 .header_type = IW_HEADER_TYPE_POINT,
377 .max_tokens = IW_GENERIC_IE_MAX,
379 [IWEVASSOCRESPIE - IWEVFIRST] = {
380 .header_type = IW_HEADER_TYPE_POINT,
382 .max_tokens = IW_GENERIC_IE_MAX,
384 [IWEVPMKIDCAND - IWEVFIRST] = {
385 .header_type = IW_HEADER_TYPE_POINT,
387 .max_tokens = sizeof(struct iw_pmkid_cand),
390 static const unsigned standard_event_num = ARRAY_SIZE(standard_event);
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 */
398 sizeof(__u32), /* IW_PRIV_TYPE_INT */
399 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
400 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
404 /* Size (in bytes) of various events */
405 static const int event_type_size[] = {
406 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
408 IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
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 */
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 */
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 */
423 IW_EV_CHAR_PK_LEN, /* IW_HEADER_TYPE_CHAR */
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 */
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 */
434 /************************ COMMON SUBROUTINES ************************/
436 * Stuff that may be used in various place or doesn't fit in one
437 * of the section below.
440 /* ---------------------------------------------------------------- */
442 * Return the driver handler associated with a specific Wireless Extension.
443 * Called from various place, so make sure it remains efficient.
445 static inline iw_handler get_handler(struct net_device *dev,
448 /* Don't "optimise" the following variable, it will crash */
449 unsigned int index; /* *MUST* be unsigned */
451 /* Check if we have some wireless handlers defined */
452 if (dev->wireless_handlers == NULL)
455 /* Try as a standard command */
456 index = cmd - SIOCIWFIRST;
457 if (index < dev->wireless_handlers->num_standard)
458 return dev->wireless_handlers->standard[index];
460 /* Try as a private command */
461 index = cmd - SIOCIWFIRSTPRIV;
462 if (index < dev->wireless_handlers->num_private)
463 return dev->wireless_handlers->private[index];
469 /* ---------------------------------------------------------------- */
471 * Get statistics out of the driver
473 static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
476 if ((dev->wireless_handlers != NULL) &&
477 (dev->wireless_handlers->get_wireless_stats != NULL))
478 return dev->wireless_handlers->get_wireless_stats(dev);
481 return (struct iw_statistics *) NULL;
484 /* ---------------------------------------------------------------- */
486 * Call the commit handler in the driver
487 * (if exist and if conditions are right)
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.
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()" ;-)
503 static inline int call_commit_handler(struct net_device * dev)
505 if ((netif_running(dev)) &&
506 (dev->wireless_handlers->standard[0] != NULL)) {
507 /* Call the commit handler on the driver */
508 return dev->wireless_handlers->standard[0](dev, NULL,
511 return 0; /* Command completed successfully */
514 /* ---------------------------------------------------------------- */
516 * Calculate size of private arguments
518 static inline int get_priv_size(__u16 args)
520 int num = args & IW_PRIV_SIZE_MASK;
521 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
523 return num * iw_priv_type_size[type];
526 /* ---------------------------------------------------------------- */
528 * Re-calculate the size of private arguments
530 static inline int adjust_priv_size(__u16 args,
531 union iwreq_data * wrqu)
533 int num = wrqu->data.length;
534 int max = args & IW_PRIV_SIZE_MASK;
535 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
537 /* Make sure the driver doesn't goof up */
541 return num * iw_priv_type_size[type];
544 /* ---------------------------------------------------------------- */
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...
550 static int iw_handler_get_iwstats(struct net_device * dev,
551 struct iw_request_info * info,
552 union iwreq_data * wrqu,
555 /* Get stats from the driver */
556 struct iw_statistics *stats;
558 stats = get_wireless_stats(dev);
559 if (stats != (struct iw_statistics *) NULL) {
561 /* Copy statistics to extra */
562 memcpy(extra, stats, sizeof(struct iw_statistics));
563 wrqu->data.length = sizeof(struct iw_statistics);
565 /* Check if we need to clear the updated flag */
566 if (wrqu->data.flags != 0)
567 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
573 /* ---------------------------------------------------------------- */
575 * Standard Wireless Handler : get iwpriv definitions
576 * Export the driver private handler definition
577 * They will be picked up by tools like iwpriv...
579 static int iw_handler_get_private(struct net_device * dev,
580 struct iw_request_info * info,
581 union iwreq_data * wrqu,
584 /* Check if the driver has something to export */
585 if ((dev->wireless_handlers->num_private_args == 0) ||
586 (dev->wireless_handlers->private_args == NULL))
589 /* Check if there is enough buffer up there */
590 if (wrqu->data.length < dev->wireless_handlers->num_private_args) {
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;
598 /* Set the number of available ioctls. */
599 wrqu->data.length = dev->wireless_handlers->num_private_args;
601 /* Copy structure to the user buffer. */
602 memcpy(extra, dev->wireless_handlers->private_args,
603 sizeof(struct iw_priv_args) * wrqu->data.length);
609 /******************** /proc/net/wireless SUPPORT ********************/
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 ;-)
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".
619 #ifdef CONFIG_PROC_FS
621 /* ---------------------------------------------------------------- */
623 * Print one entry (line) of /proc/net/wireless
625 static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
626 struct net_device *dev)
628 /* Get stats from the driver */
629 struct iw_statistics *stats = get_wireless_stats(dev);
632 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
634 dev->name, stats->status, stats->qual.qual,
635 stats->qual.updated & IW_QUAL_QUAL_UPDATED
637 ((__s32) stats->qual.level) -
638 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
639 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
641 ((__s32) stats->qual.noise) -
642 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
643 stats->qual.updated & IW_QUAL_NOISE_UPDATED
645 stats->discard.nwid, stats->discard.code,
646 stats->discard.fragment, stats->discard.retries,
647 stats->discard.misc, stats->miss.beacon);
648 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
652 /* ---------------------------------------------------------------- */
654 * Print info for /proc/net/wireless (print all entries)
656 static int wireless_seq_show(struct seq_file *seq, void *v)
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",
665 wireless_seq_printf_stats(seq, v);
669 static const struct seq_operations wireless_seq_ops = {
670 .start = dev_seq_start,
671 .next = dev_seq_next,
672 .stop = dev_seq_stop,
673 .show = wireless_seq_show,
676 static int wireless_seq_open(struct inode *inode, struct file *file)
678 return seq_open(file, &wireless_seq_ops);
681 static const struct file_operations wireless_seq_fops = {
682 .owner = THIS_MODULE,
683 .open = wireless_seq_open,
686 .release = seq_release,
689 int __init wext_proc_init(void)
691 /* Create /proc/net/wireless entry */
692 if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
697 #endif /* CONFIG_PROC_FS */
699 /************************** IOCTL SUPPORT **************************/
701 * The original user space API to configure all those Wireless Extensions
703 * In there, we check if we need to call the new driver API (iw_handler)
704 * or just call the driver ioctl handler.
707 /* ---------------------------------------------------------------- */
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.
713 static int ioctl_standard_call(struct net_device * dev,
718 struct iwreq * iwr = (struct iwreq *) ifr;
719 const struct iw_ioctl_description * descr;
720 struct iw_request_info info;
723 /* Get the description of the IOCTL */
724 if ((cmd - SIOCIWFIRST) >= standard_ioctl_num)
726 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
728 /* Prepare the call */
732 /* Check if we have a pointer to user space data or not */
733 if (descr->header_type != IW_HEADER_TYPE_POINT) {
735 /* No extra arguments. Trivial to handle */
736 ret = handler(dev, &info, &(iwr->u), NULL);
738 /* Generate an event to notify listeners of the change */
739 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
740 ((ret == 0) || (ret == -EIWCOMMIT)))
741 wireless_send_event(dev, cmd, &(iwr->u), NULL);
747 int essid_compat = 0;
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;
753 /* Check need for ESSID compatibility for WE < 21 */
759 if (iwr->u.data.length == descr->max_tokens + 1)
761 else if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
762 char essid[IW_ESSID_MAX_SIZE + 1];
764 err = copy_from_user(essid, iwr->u.data.pointer,
770 if (essid[iwr->u.data.length - 1] == '\0')
778 iwr->u.data.length -= essid_compat;
780 /* Check what user space is giving us */
781 if (IW_IS_SET(cmd)) {
782 /* Check NULL pointer */
783 if ((iwr->u.data.pointer == NULL) &&
784 (iwr->u.data.length != 0))
786 /* Check if number of token fits within bounds */
787 if (iwr->u.data.length > descr->max_tokens)
789 if (iwr->u.data.length < descr->min_tokens)
792 /* Check NULL pointer */
793 if (iwr->u.data.pointer == NULL)
795 /* Save user space buffer size for checking */
796 user_length = iwr->u.data.length;
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. */
802 /* Support for very large requests */
803 if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
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... */
816 /* Create the kernel buffer */
817 /* kzalloc ensures NULL-termination for essid_compat */
818 extra = kzalloc(extra_size, GFP_KERNEL);
823 /* If it is a SET, get all the extra data in here */
824 if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
825 err = copy_from_user(extra, iwr->u.data.pointer,
834 /* Call the handler */
835 ret = handler(dev, &info, &(iwr->u), extra);
837 iwr->u.data.length += essid_compat;
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 */
842 if (user_length < iwr->u.data.length) {
847 err = copy_to_user(iwr->u.data.pointer, extra,
854 /* Generate an event to notify listeners of the change */
855 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
856 ((ret == 0) || (ret == -EIWCOMMIT))) {
857 if (descr->flags & IW_DESCR_FLAG_RESTRICT)
858 /* If the event is restricted, don't
859 * export the payload */
860 wireless_send_event(dev, cmd, &(iwr->u), NULL);
862 wireless_send_event(dev, cmd, &(iwr->u),
866 /* Cleanup - I told you it wasn't that long ;-) */
870 /* Call commit handler if needed and defined */
871 if (ret == -EIWCOMMIT)
872 ret = call_commit_handler(dev);
874 /* Here, we will generate the appropriate event if needed */
879 /* ---------------------------------------------------------------- */
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.
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
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
895 static inline int ioctl_private_call(struct net_device * dev,
900 struct iwreq * iwr = (struct iwreq *) ifr;
901 const struct iw_priv_args * descr = NULL;
902 struct iw_request_info info;
907 /* Get the description of the IOCTL */
908 for (i = 0; i < dev->wireless_handlers->num_private_args; i++)
909 if (cmd == dev->wireless_handlers->private_args[i].cmd) {
910 descr = &(dev->wireless_handlers->private_args[i]);
914 /* Compute the size of the set/get arguments */
916 if (IW_IS_SET(cmd)) {
917 int offset = 0; /* For sub-ioctls */
918 /* Check for sub-ioctl handler */
919 if (descr->name[0] == '\0')
920 /* Reserve one int for sub-ioctl index */
921 offset = sizeof(__u32);
923 /* Size of set arguments */
924 extra_size = get_priv_size(descr->set_args);
926 /* Does it fits in iwr ? */
927 if ((descr->set_args & IW_PRIV_SIZE_FIXED) &&
928 ((extra_size + offset) <= IFNAMSIZ))
931 /* Size of get arguments */
932 extra_size = get_priv_size(descr->get_args);
934 /* Does it fits in iwr ? */
935 if ((descr->get_args & IW_PRIV_SIZE_FIXED) &&
936 (extra_size <= IFNAMSIZ))
941 /* Prepare the call */
945 /* Check if we have a pointer to user space data or not. */
946 if (extra_size == 0) {
947 /* No extra arguments. Trivial to handle */
948 ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u));
953 /* Check what user space is giving us */
954 if (IW_IS_SET(cmd)) {
955 /* Check NULL pointer */
956 if ((iwr->u.data.pointer == NULL) &&
957 (iwr->u.data.length != 0))
960 /* Does it fits within bounds ? */
961 if (iwr->u.data.length > (descr->set_args &
965 /* Check NULL pointer */
966 if (iwr->u.data.pointer == NULL)
970 /* Always allocate for max space. Easier, and won't last
972 extra = kmalloc(extra_size, GFP_KERNEL);
977 /* If it is a SET, get all the extra data in here */
978 if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
979 err = copy_from_user(extra, iwr->u.data.pointer,
987 /* Call the handler */
988 ret = handler(dev, &info, &(iwr->u), extra);
990 /* If we have something to return to the user */
991 if (!ret && IW_IS_GET(cmd)) {
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,
1000 err = copy_to_user(iwr->u.data.pointer, extra,
1006 /* Cleanup - I told you it wasn't that long ;-) */
1011 /* Call commit handler if needed and defined */
1012 if (ret == -EIWCOMMIT)
1013 ret = call_commit_handler(dev);
1018 /* ---------------------------------------------------------------- */
1020 * Main IOCTl dispatcher.
1021 * Check the type of IOCTL and call the appropriate wrapper...
1023 static int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
1025 struct net_device *dev;
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 */
1031 /* Make sure the device exist */
1032 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
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) */
1040 /* Get Wireless Stats */
1041 return ioctl_standard_call(dev,
1044 &iw_handler_get_iwstats);
1047 /* Check if we have some wireless handlers defined */
1048 if (dev->wireless_handlers != NULL) {
1049 /* We export to user space the definition of
1050 * the private handler ourselves */
1051 return ioctl_standard_call(dev,
1054 &iw_handler_get_private);
1056 // ## Fall-through for old API ##
1060 if (!netif_device_present(dev))
1062 /* New driver API : try to find the handler */
1063 handler = get_handler(dev, cmd);
1064 if (handler != NULL) {
1065 /* Standard and private are not the same */
1066 if (cmd < SIOCIWFIRSTPRIV)
1067 return ioctl_standard_call(dev,
1072 return ioctl_private_call(dev,
1077 /* Old driver API : call driver ioctl handler */
1078 if (dev->do_ioctl) {
1079 return dev->do_ioctl(dev, ifr, cmd);
1087 /* entry point from dev ioctl */
1088 int wext_handle_ioctl(struct ifreq *ifr, unsigned int cmd,
1093 /* If command is `set a parameter', or
1094 * `get the encoding parameters', check if
1095 * the user has the right to do it */
1096 if (IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT)
1097 if (!capable(CAP_NET_ADMIN))
1099 dev_load(ifr->ifr_name);
1101 ret = wireless_process_ioctl(ifr, cmd);
1103 if (IW_IS_GET(cmd) && copy_to_user(arg, ifr, sizeof(struct ifreq)))
1108 /************************* EVENT PROCESSING *************************/
1110 * Process events generated by the wireless layer or the driver.
1111 * Most often, the event will be propagated through rtnetlink
1114 /* ---------------------------------------------------------------- */
1119 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1120 * the locking issue in here and implementing this code !
1122 * The issue : wireless_send_event() is often called in interrupt context,
1123 * while the Netlink layer can never be called in interrupt context.
1124 * The fully formed RtNetlink events are queued, and then a tasklet is run
1125 * to feed those to Netlink.
1126 * The skb_queue is interrupt safe, and its lock is not held while calling
1127 * Netlink, so there is no possibility of dealock.
1131 static struct sk_buff_head wireless_nlevent_queue;
1133 static int __init wireless_nlevent_init(void)
1135 skb_queue_head_init(&wireless_nlevent_queue);
1139 subsys_initcall(wireless_nlevent_init);
1141 static void wireless_nlevent_process(unsigned long data)
1143 struct sk_buff *skb;
1145 while ((skb = skb_dequeue(&wireless_nlevent_queue)))
1146 rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
1149 static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0);
1151 /* ---------------------------------------------------------------- */
1153 * Fill a rtnetlink message with our event data.
1154 * Note that we propage only the specified event and don't dump the
1155 * current wireless config. Dumping the wireless config is far too
1156 * expensive (for each parameter, the driver need to query the hardware).
1158 static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
1159 struct net_device * dev,
1164 struct ifinfomsg *r;
1165 struct nlmsghdr *nlh;
1166 unsigned char *b = skb_tail_pointer(skb);
1168 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
1169 r = NLMSG_DATA(nlh);
1170 r->ifi_family = AF_UNSPEC;
1172 r->ifi_type = dev->type;
1173 r->ifi_index = dev->ifindex;
1174 r->ifi_flags = dev_get_flags(dev);
1175 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1177 /* Add the wireless events in the netlink packet */
1178 RTA_PUT(skb, IFLA_WIRELESS, event_len, event);
1180 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1189 /* ---------------------------------------------------------------- */
1191 * Create and broadcast and send it on the standard rtnetlink socket
1192 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1193 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1194 * within a RTM_NEWLINK event.
1196 static inline void rtmsg_iwinfo(struct net_device * dev,
1200 struct sk_buff *skb;
1201 int size = NLMSG_GOODSIZE;
1203 skb = alloc_skb(size, GFP_ATOMIC);
1207 if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
1208 event, event_len) < 0) {
1212 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
1213 skb_queue_tail(&wireless_nlevent_queue, skb);
1214 tasklet_schedule(&wireless_nlevent_tasklet);
1217 /* ---------------------------------------------------------------- */
1219 * Main event dispatcher. Called from other parts and drivers.
1220 * Send the event on the appropriate channels.
1221 * May be called from interrupt context.
1223 void wireless_send_event(struct net_device * dev,
1225 union iwreq_data * wrqu,
1228 const struct iw_ioctl_description * descr = NULL;
1230 struct iw_event *event; /* Mallocated whole event */
1231 int event_len; /* Its size */
1232 int hdr_len; /* Size of the event header */
1233 int wrqu_off = 0; /* Offset in wrqu */
1234 /* Don't "optimise" the following variable, it will crash */
1235 unsigned cmd_index; /* *MUST* be unsigned */
1237 /* Get the description of the Event */
1238 if (cmd <= SIOCIWLAST) {
1239 cmd_index = cmd - SIOCIWFIRST;
1240 if (cmd_index < standard_ioctl_num)
1241 descr = &(standard_ioctl[cmd_index]);
1243 cmd_index = cmd - IWEVFIRST;
1244 if (cmd_index < standard_event_num)
1245 descr = &(standard_event[cmd_index]);
1247 /* Don't accept unknown events */
1248 if (descr == NULL) {
1249 /* Note : we don't return an error to the driver, because
1250 * the driver would not know what to do about it. It can't
1251 * return an error to the user, because the event is not
1252 * initiated by a user request.
1253 * The best the driver could do is to log an error message.
1254 * We will do it ourselves instead...
1256 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1261 /* Check extra parameters and set extra_len */
1262 if (descr->header_type == IW_HEADER_TYPE_POINT) {
1263 /* Check if number of token fits within bounds */
1264 if (wrqu->data.length > descr->max_tokens) {
1265 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
1268 if (wrqu->data.length < descr->min_tokens) {
1269 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
1272 /* Calculate extra_len - extra is NULL for restricted events */
1274 extra_len = wrqu->data.length * descr->token_size;
1275 /* Always at an offset in wrqu */
1276 wrqu_off = IW_EV_POINT_OFF;
1279 /* Total length of the event */
1280 hdr_len = event_type_size[descr->header_type];
1281 event_len = hdr_len + extra_len;
1283 /* Create temporary buffer to hold the event */
1284 event = kmalloc(event_len, GFP_ATOMIC);
1289 event->len = event_len;
1291 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
1293 memcpy(((char *) event) + hdr_len, extra, extra_len);
1295 /* Send via the RtNetlink event channel */
1296 rtmsg_iwinfo(dev, (char *) event, event_len);
1301 return; /* Always success, I guess ;-) */
1304 /********************** ENHANCED IWSPY SUPPORT **********************/
1306 * In the old days, the driver was handling spy support all by itself.
1307 * Now, the driver can delegate this task to Wireless Extensions.
1308 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1309 * push data to us via wireless_spy_update() and include struct iw_spy_data
1310 * in its private part (and export it in net_device->wireless_data->spy_data).
1311 * One of the main advantage of centralising spy support here is that
1312 * it becomes much easier to improve and extend it without having to touch
1313 * the drivers. One example is the addition of the Spy-Threshold events.
1316 /* ---------------------------------------------------------------- */
1318 * Return the pointer to the spy data in the driver.
1319 * Because this is called on the Rx path via wireless_spy_update(),
1320 * we want it to be efficient...
1322 static inline struct iw_spy_data * get_spydata(struct net_device *dev)
1324 /* This is the new way */
1325 if (dev->wireless_data)
1326 return(dev->wireless_data->spy_data);
1330 /*------------------------------------------------------------------*/
1332 * Standard Wireless Handler : set Spy List
1334 int iw_handler_set_spy(struct net_device * dev,
1335 struct iw_request_info * info,
1336 union iwreq_data * wrqu,
1339 struct iw_spy_data * spydata = get_spydata(dev);
1340 struct sockaddr * address = (struct sockaddr *) extra;
1342 /* Make sure driver is not buggy or using the old API */
1346 /* Disable spy collection while we copy the addresses.
1347 * While we copy addresses, any call to wireless_spy_update()
1348 * will NOP. This is OK, as anyway the addresses are changing. */
1349 spydata->spy_number = 0;
1351 /* We want to operate without locking, because wireless_spy_update()
1352 * most likely will happen in the interrupt handler, and therefore
1353 * have its own locking constraints and needs performance.
1354 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1355 * This make sure wireless_spy_update() "see" that the spy list
1356 * is temporarily disabled. */
1359 /* Are there are addresses to copy? */
1360 if (wrqu->data.length > 0) {
1363 /* Copy addresses */
1364 for (i = 0; i < wrqu->data.length; i++)
1365 memcpy(spydata->spy_address[i], address[i].sa_data,
1368 memset(spydata->spy_stat, 0,
1369 sizeof(struct iw_quality) * IW_MAX_SPY);
1372 /* Make sure above is updated before re-enabling */
1375 /* Enable addresses */
1376 spydata->spy_number = wrqu->data.length;
1381 /*------------------------------------------------------------------*/
1383 * Standard Wireless Handler : get Spy List
1385 int iw_handler_get_spy(struct net_device * dev,
1386 struct iw_request_info * info,
1387 union iwreq_data * wrqu,
1390 struct iw_spy_data * spydata = get_spydata(dev);
1391 struct sockaddr * address = (struct sockaddr *) extra;
1394 /* Make sure driver is not buggy or using the old API */
1398 wrqu->data.length = spydata->spy_number;
1400 /* Copy addresses. */
1401 for (i = 0; i < spydata->spy_number; i++) {
1402 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
1403 address[i].sa_family = AF_UNIX;
1405 /* Copy stats to the user buffer (just after). */
1406 if (spydata->spy_number > 0)
1407 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
1409 sizeof(struct iw_quality) * spydata->spy_number);
1410 /* Reset updated flags. */
1411 for (i = 0; i < spydata->spy_number; i++)
1412 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
1416 /*------------------------------------------------------------------*/
1418 * Standard Wireless Handler : set spy threshold
1420 int iw_handler_set_thrspy(struct net_device * dev,
1421 struct iw_request_info *info,
1422 union iwreq_data * wrqu,
1425 struct iw_spy_data * spydata = get_spydata(dev);
1426 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1428 /* Make sure driver is not buggy or using the old API */
1433 memcpy(&(spydata->spy_thr_low), &(threshold->low),
1434 2 * sizeof(struct iw_quality));
1437 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
1442 /*------------------------------------------------------------------*/
1444 * Standard Wireless Handler : get spy threshold
1446 int iw_handler_get_thrspy(struct net_device * dev,
1447 struct iw_request_info *info,
1448 union iwreq_data * wrqu,
1451 struct iw_spy_data * spydata = get_spydata(dev);
1452 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1454 /* Make sure driver is not buggy or using the old API */
1459 memcpy(&(threshold->low), &(spydata->spy_thr_low),
1460 2 * sizeof(struct iw_quality));
1465 /*------------------------------------------------------------------*/
1467 * Prepare and send a Spy Threshold event
1469 static void iw_send_thrspy_event(struct net_device * dev,
1470 struct iw_spy_data * spydata,
1471 unsigned char * address,
1472 struct iw_quality * wstats)
1474 union iwreq_data wrqu;
1475 struct iw_thrspy threshold;
1478 wrqu.data.length = 1;
1479 wrqu.data.flags = 0;
1481 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
1482 threshold.addr.sa_family = ARPHRD_ETHER;
1484 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
1485 /* Copy also thresholds */
1486 memcpy(&(threshold.low), &(spydata->spy_thr_low),
1487 2 * sizeof(struct iw_quality));
1489 /* Send event to user space */
1490 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
1493 /* ---------------------------------------------------------------- */
1495 * Call for the driver to update the spy data.
1496 * For now, the spy data is a simple array. As the size of the array is
1497 * small, this is good enough. If we wanted to support larger number of
1498 * spy addresses, we should use something more efficient...
1500 void wireless_spy_update(struct net_device * dev,
1501 unsigned char * address,
1502 struct iw_quality * wstats)
1504 struct iw_spy_data * spydata = get_spydata(dev);
1508 /* Make sure driver is not buggy or using the old API */
1512 /* Update all records that match */
1513 for (i = 0; i < spydata->spy_number; i++)
1514 if (!compare_ether_addr(address, spydata->spy_address[i])) {
1515 memcpy(&(spydata->spy_stat[i]), wstats,
1516 sizeof(struct iw_quality));
1520 /* Generate an event if we cross the spy threshold.
1521 * To avoid event storms, we have a simple hysteresis : we generate
1522 * event only when we go under the low threshold or above the
1523 * high threshold. */
1525 if (spydata->spy_thr_under[match]) {
1526 if (wstats->level > spydata->spy_thr_high.level) {
1527 spydata->spy_thr_under[match] = 0;
1528 iw_send_thrspy_event(dev, spydata,
1532 if (wstats->level < spydata->spy_thr_low.level) {
1533 spydata->spy_thr_under[match] = 1;
1534 iw_send_thrspy_event(dev, spydata,
1541 EXPORT_SYMBOL(iw_handler_get_spy);
1542 EXPORT_SYMBOL(iw_handler_get_thrspy);
1543 EXPORT_SYMBOL(iw_handler_set_spy);
1544 EXPORT_SYMBOL(iw_handler_set_thrspy);
1545 EXPORT_SYMBOL(wireless_send_event);
1546 EXPORT_SYMBOL(wireless_spy_update);