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