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 /**************************** CONSTANTS ****************************/
107 #define WE_EVENT_RTNETLINK /* Propagate events using RtNetlink */
108 #define WE_SET_EVENT /* Generate an event on some set commands */
110 /************************* GLOBAL VARIABLES *************************/
112 * You should not use global variables, because of re-entrancy.
113 * On our case, it's only const, so it's OK...
116 * Meta-data about all the standard Wireless Extension request we
119 static const struct iw_ioctl_description standard_ioctl[] = {
120 [SIOCSIWCOMMIT - SIOCIWFIRST] = {
121 .header_type = IW_HEADER_TYPE_NULL,
123 [SIOCGIWNAME - SIOCIWFIRST] = {
124 .header_type = IW_HEADER_TYPE_CHAR,
125 .flags = IW_DESCR_FLAG_DUMP,
127 [SIOCSIWNWID - SIOCIWFIRST] = {
128 .header_type = IW_HEADER_TYPE_PARAM,
129 .flags = IW_DESCR_FLAG_EVENT,
131 [SIOCGIWNWID - SIOCIWFIRST] = {
132 .header_type = IW_HEADER_TYPE_PARAM,
133 .flags = IW_DESCR_FLAG_DUMP,
135 [SIOCSIWFREQ - SIOCIWFIRST] = {
136 .header_type = IW_HEADER_TYPE_FREQ,
137 .flags = IW_DESCR_FLAG_EVENT,
139 [SIOCGIWFREQ - SIOCIWFIRST] = {
140 .header_type = IW_HEADER_TYPE_FREQ,
141 .flags = IW_DESCR_FLAG_DUMP,
143 [SIOCSIWMODE - SIOCIWFIRST] = {
144 .header_type = IW_HEADER_TYPE_UINT,
145 .flags = IW_DESCR_FLAG_EVENT,
147 [SIOCGIWMODE - SIOCIWFIRST] = {
148 .header_type = IW_HEADER_TYPE_UINT,
149 .flags = IW_DESCR_FLAG_DUMP,
151 [SIOCSIWSENS - SIOCIWFIRST] = {
152 .header_type = IW_HEADER_TYPE_PARAM,
154 [SIOCGIWSENS - SIOCIWFIRST] = {
155 .header_type = IW_HEADER_TYPE_PARAM,
157 [SIOCSIWRANGE - SIOCIWFIRST] = {
158 .header_type = IW_HEADER_TYPE_NULL,
160 [SIOCGIWRANGE - SIOCIWFIRST] = {
161 .header_type = IW_HEADER_TYPE_POINT,
163 .max_tokens = sizeof(struct iw_range),
164 .flags = IW_DESCR_FLAG_DUMP,
166 [SIOCSIWPRIV - SIOCIWFIRST] = {
167 .header_type = IW_HEADER_TYPE_NULL,
169 [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */
170 .header_type = IW_HEADER_TYPE_POINT,
171 .token_size = sizeof(struct iw_priv_args),
173 .flags = IW_DESCR_FLAG_NOMAX,
175 [SIOCSIWSTATS - SIOCIWFIRST] = {
176 .header_type = IW_HEADER_TYPE_NULL,
178 [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */
179 .header_type = IW_HEADER_TYPE_POINT,
181 .max_tokens = sizeof(struct iw_statistics),
182 .flags = IW_DESCR_FLAG_DUMP,
184 [SIOCSIWSPY - SIOCIWFIRST] = {
185 .header_type = IW_HEADER_TYPE_POINT,
186 .token_size = sizeof(struct sockaddr),
187 .max_tokens = IW_MAX_SPY,
189 [SIOCGIWSPY - SIOCIWFIRST] = {
190 .header_type = IW_HEADER_TYPE_POINT,
191 .token_size = sizeof(struct sockaddr) +
192 sizeof(struct iw_quality),
193 .max_tokens = IW_MAX_SPY,
195 [SIOCSIWTHRSPY - SIOCIWFIRST] = {
196 .header_type = IW_HEADER_TYPE_POINT,
197 .token_size = sizeof(struct iw_thrspy),
201 [SIOCGIWTHRSPY - SIOCIWFIRST] = {
202 .header_type = IW_HEADER_TYPE_POINT,
203 .token_size = sizeof(struct iw_thrspy),
207 [SIOCSIWAP - SIOCIWFIRST] = {
208 .header_type = IW_HEADER_TYPE_ADDR,
210 [SIOCGIWAP - SIOCIWFIRST] = {
211 .header_type = IW_HEADER_TYPE_ADDR,
212 .flags = IW_DESCR_FLAG_DUMP,
214 [SIOCSIWMLME - SIOCIWFIRST] = {
215 .header_type = IW_HEADER_TYPE_POINT,
217 .min_tokens = sizeof(struct iw_mlme),
218 .max_tokens = sizeof(struct iw_mlme),
220 [SIOCGIWAPLIST - SIOCIWFIRST] = {
221 .header_type = IW_HEADER_TYPE_POINT,
222 .token_size = sizeof(struct sockaddr) +
223 sizeof(struct iw_quality),
224 .max_tokens = IW_MAX_AP,
225 .flags = IW_DESCR_FLAG_NOMAX,
227 [SIOCSIWSCAN - SIOCIWFIRST] = {
228 .header_type = IW_HEADER_TYPE_POINT,
231 .max_tokens = sizeof(struct iw_scan_req),
233 [SIOCGIWSCAN - SIOCIWFIRST] = {
234 .header_type = IW_HEADER_TYPE_POINT,
236 .max_tokens = IW_SCAN_MAX_DATA,
237 .flags = IW_DESCR_FLAG_NOMAX,
239 [SIOCSIWESSID - SIOCIWFIRST] = {
240 .header_type = IW_HEADER_TYPE_POINT,
242 .max_tokens = IW_ESSID_MAX_SIZE,
243 .flags = IW_DESCR_FLAG_EVENT,
245 [SIOCGIWESSID - SIOCIWFIRST] = {
246 .header_type = IW_HEADER_TYPE_POINT,
248 .max_tokens = IW_ESSID_MAX_SIZE,
249 .flags = IW_DESCR_FLAG_DUMP,
251 [SIOCSIWNICKN - SIOCIWFIRST] = {
252 .header_type = IW_HEADER_TYPE_POINT,
254 .max_tokens = IW_ESSID_MAX_SIZE,
256 [SIOCGIWNICKN - SIOCIWFIRST] = {
257 .header_type = IW_HEADER_TYPE_POINT,
259 .max_tokens = IW_ESSID_MAX_SIZE,
261 [SIOCSIWRATE - SIOCIWFIRST] = {
262 .header_type = IW_HEADER_TYPE_PARAM,
264 [SIOCGIWRATE - SIOCIWFIRST] = {
265 .header_type = IW_HEADER_TYPE_PARAM,
267 [SIOCSIWRTS - SIOCIWFIRST] = {
268 .header_type = IW_HEADER_TYPE_PARAM,
270 [SIOCGIWRTS - SIOCIWFIRST] = {
271 .header_type = IW_HEADER_TYPE_PARAM,
273 [SIOCSIWFRAG - SIOCIWFIRST] = {
274 .header_type = IW_HEADER_TYPE_PARAM,
276 [SIOCGIWFRAG - SIOCIWFIRST] = {
277 .header_type = IW_HEADER_TYPE_PARAM,
279 [SIOCSIWTXPOW - SIOCIWFIRST] = {
280 .header_type = IW_HEADER_TYPE_PARAM,
282 [SIOCGIWTXPOW - SIOCIWFIRST] = {
283 .header_type = IW_HEADER_TYPE_PARAM,
285 [SIOCSIWRETRY - SIOCIWFIRST] = {
286 .header_type = IW_HEADER_TYPE_PARAM,
288 [SIOCGIWRETRY - SIOCIWFIRST] = {
289 .header_type = IW_HEADER_TYPE_PARAM,
291 [SIOCSIWENCODE - SIOCIWFIRST] = {
292 .header_type = IW_HEADER_TYPE_POINT,
294 .max_tokens = IW_ENCODING_TOKEN_MAX,
295 .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
297 [SIOCGIWENCODE - SIOCIWFIRST] = {
298 .header_type = IW_HEADER_TYPE_POINT,
300 .max_tokens = IW_ENCODING_TOKEN_MAX,
301 .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
303 [SIOCSIWPOWER - SIOCIWFIRST] = {
304 .header_type = IW_HEADER_TYPE_PARAM,
306 [SIOCGIWPOWER - SIOCIWFIRST] = {
307 .header_type = IW_HEADER_TYPE_PARAM,
309 [SIOCSIWGENIE - SIOCIWFIRST] = {
310 .header_type = IW_HEADER_TYPE_POINT,
312 .max_tokens = IW_GENERIC_IE_MAX,
314 [SIOCGIWGENIE - SIOCIWFIRST] = {
315 .header_type = IW_HEADER_TYPE_POINT,
317 .max_tokens = IW_GENERIC_IE_MAX,
319 [SIOCSIWAUTH - SIOCIWFIRST] = {
320 .header_type = IW_HEADER_TYPE_PARAM,
322 [SIOCGIWAUTH - SIOCIWFIRST] = {
323 .header_type = IW_HEADER_TYPE_PARAM,
325 [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
326 .header_type = IW_HEADER_TYPE_POINT,
328 .min_tokens = sizeof(struct iw_encode_ext),
329 .max_tokens = sizeof(struct iw_encode_ext) +
330 IW_ENCODING_TOKEN_MAX,
332 [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
333 .header_type = IW_HEADER_TYPE_POINT,
335 .min_tokens = sizeof(struct iw_encode_ext),
336 .max_tokens = sizeof(struct iw_encode_ext) +
337 IW_ENCODING_TOKEN_MAX,
339 [SIOCSIWPMKSA - SIOCIWFIRST] = {
340 .header_type = IW_HEADER_TYPE_POINT,
342 .min_tokens = sizeof(struct iw_pmksa),
343 .max_tokens = sizeof(struct iw_pmksa),
346 static const unsigned standard_ioctl_num = ARRAY_SIZE(standard_ioctl);
349 * Meta-data about all the additional standard Wireless Extension events
352 static const struct iw_ioctl_description standard_event[] = {
353 [IWEVTXDROP - IWEVFIRST] = {
354 .header_type = IW_HEADER_TYPE_ADDR,
356 [IWEVQUAL - IWEVFIRST] = {
357 .header_type = IW_HEADER_TYPE_QUAL,
359 [IWEVCUSTOM - IWEVFIRST] = {
360 .header_type = IW_HEADER_TYPE_POINT,
362 .max_tokens = IW_CUSTOM_MAX,
364 [IWEVREGISTERED - IWEVFIRST] = {
365 .header_type = IW_HEADER_TYPE_ADDR,
367 [IWEVEXPIRED - IWEVFIRST] = {
368 .header_type = IW_HEADER_TYPE_ADDR,
370 [IWEVGENIE - IWEVFIRST] = {
371 .header_type = IW_HEADER_TYPE_POINT,
373 .max_tokens = IW_GENERIC_IE_MAX,
375 [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
376 .header_type = IW_HEADER_TYPE_POINT,
378 .max_tokens = sizeof(struct iw_michaelmicfailure),
380 [IWEVASSOCREQIE - IWEVFIRST] = {
381 .header_type = IW_HEADER_TYPE_POINT,
383 .max_tokens = IW_GENERIC_IE_MAX,
385 [IWEVASSOCRESPIE - IWEVFIRST] = {
386 .header_type = IW_HEADER_TYPE_POINT,
388 .max_tokens = IW_GENERIC_IE_MAX,
390 [IWEVPMKIDCAND - IWEVFIRST] = {
391 .header_type = IW_HEADER_TYPE_POINT,
393 .max_tokens = sizeof(struct iw_pmkid_cand),
396 static const unsigned standard_event_num = ARRAY_SIZE(standard_event);
398 /* Size (in bytes) of the various private data types */
399 static const char iw_priv_type_size[] = {
400 0, /* IW_PRIV_TYPE_NONE */
401 1, /* IW_PRIV_TYPE_BYTE */
402 1, /* IW_PRIV_TYPE_CHAR */
404 sizeof(__u32), /* IW_PRIV_TYPE_INT */
405 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
406 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
410 /* Size (in bytes) of various events */
411 static const int event_type_size[] = {
412 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
414 IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
416 IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
417 IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
418 IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
420 IW_EV_POINT_LEN, /* Without variable payload */
421 IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
422 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
425 /* Size (in bytes) of various events, as packed */
426 static const int event_type_pk_size[] = {
427 IW_EV_LCP_PK_LEN, /* IW_HEADER_TYPE_NULL */
429 IW_EV_CHAR_PK_LEN, /* IW_HEADER_TYPE_CHAR */
431 IW_EV_UINT_PK_LEN, /* IW_HEADER_TYPE_UINT */
432 IW_EV_FREQ_PK_LEN, /* IW_HEADER_TYPE_FREQ */
433 IW_EV_ADDR_PK_LEN, /* IW_HEADER_TYPE_ADDR */
435 IW_EV_POINT_PK_LEN, /* Without variable payload */
436 IW_EV_PARAM_PK_LEN, /* IW_HEADER_TYPE_PARAM */
437 IW_EV_QUAL_PK_LEN, /* IW_HEADER_TYPE_QUAL */
440 /************************ COMMON SUBROUTINES ************************/
442 * Stuff that may be used in various place or doesn't fit in one
443 * of the section below.
446 /* ---------------------------------------------------------------- */
448 * Return the driver handler associated with a specific Wireless Extension.
449 * Called from various place, so make sure it remains efficient.
451 static inline iw_handler get_handler(struct net_device *dev,
454 /* Don't "optimise" the following variable, it will crash */
455 unsigned int index; /* *MUST* be unsigned */
457 /* Check if we have some wireless handlers defined */
458 if (dev->wireless_handlers == NULL)
461 /* Try as a standard command */
462 index = cmd - SIOCIWFIRST;
463 if (index < dev->wireless_handlers->num_standard)
464 return dev->wireless_handlers->standard[index];
466 /* Try as a private command */
467 index = cmd - SIOCIWFIRSTPRIV;
468 if (index < dev->wireless_handlers->num_private)
469 return dev->wireless_handlers->private[index];
475 /* ---------------------------------------------------------------- */
477 * Get statistics out of the driver
479 static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
482 if ((dev->wireless_handlers != NULL) &&
483 (dev->wireless_handlers->get_wireless_stats != NULL))
484 return dev->wireless_handlers->get_wireless_stats(dev);
487 return (struct iw_statistics *) NULL;
490 /* ---------------------------------------------------------------- */
492 * Call the commit handler in the driver
493 * (if exist and if conditions are right)
495 * Note : our current commit strategy is currently pretty dumb,
496 * but we will be able to improve on that...
497 * The goal is to try to agreagate as many changes as possible
498 * before doing the commit. Drivers that will define a commit handler
499 * are usually those that need a reset after changing parameters, so
500 * we want to minimise the number of reset.
501 * A cool idea is to use a timer : at each "set" command, we re-set the
502 * timer, when the timer eventually fires, we call the driver.
503 * Hopefully, more on that later.
505 * Also, I'm waiting to see how many people will complain about the
506 * netif_running(dev) test. I'm open on that one...
507 * Hopefully, the driver will remember to do a commit in "open()" ;-)
509 static inline int call_commit_handler(struct net_device * dev)
511 if ((netif_running(dev)) &&
512 (dev->wireless_handlers->standard[0] != NULL)) {
513 /* Call the commit handler on the driver */
514 return dev->wireless_handlers->standard[0](dev, NULL,
517 return 0; /* Command completed successfully */
520 /* ---------------------------------------------------------------- */
522 * Calculate size of private arguments
524 static inline int get_priv_size(__u16 args)
526 int num = args & IW_PRIV_SIZE_MASK;
527 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
529 return num * iw_priv_type_size[type];
532 /* ---------------------------------------------------------------- */
534 * Re-calculate the size of private arguments
536 static inline int adjust_priv_size(__u16 args,
537 union iwreq_data * wrqu)
539 int num = wrqu->data.length;
540 int max = args & IW_PRIV_SIZE_MASK;
541 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
543 /* Make sure the driver doesn't goof up */
547 return num * iw_priv_type_size[type];
550 /* ---------------------------------------------------------------- */
552 * Standard Wireless Handler : get wireless stats
553 * Allow programatic access to /proc/net/wireless even if /proc
554 * doesn't exist... Also more efficient...
556 static int iw_handler_get_iwstats(struct net_device * dev,
557 struct iw_request_info * info,
558 union iwreq_data * wrqu,
561 /* Get stats from the driver */
562 struct iw_statistics *stats;
564 stats = get_wireless_stats(dev);
565 if (stats != (struct iw_statistics *) NULL) {
567 /* Copy statistics to extra */
568 memcpy(extra, stats, sizeof(struct iw_statistics));
569 wrqu->data.length = sizeof(struct iw_statistics);
571 /* Check if we need to clear the updated flag */
572 if (wrqu->data.flags != 0)
573 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
579 /* ---------------------------------------------------------------- */
581 * Standard Wireless Handler : get iwpriv definitions
582 * Export the driver private handler definition
583 * They will be picked up by tools like iwpriv...
585 static int iw_handler_get_private(struct net_device * dev,
586 struct iw_request_info * info,
587 union iwreq_data * wrqu,
590 /* Check if the driver has something to export */
591 if ((dev->wireless_handlers->num_private_args == 0) ||
592 (dev->wireless_handlers->private_args == NULL))
595 /* Check if there is enough buffer up there */
596 if (wrqu->data.length < dev->wireless_handlers->num_private_args) {
597 /* User space can't know in advance how large the buffer
598 * needs to be. Give it a hint, so that we can support
599 * any size buffer we want somewhat efficiently... */
600 wrqu->data.length = dev->wireless_handlers->num_private_args;
604 /* Set the number of available ioctls. */
605 wrqu->data.length = dev->wireless_handlers->num_private_args;
607 /* Copy structure to the user buffer. */
608 memcpy(extra, dev->wireless_handlers->private_args,
609 sizeof(struct iw_priv_args) * wrqu->data.length);
615 /******************** /proc/net/wireless SUPPORT ********************/
617 * The /proc/net/wireless file is a human readable user-space interface
618 * exporting various wireless specific statistics from the wireless devices.
619 * This is the most popular part of the Wireless Extensions ;-)
621 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
622 * The content of the file is basically the content of "struct iw_statistics".
625 #ifdef CONFIG_PROC_FS
627 /* ---------------------------------------------------------------- */
629 * Print one entry (line) of /proc/net/wireless
631 static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
632 struct net_device *dev)
634 /* Get stats from the driver */
635 struct iw_statistics *stats = get_wireless_stats(dev);
638 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
640 dev->name, stats->status, stats->qual.qual,
641 stats->qual.updated & IW_QUAL_QUAL_UPDATED
643 ((__s32) stats->qual.level) -
644 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
645 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
647 ((__s32) stats->qual.noise) -
648 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
649 stats->qual.updated & IW_QUAL_NOISE_UPDATED
651 stats->discard.nwid, stats->discard.code,
652 stats->discard.fragment, stats->discard.retries,
653 stats->discard.misc, stats->miss.beacon);
654 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
658 /* ---------------------------------------------------------------- */
660 * Print info for /proc/net/wireless (print all entries)
662 static int wireless_seq_show(struct seq_file *seq, void *v)
664 if (v == SEQ_START_TOKEN)
665 seq_printf(seq, "Inter-| sta-| Quality | Discarded "
666 "packets | Missed | WE\n"
667 " face | tus | link level noise | nwid "
668 "crypt frag retry misc | beacon | %d\n",
671 wireless_seq_printf_stats(seq, v);
675 static const struct seq_operations wireless_seq_ops = {
676 .start = dev_seq_start,
677 .next = dev_seq_next,
678 .stop = dev_seq_stop,
679 .show = wireless_seq_show,
682 static int wireless_seq_open(struct inode *inode, struct file *file)
684 return seq_open(file, &wireless_seq_ops);
687 static const struct file_operations wireless_seq_fops = {
688 .owner = THIS_MODULE,
689 .open = wireless_seq_open,
692 .release = seq_release,
695 int __init wext_proc_init(void)
697 /* Create /proc/net/wireless entry */
698 if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
703 #endif /* CONFIG_PROC_FS */
705 /************************** IOCTL SUPPORT **************************/
707 * The original user space API to configure all those Wireless Extensions
709 * In there, we check if we need to call the new driver API (iw_handler)
710 * or just call the driver ioctl handler.
713 /* ---------------------------------------------------------------- */
715 * Wrapper to call a standard Wireless Extension handler.
716 * We do various checks and also take care of moving data between
717 * user space and kernel space.
719 static int ioctl_standard_call(struct net_device * dev,
724 struct iwreq * iwr = (struct iwreq *) ifr;
725 const struct iw_ioctl_description * descr;
726 struct iw_request_info info;
729 /* Get the description of the IOCTL */
730 if ((cmd - SIOCIWFIRST) >= standard_ioctl_num)
732 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
734 /* Prepare the call */
738 /* Check if we have a pointer to user space data or not */
739 if (descr->header_type != IW_HEADER_TYPE_POINT) {
741 /* No extra arguments. Trivial to handle */
742 ret = handler(dev, &info, &(iwr->u), NULL);
745 /* Generate an event to notify listeners of the change */
746 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
747 ((ret == 0) || (ret == -EIWCOMMIT)))
748 wireless_send_event(dev, cmd, &(iwr->u), NULL);
749 #endif /* WE_SET_EVENT */
755 int essid_compat = 0;
757 /* Calculate space needed by arguments. Always allocate
758 * for max space. Easier, and won't last long... */
759 extra_size = descr->max_tokens * descr->token_size;
761 /* Check need for ESSID compatibility for WE < 21 */
767 if (iwr->u.data.length == descr->max_tokens + 1)
769 else if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
770 char essid[IW_ESSID_MAX_SIZE + 1];
772 err = copy_from_user(essid, iwr->u.data.pointer,
778 if (essid[iwr->u.data.length - 1] == '\0')
786 iwr->u.data.length -= essid_compat;
788 /* Check what user space is giving us */
789 if (IW_IS_SET(cmd)) {
790 /* Check NULL pointer */
791 if ((iwr->u.data.pointer == NULL) &&
792 (iwr->u.data.length != 0))
794 /* Check if number of token fits within bounds */
795 if (iwr->u.data.length > descr->max_tokens)
797 if (iwr->u.data.length < descr->min_tokens)
800 /* Check NULL pointer */
801 if (iwr->u.data.pointer == NULL)
803 /* Save user space buffer size for checking */
804 user_length = iwr->u.data.length;
806 /* Don't check if user_length > max to allow forward
807 * compatibility. The test user_length < min is
808 * implied by the test at the end. */
810 /* Support for very large requests */
811 if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
812 (user_length > descr->max_tokens)) {
813 /* Allow userspace to GET more than max so
814 * we can support any size GET requests.
815 * There is still a limit : -ENOMEM. */
816 extra_size = user_length * descr->token_size;
817 /* Note : user_length is originally a __u16,
818 * and token_size is controlled by us,
819 * so extra_size won't get negative and
820 * won't overflow... */
824 /* Create the kernel buffer */
825 /* kzalloc ensures NULL-termination for essid_compat */
826 extra = kzalloc(extra_size, GFP_KERNEL);
831 /* If it is a SET, get all the extra data in here */
832 if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
833 err = copy_from_user(extra, iwr->u.data.pointer,
842 /* Call the handler */
843 ret = handler(dev, &info, &(iwr->u), extra);
845 iwr->u.data.length += essid_compat;
847 /* If we have something to return to the user */
848 if (!ret && IW_IS_GET(cmd)) {
849 /* Check if there is enough buffer up there */
850 if (user_length < iwr->u.data.length) {
855 err = copy_to_user(iwr->u.data.pointer, extra,
863 /* Generate an event to notify listeners of the change */
864 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
865 ((ret == 0) || (ret == -EIWCOMMIT))) {
866 if (descr->flags & IW_DESCR_FLAG_RESTRICT)
867 /* If the event is restricted, don't
868 * export the payload */
869 wireless_send_event(dev, cmd, &(iwr->u), NULL);
871 wireless_send_event(dev, cmd, &(iwr->u),
874 #endif /* WE_SET_EVENT */
876 /* Cleanup - I told you it wasn't that long ;-) */
880 /* Call commit handler if needed and defined */
881 if (ret == -EIWCOMMIT)
882 ret = call_commit_handler(dev);
884 /* Here, we will generate the appropriate event if needed */
889 /* ---------------------------------------------------------------- */
891 * Wrapper to call a private Wireless Extension handler.
892 * We do various checks and also take care of moving data between
893 * user space and kernel space.
894 * It's not as nice and slimline as the standard wrapper. The cause
895 * is struct iw_priv_args, which was not really designed for the
896 * job we are going here.
898 * IMPORTANT : This function prevent to set and get data on the same
899 * IOCTL and enforce the SET/GET convention. Not doing it would be
901 * If you need to set and get data at the same time, please don't use
902 * a iw_handler but process it in your ioctl handler (i.e. use the
905 static inline int ioctl_private_call(struct net_device * dev,
910 struct iwreq * iwr = (struct iwreq *) ifr;
911 const struct iw_priv_args * descr = NULL;
912 struct iw_request_info info;
917 /* Get the description of the IOCTL */
918 for (i = 0; i < dev->wireless_handlers->num_private_args; i++)
919 if (cmd == dev->wireless_handlers->private_args[i].cmd) {
920 descr = &(dev->wireless_handlers->private_args[i]);
924 /* Compute the size of the set/get arguments */
926 if (IW_IS_SET(cmd)) {
927 int offset = 0; /* For sub-ioctls */
928 /* Check for sub-ioctl handler */
929 if (descr->name[0] == '\0')
930 /* Reserve one int for sub-ioctl index */
931 offset = sizeof(__u32);
933 /* Size of set arguments */
934 extra_size = get_priv_size(descr->set_args);
936 /* Does it fits in iwr ? */
937 if ((descr->set_args & IW_PRIV_SIZE_FIXED) &&
938 ((extra_size + offset) <= IFNAMSIZ))
941 /* Size of get arguments */
942 extra_size = get_priv_size(descr->get_args);
944 /* Does it fits in iwr ? */
945 if ((descr->get_args & IW_PRIV_SIZE_FIXED) &&
946 (extra_size <= IFNAMSIZ))
951 /* Prepare the call */
955 /* Check if we have a pointer to user space data or not. */
956 if (extra_size == 0) {
957 /* No extra arguments. Trivial to handle */
958 ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u));
963 /* Check what user space is giving us */
964 if (IW_IS_SET(cmd)) {
965 /* Check NULL pointer */
966 if ((iwr->u.data.pointer == NULL) &&
967 (iwr->u.data.length != 0))
970 /* Does it fits within bounds ? */
971 if (iwr->u.data.length > (descr->set_args &
975 /* Check NULL pointer */
976 if (iwr->u.data.pointer == NULL)
980 /* Always allocate for max space. Easier, and won't last
982 extra = kmalloc(extra_size, GFP_KERNEL);
987 /* If it is a SET, get all the extra data in here */
988 if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
989 err = copy_from_user(extra, iwr->u.data.pointer,
997 /* Call the handler */
998 ret = handler(dev, &info, &(iwr->u), extra);
1000 /* If we have something to return to the user */
1001 if (!ret && IW_IS_GET(cmd)) {
1003 /* Adjust for the actual length if it's variable,
1004 * avoid leaking kernel bits outside. */
1005 if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) {
1006 extra_size = adjust_priv_size(descr->get_args,
1010 err = copy_to_user(iwr->u.data.pointer, extra,
1016 /* Cleanup - I told you it wasn't that long ;-) */
1021 /* Call commit handler if needed and defined */
1022 if (ret == -EIWCOMMIT)
1023 ret = call_commit_handler(dev);
1028 /* ---------------------------------------------------------------- */
1030 * Main IOCTl dispatcher.
1031 * Check the type of IOCTL and call the appropriate wrapper...
1033 static int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
1035 struct net_device *dev;
1038 /* Permissions are already checked in dev_ioctl() before calling us.
1039 * The copy_to/from_user() of ifr is also dealt with in there */
1041 /* Make sure the device exist */
1042 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
1045 /* A bunch of special cases, then the generic case...
1046 * Note that 'cmd' is already filtered in dev_ioctl() with
1047 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1050 /* Get Wireless Stats */
1051 return ioctl_standard_call(dev,
1054 &iw_handler_get_iwstats);
1057 /* Check if we have some wireless handlers defined */
1058 if (dev->wireless_handlers != NULL) {
1059 /* We export to user space the definition of
1060 * the private handler ourselves */
1061 return ioctl_standard_call(dev,
1064 &iw_handler_get_private);
1066 // ## Fall-through for old API ##
1070 if (!netif_device_present(dev))
1072 /* New driver API : try to find the handler */
1073 handler = get_handler(dev, cmd);
1074 if (handler != NULL) {
1075 /* Standard and private are not the same */
1076 if (cmd < SIOCIWFIRSTPRIV)
1077 return ioctl_standard_call(dev,
1082 return ioctl_private_call(dev,
1087 /* Old driver API : call driver ioctl handler */
1088 if (dev->do_ioctl) {
1089 return dev->do_ioctl(dev, ifr, cmd);
1097 /* entry point from dev ioctl */
1098 int wext_handle_ioctl(struct ifreq *ifr, unsigned int cmd,
1103 /* If command is `set a parameter', or
1104 * `get the encoding parameters', check if
1105 * the user has the right to do it */
1106 if (IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT)
1107 if (!capable(CAP_NET_ADMIN))
1109 dev_load(ifr->ifr_name);
1111 ret = wireless_process_ioctl(ifr, cmd);
1113 if (IW_IS_GET(cmd) && copy_to_user(arg, ifr, sizeof(struct ifreq)))
1118 /************************* EVENT PROCESSING *************************/
1120 * Process events generated by the wireless layer or the driver.
1121 * Most often, the event will be propagated through rtnetlink
1124 #ifdef WE_EVENT_RTNETLINK
1125 /* ---------------------------------------------------------------- */
1130 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1131 * the locking issue in here and implementing this code !
1133 * The issue : wireless_send_event() is often called in interrupt context,
1134 * while the Netlink layer can never be called in interrupt context.
1135 * The fully formed RtNetlink events are queued, and then a tasklet is run
1136 * to feed those to Netlink.
1137 * The skb_queue is interrupt safe, and its lock is not held while calling
1138 * Netlink, so there is no possibility of dealock.
1142 static struct sk_buff_head wireless_nlevent_queue;
1144 static int __init wireless_nlevent_init(void)
1146 skb_queue_head_init(&wireless_nlevent_queue);
1150 subsys_initcall(wireless_nlevent_init);
1152 static void wireless_nlevent_process(unsigned long data)
1154 struct sk_buff *skb;
1156 while ((skb = skb_dequeue(&wireless_nlevent_queue)))
1157 rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
1160 static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0);
1162 /* ---------------------------------------------------------------- */
1164 * Fill a rtnetlink message with our event data.
1165 * Note that we propage only the specified event and don't dump the
1166 * current wireless config. Dumping the wireless config is far too
1167 * expensive (for each parameter, the driver need to query the hardware).
1169 static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
1170 struct net_device * dev,
1175 struct ifinfomsg *r;
1176 struct nlmsghdr *nlh;
1177 unsigned char *b = skb_tail_pointer(skb);
1179 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
1180 r = NLMSG_DATA(nlh);
1181 r->ifi_family = AF_UNSPEC;
1183 r->ifi_type = dev->type;
1184 r->ifi_index = dev->ifindex;
1185 r->ifi_flags = dev_get_flags(dev);
1186 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1188 /* Add the wireless events in the netlink packet */
1189 RTA_PUT(skb, IFLA_WIRELESS, event_len, event);
1191 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1200 /* ---------------------------------------------------------------- */
1202 * Create and broadcast and send it on the standard rtnetlink socket
1203 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1204 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1205 * within a RTM_NEWLINK event.
1207 static inline void rtmsg_iwinfo(struct net_device * dev,
1211 struct sk_buff *skb;
1212 int size = NLMSG_GOODSIZE;
1214 skb = alloc_skb(size, GFP_ATOMIC);
1218 if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
1219 event, event_len) < 0) {
1223 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
1224 skb_queue_tail(&wireless_nlevent_queue, skb);
1225 tasklet_schedule(&wireless_nlevent_tasklet);
1228 #endif /* WE_EVENT_RTNETLINK */
1230 /* ---------------------------------------------------------------- */
1232 * Main event dispatcher. Called from other parts and drivers.
1233 * Send the event on the appropriate channels.
1234 * May be called from interrupt context.
1236 void wireless_send_event(struct net_device * dev,
1238 union iwreq_data * wrqu,
1241 const struct iw_ioctl_description * descr = NULL;
1243 struct iw_event *event; /* Mallocated whole event */
1244 int event_len; /* Its size */
1245 int hdr_len; /* Size of the event header */
1246 int wrqu_off = 0; /* Offset in wrqu */
1247 /* Don't "optimise" the following variable, it will crash */
1248 unsigned cmd_index; /* *MUST* be unsigned */
1250 /* Get the description of the Event */
1251 if (cmd <= SIOCIWLAST) {
1252 cmd_index = cmd - SIOCIWFIRST;
1253 if (cmd_index < standard_ioctl_num)
1254 descr = &(standard_ioctl[cmd_index]);
1256 cmd_index = cmd - IWEVFIRST;
1257 if (cmd_index < standard_event_num)
1258 descr = &(standard_event[cmd_index]);
1260 /* Don't accept unknown events */
1261 if (descr == NULL) {
1262 /* Note : we don't return an error to the driver, because
1263 * the driver would not know what to do about it. It can't
1264 * return an error to the user, because the event is not
1265 * initiated by a user request.
1266 * The best the driver could do is to log an error message.
1267 * We will do it ourselves instead...
1269 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1274 /* Check extra parameters and set extra_len */
1275 if (descr->header_type == IW_HEADER_TYPE_POINT) {
1276 /* Check if number of token fits within bounds */
1277 if (wrqu->data.length > descr->max_tokens) {
1278 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
1281 if (wrqu->data.length < descr->min_tokens) {
1282 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
1285 /* Calculate extra_len - extra is NULL for restricted events */
1287 extra_len = wrqu->data.length * descr->token_size;
1288 /* Always at an offset in wrqu */
1289 wrqu_off = IW_EV_POINT_OFF;
1292 /* Total length of the event */
1293 hdr_len = event_type_size[descr->header_type];
1294 event_len = hdr_len + extra_len;
1296 /* Create temporary buffer to hold the event */
1297 event = kmalloc(event_len, GFP_ATOMIC);
1302 event->len = event_len;
1304 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
1306 memcpy(((char *) event) + hdr_len, extra, extra_len);
1308 #ifdef WE_EVENT_RTNETLINK
1309 /* Send via the RtNetlink event channel */
1310 rtmsg_iwinfo(dev, (char *) event, event_len);
1311 #endif /* WE_EVENT_RTNETLINK */
1316 return; /* Always success, I guess ;-) */
1319 /********************** ENHANCED IWSPY SUPPORT **********************/
1321 * In the old days, the driver was handling spy support all by itself.
1322 * Now, the driver can delegate this task to Wireless Extensions.
1323 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1324 * push data to us via wireless_spy_update() and include struct iw_spy_data
1325 * in its private part (and export it in net_device->wireless_data->spy_data).
1326 * One of the main advantage of centralising spy support here is that
1327 * it becomes much easier to improve and extend it without having to touch
1328 * the drivers. One example is the addition of the Spy-Threshold events.
1331 /* ---------------------------------------------------------------- */
1333 * Return the pointer to the spy data in the driver.
1334 * Because this is called on the Rx path via wireless_spy_update(),
1335 * we want it to be efficient...
1337 static inline struct iw_spy_data * get_spydata(struct net_device *dev)
1339 /* This is the new way */
1340 if (dev->wireless_data)
1341 return(dev->wireless_data->spy_data);
1345 /*------------------------------------------------------------------*/
1347 * Standard Wireless Handler : set Spy List
1349 int iw_handler_set_spy(struct net_device * dev,
1350 struct iw_request_info * info,
1351 union iwreq_data * wrqu,
1354 struct iw_spy_data * spydata = get_spydata(dev);
1355 struct sockaddr * address = (struct sockaddr *) extra;
1357 /* Make sure driver is not buggy or using the old API */
1361 /* Disable spy collection while we copy the addresses.
1362 * While we copy addresses, any call to wireless_spy_update()
1363 * will NOP. This is OK, as anyway the addresses are changing. */
1364 spydata->spy_number = 0;
1366 /* We want to operate without locking, because wireless_spy_update()
1367 * most likely will happen in the interrupt handler, and therefore
1368 * have its own locking constraints and needs performance.
1369 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1370 * This make sure wireless_spy_update() "see" that the spy list
1371 * is temporarily disabled. */
1374 /* Are there are addresses to copy? */
1375 if (wrqu->data.length > 0) {
1378 /* Copy addresses */
1379 for (i = 0; i < wrqu->data.length; i++)
1380 memcpy(spydata->spy_address[i], address[i].sa_data,
1383 memset(spydata->spy_stat, 0,
1384 sizeof(struct iw_quality) * IW_MAX_SPY);
1387 /* Make sure above is updated before re-enabling */
1390 /* Enable addresses */
1391 spydata->spy_number = wrqu->data.length;
1396 /*------------------------------------------------------------------*/
1398 * Standard Wireless Handler : get Spy List
1400 int iw_handler_get_spy(struct net_device * dev,
1401 struct iw_request_info * info,
1402 union iwreq_data * wrqu,
1405 struct iw_spy_data * spydata = get_spydata(dev);
1406 struct sockaddr * address = (struct sockaddr *) extra;
1409 /* Make sure driver is not buggy or using the old API */
1413 wrqu->data.length = spydata->spy_number;
1415 /* Copy addresses. */
1416 for (i = 0; i < spydata->spy_number; i++) {
1417 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
1418 address[i].sa_family = AF_UNIX;
1420 /* Copy stats to the user buffer (just after). */
1421 if (spydata->spy_number > 0)
1422 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
1424 sizeof(struct iw_quality) * spydata->spy_number);
1425 /* Reset updated flags. */
1426 for (i = 0; i < spydata->spy_number; i++)
1427 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
1431 /*------------------------------------------------------------------*/
1433 * Standard Wireless Handler : set spy threshold
1435 int iw_handler_set_thrspy(struct net_device * dev,
1436 struct iw_request_info *info,
1437 union iwreq_data * wrqu,
1440 struct iw_spy_data * spydata = get_spydata(dev);
1441 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1443 /* Make sure driver is not buggy or using the old API */
1448 memcpy(&(spydata->spy_thr_low), &(threshold->low),
1449 2 * sizeof(struct iw_quality));
1452 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
1457 /*------------------------------------------------------------------*/
1459 * Standard Wireless Handler : get spy threshold
1461 int iw_handler_get_thrspy(struct net_device * dev,
1462 struct iw_request_info *info,
1463 union iwreq_data * wrqu,
1466 struct iw_spy_data * spydata = get_spydata(dev);
1467 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1469 /* Make sure driver is not buggy or using the old API */
1474 memcpy(&(threshold->low), &(spydata->spy_thr_low),
1475 2 * sizeof(struct iw_quality));
1480 /*------------------------------------------------------------------*/
1482 * Prepare and send a Spy Threshold event
1484 static void iw_send_thrspy_event(struct net_device * dev,
1485 struct iw_spy_data * spydata,
1486 unsigned char * address,
1487 struct iw_quality * wstats)
1489 union iwreq_data wrqu;
1490 struct iw_thrspy threshold;
1493 wrqu.data.length = 1;
1494 wrqu.data.flags = 0;
1496 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
1497 threshold.addr.sa_family = ARPHRD_ETHER;
1499 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
1500 /* Copy also thresholds */
1501 memcpy(&(threshold.low), &(spydata->spy_thr_low),
1502 2 * sizeof(struct iw_quality));
1504 /* Send event to user space */
1505 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
1508 /* ---------------------------------------------------------------- */
1510 * Call for the driver to update the spy data.
1511 * For now, the spy data is a simple array. As the size of the array is
1512 * small, this is good enough. If we wanted to support larger number of
1513 * spy addresses, we should use something more efficient...
1515 void wireless_spy_update(struct net_device * dev,
1516 unsigned char * address,
1517 struct iw_quality * wstats)
1519 struct iw_spy_data * spydata = get_spydata(dev);
1523 /* Make sure driver is not buggy or using the old API */
1527 /* Update all records that match */
1528 for (i = 0; i < spydata->spy_number; i++)
1529 if (!compare_ether_addr(address, spydata->spy_address[i])) {
1530 memcpy(&(spydata->spy_stat[i]), wstats,
1531 sizeof(struct iw_quality));
1535 /* Generate an event if we cross the spy threshold.
1536 * To avoid event storms, we have a simple hysteresis : we generate
1537 * event only when we go under the low threshold or above the
1538 * high threshold. */
1540 if (spydata->spy_thr_under[match]) {
1541 if (wstats->level > spydata->spy_thr_high.level) {
1542 spydata->spy_thr_under[match] = 0;
1543 iw_send_thrspy_event(dev, spydata,
1547 if (wstats->level < spydata->spy_thr_low.level) {
1548 spydata->spy_thr_under[match] = 1;
1549 iw_send_thrspy_event(dev, spydata,
1556 EXPORT_SYMBOL(iw_handler_get_spy);
1557 EXPORT_SYMBOL(iw_handler_get_thrspy);
1558 EXPORT_SYMBOL(iw_handler_set_spy);
1559 EXPORT_SYMBOL(iw_handler_set_thrspy);
1560 EXPORT_SYMBOL(wireless_send_event);
1561 EXPORT_SYMBOL(wireless_spy_update);