2 * This file implement the Wireless Extensions APIs.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2005 Jean Tourrilhes, All Rights Reserved.
7 * (As all part of the Linux kernel, this file is GPL)
10 /************************** DOCUMENTATION **************************/
14 * See <linux/wireless.h> for details of the APIs and the rest.
19 * v1 - 5.12.01 - Jean II
20 * o Created this file.
22 * v2 - 13.12.01 - Jean II
23 * o Move /proc/net/wireless stuff from net/core/dev.c to here
24 * o Make Wireless Extension IOCTLs go through here
25 * o Added iw_handler handling ;-)
26 * o Added standard ioctl description
27 * o Initial dumb commit strategy based on orinoco.c
29 * v3 - 19.12.01 - Jean II
30 * o Make sure we don't go out of standard_ioctl[] in ioctl_standard_call
31 * o Add event dispatcher function
32 * o Add event description
33 * o Propagate events as rtnetlink IFLA_WIRELESS option
34 * o Generate event on selected SET requests
36 * v4 - 18.04.02 - Jean II
37 * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1
39 * v5 - 21.06.02 - Jean II
40 * o Add IW_PRIV_TYPE_ADDR in priv_type_size (+cleanup)
41 * o Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
42 * o Add IWEVCUSTOM for driver specific event/scanning token
43 * o Turn on WE_STRICT_WRITE by default + kernel warning
44 * o Fix WE_STRICT_WRITE in ioctl_export_private() (32 => iw_num)
45 * o Fix off-by-one in test (extra_size <= IFNAMSIZ)
47 * v6 - 9.01.03 - Jean II
48 * o Add common spy support : iw_handler_set_spy(), wireless_spy_update()
49 * o Add enhanced spy support : iw_handler_set_thrspy() and event.
50 * o Add WIRELESS_EXT version display in /proc/net/wireless
52 * v6 - 18.06.04 - Jean II
53 * o Change get_spydata() method for added safety
54 * o Remove spy #ifdef, they are always on -> cleaner code
55 * o Allow any size GET request if user specifies length > max
56 * and if request has IW_DESCR_FLAG_NOMAX flag or is SIOCGIWPRIV
57 * o Start migrating get_wireless_stats to struct iw_handler_def
58 * o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus
59 * Based on patch from Pavel Roskin <proski@gnu.org> :
60 * o Fix kernel data leak to user space in private handler handling
62 * v7 - 18.3.05 - Jean II
63 * o Remove (struct iw_point *)->pointer from events and streams
64 * o Remove spy_offset from struct iw_handler_def
65 * o Start deprecating dev->get_wireless_stats, output a warning
66 * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless
67 * o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats)
70 /***************************** INCLUDES *****************************/
72 #include <linux/config.h> /* Not needed ??? */
73 #include <linux/module.h>
74 #include <linux/types.h> /* off_t */
75 #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
76 #include <linux/proc_fs.h>
77 #include <linux/rtnetlink.h> /* rtnetlink stuff */
78 #include <linux/seq_file.h>
79 #include <linux/init.h> /* for __init */
80 #include <linux/if_arp.h> /* ARPHRD_ETHER */
82 #include <linux/wireless.h> /* Pretty obvious */
83 #include <net/iw_handler.h> /* New driver API */
85 #include <asm/uaccess.h> /* copy_to_user() */
87 /**************************** CONSTANTS ****************************/
90 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
91 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
92 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
95 #define WE_EVENT_NETLINK /* Propagate events using rtnetlink */
96 #define WE_SET_EVENT /* Generate an event on some set commands */
98 /************************* GLOBAL VARIABLES *************************/
100 * You should not use global variables, because of re-entrancy.
101 * On our case, it's only const, so it's OK...
104 * Meta-data about all the standard Wireless Extension request we
107 static const struct iw_ioctl_description standard_ioctl
[] = {
108 [SIOCSIWCOMMIT
- SIOCIWFIRST
] = {
109 .header_type
= IW_HEADER_TYPE_NULL
,
111 [SIOCGIWNAME
- SIOCIWFIRST
] = {
112 .header_type
= IW_HEADER_TYPE_CHAR
,
113 .flags
= IW_DESCR_FLAG_DUMP
,
115 [SIOCSIWNWID
- SIOCIWFIRST
] = {
116 .header_type
= IW_HEADER_TYPE_PARAM
,
117 .flags
= IW_DESCR_FLAG_EVENT
,
119 [SIOCGIWNWID
- SIOCIWFIRST
] = {
120 .header_type
= IW_HEADER_TYPE_PARAM
,
121 .flags
= IW_DESCR_FLAG_DUMP
,
123 [SIOCSIWFREQ
- SIOCIWFIRST
] = {
124 .header_type
= IW_HEADER_TYPE_FREQ
,
125 .flags
= IW_DESCR_FLAG_EVENT
,
127 [SIOCGIWFREQ
- SIOCIWFIRST
] = {
128 .header_type
= IW_HEADER_TYPE_FREQ
,
129 .flags
= IW_DESCR_FLAG_DUMP
,
131 [SIOCSIWMODE
- SIOCIWFIRST
] = {
132 .header_type
= IW_HEADER_TYPE_UINT
,
133 .flags
= IW_DESCR_FLAG_EVENT
,
135 [SIOCGIWMODE
- SIOCIWFIRST
] = {
136 .header_type
= IW_HEADER_TYPE_UINT
,
137 .flags
= IW_DESCR_FLAG_DUMP
,
139 [SIOCSIWSENS
- SIOCIWFIRST
] = {
140 .header_type
= IW_HEADER_TYPE_PARAM
,
142 [SIOCGIWSENS
- SIOCIWFIRST
] = {
143 .header_type
= IW_HEADER_TYPE_PARAM
,
145 [SIOCSIWRANGE
- SIOCIWFIRST
] = {
146 .header_type
= IW_HEADER_TYPE_NULL
,
148 [SIOCGIWRANGE
- SIOCIWFIRST
] = {
149 .header_type
= IW_HEADER_TYPE_POINT
,
151 .max_tokens
= sizeof(struct iw_range
),
152 .flags
= IW_DESCR_FLAG_DUMP
,
154 [SIOCSIWPRIV
- SIOCIWFIRST
] = {
155 .header_type
= IW_HEADER_TYPE_NULL
,
157 [SIOCGIWPRIV
- SIOCIWFIRST
] = { /* (handled directly by us) */
158 .header_type
= IW_HEADER_TYPE_NULL
,
160 [SIOCSIWSTATS
- SIOCIWFIRST
] = {
161 .header_type
= IW_HEADER_TYPE_NULL
,
163 [SIOCGIWSTATS
- SIOCIWFIRST
] = { /* (handled directly by us) */
164 .header_type
= IW_HEADER_TYPE_NULL
,
165 .flags
= IW_DESCR_FLAG_DUMP
,
167 [SIOCSIWSPY
- SIOCIWFIRST
] = {
168 .header_type
= IW_HEADER_TYPE_POINT
,
169 .token_size
= sizeof(struct sockaddr
),
170 .max_tokens
= IW_MAX_SPY
,
172 [SIOCGIWSPY
- SIOCIWFIRST
] = {
173 .header_type
= IW_HEADER_TYPE_POINT
,
174 .token_size
= sizeof(struct sockaddr
) +
175 sizeof(struct iw_quality
),
176 .max_tokens
= IW_MAX_SPY
,
178 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = {
179 .header_type
= IW_HEADER_TYPE_POINT
,
180 .token_size
= sizeof(struct iw_thrspy
),
184 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = {
185 .header_type
= IW_HEADER_TYPE_POINT
,
186 .token_size
= sizeof(struct iw_thrspy
),
190 [SIOCSIWAP
- SIOCIWFIRST
] = {
191 .header_type
= IW_HEADER_TYPE_ADDR
,
193 [SIOCGIWAP
- SIOCIWFIRST
] = {
194 .header_type
= IW_HEADER_TYPE_ADDR
,
195 .flags
= IW_DESCR_FLAG_DUMP
,
197 [SIOCSIWMLME
- SIOCIWFIRST
] = {
198 .header_type
= IW_HEADER_TYPE_POINT
,
200 .min_tokens
= sizeof(struct iw_mlme
),
201 .max_tokens
= sizeof(struct iw_mlme
),
203 [SIOCGIWAPLIST
- SIOCIWFIRST
] = {
204 .header_type
= IW_HEADER_TYPE_POINT
,
205 .token_size
= sizeof(struct sockaddr
) +
206 sizeof(struct iw_quality
),
207 .max_tokens
= IW_MAX_AP
,
208 .flags
= IW_DESCR_FLAG_NOMAX
,
210 [SIOCSIWSCAN
- SIOCIWFIRST
] = {
211 .header_type
= IW_HEADER_TYPE_POINT
,
214 .max_tokens
= sizeof(struct iw_scan_req
),
216 [SIOCGIWSCAN
- SIOCIWFIRST
] = {
217 .header_type
= IW_HEADER_TYPE_POINT
,
219 .max_tokens
= IW_SCAN_MAX_DATA
,
220 .flags
= IW_DESCR_FLAG_NOMAX
,
222 [SIOCSIWESSID
- SIOCIWFIRST
] = {
223 .header_type
= IW_HEADER_TYPE_POINT
,
225 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
226 .flags
= IW_DESCR_FLAG_EVENT
,
228 [SIOCGIWESSID
- SIOCIWFIRST
] = {
229 .header_type
= IW_HEADER_TYPE_POINT
,
231 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
232 .flags
= IW_DESCR_FLAG_DUMP
,
234 [SIOCSIWNICKN
- SIOCIWFIRST
] = {
235 .header_type
= IW_HEADER_TYPE_POINT
,
237 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
239 [SIOCGIWNICKN
- SIOCIWFIRST
] = {
240 .header_type
= IW_HEADER_TYPE_POINT
,
242 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
244 [SIOCSIWRATE
- SIOCIWFIRST
] = {
245 .header_type
= IW_HEADER_TYPE_PARAM
,
247 [SIOCGIWRATE
- SIOCIWFIRST
] = {
248 .header_type
= IW_HEADER_TYPE_PARAM
,
250 [SIOCSIWRTS
- SIOCIWFIRST
] = {
251 .header_type
= IW_HEADER_TYPE_PARAM
,
253 [SIOCGIWRTS
- SIOCIWFIRST
] = {
254 .header_type
= IW_HEADER_TYPE_PARAM
,
256 [SIOCSIWFRAG
- SIOCIWFIRST
] = {
257 .header_type
= IW_HEADER_TYPE_PARAM
,
259 [SIOCGIWFRAG
- SIOCIWFIRST
] = {
260 .header_type
= IW_HEADER_TYPE_PARAM
,
262 [SIOCSIWTXPOW
- SIOCIWFIRST
] = {
263 .header_type
= IW_HEADER_TYPE_PARAM
,
265 [SIOCGIWTXPOW
- SIOCIWFIRST
] = {
266 .header_type
= IW_HEADER_TYPE_PARAM
,
268 [SIOCSIWRETRY
- SIOCIWFIRST
] = {
269 .header_type
= IW_HEADER_TYPE_PARAM
,
271 [SIOCGIWRETRY
- SIOCIWFIRST
] = {
272 .header_type
= IW_HEADER_TYPE_PARAM
,
274 [SIOCSIWENCODE
- SIOCIWFIRST
] = {
275 .header_type
= IW_HEADER_TYPE_POINT
,
277 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
278 .flags
= IW_DESCR_FLAG_EVENT
| IW_DESCR_FLAG_RESTRICT
,
280 [SIOCGIWENCODE
- SIOCIWFIRST
] = {
281 .header_type
= IW_HEADER_TYPE_POINT
,
283 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
284 .flags
= IW_DESCR_FLAG_DUMP
| IW_DESCR_FLAG_RESTRICT
,
286 [SIOCSIWPOWER
- SIOCIWFIRST
] = {
287 .header_type
= IW_HEADER_TYPE_PARAM
,
289 [SIOCGIWPOWER
- SIOCIWFIRST
] = {
290 .header_type
= IW_HEADER_TYPE_PARAM
,
292 [SIOCSIWGENIE
- SIOCIWFIRST
] = {
293 .header_type
= IW_HEADER_TYPE_POINT
,
295 .max_tokens
= IW_GENERIC_IE_MAX
,
297 [SIOCGIWGENIE
- SIOCIWFIRST
] = {
298 .header_type
= IW_HEADER_TYPE_POINT
,
300 .max_tokens
= IW_GENERIC_IE_MAX
,
302 [SIOCSIWAUTH
- SIOCIWFIRST
] = {
303 .header_type
= IW_HEADER_TYPE_PARAM
,
305 [SIOCGIWAUTH
- SIOCIWFIRST
] = {
306 .header_type
= IW_HEADER_TYPE_PARAM
,
308 [SIOCSIWENCODEEXT
- SIOCIWFIRST
] = {
309 .header_type
= IW_HEADER_TYPE_POINT
,
311 .min_tokens
= sizeof(struct iw_encode_ext
),
312 .max_tokens
= sizeof(struct iw_encode_ext
) +
313 IW_ENCODING_TOKEN_MAX
,
315 [SIOCGIWENCODEEXT
- SIOCIWFIRST
] = {
316 .header_type
= IW_HEADER_TYPE_POINT
,
318 .min_tokens
= sizeof(struct iw_encode_ext
),
319 .max_tokens
= sizeof(struct iw_encode_ext
) +
320 IW_ENCODING_TOKEN_MAX
,
322 [SIOCSIWPMKSA
- SIOCIWFIRST
] = {
323 .header_type
= IW_HEADER_TYPE_POINT
,
325 .min_tokens
= sizeof(struct iw_pmksa
),
326 .max_tokens
= sizeof(struct iw_pmksa
),
329 static const int standard_ioctl_num
= (sizeof(standard_ioctl
) /
330 sizeof(struct iw_ioctl_description
));
333 * Meta-data about all the additional standard Wireless Extension events
336 static const struct iw_ioctl_description standard_event
[] = {
337 [IWEVTXDROP
- IWEVFIRST
] = {
338 .header_type
= IW_HEADER_TYPE_ADDR
,
340 [IWEVQUAL
- IWEVFIRST
] = {
341 .header_type
= IW_HEADER_TYPE_QUAL
,
343 [IWEVCUSTOM
- IWEVFIRST
] = {
344 .header_type
= IW_HEADER_TYPE_POINT
,
346 .max_tokens
= IW_CUSTOM_MAX
,
348 [IWEVREGISTERED
- IWEVFIRST
] = {
349 .header_type
= IW_HEADER_TYPE_ADDR
,
351 [IWEVEXPIRED
- IWEVFIRST
] = {
352 .header_type
= IW_HEADER_TYPE_ADDR
,
354 [IWEVGENIE
- IWEVFIRST
] = {
355 .header_type
= IW_HEADER_TYPE_POINT
,
357 .max_tokens
= IW_GENERIC_IE_MAX
,
359 [IWEVMICHAELMICFAILURE
- IWEVFIRST
] = {
360 .header_type
= IW_HEADER_TYPE_POINT
,
362 .max_tokens
= sizeof(struct iw_michaelmicfailure
),
364 [IWEVASSOCREQIE
- IWEVFIRST
] = {
365 .header_type
= IW_HEADER_TYPE_POINT
,
367 .max_tokens
= IW_GENERIC_IE_MAX
,
369 [IWEVASSOCRESPIE
- IWEVFIRST
] = {
370 .header_type
= IW_HEADER_TYPE_POINT
,
372 .max_tokens
= IW_GENERIC_IE_MAX
,
374 [IWEVPMKIDCAND
- IWEVFIRST
] = {
375 .header_type
= IW_HEADER_TYPE_POINT
,
377 .max_tokens
= sizeof(struct iw_pmkid_cand
),
380 static const int standard_event_num
= (sizeof(standard_event
) /
381 sizeof(struct iw_ioctl_description
));
383 /* Size (in bytes) of the various private data types */
384 static const char iw_priv_type_size
[] = {
385 0, /* IW_PRIV_TYPE_NONE */
386 1, /* IW_PRIV_TYPE_BYTE */
387 1, /* IW_PRIV_TYPE_CHAR */
389 sizeof(__u32
), /* IW_PRIV_TYPE_INT */
390 sizeof(struct iw_freq
), /* IW_PRIV_TYPE_FLOAT */
391 sizeof(struct sockaddr
), /* IW_PRIV_TYPE_ADDR */
395 /* Size (in bytes) of various events */
396 static const int event_type_size
[] = {
397 IW_EV_LCP_LEN
, /* IW_HEADER_TYPE_NULL */
399 IW_EV_CHAR_LEN
, /* IW_HEADER_TYPE_CHAR */
401 IW_EV_UINT_LEN
, /* IW_HEADER_TYPE_UINT */
402 IW_EV_FREQ_LEN
, /* IW_HEADER_TYPE_FREQ */
403 IW_EV_ADDR_LEN
, /* IW_HEADER_TYPE_ADDR */
405 IW_EV_POINT_LEN
, /* Without variable payload */
406 IW_EV_PARAM_LEN
, /* IW_HEADER_TYPE_PARAM */
407 IW_EV_QUAL_LEN
, /* IW_HEADER_TYPE_QUAL */
410 /************************ COMMON SUBROUTINES ************************/
412 * Stuff that may be used in various place or doesn't fit in one
413 * of the section below.
416 /* ---------------------------------------------------------------- */
418 * Return the driver handler associated with a specific Wireless Extension.
419 * Called from various place, so make sure it remains efficient.
421 static inline iw_handler
get_handler(struct net_device
*dev
,
424 /* Don't "optimise" the following variable, it will crash */
425 unsigned int index
; /* *MUST* be unsigned */
427 /* Check if we have some wireless handlers defined */
428 if(dev
->wireless_handlers
== NULL
)
431 /* Try as a standard command */
432 index
= cmd
- SIOCIWFIRST
;
433 if(index
< dev
->wireless_handlers
->num_standard
)
434 return dev
->wireless_handlers
->standard
[index
];
436 /* Try as a private command */
437 index
= cmd
- SIOCIWFIRSTPRIV
;
438 if(index
< dev
->wireless_handlers
->num_private
)
439 return dev
->wireless_handlers
->private[index
];
445 /* ---------------------------------------------------------------- */
447 * Get statistics out of the driver
449 static inline struct iw_statistics
*get_wireless_stats(struct net_device
*dev
)
452 if((dev
->wireless_handlers
!= NULL
) &&
453 (dev
->wireless_handlers
->get_wireless_stats
!= NULL
))
454 return dev
->wireless_handlers
->get_wireless_stats(dev
);
456 /* Old location, field to be removed in next WE */
457 if(dev
->get_wireless_stats
) {
458 printk(KERN_DEBUG
"%s (WE) : Driver using old /proc/net/wireless support, please fix driver !\n",
460 return dev
->get_wireless_stats(dev
);
463 return (struct iw_statistics
*) NULL
;
466 /* ---------------------------------------------------------------- */
468 * Call the commit handler in the driver
469 * (if exist and if conditions are right)
471 * Note : our current commit strategy is currently pretty dumb,
472 * but we will be able to improve on that...
473 * The goal is to try to agreagate as many changes as possible
474 * before doing the commit. Drivers that will define a commit handler
475 * are usually those that need a reset after changing parameters, so
476 * we want to minimise the number of reset.
477 * A cool idea is to use a timer : at each "set" command, we re-set the
478 * timer, when the timer eventually fires, we call the driver.
479 * Hopefully, more on that later.
481 * Also, I'm waiting to see how many people will complain about the
482 * netif_running(dev) test. I'm open on that one...
483 * Hopefully, the driver will remember to do a commit in "open()" ;-)
485 static inline int call_commit_handler(struct net_device
* dev
)
487 if((netif_running(dev
)) &&
488 (dev
->wireless_handlers
->standard
[0] != NULL
)) {
489 /* Call the commit handler on the driver */
490 return dev
->wireless_handlers
->standard
[0](dev
, NULL
,
493 return 0; /* Command completed successfully */
496 /* ---------------------------------------------------------------- */
498 * Calculate size of private arguments
500 static inline int get_priv_size(__u16 args
)
502 int num
= args
& IW_PRIV_SIZE_MASK
;
503 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
505 return num
* iw_priv_type_size
[type
];
508 /* ---------------------------------------------------------------- */
510 * Re-calculate the size of private arguments
512 static inline int adjust_priv_size(__u16 args
,
513 union iwreq_data
* wrqu
)
515 int num
= wrqu
->data
.length
;
516 int max
= args
& IW_PRIV_SIZE_MASK
;
517 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
519 /* Make sure the driver doesn't goof up */
523 return num
* iw_priv_type_size
[type
];
527 /******************** /proc/net/wireless SUPPORT ********************/
529 * The /proc/net/wireless file is a human readable user-space interface
530 * exporting various wireless specific statistics from the wireless devices.
531 * This is the most popular part of the Wireless Extensions ;-)
533 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
534 * The content of the file is basically the content of "struct iw_statistics".
537 #ifdef CONFIG_PROC_FS
539 /* ---------------------------------------------------------------- */
541 * Print one entry (line) of /proc/net/wireless
543 static __inline__
void wireless_seq_printf_stats(struct seq_file
*seq
,
544 struct net_device
*dev
)
546 /* Get stats from the driver */
547 struct iw_statistics
*stats
= get_wireless_stats(dev
);
550 seq_printf(seq
, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
552 dev
->name
, stats
->status
, stats
->qual
.qual
,
553 stats
->qual
.updated
& IW_QUAL_QUAL_UPDATED
555 ((__s32
) stats
->qual
.level
) -
556 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
557 stats
->qual
.updated
& IW_QUAL_LEVEL_UPDATED
559 ((__s32
) stats
->qual
.noise
) -
560 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
561 stats
->qual
.updated
& IW_QUAL_NOISE_UPDATED
563 stats
->discard
.nwid
, stats
->discard
.code
,
564 stats
->discard
.fragment
, stats
->discard
.retries
,
565 stats
->discard
.misc
, stats
->miss
.beacon
);
566 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
570 /* ---------------------------------------------------------------- */
572 * Print info for /proc/net/wireless (print all entries)
574 static int wireless_seq_show(struct seq_file
*seq
, void *v
)
576 if (v
== SEQ_START_TOKEN
)
577 seq_printf(seq
, "Inter-| sta-| Quality | Discarded "
578 "packets | Missed | WE\n"
579 " face | tus | link level noise | nwid "
580 "crypt frag retry misc | beacon | %d\n",
583 wireless_seq_printf_stats(seq
, v
);
587 static struct seq_operations wireless_seq_ops
= {
588 .start
= dev_seq_start
,
589 .next
= dev_seq_next
,
590 .stop
= dev_seq_stop
,
591 .show
= wireless_seq_show
,
594 static int wireless_seq_open(struct inode
*inode
, struct file
*file
)
596 return seq_open(file
, &wireless_seq_ops
);
599 static struct file_operations wireless_seq_fops
= {
600 .owner
= THIS_MODULE
,
601 .open
= wireless_seq_open
,
604 .release
= seq_release
,
607 int __init
wireless_proc_init(void)
609 /* Create /proc/net/wireless entry */
610 if (!proc_net_fops_create("wireless", S_IRUGO
, &wireless_seq_fops
))
615 #endif /* CONFIG_PROC_FS */
617 /************************** IOCTL SUPPORT **************************/
619 * The original user space API to configure all those Wireless Extensions
621 * In there, we check if we need to call the new driver API (iw_handler)
622 * or just call the driver ioctl handler.
625 /* ---------------------------------------------------------------- */
627 * Allow programatic access to /proc/net/wireless even if /proc
628 * doesn't exist... Also more efficient...
630 static inline int dev_iwstats(struct net_device
*dev
, struct ifreq
*ifr
)
632 /* Get stats from the driver */
633 struct iw_statistics
*stats
;
635 stats
= get_wireless_stats(dev
);
636 if (stats
!= (struct iw_statistics
*) NULL
) {
637 struct iwreq
* wrq
= (struct iwreq
*)ifr
;
639 /* Copy statistics to the user buffer */
640 if(copy_to_user(wrq
->u
.data
.pointer
, stats
,
641 sizeof(struct iw_statistics
)))
644 /* Check if we need to clear the updated flag */
645 if(wrq
->u
.data
.flags
!= 0)
646 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
652 /* ---------------------------------------------------------------- */
654 * Export the driver private handler definition
655 * They will be picked up by tools like iwpriv...
657 static inline int ioctl_export_private(struct net_device
* dev
,
660 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
662 /* Check if the driver has something to export */
663 if((dev
->wireless_handlers
->num_private_args
== 0) ||
664 (dev
->wireless_handlers
->private_args
== NULL
))
667 /* Check NULL pointer */
668 if(iwr
->u
.data
.pointer
== NULL
)
671 /* Check if there is enough buffer up there */
672 if(iwr
->u
.data
.length
< dev
->wireless_handlers
->num_private_args
) {
673 /* User space can't know in advance how large the buffer
674 * needs to be. Give it a hint, so that we can support
675 * any size buffer we want somewhat efficiently... */
676 iwr
->u
.data
.length
= dev
->wireless_handlers
->num_private_args
;
680 /* Set the number of available ioctls. */
681 iwr
->u
.data
.length
= dev
->wireless_handlers
->num_private_args
;
683 /* Copy structure to the user buffer. */
684 if (copy_to_user(iwr
->u
.data
.pointer
,
685 dev
->wireless_handlers
->private_args
,
686 sizeof(struct iw_priv_args
) * iwr
->u
.data
.length
))
692 /* ---------------------------------------------------------------- */
694 * Wrapper to call a standard Wireless Extension handler.
695 * We do various checks and also take care of moving data between
696 * user space and kernel space.
698 static inline int ioctl_standard_call(struct net_device
* dev
,
703 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
704 const struct iw_ioctl_description
* descr
;
705 struct iw_request_info info
;
708 /* Get the description of the IOCTL */
709 if((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
711 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
713 #ifdef WE_IOCTL_DEBUG
714 printk(KERN_DEBUG
"%s (WE) : Found standard handler for 0x%04X\n",
716 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
);
717 #endif /* WE_IOCTL_DEBUG */
719 /* Prepare the call */
723 /* Check if we have a pointer to user space data or not */
724 if(descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
726 /* No extra arguments. Trivial to handle */
727 ret
= handler(dev
, &info
, &(iwr
->u
), NULL
);
730 /* Generate an event to notify listeners of the change */
731 if((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
732 ((ret
== 0) || (ret
== -EIWCOMMIT
)))
733 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
734 #endif /* WE_SET_EVENT */
741 /* Calculate space needed by arguments. Always allocate
742 * for max space. Easier, and won't last long... */
743 extra_size
= descr
->max_tokens
* descr
->token_size
;
745 /* Check what user space is giving us */
747 /* Check NULL pointer */
748 if((iwr
->u
.data
.pointer
== NULL
) &&
749 (iwr
->u
.data
.length
!= 0))
751 /* Check if number of token fits within bounds */
752 if(iwr
->u
.data
.length
> descr
->max_tokens
)
754 if(iwr
->u
.data
.length
< descr
->min_tokens
)
757 /* Check NULL pointer */
758 if(iwr
->u
.data
.pointer
== NULL
)
760 /* Save user space buffer size for checking */
761 user_length
= iwr
->u
.data
.length
;
763 /* Don't check if user_length > max to allow forward
764 * compatibility. The test user_length < min is
765 * implied by the test at the end. */
767 /* Support for very large requests */
768 if((descr
->flags
& IW_DESCR_FLAG_NOMAX
) &&
769 (user_length
> descr
->max_tokens
)) {
770 /* Allow userspace to GET more than max so
771 * we can support any size GET requests.
772 * There is still a limit : -ENOMEM. */
773 extra_size
= user_length
* descr
->token_size
;
774 /* Note : user_length is originally a __u16,
775 * and token_size is controlled by us,
776 * so extra_size won't get negative and
777 * won't overflow... */
781 #ifdef WE_IOCTL_DEBUG
782 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
783 dev
->name
, extra_size
);
784 #endif /* WE_IOCTL_DEBUG */
786 /* Create the kernel buffer */
787 extra
= kmalloc(extra_size
, GFP_KERNEL
);
792 /* If it is a SET, get all the extra data in here */
793 if(IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
794 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
801 #ifdef WE_IOCTL_DEBUG
802 printk(KERN_DEBUG
"%s (WE) : Got %d bytes\n",
804 iwr
->u
.data
.length
* descr
->token_size
);
805 #endif /* WE_IOCTL_DEBUG */
808 /* Call the handler */
809 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
811 /* If we have something to return to the user */
812 if (!ret
&& IW_IS_GET(cmd
)) {
813 /* Check if there is enough buffer up there */
814 if(user_length
< iwr
->u
.data
.length
) {
819 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
824 #ifdef WE_IOCTL_DEBUG
825 printk(KERN_DEBUG
"%s (WE) : Wrote %d bytes\n",
827 iwr
->u
.data
.length
* descr
->token_size
);
828 #endif /* WE_IOCTL_DEBUG */
832 /* Generate an event to notify listeners of the change */
833 if((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
834 ((ret
== 0) || (ret
== -EIWCOMMIT
))) {
835 if(descr
->flags
& IW_DESCR_FLAG_RESTRICT
)
836 /* If the event is restricted, don't
837 * export the payload */
838 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
840 wireless_send_event(dev
, cmd
, &(iwr
->u
),
843 #endif /* WE_SET_EVENT */
845 /* Cleanup - I told you it wasn't that long ;-) */
849 /* Call commit handler if needed and defined */
850 if(ret
== -EIWCOMMIT
)
851 ret
= call_commit_handler(dev
);
853 /* Here, we will generate the appropriate event if needed */
858 /* ---------------------------------------------------------------- */
860 * Wrapper to call a private Wireless Extension handler.
861 * We do various checks and also take care of moving data between
862 * user space and kernel space.
863 * It's not as nice and slimline as the standard wrapper. The cause
864 * is struct iw_priv_args, which was not really designed for the
865 * job we are going here.
867 * IMPORTANT : This function prevent to set and get data on the same
868 * IOCTL and enforce the SET/GET convention. Not doing it would be
870 * If you need to set and get data at the same time, please don't use
871 * a iw_handler but process it in your ioctl handler (i.e. use the
874 static inline int ioctl_private_call(struct net_device
* dev
,
879 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
880 const struct iw_priv_args
* descr
= NULL
;
881 struct iw_request_info info
;
886 /* Get the description of the IOCTL */
887 for(i
= 0; i
< dev
->wireless_handlers
->num_private_args
; i
++)
888 if(cmd
== dev
->wireless_handlers
->private_args
[i
].cmd
) {
889 descr
= &(dev
->wireless_handlers
->private_args
[i
]);
893 #ifdef WE_IOCTL_DEBUG
894 printk(KERN_DEBUG
"%s (WE) : Found private handler for 0x%04X\n",
897 printk(KERN_DEBUG
"%s (WE) : Name %s, set %X, get %X\n",
898 dev
->name
, descr
->name
,
899 descr
->set_args
, descr
->get_args
);
901 #endif /* WE_IOCTL_DEBUG */
903 /* Compute the size of the set/get arguments */
906 int offset
= 0; /* For sub-ioctls */
907 /* Check for sub-ioctl handler */
908 if(descr
->name
[0] == '\0')
909 /* Reserve one int for sub-ioctl index */
910 offset
= sizeof(__u32
);
912 /* Size of set arguments */
913 extra_size
= get_priv_size(descr
->set_args
);
915 /* Does it fits in iwr ? */
916 if((descr
->set_args
& IW_PRIV_SIZE_FIXED
) &&
917 ((extra_size
+ offset
) <= IFNAMSIZ
))
920 /* Size of get arguments */
921 extra_size
= get_priv_size(descr
->get_args
);
923 /* Does it fits in iwr ? */
924 if((descr
->get_args
& IW_PRIV_SIZE_FIXED
) &&
925 (extra_size
<= IFNAMSIZ
))
930 /* Prepare the call */
934 /* Check if we have a pointer to user space data or not. */
935 if(extra_size
== 0) {
936 /* No extra arguments. Trivial to handle */
937 ret
= handler(dev
, &info
, &(iwr
->u
), (char *) &(iwr
->u
));
942 /* Check what user space is giving us */
944 /* Check NULL pointer */
945 if((iwr
->u
.data
.pointer
== NULL
) &&
946 (iwr
->u
.data
.length
!= 0))
949 /* Does it fits within bounds ? */
950 if(iwr
->u
.data
.length
> (descr
->set_args
&
954 /* Check NULL pointer */
955 if(iwr
->u
.data
.pointer
== NULL
)
959 #ifdef WE_IOCTL_DEBUG
960 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
961 dev
->name
, extra_size
);
962 #endif /* WE_IOCTL_DEBUG */
964 /* Always allocate for max space. Easier, and won't last
966 extra
= kmalloc(extra_size
, GFP_KERNEL
);
971 /* If it is a SET, get all the extra data in here */
972 if(IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
973 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
979 #ifdef WE_IOCTL_DEBUG
980 printk(KERN_DEBUG
"%s (WE) : Got %d elem\n",
981 dev
->name
, iwr
->u
.data
.length
);
982 #endif /* WE_IOCTL_DEBUG */
985 /* Call the handler */
986 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
988 /* If we have something to return to the user */
989 if (!ret
&& IW_IS_GET(cmd
)) {
991 /* Adjust for the actual length if it's variable,
992 * avoid leaking kernel bits outside. */
993 if (!(descr
->get_args
& IW_PRIV_SIZE_FIXED
)) {
994 extra_size
= adjust_priv_size(descr
->get_args
,
998 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
1002 #ifdef WE_IOCTL_DEBUG
1003 printk(KERN_DEBUG
"%s (WE) : Wrote %d elem\n",
1004 dev
->name
, iwr
->u
.data
.length
);
1005 #endif /* WE_IOCTL_DEBUG */
1008 /* Cleanup - I told you it wasn't that long ;-) */
1013 /* Call commit handler if needed and defined */
1014 if(ret
== -EIWCOMMIT
)
1015 ret
= call_commit_handler(dev
);
1020 /* ---------------------------------------------------------------- */
1022 * Main IOCTl dispatcher. Called from the main networking code
1023 * (dev_ioctl() in net/core/dev.c).
1024 * Check the type of IOCTL and call the appropriate wrapper...
1026 int wireless_process_ioctl(struct ifreq
*ifr
, unsigned int cmd
)
1028 struct net_device
*dev
;
1031 /* Permissions are already checked in dev_ioctl() before calling us.
1032 * The copy_to/from_user() of ifr is also dealt with in there */
1034 /* Make sure the device exist */
1035 if ((dev
= __dev_get_by_name(ifr
->ifr_name
)) == NULL
)
1038 /* A bunch of special cases, then the generic case...
1039 * Note that 'cmd' is already filtered in dev_ioctl() with
1040 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1044 /* Get Wireless Stats */
1045 return dev_iwstats(dev
, ifr
);
1048 /* Check if we have some wireless handlers defined */
1049 if(dev
->wireless_handlers
!= NULL
) {
1050 /* We export to user space the definition of
1051 * the private handler ourselves */
1052 return ioctl_export_private(dev
, ifr
);
1054 // ## Fall-through for old API ##
1058 if (!netif_device_present(dev
))
1060 /* New driver API : try to find the handler */
1061 handler
= get_handler(dev
, cmd
);
1062 if(handler
!= NULL
) {
1063 /* Standard and private are not the same */
1064 if(cmd
< SIOCIWFIRSTPRIV
)
1065 return ioctl_standard_call(dev
,
1070 return ioctl_private_call(dev
,
1075 /* Old driver API : call driver ioctl handler */
1076 if (dev
->do_ioctl
) {
1077 return dev
->do_ioctl(dev
, ifr
, cmd
);
1085 /************************* EVENT PROCESSING *************************/
1087 * Process events generated by the wireless layer or the driver.
1088 * Most often, the event will be propagated through rtnetlink
1091 #ifdef WE_EVENT_NETLINK
1092 /* "rtnl" is defined in net/core/rtnetlink.c, but we need it here.
1093 * It is declared in <linux/rtnetlink.h> */
1095 /* ---------------------------------------------------------------- */
1097 * Fill a rtnetlink message with our event data.
1098 * Note that we propage only the specified event and don't dump the
1099 * current wireless config. Dumping the wireless config is far too
1100 * expensive (for each parameter, the driver need to query the hardware).
1102 static inline int rtnetlink_fill_iwinfo(struct sk_buff
* skb
,
1103 struct net_device
* dev
,
1108 struct ifinfomsg
*r
;
1109 struct nlmsghdr
*nlh
;
1110 unsigned char *b
= skb
->tail
;
1112 nlh
= NLMSG_PUT(skb
, 0, 0, type
, sizeof(*r
));
1113 r
= NLMSG_DATA(nlh
);
1114 r
->ifi_family
= AF_UNSPEC
;
1116 r
->ifi_type
= dev
->type
;
1117 r
->ifi_index
= dev
->ifindex
;
1118 r
->ifi_flags
= dev
->flags
;
1119 r
->ifi_change
= 0; /* Wireless changes don't affect those flags */
1121 /* Add the wireless events in the netlink packet */
1122 RTA_PUT(skb
, IFLA_WIRELESS
,
1125 nlh
->nlmsg_len
= skb
->tail
- b
;
1130 skb_trim(skb
, b
- skb
->data
);
1134 /* ---------------------------------------------------------------- */
1136 * Create and broadcast and send it on the standard rtnetlink socket
1137 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1138 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1139 * within a RTM_NEWLINK event.
1141 static inline void rtmsg_iwinfo(struct net_device
* dev
,
1145 struct sk_buff
*skb
;
1146 int size
= NLMSG_GOODSIZE
;
1148 skb
= alloc_skb(size
, GFP_ATOMIC
);
1152 if (rtnetlink_fill_iwinfo(skb
, dev
, RTM_NEWLINK
,
1153 event
, event_len
) < 0) {
1157 NETLINK_CB(skb
).dst_group
= RTNLGRP_LINK
;
1158 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_LINK
, GFP_ATOMIC
);
1160 #endif /* WE_EVENT_NETLINK */
1162 /* ---------------------------------------------------------------- */
1164 * Main event dispatcher. Called from other parts and drivers.
1165 * Send the event on the appropriate channels.
1166 * May be called from interrupt context.
1168 void wireless_send_event(struct net_device
* dev
,
1170 union iwreq_data
* wrqu
,
1173 const struct iw_ioctl_description
* descr
= NULL
;
1175 struct iw_event
*event
; /* Mallocated whole event */
1176 int event_len
; /* Its size */
1177 int hdr_len
; /* Size of the event header */
1178 int wrqu_off
= 0; /* Offset in wrqu */
1179 /* Don't "optimise" the following variable, it will crash */
1180 unsigned cmd_index
; /* *MUST* be unsigned */
1182 /* Get the description of the Event */
1183 if(cmd
<= SIOCIWLAST
) {
1184 cmd_index
= cmd
- SIOCIWFIRST
;
1185 if(cmd_index
< standard_ioctl_num
)
1186 descr
= &(standard_ioctl
[cmd_index
]);
1188 cmd_index
= cmd
- IWEVFIRST
;
1189 if(cmd_index
< standard_event_num
)
1190 descr
= &(standard_event
[cmd_index
]);
1192 /* Don't accept unknown events */
1194 /* Note : we don't return an error to the driver, because
1195 * the driver would not know what to do about it. It can't
1196 * return an error to the user, because the event is not
1197 * initiated by a user request.
1198 * The best the driver could do is to log an error message.
1199 * We will do it ourselves instead...
1201 printk(KERN_ERR
"%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1205 #ifdef WE_EVENT_DEBUG
1206 printk(KERN_DEBUG
"%s (WE) : Got event 0x%04X\n",
1208 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
);
1209 #endif /* WE_EVENT_DEBUG */
1211 /* Check extra parameters and set extra_len */
1212 if(descr
->header_type
== IW_HEADER_TYPE_POINT
) {
1213 /* Check if number of token fits within bounds */
1214 if(wrqu
->data
.length
> descr
->max_tokens
) {
1215 printk(KERN_ERR
"%s (WE) : Wireless Event too big (%d)\n", dev
->name
, wrqu
->data
.length
);
1218 if(wrqu
->data
.length
< descr
->min_tokens
) {
1219 printk(KERN_ERR
"%s (WE) : Wireless Event too small (%d)\n", dev
->name
, wrqu
->data
.length
);
1222 /* Calculate extra_len - extra is NULL for restricted events */
1224 extra_len
= wrqu
->data
.length
* descr
->token_size
;
1225 /* Always at an offset in wrqu */
1226 wrqu_off
= IW_EV_POINT_OFF
;
1227 #ifdef WE_EVENT_DEBUG
1228 printk(KERN_DEBUG
"%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev
->name
, cmd
, wrqu
->data
.length
, extra_len
);
1229 #endif /* WE_EVENT_DEBUG */
1232 /* Total length of the event */
1233 hdr_len
= event_type_size
[descr
->header_type
];
1234 event_len
= hdr_len
+ extra_len
;
1236 #ifdef WE_EVENT_DEBUG
1237 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
);
1238 #endif /* WE_EVENT_DEBUG */
1240 /* Create temporary buffer to hold the event */
1241 event
= kmalloc(event_len
, GFP_ATOMIC
);
1246 event
->len
= event_len
;
1248 memcpy(&event
->u
, ((char *) wrqu
) + wrqu_off
, hdr_len
- IW_EV_LCP_LEN
);
1250 memcpy(((char *) event
) + hdr_len
, extra
, extra_len
);
1252 #ifdef WE_EVENT_NETLINK
1253 /* rtnetlink event channel */
1254 rtmsg_iwinfo(dev
, (char *) event
, event_len
);
1255 #endif /* WE_EVENT_NETLINK */
1260 return; /* Always success, I guess ;-) */
1263 /********************** ENHANCED IWSPY SUPPORT **********************/
1265 * In the old days, the driver was handling spy support all by itself.
1266 * Now, the driver can delegate this task to Wireless Extensions.
1267 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1268 * push data to us via wireless_spy_update() and include struct iw_spy_data
1269 * in its private part (and export it in net_device->wireless_data->spy_data).
1270 * One of the main advantage of centralising spy support here is that
1271 * it becomes much easier to improve and extend it without having to touch
1272 * the drivers. One example is the addition of the Spy-Threshold events.
1275 /* ---------------------------------------------------------------- */
1277 * Return the pointer to the spy data in the driver.
1278 * Because this is called on the Rx path via wireless_spy_update(),
1279 * we want it to be efficient...
1281 static inline struct iw_spy_data
* get_spydata(struct net_device
*dev
)
1283 /* This is the new way */
1284 if(dev
->wireless_data
)
1285 return(dev
->wireless_data
->spy_data
);
1289 /*------------------------------------------------------------------*/
1291 * Standard Wireless Handler : set Spy List
1293 int iw_handler_set_spy(struct net_device
* dev
,
1294 struct iw_request_info
* info
,
1295 union iwreq_data
* wrqu
,
1298 struct iw_spy_data
* spydata
= get_spydata(dev
);
1299 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1301 /* Make sure driver is not buggy or using the old API */
1305 /* Disable spy collection while we copy the addresses.
1306 * While we copy addresses, any call to wireless_spy_update()
1307 * will NOP. This is OK, as anyway the addresses are changing. */
1308 spydata
->spy_number
= 0;
1310 /* We want to operate without locking, because wireless_spy_update()
1311 * most likely will happen in the interrupt handler, and therefore
1312 * have its own locking constraints and needs performance.
1313 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1314 * This make sure wireless_spy_update() "see" that the spy list
1315 * is temporarily disabled. */
1318 /* Are there are addresses to copy? */
1319 if(wrqu
->data
.length
> 0) {
1322 /* Copy addresses */
1323 for(i
= 0; i
< wrqu
->data
.length
; i
++)
1324 memcpy(spydata
->spy_address
[i
], address
[i
].sa_data
,
1327 memset(spydata
->spy_stat
, 0,
1328 sizeof(struct iw_quality
) * IW_MAX_SPY
);
1331 printk(KERN_DEBUG
"iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev
->wireless_data
, spydata
, wrqu
->data
.length
);
1332 for (i
= 0; i
< wrqu
->data
.length
; i
++)
1334 "%02X:%02X:%02X:%02X:%02X:%02X \n",
1335 spydata
->spy_address
[i
][0],
1336 spydata
->spy_address
[i
][1],
1337 spydata
->spy_address
[i
][2],
1338 spydata
->spy_address
[i
][3],
1339 spydata
->spy_address
[i
][4],
1340 spydata
->spy_address
[i
][5]);
1341 #endif /* WE_SPY_DEBUG */
1344 /* Make sure above is updated before re-enabling */
1347 /* Enable addresses */
1348 spydata
->spy_number
= wrqu
->data
.length
;
1353 /*------------------------------------------------------------------*/
1355 * Standard Wireless Handler : get Spy List
1357 int iw_handler_get_spy(struct net_device
* dev
,
1358 struct iw_request_info
* info
,
1359 union iwreq_data
* wrqu
,
1362 struct iw_spy_data
* spydata
= get_spydata(dev
);
1363 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1366 /* Make sure driver is not buggy or using the old API */
1370 wrqu
->data
.length
= spydata
->spy_number
;
1372 /* Copy addresses. */
1373 for(i
= 0; i
< spydata
->spy_number
; i
++) {
1374 memcpy(address
[i
].sa_data
, spydata
->spy_address
[i
], ETH_ALEN
);
1375 address
[i
].sa_family
= AF_UNIX
;
1377 /* Copy stats to the user buffer (just after). */
1378 if(spydata
->spy_number
> 0)
1379 memcpy(extra
+ (sizeof(struct sockaddr
) *spydata
->spy_number
),
1381 sizeof(struct iw_quality
) * spydata
->spy_number
);
1382 /* Reset updated flags. */
1383 for(i
= 0; i
< spydata
->spy_number
; i
++)
1384 spydata
->spy_stat
[i
].updated
&= ~IW_QUAL_ALL_UPDATED
;
1388 /*------------------------------------------------------------------*/
1390 * Standard Wireless Handler : set spy threshold
1392 int iw_handler_set_thrspy(struct net_device
* dev
,
1393 struct iw_request_info
*info
,
1394 union iwreq_data
* wrqu
,
1397 struct iw_spy_data
* spydata
= get_spydata(dev
);
1398 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1400 /* Make sure driver is not buggy or using the old API */
1405 memcpy(&(spydata
->spy_thr_low
), &(threshold
->low
),
1406 2 * sizeof(struct iw_quality
));
1409 memset(spydata
->spy_thr_under
, '\0', sizeof(spydata
->spy_thr_under
));
1412 printk(KERN_DEBUG
"iw_handler_set_thrspy() : low %d ; high %d\n", spydata
->spy_thr_low
.level
, spydata
->spy_thr_high
.level
);
1413 #endif /* WE_SPY_DEBUG */
1418 /*------------------------------------------------------------------*/
1420 * Standard Wireless Handler : get spy threshold
1422 int iw_handler_get_thrspy(struct net_device
* dev
,
1423 struct iw_request_info
*info
,
1424 union iwreq_data
* wrqu
,
1427 struct iw_spy_data
* spydata
= get_spydata(dev
);
1428 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1430 /* Make sure driver is not buggy or using the old API */
1435 memcpy(&(threshold
->low
), &(spydata
->spy_thr_low
),
1436 2 * sizeof(struct iw_quality
));
1441 /*------------------------------------------------------------------*/
1443 * Prepare and send a Spy Threshold event
1445 static void iw_send_thrspy_event(struct net_device
* dev
,
1446 struct iw_spy_data
* spydata
,
1447 unsigned char * address
,
1448 struct iw_quality
* wstats
)
1450 union iwreq_data wrqu
;
1451 struct iw_thrspy threshold
;
1454 wrqu
.data
.length
= 1;
1455 wrqu
.data
.flags
= 0;
1457 memcpy(threshold
.addr
.sa_data
, address
, ETH_ALEN
);
1458 threshold
.addr
.sa_family
= ARPHRD_ETHER
;
1460 memcpy(&(threshold
.qual
), wstats
, sizeof(struct iw_quality
));
1461 /* Copy also thresholds */
1462 memcpy(&(threshold
.low
), &(spydata
->spy_thr_low
),
1463 2 * sizeof(struct iw_quality
));
1466 printk(KERN_DEBUG
"iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
1467 threshold
.addr
.sa_data
[0],
1468 threshold
.addr
.sa_data
[1],
1469 threshold
.addr
.sa_data
[2],
1470 threshold
.addr
.sa_data
[3],
1471 threshold
.addr
.sa_data
[4],
1472 threshold
.addr
.sa_data
[5], threshold
.qual
.level
);
1473 #endif /* WE_SPY_DEBUG */
1475 /* Send event to user space */
1476 wireless_send_event(dev
, SIOCGIWTHRSPY
, &wrqu
, (char *) &threshold
);
1479 /* ---------------------------------------------------------------- */
1481 * Call for the driver to update the spy data.
1482 * For now, the spy data is a simple array. As the size of the array is
1483 * small, this is good enough. If we wanted to support larger number of
1484 * spy addresses, we should use something more efficient...
1486 void wireless_spy_update(struct net_device
* dev
,
1487 unsigned char * address
,
1488 struct iw_quality
* wstats
)
1490 struct iw_spy_data
* spydata
= get_spydata(dev
);
1494 /* Make sure driver is not buggy or using the old API */
1499 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]);
1500 #endif /* WE_SPY_DEBUG */
1502 /* Update all records that match */
1503 for(i
= 0; i
< spydata
->spy_number
; i
++)
1504 if(!memcmp(address
, spydata
->spy_address
[i
], ETH_ALEN
)) {
1505 memcpy(&(spydata
->spy_stat
[i
]), wstats
,
1506 sizeof(struct iw_quality
));
1510 /* Generate an event if we cross the spy threshold.
1511 * To avoid event storms, we have a simple hysteresis : we generate
1512 * event only when we go under the low threshold or above the
1513 * high threshold. */
1515 if(spydata
->spy_thr_under
[match
]) {
1516 if(wstats
->level
> spydata
->spy_thr_high
.level
) {
1517 spydata
->spy_thr_under
[match
] = 0;
1518 iw_send_thrspy_event(dev
, spydata
,
1522 if(wstats
->level
< spydata
->spy_thr_low
.level
) {
1523 spydata
->spy_thr_under
[match
] = 1;
1524 iw_send_thrspy_event(dev
, spydata
,
1531 EXPORT_SYMBOL(iw_handler_get_spy
);
1532 EXPORT_SYMBOL(iw_handler_get_thrspy
);
1533 EXPORT_SYMBOL(iw_handler_set_spy
);
1534 EXPORT_SYMBOL(iw_handler_set_thrspy
);
1535 EXPORT_SYMBOL(wireless_send_event
);
1536 EXPORT_SYMBOL(wireless_spy_update
);