Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file implement the Wireless Extensions APIs. |
| 3 | * |
| 4 | * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com> |
Jean Tourrilhes | c2805fb | 2007-03-23 00:31:16 +0000 | [diff] [blame] | 5 | * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * (As all part of the Linux kernel, this file is GPL) |
| 8 | */ |
| 9 | |
| 10 | /************************** DOCUMENTATION **************************/ |
| 11 | /* |
| 12 | * API definition : |
| 13 | * -------------- |
| 14 | * See <linux/wireless.h> for details of the APIs and the rest. |
| 15 | * |
| 16 | * History : |
| 17 | * ------- |
| 18 | * |
| 19 | * v1 - 5.12.01 - Jean II |
| 20 | * o Created this file. |
| 21 | * |
| 22 | * v2 - 13.12.01 - Jean II |
| 23 | * o Move /proc/net/wireless stuff from net/core/dev.c to here |
| 24 | * o Make Wireless Extension IOCTLs go through here |
| 25 | * o Added iw_handler handling ;-) |
| 26 | * o Added standard ioctl description |
| 27 | * o Initial dumb commit strategy based on orinoco.c |
| 28 | * |
| 29 | * v3 - 19.12.01 - Jean II |
| 30 | * o Make sure we don't go out of standard_ioctl[] in ioctl_standard_call |
| 31 | * o Add event dispatcher function |
| 32 | * o Add event description |
| 33 | * o Propagate events as rtnetlink IFLA_WIRELESS option |
| 34 | * o Generate event on selected SET requests |
| 35 | * |
| 36 | * v4 - 18.04.02 - Jean II |
| 37 | * o Fix stupid off by one in iw_ioctl_description : IW_ESSID_MAX_SIZE + 1 |
| 38 | * |
| 39 | * v5 - 21.06.02 - Jean II |
| 40 | * o Add IW_PRIV_TYPE_ADDR in priv_type_size (+cleanup) |
| 41 | * o Reshuffle IW_HEADER_TYPE_XXX to map IW_PRIV_TYPE_XXX changes |
| 42 | * o Add IWEVCUSTOM for driver specific event/scanning token |
| 43 | * o Turn on WE_STRICT_WRITE by default + kernel warning |
| 44 | * o Fix WE_STRICT_WRITE in ioctl_export_private() (32 => iw_num) |
| 45 | * o Fix off-by-one in test (extra_size <= IFNAMSIZ) |
| 46 | * |
| 47 | * v6 - 9.01.03 - Jean II |
| 48 | * o Add common spy support : iw_handler_set_spy(), wireless_spy_update() |
| 49 | * o Add enhanced spy support : iw_handler_set_thrspy() and event. |
| 50 | * o Add WIRELESS_EXT version display in /proc/net/wireless |
| 51 | * |
| 52 | * v6 - 18.06.04 - Jean II |
| 53 | * o Change get_spydata() method for added safety |
| 54 | * o Remove spy #ifdef, they are always on -> cleaner code |
| 55 | * o Allow any size GET request if user specifies length > max |
| 56 | * and if request has IW_DESCR_FLAG_NOMAX flag or is SIOCGIWPRIV |
| 57 | * o Start migrating get_wireless_stats to struct iw_handler_def |
| 58 | * o Add wmb() in iw_handler_set_spy() for non-coherent archs/cpus |
| 59 | * Based on patch from Pavel Roskin <proski@gnu.org> : |
| 60 | * o Fix kernel data leak to user space in private handler handling |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 61 | * |
| 62 | * v7 - 18.3.05 - Jean II |
| 63 | * o Remove (struct iw_point *)->pointer from events and streams |
| 64 | * o Remove spy_offset from struct iw_handler_def |
| 65 | * o Start deprecating dev->get_wireless_stats, output a warning |
| 66 | * o If IW_QUAL_DBM is set, show dBm values in /proc/net/wireless |
| 67 | * o Don't loose INVALID/DBM flags when clearing UPDATED flags (iwstats) |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 68 | * |
| 69 | * v8 - 17.02.06 - Jean II |
| 70 | * o RtNetlink requests support (SET/GET) |
John W. Linville | baef186 | 2006-09-08 16:04:05 -0400 | [diff] [blame] | 71 | * |
| 72 | * v8b - 03.08.06 - Herbert Xu |
| 73 | * o Fix Wireless Event locking issues. |
| 74 | * |
| 75 | * v9 - 14.3.06 - Jean II |
| 76 | * o Change length in ESSID and NICK to strlen() instead of strlen()+1 |
| 77 | * o Make standard_ioctl_num and standard_event_num unsigned |
| 78 | * o Remove (struct net_device *)->get_wireless_stats() |
Jean Tourrilhes | c2805fb | 2007-03-23 00:31:16 +0000 | [diff] [blame] | 79 | * |
| 80 | * v10 - 16.3.07 - Jean II |
| 81 | * o Prevent leaking of kernel space in stream on 64 bits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | */ |
| 83 | |
| 84 | /***************************** INCLUDES *****************************/ |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #include <linux/module.h> |
| 87 | #include <linux/types.h> /* off_t */ |
| 88 | #include <linux/netdevice.h> /* struct ifreq, dev_get_by_name() */ |
| 89 | #include <linux/proc_fs.h> |
| 90 | #include <linux/rtnetlink.h> /* rtnetlink stuff */ |
| 91 | #include <linux/seq_file.h> |
| 92 | #include <linux/init.h> /* for __init */ |
| 93 | #include <linux/if_arp.h> /* ARPHRD_ETHER */ |
Linus Torvalds | 9819d85 | 2006-01-10 19:35:19 -0800 | [diff] [blame] | 94 | #include <linux/etherdevice.h> /* compare_ether_addr */ |
Herbert Xu | 782a667 | 2006-08-03 23:54:41 +1000 | [diff] [blame] | 95 | #include <linux/interrupt.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 96 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | #include <linux/wireless.h> /* Pretty obvious */ |
| 99 | #include <net/iw_handler.h> /* New driver API */ |
Thomas Graf | bd5785b | 2006-08-15 00:36:49 -0700 | [diff] [blame] | 100 | #include <net/netlink.h> |
Johannes Berg | 295f4a1 | 2007-04-26 20:43:56 -0700 | [diff] [blame] | 101 | #include <net/wext.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | #include <asm/uaccess.h> /* copy_to_user() */ |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /************************* GLOBAL VARIABLES *************************/ |
| 106 | /* |
| 107 | * You should not use global variables, because of re-entrancy. |
| 108 | * On our case, it's only const, so it's OK... |
| 109 | */ |
| 110 | /* |
| 111 | * Meta-data about all the standard Wireless Extension request we |
| 112 | * know about. |
| 113 | */ |
| 114 | static const struct iw_ioctl_description standard_ioctl[] = { |
| 115 | [SIOCSIWCOMMIT - SIOCIWFIRST] = { |
| 116 | .header_type = IW_HEADER_TYPE_NULL, |
| 117 | }, |
| 118 | [SIOCGIWNAME - SIOCIWFIRST] = { |
| 119 | .header_type = IW_HEADER_TYPE_CHAR, |
| 120 | .flags = IW_DESCR_FLAG_DUMP, |
| 121 | }, |
| 122 | [SIOCSIWNWID - SIOCIWFIRST] = { |
| 123 | .header_type = IW_HEADER_TYPE_PARAM, |
| 124 | .flags = IW_DESCR_FLAG_EVENT, |
| 125 | }, |
| 126 | [SIOCGIWNWID - SIOCIWFIRST] = { |
| 127 | .header_type = IW_HEADER_TYPE_PARAM, |
| 128 | .flags = IW_DESCR_FLAG_DUMP, |
| 129 | }, |
| 130 | [SIOCSIWFREQ - SIOCIWFIRST] = { |
| 131 | .header_type = IW_HEADER_TYPE_FREQ, |
| 132 | .flags = IW_DESCR_FLAG_EVENT, |
| 133 | }, |
| 134 | [SIOCGIWFREQ - SIOCIWFIRST] = { |
| 135 | .header_type = IW_HEADER_TYPE_FREQ, |
| 136 | .flags = IW_DESCR_FLAG_DUMP, |
| 137 | }, |
| 138 | [SIOCSIWMODE - SIOCIWFIRST] = { |
| 139 | .header_type = IW_HEADER_TYPE_UINT, |
| 140 | .flags = IW_DESCR_FLAG_EVENT, |
| 141 | }, |
| 142 | [SIOCGIWMODE - SIOCIWFIRST] = { |
| 143 | .header_type = IW_HEADER_TYPE_UINT, |
| 144 | .flags = IW_DESCR_FLAG_DUMP, |
| 145 | }, |
| 146 | [SIOCSIWSENS - SIOCIWFIRST] = { |
| 147 | .header_type = IW_HEADER_TYPE_PARAM, |
| 148 | }, |
| 149 | [SIOCGIWSENS - SIOCIWFIRST] = { |
| 150 | .header_type = IW_HEADER_TYPE_PARAM, |
| 151 | }, |
| 152 | [SIOCSIWRANGE - SIOCIWFIRST] = { |
| 153 | .header_type = IW_HEADER_TYPE_NULL, |
| 154 | }, |
| 155 | [SIOCGIWRANGE - SIOCIWFIRST] = { |
| 156 | .header_type = IW_HEADER_TYPE_POINT, |
| 157 | .token_size = 1, |
| 158 | .max_tokens = sizeof(struct iw_range), |
| 159 | .flags = IW_DESCR_FLAG_DUMP, |
| 160 | }, |
| 161 | [SIOCSIWPRIV - SIOCIWFIRST] = { |
| 162 | .header_type = IW_HEADER_TYPE_NULL, |
| 163 | }, |
| 164 | [SIOCGIWPRIV - SIOCIWFIRST] = { /* (handled directly by us) */ |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 165 | .header_type = IW_HEADER_TYPE_POINT, |
| 166 | .token_size = sizeof(struct iw_priv_args), |
| 167 | .max_tokens = 16, |
| 168 | .flags = IW_DESCR_FLAG_NOMAX, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | }, |
| 170 | [SIOCSIWSTATS - SIOCIWFIRST] = { |
| 171 | .header_type = IW_HEADER_TYPE_NULL, |
| 172 | }, |
| 173 | [SIOCGIWSTATS - SIOCIWFIRST] = { /* (handled directly by us) */ |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 174 | .header_type = IW_HEADER_TYPE_POINT, |
| 175 | .token_size = 1, |
| 176 | .max_tokens = sizeof(struct iw_statistics), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | .flags = IW_DESCR_FLAG_DUMP, |
| 178 | }, |
| 179 | [SIOCSIWSPY - SIOCIWFIRST] = { |
| 180 | .header_type = IW_HEADER_TYPE_POINT, |
| 181 | .token_size = sizeof(struct sockaddr), |
| 182 | .max_tokens = IW_MAX_SPY, |
| 183 | }, |
| 184 | [SIOCGIWSPY - SIOCIWFIRST] = { |
| 185 | .header_type = IW_HEADER_TYPE_POINT, |
| 186 | .token_size = sizeof(struct sockaddr) + |
| 187 | sizeof(struct iw_quality), |
| 188 | .max_tokens = IW_MAX_SPY, |
| 189 | }, |
| 190 | [SIOCSIWTHRSPY - SIOCIWFIRST] = { |
| 191 | .header_type = IW_HEADER_TYPE_POINT, |
| 192 | .token_size = sizeof(struct iw_thrspy), |
| 193 | .min_tokens = 1, |
| 194 | .max_tokens = 1, |
| 195 | }, |
| 196 | [SIOCGIWTHRSPY - SIOCIWFIRST] = { |
| 197 | .header_type = IW_HEADER_TYPE_POINT, |
| 198 | .token_size = sizeof(struct iw_thrspy), |
| 199 | .min_tokens = 1, |
| 200 | .max_tokens = 1, |
| 201 | }, |
| 202 | [SIOCSIWAP - SIOCIWFIRST] = { |
| 203 | .header_type = IW_HEADER_TYPE_ADDR, |
| 204 | }, |
| 205 | [SIOCGIWAP - SIOCIWFIRST] = { |
| 206 | .header_type = IW_HEADER_TYPE_ADDR, |
| 207 | .flags = IW_DESCR_FLAG_DUMP, |
| 208 | }, |
| fff9cfd | 2005-05-12 20:24:19 -0400 | [diff] [blame] | 209 | [SIOCSIWMLME - SIOCIWFIRST] = { |
| 210 | .header_type = IW_HEADER_TYPE_POINT, |
| 211 | .token_size = 1, |
| 212 | .min_tokens = sizeof(struct iw_mlme), |
| 213 | .max_tokens = sizeof(struct iw_mlme), |
| 214 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | [SIOCGIWAPLIST - SIOCIWFIRST] = { |
| 216 | .header_type = IW_HEADER_TYPE_POINT, |
| 217 | .token_size = sizeof(struct sockaddr) + |
| 218 | sizeof(struct iw_quality), |
| 219 | .max_tokens = IW_MAX_AP, |
| 220 | .flags = IW_DESCR_FLAG_NOMAX, |
| 221 | }, |
| 222 | [SIOCSIWSCAN - SIOCIWFIRST] = { |
| fff9cfd | 2005-05-12 20:24:19 -0400 | [diff] [blame] | 223 | .header_type = IW_HEADER_TYPE_POINT, |
| 224 | .token_size = 1, |
| 225 | .min_tokens = 0, |
| 226 | .max_tokens = sizeof(struct iw_scan_req), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | }, |
| 228 | [SIOCGIWSCAN - SIOCIWFIRST] = { |
| 229 | .header_type = IW_HEADER_TYPE_POINT, |
| 230 | .token_size = 1, |
| 231 | .max_tokens = IW_SCAN_MAX_DATA, |
| 232 | .flags = IW_DESCR_FLAG_NOMAX, |
| 233 | }, |
| 234 | [SIOCSIWESSID - SIOCIWFIRST] = { |
| 235 | .header_type = IW_HEADER_TYPE_POINT, |
| 236 | .token_size = 1, |
John W. Linville | baef186 | 2006-09-08 16:04:05 -0400 | [diff] [blame] | 237 | .max_tokens = IW_ESSID_MAX_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | .flags = IW_DESCR_FLAG_EVENT, |
| 239 | }, |
| 240 | [SIOCGIWESSID - SIOCIWFIRST] = { |
| 241 | .header_type = IW_HEADER_TYPE_POINT, |
| 242 | .token_size = 1, |
John W. Linville | baef186 | 2006-09-08 16:04:05 -0400 | [diff] [blame] | 243 | .max_tokens = IW_ESSID_MAX_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | .flags = IW_DESCR_FLAG_DUMP, |
| 245 | }, |
| 246 | [SIOCSIWNICKN - SIOCIWFIRST] = { |
| 247 | .header_type = IW_HEADER_TYPE_POINT, |
| 248 | .token_size = 1, |
John W. Linville | baef186 | 2006-09-08 16:04:05 -0400 | [diff] [blame] | 249 | .max_tokens = IW_ESSID_MAX_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | }, |
| 251 | [SIOCGIWNICKN - SIOCIWFIRST] = { |
| 252 | .header_type = IW_HEADER_TYPE_POINT, |
| 253 | .token_size = 1, |
John W. Linville | baef186 | 2006-09-08 16:04:05 -0400 | [diff] [blame] | 254 | .max_tokens = IW_ESSID_MAX_SIZE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | }, |
| 256 | [SIOCSIWRATE - SIOCIWFIRST] = { |
| 257 | .header_type = IW_HEADER_TYPE_PARAM, |
| 258 | }, |
| 259 | [SIOCGIWRATE - SIOCIWFIRST] = { |
| 260 | .header_type = IW_HEADER_TYPE_PARAM, |
| 261 | }, |
| 262 | [SIOCSIWRTS - SIOCIWFIRST] = { |
| 263 | .header_type = IW_HEADER_TYPE_PARAM, |
| 264 | }, |
| 265 | [SIOCGIWRTS - SIOCIWFIRST] = { |
| 266 | .header_type = IW_HEADER_TYPE_PARAM, |
| 267 | }, |
| 268 | [SIOCSIWFRAG - SIOCIWFIRST] = { |
| 269 | .header_type = IW_HEADER_TYPE_PARAM, |
| 270 | }, |
| 271 | [SIOCGIWFRAG - SIOCIWFIRST] = { |
| 272 | .header_type = IW_HEADER_TYPE_PARAM, |
| 273 | }, |
| 274 | [SIOCSIWTXPOW - SIOCIWFIRST] = { |
| 275 | .header_type = IW_HEADER_TYPE_PARAM, |
| 276 | }, |
| 277 | [SIOCGIWTXPOW - SIOCIWFIRST] = { |
| 278 | .header_type = IW_HEADER_TYPE_PARAM, |
| 279 | }, |
| 280 | [SIOCSIWRETRY - SIOCIWFIRST] = { |
| 281 | .header_type = IW_HEADER_TYPE_PARAM, |
| 282 | }, |
| 283 | [SIOCGIWRETRY - SIOCIWFIRST] = { |
| 284 | .header_type = IW_HEADER_TYPE_PARAM, |
| 285 | }, |
| 286 | [SIOCSIWENCODE - SIOCIWFIRST] = { |
| 287 | .header_type = IW_HEADER_TYPE_POINT, |
| 288 | .token_size = 1, |
| 289 | .max_tokens = IW_ENCODING_TOKEN_MAX, |
| 290 | .flags = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT, |
| 291 | }, |
| 292 | [SIOCGIWENCODE - SIOCIWFIRST] = { |
| 293 | .header_type = IW_HEADER_TYPE_POINT, |
| 294 | .token_size = 1, |
| 295 | .max_tokens = IW_ENCODING_TOKEN_MAX, |
| 296 | .flags = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT, |
| 297 | }, |
| 298 | [SIOCSIWPOWER - SIOCIWFIRST] = { |
| 299 | .header_type = IW_HEADER_TYPE_PARAM, |
| 300 | }, |
| 301 | [SIOCGIWPOWER - SIOCIWFIRST] = { |
| 302 | .header_type = IW_HEADER_TYPE_PARAM, |
| 303 | }, |
| fff9cfd | 2005-05-12 20:24:19 -0400 | [diff] [blame] | 304 | [SIOCSIWGENIE - SIOCIWFIRST] = { |
| 305 | .header_type = IW_HEADER_TYPE_POINT, |
| 306 | .token_size = 1, |
| 307 | .max_tokens = IW_GENERIC_IE_MAX, |
| 308 | }, |
| 309 | [SIOCGIWGENIE - SIOCIWFIRST] = { |
| 310 | .header_type = IW_HEADER_TYPE_POINT, |
| 311 | .token_size = 1, |
| 312 | .max_tokens = IW_GENERIC_IE_MAX, |
| 313 | }, |
| 314 | [SIOCSIWAUTH - SIOCIWFIRST] = { |
| 315 | .header_type = IW_HEADER_TYPE_PARAM, |
| 316 | }, |
| 317 | [SIOCGIWAUTH - SIOCIWFIRST] = { |
| 318 | .header_type = IW_HEADER_TYPE_PARAM, |
| 319 | }, |
| 320 | [SIOCSIWENCODEEXT - SIOCIWFIRST] = { |
| 321 | .header_type = IW_HEADER_TYPE_POINT, |
| 322 | .token_size = 1, |
| 323 | .min_tokens = sizeof(struct iw_encode_ext), |
| 324 | .max_tokens = sizeof(struct iw_encode_ext) + |
| 325 | IW_ENCODING_TOKEN_MAX, |
| 326 | }, |
| 327 | [SIOCGIWENCODEEXT - SIOCIWFIRST] = { |
| 328 | .header_type = IW_HEADER_TYPE_POINT, |
| 329 | .token_size = 1, |
| 330 | .min_tokens = sizeof(struct iw_encode_ext), |
| 331 | .max_tokens = sizeof(struct iw_encode_ext) + |
| 332 | IW_ENCODING_TOKEN_MAX, |
| 333 | }, |
| 334 | [SIOCSIWPMKSA - SIOCIWFIRST] = { |
| 335 | .header_type = IW_HEADER_TYPE_POINT, |
| 336 | .token_size = 1, |
| 337 | .min_tokens = sizeof(struct iw_pmksa), |
| 338 | .max_tokens = sizeof(struct iw_pmksa), |
| 339 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | }; |
Stephen Hemminger | 1ac58ee | 2007-03-08 20:43:49 -0800 | [diff] [blame] | 341 | static const unsigned standard_ioctl_num = ARRAY_SIZE(standard_ioctl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /* |
| 344 | * Meta-data about all the additional standard Wireless Extension events |
| 345 | * we know about. |
| 346 | */ |
| 347 | static const struct iw_ioctl_description standard_event[] = { |
| 348 | [IWEVTXDROP - IWEVFIRST] = { |
| 349 | .header_type = IW_HEADER_TYPE_ADDR, |
| 350 | }, |
| 351 | [IWEVQUAL - IWEVFIRST] = { |
| 352 | .header_type = IW_HEADER_TYPE_QUAL, |
| 353 | }, |
| 354 | [IWEVCUSTOM - IWEVFIRST] = { |
| 355 | .header_type = IW_HEADER_TYPE_POINT, |
| 356 | .token_size = 1, |
| 357 | .max_tokens = IW_CUSTOM_MAX, |
| 358 | }, |
| 359 | [IWEVREGISTERED - IWEVFIRST] = { |
| 360 | .header_type = IW_HEADER_TYPE_ADDR, |
| 361 | }, |
| 362 | [IWEVEXPIRED - IWEVFIRST] = { |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 363 | .header_type = IW_HEADER_TYPE_ADDR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | }, |
| fff9cfd | 2005-05-12 20:24:19 -0400 | [diff] [blame] | 365 | [IWEVGENIE - IWEVFIRST] = { |
| 366 | .header_type = IW_HEADER_TYPE_POINT, |
| 367 | .token_size = 1, |
| 368 | .max_tokens = IW_GENERIC_IE_MAX, |
| 369 | }, |
| 370 | [IWEVMICHAELMICFAILURE - IWEVFIRST] = { |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 371 | .header_type = IW_HEADER_TYPE_POINT, |
| fff9cfd | 2005-05-12 20:24:19 -0400 | [diff] [blame] | 372 | .token_size = 1, |
| 373 | .max_tokens = sizeof(struct iw_michaelmicfailure), |
| 374 | }, |
| 375 | [IWEVASSOCREQIE - IWEVFIRST] = { |
| 376 | .header_type = IW_HEADER_TYPE_POINT, |
| 377 | .token_size = 1, |
| 378 | .max_tokens = IW_GENERIC_IE_MAX, |
| 379 | }, |
| 380 | [IWEVASSOCRESPIE - IWEVFIRST] = { |
| 381 | .header_type = IW_HEADER_TYPE_POINT, |
| 382 | .token_size = 1, |
| 383 | .max_tokens = IW_GENERIC_IE_MAX, |
| 384 | }, |
| 385 | [IWEVPMKIDCAND - IWEVFIRST] = { |
| 386 | .header_type = IW_HEADER_TYPE_POINT, |
| 387 | .token_size = 1, |
| 388 | .max_tokens = sizeof(struct iw_pmkid_cand), |
| 389 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | }; |
Stephen Hemminger | 1ac58ee | 2007-03-08 20:43:49 -0800 | [diff] [blame] | 391 | static const unsigned standard_event_num = ARRAY_SIZE(standard_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
| 393 | /* Size (in bytes) of the various private data types */ |
| 394 | static const char iw_priv_type_size[] = { |
| 395 | 0, /* IW_PRIV_TYPE_NONE */ |
| 396 | 1, /* IW_PRIV_TYPE_BYTE */ |
| 397 | 1, /* IW_PRIV_TYPE_CHAR */ |
| 398 | 0, /* Not defined */ |
| 399 | sizeof(__u32), /* IW_PRIV_TYPE_INT */ |
| 400 | sizeof(struct iw_freq), /* IW_PRIV_TYPE_FLOAT */ |
| 401 | sizeof(struct sockaddr), /* IW_PRIV_TYPE_ADDR */ |
| 402 | 0, /* Not defined */ |
| 403 | }; |
| 404 | |
| 405 | /* Size (in bytes) of various events */ |
| 406 | static const int event_type_size[] = { |
| 407 | IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */ |
| 408 | 0, |
| 409 | IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */ |
| 410 | 0, |
| 411 | IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */ |
| 412 | IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */ |
| 413 | IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */ |
| 414 | 0, |
| 415 | IW_EV_POINT_LEN, /* Without variable payload */ |
| 416 | IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */ |
| 417 | IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */ |
| 418 | }; |
| 419 | |
Jean Tourrilhes | c2805fb | 2007-03-23 00:31:16 +0000 | [diff] [blame] | 420 | /* Size (in bytes) of various events, as packed */ |
| 421 | static const int event_type_pk_size[] = { |
| 422 | IW_EV_LCP_PK_LEN, /* IW_HEADER_TYPE_NULL */ |
| 423 | 0, |
| 424 | IW_EV_CHAR_PK_LEN, /* IW_HEADER_TYPE_CHAR */ |
| 425 | 0, |
| 426 | IW_EV_UINT_PK_LEN, /* IW_HEADER_TYPE_UINT */ |
| 427 | IW_EV_FREQ_PK_LEN, /* IW_HEADER_TYPE_FREQ */ |
| 428 | IW_EV_ADDR_PK_LEN, /* IW_HEADER_TYPE_ADDR */ |
| 429 | 0, |
| 430 | IW_EV_POINT_PK_LEN, /* Without variable payload */ |
| 431 | IW_EV_PARAM_PK_LEN, /* IW_HEADER_TYPE_PARAM */ |
| 432 | IW_EV_QUAL_PK_LEN, /* IW_HEADER_TYPE_QUAL */ |
| 433 | }; |
| 434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | /************************ COMMON SUBROUTINES ************************/ |
| 436 | /* |
| 437 | * Stuff that may be used in various place or doesn't fit in one |
| 438 | * of the section below. |
| 439 | */ |
| 440 | |
| 441 | /* ---------------------------------------------------------------- */ |
| 442 | /* |
| 443 | * Return the driver handler associated with a specific Wireless Extension. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | */ |
Johannes Berg | bdf5189 | 2007-04-26 20:46:55 -0700 | [diff] [blame] | 445 | static iw_handler get_handler(struct net_device *dev, unsigned int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | /* Don't "optimise" the following variable, it will crash */ |
| 448 | unsigned int index; /* *MUST* be unsigned */ |
| 449 | |
| 450 | /* Check if we have some wireless handlers defined */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 451 | if (dev->wireless_handlers == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return NULL; |
| 453 | |
| 454 | /* Try as a standard command */ |
| 455 | index = cmd - SIOCIWFIRST; |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 456 | if (index < dev->wireless_handlers->num_standard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return dev->wireless_handlers->standard[index]; |
| 458 | |
| 459 | /* Try as a private command */ |
| 460 | index = cmd - SIOCIWFIRSTPRIV; |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 461 | if (index < dev->wireless_handlers->num_private) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | return dev->wireless_handlers->private[index]; |
| 463 | |
| 464 | /* Not found */ |
| 465 | return NULL; |
| 466 | } |
| 467 | |
| 468 | /* ---------------------------------------------------------------- */ |
| 469 | /* |
| 470 | * Get statistics out of the driver |
| 471 | */ |
Johannes Berg | bdf5189 | 2007-04-26 20:46:55 -0700 | [diff] [blame] | 472 | static struct iw_statistics *get_wireless_stats(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | { |
| 474 | /* New location */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 475 | if ((dev->wireless_handlers != NULL) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | (dev->wireless_handlers->get_wireless_stats != NULL)) |
| 477 | return dev->wireless_handlers->get_wireless_stats(dev); |
| 478 | |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 479 | /* Not found */ |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 480 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /* ---------------------------------------------------------------- */ |
| 484 | /* |
| 485 | * Call the commit handler in the driver |
| 486 | * (if exist and if conditions are right) |
| 487 | * |
| 488 | * Note : our current commit strategy is currently pretty dumb, |
| 489 | * but we will be able to improve on that... |
| 490 | * The goal is to try to agreagate as many changes as possible |
| 491 | * before doing the commit. Drivers that will define a commit handler |
| 492 | * are usually those that need a reset after changing parameters, so |
| 493 | * we want to minimise the number of reset. |
| 494 | * A cool idea is to use a timer : at each "set" command, we re-set the |
| 495 | * timer, when the timer eventually fires, we call the driver. |
| 496 | * Hopefully, more on that later. |
| 497 | * |
| 498 | * Also, I'm waiting to see how many people will complain about the |
| 499 | * netif_running(dev) test. I'm open on that one... |
| 500 | * Hopefully, the driver will remember to do a commit in "open()" ;-) |
| 501 | */ |
Johannes Berg | bdf5189 | 2007-04-26 20:46:55 -0700 | [diff] [blame] | 502 | static int call_commit_handler(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 504 | if ((netif_running(dev)) && |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 505 | (dev->wireless_handlers->standard[0] != NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | /* Call the commit handler on the driver */ |
| 507 | return dev->wireless_handlers->standard[0](dev, NULL, |
| 508 | NULL, NULL); |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 509 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | return 0; /* Command completed successfully */ |
| 511 | } |
| 512 | |
| 513 | /* ---------------------------------------------------------------- */ |
| 514 | /* |
| 515 | * Calculate size of private arguments |
| 516 | */ |
| 517 | static inline int get_priv_size(__u16 args) |
| 518 | { |
| 519 | int num = args & IW_PRIV_SIZE_MASK; |
| 520 | int type = (args & IW_PRIV_TYPE_MASK) >> 12; |
| 521 | |
| 522 | return num * iw_priv_type_size[type]; |
| 523 | } |
| 524 | |
| 525 | /* ---------------------------------------------------------------- */ |
| 526 | /* |
| 527 | * Re-calculate the size of private arguments |
| 528 | */ |
| 529 | static inline int adjust_priv_size(__u16 args, |
| 530 | union iwreq_data * wrqu) |
| 531 | { |
| 532 | int num = wrqu->data.length; |
| 533 | int max = args & IW_PRIV_SIZE_MASK; |
| 534 | int type = (args & IW_PRIV_TYPE_MASK) >> 12; |
| 535 | |
| 536 | /* Make sure the driver doesn't goof up */ |
| 537 | if (max < num) |
| 538 | num = max; |
| 539 | |
| 540 | return num * iw_priv_type_size[type]; |
| 541 | } |
| 542 | |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 543 | /* ---------------------------------------------------------------- */ |
| 544 | /* |
| 545 | * Standard Wireless Handler : get wireless stats |
| 546 | * Allow programatic access to /proc/net/wireless even if /proc |
| 547 | * doesn't exist... Also more efficient... |
| 548 | */ |
| 549 | static int iw_handler_get_iwstats(struct net_device * dev, |
| 550 | struct iw_request_info * info, |
| 551 | union iwreq_data * wrqu, |
| 552 | char * extra) |
| 553 | { |
| 554 | /* Get stats from the driver */ |
| 555 | struct iw_statistics *stats; |
| 556 | |
| 557 | stats = get_wireless_stats(dev); |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 558 | if (stats) { |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 559 | /* Copy statistics to extra */ |
| 560 | memcpy(extra, stats, sizeof(struct iw_statistics)); |
| 561 | wrqu->data.length = sizeof(struct iw_statistics); |
| 562 | |
| 563 | /* Check if we need to clear the updated flag */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 564 | if (wrqu->data.flags != 0) |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 565 | stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; |
| 566 | return 0; |
| 567 | } else |
| 568 | return -EOPNOTSUPP; |
| 569 | } |
| 570 | |
| 571 | /* ---------------------------------------------------------------- */ |
| 572 | /* |
| 573 | * Standard Wireless Handler : get iwpriv definitions |
| 574 | * Export the driver private handler definition |
| 575 | * They will be picked up by tools like iwpriv... |
| 576 | */ |
| 577 | static int iw_handler_get_private(struct net_device * dev, |
| 578 | struct iw_request_info * info, |
| 579 | union iwreq_data * wrqu, |
| 580 | char * extra) |
| 581 | { |
| 582 | /* Check if the driver has something to export */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 583 | if ((dev->wireless_handlers->num_private_args == 0) || |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 584 | (dev->wireless_handlers->private_args == NULL)) |
| 585 | return -EOPNOTSUPP; |
| 586 | |
| 587 | /* Check if there is enough buffer up there */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 588 | if (wrqu->data.length < dev->wireless_handlers->num_private_args) { |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 589 | /* User space can't know in advance how large the buffer |
| 590 | * needs to be. Give it a hint, so that we can support |
| 591 | * any size buffer we want somewhat efficiently... */ |
| 592 | wrqu->data.length = dev->wireless_handlers->num_private_args; |
| 593 | return -E2BIG; |
| 594 | } |
| 595 | |
| 596 | /* Set the number of available ioctls. */ |
| 597 | wrqu->data.length = dev->wireless_handlers->num_private_args; |
| 598 | |
| 599 | /* Copy structure to the user buffer. */ |
| 600 | memcpy(extra, dev->wireless_handlers->private_args, |
| 601 | sizeof(struct iw_priv_args) * wrqu->data.length); |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | /******************** /proc/net/wireless SUPPORT ********************/ |
| 608 | /* |
| 609 | * The /proc/net/wireless file is a human readable user-space interface |
| 610 | * exporting various wireless specific statistics from the wireless devices. |
| 611 | * This is the most popular part of the Wireless Extensions ;-) |
| 612 | * |
| 613 | * This interface is a pure clone of /proc/net/dev (in net/core/dev.c). |
| 614 | * The content of the file is basically the content of "struct iw_statistics". |
| 615 | */ |
| 616 | |
| 617 | #ifdef CONFIG_PROC_FS |
| 618 | |
| 619 | /* ---------------------------------------------------------------- */ |
| 620 | /* |
| 621 | * Print one entry (line) of /proc/net/wireless |
| 622 | */ |
Johannes Berg | bdf5189 | 2007-04-26 20:46:55 -0700 | [diff] [blame] | 623 | static void wireless_seq_printf_stats(struct seq_file *seq, |
| 624 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { |
| 626 | /* Get stats from the driver */ |
| 627 | struct iw_statistics *stats = get_wireless_stats(dev); |
| 628 | |
| 629 | if (stats) { |
| 630 | seq_printf(seq, "%6s: %04x %3d%c %3d%c %3d%c %6d %6d %6d " |
| 631 | "%6d %6d %6d\n", |
| 632 | dev->name, stats->status, stats->qual.qual, |
| 633 | stats->qual.updated & IW_QUAL_QUAL_UPDATED |
| 634 | ? '.' : ' ', |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 635 | ((__s32) stats->qual.level) - |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 636 | ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | stats->qual.updated & IW_QUAL_LEVEL_UPDATED |
| 638 | ? '.' : ' ', |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 639 | ((__s32) stats->qual.noise) - |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 640 | ((stats->qual.updated & IW_QUAL_DBM) ? 0x100 : 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | stats->qual.updated & IW_QUAL_NOISE_UPDATED |
| 642 | ? '.' : ' ', |
| 643 | stats->discard.nwid, stats->discard.code, |
| 644 | stats->discard.fragment, stats->discard.retries, |
| 645 | stats->discard.misc, stats->miss.beacon); |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 646 | stats->qual.updated &= ~IW_QUAL_ALL_UPDATED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
| 650 | /* ---------------------------------------------------------------- */ |
| 651 | /* |
| 652 | * Print info for /proc/net/wireless (print all entries) |
| 653 | */ |
| 654 | static int wireless_seq_show(struct seq_file *seq, void *v) |
| 655 | { |
| 656 | if (v == SEQ_START_TOKEN) |
| 657 | seq_printf(seq, "Inter-| sta-| Quality | Discarded " |
| 658 | "packets | Missed | WE\n" |
| 659 | " face | tus | link level noise | nwid " |
| 660 | "crypt frag retry misc | beacon | %d\n", |
| 661 | WIRELESS_EXT); |
| 662 | else |
| 663 | wireless_seq_printf_stats(seq, v); |
| 664 | return 0; |
| 665 | } |
| 666 | |
Stephen Hemminger | f690808 | 2007-03-12 14:34:29 -0700 | [diff] [blame] | 667 | static const struct seq_operations wireless_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | .start = dev_seq_start, |
| 669 | .next = dev_seq_next, |
| 670 | .stop = dev_seq_stop, |
| 671 | .show = wireless_seq_show, |
| 672 | }; |
| 673 | |
| 674 | static int wireless_seq_open(struct inode *inode, struct file *file) |
| 675 | { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 676 | struct seq_file *seq; |
| 677 | int res; |
| 678 | res = seq_open(file, &wireless_seq_ops); |
| 679 | if (!res) { |
| 680 | seq = file->private_data; |
| 681 | seq->private = get_net(PROC_NET(inode)); |
| 682 | } |
| 683 | return res; |
| 684 | } |
| 685 | |
| 686 | static int wireless_seq_release(struct inode *inode, struct file *file) |
| 687 | { |
| 688 | struct seq_file *seq = file->private_data; |
| 689 | struct net *net = seq->private; |
| 690 | put_net(net); |
| 691 | return seq_release(inode, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 694 | static const struct file_operations wireless_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | .owner = THIS_MODULE, |
| 696 | .open = wireless_seq_open, |
| 697 | .read = seq_read, |
| 698 | .llseek = seq_lseek, |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 699 | .release = wireless_seq_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | }; |
| 701 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 702 | int wext_proc_init(struct net *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 704 | /* Create /proc/net/wireless entry */ |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 705 | if (!proc_net_fops_create(net, "wireless", S_IRUGO, &wireless_seq_fops)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | return -ENOMEM; |
| 707 | |
| 708 | return 0; |
| 709 | } |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 710 | |
| 711 | void wext_proc_exit(struct net *net) |
| 712 | { |
| 713 | proc_net_remove(net, "wireless"); |
| 714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | #endif /* CONFIG_PROC_FS */ |
| 716 | |
| 717 | /************************** IOCTL SUPPORT **************************/ |
| 718 | /* |
| 719 | * The original user space API to configure all those Wireless Extensions |
| 720 | * is through IOCTLs. |
| 721 | * In there, we check if we need to call the new driver API (iw_handler) |
| 722 | * or just call the driver ioctl handler. |
| 723 | */ |
| 724 | |
| 725 | /* ---------------------------------------------------------------- */ |
| 726 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | * Wrapper to call a standard Wireless Extension handler. |
| 728 | * We do various checks and also take care of moving data between |
| 729 | * user space and kernel space. |
| 730 | */ |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 731 | static int ioctl_standard_call(struct net_device * dev, |
| 732 | struct ifreq * ifr, |
| 733 | unsigned int cmd, |
| 734 | iw_handler handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
| 736 | struct iwreq * iwr = (struct iwreq *) ifr; |
| 737 | const struct iw_ioctl_description * descr; |
| 738 | struct iw_request_info info; |
| 739 | int ret = -EINVAL; |
| 740 | |
| 741 | /* Get the description of the IOCTL */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 742 | if ((cmd - SIOCIWFIRST) >= standard_ioctl_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | return -EOPNOTSUPP; |
| 744 | descr = &(standard_ioctl[cmd - SIOCIWFIRST]); |
| 745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | /* Prepare the call */ |
| 747 | info.cmd = cmd; |
| 748 | info.flags = 0; |
| 749 | |
| 750 | /* Check if we have a pointer to user space data or not */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 751 | if (descr->header_type != IW_HEADER_TYPE_POINT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
| 753 | /* No extra arguments. Trivial to handle */ |
| 754 | ret = handler(dev, &info, &(iwr->u), NULL); |
| 755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | /* Generate an event to notify listeners of the change */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 757 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | ((ret == 0) || (ret == -EIWCOMMIT))) |
| 759 | wireless_send_event(dev, cmd, &(iwr->u), NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | } else { |
| 761 | char * extra; |
| 762 | int extra_size; |
| 763 | int user_length = 0; |
| 764 | int err; |
John W. Linville | 98978ed | 2006-10-17 10:54:36 -0400 | [diff] [blame] | 765 | int essid_compat = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
| 767 | /* Calculate space needed by arguments. Always allocate |
| 768 | * for max space. Easier, and won't last long... */ |
| 769 | extra_size = descr->max_tokens * descr->token_size; |
| 770 | |
John W. Linville | 98978ed | 2006-10-17 10:54:36 -0400 | [diff] [blame] | 771 | /* Check need for ESSID compatibility for WE < 21 */ |
| 772 | switch (cmd) { |
| 773 | case SIOCSIWESSID: |
| 774 | case SIOCGIWESSID: |
| 775 | case SIOCSIWNICKN: |
| 776 | case SIOCGIWNICKN: |
| 777 | if (iwr->u.data.length == descr->max_tokens + 1) |
| 778 | essid_compat = 1; |
| 779 | else if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) { |
| 780 | char essid[IW_ESSID_MAX_SIZE + 1]; |
| 781 | |
| 782 | err = copy_from_user(essid, iwr->u.data.pointer, |
| 783 | iwr->u.data.length * |
| 784 | descr->token_size); |
| 785 | if (err) |
| 786 | return -EFAULT; |
| 787 | |
| 788 | if (essid[iwr->u.data.length - 1] == '\0') |
| 789 | essid_compat = 1; |
| 790 | } |
| 791 | break; |
| 792 | default: |
| 793 | break; |
| 794 | } |
| 795 | |
| 796 | iwr->u.data.length -= essid_compat; |
| 797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | /* Check what user space is giving us */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 799 | if (IW_IS_SET(cmd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | /* Check NULL pointer */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 801 | if ((iwr->u.data.pointer == NULL) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | (iwr->u.data.length != 0)) |
| 803 | return -EFAULT; |
| 804 | /* Check if number of token fits within bounds */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 805 | if (iwr->u.data.length > descr->max_tokens) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | return -E2BIG; |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 807 | if (iwr->u.data.length < descr->min_tokens) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | return -EINVAL; |
| 809 | } else { |
| 810 | /* Check NULL pointer */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 811 | if (iwr->u.data.pointer == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | return -EFAULT; |
| 813 | /* Save user space buffer size for checking */ |
| 814 | user_length = iwr->u.data.length; |
| 815 | |
| 816 | /* Don't check if user_length > max to allow forward |
| 817 | * compatibility. The test user_length < min is |
| 818 | * implied by the test at the end. */ |
| 819 | |
| 820 | /* Support for very large requests */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 821 | if ((descr->flags & IW_DESCR_FLAG_NOMAX) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | (user_length > descr->max_tokens)) { |
| 823 | /* Allow userspace to GET more than max so |
| 824 | * we can support any size GET requests. |
| 825 | * There is still a limit : -ENOMEM. */ |
| 826 | extra_size = user_length * descr->token_size; |
| 827 | /* Note : user_length is originally a __u16, |
| 828 | * and token_size is controlled by us, |
| 829 | * so extra_size won't get negative and |
| 830 | * won't overflow... */ |
| 831 | } |
| 832 | } |
| 833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | /* Create the kernel buffer */ |
John W. Linville | 98978ed | 2006-10-17 10:54:36 -0400 | [diff] [blame] | 835 | /* kzalloc ensures NULL-termination for essid_compat */ |
| 836 | extra = kzalloc(extra_size, GFP_KERNEL); |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 837 | if (extra == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
| 840 | /* If it is a SET, get all the extra data in here */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 841 | if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | err = copy_from_user(extra, iwr->u.data.pointer, |
| 843 | iwr->u.data.length * |
| 844 | descr->token_size); |
| 845 | if (err) { |
| 846 | kfree(extra); |
| 847 | return -EFAULT; |
| 848 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | /* Call the handler */ |
| 852 | ret = handler(dev, &info, &(iwr->u), extra); |
| 853 | |
John W. Linville | 98978ed | 2006-10-17 10:54:36 -0400 | [diff] [blame] | 854 | iwr->u.data.length += essid_compat; |
| 855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | /* If we have something to return to the user */ |
| 857 | if (!ret && IW_IS_GET(cmd)) { |
| 858 | /* Check if there is enough buffer up there */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 859 | if (user_length < iwr->u.data.length) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | kfree(extra); |
| 861 | return -E2BIG; |
| 862 | } |
| 863 | |
| 864 | err = copy_to_user(iwr->u.data.pointer, extra, |
| 865 | iwr->u.data.length * |
| 866 | descr->token_size); |
| 867 | if (err) |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 868 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |
| 870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | /* Generate an event to notify listeners of the change */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 872 | if ((descr->flags & IW_DESCR_FLAG_EVENT) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | ((ret == 0) || (ret == -EIWCOMMIT))) { |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 874 | if (descr->flags & IW_DESCR_FLAG_RESTRICT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | /* If the event is restricted, don't |
| 876 | * export the payload */ |
| 877 | wireless_send_event(dev, cmd, &(iwr->u), NULL); |
| 878 | else |
| 879 | wireless_send_event(dev, cmd, &(iwr->u), |
| 880 | extra); |
| 881 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | |
| 883 | /* Cleanup - I told you it wasn't that long ;-) */ |
| 884 | kfree(extra); |
| 885 | } |
| 886 | |
| 887 | /* Call commit handler if needed and defined */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 888 | if (ret == -EIWCOMMIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | ret = call_commit_handler(dev); |
| 890 | |
| 891 | /* Here, we will generate the appropriate event if needed */ |
| 892 | |
| 893 | return ret; |
| 894 | } |
| 895 | |
| 896 | /* ---------------------------------------------------------------- */ |
| 897 | /* |
| 898 | * Wrapper to call a private Wireless Extension handler. |
| 899 | * We do various checks and also take care of moving data between |
| 900 | * user space and kernel space. |
| 901 | * It's not as nice and slimline as the standard wrapper. The cause |
| 902 | * is struct iw_priv_args, which was not really designed for the |
| 903 | * job we are going here. |
| 904 | * |
| 905 | * IMPORTANT : This function prevent to set and get data on the same |
| 906 | * IOCTL and enforce the SET/GET convention. Not doing it would be |
| 907 | * far too hairy... |
| 908 | * If you need to set and get data at the same time, please don't use |
| 909 | * a iw_handler but process it in your ioctl handler (i.e. use the |
| 910 | * old driver API). |
| 911 | */ |
Johannes Berg | bdf5189 | 2007-04-26 20:46:55 -0700 | [diff] [blame] | 912 | static int ioctl_private_call(struct net_device *dev, struct ifreq *ifr, |
| 913 | unsigned int cmd, iw_handler handler) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | { |
| 915 | struct iwreq * iwr = (struct iwreq *) ifr; |
| 916 | const struct iw_priv_args * descr = NULL; |
| 917 | struct iw_request_info info; |
| 918 | int extra_size = 0; |
| 919 | int i; |
| 920 | int ret = -EINVAL; |
| 921 | |
| 922 | /* Get the description of the IOCTL */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 923 | for (i = 0; i < dev->wireless_handlers->num_private_args; i++) |
| 924 | if (cmd == dev->wireless_handlers->private_args[i].cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | descr = &(dev->wireless_handlers->private_args[i]); |
| 926 | break; |
| 927 | } |
| 928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | /* Compute the size of the set/get arguments */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 930 | if (descr != NULL) { |
| 931 | if (IW_IS_SET(cmd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | int offset = 0; /* For sub-ioctls */ |
| 933 | /* Check for sub-ioctl handler */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 934 | if (descr->name[0] == '\0') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | /* Reserve one int for sub-ioctl index */ |
| 936 | offset = sizeof(__u32); |
| 937 | |
| 938 | /* Size of set arguments */ |
| 939 | extra_size = get_priv_size(descr->set_args); |
| 940 | |
| 941 | /* Does it fits in iwr ? */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 942 | if ((descr->set_args & IW_PRIV_SIZE_FIXED) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | ((extra_size + offset) <= IFNAMSIZ)) |
| 944 | extra_size = 0; |
| 945 | } else { |
| 946 | /* Size of get arguments */ |
| 947 | extra_size = get_priv_size(descr->get_args); |
| 948 | |
| 949 | /* Does it fits in iwr ? */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 950 | if ((descr->get_args & IW_PRIV_SIZE_FIXED) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | (extra_size <= IFNAMSIZ)) |
| 952 | extra_size = 0; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | /* Prepare the call */ |
| 957 | info.cmd = cmd; |
| 958 | info.flags = 0; |
| 959 | |
| 960 | /* Check if we have a pointer to user space data or not. */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 961 | if (extra_size == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | /* No extra arguments. Trivial to handle */ |
| 963 | ret = handler(dev, &info, &(iwr->u), (char *) &(iwr->u)); |
| 964 | } else { |
| 965 | char * extra; |
| 966 | int err; |
| 967 | |
| 968 | /* Check what user space is giving us */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 969 | if (IW_IS_SET(cmd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | /* Check NULL pointer */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 971 | if ((iwr->u.data.pointer == NULL) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | (iwr->u.data.length != 0)) |
| 973 | return -EFAULT; |
| 974 | |
| 975 | /* Does it fits within bounds ? */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 976 | if (iwr->u.data.length > (descr->set_args & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | IW_PRIV_SIZE_MASK)) |
| 978 | return -E2BIG; |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 979 | } else if (iwr->u.data.pointer == NULL) |
| 980 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | /* Always allocate for max space. Easier, and won't last |
| 983 | * long... */ |
| 984 | extra = kmalloc(extra_size, GFP_KERNEL); |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 985 | if (extra == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
| 988 | /* If it is a SET, get all the extra data in here */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 989 | if (IW_IS_SET(cmd) && (iwr->u.data.length != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | err = copy_from_user(extra, iwr->u.data.pointer, |
| 991 | extra_size); |
| 992 | if (err) { |
| 993 | kfree(extra); |
| 994 | return -EFAULT; |
| 995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | /* Call the handler */ |
| 999 | ret = handler(dev, &info, &(iwr->u), extra); |
| 1000 | |
| 1001 | /* If we have something to return to the user */ |
| 1002 | if (!ret && IW_IS_GET(cmd)) { |
| 1003 | |
| 1004 | /* Adjust for the actual length if it's variable, |
| 1005 | * avoid leaking kernel bits outside. */ |
| 1006 | if (!(descr->get_args & IW_PRIV_SIZE_FIXED)) { |
| 1007 | extra_size = adjust_priv_size(descr->get_args, |
| 1008 | &(iwr->u)); |
| 1009 | } |
| 1010 | |
| 1011 | err = copy_to_user(iwr->u.data.pointer, extra, |
| 1012 | extra_size); |
| 1013 | if (err) |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1014 | ret = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /* Cleanup - I told you it wasn't that long ;-) */ |
| 1018 | kfree(extra); |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | /* Call commit handler if needed and defined */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1023 | if (ret == -EIWCOMMIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | ret = call_commit_handler(dev); |
| 1025 | |
| 1026 | return ret; |
| 1027 | } |
| 1028 | |
| 1029 | /* ---------------------------------------------------------------- */ |
| 1030 | /* |
Johannes Berg | 295f4a1 | 2007-04-26 20:43:56 -0700 | [diff] [blame] | 1031 | * Main IOCTl dispatcher. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | * Check the type of IOCTL and call the appropriate wrapper... |
| 1033 | */ |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 1034 | static int wireless_process_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | { |
| 1036 | struct net_device *dev; |
| 1037 | iw_handler handler; |
| 1038 | |
| 1039 | /* Permissions are already checked in dev_ioctl() before calling us. |
| 1040 | * The copy_to/from_user() of ifr is also dealt with in there */ |
| 1041 | |
| 1042 | /* Make sure the device exist */ |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 1043 | if ((dev = __dev_get_by_name(net, ifr->ifr_name)) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | return -ENODEV; |
| 1045 | |
| 1046 | /* A bunch of special cases, then the generic case... |
| 1047 | * Note that 'cmd' is already filtered in dev_ioctl() with |
| 1048 | * (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) */ |
Johannes Berg | dd8ceab | 2007-04-26 20:45:47 -0700 | [diff] [blame] | 1049 | if (cmd == SIOCGIWSTATS) |
| 1050 | return ioctl_standard_call(dev, ifr, cmd, |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1051 | &iw_handler_get_iwstats); |
| 1052 | |
Johannes Berg | dd8ceab | 2007-04-26 20:45:47 -0700 | [diff] [blame] | 1053 | if (cmd == SIOCGIWPRIV && dev->wireless_handlers) |
| 1054 | return ioctl_standard_call(dev, ifr, cmd, |
| 1055 | &iw_handler_get_private); |
| 1056 | |
| 1057 | /* Basic check */ |
| 1058 | if (!netif_device_present(dev)) |
| 1059 | return -ENODEV; |
| 1060 | |
| 1061 | /* New driver API : try to find the handler */ |
| 1062 | handler = get_handler(dev, cmd); |
| 1063 | if (handler) { |
| 1064 | /* Standard and private are not the same */ |
| 1065 | if (cmd < SIOCIWFIRSTPRIV) |
| 1066 | return ioctl_standard_call(dev, ifr, cmd, handler); |
| 1067 | else |
| 1068 | return ioctl_private_call(dev, ifr, cmd, handler); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | } |
Johannes Berg | dd8ceab | 2007-04-26 20:45:47 -0700 | [diff] [blame] | 1070 | /* Old driver API : call driver ioctl handler */ |
| 1071 | if (dev->do_ioctl) |
| 1072 | return dev->do_ioctl(dev, ifr, cmd); |
| 1073 | return -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | } |
| 1075 | |
Johannes Berg | 295f4a1 | 2007-04-26 20:43:56 -0700 | [diff] [blame] | 1076 | /* entry point from dev ioctl */ |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 1077 | int wext_handle_ioctl(struct net *net, struct ifreq *ifr, unsigned int cmd, |
Johannes Berg | 295f4a1 | 2007-04-26 20:43:56 -0700 | [diff] [blame] | 1078 | void __user *arg) |
| 1079 | { |
| 1080 | int ret; |
| 1081 | |
| 1082 | /* If command is `set a parameter', or |
| 1083 | * `get the encoding parameters', check if |
| 1084 | * the user has the right to do it */ |
Johannes Berg | dd8ceab | 2007-04-26 20:45:47 -0700 | [diff] [blame] | 1085 | if ((IW_IS_SET(cmd) || cmd == SIOCGIWENCODE || cmd == SIOCGIWENCODEEXT) |
| 1086 | && !capable(CAP_NET_ADMIN)) |
| 1087 | return -EPERM; |
| 1088 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 1089 | dev_load(net, ifr->ifr_name); |
Johannes Berg | 295f4a1 | 2007-04-26 20:43:56 -0700 | [diff] [blame] | 1090 | rtnl_lock(); |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame^] | 1091 | ret = wireless_process_ioctl(net, ifr, cmd); |
Johannes Berg | 295f4a1 | 2007-04-26 20:43:56 -0700 | [diff] [blame] | 1092 | rtnl_unlock(); |
| 1093 | if (IW_IS_GET(cmd) && copy_to_user(arg, ifr, sizeof(struct ifreq))) |
| 1094 | return -EFAULT; |
| 1095 | return ret; |
| 1096 | } |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | /************************* EVENT PROCESSING *************************/ |
| 1099 | /* |
| 1100 | * Process events generated by the wireless layer or the driver. |
| 1101 | * Most often, the event will be propagated through rtnetlink |
| 1102 | */ |
| 1103 | |
John W. Linville | baef186 | 2006-09-08 16:04:05 -0400 | [diff] [blame] | 1104 | /* ---------------------------------------------------------------- */ |
| 1105 | /* |
| 1106 | * Locking... |
| 1107 | * ---------- |
| 1108 | * |
| 1109 | * Thanks to Herbert Xu <herbert@gondor.apana.org.au> for fixing |
| 1110 | * the locking issue in here and implementing this code ! |
| 1111 | * |
| 1112 | * The issue : wireless_send_event() is often called in interrupt context, |
| 1113 | * while the Netlink layer can never be called in interrupt context. |
| 1114 | * The fully formed RtNetlink events are queued, and then a tasklet is run |
| 1115 | * to feed those to Netlink. |
| 1116 | * The skb_queue is interrupt safe, and its lock is not held while calling |
| 1117 | * Netlink, so there is no possibility of dealock. |
| 1118 | * Jean II |
| 1119 | */ |
| 1120 | |
Herbert Xu | 782a667 | 2006-08-03 23:54:41 +1000 | [diff] [blame] | 1121 | static struct sk_buff_head wireless_nlevent_queue; |
| 1122 | |
John W. Linville | baef186 | 2006-09-08 16:04:05 -0400 | [diff] [blame] | 1123 | static int __init wireless_nlevent_init(void) |
| 1124 | { |
| 1125 | skb_queue_head_init(&wireless_nlevent_queue); |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | subsys_initcall(wireless_nlevent_init); |
| 1130 | |
Herbert Xu | 782a667 | 2006-08-03 23:54:41 +1000 | [diff] [blame] | 1131 | static void wireless_nlevent_process(unsigned long data) |
| 1132 | { |
| 1133 | struct sk_buff *skb; |
| 1134 | |
| 1135 | while ((skb = skb_dequeue(&wireless_nlevent_queue))) |
Thomas Graf | bd5785b | 2006-08-15 00:36:49 -0700 | [diff] [blame] | 1136 | rtnl_notify(skb, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC); |
Herbert Xu | 782a667 | 2006-08-03 23:54:41 +1000 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | static DECLARE_TASKLET(wireless_nlevent_tasklet, wireless_nlevent_process, 0); |
| 1140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | /* ---------------------------------------------------------------- */ |
| 1142 | /* |
| 1143 | * Fill a rtnetlink message with our event data. |
| 1144 | * Note that we propage only the specified event and don't dump the |
| 1145 | * current wireless config. Dumping the wireless config is far too |
| 1146 | * expensive (for each parameter, the driver need to query the hardware). |
| 1147 | */ |
Johannes Berg | bdf5189 | 2007-04-26 20:46:55 -0700 | [diff] [blame] | 1148 | static int rtnetlink_fill_iwinfo(struct sk_buff *skb, struct net_device *dev, |
| 1149 | int type, char *event, int event_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | { |
| 1151 | struct ifinfomsg *r; |
| 1152 | struct nlmsghdr *nlh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1154 | nlh = nlmsg_put(skb, 0, 0, type, sizeof(*r), 0); |
| 1155 | if (nlh == NULL) |
| 1156 | return -EMSGSIZE; |
| 1157 | |
| 1158 | r = nlmsg_data(nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | r->ifi_family = AF_UNSPEC; |
Patrick McHardy | 9ef1d4c | 2005-06-28 12:55:30 -0700 | [diff] [blame] | 1160 | r->__ifi_pad = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | r->ifi_type = dev->type; |
| 1162 | r->ifi_index = dev->ifindex; |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1163 | r->ifi_flags = dev_get_flags(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | r->ifi_change = 0; /* Wireless changes don't affect those flags */ |
| 1165 | |
| 1166 | /* Add the wireless events in the netlink packet */ |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1167 | NLA_PUT(skb, IFLA_WIRELESS, event_len, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1169 | return nlmsg_end(skb, nlh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1171 | nla_put_failure: |
| 1172 | nlmsg_cancel(skb, nlh); |
| 1173 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | /* ---------------------------------------------------------------- */ |
| 1177 | /* |
| 1178 | * Create and broadcast and send it on the standard rtnetlink socket |
| 1179 | * This is a pure clone rtmsg_ifinfo() in net/core/rtnetlink.c |
| 1180 | * Andrzej Krzysztofowicz mandated that I used a IFLA_XXX field |
| 1181 | * within a RTM_NEWLINK event. |
| 1182 | */ |
Johannes Berg | bdf5189 | 2007-04-26 20:46:55 -0700 | [diff] [blame] | 1183 | static void rtmsg_iwinfo(struct net_device *dev, char *event, int event_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | { |
| 1185 | struct sk_buff *skb; |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1186 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1188 | skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | if (!skb) |
| 1190 | return; |
| 1191 | |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1192 | err = rtnetlink_fill_iwinfo(skb, dev, RTM_NEWLINK, event, event_len); |
| 1193 | if (err < 0) { |
| 1194 | WARN_ON(err == -EMSGSIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | kfree_skb(skb); |
| 1196 | return; |
| 1197 | } |
Thomas Graf | 744b096 | 2007-07-22 12:43:32 +0200 | [diff] [blame] | 1198 | |
Patrick McHardy | ac6d439 | 2005-08-14 19:29:52 -0700 | [diff] [blame] | 1199 | NETLINK_CB(skb).dst_group = RTNLGRP_LINK; |
Herbert Xu | 782a667 | 2006-08-03 23:54:41 +1000 | [diff] [blame] | 1200 | skb_queue_tail(&wireless_nlevent_queue, skb); |
| 1201 | tasklet_schedule(&wireless_nlevent_tasklet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | } |
Herbert Xu | 782a667 | 2006-08-03 23:54:41 +1000 | [diff] [blame] | 1203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | /* ---------------------------------------------------------------- */ |
| 1205 | /* |
| 1206 | * Main event dispatcher. Called from other parts and drivers. |
| 1207 | * Send the event on the appropriate channels. |
| 1208 | * May be called from interrupt context. |
| 1209 | */ |
| 1210 | void wireless_send_event(struct net_device * dev, |
| 1211 | unsigned int cmd, |
| 1212 | union iwreq_data * wrqu, |
| 1213 | char * extra) |
| 1214 | { |
| 1215 | const struct iw_ioctl_description * descr = NULL; |
| 1216 | int extra_len = 0; |
| 1217 | struct iw_event *event; /* Mallocated whole event */ |
| 1218 | int event_len; /* Its size */ |
| 1219 | int hdr_len; /* Size of the event header */ |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 1220 | int wrqu_off = 0; /* Offset in wrqu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | /* Don't "optimise" the following variable, it will crash */ |
| 1222 | unsigned cmd_index; /* *MUST* be unsigned */ |
| 1223 | |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 1224 | /* Get the description of the Event */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1225 | if (cmd <= SIOCIWLAST) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | cmd_index = cmd - SIOCIWFIRST; |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1227 | if (cmd_index < standard_ioctl_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | descr = &(standard_ioctl[cmd_index]); |
| 1229 | } else { |
| 1230 | cmd_index = cmd - IWEVFIRST; |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1231 | if (cmd_index < standard_event_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | descr = &(standard_event[cmd_index]); |
| 1233 | } |
| 1234 | /* Don't accept unknown events */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1235 | if (descr == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | /* Note : we don't return an error to the driver, because |
| 1237 | * the driver would not know what to do about it. It can't |
| 1238 | * return an error to the user, because the event is not |
| 1239 | * initiated by a user request. |
| 1240 | * The best the driver could do is to log an error message. |
| 1241 | * We will do it ourselves instead... |
| 1242 | */ |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1243 | printk(KERN_ERR "%s (WE) : Invalid/Unknown Wireless Event (0x%04X)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | dev->name, cmd); |
| 1245 | return; |
| 1246 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* Check extra parameters and set extra_len */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1249 | if (descr->header_type == IW_HEADER_TYPE_POINT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | /* Check if number of token fits within bounds */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1251 | if (wrqu->data.length > descr->max_tokens) { |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1252 | printk(KERN_ERR "%s (WE) : Wireless Event too big (%d)\n", dev->name, wrqu->data.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | return; |
| 1254 | } |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1255 | if (wrqu->data.length < descr->min_tokens) { |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1256 | printk(KERN_ERR "%s (WE) : Wireless Event too small (%d)\n", dev->name, wrqu->data.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | return; |
| 1258 | } |
| 1259 | /* Calculate extra_len - extra is NULL for restricted events */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1260 | if (extra != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | extra_len = wrqu->data.length * descr->token_size; |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 1262 | /* Always at an offset in wrqu */ |
| 1263 | wrqu_off = IW_EV_POINT_OFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /* Total length of the event */ |
| 1267 | hdr_len = event_type_size[descr->header_type]; |
| 1268 | event_len = hdr_len + extra_len; |
| 1269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | /* Create temporary buffer to hold the event */ |
| 1271 | event = kmalloc(event_len, GFP_ATOMIC); |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1272 | if (event == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | return; |
| 1274 | |
| 1275 | /* Fill event */ |
| 1276 | event->len = event_len; |
| 1277 | event->cmd = cmd; |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 1278 | memcpy(&event->u, ((char *) wrqu) + wrqu_off, hdr_len - IW_EV_LCP_LEN); |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 1279 | if (extra) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | memcpy(((char *) event) + hdr_len, extra, extra_len); |
| 1281 | |
Jean Tourrilhes | 711e2c3 | 2006-02-22 15:10:56 -0800 | [diff] [blame] | 1282 | /* Send via the RtNetlink event channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | rtmsg_iwinfo(dev, (char *) event, event_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
| 1285 | /* Cleanup */ |
| 1286 | kfree(event); |
| 1287 | |
| 1288 | return; /* Always success, I guess ;-) */ |
| 1289 | } |
Johannes Berg | 7a9df16 | 2007-04-26 20:46:23 -0700 | [diff] [blame] | 1290 | EXPORT_SYMBOL(wireless_send_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
| 1292 | /********************** ENHANCED IWSPY SUPPORT **********************/ |
| 1293 | /* |
| 1294 | * In the old days, the driver was handling spy support all by itself. |
| 1295 | * Now, the driver can delegate this task to Wireless Extensions. |
| 1296 | * It needs to use those standard spy iw_handler in struct iw_handler_def, |
| 1297 | * push data to us via wireless_spy_update() and include struct iw_spy_data |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 1298 | * in its private part (and export it in net_device->wireless_data->spy_data). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | * One of the main advantage of centralising spy support here is that |
| 1300 | * it becomes much easier to improve and extend it without having to touch |
| 1301 | * the drivers. One example is the addition of the Spy-Threshold events. |
| 1302 | */ |
| 1303 | |
| 1304 | /* ---------------------------------------------------------------- */ |
| 1305 | /* |
| 1306 | * Return the pointer to the spy data in the driver. |
| 1307 | * Because this is called on the Rx path via wireless_spy_update(), |
| 1308 | * we want it to be efficient... |
| 1309 | */ |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 1310 | static inline struct iw_spy_data *get_spydata(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | { |
| 1312 | /* This is the new way */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1313 | if (dev->wireless_data) |
Johannes Berg | 4d44e0d | 2007-04-26 20:47:25 -0700 | [diff] [blame] | 1314 | return dev->wireless_data->spy_data; |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 1315 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | /*------------------------------------------------------------------*/ |
| 1319 | /* |
| 1320 | * Standard Wireless Handler : set Spy List |
| 1321 | */ |
| 1322 | int iw_handler_set_spy(struct net_device * dev, |
| 1323 | struct iw_request_info * info, |
| 1324 | union iwreq_data * wrqu, |
| 1325 | char * extra) |
| 1326 | { |
| 1327 | struct iw_spy_data * spydata = get_spydata(dev); |
| 1328 | struct sockaddr * address = (struct sockaddr *) extra; |
| 1329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | /* Make sure driver is not buggy or using the old API */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1331 | if (!spydata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | return -EOPNOTSUPP; |
| 1333 | |
| 1334 | /* Disable spy collection while we copy the addresses. |
| 1335 | * While we copy addresses, any call to wireless_spy_update() |
| 1336 | * will NOP. This is OK, as anyway the addresses are changing. */ |
| 1337 | spydata->spy_number = 0; |
| 1338 | |
| 1339 | /* We want to operate without locking, because wireless_spy_update() |
| 1340 | * most likely will happen in the interrupt handler, and therefore |
| 1341 | * have its own locking constraints and needs performance. |
| 1342 | * The rtnl_lock() make sure we don't race with the other iw_handlers. |
| 1343 | * This make sure wireless_spy_update() "see" that the spy list |
| 1344 | * is temporarily disabled. */ |
Ralf Baechle | e16aa20 | 2006-12-07 00:11:33 -0800 | [diff] [blame] | 1345 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | |
| 1347 | /* Are there are addresses to copy? */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1348 | if (wrqu->data.length > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | int i; |
| 1350 | |
| 1351 | /* Copy addresses */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1352 | for (i = 0; i < wrqu->data.length; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | memcpy(spydata->spy_address[i], address[i].sa_data, |
| 1354 | ETH_ALEN); |
| 1355 | /* Reset stats */ |
| 1356 | memset(spydata->spy_stat, 0, |
| 1357 | sizeof(struct iw_quality) * IW_MAX_SPY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | /* Make sure above is updated before re-enabling */ |
Ralf Baechle | e16aa20 | 2006-12-07 00:11:33 -0800 | [diff] [blame] | 1361 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
| 1363 | /* Enable addresses */ |
| 1364 | spydata->spy_number = wrqu->data.length; |
| 1365 | |
| 1366 | return 0; |
| 1367 | } |
Johannes Berg | 7a9df16 | 2007-04-26 20:46:23 -0700 | [diff] [blame] | 1368 | EXPORT_SYMBOL(iw_handler_set_spy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | /*------------------------------------------------------------------*/ |
| 1371 | /* |
| 1372 | * Standard Wireless Handler : get Spy List |
| 1373 | */ |
| 1374 | int iw_handler_get_spy(struct net_device * dev, |
| 1375 | struct iw_request_info * info, |
| 1376 | union iwreq_data * wrqu, |
| 1377 | char * extra) |
| 1378 | { |
| 1379 | struct iw_spy_data * spydata = get_spydata(dev); |
| 1380 | struct sockaddr * address = (struct sockaddr *) extra; |
| 1381 | int i; |
| 1382 | |
| 1383 | /* Make sure driver is not buggy or using the old API */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1384 | if (!spydata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | return -EOPNOTSUPP; |
| 1386 | |
| 1387 | wrqu->data.length = spydata->spy_number; |
| 1388 | |
| 1389 | /* Copy addresses. */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1390 | for (i = 0; i < spydata->spy_number; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | memcpy(address[i].sa_data, spydata->spy_address[i], ETH_ALEN); |
| 1392 | address[i].sa_family = AF_UNIX; |
| 1393 | } |
| 1394 | /* Copy stats to the user buffer (just after). */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1395 | if (spydata->spy_number > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | memcpy(extra + (sizeof(struct sockaddr) *spydata->spy_number), |
| 1397 | spydata->spy_stat, |
| 1398 | sizeof(struct iw_quality) * spydata->spy_number); |
| 1399 | /* Reset updated flags. */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1400 | for (i = 0; i < spydata->spy_number; i++) |
Jean Tourrilhes | 6582c16 | 2005-09-02 11:32:28 -0700 | [diff] [blame] | 1401 | spydata->spy_stat[i].updated &= ~IW_QUAL_ALL_UPDATED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | return 0; |
| 1403 | } |
Johannes Berg | 7a9df16 | 2007-04-26 20:46:23 -0700 | [diff] [blame] | 1404 | EXPORT_SYMBOL(iw_handler_get_spy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
| 1406 | /*------------------------------------------------------------------*/ |
| 1407 | /* |
| 1408 | * Standard Wireless Handler : set spy threshold |
| 1409 | */ |
| 1410 | int iw_handler_set_thrspy(struct net_device * dev, |
| 1411 | struct iw_request_info *info, |
| 1412 | union iwreq_data * wrqu, |
| 1413 | char * extra) |
| 1414 | { |
| 1415 | struct iw_spy_data * spydata = get_spydata(dev); |
| 1416 | struct iw_thrspy * threshold = (struct iw_thrspy *) extra; |
| 1417 | |
| 1418 | /* Make sure driver is not buggy or using the old API */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1419 | if (!spydata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | return -EOPNOTSUPP; |
| 1421 | |
| 1422 | /* Just do it */ |
| 1423 | memcpy(&(spydata->spy_thr_low), &(threshold->low), |
| 1424 | 2 * sizeof(struct iw_quality)); |
| 1425 | |
| 1426 | /* Clear flag */ |
| 1427 | memset(spydata->spy_thr_under, '\0', sizeof(spydata->spy_thr_under)); |
| 1428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | return 0; |
| 1430 | } |
Johannes Berg | 7a9df16 | 2007-04-26 20:46:23 -0700 | [diff] [blame] | 1431 | EXPORT_SYMBOL(iw_handler_set_thrspy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | |
| 1433 | /*------------------------------------------------------------------*/ |
| 1434 | /* |
| 1435 | * Standard Wireless Handler : get spy threshold |
| 1436 | */ |
| 1437 | int iw_handler_get_thrspy(struct net_device * dev, |
| 1438 | struct iw_request_info *info, |
| 1439 | union iwreq_data * wrqu, |
| 1440 | char * extra) |
| 1441 | { |
| 1442 | struct iw_spy_data * spydata = get_spydata(dev); |
| 1443 | struct iw_thrspy * threshold = (struct iw_thrspy *) extra; |
| 1444 | |
| 1445 | /* Make sure driver is not buggy or using the old API */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1446 | if (!spydata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | return -EOPNOTSUPP; |
| 1448 | |
| 1449 | /* Just do it */ |
| 1450 | memcpy(&(threshold->low), &(spydata->spy_thr_low), |
| 1451 | 2 * sizeof(struct iw_quality)); |
| 1452 | |
| 1453 | return 0; |
| 1454 | } |
Johannes Berg | 7a9df16 | 2007-04-26 20:46:23 -0700 | [diff] [blame] | 1455 | EXPORT_SYMBOL(iw_handler_get_thrspy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
| 1457 | /*------------------------------------------------------------------*/ |
| 1458 | /* |
| 1459 | * Prepare and send a Spy Threshold event |
| 1460 | */ |
| 1461 | static void iw_send_thrspy_event(struct net_device * dev, |
| 1462 | struct iw_spy_data * spydata, |
| 1463 | unsigned char * address, |
| 1464 | struct iw_quality * wstats) |
| 1465 | { |
| 1466 | union iwreq_data wrqu; |
| 1467 | struct iw_thrspy threshold; |
| 1468 | |
| 1469 | /* Init */ |
| 1470 | wrqu.data.length = 1; |
| 1471 | wrqu.data.flags = 0; |
| 1472 | /* Copy address */ |
| 1473 | memcpy(threshold.addr.sa_data, address, ETH_ALEN); |
| 1474 | threshold.addr.sa_family = ARPHRD_ETHER; |
| 1475 | /* Copy stats */ |
| 1476 | memcpy(&(threshold.qual), wstats, sizeof(struct iw_quality)); |
| 1477 | /* Copy also thresholds */ |
| 1478 | memcpy(&(threshold.low), &(spydata->spy_thr_low), |
| 1479 | 2 * sizeof(struct iw_quality)); |
| 1480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | /* Send event to user space */ |
| 1482 | wireless_send_event(dev, SIOCGIWTHRSPY, &wrqu, (char *) &threshold); |
| 1483 | } |
| 1484 | |
| 1485 | /* ---------------------------------------------------------------- */ |
| 1486 | /* |
| 1487 | * Call for the driver to update the spy data. |
| 1488 | * For now, the spy data is a simple array. As the size of the array is |
| 1489 | * small, this is good enough. If we wanted to support larger number of |
| 1490 | * spy addresses, we should use something more efficient... |
| 1491 | */ |
| 1492 | void wireless_spy_update(struct net_device * dev, |
| 1493 | unsigned char * address, |
| 1494 | struct iw_quality * wstats) |
| 1495 | { |
| 1496 | struct iw_spy_data * spydata = get_spydata(dev); |
| 1497 | int i; |
| 1498 | int match = -1; |
| 1499 | |
| 1500 | /* Make sure driver is not buggy or using the old API */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1501 | if (!spydata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | return; |
| 1503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | /* Update all records that match */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1505 | for (i = 0; i < spydata->spy_number; i++) |
| 1506 | if (!compare_ether_addr(address, spydata->spy_address[i])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | memcpy(&(spydata->spy_stat[i]), wstats, |
| 1508 | sizeof(struct iw_quality)); |
| 1509 | match = i; |
| 1510 | } |
| 1511 | |
| 1512 | /* Generate an event if we cross the spy threshold. |
| 1513 | * To avoid event storms, we have a simple hysteresis : we generate |
| 1514 | * event only when we go under the low threshold or above the |
| 1515 | * high threshold. */ |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1516 | if (match >= 0) { |
| 1517 | if (spydata->spy_thr_under[match]) { |
| 1518 | if (wstats->level > spydata->spy_thr_high.level) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | spydata->spy_thr_under[match] = 0; |
| 1520 | iw_send_thrspy_event(dev, spydata, |
| 1521 | address, wstats); |
| 1522 | } |
| 1523 | } else { |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1524 | if (wstats->level < spydata->spy_thr_low.level) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | spydata->spy_thr_under[match] = 1; |
| 1526 | iw_send_thrspy_event(dev, spydata, |
| 1527 | address, wstats); |
| 1528 | } |
| 1529 | } |
| 1530 | } |
| 1531 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | EXPORT_SYMBOL(wireless_spy_update); |