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>
100 #include <net/wext.h>
102 #include <asm/uaccess.h> /* copy_to_user() */
104 /**************************** CONSTANTS ****************************/
106 /* Debugging stuff */
107 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
108 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
109 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
112 #define WE_EVENT_RTNETLINK /* Propagate events using RtNetlink */
113 #define WE_SET_EVENT /* Generate an event on some set commands */
115 /************************* GLOBAL VARIABLES *************************/
117 * You should not use global variables, because of re-entrancy.
118 * On our case, it's only const, so it's OK...
121 * Meta-data about all the standard Wireless Extension request we
124 static const struct iw_ioctl_description standard_ioctl
[] = {
125 [SIOCSIWCOMMIT
- SIOCIWFIRST
] = {
126 .header_type
= IW_HEADER_TYPE_NULL
,
128 [SIOCGIWNAME
- SIOCIWFIRST
] = {
129 .header_type
= IW_HEADER_TYPE_CHAR
,
130 .flags
= IW_DESCR_FLAG_DUMP
,
132 [SIOCSIWNWID
- SIOCIWFIRST
] = {
133 .header_type
= IW_HEADER_TYPE_PARAM
,
134 .flags
= IW_DESCR_FLAG_EVENT
,
136 [SIOCGIWNWID
- SIOCIWFIRST
] = {
137 .header_type
= IW_HEADER_TYPE_PARAM
,
138 .flags
= IW_DESCR_FLAG_DUMP
,
140 [SIOCSIWFREQ
- SIOCIWFIRST
] = {
141 .header_type
= IW_HEADER_TYPE_FREQ
,
142 .flags
= IW_DESCR_FLAG_EVENT
,
144 [SIOCGIWFREQ
- SIOCIWFIRST
] = {
145 .header_type
= IW_HEADER_TYPE_FREQ
,
146 .flags
= IW_DESCR_FLAG_DUMP
,
148 [SIOCSIWMODE
- SIOCIWFIRST
] = {
149 .header_type
= IW_HEADER_TYPE_UINT
,
150 .flags
= IW_DESCR_FLAG_EVENT
,
152 [SIOCGIWMODE
- SIOCIWFIRST
] = {
153 .header_type
= IW_HEADER_TYPE_UINT
,
154 .flags
= IW_DESCR_FLAG_DUMP
,
156 [SIOCSIWSENS
- SIOCIWFIRST
] = {
157 .header_type
= IW_HEADER_TYPE_PARAM
,
159 [SIOCGIWSENS
- SIOCIWFIRST
] = {
160 .header_type
= IW_HEADER_TYPE_PARAM
,
162 [SIOCSIWRANGE
- SIOCIWFIRST
] = {
163 .header_type
= IW_HEADER_TYPE_NULL
,
165 [SIOCGIWRANGE
- SIOCIWFIRST
] = {
166 .header_type
= IW_HEADER_TYPE_POINT
,
168 .max_tokens
= sizeof(struct iw_range
),
169 .flags
= IW_DESCR_FLAG_DUMP
,
171 [SIOCSIWPRIV
- SIOCIWFIRST
] = {
172 .header_type
= IW_HEADER_TYPE_NULL
,
174 [SIOCGIWPRIV
- SIOCIWFIRST
] = { /* (handled directly by us) */
175 .header_type
= IW_HEADER_TYPE_POINT
,
176 .token_size
= sizeof(struct iw_priv_args
),
178 .flags
= IW_DESCR_FLAG_NOMAX
,
180 [SIOCSIWSTATS
- SIOCIWFIRST
] = {
181 .header_type
= IW_HEADER_TYPE_NULL
,
183 [SIOCGIWSTATS
- SIOCIWFIRST
] = { /* (handled directly by us) */
184 .header_type
= IW_HEADER_TYPE_POINT
,
186 .max_tokens
= sizeof(struct iw_statistics
),
187 .flags
= IW_DESCR_FLAG_DUMP
,
189 [SIOCSIWSPY
- SIOCIWFIRST
] = {
190 .header_type
= IW_HEADER_TYPE_POINT
,
191 .token_size
= sizeof(struct sockaddr
),
192 .max_tokens
= IW_MAX_SPY
,
194 [SIOCGIWSPY
- SIOCIWFIRST
] = {
195 .header_type
= IW_HEADER_TYPE_POINT
,
196 .token_size
= sizeof(struct sockaddr
) +
197 sizeof(struct iw_quality
),
198 .max_tokens
= IW_MAX_SPY
,
200 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = {
201 .header_type
= IW_HEADER_TYPE_POINT
,
202 .token_size
= sizeof(struct iw_thrspy
),
206 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = {
207 .header_type
= IW_HEADER_TYPE_POINT
,
208 .token_size
= sizeof(struct iw_thrspy
),
212 [SIOCSIWAP
- SIOCIWFIRST
] = {
213 .header_type
= IW_HEADER_TYPE_ADDR
,
215 [SIOCGIWAP
- SIOCIWFIRST
] = {
216 .header_type
= IW_HEADER_TYPE_ADDR
,
217 .flags
= IW_DESCR_FLAG_DUMP
,
219 [SIOCSIWMLME
- SIOCIWFIRST
] = {
220 .header_type
= IW_HEADER_TYPE_POINT
,
222 .min_tokens
= sizeof(struct iw_mlme
),
223 .max_tokens
= sizeof(struct iw_mlme
),
225 [SIOCGIWAPLIST
- SIOCIWFIRST
] = {
226 .header_type
= IW_HEADER_TYPE_POINT
,
227 .token_size
= sizeof(struct sockaddr
) +
228 sizeof(struct iw_quality
),
229 .max_tokens
= IW_MAX_AP
,
230 .flags
= IW_DESCR_FLAG_NOMAX
,
232 [SIOCSIWSCAN
- SIOCIWFIRST
] = {
233 .header_type
= IW_HEADER_TYPE_POINT
,
236 .max_tokens
= sizeof(struct iw_scan_req
),
238 [SIOCGIWSCAN
- SIOCIWFIRST
] = {
239 .header_type
= IW_HEADER_TYPE_POINT
,
241 .max_tokens
= IW_SCAN_MAX_DATA
,
242 .flags
= IW_DESCR_FLAG_NOMAX
,
244 [SIOCSIWESSID
- SIOCIWFIRST
] = {
245 .header_type
= IW_HEADER_TYPE_POINT
,
247 .max_tokens
= IW_ESSID_MAX_SIZE
,
248 .flags
= IW_DESCR_FLAG_EVENT
,
250 [SIOCGIWESSID
- SIOCIWFIRST
] = {
251 .header_type
= IW_HEADER_TYPE_POINT
,
253 .max_tokens
= IW_ESSID_MAX_SIZE
,
254 .flags
= IW_DESCR_FLAG_DUMP
,
256 [SIOCSIWNICKN
- SIOCIWFIRST
] = {
257 .header_type
= IW_HEADER_TYPE_POINT
,
259 .max_tokens
= IW_ESSID_MAX_SIZE
,
261 [SIOCGIWNICKN
- SIOCIWFIRST
] = {
262 .header_type
= IW_HEADER_TYPE_POINT
,
264 .max_tokens
= IW_ESSID_MAX_SIZE
,
266 [SIOCSIWRATE
- SIOCIWFIRST
] = {
267 .header_type
= IW_HEADER_TYPE_PARAM
,
269 [SIOCGIWRATE
- SIOCIWFIRST
] = {
270 .header_type
= IW_HEADER_TYPE_PARAM
,
272 [SIOCSIWRTS
- SIOCIWFIRST
] = {
273 .header_type
= IW_HEADER_TYPE_PARAM
,
275 [SIOCGIWRTS
- SIOCIWFIRST
] = {
276 .header_type
= IW_HEADER_TYPE_PARAM
,
278 [SIOCSIWFRAG
- SIOCIWFIRST
] = {
279 .header_type
= IW_HEADER_TYPE_PARAM
,
281 [SIOCGIWFRAG
- SIOCIWFIRST
] = {
282 .header_type
= IW_HEADER_TYPE_PARAM
,
284 [SIOCSIWTXPOW
- SIOCIWFIRST
] = {
285 .header_type
= IW_HEADER_TYPE_PARAM
,
287 [SIOCGIWTXPOW
- SIOCIWFIRST
] = {
288 .header_type
= IW_HEADER_TYPE_PARAM
,
290 [SIOCSIWRETRY
- SIOCIWFIRST
] = {
291 .header_type
= IW_HEADER_TYPE_PARAM
,
293 [SIOCGIWRETRY
- SIOCIWFIRST
] = {
294 .header_type
= IW_HEADER_TYPE_PARAM
,
296 [SIOCSIWENCODE
- SIOCIWFIRST
] = {
297 .header_type
= IW_HEADER_TYPE_POINT
,
299 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
300 .flags
= IW_DESCR_FLAG_EVENT
| IW_DESCR_FLAG_RESTRICT
,
302 [SIOCGIWENCODE
- SIOCIWFIRST
] = {
303 .header_type
= IW_HEADER_TYPE_POINT
,
305 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
306 .flags
= IW_DESCR_FLAG_DUMP
| IW_DESCR_FLAG_RESTRICT
,
308 [SIOCSIWPOWER
- SIOCIWFIRST
] = {
309 .header_type
= IW_HEADER_TYPE_PARAM
,
311 [SIOCGIWPOWER
- SIOCIWFIRST
] = {
312 .header_type
= IW_HEADER_TYPE_PARAM
,
314 [SIOCSIWGENIE
- SIOCIWFIRST
] = {
315 .header_type
= IW_HEADER_TYPE_POINT
,
317 .max_tokens
= IW_GENERIC_IE_MAX
,
319 [SIOCGIWGENIE
- SIOCIWFIRST
] = {
320 .header_type
= IW_HEADER_TYPE_POINT
,
322 .max_tokens
= IW_GENERIC_IE_MAX
,
324 [SIOCSIWAUTH
- SIOCIWFIRST
] = {
325 .header_type
= IW_HEADER_TYPE_PARAM
,
327 [SIOCGIWAUTH
- SIOCIWFIRST
] = {
328 .header_type
= IW_HEADER_TYPE_PARAM
,
330 [SIOCSIWENCODEEXT
- SIOCIWFIRST
] = {
331 .header_type
= IW_HEADER_TYPE_POINT
,
333 .min_tokens
= sizeof(struct iw_encode_ext
),
334 .max_tokens
= sizeof(struct iw_encode_ext
) +
335 IW_ENCODING_TOKEN_MAX
,
337 [SIOCGIWENCODEEXT
- SIOCIWFIRST
] = {
338 .header_type
= IW_HEADER_TYPE_POINT
,
340 .min_tokens
= sizeof(struct iw_encode_ext
),
341 .max_tokens
= sizeof(struct iw_encode_ext
) +
342 IW_ENCODING_TOKEN_MAX
,
344 [SIOCSIWPMKSA
- SIOCIWFIRST
] = {
345 .header_type
= IW_HEADER_TYPE_POINT
,
347 .min_tokens
= sizeof(struct iw_pmksa
),
348 .max_tokens
= sizeof(struct iw_pmksa
),
351 static const unsigned standard_ioctl_num
= ARRAY_SIZE(standard_ioctl
);
354 * Meta-data about all the additional standard Wireless Extension events
357 static const struct iw_ioctl_description standard_event
[] = {
358 [IWEVTXDROP
- IWEVFIRST
] = {
359 .header_type
= IW_HEADER_TYPE_ADDR
,
361 [IWEVQUAL
- IWEVFIRST
] = {
362 .header_type
= IW_HEADER_TYPE_QUAL
,
364 [IWEVCUSTOM
- IWEVFIRST
] = {
365 .header_type
= IW_HEADER_TYPE_POINT
,
367 .max_tokens
= IW_CUSTOM_MAX
,
369 [IWEVREGISTERED
- IWEVFIRST
] = {
370 .header_type
= IW_HEADER_TYPE_ADDR
,
372 [IWEVEXPIRED
- IWEVFIRST
] = {
373 .header_type
= IW_HEADER_TYPE_ADDR
,
375 [IWEVGENIE
- IWEVFIRST
] = {
376 .header_type
= IW_HEADER_TYPE_POINT
,
378 .max_tokens
= IW_GENERIC_IE_MAX
,
380 [IWEVMICHAELMICFAILURE
- IWEVFIRST
] = {
381 .header_type
= IW_HEADER_TYPE_POINT
,
383 .max_tokens
= sizeof(struct iw_michaelmicfailure
),
385 [IWEVASSOCREQIE
- IWEVFIRST
] = {
386 .header_type
= IW_HEADER_TYPE_POINT
,
388 .max_tokens
= IW_GENERIC_IE_MAX
,
390 [IWEVASSOCRESPIE
- IWEVFIRST
] = {
391 .header_type
= IW_HEADER_TYPE_POINT
,
393 .max_tokens
= IW_GENERIC_IE_MAX
,
395 [IWEVPMKIDCAND
- IWEVFIRST
] = {
396 .header_type
= IW_HEADER_TYPE_POINT
,
398 .max_tokens
= sizeof(struct iw_pmkid_cand
),
401 static const unsigned standard_event_num
= ARRAY_SIZE(standard_event
);
403 /* Size (in bytes) of the various private data types */
404 static const char iw_priv_type_size
[] = {
405 0, /* IW_PRIV_TYPE_NONE */
406 1, /* IW_PRIV_TYPE_BYTE */
407 1, /* IW_PRIV_TYPE_CHAR */
409 sizeof(__u32
), /* IW_PRIV_TYPE_INT */
410 sizeof(struct iw_freq
), /* IW_PRIV_TYPE_FLOAT */
411 sizeof(struct sockaddr
), /* IW_PRIV_TYPE_ADDR */
415 /* Size (in bytes) of various events */
416 static const int event_type_size
[] = {
417 IW_EV_LCP_LEN
, /* IW_HEADER_TYPE_NULL */
419 IW_EV_CHAR_LEN
, /* IW_HEADER_TYPE_CHAR */
421 IW_EV_UINT_LEN
, /* IW_HEADER_TYPE_UINT */
422 IW_EV_FREQ_LEN
, /* IW_HEADER_TYPE_FREQ */
423 IW_EV_ADDR_LEN
, /* IW_HEADER_TYPE_ADDR */
425 IW_EV_POINT_LEN
, /* Without variable payload */
426 IW_EV_PARAM_LEN
, /* IW_HEADER_TYPE_PARAM */
427 IW_EV_QUAL_LEN
, /* IW_HEADER_TYPE_QUAL */
430 /* Size (in bytes) of various events, as packed */
431 static const int event_type_pk_size
[] = {
432 IW_EV_LCP_PK_LEN
, /* IW_HEADER_TYPE_NULL */
434 IW_EV_CHAR_PK_LEN
, /* IW_HEADER_TYPE_CHAR */
436 IW_EV_UINT_PK_LEN
, /* IW_HEADER_TYPE_UINT */
437 IW_EV_FREQ_PK_LEN
, /* IW_HEADER_TYPE_FREQ */
438 IW_EV_ADDR_PK_LEN
, /* IW_HEADER_TYPE_ADDR */
440 IW_EV_POINT_PK_LEN
, /* Without variable payload */
441 IW_EV_PARAM_PK_LEN
, /* IW_HEADER_TYPE_PARAM */
442 IW_EV_QUAL_PK_LEN
, /* IW_HEADER_TYPE_QUAL */
445 /************************ COMMON SUBROUTINES ************************/
447 * Stuff that may be used in various place or doesn't fit in one
448 * of the section below.
451 /* ---------------------------------------------------------------- */
453 * Return the driver handler associated with a specific Wireless Extension.
454 * Called from various place, so make sure it remains efficient.
456 static inline iw_handler
get_handler(struct net_device
*dev
,
459 /* Don't "optimise" the following variable, it will crash */
460 unsigned int index
; /* *MUST* be unsigned */
462 /* Check if we have some wireless handlers defined */
463 if (dev
->wireless_handlers
== NULL
)
466 /* Try as a standard command */
467 index
= cmd
- SIOCIWFIRST
;
468 if (index
< dev
->wireless_handlers
->num_standard
)
469 return dev
->wireless_handlers
->standard
[index
];
471 /* Try as a private command */
472 index
= cmd
- SIOCIWFIRSTPRIV
;
473 if (index
< dev
->wireless_handlers
->num_private
)
474 return dev
->wireless_handlers
->private[index
];
480 /* ---------------------------------------------------------------- */
482 * Get statistics out of the driver
484 static inline struct iw_statistics
*get_wireless_stats(struct net_device
*dev
)
487 if ((dev
->wireless_handlers
!= NULL
) &&
488 (dev
->wireless_handlers
->get_wireless_stats
!= NULL
))
489 return dev
->wireless_handlers
->get_wireless_stats(dev
);
492 return (struct iw_statistics
*) NULL
;
495 /* ---------------------------------------------------------------- */
497 * Call the commit handler in the driver
498 * (if exist and if conditions are right)
500 * Note : our current commit strategy is currently pretty dumb,
501 * but we will be able to improve on that...
502 * The goal is to try to agreagate as many changes as possible
503 * before doing the commit. Drivers that will define a commit handler
504 * are usually those that need a reset after changing parameters, so
505 * we want to minimise the number of reset.
506 * A cool idea is to use a timer : at each "set" command, we re-set the
507 * timer, when the timer eventually fires, we call the driver.
508 * Hopefully, more on that later.
510 * Also, I'm waiting to see how many people will complain about the
511 * netif_running(dev) test. I'm open on that one...
512 * Hopefully, the driver will remember to do a commit in "open()" ;-)
514 static inline int call_commit_handler(struct net_device
* dev
)
516 if ((netif_running(dev
)) &&
517 (dev
->wireless_handlers
->standard
[0] != NULL
)) {
518 /* Call the commit handler on the driver */
519 return dev
->wireless_handlers
->standard
[0](dev
, NULL
,
522 return 0; /* Command completed successfully */
525 /* ---------------------------------------------------------------- */
527 * Calculate size of private arguments
529 static inline int get_priv_size(__u16 args
)
531 int num
= args
& IW_PRIV_SIZE_MASK
;
532 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
534 return num
* iw_priv_type_size
[type
];
537 /* ---------------------------------------------------------------- */
539 * Re-calculate the size of private arguments
541 static inline int adjust_priv_size(__u16 args
,
542 union iwreq_data
* wrqu
)
544 int num
= wrqu
->data
.length
;
545 int max
= args
& IW_PRIV_SIZE_MASK
;
546 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
548 /* Make sure the driver doesn't goof up */
552 return num
* iw_priv_type_size
[type
];
555 /* ---------------------------------------------------------------- */
557 * Standard Wireless Handler : get wireless stats
558 * Allow programatic access to /proc/net/wireless even if /proc
559 * doesn't exist... Also more efficient...
561 static int iw_handler_get_iwstats(struct net_device
* dev
,
562 struct iw_request_info
* info
,
563 union iwreq_data
* wrqu
,
566 /* Get stats from the driver */
567 struct iw_statistics
*stats
;
569 stats
= get_wireless_stats(dev
);
570 if (stats
!= (struct iw_statistics
*) NULL
) {
572 /* Copy statistics to extra */
573 memcpy(extra
, stats
, sizeof(struct iw_statistics
));
574 wrqu
->data
.length
= sizeof(struct iw_statistics
);
576 /* Check if we need to clear the updated flag */
577 if (wrqu
->data
.flags
!= 0)
578 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
584 /* ---------------------------------------------------------------- */
586 * Standard Wireless Handler : get iwpriv definitions
587 * Export the driver private handler definition
588 * They will be picked up by tools like iwpriv...
590 static int iw_handler_get_private(struct net_device
* dev
,
591 struct iw_request_info
* info
,
592 union iwreq_data
* wrqu
,
595 /* Check if the driver has something to export */
596 if ((dev
->wireless_handlers
->num_private_args
== 0) ||
597 (dev
->wireless_handlers
->private_args
== NULL
))
600 /* Check if there is enough buffer up there */
601 if (wrqu
->data
.length
< dev
->wireless_handlers
->num_private_args
) {
602 /* User space can't know in advance how large the buffer
603 * needs to be. Give it a hint, so that we can support
604 * any size buffer we want somewhat efficiently... */
605 wrqu
->data
.length
= dev
->wireless_handlers
->num_private_args
;
609 /* Set the number of available ioctls. */
610 wrqu
->data
.length
= dev
->wireless_handlers
->num_private_args
;
612 /* Copy structure to the user buffer. */
613 memcpy(extra
, dev
->wireless_handlers
->private_args
,
614 sizeof(struct iw_priv_args
) * wrqu
->data
.length
);
620 /******************** /proc/net/wireless SUPPORT ********************/
622 * The /proc/net/wireless file is a human readable user-space interface
623 * exporting various wireless specific statistics from the wireless devices.
624 * This is the most popular part of the Wireless Extensions ;-)
626 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
627 * The content of the file is basically the content of "struct iw_statistics".
630 #ifdef CONFIG_PROC_FS
632 /* ---------------------------------------------------------------- */
634 * Print one entry (line) of /proc/net/wireless
636 static __inline__
void wireless_seq_printf_stats(struct seq_file
*seq
,
637 struct net_device
*dev
)
639 /* Get stats from the driver */
640 struct iw_statistics
*stats
= get_wireless_stats(dev
);
643 seq_printf(seq
, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
645 dev
->name
, stats
->status
, stats
->qual
.qual
,
646 stats
->qual
.updated
& IW_QUAL_QUAL_UPDATED
648 ((__s32
) stats
->qual
.level
) -
649 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
650 stats
->qual
.updated
& IW_QUAL_LEVEL_UPDATED
652 ((__s32
) stats
->qual
.noise
) -
653 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
654 stats
->qual
.updated
& IW_QUAL_NOISE_UPDATED
656 stats
->discard
.nwid
, stats
->discard
.code
,
657 stats
->discard
.fragment
, stats
->discard
.retries
,
658 stats
->discard
.misc
, stats
->miss
.beacon
);
659 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
663 /* ---------------------------------------------------------------- */
665 * Print info for /proc/net/wireless (print all entries)
667 static int wireless_seq_show(struct seq_file
*seq
, void *v
)
669 if (v
== SEQ_START_TOKEN
)
670 seq_printf(seq
, "Inter-| sta-| Quality | Discarded "
671 "packets | Missed | WE\n"
672 " face | tus | link level noise | nwid "
673 "crypt frag retry misc | beacon | %d\n",
676 wireless_seq_printf_stats(seq
, v
);
680 static const struct seq_operations wireless_seq_ops
= {
681 .start
= dev_seq_start
,
682 .next
= dev_seq_next
,
683 .stop
= dev_seq_stop
,
684 .show
= wireless_seq_show
,
687 static int wireless_seq_open(struct inode
*inode
, struct file
*file
)
689 return seq_open(file
, &wireless_seq_ops
);
692 static const struct file_operations wireless_seq_fops
= {
693 .owner
= THIS_MODULE
,
694 .open
= wireless_seq_open
,
697 .release
= seq_release
,
700 int __init
wext_proc_init(void)
702 /* Create /proc/net/wireless entry */
703 if (!proc_net_fops_create("wireless", S_IRUGO
, &wireless_seq_fops
))
708 #endif /* CONFIG_PROC_FS */
710 /************************** IOCTL SUPPORT **************************/
712 * The original user space API to configure all those Wireless Extensions
714 * In there, we check if we need to call the new driver API (iw_handler)
715 * or just call the driver ioctl handler.
718 /* ---------------------------------------------------------------- */
720 * Wrapper to call a standard Wireless Extension handler.
721 * We do various checks and also take care of moving data between
722 * user space and kernel space.
724 static int ioctl_standard_call(struct net_device
* dev
,
729 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
730 const struct iw_ioctl_description
* descr
;
731 struct iw_request_info info
;
734 /* Get the description of the IOCTL */
735 if ((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
737 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
739 #ifdef WE_IOCTL_DEBUG
740 printk(KERN_DEBUG
"%s (WE) : Found standard handler for 0x%04X\n",
742 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
);
743 #endif /* WE_IOCTL_DEBUG */
745 /* Prepare the call */
749 /* Check if we have a pointer to user space data or not */
750 if (descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
752 /* No extra arguments. Trivial to handle */
753 ret
= handler(dev
, &info
, &(iwr
->u
), NULL
);
756 /* Generate an event to notify listeners of the change */
757 if ((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
758 ((ret
== 0) || (ret
== -EIWCOMMIT
)))
759 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
760 #endif /* WE_SET_EVENT */
766 int essid_compat
= 0;
768 /* Calculate space needed by arguments. Always allocate
769 * for max space. Easier, and won't last long... */
770 extra_size
= descr
->max_tokens
* descr
->token_size
;
772 /* Check need for ESSID compatibility for WE < 21 */
778 if (iwr
->u
.data
.length
== descr
->max_tokens
+ 1)
780 else if (IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
781 char essid
[IW_ESSID_MAX_SIZE
+ 1];
783 err
= copy_from_user(essid
, iwr
->u
.data
.pointer
,
789 if (essid
[iwr
->u
.data
.length
- 1] == '\0')
797 iwr
->u
.data
.length
-= essid_compat
;
799 /* Check what user space is giving us */
800 if (IW_IS_SET(cmd
)) {
801 /* Check NULL pointer */
802 if ((iwr
->u
.data
.pointer
== NULL
) &&
803 (iwr
->u
.data
.length
!= 0))
805 /* Check if number of token fits within bounds */
806 if (iwr
->u
.data
.length
> descr
->max_tokens
)
808 if (iwr
->u
.data
.length
< descr
->min_tokens
)
811 /* Check NULL pointer */
812 if (iwr
->u
.data
.pointer
== NULL
)
814 /* Save user space buffer size for checking */
815 user_length
= iwr
->u
.data
.length
;
817 /* Don't check if user_length > max to allow forward
818 * compatibility. The test user_length < min is
819 * implied by the test at the end. */
821 /* Support for very large requests */
822 if ((descr
->flags
& IW_DESCR_FLAG_NOMAX
) &&
823 (user_length
> descr
->max_tokens
)) {
824 /* Allow userspace to GET more than max so
825 * we can support any size GET requests.
826 * There is still a limit : -ENOMEM. */
827 extra_size
= user_length
* descr
->token_size
;
828 /* Note : user_length is originally a __u16,
829 * and token_size is controlled by us,
830 * so extra_size won't get negative and
831 * won't overflow... */
835 #ifdef WE_IOCTL_DEBUG
836 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
837 dev
->name
, extra_size
);
838 #endif /* WE_IOCTL_DEBUG */
840 /* Create the kernel buffer */
841 /* kzalloc ensures NULL-termination for essid_compat */
842 extra
= kzalloc(extra_size
, GFP_KERNEL
);
847 /* If it is a SET, get all the extra data in here */
848 if (IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
849 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
856 #ifdef WE_IOCTL_DEBUG
857 printk(KERN_DEBUG
"%s (WE) : Got %d bytes\n",
859 iwr
->u
.data
.length
* descr
->token_size
);
860 #endif /* WE_IOCTL_DEBUG */
863 /* Call the handler */
864 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
866 iwr
->u
.data
.length
+= essid_compat
;
868 /* If we have something to return to the user */
869 if (!ret
&& IW_IS_GET(cmd
)) {
870 /* Check if there is enough buffer up there */
871 if (user_length
< iwr
->u
.data
.length
) {
876 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
881 #ifdef WE_IOCTL_DEBUG
882 printk(KERN_DEBUG
"%s (WE) : Wrote %d bytes\n",
884 iwr
->u
.data
.length
* descr
->token_size
);
885 #endif /* WE_IOCTL_DEBUG */
889 /* Generate an event to notify listeners of the change */
890 if ((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
891 ((ret
== 0) || (ret
== -EIWCOMMIT
))) {
892 if (descr
->flags
& IW_DESCR_FLAG_RESTRICT
)
893 /* If the event is restricted, don't
894 * export the payload */
895 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
897 wireless_send_event(dev
, cmd
, &(iwr
->u
),
900 #endif /* WE_SET_EVENT */
902 /* Cleanup - I told you it wasn't that long ;-) */
906 /* Call commit handler if needed and defined */
907 if (ret
== -EIWCOMMIT
)
908 ret
= call_commit_handler(dev
);
910 /* Here, we will generate the appropriate event if needed */
915 /* ---------------------------------------------------------------- */
917 * Wrapper to call a private Wireless Extension handler.
918 * We do various checks and also take care of moving data between
919 * user space and kernel space.
920 * It's not as nice and slimline as the standard wrapper. The cause
921 * is struct iw_priv_args, which was not really designed for the
922 * job we are going here.
924 * IMPORTANT : This function prevent to set and get data on the same
925 * IOCTL and enforce the SET/GET convention. Not doing it would be
927 * If you need to set and get data at the same time, please don't use
928 * a iw_handler but process it in your ioctl handler (i.e. use the
931 static inline int ioctl_private_call(struct net_device
* dev
,
936 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
937 const struct iw_priv_args
* descr
= NULL
;
938 struct iw_request_info info
;
943 /* Get the description of the IOCTL */
944 for (i
= 0; i
< dev
->wireless_handlers
->num_private_args
; i
++)
945 if (cmd
== dev
->wireless_handlers
->private_args
[i
].cmd
) {
946 descr
= &(dev
->wireless_handlers
->private_args
[i
]);
950 #ifdef WE_IOCTL_DEBUG
951 printk(KERN_DEBUG
"%s (WE) : Found private handler for 0x%04X\n",
954 printk(KERN_DEBUG
"%s (WE) : Name %s, set %X, get %X\n",
955 dev
->name
, descr
->name
,
956 descr
->set_args
, descr
->get_args
);
958 #endif /* WE_IOCTL_DEBUG */
960 /* Compute the size of the set/get arguments */
962 if (IW_IS_SET(cmd
)) {
963 int offset
= 0; /* For sub-ioctls */
964 /* Check for sub-ioctl handler */
965 if (descr
->name
[0] == '\0')
966 /* Reserve one int for sub-ioctl index */
967 offset
= sizeof(__u32
);
969 /* Size of set arguments */
970 extra_size
= get_priv_size(descr
->set_args
);
972 /* Does it fits in iwr ? */
973 if ((descr
->set_args
& IW_PRIV_SIZE_FIXED
) &&
974 ((extra_size
+ offset
) <= IFNAMSIZ
))
977 /* Size of get arguments */
978 extra_size
= get_priv_size(descr
->get_args
);
980 /* Does it fits in iwr ? */
981 if ((descr
->get_args
& IW_PRIV_SIZE_FIXED
) &&
982 (extra_size
<= IFNAMSIZ
))
987 /* Prepare the call */
991 /* Check if we have a pointer to user space data or not. */
992 if (extra_size
== 0) {
993 /* No extra arguments. Trivial to handle */
994 ret
= handler(dev
, &info
, &(iwr
->u
), (char *) &(iwr
->u
));
999 /* Check what user space is giving us */
1000 if (IW_IS_SET(cmd
)) {
1001 /* Check NULL pointer */
1002 if ((iwr
->u
.data
.pointer
== NULL
) &&
1003 (iwr
->u
.data
.length
!= 0))
1006 /* Does it fits within bounds ? */
1007 if (iwr
->u
.data
.length
> (descr
->set_args
&
1011 /* Check NULL pointer */
1012 if (iwr
->u
.data
.pointer
== NULL
)
1016 #ifdef WE_IOCTL_DEBUG
1017 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
1018 dev
->name
, extra_size
);
1019 #endif /* WE_IOCTL_DEBUG */
1021 /* Always allocate for max space. Easier, and won't last
1023 extra
= kmalloc(extra_size
, GFP_KERNEL
);
1024 if (extra
== NULL
) {
1028 /* If it is a SET, get all the extra data in here */
1029 if (IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
1030 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
1036 #ifdef WE_IOCTL_DEBUG
1037 printk(KERN_DEBUG
"%s (WE) : Got %d elem\n",
1038 dev
->name
, iwr
->u
.data
.length
);
1039 #endif /* WE_IOCTL_DEBUG */
1042 /* Call the handler */
1043 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
1045 /* If we have something to return to the user */
1046 if (!ret
&& IW_IS_GET(cmd
)) {
1048 /* Adjust for the actual length if it's variable,
1049 * avoid leaking kernel bits outside. */
1050 if (!(descr
->get_args
& IW_PRIV_SIZE_FIXED
)) {
1051 extra_size
= adjust_priv_size(descr
->get_args
,
1055 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
1059 #ifdef WE_IOCTL_DEBUG
1060 printk(KERN_DEBUG
"%s (WE) : Wrote %d elem\n",
1061 dev
->name
, iwr
->u
.data
.length
);
1062 #endif /* WE_IOCTL_DEBUG */
1065 /* Cleanup - I told you it wasn't that long ;-) */
1070 /* Call commit handler if needed and defined */
1071 if (ret
== -EIWCOMMIT
)
1072 ret
= call_commit_handler(dev
);
1077 /* ---------------------------------------------------------------- */
1079 * Main IOCTl dispatcher.
1080 * Check the type of IOCTL and call the appropriate wrapper...
1082 static int wireless_process_ioctl(struct ifreq
*ifr
, unsigned int cmd
)
1084 struct net_device
*dev
;
1087 /* Permissions are already checked in dev_ioctl() before calling us.
1088 * The copy_to/from_user() of ifr is also dealt with in there */
1090 /* Make sure the device exist */
1091 if ((dev
= __dev_get_by_name(ifr
->ifr_name
)) == NULL
)
1094 /* A bunch of special cases, then the generic case...
1095 * Note that 'cmd' is already filtered in dev_ioctl() with
1096 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1099 /* Get Wireless Stats */
1100 return ioctl_standard_call(dev
,
1103 &iw_handler_get_iwstats
);
1106 /* Check if we have some wireless handlers defined */
1107 if (dev
->wireless_handlers
!= NULL
) {
1108 /* We export to user space the definition of
1109 * the private handler ourselves */
1110 return ioctl_standard_call(dev
,
1113 &iw_handler_get_private
);
1115 // ## Fall-through for old API ##
1119 if (!netif_device_present(dev
))
1121 /* New driver API : try to find the handler */
1122 handler
= get_handler(dev
, cmd
);
1123 if (handler
!= NULL
) {
1124 /* Standard and private are not the same */
1125 if (cmd
< SIOCIWFIRSTPRIV
)
1126 return ioctl_standard_call(dev
,
1131 return ioctl_private_call(dev
,
1136 /* Old driver API : call driver ioctl handler */
1137 if (dev
->do_ioctl
) {
1138 return dev
->do_ioctl(dev
, ifr
, cmd
);
1146 /* entry point from dev ioctl */
1147 int wext_handle_ioctl(struct ifreq
*ifr
, unsigned int cmd
,
1152 /* If command is `set a parameter', or
1153 * `get the encoding parameters', check if
1154 * the user has the right to do it */
1155 if (IW_IS_SET(cmd
) || cmd
== SIOCGIWENCODE
|| cmd
== SIOCGIWENCODEEXT
)
1156 if (!capable(CAP_NET_ADMIN
))
1158 dev_load(ifr
->ifr_name
);
1160 ret
= wireless_process_ioctl(ifr
, cmd
);
1162 if (IW_IS_GET(cmd
) && copy_to_user(arg
, ifr
, sizeof(struct ifreq
)))
1167 /************************* EVENT PROCESSING *************************/
1169 * Process events generated by the wireless layer or the driver.
1170 * Most often, the event will be propagated through rtnetlink
1173 #ifdef WE_EVENT_RTNETLINK
1174 /* ---------------------------------------------------------------- */
1179 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1180 * the locking issue in here and implementing this code !
1182 * The issue : wireless_send_event() is often called in interrupt context,
1183 * while the Netlink layer can never be called in interrupt context.
1184 * The fully formed RtNetlink events are queued, and then a tasklet is run
1185 * to feed those to Netlink.
1186 * The skb_queue is interrupt safe, and its lock is not held while calling
1187 * Netlink, so there is no possibility of dealock.
1191 static struct sk_buff_head wireless_nlevent_queue
;
1193 static int __init
wireless_nlevent_init(void)
1195 skb_queue_head_init(&wireless_nlevent_queue
);
1199 subsys_initcall(wireless_nlevent_init
);
1201 static void wireless_nlevent_process(unsigned long data
)
1203 struct sk_buff
*skb
;
1205 while ((skb
= skb_dequeue(&wireless_nlevent_queue
)))
1206 rtnl_notify(skb
, 0, RTNLGRP_LINK
, NULL
, GFP_ATOMIC
);
1209 static DECLARE_TASKLET(wireless_nlevent_tasklet
, wireless_nlevent_process
, 0);
1211 /* ---------------------------------------------------------------- */
1213 * Fill a rtnetlink message with our event data.
1214 * Note that we propage only the specified event and don't dump the
1215 * current wireless config. Dumping the wireless config is far too
1216 * expensive (for each parameter, the driver need to query the hardware).
1218 static inline int rtnetlink_fill_iwinfo(struct sk_buff
* skb
,
1219 struct net_device
* dev
,
1224 struct ifinfomsg
*r
;
1225 struct nlmsghdr
*nlh
;
1226 unsigned char *b
= skb_tail_pointer(skb
);
1228 nlh
= NLMSG_PUT(skb
, 0, 0, type
, sizeof(*r
));
1229 r
= NLMSG_DATA(nlh
);
1230 r
->ifi_family
= AF_UNSPEC
;
1232 r
->ifi_type
= dev
->type
;
1233 r
->ifi_index
= dev
->ifindex
;
1234 r
->ifi_flags
= dev_get_flags(dev
);
1235 r
->ifi_change
= 0; /* Wireless changes don't affect those flags */
1237 /* Add the wireless events in the netlink packet */
1238 RTA_PUT(skb
, IFLA_WIRELESS
, event_len
, event
);
1240 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1249 /* ---------------------------------------------------------------- */
1251 * Create and broadcast and send it on the standard rtnetlink socket
1252 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1253 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1254 * within a RTM_NEWLINK event.
1256 static inline void rtmsg_iwinfo(struct net_device
* dev
,
1260 struct sk_buff
*skb
;
1261 int size
= NLMSG_GOODSIZE
;
1263 skb
= alloc_skb(size
, GFP_ATOMIC
);
1267 if (rtnetlink_fill_iwinfo(skb
, dev
, RTM_NEWLINK
,
1268 event
, event_len
) < 0) {
1272 NETLINK_CB(skb
).dst_group
= RTNLGRP_LINK
;
1273 skb_queue_tail(&wireless_nlevent_queue
, skb
);
1274 tasklet_schedule(&wireless_nlevent_tasklet
);
1277 #endif /* WE_EVENT_RTNETLINK */
1279 /* ---------------------------------------------------------------- */
1281 * Main event dispatcher. Called from other parts and drivers.
1282 * Send the event on the appropriate channels.
1283 * May be called from interrupt context.
1285 void wireless_send_event(struct net_device
* dev
,
1287 union iwreq_data
* wrqu
,
1290 const struct iw_ioctl_description
* descr
= NULL
;
1292 struct iw_event
*event
; /* Mallocated whole event */
1293 int event_len
; /* Its size */
1294 int hdr_len
; /* Size of the event header */
1295 int wrqu_off
= 0; /* Offset in wrqu */
1296 /* Don't "optimise" the following variable, it will crash */
1297 unsigned cmd_index
; /* *MUST* be unsigned */
1299 /* Get the description of the Event */
1300 if (cmd
<= SIOCIWLAST
) {
1301 cmd_index
= cmd
- SIOCIWFIRST
;
1302 if (cmd_index
< standard_ioctl_num
)
1303 descr
= &(standard_ioctl
[cmd_index
]);
1305 cmd_index
= cmd
- IWEVFIRST
;
1306 if (cmd_index
< standard_event_num
)
1307 descr
= &(standard_event
[cmd_index
]);
1309 /* Don't accept unknown events */
1310 if (descr
== NULL
) {
1311 /* Note : we don't return an error to the driver, because
1312 * the driver would not know what to do about it. It can't
1313 * return an error to the user, because the event is not
1314 * initiated by a user request.
1315 * The best the driver could do is to log an error message.
1316 * We will do it ourselves instead...
1318 printk(KERN_ERR
"%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1322 #ifdef WE_EVENT_DEBUG
1323 printk(KERN_DEBUG
"%s (WE) : Got event 0x%04X\n",
1325 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
);
1326 #endif /* WE_EVENT_DEBUG */
1328 /* Check extra parameters and set extra_len */
1329 if (descr
->header_type
== IW_HEADER_TYPE_POINT
) {
1330 /* Check if number of token fits within bounds */
1331 if (wrqu
->data
.length
> descr
->max_tokens
) {
1332 printk(KERN_ERR
"%s (WE) : Wireless Event too big (%d)\n", dev
->name
, wrqu
->data
.length
);
1335 if (wrqu
->data
.length
< descr
->min_tokens
) {
1336 printk(KERN_ERR
"%s (WE) : Wireless Event too small (%d)\n", dev
->name
, wrqu
->data
.length
);
1339 /* Calculate extra_len - extra is NULL for restricted events */
1341 extra_len
= wrqu
->data
.length
* descr
->token_size
;
1342 /* Always at an offset in wrqu */
1343 wrqu_off
= IW_EV_POINT_OFF
;
1344 #ifdef WE_EVENT_DEBUG
1345 printk(KERN_DEBUG
"%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev
->name
, cmd
, wrqu
->data
.length
, extra_len
);
1346 #endif /* WE_EVENT_DEBUG */
1349 /* Total length of the event */
1350 hdr_len
= event_type_size
[descr
->header_type
];
1351 event_len
= hdr_len
+ extra_len
;
1353 #ifdef WE_EVENT_DEBUG
1354 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
);
1355 #endif /* WE_EVENT_DEBUG */
1357 /* Create temporary buffer to hold the event */
1358 event
= kmalloc(event_len
, GFP_ATOMIC
);
1363 event
->len
= event_len
;
1365 memcpy(&event
->u
, ((char *) wrqu
) + wrqu_off
, hdr_len
- IW_EV_LCP_LEN
);
1367 memcpy(((char *) event
) + hdr_len
, extra
, extra_len
);
1369 #ifdef WE_EVENT_RTNETLINK
1370 /* Send via the RtNetlink event channel */
1371 rtmsg_iwinfo(dev
, (char *) event
, event_len
);
1372 #endif /* WE_EVENT_RTNETLINK */
1377 return; /* Always success, I guess ;-) */
1380 /********************** ENHANCED IWSPY SUPPORT **********************/
1382 * In the old days, the driver was handling spy support all by itself.
1383 * Now, the driver can delegate this task to Wireless Extensions.
1384 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1385 * push data to us via wireless_spy_update() and include struct iw_spy_data
1386 * in its private part (and export it in net_device->wireless_data->spy_data).
1387 * One of the main advantage of centralising spy support here is that
1388 * it becomes much easier to improve and extend it without having to touch
1389 * the drivers. One example is the addition of the Spy-Threshold events.
1392 /* ---------------------------------------------------------------- */
1394 * Return the pointer to the spy data in the driver.
1395 * Because this is called on the Rx path via wireless_spy_update(),
1396 * we want it to be efficient...
1398 static inline struct iw_spy_data
* get_spydata(struct net_device
*dev
)
1400 /* This is the new way */
1401 if (dev
->wireless_data
)
1402 return(dev
->wireless_data
->spy_data
);
1406 /*------------------------------------------------------------------*/
1408 * Standard Wireless Handler : set Spy List
1410 int iw_handler_set_spy(struct net_device
* dev
,
1411 struct iw_request_info
* info
,
1412 union iwreq_data
* wrqu
,
1415 struct iw_spy_data
* spydata
= get_spydata(dev
);
1416 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1418 /* Make sure driver is not buggy or using the old API */
1422 /* Disable spy collection while we copy the addresses.
1423 * While we copy addresses, any call to wireless_spy_update()
1424 * will NOP. This is OK, as anyway the addresses are changing. */
1425 spydata
->spy_number
= 0;
1427 /* We want to operate without locking, because wireless_spy_update()
1428 * most likely will happen in the interrupt handler, and therefore
1429 * have its own locking constraints and needs performance.
1430 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1431 * This make sure wireless_spy_update() "see" that the spy list
1432 * is temporarily disabled. */
1435 /* Are there are addresses to copy? */
1436 if (wrqu
->data
.length
> 0) {
1439 /* Copy addresses */
1440 for (i
= 0; i
< wrqu
->data
.length
; i
++)
1441 memcpy(spydata
->spy_address
[i
], address
[i
].sa_data
,
1444 memset(spydata
->spy_stat
, 0,
1445 sizeof(struct iw_quality
) * IW_MAX_SPY
);
1448 printk(KERN_DEBUG
"iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev
->wireless_data
, spydata
, wrqu
->data
.length
);
1449 for (i
= 0; i
< wrqu
->data
.length
; i
++)
1451 "%02X:%02X:%02X:%02X:%02X:%02X \n",
1452 spydata
->spy_address
[i
][0],
1453 spydata
->spy_address
[i
][1],
1454 spydata
->spy_address
[i
][2],
1455 spydata
->spy_address
[i
][3],
1456 spydata
->spy_address
[i
][4],
1457 spydata
->spy_address
[i
][5]);
1458 #endif /* WE_SPY_DEBUG */
1461 /* Make sure above is updated before re-enabling */
1464 /* Enable addresses */
1465 spydata
->spy_number
= wrqu
->data
.length
;
1470 /*------------------------------------------------------------------*/
1472 * Standard Wireless Handler : get Spy List
1474 int iw_handler_get_spy(struct net_device
* dev
,
1475 struct iw_request_info
* info
,
1476 union iwreq_data
* wrqu
,
1479 struct iw_spy_data
* spydata
= get_spydata(dev
);
1480 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1483 /* Make sure driver is not buggy or using the old API */
1487 wrqu
->data
.length
= spydata
->spy_number
;
1489 /* Copy addresses. */
1490 for (i
= 0; i
< spydata
->spy_number
; i
++) {
1491 memcpy(address
[i
].sa_data
, spydata
->spy_address
[i
], ETH_ALEN
);
1492 address
[i
].sa_family
= AF_UNIX
;
1494 /* Copy stats to the user buffer (just after). */
1495 if (spydata
->spy_number
> 0)
1496 memcpy(extra
+ (sizeof(struct sockaddr
) *spydata
->spy_number
),
1498 sizeof(struct iw_quality
) * spydata
->spy_number
);
1499 /* Reset updated flags. */
1500 for (i
= 0; i
< spydata
->spy_number
; i
++)
1501 spydata
->spy_stat
[i
].updated
&= ~IW_QUAL_ALL_UPDATED
;
1505 /*------------------------------------------------------------------*/
1507 * Standard Wireless Handler : set spy threshold
1509 int iw_handler_set_thrspy(struct net_device
* dev
,
1510 struct iw_request_info
*info
,
1511 union iwreq_data
* wrqu
,
1514 struct iw_spy_data
* spydata
= get_spydata(dev
);
1515 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1517 /* Make sure driver is not buggy or using the old API */
1522 memcpy(&(spydata
->spy_thr_low
), &(threshold
->low
),
1523 2 * sizeof(struct iw_quality
));
1526 memset(spydata
->spy_thr_under
, '\0', sizeof(spydata
->spy_thr_under
));
1529 printk(KERN_DEBUG
"iw_handler_set_thrspy() : low %d ; high %d\n", spydata
->spy_thr_low
.level
, spydata
->spy_thr_high
.level
);
1530 #endif /* WE_SPY_DEBUG */
1535 /*------------------------------------------------------------------*/
1537 * Standard Wireless Handler : get spy threshold
1539 int iw_handler_get_thrspy(struct net_device
* dev
,
1540 struct iw_request_info
*info
,
1541 union iwreq_data
* wrqu
,
1544 struct iw_spy_data
* spydata
= get_spydata(dev
);
1545 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1547 /* Make sure driver is not buggy or using the old API */
1552 memcpy(&(threshold
->low
), &(spydata
->spy_thr_low
),
1553 2 * sizeof(struct iw_quality
));
1558 /*------------------------------------------------------------------*/
1560 * Prepare and send a Spy Threshold event
1562 static void iw_send_thrspy_event(struct net_device
* dev
,
1563 struct iw_spy_data
* spydata
,
1564 unsigned char * address
,
1565 struct iw_quality
* wstats
)
1567 union iwreq_data wrqu
;
1568 struct iw_thrspy threshold
;
1571 wrqu
.data
.length
= 1;
1572 wrqu
.data
.flags
= 0;
1574 memcpy(threshold
.addr
.sa_data
, address
, ETH_ALEN
);
1575 threshold
.addr
.sa_family
= ARPHRD_ETHER
;
1577 memcpy(&(threshold
.qual
), wstats
, sizeof(struct iw_quality
));
1578 /* Copy also thresholds */
1579 memcpy(&(threshold
.low
), &(spydata
->spy_thr_low
),
1580 2 * sizeof(struct iw_quality
));
1583 printk(KERN_DEBUG
"iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
1584 threshold
.addr
.sa_data
[0],
1585 threshold
.addr
.sa_data
[1],
1586 threshold
.addr
.sa_data
[2],
1587 threshold
.addr
.sa_data
[3],
1588 threshold
.addr
.sa_data
[4],
1589 threshold
.addr
.sa_data
[5], threshold
.qual
.level
);
1590 #endif /* WE_SPY_DEBUG */
1592 /* Send event to user space */
1593 wireless_send_event(dev
, SIOCGIWTHRSPY
, &wrqu
, (char *) &threshold
);
1596 /* ---------------------------------------------------------------- */
1598 * Call for the driver to update the spy data.
1599 * For now, the spy data is a simple array. As the size of the array is
1600 * small, this is good enough. If we wanted to support larger number of
1601 * spy addresses, we should use something more efficient...
1603 void wireless_spy_update(struct net_device
* dev
,
1604 unsigned char * address
,
1605 struct iw_quality
* wstats
)
1607 struct iw_spy_data
* spydata
= get_spydata(dev
);
1611 /* Make sure driver is not buggy or using the old API */
1616 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]);
1617 #endif /* WE_SPY_DEBUG */
1619 /* Update all records that match */
1620 for (i
= 0; i
< spydata
->spy_number
; i
++)
1621 if (!compare_ether_addr(address
, spydata
->spy_address
[i
])) {
1622 memcpy(&(spydata
->spy_stat
[i
]), wstats
,
1623 sizeof(struct iw_quality
));
1627 /* Generate an event if we cross the spy threshold.
1628 * To avoid event storms, we have a simple hysteresis : we generate
1629 * event only when we go under the low threshold or above the
1630 * high threshold. */
1632 if (spydata
->spy_thr_under
[match
]) {
1633 if (wstats
->level
> spydata
->spy_thr_high
.level
) {
1634 spydata
->spy_thr_under
[match
] = 0;
1635 iw_send_thrspy_event(dev
, spydata
,
1639 if (wstats
->level
< spydata
->spy_thr_low
.level
) {
1640 spydata
->spy_thr_under
[match
] = 1;
1641 iw_send_thrspy_event(dev
, spydata
,
1648 EXPORT_SYMBOL(iw_handler_get_spy
);
1649 EXPORT_SYMBOL(iw_handler_get_thrspy
);
1650 EXPORT_SYMBOL(iw_handler_set_spy
);
1651 EXPORT_SYMBOL(iw_handler_set_thrspy
);
1652 EXPORT_SYMBOL(wireless_send_event
);
1653 EXPORT_SYMBOL(wireless_spy_update
);