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 = ARRAY_SIZE(standard_ioctl);
355 * Meta-data about all the additional standard Wireless Extension events
358 static const struct iw_ioctl_description standard_event[] = {
359 [IWEVTXDROP - IWEVFIRST] = {
360 .header_type = IW_HEADER_TYPE_ADDR,
362 [IWEVQUAL - IWEVFIRST] = {
363 .header_type = IW_HEADER_TYPE_QUAL,
365 [IWEVCUSTOM - IWEVFIRST] = {
366 .header_type = IW_HEADER_TYPE_POINT,
368 .max_tokens = IW_CUSTOM_MAX,
370 [IWEVREGISTERED - IWEVFIRST] = {
371 .header_type = IW_HEADER_TYPE_ADDR,
373 [IWEVEXPIRED - IWEVFIRST] = {
374 .header_type = IW_HEADER_TYPE_ADDR,
376 [IWEVGENIE - IWEVFIRST] = {
377 .header_type = IW_HEADER_TYPE_POINT,
379 .max_tokens = IW_GENERIC_IE_MAX,
381 [IWEVMICHAELMICFAILURE - IWEVFIRST] = {
382 .header_type = IW_HEADER_TYPE_POINT,
384 .max_tokens = sizeof(struct iw_michaelmicfailure),
386 [IWEVASSOCREQIE - IWEVFIRST] = {
387 .header_type = IW_HEADER_TYPE_POINT,
389 .max_tokens = IW_GENERIC_IE_MAX,
391 [IWEVASSOCRESPIE - IWEVFIRST] = {
392 .header_type = IW_HEADER_TYPE_POINT,
394 .max_tokens = IW_GENERIC_IE_MAX,
396 [IWEVPMKIDCAND - IWEVFIRST] = {
397 .header_type = IW_HEADER_TYPE_POINT,
399 .max_tokens = sizeof(struct iw_pmkid_cand),
402 static const unsigned standard_event_num = ARRAY_SIZE(standard_event);
404 /* Size (in bytes) of the various private data types */
405 static const char iw_priv_type_size[] = {
406 0, /* IW_PRIV_TYPE_NONE */
407 1, /* IW_PRIV_TYPE_BYTE */
408 1, /* IW_PRIV_TYPE_CHAR */
410 sizeof(__u32), /* IW_PRIV_TYPE_INT */
411 sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */
412 sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */
416 /* Size (in bytes) of various events */
417 static const int event_type_size[] = {
418 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
420 IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
422 IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
423 IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
424 IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
426 IW_EV_POINT_LEN, /* Without variable payload */
427 IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
428 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
431 /* Size (in bytes) of various events, as packed */
432 static const int event_type_pk_size[] = {
433 IW_EV_LCP_PK_LEN, /* IW_HEADER_TYPE_NULL */
435 IW_EV_CHAR_PK_LEN, /* IW_HEADER_TYPE_CHAR */
437 IW_EV_UINT_PK_LEN, /* IW_HEADER_TYPE_UINT */
438 IW_EV_FREQ_PK_LEN, /* IW_HEADER_TYPE_FREQ */
439 IW_EV_ADDR_PK_LEN, /* IW_HEADER_TYPE_ADDR */
441 IW_EV_POINT_PK_LEN, /* Without variable payload */
442 IW_EV_PARAM_PK_LEN, /* IW_HEADER_TYPE_PARAM */
443 IW_EV_QUAL_PK_LEN, /* IW_HEADER_TYPE_QUAL */
446 /************************ COMMON SUBROUTINES ************************/
448 * Stuff that may be used in various place or doesn't fit in one
449 * of the section below.
452 /* ---------------------------------------------------------------- */
454 * Return the driver handler associated with a specific Wireless Extension.
455 * Called from various place, so make sure it remains efficient.
457 static inline iw_handler get_handler(struct net_device *dev,
460 /* Don't "optimise" the following variable, it will crash */
461 unsigned int index; /* *MUST* be unsigned */
463 /* Check if we have some wireless handlers defined */
464 if (dev->wireless_handlers == NULL)
467 /* Try as a standard command */
468 index = cmd - SIOCIWFIRST;
469 if (index < dev->wireless_handlers->num_standard)
470 return dev->wireless_handlers->standard[index];
472 /* Try as a private command */
473 index = cmd - SIOCIWFIRSTPRIV;
474 if (index < dev->wireless_handlers->num_private)
475 return dev->wireless_handlers->private[index];
481 /* ---------------------------------------------------------------- */
483 * Get statistics out of the driver
485 static inline struct iw_statistics *get_wireless_stats(struct net_device *dev)
488 if ((dev->wireless_handlers != NULL) &&
489 (dev->wireless_handlers->get_wireless_stats != NULL))
490 return dev->wireless_handlers->get_wireless_stats(dev);
493 return (struct iw_statistics *) NULL;
496 /* ---------------------------------------------------------------- */
498 * Call the commit handler in the driver
499 * (if exist and if conditions are right)
501 * Note : our current commit strategy is currently pretty dumb,
502 * but we will be able to improve on that...
503 * The goal is to try to agreagate as many changes as possible
504 * before doing the commit. Drivers that will define a commit handler
505 * are usually those that need a reset after changing parameters, so
506 * we want to minimise the number of reset.
507 * A cool idea is to use a timer : at each "set" command, we re-set the
508 * timer, when the timer eventually fires, we call the driver.
509 * Hopefully, more on that later.
511 * Also, I'm waiting to see how many people will complain about the
512 * netif_running(dev) test. I'm open on that one...
513 * Hopefully, the driver will remember to do a commit in "open()" ;-)
515 static inline int call_commit_handler(struct net_device * dev)
517 if ((netif_running(dev)) &&
518 (dev->wireless_handlers->standard[0] != NULL)) {
519 /* Call the commit handler on the driver */
520 return dev->wireless_handlers->standard[0](dev, NULL,
523 return 0; /* Command completed successfully */
526 /* ---------------------------------------------------------------- */
528 * Calculate size of private arguments
530 static inline int get_priv_size(__u16 args)
532 int num = args & IW_PRIV_SIZE_MASK;
533 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
535 return num * iw_priv_type_size[type];
538 /* ---------------------------------------------------------------- */
540 * Re-calculate the size of private arguments
542 static inline int adjust_priv_size(__u16 args,
543 union iwreq_data * wrqu)
545 int num = wrqu->data.length;
546 int max = args & IW_PRIV_SIZE_MASK;
547 int type = (args & IW_PRIV_TYPE_MASK) >> 12;
549 /* Make sure the driver doesn't goof up */
553 return num * iw_priv_type_size[type];
556 /* ---------------------------------------------------------------- */
558 * Standard Wireless Handler : get wireless stats
559 * Allow programatic access to /proc/net/wireless even if /proc
560 * doesn't exist... Also more efficient...
562 static int iw_handler_get_iwstats(struct net_device * dev,
563 struct iw_request_info * info,
564 union iwreq_data * wrqu,
567 /* Get stats from the driver */
568 struct iw_statistics *stats;
570 stats = get_wireless_stats(dev);
571 if (stats != (struct iw_statistics *) NULL) {
573 /* Copy statistics to extra */
574 memcpy(extra, stats, sizeof(struct iw_statistics));
575 wrqu->data.length = sizeof(struct iw_statistics);
577 /* Check if we need to clear the updated flag */
578 if (wrqu->data.flags != 0)
579 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
585 /* ---------------------------------------------------------------- */
587 * Standard Wireless Handler : get iwpriv definitions
588 * Export the driver private handler definition
589 * They will be picked up by tools like iwpriv...
591 static int iw_handler_get_private(struct net_device * dev,
592 struct iw_request_info * info,
593 union iwreq_data * wrqu,
596 /* Check if the driver has something to export */
597 if ((dev->wireless_handlers->num_private_args == 0) ||
598 (dev->wireless_handlers->private_args == NULL))
601 /* Check if there is enough buffer up there */
602 if (wrqu->data.length < dev->wireless_handlers->num_private_args) {
603 /* User space can't know in advance how large the buffer
604 * needs to be. Give it a hint, so that we can support
605 * any size buffer we want somewhat efficiently... */
606 wrqu->data.length = dev->wireless_handlers->num_private_args;
610 /* Set the number of available ioctls. */
611 wrqu->data.length = dev->wireless_handlers->num_private_args;
613 /* Copy structure to the user buffer. */
614 memcpy(extra, dev->wireless_handlers->private_args,
615 sizeof(struct iw_priv_args) * wrqu->data.length);
621 /******************** /proc/net/wireless SUPPORT ********************/
623 * The /proc/net/wireless file is a human readable user-space interface
624 * exporting various wireless specific statistics from the wireless devices.
625 * This is the most popular part of the Wireless Extensions ;-)
627 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
628 * The content of the file is basically the content of "struct iw_statistics".
631 #ifdef CONFIG_PROC_FS
633 /* ---------------------------------------------------------------- */
635 * Print one entry (line) of /proc/net/wireless
637 static __inline__ void wireless_seq_printf_stats(struct seq_file *seq,
638 struct net_device *dev)
640 /* Get stats from the driver */
641 struct iw_statistics *stats = get_wireless_stats(dev);
644 seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
646 dev->name, stats->status, stats->qual.qual,
647 stats->qual.updated & IW_QUAL_QUAL_UPDATED
649 ((__s32) stats->qual.level) -
650 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
651 stats->qual.updated & IW_QUAL_LEVEL_UPDATED
653 ((__s32) stats->qual.noise) -
654 ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0),
655 stats->qual.updated & IW_QUAL_NOISE_UPDATED
657 stats->discard.nwid, stats->discard.code,
658 stats->discard.fragment, stats->discard.retries,
659 stats->discard.misc, stats->miss.beacon);
660 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
664 /* ---------------------------------------------------------------- */
666 * Print info for /proc/net/wireless (print all entries)
668 static int wireless_seq_show(struct seq_file *seq, void *v)
670 if (v == SEQ_START_TOKEN)
671 seq_printf(seq, "Inter-| sta-| Quality | Discarded "
672 "packets | Missed | WE\n"
673 " face | tus | link level noise | nwid "
674 "crypt frag retry misc | beacon | %d\n",
677 wireless_seq_printf_stats(seq, v);
681 static const struct seq_operations wireless_seq_ops = {
682 .start = dev_seq_start,
683 .next = dev_seq_next,
684 .stop = dev_seq_stop,
685 .show = wireless_seq_show,
688 static int wireless_seq_open(struct inode *inode, struct file *file)
690 return seq_open(file, &wireless_seq_ops);
693 static const struct file_operations wireless_seq_fops = {
694 .owner = THIS_MODULE,
695 .open = wireless_seq_open,
698 .release = seq_release,
701 int __init wireless_proc_init(void)
703 /* Create /proc/net/wireless entry */
704 if (!proc_net_fops_create("wireless", S_IRUGO, &wireless_seq_fops))
709 #endif /* CONFIG_PROC_FS */
711 /************************** IOCTL SUPPORT **************************/
713 * The original user space API to configure all those Wireless Extensions
715 * In there, we check if we need to call the new driver API (iw_handler)
716 * or just call the driver ioctl handler.
719 /* ---------------------------------------------------------------- */
721 * Wrapper to call a standard Wireless Extension handler.
722 * We do various checks and also take care of moving data between
723 * user space and kernel space.
725 static int ioctl_standard_call(struct net_device * dev,
730 struct iwreq * iwr = (struct iwreq *) ifr;
731 const struct iw_ioctl_description * descr;
732 struct iw_request_info info;
735 /* Get the description of the IOCTL */
736 if ((cmd - SIOCIWFIRST) >= standard_ioctl_num)
738 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
740 #ifdef WE_IOCTL_DEBUG
741 printk(KERN_DEBUG "%s (WE) : Found standard handler for 0x%04X\n",
743 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);
744 #endif /* WE_IOCTL_DEBUG */
746 /* Prepare the call */
750 /* Check if we have a pointer to user space data or not */
751 if (descr->header_type != IW_HEADER_TYPE_POINT) {
753 /* No extra arguments. Trivial to handle */
754 ret = handler(dev, &info, &(iwr->u), NULL);
757 /* Generate an event to notify listeners of the change */
758 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
759 ((ret == 0) || (ret == -EIWCOMMIT)))
760 wireless_send_event(dev, cmd, &(iwr->u), NULL);
761 #endif /* WE_SET_EVENT */
767 int essid_compat = 0;
769 /* Calculate space needed by arguments. Always allocate
770 * for max space. Easier, and won't last long... */
771 extra_size = descr->max_tokens * descr->token_size;
773 /* Check need for ESSID compatibility for WE < 21 */
779 if (iwr->u.data.length == descr->max_tokens + 1)
781 else if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
782 char essid[IW_ESSID_MAX_SIZE + 1];
784 err = copy_from_user(essid, iwr->u.data.pointer,
790 if (essid[iwr->u.data.length - 1] == '\0')
798 iwr->u.data.length -= essid_compat;
800 /* Check what user space is giving us */
801 if (IW_IS_SET(cmd)) {
802 /* Check NULL pointer */
803 if ((iwr->u.data.pointer == NULL) &&
804 (iwr->u.data.length != 0))
806 /* Check if number of token fits within bounds */
807 if (iwr->u.data.length > descr->max_tokens)
809 if (iwr->u.data.length < descr->min_tokens)
812 /* Check NULL pointer */
813 if (iwr->u.data.pointer == NULL)
815 /* Save user space buffer size for checking */
816 user_length = iwr->u.data.length;
818 /* Don't check if user_length > max to allow forward
819 * compatibility. The test user_length < min is
820 * implied by the test at the end. */
822 /* Support for very large requests */
823 if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
824 (user_length > descr->max_tokens)) {
825 /* Allow userspace to GET more than max so
826 * we can support any size GET requests.
827 * There is still a limit : -ENOMEM. */
828 extra_size = user_length * descr->token_size;
829 /* Note : user_length is originally a __u16,
830 * and token_size is controlled by us,
831 * so extra_size won't get negative and
832 * won't overflow... */
836 #ifdef WE_IOCTL_DEBUG
837 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
838 dev->name, extra_size);
839 #endif /* WE_IOCTL_DEBUG */
841 /* Create the kernel buffer */
842 /* kzalloc ensures NULL-termination for essid_compat */
843 extra = kzalloc(extra_size, GFP_KERNEL);
848 /* If it is a SET, get all the extra data in here */
849 if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
850 err = copy_from_user(extra, iwr->u.data.pointer,
857 #ifdef WE_IOCTL_DEBUG
858 printk(KERN_DEBUG "%s (WE) : Got %d bytes\n",
860 iwr->u.data.length * descr->token_size);
861 #endif /* WE_IOCTL_DEBUG */
864 /* Call the handler */
865 ret = handler(dev, &info, &(iwr->u), extra);
867 iwr->u.data.length += essid_compat;
869 /* If we have something to return to the user */
870 if (!ret && IW_IS_GET(cmd)) {
871 /* Check if there is enough buffer up there */
872 if (user_length < iwr->u.data.length) {
877 err = copy_to_user(iwr->u.data.pointer, extra,
882 #ifdef WE_IOCTL_DEBUG
883 printk(KERN_DEBUG "%s (WE) : Wrote %d bytes\n",
885 iwr->u.data.length * descr->token_size);
886 #endif /* WE_IOCTL_DEBUG */
890 /* Generate an event to notify listeners of the change */
891 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
892 ((ret == 0) || (ret == -EIWCOMMIT))) {
893 if (descr->flags & IW_DESCR_FLAG_RESTRICT)
894 /* If the event is restricted, don't
895 * export the payload */
896 wireless_send_event(dev, cmd, &(iwr->u), NULL);
898 wireless_send_event(dev, cmd, &(iwr->u),
901 #endif /* WE_SET_EVENT */
903 /* Cleanup - I told you it wasn't that long ;-) */
907 /* Call commit handler if needed and defined */
908 if (ret == -EIWCOMMIT)
909 ret = call_commit_handler(dev);
911 /* Here, we will generate the appropriate event if needed */
916 /* ---------------------------------------------------------------- */
918 * Wrapper to call a private Wireless Extension handler.
919 * We do various checks and also take care of moving data between
920 * user space and kernel space.
921 * It's not as nice and slimline as the standard wrapper. The cause
922 * is struct iw_priv_args, which was not really designed for the
923 * job we are going here.
925 * IMPORTANT : This function prevent to set and get data on the same
926 * IOCTL and enforce the SET/GET convention. Not doing it would be
928 * If you need to set and get data at the same time, please don't use
929 * a iw_handler but process it in your ioctl handler (i.e. use the
932 static inline int ioctl_private_call(struct net_device * dev,
937 struct iwreq * iwr = (struct iwreq *) ifr;
938 const struct iw_priv_args * descr = NULL;
939 struct iw_request_info info;
944 /* Get the description of the IOCTL */
945 for (i = 0; i < dev->wireless_handlers->num_private_args; i++)
946 if (cmd == dev->wireless_handlers->private_args[i].cmd) {
947 descr = &(dev->wireless_handlers->private_args[i]);
951 #ifdef WE_IOCTL_DEBUG
952 printk(KERN_DEBUG "%s (WE) : Found private handler for 0x%04X\n",
955 printk(KERN_DEBUG "%s (WE) : Name %s, set %X, get %X\n",
956 dev->name, descr->name,
957 descr->set_args, descr->get_args);
959 #endif /* WE_IOCTL_DEBUG */
961 /* Compute the size of the set/get arguments */
963 if (IW_IS_SET(cmd)) {
964 int offset = 0; /* For sub-ioctls */
965 /* Check for sub-ioctl handler */
966 if (descr->name[0] == '\0')
967 /* Reserve one int for sub-ioctl index */
968 offset = sizeof(__u32);
970 /* Size of set arguments */
971 extra_size = get_priv_size(descr->set_args);
973 /* Does it fits in iwr ? */
974 if ((descr->set_args & IW_PRIV_SIZE_FIXED) &&
975 ((extra_size + offset) <= IFNAMSIZ))
978 /* Size of get arguments */
979 extra_size = get_priv_size(descr->get_args);
981 /* Does it fits in iwr ? */
982 if ((descr->get_args & IW_PRIV_SIZE_FIXED) &&
983 (extra_size <= IFNAMSIZ))
988 /* Prepare the call */
992 /* Check if we have a pointer to user space data or not. */
993 if (extra_size == 0) {
994 /* No extra arguments. Trivial to handle */
995 ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u));
1000 /* Check what user space is giving us */
1001 if (IW_IS_SET(cmd)) {
1002 /* Check NULL pointer */
1003 if ((iwr->u.data.pointer == NULL) &&
1004 (iwr->u.data.length != 0))
1007 /* Does it fits within bounds ? */
1008 if (iwr->u.data.length > (descr->set_args &
1012 /* Check NULL pointer */
1013 if (iwr->u.data.pointer == NULL)
1017 #ifdef WE_IOCTL_DEBUG
1018 printk(KERN_DEBUG "%s (WE) : Malloc %d bytes\n",
1019 dev->name, extra_size);
1020 #endif /* WE_IOCTL_DEBUG */
1022 /* Always allocate for max space. Easier, and won't last
1024 extra = kmalloc(extra_size, GFP_KERNEL);
1025 if (extra == NULL) {
1029 /* If it is a SET, get all the extra data in here */
1030 if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) {
1031 err = copy_from_user(extra, iwr->u.data.pointer,
1037 #ifdef WE_IOCTL_DEBUG
1038 printk(KERN_DEBUG "%s (WE) : Got %d elem\n",
1039 dev->name, iwr->u.data.length);
1040 #endif /* WE_IOCTL_DEBUG */
1043 /* Call the handler */
1044 ret = handler(dev, &info, &(iwr->u), extra);
1046 /* If we have something to return to the user */
1047 if (!ret && IW_IS_GET(cmd)) {
1049 /* Adjust for the actual length if it's variable,
1050 * avoid leaking kernel bits outside. */
1051 if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) {
1052 extra_size = adjust_priv_size(descr->get_args,
1056 err = copy_to_user(iwr->u.data.pointer, extra,
1060 #ifdef WE_IOCTL_DEBUG
1061 printk(KERN_DEBUG "%s (WE) : Wrote %d elem\n",
1062 dev->name, iwr->u.data.length);
1063 #endif /* WE_IOCTL_DEBUG */
1066 /* Cleanup - I told you it wasn't that long ;-) */
1071 /* Call commit handler if needed and defined */
1072 if (ret == -EIWCOMMIT)
1073 ret = call_commit_handler(dev);
1078 /* ---------------------------------------------------------------- */
1080 * Main IOCTl dispatcher. Called from the main networking code
1081 * (dev_ioctl() in net/core/dev.c).
1082 * Check the type of IOCTL and call the appropriate wrapper...
1084 int wireless_process_ioctl(struct ifreq *ifr, unsigned int cmd)
1086 struct net_device *dev;
1089 /* Permissions are already checked in dev_ioctl() before calling us.
1090 * The copy_to/from_user() of ifr is also dealt with in there */
1092 /* Make sure the device exist */
1093 if ((dev = __dev_get_by_name(ifr->ifr_name)) == NULL)
1096 /* A bunch of special cases, then the generic case...
1097 * Note that 'cmd' is already filtered in dev_ioctl() with
1098 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1101 /* Get Wireless Stats */
1102 return ioctl_standard_call(dev,
1105 &iw_handler_get_iwstats);
1108 /* Check if we have some wireless handlers defined */
1109 if (dev->wireless_handlers != NULL) {
1110 /* We export to user space the definition of
1111 * the private handler ourselves */
1112 return ioctl_standard_call(dev,
1115 &iw_handler_get_private);
1117 // ## Fall-through for old API ##
1121 if (!netif_device_present(dev))
1123 /* New driver API : try to find the handler */
1124 handler = get_handler(dev, cmd);
1125 if (handler != NULL) {
1126 /* Standard and private are not the same */
1127 if (cmd < SIOCIWFIRSTPRIV)
1128 return ioctl_standard_call(dev,
1133 return ioctl_private_call(dev,
1138 /* Old driver API : call driver ioctl handler */
1139 if (dev->do_ioctl) {
1140 return dev->do_ioctl(dev, ifr, cmd);
1148 /********************** RTNETLINK REQUEST API **********************/
1150 * The alternate user space API to configure all those Wireless Extensions
1151 * is through RtNetlink.
1152 * This API support only the new driver API (iw_handler).
1154 * This RtNetlink API use the same query/reply model as the ioctl API.
1155 * Maximum effort has been done to fit in the RtNetlink model, and
1156 * we support both RtNetlink Set and RtNelink Get operations.
1157 * On the other hand, we don't offer Dump operations because of the
1158 * following reasons :
1159 * o Large number of parameters, most optional
1160 * o Large size of some parameters (> 100 bytes)
1161 * o Each parameters need to be extracted from hardware
1162 * o Scan requests can take seconds and disable network activity.
1163 * Because of this high cost/overhead, we want to return only the
1164 * parameters the user application is really interested in.
1165 * We could offer partial Dump using the IW_DESCR_FLAG_DUMP flag.
1167 * The API uses the standard RtNetlink socket. When the RtNetlink code
1168 * find a IFLA_WIRELESS field in a RtNetlink SET_LINK request,
1172 #ifdef CONFIG_NET_WIRELESS_RTNETLINK
1173 /* ---------------------------------------------------------------- */
1175 * Wrapper to call a standard Wireless Extension GET handler.
1176 * We do various checks and call the handler with the proper args.
1178 static int rtnetlink_standard_get(struct net_device * dev,
1179 struct iw_event * request,
1185 const struct iw_ioctl_description * descr = NULL;
1187 union iwreq_data * wrqu;
1189 struct iw_request_info info;
1190 char * buffer = NULL;
1191 int buffer_size = 0;
1194 /* Get the description of the Request */
1196 if ((cmd - SIOCIWFIRST) >= standard_ioctl_num)
1198 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
1200 #ifdef WE_RTNETLINK_DEBUG
1201 printk(KERN_DEBUG "%s (WE.r) : Found standard handler for 0x%04X\n",
1203 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);
1204 #endif /* WE_RTNETLINK_DEBUG */
1206 /* Check if wrqu is complete */
1207 hdr_len = event_type_size[descr->header_type];
1208 if (request_len < hdr_len) {
1209 #ifdef WE_RTNETLINK_DEBUG
1211 "%s (WE.r) : Wireless request too short (%d)\n",
1212 dev->name, request_len);
1213 #endif /* WE_RTNETLINK_DEBUG */
1217 /* Prepare the call */
1221 /* Check if we have extra data in the reply or not */
1222 if (descr->header_type != IW_HEADER_TYPE_POINT) {
1224 /* Create the kernel buffer that we will return.
1225 * It's at an offset to match the TYPE_POINT case... */
1226 buffer_size = request_len + IW_EV_POINT_OFF;
1227 buffer = kmalloc(buffer_size, GFP_KERNEL);
1228 if (buffer == NULL) {
1231 /* Copy event data */
1232 memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
1233 /* Use our own copy of wrqu */
1234 wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
1235 + IW_EV_LCP_PK_LEN);
1237 /* No extra arguments. Trivial to handle */
1238 ret = handler(dev, &info, wrqu, NULL);
1241 union iwreq_data wrqu_point;
1242 char * extra = NULL;
1245 /* Get a temp copy of wrqu (skip pointer) */
1246 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1247 ((char *) request) + IW_EV_LCP_PK_LEN,
1248 IW_EV_POINT_LEN - IW_EV_LCP_PK_LEN);
1250 /* Calculate space needed by arguments. Always allocate
1251 * for max space. Easier, and won't last long... */
1252 extra_size = descr->max_tokens * descr->token_size;
1253 /* Support for very large requests */
1254 if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
1255 (wrqu_point.data.length > descr->max_tokens))
1256 extra_size = (wrqu_point.data.length
1257 * descr->token_size);
1258 buffer_size = extra_size + IW_EV_POINT_PK_LEN + IW_EV_POINT_OFF;
1259 #ifdef WE_RTNETLINK_DEBUG
1260 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1261 dev->name, extra_size, buffer_size);
1262 #endif /* WE_RTNETLINK_DEBUG */
1264 /* Create the kernel buffer that we will return */
1265 buffer = kmalloc(buffer_size, GFP_KERNEL);
1266 if (buffer == NULL) {
1270 /* Put wrqu in the right place (just before extra).
1271 * Leave space for IWE header and dummy pointer...
1272 * Note that IW_EV_LCP_PK_LEN==4 bytes, so it's still aligned.
1274 memcpy(buffer + IW_EV_LCP_PK_LEN + IW_EV_POINT_OFF,
1275 ((char *) &wrqu_point) + IW_EV_POINT_OFF,
1276 IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1277 wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_PK_LEN);
1279 /* Extra comes logically after that. Offset +12 bytes. */
1280 extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_PK_LEN;
1282 /* Call the handler */
1283 ret = handler(dev, &info, wrqu, extra);
1285 /* Calculate real returned length */
1286 extra_size = (wrqu->data.length * descr->token_size);
1287 /* Re-adjust reply size */
1288 request->len = extra_size + IW_EV_POINT_PK_LEN;
1290 /* Put the iwe header where it should, i.e. scrap the
1292 memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_PK_LEN);
1294 #ifdef WE_RTNETLINK_DEBUG
1295 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);
1296 #endif /* WE_RTNETLINK_DEBUG */
1298 /* Check if there is enough buffer up there */
1299 if (wrqu_point.data.length < wrqu->data.length)
1303 /* Return the buffer to the caller */
1306 *p_len = request->len;
1316 /* ---------------------------------------------------------------- */
1318 * Wrapper to call a standard Wireless Extension SET handler.
1319 * We do various checks and call the handler with the proper args.
1321 static inline int rtnetlink_standard_set(struct net_device * dev,
1322 struct iw_event * request,
1326 const struct iw_ioctl_description * descr = NULL;
1328 union iwreq_data * wrqu;
1329 union iwreq_data wrqu_point;
1331 char * extra = NULL;
1333 struct iw_request_info info;
1336 /* Get the description of the Request */
1338 if ((cmd - SIOCIWFIRST) >= standard_ioctl_num)
1340 descr = &(standard_ioctl[cmd - SIOCIWFIRST]);
1342 #ifdef WE_RTNETLINK_DEBUG
1343 printk(KERN_DEBUG "%s (WE.r) : Found standard SET handler for 0x%04X\n",
1345 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);
1346 #endif /* WE_RTNETLINK_DEBUG */
1348 /* Extract fixed header from request. This is properly aligned. */
1349 wrqu = (union iwreq_data *) (((char *) request) + IW_EV_LCP_PK_LEN);
1351 /* Check if wrqu is complete */
1352 hdr_len = event_type_pk_size[descr->header_type];
1353 if (request_len < hdr_len) {
1354 #ifdef WE_RTNETLINK_DEBUG
1356 "%s (WE.r) : Wireless request too short (%d)\n",
1357 dev->name, request_len);
1358 #endif /* WE_RTNETLINK_DEBUG */
1362 /* Prepare the call */
1366 /* Check if we have extra data in the request or not */
1367 if (descr->header_type != IW_HEADER_TYPE_POINT) {
1369 /* No extra arguments. Trivial to handle */
1370 ret = handler(dev, &info, wrqu, NULL);
1375 /* Put wrqu in the right place (skip pointer) */
1376 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1377 wrqu, IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1378 /* Don't forget about the event code... */
1381 /* Check if number of token fits within bounds */
1382 if (wrqu_point.data.length > descr->max_tokens)
1384 if (wrqu_point.data.length < descr->min_tokens)
1387 /* Real length of payload */
1388 extra_len = wrqu_point.data.length * descr->token_size;
1390 /* Check if request is self consistent */
1391 if ((request_len - hdr_len) < extra_len) {
1392 #ifdef WE_RTNETLINK_DEBUG
1393 printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
1394 dev->name, extra_size);
1395 #endif /* WE_RTNETLINK_DEBUG */
1399 #ifdef WE_RTNETLINK_DEBUG
1400 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
1401 dev->name, extra_size);
1402 #endif /* WE_RTNETLINK_DEBUG */
1404 /* Always allocate for max space. Easier, and won't last
1406 extra_size = descr->max_tokens * descr->token_size;
1407 extra = kmalloc(extra_size, GFP_KERNEL);
1411 /* Copy extra in aligned buffer */
1412 memcpy(extra, ((char *) request) + hdr_len, extra_len);
1414 /* Call the handler */
1415 ret = handler(dev, &info, &wrqu_point, extra);
1419 /* Generate an event to notify listeners of the change */
1420 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
1421 ((ret == 0) || (ret == -EIWCOMMIT))) {
1422 if (descr->flags & IW_DESCR_FLAG_RESTRICT)
1423 /* If the event is restricted, don't
1424 * export the payload */
1425 wireless_send_event(dev, cmd, wrqu, NULL);
1427 wireless_send_event(dev, cmd, wrqu, extra);
1429 #endif /* WE_SET_EVENT */
1431 /* Cleanup - I told you it wasn't that long ;-) */
1435 /* Call commit handler if needed and defined */
1436 if (ret == -EIWCOMMIT)
1437 ret = call_commit_handler(dev);
1442 /* ---------------------------------------------------------------- */
1444 * Wrapper to call a private Wireless Extension GET handler.
1446 * It's not as nice and slimline as the standard wrapper. The cause
1447 * is struct iw_priv_args, which was not really designed for the
1448 * job we are going here.
1450 * IMPORTANT : This function prevent to set and get data on the same
1451 * IOCTL and enforce the SET/GET convention. Not doing it would be
1453 * If you need to set and get data at the same time, please don't use
1454 * a iw_handler but process it in your ioctl handler (i.e. use the
1457 static inline int rtnetlink_private_get(struct net_device * dev,
1458 struct iw_event * request,
1464 const struct iw_priv_args * descr = NULL;
1466 union iwreq_data * wrqu;
1468 struct iw_request_info info;
1471 char * buffer = NULL;
1472 int buffer_size = 0;
1475 /* Get the description of the Request */
1477 for (i = 0; i < dev->wireless_handlers->num_private_args; i++)
1478 if (cmd == dev->wireless_handlers->private_args[i].cmd) {
1479 descr = &(dev->wireless_handlers->private_args[i]);
1485 #ifdef WE_RTNETLINK_DEBUG
1486 printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
1488 printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
1489 dev->name, descr->name, descr->set_args, descr->get_args);
1490 #endif /* WE_RTNETLINK_DEBUG */
1492 /* Compute the max size of the get arguments */
1493 extra_size = get_priv_size(descr->get_args);
1495 /* Does it fits in wrqu ? */
1496 if ((descr->get_args & IW_PRIV_SIZE_FIXED) &&
1497 (extra_size <= IFNAMSIZ)) {
1498 hdr_len = extra_size;
1501 hdr_len = IW_EV_POINT_PK_LEN;
1504 /* Check if wrqu is complete */
1505 if (request_len < hdr_len) {
1506 #ifdef WE_RTNETLINK_DEBUG
1508 "%s (WE.r) : Wireless request too short (%d)\n",
1509 dev->name, request_len);
1510 #endif /* WE_RTNETLINK_DEBUG */
1514 /* Prepare the call */
1518 /* Check if we have a pointer to user space data or not. */
1519 if (extra_size == 0) {
1521 /* Create the kernel buffer that we will return.
1522 * It's at an offset to match the TYPE_POINT case... */
1523 buffer_size = request_len + IW_EV_POINT_OFF;
1524 buffer = kmalloc(buffer_size, GFP_KERNEL);
1525 if (buffer == NULL) {
1528 /* Copy event data */
1529 memcpy(buffer + IW_EV_POINT_OFF, request, request_len);
1530 /* Use our own copy of wrqu */
1531 wrqu = (union iwreq_data *) (buffer + IW_EV_POINT_OFF
1532 + IW_EV_LCP_PK_LEN);
1534 /* No extra arguments. Trivial to handle */
1535 ret = handler(dev, &info, wrqu, (char *) wrqu);
1540 /* Buffer for full reply */
1541 buffer_size = extra_size + IW_EV_POINT_PK_LEN + IW_EV_POINT_OFF;
1543 #ifdef WE_RTNETLINK_DEBUG
1544 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1545 dev->name, extra_size, buffer_size);
1546 #endif /* WE_RTNETLINK_DEBUG */
1548 /* Create the kernel buffer that we will return */
1549 buffer = kmalloc(buffer_size, GFP_KERNEL);
1550 if (buffer == NULL) {
1554 /* Put wrqu in the right place (just before extra).
1555 * Leave space for IWE header and dummy pointer...
1556 * Note that IW_EV_LCP_PK_LEN==4 bytes, so it's still aligned.
1558 memcpy(buffer + IW_EV_LCP_PK_LEN + IW_EV_POINT_OFF,
1559 ((char *) request) + IW_EV_LCP_PK_LEN,
1560 IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1561 wrqu = (union iwreq_data *) (buffer + IW_EV_LCP_PK_LEN);
1563 /* Extra comes logically after that. Offset +12 bytes. */
1564 extra = buffer + IW_EV_POINT_OFF + IW_EV_POINT_PK_LEN;
1566 /* Call the handler */
1567 ret = handler(dev, &info, wrqu, extra);
1569 /* Adjust for the actual length if it's variable,
1570 * avoid leaking kernel bits outside. */
1571 if (!(descr->get_args & IW_PRIV_SIZE_FIXED))
1572 extra_size = adjust_priv_size(descr->get_args, wrqu);
1573 /* Re-adjust reply size */
1574 request->len = extra_size + IW_EV_POINT_PK_LEN;
1576 /* Put the iwe header where it should, i.e. scrap the
1578 memcpy(buffer + IW_EV_POINT_OFF, request, IW_EV_LCP_PK_LEN);
1580 #ifdef WE_RTNETLINK_DEBUG
1581 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);
1582 #endif /* WE_RTNETLINK_DEBUG */
1585 /* Return the buffer to the caller */
1588 *p_len = request->len;
1598 /* ---------------------------------------------------------------- */
1600 * Wrapper to call a private Wireless Extension SET handler.
1602 * It's not as nice and slimline as the standard wrapper. The cause
1603 * is struct iw_priv_args, which was not really designed for the
1604 * job we are going here.
1606 * IMPORTANT : This function prevent to set and get data on the same
1607 * IOCTL and enforce the SET/GET convention. Not doing it would be
1609 * If you need to set and get data at the same time, please don't use
1610 * a iw_handler but process it in your ioctl handler (i.e. use the
1613 static inline int rtnetlink_private_set(struct net_device * dev,
1614 struct iw_event * request,
1618 const struct iw_priv_args * descr = NULL;
1620 union iwreq_data * wrqu;
1621 union iwreq_data wrqu_point;
1623 char * extra = NULL;
1625 int offset = 0; /* For sub-ioctls */
1626 struct iw_request_info info;
1630 /* Get the description of the Request */
1632 for (i = 0; i < dev->wireless_handlers->num_private_args; i++)
1633 if (cmd == dev->wireless_handlers->private_args[i].cmd) {
1634 descr = &(dev->wireless_handlers->private_args[i]);
1640 #ifdef WE_RTNETLINK_DEBUG
1641 printk(KERN_DEBUG "%s (WE.r) : Found private handler for 0x%04X\n",
1642 ifr->ifr_name, cmd);
1643 printk(KERN_DEBUG "%s (WE.r) : Name %s, set %X, get %X\n",
1644 dev->name, descr->name, descr->set_args, descr->get_args);
1645 #endif /* WE_RTNETLINK_DEBUG */
1647 /* Compute the size of the set arguments */
1648 /* Check for sub-ioctl handler */
1649 if (descr->name[0] == '\0')
1650 /* Reserve one int for sub-ioctl index */
1651 offset = sizeof(__u32);
1653 /* Size of set arguments */
1654 extra_size = get_priv_size(descr->set_args);
1656 /* Does it fits in wrqu ? */
1657 if ((descr->set_args & IW_PRIV_SIZE_FIXED) &&
1658 (extra_size <= IFNAMSIZ)) {
1659 hdr_len = IW_EV_LCP_PK_LEN + extra_size;
1662 hdr_len = IW_EV_POINT_PK_LEN;
1665 /* Extract fixed header from request. This is properly aligned. */
1666 wrqu = (union iwreq_data *) (((char *) request) + IW_EV_LCP_PK_LEN);
1668 /* Check if wrqu is complete */
1669 if (request_len < hdr_len) {
1670 #ifdef WE_RTNETLINK_DEBUG
1672 "%s (WE.r) : Wireless request too short (%d)\n",
1673 dev->name, request_len);
1674 #endif /* WE_RTNETLINK_DEBUG */
1678 /* Prepare the call */
1682 /* Check if we have a pointer to user space data or not. */
1683 if (extra_size == 0) {
1685 /* No extra arguments. Trivial to handle */
1686 ret = handler(dev, &info, wrqu, (char *) wrqu);
1691 /* Put wrqu in the right place (skip pointer) */
1692 memcpy(((char *) &wrqu_point) + IW_EV_POINT_OFF,
1693 wrqu, IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
1695 /* Does it fits within bounds ? */
1696 if (wrqu_point.data.length > (descr->set_args &
1700 /* Real length of payload */
1701 extra_len = adjust_priv_size(descr->set_args, &wrqu_point);
1703 /* Check if request is self consistent */
1704 if ((request_len - hdr_len) < extra_len) {
1705 #ifdef WE_RTNETLINK_DEBUG
1706 printk(KERN_DEBUG "%s (WE.r) : Wireless request data too short (%d)\n",
1707 dev->name, extra_size);
1708 #endif /* WE_RTNETLINK_DEBUG */
1712 #ifdef WE_RTNETLINK_DEBUG
1713 printk(KERN_DEBUG "%s (WE.r) : Malloc %d bytes\n",
1714 dev->name, extra_size);
1715 #endif /* WE_RTNETLINK_DEBUG */
1717 /* Always allocate for max space. Easier, and won't last
1719 extra = kmalloc(extra_size, GFP_KERNEL);
1723 /* Copy extra in aligned buffer */
1724 memcpy(extra, ((char *) request) + hdr_len, extra_len);
1726 /* Call the handler */
1727 ret = handler(dev, &info, &wrqu_point, extra);
1729 /* Cleanup - I told you it wasn't that long ;-) */
1733 /* Call commit handler if needed and defined */
1734 if (ret == -EIWCOMMIT)
1735 ret = call_commit_handler(dev);
1740 /* ---------------------------------------------------------------- */
1742 * Main RtNetlink dispatcher. Called from the main networking code
1743 * (do_getlink() in net/core/rtnetlink.c).
1744 * Check the type of Request and call the appropriate wrapper...
1746 int wireless_rtnetlink_get(struct net_device * dev,
1752 struct iw_event * request = (struct iw_event *) data;
1756 if (len < IW_EV_LCP_PK_LEN) {
1757 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
1762 /* ReCheck length (len may have padding) */
1763 if (request->len > len) {
1764 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1765 dev->name, request->len, len);
1769 /* Only accept GET requests in here */
1770 if (!IW_IS_GET(request->cmd))
1773 /* If command is `get the encoding parameters', check if
1774 * the user has the right to do it */
1775 if (request->cmd == SIOCGIWENCODE ||
1776 request->cmd == SIOCGIWENCODEEXT) {
1777 if (!capable(CAP_NET_ADMIN))
1782 if (request->cmd == SIOCGIWSTATS)
1783 /* Get Wireless Stats */
1784 return rtnetlink_standard_get(dev,
1787 &iw_handler_get_iwstats,
1789 if (request->cmd == SIOCGIWPRIV) {
1790 /* Check if we have some wireless handlers defined */
1791 if (dev->wireless_handlers == NULL)
1793 /* Get Wireless Stats */
1794 return rtnetlink_standard_get(dev,
1797 &iw_handler_get_private,
1802 if (!netif_device_present(dev))
1805 /* Try to find the handler */
1806 handler = get_handler(dev, request->cmd);
1807 if (handler != NULL) {
1808 /* Standard and private are not the same */
1809 if (request->cmd < SIOCIWFIRSTPRIV)
1810 return rtnetlink_standard_get(dev,
1816 return rtnetlink_private_get(dev,
1826 /* ---------------------------------------------------------------- */
1828 * Main RtNetlink dispatcher. Called from the main networking code
1829 * (do_setlink() in net/core/rtnetlink.c).
1830 * Check the type of Request and call the appropriate wrapper...
1832 int wireless_rtnetlink_set(struct net_device * dev,
1836 struct iw_event * request = (struct iw_event *) data;
1840 if (len < IW_EV_LCP_PK_LEN) {
1841 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request too short (%d)\n",
1846 /* ReCheck length (len may have padding) */
1847 if (request->len > len) {
1848 printk(KERN_DEBUG "%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1849 dev->name, request->len, len);
1853 /* Only accept SET requests in here */
1854 if (!IW_IS_SET(request->cmd))
1858 if (!netif_device_present(dev))
1861 /* New driver API : try to find the handler */
1862 handler = get_handler(dev, request->cmd);
1863 if (handler != NULL) {
1864 /* Standard and private are not the same */
1865 if (request->cmd < SIOCIWFIRSTPRIV)
1866 return rtnetlink_standard_set(dev,
1871 return rtnetlink_private_set(dev,
1879 #endif /* CONFIG_NET_WIRELESS_RTNETLINK */
1882 /************************* EVENT PROCESSING *************************/
1884 * Process events generated by the wireless layer or the driver.
1885 * Most often, the event will be propagated through rtnetlink
1888 #ifdef WE_EVENT_RTNETLINK
1889 /* ---------------------------------------------------------------- */
1894 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1895 * the locking issue in here and implementing this code !
1897 * The issue : wireless_send_event() is often called in interrupt context,
1898 * while the Netlink layer can never be called in interrupt context.
1899 * The fully formed RtNetlink events are queued, and then a tasklet is run
1900 * to feed those to Netlink.
1901 * The skb_queue is interrupt safe, and its lock is not held while calling
1902 * Netlink, so there is no possibility of dealock.
1906 static struct sk_buff_head wireless_nlevent_queue;
1908 static int __init wireless_nlevent_init(void)
1910 skb_queue_head_init(&wireless_nlevent_queue);
1914 subsys_initcall(wireless_nlevent_init);
1916 static void wireless_nlevent_process(unsigned long data)
1918 struct sk_buff *skb;
1920 while ((skb = skb_dequeue(&wireless_nlevent_queue)))
1921 rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
1924 static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0);
1926 /* ---------------------------------------------------------------- */
1928 * Fill a rtnetlink message with our event data.
1929 * Note that we propage only the specified event and don't dump the
1930 * current wireless config. Dumping the wireless config is far too
1931 * expensive (for each parameter, the driver need to query the hardware).
1933 static inline int rtnetlink_fill_iwinfo(struct sk_buff * skb,
1934 struct net_device * dev,
1939 struct ifinfomsg *r;
1940 struct nlmsghdr *nlh;
1941 unsigned char *b = skb_tail_pointer(skb);
1943 nlh = NLMSG_PUT(skb, 0, 0, type, sizeof(*r));
1944 r = NLMSG_DATA(nlh);
1945 r->ifi_family = AF_UNSPEC;
1947 r->ifi_type = dev->type;
1948 r->ifi_index = dev->ifindex;
1949 r->ifi_flags = dev_get_flags(dev);
1950 r->ifi_change = 0; /* Wireless changes don't affect those flags */
1952 /* Add the wireless events in the netlink packet */
1953 RTA_PUT(skb, IFLA_WIRELESS, event_len, event);
1955 nlh->nlmsg_len = skb_tail_pointer(skb) - b;
1964 /* ---------------------------------------------------------------- */
1966 * Create and broadcast and send it on the standard rtnetlink socket
1967 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1968 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1969 * within a RTM_NEWLINK event.
1971 static inline void rtmsg_iwinfo(struct net_device * dev,
1975 struct sk_buff *skb;
1976 int size = NLMSG_GOODSIZE;
1978 skb = alloc_skb(size, GFP_ATOMIC);
1982 if (rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK,
1983 event, event_len) < 0) {
1987 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
1988 skb_queue_tail(&wireless_nlevent_queue, skb);
1989 tasklet_schedule(&wireless_nlevent_tasklet);
1992 #endif /* WE_EVENT_RTNETLINK */
1994 /* ---------------------------------------------------------------- */
1996 * Main event dispatcher. Called from other parts and drivers.
1997 * Send the event on the appropriate channels.
1998 * May be called from interrupt context.
2000 void wireless_send_event(struct net_device * dev,
2002 union iwreq_data * wrqu,
2005 const struct iw_ioctl_description * descr = NULL;
2007 struct iw_event *event; /* Mallocated whole event */
2008 int event_len; /* Its size */
2009 int hdr_len; /* Size of the event header */
2010 int wrqu_off = 0; /* Offset in wrqu */
2011 /* Don't "optimise" the following variable, it will crash */
2012 unsigned cmd_index; /* *MUST* be unsigned */
2014 /* Get the description of the Event */
2015 if (cmd <= SIOCIWLAST) {
2016 cmd_index = cmd - SIOCIWFIRST;
2017 if (cmd_index < standard_ioctl_num)
2018 descr = &(standard_ioctl[cmd_index]);
2020 cmd_index = cmd - IWEVFIRST;
2021 if (cmd_index < standard_event_num)
2022 descr = &(standard_event[cmd_index]);
2024 /* Don't accept unknown events */
2025 if (descr == NULL) {
2026 /* Note : we don't return an error to the driver, because
2027 * the driver would not know what to do about it. It can't
2028 * return an error to the user, because the event is not
2029 * initiated by a user request.
2030 * The best the driver could do is to log an error message.
2031 * We will do it ourselves instead...
2033 printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
2037 #ifdef WE_EVENT_DEBUG
2038 printk(KERN_DEBUG "%s (WE) : Got event 0x%04X\n",
2040 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);
2041 #endif /* WE_EVENT_DEBUG */
2043 /* Check extra parameters and set extra_len */
2044 if (descr->header_type == IW_HEADER_TYPE_POINT) {
2045 /* Check if number of token fits within bounds */
2046 if (wrqu->data.length > descr->max_tokens) {
2047 printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length);
2050 if (wrqu->data.length < descr->min_tokens) {
2051 printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length);
2054 /* Calculate extra_len - extra is NULL for restricted events */
2056 extra_len = wrqu->data.length * descr->token_size;
2057 /* Always at an offset in wrqu */
2058 wrqu_off = IW_EV_POINT_OFF;
2059 #ifdef WE_EVENT_DEBUG
2060 printk(KERN_DEBUG "%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev->name, cmd, wrqu->data.length, extra_len);
2061 #endif /* WE_EVENT_DEBUG */
2064 /* Total length of the event */
2065 hdr_len = event_type_size[descr->header_type];
2066 event_len = hdr_len + extra_len;
2068 #ifdef WE_EVENT_DEBUG
2069 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);
2070 #endif /* WE_EVENT_DEBUG */
2072 /* Create temporary buffer to hold the event */
2073 event = kmalloc(event_len, GFP_ATOMIC);
2078 event->len = event_len;
2080 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
2082 memcpy(((char *) event) + hdr_len, extra, extra_len);
2084 #ifdef WE_EVENT_RTNETLINK
2085 /* Send via the RtNetlink event channel */
2086 rtmsg_iwinfo(dev, (char *) event, event_len);
2087 #endif /* WE_EVENT_RTNETLINK */
2092 return; /* Always success, I guess ;-) */
2095 /********************** ENHANCED IWSPY SUPPORT **********************/
2097 * In the old days, the driver was handling spy support all by itself.
2098 * Now, the driver can delegate this task to Wireless Extensions.
2099 * It needs to use those standard spy iw_handler in struct iw_handler_def,
2100 * push data to us via wireless_spy_update() and include struct iw_spy_data
2101 * in its private part (and export it in net_device->wireless_data->spy_data).
2102 * One of the main advantage of centralising spy support here is that
2103 * it becomes much easier to improve and extend it without having to touch
2104 * the drivers. One example is the addition of the Spy-Threshold events.
2107 /* ---------------------------------------------------------------- */
2109 * Return the pointer to the spy data in the driver.
2110 * Because this is called on the Rx path via wireless_spy_update(),
2111 * we want it to be efficient...
2113 static inline struct iw_spy_data * get_spydata(struct net_device *dev)
2115 /* This is the new way */
2116 if (dev->wireless_data)
2117 return(dev->wireless_data->spy_data);
2121 /*------------------------------------------------------------------*/
2123 * Standard Wireless Handler : set Spy List
2125 int iw_handler_set_spy(struct net_device * dev,
2126 struct iw_request_info * info,
2127 union iwreq_data * wrqu,
2130 struct iw_spy_data * spydata = get_spydata(dev);
2131 struct sockaddr * address = (struct sockaddr *) extra;
2133 /* Make sure driver is not buggy or using the old API */
2137 /* Disable spy collection while we copy the addresses.
2138 * While we copy addresses, any call to wireless_spy_update()
2139 * will NOP. This is OK, as anyway the addresses are changing. */
2140 spydata->spy_number = 0;
2142 /* We want to operate without locking, because wireless_spy_update()
2143 * most likely will happen in the interrupt handler, and therefore
2144 * have its own locking constraints and needs performance.
2145 * The rtnl_lock() make sure we don't race with the other iw_handlers.
2146 * This make sure wireless_spy_update() "see" that the spy list
2147 * is temporarily disabled. */
2150 /* Are there are addresses to copy? */
2151 if (wrqu->data.length > 0) {
2154 /* Copy addresses */
2155 for (i = 0; i < wrqu->data.length; i++)
2156 memcpy(spydata->spy_address[i], address[i].sa_data,
2159 memset(spydata->spy_stat, 0,
2160 sizeof(struct iw_quality) * IW_MAX_SPY);
2163 printk(KERN_DEBUG "iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev->wireless_data, spydata, wrqu->data.length);
2164 for (i = 0; i < wrqu->data.length; i++)
2166 "%02X:%02X:%02X:%02X:%02X:%02X \n",
2167 spydata->spy_address[i][0],
2168 spydata->spy_address[i][1],
2169 spydata->spy_address[i][2],
2170 spydata->spy_address[i][3],
2171 spydata->spy_address[i][4],
2172 spydata->spy_address[i][5]);
2173 #endif /* WE_SPY_DEBUG */
2176 /* Make sure above is updated before re-enabling */
2179 /* Enable addresses */
2180 spydata->spy_number = wrqu->data.length;
2185 /*------------------------------------------------------------------*/
2187 * Standard Wireless Handler : get Spy List
2189 int iw_handler_get_spy(struct net_device * dev,
2190 struct iw_request_info * info,
2191 union iwreq_data * wrqu,
2194 struct iw_spy_data * spydata = get_spydata(dev);
2195 struct sockaddr * address = (struct sockaddr *) extra;
2198 /* Make sure driver is not buggy or using the old API */
2202 wrqu->data.length = spydata->spy_number;
2204 /* Copy addresses. */
2205 for (i = 0; i < spydata->spy_number; i++) {
2206 memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN);
2207 address[i].sa_family = AF_UNIX;
2209 /* Copy stats to the user buffer (just after). */
2210 if (spydata->spy_number > 0)
2211 memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number),
2213 sizeof(struct iw_quality) * spydata->spy_number);
2214 /* Reset updated flags. */
2215 for (i = 0; i < spydata->spy_number; i++)
2216 spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED;
2220 /*------------------------------------------------------------------*/
2222 * Standard Wireless Handler : set spy threshold
2224 int iw_handler_set_thrspy(struct net_device * dev,
2225 struct iw_request_info *info,
2226 union iwreq_data * wrqu,
2229 struct iw_spy_data * spydata = get_spydata(dev);
2230 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
2232 /* Make sure driver is not buggy or using the old API */
2237 memcpy(&(spydata->spy_thr_low), &(threshold->low),
2238 2 * sizeof(struct iw_quality));
2241 memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under));
2244 printk(KERN_DEBUG "iw_handler_set_thrspy() : low %d ; high %d\n", spydata->spy_thr_low.level, spydata->spy_thr_high.level);
2245 #endif /* WE_SPY_DEBUG */
2250 /*------------------------------------------------------------------*/
2252 * Standard Wireless Handler : get spy threshold
2254 int iw_handler_get_thrspy(struct net_device * dev,
2255 struct iw_request_info *info,
2256 union iwreq_data * wrqu,
2259 struct iw_spy_data * spydata = get_spydata(dev);
2260 struct iw_thrspy * threshold = (struct iw_thrspy *) extra;
2262 /* Make sure driver is not buggy or using the old API */
2267 memcpy(&(threshold->low), &(spydata->spy_thr_low),
2268 2 * sizeof(struct iw_quality));
2273 /*------------------------------------------------------------------*/
2275 * Prepare and send a Spy Threshold event
2277 static void iw_send_thrspy_event(struct net_device * dev,
2278 struct iw_spy_data * spydata,
2279 unsigned char * address,
2280 struct iw_quality * wstats)
2282 union iwreq_data wrqu;
2283 struct iw_thrspy threshold;
2286 wrqu.data.length = 1;
2287 wrqu.data.flags = 0;
2289 memcpy(threshold.addr.sa_data, address, ETH_ALEN);
2290 threshold.addr.sa_family = ARPHRD_ETHER;
2292 memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality));
2293 /* Copy also thresholds */
2294 memcpy(&(threshold.low), &(spydata->spy_thr_low),
2295 2 * sizeof(struct iw_quality));
2298 printk(KERN_DEBUG "iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
2299 threshold.addr.sa_data[0],
2300 threshold.addr.sa_data[1],
2301 threshold.addr.sa_data[2],
2302 threshold.addr.sa_data[3],
2303 threshold.addr.sa_data[4],
2304 threshold.addr.sa_data[5], threshold.qual.level);
2305 #endif /* WE_SPY_DEBUG */
2307 /* Send event to user space */
2308 wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold);
2311 /* ---------------------------------------------------------------- */
2313 * Call for the driver to update the spy data.
2314 * For now, the spy data is a simple array. As the size of the array is
2315 * small, this is good enough. If we wanted to support larger number of
2316 * spy addresses, we should use something more efficient...
2318 void wireless_spy_update(struct net_device * dev,
2319 unsigned char * address,
2320 struct iw_quality * wstats)
2322 struct iw_spy_data * spydata = get_spydata(dev);
2326 /* Make sure driver is not buggy or using the old API */
2331 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]);
2332 #endif /* WE_SPY_DEBUG */
2334 /* Update all records that match */
2335 for (i = 0; i < spydata->spy_number; i++)
2336 if (!compare_ether_addr(address, spydata->spy_address[i])) {
2337 memcpy(&(spydata->spy_stat[i]), wstats,
2338 sizeof(struct iw_quality));
2342 /* Generate an event if we cross the spy threshold.
2343 * To avoid event storms, we have a simple hysteresis : we generate
2344 * event only when we go under the low threshold or above the
2345 * high threshold. */
2347 if (spydata->spy_thr_under[match]) {
2348 if (wstats->level > spydata->spy_thr_high.level) {
2349 spydata->spy_thr_under[match] = 0;
2350 iw_send_thrspy_event(dev, spydata,
2354 if (wstats->level < spydata->spy_thr_low.level) {
2355 spydata->spy_thr_under[match] = 1;
2356 iw_send_thrspy_event(dev, spydata,
2363 EXPORT_SYMBOL(iw_handler_get_spy);
2364 EXPORT_SYMBOL(iw_handler_get_thrspy);
2365 EXPORT_SYMBOL(iw_handler_set_spy);
2366 EXPORT_SYMBOL(iw_handler_set_thrspy);
2367 EXPORT_SYMBOL(wireless_send_event);
2368 EXPORT_SYMBOL(wireless_spy_update);