2 * This file implement the Wireless Extensions APIs.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
7 * (As all part of the Linux kernel, this file is GPL)
10 /************************** DOCUMENTATION **************************/
14 * See <linux/wireless.h> for details of the APIs and the rest.
19 * v1 - 5.12.01 - Jean II
20 * o Created this file.
22 * v2 - 13.12.01 - Jean II
23 * o Move /proc/net/wireless stuff from net/core/dev.c to here
24 * o Make Wireless Extension IOCTLs go through here
25 * o Added iw_handler handling ;-)
26 * o Added standard ioctl description
27 * o Initial dumb commit strategy based on orinoco.c
29 * v3 - 19.12.01 - Jean II
30 * o Make sure we don't go out of standard_ioctl[] in ioctl_standard_call
31 * o Add event dispatcher function
32 * o Add event description
33 * o Propagate events as rtnetlink IFLA_WIRELESS option
34 * o Generate event on selected SET requests
36 * v4 - 18.04.02 - Jean II
37 * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1
39 * v5 - 21.06.02 - Jean II
40 * o Add IW_PRIV_TYPE_ADDR in priv_type_size (+cleanup)
41 * o Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes
42 * o Add IWEVCUSTOM for driver specific event/scanning token
43 * o Turn on WE_STRICT_WRITE by default + kernel warning
44 * o Fix WE_STRICT_WRITE in ioctl_export_private() (32 => iw_num)
45 * o Fix off-by-one in test (extra_size <= IFNAMSIZ)
47 * v6 - 9.01.03 - Jean II
48 * o Add common spy support : iw_handler_set_spy(), wireless_spy_update()
49 * o Add enhanced spy support : iw_handler_set_thrspy() and event.
50 * o Add WIRELESS_EXT version display in /proc/net/wireless
52 * v6 - 18.06.04 - Jean II
53 * o Change get_spydata() method for added safety
54 * o Remove spy #ifdef, they are always on -> cleaner code
55 * o Allow any size GET request if user specifies length > max
56 * and if request has IW_DESCR_FLAG_NOMAX flag or is SIOCGIWPRIV
57 * o Start migrating get_wireless_stats to struct iw_handler_def
58 * o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus
59 * Based on patch from Pavel Roskin <proski@gnu.org> :
60 * o Fix kernel data leak to user space in private handler handling
62 * v7 - 18.3.05 - Jean II
63 * o Remove (struct iw_point *)->pointer from events and streams
64 * o Remove spy_offset from struct iw_handler_def
65 * o Start deprecating dev->get_wireless_stats, output a warning
66 * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless
67 * o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats)
69 * v8 - 17.02.06 - Jean II
70 * o RtNetlink requests support (SET/GET)
72 * v8b - 03.08.06 - Herbert Xu
73 * o Fix Wireless Event locking issues.
75 * v9 - 14.3.06 - Jean II
76 * o Change length in ESSID and NICK to strlen() instead of strlen()+1
77 * o Make standard_ioctl_num and standard_event_num unsigned
78 * o Remove (struct net_device *)->get_wireless_stats()
80 * v10 - 16.3.07 - Jean II
81 * o Prevent leaking of kernel space in stream on 64 bits.
84 /***************************** INCLUDES *****************************/
86 #include <linux/module.h>
87 #include <linux/types.h> /* off_t */
88 #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
89 #include <linux/proc_fs.h>
90 #include <linux/rtnetlink.h> /* rtnetlink stuff */
91 #include <linux/seq_file.h>
92 #include <linux/init.h> /* for __init */
93 #include <linux/if_arp.h> /* ARPHRD_ETHER */
94 #include <linux/etherdevice.h> /* compare_ether_addr */
95 #include <linux/interrupt.h>
97 #include <linux/wireless.h> /* Pretty obvious */
98 #include <net/iw_handler.h> /* New driver API */
99 #include <net/netlink.h>
101 #include <asm/uaccess.h> /* copy_to_user() */
103 /**************************** CONSTANTS ****************************/
105 /* Debugging stuff */
106 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
107 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
108 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
111 #define WE_EVENT_RTNETLINK /* Propagate events using RtNetlink */
112 #define WE_SET_EVENT /* Generate an event on some set commands */
114 /************************* GLOBAL VARIABLES *************************/
116 * You should not use global variables, because of re-entrancy.
117 * On our case, it's only const, so it's OK...
120 * Meta-data about all the standard Wireless Extension request we
123 static const struct iw_ioctl_description standard_ioctl
[] = {
124 [SIOCSIWCOMMIT
- SIOCIWFIRST
] = {
125 .header_type
= IW_HEADER_TYPE_NULL
,
127 [SIOCGIWNAME
- SIOCIWFIRST
] = {
128 .header_type
= IW_HEADER_TYPE_CHAR
,
129 .flags
= IW_DESCR_FLAG_DUMP
,
131 [SIOCSIWNWID
- SIOCIWFIRST
] = {
132 .header_type
= IW_HEADER_TYPE_PARAM
,
133 .flags
= IW_DESCR_FLAG_EVENT
,
135 [SIOCGIWNWID
- SIOCIWFIRST
] = {
136 .header_type
= IW_HEADER_TYPE_PARAM
,
137 .flags
= IW_DESCR_FLAG_DUMP
,
139 [SIOCSIWFREQ
- SIOCIWFIRST
] = {
140 .header_type
= IW_HEADER_TYPE_FREQ
,
141 .flags
= IW_DESCR_FLAG_EVENT
,
143 [SIOCGIWFREQ
- SIOCIWFIRST
] = {
144 .header_type
= IW_HEADER_TYPE_FREQ
,
145 .flags
= IW_DESCR_FLAG_DUMP
,
147 [SIOCSIWMODE
- SIOCIWFIRST
] = {
148 .header_type
= IW_HEADER_TYPE_UINT
,
149 .flags
= IW_DESCR_FLAG_EVENT
,
151 [SIOCGIWMODE
- SIOCIWFIRST
] = {
152 .header_type
= IW_HEADER_TYPE_UINT
,
153 .flags
= IW_DESCR_FLAG_DUMP
,
155 [SIOCSIWSENS
- SIOCIWFIRST
] = {
156 .header_type
= IW_HEADER_TYPE_PARAM
,
158 [SIOCGIWSENS
- SIOCIWFIRST
] = {
159 .header_type
= IW_HEADER_TYPE_PARAM
,
161 [SIOCSIWRANGE
- SIOCIWFIRST
] = {
162 .header_type
= IW_HEADER_TYPE_NULL
,
164 [SIOCGIWRANGE
- SIOCIWFIRST
] = {
165 .header_type
= IW_HEADER_TYPE_POINT
,
167 .max_tokens
= sizeof(struct iw_range
),
168 .flags
= IW_DESCR_FLAG_DUMP
,
170 [SIOCSIWPRIV
- SIOCIWFIRST
] = {
171 .header_type
= IW_HEADER_TYPE_NULL
,
173 [SIOCGIWPRIV
- SIOCIWFIRST
] = { /* (handled directly by us) */
174 .header_type
= IW_HEADER_TYPE_POINT
,
175 .token_size
= sizeof(struct iw_priv_args
),
177 .flags
= IW_DESCR_FLAG_NOMAX
,
179 [SIOCSIWSTATS
- SIOCIWFIRST
] = {
180 .header_type
= IW_HEADER_TYPE_NULL
,
182 [SIOCGIWSTATS
- SIOCIWFIRST
] = { /* (handled directly by us) */
183 .header_type
= IW_HEADER_TYPE_POINT
,
185 .max_tokens
= sizeof(struct iw_statistics
),
186 .flags
= IW_DESCR_FLAG_DUMP
,
188 [SIOCSIWSPY
- SIOCIWFIRST
] = {
189 .header_type
= IW_HEADER_TYPE_POINT
,
190 .token_size
= sizeof(struct sockaddr
),
191 .max_tokens
= IW_MAX_SPY
,
193 [SIOCGIWSPY
- SIOCIWFIRST
] = {
194 .header_type
= IW_HEADER_TYPE_POINT
,
195 .token_size
= sizeof(struct sockaddr
) +
196 sizeof(struct iw_quality
),
197 .max_tokens
= IW_MAX_SPY
,
199 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = {
200 .header_type
= IW_HEADER_TYPE_POINT
,
201 .token_size
= sizeof(struct iw_thrspy
),
205 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = {
206 .header_type
= IW_HEADER_TYPE_POINT
,
207 .token_size
= sizeof(struct iw_thrspy
),
211 [SIOCSIWAP
- SIOCIWFIRST
] = {
212 .header_type
= IW_HEADER_TYPE_ADDR
,
214 [SIOCGIWAP
- SIOCIWFIRST
] = {
215 .header_type
= IW_HEADER_TYPE_ADDR
,
216 .flags
= IW_DESCR_FLAG_DUMP
,
218 [SIOCSIWMLME
- SIOCIWFIRST
] = {
219 .header_type
= IW_HEADER_TYPE_POINT
,
221 .min_tokens
= sizeof(struct iw_mlme
),
222 .max_tokens
= sizeof(struct iw_mlme
),
224 [SIOCGIWAPLIST
- SIOCIWFIRST
] = {
225 .header_type
= IW_HEADER_TYPE_POINT
,
226 .token_size
= sizeof(struct sockaddr
) +
227 sizeof(struct iw_quality
),
228 .max_tokens
= IW_MAX_AP
,
229 .flags
= IW_DESCR_FLAG_NOMAX
,
231 [SIOCSIWSCAN
- SIOCIWFIRST
] = {
232 .header_type
= IW_HEADER_TYPE_POINT
,
235 .max_tokens
= sizeof(struct iw_scan_req
),
237 [SIOCGIWSCAN
- SIOCIWFIRST
] = {
238 .header_type
= IW_HEADER_TYPE_POINT
,
240 .max_tokens
= IW_SCAN_MAX_DATA
,
241 .flags
= IW_DESCR_FLAG_NOMAX
,
243 [SIOCSIWESSID
- SIOCIWFIRST
] = {
244 .header_type
= IW_HEADER_TYPE_POINT
,
246 .max_tokens
= IW_ESSID_MAX_SIZE
,
247 .flags
= IW_DESCR_FLAG_EVENT
,
249 [SIOCGIWESSID
- SIOCIWFIRST
] = {
250 .header_type
= IW_HEADER_TYPE_POINT
,
252 .max_tokens
= IW_ESSID_MAX_SIZE
,
253 .flags
= IW_DESCR_FLAG_DUMP
,
255 [SIOCSIWNICKN
- SIOCIWFIRST
] = {
256 .header_type
= IW_HEADER_TYPE_POINT
,
258 .max_tokens
= IW_ESSID_MAX_SIZE
,
260 [SIOCGIWNICKN
- SIOCIWFIRST
] = {
261 .header_type
= IW_HEADER_TYPE_POINT
,
263 .max_tokens
= IW_ESSID_MAX_SIZE
,
265 [SIOCSIWRATE
- SIOCIWFIRST
] = {
266 .header_type
= IW_HEADER_TYPE_PARAM
,
268 [SIOCGIWRATE
- SIOCIWFIRST
] = {
269 .header_type
= IW_HEADER_TYPE_PARAM
,
271 [SIOCSIWRTS
- SIOCIWFIRST
] = {
272 .header_type
= IW_HEADER_TYPE_PARAM
,
274 [SIOCGIWRTS
- SIOCIWFIRST
] = {
275 .header_type
= IW_HEADER_TYPE_PARAM
,
277 [SIOCSIWFRAG
- SIOCIWFIRST
] = {
278 .header_type
= IW_HEADER_TYPE_PARAM
,
280 [SIOCGIWFRAG
- SIOCIWFIRST
] = {
281 .header_type
= IW_HEADER_TYPE_PARAM
,
283 [SIOCSIWTXPOW
- SIOCIWFIRST
] = {
284 .header_type
= IW_HEADER_TYPE_PARAM
,
286 [SIOCGIWTXPOW
- SIOCIWFIRST
] = {
287 .header_type
= IW_HEADER_TYPE_PARAM
,
289 [SIOCSIWRETRY
- SIOCIWFIRST
] = {
290 .header_type
= IW_HEADER_TYPE_PARAM
,
292 [SIOCGIWRETRY
- SIOCIWFIRST
] = {
293 .header_type
= IW_HEADER_TYPE_PARAM
,
295 [SIOCSIWENCODE
- SIOCIWFIRST
] = {
296 .header_type
= IW_HEADER_TYPE_POINT
,
298 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
299 .flags
= IW_DESCR_FLAG_EVENT
| IW_DESCR_FLAG_RESTRICT
,
301 [SIOCGIWENCODE
- SIOCIWFIRST
] = {
302 .header_type
= IW_HEADER_TYPE_POINT
,
304 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
305 .flags
= IW_DESCR_FLAG_DUMP
| IW_DESCR_FLAG_RESTRICT
,
307 [SIOCSIWPOWER
- SIOCIWFIRST
] = {
308 .header_type
= IW_HEADER_TYPE_PARAM
,
310 [SIOCGIWPOWER
- SIOCIWFIRST
] = {
311 .header_type
= IW_HEADER_TYPE_PARAM
,
313 [SIOCSIWGENIE
- SIOCIWFIRST
] = {
314 .header_type
= IW_HEADER_TYPE_POINT
,
316 .max_tokens
= IW_GENERIC_IE_MAX
,
318 [SIOCGIWGENIE
- SIOCIWFIRST
] = {
319 .header_type
= IW_HEADER_TYPE_POINT
,
321 .max_tokens
= IW_GENERIC_IE_MAX
,
323 [SIOCSIWAUTH
- SIOCIWFIRST
] = {
324 .header_type
= IW_HEADER_TYPE_PARAM
,
326 [SIOCGIWAUTH
- SIOCIWFIRST
] = {
327 .header_type
= IW_HEADER_TYPE_PARAM
,
329 [SIOCSIWENCODEEXT
- SIOCIWFIRST
] = {
330 .header_type
= IW_HEADER_TYPE_POINT
,
332 .min_tokens
= sizeof(struct iw_encode_ext
),
333 .max_tokens
= sizeof(struct iw_encode_ext
) +
334 IW_ENCODING_TOKEN_MAX
,
336 [SIOCGIWENCODEEXT
- SIOCIWFIRST
] = {
337 .header_type
= IW_HEADER_TYPE_POINT
,
339 .min_tokens
= sizeof(struct iw_encode_ext
),
340 .max_tokens
= sizeof(struct iw_encode_ext
) +
341 IW_ENCODING_TOKEN_MAX
,
343 [SIOCSIWPMKSA
- SIOCIWFIRST
] = {
344 .header_type
= IW_HEADER_TYPE_POINT
,
346 .min_tokens
= sizeof(struct iw_pmksa
),
347 .max_tokens
= sizeof(struct iw_pmksa
),
350 static const unsigned standard_ioctl_num
= ARRAY_SIZE(standard_ioctl
);
353 * Meta-data about all the additional standard Wireless Extension events
356 static const struct iw_ioctl_description standard_event
[] = {
357 [IWEVTXDROP
- IWEVFIRST
] = {
358 .header_type
= IW_HEADER_TYPE_ADDR
,
360 [IWEVQUAL
- IWEVFIRST
] = {
361 .header_type
= IW_HEADER_TYPE_QUAL
,
363 [IWEVCUSTOM
- IWEVFIRST
] = {
364 .header_type
= IW_HEADER_TYPE_POINT
,
366 .max_tokens
= IW_CUSTOM_MAX
,
368 [IWEVREGISTERED
- IWEVFIRST
] = {
369 .header_type
= IW_HEADER_TYPE_ADDR
,
371 [IWEVEXPIRED
- IWEVFIRST
] = {
372 .header_type
= IW_HEADER_TYPE_ADDR
,
374 [IWEVGENIE
- IWEVFIRST
] = {
375 .header_type
= IW_HEADER_TYPE_POINT
,
377 .max_tokens
= IW_GENERIC_IE_MAX
,
379 [IWEVMICHAELMICFAILURE
- IWEVFIRST
] = {
380 .header_type
= IW_HEADER_TYPE_POINT
,
382 .max_tokens
= sizeof(struct iw_michaelmicfailure
),
384 [IWEVASSOCREQIE
- IWEVFIRST
] = {
385 .header_type
= IW_HEADER_TYPE_POINT
,
387 .max_tokens
= IW_GENERIC_IE_MAX
,
389 [IWEVASSOCRESPIE
- IWEVFIRST
] = {
390 .header_type
= IW_HEADER_TYPE_POINT
,
392 .max_tokens
= IW_GENERIC_IE_MAX
,
394 [IWEVPMKIDCAND
- IWEVFIRST
] = {
395 .header_type
= IW_HEADER_TYPE_POINT
,
397 .max_tokens
= sizeof(struct iw_pmkid_cand
),
400 static const unsigned standard_event_num
= ARRAY_SIZE(standard_event
);
402 /* Size (in bytes) of the various private data types */
403 static const char iw_priv_type_size
[] = {
404 0, /* IW_PRIV_TYPE_NONE */
405 1, /* IW_PRIV_TYPE_BYTE */
406 1, /* IW_PRIV_TYPE_CHAR */
408 sizeof(__u32
), /* IW_PRIV_TYPE_INT */
409 sizeof(struct iw_freq
), /* IW_PRIV_TYPE_FLOAT */
410 sizeof(struct sockaddr
), /* IW_PRIV_TYPE_ADDR */
414 /* Size (in bytes) of various events */
415 static const int event_type_size
[] = {
416 IW_EV_LCP_LEN
, /* IW_HEADER_TYPE_NULL */
418 IW_EV_CHAR_LEN
, /* IW_HEADER_TYPE_CHAR */
420 IW_EV_UINT_LEN
, /* IW_HEADER_TYPE_UINT */
421 IW_EV_FREQ_LEN
, /* IW_HEADER_TYPE_FREQ */
422 IW_EV_ADDR_LEN
, /* IW_HEADER_TYPE_ADDR */
424 IW_EV_POINT_LEN
, /* Without variable payload */
425 IW_EV_PARAM_LEN
, /* IW_HEADER_TYPE_PARAM */
426 IW_EV_QUAL_LEN
, /* IW_HEADER_TYPE_QUAL */
429 /* Size (in bytes) of various events, as packed */
430 static const int event_type_pk_size
[] = {
431 IW_EV_LCP_PK_LEN
, /* IW_HEADER_TYPE_NULL */
433 IW_EV_CHAR_PK_LEN
, /* IW_HEADER_TYPE_CHAR */
435 IW_EV_UINT_PK_LEN
, /* IW_HEADER_TYPE_UINT */
436 IW_EV_FREQ_PK_LEN
, /* IW_HEADER_TYPE_FREQ */
437 IW_EV_ADDR_PK_LEN
, /* IW_HEADER_TYPE_ADDR */
439 IW_EV_POINT_PK_LEN
, /* Without variable payload */
440 IW_EV_PARAM_PK_LEN
, /* IW_HEADER_TYPE_PARAM */
441 IW_EV_QUAL_PK_LEN
, /* IW_HEADER_TYPE_QUAL */
444 /************************ COMMON SUBROUTINES ************************/
446 * Stuff that may be used in various place or doesn't fit in one
447 * of the section below.
450 /* ---------------------------------------------------------------- */
452 * Return the driver handler associated with a specific Wireless Extension.
453 * Called from various place, so make sure it remains efficient.
455 static inline iw_handler
get_handler(struct net_device
*dev
,
458 /* Don't "optimise" the following variable, it will crash */
459 unsigned int index
; /* *MUST* be unsigned */
461 /* Check if we have some wireless handlers defined */
462 if (dev
->wireless_handlers
== NULL
)
465 /* Try as a standard command */
466 index
= cmd
- SIOCIWFIRST
;
467 if (index
< dev
->wireless_handlers
->num_standard
)
468 return dev
->wireless_handlers
->standard
[index
];
470 /* Try as a private command */
471 index
= cmd
- SIOCIWFIRSTPRIV
;
472 if (index
< dev
->wireless_handlers
->num_private
)
473 return dev
->wireless_handlers
->private[index
];
479 /* ---------------------------------------------------------------- */
481 * Get statistics out of the driver
483 static inline struct iw_statistics
*get_wireless_stats(struct net_device
*dev
)
486 if ((dev
->wireless_handlers
!= NULL
) &&
487 (dev
->wireless_handlers
->get_wireless_stats
!= NULL
))
488 return dev
->wireless_handlers
->get_wireless_stats(dev
);
491 return (struct iw_statistics
*) NULL
;
494 /* ---------------------------------------------------------------- */
496 * Call the commit handler in the driver
497 * (if exist and if conditions are right)
499 * Note : our current commit strategy is currently pretty dumb,
500 * but we will be able to improve on that...
501 * The goal is to try to agreagate as many changes as possible
502 * before doing the commit. Drivers that will define a commit handler
503 * are usually those that need a reset after changing parameters, so
504 * we want to minimise the number of reset.
505 * A cool idea is to use a timer : at each "set" command, we re-set the
506 * timer, when the timer eventually fires, we call the driver.
507 * Hopefully, more on that later.
509 * Also, I'm waiting to see how many people will complain about the
510 * netif_running(dev) test. I'm open on that one...
511 * Hopefully, the driver will remember to do a commit in "open()" ;-)
513 static inline int call_commit_handler(struct net_device
* dev
)
515 if ((netif_running(dev
)) &&
516 (dev
->wireless_handlers
->standard
[0] != NULL
)) {
517 /* Call the commit handler on the driver */
518 return dev
->wireless_handlers
->standard
[0](dev
, NULL
,
521 return 0; /* Command completed successfully */
524 /* ---------------------------------------------------------------- */
526 * Calculate size of private arguments
528 static inline int get_priv_size(__u16 args
)
530 int num
= args
& IW_PRIV_SIZE_MASK
;
531 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
533 return num
* iw_priv_type_size
[type
];
536 /* ---------------------------------------------------------------- */
538 * Re-calculate the size of private arguments
540 static inline int adjust_priv_size(__u16 args
,
541 union iwreq_data
* wrqu
)
543 int num
= wrqu
->data
.length
;
544 int max
= args
& IW_PRIV_SIZE_MASK
;
545 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
547 /* Make sure the driver doesn't goof up */
551 return num
* iw_priv_type_size
[type
];
554 /* ---------------------------------------------------------------- */
556 * Standard Wireless Handler : get wireless stats
557 * Allow programatic access to /proc/net/wireless even if /proc
558 * doesn't exist... Also more efficient...
560 static int iw_handler_get_iwstats(struct net_device
* dev
,
561 struct iw_request_info
* info
,
562 union iwreq_data
* wrqu
,
565 /* Get stats from the driver */
566 struct iw_statistics
*stats
;
568 stats
= get_wireless_stats(dev
);
569 if (stats
!= (struct iw_statistics
*) NULL
) {
571 /* Copy statistics to extra */
572 memcpy(extra
, stats
, sizeof(struct iw_statistics
));
573 wrqu
->data
.length
= sizeof(struct iw_statistics
);
575 /* Check if we need to clear the updated flag */
576 if (wrqu
->data
.flags
!= 0)
577 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
583 /* ---------------------------------------------------------------- */
585 * Standard Wireless Handler : get iwpriv definitions
586 * Export the driver private handler definition
587 * They will be picked up by tools like iwpriv...
589 static int iw_handler_get_private(struct net_device
* dev
,
590 struct iw_request_info
* info
,
591 union iwreq_data
* wrqu
,
594 /* Check if the driver has something to export */
595 if ((dev
->wireless_handlers
->num_private_args
== 0) ||
596 (dev
->wireless_handlers
->private_args
== NULL
))
599 /* Check if there is enough buffer up there */
600 if (wrqu
->data
.length
< dev
->wireless_handlers
->num_private_args
) {
601 /* User space can't know in advance how large the buffer
602 * needs to be. Give it a hint, so that we can support
603 * any size buffer we want somewhat efficiently... */
604 wrqu
->data
.length
= dev
->wireless_handlers
->num_private_args
;
608 /* Set the number of available ioctls. */
609 wrqu
->data
.length
= dev
->wireless_handlers
->num_private_args
;
611 /* Copy structure to the user buffer. */
612 memcpy(extra
, dev
->wireless_handlers
->private_args
,
613 sizeof(struct iw_priv_args
) * wrqu
->data
.length
);
619 /******************** /proc/net/wireless SUPPORT ********************/
621 * The /proc/net/wireless file is a human readable user-space interface
622 * exporting various wireless specific statistics from the wireless devices.
623 * This is the most popular part of the Wireless Extensions ;-)
625 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
626 * The content of the file is basically the content of "struct iw_statistics".
629 #ifdef CONFIG_PROC_FS
631 /* ---------------------------------------------------------------- */
633 * Print one entry (line) of /proc/net/wireless
635 static __inline__
void wireless_seq_printf_stats(struct seq_file
*seq
,
636 struct net_device
*dev
)
638 /* Get stats from the driver */
639 struct iw_statistics
*stats
= get_wireless_stats(dev
);
642 seq_printf(seq
, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
644 dev
->name
, stats
->status
, stats
->qual
.qual
,
645 stats
->qual
.updated
& IW_QUAL_QUAL_UPDATED
647 ((__s32
) stats
->qual
.level
) -
648 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
649 stats
->qual
.updated
& IW_QUAL_LEVEL_UPDATED
651 ((__s32
) stats
->qual
.noise
) -
652 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
653 stats
->qual
.updated
& IW_QUAL_NOISE_UPDATED
655 stats
->discard
.nwid
, stats
->discard
.code
,
656 stats
->discard
.fragment
, stats
->discard
.retries
,
657 stats
->discard
.misc
, stats
->miss
.beacon
);
658 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
662 /* ---------------------------------------------------------------- */
664 * Print info for /proc/net/wireless (print all entries)
666 static int wireless_seq_show(struct seq_file
*seq
, void *v
)
668 if (v
== SEQ_START_TOKEN
)
669 seq_printf(seq
, "Inter-| sta-| Quality | Discarded "
670 "packets | Missed | WE\n"
671 " face | tus | link level noise | nwid "
672 "crypt frag retry misc | beacon | %d\n",
675 wireless_seq_printf_stats(seq
, v
);
679 static const struct seq_operations wireless_seq_ops
= {
680 .start
= dev_seq_start
,
681 .next
= dev_seq_next
,
682 .stop
= dev_seq_stop
,
683 .show
= wireless_seq_show
,
686 static int wireless_seq_open(struct inode
*inode
, struct file
*file
)
688 return seq_open(file
, &wireless_seq_ops
);
691 static const struct file_operations wireless_seq_fops
= {
692 .owner
= THIS_MODULE
,
693 .open
= wireless_seq_open
,
696 .release
= seq_release
,
699 int __init
wireless_proc_init(void)
701 /* Create /proc/net/wireless entry */
702 if (!proc_net_fops_create("wireless", S_IRUGO
, &wireless_seq_fops
))
707 #endif /* CONFIG_PROC_FS */
709 /************************** IOCTL SUPPORT **************************/
711 * The original user space API to configure all those Wireless Extensions
713 * In there, we check if we need to call the new driver API (iw_handler)
714 * or just call the driver ioctl handler.
717 /* ---------------------------------------------------------------- */
719 * Wrapper to call a standard Wireless Extension handler.
720 * We do various checks and also take care of moving data between
721 * user space and kernel space.
723 static int ioctl_standard_call(struct net_device
* dev
,
728 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
729 const struct iw_ioctl_description
* descr
;
730 struct iw_request_info info
;
733 /* Get the description of the IOCTL */
734 if ((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
736 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
738 #ifdef WE_IOCTL_DEBUG
739 printk(KERN_DEBUG
"%s (WE) : Found standard handler for 0x%04X\n",
741 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
);
742 #endif /* WE_IOCTL_DEBUG */
744 /* Prepare the call */
748 /* Check if we have a pointer to user space data or not */
749 if (descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
751 /* No extra arguments. Trivial to handle */
752 ret
= handler(dev
, &info
, &(iwr
->u
), NULL
);
755 /* Generate an event to notify listeners of the change */
756 if ((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
757 ((ret
== 0) || (ret
== -EIWCOMMIT
)))
758 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
759 #endif /* WE_SET_EVENT */
765 int essid_compat
= 0;
767 /* Calculate space needed by arguments. Always allocate
768 * for max space. Easier, and won't last long... */
769 extra_size
= descr
->max_tokens
* descr
->token_size
;
771 /* Check need for ESSID compatibility for WE < 21 */
777 if (iwr
->u
.data
.length
== descr
->max_tokens
+ 1)
779 else if (IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
780 char essid
[IW_ESSID_MAX_SIZE
+ 1];
782 err
= copy_from_user(essid
, iwr
->u
.data
.pointer
,
788 if (essid
[iwr
->u
.data
.length
- 1] == '\0')
796 iwr
->u
.data
.length
-= essid_compat
;
798 /* Check what user space is giving us */
799 if (IW_IS_SET(cmd
)) {
800 /* Check NULL pointer */
801 if ((iwr
->u
.data
.pointer
== NULL
) &&
802 (iwr
->u
.data
.length
!= 0))
804 /* Check if number of token fits within bounds */
805 if (iwr
->u
.data
.length
> descr
->max_tokens
)
807 if (iwr
->u
.data
.length
< descr
->min_tokens
)
810 /* Check NULL pointer */
811 if (iwr
->u
.data
.pointer
== NULL
)
813 /* Save user space buffer size for checking */
814 user_length
= iwr
->u
.data
.length
;
816 /* Don't check if user_length > max to allow forward
817 * compatibility. The test user_length < min is
818 * implied by the test at the end. */
820 /* Support for very large requests */
821 if ((descr
->flags
& IW_DESCR_FLAG_NOMAX
) &&
822 (user_length
> descr
->max_tokens
)) {
823 /* Allow userspace to GET more than max so
824 * we can support any size GET requests.
825 * There is still a limit : -ENOMEM. */
826 extra_size
= user_length
* descr
->token_size
;
827 /* Note : user_length is originally a __u16,
828 * and token_size is controlled by us,
829 * so extra_size won't get negative and
830 * won't overflow... */
834 #ifdef WE_IOCTL_DEBUG
835 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
836 dev
->name
, extra_size
);
837 #endif /* WE_IOCTL_DEBUG */
839 /* Create the kernel buffer */
840 /* kzalloc ensures NULL-termination for essid_compat */
841 extra
= kzalloc(extra_size
, GFP_KERNEL
);
846 /* If it is a SET, get all the extra data in here */
847 if (IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
848 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
855 #ifdef WE_IOCTL_DEBUG
856 printk(KERN_DEBUG
"%s (WE) : Got %d bytes\n",
858 iwr
->u
.data
.length
* descr
->token_size
);
859 #endif /* WE_IOCTL_DEBUG */
862 /* Call the handler */
863 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
865 iwr
->u
.data
.length
+= essid_compat
;
867 /* If we have something to return to the user */
868 if (!ret
&& IW_IS_GET(cmd
)) {
869 /* Check if there is enough buffer up there */
870 if (user_length
< iwr
->u
.data
.length
) {
875 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
880 #ifdef WE_IOCTL_DEBUG
881 printk(KERN_DEBUG
"%s (WE) : Wrote %d bytes\n",
883 iwr
->u
.data
.length
* descr
->token_size
);
884 #endif /* WE_IOCTL_DEBUG */
888 /* Generate an event to notify listeners of the change */
889 if ((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
890 ((ret
== 0) || (ret
== -EIWCOMMIT
))) {
891 if (descr
->flags
& IW_DESCR_FLAG_RESTRICT
)
892 /* If the event is restricted, don't
893 * export the payload */
894 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
896 wireless_send_event(dev
, cmd
, &(iwr
->u
),
899 #endif /* WE_SET_EVENT */
901 /* Cleanup - I told you it wasn't that long ;-) */
905 /* Call commit handler if needed and defined */
906 if (ret
== -EIWCOMMIT
)
907 ret
= call_commit_handler(dev
);
909 /* Here, we will generate the appropriate event if needed */
914 /* ---------------------------------------------------------------- */
916 * Wrapper to call a private Wireless Extension handler.
917 * We do various checks and also take care of moving data between
918 * user space and kernel space.
919 * It's not as nice and slimline as the standard wrapper. The cause
920 * is struct iw_priv_args, which was not really designed for the
921 * job we are going here.
923 * IMPORTANT : This function prevent to set and get data on the same
924 * IOCTL and enforce the SET/GET convention. Not doing it would be
926 * If you need to set and get data at the same time, please don't use
927 * a iw_handler but process it in your ioctl handler (i.e. use the
930 static inline int ioctl_private_call(struct net_device
* dev
,
935 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
936 const struct iw_priv_args
* descr
= NULL
;
937 struct iw_request_info info
;
942 /* Get the description of the IOCTL */
943 for (i
= 0; i
< dev
->wireless_handlers
->num_private_args
; i
++)
944 if (cmd
== dev
->wireless_handlers
->private_args
[i
].cmd
) {
945 descr
= &(dev
->wireless_handlers
->private_args
[i
]);
949 #ifdef WE_IOCTL_DEBUG
950 printk(KERN_DEBUG
"%s (WE) : Found private handler for 0x%04X\n",
953 printk(KERN_DEBUG
"%s (WE) : Name %s, set %X, get %X\n",
954 dev
->name
, descr
->name
,
955 descr
->set_args
, descr
->get_args
);
957 #endif /* WE_IOCTL_DEBUG */
959 /* Compute the size of the set/get arguments */
961 if (IW_IS_SET(cmd
)) {
962 int offset
= 0; /* For sub-ioctls */
963 /* Check for sub-ioctl handler */
964 if (descr
->name
[0] == '\0')
965 /* Reserve one int for sub-ioctl index */
966 offset
= sizeof(__u32
);
968 /* Size of set arguments */
969 extra_size
= get_priv_size(descr
->set_args
);
971 /* Does it fits in iwr ? */
972 if ((descr
->set_args
& IW_PRIV_SIZE_FIXED
) &&
973 ((extra_size
+ offset
) <= IFNAMSIZ
))
976 /* Size of get arguments */
977 extra_size
= get_priv_size(descr
->get_args
);
979 /* Does it fits in iwr ? */
980 if ((descr
->get_args
& IW_PRIV_SIZE_FIXED
) &&
981 (extra_size
<= IFNAMSIZ
))
986 /* Prepare the call */
990 /* Check if we have a pointer to user space data or not. */
991 if (extra_size
== 0) {
992 /* No extra arguments. Trivial to handle */
993 ret
= handler(dev
, &info
, &(iwr
->u
), (char *) &(iwr
->u
));
998 /* Check what user space is giving us */
999 if (IW_IS_SET(cmd
)) {
1000 /* Check NULL pointer */
1001 if ((iwr
->u
.data
.pointer
== NULL
) &&
1002 (iwr
->u
.data
.length
!= 0))
1005 /* Does it fits within bounds ? */
1006 if (iwr
->u
.data
.length
> (descr
->set_args
&
1010 /* Check NULL pointer */
1011 if (iwr
->u
.data
.pointer
== NULL
)
1015 #ifdef WE_IOCTL_DEBUG
1016 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
1017 dev
->name
, extra_size
);
1018 #endif /* WE_IOCTL_DEBUG */
1020 /* Always allocate for max space. Easier, and won't last
1022 extra
= kmalloc(extra_size
, GFP_KERNEL
);
1023 if (extra
== NULL
) {
1027 /* If it is a SET, get all the extra data in here */
1028 if (IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
1029 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
1035 #ifdef WE_IOCTL_DEBUG
1036 printk(KERN_DEBUG
"%s (WE) : Got %d elem\n",
1037 dev
->name
, iwr
->u
.data
.length
);
1038 #endif /* WE_IOCTL_DEBUG */
1041 /* Call the handler */
1042 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
1044 /* If we have something to return to the user */
1045 if (!ret
&& IW_IS_GET(cmd
)) {
1047 /* Adjust for the actual length if it's variable,
1048 * avoid leaking kernel bits outside. */
1049 if (!(descr
->get_args
& IW_PRIV_SIZE_FIXED
)) {
1050 extra_size
= adjust_priv_size(descr
->get_args
,
1054 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
1058 #ifdef WE_IOCTL_DEBUG
1059 printk(KERN_DEBUG
"%s (WE) : Wrote %d elem\n",
1060 dev
->name
, iwr
->u
.data
.length
);
1061 #endif /* WE_IOCTL_DEBUG */
1064 /* Cleanup - I told you it wasn't that long ;-) */
1069 /* Call commit handler if needed and defined */
1070 if (ret
== -EIWCOMMIT
)
1071 ret
= call_commit_handler(dev
);
1076 /* ---------------------------------------------------------------- */
1078 * Main IOCTl dispatcher. Called from the main networking code
1079 * (dev_ioctl() in net/core/dev.c).
1080 * Check the type of IOCTL and call the appropriate wrapper...
1082 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
);
1147 /************************* EVENT PROCESSING *************************/
1149 * Process events generated by the wireless layer or the driver.
1150 * Most often, the event will be propagated through rtnetlink
1153 #ifdef WE_EVENT_RTNETLINK
1154 /* ---------------------------------------------------------------- */
1159 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1160 * the locking issue in here and implementing this code !
1162 * The issue : wireless_send_event() is often called in interrupt context,
1163 * while the Netlink layer can never be called in interrupt context.
1164 * The fully formed RtNetlink events are queued, and then a tasklet is run
1165 * to feed those to Netlink.
1166 * The skb_queue is interrupt safe, and its lock is not held while calling
1167 * Netlink, so there is no possibility of dealock.
1171 static struct sk_buff_head wireless_nlevent_queue
;
1173 static int __init
wireless_nlevent_init(void)
1175 skb_queue_head_init(&wireless_nlevent_queue
);
1179 subsys_initcall(wireless_nlevent_init
);
1181 static void wireless_nlevent_process(unsigned long data
)
1183 struct sk_buff
*skb
;
1185 while ((skb
= skb_dequeue(&wireless_nlevent_queue
)))
1186 rtnl_notify(skb
, 0, RTNLGRP_LINK
, NULL
, GFP_ATOMIC
);
1189 static DECLARE_TASKLET(wireless_nlevent_tasklet
, wireless_nlevent_process
, 0);
1191 /* ---------------------------------------------------------------- */
1193 * Fill a rtnetlink message with our event data.
1194 * Note that we propage only the specified event and don't dump the
1195 * current wireless config. Dumping the wireless config is far too
1196 * expensive (for each parameter, the driver need to query the hardware).
1198 static inline int rtnetlink_fill_iwinfo(struct sk_buff
* skb
,
1199 struct net_device
* dev
,
1204 struct ifinfomsg
*r
;
1205 struct nlmsghdr
*nlh
;
1206 unsigned char *b
= skb_tail_pointer(skb
);
1208 nlh
= NLMSG_PUT(skb
, 0, 0, type
, sizeof(*r
));
1209 r
= NLMSG_DATA(nlh
);
1210 r
->ifi_family
= AF_UNSPEC
;
1212 r
->ifi_type
= dev
->type
;
1213 r
->ifi_index
= dev
->ifindex
;
1214 r
->ifi_flags
= dev_get_flags(dev
);
1215 r
->ifi_change
= 0; /* Wireless changes don't affect those flags */
1217 /* Add the wireless events in the netlink packet */
1218 RTA_PUT(skb
, IFLA_WIRELESS
, event_len
, event
);
1220 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - b
;
1229 /* ---------------------------------------------------------------- */
1231 * Create and broadcast and send it on the standard rtnetlink socket
1232 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1233 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1234 * within a RTM_NEWLINK event.
1236 static inline void rtmsg_iwinfo(struct net_device
* dev
,
1240 struct sk_buff
*skb
;
1241 int size
= NLMSG_GOODSIZE
;
1243 skb
= alloc_skb(size
, GFP_ATOMIC
);
1247 if (rtnetlink_fill_iwinfo(skb
, dev
, RTM_NEWLINK
,
1248 event
, event_len
) < 0) {
1252 NETLINK_CB(skb
).dst_group
= RTNLGRP_LINK
;
1253 skb_queue_tail(&wireless_nlevent_queue
, skb
);
1254 tasklet_schedule(&wireless_nlevent_tasklet
);
1257 #endif /* WE_EVENT_RTNETLINK */
1259 /* ---------------------------------------------------------------- */
1261 * Main event dispatcher. Called from other parts and drivers.
1262 * Send the event on the appropriate channels.
1263 * May be called from interrupt context.
1265 void wireless_send_event(struct net_device
* dev
,
1267 union iwreq_data
* wrqu
,
1270 const struct iw_ioctl_description
* descr
= NULL
;
1272 struct iw_event
*event
; /* Mallocated whole event */
1273 int event_len
; /* Its size */
1274 int hdr_len
; /* Size of the event header */
1275 int wrqu_off
= 0; /* Offset in wrqu */
1276 /* Don't "optimise" the following variable, it will crash */
1277 unsigned cmd_index
; /* *MUST* be unsigned */
1279 /* Get the description of the Event */
1280 if (cmd
<= SIOCIWLAST
) {
1281 cmd_index
= cmd
- SIOCIWFIRST
;
1282 if (cmd_index
< standard_ioctl_num
)
1283 descr
= &(standard_ioctl
[cmd_index
]);
1285 cmd_index
= cmd
- IWEVFIRST
;
1286 if (cmd_index
< standard_event_num
)
1287 descr
= &(standard_event
[cmd_index
]);
1289 /* Don't accept unknown events */
1290 if (descr
== NULL
) {
1291 /* Note : we don't return an error to the driver, because
1292 * the driver would not know what to do about it. It can't
1293 * return an error to the user, because the event is not
1294 * initiated by a user request.
1295 * The best the driver could do is to log an error message.
1296 * We will do it ourselves instead...
1298 printk(KERN_ERR
"%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1302 #ifdef WE_EVENT_DEBUG
1303 printk(KERN_DEBUG
"%s (WE) : Got event 0x%04X\n",
1305 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
);
1306 #endif /* WE_EVENT_DEBUG */
1308 /* Check extra parameters and set extra_len */
1309 if (descr
->header_type
== IW_HEADER_TYPE_POINT
) {
1310 /* Check if number of token fits within bounds */
1311 if (wrqu
->data
.length
> descr
->max_tokens
) {
1312 printk(KERN_ERR
"%s (WE) : Wireless Event too big (%d)\n", dev
->name
, wrqu
->data
.length
);
1315 if (wrqu
->data
.length
< descr
->min_tokens
) {
1316 printk(KERN_ERR
"%s (WE) : Wireless Event too small (%d)\n", dev
->name
, wrqu
->data
.length
);
1319 /* Calculate extra_len - extra is NULL for restricted events */
1321 extra_len
= wrqu
->data
.length
* descr
->token_size
;
1322 /* Always at an offset in wrqu */
1323 wrqu_off
= IW_EV_POINT_OFF
;
1324 #ifdef WE_EVENT_DEBUG
1325 printk(KERN_DEBUG
"%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev
->name
, cmd
, wrqu
->data
.length
, extra_len
);
1326 #endif /* WE_EVENT_DEBUG */
1329 /* Total length of the event */
1330 hdr_len
= event_type_size
[descr
->header_type
];
1331 event_len
= hdr_len
+ extra_len
;
1333 #ifdef WE_EVENT_DEBUG
1334 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
);
1335 #endif /* WE_EVENT_DEBUG */
1337 /* Create temporary buffer to hold the event */
1338 event
= kmalloc(event_len
, GFP_ATOMIC
);
1343 event
->len
= event_len
;
1345 memcpy(&event
->u
, ((char *) wrqu
) + wrqu_off
, hdr_len
- IW_EV_LCP_LEN
);
1347 memcpy(((char *) event
) + hdr_len
, extra
, extra_len
);
1349 #ifdef WE_EVENT_RTNETLINK
1350 /* Send via the RtNetlink event channel */
1351 rtmsg_iwinfo(dev
, (char *) event
, event_len
);
1352 #endif /* WE_EVENT_RTNETLINK */
1357 return; /* Always success, I guess ;-) */
1360 /********************** ENHANCED IWSPY SUPPORT **********************/
1362 * In the old days, the driver was handling spy support all by itself.
1363 * Now, the driver can delegate this task to Wireless Extensions.
1364 * It needs to use those standard spy iw_handler in struct iw_handler_def,
1365 * push data to us via wireless_spy_update() and include struct iw_spy_data
1366 * in its private part (and export it in net_device->wireless_data->spy_data).
1367 * One of the main advantage of centralising spy support here is that
1368 * it becomes much easier to improve and extend it without having to touch
1369 * the drivers. One example is the addition of the Spy-Threshold events.
1372 /* ---------------------------------------------------------------- */
1374 * Return the pointer to the spy data in the driver.
1375 * Because this is called on the Rx path via wireless_spy_update(),
1376 * we want it to be efficient...
1378 static inline struct iw_spy_data
* get_spydata(struct net_device
*dev
)
1380 /* This is the new way */
1381 if (dev
->wireless_data
)
1382 return(dev
->wireless_data
->spy_data
);
1386 /*------------------------------------------------------------------*/
1388 * Standard Wireless Handler : set Spy List
1390 int iw_handler_set_spy(struct net_device
* dev
,
1391 struct iw_request_info
* info
,
1392 union iwreq_data
* wrqu
,
1395 struct iw_spy_data
* spydata
= get_spydata(dev
);
1396 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1398 /* Make sure driver is not buggy or using the old API */
1402 /* Disable spy collection while we copy the addresses.
1403 * While we copy addresses, any call to wireless_spy_update()
1404 * will NOP. This is OK, as anyway the addresses are changing. */
1405 spydata
->spy_number
= 0;
1407 /* We want to operate without locking, because wireless_spy_update()
1408 * most likely will happen in the interrupt handler, and therefore
1409 * have its own locking constraints and needs performance.
1410 * The rtnl_lock() make sure we don't race with the other iw_handlers.
1411 * This make sure wireless_spy_update() "see" that the spy list
1412 * is temporarily disabled. */
1415 /* Are there are addresses to copy? */
1416 if (wrqu
->data
.length
> 0) {
1419 /* Copy addresses */
1420 for (i
= 0; i
< wrqu
->data
.length
; i
++)
1421 memcpy(spydata
->spy_address
[i
], address
[i
].sa_data
,
1424 memset(spydata
->spy_stat
, 0,
1425 sizeof(struct iw_quality
) * IW_MAX_SPY
);
1428 printk(KERN_DEBUG
"iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev
->wireless_data
, spydata
, wrqu
->data
.length
);
1429 for (i
= 0; i
< wrqu
->data
.length
; i
++)
1431 "%02X:%02X:%02X:%02X:%02X:%02X \n",
1432 spydata
->spy_address
[i
][0],
1433 spydata
->spy_address
[i
][1],
1434 spydata
->spy_address
[i
][2],
1435 spydata
->spy_address
[i
][3],
1436 spydata
->spy_address
[i
][4],
1437 spydata
->spy_address
[i
][5]);
1438 #endif /* WE_SPY_DEBUG */
1441 /* Make sure above is updated before re-enabling */
1444 /* Enable addresses */
1445 spydata
->spy_number
= wrqu
->data
.length
;
1450 /*------------------------------------------------------------------*/
1452 * Standard Wireless Handler : get Spy List
1454 int iw_handler_get_spy(struct net_device
* dev
,
1455 struct iw_request_info
* info
,
1456 union iwreq_data
* wrqu
,
1459 struct iw_spy_data
* spydata
= get_spydata(dev
);
1460 struct sockaddr
* address
= (struct sockaddr
*) extra
;
1463 /* Make sure driver is not buggy or using the old API */
1467 wrqu
->data
.length
= spydata
->spy_number
;
1469 /* Copy addresses. */
1470 for (i
= 0; i
< spydata
->spy_number
; i
++) {
1471 memcpy(address
[i
].sa_data
, spydata
->spy_address
[i
], ETH_ALEN
);
1472 address
[i
].sa_family
= AF_UNIX
;
1474 /* Copy stats to the user buffer (just after). */
1475 if (spydata
->spy_number
> 0)
1476 memcpy(extra
+ (sizeof(struct sockaddr
) *spydata
->spy_number
),
1478 sizeof(struct iw_quality
) * spydata
->spy_number
);
1479 /* Reset updated flags. */
1480 for (i
= 0; i
< spydata
->spy_number
; i
++)
1481 spydata
->spy_stat
[i
].updated
&= ~IW_QUAL_ALL_UPDATED
;
1485 /*------------------------------------------------------------------*/
1487 * Standard Wireless Handler : set spy threshold
1489 int iw_handler_set_thrspy(struct net_device
* dev
,
1490 struct iw_request_info
*info
,
1491 union iwreq_data
* wrqu
,
1494 struct iw_spy_data
* spydata
= get_spydata(dev
);
1495 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1497 /* Make sure driver is not buggy or using the old API */
1502 memcpy(&(spydata
->spy_thr_low
), &(threshold
->low
),
1503 2 * sizeof(struct iw_quality
));
1506 memset(spydata
->spy_thr_under
, '\0', sizeof(spydata
->spy_thr_under
));
1509 printk(KERN_DEBUG
"iw_handler_set_thrspy() : low %d ; high %d\n", spydata
->spy_thr_low
.level
, spydata
->spy_thr_high
.level
);
1510 #endif /* WE_SPY_DEBUG */
1515 /*------------------------------------------------------------------*/
1517 * Standard Wireless Handler : get spy threshold
1519 int iw_handler_get_thrspy(struct net_device
* dev
,
1520 struct iw_request_info
*info
,
1521 union iwreq_data
* wrqu
,
1524 struct iw_spy_data
* spydata
= get_spydata(dev
);
1525 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
1527 /* Make sure driver is not buggy or using the old API */
1532 memcpy(&(threshold
->low
), &(spydata
->spy_thr_low
),
1533 2 * sizeof(struct iw_quality
));
1538 /*------------------------------------------------------------------*/
1540 * Prepare and send a Spy Threshold event
1542 static void iw_send_thrspy_event(struct net_device
* dev
,
1543 struct iw_spy_data
* spydata
,
1544 unsigned char * address
,
1545 struct iw_quality
* wstats
)
1547 union iwreq_data wrqu
;
1548 struct iw_thrspy threshold
;
1551 wrqu
.data
.length
= 1;
1552 wrqu
.data
.flags
= 0;
1554 memcpy(threshold
.addr
.sa_data
, address
, ETH_ALEN
);
1555 threshold
.addr
.sa_family
= ARPHRD_ETHER
;
1557 memcpy(&(threshold
.qual
), wstats
, sizeof(struct iw_quality
));
1558 /* Copy also thresholds */
1559 memcpy(&(threshold
.low
), &(spydata
->spy_thr_low
),
1560 2 * sizeof(struct iw_quality
));
1563 printk(KERN_DEBUG
"iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
1564 threshold
.addr
.sa_data
[0],
1565 threshold
.addr
.sa_data
[1],
1566 threshold
.addr
.sa_data
[2],
1567 threshold
.addr
.sa_data
[3],
1568 threshold
.addr
.sa_data
[4],
1569 threshold
.addr
.sa_data
[5], threshold
.qual
.level
);
1570 #endif /* WE_SPY_DEBUG */
1572 /* Send event to user space */
1573 wireless_send_event(dev
, SIOCGIWTHRSPY
, &wrqu
, (char *) &threshold
);
1576 /* ---------------------------------------------------------------- */
1578 * Call for the driver to update the spy data.
1579 * For now, the spy data is a simple array. As the size of the array is
1580 * small, this is good enough. If we wanted to support larger number of
1581 * spy addresses, we should use something more efficient...
1583 void wireless_spy_update(struct net_device
* dev
,
1584 unsigned char * address
,
1585 struct iw_quality
* wstats
)
1587 struct iw_spy_data
* spydata
= get_spydata(dev
);
1591 /* Make sure driver is not buggy or using the old API */
1596 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]);
1597 #endif /* WE_SPY_DEBUG */
1599 /* Update all records that match */
1600 for (i
= 0; i
< spydata
->spy_number
; i
++)
1601 if (!compare_ether_addr(address
, spydata
->spy_address
[i
])) {
1602 memcpy(&(spydata
->spy_stat
[i
]), wstats
,
1603 sizeof(struct iw_quality
));
1607 /* Generate an event if we cross the spy threshold.
1608 * To avoid event storms, we have a simple hysteresis : we generate
1609 * event only when we go under the low threshold or above the
1610 * high threshold. */
1612 if (spydata
->spy_thr_under
[match
]) {
1613 if (wstats
->level
> spydata
->spy_thr_high
.level
) {
1614 spydata
->spy_thr_under
[match
] = 0;
1615 iw_send_thrspy_event(dev
, spydata
,
1619 if (wstats
->level
< spydata
->spy_thr_low
.level
) {
1620 spydata
->spy_thr_under
[match
] = 1;
1621 iw_send_thrspy_event(dev
, spydata
,
1628 EXPORT_SYMBOL(iw_handler_get_spy
);
1629 EXPORT_SYMBOL(iw_handler_get_thrspy
);
1630 EXPORT_SYMBOL(iw_handler_set_spy
);
1631 EXPORT_SYMBOL(iw_handler_set_thrspy
);
1632 EXPORT_SYMBOL(wireless_send_event
);
1633 EXPORT_SYMBOL(wireless_spy_update
);