Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
3d23e349 | 2 | * This file implement the Wireless Extensions core API. |
1da177e4 LT |
3 | * |
4 | * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com> | |
c2805fbb | 5 | * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved. |
3d23e349 | 6 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
1da177e4 LT |
7 | * |
8 | * (As all part of the Linux kernel, this file is GPL) | |
9 | */ | |
3d23e349 JB |
10 | #include <linux/kernel.h> |
11 | #include <linux/netdevice.h> | |
12 | #include <linux/rtnetlink.h> | |
5a0e3ad6 | 13 | #include <linux/slab.h> |
3d23e349 JB |
14 | #include <linux/wireless.h> |
15 | #include <linux/uaccess.h> | |
bc3b2d7f | 16 | #include <linux/export.h> |
3d23e349 JB |
17 | #include <net/cfg80211.h> |
18 | #include <net/iw_handler.h> | |
bd5785ba | 19 | #include <net/netlink.h> |
295f4a1f | 20 | #include <net/wext.h> |
3d23e349 JB |
21 | #include <net/net_namespace.h> |
22 | ||
23 | typedef int (*wext_ioctl_func)(struct net_device *, struct iwreq *, | |
24 | unsigned int, struct iw_request_info *, | |
25 | iw_handler); | |
1da177e4 | 26 | |
1da177e4 | 27 | |
1da177e4 LT |
28 | /* |
29 | * Meta-data about all the standard Wireless Extension request we | |
30 | * know about. | |
31 | */ | |
32 | static const struct iw_ioctl_description standard_ioctl[] = { | |
44608f80 | 33 | [IW_IOCTL_IDX(SIOCSIWCOMMIT)] = { |
1da177e4 LT |
34 | .header_type = IW_HEADER_TYPE_NULL, |
35 | }, | |
44608f80 | 36 | [IW_IOCTL_IDX(SIOCGIWNAME)] = { |
1da177e4 LT |
37 | .header_type = IW_HEADER_TYPE_CHAR, |
38 | .flags = IW_DESCR_FLAG_DUMP, | |
39 | }, | |
44608f80 | 40 | [IW_IOCTL_IDX(SIOCSIWNWID)] = { |
1da177e4 LT |
41 | .header_type = IW_HEADER_TYPE_PARAM, |
42 | .flags = IW_DESCR_FLAG_EVENT, | |
43 | }, | |
44608f80 | 44 | [IW_IOCTL_IDX(SIOCGIWNWID)] = { |
1da177e4 LT |
45 | .header_type = IW_HEADER_TYPE_PARAM, |
46 | .flags = IW_DESCR_FLAG_DUMP, | |
47 | }, | |
44608f80 | 48 | [IW_IOCTL_IDX(SIOCSIWFREQ)] = { |
1da177e4 LT |
49 | .header_type = IW_HEADER_TYPE_FREQ, |
50 | .flags = IW_DESCR_FLAG_EVENT, | |
51 | }, | |
44608f80 | 52 | [IW_IOCTL_IDX(SIOCGIWFREQ)] = { |
1da177e4 LT |
53 | .header_type = IW_HEADER_TYPE_FREQ, |
54 | .flags = IW_DESCR_FLAG_DUMP, | |
55 | }, | |
44608f80 | 56 | [IW_IOCTL_IDX(SIOCSIWMODE)] = { |
1da177e4 LT |
57 | .header_type = IW_HEADER_TYPE_UINT, |
58 | .flags = IW_DESCR_FLAG_EVENT, | |
59 | }, | |
44608f80 | 60 | [IW_IOCTL_IDX(SIOCGIWMODE)] = { |
1da177e4 LT |
61 | .header_type = IW_HEADER_TYPE_UINT, |
62 | .flags = IW_DESCR_FLAG_DUMP, | |
63 | }, | |
44608f80 | 64 | [IW_IOCTL_IDX(SIOCSIWSENS)] = { |
1da177e4 LT |
65 | .header_type = IW_HEADER_TYPE_PARAM, |
66 | }, | |
44608f80 | 67 | [IW_IOCTL_IDX(SIOCGIWSENS)] = { |
1da177e4 LT |
68 | .header_type = IW_HEADER_TYPE_PARAM, |
69 | }, | |
44608f80 | 70 | [IW_IOCTL_IDX(SIOCSIWRANGE)] = { |
1da177e4 LT |
71 | .header_type = IW_HEADER_TYPE_NULL, |
72 | }, | |
44608f80 | 73 | [IW_IOCTL_IDX(SIOCGIWRANGE)] = { |
1da177e4 LT |
74 | .header_type = IW_HEADER_TYPE_POINT, |
75 | .token_size = 1, | |
76 | .max_tokens = sizeof(struct iw_range), | |
77 | .flags = IW_DESCR_FLAG_DUMP, | |
78 | }, | |
44608f80 | 79 | [IW_IOCTL_IDX(SIOCSIWPRIV)] = { |
1da177e4 LT |
80 | .header_type = IW_HEADER_TYPE_NULL, |
81 | }, | |
44608f80 | 82 | [IW_IOCTL_IDX(SIOCGIWPRIV)] = { /* (handled directly by us) */ |
711e2c33 JT |
83 | .header_type = IW_HEADER_TYPE_POINT, |
84 | .token_size = sizeof(struct iw_priv_args), | |
85 | .max_tokens = 16, | |
86 | .flags = IW_DESCR_FLAG_NOMAX, | |
1da177e4 | 87 | }, |
44608f80 | 88 | [IW_IOCTL_IDX(SIOCSIWSTATS)] = { |
1da177e4 LT |
89 | .header_type = IW_HEADER_TYPE_NULL, |
90 | }, | |
44608f80 | 91 | [IW_IOCTL_IDX(SIOCGIWSTATS)] = { /* (handled directly by us) */ |
711e2c33 JT |
92 | .header_type = IW_HEADER_TYPE_POINT, |
93 | .token_size = 1, | |
94 | .max_tokens = sizeof(struct iw_statistics), | |
1da177e4 LT |
95 | .flags = IW_DESCR_FLAG_DUMP, |
96 | }, | |
44608f80 | 97 | [IW_IOCTL_IDX(SIOCSIWSPY)] = { |
1da177e4 LT |
98 | .header_type = IW_HEADER_TYPE_POINT, |
99 | .token_size = sizeof(struct sockaddr), | |
100 | .max_tokens = IW_MAX_SPY, | |
101 | }, | |
44608f80 | 102 | [IW_IOCTL_IDX(SIOCGIWSPY)] = { |
1da177e4 LT |
103 | .header_type = IW_HEADER_TYPE_POINT, |
104 | .token_size = sizeof(struct sockaddr) + | |
105 | sizeof(struct iw_quality), | |
106 | .max_tokens = IW_MAX_SPY, | |
107 | }, | |
44608f80 | 108 | [IW_IOCTL_IDX(SIOCSIWTHRSPY)] = { |
1da177e4 LT |
109 | .header_type = IW_HEADER_TYPE_POINT, |
110 | .token_size = sizeof(struct iw_thrspy), | |
111 | .min_tokens = 1, | |
112 | .max_tokens = 1, | |
113 | }, | |
44608f80 | 114 | [IW_IOCTL_IDX(SIOCGIWTHRSPY)] = { |
1da177e4 LT |
115 | .header_type = IW_HEADER_TYPE_POINT, |
116 | .token_size = sizeof(struct iw_thrspy), | |
117 | .min_tokens = 1, | |
118 | .max_tokens = 1, | |
119 | }, | |
44608f80 | 120 | [IW_IOCTL_IDX(SIOCSIWAP)] = { |
1da177e4 LT |
121 | .header_type = IW_HEADER_TYPE_ADDR, |
122 | }, | |
44608f80 | 123 | [IW_IOCTL_IDX(SIOCGIWAP)] = { |
1da177e4 LT |
124 | .header_type = IW_HEADER_TYPE_ADDR, |
125 | .flags = IW_DESCR_FLAG_DUMP, | |
126 | }, | |
44608f80 | 127 | [IW_IOCTL_IDX(SIOCSIWMLME)] = { |
fff9cfd9 | 128 | .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 | }, | |
44608f80 | 133 | [IW_IOCTL_IDX(SIOCGIWAPLIST)] = { |
1da177e4 LT |
134 | .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 | }, | |
44608f80 | 140 | [IW_IOCTL_IDX(SIOCSIWSCAN)] = { |
fff9cfd9 | 141 | .header_type = IW_HEADER_TYPE_POINT, |
142 | .token_size = 1, | |
143 | .min_tokens = 0, | |
144 | .max_tokens = sizeof(struct iw_scan_req), | |
1da177e4 | 145 | }, |
44608f80 | 146 | [IW_IOCTL_IDX(SIOCGIWSCAN)] = { |
1da177e4 LT |
147 | .header_type = IW_HEADER_TYPE_POINT, |
148 | .token_size = 1, | |
149 | .max_tokens = IW_SCAN_MAX_DATA, | |
150 | .flags = IW_DESCR_FLAG_NOMAX, | |
151 | }, | |
44608f80 | 152 | [IW_IOCTL_IDX(SIOCSIWESSID)] = { |
1da177e4 LT |
153 | .header_type = IW_HEADER_TYPE_POINT, |
154 | .token_size = 1, | |
baef1865 | 155 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 LT |
156 | .flags = IW_DESCR_FLAG_EVENT, |
157 | }, | |
44608f80 | 158 | [IW_IOCTL_IDX(SIOCGIWESSID)] = { |
1da177e4 LT |
159 | .header_type = IW_HEADER_TYPE_POINT, |
160 | .token_size = 1, | |
baef1865 | 161 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 LT |
162 | .flags = IW_DESCR_FLAG_DUMP, |
163 | }, | |
44608f80 | 164 | [IW_IOCTL_IDX(SIOCSIWNICKN)] = { |
1da177e4 LT |
165 | .header_type = IW_HEADER_TYPE_POINT, |
166 | .token_size = 1, | |
baef1865 | 167 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 | 168 | }, |
44608f80 | 169 | [IW_IOCTL_IDX(SIOCGIWNICKN)] = { |
1da177e4 LT |
170 | .header_type = IW_HEADER_TYPE_POINT, |
171 | .token_size = 1, | |
baef1865 | 172 | .max_tokens = IW_ESSID_MAX_SIZE, |
1da177e4 | 173 | }, |
44608f80 | 174 | [IW_IOCTL_IDX(SIOCSIWRATE)] = { |
1da177e4 LT |
175 | .header_type = IW_HEADER_TYPE_PARAM, |
176 | }, | |
44608f80 | 177 | [IW_IOCTL_IDX(SIOCGIWRATE)] = { |
1da177e4 LT |
178 | .header_type = IW_HEADER_TYPE_PARAM, |
179 | }, | |
44608f80 | 180 | [IW_IOCTL_IDX(SIOCSIWRTS)] = { |
1da177e4 LT |
181 | .header_type = IW_HEADER_TYPE_PARAM, |
182 | }, | |
44608f80 | 183 | [IW_IOCTL_IDX(SIOCGIWRTS)] = { |
1da177e4 LT |
184 | .header_type = IW_HEADER_TYPE_PARAM, |
185 | }, | |
44608f80 | 186 | [IW_IOCTL_IDX(SIOCSIWFRAG)] = { |
1da177e4 LT |
187 | .header_type = IW_HEADER_TYPE_PARAM, |
188 | }, | |
44608f80 | 189 | [IW_IOCTL_IDX(SIOCGIWFRAG)] = { |
1da177e4 LT |
190 | .header_type = IW_HEADER_TYPE_PARAM, |
191 | }, | |
44608f80 | 192 | [IW_IOCTL_IDX(SIOCSIWTXPOW)] = { |
1da177e4 LT |
193 | .header_type = IW_HEADER_TYPE_PARAM, |
194 | }, | |
44608f80 | 195 | [IW_IOCTL_IDX(SIOCGIWTXPOW)] = { |
1da177e4 LT |
196 | .header_type = IW_HEADER_TYPE_PARAM, |
197 | }, | |
44608f80 | 198 | [IW_IOCTL_IDX(SIOCSIWRETRY)] = { |
1da177e4 LT |
199 | .header_type = IW_HEADER_TYPE_PARAM, |
200 | }, | |
44608f80 | 201 | [IW_IOCTL_IDX(SIOCGIWRETRY)] = { |
1da177e4 LT |
202 | .header_type = IW_HEADER_TYPE_PARAM, |
203 | }, | |
44608f80 | 204 | [IW_IOCTL_IDX(SIOCSIWENCODE)] = { |
1da177e4 LT |
205 | .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 | }, | |
44608f80 | 210 | [IW_IOCTL_IDX(SIOCGIWENCODE)] = { |
1da177e4 LT |
211 | .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 | }, | |
44608f80 | 216 | [IW_IOCTL_IDX(SIOCSIWPOWER)] = { |
1da177e4 LT |
217 | .header_type = IW_HEADER_TYPE_PARAM, |
218 | }, | |
44608f80 | 219 | [IW_IOCTL_IDX(SIOCGIWPOWER)] = { |
1da177e4 LT |
220 | .header_type = IW_HEADER_TYPE_PARAM, |
221 | }, | |
44608f80 | 222 | [IW_IOCTL_IDX(SIOCSIWGENIE)] = { |
fff9cfd9 | 223 | .header_type = IW_HEADER_TYPE_POINT, |
224 | .token_size = 1, | |
225 | .max_tokens = IW_GENERIC_IE_MAX, | |
226 | }, | |
44608f80 | 227 | [IW_IOCTL_IDX(SIOCGIWGENIE)] = { |
fff9cfd9 | 228 | .header_type = IW_HEADER_TYPE_POINT, |
229 | .token_size = 1, | |
230 | .max_tokens = IW_GENERIC_IE_MAX, | |
231 | }, | |
44608f80 | 232 | [IW_IOCTL_IDX(SIOCSIWAUTH)] = { |
fff9cfd9 | 233 | .header_type = IW_HEADER_TYPE_PARAM, |
234 | }, | |
44608f80 | 235 | [IW_IOCTL_IDX(SIOCGIWAUTH)] = { |
fff9cfd9 | 236 | .header_type = IW_HEADER_TYPE_PARAM, |
237 | }, | |
44608f80 | 238 | [IW_IOCTL_IDX(SIOCSIWENCODEEXT)] = { |
fff9cfd9 | 239 | .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 | }, | |
44608f80 | 245 | [IW_IOCTL_IDX(SIOCGIWENCODEEXT)] = { |
fff9cfd9 | 246 | .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 | }, | |
44608f80 | 252 | [IW_IOCTL_IDX(SIOCSIWPMKSA)] = { |
fff9cfd9 | 253 | .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 | }, | |
1da177e4 | 258 | }; |
95c96174 | 259 | static const unsigned int standard_ioctl_num = ARRAY_SIZE(standard_ioctl); |
1da177e4 LT |
260 | |
261 | /* | |
262 | * Meta-data about all the additional standard Wireless Extension events | |
263 | * we know about. | |
264 | */ | |
265 | static const struct iw_ioctl_description standard_event[] = { | |
76326f1d | 266 | [IW_EVENT_IDX(IWEVTXDROP)] = { |
1da177e4 LT |
267 | .header_type = IW_HEADER_TYPE_ADDR, |
268 | }, | |
76326f1d | 269 | [IW_EVENT_IDX(IWEVQUAL)] = { |
1da177e4 LT |
270 | .header_type = IW_HEADER_TYPE_QUAL, |
271 | }, | |
76326f1d | 272 | [IW_EVENT_IDX(IWEVCUSTOM)] = { |
1da177e4 LT |
273 | .header_type = IW_HEADER_TYPE_POINT, |
274 | .token_size = 1, | |
275 | .max_tokens = IW_CUSTOM_MAX, | |
276 | }, | |
76326f1d | 277 | [IW_EVENT_IDX(IWEVREGISTERED)] = { |
1da177e4 LT |
278 | .header_type = IW_HEADER_TYPE_ADDR, |
279 | }, | |
76326f1d | 280 | [IW_EVENT_IDX(IWEVEXPIRED)] = { |
4ec93edb | 281 | .header_type = IW_HEADER_TYPE_ADDR, |
1da177e4 | 282 | }, |
76326f1d | 283 | [IW_EVENT_IDX(IWEVGENIE)] = { |
fff9cfd9 | 284 | .header_type = IW_HEADER_TYPE_POINT, |
285 | .token_size = 1, | |
286 | .max_tokens = IW_GENERIC_IE_MAX, | |
287 | }, | |
76326f1d | 288 | [IW_EVENT_IDX(IWEVMICHAELMICFAILURE)] = { |
4ec93edb | 289 | .header_type = IW_HEADER_TYPE_POINT, |
fff9cfd9 | 290 | .token_size = 1, |
291 | .max_tokens = sizeof(struct iw_michaelmicfailure), | |
292 | }, | |
76326f1d | 293 | [IW_EVENT_IDX(IWEVASSOCREQIE)] = { |
fff9cfd9 | 294 | .header_type = IW_HEADER_TYPE_POINT, |
295 | .token_size = 1, | |
296 | .max_tokens = IW_GENERIC_IE_MAX, | |
297 | }, | |
76326f1d | 298 | [IW_EVENT_IDX(IWEVASSOCRESPIE)] = { |
fff9cfd9 | 299 | .header_type = IW_HEADER_TYPE_POINT, |
300 | .token_size = 1, | |
301 | .max_tokens = IW_GENERIC_IE_MAX, | |
302 | }, | |
76326f1d | 303 | [IW_EVENT_IDX(IWEVPMKIDCAND)] = { |
fff9cfd9 | 304 | .header_type = IW_HEADER_TYPE_POINT, |
305 | .token_size = 1, | |
306 | .max_tokens = sizeof(struct iw_pmkid_cand), | |
307 | }, | |
1da177e4 | 308 | }; |
95c96174 | 309 | static const unsigned int standard_event_num = ARRAY_SIZE(standard_event); |
1da177e4 | 310 | |
1da177e4 LT |
311 | /* Size (in bytes) of various events */ |
312 | static 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 | ||
1dacc76d JB |
326 | #ifdef CONFIG_COMPAT |
327 | static 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 | |
c2805fbb | 341 | |
1da177e4 | 342 | |
3d23e349 | 343 | /* IW event code */ |
1da177e4 | 344 | |
cb150b9d | 345 | void wireless_nlevent_flush(void) |
8bf86273 JB |
346 | { |
347 | struct sk_buff *skb; | |
348 | struct net *net; | |
349 | ||
350 | ASSERT_RTNL(); | |
351 | ||
352 | for_each_net(net) { | |
353 | while ((skb = skb_dequeue(&net->wext_nlevents))) | |
354 | rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, | |
355 | GFP_KERNEL); | |
356 | } | |
357 | } | |
cb150b9d | 358 | EXPORT_SYMBOL_GPL(wireless_nlevent_flush); |
8bf86273 JB |
359 | |
360 | static int wext_netdev_notifier_call(struct notifier_block *nb, | |
361 | unsigned long state, void *ptr) | |
362 | { | |
363 | /* | |
364 | * When a netdev changes state in any way, flush all pending messages | |
365 | * to avoid them going out in a strange order, e.g. RTM_NEWLINK after | |
366 | * RTM_DELLINK, or with IFF_UP after without IFF_UP during dev_close() | |
367 | * or similar - all of which could otherwise happen due to delays from | |
368 | * schedule_work(). | |
369 | */ | |
370 | wireless_nlevent_flush(); | |
371 | ||
372 | return NOTIFY_OK; | |
373 | } | |
374 | ||
375 | static struct notifier_block wext_netdev_notifier = { | |
376 | .notifier_call = wext_netdev_notifier_call, | |
377 | }; | |
378 | ||
3d23e349 | 379 | static int __net_init wext_pernet_init(struct net *net) |
711e2c33 | 380 | { |
3d23e349 JB |
381 | skb_queue_head_init(&net->wext_nlevents); |
382 | return 0; | |
711e2c33 JT |
383 | } |
384 | ||
3d23e349 | 385 | static void __net_exit wext_pernet_exit(struct net *net) |
711e2c33 | 386 | { |
3d23e349 | 387 | skb_queue_purge(&net->wext_nlevents); |
711e2c33 JT |
388 | } |
389 | ||
3d23e349 JB |
390 | static struct pernet_operations wext_pernet_ops = { |
391 | .init = wext_pernet_init, | |
392 | .exit = wext_pernet_exit, | |
393 | }; | |
1da177e4 | 394 | |
3d23e349 | 395 | static int __init wireless_nlevent_init(void) |
1da177e4 | 396 | { |
8bf86273 JB |
397 | int err = register_pernet_subsys(&wext_pernet_ops); |
398 | ||
399 | if (err) | |
400 | return err; | |
401 | ||
98bd147d JB |
402 | err = register_netdevice_notifier(&wext_netdev_notifier); |
403 | if (err) | |
404 | unregister_pernet_subsys(&wext_pernet_ops); | |
405 | return err; | |
1da177e4 LT |
406 | } |
407 | ||
3d23e349 | 408 | subsys_initcall(wireless_nlevent_init); |
1da177e4 | 409 | |
3d23e349 JB |
410 | /* Process events generated by the wireless layer or the driver. */ |
411 | static void wireless_nlevent_process(struct work_struct *work) | |
7be69c0b JB |
412 | { |
413 | rtnl_lock(); | |
8bf86273 | 414 | wireless_nlevent_flush(); |
7be69c0b JB |
415 | rtnl_unlock(); |
416 | } | |
417 | ||
3d23e349 | 418 | static DECLARE_WORK(wireless_nlevent_work, wireless_nlevent_process); |
1da177e4 | 419 | |
3d23e349 JB |
420 | static struct nlmsghdr *rtnetlink_ifinfo_prep(struct net_device *dev, |
421 | struct sk_buff *skb) | |
1da177e4 | 422 | { |
3d23e349 JB |
423 | struct ifinfomsg *r; |
424 | struct nlmsghdr *nlh; | |
1da177e4 | 425 | |
3d23e349 JB |
426 | nlh = nlmsg_put(skb, 0, 0, RTM_NEWLINK, sizeof(*r), 0); |
427 | if (!nlh) | |
428 | return NULL; | |
1da177e4 | 429 | |
3d23e349 JB |
430 | r = nlmsg_data(nlh); |
431 | r->ifi_family = AF_UNSPEC; | |
432 | r->__ifi_pad = 0; | |
433 | r->ifi_type = dev->type; | |
434 | r->ifi_index = dev->ifindex; | |
435 | r->ifi_flags = dev_get_flags(dev); | |
436 | r->ifi_change = 0; /* Wireless changes don't affect those flags */ | |
1da177e4 | 437 | |
9360ffd1 DM |
438 | if (nla_put_string(skb, IFLA_IFNAME, dev->name)) |
439 | goto nla_put_failure; | |
881d966b | 440 | |
3d23e349 JB |
441 | return nlh; |
442 | nla_put_failure: | |
443 | nlmsg_cancel(skb, nlh); | |
444 | return NULL; | |
881d966b | 445 | } |
1da177e4 | 446 | |
3d23e349 | 447 | |
1da177e4 | 448 | /* |
3d23e349 JB |
449 | * Main event dispatcher. Called from other parts and drivers. |
450 | * Send the event on the appropriate channels. | |
451 | * May be called from interrupt context. | |
1da177e4 | 452 | */ |
3d23e349 JB |
453 | void wireless_send_event(struct net_device * dev, |
454 | unsigned int cmd, | |
455 | union iwreq_data * wrqu, | |
456 | const char * extra) | |
84149b0f | 457 | { |
3d23e349 JB |
458 | const struct iw_ioctl_description * descr = NULL; |
459 | int extra_len = 0; | |
460 | struct iw_event *event; /* Mallocated whole event */ | |
461 | int event_len; /* Its size */ | |
462 | int hdr_len; /* Size of the event header */ | |
463 | int wrqu_off = 0; /* Offset in wrqu */ | |
464 | /* Don't "optimise" the following variable, it will crash */ | |
95c96174 | 465 | unsigned int cmd_index; /* *MUST* be unsigned */ |
3d23e349 JB |
466 | struct sk_buff *skb; |
467 | struct nlmsghdr *nlh; | |
468 | struct nlattr *nla; | |
469 | #ifdef CONFIG_COMPAT | |
470 | struct __compat_iw_event *compat_event; | |
471 | struct compat_iw_point compat_wrqu; | |
472 | struct sk_buff *compskb; | |
473 | #endif | |
84149b0f | 474 | |
3d23e349 JB |
475 | /* |
476 | * Nothing in the kernel sends scan events with data, be safe. | |
477 | * This is necessary because we cannot fix up scan event data | |
478 | * for compat, due to being contained in 'extra', but normally | |
479 | * applications are required to retrieve the scan data anyway | |
480 | * and no data is included in the event, this codifies that | |
481 | * practice. | |
84149b0f | 482 | */ |
3d23e349 JB |
483 | if (WARN_ON(cmd == SIOCGIWSCAN && extra)) |
484 | extra = NULL; | |
84149b0f | 485 | |
3d23e349 JB |
486 | /* Get the description of the Event */ |
487 | if (cmd <= SIOCIWLAST) { | |
44608f80 | 488 | cmd_index = IW_IOCTL_IDX(cmd); |
3d23e349 JB |
489 | if (cmd_index < standard_ioctl_num) |
490 | descr = &(standard_ioctl[cmd_index]); | |
491 | } else { | |
76326f1d | 492 | cmd_index = IW_EVENT_IDX(cmd); |
3d23e349 JB |
493 | if (cmd_index < standard_event_num) |
494 | descr = &(standard_event[cmd_index]); | |
495 | } | |
496 | /* Don't accept unknown events */ | |
497 | if (descr == NULL) { | |
498 | /* Note : we don't return an error to the driver, because | |
499 | * the driver would not know what to do about it. It can't | |
500 | * return an error to the user, because the event is not | |
501 | * initiated by a user request. | |
502 | * The best the driver could do is to log an error message. | |
503 | * We will do it ourselves instead... | |
504 | */ | |
e9c0268f JP |
505 | netdev_err(dev, "(WE) : Invalid/Unknown Wireless Event (0x%04X)\n", |
506 | cmd); | |
3d23e349 JB |
507 | return; |
508 | } | |
509 | ||
510 | /* Check extra parameters and set extra_len */ | |
511 | if (descr->header_type == IW_HEADER_TYPE_POINT) { | |
512 | /* Check if number of token fits within bounds */ | |
513 | if (wrqu->data.length > descr->max_tokens) { | |
e5f5b2fb AS |
514 | netdev_err(dev, "(WE) : Wireless Event (cmd=0x%04X) too big (%d)\n", |
515 | cmd, wrqu->data.length); | |
3d23e349 JB |
516 | return; |
517 | } | |
518 | if (wrqu->data.length < descr->min_tokens) { | |
e5f5b2fb AS |
519 | netdev_err(dev, "(WE) : Wireless Event (cmd=0x%04X) too small (%d)\n", |
520 | cmd, wrqu->data.length); | |
3d23e349 JB |
521 | return; |
522 | } | |
523 | /* Calculate extra_len - extra is NULL for restricted events */ | |
524 | if (extra != NULL) | |
525 | extra_len = wrqu->data.length * descr->token_size; | |
526 | /* Always at an offset in wrqu */ | |
527 | wrqu_off = IW_EV_POINT_OFF; | |
528 | } | |
529 | ||
530 | /* Total length of the event */ | |
531 | hdr_len = event_type_size[descr->header_type]; | |
532 | event_len = hdr_len + extra_len; | |
533 | ||
534 | /* | |
535 | * The problem for 64/32 bit. | |
536 | * | |
537 | * On 64-bit, a regular event is laid out as follows: | |
538 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | | |
539 | * | event.len | event.cmd | p a d d i n g | | |
540 | * | wrqu data ... (with the correct size) | | |
541 | * | |
542 | * This padding exists because we manipulate event->u, | |
543 | * and 'event' is not packed. | |
544 | * | |
545 | * An iw_point event is laid out like this instead: | |
546 | * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | | |
547 | * | event.len | event.cmd | p a d d i n g | | |
548 | * | iwpnt.len | iwpnt.flg | p a d d i n g | | |
549 | * | extra data ... | |
550 | * | |
551 | * The second padding exists because struct iw_point is extended, | |
552 | * but this depends on the platform... | |
553 | * | |
554 | * On 32-bit, all the padding shouldn't be there. | |
555 | */ | |
556 | ||
557 | skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); | |
558 | if (!skb) | |
559 | return; | |
560 | ||
561 | /* Send via the RtNetlink event channel */ | |
562 | nlh = rtnetlink_ifinfo_prep(dev, skb); | |
563 | if (WARN_ON(!nlh)) { | |
564 | kfree_skb(skb); | |
565 | return; | |
566 | } | |
567 | ||
568 | /* Add the wireless events in the netlink packet */ | |
569 | nla = nla_reserve(skb, IFLA_WIRELESS, event_len); | |
570 | if (!nla) { | |
571 | kfree_skb(skb); | |
572 | return; | |
573 | } | |
574 | event = nla_data(nla); | |
575 | ||
576 | /* Fill event - first clear to avoid data leaking */ | |
577 | memset(event, 0, hdr_len); | |
578 | event->len = event_len; | |
579 | event->cmd = cmd; | |
580 | memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN); | |
581 | if (extra_len) | |
582 | memcpy(((char *) event) + hdr_len, extra, extra_len); | |
583 | ||
584 | nlmsg_end(skb, nlh); | |
585 | #ifdef CONFIG_COMPAT | |
586 | hdr_len = compat_event_type_size[descr->header_type]; | |
587 | event_len = hdr_len + extra_len; | |
588 | ||
589 | compskb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); | |
590 | if (!compskb) { | |
591 | kfree_skb(skb); | |
592 | return; | |
593 | } | |
594 | ||
595 | /* Send via the RtNetlink event channel */ | |
596 | nlh = rtnetlink_ifinfo_prep(dev, compskb); | |
597 | if (WARN_ON(!nlh)) { | |
598 | kfree_skb(skb); | |
599 | kfree_skb(compskb); | |
600 | return; | |
601 | } | |
602 | ||
603 | /* Add the wireless events in the netlink packet */ | |
604 | nla = nla_reserve(compskb, IFLA_WIRELESS, event_len); | |
605 | if (!nla) { | |
606 | kfree_skb(skb); | |
607 | kfree_skb(compskb); | |
608 | return; | |
609 | } | |
610 | compat_event = nla_data(nla); | |
611 | ||
612 | compat_event->len = event_len; | |
613 | compat_event->cmd = cmd; | |
614 | if (descr->header_type == IW_HEADER_TYPE_POINT) { | |
615 | compat_wrqu.length = wrqu->data.length; | |
616 | compat_wrqu.flags = wrqu->data.flags; | |
617 | memcpy(&compat_event->pointer, | |
618 | ((char *) &compat_wrqu) + IW_EV_COMPAT_POINT_OFF, | |
619 | hdr_len - IW_EV_COMPAT_LCP_LEN); | |
620 | if (extra_len) | |
621 | memcpy(((char *) compat_event) + hdr_len, | |
622 | extra, extra_len); | |
623 | } else { | |
624 | /* extra_len must be zero, so no if (extra) needed */ | |
625 | memcpy(&compat_event->pointer, wrqu, | |
626 | hdr_len - IW_EV_COMPAT_LCP_LEN); | |
627 | } | |
628 | ||
629 | nlmsg_end(compskb, nlh); | |
630 | ||
631 | skb_shinfo(skb)->frag_list = compskb; | |
632 | #endif | |
633 | skb_queue_tail(&dev_net(dev)->wext_nlevents, skb); | |
634 | schedule_work(&wireless_nlevent_work); | |
635 | } | |
636 | EXPORT_SYMBOL(wireless_send_event); | |
637 | ||
638 | ||
639 | ||
640 | /* IW handlers */ | |
641 | ||
642 | struct iw_statistics *get_wireless_stats(struct net_device *dev) | |
643 | { | |
644 | #ifdef CONFIG_WIRELESS_EXT | |
645 | if ((dev->wireless_handlers != NULL) && | |
646 | (dev->wireless_handlers->get_wireless_stats != NULL)) | |
647 | return dev->wireless_handlers->get_wireless_stats(dev); | |
648 | #endif | |
649 | ||
650 | #ifdef CONFIG_CFG80211_WEXT | |
36539107 | 651 | if (dev->ieee80211_ptr && |
3d23e349 JB |
652 | dev->ieee80211_ptr->wiphy && |
653 | dev->ieee80211_ptr->wiphy->wext && | |
654 | dev->ieee80211_ptr->wiphy->wext->get_wireless_stats) | |
655 | return dev->ieee80211_ptr->wiphy->wext->get_wireless_stats(dev); | |
656 | #endif | |
657 | ||
658 | /* not found */ | |
659 | return NULL; | |
660 | } | |
661 | ||
662 | static int iw_handler_get_iwstats(struct net_device * dev, | |
663 | struct iw_request_info * info, | |
664 | union iwreq_data * wrqu, | |
665 | char * extra) | |
666 | { | |
667 | /* Get stats from the driver */ | |
668 | struct iw_statistics *stats; | |
669 | ||
670 | stats = get_wireless_stats(dev); | |
671 | if (stats) { | |
672 | /* Copy statistics to extra */ | |
673 | memcpy(extra, stats, sizeof(struct iw_statistics)); | |
674 | wrqu->data.length = sizeof(struct iw_statistics); | |
675 | ||
676 | /* Check if we need to clear the updated flag */ | |
677 | if (wrqu->data.flags != 0) | |
678 | stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; | |
679 | return 0; | |
680 | } else | |
681 | return -EOPNOTSUPP; | |
682 | } | |
683 | ||
684 | static iw_handler get_handler(struct net_device *dev, unsigned int cmd) | |
685 | { | |
686 | /* Don't "optimise" the following variable, it will crash */ | |
687 | unsigned int index; /* *MUST* be unsigned */ | |
688 | const struct iw_handler_def *handlers = NULL; | |
689 | ||
690 | #ifdef CONFIG_CFG80211_WEXT | |
691 | if (dev->ieee80211_ptr && dev->ieee80211_ptr->wiphy) | |
692 | handlers = dev->ieee80211_ptr->wiphy->wext; | |
693 | #endif | |
694 | #ifdef CONFIG_WIRELESS_EXT | |
695 | if (dev->wireless_handlers) | |
696 | handlers = dev->wireless_handlers; | |
697 | #endif | |
698 | ||
699 | if (!handlers) | |
700 | return NULL; | |
701 | ||
702 | /* Try as a standard command */ | |
44608f80 | 703 | index = IW_IOCTL_IDX(cmd); |
3d23e349 JB |
704 | if (index < handlers->num_standard) |
705 | return handlers->standard[index]; | |
706 | ||
707 | #ifdef CONFIG_WEXT_PRIV | |
708 | /* Try as a private command */ | |
709 | index = cmd - SIOCIWFIRSTPRIV; | |
710 | if (index < handlers->num_private) | |
711 | return handlers->private[index]; | |
712 | #endif | |
713 | ||
714 | /* Not found */ | |
715 | return NULL; | |
716 | } | |
717 | ||
718 | static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd, | |
719 | const struct iw_ioctl_description *descr, | |
720 | iw_handler handler, struct net_device *dev, | |
721 | struct iw_request_info *info) | |
722 | { | |
723 | int err, extra_size, user_length = 0, essid_compat = 0; | |
724 | char *extra; | |
725 | ||
726 | /* Calculate space needed by arguments. Always allocate | |
727 | * for max space. | |
728 | */ | |
729 | extra_size = descr->max_tokens * descr->token_size; | |
730 | ||
731 | /* Check need for ESSID compatibility for WE < 21 */ | |
732 | switch (cmd) { | |
84149b0f DM |
733 | case SIOCSIWESSID: |
734 | case SIOCGIWESSID: | |
735 | case SIOCSIWNICKN: | |
736 | case SIOCGIWNICKN: | |
737 | if (iwp->length == descr->max_tokens + 1) | |
738 | essid_compat = 1; | |
739 | else if (IW_IS_SET(cmd) && (iwp->length != 0)) { | |
740 | char essid[IW_ESSID_MAX_SIZE + 1]; | |
8503bd8c AV |
741 | unsigned int len; |
742 | len = iwp->length * descr->token_size; | |
84149b0f | 743 | |
8503bd8c AV |
744 | if (len > IW_ESSID_MAX_SIZE) |
745 | return -EFAULT; | |
746 | ||
747 | err = copy_from_user(essid, iwp->pointer, len); | |
84149b0f DM |
748 | if (err) |
749 | return -EFAULT; | |
750 | ||
751 | if (essid[iwp->length - 1] == '\0') | |
752 | essid_compat = 1; | |
753 | } | |
754 | break; | |
755 | default: | |
756 | break; | |
757 | } | |
758 | ||
759 | iwp->length -= essid_compat; | |
760 | ||
761 | /* Check what user space is giving us */ | |
762 | if (IW_IS_SET(cmd)) { | |
763 | /* Check NULL pointer */ | |
764 | if (!iwp->pointer && iwp->length != 0) | |
765 | return -EFAULT; | |
766 | /* Check if number of token fits within bounds */ | |
767 | if (iwp->length > descr->max_tokens) | |
768 | return -E2BIG; | |
769 | if (iwp->length < descr->min_tokens) | |
770 | return -EINVAL; | |
771 | } else { | |
772 | /* Check NULL pointer */ | |
773 | if (!iwp->pointer) | |
774 | return -EFAULT; | |
775 | /* Save user space buffer size for checking */ | |
776 | user_length = iwp->length; | |
777 | ||
778 | /* Don't check if user_length > max to allow forward | |
779 | * compatibility. The test user_length < min is | |
780 | * implied by the test at the end. | |
781 | */ | |
782 | ||
783 | /* Support for very large requests */ | |
784 | if ((descr->flags & IW_DESCR_FLAG_NOMAX) && | |
785 | (user_length > descr->max_tokens)) { | |
786 | /* Allow userspace to GET more than max so | |
787 | * we can support any size GET requests. | |
788 | * There is still a limit : -ENOMEM. | |
789 | */ | |
790 | extra_size = user_length * descr->token_size; | |
791 | ||
792 | /* Note : user_length is originally a __u16, | |
793 | * and token_size is controlled by us, | |
794 | * so extra_size won't get negative and | |
795 | * won't overflow... | |
796 | */ | |
797 | } | |
798 | } | |
799 | ||
800 | /* kzalloc() ensures NULL-termination for essid_compat. */ | |
801 | extra = kzalloc(extra_size, GFP_KERNEL); | |
802 | if (!extra) | |
803 | return -ENOMEM; | |
804 | ||
805 | /* If it is a SET, get all the extra data in here */ | |
806 | if (IW_IS_SET(cmd) && (iwp->length != 0)) { | |
807 | if (copy_from_user(extra, iwp->pointer, | |
808 | iwp->length * | |
809 | descr->token_size)) { | |
810 | err = -EFAULT; | |
811 | goto out; | |
812 | } | |
88f16db7 JB |
813 | |
814 | if (cmd == SIOCSIWENCODEEXT) { | |
815 | struct iw_encode_ext *ee = (void *) extra; | |
816 | ||
7ab2485b JL |
817 | if (iwp->length < sizeof(*ee) + ee->key_len) { |
818 | err = -EFAULT; | |
819 | goto out; | |
820 | } | |
88f16db7 | 821 | } |
84149b0f DM |
822 | } |
823 | ||
42da2f94 JB |
824 | if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) { |
825 | /* | |
826 | * If this is a GET, but not NOMAX, it means that the extra | |
827 | * data is not bounded by userspace, but by max_tokens. Thus | |
828 | * set the length to max_tokens. This matches the extra data | |
829 | * allocation. | |
830 | * The driver should fill it with the number of tokens it | |
831 | * provided, and it may check iwp->length rather than having | |
832 | * knowledge of max_tokens. If the driver doesn't change the | |
833 | * iwp->length, this ioctl just copies back max_token tokens | |
834 | * filled with zeroes. Hopefully the driver isn't claiming | |
835 | * them to be valid data. | |
836 | */ | |
837 | iwp->length = descr->max_tokens; | |
838 | } | |
839 | ||
84149b0f DM |
840 | err = handler(dev, info, (union iwreq_data *) iwp, extra); |
841 | ||
842 | iwp->length += essid_compat; | |
843 | ||
844 | /* If we have something to return to the user */ | |
845 | if (!err && IW_IS_GET(cmd)) { | |
846 | /* Check if there is enough buffer up there */ | |
847 | if (user_length < iwp->length) { | |
848 | err = -E2BIG; | |
849 | goto out; | |
850 | } | |
851 | ||
852 | if (copy_to_user(iwp->pointer, extra, | |
853 | iwp->length * | |
854 | descr->token_size)) { | |
855 | err = -EFAULT; | |
856 | goto out; | |
857 | } | |
858 | } | |
859 | ||
860 | /* Generate an event to notify listeners of the change */ | |
1014eb6e JT |
861 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && |
862 | ((err == 0) || (err == -EIWCOMMIT))) { | |
84149b0f DM |
863 | union iwreq_data *data = (union iwreq_data *) iwp; |
864 | ||
865 | if (descr->flags & IW_DESCR_FLAG_RESTRICT) | |
866 | /* If the event is restricted, don't | |
867 | * export the payload. | |
868 | */ | |
869 | wireless_send_event(dev, cmd, data, NULL); | |
870 | else | |
871 | wireless_send_event(dev, cmd, data, extra); | |
872 | } | |
873 | ||
874 | out: | |
875 | kfree(extra); | |
876 | return err; | |
877 | } | |
878 | ||
1da177e4 | 879 | /* |
3d23e349 JB |
880 | * Call the commit handler in the driver |
881 | * (if exist and if conditions are right) | |
882 | * | |
883 | * Note : our current commit strategy is currently pretty dumb, | |
884 | * but we will be able to improve on that... | |
885 | * The goal is to try to agreagate as many changes as possible | |
886 | * before doing the commit. Drivers that will define a commit handler | |
887 | * are usually those that need a reset after changing parameters, so | |
888 | * we want to minimise the number of reset. | |
889 | * A cool idea is to use a timer : at each "set" command, we re-set the | |
890 | * timer, when the timer eventually fires, we call the driver. | |
891 | * Hopefully, more on that later. | |
892 | * | |
893 | * Also, I'm waiting to see how many people will complain about the | |
894 | * netif_running(dev) test. I'm open on that one... | |
895 | * Hopefully, the driver will remember to do a commit in "open()" ;-) | |
1da177e4 | 896 | */ |
3d23e349 | 897 | int call_commit_handler(struct net_device *dev) |
1da177e4 | 898 | { |
3d23e349 JB |
899 | #ifdef CONFIG_WIRELESS_EXT |
900 | if ((netif_running(dev)) && | |
901 | (dev->wireless_handlers->standard[0] != NULL)) | |
902 | /* Call the commit handler on the driver */ | |
903 | return dev->wireless_handlers->standard[0](dev, NULL, | |
904 | NULL, NULL); | |
905 | else | |
906 | return 0; /* Command completed successfully */ | |
907 | #else | |
908 | /* cfg80211 has no commit */ | |
909 | return 0; | |
910 | #endif | |
1da177e4 LT |
911 | } |
912 | ||
1da177e4 | 913 | /* |
295f4a1f | 914 | * Main IOCTl dispatcher. |
1da177e4 LT |
915 | * Check the type of IOCTL and call the appropriate wrapper... |
916 | */ | |
ca1e8bb8 DM |
917 | static int wireless_process_ioctl(struct net *net, struct ifreq *ifr, |
918 | unsigned int cmd, | |
0f5cabba | 919 | struct iw_request_info *info, |
ca1e8bb8 DM |
920 | wext_ioctl_func standard, |
921 | wext_ioctl_func private) | |
1da177e4 | 922 | { |
d2911255 | 923 | struct iwreq *iwr = (struct iwreq *) ifr; |
1da177e4 LT |
924 | struct net_device *dev; |
925 | iw_handler handler; | |
926 | ||
927 | /* Permissions are already checked in dev_ioctl() before calling us. | |
928 | * The copy_to/from_user() of ifr is also dealt with in there */ | |
929 | ||
930 | /* Make sure the device exist */ | |
881d966b | 931 | if ((dev = __dev_get_by_name(net, ifr->ifr_name)) == NULL) |
1da177e4 LT |
932 | return -ENODEV; |
933 | ||
934 | /* A bunch of special cases, then the generic case... | |
935 | * Note that 'cmd' is already filtered in dev_ioctl() with | |
936 | * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */ | |
dd8ceabc | 937 | if (cmd == SIOCGIWSTATS) |
0f5cabba | 938 | return standard(dev, iwr, cmd, info, |
ca1e8bb8 | 939 | &iw_handler_get_iwstats); |
e71a4783 | 940 | |
3d23e349 | 941 | #ifdef CONFIG_WEXT_PRIV |
dd8ceabc | 942 | if (cmd == SIOCGIWPRIV && dev->wireless_handlers) |
0f5cabba | 943 | return standard(dev, iwr, cmd, info, |
3d23e349 JB |
944 | iw_handler_get_private); |
945 | #endif | |
dd8ceabc JB |
946 | |
947 | /* Basic check */ | |
948 | if (!netif_device_present(dev)) | |
949 | return -ENODEV; | |
950 | ||
951 | /* New driver API : try to find the handler */ | |
952 | handler = get_handler(dev, cmd); | |
953 | if (handler) { | |
954 | /* Standard and private are not the same */ | |
955 | if (cmd < SIOCIWFIRSTPRIV) | |
0f5cabba | 956 | return standard(dev, iwr, cmd, info, handler); |
3d23e349 | 957 | else if (private) |
0f5cabba | 958 | return private(dev, iwr, cmd, info, handler); |
1da177e4 | 959 | } |
dd8ceabc | 960 | /* Old driver API : call driver ioctl handler */ |
3d5fdff4 PM |
961 | if (dev->netdev_ops->ndo_do_ioctl) { |
962 | #ifdef CONFIG_COMPAT | |
963 | if (info->flags & IW_REQUEST_FLAG_COMPAT) { | |
964 | int ret = 0; | |
965 | struct iwreq iwr_lcl; | |
966 | struct compat_iw_point *iwp_compat = (void *) &iwr->u.data; | |
967 | ||
968 | memcpy(&iwr_lcl, iwr, sizeof(struct iwreq)); | |
969 | iwr_lcl.u.data.pointer = compat_ptr(iwp_compat->pointer); | |
970 | iwr_lcl.u.data.length = iwp_compat->length; | |
971 | iwr_lcl.u.data.flags = iwp_compat->flags; | |
972 | ||
973 | ret = dev->netdev_ops->ndo_do_ioctl(dev, (void *) &iwr_lcl, cmd); | |
974 | ||
975 | iwp_compat->pointer = ptr_to_compat(iwr_lcl.u.data.pointer); | |
976 | iwp_compat->length = iwr_lcl.u.data.length; | |
977 | iwp_compat->flags = iwr_lcl.u.data.flags; | |
978 | ||
979 | return ret; | |
980 | } else | |
981 | #endif | |
982 | return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd); | |
983 | } | |
dd8ceabc | 984 | return -EOPNOTSUPP; |
1da177e4 LT |
985 | } |
986 | ||
67dd7608 DM |
987 | /* If command is `set a parameter', or `get the encoding parameters', |
988 | * check if the user has the right to do it. | |
989 | */ | |
990 | static int wext_permission_check(unsigned int cmd) | |
991 | { | |
f64f9e71 JP |
992 | if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || |
993 | cmd == SIOCGIWENCODEEXT) && | |
994 | !capable(CAP_NET_ADMIN)) | |
67dd7608 DM |
995 | return -EPERM; |
996 | ||
997 | return 0; | |
998 | } | |
999 | ||
295f4a1f | 1000 | /* entry point from dev ioctl */ |
a67fa76d | 1001 | static int wext_ioctl_dispatch(struct net *net, struct ifreq *ifr, |
0f5cabba | 1002 | unsigned int cmd, struct iw_request_info *info, |
a67fa76d DM |
1003 | wext_ioctl_func standard, |
1004 | wext_ioctl_func private) | |
295f4a1f | 1005 | { |
67dd7608 | 1006 | int ret = wext_permission_check(cmd); |
295f4a1f | 1007 | |
67dd7608 DM |
1008 | if (ret) |
1009 | return ret; | |
dd8ceabc | 1010 | |
881d966b | 1011 | dev_load(net, ifr->ifr_name); |
295f4a1f | 1012 | rtnl_lock(); |
0f5cabba | 1013 | ret = wireless_process_ioctl(net, ifr, cmd, info, standard, private); |
295f4a1f | 1014 | rtnl_unlock(); |
a67fa76d DM |
1015 | |
1016 | return ret; | |
1017 | } | |
1018 | ||
3d23e349 JB |
1019 | /* |
1020 | * Wrapper to call a standard Wireless Extension handler. | |
1021 | * We do various checks and also take care of moving data between | |
1022 | * user space and kernel space. | |
1023 | */ | |
1024 | static int ioctl_standard_call(struct net_device * dev, | |
1025 | struct iwreq *iwr, | |
1026 | unsigned int cmd, | |
1027 | struct iw_request_info *info, | |
1028 | iw_handler handler) | |
1029 | { | |
1030 | const struct iw_ioctl_description * descr; | |
1031 | int ret = -EINVAL; | |
1032 | ||
1033 | /* Get the description of the IOCTL */ | |
44608f80 | 1034 | if (IW_IOCTL_IDX(cmd) >= standard_ioctl_num) |
3d23e349 | 1035 | return -EOPNOTSUPP; |
44608f80 | 1036 | descr = &(standard_ioctl[IW_IOCTL_IDX(cmd)]); |
3d23e349 JB |
1037 | |
1038 | /* Check if we have a pointer to user space data or not */ | |
1039 | if (descr->header_type != IW_HEADER_TYPE_POINT) { | |
1040 | ||
1041 | /* No extra arguments. Trivial to handle */ | |
1042 | ret = handler(dev, info, &(iwr->u), NULL); | |
1043 | ||
1044 | /* Generate an event to notify listeners of the change */ | |
1045 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && | |
1046 | ((ret == 0) || (ret == -EIWCOMMIT))) | |
1047 | wireless_send_event(dev, cmd, &(iwr->u), NULL); | |
1048 | } else { | |
1049 | ret = ioctl_standard_iw_point(&iwr->u.data, cmd, descr, | |
1050 | handler, dev, info); | |
1051 | } | |
1052 | ||
1053 | /* Call commit handler if needed and defined */ | |
1054 | if (ret == -EIWCOMMIT) | |
1055 | ret = call_commit_handler(dev); | |
1056 | ||
1057 | /* Here, we will generate the appropriate event if needed */ | |
1058 | ||
1059 | return ret; | |
1060 | } | |
1061 | ||
1062 | ||
a67fa76d DM |
1063 | int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd, |
1064 | void __user *arg) | |
1065 | { | |
0f5cabba DM |
1066 | struct iw_request_info info = { .cmd = cmd, .flags = 0 }; |
1067 | int ret; | |
a67fa76d | 1068 | |
0f5cabba DM |
1069 | ret = wext_ioctl_dispatch(net, ifr, cmd, &info, |
1070 | ioctl_standard_call, | |
1071 | ioctl_private_call); | |
a67fa76d DM |
1072 | if (ret >= 0 && |
1073 | IW_IS_GET(cmd) && | |
1074 | copy_to_user(arg, ifr, sizeof(struct iwreq))) | |
295f4a1f | 1075 | return -EFAULT; |
a67fa76d | 1076 | |
295f4a1f JB |
1077 | return ret; |
1078 | } | |
711e2c33 | 1079 | |
87de87d5 DM |
1080 | #ifdef CONFIG_COMPAT |
1081 | static int compat_standard_call(struct net_device *dev, | |
1082 | struct iwreq *iwr, | |
1083 | unsigned int cmd, | |
0f5cabba | 1084 | struct iw_request_info *info, |
87de87d5 DM |
1085 | iw_handler handler) |
1086 | { | |
1087 | const struct iw_ioctl_description *descr; | |
1088 | struct compat_iw_point *iwp_compat; | |
87de87d5 DM |
1089 | struct iw_point iwp; |
1090 | int err; | |
1091 | ||
44608f80 | 1092 | descr = standard_ioctl + IW_IOCTL_IDX(cmd); |
87de87d5 DM |
1093 | |
1094 | if (descr->header_type != IW_HEADER_TYPE_POINT) | |
0f5cabba | 1095 | return ioctl_standard_call(dev, iwr, cmd, info, handler); |
87de87d5 DM |
1096 | |
1097 | iwp_compat = (struct compat_iw_point *) &iwr->u.data; | |
1098 | iwp.pointer = compat_ptr(iwp_compat->pointer); | |
1099 | iwp.length = iwp_compat->length; | |
1100 | iwp.flags = iwp_compat->flags; | |
1101 | ||
0f5cabba | 1102 | err = ioctl_standard_iw_point(&iwp, cmd, descr, handler, dev, info); |
87de87d5 DM |
1103 | |
1104 | iwp_compat->pointer = ptr_to_compat(iwp.pointer); | |
1105 | iwp_compat->length = iwp.length; | |
1106 | iwp_compat->flags = iwp.flags; | |
1107 | ||
1108 | return err; | |
1109 | } | |
1110 | ||
87de87d5 DM |
1111 | int compat_wext_handle_ioctl(struct net *net, unsigned int cmd, |
1112 | unsigned long arg) | |
1113 | { | |
1114 | void __user *argp = (void __user *)arg; | |
0f5cabba | 1115 | struct iw_request_info info; |
87de87d5 DM |
1116 | struct iwreq iwr; |
1117 | char *colon; | |
1118 | int ret; | |
1119 | ||
1120 | if (copy_from_user(&iwr, argp, sizeof(struct iwreq))) | |
1121 | return -EFAULT; | |
1122 | ||
1123 | iwr.ifr_name[IFNAMSIZ-1] = 0; | |
1124 | colon = strchr(iwr.ifr_name, ':'); | |
1125 | if (colon) | |
1126 | *colon = 0; | |
1127 | ||
0f5cabba DM |
1128 | info.cmd = cmd; |
1129 | info.flags = IW_REQUEST_FLAG_COMPAT; | |
1130 | ||
1131 | ret = wext_ioctl_dispatch(net, (struct ifreq *) &iwr, cmd, &info, | |
87de87d5 DM |
1132 | compat_standard_call, |
1133 | compat_private_call); | |
1134 | ||
1135 | if (ret >= 0 && | |
1136 | IW_IS_GET(cmd) && | |
1137 | copy_to_user(argp, &iwr, sizeof(struct iwreq))) | |
1138 | return -EFAULT; | |
1139 | ||
1140 | return ret; | |
1141 | } | |
1142 | #endif |