blob: 9f544c95171ce35b79f3ef0ae8fbf98b8785bb49 [file] [log] [blame]
Johannes Berg3d23e342009-09-29 23:27:28 +02001/*
2 * This file implement the Wireless Extensions core API.
3 *
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>
7 *
8 * (As all part of the Linux kernel, this file is GPL)
9 */
10#include <linux/kernel.h>
11#include <linux/netdevice.h>
12#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Johannes Berg3d23e342009-09-29 23:27:28 +020014#include <linux/wireless.h>
15#include <linux/uaccess.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040016#include <linux/export.h>
Johannes Berg3d23e342009-09-29 23:27:28 +020017#include <net/cfg80211.h>
18#include <net/iw_handler.h>
19#include <net/netlink.h>
20#include <net/wext.h>
21#include <net/net_namespace.h>
22
23typedef int (*wext_ioctl_func)(struct net_device *, struct iwreq *,
24 unsigned int, struct iw_request_info *,
25 iw_handler);
26
27
28/*
29 * Meta-data about all the standard Wireless Extension request we
30 * know about.
31 */
32static const struct iw_ioctl_description standard_ioctl[] = {
Joe Perches44608f82010-03-18 18:29:35 -070033 [IW_IOCTL_IDX(SIOCSIWCOMMIT)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020034 .header_type = IW_HEADER_TYPE_NULL,
35 },
Joe Perches44608f82010-03-18 18:29:35 -070036 [IW_IOCTL_IDX(SIOCGIWNAME)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020037 .header_type = IW_HEADER_TYPE_CHAR,
38 .flags = IW_DESCR_FLAG_DUMP,
39 },
Joe Perches44608f82010-03-18 18:29:35 -070040 [IW_IOCTL_IDX(SIOCSIWNWID)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020041 .header_type = IW_HEADER_TYPE_PARAM,
42 .flags = IW_DESCR_FLAG_EVENT,
43 },
Joe Perches44608f82010-03-18 18:29:35 -070044 [IW_IOCTL_IDX(SIOCGIWNWID)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020045 .header_type = IW_HEADER_TYPE_PARAM,
46 .flags = IW_DESCR_FLAG_DUMP,
47 },
Joe Perches44608f82010-03-18 18:29:35 -070048 [IW_IOCTL_IDX(SIOCSIWFREQ)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020049 .header_type = IW_HEADER_TYPE_FREQ,
50 .flags = IW_DESCR_FLAG_EVENT,
51 },
Joe Perches44608f82010-03-18 18:29:35 -070052 [IW_IOCTL_IDX(SIOCGIWFREQ)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020053 .header_type = IW_HEADER_TYPE_FREQ,
54 .flags = IW_DESCR_FLAG_DUMP,
55 },
Joe Perches44608f82010-03-18 18:29:35 -070056 [IW_IOCTL_IDX(SIOCSIWMODE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020057 .header_type = IW_HEADER_TYPE_UINT,
58 .flags = IW_DESCR_FLAG_EVENT,
59 },
Joe Perches44608f82010-03-18 18:29:35 -070060 [IW_IOCTL_IDX(SIOCGIWMODE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020061 .header_type = IW_HEADER_TYPE_UINT,
62 .flags = IW_DESCR_FLAG_DUMP,
63 },
Joe Perches44608f82010-03-18 18:29:35 -070064 [IW_IOCTL_IDX(SIOCSIWSENS)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020065 .header_type = IW_HEADER_TYPE_PARAM,
66 },
Joe Perches44608f82010-03-18 18:29:35 -070067 [IW_IOCTL_IDX(SIOCGIWSENS)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020068 .header_type = IW_HEADER_TYPE_PARAM,
69 },
Joe Perches44608f82010-03-18 18:29:35 -070070 [IW_IOCTL_IDX(SIOCSIWRANGE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020071 .header_type = IW_HEADER_TYPE_NULL,
72 },
Joe Perches44608f82010-03-18 18:29:35 -070073 [IW_IOCTL_IDX(SIOCGIWRANGE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020074 .header_type = IW_HEADER_TYPE_POINT,
75 .token_size = 1,
76 .max_tokens = sizeof(struct iw_range),
77 .flags = IW_DESCR_FLAG_DUMP,
78 },
Joe Perches44608f82010-03-18 18:29:35 -070079 [IW_IOCTL_IDX(SIOCSIWPRIV)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020080 .header_type = IW_HEADER_TYPE_NULL,
81 },
Joe Perches44608f82010-03-18 18:29:35 -070082 [IW_IOCTL_IDX(SIOCGIWPRIV)] = { /* (handled directly by us) */
Johannes Berg3d23e342009-09-29 23:27:28 +020083 .header_type = IW_HEADER_TYPE_POINT,
84 .token_size = sizeof(struct iw_priv_args),
85 .max_tokens = 16,
86 .flags = IW_DESCR_FLAG_NOMAX,
87 },
Joe Perches44608f82010-03-18 18:29:35 -070088 [IW_IOCTL_IDX(SIOCSIWSTATS)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020089 .header_type = IW_HEADER_TYPE_NULL,
90 },
Joe Perches44608f82010-03-18 18:29:35 -070091 [IW_IOCTL_IDX(SIOCGIWSTATS)] = { /* (handled directly by us) */
Johannes Berg3d23e342009-09-29 23:27:28 +020092 .header_type = IW_HEADER_TYPE_POINT,
93 .token_size = 1,
94 .max_tokens = sizeof(struct iw_statistics),
95 .flags = IW_DESCR_FLAG_DUMP,
96 },
Joe Perches44608f82010-03-18 18:29:35 -070097 [IW_IOCTL_IDX(SIOCSIWSPY)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +020098 .header_type = IW_HEADER_TYPE_POINT,
99 .token_size = sizeof(struct sockaddr),
100 .max_tokens = IW_MAX_SPY,
101 },
Joe Perches44608f82010-03-18 18:29:35 -0700102 [IW_IOCTL_IDX(SIOCGIWSPY)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200103 .header_type = IW_HEADER_TYPE_POINT,
104 .token_size = sizeof(struct sockaddr) +
105 sizeof(struct iw_quality),
106 .max_tokens = IW_MAX_SPY,
107 },
Joe Perches44608f82010-03-18 18:29:35 -0700108 [IW_IOCTL_IDX(SIOCSIWTHRSPY)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200109 .header_type = IW_HEADER_TYPE_POINT,
110 .token_size = sizeof(struct iw_thrspy),
111 .min_tokens = 1,
112 .max_tokens = 1,
113 },
Joe Perches44608f82010-03-18 18:29:35 -0700114 [IW_IOCTL_IDX(SIOCGIWTHRSPY)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200115 .header_type = IW_HEADER_TYPE_POINT,
116 .token_size = sizeof(struct iw_thrspy),
117 .min_tokens = 1,
118 .max_tokens = 1,
119 },
Joe Perches44608f82010-03-18 18:29:35 -0700120 [IW_IOCTL_IDX(SIOCSIWAP)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200121 .header_type = IW_HEADER_TYPE_ADDR,
122 },
Joe Perches44608f82010-03-18 18:29:35 -0700123 [IW_IOCTL_IDX(SIOCGIWAP)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200124 .header_type = IW_HEADER_TYPE_ADDR,
125 .flags = IW_DESCR_FLAG_DUMP,
126 },
Joe Perches44608f82010-03-18 18:29:35 -0700127 [IW_IOCTL_IDX(SIOCSIWMLME)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200128 .header_type = IW_HEADER_TYPE_POINT,
129 .token_size = 1,
130 .min_tokens = sizeof(struct iw_mlme),
131 .max_tokens = sizeof(struct iw_mlme),
132 },
Joe Perches44608f82010-03-18 18:29:35 -0700133 [IW_IOCTL_IDX(SIOCGIWAPLIST)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200134 .header_type = IW_HEADER_TYPE_POINT,
135 .token_size = sizeof(struct sockaddr) +
136 sizeof(struct iw_quality),
137 .max_tokens = IW_MAX_AP,
138 .flags = IW_DESCR_FLAG_NOMAX,
139 },
Joe Perches44608f82010-03-18 18:29:35 -0700140 [IW_IOCTL_IDX(SIOCSIWSCAN)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200141 .header_type = IW_HEADER_TYPE_POINT,
142 .token_size = 1,
143 .min_tokens = 0,
144 .max_tokens = sizeof(struct iw_scan_req),
145 },
Joe Perches44608f82010-03-18 18:29:35 -0700146 [IW_IOCTL_IDX(SIOCGIWSCAN)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200147 .header_type = IW_HEADER_TYPE_POINT,
148 .token_size = 1,
149 .max_tokens = IW_SCAN_MAX_DATA,
150 .flags = IW_DESCR_FLAG_NOMAX,
151 },
Joe Perches44608f82010-03-18 18:29:35 -0700152 [IW_IOCTL_IDX(SIOCSIWESSID)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200153 .header_type = IW_HEADER_TYPE_POINT,
154 .token_size = 1,
155 .max_tokens = IW_ESSID_MAX_SIZE,
156 .flags = IW_DESCR_FLAG_EVENT,
157 },
Joe Perches44608f82010-03-18 18:29:35 -0700158 [IW_IOCTL_IDX(SIOCGIWESSID)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200159 .header_type = IW_HEADER_TYPE_POINT,
160 .token_size = 1,
161 .max_tokens = IW_ESSID_MAX_SIZE,
162 .flags = IW_DESCR_FLAG_DUMP,
163 },
Joe Perches44608f82010-03-18 18:29:35 -0700164 [IW_IOCTL_IDX(SIOCSIWNICKN)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200165 .header_type = IW_HEADER_TYPE_POINT,
166 .token_size = 1,
167 .max_tokens = IW_ESSID_MAX_SIZE,
168 },
Joe Perches44608f82010-03-18 18:29:35 -0700169 [IW_IOCTL_IDX(SIOCGIWNICKN)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200170 .header_type = IW_HEADER_TYPE_POINT,
171 .token_size = 1,
172 .max_tokens = IW_ESSID_MAX_SIZE,
173 },
Joe Perches44608f82010-03-18 18:29:35 -0700174 [IW_IOCTL_IDX(SIOCSIWRATE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200175 .header_type = IW_HEADER_TYPE_PARAM,
176 },
Joe Perches44608f82010-03-18 18:29:35 -0700177 [IW_IOCTL_IDX(SIOCGIWRATE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200178 .header_type = IW_HEADER_TYPE_PARAM,
179 },
Joe Perches44608f82010-03-18 18:29:35 -0700180 [IW_IOCTL_IDX(SIOCSIWRTS)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200181 .header_type = IW_HEADER_TYPE_PARAM,
182 },
Joe Perches44608f82010-03-18 18:29:35 -0700183 [IW_IOCTL_IDX(SIOCGIWRTS)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200184 .header_type = IW_HEADER_TYPE_PARAM,
185 },
Joe Perches44608f82010-03-18 18:29:35 -0700186 [IW_IOCTL_IDX(SIOCSIWFRAG)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200187 .header_type = IW_HEADER_TYPE_PARAM,
188 },
Joe Perches44608f82010-03-18 18:29:35 -0700189 [IW_IOCTL_IDX(SIOCGIWFRAG)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200190 .header_type = IW_HEADER_TYPE_PARAM,
191 },
Joe Perches44608f82010-03-18 18:29:35 -0700192 [IW_IOCTL_IDX(SIOCSIWTXPOW)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200193 .header_type = IW_HEADER_TYPE_PARAM,
194 },
Joe Perches44608f82010-03-18 18:29:35 -0700195 [IW_IOCTL_IDX(SIOCGIWTXPOW)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200196 .header_type = IW_HEADER_TYPE_PARAM,
197 },
Joe Perches44608f82010-03-18 18:29:35 -0700198 [IW_IOCTL_IDX(SIOCSIWRETRY)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200199 .header_type = IW_HEADER_TYPE_PARAM,
200 },
Joe Perches44608f82010-03-18 18:29:35 -0700201 [IW_IOCTL_IDX(SIOCGIWRETRY)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200202 .header_type = IW_HEADER_TYPE_PARAM,
203 },
Joe Perches44608f82010-03-18 18:29:35 -0700204 [IW_IOCTL_IDX(SIOCSIWENCODE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200205 .header_type = IW_HEADER_TYPE_POINT,
206 .token_size = 1,
207 .max_tokens = IW_ENCODING_TOKEN_MAX,
208 .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
209 },
Joe Perches44608f82010-03-18 18:29:35 -0700210 [IW_IOCTL_IDX(SIOCGIWENCODE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200211 .header_type = IW_HEADER_TYPE_POINT,
212 .token_size = 1,
213 .max_tokens = IW_ENCODING_TOKEN_MAX,
214 .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
215 },
Joe Perches44608f82010-03-18 18:29:35 -0700216 [IW_IOCTL_IDX(SIOCSIWPOWER)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200217 .header_type = IW_HEADER_TYPE_PARAM,
218 },
Joe Perches44608f82010-03-18 18:29:35 -0700219 [IW_IOCTL_IDX(SIOCGIWPOWER)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200220 .header_type = IW_HEADER_TYPE_PARAM,
221 },
Joe Perches44608f82010-03-18 18:29:35 -0700222 [IW_IOCTL_IDX(SIOCSIWGENIE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200223 .header_type = IW_HEADER_TYPE_POINT,
224 .token_size = 1,
225 .max_tokens = IW_GENERIC_IE_MAX,
226 },
Joe Perches44608f82010-03-18 18:29:35 -0700227 [IW_IOCTL_IDX(SIOCGIWGENIE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200228 .header_type = IW_HEADER_TYPE_POINT,
229 .token_size = 1,
230 .max_tokens = IW_GENERIC_IE_MAX,
231 },
Joe Perches44608f82010-03-18 18:29:35 -0700232 [IW_IOCTL_IDX(SIOCSIWAUTH)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200233 .header_type = IW_HEADER_TYPE_PARAM,
234 },
Joe Perches44608f82010-03-18 18:29:35 -0700235 [IW_IOCTL_IDX(SIOCGIWAUTH)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200236 .header_type = IW_HEADER_TYPE_PARAM,
237 },
Joe Perches44608f82010-03-18 18:29:35 -0700238 [IW_IOCTL_IDX(SIOCSIWENCODEEXT)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200239 .header_type = IW_HEADER_TYPE_POINT,
240 .token_size = 1,
241 .min_tokens = sizeof(struct iw_encode_ext),
242 .max_tokens = sizeof(struct iw_encode_ext) +
243 IW_ENCODING_TOKEN_MAX,
244 },
Joe Perches44608f82010-03-18 18:29:35 -0700245 [IW_IOCTL_IDX(SIOCGIWENCODEEXT)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200246 .header_type = IW_HEADER_TYPE_POINT,
247 .token_size = 1,
248 .min_tokens = sizeof(struct iw_encode_ext),
249 .max_tokens = sizeof(struct iw_encode_ext) +
250 IW_ENCODING_TOKEN_MAX,
251 },
Joe Perches44608f82010-03-18 18:29:35 -0700252 [IW_IOCTL_IDX(SIOCSIWPMKSA)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200253 .header_type = IW_HEADER_TYPE_POINT,
254 .token_size = 1,
255 .min_tokens = sizeof(struct iw_pmksa),
256 .max_tokens = sizeof(struct iw_pmksa),
257 },
258};
259static const unsigned standard_ioctl_num = ARRAY_SIZE(standard_ioctl);
260
261/*
262 * Meta-data about all the additional standard Wireless Extension events
263 * we know about.
264 */
265static const struct iw_ioctl_description standard_event[] = {
Joe Perches76326f12010-03-18 18:29:36 -0700266 [IW_EVENT_IDX(IWEVTXDROP)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200267 .header_type = IW_HEADER_TYPE_ADDR,
268 },
Joe Perches76326f12010-03-18 18:29:36 -0700269 [IW_EVENT_IDX(IWEVQUAL)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200270 .header_type = IW_HEADER_TYPE_QUAL,
271 },
Joe Perches76326f12010-03-18 18:29:36 -0700272 [IW_EVENT_IDX(IWEVCUSTOM)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200273 .header_type = IW_HEADER_TYPE_POINT,
274 .token_size = 1,
275 .max_tokens = IW_CUSTOM_MAX,
276 },
Joe Perches76326f12010-03-18 18:29:36 -0700277 [IW_EVENT_IDX(IWEVREGISTERED)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200278 .header_type = IW_HEADER_TYPE_ADDR,
279 },
Joe Perches76326f12010-03-18 18:29:36 -0700280 [IW_EVENT_IDX(IWEVEXPIRED)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200281 .header_type = IW_HEADER_TYPE_ADDR,
282 },
Joe Perches76326f12010-03-18 18:29:36 -0700283 [IW_EVENT_IDX(IWEVGENIE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200284 .header_type = IW_HEADER_TYPE_POINT,
285 .token_size = 1,
286 .max_tokens = IW_GENERIC_IE_MAX,
287 },
Joe Perches76326f12010-03-18 18:29:36 -0700288 [IW_EVENT_IDX(IWEVMICHAELMICFAILURE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200289 .header_type = IW_HEADER_TYPE_POINT,
290 .token_size = 1,
291 .max_tokens = sizeof(struct iw_michaelmicfailure),
292 },
Joe Perches76326f12010-03-18 18:29:36 -0700293 [IW_EVENT_IDX(IWEVASSOCREQIE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200294 .header_type = IW_HEADER_TYPE_POINT,
295 .token_size = 1,
296 .max_tokens = IW_GENERIC_IE_MAX,
297 },
Joe Perches76326f12010-03-18 18:29:36 -0700298 [IW_EVENT_IDX(IWEVASSOCRESPIE)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200299 .header_type = IW_HEADER_TYPE_POINT,
300 .token_size = 1,
301 .max_tokens = IW_GENERIC_IE_MAX,
302 },
Joe Perches76326f12010-03-18 18:29:36 -0700303 [IW_EVENT_IDX(IWEVPMKIDCAND)] = {
Johannes Berg3d23e342009-09-29 23:27:28 +0200304 .header_type = IW_HEADER_TYPE_POINT,
305 .token_size = 1,
306 .max_tokens = sizeof(struct iw_pmkid_cand),
307 },
308};
309static const unsigned standard_event_num = ARRAY_SIZE(standard_event);
310
311/* Size (in bytes) of various events */
312static const int event_type_size[] = {
313 IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */
314 0,
315 IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
316 0,
317 IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */
318 IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
319 IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
320 0,
321 IW_EV_POINT_LEN, /* Without variable payload */
322 IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
323 IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
324};
325
326#ifdef CONFIG_COMPAT
327static const int compat_event_type_size[] = {
328 IW_EV_COMPAT_LCP_LEN, /* IW_HEADER_TYPE_NULL */
329 0,
330 IW_EV_COMPAT_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */
331 0,
332 IW_EV_COMPAT_UINT_LEN, /* IW_HEADER_TYPE_UINT */
333 IW_EV_COMPAT_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */
334 IW_EV_COMPAT_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */
335 0,
336 IW_EV_COMPAT_POINT_LEN, /* Without variable payload */
337 IW_EV_COMPAT_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */
338 IW_EV_COMPAT_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */
339};
340#endif
341
342
343/* IW event code */
344
345static int __net_init wext_pernet_init(struct net *net)
346{
347 skb_queue_head_init(&net->wext_nlevents);
348 return 0;
349}
350
351static void __net_exit wext_pernet_exit(struct net *net)
352{
353 skb_queue_purge(&net->wext_nlevents);
354}
355
356static struct pernet_operations wext_pernet_ops = {
357 .init = wext_pernet_init,
358 .exit = wext_pernet_exit,
359};
360
361static int __init wireless_nlevent_init(void)
362{
363 return register_pernet_subsys(&wext_pernet_ops);
364}
365
366subsys_initcall(wireless_nlevent_init);
367
368/* Process events generated by the wireless layer or the driver. */
369static void wireless_nlevent_process(struct work_struct *work)
370{
371 struct sk_buff *skb;
372 struct net *net;
373
374 rtnl_lock();
375
376 for_each_net(net) {
377 while ((skb = skb_dequeue(&net->wext_nlevents)))
378 rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL,
379 GFP_KERNEL);
380 }
381
382 rtnl_unlock();
383}
384
385static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process);
386
387static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev,
388 struct sk_buff *skb)
389{
390 struct ifinfomsg *r;
391 struct nlmsghdr *nlh;
392
393 nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*r), 0);
394 if (!nlh)
395 return NULL;
396
397 r = nlmsg_data(nlh);
398 r->ifi_family = AF_UNSPEC;
399 r->__ifi_pad = 0;
400 r->ifi_type = dev->type;
401 r->ifi_index = dev->ifindex;
402 r->ifi_flags = dev_get_flags(dev);
403 r->ifi_change = 0; /* Wireless changes don't affect those flags */
404
David S. Miller9360ffd2012-03-29 04:41:26 -0400405 if (nla_put_string(skb, IFLA_IFNAME, dev->name))
406 goto nla_put_failure;
Johannes Berg3d23e342009-09-29 23:27:28 +0200407
408 return nlh;
409 nla_put_failure:
410 nlmsg_cancel(skb, nlh);
411 return NULL;
412}
413
414
415/*
416 * Main event dispatcher. Called from other parts and drivers.
417 * Send the event on the appropriate channels.
418 * May be called from interrupt context.
419 */
420void wireless_send_event(struct net_device * dev,
421 unsigned int cmd,
422 union iwreq_data * wrqu,
423 const char * extra)
424{
425 const struct iw_ioctl_description * descr = NULL;
426 int extra_len = 0;
427 struct iw_event *event; /* Mallocated whole event */
428 int event_len; /* Its size */
429 int hdr_len; /* Size of the event header */
430 int wrqu_off = 0; /* Offset in wrqu */
431 /* Don't "optimise" the following variable, it will crash */
432 unsigned cmd_index; /* *MUST* be unsigned */
433 struct sk_buff *skb;
434 struct nlmsghdr *nlh;
435 struct nlattr *nla;
436#ifdef CONFIG_COMPAT
437 struct __compat_iw_event *compat_event;
438 struct compat_iw_point compat_wrqu;
439 struct sk_buff *compskb;
440#endif
441
442 /*
443 * Nothing in the kernel sends scan events with data, be safe.
444 * This is necessary because we cannot fix up scan event data
445 * for compat, due to being contained in 'extra', but normally
446 * applications are required to retrieve the scan data anyway
447 * and no data is included in the event, this codifies that
448 * practice.
449 */
450 if (WARN_ON(cmd == SIOCGIWSCAN && extra))
451 extra = NULL;
452
453 /* Get the description of the Event */
454 if (cmd <= SIOCIWLAST) {
Joe Perches44608f82010-03-18 18:29:35 -0700455 cmd_index = IW_IOCTL_IDX(cmd);
Johannes Berg3d23e342009-09-29 23:27:28 +0200456 if (cmd_index < standard_ioctl_num)
457 descr = &(standard_ioctl[cmd_index]);
458 } else {
Joe Perches76326f12010-03-18 18:29:36 -0700459 cmd_index = IW_EVENT_IDX(cmd);
Johannes Berg3d23e342009-09-29 23:27:28 +0200460 if (cmd_index < standard_event_num)
461 descr = &(standard_event[cmd_index]);
462 }
463 /* Don't accept unknown events */
464 if (descr == NULL) {
465 /* Note : we don't return an error to the driver, because
466 * the driver would not know what to do about it. It can't
467 * return an error to the user, because the event is not
468 * initiated by a user request.
469 * The best the driver could do is to log an error message.
470 * We will do it ourselves instead...
471 */
Joe Perchese9c02682010-11-16 19:56:49 -0800472 netdev_err(dev, "(WE) : Invalid/Unknown Wireless Event (0x%04X)\n",
473 cmd);
Johannes Berg3d23e342009-09-29 23:27:28 +0200474 return;
475 }
476
477 /* Check extra parameters and set extra_len */
478 if (descr->header_type == IW_HEADER_TYPE_POINT) {
479 /* Check if number of token fits within bounds */
480 if (wrqu->data.length > descr->max_tokens) {
Joe Perchese9c02682010-11-16 19:56:49 -0800481 netdev_err(dev, "(WE) : Wireless Event too big (%d)\n",
482 wrqu->data.length);
Johannes Berg3d23e342009-09-29 23:27:28 +0200483 return;
484 }
485 if (wrqu->data.length < descr->min_tokens) {
Joe Perchese9c02682010-11-16 19:56:49 -0800486 netdev_err(dev, "(WE) : Wireless Event too small (%d)\n",
487 wrqu->data.length);
Johannes Berg3d23e342009-09-29 23:27:28 +0200488 return;
489 }
490 /* Calculate extra_len - extra is NULL for restricted events */
491 if (extra != NULL)
492 extra_len = wrqu->data.length * descr->token_size;
493 /* Always at an offset in wrqu */
494 wrqu_off = IW_EV_POINT_OFF;
495 }
496
497 /* Total length of the event */
498 hdr_len = event_type_size[descr->header_type];
499 event_len = hdr_len + extra_len;
500
501 /*
502 * The problem for 64/32 bit.
503 *
504 * On 64-bit, a regular event is laid out as follows:
505 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
506 * | event.len | event.cmd | p a d d i n g |
507 * | wrqu data ... (with the correct size) |
508 *
509 * This padding exists because we manipulate event->u,
510 * and 'event' is not packed.
511 *
512 * An iw_point event is laid out like this instead:
513 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
514 * | event.len | event.cmd | p a d d i n g |
515 * | iwpnt.len | iwpnt.flg | p a d d i n g |
516 * | extra data ...
517 *
518 * The second padding exists because struct iw_point is extended,
519 * but this depends on the platform...
520 *
521 * On 32-bit, all the padding shouldn't be there.
522 */
523
524 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
525 if (!skb)
526 return;
527
528 /* Send via the RtNetlink event channel */
529 nlh = rtnetlink_ifinfo_prep(dev, skb);
530 if (WARN_ON(!nlh)) {
531 kfree_skb(skb);
532 return;
533 }
534
535 /* Add the wireless events in the netlink packet */
536 nla = nla_reserve(skb, IFLA_WIRELESS, event_len);
537 if (!nla) {
538 kfree_skb(skb);
539 return;
540 }
541 event = nla_data(nla);
542
543 /* Fill event - first clear to avoid data leaking */
544 memset(event, 0, hdr_len);
545 event->len = event_len;
546 event->cmd = cmd;
547 memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN);
548 if (extra_len)
549 memcpy(((char *) event) + hdr_len, extra, extra_len);
550
551 nlmsg_end(skb, nlh);
552#ifdef CONFIG_COMPAT
553 hdr_len = compat_event_type_size[descr->header_type];
554 event_len = hdr_len + extra_len;
555
556 compskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
557 if (!compskb) {
558 kfree_skb(skb);
559 return;
560 }
561
562 /* Send via the RtNetlink event channel */
563 nlh = rtnetlink_ifinfo_prep(dev, compskb);
564 if (WARN_ON(!nlh)) {
565 kfree_skb(skb);
566 kfree_skb(compskb);
567 return;
568 }
569
570 /* Add the wireless events in the netlink packet */
571 nla = nla_reserve(compskb, IFLA_WIRELESS, event_len);
572 if (!nla) {
573 kfree_skb(skb);
574 kfree_skb(compskb);
575 return;
576 }
577 compat_event = nla_data(nla);
578
579 compat_event->len = event_len;
580 compat_event->cmd = cmd;
581 if (descr->header_type == IW_HEADER_TYPE_POINT) {
582 compat_wrqu.length = wrqu->data.length;
583 compat_wrqu.flags = wrqu->data.flags;
584 memcpy(&compat_event->pointer,
585 ((char *) &compat_wrqu) + IW_EV_COMPAT_POINT_OFF,
586 hdr_len - IW_EV_COMPAT_LCP_LEN);
587 if (extra_len)
588 memcpy(((char *) compat_event) + hdr_len,
589 extra, extra_len);
590 } else {
591 /* extra_len must be zero, so no if (extra) needed */
592 memcpy(&compat_event->pointer, wrqu,
593 hdr_len - IW_EV_COMPAT_LCP_LEN);
594 }
595
596 nlmsg_end(compskb, nlh);
597
598 skb_shinfo(skb)->frag_list = compskb;
599#endif
600 skb_queue_tail(&dev_net(dev)->wext_nlevents, skb);
601 schedule_work(&wireless_nlevent_work);
602}
603EXPORT_SYMBOL(wireless_send_event);
604
605
606
607/* IW handlers */
608
609struct iw_statistics *get_wireless_stats(struct net_device *dev)
610{
611#ifdef CONFIG_WIRELESS_EXT
612 if ((dev->wireless_handlers != NULL) &&
613 (dev->wireless_handlers->get_wireless_stats != NULL))
614 return dev->wireless_handlers->get_wireless_stats(dev);
615#endif
616
617#ifdef CONFIG_CFG80211_WEXT
Julia Lawall36539102010-08-28 17:41:06 +0200618 if (dev->ieee80211_ptr &&
Johannes Berg3d23e342009-09-29 23:27:28 +0200619 dev->ieee80211_ptr->wiphy &&
620 dev->ieee80211_ptr->wiphy->wext &&
621 dev->ieee80211_ptr->wiphy->wext->get_wireless_stats)
622 return dev->ieee80211_ptr->wiphy->wext->get_wireless_stats(dev);
623#endif
624
625 /* not found */
626 return NULL;
627}
628
629static int iw_handler_get_iwstats(struct net_device * dev,
630 struct iw_request_info * info,
631 union iwreq_data * wrqu,
632 char * extra)
633{
634 /* Get stats from the driver */
635 struct iw_statistics *stats;
636
637 stats = get_wireless_stats(dev);
638 if (stats) {
639 /* Copy statistics to extra */
640 memcpy(extra, stats, sizeof(struct iw_statistics));
641 wrqu->data.length = sizeof(struct iw_statistics);
642
643 /* Check if we need to clear the updated flag */
644 if (wrqu->data.flags != 0)
645 stats->qual.updated &= ~IW_QUAL_ALL_UPDATED;
646 return 0;
647 } else
648 return -EOPNOTSUPP;
649}
650
651static iw_handler get_handler(struct net_device *dev, unsigned int cmd)
652{
653 /* Don't "optimise" the following variable, it will crash */
654 unsigned int index; /* *MUST* be unsigned */
655 const struct iw_handler_def *handlers = NULL;
656
657#ifdef CONFIG_CFG80211_WEXT
658 if (dev->ieee80211_ptr && dev->ieee80211_ptr->wiphy)
659 handlers = dev->ieee80211_ptr->wiphy->wext;
660#endif
661#ifdef CONFIG_WIRELESS_EXT
662 if (dev->wireless_handlers)
663 handlers = dev->wireless_handlers;
664#endif
665
666 if (!handlers)
667 return NULL;
668
669 /* Try as a standard command */
Joe Perches44608f82010-03-18 18:29:35 -0700670 index = IW_IOCTL_IDX(cmd);
Johannes Berg3d23e342009-09-29 23:27:28 +0200671 if (index < handlers->num_standard)
672 return handlers->standard[index];
673
674#ifdef CONFIG_WEXT_PRIV
675 /* Try as a private command */
676 index = cmd - SIOCIWFIRSTPRIV;
677 if (index < handlers->num_private)
678 return handlers->private[index];
679#endif
680
681 /* Not found */
682 return NULL;
683}
684
685static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
686 const struct iw_ioctl_description *descr,
687 iw_handler handler, struct net_device *dev,
688 struct iw_request_info *info)
689{
690 int err, extra_size, user_length = 0, essid_compat = 0;
691 char *extra;
692
693 /* Calculate space needed by arguments. Always allocate
694 * for max space.
695 */
696 extra_size = descr->max_tokens * descr->token_size;
697
698 /* Check need for ESSID compatibility for WE < 21 */
699 switch (cmd) {
700 case SIOCSIWESSID:
701 case SIOCGIWESSID:
702 case SIOCSIWNICKN:
703 case SIOCGIWNICKN:
704 if (iwp->length == descr->max_tokens + 1)
705 essid_compat = 1;
706 else if (IW_IS_SET(cmd) && (iwp->length != 0)) {
707 char essid[IW_ESSID_MAX_SIZE + 1];
708 unsigned int len;
709 len = iwp->length * descr->token_size;
710
711 if (len > IW_ESSID_MAX_SIZE)
712 return -EFAULT;
713
714 err = copy_from_user(essid, iwp->pointer, len);
715 if (err)
716 return -EFAULT;
717
718 if (essid[iwp->length - 1] == '\0')
719 essid_compat = 1;
720 }
721 break;
722 default:
723 break;
724 }
725
726 iwp->length -= essid_compat;
727
728 /* Check what user space is giving us */
729 if (IW_IS_SET(cmd)) {
730 /* Check NULL pointer */
731 if (!iwp->pointer && iwp->length != 0)
732 return -EFAULT;
733 /* Check if number of token fits within bounds */
734 if (iwp->length > descr->max_tokens)
735 return -E2BIG;
736 if (iwp->length < descr->min_tokens)
737 return -EINVAL;
738 } else {
739 /* Check NULL pointer */
740 if (!iwp->pointer)
741 return -EFAULT;
742 /* Save user space buffer size for checking */
743 user_length = iwp->length;
744
745 /* Don't check if user_length > max to allow forward
746 * compatibility. The test user_length < min is
747 * implied by the test at the end.
748 */
749
750 /* Support for very large requests */
751 if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
752 (user_length > descr->max_tokens)) {
753 /* Allow userspace to GET more than max so
754 * we can support any size GET requests.
755 * There is still a limit : -ENOMEM.
756 */
757 extra_size = user_length * descr->token_size;
758
759 /* Note : user_length is originally a __u16,
760 * and token_size is controlled by us,
761 * so extra_size won't get negative and
762 * won't overflow...
763 */
764 }
765 }
766
767 /* kzalloc() ensures NULL-termination for essid_compat. */
768 extra = kzalloc(extra_size, GFP_KERNEL);
769 if (!extra)
770 return -ENOMEM;
771
772 /* If it is a SET, get all the extra data in here */
773 if (IW_IS_SET(cmd) && (iwp->length != 0)) {
774 if (copy_from_user(extra, iwp->pointer,
775 iwp->length *
776 descr->token_size)) {
777 err = -EFAULT;
778 goto out;
779 }
780
781 if (cmd == SIOCSIWENCODEEXT) {
782 struct iw_encode_ext *ee = (void *) extra;
783
784 if (iwp->length < sizeof(*ee) + ee->key_len)
785 return -EFAULT;
786 }
787 }
788
Johannes Berg42da2f92010-08-30 12:24:54 +0200789 if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
790 /*
791 * If this is a GET, but not NOMAX, it means that the extra
792 * data is not bounded by userspace, but by max_tokens. Thus
793 * set the length to max_tokens. This matches the extra data
794 * allocation.
795 * The driver should fill it with the number of tokens it
796 * provided, and it may check iwp->length rather than having
797 * knowledge of max_tokens. If the driver doesn't change the
798 * iwp->length, this ioctl just copies back max_token tokens
799 * filled with zeroes. Hopefully the driver isn't claiming
800 * them to be valid data.
801 */
802 iwp->length = descr->max_tokens;
803 }
804
Johannes Berg3d23e342009-09-29 23:27:28 +0200805 err = handler(dev, info, (union iwreq_data *) iwp, extra);
806
807 iwp->length += essid_compat;
808
809 /* If we have something to return to the user */
810 if (!err && IW_IS_GET(cmd)) {
811 /* Check if there is enough buffer up there */
812 if (user_length < iwp->length) {
813 err = -E2BIG;
814 goto out;
815 }
816
817 if (copy_to_user(iwp->pointer, extra,
818 iwp->length *
819 descr->token_size)) {
820 err = -EFAULT;
821 goto out;
822 }
823 }
824
825 /* Generate an event to notify listeners of the change */
Jean Tourrilhes1014eb62009-11-24 10:47:08 -0800826 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
827 ((err == 0) || (err == -EIWCOMMIT))) {
Johannes Berg3d23e342009-09-29 23:27:28 +0200828 union iwreq_data *data = (union iwreq_data *) iwp;
829
830 if (descr->flags & IW_DESCR_FLAG_RESTRICT)
831 /* If the event is restricted, don't
832 * export the payload.
833 */
834 wireless_send_event(dev, cmd, data, NULL);
835 else
836 wireless_send_event(dev, cmd, data, extra);
837 }
838
839out:
840 kfree(extra);
841 return err;
842}
843
844/*
845 * Call the commit handler in the driver
846 * (if exist and if conditions are right)
847 *
848 * Note : our current commit strategy is currently pretty dumb,
849 * but we will be able to improve on that...
850 * The goal is to try to agreagate as many changes as possible
851 * before doing the commit. Drivers that will define a commit handler
852 * are usually those that need a reset after changing parameters, so
853 * we want to minimise the number of reset.
854 * A cool idea is to use a timer : at each "set" command, we re-set the
855 * timer, when the timer eventually fires, we call the driver.
856 * Hopefully, more on that later.
857 *
858 * Also, I'm waiting to see how many people will complain about the
859 * netif_running(dev) test. I'm open on that one...
860 * Hopefully, the driver will remember to do a commit in "open()" ;-)
861 */
862int call_commit_handler(struct net_device *dev)
863{
864#ifdef CONFIG_WIRELESS_EXT
865 if ((netif_running(dev)) &&
866 (dev->wireless_handlers->standard[0] != NULL))
867 /* Call the commit handler on the driver */
868 return dev->wireless_handlers->standard[0](dev, NULL,
869 NULL, NULL);
870 else
871 return 0; /* Command completed successfully */
872#else
873 /* cfg80211 has no commit */
874 return 0;
875#endif
876}
877
878/*
879 * Main IOCTl dispatcher.
880 * Check the type of IOCTL and call the appropriate wrapper...
881 */
882static int wireless_process_ioctl(struct net *net, struct ifreq *ifr,
883 unsigned int cmd,
884 struct iw_request_info *info,
885 wext_ioctl_func standard,
886 wext_ioctl_func private)
887{
888 struct iwreq *iwr = (struct iwreq *) ifr;
889 struct net_device *dev;
890 iw_handler handler;
891
892 /* Permissions are already checked in dev_ioctl() before calling us.
893 * The copy_to/from_user() of ifr is also dealt with in there */
894
895 /* Make sure the device exist */
896 if ((dev = __dev_get_by_name(net, ifr->ifr_name)) == NULL)
897 return -ENODEV;
898
899 /* A bunch of special cases, then the generic case...
900 * Note that 'cmd' is already filtered in dev_ioctl() with
901 * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */
902 if (cmd == SIOCGIWSTATS)
903 return standard(dev, iwr, cmd, info,
904 &iw_handler_get_iwstats);
905
906#ifdef CONFIG_WEXT_PRIV
907 if (cmd == SIOCGIWPRIV && dev->wireless_handlers)
908 return standard(dev, iwr, cmd, info,
909 iw_handler_get_private);
910#endif
911
912 /* Basic check */
913 if (!netif_device_present(dev))
914 return -ENODEV;
915
916 /* New driver API : try to find the handler */
917 handler = get_handler(dev, cmd);
918 if (handler) {
919 /* Standard and private are not the same */
920 if (cmd < SIOCIWFIRSTPRIV)
921 return standard(dev, iwr, cmd, info, handler);
922 else if (private)
923 return private(dev, iwr, cmd, info, handler);
924 }
925 /* Old driver API : call driver ioctl handler */
926 if (dev->netdev_ops->ndo_do_ioctl)
927 return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd);
928 return -EOPNOTSUPP;
929}
930
931/* If command is `set a parameter', or `get the encoding parameters',
932 * check if the user has the right to do it.
933 */
934static int wext_permission_check(unsigned int cmd)
935{
Joe Perchesf64f9e72009-11-29 16:55:45 -0800936 if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE ||
937 cmd == SIOCGIWENCODEEXT) &&
938 !capable(CAP_NET_ADMIN))
Johannes Berg3d23e342009-09-29 23:27:28 +0200939 return -EPERM;
940
941 return 0;
942}
943
944/* entry point from dev ioctl */
945static int wext_ioctl_dispatch(struct net *net, struct ifreq *ifr,
946 unsigned int cmd, struct iw_request_info *info,
947 wext_ioctl_func standard,
948 wext_ioctl_func private)
949{
950 int ret = wext_permission_check(cmd);
951
952 if (ret)
953 return ret;
954
955 dev_load(net, ifr->ifr_name);
956 rtnl_lock();
957 ret = wireless_process_ioctl(net, ifr, cmd, info, standard, private);
958 rtnl_unlock();
959
960 return ret;
961}
962
963/*
964 * Wrapper to call a standard Wireless Extension handler.
965 * We do various checks and also take care of moving data between
966 * user space and kernel space.
967 */
968static int ioctl_standard_call(struct net_device * dev,
969 struct iwreq *iwr,
970 unsigned int cmd,
971 struct iw_request_info *info,
972 iw_handler handler)
973{
974 const struct iw_ioctl_description * descr;
975 int ret = -EINVAL;
976
977 /* Get the description of the IOCTL */
Joe Perches44608f82010-03-18 18:29:35 -0700978 if (IW_IOCTL_IDX(cmd) >= standard_ioctl_num)
Johannes Berg3d23e342009-09-29 23:27:28 +0200979 return -EOPNOTSUPP;
Joe Perches44608f82010-03-18 18:29:35 -0700980 descr = &(standard_ioctl[IW_IOCTL_IDX(cmd)]);
Johannes Berg3d23e342009-09-29 23:27:28 +0200981
982 /* Check if we have a pointer to user space data or not */
983 if (descr->header_type != IW_HEADER_TYPE_POINT) {
984
985 /* No extra arguments. Trivial to handle */
986 ret = handler(dev, info, &(iwr->u), NULL);
987
988 /* Generate an event to notify listeners of the change */
989 if ((descr->flags & IW_DESCR_FLAG_EVENT) &&
990 ((ret == 0) || (ret == -EIWCOMMIT)))
991 wireless_send_event(dev, cmd, &(iwr->u), NULL);
992 } else {
993 ret = ioctl_standard_iw_point(&iwr->u.data, cmd, descr,
994 handler, dev, info);
995 }
996
997 /* Call commit handler if needed and defined */
998 if (ret == -EIWCOMMIT)
999 ret = call_commit_handler(dev);
1000
1001 /* Here, we will generate the appropriate event if needed */
1002
1003 return ret;
1004}
1005
1006
1007int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd,
1008 void __user *arg)
1009{
1010 struct iw_request_info info = { .cmd = cmd, .flags = 0 };
1011 int ret;
1012
1013 ret = wext_ioctl_dispatch(net, ifr, cmd, &info,
1014 ioctl_standard_call,
1015 ioctl_private_call);
1016 if (ret >= 0 &&
1017 IW_IS_GET(cmd) &&
1018 copy_to_user(arg, ifr, sizeof(struct iwreq)))
1019 return -EFAULT;
1020
1021 return ret;
1022}
1023
1024#ifdef CONFIG_COMPAT
1025static int compat_standard_call(struct net_device *dev,
1026 struct iwreq *iwr,
1027 unsigned int cmd,
1028 struct iw_request_info *info,
1029 iw_handler handler)
1030{
1031 const struct iw_ioctl_description *descr;
1032 struct compat_iw_point *iwp_compat;
1033 struct iw_point iwp;
1034 int err;
1035
Joe Perches44608f82010-03-18 18:29:35 -07001036 descr = standard_ioctl + IW_IOCTL_IDX(cmd);
Johannes Berg3d23e342009-09-29 23:27:28 +02001037
1038 if (descr->header_type != IW_HEADER_TYPE_POINT)
1039 return ioctl_standard_call(dev, iwr, cmd, info, handler);
1040
1041 iwp_compat = (struct compat_iw_point *) &iwr->u.data;
1042 iwp.pointer = compat_ptr(iwp_compat->pointer);
1043 iwp.length = iwp_compat->length;
1044 iwp.flags = iwp_compat->flags;
1045
1046 err = ioctl_standard_iw_point(&iwp, cmd, descr, handler, dev, info);
1047
1048 iwp_compat->pointer = ptr_to_compat(iwp.pointer);
1049 iwp_compat->length = iwp.length;
1050 iwp_compat->flags = iwp.flags;
1051
1052 return err;
1053}
1054
1055int compat_wext_handle_ioctl(struct net *net, unsigned int cmd,
1056 unsigned long arg)
1057{
1058 void __user *argp = (void __user *)arg;
1059 struct iw_request_info info;
1060 struct iwreq iwr;
1061 char *colon;
1062 int ret;
1063
1064 if (copy_from_user(&iwr, argp, sizeof(struct iwreq)))
1065 return -EFAULT;
1066
1067 iwr.ifr_name[IFNAMSIZ-1] = 0;
1068 colon = strchr(iwr.ifr_name, ':');
1069 if (colon)
1070 *colon = 0;
1071
1072 info.cmd = cmd;
1073 info.flags = IW_REQUEST_FLAG_COMPAT;
1074
1075 ret = wext_ioctl_dispatch(net, (struct ifreq *) &iwr, cmd, &info,
1076 compat_standard_call,
1077 compat_private_call);
1078
1079 if (ret >= 0 &&
1080 IW_IS_GET(cmd) &&
1081 copy_to_user(argp, &iwr, sizeof(struct iwreq)))
1082 return -EFAULT;
1083
1084 return ret;
1085}
1086#endif