2 * This file implement the Wireless Extensions APIs.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
7 * (As all part of the Linux kernel, this file is GPL)
10 /************************** DOCUMENTATION **************************/
14 * See <linux/wireless.h> for details of the APIs and the rest.
19 * v1 - 5.12.01 - Jean II
20 * o Created this file.
22 * v2 - 13.12.01 - Jean II
23 * o Move /proc/net/wireless stuff from net/core/dev.c to here
24 * o Make Wireless Extension IOCTLs go through here
25 * o Added iw_handler handling ;-)
26 * o Added standard ioctl description
27 * o Initial dumb commit strategy based on orinoco.c
29 * v3 - 19.12.01 - Jean II
30 * o Make sure we don't go out of standard_ioctl[] in ioctl_standard_call
31 * o Add event dispatcher function
32 * o Add event description
33 * o Propagate events as rtnetlink IFLA_WIRELESS option
34 * o Generate event on selected SET requests
36 * v4 - 18.04.02 - Jean II
37 * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1
39 * v5 - 21.06.02 - Jean II
40 * o Add IW_PRIV_TYPE_ADDR in priv_type_size (+cleanup)
41 * o Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
42 * o Add IWEVCUSTOM for driver specific event/scanning token
43 * o Turn on WE_STRICT_WRITE by default + kernel warning
44 * o Fix WE_STRICT_WRITE in ioctl_export_private() (32 => iw_num)
45 * o Fix off-by-one in test (extra_size <= IFNAMSIZ)
47 * v6 - 9.01.03 - Jean II
48 * o Add common spy support : iw_handler_set_spy(), wireless_spy_update()
49 * o Add enhanced spy support : iw_handler_set_thrspy() and event.
50 * o Add WIRELESS_EXT version display in /proc/net/wireless
52 * v6 - 18.06.04 - Jean II
53 * o Change get_spydata() method for added safety
54 * o Remove spy #ifdef, they are always on -> cleaner code
55 * o Allow any size GET request if user specifies length > max
56 * and if request has IW_DESCR_FLAG_NOMAX flag or is SIOCGIWPRIV
57 * o Start migrating get_wireless_stats to struct iw_handler_def
58 * o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus
59 * Based on patch from Pavel Roskin <proski@gnu.org> :
60 * o Fix kernel data leak to user space in private handler handling
62 * v7 - 18.3.05 - Jean II
63 * o Remove (struct iw_point *)->pointer from events and streams
64 * o Remove spy_offset from struct iw_handler_def
65 * o Start deprecating dev->get_wireless_stats, output a warning
66 * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless
67 * o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats)
69 * v8 - 17.02.06 - Jean II
70 * o RtNetlink requests support (SET/GET)
72 * v8b - 03.08.06 - Herbert Xu
73 * o Fix Wireless Event locking issues.
75 * v9 - 14.3.06 - Jean II
76 * o Change length in ESSID and NICK to strlen() instead of strlen()+1
77 * o Make standard_ioctl_num and standard_event_num unsigned
78 * o Remove (struct net_device *)->get_wireless_stats()
80 * v10 - 16.3.07 - Jean II
81 * o Prevent leaking of kernel space in stream on 64 bits.
84 /***************************** INCLUDES *****************************/
86 #include <linux/module.h>
87 #include <linux/types.h> /* off_t */
88 #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
89 #include <linux/proc_fs.h>
90 #include <linux/rtnetlink.h> /* rtnetlink stuff */
91 #include <linux/seq_file.h>
92 #include <linux/init.h> /* for __init */
93 #include <linux/if_arp.h> /* ARPHRD_ETHER */
94 #include <linux/etherdevice.h> /* compare_ether_addr */
95 #include <linux/interrupt.h>
97 #include <linux/wireless.h> /* Pretty obvious */
98 #include <net/iw_handler.h> /* New driver API */
99 #include <net/netlink.h>
101 #include <asm/uaccess.h> /* copy_to_user() */
103 /**************************** CONSTANTS ****************************/
105 /* Debugging stuff */
106 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
107 #undef WE_RTNETLINK_DEBUG /* Debug RtNetlink API */
108 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
109 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
112 //CONFIG_NET_WIRELESS_RTNETLINK /* Wireless requests over RtNetlink */
113 #define WE_EVENT_RTNETLINK /* Propagate events using RtNetlink */
114 #define WE_SET_EVENT /* Generate an event on some set commands */
116 /************************* GLOBAL VARIABLES *************************/
118 * You should not use global variables, because of re-entrancy.
119 * On our case, it's only const, so it's OK...
122 * Meta-data about all the standard Wireless Extension request we
125 static const struct iw_ioctl_description standard_ioctl[] = {
126 [SIOCSIWCOMMIT - SIOCIWFIRST] = {
127 .header_type = IW_HEADER_TYPE_NULL,
129 [SIOCGIWNAME - SIOCIWFIRST] = {
130 .header_type = IW_HEADER_TYPE_CHAR,
131 .flags = IW_DESCR_FLAG_DUMP,
133 [SIOCSIWNWID - SIOCIWFIRST] = {
134 .header_type = IW_HEADER_TYPE_PARAM,
135 .flags = IW_DESCR_FLAG_EVENT,
137 [SIOCGIWNWID - SIOCIWFIRST] = {
138 .header_type = IW_HEADER_TYPE_PARAM,
139 .flags = IW_DESCR_FLAG_DUMP,
141 [SIOCSIWFREQ - SIOCIWFIRST] = {
142 .header_type = IW_HEADER_TYPE_FREQ,
143 .flags = IW_DESCR_FLAG_EVENT,
145 [SIOCGIWFREQ - SIOCIWFIRST] = {
146 .header_type = IW_HEADER_TYPE_FREQ,
147 .flags = IW_DESCR_FLAG_DUMP,
149 [SIOCSIWMODE - SIOCIWFIRST] = {
150 .header_type = IW_HEADER_TYPE_UINT,
151 .flags = IW_DESCR_FLAG_EVENT,
153 [SIOCGIWMODE - SIOCIWFIRST] = {
154 .header_type = IW_HEADER_TYPE_UINT,
155 .flags = IW_DESCR_FLAG_DUMP,
157 [SIOCSIWSENS - SIOCIWFIRST] = {
158 .header_type = IW_HEADER_TYPE_PARAM,
160 [SIOCGIWSENS - SIOCIWFIRST] = {
161 .header_type = IW_HEADER_TYPE_PARAM,
163 [SIOCSIWRANGE - SIOCIWFIRST] = {
164 .header_type = IW_HEADER_TYPE_NULL,
166 [SIOCGIWRANGE - SIOCIWFIRST] = {
167 .header_type = IW_HEADER_TYPE_POINT,
169 .max_tokens = sizeof(struct iw_range),
170 .flags = IW_DESCR_FLAG_DUMP,
172 [SIOCSIWPRIV - SIOCIWFIRST] = {
173 .header_type = IW_HEADER_TYPE_NULL,
175 [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */
176 .header_type = IW_HEADER_TYPE_POINT,
177 .token_size = sizeof(struct iw_priv_args),
179 .flags = IW_DESCR_FLAG_NOMAX,
181 [SIOCSIWSTATS - SIOCIWFIRST] = {
182 .header_type = IW_HEADER_TYPE_NULL,
184 [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */
185 .header_type = IW_HEADER_TYPE_POINT,
187 .max_tokens = sizeof(struct iw_statistics),
188 .flags = IW_DESCR_FLAG_DUMP,
190 [SIOCSIWSPY - SIOCIWFIRST] = {
191 .header_type = IW_HEADER_TYPE_POINT,
192 .token_size = sizeof(struct sockaddr),
193 .max_tokens = IW_MAX_SPY,
195 [SIOCGIWSPY - SIOCIWFIRST] = {
196 .header_type = IW_HEADER_TYPE_POINT,
197 .token_size = sizeof(struct sockaddr) +
198 sizeof(struct iw_quality),
199 .max_tokens = IW_MAX_SPY,
201 [SIOCSIWTHRSPY - SIOCIWFIRST] = {
202 .header_type = IW_HEADER_TYPE_POINT,
203 .token_size = sizeof(struct iw_thrspy),
207 [SIOCGIWTHRSPY - SIOCIWFIRST] = {
208 .header_type = IW_HEADER_TYPE_POINT,
209 .token_size = sizeof(struct iw_thrspy),
213 [SIOCSIWAP - SIOCIWFIRST] = {
214 .header_type = IW_HEADER_TYPE_ADDR,
216 [SIOCGIWAP - SIOCIWFIRST] = {
217 .header_type = IW_HEADER_TYPE_ADDR,
218 .flags = IW_DESCR_FLAG_DUMP,
220 [SIOCSIWMLME - SIOCIWFIRST] = {
221 .header_type = IW_HEADER_TYPE_POINT,
223 .min_tokens = sizeof(struct iw_mlme),
224 .max_tokens = sizeof(struct iw_mlme),
226 [SIOCGIWAPLIST - SIOCIWFIRST] = {
227 .header_type = IW_HEADER_TYPE_POINT,
228 .token_size = sizeof(struct sockaddr) +
229 sizeof(struct iw_quality),
230 .max_tokens = IW_MAX_AP,
231 .flags = IW_DESCR_FLAG_NOMAX,
233 [SIOCSIWSCAN - SIOCIWFIRST] = {
234 .header_type = IW_HEADER_TYPE_POINT,
237 .max_tokens = sizeof(struct iw_scan_req),
239 [SIOCGIWSCAN - SIOCIWFIRST] = {
240 .header_type = IW_HEADER_TYPE_POINT,
242 .max_tokens = IW_SCAN_MAX_DATA,
243 .flags = IW_DESCR_FLAG_NOMAX,
245 [SIOCSIWESSID - SIOCIWFIRST] = {
246 .header_type = IW_HEADER_TYPE_POINT,
248 .max_tokens = IW_ESSID_MAX_SIZE,
249 .flags = IW_DESCR_FLAG_EVENT,
251 [SIOCGIWESSID - SIOCIWFIRST] = {
252 .header_type = IW_HEADER_TYPE_POINT,
254 .max_tokens = IW_ESSID_MAX_SIZE,
255 .flags = IW_DESCR_FLAG_DUMP,
257 [SIOCSIWNICKN - SIOCIWFIRST] = {
258 .header_type = IW_HEADER_TYPE_POINT,
260 .max_tokens = IW_ESSID_MAX_SIZE,
262 [SIOCGIWNICKN - SIOCIWFIRST] = {
263 .header_type = IW_HEADER_TYPE_POINT,
265 .max_tokens = IW_ESSID_MAX_SIZE,
267 [SIOCSIWRATE - SIOCIWFIRST] = {
268 .header_type = IW_HEADER_TYPE_PARAM,
270 [SIOCGIWRATE - SIOCIWFIRST] = {
271 .header_type = IW_HEADER_TYPE_PARAM,
273 [SIOCSIWRTS - SIOCIWFIRST] = {
274 .header_type = IW_HEADER_TYPE_PARAM,
276 [SIOCGIWRTS - SIOCIWFIRST] = {
277 .header_type = IW_HEADER_TYPE_PARAM,
279 [SIOCSIWFRAG - SIOCIWFIRST] = {
280 .header_type = IW_HEADER_TYPE_PARAM,
282 [SIOCGIWFRAG - SIOCIWFIRST] = {
283 .header_type = IW_HEADER_TYPE_PARAM,
285 [SIOCSIWTXPOW - SIOCIWFIRST] = {
286 .header_type = IW_HEADER_TYPE_PARAM,
288 [SIOCGIWTXPOW - SIOCIWFIRST] = {
289 .header_type = IW_HEADER_TYPE_PARAM,
291 [SIOCSIWRETRY - SIOCIWFIRST] = {
292 .header_type = IW_HEADER_TYPE_PARAM,
294 [SIOCGIWRETRY - SIOCIWFIRST] = {
295 .header_type = IW_HEADER_TYPE_PARAM,
297 [SIOCSIWENCODE - SIOCIWFIRST] = {
298 .header_type = IW_HEADER_TYPE_POINT,
300 .max_tokens = IW_ENCODING_TOKEN_MAX,
301 .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
303 [SIOCGIWENCODE - SIOCIWFIRST] = {
304 .header_type = IW_HEADER_TYPE_POINT,
306 .max_tokens = IW_ENCODING_TOKEN_MAX,
307 .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
309 [SIOCSIWPOWER - SIOCIWFIRST] = {
310 .header_type = IW_HEADER_TYPE_PARAM,
312 [SIOCGIWPOWER - SIOCIWFIRST] = {
313 .header_type = IW_HEADER_TYPE_PARAM,
315 [SIOCSIWGENIE - SIOCIWFIRST] = {
316 .header_type = IW_HEADER_TYPE_POINT,
318 .max_tokens = IW_GENERIC_IE_MAX,
320 [SIOCGIWGENIE - SIOCIWFIRST] = {
321 .header_type = IW_HEADER_TYPE_POINT,
323 .max_tokens = IW_GENERIC_IE_MAX,
325 [SIOCSIWAUTH - SIOCIWFIRST] = {
326 .header_type = IW_HEADER_TYPE_PARAM,
328 [SIOCGIWAUTH - SIOCIWFIRST] = {
329 .header_type = IW_HEADER_TYPE_PARAM,
331 [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
332 .header_type = IW_HEADER_TYPE_POINT,
334 .min_tokens = sizeof(struct iw_encode_ext),
335 .max_tokens = sizeof(struct iw_encode_ext) +
336 IW_ENCODING_TOKEN_MAX,
338 [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
339 .header_type = IW_HEADER_TYPE_POINT,
341 .min_tokens = sizeof(struct iw_encode_ext),
342 .max_tokens = sizeof(struct iw_encode_ext) +
343 IW_ENCODING_TOKEN_MAX,
345 [SIOCSIWPMKSA - SIOCIWFIRST] = {
346 .header_type = IW_HEADER_TYPE_POINT,
348 .min_tokens = sizeof(struct iw_pmksa),
349 .max_tokens = sizeof(struct iw_pmksa),
352 static const unsigned standard_ioctl_num = (sizeof(standard_ioctl) /
353 sizeof(struct iw_ioctl_description));
356 * Meta-data about all the additional standard Wireless Extension events
359 static const struct iw_ioctl_description standard_event[] = {
360 [IWEVTXDROP - IWEVFIRST] = {
361 .header_type = IW_HEADER_TYPE_ADDR,
363 [IWEVQUAL - IWEVFIRST] = {
364 .header_type = IW_HEADER_TYPE_QUAL,
366 [IWEVCUSTOM - IWEVFIRST] = {
367 .header_type = IW_HEADER_TYPE_POINT,
369 .max_tokens = IW_CUSTOM_MAX,
371 [IWEVREGISTERED - IWEVFIRST] = {
372 .header_type = IW_HEADER_TYPE_ADDR,
374 [IWEVEXPIRED - IWEVFIRST] = {
375 .header_type = IW_HEADER_TYPE_ADDR,
377 [IWEVGENIE - IWEVFIRST] = {
378 .header_type = IW_HEADER_TYPE_POINT,
380 .max_tokens = IW_GENERIC_IE_MAX,
382 [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
383 .header_type = IW_HEADER_TYPE_POINT,
385 .max_tokens = sizeof(struct iw_michaelmicfailure),
387 [IWEVASSOCREQIE - IWEVFIRST] = {
388 .header_type = IW_HEADER_TYPE_POINT,
390 .max_tokens = IW_GENERIC_IE_MAX,
392 [IWEVASSOCRESPIE - IWEVFIRST] = {
393 .header_type = IW_HEADER_TYPE_POINT,
395 .max_tokens = IW_GENERIC_IE_MAX,
397 [IWEVPMKIDCAND - IWEVFIRST] = {
398 .header_type = IW_HEADER_TYPE_POINT,
400 .max_tokens = sizeof(struct iw_pmkid_cand),
403 static const unsigned standard_event_num = (sizeof(standard_event) /
404 sizeof(struct iw_ioctl_description));
406 /* Size (in bytes) of the various private data types */
407 static const char iw_priv_type_size[] = {
408 0, /* IW_PRIV_TYPE_NONE */
409 1, /* IW_PRIV_TYPE_BYTE */
410 1, /* IW_PRIV_TYPE_CHAR */
412 sizeof(__u32), /* IW_PRIV_TYPE_INT */
413 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
414 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
418 /* Size (in bytes) of various events */
419 static const int event_type_size[] = {
420 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
422 IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
424 IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
425 IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
426 IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
428 IW_EV_POINT_LEN, /* Without variable payload */
429 IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
430 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
433 /* Size (in bytes) of various events, as packed */
434 static const int event_type_pk_size[] = {
435 IW_EV_LCP_PK_LEN, /* IW_HEADER_TYPE_NULL */
437 IW_EV_CHAR_PK_LEN, /* IW_HEADER_TYPE_CHAR */
439 IW_EV_UINT_PK_LEN, /* IW_HEADER_TYPE_UINT */
440 IW_EV_FREQ_PK_LEN, /* IW_HEADER_TYPE_FREQ */
441 IW_EV_ADDR_PK_LEN, /* IW_HEADER_TYPE_ADDR */
443 IW_EV_POINT_PK_LEN, /* Without variable payload */
444 IW_EV_PARAM_PK_LEN, /* IW_HEADER_TYPE_PARAM */
445 IW_EV_QUAL_PK_LEN, /* IW_HEADER_TYPE_QUAL */
448 /************************ COMMON SUBROUTINES ************************/
450 * Stuff that may be used in various place or doesn't fit in one
451 * of the section below.
454 /* ---------------------------------------------------------------- */
456 * Return the driver handler associated with a specific Wireless Extension.
457 * Called from various place, so make sure it remains efficient.
459 static inline iw_handler get_handler(struct net_device *dev,
462 /* Don't "optimise" the following variable, it will crash */
463 unsigned int index; /* *MUST* be unsigned */
465 /* Check if we have some wireless handlers defined */
466 if(dev->wireless_handlers == NULL)
469 /* Try as a standard command */
470 index = cmd - SIOCIWFIRST;
471 if(index < dev->wireless_handlers->num_standard)
472 return dev->wireless_handlers->standard[index];
474 /* Try as a private command */
475 index = cmd - SIOCIWFIRSTPRIV;
476 if(index < dev->wireless_handlers->num_private)
477 return dev->wireless_handlers->private[index];
483 /* ---------------------------------------------------------------- */
485 * Get statistics out of the driver
487 static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
490 if((dev->wireless_handlers != NULL) &&
491 (dev->wireless_handlers->get_wireless_stats != NULL))
492 return dev->wireless_handlers->get_wireless_stats(dev);
495 return (struct iw_statistics *) NULL;
498 /* ---------------------------------------------------------------- */
500 * Call the commit handler in the driver
501 * (if exist and if conditions are right)
503 * Note : our current commit strategy is currently pretty dumb,
504 * but we will be able to improve on that...
505 * The goal is to try to agreagate as many changes as possible
506 * before doing the commit. Drivers that will define a commit handler
507 * are usually those that need a reset after changing parameters, so
508 * we want to minimise the number of reset.
509 * A cool idea is to use a timer : at each "set" command, we re-set the
510 * timer, when the timer eventually fires, we call the driver.
511 * Hopefully, more on that later.
513 * Also, I'm waiting to see how many people will complain about the
514 * netif_running(dev) test. I'm open on that one...
515 * Hopefully, the driver will remember to do a commit in "open()" ;-)
517 static inline int call_commit_handler(struct net_device * dev)
519 if((netif_running(dev)) &&
520 (dev->wireless_handlers->standard[0] != NULL)) {
521 /* Call the commit handler on the driver */
522 return dev->wireless_handlers->standard[0](dev, NULL,
525 return 0; /* Command completed successfully */
528 /* ---------------------------------------------------------------- */
530 * Calculate size of private arguments
532 static inline int get_priv_size(__u16 args)
534 int num = args & IW_PRIV_SIZE_MASK;
535 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
537 return num * iw_priv_type_size[type];
540 /* ---------------------------------------------------------------- */
542 * Re-calculate the size of private arguments
544 static inline int adjust_priv_size(__u16 args,
545 union iwreq_data * wrqu)
547 int num = wrqu->data.length;
548 int max = args & IW_PRIV_SIZE_MASK;
549 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
551 /* Make sure the driver doesn't goof up */
555 return num * iw_priv_type_size[type];
558 /* ---------------------------------------------------------------- */
560 * Standard Wireless Handler : get wireless stats
561 * Allow programatic access to /proc/net/wireless even if /proc
562 * doesn't exist... Also more efficient...
564 static int iw_handler_get_iwstats(struct net_device * dev,
565 struct iw_request_info * info,
566 union iwreq_data * wrqu,
569 /* Get stats from the driver */
570 struct iw_statistics *stats;
572 stats = get_wireless_stats(dev);
573 if (stats != (struct iw_statistics *) NULL) {
575 /* Copy statistics to extra */
576 memcpy(extra, stats, sizeof(struct iw_statistics));
577 wrqu->data.length = sizeof(struct iw_statistics);
579 /* Check if we need to clear the updated flag */
580 if(wrqu->data.flags != 0)
581 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
587 /* ---------------------------------------------------------------- */
589 * Standard Wireless Handler : get iwpriv definitions
590 * Export the driver private handler definition
591 * They will be picked up by tools like iwpriv...
593 static int iw_handler_get_private(struct net_device * dev,
594 struct iw_request_info * info,
595 union iwreq_data * wrqu,
598 /* Check if the driver has something to export */
599 if((dev->wireless_handlers->num_private_args == 0) ||
600 (dev->wireless_handlers->private_args == NULL))
603 /* Check if there is enough buffer up there */
604 if(wrqu->data.length < dev->wireless_handlers->num_private_args) {
605 /* User space can't know in advance how large the buffer
606 * needs to be. Give it a hint, so that we can support
607 * any size buffer we want somewhat efficiently... */
608 wrqu->data.length = dev->wireless_handlers->num_private_args;
612 /* Set the number of available ioctls. */
613 wrqu->data.length = dev->wireless_handlers->num_private_args;
615 /* Copy structure to the user buffer. */
616 memcpy(extra, dev->wireless_handlers->private_args,
617 sizeof(struct iw_priv_args) * wrqu->data.length);
623 /******************** /proc/net/wireless SUPPORT ********************/
625 * The /proc/net/wireless file is a human readable user-space interface
626 * exporting various wireless specific statistics from the wireless devices.
627 * This is the most popular part of the Wireless Extensions ;-)
629 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
630 * The content of the file is basically the content of "struct iw_statistics".
633 #ifdef CONFIG_PROC_FS
635 /* ---------------------------------------------------------------- */
637 * Print one entry (line) of /proc/net/wireless
639 static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
640 struct net_device *dev)
642 /* Get stats from the driver */
643 struct iw_statistics *stats = get_wireless_stats(dev);
646 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
648 dev->name, stats->status, stats->qual.qual,
649 stats->qual.updated & IW_QUAL_QUAL_UPDATED
651 ((__s32) stats->qual.level) -
652 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
653 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
655 ((__s32) stats->qual.noise) -
656 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
657 stats->qual.updated & IW_QUAL_NOISE_UPDATED
659 stats->discard.nwid, stats->discard.code,
660 stats->discard.fragment, stats->discard.retries,
661 stats->discard.misc, stats->miss.beacon);
662 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
666 /* ---------------------------------------------------------------- */
668 * Print info for /proc/net/wireless (print all entries)
670 static int wireless_seq_show(struct seq_file *seq, void *v)
672 if (v == SEQ_START_TOKEN)
673 seq_printf(seq, "Inter-| sta-| Quality | Discarded "
674 "packets | Missed | WE\n"
675 " face | tus | link level noise | nwid "
676 "crypt frag retry misc | beacon | %d\n",
679 wireless_seq_printf_stats(seq, v);
683 static struct seq_operations wireless_seq_ops = {
684 .start = dev_seq_start,
685 .next = dev_seq_next,
686 .stop = dev_seq_stop,
687 .show = wireless_seq_show,
690 static int wireless_seq_open(struct inode *inode, struct file *file)
692 return seq_open(file, &wireless_seq_ops);
695 static const struct file_operations wireless_seq_fops = {
696 .owner = THIS_MODULE,
697 .open = wireless_seq_open,
700 .release = seq_release,
703 int __init wireless_proc_init(void)
705 /* Create /proc/net/wireless entry */
706 if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
711 #endif /* CONFIG_PROC_FS */
713 /************************** IOCTL SUPPORT **************************/
715 * The original user space API to configure all those Wireless Extensions
717 * In there, we check if we need to call the new driver API (iw_handler)
718 * or just call the driver ioctl handler.
721 /* ---------------------------------------------------------------- */
723 * Wrapper to call a standard Wireless Extension handler.
724 * We do various checks and also take care of moving data between
725 * user space and kernel space.
727 static int ioctl_standard_call(struct net_device * dev,
732 struct iwreq * iwr = (struct iwreq *) ifr;
733 const struct iw_ioctl_description * descr;
734 struct iw_request_info info;
737 /* Get the description of the IOCTL */
738 if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
740 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
742 #ifdef WE_IOCTL_DEBUG
743 printk(KERN_DEBUG "%s (WE) : Found standard handler for 0x%04X\n",
745 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);
746 #endif /* WE_IOCTL_DEBUG */
748 /* Prepare the call */
752 /* Check if we have a pointer to user space data or not */
753 if(descr->header_type != IW_HEADER_TYPE_POINT) {
755 /* No extra arguments. Trivial to handle */
756 ret = handler(dev, &info, &(iwr->u), NULL);
759 /* Generate an event to notify listeners of the change */
760 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
761 ((ret == 0) || (ret == -EIWCOMMIT)))
762 wireless_send_event(dev, cmd, &(iwr->u), NULL);
763 #endif /* WE_SET_EVENT */
769 int essid_compat = 0;
771 /* Calculate space needed by arguments. Always allocate
772 * for max space. Easier, and won't last long... */
773 extra_size = descr->max_tokens * descr->token_size;
775 /* Check need for ESSID compatibility for WE < 21 */
781 if (iwr->u.data.length == descr->max_tokens + 1)
783 else if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
784 char essid[IW_ESSID_MAX_SIZE + 1];
786 err = copy_from_user(essid, iwr->u.data.pointer,
792 if (essid[iwr->u.data.length - 1] == '\0')
800 iwr->u.data.length -= essid_compat;
802 /* Check what user space is giving us */
804 /* Check NULL pointer */
805 if((iwr->u.data.pointer == NULL) &&
806 (iwr->u.data.length != 0))
808 /* Check if number of token fits within bounds */
809 if(iwr->u.data.length > descr->max_tokens)
811 if(iwr->u.data.length < descr->min_tokens)
814 /* Check NULL pointer */
815 if(iwr->u.data.pointer == NULL)
817 /* Save user space buffer size for checking */
818 user_length = iwr->u.data.length;
820 /* Don't check if user_length > max to allow forward
821 * compatibility. The test user_length < min is
822 * implied by the test at the end. */
824 /* Support for very large requests */
825 if((descr->flags & IW_DESCR_FLAG_NOMAX) &&
826 (user_length > descr->max_tokens)) {
827 /* Allow userspace to GET more than max so
828 * we can support any size GET requests.
829 * There is still a limit : -ENOMEM. */
830 extra_size = user_length * descr->token_size;
831 /* Note : user_length is originally a __u16,
832 * and token_size is controlled by us,
833 * so extra_size won't get negative and
834 * won't overflow... */
838 #ifdef WE_IOCTL_DEBUG
839 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
840 dev->name, extra_size);
841 #endif /* WE_IOCTL_DEBUG */
843 /* Create the kernel buffer */
844 /* kzalloc ensures NULL-termination for essid_compat */
845 extra = kzalloc(extra_size, GFP_KERNEL);
850 /* If it is a SET, get all the extra data in here */
851 if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
852 err = copy_from_user(extra, iwr->u.data.pointer,
859 #ifdef WE_IOCTL_DEBUG
860 printk(KERN_DEBUG "%s (WE) : Got %d bytes\n",
862 iwr->u.data.length * descr->token_size);
863 #endif /* WE_IOCTL_DEBUG */
866 /* Call the handler */
867 ret = handler(dev, &info, &(iwr->u), extra);
869 iwr->u.data.length += essid_compat;
871 /* If we have something to return to the user */
872 if (!ret && IW_IS_GET(cmd)) {
873 /* Check if there is enough buffer up there */
874 if(user_length < iwr->u.data.length) {
879 err = copy_to_user(iwr->u.data.pointer, extra,
884 #ifdef WE_IOCTL_DEBUG
885 printk(KERN_DEBUG "%s (WE) : Wrote %d bytes\n",
887 iwr->u.data.length * descr->token_size);
888 #endif /* WE_IOCTL_DEBUG */
892 /* Generate an event to notify listeners of the change */
893 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
894 ((ret == 0) || (ret == -EIWCOMMIT))) {
895 if(descr->flags & IW_DESCR_FLAG_RESTRICT)
896 /* If the event is restricted, don't
897 * export the payload */
898 wireless_send_event(dev, cmd, &(iwr->u), NULL);
900 wireless_send_event(dev, cmd, &(iwr->u),
903 #endif /* WE_SET_EVENT */
905 /* Cleanup - I told you it wasn't that long ;-) */
909 /* Call commit handler if needed and defined */
910 if(ret == -EIWCOMMIT)
911 ret = call_commit_handler(dev);
913 /* Here, we will generate the appropriate event if needed */
918 /* ---------------------------------------------------------------- */
920 * Wrapper to call a private Wireless Extension handler.
921 * We do various checks and also take care of moving data between
922 * user space and kernel space.
923 * It's not as nice and slimline as the standard wrapper. The cause
924 * is struct iw_priv_args, which was not really designed for the
925 * job we are going here.
927 * IMPORTANT : This function prevent to set and get data on the same
928 * IOCTL and enforce the SET/GET convention. Not doing it would be
930 * If you need to set and get data at the same time, please don't use
931 * a iw_handler but process it in your ioctl handler (i.e. use the
934 static inline int ioctl_private_call(struct net_device * dev,
939 struct iwreq * iwr = (struct iwreq *) ifr;
940 const struct iw_priv_args * descr = NULL;
941 struct iw_request_info info;
946 /* Get the description of the IOCTL */
947 for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
948 if(cmd == dev->wireless_handlers->private_args[i].cmd) {
949 descr = &(dev->wireless_handlers->private_args[i]);
953 #ifdef WE_IOCTL_DEBUG
954 printk(KERN_DEBUG "%s (WE) : Found private handler for 0x%04X\n",
957 printk(KERN_DEBUG "%s (WE) : Name %s, set %X, get %X\n",
958 dev->name, descr->name,
959 descr->set_args, descr->get_args);
961 #endif /* WE_IOCTL_DEBUG */
963 /* Compute the size of the set/get arguments */
966 int offset = 0; /* For sub-ioctls */
967 /* Check for sub-ioctl handler */
968 if(descr->name[0] == '\0')
969 /* Reserve one int for sub-ioctl index */
970 offset = sizeof(__u32);
972 /* Size of set arguments */
973 extra_size = get_priv_size(descr->set_args);
975 /* Does it fits in iwr ? */
976 if((descr->set_args & IW_PRIV_SIZE_FIXED) &&
977 ((extra_size + offset) <= IFNAMSIZ))
980 /* Size of get arguments */
981 extra_size = get_priv_size(descr->get_args);
983 /* Does it fits in iwr ? */
984 if((descr->get_args & IW_PRIV_SIZE_FIXED) &&
985 (extra_size <= IFNAMSIZ))
990 /* Prepare the call */
994 /* Check if we have a pointer to user space data or not. */
995 if(extra_size == 0) {
996 /* No extra arguments. Trivial to handle */
997 ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u));
1002 /* Check what user space is giving us */
1003 if(IW_IS_SET(cmd)) {
1004 /* Check NULL pointer */
1005 if((iwr->u.data.pointer == NULL) &&
1006 (iwr->u.data.length != 0))
1009 /* Does it fits within bounds ? */
1010 if(iwr->u.data.length > (descr->set_args &
1014 /* Check NULL pointer */
1015 if(iwr->u.data.pointer == NULL)
1019 #ifdef WE_IOCTL_DEBUG
1020 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
1021 dev->name, extra_size);
1022 #endif /* WE_IOCTL_DEBUG */
1024 /* Always allocate for max space. Easier, and won't last
1026 extra = kmalloc(extra_size, GFP_KERNEL);
1027 if (extra == NULL) {
1031 /* If it is a SET, get all the extra data in here */
1032 if(IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
1033 err = copy_from_user(extra, iwr->u.data.pointer,
1039 #ifdef WE_IOCTL_DEBUG
1040 printk(KERN_DEBUG "%s (WE) : Got %d elem\n",
1041 dev->name, iwr->u.data.length);
1042 #endif /* WE_IOCTL_DEBUG */
1045 /* Call the handler */
1046 ret = handler(dev, &info, &(iwr->u), extra);
1048 /* If we have something to return to the user */
1049 if (!ret && IW_IS_GET(cmd)) {
1051 /* Adjust for the actual length if it's variable,
1052 * avoid leaking kernel bits outside. */
1053 if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) {
1054 extra_size = adjust_priv_size(descr->get_args,
1058 err = copy_to_user(iwr->u.data.pointer, extra,
1062 #ifdef WE_IOCTL_DEBUG
1063 printk(KERN_DEBUG "%s (WE) : Wrote %d elem\n",
1064 dev->name, iwr->u.data.length);
1065 #endif /* WE_IOCTL_DEBUG */
1068 /* Cleanup - I told you it wasn't that long ;-) */
1073 /* Call commit handler if needed and defined */
1074 if(ret == -EIWCOMMIT)
1075 ret = call_commit_handler(dev);
1080 /* ---------------------------------------------------------------- */
1082 * Main IOCTl dispatcher. Called from the main networking code
1083 * (dev_ioctl() in net/core/dev.c).
1084 * Check the type of IOCTL and call the appropriate wrapper...
1086 int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
1088 struct net_device *dev;
1091 /* Permissions are already checked in dev_ioctl() before calling us.
1092 * The copy_to/from_user() of ifr is also dealt with in there */
1094 /* Make sure the device exist */
1095 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
1098 /* A bunch of special cases, then the generic case...
1099 * Note that 'cmd' is already filtered in dev_ioctl() with
1100 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1104 /* Get Wireless Stats */
1105 return ioctl_standard_call(dev,
1108 &iw_handler_get_iwstats);
1111 /* Check if we have some wireless handlers defined */
1112 if(dev->wireless_handlers != NULL) {
1113 /* We export to user space the definition of
1114 * the private handler ourselves */
1115 return ioctl_standard_call(dev,
1118 &iw_handler_get_private);
1120 // ## Fall-through for old API ##
1124 if (!netif_device_present(dev))
1126 /* New driver API : try to find the handler */
1127 handler = get_handler(dev, cmd);
1128 if(handler != NULL) {
1129 /* Standard and private are not the same */
1130 if(cmd < SIOCIWFIRSTPRIV)
1131 return ioctl_standard_call(dev,
1136 return ioctl_private_call(dev,
1141 /* Old driver API : call driver ioctl handler */
1142 if (dev->do_ioctl) {
1143 return dev->do_ioctl(dev, ifr, cmd);
1151 /********************** RTNETLINK REQUEST API **********************/
1153 * The alternate user space API to configure all those Wireless Extensions
1154 * is through RtNetlink.
1155 * This API support only the new driver API (iw_handler).
1157 * This RtNetlink API use the same query/reply model as the ioctl API.
1158 * Maximum effort has been done to fit in the RtNetlink model, and
1159 * we support both RtNetlink Set and RtNelink Get operations.
1160 * On the other hand, we don't offer Dump operations because of the
1161 * following reasons :
1162 * o Large number of parameters, most optional
1163 * o Large size of some parameters (> 100 bytes)
1164 * o Each parameters need to be extracted from hardware
1165 * o Scan requests can take seconds and disable network activity.
1166 * Because of this high cost/overhead, we want to return only the
1167 * parameters the user application is really interested in.
1168 * We could offer partial Dump using the IW_DESCR_FLAG_DUMP flag.
1170 * The API uses the standard RtNetlink socket. When the RtNetlink code
1171 * find a IFLA_WIRELESS field in a RtNetlink SET_LINK request,
1175 #ifdef CONFIG_NET_WIRELESS_RTNETLINK
1176 /* ---------------------------------------------------------------- */
1178 * Wrapper to call a standard Wireless Extension GET handler.
1179 * We do various checks and call the handler with the proper args.
1181 static int rtnetlink_standard_get(struct net_device * dev,
1182 struct iw_event * request,
1188 const struct iw_ioctl_description * descr = NULL;
1190 union iwreq_data * wrqu;
1192 struct iw_request_info info;
1193 char * buffer = NULL;
1194 int buffer_size = 0;
1197 /* Get the description of the Request */
1199 if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
1201 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
1203 #ifdef WE_RTNETLINK_DEBUG
1204 printk(KERN_DEBUG "%s (WE.r) : Found standard handler for 0x%04X\n",
1206 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);
1207 #endif /* WE_RTNETLINK_DEBUG */
1209 /* Check if wrqu is complete */
1210 hdr_len = event_type_size[descr->header_type];
1211 if(request_len < hdr_len) {
1212 #ifdef WE_RTNETLINK_DEBUG
1214 "%s (WE.r) : Wireless request too short (%d)\n",
1215 dev->name, request_len);
1216 #endif /* WE_RTNETLINK_DEBUG */
1220 /* Prepare the call */
1224 /* Check if we have extra data in the reply or not */
1225 if(descr->header_type != IW_HEADER_TYPE_POINT) {
1227 /* Create the kernel buffer that we will return.
1228 * It's at an offset to match the TYPE_POINT case... */
1229 buffer_size = request_len + IW_EV_POINT_OFF;
1230 buffer = kmalloc(buffer_size, GFP_KERNEL);
1231 if (buffer == NULL) {
1234 /* Copy event data */
1235 memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
1236 /* Use our own copy of wrqu */
1237 wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
1238 + IW_EV_LCP_PK_LEN);
1240 /* No extra arguments. Trivial to handle */
1241 ret = handler(dev, &info, wrqu, NULL);
1244 union iwreq_data wrqu_point;
1245 char * extra = NULL;
1248 /* Get a temp copy of wrqu (skip pointer) */
1249 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1250 ((char *) request) + IW_EV_LCP_PK_LEN,
1251 IW_EV_POINT_LEN - IW_EV_LCP_PK_LEN);
1253 /* Calculate space needed by arguments. Always allocate
1254 * for max space. Easier, and won't last long... */
1255 extra_size = descr->max_tokens * descr->token_size;
1256 /* Support for very large requests */
1257 if((descr->flags & IW_DESCR_FLAG_NOMAX) &&
1258 (wrqu_point.data.length > descr->max_tokens))
1259 extra_size = (wrqu_point.data.length
1260 * descr->token_size);
1261 buffer_size = extra_size + IW_EV_POINT_PK_LEN + IW_EV_POINT_OFF;
1262 #ifdef WE_RTNETLINK_DEBUG
1263 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1264 dev->name, extra_size, buffer_size);
1265 #endif /* WE_RTNETLINK_DEBUG */
1267 /* Create the kernel buffer that we will return */
1268 buffer = kmalloc(buffer_size, GFP_KERNEL);
1269 if (buffer == NULL) {
1273 /* Put wrqu in the right place (just before extra).
1274 * Leave space for IWE header and dummy pointer...
1275 * Note that IW_EV_LCP_PK_LEN==4 bytes, so it's still aligned.
1277 memcpy(buffer + IW_EV_LCP_PK_LEN + IW_EV_POINT_OFF,
1278 ((char *) &wrqu_point) + IW_EV_POINT_OFF,
1279 IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1280 wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_PK_LEN);
1282 /* Extra comes logically after that. Offset +12 bytes. */
1283 extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_PK_LEN;
1285 /* Call the handler */
1286 ret = handler(dev, &info, wrqu, extra);
1288 /* Calculate real returned length */
1289 extra_size = (wrqu->data.length * descr->token_size);
1290 /* Re-adjust reply size */
1291 request->len = extra_size + IW_EV_POINT_PK_LEN;
1293 /* Put the iwe header where it should, i.e. scrap the
1295 memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_PK_LEN);
1297 #ifdef WE_RTNETLINK_DEBUG
1298 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);
1299 #endif /* WE_RTNETLINK_DEBUG */
1301 /* Check if there is enough buffer up there */
1302 if(wrqu_point.data.length < wrqu->data.length)
1306 /* Return the buffer to the caller */
1309 *p_len = request->len;
1319 /* ---------------------------------------------------------------- */
1321 * Wrapper to call a standard Wireless Extension SET handler.
1322 * We do various checks and call the handler with the proper args.
1324 static inline int rtnetlink_standard_set(struct net_device * dev,
1325 struct iw_event * request,
1329 const struct iw_ioctl_description * descr = NULL;
1331 union iwreq_data * wrqu;
1332 union iwreq_data wrqu_point;
1334 char * extra = NULL;
1336 struct iw_request_info info;
1339 /* Get the description of the Request */
1341 if((cmd - SIOCIWFIRST) >= standard_ioctl_num)
1343 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
1345 #ifdef WE_RTNETLINK_DEBUG
1346 printk(KERN_DEBUG "%s (WE.r) : Found standard SET handler for 0x%04X\n",
1348 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);
1349 #endif /* WE_RTNETLINK_DEBUG */
1351 /* Extract fixed header from request. This is properly aligned. */
1352 wrqu = (union iwreq_data *) (((char *) request) + IW_EV_LCP_PK_LEN);
1354 /* Check if wrqu is complete */
1355 hdr_len = event_type_pk_size[descr->header_type];
1356 if(request_len < hdr_len) {
1357 #ifdef WE_RTNETLINK_DEBUG
1359 "%s (WE.r) : Wireless request too short (%d)\n",
1360 dev->name, request_len);
1361 #endif /* WE_RTNETLINK_DEBUG */
1365 /* Prepare the call */
1369 /* Check if we have extra data in the request or not */
1370 if(descr->header_type != IW_HEADER_TYPE_POINT) {
1372 /* No extra arguments. Trivial to handle */
1373 ret = handler(dev, &info, wrqu, NULL);
1378 /* Put wrqu in the right place (skip pointer) */
1379 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1380 wrqu, IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1381 /* Don't forget about the event code... */
1384 /* Check if number of token fits within bounds */
1385 if(wrqu_point.data.length > descr->max_tokens)
1387 if(wrqu_point.data.length < descr->min_tokens)
1390 /* Real length of payload */
1391 extra_len = wrqu_point.data.length * descr->token_size;
1393 /* Check if request is self consistent */
1394 if((request_len - hdr_len) < extra_len) {
1395 #ifdef WE_RTNETLINK_DEBUG
1396 printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
1397 dev->name, extra_size);
1398 #endif /* WE_RTNETLINK_DEBUG */
1402 #ifdef WE_RTNETLINK_DEBUG
1403 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
1404 dev->name, extra_size);
1405 #endif /* WE_RTNETLINK_DEBUG */
1407 /* Always allocate for max space. Easier, and won't last
1409 extra_size = descr->max_tokens * descr->token_size;
1410 extra = kmalloc(extra_size, GFP_KERNEL);
1414 /* Copy extra in aligned buffer */
1415 memcpy(extra, ((char *) request) + hdr_len, extra_len);
1417 /* Call the handler */
1418 ret = handler(dev, &info, &wrqu_point, extra);
1422 /* Generate an event to notify listeners of the change */
1423 if((descr->flags & IW_DESCR_FLAG_EVENT) &&
1424 ((ret == 0) || (ret == -EIWCOMMIT))) {
1425 if(descr->flags & IW_DESCR_FLAG_RESTRICT)
1426 /* If the event is restricted, don't
1427 * export the payload */
1428 wireless_send_event(dev, cmd, wrqu, NULL);
1430 wireless_send_event(dev, cmd, wrqu, extra);
1432 #endif /* WE_SET_EVENT */
1434 /* Cleanup - I told you it wasn't that long ;-) */
1438 /* Call commit handler if needed and defined */
1439 if(ret == -EIWCOMMIT)
1440 ret = call_commit_handler(dev);
1445 /* ---------------------------------------------------------------- */
1447 * Wrapper to call a private Wireless Extension GET handler.
1449 * It's not as nice and slimline as the standard wrapper. The cause
1450 * is struct iw_priv_args, which was not really designed for the
1451 * job we are going here.
1453 * IMPORTANT : This function prevent to set and get data on the same
1454 * IOCTL and enforce the SET/GET convention. Not doing it would be
1456 * If you need to set and get data at the same time, please don't use
1457 * a iw_handler but process it in your ioctl handler (i.e. use the
1460 static inline int rtnetlink_private_get(struct net_device * dev,
1461 struct iw_event * request,
1467 const struct iw_priv_args * descr = NULL;
1469 union iwreq_data * wrqu;
1471 struct iw_request_info info;
1474 char * buffer = NULL;
1475 int buffer_size = 0;
1478 /* Get the description of the Request */
1480 for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
1481 if(cmd == dev->wireless_handlers->private_args[i].cmd) {
1482 descr = &(dev->wireless_handlers->private_args[i]);
1488 #ifdef WE_RTNETLINK_DEBUG
1489 printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
1491 printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
1492 dev->name, descr->name, descr->set_args, descr->get_args);
1493 #endif /* WE_RTNETLINK_DEBUG */
1495 /* Compute the max size of the get arguments */
1496 extra_size = get_priv_size(descr->get_args);
1498 /* Does it fits in wrqu ? */
1499 if((descr->get_args & IW_PRIV_SIZE_FIXED) &&
1500 (extra_size <= IFNAMSIZ)) {
1501 hdr_len = extra_size;
1504 hdr_len = IW_EV_POINT_PK_LEN;
1507 /* Check if wrqu is complete */
1508 if(request_len < hdr_len) {
1509 #ifdef WE_RTNETLINK_DEBUG
1511 "%s (WE.r) : Wireless request too short (%d)\n",
1512 dev->name, request_len);
1513 #endif /* WE_RTNETLINK_DEBUG */
1517 /* Prepare the call */
1521 /* Check if we have a pointer to user space data or not. */
1522 if(extra_size == 0) {
1524 /* Create the kernel buffer that we will return.
1525 * It's at an offset to match the TYPE_POINT case... */
1526 buffer_size = request_len + IW_EV_POINT_OFF;
1527 buffer = kmalloc(buffer_size, GFP_KERNEL);
1528 if (buffer == NULL) {
1531 /* Copy event data */
1532 memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
1533 /* Use our own copy of wrqu */
1534 wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
1535 + IW_EV_LCP_PK_LEN);
1537 /* No extra arguments. Trivial to handle */
1538 ret = handler(dev, &info, wrqu, (char *) wrqu);
1543 /* Buffer for full reply */
1544 buffer_size = extra_size + IW_EV_POINT_PK_LEN + IW_EV_POINT_OFF;
1546 #ifdef WE_RTNETLINK_DEBUG
1547 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1548 dev->name, extra_size, buffer_size);
1549 #endif /* WE_RTNETLINK_DEBUG */
1551 /* Create the kernel buffer that we will return */
1552 buffer = kmalloc(buffer_size, GFP_KERNEL);
1553 if (buffer == NULL) {
1557 /* Put wrqu in the right place (just before extra).
1558 * Leave space for IWE header and dummy pointer...
1559 * Note that IW_EV_LCP_PK_LEN==4 bytes, so it's still aligned.
1561 memcpy(buffer + IW_EV_LCP_PK_LEN + IW_EV_POINT_OFF,
1562 ((char *) request) + IW_EV_LCP_PK_LEN,
1563 IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1564 wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_PK_LEN);
1566 /* Extra comes logically after that. Offset +12 bytes. */
1567 extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_PK_LEN;
1569 /* Call the handler */
1570 ret = handler(dev, &info, wrqu, extra);
1572 /* Adjust for the actual length if it's variable,
1573 * avoid leaking kernel bits outside. */
1574 if (!(descr->get_args & IW_PRIV_SIZE_FIXED))
1575 extra_size = adjust_priv_size(descr->get_args, wrqu);
1576 /* Re-adjust reply size */
1577 request->len = extra_size + IW_EV_POINT_PK_LEN;
1579 /* Put the iwe header where it should, i.e. scrap the
1581 memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_PK_LEN);
1583 #ifdef WE_RTNETLINK_DEBUG
1584 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);
1585 #endif /* WE_RTNETLINK_DEBUG */
1588 /* Return the buffer to the caller */
1591 *p_len = request->len;
1601 /* ---------------------------------------------------------------- */
1603 * Wrapper to call a private Wireless Extension SET handler.
1605 * It's not as nice and slimline as the standard wrapper. The cause
1606 * is struct iw_priv_args, which was not really designed for the
1607 * job we are going here.
1609 * IMPORTANT : This function prevent to set and get data on the same
1610 * IOCTL and enforce the SET/GET convention. Not doing it would be
1612 * If you need to set and get data at the same time, please don't use
1613 * a iw_handler but process it in your ioctl handler (i.e. use the
1616 static inline int rtnetlink_private_set(struct net_device * dev,
1617 struct iw_event * request,
1621 const struct iw_priv_args * descr = NULL;
1623 union iwreq_data * wrqu;
1624 union iwreq_data wrqu_point;
1626 char * extra = NULL;
1628 int offset = 0; /* For sub-ioctls */
1629 struct iw_request_info info;
1633 /* Get the description of the Request */
1635 for(i = 0; i < dev->wireless_handlers->num_private_args; i++)
1636 if(cmd == dev->wireless_handlers->private_args[i].cmd) {
1637 descr = &(dev->wireless_handlers->private_args[i]);
1643 #ifdef WE_RTNETLINK_DEBUG
1644 printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
1645 ifr->ifr_name, cmd);
1646 printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
1647 dev->name, descr->name, descr->set_args, descr->get_args);
1648 #endif /* WE_RTNETLINK_DEBUG */
1650 /* Compute the size of the set arguments */
1651 /* Check for sub-ioctl handler */
1652 if(descr->name[0] == '\0')
1653 /* Reserve one int for sub-ioctl index */
1654 offset = sizeof(__u32);
1656 /* Size of set arguments */
1657 extra_size = get_priv_size(descr->set_args);
1659 /* Does it fits in wrqu ? */
1660 if((descr->set_args & IW_PRIV_SIZE_FIXED) &&
1661 (extra_size <= IFNAMSIZ)) {
1662 hdr_len = IW_EV_LCP_PK_LEN + extra_size;
1665 hdr_len = IW_EV_POINT_PK_LEN;
1668 /* Extract fixed header from request. This is properly aligned. */
1669 wrqu = (union iwreq_data *) (((char *) request) + IW_EV_LCP_PK_LEN);
1671 /* Check if wrqu is complete */
1672 if(request_len < hdr_len) {
1673 #ifdef WE_RTNETLINK_DEBUG
1675 "%s (WE.r) : Wireless request too short (%d)\n",
1676 dev->name, request_len);
1677 #endif /* WE_RTNETLINK_DEBUG */
1681 /* Prepare the call */
1685 /* Check if we have a pointer to user space data or not. */
1686 if(extra_size == 0) {
1688 /* No extra arguments. Trivial to handle */
1689 ret = handler(dev, &info, wrqu, (char *) wrqu);
1694 /* Put wrqu in the right place (skip pointer) */
1695 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1696 wrqu, IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1698 /* Does it fits within bounds ? */
1699 if(wrqu_point.data.length > (descr->set_args &
1703 /* Real length of payload */
1704 extra_len = adjust_priv_size(descr->set_args, &wrqu_point);
1706 /* Check if request is self consistent */
1707 if((request_len - hdr_len) < extra_len) {
1708 #ifdef WE_RTNETLINK_DEBUG
1709 printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
1710 dev->name, extra_size);
1711 #endif /* WE_RTNETLINK_DEBUG */
1715 #ifdef WE_RTNETLINK_DEBUG
1716 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
1717 dev->name, extra_size);
1718 #endif /* WE_RTNETLINK_DEBUG */
1720 /* Always allocate for max space. Easier, and won't last
1722 extra = kmalloc(extra_size, GFP_KERNEL);
1726 /* Copy extra in aligned buffer */
1727 memcpy(extra, ((char *) request) + hdr_len, extra_len);
1729 /* Call the handler */
1730 ret = handler(dev, &info, &wrqu_point, extra);
1732 /* Cleanup - I told you it wasn't that long ;-) */
1736 /* Call commit handler if needed and defined */
1737 if(ret == -EIWCOMMIT)
1738 ret = call_commit_handler(dev);
1743 /* ---------------------------------------------------------------- */
1745 * Main RtNetlink dispatcher. Called from the main networking code
1746 * (do_getlink() in net/core/rtnetlink.c).
1747 * Check the type of Request and call the appropriate wrapper...
1749 int wireless_rtnetlink_get(struct net_device * dev,
1755 struct iw_event * request = (struct iw_event *) data;
1759 if(len < IW_EV_LCP_PK_LEN) {
1760 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
1765 /* ReCheck length (len may have padding) */
1766 if(request->len > len) {
1767 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1768 dev->name, request->len, len);
1772 /* Only accept GET requests in here */
1773 if(!IW_IS_GET(request->cmd))
1776 /* If command is `get the encoding parameters', check if
1777 * the user has the right to do it */
1778 if (request->cmd == SIOCGIWENCODE ||
1779 request->cmd == SIOCGIWENCODEEXT) {
1780 if (!capable(CAP_NET_ADMIN))
1785 if(request->cmd == SIOCGIWSTATS)
1786 /* Get Wireless Stats */
1787 return rtnetlink_standard_get(dev,
1790 &iw_handler_get_iwstats,
1792 if(request->cmd == SIOCGIWPRIV) {
1793 /* Check if we have some wireless handlers defined */
1794 if(dev->wireless_handlers == NULL)
1796 /* Get Wireless Stats */
1797 return rtnetlink_standard_get(dev,
1800 &iw_handler_get_private,
1805 if (!netif_device_present(dev))
1808 /* Try to find the handler */
1809 handler = get_handler(dev, request->cmd);
1810 if(handler != NULL) {
1811 /* Standard and private are not the same */
1812 if(request->cmd < SIOCIWFIRSTPRIV)
1813 return rtnetlink_standard_get(dev,
1819 return rtnetlink_private_get(dev,
1829 /* ---------------------------------------------------------------- */
1831 * Main RtNetlink dispatcher. Called from the main networking code
1832 * (do_setlink() in net/core/rtnetlink.c).
1833 * Check the type of Request and call the appropriate wrapper...
1835 int wireless_rtnetlink_set(struct net_device * dev,
1839 struct iw_event * request = (struct iw_event *) data;
1843 if(len < IW_EV_LCP_PK_LEN) {
1844 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
1849 /* ReCheck length (len may have padding) */
1850 if(request->len > len) {
1851 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1852 dev->name, request->len, len);
1856 /* Only accept SET requests in here */
1857 if(!IW_IS_SET(request->cmd))
1861 if (!netif_device_present(dev))
1864 /* New driver API : try to find the handler */
1865 handler = get_handler(dev, request->cmd);
1866 if(handler != NULL) {
1867 /* Standard and private are not the same */
1868 if(request->cmd < SIOCIWFIRSTPRIV)
1869 return rtnetlink_standard_set(dev,
1874 return rtnetlink_private_set(dev,
1882 #endif /* CONFIG_NET_WIRELESS_RTNETLINK */
1885 /************************* EVENT PROCESSING *************************/
1887 * Process events generated by the wireless layer or the driver.
1888 * Most often, the event will be propagated through rtnetlink
1891 #ifdef WE_EVENT_RTNETLINK
1892 /* ---------------------------------------------------------------- */
1897 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1898 * the locking issue in here and implementing this code !
1900 * The issue : wireless_send_event() is often called in interrupt context,
1901 * while the Netlink layer can never be called in interrupt context.
1902 * The fully formed RtNetlink events are queued, and then a tasklet is run
1903 * to feed those to Netlink.
1904 * The skb_queue is interrupt safe, and its lock is not held while calling
1905 * Netlink, so there is no possibility of dealock.
1909 static struct sk_buff_head wireless_nlevent_queue;
1911 static int __init wireless_nlevent_init(void)
1913 skb_queue_head_init(&wireless_nlevent_queue);
1917 subsys_initcall(wireless_nlevent_init);
1919 static void wireless_nlevent_process(unsigned long data)
1921 struct sk_buff *skb;
1923 while ((skb = skb_dequeue(&wireless_nlevent_queue)))
1924 rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
1927 static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0);
1929 /* ---------------------------------------------------------------- */
1931 * Fill a rtnetlink message with our event data.
1932 * Note that we propage only the specified event and don't dump the
1933 * current wireless config. Dumping the wireless config is far too
1934 * expensive (for each parameter, the driver need to query the hardware).
1936 static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
1937 struct net_device * dev,
1942 struct ifinfomsg *r;
1943 struct nlmsghdr *nlh;
1944 unsigned char *b = skb->tail;
1946 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
1947 r = NLMSG_DATA(nlh);
1948 r->ifi_family = AF_UNSPEC;
1950 r->ifi_type = dev->type;
1951 r->ifi_index = dev->ifindex;
1952 r->ifi_flags = dev_get_flags(dev);
1953 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1955 /* Add the wireless events in the netlink packet */
1956 RTA_PUT(skb, IFLA_WIRELESS, event_len, event);
1958 nlh->nlmsg_len = skb->tail - b;
1963 skb_trim(skb, b - skb->data);
1967 /* ---------------------------------------------------------------- */
1969 * Create and broadcast and send it on the standard rtnetlink socket
1970 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1971 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1972 * within a RTM_NEWLINK event.
1974 static inline void rtmsg_iwinfo(struct net_device * dev,
1978 struct sk_buff *skb;
1979 int size = NLMSG_GOODSIZE;
1981 skb = alloc_skb(size, GFP_ATOMIC);
1985 if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
1986 event, event_len) < 0) {
1990 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
1991 skb_queue_tail(&wireless_nlevent_queue, skb);
1992 tasklet_schedule(&wireless_nlevent_tasklet);
1995 #endif /* WE_EVENT_RTNETLINK */
1997 /* ---------------------------------------------------------------- */
1999 * Main event dispatcher. Called from other parts and drivers.
2000 * Send the event on the appropriate channels.
2001 * May be called from interrupt context.
2003 void wireless_send_event(struct net_device * dev,
2005 union iwreq_data * wrqu,
2008 const struct iw_ioctl_description * descr = NULL;
2010 struct iw_event *event; /* Mallocated whole event */
2011 int event_len; /* Its size */
2012 int hdr_len; /* Size of the event header */
2013 int wrqu_off = 0; /* Offset in wrqu */
2014 /* Don't "optimise" the following variable, it will crash */
2015 unsigned cmd_index; /* *MUST* be unsigned */
2017 /* Get the description of the Event */
2018 if(cmd <= SIOCIWLAST) {
2019 cmd_index = cmd - SIOCIWFIRST;
2020 if(cmd_index < standard_ioctl_num)
2021 descr = &(standard_ioctl[cmd_index]);
2023 cmd_index = cmd - IWEVFIRST;
2024 if(cmd_index < standard_event_num)
2025 descr = &(standard_event[cmd_index]);
2027 /* Don't accept unknown events */
2029 /* Note : we don't return an error to the driver, because
2030 * the driver would not know what to do about it. It can't
2031 * return an error to the user, because the event is not
2032 * initiated by a user request.
2033 * The best the driver could do is to log an error message.
2034 * We will do it ourselves instead...
2036 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
2040 #ifdef WE_EVENT_DEBUG
2041 printk(KERN_DEBUG "%s (WE) : Got event 0x%04X\n",
2043 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);
2044 #endif /* WE_EVENT_DEBUG */
2046 /* Check extra parameters and set extra_len */
2047 if(descr->header_type == IW_HEADER_TYPE_POINT) {
2048 /* Check if number of token fits within bounds */
2049 if(wrqu->data.length > descr->max_tokens) {
2050 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
2053 if(wrqu->data.length < descr->min_tokens) {
2054 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
2057 /* Calculate extra_len - extra is NULL for restricted events */
2059 extra_len = wrqu->data.length * descr->token_size;
2060 /* Always at an offset in wrqu */
2061 wrqu_off = IW_EV_POINT_OFF;
2062 #ifdef WE_EVENT_DEBUG
2063 printk(KERN_DEBUG "%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev->name, cmd, wrqu->data.length, extra_len);
2064 #endif /* WE_EVENT_DEBUG */
2067 /* Total length of the event */
2068 hdr_len = event_type_size[descr->header_type];
2069 event_len = hdr_len + extra_len;
2071 #ifdef WE_EVENT_DEBUG
2072 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);
2073 #endif /* WE_EVENT_DEBUG */
2075 /* Create temporary buffer to hold the event */
2076 event = kmalloc(event_len, GFP_ATOMIC);
2081 event->len = event_len;
2083 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
2085 memcpy(((char *) event) + hdr_len, extra, extra_len);
2087 #ifdef WE_EVENT_RTNETLINK
2088 /* Send via the RtNetlink event channel */
2089 rtmsg_iwinfo(dev, (char *) event, event_len);
2090 #endif /* WE_EVENT_RTNETLINK */
2095 return; /* Always success, I guess ;-) */
2098 /********************** ENHANCED IWSPY SUPPORT **********************/
2100 * In the old days, the driver was handling spy support all by itself.
2101 * Now, the driver can delegate this task to Wireless Extensions.
2102 * It needs to use those standard spy iw_handler in struct iw_handler_def,
2103 * push data to us via wireless_spy_update() and include struct iw_spy_data
2104 * in its private part (and export it in net_device->wireless_data->spy_data).
2105 * One of the main advantage of centralising spy support here is that
2106 * it becomes much easier to improve and extend it without having to touch
2107 * the drivers. One example is the addition of the Spy-Threshold events.
2110 /* ---------------------------------------------------------------- */
2112 * Return the pointer to the spy data in the driver.
2113 * Because this is called on the Rx path via wireless_spy_update(),
2114 * we want it to be efficient...
2116 static inline struct iw_spy_data * get_spydata(struct net_device *dev)
2118 /* This is the new way */
2119 if(dev->wireless_data)
2120 return(dev->wireless_data->spy_data);
2124 /*------------------------------------------------------------------*/
2126 * Standard Wireless Handler : set Spy List
2128 int iw_handler_set_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;
2136 /* Make sure driver is not buggy or using the old API */
2140 /* Disable spy collection while we copy the addresses.
2141 * While we copy addresses, any call to wireless_spy_update()
2142 * will NOP. This is OK, as anyway the addresses are changing. */
2143 spydata->spy_number = 0;
2145 /* We want to operate without locking, because wireless_spy_update()
2146 * most likely will happen in the interrupt handler, and therefore
2147 * have its own locking constraints and needs performance.
2148 * The rtnl_lock() make sure we don't race with the other iw_handlers.
2149 * This make sure wireless_spy_update() "see" that the spy list
2150 * is temporarily disabled. */
2153 /* Are there are addresses to copy? */
2154 if(wrqu->data.length > 0) {
2157 /* Copy addresses */
2158 for(i = 0; i < wrqu->data.length; i++)
2159 memcpy(spydata->spy_address[i], address[i].sa_data,
2162 memset(spydata->spy_stat, 0,
2163 sizeof(struct iw_quality) * IW_MAX_SPY);
2166 printk(KERN_DEBUG "iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev->wireless_data, spydata, wrqu->data.length);
2167 for (i = 0; i < wrqu->data.length; i++)
2169 "%02X:%02X:%02X:%02X:%02X:%02X \n",
2170 spydata->spy_address[i][0],
2171 spydata->spy_address[i][1],
2172 spydata->spy_address[i][2],
2173 spydata->spy_address[i][3],
2174 spydata->spy_address[i][4],
2175 spydata->spy_address[i][5]);
2176 #endif /* WE_SPY_DEBUG */
2179 /* Make sure above is updated before re-enabling */
2182 /* Enable addresses */
2183 spydata->spy_number = wrqu->data.length;
2188 /*------------------------------------------------------------------*/
2190 * Standard Wireless Handler : get Spy List
2192 int iw_handler_get_spy(struct net_device * dev,
2193 struct iw_request_info * info,
2194 union iwreq_data * wrqu,
2197 struct iw_spy_data * spydata = get_spydata(dev);
2198 struct sockaddr * address = (struct sockaddr *) extra;
2201 /* Make sure driver is not buggy or using the old API */
2205 wrqu->data.length = spydata->spy_number;
2207 /* Copy addresses. */
2208 for(i = 0; i < spydata->spy_number; i++) {
2209 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
2210 address[i].sa_family = AF_UNIX;
2212 /* Copy stats to the user buffer (just after). */
2213 if(spydata->spy_number > 0)
2214 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
2216 sizeof(struct iw_quality) * spydata->spy_number);
2217 /* Reset updated flags. */
2218 for(i = 0; i < spydata->spy_number; i++)
2219 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
2223 /*------------------------------------------------------------------*/
2225 * Standard Wireless Handler : set spy threshold
2227 int iw_handler_set_thrspy(struct net_device * dev,
2228 struct iw_request_info *info,
2229 union iwreq_data * wrqu,
2232 struct iw_spy_data * spydata = get_spydata(dev);
2233 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
2235 /* Make sure driver is not buggy or using the old API */
2240 memcpy(&(spydata->spy_thr_low), &(threshold->low),
2241 2 * sizeof(struct iw_quality));
2244 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
2247 printk(KERN_DEBUG "iw_handler_set_thrspy() : low %d ; high %d\n", spydata->spy_thr_low.level, spydata->spy_thr_high.level);
2248 #endif /* WE_SPY_DEBUG */
2253 /*------------------------------------------------------------------*/
2255 * Standard Wireless Handler : get spy threshold
2257 int iw_handler_get_thrspy(struct net_device * dev,
2258 struct iw_request_info *info,
2259 union iwreq_data * wrqu,
2262 struct iw_spy_data * spydata = get_spydata(dev);
2263 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
2265 /* Make sure driver is not buggy or using the old API */
2270 memcpy(&(threshold->low), &(spydata->spy_thr_low),
2271 2 * sizeof(struct iw_quality));
2276 /*------------------------------------------------------------------*/
2278 * Prepare and send a Spy Threshold event
2280 static void iw_send_thrspy_event(struct net_device * dev,
2281 struct iw_spy_data * spydata,
2282 unsigned char * address,
2283 struct iw_quality * wstats)
2285 union iwreq_data wrqu;
2286 struct iw_thrspy threshold;
2289 wrqu.data.length = 1;
2290 wrqu.data.flags = 0;
2292 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
2293 threshold.addr.sa_family = ARPHRD_ETHER;
2295 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
2296 /* Copy also thresholds */
2297 memcpy(&(threshold.low), &(spydata->spy_thr_low),
2298 2 * sizeof(struct iw_quality));
2301 printk(KERN_DEBUG "iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
2302 threshold.addr.sa_data[0],
2303 threshold.addr.sa_data[1],
2304 threshold.addr.sa_data[2],
2305 threshold.addr.sa_data[3],
2306 threshold.addr.sa_data[4],
2307 threshold.addr.sa_data[5], threshold.qual.level);
2308 #endif /* WE_SPY_DEBUG */
2310 /* Send event to user space */
2311 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
2314 /* ---------------------------------------------------------------- */
2316 * Call for the driver to update the spy data.
2317 * For now, the spy data is a simple array. As the size of the array is
2318 * small, this is good enough. If we wanted to support larger number of
2319 * spy addresses, we should use something more efficient...
2321 void wireless_spy_update(struct net_device * dev,
2322 unsigned char * address,
2323 struct iw_quality * wstats)
2325 struct iw_spy_data * spydata = get_spydata(dev);
2329 /* Make sure driver is not buggy or using the old API */
2334 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]);
2335 #endif /* WE_SPY_DEBUG */
2337 /* Update all records that match */
2338 for(i = 0; i < spydata->spy_number; i++)
2339 if(!compare_ether_addr(address, spydata->spy_address[i])) {
2340 memcpy(&(spydata->spy_stat[i]), wstats,
2341 sizeof(struct iw_quality));
2345 /* Generate an event if we cross the spy threshold.
2346 * To avoid event storms, we have a simple hysteresis : we generate
2347 * event only when we go under the low threshold or above the
2348 * high threshold. */
2350 if(spydata->spy_thr_under[match]) {
2351 if(wstats->level > spydata->spy_thr_high.level) {
2352 spydata->spy_thr_under[match] = 0;
2353 iw_send_thrspy_event(dev, spydata,
2357 if(wstats->level < spydata->spy_thr_low.level) {
2358 spydata->spy_thr_under[match] = 1;
2359 iw_send_thrspy_event(dev, spydata,
2366 EXPORT_SYMBOL(iw_handler_get_spy);
2367 EXPORT_SYMBOL(iw_handler_get_thrspy);
2368 EXPORT_SYMBOL(iw_handler_set_spy);
2369 EXPORT_SYMBOL(iw_handler_set_thrspy);
2370 EXPORT_SYMBOL(wireless_send_event);
2371 EXPORT_SYMBOL(wireless_spy_update);