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
63 /***************************** INCLUDES *****************************/
65 #include <linux/config.h> /* Not needed ??? */
66 #include <linux/module.h>
67 #include <linux/types.h> /* off_t */
68 #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
69 #include <linux/proc_fs.h>
70 #include <linux/rtnetlink.h> /* rtnetlink stuff */
71 #include <linux/seq_file.h>
72 #include <linux/init.h> /* for __init */
73 #include <linux/if_arp.h> /* ARPHRD_ETHER */
75 #include <linux/wireless.h> /* Pretty obvious */
76 #include <net/iw_handler.h> /* New driver API */
78 #include <asm/uaccess.h> /* copy_to_user() */
80 /**************************** CONSTANTS ****************************/
83 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
84 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
85 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
88 #define WE_EVENT_NETLINK /* Propagate events using rtnetlink */
89 #define WE_SET_EVENT /* Generate an event on some set commands */
91 /************************* GLOBAL VARIABLES *************************/
93 * You should not use global variables, because of re-entrancy.
94 * On our case, it's only const, so it's OK...
97 * Meta-data about all the standard Wireless Extension request we
100 static const struct iw_ioctl_description standard_ioctl
[] = {
101 [SIOCSIWCOMMIT
- SIOCIWFIRST
] = {
102 .header_type
= IW_HEADER_TYPE_NULL
,
104 [SIOCGIWNAME
- SIOCIWFIRST
] = {
105 .header_type
= IW_HEADER_TYPE_CHAR
,
106 .flags
= IW_DESCR_FLAG_DUMP
,
108 [SIOCSIWNWID
- SIOCIWFIRST
] = {
109 .header_type
= IW_HEADER_TYPE_PARAM
,
110 .flags
= IW_DESCR_FLAG_EVENT
,
112 [SIOCGIWNWID
- SIOCIWFIRST
] = {
113 .header_type
= IW_HEADER_TYPE_PARAM
,
114 .flags
= IW_DESCR_FLAG_DUMP
,
116 [SIOCSIWFREQ
- SIOCIWFIRST
] = {
117 .header_type
= IW_HEADER_TYPE_FREQ
,
118 .flags
= IW_DESCR_FLAG_EVENT
,
120 [SIOCGIWFREQ
- SIOCIWFIRST
] = {
121 .header_type
= IW_HEADER_TYPE_FREQ
,
122 .flags
= IW_DESCR_FLAG_DUMP
,
124 [SIOCSIWMODE
- SIOCIWFIRST
] = {
125 .header_type
= IW_HEADER_TYPE_UINT
,
126 .flags
= IW_DESCR_FLAG_EVENT
,
128 [SIOCGIWMODE
- SIOCIWFIRST
] = {
129 .header_type
= IW_HEADER_TYPE_UINT
,
130 .flags
= IW_DESCR_FLAG_DUMP
,
132 [SIOCSIWSENS
- SIOCIWFIRST
] = {
133 .header_type
= IW_HEADER_TYPE_PARAM
,
135 [SIOCGIWSENS
- SIOCIWFIRST
] = {
136 .header_type
= IW_HEADER_TYPE_PARAM
,
138 [SIOCSIWRANGE
- SIOCIWFIRST
] = {
139 .header_type
= IW_HEADER_TYPE_NULL
,
141 [SIOCGIWRANGE
- SIOCIWFIRST
] = {
142 .header_type
= IW_HEADER_TYPE_POINT
,
144 .max_tokens
= sizeof(struct iw_range
),
145 .flags
= IW_DESCR_FLAG_DUMP
,
147 [SIOCSIWPRIV
- SIOCIWFIRST
] = {
148 .header_type
= IW_HEADER_TYPE_NULL
,
150 [SIOCGIWPRIV
- SIOCIWFIRST
] = { /* (handled directly by us) */
151 .header_type
= IW_HEADER_TYPE_NULL
,
153 [SIOCSIWSTATS
- SIOCIWFIRST
] = {
154 .header_type
= IW_HEADER_TYPE_NULL
,
156 [SIOCGIWSTATS
- SIOCIWFIRST
] = { /* (handled directly by us) */
157 .header_type
= IW_HEADER_TYPE_NULL
,
158 .flags
= IW_DESCR_FLAG_DUMP
,
160 [SIOCSIWSPY
- SIOCIWFIRST
] = {
161 .header_type
= IW_HEADER_TYPE_POINT
,
162 .token_size
= sizeof(struct sockaddr
),
163 .max_tokens
= IW_MAX_SPY
,
165 [SIOCGIWSPY
- SIOCIWFIRST
] = {
166 .header_type
= IW_HEADER_TYPE_POINT
,
167 .token_size
= sizeof(struct sockaddr
) +
168 sizeof(struct iw_quality
),
169 .max_tokens
= IW_MAX_SPY
,
171 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = {
172 .header_type
= IW_HEADER_TYPE_POINT
,
173 .token_size
= sizeof(struct iw_thrspy
),
177 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = {
178 .header_type
= IW_HEADER_TYPE_POINT
,
179 .token_size
= sizeof(struct iw_thrspy
),
183 [SIOCSIWAP
- SIOCIWFIRST
] = {
184 .header_type
= IW_HEADER_TYPE_ADDR
,
186 [SIOCGIWAP
- SIOCIWFIRST
] = {
187 .header_type
= IW_HEADER_TYPE_ADDR
,
188 .flags
= IW_DESCR_FLAG_DUMP
,
190 [SIOCSIWMLME
- SIOCIWFIRST
] = {
191 .header_type
= IW_HEADER_TYPE_POINT
,
193 .min_tokens
= sizeof(struct iw_mlme
),
194 .max_tokens
= sizeof(struct iw_mlme
),
196 [SIOCGIWAPLIST
- SIOCIWFIRST
] = {
197 .header_type
= IW_HEADER_TYPE_POINT
,
198 .token_size
= sizeof(struct sockaddr
) +
199 sizeof(struct iw_quality
),
200 .max_tokens
= IW_MAX_AP
,
201 .flags
= IW_DESCR_FLAG_NOMAX
,
203 [SIOCSIWSCAN
- SIOCIWFIRST
] = {
204 .header_type
= IW_HEADER_TYPE_POINT
,
207 .max_tokens
= sizeof(struct iw_scan_req
),
209 [SIOCGIWSCAN
- SIOCIWFIRST
] = {
210 .header_type
= IW_HEADER_TYPE_POINT
,
212 .max_tokens
= IW_SCAN_MAX_DATA
,
213 .flags
= IW_DESCR_FLAG_NOMAX
,
215 [SIOCSIWESSID
- SIOCIWFIRST
] = {
216 .header_type
= IW_HEADER_TYPE_POINT
,
218 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
219 .flags
= IW_DESCR_FLAG_EVENT
,
221 [SIOCGIWESSID
- SIOCIWFIRST
] = {
222 .header_type
= IW_HEADER_TYPE_POINT
,
224 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
225 .flags
= IW_DESCR_FLAG_DUMP
,
227 [SIOCSIWNICKN
- SIOCIWFIRST
] = {
228 .header_type
= IW_HEADER_TYPE_POINT
,
230 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
232 [SIOCGIWNICKN
- SIOCIWFIRST
] = {
233 .header_type
= IW_HEADER_TYPE_POINT
,
235 .max_tokens
= IW_ESSID_MAX_SIZE
+ 1,
237 [SIOCSIWRATE
- SIOCIWFIRST
] = {
238 .header_type
= IW_HEADER_TYPE_PARAM
,
240 [SIOCGIWRATE
- SIOCIWFIRST
] = {
241 .header_type
= IW_HEADER_TYPE_PARAM
,
243 [SIOCSIWRTS
- SIOCIWFIRST
] = {
244 .header_type
= IW_HEADER_TYPE_PARAM
,
246 [SIOCGIWRTS
- SIOCIWFIRST
] = {
247 .header_type
= IW_HEADER_TYPE_PARAM
,
249 [SIOCSIWFRAG
- SIOCIWFIRST
] = {
250 .header_type
= IW_HEADER_TYPE_PARAM
,
252 [SIOCGIWFRAG
- SIOCIWFIRST
] = {
253 .header_type
= IW_HEADER_TYPE_PARAM
,
255 [SIOCSIWTXPOW
- SIOCIWFIRST
] = {
256 .header_type
= IW_HEADER_TYPE_PARAM
,
258 [SIOCGIWTXPOW
- SIOCIWFIRST
] = {
259 .header_type
= IW_HEADER_TYPE_PARAM
,
261 [SIOCSIWRETRY
- SIOCIWFIRST
] = {
262 .header_type
= IW_HEADER_TYPE_PARAM
,
264 [SIOCGIWRETRY
- SIOCIWFIRST
] = {
265 .header_type
= IW_HEADER_TYPE_PARAM
,
267 [SIOCSIWENCODE
- SIOCIWFIRST
] = {
268 .header_type
= IW_HEADER_TYPE_POINT
,
270 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
271 .flags
= IW_DESCR_FLAG_EVENT
| IW_DESCR_FLAG_RESTRICT
,
273 [SIOCGIWENCODE
- SIOCIWFIRST
] = {
274 .header_type
= IW_HEADER_TYPE_POINT
,
276 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
277 .flags
= IW_DESCR_FLAG_DUMP
| IW_DESCR_FLAG_RESTRICT
,
279 [SIOCSIWPOWER
- SIOCIWFIRST
] = {
280 .header_type
= IW_HEADER_TYPE_PARAM
,
282 [SIOCGIWPOWER
- SIOCIWFIRST
] = {
283 .header_type
= IW_HEADER_TYPE_PARAM
,
285 [SIOCSIWGENIE
- SIOCIWFIRST
] = {
286 .header_type
= IW_HEADER_TYPE_POINT
,
288 .max_tokens
= IW_GENERIC_IE_MAX
,
290 [SIOCGIWGENIE
- SIOCIWFIRST
] = {
291 .header_type
= IW_HEADER_TYPE_POINT
,
293 .max_tokens
= IW_GENERIC_IE_MAX
,
295 [SIOCSIWAUTH
- SIOCIWFIRST
] = {
296 .header_type
= IW_HEADER_TYPE_PARAM
,
298 [SIOCGIWAUTH
- SIOCIWFIRST
] = {
299 .header_type
= IW_HEADER_TYPE_PARAM
,
301 [SIOCSIWENCODEEXT
- SIOCIWFIRST
] = {
302 .header_type
= IW_HEADER_TYPE_POINT
,
304 .min_tokens
= sizeof(struct iw_encode_ext
),
305 .max_tokens
= sizeof(struct iw_encode_ext
) +
306 IW_ENCODING_TOKEN_MAX
,
308 [SIOCGIWENCODEEXT
- 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 [SIOCSIWPMKSA
- SIOCIWFIRST
] = {
316 .header_type
= IW_HEADER_TYPE_POINT
,
318 .min_tokens
= sizeof(struct iw_pmksa
),
319 .max_tokens
= sizeof(struct iw_pmksa
),
322 static const int standard_ioctl_num
= (sizeof(standard_ioctl
) /
323 sizeof(struct iw_ioctl_description
));
326 * Meta-data about all the additional standard Wireless Extension events
329 static const struct iw_ioctl_description standard_event
[] = {
330 [IWEVTXDROP
- IWEVFIRST
] = {
331 .header_type
= IW_HEADER_TYPE_ADDR
,
333 [IWEVQUAL
- IWEVFIRST
] = {
334 .header_type
= IW_HEADER_TYPE_QUAL
,
336 [IWEVCUSTOM
- IWEVFIRST
] = {
337 .header_type
= IW_HEADER_TYPE_POINT
,
339 .max_tokens
= IW_CUSTOM_MAX
,
341 [IWEVREGISTERED
- IWEVFIRST
] = {
342 .header_type
= IW_HEADER_TYPE_ADDR
,
344 [IWEVEXPIRED
- IWEVFIRST
] = {
345 .header_type
= IW_HEADER_TYPE_ADDR
,
347 [IWEVGENIE
- IWEVFIRST
] = {
348 .header_type
= IW_HEADER_TYPE_POINT
,
350 .max_tokens
= IW_GENERIC_IE_MAX
,
352 [IWEVMICHAELMICFAILURE
- IWEVFIRST
] = {
353 .header_type
= IW_HEADER_TYPE_POINT
,
355 .max_tokens
= sizeof(struct iw_michaelmicfailure
),
357 [IWEVASSOCREQIE
- IWEVFIRST
] = {
358 .header_type
= IW_HEADER_TYPE_POINT
,
360 .max_tokens
= IW_GENERIC_IE_MAX
,
362 [IWEVASSOCRESPIE
- IWEVFIRST
] = {
363 .header_type
= IW_HEADER_TYPE_POINT
,
365 .max_tokens
= IW_GENERIC_IE_MAX
,
367 [IWEVPMKIDCAND
- IWEVFIRST
] = {
368 .header_type
= IW_HEADER_TYPE_POINT
,
370 .max_tokens
= sizeof(struct iw_pmkid_cand
),
373 static const int standard_event_num
= (sizeof(standard_event
) /
374 sizeof(struct iw_ioctl_description
));
376 /* Size (in bytes) of the various private data types */
377 static const char iw_priv_type_size
[] = {
378 0, /* IW_PRIV_TYPE_NONE */
379 1, /* IW_PRIV_TYPE_BYTE */
380 1, /* IW_PRIV_TYPE_CHAR */
382 sizeof(__u32
), /* IW_PRIV_TYPE_INT */
383 sizeof(struct iw_freq
), /* IW_PRIV_TYPE_FLOAT */
384 sizeof(struct sockaddr
), /* IW_PRIV_TYPE_ADDR */
388 /* Size (in bytes) of various events */
389 static const int event_type_size
[] = {
390 IW_EV_LCP_LEN
, /* IW_HEADER_TYPE_NULL */
392 IW_EV_CHAR_LEN
, /* IW_HEADER_TYPE_CHAR */
394 IW_EV_UINT_LEN
, /* IW_HEADER_TYPE_UINT */
395 IW_EV_FREQ_LEN
, /* IW_HEADER_TYPE_FREQ */
396 IW_EV_ADDR_LEN
, /* IW_HEADER_TYPE_ADDR */
398 IW_EV_POINT_LEN
, /* Without variable payload */
399 IW_EV_PARAM_LEN
, /* IW_HEADER_TYPE_PARAM */
400 IW_EV_QUAL_LEN
, /* IW_HEADER_TYPE_QUAL */
403 /************************ COMMON SUBROUTINES ************************/
405 * Stuff that may be used in various place or doesn't fit in one
406 * of the section below.
409 /* ---------------------------------------------------------------- */
411 * Return the driver handler associated with a specific Wireless Extension.
412 * Called from various place, so make sure it remains efficient.
414 static inline iw_handler
get_handler(struct net_device
*dev
,
417 /* Don't "optimise" the following variable, it will crash */
418 unsigned int index
; /* *MUST* be unsigned */
420 /* Check if we have some wireless handlers defined */
421 if(dev
->wireless_handlers
== NULL
)
424 /* Try as a standard command */
425 index
= cmd
- SIOCIWFIRST
;
426 if(index
< dev
->wireless_handlers
->num_standard
)
427 return dev
->wireless_handlers
->standard
[index
];
429 /* Try as a private command */
430 index
= cmd
- SIOCIWFIRSTPRIV
;
431 if(index
< dev
->wireless_handlers
->num_private
)
432 return dev
->wireless_handlers
->private[index
];
438 /* ---------------------------------------------------------------- */
440 * Get statistics out of the driver
442 static inline struct iw_statistics
*get_wireless_stats(struct net_device
*dev
)
445 if((dev
->wireless_handlers
!= NULL
) &&
446 (dev
->wireless_handlers
->get_wireless_stats
!= NULL
))
447 return dev
->wireless_handlers
->get_wireless_stats(dev
);
449 /* Old location, will be phased out in next WE */
450 return (dev
->get_wireless_stats
?
451 dev
->get_wireless_stats(dev
) :
452 (struct iw_statistics
*) NULL
);
455 /* ---------------------------------------------------------------- */
457 * Call the commit handler in the driver
458 * (if exist and if conditions are right)
460 * Note : our current commit strategy is currently pretty dumb,
461 * but we will be able to improve on that...
462 * The goal is to try to agreagate as many changes as possible
463 * before doing the commit. Drivers that will define a commit handler
464 * are usually those that need a reset after changing parameters, so
465 * we want to minimise the number of reset.
466 * A cool idea is to use a timer : at each "set" command, we re-set the
467 * timer, when the timer eventually fires, we call the driver.
468 * Hopefully, more on that later.
470 * Also, I'm waiting to see how many people will complain about the
471 * netif_running(dev) test. I'm open on that one...
472 * Hopefully, the driver will remember to do a commit in "open()" ;-)
474 static inline int call_commit_handler(struct net_device
* dev
)
476 if((netif_running(dev
)) &&
477 (dev
->wireless_handlers
->standard
[0] != NULL
)) {
478 /* Call the commit handler on the driver */
479 return dev
->wireless_handlers
->standard
[0](dev
, NULL
,
482 return 0; /* Command completed successfully */
485 /* ---------------------------------------------------------------- */
487 * Calculate size of private arguments
489 static inline int get_priv_size(__u16 args
)
491 int num
= args
& IW_PRIV_SIZE_MASK
;
492 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
494 return num
* iw_priv_type_size
[type
];
497 /* ---------------------------------------------------------------- */
499 * Re-calculate the size of private arguments
501 static inline int adjust_priv_size(__u16 args
,
502 union iwreq_data
* wrqu
)
504 int num
= wrqu
->data
.length
;
505 int max
= args
& IW_PRIV_SIZE_MASK
;
506 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
508 /* Make sure the driver doesn't goof up */
512 return num
* iw_priv_type_size
[type
];
516 /******************** /proc/net/wireless SUPPORT ********************/
518 * The /proc/net/wireless file is a human readable user-space interface
519 * exporting various wireless specific statistics from the wireless devices.
520 * This is the most popular part of the Wireless Extensions ;-)
522 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
523 * The content of the file is basically the content of "struct iw_statistics".
526 #ifdef CONFIG_PROC_FS
528 /* ---------------------------------------------------------------- */
530 * Print one entry (line) of /proc/net/wireless
532 static __inline__
void wireless_seq_printf_stats(struct seq_file
*seq
,
533 struct net_device
*dev
)
535 /* Get stats from the driver */
536 struct iw_statistics
*stats
= get_wireless_stats(dev
);
539 seq_printf(seq
, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
541 dev
->name
, stats
->status
, stats
->qual
.qual
,
542 stats
->qual
.updated
& IW_QUAL_QUAL_UPDATED
544 ((__u8
) stats
->qual
.level
),
545 stats
->qual
.updated
& IW_QUAL_LEVEL_UPDATED
547 ((__u8
) stats
->qual
.noise
),
548 stats
->qual
.updated
& IW_QUAL_NOISE_UPDATED
550 stats
->discard
.nwid
, stats
->discard
.code
,
551 stats
->discard
.fragment
, stats
->discard
.retries
,
552 stats
->discard
.misc
, stats
->miss
.beacon
);
553 stats
->qual
.updated
= 0;
557 /* ---------------------------------------------------------------- */
559 * Print info for /proc/net/wireless (print all entries)
561 static int wireless_seq_show(struct seq_file
*seq
, void *v
)
563 if (v
== SEQ_START_TOKEN
)
564 seq_printf(seq
, "Inter-| sta-| Quality | Discarded "
565 "packets | Missed | WE\n"
566 " face | tus | link level noise | nwid "
567 "crypt frag retry misc | beacon | %d\n",
570 wireless_seq_printf_stats(seq
, v
);
574 static struct seq_operations wireless_seq_ops
= {
575 .start
= dev_seq_start
,
576 .next
= dev_seq_next
,
577 .stop
= dev_seq_stop
,
578 .show
= wireless_seq_show
,
581 static int wireless_seq_open(struct inode
*inode
, struct file
*file
)
583 return seq_open(file
, &wireless_seq_ops
);
586 static struct file_operations wireless_seq_fops
= {
587 .owner
= THIS_MODULE
,
588 .open
= wireless_seq_open
,
591 .release
= seq_release
,
594 int __init
wireless_proc_init(void)
596 if (!proc_net_fops_create("wireless", S_IRUGO
, &wireless_seq_fops
))
601 #endif /* CONFIG_PROC_FS */
603 /************************** IOCTL SUPPORT **************************/
605 * The original user space API to configure all those Wireless Extensions
607 * In there, we check if we need to call the new driver API (iw_handler)
608 * or just call the driver ioctl handler.
611 /* ---------------------------------------------------------------- */
613 * Allow programatic access to /proc/net/wireless even if /proc
614 * doesn't exist... Also more efficient...
616 static inline int dev_iwstats(struct net_device
*dev
, struct ifreq
*ifr
)
618 /* Get stats from the driver */
619 struct iw_statistics
*stats
;
621 stats
= get_wireless_stats(dev
);
622 if (stats
!= (struct iw_statistics
*) NULL
) {
623 struct iwreq
* wrq
= (struct iwreq
*)ifr
;
625 /* Copy statistics to the user buffer */
626 if(copy_to_user(wrq
->u
.data
.pointer
, stats
,
627 sizeof(struct iw_statistics
)))
630 /* Check if we need to clear the update flag */
631 if(wrq
->u
.data
.flags
!= 0)
632 stats
->qual
.updated
= 0;
638 /* ---------------------------------------------------------------- */
640 * Export the driver private handler definition
641 * They will be picked up by tools like iwpriv...
643 static inline int ioctl_export_private(struct net_device
* dev
,
646 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
648 /* Check if the driver has something to export */
649 if((dev
->wireless_handlers
->num_private_args
== 0) ||
650 (dev
->wireless_handlers
->private_args
== NULL
))
653 /* Check NULL pointer */
654 if(iwr
->u
.data
.pointer
== NULL
)
657 /* Check if there is enough buffer up there */
658 if(iwr
->u
.data
.length
< dev
->wireless_handlers
->num_private_args
) {
659 /* User space can't know in advance how large the buffer
660 * needs to be. Give it a hint, so that we can support
661 * any size buffer we want somewhat efficiently... */
662 iwr
->u
.data
.length
= dev
->wireless_handlers
->num_private_args
;
666 /* Set the number of available ioctls. */
667 iwr
->u
.data
.length
= dev
->wireless_handlers
->num_private_args
;
669 /* Copy structure to the user buffer. */
670 if (copy_to_user(iwr
->u
.data
.pointer
,
671 dev
->wireless_handlers
->private_args
,
672 sizeof(struct iw_priv_args
) * iwr
->u
.data
.length
))
678 /* ---------------------------------------------------------------- */
680 * Wrapper to call a standard Wireless Extension handler.
681 * We do various checks and also take care of moving data between
682 * user space and kernel space.
684 static inline int ioctl_standard_call(struct net_device
* dev
,
689 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
690 const struct iw_ioctl_description
* descr
;
691 struct iw_request_info info
;
694 /* Get the description of the IOCTL */
695 if((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
697 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
699 #ifdef WE_IOCTL_DEBUG
700 printk(KERN_DEBUG
"%s (WE) : Found standard handler for 0x%04X\n",
702 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
);
703 #endif /* WE_IOCTL_DEBUG */
705 /* Prepare the call */
709 /* Check if we have a pointer to user space data or not */
710 if(descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
712 /* No extra arguments. Trivial to handle */
713 ret
= handler(dev
, &info
, &(iwr
->u
), NULL
);
716 /* Generate an event to notify listeners of the change */
717 if((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
718 ((ret
== 0) || (ret
== -EIWCOMMIT
)))
719 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
720 #endif /* WE_SET_EVENT */
727 /* Calculate space needed by arguments. Always allocate
728 * for max space. Easier, and won't last long... */
729 extra_size
= descr
->max_tokens
* descr
->token_size
;
731 /* Check what user space is giving us */
733 /* Check NULL pointer */
734 if((iwr
->u
.data
.pointer
== NULL
) &&
735 (iwr
->u
.data
.length
!= 0))
737 /* Check if number of token fits within bounds */
738 if(iwr
->u
.data
.length
> descr
->max_tokens
)
740 if(iwr
->u
.data
.length
< descr
->min_tokens
)
743 /* Check NULL pointer */
744 if(iwr
->u
.data
.pointer
== NULL
)
746 /* Save user space buffer size for checking */
747 user_length
= iwr
->u
.data
.length
;
749 /* Don't check if user_length > max to allow forward
750 * compatibility. The test user_length < min is
751 * implied by the test at the end. */
753 /* Support for very large requests */
754 if((descr
->flags
& IW_DESCR_FLAG_NOMAX
) &&
755 (user_length
> descr
->max_tokens
)) {
756 /* Allow userspace to GET more than max so
757 * we can support any size GET requests.
758 * There is still a limit : -ENOMEM. */
759 extra_size
= user_length
* descr
->token_size
;
760 /* Note : user_length is originally a __u16,
761 * and token_size is controlled by us,
762 * so extra_size won't get negative and
763 * won't overflow... */
767 #ifdef WE_IOCTL_DEBUG
768 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
769 dev
->name
, extra_size
);
770 #endif /* WE_IOCTL_DEBUG */
772 /* Create the kernel buffer */
773 extra
= kmalloc(extra_size
, GFP_KERNEL
);
778 /* If it is a SET, get all the extra data in here */
779 if(IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
780 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
787 #ifdef WE_IOCTL_DEBUG
788 printk(KERN_DEBUG
"%s (WE) : Got %d bytes\n",
790 iwr
->u
.data
.length
* descr
->token_size
);
791 #endif /* WE_IOCTL_DEBUG */
794 /* Call the handler */
795 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
797 /* If we have something to return to the user */
798 if (!ret
&& IW_IS_GET(cmd
)) {
799 /* Check if there is enough buffer up there */
800 if(user_length
< iwr
->u
.data
.length
) {
805 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
810 #ifdef WE_IOCTL_DEBUG
811 printk(KERN_DEBUG
"%s (WE) : Wrote %d bytes\n",
813 iwr
->u
.data
.length
* descr
->token_size
);
814 #endif /* WE_IOCTL_DEBUG */
818 /* Generate an event to notify listeners of the change */
819 if((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
820 ((ret
== 0) || (ret
== -EIWCOMMIT
))) {
821 if(descr
->flags
& IW_DESCR_FLAG_RESTRICT
)
822 /* If the event is restricted, don't
823 * export the payload */
824 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
826 wireless_send_event(dev
, cmd
, &(iwr
->u
),
829 #endif /* WE_SET_EVENT */
831 /* Cleanup - I told you it wasn't that long ;-) */
835 /* Call commit handler if needed and defined */
836 if(ret
== -EIWCOMMIT
)
837 ret
= call_commit_handler(dev
);
839 /* Here, we will generate the appropriate event if needed */
844 /* ---------------------------------------------------------------- */
846 * Wrapper to call a private Wireless Extension handler.
847 * We do various checks and also take care of moving data between
848 * user space and kernel space.
849 * It's not as nice and slimline as the standard wrapper. The cause
850 * is struct iw_priv_args, which was not really designed for the
851 * job we are going here.
853 * IMPORTANT : This function prevent to set and get data on the same
854 * IOCTL and enforce the SET/GET convention. Not doing it would be
856 * If you need to set and get data at the same time, please don't use
857 * a iw_handler but process it in your ioctl handler (i.e. use the
860 static inline int ioctl_private_call(struct net_device
* dev
,
865 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
866 const struct iw_priv_args
* descr
= NULL
;
867 struct iw_request_info info
;
872 /* Get the description of the IOCTL */
873 for(i
= 0; i
< dev
->wireless_handlers
->num_private_args
; i
++)
874 if(cmd
== dev
->wireless_handlers
->private_args
[i
].cmd
) {
875 descr
= &(dev
->wireless_handlers
->private_args
[i
]);
879 #ifdef WE_IOCTL_DEBUG
880 printk(KERN_DEBUG
"%s (WE) : Found private handler for 0x%04X\n",
883 printk(KERN_DEBUG
"%s (WE) : Name %s, set %X, get %X\n",
884 dev
->name
, descr
->name
,
885 descr
->set_args
, descr
->get_args
);
887 #endif /* WE_IOCTL_DEBUG */
889 /* Compute the size of the set/get arguments */
892 int offset
= 0; /* For sub-ioctls */
893 /* Check for sub-ioctl handler */
894 if(descr
->name
[0] == '\0')
895 /* Reserve one int for sub-ioctl index */
896 offset
= sizeof(__u32
);
898 /* Size of set arguments */
899 extra_size
= get_priv_size(descr
->set_args
);
901 /* Does it fits in iwr ? */
902 if((descr
->set_args
& IW_PRIV_SIZE_FIXED
) &&
903 ((extra_size
+ offset
) <= IFNAMSIZ
))
906 /* Size of get arguments */
907 extra_size
= get_priv_size(descr
->get_args
);
909 /* Does it fits in iwr ? */
910 if((descr
->get_args
& IW_PRIV_SIZE_FIXED
) &&
911 (extra_size
<= IFNAMSIZ
))
916 /* Prepare the call */
920 /* Check if we have a pointer to user space data or not. */
921 if(extra_size
== 0) {
922 /* No extra arguments. Trivial to handle */
923 ret
= handler(dev
, &info
, &(iwr
->u
), (char *) &(iwr
->u
));
928 /* Check what user space is giving us */
930 /* Check NULL pointer */
931 if((iwr
->u
.data
.pointer
== NULL
) &&
932 (iwr
->u
.data
.length
!= 0))
935 /* Does it fits within bounds ? */
936 if(iwr
->u
.data
.length
> (descr
->set_args
&
940 /* Check NULL pointer */
941 if(iwr
->u
.data
.pointer
== NULL
)
945 #ifdef WE_IOCTL_DEBUG
946 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
947 dev
->name
, extra_size
);
948 #endif /* WE_IOCTL_DEBUG */
950 /* Always allocate for max space. Easier, and won't last
952 extra
= kmalloc(extra_size
, GFP_KERNEL
);
957 /* If it is a SET, get all the extra data in here */
958 if(IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
959 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
965 #ifdef WE_IOCTL_DEBUG
966 printk(KERN_DEBUG
"%s (WE) : Got %d elem\n",
967 dev
->name
, iwr
->u
.data
.length
);
968 #endif /* WE_IOCTL_DEBUG */
971 /* Call the handler */
972 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
974 /* If we have something to return to the user */
975 if (!ret
&& IW_IS_GET(cmd
)) {
977 /* Adjust for the actual length if it's variable,
978 * avoid leaking kernel bits outside. */
979 if (!(descr
->get_args
& IW_PRIV_SIZE_FIXED
)) {
980 extra_size
= adjust_priv_size(descr
->get_args
,
984 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
988 #ifdef WE_IOCTL_DEBUG
989 printk(KERN_DEBUG
"%s (WE) : Wrote %d elem\n",
990 dev
->name
, iwr
->u
.data
.length
);
991 #endif /* WE_IOCTL_DEBUG */
994 /* Cleanup - I told you it wasn't that long ;-) */
999 /* Call commit handler if needed and defined */
1000 if(ret
== -EIWCOMMIT
)
1001 ret
= call_commit_handler(dev
);
1006 /* ---------------------------------------------------------------- */
1008 * Main IOCTl dispatcher. Called from the main networking code
1009 * (dev_ioctl() in net/core/dev.c).
1010 * Check the type of IOCTL and call the appropriate wrapper...
1012 int wireless_process_ioctl(struct ifreq
*ifr
, unsigned int cmd
)
1014 struct net_device
*dev
;
1017 /* Permissions are already checked in dev_ioctl() before calling us.
1018 * The copy_to/from_user() of ifr is also dealt with in there */
1020 /* Make sure the device exist */
1021 if ((dev
= __dev_get_by_name(ifr
->ifr_name
)) == NULL
)
1024 /* A bunch of special cases, then the generic case...
1025 * Note that 'cmd' is already filtered in dev_ioctl() with
1026 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1030 /* Get Wireless Stats */
1031 return dev_iwstats(dev
, ifr
);
1034 /* Check if we have some wireless handlers defined */
1035 if(dev
->wireless_handlers
!= NULL
) {
1036 /* We export to user space the definition of
1037 * the private handler ourselves */
1038 return ioctl_export_private(dev
, ifr
);
1040 // ## Fall-through for old API ##
1044 if (!netif_device_present(dev
))
1046 /* New driver API : try to find the handler */
1047 handler
= get_handler(dev
, cmd
);
1048 if(handler
!= NULL
) {
1049 /* Standard and private are not the same */
1050 if(cmd
< SIOCIWFIRSTPRIV
)
1051 return ioctl_standard_call(dev
,
1056 return ioctl_private_call(dev
,
1061 /* Old driver API : call driver ioctl handler */
1062 if (dev
->do_ioctl
) {
1063 return dev
->do_ioctl(dev
, ifr
, cmd
);
1071 /************************* EVENT PROCESSING *************************/
1073 * Process events generated by the wireless layer or the driver.
1074 * Most often, the event will be propagated through rtnetlink
1077 #ifdef WE_EVENT_NETLINK
1078 /* "rtnl" is defined in net/core/rtnetlink.c, but we need it here.
1079 * It is declared in <linux/rtnetlink.h> */
1081 /* ---------------------------------------------------------------- */
1083 * Fill a rtnetlink message with our event data.
1084 * Note that we propage only the specified event and don't dump the
1085 * current wireless config. Dumping the wireless config is far too
1086 * expensive (for each parameter, the driver need to query the hardware).
1088 static inline int rtnetlink_fill_iwinfo(struct sk_buff
* skb
,
1089 struct net_device
* dev
,
1094 struct ifinfomsg
*r
;
1095 struct nlmsghdr
*nlh
;
1096 unsigned char *b
= skb
->tail
;
1098 nlh
= NLMSG_PUT(skb
, 0, 0, type
, sizeof(*r
));
1099 r
= NLMSG_DATA(nlh
);
1100 r
->ifi_family
= AF_UNSPEC
;
1102 r
->ifi_type
= dev
->type
;
1103 r
->ifi_index
= dev
->ifindex
;
1104 r
->ifi_flags
= dev
->flags
;
1105 r
->ifi_change
= 0; /* Wireless changes don't affect those flags */
1107 /* Add the wireless events in the netlink packet */
1108 RTA_PUT(skb
, IFLA_WIRELESS
,
1111 nlh
->nlmsg_len
= skb
->tail
- b
;
1116 skb_trim(skb
, b
- skb
->data
);
1120 /* ---------------------------------------------------------------- */
1122 * Create and broadcast and send it on the standard rtnetlink socket
1123 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1124 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1125 * within a RTM_NEWLINK event.
1127 static inline void rtmsg_iwinfo(struct net_device
* dev
,
1131 struct sk_buff
*skb
;
1132 int size
= NLMSG_GOODSIZE
;
1134 skb
= alloc_skb(size
, GFP_ATOMIC
);
1138 if (rtnetlink_fill_iwinfo(skb
, dev
, RTM_NEWLINK
,
1139 event
, event_len
) < 0) {
1143 NETLINK_CB(skb
).dst_group
= RTNLGRP_LINK
;
1144 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_LINK
, GFP_ATOMIC
);
1146 #endif /* WE_EVENT_NETLINK */
1148 /* ---------------------------------------------------------------- */
1150 * Main event dispatcher. Called from other parts and drivers.
1151 * Send the event on the appropriate channels.
1152 * May be called from interrupt context.
1154 void wireless_send_event(struct net_device
* dev
,
1156 union iwreq_data
* wrqu
,
1159 const struct iw_ioctl_description
* descr
= NULL
;
1161 struct iw_event
*event
; /* Mallocated whole event */
1162 int event_len
; /* Its size */
1163 int hdr_len
; /* Size of the event header */
1164 /* Don't "optimise" the following variable, it will crash */
1165 unsigned cmd_index
; /* *MUST* be unsigned */
1167 /* Get the description of the IOCTL */
1168 if(cmd
<= SIOCIWLAST
) {
1169 cmd_index
= cmd
- SIOCIWFIRST
;
1170 if(cmd_index
< standard_ioctl_num
)
1171 descr
= &(standard_ioctl
[cmd_index
]);
1173 cmd_index
= cmd
- IWEVFIRST
;
1174 if(cmd_index
< standard_event_num
)
1175 descr
= &(standard_event
[cmd_index
]);
1177 /* Don't accept unknown events */
1179 /* Note : we don't return an error to the driver, because
1180 * the driver would not know what to do about it. It can't
1181 * return an error to the user, because the event is not
1182 * initiated by a user request.
1183 * The best the driver could do is to log an error message.
1184 * We will do it ourselves instead...
1186 printk(KERN_ERR
"%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1190 #ifdef WE_EVENT_DEBUG
1191 printk(KERN_DEBUG
"%s (WE) : Got event 0x%04X\n",
1193 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
);
1194 #endif /* WE_EVENT_DEBUG */
1196 /* Check extra parameters and set extra_len */
1197 if(descr
->header_type
== IW_HEADER_TYPE_POINT
) {
1198 /* Check if number of token fits within bounds */
1199 if(wrqu
->data
.length
> descr
->max_tokens
) {
1200 printk(KERN_ERR
"%s (WE) : Wireless Event too big (%d)\n", dev
->name
, wrqu
->data
.length
);
1203 if(wrqu
->data
.length
< descr
->min_tokens
) {
1204 printk(KERN_ERR
"%s (WE) : Wireless Event too small (%d)\n", dev
->name
, wrqu
->data
.length
);
1207 /* Calculate extra_len - extra is NULL for restricted events */
1209 extra_len
= wrqu
->data
.length
* descr
->token_size
;
1210 #ifdef WE_EVENT_DEBUG
1211 printk(KERN_DEBUG
"%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev
->name
, cmd
, wrqu
->data
.length
, extra_len
);
1212 #endif /* WE_EVENT_DEBUG */
1215 /* Total length of the event */
1216 hdr_len
= event_type_size
[descr
->header_type
];
1217 event_len
= hdr_len
+ extra_len
;
1219 #ifdef WE_EVENT_DEBUG
1220 printk(KERN_DEBUG
"%s (WE) : Event 0x%04X, hdr_len %d, event_len %d\n", dev
->name
, cmd
, hdr_len
, event_len
);
1221 #endif /* WE_EVENT_DEBUG */
1223 /* Create temporary buffer to hold the event */
1224 event
= kmalloc(event_len
, GFP_ATOMIC
);
1229 event
->len
= event_len
;
1231 memcpy(&event
->u
, wrqu
, hdr_len
- IW_EV_LCP_LEN
);
1233 memcpy(((char *) event
) + hdr_len
, extra
, extra_len
);
1235 #ifdef WE_EVENT_NETLINK
1236 /* rtnetlink event channel */
1237 rtmsg_iwinfo(dev
, (char *) event
, event_len
);
1238 #endif /* WE_EVENT_NETLINK */
1243 return; /* Always success, I guess ;-) */
1246 /********************** ENHANCED IWSPY SUPPORT **********************/
1248 * In the old days, the driver was handling spy support all by itself.
1249 * Now, the driver can delegate this task to Wireless Extensions.
1250 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1251 * push data to us via wireless_spy_update() and include struct iw_spy_data
1252 * in its private part (and advertise it in iw_handler_def->spy_offset).
1253 * One of the main advantage of centralising spy support here is that
1254 * it becomes much easier to improve and extend it without having to touch
1255 * the drivers. One example is the addition of the Spy-Threshold events.
1258 /* ---------------------------------------------------------------- */
1260 * Return the pointer to the spy data in the driver.
1261 * Because this is called on the Rx path via wireless_spy_update(),
1262 * we want it to be efficient...
1264 static inline struct iw_spy_data
* get_spydata(struct net_device
*dev
)
1266 /* This is the new way */
1267 if(dev
->wireless_data
)
1268 return(dev
->wireless_data
->spy_data
);
1270 /* This is the old way. Doesn't work for multi-headed drivers.
1271 * It will be removed in the next version of WE. */
1272 return (dev
->priv
+ dev
->wireless_handlers
->spy_offset
);
1275 /*------------------------------------------------------------------*/
1277 * Standard Wireless Handler : set Spy List
1279 int iw_handler_set_spy(struct net_device
* dev
,
1280 struct iw_request_info
* info
,
1281 union iwreq_data
* wrqu
,
1284 struct iw_spy_data
* spydata
= get_spydata(dev
);
1285 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1287 if(!dev
->wireless_data
)
1288 /* Help user know that driver needs updating */
1289 printk(KERN_DEBUG
"%s (WE) : Driver using old/buggy spy support, please fix driver !\n",
1291 /* Make sure driver is not buggy or using the old API */
1295 /* Disable spy collection while we copy the addresses.
1296 * While we copy addresses, any call to wireless_spy_update()
1297 * will NOP. This is OK, as anyway the addresses are changing. */
1298 spydata
->spy_number
= 0;
1300 /* We want to operate without locking, because wireless_spy_update()
1301 * most likely will happen in the interrupt handler, and therefore
1302 * have its own locking constraints and needs performance.
1303 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1304 * This make sure wireless_spy_update() "see" that the spy list
1305 * is temporarily disabled. */
1308 /* Are there are addresses to copy? */
1309 if(wrqu
->data
.length
> 0) {
1312 /* Copy addresses */
1313 for(i
= 0; i
< wrqu
->data
.length
; i
++)
1314 memcpy(spydata
->spy_address
[i
], address
[i
].sa_data
,
1317 memset(spydata
->spy_stat
, 0,
1318 sizeof(struct iw_quality
) * IW_MAX_SPY
);
1321 printk(KERN_DEBUG
"iw_handler_set_spy() : offset %ld, spydata %p, num %d\n", dev
->wireless_handlers
->spy_offset
, spydata
, wrqu
->data
.length
);
1322 for (i
= 0; i
< wrqu
->data
.length
; i
++)
1324 "%02X:%02X:%02X:%02X:%02X:%02X \n",
1325 spydata
->spy_address
[i
][0],
1326 spydata
->spy_address
[i
][1],
1327 spydata
->spy_address
[i
][2],
1328 spydata
->spy_address
[i
][3],
1329 spydata
->spy_address
[i
][4],
1330 spydata
->spy_address
[i
][5]);
1331 #endif /* WE_SPY_DEBUG */
1334 /* Make sure above is updated before re-enabling */
1337 /* Enable addresses */
1338 spydata
->spy_number
= wrqu
->data
.length
;
1343 /*------------------------------------------------------------------*/
1345 * Standard Wireless Handler : get Spy List
1347 int iw_handler_get_spy(struct net_device
* dev
,
1348 struct iw_request_info
* info
,
1349 union iwreq_data
* wrqu
,
1352 struct iw_spy_data
* spydata
= get_spydata(dev
);
1353 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1356 /* Make sure driver is not buggy or using the old API */
1360 wrqu
->data
.length
= spydata
->spy_number
;
1362 /* Copy addresses. */
1363 for(i
= 0; i
< spydata
->spy_number
; i
++) {
1364 memcpy(address
[i
].sa_data
, spydata
->spy_address
[i
], ETH_ALEN
);
1365 address
[i
].sa_family
= AF_UNIX
;
1367 /* Copy stats to the user buffer (just after). */
1368 if(spydata
->spy_number
> 0)
1369 memcpy(extra
+ (sizeof(struct sockaddr
) *spydata
->spy_number
),
1371 sizeof(struct iw_quality
) * spydata
->spy_number
);
1372 /* Reset updated flags. */
1373 for(i
= 0; i
< spydata
->spy_number
; i
++)
1374 spydata
->spy_stat
[i
].updated
= 0;
1378 /*------------------------------------------------------------------*/
1380 * Standard Wireless Handler : set spy threshold
1382 int iw_handler_set_thrspy(struct net_device
* dev
,
1383 struct iw_request_info
*info
,
1384 union iwreq_data
* wrqu
,
1387 struct iw_spy_data
* spydata
= get_spydata(dev
);
1388 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1390 /* Make sure driver is not buggy or using the old API */
1395 memcpy(&(spydata
->spy_thr_low
), &(threshold
->low
),
1396 2 * sizeof(struct iw_quality
));
1399 memset(spydata
->spy_thr_under
, '\0', sizeof(spydata
->spy_thr_under
));
1402 printk(KERN_DEBUG
"iw_handler_set_thrspy() : low %d ; high %d\n", spydata
->spy_thr_low
.level
, spydata
->spy_thr_high
.level
);
1403 #endif /* WE_SPY_DEBUG */
1408 /*------------------------------------------------------------------*/
1410 * Standard Wireless Handler : get spy threshold
1412 int iw_handler_get_thrspy(struct net_device
* dev
,
1413 struct iw_request_info
*info
,
1414 union iwreq_data
* wrqu
,
1417 struct iw_spy_data
* spydata
= get_spydata(dev
);
1418 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1420 /* Make sure driver is not buggy or using the old API */
1425 memcpy(&(threshold
->low
), &(spydata
->spy_thr_low
),
1426 2 * sizeof(struct iw_quality
));
1431 /*------------------------------------------------------------------*/
1433 * Prepare and send a Spy Threshold event
1435 static void iw_send_thrspy_event(struct net_device
* dev
,
1436 struct iw_spy_data
* spydata
,
1437 unsigned char * address
,
1438 struct iw_quality
* wstats
)
1440 union iwreq_data wrqu
;
1441 struct iw_thrspy threshold
;
1444 wrqu
.data
.length
= 1;
1445 wrqu
.data
.flags
= 0;
1447 memcpy(threshold
.addr
.sa_data
, address
, ETH_ALEN
);
1448 threshold
.addr
.sa_family
= ARPHRD_ETHER
;
1450 memcpy(&(threshold
.qual
), wstats
, sizeof(struct iw_quality
));
1451 /* Copy also thresholds */
1452 memcpy(&(threshold
.low
), &(spydata
->spy_thr_low
),
1453 2 * sizeof(struct iw_quality
));
1456 printk(KERN_DEBUG
"iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
1457 threshold
.addr
.sa_data
[0],
1458 threshold
.addr
.sa_data
[1],
1459 threshold
.addr
.sa_data
[2],
1460 threshold
.addr
.sa_data
[3],
1461 threshold
.addr
.sa_data
[4],
1462 threshold
.addr
.sa_data
[5], threshold
.qual
.level
);
1463 #endif /* WE_SPY_DEBUG */
1465 /* Send event to user space */
1466 wireless_send_event(dev
, SIOCGIWTHRSPY
, &wrqu
, (char *) &threshold
);
1469 /* ---------------------------------------------------------------- */
1471 * Call for the driver to update the spy data.
1472 * For now, the spy data is a simple array. As the size of the array is
1473 * small, this is good enough. If we wanted to support larger number of
1474 * spy addresses, we should use something more efficient...
1476 void wireless_spy_update(struct net_device
* dev
,
1477 unsigned char * address
,
1478 struct iw_quality
* wstats
)
1480 struct iw_spy_data
* spydata
= get_spydata(dev
);
1484 /* Make sure driver is not buggy or using the old API */
1489 printk(KERN_DEBUG
"wireless_spy_update() : offset %ld, spydata %p, address %02X:%02X:%02X:%02X:%02X:%02X\n", dev
->wireless_handlers
->spy_offset
, spydata
, address
[0], address
[1], address
[2], address
[3], address
[4], address
[5]);
1490 #endif /* WE_SPY_DEBUG */
1492 /* Update all records that match */
1493 for(i
= 0; i
< spydata
->spy_number
; i
++)
1494 if(!memcmp(address
, spydata
->spy_address
[i
], ETH_ALEN
)) {
1495 memcpy(&(spydata
->spy_stat
[i
]), wstats
,
1496 sizeof(struct iw_quality
));
1500 /* Generate an event if we cross the spy threshold.
1501 * To avoid event storms, we have a simple hysteresis : we generate
1502 * event only when we go under the low threshold or above the
1503 * high threshold. */
1505 if(spydata
->spy_thr_under
[match
]) {
1506 if(wstats
->level
> spydata
->spy_thr_high
.level
) {
1507 spydata
->spy_thr_under
[match
] = 0;
1508 iw_send_thrspy_event(dev
, spydata
,
1512 if(wstats
->level
< spydata
->spy_thr_low
.level
) {
1513 spydata
->spy_thr_under
[match
] = 1;
1514 iw_send_thrspy_event(dev
, spydata
,
1521 EXPORT_SYMBOL(iw_handler_get_spy
);
1522 EXPORT_SYMBOL(iw_handler_get_thrspy
);
1523 EXPORT_SYMBOL(iw_handler_set_spy
);
1524 EXPORT_SYMBOL(iw_handler_set_thrspy
);
1525 EXPORT_SYMBOL(wireless_send_event
);
1526 EXPORT_SYMBOL(wireless_spy_update
);