2 * This file implement the Wireless Extensions APIs.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2006 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()
81 /***************************** INCLUDES *****************************/
83 #include <linux/module.h>
84 #include <linux/types.h> /* off_t */
85 #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */
86 #include <linux/proc_fs.h>
87 #include <linux/rtnetlink.h> /* rtnetlink stuff */
88 #include <linux/seq_file.h>
89 #include <linux/init.h> /* for __init */
90 #include <linux/if_arp.h> /* ARPHRD_ETHER */
91 #include <linux/etherdevice.h> /* compare_ether_addr */
92 #include <linux/interrupt.h>
94 #include <linux/wireless.h> /* Pretty obvious */
95 #include <net/iw_handler.h> /* New driver API */
96 #include <net/netlink.h>
98 #include <asm/uaccess.h> /* copy_to_user() */
100 /**************************** CONSTANTS ****************************/
102 /* Debugging stuff */
103 #undef WE_IOCTL_DEBUG /* Debug IOCTL API */
104 #undef WE_RTNETLINK_DEBUG /* Debug RtNetlink API */
105 #undef WE_EVENT_DEBUG /* Debug Event dispatcher */
106 #undef WE_SPY_DEBUG /* Debug enhanced spy support */
109 //CONFIG_NET_WIRELESS_RTNETLINK /* Wireless requests over RtNetlink */
110 #define WE_EVENT_RTNETLINK /* Propagate events using RtNetlink */
111 #define WE_SET_EVENT /* Generate an event on some set commands */
113 /************************* GLOBAL VARIABLES *************************/
115 * You should not use global variables, because of re-entrancy.
116 * On our case, it's only const, so it's OK...
119 * Meta-data about all the standard Wireless Extension request we
122 static const struct iw_ioctl_description standard_ioctl
[] = {
123 [SIOCSIWCOMMIT
- SIOCIWFIRST
] = {
124 .header_type
= IW_HEADER_TYPE_NULL
,
126 [SIOCGIWNAME
- SIOCIWFIRST
] = {
127 .header_type
= IW_HEADER_TYPE_CHAR
,
128 .flags
= IW_DESCR_FLAG_DUMP
,
130 [SIOCSIWNWID
- SIOCIWFIRST
] = {
131 .header_type
= IW_HEADER_TYPE_PARAM
,
132 .flags
= IW_DESCR_FLAG_EVENT
,
134 [SIOCGIWNWID
- SIOCIWFIRST
] = {
135 .header_type
= IW_HEADER_TYPE_PARAM
,
136 .flags
= IW_DESCR_FLAG_DUMP
,
138 [SIOCSIWFREQ
- SIOCIWFIRST
] = {
139 .header_type
= IW_HEADER_TYPE_FREQ
,
140 .flags
= IW_DESCR_FLAG_EVENT
,
142 [SIOCGIWFREQ
- SIOCIWFIRST
] = {
143 .header_type
= IW_HEADER_TYPE_FREQ
,
144 .flags
= IW_DESCR_FLAG_DUMP
,
146 [SIOCSIWMODE
- SIOCIWFIRST
] = {
147 .header_type
= IW_HEADER_TYPE_UINT
,
148 .flags
= IW_DESCR_FLAG_EVENT
,
150 [SIOCGIWMODE
- SIOCIWFIRST
] = {
151 .header_type
= IW_HEADER_TYPE_UINT
,
152 .flags
= IW_DESCR_FLAG_DUMP
,
154 [SIOCSIWSENS
- SIOCIWFIRST
] = {
155 .header_type
= IW_HEADER_TYPE_PARAM
,
157 [SIOCGIWSENS
- SIOCIWFIRST
] = {
158 .header_type
= IW_HEADER_TYPE_PARAM
,
160 [SIOCSIWRANGE
- SIOCIWFIRST
] = {
161 .header_type
= IW_HEADER_TYPE_NULL
,
163 [SIOCGIWRANGE
- SIOCIWFIRST
] = {
164 .header_type
= IW_HEADER_TYPE_POINT
,
166 .max_tokens
= sizeof(struct iw_range
),
167 .flags
= IW_DESCR_FLAG_DUMP
,
169 [SIOCSIWPRIV
- SIOCIWFIRST
] = {
170 .header_type
= IW_HEADER_TYPE_NULL
,
172 [SIOCGIWPRIV
- SIOCIWFIRST
] = { /* (handled directly by us) */
173 .header_type
= IW_HEADER_TYPE_POINT
,
174 .token_size
= sizeof(struct iw_priv_args
),
176 .flags
= IW_DESCR_FLAG_NOMAX
,
178 [SIOCSIWSTATS
- SIOCIWFIRST
] = {
179 .header_type
= IW_HEADER_TYPE_NULL
,
181 [SIOCGIWSTATS
- SIOCIWFIRST
] = { /* (handled directly by us) */
182 .header_type
= IW_HEADER_TYPE_POINT
,
184 .max_tokens
= sizeof(struct iw_statistics
),
185 .flags
= IW_DESCR_FLAG_DUMP
,
187 [SIOCSIWSPY
- SIOCIWFIRST
] = {
188 .header_type
= IW_HEADER_TYPE_POINT
,
189 .token_size
= sizeof(struct sockaddr
),
190 .max_tokens
= IW_MAX_SPY
,
192 [SIOCGIWSPY
- SIOCIWFIRST
] = {
193 .header_type
= IW_HEADER_TYPE_POINT
,
194 .token_size
= sizeof(struct sockaddr
) +
195 sizeof(struct iw_quality
),
196 .max_tokens
= IW_MAX_SPY
,
198 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = {
199 .header_type
= IW_HEADER_TYPE_POINT
,
200 .token_size
= sizeof(struct iw_thrspy
),
204 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = {
205 .header_type
= IW_HEADER_TYPE_POINT
,
206 .token_size
= sizeof(struct iw_thrspy
),
210 [SIOCSIWAP
- SIOCIWFIRST
] = {
211 .header_type
= IW_HEADER_TYPE_ADDR
,
213 [SIOCGIWAP
- SIOCIWFIRST
] = {
214 .header_type
= IW_HEADER_TYPE_ADDR
,
215 .flags
= IW_DESCR_FLAG_DUMP
,
217 [SIOCSIWMLME
- SIOCIWFIRST
] = {
218 .header_type
= IW_HEADER_TYPE_POINT
,
220 .min_tokens
= sizeof(struct iw_mlme
),
221 .max_tokens
= sizeof(struct iw_mlme
),
223 [SIOCGIWAPLIST
- SIOCIWFIRST
] = {
224 .header_type
= IW_HEADER_TYPE_POINT
,
225 .token_size
= sizeof(struct sockaddr
) +
226 sizeof(struct iw_quality
),
227 .max_tokens
= IW_MAX_AP
,
228 .flags
= IW_DESCR_FLAG_NOMAX
,
230 [SIOCSIWSCAN
- SIOCIWFIRST
] = {
231 .header_type
= IW_HEADER_TYPE_POINT
,
234 .max_tokens
= sizeof(struct iw_scan_req
),
236 [SIOCGIWSCAN
- SIOCIWFIRST
] = {
237 .header_type
= IW_HEADER_TYPE_POINT
,
239 .max_tokens
= IW_SCAN_MAX_DATA
,
240 .flags
= IW_DESCR_FLAG_NOMAX
,
242 [SIOCSIWESSID
- SIOCIWFIRST
] = {
243 .header_type
= IW_HEADER_TYPE_POINT
,
245 .max_tokens
= IW_ESSID_MAX_SIZE
,
246 .flags
= IW_DESCR_FLAG_EVENT
,
248 [SIOCGIWESSID
- SIOCIWFIRST
] = {
249 .header_type
= IW_HEADER_TYPE_POINT
,
251 .max_tokens
= IW_ESSID_MAX_SIZE
,
252 .flags
= IW_DESCR_FLAG_DUMP
,
254 [SIOCSIWNICKN
- SIOCIWFIRST
] = {
255 .header_type
= IW_HEADER_TYPE_POINT
,
257 .max_tokens
= IW_ESSID_MAX_SIZE
,
259 [SIOCGIWNICKN
- SIOCIWFIRST
] = {
260 .header_type
= IW_HEADER_TYPE_POINT
,
262 .max_tokens
= IW_ESSID_MAX_SIZE
,
264 [SIOCSIWRATE
- SIOCIWFIRST
] = {
265 .header_type
= IW_HEADER_TYPE_PARAM
,
267 [SIOCGIWRATE
- SIOCIWFIRST
] = {
268 .header_type
= IW_HEADER_TYPE_PARAM
,
270 [SIOCSIWRTS
- SIOCIWFIRST
] = {
271 .header_type
= IW_HEADER_TYPE_PARAM
,
273 [SIOCGIWRTS
- SIOCIWFIRST
] = {
274 .header_type
= IW_HEADER_TYPE_PARAM
,
276 [SIOCSIWFRAG
- SIOCIWFIRST
] = {
277 .header_type
= IW_HEADER_TYPE_PARAM
,
279 [SIOCGIWFRAG
- SIOCIWFIRST
] = {
280 .header_type
= IW_HEADER_TYPE_PARAM
,
282 [SIOCSIWTXPOW
- SIOCIWFIRST
] = {
283 .header_type
= IW_HEADER_TYPE_PARAM
,
285 [SIOCGIWTXPOW
- SIOCIWFIRST
] = {
286 .header_type
= IW_HEADER_TYPE_PARAM
,
288 [SIOCSIWRETRY
- SIOCIWFIRST
] = {
289 .header_type
= IW_HEADER_TYPE_PARAM
,
291 [SIOCGIWRETRY
- SIOCIWFIRST
] = {
292 .header_type
= IW_HEADER_TYPE_PARAM
,
294 [SIOCSIWENCODE
- SIOCIWFIRST
] = {
295 .header_type
= IW_HEADER_TYPE_POINT
,
297 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
298 .flags
= IW_DESCR_FLAG_EVENT
| IW_DESCR_FLAG_RESTRICT
,
300 [SIOCGIWENCODE
- SIOCIWFIRST
] = {
301 .header_type
= IW_HEADER_TYPE_POINT
,
303 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
304 .flags
= IW_DESCR_FLAG_DUMP
| IW_DESCR_FLAG_RESTRICT
,
306 [SIOCSIWPOWER
- SIOCIWFIRST
] = {
307 .header_type
= IW_HEADER_TYPE_PARAM
,
309 [SIOCGIWPOWER
- SIOCIWFIRST
] = {
310 .header_type
= IW_HEADER_TYPE_PARAM
,
312 [SIOCSIWGENIE
- SIOCIWFIRST
] = {
313 .header_type
= IW_HEADER_TYPE_POINT
,
315 .max_tokens
= IW_GENERIC_IE_MAX
,
317 [SIOCGIWGENIE
- SIOCIWFIRST
] = {
318 .header_type
= IW_HEADER_TYPE_POINT
,
320 .max_tokens
= IW_GENERIC_IE_MAX
,
322 [SIOCSIWAUTH
- SIOCIWFIRST
] = {
323 .header_type
= IW_HEADER_TYPE_PARAM
,
325 [SIOCGIWAUTH
- SIOCIWFIRST
] = {
326 .header_type
= IW_HEADER_TYPE_PARAM
,
328 [SIOCSIWENCODEEXT
- SIOCIWFIRST
] = {
329 .header_type
= IW_HEADER_TYPE_POINT
,
331 .min_tokens
= sizeof(struct iw_encode_ext
),
332 .max_tokens
= sizeof(struct iw_encode_ext
) +
333 IW_ENCODING_TOKEN_MAX
,
335 [SIOCGIWENCODEEXT
- SIOCIWFIRST
] = {
336 .header_type
= IW_HEADER_TYPE_POINT
,
338 .min_tokens
= sizeof(struct iw_encode_ext
),
339 .max_tokens
= sizeof(struct iw_encode_ext
) +
340 IW_ENCODING_TOKEN_MAX
,
342 [SIOCSIWPMKSA
- SIOCIWFIRST
] = {
343 .header_type
= IW_HEADER_TYPE_POINT
,
345 .min_tokens
= sizeof(struct iw_pmksa
),
346 .max_tokens
= sizeof(struct iw_pmksa
),
349 static const unsigned standard_ioctl_num
= (sizeof(standard_ioctl
) /
350 sizeof(struct iw_ioctl_description
));
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
= (sizeof(standard_event
) /
401 sizeof(struct iw_ioctl_description
));
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 /************************ COMMON SUBROUTINES ************************/
432 * Stuff that may be used in various place or doesn't fit in one
433 * of the section below.
436 /* ---------------------------------------------------------------- */
438 * Return the driver handler associated with a specific Wireless Extension.
439 * Called from various place, so make sure it remains efficient.
441 static inline iw_handler
get_handler(struct net_device
*dev
,
444 /* Don't "optimise" the following variable, it will crash */
445 unsigned int index
; /* *MUST* be unsigned */
447 /* Check if we have some wireless handlers defined */
448 if(dev
->wireless_handlers
== NULL
)
451 /* Try as a standard command */
452 index
= cmd
- SIOCIWFIRST
;
453 if(index
< dev
->wireless_handlers
->num_standard
)
454 return dev
->wireless_handlers
->standard
[index
];
456 /* Try as a private command */
457 index
= cmd
- SIOCIWFIRSTPRIV
;
458 if(index
< dev
->wireless_handlers
->num_private
)
459 return dev
->wireless_handlers
->private[index
];
465 /* ---------------------------------------------------------------- */
467 * Get statistics out of the driver
469 static inline struct iw_statistics
*get_wireless_stats(struct net_device
*dev
)
472 if((dev
->wireless_handlers
!= NULL
) &&
473 (dev
->wireless_handlers
->get_wireless_stats
!= NULL
))
474 return dev
->wireless_handlers
->get_wireless_stats(dev
);
477 return (struct iw_statistics
*) NULL
;
480 /* ---------------------------------------------------------------- */
482 * Call the commit handler in the driver
483 * (if exist and if conditions are right)
485 * Note : our current commit strategy is currently pretty dumb,
486 * but we will be able to improve on that...
487 * The goal is to try to agreagate as many changes as possible
488 * before doing the commit. Drivers that will define a commit handler
489 * are usually those that need a reset after changing parameters, so
490 * we want to minimise the number of reset.
491 * A cool idea is to use a timer : at each "set" command, we re-set the
492 * timer, when the timer eventually fires, we call the driver.
493 * Hopefully, more on that later.
495 * Also, I'm waiting to see how many people will complain about the
496 * netif_running(dev) test. I'm open on that one...
497 * Hopefully, the driver will remember to do a commit in "open()" ;-)
499 static inline int call_commit_handler(struct net_device
* dev
)
501 if((netif_running(dev
)) &&
502 (dev
->wireless_handlers
->standard
[0] != NULL
)) {
503 /* Call the commit handler on the driver */
504 return dev
->wireless_handlers
->standard
[0](dev
, NULL
,
507 return 0; /* Command completed successfully */
510 /* ---------------------------------------------------------------- */
512 * Calculate size of private arguments
514 static inline int get_priv_size(__u16 args
)
516 int num
= args
& IW_PRIV_SIZE_MASK
;
517 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
519 return num
* iw_priv_type_size
[type
];
522 /* ---------------------------------------------------------------- */
524 * Re-calculate the size of private arguments
526 static inline int adjust_priv_size(__u16 args
,
527 union iwreq_data
* wrqu
)
529 int num
= wrqu
->data
.length
;
530 int max
= args
& IW_PRIV_SIZE_MASK
;
531 int type
= (args
& IW_PRIV_TYPE_MASK
) >> 12;
533 /* Make sure the driver doesn't goof up */
537 return num
* iw_priv_type_size
[type
];
540 /* ---------------------------------------------------------------- */
542 * Standard Wireless Handler : get wireless stats
543 * Allow programatic access to /proc/net/wireless even if /proc
544 * doesn't exist... Also more efficient...
546 static int iw_handler_get_iwstats(struct net_device
* dev
,
547 struct iw_request_info
* info
,
548 union iwreq_data
* wrqu
,
551 /* Get stats from the driver */
552 struct iw_statistics
*stats
;
554 stats
= get_wireless_stats(dev
);
555 if (stats
!= (struct iw_statistics
*) NULL
) {
557 /* Copy statistics to extra */
558 memcpy(extra
, stats
, sizeof(struct iw_statistics
));
559 wrqu
->data
.length
= sizeof(struct iw_statistics
);
561 /* Check if we need to clear the updated flag */
562 if(wrqu
->data
.flags
!= 0)
563 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
569 /* ---------------------------------------------------------------- */
571 * Standard Wireless Handler : get iwpriv definitions
572 * Export the driver private handler definition
573 * They will be picked up by tools like iwpriv...
575 static int iw_handler_get_private(struct net_device
* dev
,
576 struct iw_request_info
* info
,
577 union iwreq_data
* wrqu
,
580 /* Check if the driver has something to export */
581 if((dev
->wireless_handlers
->num_private_args
== 0) ||
582 (dev
->wireless_handlers
->private_args
== NULL
))
585 /* Check if there is enough buffer up there */
586 if(wrqu
->data
.length
< dev
->wireless_handlers
->num_private_args
) {
587 /* User space can't know in advance how large the buffer
588 * needs to be. Give it a hint, so that we can support
589 * any size buffer we want somewhat efficiently... */
590 wrqu
->data
.length
= dev
->wireless_handlers
->num_private_args
;
594 /* Set the number of available ioctls. */
595 wrqu
->data
.length
= dev
->wireless_handlers
->num_private_args
;
597 /* Copy structure to the user buffer. */
598 memcpy(extra
, dev
->wireless_handlers
->private_args
,
599 sizeof(struct iw_priv_args
) * wrqu
->data
.length
);
605 /******************** /proc/net/wireless SUPPORT ********************/
607 * The /proc/net/wireless file is a human readable user-space interface
608 * exporting various wireless specific statistics from the wireless devices.
609 * This is the most popular part of the Wireless Extensions ;-)
611 * This interface is a pure clone of /proc/net/dev (in net/core/dev.c).
612 * The content of the file is basically the content of "struct iw_statistics".
615 #ifdef CONFIG_PROC_FS
617 /* ---------------------------------------------------------------- */
619 * Print one entry (line) of /proc/net/wireless
621 static __inline__
void wireless_seq_printf_stats(struct seq_file
*seq
,
622 struct net_device
*dev
)
624 /* Get stats from the driver */
625 struct iw_statistics
*stats
= get_wireless_stats(dev
);
628 seq_printf(seq
, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d "
630 dev
->name
, stats
->status
, stats
->qual
.qual
,
631 stats
->qual
.updated
& IW_QUAL_QUAL_UPDATED
633 ((__s32
) stats
->qual
.level
) -
634 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
635 stats
->qual
.updated
& IW_QUAL_LEVEL_UPDATED
637 ((__s32
) stats
->qual
.noise
) -
638 ((stats
->qual
.updated
& IW_QUAL_DBM
) ? 0x100 : 0),
639 stats
->qual
.updated
& IW_QUAL_NOISE_UPDATED
641 stats
->discard
.nwid
, stats
->discard
.code
,
642 stats
->discard
.fragment
, stats
->discard
.retries
,
643 stats
->discard
.misc
, stats
->miss
.beacon
);
644 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
648 /* ---------------------------------------------------------------- */
650 * Print info for /proc/net/wireless (print all entries)
652 static int wireless_seq_show(struct seq_file
*seq
, void *v
)
654 if (v
== SEQ_START_TOKEN
)
655 seq_printf(seq
, "Inter-| sta-| Quality | Discarded "
656 "packets | Missed | WE\n"
657 " face | tus | link level noise | nwid "
658 "crypt frag retry misc | beacon | %d\n",
661 wireless_seq_printf_stats(seq
, v
);
665 static struct seq_operations wireless_seq_ops
= {
666 .start
= dev_seq_start
,
667 .next
= dev_seq_next
,
668 .stop
= dev_seq_stop
,
669 .show
= wireless_seq_show
,
672 static int wireless_seq_open(struct inode
*inode
, struct file
*file
)
674 return seq_open(file
, &wireless_seq_ops
);
677 static struct file_operations wireless_seq_fops
= {
678 .owner
= THIS_MODULE
,
679 .open
= wireless_seq_open
,
682 .release
= seq_release
,
685 int __init
wireless_proc_init(void)
687 /* Create /proc/net/wireless entry */
688 if (!proc_net_fops_create("wireless", S_IRUGO
, &wireless_seq_fops
))
693 #endif /* CONFIG_PROC_FS */
695 /************************** IOCTL SUPPORT **************************/
697 * The original user space API to configure all those Wireless Extensions
699 * In there, we check if we need to call the new driver API (iw_handler)
700 * or just call the driver ioctl handler.
703 /* ---------------------------------------------------------------- */
705 * Wrapper to call a standard Wireless Extension handler.
706 * We do various checks and also take care of moving data between
707 * user space and kernel space.
709 static int ioctl_standard_call(struct net_device
* dev
,
714 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
715 const struct iw_ioctl_description
* descr
;
716 struct iw_request_info info
;
719 /* Get the description of the IOCTL */
720 if((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
722 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
724 #ifdef WE_IOCTL_DEBUG
725 printk(KERN_DEBUG
"%s (WE) : Found standard handler for 0x%04X\n",
727 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
);
728 #endif /* WE_IOCTL_DEBUG */
730 /* Prepare the call */
734 /* Check if we have a pointer to user space data or not */
735 if(descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
737 /* No extra arguments. Trivial to handle */
738 ret
= handler(dev
, &info
, &(iwr
->u
), NULL
);
741 /* Generate an event to notify listeners of the change */
742 if((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
743 ((ret
== 0) || (ret
== -EIWCOMMIT
)))
744 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
745 #endif /* WE_SET_EVENT */
752 /* Calculate space needed by arguments. Always allocate
753 * for max space. Easier, and won't last long... */
754 extra_size
= descr
->max_tokens
* descr
->token_size
;
756 /* Check what user space is giving us */
758 /* Check NULL pointer */
759 if((iwr
->u
.data
.pointer
== NULL
) &&
760 (iwr
->u
.data
.length
!= 0))
762 /* Check if number of token fits within bounds */
763 if(iwr
->u
.data
.length
> descr
->max_tokens
)
765 if(iwr
->u
.data
.length
< descr
->min_tokens
)
768 /* Check NULL pointer */
769 if(iwr
->u
.data
.pointer
== NULL
)
771 /* Save user space buffer size for checking */
772 user_length
= iwr
->u
.data
.length
;
774 /* Don't check if user_length > max to allow forward
775 * compatibility. The test user_length < min is
776 * implied by the test at the end. */
778 /* Support for very large requests */
779 if((descr
->flags
& IW_DESCR_FLAG_NOMAX
) &&
780 (user_length
> descr
->max_tokens
)) {
781 /* Allow userspace to GET more than max so
782 * we can support any size GET requests.
783 * There is still a limit : -ENOMEM. */
784 extra_size
= user_length
* descr
->token_size
;
785 /* Note : user_length is originally a __u16,
786 * and token_size is controlled by us,
787 * so extra_size won't get negative and
788 * won't overflow... */
792 #ifdef WE_IOCTL_DEBUG
793 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
794 dev
->name
, extra_size
);
795 #endif /* WE_IOCTL_DEBUG */
797 /* Create the kernel buffer */
798 extra
= kmalloc(extra_size
, GFP_KERNEL
);
803 /* If it is a SET, get all the extra data in here */
804 if(IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
805 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
812 #ifdef WE_IOCTL_DEBUG
813 printk(KERN_DEBUG
"%s (WE) : Got %d bytes\n",
815 iwr
->u
.data
.length
* descr
->token_size
);
816 #endif /* WE_IOCTL_DEBUG */
819 /* Call the handler */
820 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
822 /* If we have something to return to the user */
823 if (!ret
&& IW_IS_GET(cmd
)) {
824 /* Check if there is enough buffer up there */
825 if(user_length
< iwr
->u
.data
.length
) {
830 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
835 #ifdef WE_IOCTL_DEBUG
836 printk(KERN_DEBUG
"%s (WE) : Wrote %d bytes\n",
838 iwr
->u
.data
.length
* descr
->token_size
);
839 #endif /* WE_IOCTL_DEBUG */
843 /* Generate an event to notify listeners of the change */
844 if((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
845 ((ret
== 0) || (ret
== -EIWCOMMIT
))) {
846 if(descr
->flags
& IW_DESCR_FLAG_RESTRICT
)
847 /* If the event is restricted, don't
848 * export the payload */
849 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
851 wireless_send_event(dev
, cmd
, &(iwr
->u
),
854 #endif /* WE_SET_EVENT */
856 /* Cleanup - I told you it wasn't that long ;-) */
860 /* Call commit handler if needed and defined */
861 if(ret
== -EIWCOMMIT
)
862 ret
= call_commit_handler(dev
);
864 /* Here, we will generate the appropriate event if needed */
869 /* ---------------------------------------------------------------- */
871 * Wrapper to call a private Wireless Extension handler.
872 * We do various checks and also take care of moving data between
873 * user space and kernel space.
874 * It's not as nice and slimline as the standard wrapper. The cause
875 * is struct iw_priv_args, which was not really designed for the
876 * job we are going here.
878 * IMPORTANT : This function prevent to set and get data on the same
879 * IOCTL and enforce the SET/GET convention. Not doing it would be
881 * If you need to set and get data at the same time, please don't use
882 * a iw_handler but process it in your ioctl handler (i.e. use the
885 static inline int ioctl_private_call(struct net_device
* dev
,
890 struct iwreq
* iwr
= (struct iwreq
*) ifr
;
891 const struct iw_priv_args
* descr
= NULL
;
892 struct iw_request_info info
;
897 /* Get the description of the IOCTL */
898 for(i
= 0; i
< dev
->wireless_handlers
->num_private_args
; i
++)
899 if(cmd
== dev
->wireless_handlers
->private_args
[i
].cmd
) {
900 descr
= &(dev
->wireless_handlers
->private_args
[i
]);
904 #ifdef WE_IOCTL_DEBUG
905 printk(KERN_DEBUG
"%s (WE) : Found private handler for 0x%04X\n",
908 printk(KERN_DEBUG
"%s (WE) : Name %s, set %X, get %X\n",
909 dev
->name
, descr
->name
,
910 descr
->set_args
, descr
->get_args
);
912 #endif /* WE_IOCTL_DEBUG */
914 /* Compute the size of the set/get arguments */
917 int offset
= 0; /* For sub-ioctls */
918 /* Check for sub-ioctl handler */
919 if(descr
->name
[0] == '\0')
920 /* Reserve one int for sub-ioctl index */
921 offset
= sizeof(__u32
);
923 /* Size of set arguments */
924 extra_size
= get_priv_size(descr
->set_args
);
926 /* Does it fits in iwr ? */
927 if((descr
->set_args
& IW_PRIV_SIZE_FIXED
) &&
928 ((extra_size
+ offset
) <= IFNAMSIZ
))
931 /* Size of get arguments */
932 extra_size
= get_priv_size(descr
->get_args
);
934 /* Does it fits in iwr ? */
935 if((descr
->get_args
& IW_PRIV_SIZE_FIXED
) &&
936 (extra_size
<= IFNAMSIZ
))
941 /* Prepare the call */
945 /* Check if we have a pointer to user space data or not. */
946 if(extra_size
== 0) {
947 /* No extra arguments. Trivial to handle */
948 ret
= handler(dev
, &info
, &(iwr
->u
), (char *) &(iwr
->u
));
953 /* Check what user space is giving us */
955 /* Check NULL pointer */
956 if((iwr
->u
.data
.pointer
== NULL
) &&
957 (iwr
->u
.data
.length
!= 0))
960 /* Does it fits within bounds ? */
961 if(iwr
->u
.data
.length
> (descr
->set_args
&
965 /* Check NULL pointer */
966 if(iwr
->u
.data
.pointer
== NULL
)
970 #ifdef WE_IOCTL_DEBUG
971 printk(KERN_DEBUG
"%s (WE) : Malloc %d bytes\n",
972 dev
->name
, extra_size
);
973 #endif /* WE_IOCTL_DEBUG */
975 /* Always allocate for max space. Easier, and won't last
977 extra
= kmalloc(extra_size
, GFP_KERNEL
);
982 /* If it is a SET, get all the extra data in here */
983 if(IW_IS_SET(cmd
) && (iwr
->u
.data
.length
!= 0)) {
984 err
= copy_from_user(extra
, iwr
->u
.data
.pointer
,
990 #ifdef WE_IOCTL_DEBUG
991 printk(KERN_DEBUG
"%s (WE) : Got %d elem\n",
992 dev
->name
, iwr
->u
.data
.length
);
993 #endif /* WE_IOCTL_DEBUG */
996 /* Call the handler */
997 ret
= handler(dev
, &info
, &(iwr
->u
), extra
);
999 /* If we have something to return to the user */
1000 if (!ret
&& IW_IS_GET(cmd
)) {
1002 /* Adjust for the actual length if it's variable,
1003 * avoid leaking kernel bits outside. */
1004 if (!(descr
->get_args
& IW_PRIV_SIZE_FIXED
)) {
1005 extra_size
= adjust_priv_size(descr
->get_args
,
1009 err
= copy_to_user(iwr
->u
.data
.pointer
, extra
,
1013 #ifdef WE_IOCTL_DEBUG
1014 printk(KERN_DEBUG
"%s (WE) : Wrote %d elem\n",
1015 dev
->name
, iwr
->u
.data
.length
);
1016 #endif /* WE_IOCTL_DEBUG */
1019 /* Cleanup - I told you it wasn't that long ;-) */
1024 /* Call commit handler if needed and defined */
1025 if(ret
== -EIWCOMMIT
)
1026 ret
= call_commit_handler(dev
);
1031 /* ---------------------------------------------------------------- */
1033 * Main IOCTl dispatcher. Called from the main networking code
1034 * (dev_ioctl() in net/core/dev.c).
1035 * Check the type of IOCTL and call the appropriate wrapper...
1037 int wireless_process_ioctl(struct ifreq
*ifr
, unsigned int cmd
)
1039 struct net_device
*dev
;
1042 /* Permissions are already checked in dev_ioctl() before calling us.
1043 * The copy_to/from_user() of ifr is also dealt with in there */
1045 /* Make sure the device exist */
1046 if ((dev
= __dev_get_by_name(ifr
->ifr_name
)) == NULL
)
1049 /* A bunch of special cases, then the generic case...
1050 * Note that 'cmd' is already filtered in dev_ioctl() with
1051 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
1055 /* Get Wireless Stats */
1056 return ioctl_standard_call(dev
,
1059 &iw_handler_get_iwstats
);
1062 /* Check if we have some wireless handlers defined */
1063 if(dev
->wireless_handlers
!= NULL
) {
1064 /* We export to user space the definition of
1065 * the private handler ourselves */
1066 return ioctl_standard_call(dev
,
1069 &iw_handler_get_private
);
1071 // ## Fall-through for old API ##
1075 if (!netif_device_present(dev
))
1077 /* New driver API : try to find the handler */
1078 handler
= get_handler(dev
, cmd
);
1079 if(handler
!= NULL
) {
1080 /* Standard and private are not the same */
1081 if(cmd
< SIOCIWFIRSTPRIV
)
1082 return ioctl_standard_call(dev
,
1087 return ioctl_private_call(dev
,
1092 /* Old driver API : call driver ioctl handler */
1093 if (dev
->do_ioctl
) {
1094 return dev
->do_ioctl(dev
, ifr
, cmd
);
1102 /********************** RTNETLINK REQUEST API **********************/
1104 * The alternate user space API to configure all those Wireless Extensions
1105 * is through RtNetlink.
1106 * This API support only the new driver API (iw_handler).
1108 * This RtNetlink API use the same query/reply model as the ioctl API.
1109 * Maximum effort has been done to fit in the RtNetlink model, and
1110 * we support both RtNetlink Set and RtNelink Get operations.
1111 * On the other hand, we don't offer Dump operations because of the
1112 * following reasons :
1113 * o Large number of parameters, most optional
1114 * o Large size of some parameters (> 100 bytes)
1115 * o Each parameters need to be extracted from hardware
1116 * o Scan requests can take seconds and disable network activity.
1117 * Because of this high cost/overhead, we want to return only the
1118 * parameters the user application is really interested in.
1119 * We could offer partial Dump using the IW_DESCR_FLAG_DUMP flag.
1121 * The API uses the standard RtNetlink socket. When the RtNetlink code
1122 * find a IFLA_WIRELESS field in a RtNetlink SET_LINK request,
1126 #ifdef CONFIG_NET_WIRELESS_RTNETLINK
1127 /* ---------------------------------------------------------------- */
1129 * Wrapper to call a standard Wireless Extension GET handler.
1130 * We do various checks and call the handler with the proper args.
1132 static int rtnetlink_standard_get(struct net_device
* dev
,
1133 struct iw_event
* request
,
1139 const struct iw_ioctl_description
* descr
= NULL
;
1141 union iwreq_data
* wrqu
;
1143 struct iw_request_info info
;
1144 char * buffer
= NULL
;
1145 int buffer_size
= 0;
1148 /* Get the description of the Request */
1150 if((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
1152 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
1154 #ifdef WE_RTNETLINK_DEBUG
1155 printk(KERN_DEBUG
"%s (WE.r) : Found standard handler for 0x%04X\n",
1157 printk(KERN_DEBUG
"%s (WE.r) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev
->name
, descr
->header_type
, descr
->token_type
, descr
->token_size
, descr
->max_tokens
);
1158 #endif /* WE_RTNETLINK_DEBUG */
1160 /* Check if wrqu is complete */
1161 hdr_len
= event_type_size
[descr
->header_type
];
1162 if(request_len
< hdr_len
) {
1163 #ifdef WE_RTNETLINK_DEBUG
1165 "%s (WE.r) : Wireless request too short (%d)\n",
1166 dev
->name
, request_len
);
1167 #endif /* WE_RTNETLINK_DEBUG */
1171 /* Prepare the call */
1175 /* Check if we have extra data in the reply or not */
1176 if(descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
1178 /* Create the kernel buffer that we will return.
1179 * It's at an offset to match the TYPE_POINT case... */
1180 buffer_size
= request_len
+ IW_EV_POINT_OFF
;
1181 buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
1182 if (buffer
== NULL
) {
1185 /* Copy event data */
1186 memcpy(buffer
+ IW_EV_POINT_OFF
, request
, request_len
);
1187 /* Use our own copy of wrqu */
1188 wrqu
= (union iwreq_data
*) (buffer
+ IW_EV_POINT_OFF
1191 /* No extra arguments. Trivial to handle */
1192 ret
= handler(dev
, &info
, wrqu
, NULL
);
1195 union iwreq_data wrqu_point
;
1196 char * extra
= NULL
;
1199 /* Get a temp copy of wrqu (skip pointer) */
1200 memcpy(((char *) &wrqu_point
) + IW_EV_POINT_OFF
,
1201 ((char *) request
) + IW_EV_LCP_LEN
,
1202 IW_EV_POINT_LEN
- IW_EV_LCP_LEN
);
1204 /* Calculate space needed by arguments. Always allocate
1205 * for max space. Easier, and won't last long... */
1206 extra_size
= descr
->max_tokens
* descr
->token_size
;
1207 /* Support for very large requests */
1208 if((descr
->flags
& IW_DESCR_FLAG_NOMAX
) &&
1209 (wrqu_point
.data
.length
> descr
->max_tokens
))
1210 extra_size
= (wrqu_point
.data
.length
1211 * descr
->token_size
);
1212 buffer_size
= extra_size
+ IW_EV_POINT_LEN
+ IW_EV_POINT_OFF
;
1213 #ifdef WE_RTNETLINK_DEBUG
1214 printk(KERN_DEBUG
"%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1215 dev
->name
, extra_size
, buffer_size
);
1216 #endif /* WE_RTNETLINK_DEBUG */
1218 /* Create the kernel buffer that we will return */
1219 buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
1220 if (buffer
== NULL
) {
1224 /* Put wrqu in the right place (just before extra).
1225 * Leave space for IWE header and dummy pointer...
1226 * Note that IW_EV_LCP_LEN==4 bytes, so it's still aligned...
1228 memcpy(buffer
+ IW_EV_LCP_LEN
+ IW_EV_POINT_OFF
,
1229 ((char *) &wrqu_point
) + IW_EV_POINT_OFF
,
1230 IW_EV_POINT_LEN
- IW_EV_LCP_LEN
);
1231 wrqu
= (union iwreq_data
*) (buffer
+ IW_EV_LCP_LEN
);
1233 /* Extra comes logically after that. Offset +12 bytes. */
1234 extra
= buffer
+ IW_EV_POINT_OFF
+ IW_EV_POINT_LEN
;
1236 /* Call the handler */
1237 ret
= handler(dev
, &info
, wrqu
, extra
);
1239 /* Calculate real returned length */
1240 extra_size
= (wrqu
->data
.length
* descr
->token_size
);
1241 /* Re-adjust reply size */
1242 request
->len
= extra_size
+ IW_EV_POINT_LEN
;
1244 /* Put the iwe header where it should, i.e. scrap the
1246 memcpy(buffer
+ IW_EV_POINT_OFF
, request
, IW_EV_LCP_LEN
);
1248 #ifdef WE_RTNETLINK_DEBUG
1249 printk(KERN_DEBUG
"%s (WE.r) : Reply 0x%04X, hdr_len %d, tokens %d, extra_size %d, buffer_size %d\n", dev
->name
, cmd
, hdr_len
, wrqu
->data
.length
, extra_size
, buffer_size
);
1250 #endif /* WE_RTNETLINK_DEBUG */
1252 /* Check if there is enough buffer up there */
1253 if(wrqu_point
.data
.length
< wrqu
->data
.length
)
1257 /* Return the buffer to the caller */
1260 *p_len
= request
->len
;
1270 /* ---------------------------------------------------------------- */
1272 * Wrapper to call a standard Wireless Extension SET handler.
1273 * We do various checks and call the handler with the proper args.
1275 static inline int rtnetlink_standard_set(struct net_device
* dev
,
1276 struct iw_event
* request
,
1280 const struct iw_ioctl_description
* descr
= NULL
;
1282 union iwreq_data
* wrqu
;
1283 union iwreq_data wrqu_point
;
1285 char * extra
= NULL
;
1287 struct iw_request_info info
;
1290 /* Get the description of the Request */
1292 if((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
1294 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
1296 #ifdef WE_RTNETLINK_DEBUG
1297 printk(KERN_DEBUG
"%s (WE.r) : Found standard SET handler for 0x%04X\n",
1299 printk(KERN_DEBUG
"%s (WE.r) : Header type : %d, Token type : %d, size : %d, token : %d\n", dev
->name
, descr
->header_type
, descr
->token_type
, descr
->token_size
, descr
->max_tokens
);
1300 #endif /* WE_RTNETLINK_DEBUG */
1302 /* Extract fixed header from request. This is properly aligned. */
1305 /* Check if wrqu is complete */
1306 hdr_len
= event_type_size
[descr
->header_type
];
1307 if(request_len
< hdr_len
) {
1308 #ifdef WE_RTNETLINK_DEBUG
1310 "%s (WE.r) : Wireless request too short (%d)\n",
1311 dev
->name
, request_len
);
1312 #endif /* WE_RTNETLINK_DEBUG */
1316 /* Prepare the call */
1320 /* Check if we have extra data in the request or not */
1321 if(descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
1323 /* No extra arguments. Trivial to handle */
1324 ret
= handler(dev
, &info
, wrqu
, NULL
);
1329 /* Put wrqu in the right place (skip pointer) */
1330 memcpy(((char *) &wrqu_point
) + IW_EV_POINT_OFF
,
1331 wrqu
, IW_EV_POINT_LEN
- IW_EV_LCP_LEN
);
1332 /* Don't forget about the event code... */
1335 /* Check if number of token fits within bounds */
1336 if(wrqu_point
.data
.length
> descr
->max_tokens
)
1338 if(wrqu_point
.data
.length
< descr
->min_tokens
)
1341 /* Real length of payload */
1342 extra_len
= wrqu_point
.data
.length
* descr
->token_size
;
1344 /* Check if request is self consistent */
1345 if((request_len
- hdr_len
) < extra_len
) {
1346 #ifdef WE_RTNETLINK_DEBUG
1347 printk(KERN_DEBUG
"%s (WE.r) : Wireless request data too short (%d)\n",
1348 dev
->name
, extra_size
);
1349 #endif /* WE_RTNETLINK_DEBUG */
1353 #ifdef WE_RTNETLINK_DEBUG
1354 printk(KERN_DEBUG
"%s (WE.r) : Malloc %d bytes\n",
1355 dev
->name
, extra_size
);
1356 #endif /* WE_RTNETLINK_DEBUG */
1358 /* Always allocate for max space. Easier, and won't last
1360 extra_size
= descr
->max_tokens
* descr
->token_size
;
1361 extra
= kmalloc(extra_size
, GFP_KERNEL
);
1365 /* Copy extra in aligned buffer */
1366 memcpy(extra
, ((char *) request
) + hdr_len
, extra_len
);
1368 /* Call the handler */
1369 ret
= handler(dev
, &info
, &wrqu_point
, extra
);
1373 /* Generate an event to notify listeners of the change */
1374 if((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
1375 ((ret
== 0) || (ret
== -EIWCOMMIT
))) {
1376 if(descr
->flags
& IW_DESCR_FLAG_RESTRICT
)
1377 /* If the event is restricted, don't
1378 * export the payload */
1379 wireless_send_event(dev
, cmd
, wrqu
, NULL
);
1381 wireless_send_event(dev
, cmd
, wrqu
, extra
);
1383 #endif /* WE_SET_EVENT */
1385 /* Cleanup - I told you it wasn't that long ;-) */
1389 /* Call commit handler if needed and defined */
1390 if(ret
== -EIWCOMMIT
)
1391 ret
= call_commit_handler(dev
);
1396 /* ---------------------------------------------------------------- */
1398 * Wrapper to call a private Wireless Extension GET handler.
1400 * It's not as nice and slimline as the standard wrapper. The cause
1401 * is struct iw_priv_args, which was not really designed for the
1402 * job we are going here.
1404 * IMPORTANT : This function prevent to set and get data on the same
1405 * IOCTL and enforce the SET/GET convention. Not doing it would be
1407 * If you need to set and get data at the same time, please don't use
1408 * a iw_handler but process it in your ioctl handler (i.e. use the
1411 static inline int rtnetlink_private_get(struct net_device
* dev
,
1412 struct iw_event
* request
,
1418 const struct iw_priv_args
* descr
= NULL
;
1420 union iwreq_data
* wrqu
;
1422 struct iw_request_info info
;
1425 char * buffer
= NULL
;
1426 int buffer_size
= 0;
1429 /* Get the description of the Request */
1431 for(i
= 0; i
< dev
->wireless_handlers
->num_private_args
; i
++)
1432 if(cmd
== dev
->wireless_handlers
->private_args
[i
].cmd
) {
1433 descr
= &(dev
->wireless_handlers
->private_args
[i
]);
1439 #ifdef WE_RTNETLINK_DEBUG
1440 printk(KERN_DEBUG
"%s (WE.r) : Found private handler for 0x%04X\n",
1442 printk(KERN_DEBUG
"%s (WE.r) : Name %s, set %X, get %X\n",
1443 dev
->name
, descr
->name
, descr
->set_args
, descr
->get_args
);
1444 #endif /* WE_RTNETLINK_DEBUG */
1446 /* Compute the max size of the get arguments */
1447 extra_size
= get_priv_size(descr
->get_args
);
1449 /* Does it fits in wrqu ? */
1450 if((descr
->get_args
& IW_PRIV_SIZE_FIXED
) &&
1451 (extra_size
<= IFNAMSIZ
)) {
1452 hdr_len
= extra_size
;
1455 hdr_len
= IW_EV_POINT_LEN
;
1458 /* Check if wrqu is complete */
1459 if(request_len
< hdr_len
) {
1460 #ifdef WE_RTNETLINK_DEBUG
1462 "%s (WE.r) : Wireless request too short (%d)\n",
1463 dev
->name
, request_len
);
1464 #endif /* WE_RTNETLINK_DEBUG */
1468 /* Prepare the call */
1472 /* Check if we have a pointer to user space data or not. */
1473 if(extra_size
== 0) {
1475 /* Create the kernel buffer that we will return.
1476 * It's at an offset to match the TYPE_POINT case... */
1477 buffer_size
= request_len
+ IW_EV_POINT_OFF
;
1478 buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
1479 if (buffer
== NULL
) {
1482 /* Copy event data */
1483 memcpy(buffer
+ IW_EV_POINT_OFF
, request
, request_len
);
1484 /* Use our own copy of wrqu */
1485 wrqu
= (union iwreq_data
*) (buffer
+ IW_EV_POINT_OFF
1488 /* No extra arguments. Trivial to handle */
1489 ret
= handler(dev
, &info
, wrqu
, (char *) wrqu
);
1494 /* Buffer for full reply */
1495 buffer_size
= extra_size
+ IW_EV_POINT_LEN
+ IW_EV_POINT_OFF
;
1497 #ifdef WE_RTNETLINK_DEBUG
1498 printk(KERN_DEBUG
"%s (WE.r) : Malloc %d bytes (%d bytes)\n",
1499 dev
->name
, extra_size
, buffer_size
);
1500 #endif /* WE_RTNETLINK_DEBUG */
1502 /* Create the kernel buffer that we will return */
1503 buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
1504 if (buffer
== NULL
) {
1508 /* Put wrqu in the right place (just before extra).
1509 * Leave space for IWE header and dummy pointer...
1510 * Note that IW_EV_LCP_LEN==4 bytes, so it's still aligned...
1512 memcpy(buffer
+ IW_EV_LCP_LEN
+ IW_EV_POINT_OFF
,
1513 ((char *) request
) + IW_EV_LCP_LEN
,
1514 IW_EV_POINT_LEN
- IW_EV_LCP_LEN
);
1515 wrqu
= (union iwreq_data
*) (buffer
+ IW_EV_LCP_LEN
);
1517 /* Extra comes logically after that. Offset +12 bytes. */
1518 extra
= buffer
+ IW_EV_POINT_OFF
+ IW_EV_POINT_LEN
;
1520 /* Call the handler */
1521 ret
= handler(dev
, &info
, wrqu
, extra
);
1523 /* Adjust for the actual length if it's variable,
1524 * avoid leaking kernel bits outside. */
1525 if (!(descr
->get_args
& IW_PRIV_SIZE_FIXED
))
1526 extra_size
= adjust_priv_size(descr
->get_args
, wrqu
);
1527 /* Re-adjust reply size */
1528 request
->len
= extra_size
+ IW_EV_POINT_LEN
;
1530 /* Put the iwe header where it should, i.e. scrap the
1532 memcpy(buffer
+ IW_EV_POINT_OFF
, request
, IW_EV_LCP_LEN
);
1534 #ifdef WE_RTNETLINK_DEBUG
1535 printk(KERN_DEBUG
"%s (WE.r) : Reply 0x%04X, hdr_len %d, tokens %d, extra_size %d, buffer_size %d\n", dev
->name
, cmd
, hdr_len
, wrqu
->data
.length
, extra_size
, buffer_size
);
1536 #endif /* WE_RTNETLINK_DEBUG */
1539 /* Return the buffer to the caller */
1542 *p_len
= request
->len
;
1552 /* ---------------------------------------------------------------- */
1554 * Wrapper to call a private Wireless Extension SET handler.
1556 * It's not as nice and slimline as the standard wrapper. The cause
1557 * is struct iw_priv_args, which was not really designed for the
1558 * job we are going here.
1560 * IMPORTANT : This function prevent to set and get data on the same
1561 * IOCTL and enforce the SET/GET convention. Not doing it would be
1563 * If you need to set and get data at the same time, please don't use
1564 * a iw_handler but process it in your ioctl handler (i.e. use the
1567 static inline int rtnetlink_private_set(struct net_device
* dev
,
1568 struct iw_event
* request
,
1572 const struct iw_priv_args
* descr
= NULL
;
1574 union iwreq_data
* wrqu
;
1575 union iwreq_data wrqu_point
;
1577 char * extra
= NULL
;
1579 int offset
= 0; /* For sub-ioctls */
1580 struct iw_request_info info
;
1584 /* Get the description of the Request */
1586 for(i
= 0; i
< dev
->wireless_handlers
->num_private_args
; i
++)
1587 if(cmd
== dev
->wireless_handlers
->private_args
[i
].cmd
) {
1588 descr
= &(dev
->wireless_handlers
->private_args
[i
]);
1594 #ifdef WE_RTNETLINK_DEBUG
1595 printk(KERN_DEBUG
"%s (WE.r) : Found private handler for 0x%04X\n",
1596 ifr
->ifr_name
, cmd
);
1597 printk(KERN_DEBUG
"%s (WE.r) : Name %s, set %X, get %X\n",
1598 dev
->name
, descr
->name
, descr
->set_args
, descr
->get_args
);
1599 #endif /* WE_RTNETLINK_DEBUG */
1601 /* Compute the size of the set arguments */
1602 /* Check for sub-ioctl handler */
1603 if(descr
->name
[0] == '\0')
1604 /* Reserve one int for sub-ioctl index */
1605 offset
= sizeof(__u32
);
1607 /* Size of set arguments */
1608 extra_size
= get_priv_size(descr
->set_args
);
1610 /* Does it fits in wrqu ? */
1611 if((descr
->set_args
& IW_PRIV_SIZE_FIXED
) &&
1612 (extra_size
<= IFNAMSIZ
)) {
1613 hdr_len
= IW_EV_LCP_LEN
+ extra_size
;
1616 hdr_len
= IW_EV_POINT_LEN
;
1619 /* Extract fixed header from request. This is properly aligned. */
1622 /* Check if wrqu is complete */
1623 if(request_len
< hdr_len
) {
1624 #ifdef WE_RTNETLINK_DEBUG
1626 "%s (WE.r) : Wireless request too short (%d)\n",
1627 dev
->name
, request_len
);
1628 #endif /* WE_RTNETLINK_DEBUG */
1632 /* Prepare the call */
1636 /* Check if we have a pointer to user space data or not. */
1637 if(extra_size
== 0) {
1639 /* No extra arguments. Trivial to handle */
1640 ret
= handler(dev
, &info
, wrqu
, (char *) wrqu
);
1645 /* Put wrqu in the right place (skip pointer) */
1646 memcpy(((char *) &wrqu_point
) + IW_EV_POINT_OFF
,
1647 wrqu
, IW_EV_POINT_LEN
- IW_EV_LCP_LEN
);
1649 /* Does it fits within bounds ? */
1650 if(wrqu_point
.data
.length
> (descr
->set_args
&
1654 /* Real length of payload */
1655 extra_len
= adjust_priv_size(descr
->set_args
, &wrqu_point
);
1657 /* Check if request is self consistent */
1658 if((request_len
- hdr_len
) < extra_len
) {
1659 #ifdef WE_RTNETLINK_DEBUG
1660 printk(KERN_DEBUG
"%s (WE.r) : Wireless request data too short (%d)\n",
1661 dev
->name
, extra_size
);
1662 #endif /* WE_RTNETLINK_DEBUG */
1666 #ifdef WE_RTNETLINK_DEBUG
1667 printk(KERN_DEBUG
"%s (WE.r) : Malloc %d bytes\n",
1668 dev
->name
, extra_size
);
1669 #endif /* WE_RTNETLINK_DEBUG */
1671 /* Always allocate for max space. Easier, and won't last
1673 extra
= kmalloc(extra_size
, GFP_KERNEL
);
1677 /* Copy extra in aligned buffer */
1678 memcpy(extra
, ((char *) request
) + hdr_len
, extra_len
);
1680 /* Call the handler */
1681 ret
= handler(dev
, &info
, &wrqu_point
, extra
);
1683 /* Cleanup - I told you it wasn't that long ;-) */
1687 /* Call commit handler if needed and defined */
1688 if(ret
== -EIWCOMMIT
)
1689 ret
= call_commit_handler(dev
);
1694 /* ---------------------------------------------------------------- */
1696 * Main RtNetlink dispatcher. Called from the main networking code
1697 * (do_getlink() in net/core/rtnetlink.c).
1698 * Check the type of Request and call the appropriate wrapper...
1700 int wireless_rtnetlink_get(struct net_device
* dev
,
1706 struct iw_event
* request
= (struct iw_event
*) data
;
1710 if(len
< IW_EV_LCP_LEN
) {
1711 printk(KERN_DEBUG
"%s (WE.r) : RtNetlink request too short (%d)\n",
1716 /* ReCheck length (len may have padding) */
1717 if(request
->len
> len
) {
1718 printk(KERN_DEBUG
"%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1719 dev
->name
, request
->len
, len
);
1723 /* Only accept GET requests in here */
1724 if(!IW_IS_GET(request
->cmd
))
1727 /* If command is `get the encoding parameters', check if
1728 * the user has the right to do it */
1729 if (request
->cmd
== SIOCGIWENCODE
||
1730 request
->cmd
== SIOCGIWENCODEEXT
) {
1731 if (!capable(CAP_NET_ADMIN
))
1736 if(request
->cmd
== SIOCGIWSTATS
)
1737 /* Get Wireless Stats */
1738 return rtnetlink_standard_get(dev
,
1741 &iw_handler_get_iwstats
,
1743 if(request
->cmd
== SIOCGIWPRIV
) {
1744 /* Check if we have some wireless handlers defined */
1745 if(dev
->wireless_handlers
== NULL
)
1747 /* Get Wireless Stats */
1748 return rtnetlink_standard_get(dev
,
1751 &iw_handler_get_private
,
1756 if (!netif_device_present(dev
))
1759 /* Try to find the handler */
1760 handler
= get_handler(dev
, request
->cmd
);
1761 if(handler
!= NULL
) {
1762 /* Standard and private are not the same */
1763 if(request
->cmd
< SIOCIWFIRSTPRIV
)
1764 return rtnetlink_standard_get(dev
,
1770 return rtnetlink_private_get(dev
,
1780 /* ---------------------------------------------------------------- */
1782 * Main RtNetlink dispatcher. Called from the main networking code
1783 * (do_setlink() in net/core/rtnetlink.c).
1784 * Check the type of Request and call the appropriate wrapper...
1786 int wireless_rtnetlink_set(struct net_device
* dev
,
1790 struct iw_event
* request
= (struct iw_event
*) data
;
1794 if(len
< IW_EV_LCP_LEN
) {
1795 printk(KERN_DEBUG
"%s (WE.r) : RtNetlink request too short (%d)\n",
1800 /* ReCheck length (len may have padding) */
1801 if(request
->len
> len
) {
1802 printk(KERN_DEBUG
"%s (WE.r) : RtNetlink request len invalid (%d-%d)\n",
1803 dev
->name
, request
->len
, len
);
1807 /* Only accept SET requests in here */
1808 if(!IW_IS_SET(request
->cmd
))
1812 if (!netif_device_present(dev
))
1815 /* New driver API : try to find the handler */
1816 handler
= get_handler(dev
, request
->cmd
);
1817 if(handler
!= NULL
) {
1818 /* Standard and private are not the same */
1819 if(request
->cmd
< SIOCIWFIRSTPRIV
)
1820 return rtnetlink_standard_set(dev
,
1825 return rtnetlink_private_set(dev
,
1833 #endif /* CONFIG_NET_WIRELESS_RTNETLINK */
1836 /************************* EVENT PROCESSING *************************/
1838 * Process events generated by the wireless layer or the driver.
1839 * Most often, the event will be propagated through rtnetlink
1842 #ifdef WE_EVENT_RTNETLINK
1843 /* ---------------------------------------------------------------- */
1848 * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing
1849 * the locking issue in here and implementing this code !
1851 * The issue : wireless_send_event() is often called in interrupt context,
1852 * while the Netlink layer can never be called in interrupt context.
1853 * The fully formed RtNetlink events are queued, and then a tasklet is run
1854 * to feed those to Netlink.
1855 * The skb_queue is interrupt safe, and its lock is not held while calling
1856 * Netlink, so there is no possibility of dealock.
1860 static struct sk_buff_head wireless_nlevent_queue
;
1862 static int __init
wireless_nlevent_init(void)
1864 skb_queue_head_init(&wireless_nlevent_queue
);
1868 subsys_initcall(wireless_nlevent_init
);
1870 static void wireless_nlevent_process(unsigned long data
)
1872 struct sk_buff
*skb
;
1874 while ((skb
= skb_dequeue(&wireless_nlevent_queue
)))
1875 rtnl_notify(skb
, 0, RTNLGRP_LINK
, NULL
, GFP_ATOMIC
);
1878 static DECLARE_TASKLET(wireless_nlevent_tasklet
, wireless_nlevent_process
, 0);
1880 /* ---------------------------------------------------------------- */
1882 * Fill a rtnetlink message with our event data.
1883 * Note that we propage only the specified event and don't dump the
1884 * current wireless config. Dumping the wireless config is far too
1885 * expensive (for each parameter, the driver need to query the hardware).
1887 static inline int rtnetlink_fill_iwinfo(struct sk_buff
* skb
,
1888 struct net_device
* dev
,
1893 struct ifinfomsg
*r
;
1894 struct nlmsghdr
*nlh
;
1895 unsigned char *b
= skb
->tail
;
1897 nlh
= NLMSG_PUT(skb
, 0, 0, type
, sizeof(*r
));
1898 r
= NLMSG_DATA(nlh
);
1899 r
->ifi_family
= AF_UNSPEC
;
1901 r
->ifi_type
= dev
->type
;
1902 r
->ifi_index
= dev
->ifindex
;
1903 r
->ifi_flags
= dev_get_flags(dev
);
1904 r
->ifi_change
= 0; /* Wireless changes don't affect those flags */
1906 /* Add the wireless events in the netlink packet */
1907 RTA_PUT(skb
, IFLA_WIRELESS
, event_len
, event
);
1909 nlh
->nlmsg_len
= skb
->tail
- b
;
1914 skb_trim(skb
, b
- skb
->data
);
1918 /* ---------------------------------------------------------------- */
1920 * Create and broadcast and send it on the standard rtnetlink socket
1921 * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c
1922 * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field
1923 * within a RTM_NEWLINK event.
1925 static inline void rtmsg_iwinfo(struct net_device
* dev
,
1929 struct sk_buff
*skb
;
1930 int size
= NLMSG_GOODSIZE
;
1932 skb
= alloc_skb(size
, GFP_ATOMIC
);
1936 if (rtnetlink_fill_iwinfo(skb
, dev
, RTM_NEWLINK
,
1937 event
, event_len
) < 0) {
1941 NETLINK_CB(skb
).dst_group
= RTNLGRP_LINK
;
1942 skb_queue_tail(&wireless_nlevent_queue
, skb
);
1943 tasklet_schedule(&wireless_nlevent_tasklet
);
1946 #endif /* WE_EVENT_RTNETLINK */
1948 /* ---------------------------------------------------------------- */
1950 * Main event dispatcher. Called from other parts and drivers.
1951 * Send the event on the appropriate channels.
1952 * May be called from interrupt context.
1954 void wireless_send_event(struct net_device
* dev
,
1956 union iwreq_data
* wrqu
,
1959 const struct iw_ioctl_description
* descr
= NULL
;
1961 struct iw_event
*event
; /* Mallocated whole event */
1962 int event_len
; /* Its size */
1963 int hdr_len
; /* Size of the event header */
1964 int wrqu_off
= 0; /* Offset in wrqu */
1965 /* Don't "optimise" the following variable, it will crash */
1966 unsigned cmd_index
; /* *MUST* be unsigned */
1968 /* Get the description of the Event */
1969 if(cmd
<= SIOCIWLAST
) {
1970 cmd_index
= cmd
- SIOCIWFIRST
;
1971 if(cmd_index
< standard_ioctl_num
)
1972 descr
= &(standard_ioctl
[cmd_index
]);
1974 cmd_index
= cmd
- IWEVFIRST
;
1975 if(cmd_index
< standard_event_num
)
1976 descr
= &(standard_event
[cmd_index
]);
1978 /* Don't accept unknown events */
1980 /* Note : we don't return an error to the driver, because
1981 * the driver would not know what to do about it. It can't
1982 * return an error to the user, because the event is not
1983 * initiated by a user request.
1984 * The best the driver could do is to log an error message.
1985 * We will do it ourselves instead...
1987 printk(KERN_ERR
"%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
1991 #ifdef WE_EVENT_DEBUG
1992 printk(KERN_DEBUG
"%s (WE) : Got event 0x%04X\n",
1994 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
);
1995 #endif /* WE_EVENT_DEBUG */
1997 /* Check extra parameters and set extra_len */
1998 if(descr
->header_type
== IW_HEADER_TYPE_POINT
) {
1999 /* Check if number of token fits within bounds */
2000 if(wrqu
->data
.length
> descr
->max_tokens
) {
2001 printk(KERN_ERR
"%s (WE) : Wireless Event too big (%d)\n", dev
->name
, wrqu
->data
.length
);
2004 if(wrqu
->data
.length
< descr
->min_tokens
) {
2005 printk(KERN_ERR
"%s (WE) : Wireless Event too small (%d)\n", dev
->name
, wrqu
->data
.length
);
2008 /* Calculate extra_len - extra is NULL for restricted events */
2010 extra_len
= wrqu
->data
.length
* descr
->token_size
;
2011 /* Always at an offset in wrqu */
2012 wrqu_off
= IW_EV_POINT_OFF
;
2013 #ifdef WE_EVENT_DEBUG
2014 printk(KERN_DEBUG
"%s (WE) : Event 0x%04X, tokens %d, extra_len %d\n", dev
->name
, cmd
, wrqu
->data
.length
, extra_len
);
2015 #endif /* WE_EVENT_DEBUG */
2018 /* Total length of the event */
2019 hdr_len
= event_type_size
[descr
->header_type
];
2020 event_len
= hdr_len
+ extra_len
;
2022 #ifdef WE_EVENT_DEBUG
2023 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
);
2024 #endif /* WE_EVENT_DEBUG */
2026 /* Create temporary buffer to hold the event */
2027 event
= kmalloc(event_len
, GFP_ATOMIC
);
2032 event
->len
= event_len
;
2034 memcpy(&event
->u
, ((char *) wrqu
) + wrqu_off
, hdr_len
- IW_EV_LCP_LEN
);
2036 memcpy(((char *) event
) + hdr_len
, extra
, extra_len
);
2038 #ifdef WE_EVENT_RTNETLINK
2039 /* Send via the RtNetlink event channel */
2040 rtmsg_iwinfo(dev
, (char *) event
, event_len
);
2041 #endif /* WE_EVENT_RTNETLINK */
2046 return; /* Always success, I guess ;-) */
2049 /********************** ENHANCED IWSPY SUPPORT **********************/
2051 * In the old days, the driver was handling spy support all by itself.
2052 * Now, the driver can delegate this task to Wireless Extensions.
2053 * It needs to use those standard spy iw_handler in struct iw_handler_def,
2054 * push data to us via wireless_spy_update() and include struct iw_spy_data
2055 * in its private part (and export it in net_device->wireless_data->spy_data).
2056 * One of the main advantage of centralising spy support here is that
2057 * it becomes much easier to improve and extend it without having to touch
2058 * the drivers. One example is the addition of the Spy-Threshold events.
2061 /* ---------------------------------------------------------------- */
2063 * Return the pointer to the spy data in the driver.
2064 * Because this is called on the Rx path via wireless_spy_update(),
2065 * we want it to be efficient...
2067 static inline struct iw_spy_data
* get_spydata(struct net_device
*dev
)
2069 /* This is the new way */
2070 if(dev
->wireless_data
)
2071 return(dev
->wireless_data
->spy_data
);
2075 /*------------------------------------------------------------------*/
2077 * Standard Wireless Handler : set Spy List
2079 int iw_handler_set_spy(struct net_device
* dev
,
2080 struct iw_request_info
* info
,
2081 union iwreq_data
* wrqu
,
2084 struct iw_spy_data
* spydata
= get_spydata(dev
);
2085 struct sockaddr
* address
= (struct sockaddr
*) extra
;
2087 /* Make sure driver is not buggy or using the old API */
2091 /* Disable spy collection while we copy the addresses.
2092 * While we copy addresses, any call to wireless_spy_update()
2093 * will NOP. This is OK, as anyway the addresses are changing. */
2094 spydata
->spy_number
= 0;
2096 /* We want to operate without locking, because wireless_spy_update()
2097 * most likely will happen in the interrupt handler, and therefore
2098 * have its own locking constraints and needs performance.
2099 * The rtnl_lock() make sure we don't race with the other iw_handlers.
2100 * This make sure wireless_spy_update() "see" that the spy list
2101 * is temporarily disabled. */
2104 /* Are there are addresses to copy? */
2105 if(wrqu
->data
.length
> 0) {
2108 /* Copy addresses */
2109 for(i
= 0; i
< wrqu
->data
.length
; i
++)
2110 memcpy(spydata
->spy_address
[i
], address
[i
].sa_data
,
2113 memset(spydata
->spy_stat
, 0,
2114 sizeof(struct iw_quality
) * IW_MAX_SPY
);
2117 printk(KERN_DEBUG
"iw_handler_set_spy() : wireless_data %p, spydata %p, num %d\n", dev
->wireless_data
, spydata
, wrqu
->data
.length
);
2118 for (i
= 0; i
< wrqu
->data
.length
; i
++)
2120 "%02X:%02X:%02X:%02X:%02X:%02X \n",
2121 spydata
->spy_address
[i
][0],
2122 spydata
->spy_address
[i
][1],
2123 spydata
->spy_address
[i
][2],
2124 spydata
->spy_address
[i
][3],
2125 spydata
->spy_address
[i
][4],
2126 spydata
->spy_address
[i
][5]);
2127 #endif /* WE_SPY_DEBUG */
2130 /* Make sure above is updated before re-enabling */
2133 /* Enable addresses */
2134 spydata
->spy_number
= wrqu
->data
.length
;
2139 /*------------------------------------------------------------------*/
2141 * Standard Wireless Handler : get Spy List
2143 int iw_handler_get_spy(struct net_device
* dev
,
2144 struct iw_request_info
* info
,
2145 union iwreq_data
* wrqu
,
2148 struct iw_spy_data
* spydata
= get_spydata(dev
);
2149 struct sockaddr
* address
= (struct sockaddr
*) extra
;
2152 /* Make sure driver is not buggy or using the old API */
2156 wrqu
->data
.length
= spydata
->spy_number
;
2158 /* Copy addresses. */
2159 for(i
= 0; i
< spydata
->spy_number
; i
++) {
2160 memcpy(address
[i
].sa_data
, spydata
->spy_address
[i
], ETH_ALEN
);
2161 address
[i
].sa_family
= AF_UNIX
;
2163 /* Copy stats to the user buffer (just after). */
2164 if(spydata
->spy_number
> 0)
2165 memcpy(extra
+ (sizeof(struct sockaddr
) *spydata
->spy_number
),
2167 sizeof(struct iw_quality
) * spydata
->spy_number
);
2168 /* Reset updated flags. */
2169 for(i
= 0; i
< spydata
->spy_number
; i
++)
2170 spydata
->spy_stat
[i
].updated
&= ~IW_QUAL_ALL_UPDATED
;
2174 /*------------------------------------------------------------------*/
2176 * Standard Wireless Handler : set spy threshold
2178 int iw_handler_set_thrspy(struct net_device
* dev
,
2179 struct iw_request_info
*info
,
2180 union iwreq_data
* wrqu
,
2183 struct iw_spy_data
* spydata
= get_spydata(dev
);
2184 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
2186 /* Make sure driver is not buggy or using the old API */
2191 memcpy(&(spydata
->spy_thr_low
), &(threshold
->low
),
2192 2 * sizeof(struct iw_quality
));
2195 memset(spydata
->spy_thr_under
, '\0', sizeof(spydata
->spy_thr_under
));
2198 printk(KERN_DEBUG
"iw_handler_set_thrspy() : low %d ; high %d\n", spydata
->spy_thr_low
.level
, spydata
->spy_thr_high
.level
);
2199 #endif /* WE_SPY_DEBUG */
2204 /*------------------------------------------------------------------*/
2206 * Standard Wireless Handler : get spy threshold
2208 int iw_handler_get_thrspy(struct net_device
* dev
,
2209 struct iw_request_info
*info
,
2210 union iwreq_data
* wrqu
,
2213 struct iw_spy_data
* spydata
= get_spydata(dev
);
2214 struct iw_thrspy
* threshold
= (struct iw_thrspy
*) extra
;
2216 /* Make sure driver is not buggy or using the old API */
2221 memcpy(&(threshold
->low
), &(spydata
->spy_thr_low
),
2222 2 * sizeof(struct iw_quality
));
2227 /*------------------------------------------------------------------*/
2229 * Prepare and send a Spy Threshold event
2231 static void iw_send_thrspy_event(struct net_device
* dev
,
2232 struct iw_spy_data
* spydata
,
2233 unsigned char * address
,
2234 struct iw_quality
* wstats
)
2236 union iwreq_data wrqu
;
2237 struct iw_thrspy threshold
;
2240 wrqu
.data
.length
= 1;
2241 wrqu
.data
.flags
= 0;
2243 memcpy(threshold
.addr
.sa_data
, address
, ETH_ALEN
);
2244 threshold
.addr
.sa_family
= ARPHRD_ETHER
;
2246 memcpy(&(threshold
.qual
), wstats
, sizeof(struct iw_quality
));
2247 /* Copy also thresholds */
2248 memcpy(&(threshold
.low
), &(spydata
->spy_thr_low
),
2249 2 * sizeof(struct iw_quality
));
2252 printk(KERN_DEBUG
"iw_send_thrspy_event() : address %02X:%02X:%02X:%02X:%02X:%02X, level %d, up = %d\n",
2253 threshold
.addr
.sa_data
[0],
2254 threshold
.addr
.sa_data
[1],
2255 threshold
.addr
.sa_data
[2],
2256 threshold
.addr
.sa_data
[3],
2257 threshold
.addr
.sa_data
[4],
2258 threshold
.addr
.sa_data
[5], threshold
.qual
.level
);
2259 #endif /* WE_SPY_DEBUG */
2261 /* Send event to user space */
2262 wireless_send_event(dev
, SIOCGIWTHRSPY
, &wrqu
, (char *) &threshold
);
2265 /* ---------------------------------------------------------------- */
2267 * Call for the driver to update the spy data.
2268 * For now, the spy data is a simple array. As the size of the array is
2269 * small, this is good enough. If we wanted to support larger number of
2270 * spy addresses, we should use something more efficient...
2272 void wireless_spy_update(struct net_device
* dev
,
2273 unsigned char * address
,
2274 struct iw_quality
* wstats
)
2276 struct iw_spy_data
* spydata
= get_spydata(dev
);
2280 /* Make sure driver is not buggy or using the old API */
2285 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]);
2286 #endif /* WE_SPY_DEBUG */
2288 /* Update all records that match */
2289 for(i
= 0; i
< spydata
->spy_number
; i
++)
2290 if(!compare_ether_addr(address
, spydata
->spy_address
[i
])) {
2291 memcpy(&(spydata
->spy_stat
[i
]), wstats
,
2292 sizeof(struct iw_quality
));
2296 /* Generate an event if we cross the spy threshold.
2297 * To avoid event storms, we have a simple hysteresis : we generate
2298 * event only when we go under the low threshold or above the
2299 * high threshold. */
2301 if(spydata
->spy_thr_under
[match
]) {
2302 if(wstats
->level
> spydata
->spy_thr_high
.level
) {
2303 spydata
->spy_thr_under
[match
] = 0;
2304 iw_send_thrspy_event(dev
, spydata
,
2308 if(wstats
->level
< spydata
->spy_thr_low
.level
) {
2309 spydata
->spy_thr_under
[match
] = 1;
2310 iw_send_thrspy_event(dev
, spydata
,
2317 EXPORT_SYMBOL(iw_handler_get_spy
);
2318 EXPORT_SYMBOL(iw_handler_get_thrspy
);
2319 EXPORT_SYMBOL(iw_handler_set_spy
);
2320 EXPORT_SYMBOL(iw_handler_set_thrspy
);
2321 EXPORT_SYMBOL(wireless_send_event
);
2322 EXPORT_SYMBOL(wireless_spy_update
);