2 * This file implement the Wireless Extensions core API.
4 * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com>
5 * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
6 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
8 * (As all part of the Linux kernel, this file is GPL)
10 #include <linux/kernel.h>
11 #include <linux/netdevice.h>
12 #include <linux/rtnetlink.h>
13 #include <linux/wireless.h>
14 #include <linux/uaccess.h>
15 #include <net/cfg80211.h>
16 #include <net/iw_handler.h>
17 #include <net/netlink.h>
19 #include <net/net_namespace.h>
21 typedef int (*wext_ioctl_func
)(struct net_device
*, struct iwreq
*,
22 unsigned int, struct iw_request_info
*,
27 * Meta-data about all the standard Wireless Extension request we
30 static const struct iw_ioctl_description standard_ioctl
[] = {
31 [SIOCSIWCOMMIT
- SIOCIWFIRST
] = {
32 .header_type
= IW_HEADER_TYPE_NULL
,
34 [SIOCGIWNAME
- SIOCIWFIRST
] = {
35 .header_type
= IW_HEADER_TYPE_CHAR
,
36 .flags
= IW_DESCR_FLAG_DUMP
,
38 [SIOCSIWNWID
- SIOCIWFIRST
] = {
39 .header_type
= IW_HEADER_TYPE_PARAM
,
40 .flags
= IW_DESCR_FLAG_EVENT
,
42 [SIOCGIWNWID
- SIOCIWFIRST
] = {
43 .header_type
= IW_HEADER_TYPE_PARAM
,
44 .flags
= IW_DESCR_FLAG_DUMP
,
46 [SIOCSIWFREQ
- SIOCIWFIRST
] = {
47 .header_type
= IW_HEADER_TYPE_FREQ
,
48 .flags
= IW_DESCR_FLAG_EVENT
,
50 [SIOCGIWFREQ
- SIOCIWFIRST
] = {
51 .header_type
= IW_HEADER_TYPE_FREQ
,
52 .flags
= IW_DESCR_FLAG_DUMP
,
54 [SIOCSIWMODE
- SIOCIWFIRST
] = {
55 .header_type
= IW_HEADER_TYPE_UINT
,
56 .flags
= IW_DESCR_FLAG_EVENT
,
58 [SIOCGIWMODE
- SIOCIWFIRST
] = {
59 .header_type
= IW_HEADER_TYPE_UINT
,
60 .flags
= IW_DESCR_FLAG_DUMP
,
62 [SIOCSIWSENS
- SIOCIWFIRST
] = {
63 .header_type
= IW_HEADER_TYPE_PARAM
,
65 [SIOCGIWSENS
- SIOCIWFIRST
] = {
66 .header_type
= IW_HEADER_TYPE_PARAM
,
68 [SIOCSIWRANGE
- SIOCIWFIRST
] = {
69 .header_type
= IW_HEADER_TYPE_NULL
,
71 [SIOCGIWRANGE
- SIOCIWFIRST
] = {
72 .header_type
= IW_HEADER_TYPE_POINT
,
74 .max_tokens
= sizeof(struct iw_range
),
75 .flags
= IW_DESCR_FLAG_DUMP
,
77 [SIOCSIWPRIV
- SIOCIWFIRST
] = {
78 .header_type
= IW_HEADER_TYPE_NULL
,
80 [SIOCGIWPRIV
- SIOCIWFIRST
] = { /* (handled directly by us) */
81 .header_type
= IW_HEADER_TYPE_POINT
,
82 .token_size
= sizeof(struct iw_priv_args
),
84 .flags
= IW_DESCR_FLAG_NOMAX
,
86 [SIOCSIWSTATS
- SIOCIWFIRST
] = {
87 .header_type
= IW_HEADER_TYPE_NULL
,
89 [SIOCGIWSTATS
- SIOCIWFIRST
] = { /* (handled directly by us) */
90 .header_type
= IW_HEADER_TYPE_POINT
,
92 .max_tokens
= sizeof(struct iw_statistics
),
93 .flags
= IW_DESCR_FLAG_DUMP
,
95 [SIOCSIWSPY
- SIOCIWFIRST
] = {
96 .header_type
= IW_HEADER_TYPE_POINT
,
97 .token_size
= sizeof(struct sockaddr
),
98 .max_tokens
= IW_MAX_SPY
,
100 [SIOCGIWSPY
- SIOCIWFIRST
] = {
101 .header_type
= IW_HEADER_TYPE_POINT
,
102 .token_size
= sizeof(struct sockaddr
) +
103 sizeof(struct iw_quality
),
104 .max_tokens
= IW_MAX_SPY
,
106 [SIOCSIWTHRSPY
- SIOCIWFIRST
] = {
107 .header_type
= IW_HEADER_TYPE_POINT
,
108 .token_size
= sizeof(struct iw_thrspy
),
112 [SIOCGIWTHRSPY
- SIOCIWFIRST
] = {
113 .header_type
= IW_HEADER_TYPE_POINT
,
114 .token_size
= sizeof(struct iw_thrspy
),
118 [SIOCSIWAP
- SIOCIWFIRST
] = {
119 .header_type
= IW_HEADER_TYPE_ADDR
,
121 [SIOCGIWAP
- SIOCIWFIRST
] = {
122 .header_type
= IW_HEADER_TYPE_ADDR
,
123 .flags
= IW_DESCR_FLAG_DUMP
,
125 [SIOCSIWMLME
- SIOCIWFIRST
] = {
126 .header_type
= IW_HEADER_TYPE_POINT
,
128 .min_tokens
= sizeof(struct iw_mlme
),
129 .max_tokens
= sizeof(struct iw_mlme
),
131 [SIOCGIWAPLIST
- SIOCIWFIRST
] = {
132 .header_type
= IW_HEADER_TYPE_POINT
,
133 .token_size
= sizeof(struct sockaddr
) +
134 sizeof(struct iw_quality
),
135 .max_tokens
= IW_MAX_AP
,
136 .flags
= IW_DESCR_FLAG_NOMAX
,
138 [SIOCSIWSCAN
- SIOCIWFIRST
] = {
139 .header_type
= IW_HEADER_TYPE_POINT
,
142 .max_tokens
= sizeof(struct iw_scan_req
),
144 [SIOCGIWSCAN
- SIOCIWFIRST
] = {
145 .header_type
= IW_HEADER_TYPE_POINT
,
147 .max_tokens
= IW_SCAN_MAX_DATA
,
148 .flags
= IW_DESCR_FLAG_NOMAX
,
150 [SIOCSIWESSID
- SIOCIWFIRST
] = {
151 .header_type
= IW_HEADER_TYPE_POINT
,
153 .max_tokens
= IW_ESSID_MAX_SIZE
,
154 .flags
= IW_DESCR_FLAG_EVENT
,
156 [SIOCGIWESSID
- SIOCIWFIRST
] = {
157 .header_type
= IW_HEADER_TYPE_POINT
,
159 .max_tokens
= IW_ESSID_MAX_SIZE
,
160 .flags
= IW_DESCR_FLAG_DUMP
,
162 [SIOCSIWNICKN
- SIOCIWFIRST
] = {
163 .header_type
= IW_HEADER_TYPE_POINT
,
165 .max_tokens
= IW_ESSID_MAX_SIZE
,
167 [SIOCGIWNICKN
- SIOCIWFIRST
] = {
168 .header_type
= IW_HEADER_TYPE_POINT
,
170 .max_tokens
= IW_ESSID_MAX_SIZE
,
172 [SIOCSIWRATE
- SIOCIWFIRST
] = {
173 .header_type
= IW_HEADER_TYPE_PARAM
,
175 [SIOCGIWRATE
- SIOCIWFIRST
] = {
176 .header_type
= IW_HEADER_TYPE_PARAM
,
178 [SIOCSIWRTS
- SIOCIWFIRST
] = {
179 .header_type
= IW_HEADER_TYPE_PARAM
,
181 [SIOCGIWRTS
- SIOCIWFIRST
] = {
182 .header_type
= IW_HEADER_TYPE_PARAM
,
184 [SIOCSIWFRAG
- SIOCIWFIRST
] = {
185 .header_type
= IW_HEADER_TYPE_PARAM
,
187 [SIOCGIWFRAG
- SIOCIWFIRST
] = {
188 .header_type
= IW_HEADER_TYPE_PARAM
,
190 [SIOCSIWTXPOW
- SIOCIWFIRST
] = {
191 .header_type
= IW_HEADER_TYPE_PARAM
,
193 [SIOCGIWTXPOW
- SIOCIWFIRST
] = {
194 .header_type
= IW_HEADER_TYPE_PARAM
,
196 [SIOCSIWRETRY
- SIOCIWFIRST
] = {
197 .header_type
= IW_HEADER_TYPE_PARAM
,
199 [SIOCGIWRETRY
- SIOCIWFIRST
] = {
200 .header_type
= IW_HEADER_TYPE_PARAM
,
202 [SIOCSIWENCODE
- SIOCIWFIRST
] = {
203 .header_type
= IW_HEADER_TYPE_POINT
,
205 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
206 .flags
= IW_DESCR_FLAG_EVENT
| IW_DESCR_FLAG_RESTRICT
,
208 [SIOCGIWENCODE
- SIOCIWFIRST
] = {
209 .header_type
= IW_HEADER_TYPE_POINT
,
211 .max_tokens
= IW_ENCODING_TOKEN_MAX
,
212 .flags
= IW_DESCR_FLAG_DUMP
| IW_DESCR_FLAG_RESTRICT
,
214 [SIOCSIWPOWER
- SIOCIWFIRST
] = {
215 .header_type
= IW_HEADER_TYPE_PARAM
,
217 [SIOCGIWPOWER
- SIOCIWFIRST
] = {
218 .header_type
= IW_HEADER_TYPE_PARAM
,
220 [SIOCSIWGENIE
- SIOCIWFIRST
] = {
221 .header_type
= IW_HEADER_TYPE_POINT
,
223 .max_tokens
= IW_GENERIC_IE_MAX
,
225 [SIOCGIWGENIE
- SIOCIWFIRST
] = {
226 .header_type
= IW_HEADER_TYPE_POINT
,
228 .max_tokens
= IW_GENERIC_IE_MAX
,
230 [SIOCSIWAUTH
- SIOCIWFIRST
] = {
231 .header_type
= IW_HEADER_TYPE_PARAM
,
233 [SIOCGIWAUTH
- SIOCIWFIRST
] = {
234 .header_type
= IW_HEADER_TYPE_PARAM
,
236 [SIOCSIWENCODEEXT
- SIOCIWFIRST
] = {
237 .header_type
= IW_HEADER_TYPE_POINT
,
239 .min_tokens
= sizeof(struct iw_encode_ext
),
240 .max_tokens
= sizeof(struct iw_encode_ext
) +
241 IW_ENCODING_TOKEN_MAX
,
243 [SIOCGIWENCODEEXT
- SIOCIWFIRST
] = {
244 .header_type
= IW_HEADER_TYPE_POINT
,
246 .min_tokens
= sizeof(struct iw_encode_ext
),
247 .max_tokens
= sizeof(struct iw_encode_ext
) +
248 IW_ENCODING_TOKEN_MAX
,
250 [SIOCSIWPMKSA
- SIOCIWFIRST
] = {
251 .header_type
= IW_HEADER_TYPE_POINT
,
253 .min_tokens
= sizeof(struct iw_pmksa
),
254 .max_tokens
= sizeof(struct iw_pmksa
),
257 static const unsigned standard_ioctl_num
= ARRAY_SIZE(standard_ioctl
);
260 * Meta-data about all the additional standard Wireless Extension events
263 static const struct iw_ioctl_description standard_event
[] = {
264 [IWEVTXDROP
- IWEVFIRST
] = {
265 .header_type
= IW_HEADER_TYPE_ADDR
,
267 [IWEVQUAL
- IWEVFIRST
] = {
268 .header_type
= IW_HEADER_TYPE_QUAL
,
270 [IWEVCUSTOM
- IWEVFIRST
] = {
271 .header_type
= IW_HEADER_TYPE_POINT
,
273 .max_tokens
= IW_CUSTOM_MAX
,
275 [IWEVREGISTERED
- IWEVFIRST
] = {
276 .header_type
= IW_HEADER_TYPE_ADDR
,
278 [IWEVEXPIRED
- IWEVFIRST
] = {
279 .header_type
= IW_HEADER_TYPE_ADDR
,
281 [IWEVGENIE
- IWEVFIRST
] = {
282 .header_type
= IW_HEADER_TYPE_POINT
,
284 .max_tokens
= IW_GENERIC_IE_MAX
,
286 [IWEVMICHAELMICFAILURE
- IWEVFIRST
] = {
287 .header_type
= IW_HEADER_TYPE_POINT
,
289 .max_tokens
= sizeof(struct iw_michaelmicfailure
),
291 [IWEVASSOCREQIE
- IWEVFIRST
] = {
292 .header_type
= IW_HEADER_TYPE_POINT
,
294 .max_tokens
= IW_GENERIC_IE_MAX
,
296 [IWEVASSOCRESPIE
- IWEVFIRST
] = {
297 .header_type
= IW_HEADER_TYPE_POINT
,
299 .max_tokens
= IW_GENERIC_IE_MAX
,
301 [IWEVPMKIDCAND
- IWEVFIRST
] = {
302 .header_type
= IW_HEADER_TYPE_POINT
,
304 .max_tokens
= sizeof(struct iw_pmkid_cand
),
307 static const unsigned standard_event_num
= ARRAY_SIZE(standard_event
);
309 /* Size (in bytes) of various events */
310 static const int event_type_size
[] = {
311 IW_EV_LCP_LEN
, /* IW_HEADER_TYPE_NULL */
313 IW_EV_CHAR_LEN
, /* IW_HEADER_TYPE_CHAR */
315 IW_EV_UINT_LEN
, /* IW_HEADER_TYPE_UINT */
316 IW_EV_FREQ_LEN
, /* IW_HEADER_TYPE_FREQ */
317 IW_EV_ADDR_LEN
, /* IW_HEADER_TYPE_ADDR */
319 IW_EV_POINT_LEN
, /* Without variable payload */
320 IW_EV_PARAM_LEN
, /* IW_HEADER_TYPE_PARAM */
321 IW_EV_QUAL_LEN
, /* IW_HEADER_TYPE_QUAL */
325 static const int compat_event_type_size
[] = {
326 IW_EV_COMPAT_LCP_LEN
, /* IW_HEADER_TYPE_NULL */
328 IW_EV_COMPAT_CHAR_LEN
, /* IW_HEADER_TYPE_CHAR */
330 IW_EV_COMPAT_UINT_LEN
, /* IW_HEADER_TYPE_UINT */
331 IW_EV_COMPAT_FREQ_LEN
, /* IW_HEADER_TYPE_FREQ */
332 IW_EV_COMPAT_ADDR_LEN
, /* IW_HEADER_TYPE_ADDR */
334 IW_EV_COMPAT_POINT_LEN
, /* Without variable payload */
335 IW_EV_COMPAT_PARAM_LEN
, /* IW_HEADER_TYPE_PARAM */
336 IW_EV_COMPAT_QUAL_LEN
, /* IW_HEADER_TYPE_QUAL */
343 static int __net_init
wext_pernet_init(struct net
*net
)
345 skb_queue_head_init(&net
->wext_nlevents
);
349 static void __net_exit
wext_pernet_exit(struct net
*net
)
351 skb_queue_purge(&net
->wext_nlevents
);
354 static struct pernet_operations wext_pernet_ops
= {
355 .init
= wext_pernet_init
,
356 .exit
= wext_pernet_exit
,
359 static int __init
wireless_nlevent_init(void)
361 return register_pernet_subsys(&wext_pernet_ops
);
364 subsys_initcall(wireless_nlevent_init
);
366 /* Process events generated by the wireless layer or the driver. */
367 static void wireless_nlevent_process(struct work_struct
*work
)
375 while ((skb
= skb_dequeue(&net
->wext_nlevents
)))
376 rtnl_notify(skb
, net
, 0, RTNLGRP_LINK
, NULL
,
383 static DECLARE_WORK(wireless_nlevent_work
, wireless_nlevent_process
);
385 static struct nlmsghdr
*rtnetlink_ifinfo_prep(struct net_device
*dev
,
389 struct nlmsghdr
*nlh
;
391 nlh
= nlmsg_put(skb
, 0, 0, RTM_NEWLINK
, sizeof(*r
), 0);
396 r
->ifi_family
= AF_UNSPEC
;
398 r
->ifi_type
= dev
->type
;
399 r
->ifi_index
= dev
->ifindex
;
400 r
->ifi_flags
= dev_get_flags(dev
);
401 r
->ifi_change
= 0; /* Wireless changes don't affect those flags */
403 NLA_PUT_STRING(skb
, IFLA_IFNAME
, dev
->name
);
407 nlmsg_cancel(skb
, nlh
);
413 * Main event dispatcher. Called from other parts and drivers.
414 * Send the event on the appropriate channels.
415 * May be called from interrupt context.
417 void wireless_send_event(struct net_device
* dev
,
419 union iwreq_data
* wrqu
,
422 const struct iw_ioctl_description
* descr
= NULL
;
424 struct iw_event
*event
; /* Mallocated whole event */
425 int event_len
; /* Its size */
426 int hdr_len
; /* Size of the event header */
427 int wrqu_off
= 0; /* Offset in wrqu */
428 /* Don't "optimise" the following variable, it will crash */
429 unsigned cmd_index
; /* *MUST* be unsigned */
431 struct nlmsghdr
*nlh
;
434 struct __compat_iw_event
*compat_event
;
435 struct compat_iw_point compat_wrqu
;
436 struct sk_buff
*compskb
;
440 * Nothing in the kernel sends scan events with data, be safe.
441 * This is necessary because we cannot fix up scan event data
442 * for compat, due to being contained in 'extra', but normally
443 * applications are required to retrieve the scan data anyway
444 * and no data is included in the event, this codifies that
447 if (WARN_ON(cmd
== SIOCGIWSCAN
&& extra
))
450 /* Get the description of the Event */
451 if (cmd
<= SIOCIWLAST
) {
452 cmd_index
= cmd
- SIOCIWFIRST
;
453 if (cmd_index
< standard_ioctl_num
)
454 descr
= &(standard_ioctl
[cmd_index
]);
456 cmd_index
= cmd
- IWEVFIRST
;
457 if (cmd_index
< standard_event_num
)
458 descr
= &(standard_event
[cmd_index
]);
460 /* Don't accept unknown events */
462 /* Note : we don't return an error to the driver, because
463 * the driver would not know what to do about it. It can't
464 * return an error to the user, because the event is not
465 * initiated by a user request.
466 * The best the driver could do is to log an error message.
467 * We will do it ourselves instead...
469 printk(KERN_ERR
"%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
474 /* Check extra parameters and set extra_len */
475 if (descr
->header_type
== IW_HEADER_TYPE_POINT
) {
476 /* Check if number of token fits within bounds */
477 if (wrqu
->data
.length
> descr
->max_tokens
) {
478 printk(KERN_ERR
"%s (WE) : Wireless Event too big (%d)\n", dev
->name
, wrqu
->data
.length
);
481 if (wrqu
->data
.length
< descr
->min_tokens
) {
482 printk(KERN_ERR
"%s (WE) : Wireless Event too small (%d)\n", dev
->name
, wrqu
->data
.length
);
485 /* Calculate extra_len - extra is NULL for restricted events */
487 extra_len
= wrqu
->data
.length
* descr
->token_size
;
488 /* Always at an offset in wrqu */
489 wrqu_off
= IW_EV_POINT_OFF
;
492 /* Total length of the event */
493 hdr_len
= event_type_size
[descr
->header_type
];
494 event_len
= hdr_len
+ extra_len
;
497 * The problem for 64/32 bit.
499 * On 64-bit, a regular event is laid out as follows:
500 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
501 * | event.len | event.cmd | p a d d i n g |
502 * | wrqu data ... (with the correct size) |
504 * This padding exists because we manipulate event->u,
505 * and 'event' is not packed.
507 * An iw_point event is laid out like this instead:
508 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
509 * | event.len | event.cmd | p a d d i n g |
510 * | iwpnt.len | iwpnt.flg | p a d d i n g |
513 * The second padding exists because struct iw_point is extended,
514 * but this depends on the platform...
516 * On 32-bit, all the padding shouldn't be there.
519 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
523 /* Send via the RtNetlink event channel */
524 nlh
= rtnetlink_ifinfo_prep(dev
, skb
);
530 /* Add the wireless events in the netlink packet */
531 nla
= nla_reserve(skb
, IFLA_WIRELESS
, event_len
);
536 event
= nla_data(nla
);
538 /* Fill event - first clear to avoid data leaking */
539 memset(event
, 0, hdr_len
);
540 event
->len
= event_len
;
542 memcpy(&event
->u
, ((char *) wrqu
) + wrqu_off
, hdr_len
- IW_EV_LCP_LEN
);
544 memcpy(((char *) event
) + hdr_len
, extra
, extra_len
);
548 hdr_len
= compat_event_type_size
[descr
->header_type
];
549 event_len
= hdr_len
+ extra_len
;
551 compskb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
557 /* Send via the RtNetlink event channel */
558 nlh
= rtnetlink_ifinfo_prep(dev
, compskb
);
565 /* Add the wireless events in the netlink packet */
566 nla
= nla_reserve(compskb
, IFLA_WIRELESS
, event_len
);
572 compat_event
= nla_data(nla
);
574 compat_event
->len
= event_len
;
575 compat_event
->cmd
= cmd
;
576 if (descr
->header_type
== IW_HEADER_TYPE_POINT
) {
577 compat_wrqu
.length
= wrqu
->data
.length
;
578 compat_wrqu
.flags
= wrqu
->data
.flags
;
579 memcpy(&compat_event
->pointer
,
580 ((char *) &compat_wrqu
) + IW_EV_COMPAT_POINT_OFF
,
581 hdr_len
- IW_EV_COMPAT_LCP_LEN
);
583 memcpy(((char *) compat_event
) + hdr_len
,
586 /* extra_len must be zero, so no if (extra) needed */
587 memcpy(&compat_event
->pointer
, wrqu
,
588 hdr_len
- IW_EV_COMPAT_LCP_LEN
);
591 nlmsg_end(compskb
, nlh
);
593 skb_shinfo(skb
)->frag_list
= compskb
;
595 skb_queue_tail(&dev_net(dev
)->wext_nlevents
, skb
);
596 schedule_work(&wireless_nlevent_work
);
598 EXPORT_SYMBOL(wireless_send_event
);
604 struct iw_statistics
*get_wireless_stats(struct net_device
*dev
)
606 #ifdef CONFIG_WIRELESS_EXT
607 if ((dev
->wireless_handlers
!= NULL
) &&
608 (dev
->wireless_handlers
->get_wireless_stats
!= NULL
))
609 return dev
->wireless_handlers
->get_wireless_stats(dev
);
612 #ifdef CONFIG_CFG80211_WEXT
613 if (dev
->ieee80211_ptr
&& dev
->ieee80211_ptr
&&
614 dev
->ieee80211_ptr
->wiphy
&&
615 dev
->ieee80211_ptr
->wiphy
->wext
&&
616 dev
->ieee80211_ptr
->wiphy
->wext
->get_wireless_stats
)
617 return dev
->ieee80211_ptr
->wiphy
->wext
->get_wireless_stats(dev
);
624 static int iw_handler_get_iwstats(struct net_device
* dev
,
625 struct iw_request_info
* info
,
626 union iwreq_data
* wrqu
,
629 /* Get stats from the driver */
630 struct iw_statistics
*stats
;
632 stats
= get_wireless_stats(dev
);
634 /* Copy statistics to extra */
635 memcpy(extra
, stats
, sizeof(struct iw_statistics
));
636 wrqu
->data
.length
= sizeof(struct iw_statistics
);
638 /* Check if we need to clear the updated flag */
639 if (wrqu
->data
.flags
!= 0)
640 stats
->qual
.updated
&= ~IW_QUAL_ALL_UPDATED
;
646 static iw_handler
get_handler(struct net_device
*dev
, unsigned int cmd
)
648 /* Don't "optimise" the following variable, it will crash */
649 unsigned int index
; /* *MUST* be unsigned */
650 const struct iw_handler_def
*handlers
= NULL
;
652 #ifdef CONFIG_CFG80211_WEXT
653 if (dev
->ieee80211_ptr
&& dev
->ieee80211_ptr
->wiphy
)
654 handlers
= dev
->ieee80211_ptr
->wiphy
->wext
;
656 #ifdef CONFIG_WIRELESS_EXT
657 if (dev
->wireless_handlers
)
658 handlers
= dev
->wireless_handlers
;
664 /* Try as a standard command */
665 index
= cmd
- SIOCIWFIRST
;
666 if (index
< handlers
->num_standard
)
667 return handlers
->standard
[index
];
669 #ifdef CONFIG_WEXT_PRIV
670 /* Try as a private command */
671 index
= cmd
- SIOCIWFIRSTPRIV
;
672 if (index
< handlers
->num_private
)
673 return handlers
->private[index
];
680 static int ioctl_standard_iw_point(struct iw_point
*iwp
, unsigned int cmd
,
681 const struct iw_ioctl_description
*descr
,
682 iw_handler handler
, struct net_device
*dev
,
683 struct iw_request_info
*info
)
685 int err
, extra_size
, user_length
= 0, essid_compat
= 0;
688 /* Calculate space needed by arguments. Always allocate
691 extra_size
= descr
->max_tokens
* descr
->token_size
;
693 /* Check need for ESSID compatibility for WE < 21 */
699 if (iwp
->length
== descr
->max_tokens
+ 1)
701 else if (IW_IS_SET(cmd
) && (iwp
->length
!= 0)) {
702 char essid
[IW_ESSID_MAX_SIZE
+ 1];
704 len
= iwp
->length
* descr
->token_size
;
706 if (len
> IW_ESSID_MAX_SIZE
)
709 err
= copy_from_user(essid
, iwp
->pointer
, len
);
713 if (essid
[iwp
->length
- 1] == '\0')
721 iwp
->length
-= essid_compat
;
723 /* Check what user space is giving us */
724 if (IW_IS_SET(cmd
)) {
725 /* Check NULL pointer */
726 if (!iwp
->pointer
&& iwp
->length
!= 0)
728 /* Check if number of token fits within bounds */
729 if (iwp
->length
> descr
->max_tokens
)
731 if (iwp
->length
< descr
->min_tokens
)
734 /* Check NULL pointer */
737 /* Save user space buffer size for checking */
738 user_length
= iwp
->length
;
740 /* Don't check if user_length > max to allow forward
741 * compatibility. The test user_length < min is
742 * implied by the test at the end.
745 /* Support for very large requests */
746 if ((descr
->flags
& IW_DESCR_FLAG_NOMAX
) &&
747 (user_length
> descr
->max_tokens
)) {
748 /* Allow userspace to GET more than max so
749 * we can support any size GET requests.
750 * There is still a limit : -ENOMEM.
752 extra_size
= user_length
* descr
->token_size
;
754 /* Note : user_length is originally a __u16,
755 * and token_size is controlled by us,
756 * so extra_size won't get negative and
762 /* kzalloc() ensures NULL-termination for essid_compat. */
763 extra
= kzalloc(extra_size
, GFP_KERNEL
);
767 /* If it is a SET, get all the extra data in here */
768 if (IW_IS_SET(cmd
) && (iwp
->length
!= 0)) {
769 if (copy_from_user(extra
, iwp
->pointer
,
771 descr
->token_size
)) {
776 if (cmd
== SIOCSIWENCODEEXT
) {
777 struct iw_encode_ext
*ee
= (void *) extra
;
779 if (iwp
->length
< sizeof(*ee
) + ee
->key_len
)
784 err
= handler(dev
, info
, (union iwreq_data
*) iwp
, extra
);
786 iwp
->length
+= essid_compat
;
788 /* If we have something to return to the user */
789 if (!err
&& IW_IS_GET(cmd
)) {
790 /* Check if there is enough buffer up there */
791 if (user_length
< iwp
->length
) {
796 if (copy_to_user(iwp
->pointer
, extra
,
798 descr
->token_size
)) {
804 /* Generate an event to notify listeners of the change */
805 if ((descr
->flags
& IW_DESCR_FLAG_EVENT
) && err
== -EIWCOMMIT
) {
806 union iwreq_data
*data
= (union iwreq_data
*) iwp
;
808 if (descr
->flags
& IW_DESCR_FLAG_RESTRICT
)
809 /* If the event is restricted, don't
810 * export the payload.
812 wireless_send_event(dev
, cmd
, data
, NULL
);
814 wireless_send_event(dev
, cmd
, data
, extra
);
823 * Call the commit handler in the driver
824 * (if exist and if conditions are right)
826 * Note : our current commit strategy is currently pretty dumb,
827 * but we will be able to improve on that...
828 * The goal is to try to agreagate as many changes as possible
829 * before doing the commit. Drivers that will define a commit handler
830 * are usually those that need a reset after changing parameters, so
831 * we want to minimise the number of reset.
832 * A cool idea is to use a timer : at each "set" command, we re-set the
833 * timer, when the timer eventually fires, we call the driver.
834 * Hopefully, more on that later.
836 * Also, I'm waiting to see how many people will complain about the
837 * netif_running(dev) test. I'm open on that one...
838 * Hopefully, the driver will remember to do a commit in "open()" ;-)
840 int call_commit_handler(struct net_device
*dev
)
842 #ifdef CONFIG_WIRELESS_EXT
843 if ((netif_running(dev
)) &&
844 (dev
->wireless_handlers
->standard
[0] != NULL
))
845 /* Call the commit handler on the driver */
846 return dev
->wireless_handlers
->standard
[0](dev
, NULL
,
849 return 0; /* Command completed successfully */
851 /* cfg80211 has no commit */
857 * Main IOCTl dispatcher.
858 * Check the type of IOCTL and call the appropriate wrapper...
860 static int wireless_process_ioctl(struct net
*net
, struct ifreq
*ifr
,
862 struct iw_request_info
*info
,
863 wext_ioctl_func standard
,
864 wext_ioctl_func
private)
866 struct iwreq
*iwr
= (struct iwreq
*) ifr
;
867 struct net_device
*dev
;
870 /* Permissions are already checked in dev_ioctl() before calling us.
871 * The copy_to/from_user() of ifr is also dealt with in there */
873 /* Make sure the device exist */
874 if ((dev
= __dev_get_by_name(net
, ifr
->ifr_name
)) == NULL
)
877 /* A bunch of special cases, then the generic case...
878 * Note that 'cmd' is already filtered in dev_ioctl() with
879 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
880 if (cmd
== SIOCGIWSTATS
)
881 return standard(dev
, iwr
, cmd
, info
,
882 &iw_handler_get_iwstats
);
884 #ifdef CONFIG_WEXT_PRIV
885 if (cmd
== SIOCGIWPRIV
&& dev
->wireless_handlers
)
886 return standard(dev
, iwr
, cmd
, info
,
887 iw_handler_get_private
);
891 if (!netif_device_present(dev
))
894 /* New driver API : try to find the handler */
895 handler
= get_handler(dev
, cmd
);
897 /* Standard and private are not the same */
898 if (cmd
< SIOCIWFIRSTPRIV
)
899 return standard(dev
, iwr
, cmd
, info
, handler
);
901 return private(dev
, iwr
, cmd
, info
, handler
);
903 /* Old driver API : call driver ioctl handler */
904 if (dev
->netdev_ops
->ndo_do_ioctl
)
905 return dev
->netdev_ops
->ndo_do_ioctl(dev
, ifr
, cmd
);
909 /* If command is `set a parameter', or `get the encoding parameters',
910 * check if the user has the right to do it.
912 static int wext_permission_check(unsigned int cmd
)
914 if ((IW_IS_SET(cmd
) || cmd
== SIOCGIWENCODE
|| cmd
== SIOCGIWENCODEEXT
)
915 && !capable(CAP_NET_ADMIN
))
921 /* entry point from dev ioctl */
922 static int wext_ioctl_dispatch(struct net
*net
, struct ifreq
*ifr
,
923 unsigned int cmd
, struct iw_request_info
*info
,
924 wext_ioctl_func standard
,
925 wext_ioctl_func
private)
927 int ret
= wext_permission_check(cmd
);
932 dev_load(net
, ifr
->ifr_name
);
934 ret
= wireless_process_ioctl(net
, ifr
, cmd
, info
, standard
, private);
941 * Wrapper to call a standard Wireless Extension handler.
942 * We do various checks and also take care of moving data between
943 * user space and kernel space.
945 static int ioctl_standard_call(struct net_device
* dev
,
948 struct iw_request_info
*info
,
951 const struct iw_ioctl_description
* descr
;
954 /* Get the description of the IOCTL */
955 if ((cmd
- SIOCIWFIRST
) >= standard_ioctl_num
)
957 descr
= &(standard_ioctl
[cmd
- SIOCIWFIRST
]);
959 /* Check if we have a pointer to user space data or not */
960 if (descr
->header_type
!= IW_HEADER_TYPE_POINT
) {
962 /* No extra arguments. Trivial to handle */
963 ret
= handler(dev
, info
, &(iwr
->u
), NULL
);
965 /* Generate an event to notify listeners of the change */
966 if ((descr
->flags
& IW_DESCR_FLAG_EVENT
) &&
967 ((ret
== 0) || (ret
== -EIWCOMMIT
)))
968 wireless_send_event(dev
, cmd
, &(iwr
->u
), NULL
);
970 ret
= ioctl_standard_iw_point(&iwr
->u
.data
, cmd
, descr
,
974 /* Call commit handler if needed and defined */
975 if (ret
== -EIWCOMMIT
)
976 ret
= call_commit_handler(dev
);
978 /* Here, we will generate the appropriate event if needed */
984 int wext_handle_ioctl(struct net
*net
, struct ifreq
*ifr
, unsigned int cmd
,
987 struct iw_request_info info
= { .cmd
= cmd
, .flags
= 0 };
990 ret
= wext_ioctl_dispatch(net
, ifr
, cmd
, &info
,
995 copy_to_user(arg
, ifr
, sizeof(struct iwreq
)))
1001 #ifdef CONFIG_COMPAT
1002 static int compat_standard_call(struct net_device
*dev
,
1005 struct iw_request_info
*info
,
1008 const struct iw_ioctl_description
*descr
;
1009 struct compat_iw_point
*iwp_compat
;
1010 struct iw_point iwp
;
1013 descr
= standard_ioctl
+ (cmd
- SIOCIWFIRST
);
1015 if (descr
->header_type
!= IW_HEADER_TYPE_POINT
)
1016 return ioctl_standard_call(dev
, iwr
, cmd
, info
, handler
);
1018 iwp_compat
= (struct compat_iw_point
*) &iwr
->u
.data
;
1019 iwp
.pointer
= compat_ptr(iwp_compat
->pointer
);
1020 iwp
.length
= iwp_compat
->length
;
1021 iwp
.flags
= iwp_compat
->flags
;
1023 err
= ioctl_standard_iw_point(&iwp
, cmd
, descr
, handler
, dev
, info
);
1025 iwp_compat
->pointer
= ptr_to_compat(iwp
.pointer
);
1026 iwp_compat
->length
= iwp
.length
;
1027 iwp_compat
->flags
= iwp
.flags
;
1032 int compat_wext_handle_ioctl(struct net
*net
, unsigned int cmd
,
1035 void __user
*argp
= (void __user
*)arg
;
1036 struct iw_request_info info
;
1041 if (copy_from_user(&iwr
, argp
, sizeof(struct iwreq
)))
1044 iwr
.ifr_name
[IFNAMSIZ
-1] = 0;
1045 colon
= strchr(iwr
.ifr_name
, ':');
1050 info
.flags
= IW_REQUEST_FLAG_COMPAT
;
1052 ret
= wext_ioctl_dispatch(net
, (struct ifreq
*) &iwr
, cmd
, &info
,
1053 compat_standard_call
,
1054 compat_private_call
);
1058 copy_to_user(argp
, &iwr
, sizeof(struct iwreq
)))