2 * This file implement the Wireless Extensions APIs.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2005 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)
70 /***************************** INCLUDES *****************************/
72 #include <linux/config.h> /* Not needed ??? */
73 #include <linux/module.h>
74 #include <linux/types.h> /* off_t */
75 #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
76 #include <linux/proc_fs.h>
77 #include <linux/rtnetlink.h> /* rtnetlink stuff */
78 #include <linux/seq_file.h>
79 #include <linux/init.h> /* for __init */
80 #include <linux/if_arp.h> /* ARPHRD_ETHER */
81 #include <linux/etherdevice.h> /* compare_ether_addr */
83 #include <linux/wireless.h> /* Pretty obvious */
84 #include <net/iw_handler.h> /* New driver API */
86 #include <asm/uaccess.h> /* copy_to_user() */
88 /**************************** CONSTANTS ****************************/
91 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
92 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
93 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
96 #define WE_EVENT_NETLINK /* Propagate events using rtnetlink */
97 #define WE_SET_EVENT /* Generate an event on some set commands */
99 /************************* GLOBAL VARIABLES *************************/
101 * You should not use global variables, because of re-entrancy.
102 * On our case, it's only const, so it's OK...
105 * Meta-data about all the standard Wireless Extension request we
108 static const struct iw_ioctl_description standard_ioctl[] = {
109 [SIOCSIWCOMMIT - SIOCIWFIRST] = {
110 .header_type = IW_HEADER_TYPE_NULL,
112 [SIOCGIWNAME - SIOCIWFIRST] = {
113 .header_type = IW_HEADER_TYPE_CHAR,
114 .flags = IW_DESCR_FLAG_DUMP,
116 [SIOCSIWNWID - SIOCIWFIRST] = {
117 .header_type = IW_HEADER_TYPE_PARAM,
118 .flags = IW_DESCR_FLAG_EVENT,
120 [SIOCGIWNWID - SIOCIWFIRST] = {
121 .header_type = IW_HEADER_TYPE_PARAM,
122 .flags = IW_DESCR_FLAG_DUMP,
124 [SIOCSIWFREQ - SIOCIWFIRST] = {
125 .header_type = IW_HEADER_TYPE_FREQ,
126 .flags = IW_DESCR_FLAG_EVENT,
128 [SIOCGIWFREQ - SIOCIWFIRST] = {
129 .header_type = IW_HEADER_TYPE_FREQ,
130 .flags = IW_DESCR_FLAG_DUMP,
132 [SIOCSIWMODE - SIOCIWFIRST] = {
133 .header_type = IW_HEADER_TYPE_UINT,
134 .flags = IW_DESCR_FLAG_EVENT,
136 [SIOCGIWMODE - SIOCIWFIRST] = {
137 .header_type = IW_HEADER_TYPE_UINT,
138 .flags = IW_DESCR_FLAG_DUMP,
140 [SIOCSIWSENS - SIOCIWFIRST] = {
141 .header_type = IW_HEADER_TYPE_PARAM,
143 [SIOCGIWSENS - SIOCIWFIRST] = {
144 .header_type = IW_HEADER_TYPE_PARAM,
146 [SIOCSIWRANGE - SIOCIWFIRST] = {
147 .header_type = IW_HEADER_TYPE_NULL,
149 [SIOCGIWRANGE - SIOCIWFIRST] = {
150 .header_type = IW_HEADER_TYPE_POINT,
152 .max_tokens = sizeof(struct iw_range),
153 .flags = IW_DESCR_FLAG_DUMP,
155 [SIOCSIWPRIV - SIOCIWFIRST] = {
156 .header_type = IW_HEADER_TYPE_NULL,
158 [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */
159 .header_type = IW_HEADER_TYPE_NULL,
161 [SIOCSIWSTATS - SIOCIWFIRST] = {
162 .header_type = IW_HEADER_TYPE_NULL,
164 [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */
165 .header_type = IW_HEADER_TYPE_NULL,
166 .flags = IW_DESCR_FLAG_DUMP,
168 [SIOCSIWSPY - SIOCIWFIRST] = {
169 .header_type = IW_HEADER_TYPE_POINT,
170 .token_size = sizeof(struct sockaddr),
171 .max_tokens = IW_MAX_SPY,
173 [SIOCGIWSPY - SIOCIWFIRST] = {
174 .header_type = IW_HEADER_TYPE_POINT,
175 .token_size = sizeof(struct sockaddr) +
176 sizeof(struct iw_quality),
177 .max_tokens = IW_MAX_SPY,
179 [SIOCSIWTHRSPY - SIOCIWFIRST] = {
180 .header_type = IW_HEADER_TYPE_POINT,
181 .token_size = sizeof(struct iw_thrspy),
185 [SIOCGIWTHRSPY - SIOCIWFIRST] = {
186 .header_type = IW_HEADER_TYPE_POINT,
187 .token_size = sizeof(struct iw_thrspy),
191 [SIOCSIWAP - SIOCIWFIRST] = {
192 .header_type = IW_HEADER_TYPE_ADDR,
194 [SIOCGIWAP - SIOCIWFIRST] = {
195 .header_type = IW_HEADER_TYPE_ADDR,
196 .flags = IW_DESCR_FLAG_DUMP,
198 [SIOCSIWMLME - SIOCIWFIRST] = {
199 .header_type = IW_HEADER_TYPE_POINT,
201 .min_tokens = sizeof(struct iw_mlme),
202 .max_tokens = sizeof(struct iw_mlme),
204 [SIOCGIWAPLIST - SIOCIWFIRST] = {
205 .header_type = IW_HEADER_TYPE_POINT,
206 .token_size = sizeof(struct sockaddr) +
207 sizeof(struct iw_quality),
208 .max_tokens = IW_MAX_AP,
209 .flags = IW_DESCR_FLAG_NOMAX,
211 [SIOCSIWSCAN - SIOCIWFIRST] = {
212 .header_type = IW_HEADER_TYPE_POINT,
215 .max_tokens = sizeof(struct iw_scan_req),
217 [SIOCGIWSCAN - SIOCIWFIRST] = {
218 .header_type = IW_HEADER_TYPE_POINT,
220 .max_tokens = IW_SCAN_MAX_DATA,
221 .flags = IW_DESCR_FLAG_NOMAX,
223 [SIOCSIWESSID - SIOCIWFIRST] = {
224 .header_type = IW_HEADER_TYPE_POINT,
226 .max_tokens = IW_ESSID_MAX_SIZE + 1,
227 .flags = IW_DESCR_FLAG_EVENT,
229 [SIOCGIWESSID - SIOCIWFIRST] = {
230 .header_type = IW_HEADER_TYPE_POINT,
232 .max_tokens = IW_ESSID_MAX_SIZE + 1,
233 .flags = IW_DESCR_FLAG_DUMP,
235 [SIOCSIWNICKN - SIOCIWFIRST] = {
236 .header_type = IW_HEADER_TYPE_POINT,
238 .max_tokens = IW_ESSID_MAX_SIZE + 1,
240 [SIOCGIWNICKN - SIOCIWFIRST] = {
241 .header_type = IW_HEADER_TYPE_POINT,
243 .max_tokens = IW_ESSID_MAX_SIZE + 1,
245 [SIOCSIWRATE - SIOCIWFIRST] = {
246 .header_type = IW_HEADER_TYPE_PARAM,
248 [SIOCGIWRATE - SIOCIWFIRST] = {
249 .header_type = IW_HEADER_TYPE_PARAM,
251 [SIOCSIWRTS - SIOCIWFIRST] = {
252 .header_type = IW_HEADER_TYPE_PARAM,
254 [SIOCGIWRTS - SIOCIWFIRST] = {
255 .header_type = IW_HEADER_TYPE_PARAM,
257 [SIOCSIWFRAG - SIOCIWFIRST] = {
258 .header_type = IW_HEADER_TYPE_PARAM,
260 [SIOCGIWFRAG - SIOCIWFIRST] = {
261 .header_type = IW_HEADER_TYPE_PARAM,
263 [SIOCSIWTXPOW - SIOCIWFIRST] = {
264 .header_type = IW_HEADER_TYPE_PARAM,
266 [SIOCGIWTXPOW - SIOCIWFIRST] = {
267 .header_type = IW_HEADER_TYPE_PARAM,
269 [SIOCSIWRETRY - SIOCIWFIRST] = {
270 .header_type = IW_HEADER_TYPE_PARAM,
272 [SIOCGIWRETRY - SIOCIWFIRST] = {
273 .header_type = IW_HEADER_TYPE_PARAM,
275 [SIOCSIWENCODE - SIOCIWFIRST] = {
276 .header_type = IW_HEADER_TYPE_POINT,
278 .max_tokens = IW_ENCODING_TOKEN_MAX,
279 .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
281 [SIOCGIWENCODE - SIOCIWFIRST] = {
282 .header_type = IW_HEADER_TYPE_POINT,
284 .max_tokens = IW_ENCODING_TOKEN_MAX,
285 .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
287 [SIOCSIWPOWER - SIOCIWFIRST] = {
288 .header_type = IW_HEADER_TYPE_PARAM,
290 [SIOCGIWPOWER - SIOCIWFIRST] = {
291 .header_type = IW_HEADER_TYPE_PARAM,
293 [SIOCSIWGENIE - SIOCIWFIRST] = {
294 .header_type = IW_HEADER_TYPE_POINT,
296 .max_tokens = IW_GENERIC_IE_MAX,
298 [SIOCGIWGENIE - SIOCIWFIRST] = {
299 .header_type = IW_HEADER_TYPE_POINT,
301 .max_tokens = IW_GENERIC_IE_MAX,
303 [SIOCSIWAUTH - SIOCIWFIRST] = {
304 .header_type = IW_HEADER_TYPE_PARAM,
306 [SIOCGIWAUTH - SIOCIWFIRST] = {
307 .header_type = IW_HEADER_TYPE_PARAM,
309 [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
310 .header_type = IW_HEADER_TYPE_POINT,
312 .min_tokens = sizeof(struct iw_encode_ext),
313 .max_tokens = sizeof(struct iw_encode_ext) +
314 IW_ENCODING_TOKEN_MAX,
316 [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
317 .header_type = IW_HEADER_TYPE_POINT,
319 .min_tokens = sizeof(struct iw_encode_ext),
320 .max_tokens = sizeof(struct iw_encode_ext) +
321 IW_ENCODING_TOKEN_MAX,
323 [SIOCSIWPMKSA - SIOCIWFIRST] = {
324 .header_type = IW_HEADER_TYPE_POINT,
326 .min_tokens = sizeof(struct iw_pmksa),
327 .max_tokens = sizeof(struct iw_pmksa),
330 static const int standard_ioctl_num = (sizeof(standard_ioctl) /
331 sizeof(struct iw_ioctl_description));
334 * Meta-data about all the additional standard Wireless Extension events
337 static const struct iw_ioctl_description standard_event[] = {
338 [IWEVTXDROP - IWEVFIRST] = {
339 .header_type = IW_HEADER_TYPE_ADDR,
341 [IWEVQUAL - IWEVFIRST] = {
342 .header_type = IW_HEADER_TYPE_QUAL,
344 [IWEVCUSTOM - IWEVFIRST] = {
345 .header_type = IW_HEADER_TYPE_POINT,
347 .max_tokens = IW_CUSTOM_MAX,
349 [IWEVREGISTERED - IWEVFIRST] = {
350 .header_type = IW_HEADER_TYPE_ADDR,
352 [IWEVEXPIRED - IWEVFIRST] = {
353 .header_type = IW_HEADER_TYPE_ADDR,
355 [IWEVGENIE - IWEVFIRST] = {
356 .header_type = IW_HEADER_TYPE_POINT,
358 .max_tokens = IW_GENERIC_IE_MAX,
360 [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
361 .header_type = IW_HEADER_TYPE_POINT,
363 .max_tokens = sizeof(struct iw_michaelmicfailure),
365 [IWEVASSOCREQIE - IWEVFIRST] = {
366 .header_type = IW_HEADER_TYPE_POINT,
368 .max_tokens = IW_GENERIC_IE_MAX,
370 [IWEVASSOCRESPIE - IWEVFIRST] = {
371 .header_type = IW_HEADER_TYPE_POINT,
373 .max_tokens = IW_GENERIC_IE_MAX,
375 [IWEVPMKIDCAND - IWEVFIRST] = {
376 .header_type = IW_HEADER_TYPE_POINT,
378 .max_tokens = sizeof(struct iw_pmkid_cand),
381 static const int standard_event_num = (sizeof(standard_event) /
382 sizeof(struct iw_ioctl_description));
384 /* Size (in bytes) of the various private data types */
385 static const char iw_priv_type_size[] = {
386 0, /* IW_PRIV_TYPE_NONE */
387 1, /* IW_PRIV_TYPE_BYTE */
388 1, /* IW_PRIV_TYPE_CHAR */
390 sizeof(__u32), /* IW_PRIV_TYPE_INT */
391 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
392 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
396 /* Size (in bytes) of various events */
397 static const int event_type_size[] = {
398 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
400 IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
402 IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
403 IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
404 IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
406 IW_EV_POINT_LEN, /* Without variable payload */
407 IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
408 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
411 /************************ COMMON SUBROUTINES ************************/
413 * Stuff that may be used in various place or doesn't fit in one
414 * of the section below.
417 /* ---------------------------------------------------------------- */
419 * Return the driver handler associated with a specific Wireless Extension.
420 * Called from various place, so make sure it remains efficient.
422 static inline iw_handler get_handler(struct net_device *dev,
425 /* Don't "optimise" the following variable, it will crash */
426 unsigned int index; /* *MUST* be unsigned */
428 /* Check if we have some wireless handlers defined */
429 if(dev->wireless_handlers == NULL)
432 /* Try as a standard command */
433 index = cmd - SIOCIWFIRST;
434 if(index < dev->wireless_handlers->num_standard)
435 return dev->wireless_handlers->standard[index];
437 /* Try as a private command */
438 index = cmd - SIOCIWFIRSTPRIV;
439 if(index < dev->wireless_handlers->num_private)
440 return dev->wireless_handlers->private[index];
446 /* ---------------------------------------------------------------- */
448 * Get statistics out of the driver
450 static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
453 if((dev->wireless_handlers != NULL) &&
454 (dev->wireless_handlers->get_wireless_stats != NULL))
455 return dev->wireless_handlers->get_wireless_stats(dev);
457 /* Old location, field to be removed in next WE */
458 if(dev->get_wireless_stats) {
459 static int printed_message;
461 if (!printed_message++)
462 printk(KERN_DEBUG "%s (WE) : Driver using old /proc/net/wireless support, please fix driver !\n",
465 return dev->get_wireless_stats(dev);
469 return (struct iw_statistics *) NULL;
472 /* ---------------------------------------------------------------- */
474 * Call the commit handler in the driver
475 * (if exist and if conditions are right)
477 * Note : our current commit strategy is currently pretty dumb,
478 * but we will be able to improve on that...
479 * The goal is to try to agreagate as many changes as possible
480 * before doing the commit. Drivers that will define a commit handler
481 * are usually those that need a reset after changing parameters, so
482 * we want to minimise the number of reset.
483 * A cool idea is to use a timer : at each "set" command, we re-set the
484 * timer, when the timer eventually fires, we call the driver.
485 * Hopefully, more on that later.
487 * Also, I'm waiting to see how many people will complain about the
488 * netif_running(dev) test. I'm open on that one...
489 * Hopefully, the driver will remember to do a commit in "open()" ;-)
491 static inline int call_commit_handler(struct net_device * dev)
493 if((netif_running(dev)) &&
494 (dev->wireless_handlers->standard[0] != NULL)) {
495 /* Call the commit handler on the driver */
496 return dev->wireless_handlers->standard[0](dev, NULL,
499 return 0; /* Command completed successfully */
502 /* ---------------------------------------------------------------- */
504 * Calculate size of private arguments
506 static inline int get_priv_size(__u16 args)
508 int num = args & IW_PRIV_SIZE_MASK;
509 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
511 return num * iw_priv_type_size[type];
514 /* ---------------------------------------------------------------- */
516 * Re-calculate the size of private arguments
518 static inline int adjust_priv_size(__u16 args,
519 union iwreq_data * wrqu)
521 int num = wrqu->data.length;
522 int max = args & IW_PRIV_SIZE_MASK;
523 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
525 /* Make sure the driver doesn't goof up */
529 return num * iw_priv_type_size[type];
533 /******************** /proc/net/wireless SUPPORT ********************/
535 * The /proc/net/wireless file is a human readable user-space interface
536 * exporting various wireless specific statistics from the wireless devices.
537 * This is the most popular part of the Wireless Extensions ;-)
539 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
540 * The content of the file is basically the content of "struct iw_statistics".
543 #ifdef CONFIG_PROC_FS
545 /* ---------------------------------------------------------------- */
547 * Print one entry (line) of /proc/net/wireless
549 static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
550 struct net_device *dev)
552 /* Get stats from the driver */
553 struct iw_statistics *stats = get_wireless_stats(dev);
556 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
558 dev->name, stats->status, stats->qual.qual,
559 stats->qual.updated & IW_QUAL_QUAL_UPDATED
561 ((__s32) stats->qual.level) -
562 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
563 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
565 ((__s32) stats->qual.noise) -
566 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
567 stats->qual.updated & IW_QUAL_NOISE_UPDATED
569 stats->discard.nwid, stats->discard.code,
570 stats->discard.fragment, stats->discard.retries,
571 stats->discard.misc, stats->miss.beacon);
572 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
576 /* ---------------------------------------------------------------- */
578 * Print info for /proc/net/wireless (print all entries)
580 static int wireless_seq_show(struct seq_file *seq, void *v)
582 if (v == SEQ_START_TOKEN)
583 seq_printf(seq, "Inter-| sta-| Quality | Discarded "
584 "packets | Missed | WE\n"
585 " face | tus | link level noise | nwid "
586 "crypt frag retry misc | beacon | %d\n",
589 wireless_seq_printf_stats(seq, v);
593 static struct seq_operations wireless_seq_ops = {
594 .start = dev_seq_start,
595 .next = dev_seq_next,
596 .stop = dev_seq_stop,
597 .show = wireless_seq_show,
600 static int wireless_seq_open(struct inode *inode, struct file *file)
602 return seq_open(file, &wireless_seq_ops);
605 static struct file_operations wireless_seq_fops = {
606 .owner = THIS_MODULE,
607 .open = wireless_seq_open,
610 .release = seq_release,
613 int __init wireless_proc_init(void)
615 /* Create /proc/net/wireless entry */
616 if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
621 #endif /* CONFIG_PROC_FS */
623 /************************** IOCTL SUPPORT **************************/
625 * The original user space API to configure all those Wireless Extensions
627 * In there, we check if we need to call the new driver API (iw_handler)
628 * or just call the driver ioctl handler.
631 /* ---------------------------------------------------------------- */
633 * Allow programatic access to /proc/net/wireless even if /proc
634 * doesn't exist... Also more efficient...
636 static inline int dev_iwstats(struct net_device *dev, struct ifreq *ifr)
638 /* Get stats from the driver */
639 struct iw_statistics *stats;
641 stats = get_wireless_stats(dev);
642 if (stats != (struct iw_statistics *) NULL) {
643 struct iwreq * wrq = (struct iwreq *)ifr;
645 /* Copy statistics to the user buffer */
646 if(copy_to_user(wrq->u.data.pointer, stats,
647 sizeof(struct iw_statistics)))
650 /* Check if we need to clear the updated flag */
651 if(wrq->u.data.flags != 0)
652 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
658 /* ---------------------------------------------------------------- */
660 * Export the driver private handler definition
661 * They will be picked up by tools like iwpriv...
663 static inline int ioctl_export_private(struct net_device * dev,
666 struct iwreq * iwr = (struct iwreq *) ifr;
668 /* Check if the driver has something to export */
669 if((dev->wireless_handlers->num_private_args == 0) ||
670 (dev->wireless_handlers->private_args == NULL))
673 /* Check NULL pointer */
674 if(iwr->u.data.pointer == NULL)
677 /* Check if there is enough buffer up there */
678 if(iwr->u.data.length < dev->wireless_handlers->num_private_args) {
679 /* User space can't know in advance how large the buffer
680 * needs to be. Give it a hint, so that we can support
681 * any size buffer we want somewhat efficiently... */
682 iwr->u.data.length = dev->wireless_handlers->num_private_args;
686 /* Set the number of available ioctls. */
687 iwr->u.data.length = dev->wireless_handlers->num_private_args;
689 /* Copy structure to the user buffer. */
690 if (copy_to_user(iwr->u.data.pointer,
691 dev->wireless_handlers->private_args,
692 sizeof(struct iw_priv_args) * iwr->u.data.length))
698 /* ---------------------------------------------------------------- */
700 * Wrapper to call a standard Wireless Extension handler.
701 * We do various checks and also take care of moving data between
702 * user space and kernel space.
704 static inline int ioctl_standard_call(struct net_device * dev,
709 struct iwreq * iwr = (struct iwreq *) ifr;
710 const struct iw_ioctl_description * descr;
711 struct iw_request_info info;
714 /* Get the description of the IOCTL */
715 if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
717 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
719 #ifdef WE_IOCTL_DEBUG
720 printk(KERN_DEBUG "%s (WE) : Found standard handler for 0x%04X\n",
722 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);
723 #endif /* WE_IOCTL_DEBUG */
725 /* Prepare the call */
729 /* Check if we have a pointer to user space data or not */
730 if(descr->header_type != IW_HEADER_TYPE_POINT) {
732 /* No extra arguments. Trivial to handle */
733 ret = handler(dev, &info, &(iwr->u), NULL);
736 /* Generate an event to notify listeners of the change */
737 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
738 ((ret == 0) || (ret == -EIWCOMMIT)))
739 wireless_send_event(dev, cmd, &(iwr->u), NULL);
740 #endif /* WE_SET_EVENT */
747 /* Calculate space needed by arguments. Always allocate
748 * for max space. Easier, and won't last long... */
749 extra_size = descr->max_tokens * descr->token_size;
751 /* Check what user space is giving us */
753 /* Check NULL pointer */
754 if((iwr->u.data.pointer == NULL) &&
755 (iwr->u.data.length != 0))
757 /* Check if number of token fits within bounds */
758 if(iwr->u.data.length > descr->max_tokens)
760 if(iwr->u.data.length < descr->min_tokens)
763 /* Check NULL pointer */
764 if(iwr->u.data.pointer == NULL)
766 /* Save user space buffer size for checking */
767 user_length = iwr->u.data.length;
769 /* Don't check if user_length > max to allow forward
770 * compatibility. The test user_length < min is
771 * implied by the test at the end. */
773 /* Support for very large requests */
774 if((descr->flags & IW_DESCR_FLAG_NOMAX) &&
775 (user_length > descr->max_tokens)) {
776 /* Allow userspace to GET more than max so
777 * we can support any size GET requests.
778 * There is still a limit : -ENOMEM. */
779 extra_size = user_length * descr->token_size;
780 /* Note : user_length is originally a __u16,
781 * and token_size is controlled by us,
782 * so extra_size won't get negative and
783 * won't overflow... */
787 #ifdef WE_IOCTL_DEBUG
788 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
789 dev->name, extra_size);
790 #endif /* WE_IOCTL_DEBUG */
792 /* Create the kernel buffer */
793 extra = kmalloc(extra_size, GFP_KERNEL);
798 /* If it is a SET, get all the extra data in here */
799 if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
800 err = copy_from_user(extra, iwr->u.data.pointer,
807 #ifdef WE_IOCTL_DEBUG
808 printk(KERN_DEBUG "%s (WE) : Got %d bytes\n",
810 iwr->u.data.length * descr->token_size);
811 #endif /* WE_IOCTL_DEBUG */
814 /* Call the handler */
815 ret = handler(dev, &info, &(iwr->u), extra);
817 /* If we have something to return to the user */
818 if (!ret && IW_IS_GET(cmd)) {
819 /* Check if there is enough buffer up there */
820 if(user_length < iwr->u.data.length) {
825 err = copy_to_user(iwr->u.data.pointer, extra,
830 #ifdef WE_IOCTL_DEBUG
831 printk(KERN_DEBUG "%s (WE) : Wrote %d bytes\n",
833 iwr->u.data.length * descr->token_size);
834 #endif /* WE_IOCTL_DEBUG */
838 /* Generate an event to notify listeners of the change */
839 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
840 ((ret == 0) || (ret == -EIWCOMMIT))) {
841 if(descr->flags & IW_DESCR_FLAG_RESTRICT)
842 /* If the event is restricted, don't
843 * export the payload */
844 wireless_send_event(dev, cmd, &(iwr->u), NULL);
846 wireless_send_event(dev, cmd, &(iwr->u),
849 #endif /* WE_SET_EVENT */
851 /* Cleanup - I told you it wasn't that long ;-) */
855 /* Call commit handler if needed and defined */
856 if(ret == -EIWCOMMIT)
857 ret = call_commit_handler(dev);
859 /* Here, we will generate the appropriate event if needed */
864 /* ---------------------------------------------------------------- */
866 * Wrapper to call a private Wireless Extension handler.
867 * We do various checks and also take care of moving data between
868 * user space and kernel space.
869 * It's not as nice and slimline as the standard wrapper. The cause
870 * is struct iw_priv_args, which was not really designed for the
871 * job we are going here.
873 * IMPORTANT : This function prevent to set and get data on the same
874 * IOCTL and enforce the SET/GET convention. Not doing it would be
876 * If you need to set and get data at the same time, please don't use
877 * a iw_handler but process it in your ioctl handler (i.e. use the
880 static inline int ioctl_private_call(struct net_device * dev,
885 struct iwreq * iwr = (struct iwreq *) ifr;
886 const struct iw_priv_args * descr = NULL;
887 struct iw_request_info info;
892 /* Get the description of the IOCTL */
893 for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
894 if(cmd == dev->wireless_handlers->private_args[i].cmd) {
895 descr = &(dev->wireless_handlers->private_args[i]);
899 #ifdef WE_IOCTL_DEBUG
900 printk(KERN_DEBUG "%s (WE) : Found private handler for 0x%04X\n",
903 printk(KERN_DEBUG "%s (WE) : Name %s, set %X, get %X\n",
904 dev->name, descr->name,
905 descr->set_args, descr->get_args);
907 #endif /* WE_IOCTL_DEBUG */
909 /* Compute the size of the set/get arguments */
912 int offset = 0; /* For sub-ioctls */
913 /* Check for sub-ioctl handler */
914 if(descr->name[0] == '\0')
915 /* Reserve one int for sub-ioctl index */
916 offset = sizeof(__u32);
918 /* Size of set arguments */
919 extra_size = get_priv_size(descr->set_args);
921 /* Does it fits in iwr ? */
922 if((descr->set_args & IW_PRIV_SIZE_FIXED) &&
923 ((extra_size + offset) <= IFNAMSIZ))
926 /* Size of get arguments */
927 extra_size = get_priv_size(descr->get_args);
929 /* Does it fits in iwr ? */
930 if((descr->get_args & IW_PRIV_SIZE_FIXED) &&
931 (extra_size <= IFNAMSIZ))
936 /* Prepare the call */
940 /* Check if we have a pointer to user space data or not. */
941 if(extra_size == 0) {
942 /* No extra arguments. Trivial to handle */
943 ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u));
948 /* Check what user space is giving us */
950 /* Check NULL pointer */
951 if((iwr->u.data.pointer == NULL) &&
952 (iwr->u.data.length != 0))
955 /* Does it fits within bounds ? */
956 if(iwr->u.data.length > (descr->set_args &
960 /* Check NULL pointer */
961 if(iwr->u.data.pointer == NULL)
965 #ifdef WE_IOCTL_DEBUG
966 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
967 dev->name, extra_size);
968 #endif /* WE_IOCTL_DEBUG */
970 /* Always allocate for max space. Easier, and won't last
972 extra = kmalloc(extra_size, GFP_KERNEL);
977 /* If it is a SET, get all the extra data in here */
978 if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
979 err = copy_from_user(extra, iwr->u.data.pointer,
985 #ifdef WE_IOCTL_DEBUG
986 printk(KERN_DEBUG "%s (WE) : Got %d elem\n",
987 dev->name, iwr->u.data.length);
988 #endif /* WE_IOCTL_DEBUG */
991 /* Call the handler */
992 ret = handler(dev, &info, &(iwr->u), extra);
994 /* If we have something to return to the user */
995 if (!ret && IW_IS_GET(cmd)) {
997 /* Adjust for the actual length if it's variable,
998 * avoid leaking kernel bits outside. */
999 if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) {
1000 extra_size = adjust_priv_size(descr->get_args,
1004 err = copy_to_user(iwr->u.data.pointer, extra,
1008 #ifdef WE_IOCTL_DEBUG
1009 printk(KERN_DEBUG "%s (WE) : Wrote %d elem\n",
1010 dev->name, iwr->u.data.length);
1011 #endif /* WE_IOCTL_DEBUG */
1014 /* Cleanup - I told you it wasn't that long ;-) */
1019 /* Call commit handler if needed and defined */
1020 if(ret == -EIWCOMMIT)
1021 ret = call_commit_handler(dev);
1026 /* ---------------------------------------------------------------- */
1028 * Main IOCTl dispatcher. Called from the main networking code
1029 * (dev_ioctl() in net/core/dev.c).
1030 * Check the type of IOCTL and call the appropriate wrapper...
1032 int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
1034 struct net_device *dev;
1037 /* Permissions are already checked in dev_ioctl() before calling us.
1038 * The copy_to/from_user() of ifr is also dealt with in there */
1040 /* Make sure the device exist */
1041 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
1044 /* A bunch of special cases, then the generic case...
1045 * Note that 'cmd' is already filtered in dev_ioctl() with
1046 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1050 /* Get Wireless Stats */
1051 return dev_iwstats(dev, ifr);
1054 /* Check if we have some wireless handlers defined */
1055 if(dev->wireless_handlers != NULL) {
1056 /* We export to user space the definition of
1057 * the private handler ourselves */
1058 return ioctl_export_private(dev, ifr);
1060 // ## Fall-through for old API ##
1064 if (!netif_device_present(dev))
1066 /* New driver API : try to find the handler */
1067 handler = get_handler(dev, cmd);
1068 if(handler != NULL) {
1069 /* Standard and private are not the same */
1070 if(cmd < SIOCIWFIRSTPRIV)
1071 return ioctl_standard_call(dev,
1076 return ioctl_private_call(dev,
1081 /* Old driver API : call driver ioctl handler */
1082 if (dev->do_ioctl) {
1083 return dev->do_ioctl(dev, ifr, cmd);
1091 /************************* EVENT PROCESSING *************************/
1093 * Process events generated by the wireless layer or the driver.
1094 * Most often, the event will be propagated through rtnetlink
1097 #ifdef WE_EVENT_NETLINK
1098 /* "rtnl" is defined in net/core/rtnetlink.c, but we need it here.
1099 * It is declared in <linux/rtnetlink.h> */
1101 /* ---------------------------------------------------------------- */
1103 * Fill a rtnetlink message with our event data.
1104 * Note that we propage only the specified event and don't dump the
1105 * current wireless config. Dumping the wireless config is far too
1106 * expensive (for each parameter, the driver need to query the hardware).
1108 static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
1109 struct net_device * dev,
1114 struct ifinfomsg *r;
1115 struct nlmsghdr *nlh;
1116 unsigned char *b = skb->tail;
1118 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
1119 r = NLMSG_DATA(nlh);
1120 r->ifi_family = AF_UNSPEC;
1122 r->ifi_type = dev->type;
1123 r->ifi_index = dev->ifindex;
1124 r->ifi_flags = dev->flags;
1125 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1127 /* Add the wireless events in the netlink packet */
1128 RTA_PUT(skb, IFLA_WIRELESS,
1131 nlh->nlmsg_len = skb->tail - b;
1136 skb_trim(skb, b - skb->data);
1140 /* ---------------------------------------------------------------- */
1142 * Create and broadcast and send it on the standard rtnetlink socket
1143 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1144 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1145 * within a RTM_NEWLINK event.
1147 static inline void rtmsg_iwinfo(struct net_device * dev,
1151 struct sk_buff *skb;
1152 int size = NLMSG_GOODSIZE;
1154 skb = alloc_skb(size, GFP_ATOMIC);
1158 if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
1159 event, event_len) < 0) {
1163 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
1164 netlink_broadcast(rtnl, skb, 0, RTNLGRP_LINK, GFP_ATOMIC);
1166 #endif /* WE_EVENT_NETLINK */
1168 /* ---------------------------------------------------------------- */
1170 * Main event dispatcher. Called from other parts and drivers.
1171 * Send the event on the appropriate channels.
1172 * May be called from interrupt context.
1174 void wireless_send_event(struct net_device * dev,
1176 union iwreq_data * wrqu,
1179 const struct iw_ioctl_description * descr = NULL;
1181 struct iw_event *event; /* Mallocated whole event */
1182 int event_len; /* Its size */
1183 int hdr_len; /* Size of the event header */
1184 int wrqu_off = 0; /* Offset in wrqu */
1185 /* Don't "optimise" the following variable, it will crash */
1186 unsigned cmd_index; /* *MUST* be unsigned */
1188 /* Get the description of the Event */
1189 if(cmd <= SIOCIWLAST) {
1190 cmd_index = cmd - SIOCIWFIRST;
1191 if(cmd_index < standard_ioctl_num)
1192 descr = &(standard_ioctl[cmd_index]);
1194 cmd_index = cmd - IWEVFIRST;
1195 if(cmd_index < standard_event_num)
1196 descr = &(standard_event[cmd_index]);
1198 /* Don't accept unknown events */
1200 /* Note : we don't return an error to the driver, because
1201 * the driver would not know what to do about it. It can't
1202 * return an error to the user, because the event is not
1203 * initiated by a user request.
1204 * The best the driver could do is to log an error message.
1205 * We will do it ourselves instead...
1207 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1211 #ifdef WE_EVENT_DEBUG
1212 printk(KERN_DEBUG "%s (WE) : Got event 0x%04X\n",
1214 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);
1215 #endif /* WE_EVENT_DEBUG */
1217 /* Check extra parameters and set extra_len */
1218 if(descr->header_type == IW_HEADER_TYPE_POINT) {
1219 /* Check if number of token fits within bounds */
1220 if(wrqu->data.length > descr->max_tokens) {
1221 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
1224 if(wrqu->data.length < descr->min_tokens) {
1225 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
1228 /* Calculate extra_len - extra is NULL for restricted events */
1230 extra_len = wrqu->data.length * descr->token_size;
1231 /* Always at an offset in wrqu */
1232 wrqu_off = IW_EV_POINT_OFF;
1233 #ifdef WE_EVENT_DEBUG
1234 printk(KERN_DEBUG "%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev->name, cmd, wrqu->data.length, extra_len);
1235 #endif /* WE_EVENT_DEBUG */
1238 /* Total length of the event */
1239 hdr_len = event_type_size[descr->header_type];
1240 event_len = hdr_len + extra_len;
1242 #ifdef WE_EVENT_DEBUG
1243 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);
1244 #endif /* WE_EVENT_DEBUG */
1246 /* Create temporary buffer to hold the event */
1247 event = kmalloc(event_len, GFP_ATOMIC);
1252 event->len = event_len;
1254 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
1256 memcpy(((char *) event) + hdr_len, extra, extra_len);
1258 #ifdef WE_EVENT_NETLINK
1259 /* rtnetlink event channel */
1260 rtmsg_iwinfo(dev, (char *) event, event_len);
1261 #endif /* WE_EVENT_NETLINK */
1266 return; /* Always success, I guess ;-) */
1269 /********************** ENHANCED IWSPY SUPPORT **********************/
1271 * In the old days, the driver was handling spy support all by itself.
1272 * Now, the driver can delegate this task to Wireless Extensions.
1273 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1274 * push data to us via wireless_spy_update() and include struct iw_spy_data
1275 * in its private part (and export it in net_device->wireless_data->spy_data).
1276 * One of the main advantage of centralising spy support here is that
1277 * it becomes much easier to improve and extend it without having to touch
1278 * the drivers. One example is the addition of the Spy-Threshold events.
1281 /* ---------------------------------------------------------------- */
1283 * Return the pointer to the spy data in the driver.
1284 * Because this is called on the Rx path via wireless_spy_update(),
1285 * we want it to be efficient...
1287 static inline struct iw_spy_data * get_spydata(struct net_device *dev)
1289 /* This is the new way */
1290 if(dev->wireless_data)
1291 return(dev->wireless_data->spy_data);
1295 /*------------------------------------------------------------------*/
1297 * Standard Wireless Handler : set Spy List
1299 int iw_handler_set_spy(struct net_device * dev,
1300 struct iw_request_info * info,
1301 union iwreq_data * wrqu,
1304 struct iw_spy_data * spydata = get_spydata(dev);
1305 struct sockaddr * address = (struct sockaddr *) extra;
1307 /* Make sure driver is not buggy or using the old API */
1311 /* Disable spy collection while we copy the addresses.
1312 * While we copy addresses, any call to wireless_spy_update()
1313 * will NOP. This is OK, as anyway the addresses are changing. */
1314 spydata->spy_number = 0;
1316 /* We want to operate without locking, because wireless_spy_update()
1317 * most likely will happen in the interrupt handler, and therefore
1318 * have its own locking constraints and needs performance.
1319 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1320 * This make sure wireless_spy_update() "see" that the spy list
1321 * is temporarily disabled. */
1324 /* Are there are addresses to copy? */
1325 if(wrqu->data.length > 0) {
1328 /* Copy addresses */
1329 for(i = 0; i < wrqu->data.length; i++)
1330 memcpy(spydata->spy_address[i], address[i].sa_data,
1333 memset(spydata->spy_stat, 0,
1334 sizeof(struct iw_quality) * IW_MAX_SPY);
1337 printk(KERN_DEBUG "iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev->wireless_data, spydata, wrqu->data.length);
1338 for (i = 0; i < wrqu->data.length; i++)
1340 "%02X:%02X:%02X:%02X:%02X:%02X \n",
1341 spydata->spy_address[i][0],
1342 spydata->spy_address[i][1],
1343 spydata->spy_address[i][2],
1344 spydata->spy_address[i][3],
1345 spydata->spy_address[i][4],
1346 spydata->spy_address[i][5]);
1347 #endif /* WE_SPY_DEBUG */
1350 /* Make sure above is updated before re-enabling */
1353 /* Enable addresses */
1354 spydata->spy_number = wrqu->data.length;
1359 /*------------------------------------------------------------------*/
1361 * Standard Wireless Handler : get Spy List
1363 int iw_handler_get_spy(struct net_device * dev,
1364 struct iw_request_info * info,
1365 union iwreq_data * wrqu,
1368 struct iw_spy_data * spydata = get_spydata(dev);
1369 struct sockaddr * address = (struct sockaddr *) extra;
1372 /* Make sure driver is not buggy or using the old API */
1376 wrqu->data.length = spydata->spy_number;
1378 /* Copy addresses. */
1379 for(i = 0; i < spydata->spy_number; i++) {
1380 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
1381 address[i].sa_family = AF_UNIX;
1383 /* Copy stats to the user buffer (just after). */
1384 if(spydata->spy_number > 0)
1385 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
1387 sizeof(struct iw_quality) * spydata->spy_number);
1388 /* Reset updated flags. */
1389 for(i = 0; i < spydata->spy_number; i++)
1390 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
1394 /*------------------------------------------------------------------*/
1396 * Standard Wireless Handler : set spy threshold
1398 int iw_handler_set_thrspy(struct net_device * dev,
1399 struct iw_request_info *info,
1400 union iwreq_data * wrqu,
1403 struct iw_spy_data * spydata = get_spydata(dev);
1404 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1406 /* Make sure driver is not buggy or using the old API */
1411 memcpy(&(spydata->spy_thr_low), &(threshold->low),
1412 2 * sizeof(struct iw_quality));
1415 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
1418 printk(KERN_DEBUG "iw_handler_set_thrspy() : low %d ; high %d\n", spydata->spy_thr_low.level, spydata->spy_thr_high.level);
1419 #endif /* WE_SPY_DEBUG */
1424 /*------------------------------------------------------------------*/
1426 * Standard Wireless Handler : get spy threshold
1428 int iw_handler_get_thrspy(struct net_device * dev,
1429 struct iw_request_info *info,
1430 union iwreq_data * wrqu,
1433 struct iw_spy_data * spydata = get_spydata(dev);
1434 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
1436 /* Make sure driver is not buggy or using the old API */
1441 memcpy(&(threshold->low), &(spydata->spy_thr_low),
1442 2 * sizeof(struct iw_quality));
1447 /*------------------------------------------------------------------*/
1449 * Prepare and send a Spy Threshold event
1451 static void iw_send_thrspy_event(struct net_device * dev,
1452 struct iw_spy_data * spydata,
1453 unsigned char * address,
1454 struct iw_quality * wstats)
1456 union iwreq_data wrqu;
1457 struct iw_thrspy threshold;
1460 wrqu.data.length = 1;
1461 wrqu.data.flags = 0;
1463 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
1464 threshold.addr.sa_family = ARPHRD_ETHER;
1466 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
1467 /* Copy also thresholds */
1468 memcpy(&(threshold.low), &(spydata->spy_thr_low),
1469 2 * sizeof(struct iw_quality));
1472 printk(KERN_DEBUG "iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
1473 threshold.addr.sa_data[0],
1474 threshold.addr.sa_data[1],
1475 threshold.addr.sa_data[2],
1476 threshold.addr.sa_data[3],
1477 threshold.addr.sa_data[4],
1478 threshold.addr.sa_data[5], threshold.qual.level);
1479 #endif /* WE_SPY_DEBUG */
1481 /* Send event to user space */
1482 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
1485 /* ---------------------------------------------------------------- */
1487 * Call for the driver to update the spy data.
1488 * For now, the spy data is a simple array. As the size of the array is
1489 * small, this is good enough. If we wanted to support larger number of
1490 * spy addresses, we should use something more efficient...
1492 void wireless_spy_update(struct net_device * dev,
1493 unsigned char * address,
1494 struct iw_quality * wstats)
1496 struct iw_spy_data * spydata = get_spydata(dev);
1500 /* Make sure driver is not buggy or using the old API */
1505 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]);
1506 #endif /* WE_SPY_DEBUG */
1508 /* Update all records that match */
1509 for(i = 0; i < spydata->spy_number; i++)
1510 if(!compare_ether_addr(address, spydata->spy_address[i])) {
1511 memcpy(&(spydata->spy_stat[i]), wstats,
1512 sizeof(struct iw_quality));
1516 /* Generate an event if we cross the spy threshold.
1517 * To avoid event storms, we have a simple hysteresis : we generate
1518 * event only when we go under the low threshold or above the
1519 * high threshold. */
1521 if(spydata->spy_thr_under[match]) {
1522 if(wstats->level > spydata->spy_thr_high.level) {
1523 spydata->spy_thr_under[match] = 0;
1524 iw_send_thrspy_event(dev, spydata,
1528 if(wstats->level < spydata->spy_thr_low.level) {
1529 spydata->spy_thr_under[match] = 1;
1530 iw_send_thrspy_event(dev, spydata,
1537 EXPORT_SYMBOL(iw_handler_get_spy);
1538 EXPORT_SYMBOL(iw_handler_get_thrspy);
1539 EXPORT_SYMBOL(iw_handler_set_spy);
1540 EXPORT_SYMBOL(iw_handler_set_thrspy);
1541 EXPORT_SYMBOL(wireless_send_event);
1542 EXPORT_SYMBOL(wireless_spy_update);