2 * This file implement the Wireless Extensions APIs.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2006 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)
73 /***************************** INCLUDES *****************************/
75 #include <linux/config.h> /* Not needed ??? */
76 #include <linux/module.h>
77 #include <linux/types.h> /* off_t */
78 #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
79 #include <linux/proc_fs.h>
80 #include <linux/rtnetlink.h> /* rtnetlink stuff */
81 #include <linux/seq_file.h>
82 #include <linux/init.h> /* for __init */
83 #include <linux/if_arp.h> /* ARPHRD_ETHER */
84 #include <linux/etherdevice.h> /* compare_ether_addr */
85 #include <linux/interrupt.h>
87 #include <linux/wireless.h> /* Pretty obvious */
88 #include <net/iw_handler.h> /* New driver API */
90 #include <asm/uaccess.h> /* copy_to_user() */
92 /**************************** CONSTANTS ****************************/
95 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
96 #undef WE_RTNETLINK_DEBUG /* Debug RtNetlink API */
97 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
98 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
101 //CONFIG_NET_WIRELESS_RTNETLINK /* Wireless requests over RtNetlink */
102 #define WE_EVENT_RTNETLINK /* Propagate events using RtNetlink */
103 #define WE_SET_EVENT /* Generate an event on some set commands */
105 /************************* GLOBAL VARIABLES *************************/
107 * You should not use global variables, because of re-entrancy.
108 * On our case, it's only const, so it's OK...
111 * Meta-data about all the standard Wireless Extension request we
114 static const struct iw_ioctl_description standard_ioctl[] = {
115 [SIOCSIWCOMMIT - SIOCIWFIRST] = {
116 .header_type = IW_HEADER_TYPE_NULL,
118 [SIOCGIWNAME - SIOCIWFIRST] = {
119 .header_type = IW_HEADER_TYPE_CHAR,
120 .flags = IW_DESCR_FLAG_DUMP,
122 [SIOCSIWNWID - SIOCIWFIRST] = {
123 .header_type = IW_HEADER_TYPE_PARAM,
124 .flags = IW_DESCR_FLAG_EVENT,
126 [SIOCGIWNWID - SIOCIWFIRST] = {
127 .header_type = IW_HEADER_TYPE_PARAM,
128 .flags = IW_DESCR_FLAG_DUMP,
130 [SIOCSIWFREQ - SIOCIWFIRST] = {
131 .header_type = IW_HEADER_TYPE_FREQ,
132 .flags = IW_DESCR_FLAG_EVENT,
134 [SIOCGIWFREQ - SIOCIWFIRST] = {
135 .header_type = IW_HEADER_TYPE_FREQ,
136 .flags = IW_DESCR_FLAG_DUMP,
138 [SIOCSIWMODE - SIOCIWFIRST] = {
139 .header_type = IW_HEADER_TYPE_UINT,
140 .flags = IW_DESCR_FLAG_EVENT,
142 [SIOCGIWMODE - SIOCIWFIRST] = {
143 .header_type = IW_HEADER_TYPE_UINT,
144 .flags = IW_DESCR_FLAG_DUMP,
146 [SIOCSIWSENS - SIOCIWFIRST] = {
147 .header_type = IW_HEADER_TYPE_PARAM,
149 [SIOCGIWSENS - SIOCIWFIRST] = {
150 .header_type = IW_HEADER_TYPE_PARAM,
152 [SIOCSIWRANGE - SIOCIWFIRST] = {
153 .header_type = IW_HEADER_TYPE_NULL,
155 [SIOCGIWRANGE - SIOCIWFIRST] = {
156 .header_type = IW_HEADER_TYPE_POINT,
158 .max_tokens = sizeof(struct iw_range),
159 .flags = IW_DESCR_FLAG_DUMP,
161 [SIOCSIWPRIV - SIOCIWFIRST] = {
162 .header_type = IW_HEADER_TYPE_NULL,
164 [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */
165 .header_type = IW_HEADER_TYPE_POINT,
166 .token_size = sizeof(struct iw_priv_args),
168 .flags = IW_DESCR_FLAG_NOMAX,
170 [SIOCSIWSTATS - SIOCIWFIRST] = {
171 .header_type = IW_HEADER_TYPE_NULL,
173 [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */
174 .header_type = IW_HEADER_TYPE_POINT,
176 .max_tokens = sizeof(struct iw_statistics),
177 .flags = IW_DESCR_FLAG_DUMP,
179 [SIOCSIWSPY - SIOCIWFIRST] = {
180 .header_type = IW_HEADER_TYPE_POINT,
181 .token_size = sizeof(struct sockaddr),
182 .max_tokens = IW_MAX_SPY,
184 [SIOCGIWSPY - SIOCIWFIRST] = {
185 .header_type = IW_HEADER_TYPE_POINT,
186 .token_size = sizeof(struct sockaddr) +
187 sizeof(struct iw_quality),
188 .max_tokens = IW_MAX_SPY,
190 [SIOCSIWTHRSPY - SIOCIWFIRST] = {
191 .header_type = IW_HEADER_TYPE_POINT,
192 .token_size = sizeof(struct iw_thrspy),
196 [SIOCGIWTHRSPY - SIOCIWFIRST] = {
197 .header_type = IW_HEADER_TYPE_POINT,
198 .token_size = sizeof(struct iw_thrspy),
202 [SIOCSIWAP - SIOCIWFIRST] = {
203 .header_type = IW_HEADER_TYPE_ADDR,
205 [SIOCGIWAP - SIOCIWFIRST] = {
206 .header_type = IW_HEADER_TYPE_ADDR,
207 .flags = IW_DESCR_FLAG_DUMP,
209 [SIOCSIWMLME - SIOCIWFIRST] = {
210 .header_type = IW_HEADER_TYPE_POINT,
212 .min_tokens = sizeof(struct iw_mlme),
213 .max_tokens = sizeof(struct iw_mlme),
215 [SIOCGIWAPLIST - SIOCIWFIRST] = {
216 .header_type = IW_HEADER_TYPE_POINT,
217 .token_size = sizeof(struct sockaddr) +
218 sizeof(struct iw_quality),
219 .max_tokens = IW_MAX_AP,
220 .flags = IW_DESCR_FLAG_NOMAX,
222 [SIOCSIWSCAN - SIOCIWFIRST] = {
223 .header_type = IW_HEADER_TYPE_POINT,
226 .max_tokens = sizeof(struct iw_scan_req),
228 [SIOCGIWSCAN - SIOCIWFIRST] = {
229 .header_type = IW_HEADER_TYPE_POINT,
231 .max_tokens = IW_SCAN_MAX_DATA,
232 .flags = IW_DESCR_FLAG_NOMAX,
234 [SIOCSIWESSID - SIOCIWFIRST] = {
235 .header_type = IW_HEADER_TYPE_POINT,
237 .max_tokens = IW_ESSID_MAX_SIZE + 1,
238 .flags = IW_DESCR_FLAG_EVENT,
240 [SIOCGIWESSID - SIOCIWFIRST] = {
241 .header_type = IW_HEADER_TYPE_POINT,
243 .max_tokens = IW_ESSID_MAX_SIZE + 1,
244 .flags = IW_DESCR_FLAG_DUMP,
246 [SIOCSIWNICKN - SIOCIWFIRST] = {
247 .header_type = IW_HEADER_TYPE_POINT,
249 .max_tokens = IW_ESSID_MAX_SIZE + 1,
251 [SIOCGIWNICKN - SIOCIWFIRST] = {
252 .header_type = IW_HEADER_TYPE_POINT,
254 .max_tokens = IW_ESSID_MAX_SIZE + 1,
256 [SIOCSIWRATE - SIOCIWFIRST] = {
257 .header_type = IW_HEADER_TYPE_PARAM,
259 [SIOCGIWRATE - SIOCIWFIRST] = {
260 .header_type = IW_HEADER_TYPE_PARAM,
262 [SIOCSIWRTS - SIOCIWFIRST] = {
263 .header_type = IW_HEADER_TYPE_PARAM,
265 [SIOCGIWRTS - SIOCIWFIRST] = {
266 .header_type = IW_HEADER_TYPE_PARAM,
268 [SIOCSIWFRAG - SIOCIWFIRST] = {
269 .header_type = IW_HEADER_TYPE_PARAM,
271 [SIOCGIWFRAG - SIOCIWFIRST] = {
272 .header_type = IW_HEADER_TYPE_PARAM,
274 [SIOCSIWTXPOW - SIOCIWFIRST] = {
275 .header_type = IW_HEADER_TYPE_PARAM,
277 [SIOCGIWTXPOW - SIOCIWFIRST] = {
278 .header_type = IW_HEADER_TYPE_PARAM,
280 [SIOCSIWRETRY - SIOCIWFIRST] = {
281 .header_type = IW_HEADER_TYPE_PARAM,
283 [SIOCGIWRETRY - SIOCIWFIRST] = {
284 .header_type = IW_HEADER_TYPE_PARAM,
286 [SIOCSIWENCODE - SIOCIWFIRST] = {
287 .header_type = IW_HEADER_TYPE_POINT,
289 .max_tokens = IW_ENCODING_TOKEN_MAX,
290 .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
292 [SIOCGIWENCODE - SIOCIWFIRST] = {
293 .header_type = IW_HEADER_TYPE_POINT,
295 .max_tokens = IW_ENCODING_TOKEN_MAX,
296 .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
298 [SIOCSIWPOWER - SIOCIWFIRST] = {
299 .header_type = IW_HEADER_TYPE_PARAM,
301 [SIOCGIWPOWER - SIOCIWFIRST] = {
302 .header_type = IW_HEADER_TYPE_PARAM,
304 [SIOCSIWGENIE - SIOCIWFIRST] = {
305 .header_type = IW_HEADER_TYPE_POINT,
307 .max_tokens = IW_GENERIC_IE_MAX,
309 [SIOCGIWGENIE - SIOCIWFIRST] = {
310 .header_type = IW_HEADER_TYPE_POINT,
312 .max_tokens = IW_GENERIC_IE_MAX,
314 [SIOCSIWAUTH - SIOCIWFIRST] = {
315 .header_type = IW_HEADER_TYPE_PARAM,
317 [SIOCGIWAUTH - SIOCIWFIRST] = {
318 .header_type = IW_HEADER_TYPE_PARAM,
320 [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
321 .header_type = IW_HEADER_TYPE_POINT,
323 .min_tokens = sizeof(struct iw_encode_ext),
324 .max_tokens = sizeof(struct iw_encode_ext) +
325 IW_ENCODING_TOKEN_MAX,
327 [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
328 .header_type = IW_HEADER_TYPE_POINT,
330 .min_tokens = sizeof(struct iw_encode_ext),
331 .max_tokens = sizeof(struct iw_encode_ext) +
332 IW_ENCODING_TOKEN_MAX,
334 [SIOCSIWPMKSA - SIOCIWFIRST] = {
335 .header_type = IW_HEADER_TYPE_POINT,
337 .min_tokens = sizeof(struct iw_pmksa),
338 .max_tokens = sizeof(struct iw_pmksa),
341 static const int standard_ioctl_num = (sizeof(standard_ioctl) /
342 sizeof(struct iw_ioctl_description));
345 * Meta-data about all the additional standard Wireless Extension events
348 static const struct iw_ioctl_description standard_event[] = {
349 [IWEVTXDROP - IWEVFIRST] = {
350 .header_type = IW_HEADER_TYPE_ADDR,
352 [IWEVQUAL - IWEVFIRST] = {
353 .header_type = IW_HEADER_TYPE_QUAL,
355 [IWEVCUSTOM - IWEVFIRST] = {
356 .header_type = IW_HEADER_TYPE_POINT,
358 .max_tokens = IW_CUSTOM_MAX,
360 [IWEVREGISTERED - IWEVFIRST] = {
361 .header_type = IW_HEADER_TYPE_ADDR,
363 [IWEVEXPIRED - IWEVFIRST] = {
364 .header_type = IW_HEADER_TYPE_ADDR,
366 [IWEVGENIE - IWEVFIRST] = {
367 .header_type = IW_HEADER_TYPE_POINT,
369 .max_tokens = IW_GENERIC_IE_MAX,
371 [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
372 .header_type = IW_HEADER_TYPE_POINT,
374 .max_tokens = sizeof(struct iw_michaelmicfailure),
376 [IWEVASSOCREQIE - IWEVFIRST] = {
377 .header_type = IW_HEADER_TYPE_POINT,
379 .max_tokens = IW_GENERIC_IE_MAX,
381 [IWEVASSOCRESPIE - IWEVFIRST] = {
382 .header_type = IW_HEADER_TYPE_POINT,
384 .max_tokens = IW_GENERIC_IE_MAX,
386 [IWEVPMKIDCAND - IWEVFIRST] = {
387 .header_type = IW_HEADER_TYPE_POINT,
389 .max_tokens = sizeof(struct iw_pmkid_cand),
392 static const int standard_event_num = (sizeof(standard_event) /
393 sizeof(struct iw_ioctl_description));
395 /* Size (in bytes) of the various private data types */
396 static const char iw_priv_type_size[] = {
397 0, /* IW_PRIV_TYPE_NONE */
398 1, /* IW_PRIV_TYPE_BYTE */
399 1, /* IW_PRIV_TYPE_CHAR */
401 sizeof(__u32), /* IW_PRIV_TYPE_INT */
402 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
403 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
407 /* Size (in bytes) of various events */
408 static const int event_type_size[] = {
409 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
411 IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
413 IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
414 IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
415 IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
417 IW_EV_POINT_LEN, /* Without variable payload */
418 IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
419 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
422 /************************ COMMON SUBROUTINES ************************/
424 * Stuff that may be used in various place or doesn't fit in one
425 * of the section below.
428 /* ---------------------------------------------------------------- */
430 * Return the driver handler associated with a specific Wireless Extension.
431 * Called from various place, so make sure it remains efficient.
433 static inline iw_handler get_handler(struct net_device *dev,
436 /* Don't "optimise" the following variable, it will crash */
437 unsigned int index; /* *MUST* be unsigned */
439 /* Check if we have some wireless handlers defined */
440 if(dev->wireless_handlers == NULL)
443 /* Try as a standard command */
444 index = cmd - SIOCIWFIRST;
445 if(index < dev->wireless_handlers->num_standard)
446 return dev->wireless_handlers->standard[index];
448 /* Try as a private command */
449 index = cmd - SIOCIWFIRSTPRIV;
450 if(index < dev->wireless_handlers->num_private)
451 return dev->wireless_handlers->private[index];
457 /* ---------------------------------------------------------------- */
459 * Get statistics out of the driver
461 static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
464 if((dev->wireless_handlers != NULL) &&
465 (dev->wireless_handlers->get_wireless_stats != NULL))
466 return dev->wireless_handlers->get_wireless_stats(dev);
468 /* Old location, field to be removed in next WE */
469 if(dev->get_wireless_stats) {
470 static int printed_message;
472 if (!printed_message++)
473 printk(KERN_DEBUG "%s (WE) : Driver using old /proc/net/wireless support, please fix driver !\n",
476 return dev->get_wireless_stats(dev);
480 return (struct iw_statistics *) NULL;
483 /* ---------------------------------------------------------------- */
485 * Call the commit handler in the driver
486 * (if exist and if conditions are right)
488 * Note : our current commit strategy is currently pretty dumb,
489 * but we will be able to improve on that...
490 * The goal is to try to agreagate as many changes as possible
491 * before doing the commit. Drivers that will define a commit handler
492 * are usually those that need a reset after changing parameters, so
493 * we want to minimise the number of reset.
494 * A cool idea is to use a timer : at each "set" command, we re-set the
495 * timer, when the timer eventually fires, we call the driver.
496 * Hopefully, more on that later.
498 * Also, I'm waiting to see how many people will complain about the
499 * netif_running(dev) test. I'm open on that one...
500 * Hopefully, the driver will remember to do a commit in "open()" ;-)
502 static inline int call_commit_handler(struct net_device * dev)
504 if((netif_running(dev)) &&
505 (dev->wireless_handlers->standard[0] != NULL)) {
506 /* Call the commit handler on the driver */
507 return dev->wireless_handlers->standard[0](dev, NULL,
510 return 0; /* Command completed successfully */
513 /* ---------------------------------------------------------------- */
515 * Calculate size of private arguments
517 static inline int get_priv_size(__u16 args)
519 int num = args & IW_PRIV_SIZE_MASK;
520 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
522 return num * iw_priv_type_size[type];
525 /* ---------------------------------------------------------------- */
527 * Re-calculate the size of private arguments
529 static inline int adjust_priv_size(__u16 args,
530 union iwreq_data * wrqu)
532 int num = wrqu->data.length;
533 int max = args & IW_PRIV_SIZE_MASK;
534 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
536 /* Make sure the driver doesn't goof up */
540 return num * iw_priv_type_size[type];
543 /* ---------------------------------------------------------------- */
545 * Standard Wireless Handler : get wireless stats
546 * Allow programatic access to /proc/net/wireless even if /proc
547 * doesn't exist... Also more efficient...
549 static int iw_handler_get_iwstats(struct net_device * dev,
550 struct iw_request_info * info,
551 union iwreq_data * wrqu,
554 /* Get stats from the driver */
555 struct iw_statistics *stats;
557 stats = get_wireless_stats(dev);
558 if (stats != (struct iw_statistics *) NULL) {
560 /* Copy statistics to extra */
561 memcpy(extra, stats, sizeof(struct iw_statistics));
562 wrqu->data.length = sizeof(struct iw_statistics);
564 /* Check if we need to clear the updated flag */
565 if(wrqu->data.flags != 0)
566 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
572 /* ---------------------------------------------------------------- */
574 * Standard Wireless Handler : get iwpriv definitions
575 * Export the driver private handler definition
576 * They will be picked up by tools like iwpriv...
578 static int iw_handler_get_private(struct net_device * dev,
579 struct iw_request_info * info,
580 union iwreq_data * wrqu,
583 /* Check if the driver has something to export */
584 if((dev->wireless_handlers->num_private_args == 0) ||
585 (dev->wireless_handlers->private_args == NULL))
588 /* Check if there is enough buffer up there */
589 if(wrqu->data.length < dev->wireless_handlers->num_private_args) {
590 /* User space can't know in advance how large the buffer
591 * needs to be. Give it a hint, so that we can support
592 * any size buffer we want somewhat efficiently... */
593 wrqu->data.length = dev->wireless_handlers->num_private_args;
597 /* Set the number of available ioctls. */
598 wrqu->data.length = dev->wireless_handlers->num_private_args;
600 /* Copy structure to the user buffer. */
601 memcpy(extra, dev->wireless_handlers->private_args,
602 sizeof(struct iw_priv_args) * wrqu->data.length);
608 /******************** /proc/net/wireless SUPPORT ********************/
610 * The /proc/net/wireless file is a human readable user-space interface
611 * exporting various wireless specific statistics from the wireless devices.
612 * This is the most popular part of the Wireless Extensions ;-)
614 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
615 * The content of the file is basically the content of "struct iw_statistics".
618 #ifdef CONFIG_PROC_FS
620 /* ---------------------------------------------------------------- */
622 * Print one entry (line) of /proc/net/wireless
624 static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
625 struct net_device *dev)
627 /* Get stats from the driver */
628 struct iw_statistics *stats = get_wireless_stats(dev);
631 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
633 dev->name, stats->status, stats->qual.qual,
634 stats->qual.updated & IW_QUAL_QUAL_UPDATED
636 ((__s32) stats->qual.level) -
637 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
638 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
640 ((__s32) stats->qual.noise) -
641 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
642 stats->qual.updated & IW_QUAL_NOISE_UPDATED
644 stats->discard.nwid, stats->discard.code,
645 stats->discard.fragment, stats->discard.retries,
646 stats->discard.misc, stats->miss.beacon);
647 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
651 /* ---------------------------------------------------------------- */
653 * Print info for /proc/net/wireless (print all entries)
655 static int wireless_seq_show(struct seq_file *seq, void *v)
657 if (v == SEQ_START_TOKEN)
658 seq_printf(seq, "Inter-| sta-| Quality | Discarded "
659 "packets | Missed | WE\n"
660 " face | tus | link level noise | nwid "
661 "crypt frag retry misc | beacon | %d\n",
664 wireless_seq_printf_stats(seq, v);
668 static struct seq_operations wireless_seq_ops = {
669 .start = dev_seq_start,
670 .next = dev_seq_next,
671 .stop = dev_seq_stop,
672 .show = wireless_seq_show,
675 static int wireless_seq_open(struct inode *inode, struct file *file)
677 return seq_open(file, &wireless_seq_ops);
680 static struct file_operations wireless_seq_fops = {
681 .owner = THIS_MODULE,
682 .open = wireless_seq_open,
685 .release = seq_release,
688 int __init wireless_proc_init(void)
690 /* Create /proc/net/wireless entry */
691 if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
696 #endif /* CONFIG_PROC_FS */
698 /************************** IOCTL SUPPORT **************************/
700 * The original user space API to configure all those Wireless Extensions
702 * In there, we check if we need to call the new driver API (iw_handler)
703 * or just call the driver ioctl handler.
706 /* ---------------------------------------------------------------- */
708 * Wrapper to call a standard Wireless Extension handler.
709 * We do various checks and also take care of moving data between
710 * user space and kernel space.
712 static int ioctl_standard_call(struct net_device * dev,
717 struct iwreq * iwr = (struct iwreq *) ifr;
718 const struct iw_ioctl_description * descr;
719 struct iw_request_info info;
722 /* Get the description of the IOCTL */
723 if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
725 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
727 #ifdef WE_IOCTL_DEBUG
728 printk(KERN_DEBUG "%s (WE) : Found standard handler for 0x%04X\n",
730 printk(KERN_DEBUG "%s (WE) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
731 #endif /* WE_IOCTL_DEBUG */
733 /* Prepare the call */
737 /* Check if we have a pointer to user space data or not */
738 if(descr->header_type != IW_HEADER_TYPE_POINT) {
740 /* No extra arguments. Trivial to handle */
741 ret = handler(dev, &info, &(iwr->u), NULL);
744 /* Generate an event to notify listeners of the change */
745 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
746 ((ret == 0) || (ret == -EIWCOMMIT)))
747 wireless_send_event(dev, cmd, &(iwr->u), NULL);
748 #endif /* WE_SET_EVENT */
755 /* Calculate space needed by arguments. Always allocate
756 * for max space. Easier, and won't last long... */
757 extra_size = descr->max_tokens * descr->token_size;
759 /* Check what user space is giving us */
761 /* Check NULL pointer */
762 if((iwr->u.data.pointer == NULL) &&
763 (iwr->u.data.length != 0))
765 /* Check if number of token fits within bounds */
766 if(iwr->u.data.length > descr->max_tokens)
768 if(iwr->u.data.length < descr->min_tokens)
771 /* Check NULL pointer */
772 if(iwr->u.data.pointer == NULL)
774 /* Save user space buffer size for checking */
775 user_length = iwr->u.data.length;
777 /* Don't check if user_length > max to allow forward
778 * compatibility. The test user_length < min is
779 * implied by the test at the end. */
781 /* Support for very large requests */
782 if((descr->flags & IW_DESCR_FLAG_NOMAX) &&
783 (user_length > descr->max_tokens)) {
784 /* Allow userspace to GET more than max so
785 * we can support any size GET requests.
786 * There is still a limit : -ENOMEM. */
787 extra_size = user_length * descr->token_size;
788 /* Note : user_length is originally a __u16,
789 * and token_size is controlled by us,
790 * so extra_size won't get negative and
791 * won't overflow... */
795 #ifdef WE_IOCTL_DEBUG
796 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
797 dev->name, extra_size);
798 #endif /* WE_IOCTL_DEBUG */
800 /* Create the kernel buffer */
801 extra = kmalloc(extra_size, GFP_KERNEL);
806 /* If it is a SET, get all the extra data in here */
807 if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
808 err = copy_from_user(extra, iwr->u.data.pointer,
815 #ifdef WE_IOCTL_DEBUG
816 printk(KERN_DEBUG "%s (WE) : Got %d bytes\n",
818 iwr->u.data.length * descr->token_size);
819 #endif /* WE_IOCTL_DEBUG */
822 /* Call the handler */
823 ret = handler(dev, &info, &(iwr->u), extra);
825 /* If we have something to return to the user */
826 if (!ret && IW_IS_GET(cmd)) {
827 /* Check if there is enough buffer up there */
828 if(user_length < iwr->u.data.length) {
833 err = copy_to_user(iwr->u.data.pointer, extra,
838 #ifdef WE_IOCTL_DEBUG
839 printk(KERN_DEBUG "%s (WE) : Wrote %d bytes\n",
841 iwr->u.data.length * descr->token_size);
842 #endif /* WE_IOCTL_DEBUG */
846 /* Generate an event to notify listeners of the change */
847 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
848 ((ret == 0) || (ret == -EIWCOMMIT))) {
849 if(descr->flags & IW_DESCR_FLAG_RESTRICT)
850 /* If the event is restricted, don't
851 * export the payload */
852 wireless_send_event(dev, cmd, &(iwr->u), NULL);
854 wireless_send_event(dev, cmd, &(iwr->u),
857 #endif /* WE_SET_EVENT */
859 /* Cleanup - I told you it wasn't that long ;-) */
863 /* Call commit handler if needed and defined */
864 if(ret == -EIWCOMMIT)
865 ret = call_commit_handler(dev);
867 /* Here, we will generate the appropriate event if needed */
872 /* ---------------------------------------------------------------- */
874 * Wrapper to call a private Wireless Extension handler.
875 * We do various checks and also take care of moving data between
876 * user space and kernel space.
877 * It's not as nice and slimline as the standard wrapper. The cause
878 * is struct iw_priv_args, which was not really designed for the
879 * job we are going here.
881 * IMPORTANT : This function prevent to set and get data on the same
882 * IOCTL and enforce the SET/GET convention. Not doing it would be
884 * If you need to set and get data at the same time, please don't use
885 * a iw_handler but process it in your ioctl handler (i.e. use the
888 static inline int ioctl_private_call(struct net_device * dev,
893 struct iwreq * iwr = (struct iwreq *) ifr;
894 const struct iw_priv_args * descr = NULL;
895 struct iw_request_info info;
900 /* Get the description of the IOCTL */
901 for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
902 if(cmd == dev->wireless_handlers->private_args[i].cmd) {
903 descr = &(dev->wireless_handlers->private_args[i]);
907 #ifdef WE_IOCTL_DEBUG
908 printk(KERN_DEBUG "%s (WE) : Found private handler for 0x%04X\n",
911 printk(KERN_DEBUG "%s (WE) : Name %s, set %X, get %X\n",
912 dev->name, descr->name,
913 descr->set_args, descr->get_args);
915 #endif /* WE_IOCTL_DEBUG */
917 /* Compute the size of the set/get arguments */
920 int offset = 0; /* For sub-ioctls */
921 /* Check for sub-ioctl handler */
922 if(descr->name[0] == '\0')
923 /* Reserve one int for sub-ioctl index */
924 offset = sizeof(__u32);
926 /* Size of set arguments */
927 extra_size = get_priv_size(descr->set_args);
929 /* Does it fits in iwr ? */
930 if((descr->set_args & IW_PRIV_SIZE_FIXED) &&
931 ((extra_size + offset) <= IFNAMSIZ))
934 /* Size of get arguments */
935 extra_size = get_priv_size(descr->get_args);
937 /* Does it fits in iwr ? */
938 if((descr->get_args & IW_PRIV_SIZE_FIXED) &&
939 (extra_size <= IFNAMSIZ))
944 /* Prepare the call */
948 /* Check if we have a pointer to user space data or not. */
949 if(extra_size == 0) {
950 /* No extra arguments. Trivial to handle */
951 ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u));
956 /* Check what user space is giving us */
958 /* Check NULL pointer */
959 if((iwr->u.data.pointer == NULL) &&
960 (iwr->u.data.length != 0))
963 /* Does it fits within bounds ? */
964 if(iwr->u.data.length > (descr->set_args &
968 /* Check NULL pointer */
969 if(iwr->u.data.pointer == NULL)
973 #ifdef WE_IOCTL_DEBUG
974 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
975 dev->name, extra_size);
976 #endif /* WE_IOCTL_DEBUG */
978 /* Always allocate for max space. Easier, and won't last
980 extra = kmalloc(extra_size, GFP_KERNEL);
985 /* If it is a SET, get all the extra data in here */
986 if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
987 err = copy_from_user(extra, iwr->u.data.pointer,
993 #ifdef WE_IOCTL_DEBUG
994 printk(KERN_DEBUG "%s (WE) : Got %d elem\n",
995 dev->name, iwr->u.data.length);
996 #endif /* WE_IOCTL_DEBUG */
999 /* Call the handler */
1000 ret = handler(dev, &info, &(iwr->u), extra);
1002 /* If we have something to return to the user */
1003 if (!ret && IW_IS_GET(cmd)) {
1005 /* Adjust for the actual length if it's variable,
1006 * avoid leaking kernel bits outside. */
1007 if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) {
1008 extra_size = adjust_priv_size(descr->get_args,
1012 err = copy_to_user(iwr->u.data.pointer, extra,
1016 #ifdef WE_IOCTL_DEBUG
1017 printk(KERN_DEBUG "%s (WE) : Wrote %d elem\n",
1018 dev->name, iwr->u.data.length);
1019 #endif /* WE_IOCTL_DEBUG */
1022 /* Cleanup - I told you it wasn't that long ;-) */
1027 /* Call commit handler if needed and defined */
1028 if(ret == -EIWCOMMIT)
1029 ret = call_commit_handler(dev);
1034 /* ---------------------------------------------------------------- */
1036 * Main IOCTl dispatcher. Called from the main networking code
1037 * (dev_ioctl() in net/core/dev.c).
1038 * Check the type of IOCTL and call the appropriate wrapper...
1040 int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
1042 struct net_device *dev;
1045 /* Permissions are already checked in dev_ioctl() before calling us.
1046 * The copy_to/from_user() of ifr is also dealt with in there */
1048 /* Make sure the device exist */
1049 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
1052 /* A bunch of special cases, then the generic case...
1053 * Note that 'cmd' is already filtered in dev_ioctl() with
1054 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1058 /* Get Wireless Stats */
1059 return ioctl_standard_call(dev,
1062 &iw_handler_get_iwstats);
1065 /* Check if we have some wireless handlers defined */
1066 if(dev->wireless_handlers != NULL) {
1067 /* We export to user space the definition of
1068 * the private handler ourselves */
1069 return ioctl_standard_call(dev,
1072 &iw_handler_get_private);
1074 // ## Fall-through for old API ##
1078 if (!netif_device_present(dev))
1080 /* New driver API : try to find the handler */
1081 handler = get_handler(dev, cmd);
1082 if(handler != NULL) {
1083 /* Standard and private are not the same */
1084 if(cmd < SIOCIWFIRSTPRIV)
1085 return ioctl_standard_call(dev,
1090 return ioctl_private_call(dev,
1095 /* Old driver API : call driver ioctl handler */
1096 if (dev->do_ioctl) {
1097 return dev->do_ioctl(dev, ifr, cmd);
1105 /********************** RTNETLINK REQUEST API **********************/
1107 * The alternate user space API to configure all those Wireless Extensions
1108 * is through RtNetlink.
1109 * This API support only the new driver API (iw_handler).
1111 * This RtNetlink API use the same query/reply model as the ioctl API.
1112 * Maximum effort has been done to fit in the RtNetlink model, and
1113 * we support both RtNetlink Set and RtNelink Get operations.
1114 * On the other hand, we don't offer Dump operations because of the
1115 * following reasons :
1116 * o Large number of parameters, most optional
1117 * o Large size of some parameters (> 100 bytes)
1118 * o Each parameters need to be extracted from hardware
1119 * o Scan requests can take seconds and disable network activity.
1120 * Because of this high cost/overhead, we want to return only the
1121 * parameters the user application is really interested in.
1122 * We could offer partial Dump using the IW_DESCR_FLAG_DUMP flag.
1124 * The API uses the standard RtNetlink socket. When the RtNetlink code
1125 * find a IFLA_WIRELESS field in a RtNetlink SET_LINK request,
1129 #ifdef CONFIG_NET_WIRELESS_RTNETLINK
1130 /* ---------------------------------------------------------------- */
1132 * Wrapper to call a standard Wireless Extension GET handler.
1133 * We do various checks and call the handler with the proper args.
1135 static int rtnetlink_standard_get(struct net_device * dev,
1136 struct iw_event * request,
1142 const struct iw_ioctl_description * descr = NULL;
1144 union iwreq_data * wrqu;
1146 struct iw_request_info info;
1147 char * buffer = NULL;
1148 int buffer_size = 0;
1151 /* Get the description of the Request */
1153 if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
1155 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
1157 #ifdef WE_RTNETLINK_DEBUG
1158 printk(KERN_DEBUG "%s (WE.r) : Found standard handler for 0x%04X\n",
1160 printk(KERN_DEBUG "%s (WE.r) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
1161 #endif /* WE_RTNETLINK_DEBUG */
1163 /* Check if wrqu is complete */
1164 hdr_len = event_type_size[descr->header_type];
1165 if(request_len < hdr_len) {
1166 #ifdef WE_RTNETLINK_DEBUG
1168 "%s (WE.r) : Wireless request too short (%d)\n",
1169 dev->name, request_len);
1170 #endif /* WE_RTNETLINK_DEBUG */
1174 /* Prepare the call */
1178 /* Check if we have extra data in the reply or not */
1179 if(descr->header_type != IW_HEADER_TYPE_POINT) {
1181 /* Create the kernel buffer that we will return.
1182 * It's at an offset to match the TYPE_POINT case... */
1183 buffer_size = request_len + IW_EV_POINT_OFF;
1184 buffer = kmalloc(buffer_size, GFP_KERNEL);
1185 if (buffer == NULL) {
1188 /* Copy event data */
1189 memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
1190 /* Use our own copy of wrqu */
1191 wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
1194 /* No extra arguments. Trivial to handle */
1195 ret = handler(dev, &info, wrqu, NULL);
1198 union iwreq_data wrqu_point;
1199 char * extra = NULL;
1202 /* Get a temp copy of wrqu (skip pointer) */
1203 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1204 ((char *) request) + IW_EV_LCP_LEN,
1205 IW_EV_POINT_LEN - IW_EV_LCP_LEN);
1207 /* Calculate space needed by arguments. Always allocate
1208 * for max space. Easier, and won't last long... */
1209 extra_size = descr->max_tokens * descr->token_size;
1210 /* Support for very large requests */
1211 if((descr->flags & IW_DESCR_FLAG_NOMAX) &&
1212 (wrqu_point.data.length > descr->max_tokens))
1213 extra_size = (wrqu_point.data.length
1214 * descr->token_size);
1215 buffer_size = extra_size + IW_EV_POINT_LEN + IW_EV_POINT_OFF;
1216 #ifdef WE_RTNETLINK_DEBUG
1217 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1218 dev->name, extra_size, buffer_size);
1219 #endif /* WE_RTNETLINK_DEBUG */
1221 /* Create the kernel buffer that we will return */
1222 buffer = kmalloc(buffer_size, GFP_KERNEL);
1223 if (buffer == NULL) {
1227 /* Put wrqu in the right place (just before extra).
1228 * Leave space for IWE header and dummy pointer...
1229 * Note that IW_EV_LCP_LEN==4 bytes, so it's still aligned...
1231 memcpy(buffer + IW_EV_LCP_LEN + IW_EV_POINT_OFF,
1232 ((char *) &wrqu_point) + IW_EV_POINT_OFF,
1233 IW_EV_POINT_LEN - IW_EV_LCP_LEN);
1234 wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_LEN);
1236 /* Extra comes logically after that. Offset +12 bytes. */
1237 extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_LEN;
1239 /* Call the handler */
1240 ret = handler(dev, &info, wrqu, extra);
1242 /* Calculate real returned length */
1243 extra_size = (wrqu->data.length * descr->token_size);
1244 /* Re-adjust reply size */
1245 request->len = extra_size + IW_EV_POINT_LEN;
1247 /* Put the iwe header where it should, i.e. scrap the
1249 memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_LEN);
1251 #ifdef WE_RTNETLINK_DEBUG
1252 printk(KERN_DEBUG "%s (WE.r) : Reply 0x%04X, hdr_len %d, tokens %d, extra_size %d, buffer_size %d\n", dev->name, cmd, hdr_len, wrqu->data.length, extra_size, buffer_size);
1253 #endif /* WE_RTNETLINK_DEBUG */
1255 /* Check if there is enough buffer up there */
1256 if(wrqu_point.data.length < wrqu->data.length)
1260 /* Return the buffer to the caller */
1263 *p_len = request->len;
1273 /* ---------------------------------------------------------------- */
1275 * Wrapper to call a standard Wireless Extension SET handler.
1276 * We do various checks and call the handler with the proper args.
1278 static inline int rtnetlink_standard_set(struct net_device * dev,
1279 struct iw_event * request,
1283 const struct iw_ioctl_description * descr = NULL;
1285 union iwreq_data * wrqu;
1286 union iwreq_data wrqu_point;
1288 char * extra = NULL;
1290 struct iw_request_info info;
1293 /* Get the description of the Request */
1295 if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
1297 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
1299 #ifdef WE_RTNETLINK_DEBUG
1300 printk(KERN_DEBUG "%s (WE.r) : Found standard SET handler for 0x%04X\n",
1302 printk(KERN_DEBUG "%s (WE.r) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
1303 #endif /* WE_RTNETLINK_DEBUG */
1305 /* Extract fixed header from request. This is properly aligned. */
1308 /* Check if wrqu is complete */
1309 hdr_len = event_type_size[descr->header_type];
1310 if(request_len < hdr_len) {
1311 #ifdef WE_RTNETLINK_DEBUG
1313 "%s (WE.r) : Wireless request too short (%d)\n",
1314 dev->name, request_len);
1315 #endif /* WE_RTNETLINK_DEBUG */
1319 /* Prepare the call */
1323 /* Check if we have extra data in the request or not */
1324 if(descr->header_type != IW_HEADER_TYPE_POINT) {
1326 /* No extra arguments. Trivial to handle */
1327 ret = handler(dev, &info, wrqu, NULL);
1332 /* Put wrqu in the right place (skip pointer) */
1333 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1334 wrqu, IW_EV_POINT_LEN - IW_EV_LCP_LEN);
1335 /* Don't forget about the event code... */
1338 /* Check if number of token fits within bounds */
1339 if(wrqu_point.data.length > descr->max_tokens)
1341 if(wrqu_point.data.length < descr->min_tokens)
1344 /* Real length of payload */
1345 extra_len = wrqu_point.data.length * descr->token_size;
1347 /* Check if request is self consistent */
1348 if((request_len - hdr_len) < extra_len) {
1349 #ifdef WE_RTNETLINK_DEBUG
1350 printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
1351 dev->name, extra_size);
1352 #endif /* WE_RTNETLINK_DEBUG */
1356 #ifdef WE_RTNETLINK_DEBUG
1357 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
1358 dev->name, extra_size);
1359 #endif /* WE_RTNETLINK_DEBUG */
1361 /* Always allocate for max space. Easier, and won't last
1363 extra_size = descr->max_tokens * descr->token_size;
1364 extra = kmalloc(extra_size, GFP_KERNEL);
1368 /* Copy extra in aligned buffer */
1369 memcpy(extra, ((char *) request) + hdr_len, extra_len);
1371 /* Call the handler */
1372 ret = handler(dev, &info, &wrqu_point, extra);
1376 /* Generate an event to notify listeners of the change */
1377 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
1378 ((ret == 0) || (ret == -EIWCOMMIT))) {
1379 if(descr->flags & IW_DESCR_FLAG_RESTRICT)
1380 /* If the event is restricted, don't
1381 * export the payload */
1382 wireless_send_event(dev, cmd, wrqu, NULL);
1384 wireless_send_event(dev, cmd, wrqu, extra);
1386 #endif /* WE_SET_EVENT */
1388 /* Cleanup - I told you it wasn't that long ;-) */
1392 /* Call commit handler if needed and defined */
1393 if(ret == -EIWCOMMIT)
1394 ret = call_commit_handler(dev);
1399 /* ---------------------------------------------------------------- */
1401 * Wrapper to call a private Wireless Extension GET handler.
1403 * It's not as nice and slimline as the standard wrapper. The cause
1404 * is struct iw_priv_args, which was not really designed for the
1405 * job we are going here.
1407 * IMPORTANT : This function prevent to set and get data on the same
1408 * IOCTL and enforce the SET/GET convention. Not doing it would be
1410 * If you need to set and get data at the same time, please don't use
1411 * a iw_handler but process it in your ioctl handler (i.e. use the
1414 static inline int rtnetlink_private_get(struct net_device * dev,
1415 struct iw_event * request,
1421 const struct iw_priv_args * descr = NULL;
1423 union iwreq_data * wrqu;
1425 struct iw_request_info info;
1428 char * buffer = NULL;
1429 int buffer_size = 0;
1432 /* Get the description of the Request */
1434 for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
1435 if(cmd == dev->wireless_handlers->private_args[i].cmd) {
1436 descr = &(dev->wireless_handlers->private_args[i]);
1442 #ifdef WE_RTNETLINK_DEBUG
1443 printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
1445 printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
1446 dev->name, descr->name, descr->set_args, descr->get_args);
1447 #endif /* WE_RTNETLINK_DEBUG */
1449 /* Compute the max size of the get arguments */
1450 extra_size = get_priv_size(descr->get_args);
1452 /* Does it fits in wrqu ? */
1453 if((descr->get_args & IW_PRIV_SIZE_FIXED) &&
1454 (extra_size <= IFNAMSIZ)) {
1455 hdr_len = extra_size;
1458 hdr_len = IW_EV_POINT_LEN;
1461 /* Check if wrqu is complete */
1462 if(request_len < hdr_len) {
1463 #ifdef WE_RTNETLINK_DEBUG
1465 "%s (WE.r) : Wireless request too short (%d)\n",
1466 dev->name, request_len);
1467 #endif /* WE_RTNETLINK_DEBUG */
1471 /* Prepare the call */
1475 /* Check if we have a pointer to user space data or not. */
1476 if(extra_size == 0) {
1478 /* Create the kernel buffer that we will return.
1479 * It's at an offset to match the TYPE_POINT case... */
1480 buffer_size = request_len + IW_EV_POINT_OFF;
1481 buffer = kmalloc(buffer_size, GFP_KERNEL);
1482 if (buffer == NULL) {
1485 /* Copy event data */
1486 memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
1487 /* Use our own copy of wrqu */
1488 wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
1491 /* No extra arguments. Trivial to handle */
1492 ret = handler(dev, &info, wrqu, (char *) wrqu);
1497 /* Buffer for full reply */
1498 buffer_size = extra_size + IW_EV_POINT_LEN + IW_EV_POINT_OFF;
1500 #ifdef WE_RTNETLINK_DEBUG
1501 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1502 dev->name, extra_size, buffer_size);
1503 #endif /* WE_RTNETLINK_DEBUG */
1505 /* Create the kernel buffer that we will return */
1506 buffer = kmalloc(buffer_size, GFP_KERNEL);
1507 if (buffer == NULL) {
1511 /* Put wrqu in the right place (just before extra).
1512 * Leave space for IWE header and dummy pointer...
1513 * Note that IW_EV_LCP_LEN==4 bytes, so it's still aligned...
1515 memcpy(buffer + IW_EV_LCP_LEN + IW_EV_POINT_OFF,
1516 ((char *) request) + IW_EV_LCP_LEN,
1517 IW_EV_POINT_LEN - IW_EV_LCP_LEN);
1518 wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_LEN);
1520 /* Extra comes logically after that. Offset +12 bytes. */
1521 extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_LEN;
1523 /* Call the handler */
1524 ret = handler(dev, &info, wrqu, extra);
1526 /* Adjust for the actual length if it's variable,
1527 * avoid leaking kernel bits outside. */
1528 if (!(descr->get_args & IW_PRIV_SIZE_FIXED))
1529 extra_size = adjust_priv_size(descr->get_args, wrqu);
1530 /* Re-adjust reply size */
1531 request->len = extra_size + IW_EV_POINT_LEN;
1533 /* Put the iwe header where it should, i.e. scrap the
1535 memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_LEN);
1537 #ifdef WE_RTNETLINK_DEBUG
1538 printk(KERN_DEBUG "%s (WE.r) : Reply 0x%04X, hdr_len %d, tokens %d, extra_size %d, buffer_size %d\n", dev->name, cmd, hdr_len, wrqu->data.length, extra_size, buffer_size);
1539 #endif /* WE_RTNETLINK_DEBUG */
1542 /* Return the buffer to the caller */
1545 *p_len = request->len;
1555 /* ---------------------------------------------------------------- */
1557 * Wrapper to call a private Wireless Extension SET handler.
1559 * It's not as nice and slimline as the standard wrapper. The cause
1560 * is struct iw_priv_args, which was not really designed for the
1561 * job we are going here.
1563 * IMPORTANT : This function prevent to set and get data on the same
1564 * IOCTL and enforce the SET/GET convention. Not doing it would be
1566 * If you need to set and get data at the same time, please don't use
1567 * a iw_handler but process it in your ioctl handler (i.e. use the
1570 static inline int rtnetlink_private_set(struct net_device * dev,
1571 struct iw_event * request,
1575 const struct iw_priv_args * descr = NULL;
1577 union iwreq_data * wrqu;
1578 union iwreq_data wrqu_point;
1580 char * extra = NULL;
1582 int offset = 0; /* For sub-ioctls */
1583 struct iw_request_info info;
1587 /* Get the description of the Request */
1589 for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
1590 if(cmd == dev->wireless_handlers->private_args[i].cmd) {
1591 descr = &(dev->wireless_handlers->private_args[i]);
1597 #ifdef WE_RTNETLINK_DEBUG
1598 printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
1599 ifr->ifr_name, cmd);
1600 printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
1601 dev->name, descr->name, descr->set_args, descr->get_args);
1602 #endif /* WE_RTNETLINK_DEBUG */
1604 /* Compute the size of the set arguments */
1605 /* Check for sub-ioctl handler */
1606 if(descr->name[0] == '\0')
1607 /* Reserve one int for sub-ioctl index */
1608 offset = sizeof(__u32);
1610 /* Size of set arguments */
1611 extra_size = get_priv_size(descr->set_args);
1613 /* Does it fits in wrqu ? */
1614 if((descr->set_args & IW_PRIV_SIZE_FIXED) &&
1615 (extra_size <= IFNAMSIZ)) {
1616 hdr_len = IW_EV_LCP_LEN + extra_size;
1619 hdr_len = IW_EV_POINT_LEN;
1622 /* Extract fixed header from request. This is properly aligned. */
1625 /* Check if wrqu is complete */
1626 if(request_len < hdr_len) {
1627 #ifdef WE_RTNETLINK_DEBUG
1629 "%s (WE.r) : Wireless request too short (%d)\n",
1630 dev->name, request_len);
1631 #endif /* WE_RTNETLINK_DEBUG */
1635 /* Prepare the call */
1639 /* Check if we have a pointer to user space data or not. */
1640 if(extra_size == 0) {
1642 /* No extra arguments. Trivial to handle */
1643 ret = handler(dev, &info, wrqu, (char *) wrqu);
1648 /* Put wrqu in the right place (skip pointer) */
1649 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1650 wrqu, IW_EV_POINT_LEN - IW_EV_LCP_LEN);
1652 /* Does it fits within bounds ? */
1653 if(wrqu_point.data.length > (descr->set_args &
1657 /* Real length of payload */
1658 extra_len = adjust_priv_size(descr->set_args, &wrqu_point);
1660 /* Check if request is self consistent */
1661 if((request_len - hdr_len) < extra_len) {
1662 #ifdef WE_RTNETLINK_DEBUG
1663 printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
1664 dev->name, extra_size);
1665 #endif /* WE_RTNETLINK_DEBUG */
1669 #ifdef WE_RTNETLINK_DEBUG
1670 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
1671 dev->name, extra_size);
1672 #endif /* WE_RTNETLINK_DEBUG */
1674 /* Always allocate for max space. Easier, and won't last
1676 extra = kmalloc(extra_size, GFP_KERNEL);
1680 /* Copy extra in aligned buffer */
1681 memcpy(extra, ((char *) request) + hdr_len, extra_len);
1683 /* Call the handler */
1684 ret = handler(dev, &info, &wrqu_point, extra);
1686 /* Cleanup - I told you it wasn't that long ;-) */
1690 /* Call commit handler if needed and defined */
1691 if(ret == -EIWCOMMIT)
1692 ret = call_commit_handler(dev);
1697 /* ---------------------------------------------------------------- */
1699 * Main RtNetlink dispatcher. Called from the main networking code
1700 * (do_getlink() in net/core/rtnetlink.c).
1701 * Check the type of Request and call the appropriate wrapper...
1703 int wireless_rtnetlink_get(struct net_device * dev,
1709 struct iw_event * request = (struct iw_event *) data;
1713 if(len < IW_EV_LCP_LEN) {
1714 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
1719 /* ReCheck length (len may have padding) */
1720 if(request->len > len) {
1721 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1722 dev->name, request->len, len);
1726 /* Only accept GET requests in here */
1727 if(!IW_IS_GET(request->cmd))
1730 /* If command is `get the encoding parameters', check if
1731 * the user has the right to do it */
1732 if (request->cmd == SIOCGIWENCODE ||
1733 request->cmd == SIOCGIWENCODEEXT) {
1734 if (!capable(CAP_NET_ADMIN))
1739 if(request->cmd == SIOCGIWSTATS)
1740 /* Get Wireless Stats */
1741 return rtnetlink_standard_get(dev,
1744 &iw_handler_get_iwstats,
1746 if(request->cmd == SIOCGIWPRIV) {
1747 /* Check if we have some wireless handlers defined */
1748 if(dev->wireless_handlers == NULL)
1750 /* Get Wireless Stats */
1751 return rtnetlink_standard_get(dev,
1754 &iw_handler_get_private,
1759 if (!netif_device_present(dev))
1762 /* Try to find the handler */
1763 handler = get_handler(dev, request->cmd);
1764 if(handler != NULL) {
1765 /* Standard and private are not the same */
1766 if(request->cmd < SIOCIWFIRSTPRIV)
1767 return rtnetlink_standard_get(dev,
1773 return rtnetlink_private_get(dev,
1783 /* ---------------------------------------------------------------- */
1785 * Main RtNetlink dispatcher. Called from the main networking code
1786 * (do_setlink() in net/core/rtnetlink.c).
1787 * Check the type of Request and call the appropriate wrapper...
1789 int wireless_rtnetlink_set(struct net_device * dev,
1793 struct iw_event * request = (struct iw_event *) data;
1797 if(len < IW_EV_LCP_LEN) {
1798 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
1803 /* ReCheck length (len may have padding) */
1804 if(request->len > len) {
1805 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1806 dev->name, request->len, len);
1810 /* Only accept SET requests in here */
1811 if(!IW_IS_SET(request->cmd))
1815 if (!netif_device_present(dev))
1818 /* New driver API : try to find the handler */
1819 handler = get_handler(dev, request->cmd);
1820 if(handler != NULL) {
1821 /* Standard and private are not the same */
1822 if(request->cmd < SIOCIWFIRSTPRIV)
1823 return rtnetlink_standard_set(dev,
1828 return rtnetlink_private_set(dev,
1836 #endif /* CONFIG_NET_WIRELESS_RTNETLINK */
1839 /************************* EVENT PROCESSING *************************/
1841 * Process events generated by the wireless layer or the driver.
1842 * Most often, the event will be propagated through rtnetlink
1845 #ifdef WE_EVENT_RTNETLINK
1846 static struct sk_buff_head wireless_nlevent_queue;
1848 static void wireless_nlevent_process(unsigned long data)
1850 struct sk_buff *skb;
1852 while ((skb = skb_dequeue(&wireless_nlevent_queue)))
1853 netlink_broadcast(rtnl, skb, 0, RTNLGRP_LINK, GFP_ATOMIC);
1856 static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0);
1858 /* ---------------------------------------------------------------- */
1860 * Fill a rtnetlink message with our event data.
1861 * Note that we propage only the specified event and don't dump the
1862 * current wireless config. Dumping the wireless config is far too
1863 * expensive (for each parameter, the driver need to query the hardware).
1865 static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
1866 struct net_device * dev,
1871 struct ifinfomsg *r;
1872 struct nlmsghdr *nlh;
1873 unsigned char *b = skb->tail;
1875 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
1876 r = NLMSG_DATA(nlh);
1877 r->ifi_family = AF_UNSPEC;
1879 r->ifi_type = dev->type;
1880 r->ifi_index = dev->ifindex;
1881 r->ifi_flags = dev_get_flags(dev);
1882 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1884 /* Add the wireless events in the netlink packet */
1885 RTA_PUT(skb, IFLA_WIRELESS, event_len, event);
1887 nlh->nlmsg_len = skb->tail - b;
1892 skb_trim(skb, b - skb->data);
1896 /* ---------------------------------------------------------------- */
1898 * Create and broadcast and send it on the standard rtnetlink socket
1899 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1900 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1901 * within a RTM_NEWLINK event.
1903 static inline void rtmsg_iwinfo(struct net_device * dev,
1907 struct sk_buff *skb;
1908 int size = NLMSG_GOODSIZE;
1910 skb = alloc_skb(size, GFP_ATOMIC);
1914 if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
1915 event, event_len) < 0) {
1919 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
1920 skb_queue_tail(&wireless_nlevent_queue, skb);
1921 tasklet_schedule(&wireless_nlevent_tasklet);
1924 static int __init wireless_nlevent_init(void)
1926 skb_queue_head_init(&wireless_nlevent_queue);
1930 subsys_initcall(wireless_nlevent_init);
1931 #endif /* WE_EVENT_RTNETLINK */
1933 /* ---------------------------------------------------------------- */
1935 * Main event dispatcher. Called from other parts and drivers.
1936 * Send the event on the appropriate channels.
1937 * May be called from interrupt context.
1939 void wireless_send_event(struct net_device * dev,
1941 union iwreq_data * wrqu,
1944 const struct iw_ioctl_description * descr = NULL;
1946 struct iw_event *event; /* Mallocated whole event */
1947 int event_len; /* Its size */
1948 int hdr_len; /* Size of the event header */
1949 int wrqu_off = 0; /* Offset in wrqu */
1950 /* Don't "optimise" the following variable, it will crash */
1951 unsigned cmd_index; /* *MUST* be unsigned */
1953 /* Get the description of the Event */
1954 if(cmd <= SIOCIWLAST) {
1955 cmd_index = cmd - SIOCIWFIRST;
1956 if(cmd_index < standard_ioctl_num)
1957 descr = &(standard_ioctl[cmd_index]);
1959 cmd_index = cmd - IWEVFIRST;
1960 if(cmd_index < standard_event_num)
1961 descr = &(standard_event[cmd_index]);
1963 /* Don't accept unknown events */
1965 /* Note : we don't return an error to the driver, because
1966 * the driver would not know what to do about it. It can't
1967 * return an error to the user, because the event is not
1968 * initiated by a user request.
1969 * The best the driver could do is to log an error message.
1970 * We will do it ourselves instead...
1972 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1976 #ifdef WE_EVENT_DEBUG
1977 printk(KERN_DEBUG "%s (WE) : Got event 0x%04X\n",
1979 printk(KERN_DEBUG "%s (WE) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev->name, descr->header_type, descr->token_type, descr->token_size, descr->max_tokens);
1980 #endif /* WE_EVENT_DEBUG */
1982 /* Check extra parameters and set extra_len */
1983 if(descr->header_type == IW_HEADER_TYPE_POINT) {
1984 /* Check if number of token fits within bounds */
1985 if(wrqu->data.length > descr->max_tokens) {
1986 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
1989 if(wrqu->data.length < descr->min_tokens) {
1990 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
1993 /* Calculate extra_len - extra is NULL for restricted events */
1995 extra_len = wrqu->data.length * descr->token_size;
1996 /* Always at an offset in wrqu */
1997 wrqu_off = IW_EV_POINT_OFF;
1998 #ifdef WE_EVENT_DEBUG
1999 printk(KERN_DEBUG "%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev->name, cmd, wrqu->data.length, extra_len);
2000 #endif /* WE_EVENT_DEBUG */
2003 /* Total length of the event */
2004 hdr_len = event_type_size[descr->header_type];
2005 event_len = hdr_len + extra_len;
2007 #ifdef WE_EVENT_DEBUG
2008 printk(KERN_DEBUG "%s (WE) : Event 0x%04X, hdr_len %d, wrqu_off %d, event_len %d\n", dev->name, cmd, hdr_len, wrqu_off, event_len);
2009 #endif /* WE_EVENT_DEBUG */
2011 /* Create temporary buffer to hold the event */
2012 event = kmalloc(event_len, GFP_ATOMIC);
2017 event->len = event_len;
2019 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
2021 memcpy(((char *) event) + hdr_len, extra, extra_len);
2023 #ifdef WE_EVENT_RTNETLINK
2024 /* Send via the RtNetlink event channel */
2025 rtmsg_iwinfo(dev, (char *) event, event_len);
2026 #endif /* WE_EVENT_RTNETLINK */
2031 return; /* Always success, I guess ;-) */
2034 /********************** ENHANCED IWSPY SUPPORT **********************/
2036 * In the old days, the driver was handling spy support all by itself.
2037 * Now, the driver can delegate this task to Wireless Extensions.
2038 * It needs to use those standard spy iw_handler in struct iw_handler_def,
2039 * push data to us via wireless_spy_update() and include struct iw_spy_data
2040 * in its private part (and export it in net_device->wireless_data->spy_data).
2041 * One of the main advantage of centralising spy support here is that
2042 * it becomes much easier to improve and extend it without having to touch
2043 * the drivers. One example is the addition of the Spy-Threshold events.
2046 /* ---------------------------------------------------------------- */
2048 * Return the pointer to the spy data in the driver.
2049 * Because this is called on the Rx path via wireless_spy_update(),
2050 * we want it to be efficient...
2052 static inline struct iw_spy_data * get_spydata(struct net_device *dev)
2054 /* This is the new way */
2055 if(dev->wireless_data)
2056 return(dev->wireless_data->spy_data);
2060 /*------------------------------------------------------------------*/
2062 * Standard Wireless Handler : set Spy List
2064 int iw_handler_set_spy(struct net_device * dev,
2065 struct iw_request_info * info,
2066 union iwreq_data * wrqu,
2069 struct iw_spy_data * spydata = get_spydata(dev);
2070 struct sockaddr * address = (struct sockaddr *) extra;
2072 /* Make sure driver is not buggy or using the old API */
2076 /* Disable spy collection while we copy the addresses.
2077 * While we copy addresses, any call to wireless_spy_update()
2078 * will NOP. This is OK, as anyway the addresses are changing. */
2079 spydata->spy_number = 0;
2081 /* We want to operate without locking, because wireless_spy_update()
2082 * most likely will happen in the interrupt handler, and therefore
2083 * have its own locking constraints and needs performance.
2084 * The rtnl_lock() make sure we don't race with the other iw_handlers.
2085 * This make sure wireless_spy_update() "see" that the spy list
2086 * is temporarily disabled. */
2089 /* Are there are addresses to copy? */
2090 if(wrqu->data.length > 0) {
2093 /* Copy addresses */
2094 for(i = 0; i < wrqu->data.length; i++)
2095 memcpy(spydata->spy_address[i], address[i].sa_data,
2098 memset(spydata->spy_stat, 0,
2099 sizeof(struct iw_quality) * IW_MAX_SPY);
2102 printk(KERN_DEBUG "iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev->wireless_data, spydata, wrqu->data.length);
2103 for (i = 0; i < wrqu->data.length; i++)
2105 "%02X:%02X:%02X:%02X:%02X:%02X \n",
2106 spydata->spy_address[i][0],
2107 spydata->spy_address[i][1],
2108 spydata->spy_address[i][2],
2109 spydata->spy_address[i][3],
2110 spydata->spy_address[i][4],
2111 spydata->spy_address[i][5]);
2112 #endif /* WE_SPY_DEBUG */
2115 /* Make sure above is updated before re-enabling */
2118 /* Enable addresses */
2119 spydata->spy_number = wrqu->data.length;
2124 /*------------------------------------------------------------------*/
2126 * Standard Wireless Handler : get Spy List
2128 int iw_handler_get_spy(struct net_device * dev,
2129 struct iw_request_info * info,
2130 union iwreq_data * wrqu,
2133 struct iw_spy_data * spydata = get_spydata(dev);
2134 struct sockaddr * address = (struct sockaddr *) extra;
2137 /* Make sure driver is not buggy or using the old API */
2141 wrqu->data.length = spydata->spy_number;
2143 /* Copy addresses. */
2144 for(i = 0; i < spydata->spy_number; i++) {
2145 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
2146 address[i].sa_family = AF_UNIX;
2148 /* Copy stats to the user buffer (just after). */
2149 if(spydata->spy_number > 0)
2150 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
2152 sizeof(struct iw_quality) * spydata->spy_number);
2153 /* Reset updated flags. */
2154 for(i = 0; i < spydata->spy_number; i++)
2155 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
2159 /*------------------------------------------------------------------*/
2161 * Standard Wireless Handler : set spy threshold
2163 int iw_handler_set_thrspy(struct net_device * dev,
2164 struct iw_request_info *info,
2165 union iwreq_data * wrqu,
2168 struct iw_spy_data * spydata = get_spydata(dev);
2169 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
2171 /* Make sure driver is not buggy or using the old API */
2176 memcpy(&(spydata->spy_thr_low), &(threshold->low),
2177 2 * sizeof(struct iw_quality));
2180 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
2183 printk(KERN_DEBUG "iw_handler_set_thrspy() : low %d ; high %d\n", spydata->spy_thr_low.level, spydata->spy_thr_high.level);
2184 #endif /* WE_SPY_DEBUG */
2189 /*------------------------------------------------------------------*/
2191 * Standard Wireless Handler : get spy threshold
2193 int iw_handler_get_thrspy(struct net_device * dev,
2194 struct iw_request_info *info,
2195 union iwreq_data * wrqu,
2198 struct iw_spy_data * spydata = get_spydata(dev);
2199 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
2201 /* Make sure driver is not buggy or using the old API */
2206 memcpy(&(threshold->low), &(spydata->spy_thr_low),
2207 2 * sizeof(struct iw_quality));
2212 /*------------------------------------------------------------------*/
2214 * Prepare and send a Spy Threshold event
2216 static void iw_send_thrspy_event(struct net_device * dev,
2217 struct iw_spy_data * spydata,
2218 unsigned char * address,
2219 struct iw_quality * wstats)
2221 union iwreq_data wrqu;
2222 struct iw_thrspy threshold;
2225 wrqu.data.length = 1;
2226 wrqu.data.flags = 0;
2228 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
2229 threshold.addr.sa_family = ARPHRD_ETHER;
2231 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
2232 /* Copy also thresholds */
2233 memcpy(&(threshold.low), &(spydata->spy_thr_low),
2234 2 * sizeof(struct iw_quality));
2237 printk(KERN_DEBUG "iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
2238 threshold.addr.sa_data[0],
2239 threshold.addr.sa_data[1],
2240 threshold.addr.sa_data[2],
2241 threshold.addr.sa_data[3],
2242 threshold.addr.sa_data[4],
2243 threshold.addr.sa_data[5], threshold.qual.level);
2244 #endif /* WE_SPY_DEBUG */
2246 /* Send event to user space */
2247 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
2250 /* ---------------------------------------------------------------- */
2252 * Call for the driver to update the spy data.
2253 * For now, the spy data is a simple array. As the size of the array is
2254 * small, this is good enough. If we wanted to support larger number of
2255 * spy addresses, we should use something more efficient...
2257 void wireless_spy_update(struct net_device * dev,
2258 unsigned char * address,
2259 struct iw_quality * wstats)
2261 struct iw_spy_data * spydata = get_spydata(dev);
2265 /* Make sure driver is not buggy or using the old API */
2270 printk(KERN_DEBUG "wireless_spy_update() : wireless_data %p, spydata %p, address %02X:%02X:%02X:%02X:%02X:%02X\n", dev->wireless_data, spydata, address[0], address[1], address[2], address[3], address[4], address[5]);
2271 #endif /* WE_SPY_DEBUG */
2273 /* Update all records that match */
2274 for(i = 0; i < spydata->spy_number; i++)
2275 if(!compare_ether_addr(address, spydata->spy_address[i])) {
2276 memcpy(&(spydata->spy_stat[i]), wstats,
2277 sizeof(struct iw_quality));
2281 /* Generate an event if we cross the spy threshold.
2282 * To avoid event storms, we have a simple hysteresis : we generate
2283 * event only when we go under the low threshold or above the
2284 * high threshold. */
2286 if(spydata->spy_thr_under[match]) {
2287 if(wstats->level > spydata->spy_thr_high.level) {
2288 spydata->spy_thr_under[match] = 0;
2289 iw_send_thrspy_event(dev, spydata,
2293 if(wstats->level < spydata->spy_thr_low.level) {
2294 spydata->spy_thr_under[match] = 1;
2295 iw_send_thrspy_event(dev, spydata,
2302 EXPORT_SYMBOL(iw_handler_get_spy);
2303 EXPORT_SYMBOL(iw_handler_get_thrspy);
2304 EXPORT_SYMBOL(iw_handler_set_spy);
2305 EXPORT_SYMBOL(iw_handler_set_thrspy);
2306 EXPORT_SYMBOL(wireless_send_event);
2307 EXPORT_SYMBOL(wireless_spy_update);