Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2002 Intersil Americas Inc. |
| 4 | * (C) 2003,2004 Aurelien Alleaume <slts@free.fr> |
| 5 | * (C) 2003 Herbert Valerio Riedel <hvr@gnu.org> |
| 6 | * (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/if_arp.h> |
| 26 | #include <linux/pci.h> |
| 27 | |
| 28 | #include <asm/uaccess.h> |
| 29 | |
| 30 | #include "prismcompat.h" |
| 31 | #include "isl_ioctl.h" |
| 32 | #include "islpci_mgt.h" |
| 33 | #include "isl_oid.h" /* additional types and defs for isl38xx fw */ |
| 34 | #include "oid_mgt.h" |
| 35 | |
| 36 | #include <net/iw_handler.h> /* New driver API */ |
| 37 | |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 38 | #define KEY_SIZE_WEP104 13 /* 104/128-bit WEP keys */ |
| 39 | #define KEY_SIZE_WEP40 5 /* 40/64-bit WEP keys */ |
| 40 | /* KEY_SIZE_TKIP should match isl_oid.h, struct obj_key.key[] size */ |
| 41 | #define KEY_SIZE_TKIP 32 /* TKIP keys */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 43 | static void prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | u8 *wpa_ie, size_t wpa_ie_len); |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 45 | static size_t prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | static int prism54_set_wpa(struct net_device *, struct iw_request_info *, |
| 47 | __u32 *, char *); |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * prism54_mib_mode_helper - MIB change mode helper function |
| 52 | * @mib: the &struct islpci_mib object to modify |
| 53 | * @iw_mode: new mode (%IW_MODE_*) |
| 54 | * |
| 55 | * This is a helper function, hence it does not lock. Make sure |
| 56 | * caller deals with locking *if* necessary. This function sets the |
| 57 | * mode-dependent mib values and does the mapping of the Linux |
| 58 | * Wireless API modes to Device firmware modes. It also checks for |
| 59 | * correct valid Linux wireless modes. |
| 60 | */ |
| 61 | static int |
| 62 | prism54_mib_mode_helper(islpci_private *priv, u32 iw_mode) |
| 63 | { |
| 64 | u32 config = INL_CONFIG_MANUALRUN; |
| 65 | u32 mode, bsstype; |
| 66 | |
| 67 | /* For now, just catch early the Repeater and Secondary modes here */ |
| 68 | if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) { |
| 69 | printk(KERN_DEBUG |
| 70 | "%s(): Sorry, Repeater mode and Secondary mode " |
| 71 | "are not yet supported by this driver.\n", __FUNCTION__); |
| 72 | return -EINVAL; |
| 73 | } |
| 74 | |
| 75 | priv->iw_mode = iw_mode; |
| 76 | |
| 77 | switch (iw_mode) { |
| 78 | case IW_MODE_AUTO: |
| 79 | mode = INL_MODE_CLIENT; |
| 80 | bsstype = DOT11_BSSTYPE_ANY; |
| 81 | break; |
| 82 | case IW_MODE_ADHOC: |
| 83 | mode = INL_MODE_CLIENT; |
| 84 | bsstype = DOT11_BSSTYPE_IBSS; |
| 85 | break; |
| 86 | case IW_MODE_INFRA: |
| 87 | mode = INL_MODE_CLIENT; |
| 88 | bsstype = DOT11_BSSTYPE_INFRA; |
| 89 | break; |
| 90 | case IW_MODE_MASTER: |
| 91 | mode = INL_MODE_AP; |
| 92 | bsstype = DOT11_BSSTYPE_INFRA; |
| 93 | break; |
| 94 | case IW_MODE_MONITOR: |
| 95 | mode = INL_MODE_PROMISCUOUS; |
| 96 | bsstype = DOT11_BSSTYPE_ANY; |
| 97 | config |= INL_CONFIG_RXANNEX; |
| 98 | break; |
| 99 | default: |
| 100 | return -EINVAL; |
| 101 | } |
| 102 | |
| 103 | if (init_wds) |
| 104 | config |= INL_CONFIG_WDS; |
| 105 | mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype); |
| 106 | mgt_set(priv, OID_INL_CONFIG, &config); |
| 107 | mgt_set(priv, OID_INL_MODE, &mode); |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * prism54_mib_init - fill MIB cache with defaults |
| 114 | * |
| 115 | * this function initializes the struct given as @mib with defaults, |
| 116 | * of which many are retrieved from the global module parameter |
| 117 | * variables. |
| 118 | */ |
| 119 | |
| 120 | void |
| 121 | prism54_mib_init(islpci_private *priv) |
| 122 | { |
| 123 | u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode; |
| 124 | struct obj_buffer psm_buffer = { |
| 125 | .size = PSM_BUFFER_SIZE, |
| 126 | .addr = priv->device_psm_buffer |
| 127 | }; |
| 128 | |
| 129 | channel = CARD_DEFAULT_CHANNEL; |
| 130 | authen = CARD_DEFAULT_AUTHEN; |
| 131 | wep = CARD_DEFAULT_WEP; |
| 132 | filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */ |
| 133 | dot1x = CARD_DEFAULT_DOT1X; |
| 134 | mlme = CARD_DEFAULT_MLME_MODE; |
| 135 | conformance = CARD_DEFAULT_CONFORMANCE; |
| 136 | power = 127; |
| 137 | mode = CARD_DEFAULT_IW_MODE; |
| 138 | |
| 139 | mgt_set(priv, DOT11_OID_CHANNEL, &channel); |
| 140 | mgt_set(priv, DOT11_OID_AUTHENABLE, &authen); |
| 141 | mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep); |
| 142 | mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer); |
| 143 | mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter); |
| 144 | mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x); |
| 145 | mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme); |
| 146 | mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance); |
| 147 | mgt_set(priv, OID_INL_OUTPUTPOWER, &power); |
| 148 | |
| 149 | /* This sets all of the mode-dependent values */ |
| 150 | prism54_mib_mode_helper(priv, mode); |
| 151 | } |
| 152 | |
| 153 | /* this will be executed outside of atomic context thanks to |
| 154 | * schedule_work(), thus we can as well use sleeping semaphore |
| 155 | * locking */ |
| 156 | void |
| 157 | prism54_update_stats(islpci_private *priv) |
| 158 | { |
| 159 | char *data; |
| 160 | int j; |
| 161 | struct obj_bss bss, *bss2; |
| 162 | union oid_res_t r; |
| 163 | |
| 164 | if (down_interruptible(&priv->stats_sem)) |
| 165 | return; |
| 166 | |
| 167 | /* Noise floor. |
| 168 | * I'm not sure if the unit is dBm. |
| 169 | * Note : If we are not connected, this value seems to be irrelevant. */ |
| 170 | |
| 171 | mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r); |
| 172 | priv->local_iwstatistics.qual.noise = r.u; |
| 173 | |
| 174 | /* Get the rssi of the link. To do this we need to retrieve a bss. */ |
| 175 | |
| 176 | /* First get the MAC address of the AP we are associated with. */ |
| 177 | mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r); |
| 178 | data = r.ptr; |
| 179 | |
| 180 | /* copy this MAC to the bss */ |
| 181 | memcpy(bss.address, data, 6); |
| 182 | kfree(data); |
| 183 | |
| 184 | /* now ask for the corresponding bss */ |
| 185 | j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r); |
| 186 | bss2 = r.ptr; |
| 187 | /* report the rssi and use it to calculate |
| 188 | * link quality through a signal-noise |
| 189 | * ratio */ |
| 190 | priv->local_iwstatistics.qual.level = bss2->rssi; |
| 191 | priv->local_iwstatistics.qual.qual = |
| 192 | bss2->rssi - priv->iwstatistics.qual.noise; |
| 193 | |
| 194 | kfree(bss2); |
| 195 | |
| 196 | /* report that the stats are new */ |
| 197 | priv->local_iwstatistics.qual.updated = 0x7; |
| 198 | |
| 199 | /* Rx : unable to decrypt the MPDU */ |
| 200 | mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r); |
| 201 | priv->local_iwstatistics.discard.code = r.u; |
| 202 | |
| 203 | /* Tx : Max MAC retries num reached */ |
| 204 | mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r); |
| 205 | priv->local_iwstatistics.discard.retries = r.u; |
| 206 | |
| 207 | up(&priv->stats_sem); |
| 208 | |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | struct iw_statistics * |
| 213 | prism54_get_wireless_stats(struct net_device *ndev) |
| 214 | { |
| 215 | islpci_private *priv = netdev_priv(ndev); |
| 216 | |
| 217 | /* If the stats are being updated return old data */ |
| 218 | if (down_trylock(&priv->stats_sem) == 0) { |
| 219 | memcpy(&priv->iwstatistics, &priv->local_iwstatistics, |
| 220 | sizeof (struct iw_statistics)); |
| 221 | /* They won't be marked updated for the next time */ |
| 222 | priv->local_iwstatistics.qual.updated = 0; |
| 223 | up(&priv->stats_sem); |
| 224 | } else |
| 225 | priv->iwstatistics.qual.updated = 0; |
| 226 | |
| 227 | /* Update our wireless stats, but do not schedule to often |
| 228 | * (max 1 HZ) */ |
| 229 | if ((priv->stats_timestamp == 0) || |
| 230 | time_after(jiffies, priv->stats_timestamp + 1 * HZ)) { |
| 231 | schedule_work(&priv->stats_work); |
| 232 | priv->stats_timestamp = jiffies; |
| 233 | } |
| 234 | |
| 235 | return &priv->iwstatistics; |
| 236 | } |
| 237 | |
| 238 | static int |
| 239 | prism54_commit(struct net_device *ndev, struct iw_request_info *info, |
| 240 | char *cwrq, char *extra) |
| 241 | { |
| 242 | islpci_private *priv = netdev_priv(ndev); |
| 243 | |
| 244 | /* simply re-set the last set SSID, this should commit most stuff */ |
| 245 | |
| 246 | /* Commit in Monitor mode is not necessary, also setting essid |
| 247 | * in Monitor mode does not make sense and isn't allowed for this |
| 248 | * device's firmware */ |
| 249 | if (priv->iw_mode != IW_MODE_MONITOR) |
| 250 | return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static int |
| 255 | prism54_get_name(struct net_device *ndev, struct iw_request_info *info, |
| 256 | char *cwrq, char *extra) |
| 257 | { |
| 258 | islpci_private *priv = netdev_priv(ndev); |
| 259 | char *capabilities; |
| 260 | union oid_res_t r; |
| 261 | int rvalue; |
| 262 | |
| 263 | if (islpci_get_state(priv) < PRV_STATE_INIT) { |
| 264 | strncpy(cwrq, "NOT READY!", IFNAMSIZ); |
| 265 | return 0; |
| 266 | } |
| 267 | rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r); |
| 268 | |
| 269 | switch (r.u) { |
| 270 | case INL_PHYCAP_5000MHZ: |
| 271 | capabilities = "IEEE 802.11a/b/g"; |
| 272 | break; |
| 273 | case INL_PHYCAP_FAA: |
| 274 | capabilities = "IEEE 802.11b/g - FAA Support"; |
| 275 | break; |
| 276 | case INL_PHYCAP_2400MHZ: |
| 277 | default: |
| 278 | capabilities = "IEEE 802.11b/g"; /* Default */ |
| 279 | break; |
| 280 | } |
| 281 | strncpy(cwrq, capabilities, IFNAMSIZ); |
| 282 | return rvalue; |
| 283 | } |
| 284 | |
| 285 | static int |
| 286 | prism54_set_freq(struct net_device *ndev, struct iw_request_info *info, |
| 287 | struct iw_freq *fwrq, char *extra) |
| 288 | { |
| 289 | islpci_private *priv = netdev_priv(ndev); |
| 290 | int rvalue; |
| 291 | u32 c; |
| 292 | |
| 293 | if (fwrq->m < 1000) |
| 294 | /* we have a channel number */ |
| 295 | c = fwrq->m; |
| 296 | else |
| 297 | c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0; |
| 298 | |
| 299 | rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL; |
| 300 | |
| 301 | /* Call commit handler */ |
| 302 | return (rvalue ? rvalue : -EINPROGRESS); |
| 303 | } |
| 304 | |
| 305 | static int |
| 306 | prism54_get_freq(struct net_device *ndev, struct iw_request_info *info, |
| 307 | struct iw_freq *fwrq, char *extra) |
| 308 | { |
| 309 | islpci_private *priv = netdev_priv(ndev); |
| 310 | union oid_res_t r; |
| 311 | int rvalue; |
| 312 | |
| 313 | rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r); |
| 314 | fwrq->i = r.u; |
| 315 | rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r); |
| 316 | fwrq->m = r.u; |
| 317 | fwrq->e = 3; |
| 318 | |
| 319 | return rvalue; |
| 320 | } |
| 321 | |
| 322 | static int |
| 323 | prism54_set_mode(struct net_device *ndev, struct iw_request_info *info, |
| 324 | __u32 * uwrq, char *extra) |
| 325 | { |
| 326 | islpci_private *priv = netdev_priv(ndev); |
| 327 | u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE; |
| 328 | |
| 329 | /* Let's see if the user passed a valid Linux Wireless mode */ |
| 330 | if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) { |
| 331 | printk(KERN_DEBUG |
| 332 | "%s: %s() You passed a non-valid init_mode.\n", |
| 333 | priv->ndev->name, __FUNCTION__); |
| 334 | return -EINVAL; |
| 335 | } |
| 336 | |
| 337 | down_write(&priv->mib_sem); |
| 338 | |
| 339 | if (prism54_mib_mode_helper(priv, *uwrq)) { |
| 340 | up_write(&priv->mib_sem); |
| 341 | return -EOPNOTSUPP; |
| 342 | } |
| 343 | |
| 344 | /* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an |
| 345 | * extended one. |
| 346 | */ |
| 347 | if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN)) |
| 348 | mlmeautolevel = DOT11_MLME_INTERMEDIATE; |
| 349 | if (priv->wpa) |
| 350 | mlmeautolevel = DOT11_MLME_EXTENDED; |
| 351 | |
| 352 | mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel); |
| 353 | |
| 354 | if (mgt_commit(priv)) { |
| 355 | up_write(&priv->mib_sem); |
| 356 | return -EIO; |
| 357 | } |
| 358 | priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR) |
| 359 | ? priv->monitor_type : ARPHRD_ETHER; |
| 360 | up_write(&priv->mib_sem); |
| 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | /* Use mib cache */ |
| 366 | static int |
| 367 | prism54_get_mode(struct net_device *ndev, struct iw_request_info *info, |
| 368 | __u32 * uwrq, char *extra) |
| 369 | { |
| 370 | islpci_private *priv = netdev_priv(ndev); |
| 371 | |
| 372 | BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode > |
| 373 | IW_MODE_MONITOR)); |
| 374 | *uwrq = priv->iw_mode; |
| 375 | |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to |
| 380 | * emit data if (sensitivity > rssi - noise) (in dBm). |
| 381 | * prism54_set_sens does not seem to work. |
| 382 | */ |
| 383 | |
| 384 | static int |
| 385 | prism54_set_sens(struct net_device *ndev, struct iw_request_info *info, |
| 386 | struct iw_param *vwrq, char *extra) |
| 387 | { |
| 388 | islpci_private *priv = netdev_priv(ndev); |
| 389 | u32 sens; |
| 390 | |
| 391 | /* by default the card sets this to 20. */ |
| 392 | sens = vwrq->disabled ? 20 : vwrq->value; |
| 393 | |
| 394 | return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens); |
| 395 | } |
| 396 | |
| 397 | static int |
| 398 | prism54_get_sens(struct net_device *ndev, struct iw_request_info *info, |
| 399 | struct iw_param *vwrq, char *extra) |
| 400 | { |
| 401 | islpci_private *priv = netdev_priv(ndev); |
| 402 | union oid_res_t r; |
| 403 | int rvalue; |
| 404 | |
| 405 | rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r); |
| 406 | |
| 407 | vwrq->value = r.u; |
| 408 | vwrq->disabled = (vwrq->value == 0); |
| 409 | vwrq->fixed = 1; |
| 410 | |
| 411 | return rvalue; |
| 412 | } |
| 413 | |
| 414 | static int |
| 415 | prism54_get_range(struct net_device *ndev, struct iw_request_info *info, |
| 416 | struct iw_point *dwrq, char *extra) |
| 417 | { |
| 418 | struct iw_range *range = (struct iw_range *) extra; |
| 419 | islpci_private *priv = netdev_priv(ndev); |
| 420 | u8 *data; |
| 421 | int i, m, rvalue; |
| 422 | struct obj_frequencies *freq; |
| 423 | union oid_res_t r; |
| 424 | |
| 425 | memset(range, 0, sizeof (struct iw_range)); |
| 426 | dwrq->length = sizeof (struct iw_range); |
| 427 | |
| 428 | /* set the wireless extension version number */ |
| 429 | range->we_version_source = SUPPORTED_WIRELESS_EXT; |
| 430 | range->we_version_compiled = WIRELESS_EXT; |
| 431 | |
| 432 | /* Now the encoding capabilities */ |
| 433 | range->num_encoding_sizes = 3; |
| 434 | /* 64(40) bits WEP */ |
| 435 | range->encoding_size[0] = 5; |
| 436 | /* 128(104) bits WEP */ |
| 437 | range->encoding_size[1] = 13; |
| 438 | /* 256 bits for WPA-PSK */ |
| 439 | range->encoding_size[2] = 32; |
| 440 | /* 4 keys are allowed */ |
| 441 | range->max_encoding_tokens = 4; |
| 442 | |
| 443 | /* we don't know the quality range... */ |
| 444 | range->max_qual.level = 0; |
| 445 | range->max_qual.noise = 0; |
| 446 | range->max_qual.qual = 0; |
| 447 | /* these value describe an average quality. Needs more tweaking... */ |
| 448 | range->avg_qual.level = -80; /* -80 dBm */ |
| 449 | range->avg_qual.noise = 0; /* don't know what to put here */ |
| 450 | range->avg_qual.qual = 0; |
| 451 | |
| 452 | range->sensitivity = 200; |
| 453 | |
| 454 | /* retry limit capabilities */ |
| 455 | range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME; |
| 456 | range->retry_flags = IW_RETRY_LIMIT; |
| 457 | range->r_time_flags = IW_RETRY_LIFETIME; |
| 458 | |
| 459 | /* I don't know the range. Put stupid things here */ |
| 460 | range->min_retry = 1; |
| 461 | range->max_retry = 65535; |
| 462 | range->min_r_time = 1024; |
| 463 | range->max_r_time = 65535 * 1024; |
| 464 | |
| 465 | /* txpower is supported in dBm's */ |
| 466 | range->txpower_capa = IW_TXPOW_DBM; |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | /* Event capability (kernel + driver) */ |
| 469 | range->event_capa[0] = (IW_EVENT_CAPA_K_0 | |
| 470 | IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) | |
| 471 | IW_EVENT_CAPA_MASK(SIOCGIWAP)); |
| 472 | range->event_capa[1] = IW_EVENT_CAPA_K_1; |
| 473 | range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 475 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | |
| 476 | IW_ENC_CAPA_CIPHER_TKIP; |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | if (islpci_get_state(priv) < PRV_STATE_INIT) |
| 479 | return 0; |
| 480 | |
| 481 | /* Request the device for the supported frequencies |
| 482 | * not really relevant since some devices will report the 5 GHz band |
| 483 | * frequencies even if they don't support them. |
| 484 | */ |
| 485 | rvalue = |
| 486 | mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r); |
| 487 | freq = r.ptr; |
| 488 | |
| 489 | range->num_channels = freq->nr; |
| 490 | range->num_frequency = freq->nr; |
| 491 | |
| 492 | m = min(IW_MAX_FREQUENCIES, (int) freq->nr); |
| 493 | for (i = 0; i < m; i++) { |
| 494 | range->freq[i].m = freq->mhz[i]; |
| 495 | range->freq[i].e = 6; |
| 496 | range->freq[i].i = channel_of_freq(freq->mhz[i]); |
| 497 | } |
| 498 | kfree(freq); |
| 499 | |
| 500 | rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r); |
| 501 | data = r.ptr; |
| 502 | |
| 503 | /* We got an array of char. It is NULL terminated. */ |
| 504 | i = 0; |
| 505 | while ((i < IW_MAX_BITRATES) && (*data != 0)) { |
| 506 | /* the result must be in bps. The card gives us 500Kbps */ |
| 507 | range->bitrate[i] = *data * 500000; |
| 508 | i++; |
| 509 | data++; |
| 510 | } |
| 511 | range->num_bitrates = i; |
| 512 | kfree(r.ptr); |
| 513 | |
| 514 | return rvalue; |
| 515 | } |
| 516 | |
| 517 | /* Set AP address*/ |
| 518 | |
| 519 | static int |
| 520 | prism54_set_wap(struct net_device *ndev, struct iw_request_info *info, |
| 521 | struct sockaddr *awrq, char *extra) |
| 522 | { |
| 523 | islpci_private *priv = netdev_priv(ndev); |
| 524 | char bssid[6]; |
| 525 | int rvalue; |
| 526 | |
| 527 | if (awrq->sa_family != ARPHRD_ETHER) |
| 528 | return -EINVAL; |
| 529 | |
| 530 | /* prepare the structure for the set object */ |
| 531 | memcpy(&bssid[0], awrq->sa_data, 6); |
| 532 | |
| 533 | /* set the bssid -- does this make sense when in AP mode? */ |
| 534 | rvalue = mgt_set_request(priv, DOT11_OID_BSSID, 0, &bssid); |
| 535 | |
| 536 | return (rvalue ? rvalue : -EINPROGRESS); /* Call commit handler */ |
| 537 | } |
| 538 | |
| 539 | /* get AP address*/ |
| 540 | |
| 541 | static int |
| 542 | prism54_get_wap(struct net_device *ndev, struct iw_request_info *info, |
| 543 | struct sockaddr *awrq, char *extra) |
| 544 | { |
| 545 | islpci_private *priv = netdev_priv(ndev); |
| 546 | union oid_res_t r; |
| 547 | int rvalue; |
| 548 | |
| 549 | rvalue = mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r); |
| 550 | memcpy(awrq->sa_data, r.ptr, 6); |
| 551 | awrq->sa_family = ARPHRD_ETHER; |
| 552 | kfree(r.ptr); |
| 553 | |
| 554 | return rvalue; |
| 555 | } |
| 556 | |
| 557 | static int |
| 558 | prism54_set_scan(struct net_device *dev, struct iw_request_info *info, |
| 559 | struct iw_param *vwrq, char *extra) |
| 560 | { |
| 561 | /* hehe the device does this automagicaly */ |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | /* a little helper that will translate our data into a card independent |
| 566 | * format that the Wireless Tools will understand. This was inspired by |
| 567 | * the "Aironet driver for 4500 and 4800 series cards" (GPL) |
| 568 | */ |
| 569 | |
| 570 | static char * |
| 571 | prism54_translate_bss(struct net_device *ndev, char *current_ev, |
| 572 | char *end_buf, struct obj_bss *bss, char noise) |
| 573 | { |
| 574 | struct iw_event iwe; /* Temporary buffer */ |
| 575 | short cap; |
| 576 | islpci_private *priv = netdev_priv(ndev); |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 577 | u8 wpa_ie[MAX_WPA_IE_LEN]; |
| 578 | size_t wpa_ie_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
| 580 | /* The first entry must be the MAC address */ |
| 581 | memcpy(iwe.u.ap_addr.sa_data, bss->address, 6); |
| 582 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 583 | iwe.cmd = SIOCGIWAP; |
| 584 | current_ev = |
| 585 | iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN); |
| 586 | |
| 587 | /* The following entries will be displayed in the same order we give them */ |
| 588 | |
| 589 | /* The ESSID. */ |
| 590 | iwe.u.data.length = bss->ssid.length; |
| 591 | iwe.u.data.flags = 1; |
| 592 | iwe.cmd = SIOCGIWESSID; |
| 593 | current_ev = iwe_stream_add_point(current_ev, end_buf, |
| 594 | &iwe, bss->ssid.octets); |
| 595 | |
| 596 | /* Capabilities */ |
| 597 | #define CAP_ESS 0x01 |
| 598 | #define CAP_IBSS 0x02 |
| 599 | #define CAP_CRYPT 0x10 |
| 600 | |
| 601 | /* Mode */ |
| 602 | cap = bss->capinfo; |
| 603 | iwe.u.mode = 0; |
| 604 | if (cap & CAP_ESS) |
| 605 | iwe.u.mode = IW_MODE_MASTER; |
| 606 | else if (cap & CAP_IBSS) |
| 607 | iwe.u.mode = IW_MODE_ADHOC; |
| 608 | iwe.cmd = SIOCGIWMODE; |
| 609 | if (iwe.u.mode) |
| 610 | current_ev = |
| 611 | iwe_stream_add_event(current_ev, end_buf, &iwe, |
| 612 | IW_EV_UINT_LEN); |
| 613 | |
| 614 | /* Encryption capability */ |
| 615 | if (cap & CAP_CRYPT) |
| 616 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 617 | else |
| 618 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 619 | iwe.u.data.length = 0; |
| 620 | iwe.cmd = SIOCGIWENCODE; |
| 621 | current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL); |
| 622 | |
| 623 | /* Add frequency. (short) bss->channel is the frequency in MHz */ |
| 624 | iwe.u.freq.m = bss->channel; |
| 625 | iwe.u.freq.e = 6; |
| 626 | iwe.cmd = SIOCGIWFREQ; |
| 627 | current_ev = |
| 628 | iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN); |
| 629 | |
| 630 | /* Add quality statistics */ |
| 631 | iwe.u.qual.level = bss->rssi; |
| 632 | iwe.u.qual.noise = noise; |
| 633 | /* do a simple SNR for quality */ |
| 634 | iwe.u.qual.qual = bss->rssi - noise; |
| 635 | iwe.cmd = IWEVQUAL; |
| 636 | current_ev = |
| 637 | iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN); |
| 638 | |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 639 | /* Add WPA/RSN Information Element, if any */ |
| 640 | wpa_ie_len = prism54_wpa_bss_ie_get(priv, bss->address, wpa_ie); |
| 641 | if (wpa_ie_len > 0) { |
| 642 | iwe.cmd = IWEVGENIE; |
| 643 | iwe.u.data.length = min(wpa_ie_len, (size_t)MAX_WPA_IE_LEN); |
| 644 | current_ev = iwe_stream_add_point(current_ev, end_buf, |
| 645 | &iwe, wpa_ie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | return current_ev; |
| 648 | } |
| 649 | |
| 650 | static int |
| 651 | prism54_get_scan(struct net_device *ndev, struct iw_request_info *info, |
| 652 | struct iw_point *dwrq, char *extra) |
| 653 | { |
| 654 | islpci_private *priv = netdev_priv(ndev); |
| 655 | int i, rvalue; |
| 656 | struct obj_bsslist *bsslist; |
| 657 | u32 noise = 0; |
| 658 | char *current_ev = extra; |
| 659 | union oid_res_t r; |
| 660 | |
| 661 | if (islpci_get_state(priv) < PRV_STATE_INIT) { |
| 662 | /* device is not ready, fail gently */ |
| 663 | dwrq->length = 0; |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | /* first get the noise value. We will use it to report the link quality */ |
| 668 | rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r); |
| 669 | noise = r.u; |
| 670 | |
| 671 | /* Ask the device for a list of known bss. |
| 672 | * The old API, using SIOCGIWAPLIST, had a hard limit of IW_MAX_AP=64. |
| 673 | * The new API, using SIOCGIWSCAN, is only limited by the buffer size. |
| 674 | * WE-14->WE-16, the buffer is limited to IW_SCAN_MAX_DATA bytes. |
| 675 | * Starting with WE-17, the buffer can be as big as needed. |
| 676 | * But the device won't repport anything if you change the value |
| 677 | * of IWMAX_BSS=24. */ |
| 678 | |
| 679 | rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r); |
| 680 | bsslist = r.ptr; |
| 681 | |
| 682 | /* ok now, scan the list and translate its info */ |
| 683 | for (i = 0; i < (int) bsslist->nr; i++) { |
| 684 | current_ev = prism54_translate_bss(ndev, current_ev, |
| 685 | extra + dwrq->length, |
| 686 | &(bsslist->bsslist[i]), |
| 687 | noise); |
Jeff Garzik | e2e9650 | 2005-09-24 04:05:52 -0400 | [diff] [blame] | 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | /* Check if there is space for one more entry */ |
| 690 | if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) { |
| 691 | /* Ask user space to try again with a bigger buffer */ |
| 692 | rvalue = -E2BIG; |
| 693 | break; |
| 694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | kfree(bsslist); |
| 698 | dwrq->length = (current_ev - extra); |
| 699 | dwrq->flags = 0; /* todo */ |
| 700 | |
| 701 | return rvalue; |
| 702 | } |
| 703 | |
| 704 | static int |
| 705 | prism54_set_essid(struct net_device *ndev, struct iw_request_info *info, |
| 706 | struct iw_point *dwrq, char *extra) |
| 707 | { |
| 708 | islpci_private *priv = netdev_priv(ndev); |
| 709 | struct obj_ssid essid; |
| 710 | |
| 711 | memset(essid.octets, 0, 33); |
| 712 | |
| 713 | /* Check if we were asked for `any' */ |
| 714 | if (dwrq->flags && dwrq->length) { |
| 715 | if (dwrq->length > min(33, IW_ESSID_MAX_SIZE + 1)) |
| 716 | return -E2BIG; |
| 717 | essid.length = dwrq->length - 1; |
| 718 | memcpy(essid.octets, extra, dwrq->length); |
| 719 | } else |
| 720 | essid.length = 0; |
| 721 | |
| 722 | if (priv->iw_mode != IW_MODE_MONITOR) |
| 723 | return mgt_set_request(priv, DOT11_OID_SSID, 0, &essid); |
| 724 | |
| 725 | /* If in monitor mode, just save to mib */ |
| 726 | mgt_set(priv, DOT11_OID_SSID, &essid); |
| 727 | return 0; |
| 728 | |
| 729 | } |
| 730 | |
| 731 | static int |
| 732 | prism54_get_essid(struct net_device *ndev, struct iw_request_info *info, |
| 733 | struct iw_point *dwrq, char *extra) |
| 734 | { |
| 735 | islpci_private *priv = netdev_priv(ndev); |
| 736 | struct obj_ssid *essid; |
| 737 | union oid_res_t r; |
| 738 | int rvalue; |
| 739 | |
| 740 | rvalue = mgt_get_request(priv, DOT11_OID_SSID, 0, NULL, &r); |
| 741 | essid = r.ptr; |
| 742 | |
| 743 | if (essid->length) { |
| 744 | dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */ |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 745 | /* if it is too big, trunk it */ |
Al Viro | bf82a44 | 2006-02-01 06:42:28 -0500 | [diff] [blame] | 746 | dwrq->length = min((u8)IW_ESSID_MAX_SIZE, essid->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } else { |
| 748 | dwrq->flags = 0; |
| 749 | dwrq->length = 0; |
| 750 | } |
| 751 | essid->octets[essid->length] = '\0'; |
| 752 | memcpy(extra, essid->octets, dwrq->length); |
| 753 | kfree(essid); |
| 754 | |
| 755 | return rvalue; |
| 756 | } |
| 757 | |
| 758 | /* Provides no functionality, just completes the ioctl. In essence this is a |
| 759 | * just a cosmetic ioctl. |
| 760 | */ |
| 761 | static int |
| 762 | prism54_set_nick(struct net_device *ndev, struct iw_request_info *info, |
| 763 | struct iw_point *dwrq, char *extra) |
| 764 | { |
| 765 | islpci_private *priv = netdev_priv(ndev); |
| 766 | |
| 767 | if (dwrq->length > IW_ESSID_MAX_SIZE) |
| 768 | return -E2BIG; |
| 769 | |
| 770 | down_write(&priv->mib_sem); |
| 771 | memset(priv->nickname, 0, sizeof (priv->nickname)); |
| 772 | memcpy(priv->nickname, extra, dwrq->length); |
| 773 | up_write(&priv->mib_sem); |
| 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | static int |
| 779 | prism54_get_nick(struct net_device *ndev, struct iw_request_info *info, |
| 780 | struct iw_point *dwrq, char *extra) |
| 781 | { |
| 782 | islpci_private *priv = netdev_priv(ndev); |
| 783 | |
| 784 | dwrq->length = 0; |
| 785 | |
| 786 | down_read(&priv->mib_sem); |
| 787 | dwrq->length = strlen(priv->nickname) + 1; |
| 788 | memcpy(extra, priv->nickname, dwrq->length); |
| 789 | up_read(&priv->mib_sem); |
| 790 | |
| 791 | return 0; |
| 792 | } |
| 793 | |
| 794 | /* Set the allowed Bitrates */ |
| 795 | |
| 796 | static int |
| 797 | prism54_set_rate(struct net_device *ndev, |
| 798 | struct iw_request_info *info, |
| 799 | struct iw_param *vwrq, char *extra) |
| 800 | { |
| 801 | |
| 802 | islpci_private *priv = netdev_priv(ndev); |
| 803 | u32 rate, profile; |
| 804 | char *data; |
| 805 | int ret, i; |
| 806 | union oid_res_t r; |
| 807 | |
| 808 | if (vwrq->value == -1) { |
| 809 | /* auto mode. No limit. */ |
| 810 | profile = 1; |
| 811 | return mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile); |
| 812 | } |
| 813 | |
| 814 | ret = mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r); |
| 815 | if (ret) { |
| 816 | kfree(r.ptr); |
| 817 | return ret; |
| 818 | } |
| 819 | |
| 820 | rate = (u32) (vwrq->value / 500000); |
| 821 | data = r.ptr; |
| 822 | i = 0; |
| 823 | |
| 824 | while (data[i]) { |
| 825 | if (rate && (data[i] == rate)) { |
| 826 | break; |
| 827 | } |
| 828 | if (vwrq->value == i) { |
| 829 | break; |
| 830 | } |
| 831 | data[i] |= 0x80; |
| 832 | i++; |
| 833 | } |
| 834 | |
| 835 | if (!data[i]) { |
| 836 | kfree(r.ptr); |
| 837 | return -EINVAL; |
| 838 | } |
| 839 | |
| 840 | data[i] |= 0x80; |
| 841 | data[i + 1] = 0; |
| 842 | |
| 843 | /* Now, check if we want a fixed or auto value */ |
| 844 | if (vwrq->fixed) { |
| 845 | data[0] = data[i]; |
| 846 | data[1] = 0; |
| 847 | } |
| 848 | |
| 849 | /* |
| 850 | i = 0; |
| 851 | printk("prism54 rate: "); |
| 852 | while(data[i]) { |
| 853 | printk("%u ", data[i]); |
| 854 | i++; |
| 855 | } |
| 856 | printk("0\n"); |
| 857 | */ |
| 858 | profile = -1; |
| 859 | ret = mgt_set_request(priv, DOT11_OID_PROFILES, 0, &profile); |
| 860 | ret |= mgt_set_request(priv, DOT11_OID_EXTENDEDRATES, 0, data); |
| 861 | ret |= mgt_set_request(priv, DOT11_OID_RATES, 0, data); |
| 862 | |
| 863 | kfree(r.ptr); |
| 864 | |
| 865 | return ret; |
| 866 | } |
| 867 | |
| 868 | /* Get the current bit rate */ |
| 869 | static int |
| 870 | prism54_get_rate(struct net_device *ndev, |
| 871 | struct iw_request_info *info, |
| 872 | struct iw_param *vwrq, char *extra) |
| 873 | { |
| 874 | islpci_private *priv = netdev_priv(ndev); |
| 875 | int rvalue; |
| 876 | char *data; |
| 877 | union oid_res_t r; |
| 878 | |
| 879 | /* Get the current bit rate */ |
| 880 | if ((rvalue = mgt_get_request(priv, GEN_OID_LINKSTATE, 0, NULL, &r))) |
| 881 | return rvalue; |
| 882 | vwrq->value = r.u * 500000; |
| 883 | |
| 884 | /* request the device for the enabled rates */ |
| 885 | rvalue = mgt_get_request(priv, DOT11_OID_RATES, 0, NULL, &r); |
| 886 | if (rvalue) { |
| 887 | kfree(r.ptr); |
| 888 | return rvalue; |
| 889 | } |
| 890 | data = r.ptr; |
| 891 | vwrq->fixed = (data[0] != 0) && (data[1] == 0); |
| 892 | kfree(r.ptr); |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | static int |
| 898 | prism54_set_rts(struct net_device *ndev, struct iw_request_info *info, |
| 899 | struct iw_param *vwrq, char *extra) |
| 900 | { |
| 901 | islpci_private *priv = netdev_priv(ndev); |
| 902 | |
| 903 | return mgt_set_request(priv, DOT11_OID_RTSTHRESH, 0, &vwrq->value); |
| 904 | } |
| 905 | |
| 906 | static int |
| 907 | prism54_get_rts(struct net_device *ndev, struct iw_request_info *info, |
| 908 | struct iw_param *vwrq, char *extra) |
| 909 | { |
| 910 | islpci_private *priv = netdev_priv(ndev); |
| 911 | union oid_res_t r; |
| 912 | int rvalue; |
| 913 | |
| 914 | /* get the rts threshold */ |
| 915 | rvalue = mgt_get_request(priv, DOT11_OID_RTSTHRESH, 0, NULL, &r); |
| 916 | vwrq->value = r.u; |
| 917 | |
| 918 | return rvalue; |
| 919 | } |
| 920 | |
| 921 | static int |
| 922 | prism54_set_frag(struct net_device *ndev, struct iw_request_info *info, |
| 923 | struct iw_param *vwrq, char *extra) |
| 924 | { |
| 925 | islpci_private *priv = netdev_priv(ndev); |
| 926 | |
| 927 | return mgt_set_request(priv, DOT11_OID_FRAGTHRESH, 0, &vwrq->value); |
| 928 | } |
| 929 | |
| 930 | static int |
| 931 | prism54_get_frag(struct net_device *ndev, struct iw_request_info *info, |
| 932 | struct iw_param *vwrq, char *extra) |
| 933 | { |
| 934 | islpci_private *priv = netdev_priv(ndev); |
| 935 | union oid_res_t r; |
| 936 | int rvalue; |
| 937 | |
| 938 | rvalue = mgt_get_request(priv, DOT11_OID_FRAGTHRESH, 0, NULL, &r); |
| 939 | vwrq->value = r.u; |
| 940 | |
| 941 | return rvalue; |
| 942 | } |
| 943 | |
| 944 | /* Here we have (min,max) = max retries for (small frames, big frames). Where |
| 945 | * big frame <=> bigger than the rts threshold |
| 946 | * small frame <=> smaller than the rts threshold |
| 947 | * This is not really the behavior expected by the wireless tool but it seems |
| 948 | * to be a common behavior in other drivers. |
| 949 | */ |
| 950 | |
| 951 | static int |
| 952 | prism54_set_retry(struct net_device *ndev, struct iw_request_info *info, |
| 953 | struct iw_param *vwrq, char *extra) |
| 954 | { |
| 955 | islpci_private *priv = netdev_priv(ndev); |
| 956 | u32 slimit = 0, llimit = 0; /* short and long limit */ |
| 957 | u32 lifetime = 0; |
| 958 | int rvalue = 0; |
| 959 | |
| 960 | if (vwrq->disabled) |
| 961 | /* we cannot disable this feature */ |
| 962 | return -EINVAL; |
| 963 | |
| 964 | if (vwrq->flags & IW_RETRY_LIMIT) { |
| 965 | if (vwrq->flags & IW_RETRY_MIN) |
| 966 | slimit = vwrq->value; |
| 967 | else if (vwrq->flags & IW_RETRY_MAX) |
| 968 | llimit = vwrq->value; |
| 969 | else { |
| 970 | /* we are asked to set both */ |
| 971 | slimit = vwrq->value; |
| 972 | llimit = vwrq->value; |
| 973 | } |
| 974 | } |
| 975 | if (vwrq->flags & IW_RETRY_LIFETIME) |
| 976 | /* Wireless tools use us unit while the device uses 1024 us unit */ |
| 977 | lifetime = vwrq->value / 1024; |
| 978 | |
| 979 | /* now set what is requested */ |
| 980 | if (slimit) |
| 981 | rvalue = |
| 982 | mgt_set_request(priv, DOT11_OID_SHORTRETRIES, 0, &slimit); |
| 983 | if (llimit) |
| 984 | rvalue |= |
| 985 | mgt_set_request(priv, DOT11_OID_LONGRETRIES, 0, &llimit); |
| 986 | if (lifetime) |
| 987 | rvalue |= |
| 988 | mgt_set_request(priv, DOT11_OID_MAXTXLIFETIME, 0, |
| 989 | &lifetime); |
| 990 | return rvalue; |
| 991 | } |
| 992 | |
| 993 | static int |
| 994 | prism54_get_retry(struct net_device *ndev, struct iw_request_info *info, |
| 995 | struct iw_param *vwrq, char *extra) |
| 996 | { |
| 997 | islpci_private *priv = netdev_priv(ndev); |
| 998 | union oid_res_t r; |
| 999 | int rvalue = 0; |
| 1000 | vwrq->disabled = 0; /* It cannot be disabled */ |
| 1001 | |
| 1002 | if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
| 1003 | /* we are asked for the life time */ |
| 1004 | rvalue = |
| 1005 | mgt_get_request(priv, DOT11_OID_MAXTXLIFETIME, 0, NULL, &r); |
| 1006 | vwrq->value = r.u * 1024; |
| 1007 | vwrq->flags = IW_RETRY_LIFETIME; |
| 1008 | } else if ((vwrq->flags & IW_RETRY_MAX)) { |
| 1009 | /* we are asked for the long retry limit */ |
| 1010 | rvalue |= |
| 1011 | mgt_get_request(priv, DOT11_OID_LONGRETRIES, 0, NULL, &r); |
| 1012 | vwrq->value = r.u; |
| 1013 | vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; |
| 1014 | } else { |
| 1015 | /* default. get the short retry limit */ |
| 1016 | rvalue |= |
| 1017 | mgt_get_request(priv, DOT11_OID_SHORTRETRIES, 0, NULL, &r); |
| 1018 | vwrq->value = r.u; |
| 1019 | vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MIN; |
| 1020 | } |
| 1021 | |
| 1022 | return rvalue; |
| 1023 | } |
| 1024 | |
| 1025 | static int |
| 1026 | prism54_set_encode(struct net_device *ndev, struct iw_request_info *info, |
| 1027 | struct iw_point *dwrq, char *extra) |
| 1028 | { |
| 1029 | islpci_private *priv = netdev_priv(ndev); |
| 1030 | int rvalue = 0, force = 0; |
| 1031 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0; |
| 1032 | union oid_res_t r; |
| 1033 | |
| 1034 | /* with the new API, it's impossible to get a NULL pointer. |
| 1035 | * New version of iwconfig set the IW_ENCODE_NOKEY flag |
| 1036 | * when no key is given, but older versions don't. */ |
| 1037 | |
| 1038 | if (dwrq->length > 0) { |
| 1039 | /* we have a key to set */ |
| 1040 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 1041 | int current_index; |
| 1042 | struct obj_key key = { DOT11_PRIV_WEP, 0, "" }; |
| 1043 | |
| 1044 | /* get the current key index */ |
| 1045 | rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); |
| 1046 | current_index = r.u; |
| 1047 | /* Verify that the key is not marked as invalid */ |
| 1048 | if (!(dwrq->flags & IW_ENCODE_NOKEY)) { |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 1049 | if (dwrq->length > KEY_SIZE_TKIP) { |
| 1050 | /* User-provided key data too big */ |
| 1051 | return -EINVAL; |
| 1052 | } |
| 1053 | if (dwrq->length > KEY_SIZE_WEP104) { |
| 1054 | /* WPA-PSK TKIP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | key.type = DOT11_PRIV_TKIP; |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 1056 | key.length = KEY_SIZE_TKIP; |
| 1057 | } else if (dwrq->length > KEY_SIZE_WEP40) { |
| 1058 | /* WEP 104/128 */ |
| 1059 | key.length = KEY_SIZE_WEP104; |
| 1060 | } else { |
| 1061 | /* WEP 40/64 */ |
| 1062 | key.length = KEY_SIZE_WEP40; |
| 1063 | } |
| 1064 | memset(key.key, 0, sizeof (key.key)); |
| 1065 | memcpy(key.key, extra, dwrq->length); |
| 1066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | if ((index < 0) || (index > 3)) |
| 1068 | /* no index provided use the current one */ |
| 1069 | index = current_index; |
| 1070 | |
| 1071 | /* now send the key to the card */ |
| 1072 | rvalue |= |
| 1073 | mgt_set_request(priv, DOT11_OID_DEFKEYX, index, |
| 1074 | &key); |
| 1075 | } |
| 1076 | /* |
| 1077 | * If a valid key is set, encryption should be enabled |
| 1078 | * (user may turn it off later). |
| 1079 | * This is also how "iwconfig ethX key on" works |
| 1080 | */ |
| 1081 | if ((index == current_index) && (key.length > 0)) |
| 1082 | force = 1; |
| 1083 | } else { |
| 1084 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 1085 | if ((index >= 0) && (index <= 3)) { |
| 1086 | /* we want to set the key index */ |
| 1087 | rvalue |= |
| 1088 | mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, |
| 1089 | &index); |
| 1090 | } else { |
| 1091 | if (!dwrq->flags & IW_ENCODE_MODE) { |
| 1092 | /* we cannot do anything. Complain. */ |
| 1093 | return -EINVAL; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | /* now read the flags */ |
| 1098 | if (dwrq->flags & IW_ENCODE_DISABLED) { |
| 1099 | /* Encoding disabled, |
| 1100 | * authen = DOT11_AUTH_OS; |
| 1101 | * invoke = 0; |
| 1102 | * exunencrypt = 0; */ |
| 1103 | } |
| 1104 | if (dwrq->flags & IW_ENCODE_OPEN) |
| 1105 | /* Encode but accept non-encoded packets. No auth */ |
| 1106 | invoke = 1; |
| 1107 | if ((dwrq->flags & IW_ENCODE_RESTRICTED) || force) { |
| 1108 | /* Refuse non-encoded packets. Auth */ |
| 1109 | authen = DOT11_AUTH_BOTH; |
| 1110 | invoke = 1; |
| 1111 | exunencrypt = 1; |
| 1112 | } |
| 1113 | /* do the change if requested */ |
| 1114 | if ((dwrq->flags & IW_ENCODE_MODE) || force) { |
| 1115 | rvalue |= |
| 1116 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); |
| 1117 | rvalue |= |
| 1118 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke); |
| 1119 | rvalue |= |
| 1120 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, |
| 1121 | &exunencrypt); |
| 1122 | } |
| 1123 | return rvalue; |
| 1124 | } |
| 1125 | |
| 1126 | static int |
| 1127 | prism54_get_encode(struct net_device *ndev, struct iw_request_info *info, |
| 1128 | struct iw_point *dwrq, char *extra) |
| 1129 | { |
| 1130 | islpci_private *priv = netdev_priv(ndev); |
| 1131 | struct obj_key *key; |
| 1132 | u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
| 1133 | u32 authen = 0, invoke = 0, exunencrypt = 0; |
| 1134 | int rvalue; |
| 1135 | union oid_res_t r; |
| 1136 | |
| 1137 | /* first get the flags */ |
| 1138 | rvalue = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); |
| 1139 | authen = r.u; |
| 1140 | rvalue |= mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); |
| 1141 | invoke = r.u; |
| 1142 | rvalue |= mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); |
| 1143 | exunencrypt = r.u; |
| 1144 | |
| 1145 | if (invoke && (authen == DOT11_AUTH_BOTH) && exunencrypt) |
| 1146 | dwrq->flags = IW_ENCODE_RESTRICTED; |
| 1147 | else if ((authen == DOT11_AUTH_OS) && !exunencrypt) { |
| 1148 | if (invoke) |
| 1149 | dwrq->flags = IW_ENCODE_OPEN; |
| 1150 | else |
| 1151 | dwrq->flags = IW_ENCODE_DISABLED; |
| 1152 | } else |
| 1153 | /* The card should not work in this state */ |
| 1154 | dwrq->flags = 0; |
| 1155 | |
| 1156 | /* get the current device key index */ |
| 1157 | rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); |
| 1158 | devindex = r.u; |
| 1159 | /* Now get the key, return it */ |
| 1160 | if ((index < 0) || (index > 3)) |
| 1161 | /* no index provided, use the current one */ |
| 1162 | index = devindex; |
| 1163 | rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r); |
| 1164 | key = r.ptr; |
| 1165 | dwrq->length = key->length; |
| 1166 | memcpy(extra, key->key, dwrq->length); |
| 1167 | kfree(key); |
| 1168 | /* return the used key index */ |
| 1169 | dwrq->flags |= devindex + 1; |
| 1170 | |
| 1171 | return rvalue; |
| 1172 | } |
| 1173 | |
| 1174 | static int |
| 1175 | prism54_get_txpower(struct net_device *ndev, struct iw_request_info *info, |
| 1176 | struct iw_param *vwrq, char *extra) |
| 1177 | { |
| 1178 | islpci_private *priv = netdev_priv(ndev); |
| 1179 | union oid_res_t r; |
| 1180 | int rvalue; |
| 1181 | |
| 1182 | rvalue = mgt_get_request(priv, OID_INL_OUTPUTPOWER, 0, NULL, &r); |
| 1183 | /* intersil firmware operates in 0.25 dBm (1/4 dBm) */ |
| 1184 | vwrq->value = (s32) r.u / 4; |
| 1185 | vwrq->fixed = 1; |
| 1186 | /* radio is not turned of |
| 1187 | * btw: how is possible to turn off only the radio |
| 1188 | */ |
| 1189 | vwrq->disabled = 0; |
| 1190 | |
| 1191 | return rvalue; |
| 1192 | } |
| 1193 | |
| 1194 | static int |
| 1195 | prism54_set_txpower(struct net_device *ndev, struct iw_request_info *info, |
| 1196 | struct iw_param *vwrq, char *extra) |
| 1197 | { |
| 1198 | islpci_private *priv = netdev_priv(ndev); |
| 1199 | s32 u = vwrq->value; |
| 1200 | |
| 1201 | /* intersil firmware operates in 0.25 dBm (1/4) */ |
| 1202 | u *= 4; |
| 1203 | if (vwrq->disabled) { |
| 1204 | /* don't know how to disable radio */ |
| 1205 | printk(KERN_DEBUG |
| 1206 | "%s: %s() disabling radio is not yet supported.\n", |
| 1207 | priv->ndev->name, __FUNCTION__); |
| 1208 | return -ENOTSUPP; |
| 1209 | } else if (vwrq->fixed) |
| 1210 | /* currently only fixed value is supported */ |
| 1211 | return mgt_set_request(priv, OID_INL_OUTPUTPOWER, 0, &u); |
| 1212 | else { |
| 1213 | printk(KERN_DEBUG |
| 1214 | "%s: %s() auto power will be implemented later.\n", |
| 1215 | priv->ndev->name, __FUNCTION__); |
| 1216 | return -ENOTSUPP; |
| 1217 | } |
| 1218 | } |
| 1219 | |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 1220 | static int prism54_set_genie(struct net_device *ndev, |
| 1221 | struct iw_request_info *info, |
| 1222 | struct iw_point *data, char *extra) |
| 1223 | { |
| 1224 | islpci_private *priv = netdev_priv(ndev); |
| 1225 | int alen, ret = 0; |
| 1226 | struct obj_attachment *attach; |
| 1227 | |
| 1228 | if (data->length > MAX_WPA_IE_LEN || |
| 1229 | (data->length && extra == NULL)) |
| 1230 | return -EINVAL; |
| 1231 | |
| 1232 | memcpy(priv->wpa_ie, extra, data->length); |
| 1233 | priv->wpa_ie_len = data->length; |
| 1234 | |
| 1235 | alen = sizeof(*attach) + priv->wpa_ie_len; |
| 1236 | attach = kzalloc(alen, GFP_KERNEL); |
| 1237 | if (attach == NULL) |
| 1238 | return -ENOMEM; |
| 1239 | |
| 1240 | #define WLAN_FC_TYPE_MGMT 0 |
| 1241 | #define WLAN_FC_STYPE_ASSOC_REQ 0 |
| 1242 | #define WLAN_FC_STYPE_REASSOC_REQ 2 |
| 1243 | |
| 1244 | /* Note: endianness is covered by mgt_set_varlen */ |
| 1245 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | |
| 1246 | (WLAN_FC_STYPE_ASSOC_REQ << 4); |
| 1247 | attach->id = -1; |
| 1248 | attach->size = priv->wpa_ie_len; |
| 1249 | memcpy(attach->data, extra, priv->wpa_ie_len); |
| 1250 | |
| 1251 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, |
| 1252 | priv->wpa_ie_len); |
| 1253 | if (ret == 0) { |
| 1254 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | |
| 1255 | (WLAN_FC_STYPE_REASSOC_REQ << 4); |
| 1256 | |
| 1257 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, |
| 1258 | priv->wpa_ie_len); |
| 1259 | if (ret == 0) |
| 1260 | printk(KERN_DEBUG "%s: WPA IE Attachment was set\n", |
| 1261 | ndev->name); |
| 1262 | } |
| 1263 | |
| 1264 | kfree(attach); |
| 1265 | return ret; |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | static int prism54_get_genie(struct net_device *ndev, |
| 1270 | struct iw_request_info *info, |
| 1271 | struct iw_point *data, char *extra) |
| 1272 | { |
| 1273 | islpci_private *priv = netdev_priv(ndev); |
| 1274 | int len = priv->wpa_ie_len; |
| 1275 | |
| 1276 | if (len <= 0) { |
| 1277 | data->length = 0; |
| 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | if (data->length < len) |
| 1282 | return -E2BIG; |
| 1283 | |
| 1284 | data->length = len; |
| 1285 | memcpy(extra, priv->wpa_ie, len); |
| 1286 | |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | static int prism54_set_auth(struct net_device *ndev, |
| 1291 | struct iw_request_info *info, |
| 1292 | union iwreq_data *wrqu, char *extra) |
| 1293 | { |
| 1294 | islpci_private *priv = netdev_priv(ndev); |
| 1295 | struct iw_param *param = &wrqu->param; |
| 1296 | u32 mlmelevel = 0, authen = 0, dot1x = 0; |
| 1297 | u32 exunencrypt = 0, privinvoked = 0, wpa = 0; |
| 1298 | u32 old_wpa; |
| 1299 | int ret = 0; |
| 1300 | union oid_res_t r; |
| 1301 | |
| 1302 | if (islpci_get_state(priv) < PRV_STATE_INIT) |
| 1303 | return 0; |
| 1304 | |
| 1305 | /* first get the flags */ |
| 1306 | down_write(&priv->mib_sem); |
| 1307 | wpa = old_wpa = priv->wpa; |
| 1308 | up_write(&priv->mib_sem); |
| 1309 | ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); |
| 1310 | authen = r.u; |
| 1311 | ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); |
| 1312 | privinvoked = r.u; |
| 1313 | ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); |
| 1314 | exunencrypt = r.u; |
| 1315 | ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r); |
| 1316 | dot1x = r.u; |
| 1317 | ret = mgt_get_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, NULL, &r); |
| 1318 | mlmelevel = r.u; |
| 1319 | |
| 1320 | if (ret < 0) |
| 1321 | goto out; |
| 1322 | |
| 1323 | switch (param->flags & IW_AUTH_INDEX) { |
| 1324 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1325 | case IW_AUTH_CIPHER_GROUP: |
| 1326 | case IW_AUTH_KEY_MGMT: |
| 1327 | break; |
| 1328 | |
| 1329 | case IW_AUTH_WPA_ENABLED: |
| 1330 | /* Do the same thing as IW_AUTH_WPA_VERSION */ |
| 1331 | if (param->value) { |
| 1332 | wpa = 1; |
| 1333 | privinvoked = 1; /* For privacy invoked */ |
| 1334 | exunencrypt = 1; /* Filter out all unencrypted frames */ |
| 1335 | dot1x = 0x01; /* To enable eap filter */ |
| 1336 | mlmelevel = DOT11_MLME_EXTENDED; |
| 1337 | authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */ |
| 1338 | } else { |
| 1339 | wpa = 0; |
| 1340 | privinvoked = 0; |
| 1341 | exunencrypt = 0; /* Do not filter un-encrypted data */ |
| 1342 | dot1x = 0; |
| 1343 | mlmelevel = DOT11_MLME_AUTO; |
| 1344 | } |
| 1345 | break; |
| 1346 | |
| 1347 | case IW_AUTH_WPA_VERSION: |
| 1348 | if (param->value & IW_AUTH_WPA_VERSION_DISABLED) { |
| 1349 | wpa = 0; |
| 1350 | privinvoked = 0; |
| 1351 | exunencrypt = 0; /* Do not filter un-encrypted data */ |
| 1352 | dot1x = 0; |
| 1353 | mlmelevel = DOT11_MLME_AUTO; |
| 1354 | } else { |
| 1355 | if (param->value & IW_AUTH_WPA_VERSION_WPA) |
| 1356 | wpa = 1; |
| 1357 | else if (param->value & IW_AUTH_WPA_VERSION_WPA2) |
| 1358 | wpa = 2; |
| 1359 | privinvoked = 1; /* For privacy invoked */ |
| 1360 | exunencrypt = 1; /* Filter out all unencrypted frames */ |
| 1361 | dot1x = 0x01; /* To enable eap filter */ |
| 1362 | mlmelevel = DOT11_MLME_EXTENDED; |
| 1363 | authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */ |
| 1364 | } |
| 1365 | break; |
| 1366 | |
| 1367 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1368 | dot1x = param->value ? 1 : 0; |
| 1369 | break; |
| 1370 | |
| 1371 | case IW_AUTH_PRIVACY_INVOKED: |
| 1372 | privinvoked = param->value ? 1 : 0; |
| 1373 | |
| 1374 | case IW_AUTH_DROP_UNENCRYPTED: |
| 1375 | exunencrypt = param->value ? 1 : 0; |
| 1376 | break; |
| 1377 | |
| 1378 | case IW_AUTH_80211_AUTH_ALG: |
| 1379 | if (param->value & IW_AUTH_ALG_SHARED_KEY) { |
| 1380 | /* Only WEP uses _SK and _BOTH */ |
| 1381 | if (wpa > 0) { |
| 1382 | ret = -EINVAL; |
| 1383 | goto out; |
| 1384 | } |
| 1385 | authen = DOT11_AUTH_SK; |
| 1386 | } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) { |
| 1387 | authen = DOT11_AUTH_OS; |
| 1388 | } else { |
| 1389 | ret = -EINVAL; |
| 1390 | goto out; |
| 1391 | } |
| 1392 | break; |
| 1393 | |
| 1394 | default: |
| 1395 | return -EOPNOTSUPP; |
| 1396 | } |
| 1397 | |
| 1398 | /* Set all the values */ |
| 1399 | down_write(&priv->mib_sem); |
| 1400 | priv->wpa = wpa; |
| 1401 | up_write(&priv->mib_sem); |
| 1402 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); |
| 1403 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &privinvoked); |
| 1404 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &exunencrypt); |
| 1405 | mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x); |
| 1406 | mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlmelevel); |
| 1407 | |
| 1408 | out: |
| 1409 | return ret; |
| 1410 | } |
| 1411 | |
| 1412 | static int prism54_get_auth(struct net_device *ndev, |
| 1413 | struct iw_request_info *info, |
| 1414 | union iwreq_data *wrqu, char *extra) |
| 1415 | { |
| 1416 | islpci_private *priv = netdev_priv(ndev); |
| 1417 | struct iw_param *param = &wrqu->param; |
| 1418 | u32 wpa = 0; |
| 1419 | int ret = 0; |
| 1420 | union oid_res_t r; |
| 1421 | |
| 1422 | if (islpci_get_state(priv) < PRV_STATE_INIT) |
| 1423 | return 0; |
| 1424 | |
| 1425 | /* first get the flags */ |
| 1426 | down_write(&priv->mib_sem); |
| 1427 | wpa = priv->wpa; |
| 1428 | up_write(&priv->mib_sem); |
| 1429 | |
| 1430 | switch (param->flags & IW_AUTH_INDEX) { |
| 1431 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1432 | case IW_AUTH_CIPHER_GROUP: |
| 1433 | case IW_AUTH_KEY_MGMT: |
| 1434 | /* |
| 1435 | * wpa_supplicant will control these internally |
| 1436 | */ |
| 1437 | ret = -EOPNOTSUPP; |
| 1438 | break; |
| 1439 | |
| 1440 | case IW_AUTH_WPA_VERSION: |
| 1441 | switch (wpa) { |
| 1442 | case 1: |
| 1443 | param->value = IW_AUTH_WPA_VERSION_WPA; |
| 1444 | break; |
| 1445 | case 2: |
| 1446 | param->value = IW_AUTH_WPA_VERSION_WPA2; |
| 1447 | break; |
| 1448 | case 0: |
| 1449 | default: |
| 1450 | param->value = IW_AUTH_WPA_VERSION_DISABLED; |
| 1451 | break; |
| 1452 | } |
| 1453 | break; |
| 1454 | |
| 1455 | case IW_AUTH_DROP_UNENCRYPTED: |
| 1456 | ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); |
| 1457 | if (ret >= 0) |
| 1458 | param->value = r.u > 0 ? 1 : 0; |
| 1459 | break; |
| 1460 | |
| 1461 | case IW_AUTH_80211_AUTH_ALG: |
| 1462 | ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); |
| 1463 | if (ret >= 0) { |
| 1464 | switch (r.u) { |
| 1465 | case DOT11_AUTH_OS: |
| 1466 | param->value = IW_AUTH_ALG_OPEN_SYSTEM; |
| 1467 | break; |
| 1468 | case DOT11_AUTH_BOTH: |
| 1469 | case DOT11_AUTH_SK: |
| 1470 | param->value = IW_AUTH_ALG_SHARED_KEY; |
| 1471 | case DOT11_AUTH_NONE: |
| 1472 | default: |
| 1473 | param->value = 0; |
| 1474 | break; |
| 1475 | } |
| 1476 | } |
| 1477 | break; |
| 1478 | |
| 1479 | case IW_AUTH_WPA_ENABLED: |
| 1480 | param->value = wpa > 0 ? 1 : 0; |
| 1481 | break; |
| 1482 | |
| 1483 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1484 | ret = mgt_get_request(priv, DOT11_OID_DOT1XENABLE, 0, NULL, &r); |
| 1485 | if (ret >= 0) |
| 1486 | param->value = r.u > 0 ? 1 : 0; |
| 1487 | break; |
| 1488 | |
| 1489 | case IW_AUTH_PRIVACY_INVOKED: |
| 1490 | ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); |
| 1491 | if (ret >= 0) |
| 1492 | param->value = r.u > 0 ? 1 : 0; |
| 1493 | break; |
| 1494 | |
| 1495 | default: |
| 1496 | return -EOPNOTSUPP; |
| 1497 | } |
| 1498 | return ret; |
| 1499 | } |
| 1500 | |
| 1501 | static int prism54_set_encodeext(struct net_device *ndev, |
| 1502 | struct iw_request_info *info, |
| 1503 | union iwreq_data *wrqu, |
| 1504 | char *extra) |
| 1505 | { |
| 1506 | islpci_private *priv = netdev_priv(ndev); |
| 1507 | struct iw_point *encoding = &wrqu->encoding; |
| 1508 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 1509 | int idx, alg = ext->alg, set_key = 1; |
| 1510 | union oid_res_t r; |
| 1511 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0; |
| 1512 | int ret = 0; |
| 1513 | |
| 1514 | if (islpci_get_state(priv) < PRV_STATE_INIT) |
| 1515 | return 0; |
| 1516 | |
| 1517 | /* Determine and validate the key index */ |
| 1518 | idx = (encoding->flags & IW_ENCODE_INDEX) - 1; |
| 1519 | if (idx) { |
| 1520 | if (idx < 0 || idx > 3) |
| 1521 | return -EINVAL; |
| 1522 | } else { |
| 1523 | ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); |
| 1524 | if (ret < 0) |
| 1525 | goto out; |
| 1526 | idx = r.u; |
| 1527 | } |
| 1528 | |
| 1529 | if (encoding->flags & IW_ENCODE_DISABLED) |
| 1530 | alg = IW_ENCODE_ALG_NONE; |
| 1531 | |
| 1532 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { |
| 1533 | /* Only set transmit key index here, actual |
| 1534 | * key is set below if needed. |
| 1535 | */ |
| 1536 | ret = mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, &idx); |
| 1537 | set_key = ext->key_len > 0 ? 1 : 0; |
| 1538 | } |
| 1539 | |
| 1540 | if (set_key) { |
| 1541 | struct obj_key key = { DOT11_PRIV_WEP, 0, "" }; |
| 1542 | switch (alg) { |
| 1543 | case IW_ENCODE_ALG_NONE: |
| 1544 | break; |
| 1545 | case IW_ENCODE_ALG_WEP: |
| 1546 | if (ext->key_len > KEY_SIZE_WEP104) { |
| 1547 | ret = -EINVAL; |
| 1548 | goto out; |
| 1549 | } |
| 1550 | if (ext->key_len > KEY_SIZE_WEP40) |
| 1551 | key.length = KEY_SIZE_WEP104; |
| 1552 | else |
| 1553 | key.length = KEY_SIZE_WEP40; |
| 1554 | break; |
| 1555 | case IW_ENCODE_ALG_TKIP: |
| 1556 | if (ext->key_len > KEY_SIZE_TKIP) { |
| 1557 | ret = -EINVAL; |
| 1558 | goto out; |
| 1559 | } |
| 1560 | key.type = DOT11_PRIV_TKIP; |
| 1561 | key.length = KEY_SIZE_TKIP; |
| 1562 | default: |
| 1563 | return -EINVAL; |
| 1564 | } |
| 1565 | |
| 1566 | if (key.length) { |
| 1567 | memset(key.key, 0, sizeof(key.key)); |
| 1568 | memcpy(key.key, ext->key, ext->key_len); |
| 1569 | ret = mgt_set_request(priv, DOT11_OID_DEFKEYX, idx, |
| 1570 | &key); |
| 1571 | if (ret < 0) |
| 1572 | goto out; |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | /* Read the flags */ |
| 1577 | if (encoding->flags & IW_ENCODE_DISABLED) { |
| 1578 | /* Encoding disabled, |
| 1579 | * authen = DOT11_AUTH_OS; |
| 1580 | * invoke = 0; |
| 1581 | * exunencrypt = 0; */ |
| 1582 | } |
| 1583 | if (encoding->flags & IW_ENCODE_OPEN) { |
| 1584 | /* Encode but accept non-encoded packets. No auth */ |
| 1585 | invoke = 1; |
| 1586 | } |
| 1587 | if (encoding->flags & IW_ENCODE_RESTRICTED) { |
| 1588 | /* Refuse non-encoded packets. Auth */ |
| 1589 | authen = DOT11_AUTH_BOTH; |
| 1590 | invoke = 1; |
| 1591 | exunencrypt = 1; |
| 1592 | } |
| 1593 | |
| 1594 | /* do the change if requested */ |
| 1595 | if (encoding->flags & IW_ENCODE_MODE) { |
| 1596 | ret = mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, |
| 1597 | &authen); |
| 1598 | ret = mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, |
| 1599 | &invoke); |
| 1600 | ret = mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, |
| 1601 | &exunencrypt); |
| 1602 | } |
| 1603 | |
| 1604 | out: |
| 1605 | return ret; |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | static int prism54_get_encodeext(struct net_device *ndev, |
| 1610 | struct iw_request_info *info, |
| 1611 | union iwreq_data *wrqu, |
| 1612 | char *extra) |
| 1613 | { |
| 1614 | islpci_private *priv = netdev_priv(ndev); |
| 1615 | struct iw_point *encoding = &wrqu->encoding; |
| 1616 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 1617 | int idx, max_key_len; |
| 1618 | union oid_res_t r; |
| 1619 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0, wpa = 0; |
| 1620 | int ret = 0; |
| 1621 | |
| 1622 | if (islpci_get_state(priv) < PRV_STATE_INIT) |
| 1623 | return 0; |
| 1624 | |
| 1625 | /* first get the flags */ |
| 1626 | ret = mgt_get_request(priv, DOT11_OID_AUTHENABLE, 0, NULL, &r); |
| 1627 | authen = r.u; |
| 1628 | ret = mgt_get_request(priv, DOT11_OID_PRIVACYINVOKED, 0, NULL, &r); |
| 1629 | invoke = r.u; |
| 1630 | ret = mgt_get_request(priv, DOT11_OID_EXUNENCRYPTED, 0, NULL, &r); |
| 1631 | exunencrypt = r.u; |
| 1632 | if (ret < 0) |
| 1633 | goto out; |
| 1634 | |
| 1635 | max_key_len = encoding->length - sizeof(*ext); |
| 1636 | if (max_key_len < 0) |
| 1637 | return -EINVAL; |
| 1638 | |
| 1639 | idx = (encoding->flags & IW_ENCODE_INDEX) - 1; |
| 1640 | if (idx) { |
| 1641 | if (idx < 0 || idx > 3) |
| 1642 | return -EINVAL; |
| 1643 | } else { |
| 1644 | ret = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); |
| 1645 | if (ret < 0) |
| 1646 | goto out; |
| 1647 | idx = r.u; |
| 1648 | } |
| 1649 | |
| 1650 | encoding->flags = idx + 1; |
| 1651 | memset(ext, 0, sizeof(*ext)); |
| 1652 | |
| 1653 | switch (authen) { |
| 1654 | case DOT11_AUTH_BOTH: |
| 1655 | case DOT11_AUTH_SK: |
| 1656 | wrqu->encoding.flags |= IW_ENCODE_RESTRICTED; |
| 1657 | case DOT11_AUTH_OS: |
| 1658 | default: |
| 1659 | wrqu->encoding.flags |= IW_ENCODE_OPEN; |
| 1660 | break; |
| 1661 | } |
| 1662 | |
| 1663 | down_write(&priv->mib_sem); |
| 1664 | wpa = priv->wpa; |
| 1665 | up_write(&priv->mib_sem); |
| 1666 | |
| 1667 | if (authen == DOT11_AUTH_OS && !exunencrypt && !invoke && !wpa) { |
| 1668 | /* No encryption */ |
| 1669 | ext->alg = IW_ENCODE_ALG_NONE; |
| 1670 | ext->key_len = 0; |
| 1671 | wrqu->encoding.flags |= IW_ENCODE_DISABLED; |
| 1672 | } else { |
| 1673 | struct obj_key *key; |
| 1674 | |
| 1675 | ret = mgt_get_request(priv, DOT11_OID_DEFKEYX, idx, NULL, &r); |
| 1676 | if (ret < 0) |
| 1677 | goto out; |
| 1678 | key = r.ptr; |
| 1679 | if (max_key_len < key->length) { |
| 1680 | ret = -E2BIG; |
| 1681 | goto out; |
| 1682 | } |
| 1683 | memcpy(ext->key, key->key, key->length); |
| 1684 | ext->key_len = key->length; |
| 1685 | |
| 1686 | switch (key->type) { |
| 1687 | case DOT11_PRIV_TKIP: |
| 1688 | ext->alg = IW_ENCODE_ALG_TKIP; |
| 1689 | break; |
| 1690 | default: |
| 1691 | case DOT11_PRIV_WEP: |
| 1692 | ext->alg = IW_ENCODE_ALG_WEP; |
| 1693 | break; |
| 1694 | } |
| 1695 | wrqu->encoding.flags |= IW_ENCODE_ENABLED; |
| 1696 | } |
| 1697 | |
| 1698 | out: |
| 1699 | return ret; |
| 1700 | } |
| 1701 | |
| 1702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | static int |
| 1704 | prism54_reset(struct net_device *ndev, struct iw_request_info *info, |
| 1705 | __u32 * uwrq, char *extra) |
| 1706 | { |
| 1707 | islpci_reset(netdev_priv(ndev), 0); |
| 1708 | |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
| 1712 | static int |
| 1713 | prism54_get_oid(struct net_device *ndev, struct iw_request_info *info, |
| 1714 | struct iw_point *dwrq, char *extra) |
| 1715 | { |
| 1716 | union oid_res_t r; |
| 1717 | int rvalue; |
| 1718 | enum oid_num_t n = dwrq->flags; |
| 1719 | |
| 1720 | rvalue = mgt_get_request((islpci_private *) ndev->priv, n, 0, NULL, &r); |
| 1721 | dwrq->length = mgt_response_to_str(n, &r, extra); |
| 1722 | if ((isl_oid[n].flags & OID_FLAG_TYPE) != OID_TYPE_U32) |
| 1723 | kfree(r.ptr); |
| 1724 | return rvalue; |
| 1725 | } |
| 1726 | |
| 1727 | static int |
| 1728 | prism54_set_u32(struct net_device *ndev, struct iw_request_info *info, |
| 1729 | __u32 * uwrq, char *extra) |
| 1730 | { |
| 1731 | u32 oid = uwrq[0], u = uwrq[1]; |
| 1732 | |
| 1733 | return mgt_set_request((islpci_private *) ndev->priv, oid, 0, &u); |
| 1734 | } |
| 1735 | |
| 1736 | static int |
| 1737 | prism54_set_raw(struct net_device *ndev, struct iw_request_info *info, |
| 1738 | struct iw_point *dwrq, char *extra) |
| 1739 | { |
| 1740 | u32 oid = dwrq->flags; |
| 1741 | |
| 1742 | return mgt_set_request((islpci_private *) ndev->priv, oid, 0, extra); |
| 1743 | } |
| 1744 | |
| 1745 | void |
| 1746 | prism54_acl_init(struct islpci_acl *acl) |
| 1747 | { |
| 1748 | sema_init(&acl->sem, 1); |
| 1749 | INIT_LIST_HEAD(&acl->mac_list); |
| 1750 | acl->size = 0; |
| 1751 | acl->policy = MAC_POLICY_OPEN; |
| 1752 | } |
| 1753 | |
| 1754 | static void |
| 1755 | prism54_clear_mac(struct islpci_acl *acl) |
| 1756 | { |
| 1757 | struct list_head *ptr, *next; |
| 1758 | struct mac_entry *entry; |
| 1759 | |
| 1760 | if (down_interruptible(&acl->sem)) |
| 1761 | return; |
| 1762 | |
| 1763 | if (acl->size == 0) { |
| 1764 | up(&acl->sem); |
| 1765 | return; |
| 1766 | } |
| 1767 | |
| 1768 | for (ptr = acl->mac_list.next, next = ptr->next; |
| 1769 | ptr != &acl->mac_list; ptr = next, next = ptr->next) { |
| 1770 | entry = list_entry(ptr, struct mac_entry, _list); |
| 1771 | list_del(ptr); |
| 1772 | kfree(entry); |
| 1773 | } |
| 1774 | acl->size = 0; |
| 1775 | up(&acl->sem); |
| 1776 | } |
| 1777 | |
| 1778 | void |
| 1779 | prism54_acl_clean(struct islpci_acl *acl) |
| 1780 | { |
| 1781 | prism54_clear_mac(acl); |
| 1782 | } |
| 1783 | |
| 1784 | static int |
| 1785 | prism54_add_mac(struct net_device *ndev, struct iw_request_info *info, |
| 1786 | struct sockaddr *awrq, char *extra) |
| 1787 | { |
| 1788 | islpci_private *priv = netdev_priv(ndev); |
| 1789 | struct islpci_acl *acl = &priv->acl; |
| 1790 | struct mac_entry *entry; |
| 1791 | struct sockaddr *addr = (struct sockaddr *) extra; |
| 1792 | |
| 1793 | if (addr->sa_family != ARPHRD_ETHER) |
| 1794 | return -EOPNOTSUPP; |
| 1795 | |
| 1796 | entry = kmalloc(sizeof (struct mac_entry), GFP_KERNEL); |
| 1797 | if (entry == NULL) |
| 1798 | return -ENOMEM; |
| 1799 | |
| 1800 | memcpy(entry->addr, addr->sa_data, ETH_ALEN); |
| 1801 | |
| 1802 | if (down_interruptible(&acl->sem)) { |
| 1803 | kfree(entry); |
| 1804 | return -ERESTARTSYS; |
| 1805 | } |
| 1806 | list_add_tail(&entry->_list, &acl->mac_list); |
| 1807 | acl->size++; |
| 1808 | up(&acl->sem); |
| 1809 | |
| 1810 | return 0; |
| 1811 | } |
| 1812 | |
| 1813 | static int |
| 1814 | prism54_del_mac(struct net_device *ndev, struct iw_request_info *info, |
| 1815 | struct sockaddr *awrq, char *extra) |
| 1816 | { |
| 1817 | islpci_private *priv = netdev_priv(ndev); |
| 1818 | struct islpci_acl *acl = &priv->acl; |
| 1819 | struct mac_entry *entry; |
| 1820 | struct list_head *ptr; |
| 1821 | struct sockaddr *addr = (struct sockaddr *) extra; |
| 1822 | |
| 1823 | if (addr->sa_family != ARPHRD_ETHER) |
| 1824 | return -EOPNOTSUPP; |
| 1825 | |
| 1826 | if (down_interruptible(&acl->sem)) |
| 1827 | return -ERESTARTSYS; |
| 1828 | for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) { |
| 1829 | entry = list_entry(ptr, struct mac_entry, _list); |
| 1830 | |
| 1831 | if (memcmp(entry->addr, addr->sa_data, ETH_ALEN) == 0) { |
| 1832 | list_del(ptr); |
| 1833 | acl->size--; |
| 1834 | kfree(entry); |
| 1835 | up(&acl->sem); |
| 1836 | return 0; |
| 1837 | } |
| 1838 | } |
| 1839 | up(&acl->sem); |
| 1840 | return -EINVAL; |
| 1841 | } |
| 1842 | |
| 1843 | static int |
| 1844 | prism54_get_mac(struct net_device *ndev, struct iw_request_info *info, |
| 1845 | struct iw_point *dwrq, char *extra) |
| 1846 | { |
| 1847 | islpci_private *priv = netdev_priv(ndev); |
| 1848 | struct islpci_acl *acl = &priv->acl; |
| 1849 | struct mac_entry *entry; |
| 1850 | struct list_head *ptr; |
| 1851 | struct sockaddr *dst = (struct sockaddr *) extra; |
| 1852 | |
| 1853 | dwrq->length = 0; |
| 1854 | |
| 1855 | if (down_interruptible(&acl->sem)) |
| 1856 | return -ERESTARTSYS; |
| 1857 | |
| 1858 | for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) { |
| 1859 | entry = list_entry(ptr, struct mac_entry, _list); |
| 1860 | |
| 1861 | memcpy(dst->sa_data, entry->addr, ETH_ALEN); |
| 1862 | dst->sa_family = ARPHRD_ETHER; |
| 1863 | dwrq->length++; |
| 1864 | dst++; |
| 1865 | } |
| 1866 | up(&acl->sem); |
| 1867 | return 0; |
| 1868 | } |
| 1869 | |
| 1870 | /* Setting policy also clears the MAC acl, even if we don't change the defaut |
| 1871 | * policy |
| 1872 | */ |
| 1873 | |
| 1874 | static int |
| 1875 | prism54_set_policy(struct net_device *ndev, struct iw_request_info *info, |
| 1876 | __u32 * uwrq, char *extra) |
| 1877 | { |
| 1878 | islpci_private *priv = netdev_priv(ndev); |
| 1879 | struct islpci_acl *acl = &priv->acl; |
| 1880 | u32 mlmeautolevel; |
| 1881 | |
| 1882 | prism54_clear_mac(acl); |
| 1883 | |
| 1884 | if ((*uwrq < MAC_POLICY_OPEN) || (*uwrq > MAC_POLICY_REJECT)) |
| 1885 | return -EINVAL; |
| 1886 | |
| 1887 | down_write(&priv->mib_sem); |
| 1888 | |
| 1889 | acl->policy = *uwrq; |
| 1890 | |
| 1891 | /* the ACL code needs an intermediate mlmeautolevel */ |
| 1892 | if ((priv->iw_mode == IW_MODE_MASTER) && |
| 1893 | (acl->policy != MAC_POLICY_OPEN)) |
| 1894 | mlmeautolevel = DOT11_MLME_INTERMEDIATE; |
| 1895 | else |
| 1896 | mlmeautolevel = CARD_DEFAULT_MLME_MODE; |
| 1897 | if (priv->wpa) |
| 1898 | mlmeautolevel = DOT11_MLME_EXTENDED; |
| 1899 | mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel); |
| 1900 | /* restart the card with our new policy */ |
| 1901 | if (mgt_commit(priv)) { |
| 1902 | up_write(&priv->mib_sem); |
| 1903 | return -EIO; |
| 1904 | } |
| 1905 | up_write(&priv->mib_sem); |
| 1906 | |
| 1907 | return 0; |
| 1908 | } |
| 1909 | |
| 1910 | static int |
| 1911 | prism54_get_policy(struct net_device *ndev, struct iw_request_info *info, |
| 1912 | __u32 * uwrq, char *extra) |
| 1913 | { |
| 1914 | islpci_private *priv = netdev_priv(ndev); |
| 1915 | struct islpci_acl *acl = &priv->acl; |
| 1916 | |
| 1917 | *uwrq = acl->policy; |
| 1918 | |
| 1919 | return 0; |
| 1920 | } |
| 1921 | |
| 1922 | /* Return 1 only if client should be accepted. */ |
| 1923 | |
| 1924 | static int |
| 1925 | prism54_mac_accept(struct islpci_acl *acl, char *mac) |
| 1926 | { |
| 1927 | struct list_head *ptr; |
| 1928 | struct mac_entry *entry; |
| 1929 | int res = 0; |
| 1930 | |
| 1931 | if (down_interruptible(&acl->sem)) |
| 1932 | return -ERESTARTSYS; |
| 1933 | |
| 1934 | if (acl->policy == MAC_POLICY_OPEN) { |
| 1935 | up(&acl->sem); |
| 1936 | return 1; |
| 1937 | } |
| 1938 | |
| 1939 | for (ptr = acl->mac_list.next; ptr != &acl->mac_list; ptr = ptr->next) { |
| 1940 | entry = list_entry(ptr, struct mac_entry, _list); |
| 1941 | if (memcmp(entry->addr, mac, ETH_ALEN) == 0) { |
| 1942 | res = 1; |
| 1943 | break; |
| 1944 | } |
| 1945 | } |
| 1946 | res = (acl->policy == MAC_POLICY_ACCEPT) ? !res : res; |
| 1947 | up(&acl->sem); |
| 1948 | |
| 1949 | return res; |
| 1950 | } |
| 1951 | |
| 1952 | static int |
| 1953 | prism54_kick_all(struct net_device *ndev, struct iw_request_info *info, |
| 1954 | struct iw_point *dwrq, char *extra) |
| 1955 | { |
| 1956 | struct obj_mlme *mlme; |
| 1957 | int rvalue; |
| 1958 | |
| 1959 | mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL); |
| 1960 | if (mlme == NULL) |
| 1961 | return -ENOMEM; |
| 1962 | |
| 1963 | /* Tell the card to kick every client */ |
| 1964 | mlme->id = 0; |
| 1965 | rvalue = |
| 1966 | mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme); |
| 1967 | kfree(mlme); |
| 1968 | |
| 1969 | return rvalue; |
| 1970 | } |
| 1971 | |
| 1972 | static int |
| 1973 | prism54_kick_mac(struct net_device *ndev, struct iw_request_info *info, |
| 1974 | struct sockaddr *awrq, char *extra) |
| 1975 | { |
| 1976 | struct obj_mlme *mlme; |
| 1977 | struct sockaddr *addr = (struct sockaddr *) extra; |
| 1978 | int rvalue; |
| 1979 | |
| 1980 | if (addr->sa_family != ARPHRD_ETHER) |
| 1981 | return -EOPNOTSUPP; |
| 1982 | |
| 1983 | mlme = kmalloc(sizeof (struct obj_mlme), GFP_KERNEL); |
| 1984 | if (mlme == NULL) |
| 1985 | return -ENOMEM; |
| 1986 | |
| 1987 | /* Tell the card to only kick the corresponding bastard */ |
| 1988 | memcpy(mlme->address, addr->sa_data, ETH_ALEN); |
| 1989 | mlme->id = -1; |
| 1990 | rvalue = |
| 1991 | mgt_set_request(netdev_priv(ndev), DOT11_OID_DISASSOCIATE, 0, mlme); |
| 1992 | |
| 1993 | kfree(mlme); |
| 1994 | |
| 1995 | return rvalue; |
| 1996 | } |
| 1997 | |
| 1998 | /* Translate a TRAP oid into a wireless event. Called in islpci_mgt_receive. */ |
| 1999 | |
| 2000 | static void |
| 2001 | format_event(islpci_private *priv, char *dest, const char *str, |
| 2002 | const struct obj_mlme *mlme, u16 *length, int error) |
| 2003 | { |
| 2004 | const u8 *a = mlme->address; |
| 2005 | int n = snprintf(dest, IW_CUSTOM_MAX, |
| 2006 | "%s %s %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X %s (%2.2X)", |
| 2007 | str, |
| 2008 | ((priv->iw_mode == IW_MODE_MASTER) ? "from" : "to"), |
| 2009 | a[0], a[1], a[2], a[3], a[4], a[5], |
| 2010 | (error ? (mlme->code ? " : REJECTED " : " : ACCEPTED ") |
| 2011 | : ""), mlme->code); |
| 2012 | BUG_ON(n > IW_CUSTOM_MAX); |
| 2013 | *length = n; |
| 2014 | } |
| 2015 | |
| 2016 | static void |
| 2017 | send_formatted_event(islpci_private *priv, const char *str, |
| 2018 | const struct obj_mlme *mlme, int error) |
| 2019 | { |
| 2020 | union iwreq_data wrqu; |
| 2021 | char *memptr; |
| 2022 | |
| 2023 | memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL); |
| 2024 | if (!memptr) |
| 2025 | return; |
| 2026 | wrqu.data.pointer = memptr; |
| 2027 | wrqu.data.length = 0; |
| 2028 | format_event(priv, memptr, str, mlme, &wrqu.data.length, |
| 2029 | error); |
| 2030 | wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr); |
| 2031 | kfree(memptr); |
| 2032 | } |
| 2033 | |
| 2034 | static void |
| 2035 | send_simple_event(islpci_private *priv, const char *str) |
| 2036 | { |
| 2037 | union iwreq_data wrqu; |
| 2038 | char *memptr; |
| 2039 | int n = strlen(str); |
| 2040 | |
| 2041 | memptr = kmalloc(IW_CUSTOM_MAX, GFP_KERNEL); |
| 2042 | if (!memptr) |
| 2043 | return; |
| 2044 | BUG_ON(n > IW_CUSTOM_MAX); |
| 2045 | wrqu.data.pointer = memptr; |
| 2046 | wrqu.data.length = n; |
| 2047 | strcpy(memptr, str); |
| 2048 | wireless_send_event(priv->ndev, IWEVCUSTOM, &wrqu, memptr); |
| 2049 | kfree(memptr); |
| 2050 | } |
| 2051 | |
| 2052 | static void |
| 2053 | link_changed(struct net_device *ndev, u32 bitrate) |
| 2054 | { |
| 2055 | islpci_private *priv = netdev_priv(ndev); |
| 2056 | |
| 2057 | if (bitrate) { |
| 2058 | if (priv->iw_mode == IW_MODE_INFRA) { |
| 2059 | union iwreq_data uwrq; |
| 2060 | prism54_get_wap(ndev, NULL, (struct sockaddr *) &uwrq, |
| 2061 | NULL); |
| 2062 | wireless_send_event(ndev, SIOCGIWAP, &uwrq, NULL); |
| 2063 | } else |
| 2064 | send_simple_event(netdev_priv(ndev), |
| 2065 | "Link established"); |
| 2066 | } else |
| 2067 | send_simple_event(netdev_priv(ndev), "Link lost"); |
| 2068 | } |
| 2069 | |
| 2070 | /* Beacon/ProbeResp payload header */ |
| 2071 | struct ieee80211_beacon_phdr { |
| 2072 | u8 timestamp[8]; |
| 2073 | u16 beacon_int; |
| 2074 | u16 capab_info; |
| 2075 | } __attribute__ ((packed)); |
| 2076 | |
| 2077 | #define WLAN_EID_GENERIC 0xdd |
| 2078 | static u8 wpa_oid[4] = { 0x00, 0x50, 0xf2, 1 }; |
| 2079 | |
| 2080 | #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] |
| 2081 | #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" |
| 2082 | |
| 2083 | static void |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2084 | prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid, |
| 2085 | u8 *wpa_ie, size_t wpa_ie_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | { |
| 2087 | struct list_head *ptr; |
| 2088 | struct islpci_bss_wpa_ie *bss = NULL; |
| 2089 | |
| 2090 | if (wpa_ie_len > MAX_WPA_IE_LEN) |
| 2091 | wpa_ie_len = MAX_WPA_IE_LEN; |
| 2092 | |
| 2093 | if (down_interruptible(&priv->wpa_sem)) |
| 2094 | return; |
| 2095 | |
| 2096 | /* try to use existing entry */ |
| 2097 | list_for_each(ptr, &priv->bss_wpa_list) { |
| 2098 | bss = list_entry(ptr, struct islpci_bss_wpa_ie, list); |
| 2099 | if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) { |
| 2100 | list_move(&bss->list, &priv->bss_wpa_list); |
| 2101 | break; |
| 2102 | } |
| 2103 | bss = NULL; |
| 2104 | } |
| 2105 | |
| 2106 | if (bss == NULL) { |
| 2107 | /* add a new BSS entry; if max number of entries is already |
| 2108 | * reached, replace the least recently updated */ |
| 2109 | if (priv->num_bss_wpa >= MAX_BSS_WPA_IE_COUNT) { |
| 2110 | bss = list_entry(priv->bss_wpa_list.prev, |
| 2111 | struct islpci_bss_wpa_ie, list); |
| 2112 | list_del(&bss->list); |
| 2113 | } else { |
| 2114 | bss = kmalloc(sizeof (*bss), GFP_ATOMIC); |
| 2115 | if (bss != NULL) { |
| 2116 | priv->num_bss_wpa++; |
| 2117 | memset(bss, 0, sizeof (*bss)); |
| 2118 | } |
| 2119 | } |
| 2120 | if (bss != NULL) { |
| 2121 | memcpy(bss->bssid, bssid, ETH_ALEN); |
| 2122 | list_add(&bss->list, &priv->bss_wpa_list); |
| 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | if (bss != NULL) { |
| 2127 | memcpy(bss->wpa_ie, wpa_ie, wpa_ie_len); |
| 2128 | bss->wpa_ie_len = wpa_ie_len; |
| 2129 | bss->last_update = jiffies; |
| 2130 | } else { |
| 2131 | printk(KERN_DEBUG "Failed to add BSS WPA entry for " MACSTR |
| 2132 | "\n", MAC2STR(bssid)); |
| 2133 | } |
| 2134 | |
| 2135 | /* expire old entries from WPA list */ |
| 2136 | while (priv->num_bss_wpa > 0) { |
| 2137 | bss = list_entry(priv->bss_wpa_list.prev, |
| 2138 | struct islpci_bss_wpa_ie, list); |
| 2139 | if (!time_after(jiffies, bss->last_update + 60 * HZ)) |
| 2140 | break; |
| 2141 | |
| 2142 | list_del(&bss->list); |
| 2143 | priv->num_bss_wpa--; |
| 2144 | kfree(bss); |
| 2145 | } |
| 2146 | |
| 2147 | up(&priv->wpa_sem); |
| 2148 | } |
| 2149 | |
| 2150 | static size_t |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2151 | prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | { |
| 2153 | struct list_head *ptr; |
| 2154 | struct islpci_bss_wpa_ie *bss = NULL; |
| 2155 | size_t len = 0; |
| 2156 | |
| 2157 | if (down_interruptible(&priv->wpa_sem)) |
| 2158 | return 0; |
| 2159 | |
| 2160 | list_for_each(ptr, &priv->bss_wpa_list) { |
| 2161 | bss = list_entry(ptr, struct islpci_bss_wpa_ie, list); |
| 2162 | if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) |
| 2163 | break; |
| 2164 | bss = NULL; |
| 2165 | } |
| 2166 | if (bss) { |
| 2167 | len = bss->wpa_ie_len; |
| 2168 | memcpy(wpa_ie, bss->wpa_ie, len); |
| 2169 | } |
| 2170 | up(&priv->wpa_sem); |
| 2171 | |
| 2172 | return len; |
| 2173 | } |
| 2174 | |
| 2175 | void |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2176 | prism54_wpa_bss_ie_init(islpci_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | { |
| 2178 | INIT_LIST_HEAD(&priv->bss_wpa_list); |
| 2179 | sema_init(&priv->wpa_sem, 1); |
| 2180 | } |
| 2181 | |
| 2182 | void |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2183 | prism54_wpa_bss_ie_clean(islpci_private *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | { |
| 2185 | struct list_head *ptr, *n; |
| 2186 | |
| 2187 | list_for_each_safe(ptr, n, &priv->bss_wpa_list) { |
| 2188 | struct islpci_bss_wpa_ie *bss; |
| 2189 | bss = list_entry(ptr, struct islpci_bss_wpa_ie, list); |
| 2190 | kfree(bss); |
| 2191 | } |
| 2192 | } |
| 2193 | |
| 2194 | static void |
| 2195 | prism54_process_bss_data(islpci_private *priv, u32 oid, u8 *addr, |
| 2196 | u8 *payload, size_t len) |
| 2197 | { |
| 2198 | struct ieee80211_beacon_phdr *hdr; |
| 2199 | u8 *pos, *end; |
| 2200 | |
| 2201 | if (!priv->wpa) |
| 2202 | return; |
| 2203 | |
| 2204 | hdr = (struct ieee80211_beacon_phdr *) payload; |
| 2205 | pos = (u8 *) (hdr + 1); |
| 2206 | end = payload + len; |
| 2207 | while (pos < end) { |
| 2208 | if (pos + 2 + pos[1] > end) { |
| 2209 | printk(KERN_DEBUG "Parsing Beacon/ProbeResp failed " |
| 2210 | "for " MACSTR "\n", MAC2STR(addr)); |
| 2211 | return; |
| 2212 | } |
| 2213 | if (pos[0] == WLAN_EID_GENERIC && pos[1] >= 4 && |
| 2214 | memcmp(pos + 2, wpa_oid, 4) == 0) { |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2215 | prism54_wpa_bss_ie_add(priv, addr, pos, pos[1] + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | return; |
| 2217 | } |
| 2218 | pos += 2 + pos[1]; |
| 2219 | } |
| 2220 | } |
| 2221 | |
| 2222 | static void |
| 2223 | handle_request(islpci_private *priv, struct obj_mlme *mlme, enum oid_num_t oid) |
| 2224 | { |
| 2225 | if (((mlme->state == DOT11_STATE_AUTHING) || |
| 2226 | (mlme->state == DOT11_STATE_ASSOCING)) |
| 2227 | && mgt_mlme_answer(priv)) { |
| 2228 | /* Someone is requesting auth and we must respond. Just send back |
| 2229 | * the trap with error code set accordingly. |
| 2230 | */ |
| 2231 | mlme->code = prism54_mac_accept(&priv->acl, |
| 2232 | mlme->address) ? 0 : 1; |
| 2233 | mgt_set_request(priv, oid, 0, mlme); |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | static int |
| 2238 | prism54_process_trap_helper(islpci_private *priv, enum oid_num_t oid, |
| 2239 | char *data) |
| 2240 | { |
| 2241 | struct obj_mlme *mlme = (struct obj_mlme *) data; |
| 2242 | struct obj_mlmeex *mlmeex = (struct obj_mlmeex *) data; |
| 2243 | struct obj_mlmeex *confirm; |
| 2244 | u8 wpa_ie[MAX_WPA_IE_LEN]; |
| 2245 | int wpa_ie_len; |
| 2246 | size_t len = 0; /* u16, better? */ |
| 2247 | u8 *payload = NULL, *pos = NULL; |
| 2248 | int ret; |
| 2249 | |
| 2250 | /* I think all trapable objects are listed here. |
| 2251 | * Some oids have a EX version. The difference is that they are emitted |
| 2252 | * in DOT11_MLME_EXTENDED mode (set with DOT11_OID_MLMEAUTOLEVEL) |
| 2253 | * with more info. |
| 2254 | * The few events already defined by the wireless tools are not really |
| 2255 | * suited. We use the more flexible custom event facility. |
| 2256 | */ |
| 2257 | |
| 2258 | if (oid >= DOT11_OID_BEACON) { |
| 2259 | len = mlmeex->size; |
| 2260 | payload = pos = mlmeex->data; |
| 2261 | } |
| 2262 | |
| 2263 | /* I fear prism54_process_bss_data won't work with big endian data */ |
| 2264 | if ((oid == DOT11_OID_BEACON) || (oid == DOT11_OID_PROBE)) |
| 2265 | prism54_process_bss_data(priv, oid, mlmeex->address, |
| 2266 | payload, len); |
| 2267 | |
| 2268 | mgt_le_to_cpu(isl_oid[oid].flags & OID_FLAG_TYPE, (void *) mlme); |
| 2269 | |
| 2270 | switch (oid) { |
| 2271 | |
| 2272 | case GEN_OID_LINKSTATE: |
| 2273 | link_changed(priv->ndev, (u32) *data); |
| 2274 | break; |
| 2275 | |
| 2276 | case DOT11_OID_MICFAILURE: |
| 2277 | send_simple_event(priv, "Mic failure"); |
| 2278 | break; |
| 2279 | |
| 2280 | case DOT11_OID_DEAUTHENTICATE: |
| 2281 | send_formatted_event(priv, "DeAuthenticate request", mlme, 0); |
| 2282 | break; |
| 2283 | |
| 2284 | case DOT11_OID_AUTHENTICATE: |
| 2285 | handle_request(priv, mlme, oid); |
| 2286 | send_formatted_event(priv, "Authenticate request", mlme, 1); |
| 2287 | break; |
| 2288 | |
| 2289 | case DOT11_OID_DISASSOCIATE: |
| 2290 | send_formatted_event(priv, "Disassociate request", mlme, 0); |
| 2291 | break; |
| 2292 | |
| 2293 | case DOT11_OID_ASSOCIATE: |
| 2294 | handle_request(priv, mlme, oid); |
| 2295 | send_formatted_event(priv, "Associate request", mlme, 1); |
| 2296 | break; |
| 2297 | |
| 2298 | case DOT11_OID_REASSOCIATE: |
| 2299 | handle_request(priv, mlme, oid); |
| 2300 | send_formatted_event(priv, "ReAssociate request", mlme, 1); |
| 2301 | break; |
| 2302 | |
| 2303 | case DOT11_OID_BEACON: |
| 2304 | send_formatted_event(priv, |
| 2305 | "Received a beacon from an unkown AP", |
| 2306 | mlme, 0); |
| 2307 | break; |
| 2308 | |
| 2309 | case DOT11_OID_PROBE: |
| 2310 | /* we received a probe from a client. */ |
| 2311 | send_formatted_event(priv, "Received a probe from client", mlme, |
| 2312 | 0); |
| 2313 | break; |
| 2314 | |
| 2315 | /* Note : "mlme" is actually a "struct obj_mlmeex *" here, but this |
| 2316 | * is backward compatible layout-wise with "struct obj_mlme". |
| 2317 | */ |
| 2318 | |
| 2319 | case DOT11_OID_DEAUTHENTICATEEX: |
| 2320 | send_formatted_event(priv, "DeAuthenticate request", mlme, 0); |
| 2321 | break; |
| 2322 | |
| 2323 | case DOT11_OID_AUTHENTICATEEX: |
| 2324 | handle_request(priv, mlme, oid); |
| 2325 | send_formatted_event(priv, "Authenticate request (ex)", mlme, 1); |
| 2326 | |
| 2327 | if (priv->iw_mode != IW_MODE_MASTER |
| 2328 | && mlmeex->state != DOT11_STATE_AUTHING) |
| 2329 | break; |
| 2330 | |
| 2331 | confirm = kmalloc(sizeof(struct obj_mlmeex) + 6, GFP_ATOMIC); |
| 2332 | |
| 2333 | if (!confirm) |
| 2334 | break; |
| 2335 | |
| 2336 | memcpy(&confirm->address, mlmeex->address, ETH_ALEN); |
| 2337 | printk(KERN_DEBUG "Authenticate from: address:\t%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 2338 | mlmeex->address[0], |
| 2339 | mlmeex->address[1], |
| 2340 | mlmeex->address[2], |
| 2341 | mlmeex->address[3], |
| 2342 | mlmeex->address[4], |
| 2343 | mlmeex->address[5] |
| 2344 | ); |
| 2345 | confirm->id = -1; /* or mlmeex->id ? */ |
| 2346 | confirm->state = 0; /* not used */ |
| 2347 | confirm->code = 0; |
| 2348 | confirm->size = 6; |
| 2349 | confirm->data[0] = 0x00; |
| 2350 | confirm->data[1] = 0x00; |
| 2351 | confirm->data[2] = 0x02; |
| 2352 | confirm->data[3] = 0x00; |
| 2353 | confirm->data[4] = 0x00; |
| 2354 | confirm->data[5] = 0x00; |
| 2355 | |
| 2356 | ret = mgt_set_varlen(priv, DOT11_OID_ASSOCIATEEX, confirm, 6); |
| 2357 | |
| 2358 | kfree(confirm); |
| 2359 | if (ret) |
| 2360 | return ret; |
| 2361 | break; |
| 2362 | |
| 2363 | case DOT11_OID_DISASSOCIATEEX: |
| 2364 | send_formatted_event(priv, "Disassociate request (ex)", mlme, 0); |
| 2365 | break; |
| 2366 | |
| 2367 | case DOT11_OID_ASSOCIATEEX: |
| 2368 | handle_request(priv, mlme, oid); |
| 2369 | send_formatted_event(priv, "Associate request (ex)", mlme, 1); |
| 2370 | |
| 2371 | if (priv->iw_mode != IW_MODE_MASTER |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2372 | && mlmeex->state != DOT11_STATE_ASSOCING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | break; |
| 2374 | |
| 2375 | confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC); |
| 2376 | |
| 2377 | if (!confirm) |
| 2378 | break; |
| 2379 | |
| 2380 | memcpy(&confirm->address, mlmeex->address, ETH_ALEN); |
| 2381 | |
| 2382 | confirm->id = ((struct obj_mlmeex *)mlme)->id; |
| 2383 | confirm->state = 0; /* not used */ |
| 2384 | confirm->code = 0; |
| 2385 | |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2386 | wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | |
| 2388 | if (!wpa_ie_len) { |
| 2389 | printk(KERN_DEBUG "No WPA IE found from " |
| 2390 | "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 2391 | mlmeex->address[0], |
| 2392 | mlmeex->address[1], |
| 2393 | mlmeex->address[2], |
| 2394 | mlmeex->address[3], |
| 2395 | mlmeex->address[4], |
| 2396 | mlmeex->address[5] |
| 2397 | ); |
| 2398 | kfree(confirm); |
| 2399 | break; |
| 2400 | } |
| 2401 | |
| 2402 | confirm->size = wpa_ie_len; |
| 2403 | memcpy(&confirm->data, wpa_ie, wpa_ie_len); |
| 2404 | |
| 2405 | mgt_set_varlen(priv, oid, confirm, wpa_ie_len); |
| 2406 | |
| 2407 | kfree(confirm); |
| 2408 | |
| 2409 | break; |
| 2410 | |
| 2411 | case DOT11_OID_REASSOCIATEEX: |
| 2412 | handle_request(priv, mlme, oid); |
| 2413 | send_formatted_event(priv, "Reassociate request (ex)", mlme, 1); |
| 2414 | |
| 2415 | if (priv->iw_mode != IW_MODE_MASTER |
| 2416 | && mlmeex->state != DOT11_STATE_ASSOCING) |
| 2417 | break; |
| 2418 | |
| 2419 | confirm = kmalloc(sizeof(struct obj_mlmeex), GFP_ATOMIC); |
| 2420 | |
| 2421 | if (!confirm) |
| 2422 | break; |
| 2423 | |
| 2424 | memcpy(&confirm->address, mlmeex->address, ETH_ALEN); |
| 2425 | |
| 2426 | confirm->id = mlmeex->id; |
| 2427 | confirm->state = 0; /* not used */ |
| 2428 | confirm->code = 0; |
| 2429 | |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 2430 | wpa_ie_len = prism54_wpa_bss_ie_get(priv, mlmeex->address, wpa_ie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | |
| 2432 | if (!wpa_ie_len) { |
| 2433 | printk(KERN_DEBUG "No WPA IE found from " |
| 2434 | "address:\t%02x:%02x:%02x:%02x:%02x:%02x\n", |
| 2435 | mlmeex->address[0], |
| 2436 | mlmeex->address[1], |
| 2437 | mlmeex->address[2], |
| 2438 | mlmeex->address[3], |
| 2439 | mlmeex->address[4], |
| 2440 | mlmeex->address[5] |
| 2441 | ); |
| 2442 | kfree(confirm); |
| 2443 | break; |
| 2444 | } |
| 2445 | |
| 2446 | confirm->size = wpa_ie_len; |
| 2447 | memcpy(&confirm->data, wpa_ie, wpa_ie_len); |
| 2448 | |
| 2449 | mgt_set_varlen(priv, oid, confirm, wpa_ie_len); |
| 2450 | |
| 2451 | kfree(confirm); |
| 2452 | |
| 2453 | break; |
| 2454 | |
| 2455 | default: |
| 2456 | return -EINVAL; |
| 2457 | } |
| 2458 | |
| 2459 | return 0; |
| 2460 | } |
| 2461 | |
| 2462 | /* |
| 2463 | * Process a device trap. This is called via schedule_work(), outside of |
| 2464 | * interrupt context, no locks held. |
| 2465 | */ |
| 2466 | void |
| 2467 | prism54_process_trap(void *data) |
| 2468 | { |
| 2469 | struct islpci_mgmtframe *frame = data; |
| 2470 | struct net_device *ndev = frame->ndev; |
| 2471 | enum oid_num_t n = mgt_oidtonum(frame->header->oid); |
| 2472 | |
| 2473 | if (n != OID_NUM_LAST) |
| 2474 | prism54_process_trap_helper(netdev_priv(ndev), n, frame->data); |
| 2475 | islpci_mgt_release(frame); |
| 2476 | } |
| 2477 | |
| 2478 | int |
| 2479 | prism54_set_mac_address(struct net_device *ndev, void *addr) |
| 2480 | { |
| 2481 | islpci_private *priv = netdev_priv(ndev); |
| 2482 | int ret; |
| 2483 | |
| 2484 | if (ndev->addr_len != 6) |
| 2485 | return -EINVAL; |
| 2486 | ret = mgt_set_request(priv, GEN_OID_MACADDRESS, 0, |
| 2487 | &((struct sockaddr *) addr)->sa_data); |
| 2488 | if (!ret) |
| 2489 | memcpy(priv->ndev->dev_addr, |
| 2490 | &((struct sockaddr *) addr)->sa_data, 6); |
| 2491 | |
| 2492 | return ret; |
| 2493 | } |
| 2494 | |
| 2495 | /* Note: currently, use hostapd ioctl from the Host AP driver for WPA |
| 2496 | * support. This is to be replaced with Linux wireless extensions once they |
| 2497 | * get WPA support. */ |
| 2498 | |
| 2499 | /* Note II: please leave all this together as it will be easier to remove later, |
| 2500 | * once wireless extensions add WPA support -mcgrof */ |
| 2501 | |
| 2502 | /* PRISM54_HOSTAPD ioctl() cmd: */ |
| 2503 | enum { |
| 2504 | PRISM2_SET_ENCRYPTION = 6, |
| 2505 | PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12, |
| 2506 | PRISM2_HOSTAPD_MLME = 13, |
| 2507 | PRISM2_HOSTAPD_SCAN_REQ = 14, |
| 2508 | }; |
| 2509 | |
| 2510 | #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12 |
| 2511 | #define PRISM54_HOSTAPD SIOCIWFIRSTPRIV+25 |
| 2512 | #define PRISM54_DROP_UNENCRYPTED SIOCIWFIRSTPRIV+26 |
| 2513 | |
| 2514 | #define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024 |
| 2515 | #define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \ |
| 2516 | ((int) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data)) |
| 2517 | |
| 2518 | /* Maximum length for algorithm names (-1 for nul termination) |
| 2519 | * used in ioctl() */ |
| 2520 | #define HOSTAP_CRYPT_ALG_NAME_LEN 16 |
| 2521 | |
| 2522 | struct prism2_hostapd_param { |
| 2523 | u32 cmd; |
| 2524 | u8 sta_addr[ETH_ALEN]; |
| 2525 | union { |
| 2526 | struct { |
| 2527 | u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN]; |
| 2528 | u32 flags; |
| 2529 | u32 err; |
| 2530 | u8 idx; |
| 2531 | u8 seq[8]; /* sequence counter (set: RX, get: TX) */ |
| 2532 | u16 key_len; |
| 2533 | u8 key[0]; |
| 2534 | } crypt; |
| 2535 | struct { |
| 2536 | u8 len; |
| 2537 | u8 data[0]; |
| 2538 | } generic_elem; |
| 2539 | struct { |
| 2540 | #define MLME_STA_DEAUTH 0 |
| 2541 | #define MLME_STA_DISASSOC 1 |
| 2542 | u16 cmd; |
| 2543 | u16 reason_code; |
| 2544 | } mlme; |
| 2545 | struct { |
| 2546 | u8 ssid_len; |
| 2547 | u8 ssid[32]; |
| 2548 | } scan_req; |
| 2549 | } u; |
| 2550 | }; |
| 2551 | |
| 2552 | |
| 2553 | static int |
| 2554 | prism2_ioctl_set_encryption(struct net_device *dev, |
| 2555 | struct prism2_hostapd_param *param, |
| 2556 | int param_len) |
| 2557 | { |
| 2558 | islpci_private *priv = netdev_priv(dev); |
| 2559 | int rvalue = 0, force = 0; |
| 2560 | int authen = DOT11_AUTH_OS, invoke = 0, exunencrypt = 0; |
| 2561 | union oid_res_t r; |
| 2562 | |
| 2563 | /* with the new API, it's impossible to get a NULL pointer. |
| 2564 | * New version of iwconfig set the IW_ENCODE_NOKEY flag |
| 2565 | * when no key is given, but older versions don't. */ |
| 2566 | |
| 2567 | if (param->u.crypt.key_len > 0) { |
| 2568 | /* we have a key to set */ |
| 2569 | int index = param->u.crypt.idx; |
| 2570 | int current_index; |
| 2571 | struct obj_key key = { DOT11_PRIV_TKIP, 0, "" }; |
| 2572 | |
| 2573 | /* get the current key index */ |
| 2574 | rvalue = mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); |
| 2575 | current_index = r.u; |
| 2576 | /* Verify that the key is not marked as invalid */ |
| 2577 | if (!(param->u.crypt.flags & IW_ENCODE_NOKEY)) { |
| 2578 | key.length = param->u.crypt.key_len > sizeof (param->u.crypt.key) ? |
| 2579 | sizeof (param->u.crypt.key) : param->u.crypt.key_len; |
| 2580 | memcpy(key.key, param->u.crypt.key, key.length); |
| 2581 | if (key.length == 32) |
| 2582 | /* we want WPA-PSK */ |
| 2583 | key.type = DOT11_PRIV_TKIP; |
| 2584 | if ((index < 0) || (index > 3)) |
| 2585 | /* no index provided use the current one */ |
| 2586 | index = current_index; |
| 2587 | |
| 2588 | /* now send the key to the card */ |
| 2589 | rvalue |= |
| 2590 | mgt_set_request(priv, DOT11_OID_DEFKEYX, index, |
| 2591 | &key); |
| 2592 | } |
| 2593 | /* |
| 2594 | * If a valid key is set, encryption should be enabled |
| 2595 | * (user may turn it off later). |
| 2596 | * This is also how "iwconfig ethX key on" works |
| 2597 | */ |
| 2598 | if ((index == current_index) && (key.length > 0)) |
| 2599 | force = 1; |
| 2600 | } else { |
| 2601 | int index = (param->u.crypt.flags & IW_ENCODE_INDEX) - 1; |
| 2602 | if ((index >= 0) && (index <= 3)) { |
| 2603 | /* we want to set the key index */ |
| 2604 | rvalue |= |
| 2605 | mgt_set_request(priv, DOT11_OID_DEFKEYID, 0, |
| 2606 | &index); |
| 2607 | } else { |
| 2608 | if (!param->u.crypt.flags & IW_ENCODE_MODE) { |
| 2609 | /* we cannot do anything. Complain. */ |
| 2610 | return -EINVAL; |
| 2611 | } |
| 2612 | } |
| 2613 | } |
| 2614 | /* now read the flags */ |
| 2615 | if (param->u.crypt.flags & IW_ENCODE_DISABLED) { |
| 2616 | /* Encoding disabled, |
| 2617 | * authen = DOT11_AUTH_OS; |
| 2618 | * invoke = 0; |
| 2619 | * exunencrypt = 0; */ |
| 2620 | } |
| 2621 | if (param->u.crypt.flags & IW_ENCODE_OPEN) |
| 2622 | /* Encode but accept non-encoded packets. No auth */ |
| 2623 | invoke = 1; |
| 2624 | if ((param->u.crypt.flags & IW_ENCODE_RESTRICTED) || force) { |
| 2625 | /* Refuse non-encoded packets. Auth */ |
| 2626 | authen = DOT11_AUTH_BOTH; |
| 2627 | invoke = 1; |
| 2628 | exunencrypt = 1; |
| 2629 | } |
| 2630 | /* do the change if requested */ |
| 2631 | if ((param->u.crypt.flags & IW_ENCODE_MODE) || force) { |
| 2632 | rvalue |= |
| 2633 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); |
| 2634 | rvalue |= |
| 2635 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &invoke); |
| 2636 | rvalue |= |
| 2637 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, |
| 2638 | &exunencrypt); |
| 2639 | } |
| 2640 | return rvalue; |
| 2641 | } |
| 2642 | |
| 2643 | static int |
| 2644 | prism2_ioctl_set_generic_element(struct net_device *ndev, |
| 2645 | struct prism2_hostapd_param *param, |
| 2646 | int param_len) |
| 2647 | { |
| 2648 | islpci_private *priv = netdev_priv(ndev); |
| 2649 | int max_len, len, alen, ret=0; |
| 2650 | struct obj_attachment *attach; |
| 2651 | |
| 2652 | len = param->u.generic_elem.len; |
| 2653 | max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN; |
| 2654 | if (max_len < 0 || max_len < len) |
| 2655 | return -EINVAL; |
| 2656 | |
| 2657 | alen = sizeof(*attach) + len; |
| 2658 | attach = kmalloc(alen, GFP_KERNEL); |
| 2659 | if (attach == NULL) |
| 2660 | return -ENOMEM; |
| 2661 | |
| 2662 | memset(attach, 0, alen); |
| 2663 | #define WLAN_FC_TYPE_MGMT 0 |
| 2664 | #define WLAN_FC_STYPE_ASSOC_REQ 0 |
| 2665 | #define WLAN_FC_STYPE_REASSOC_REQ 2 |
| 2666 | |
| 2667 | /* Note: endianness is covered by mgt_set_varlen */ |
| 2668 | |
| 2669 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | |
| 2670 | (WLAN_FC_STYPE_ASSOC_REQ << 4); |
| 2671 | attach->id = -1; |
| 2672 | attach->size = len; |
| 2673 | memcpy(attach->data, param->u.generic_elem.data, len); |
| 2674 | |
| 2675 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len); |
| 2676 | |
| 2677 | if (ret == 0) { |
| 2678 | attach->type = (WLAN_FC_TYPE_MGMT << 2) | |
| 2679 | (WLAN_FC_STYPE_REASSOC_REQ << 4); |
| 2680 | |
| 2681 | ret = mgt_set_varlen(priv, DOT11_OID_ATTACHMENT, attach, len); |
| 2682 | |
| 2683 | if (ret == 0) |
| 2684 | printk(KERN_DEBUG "%s: WPA IE Attachment was set\n", |
| 2685 | ndev->name); |
| 2686 | } |
| 2687 | |
| 2688 | kfree(attach); |
| 2689 | return ret; |
| 2690 | |
| 2691 | } |
| 2692 | |
| 2693 | static int |
| 2694 | prism2_ioctl_mlme(struct net_device *dev, struct prism2_hostapd_param *param) |
| 2695 | { |
| 2696 | return -EOPNOTSUPP; |
| 2697 | } |
| 2698 | |
| 2699 | static int |
| 2700 | prism2_ioctl_scan_req(struct net_device *ndev, |
| 2701 | struct prism2_hostapd_param *param) |
| 2702 | { |
| 2703 | islpci_private *priv = netdev_priv(ndev); |
| 2704 | int i, rvalue; |
| 2705 | struct obj_bsslist *bsslist; |
| 2706 | u32 noise = 0; |
| 2707 | char *extra = ""; |
| 2708 | char *current_ev = "foo"; |
| 2709 | union oid_res_t r; |
| 2710 | |
| 2711 | if (islpci_get_state(priv) < PRV_STATE_INIT) { |
| 2712 | /* device is not ready, fail gently */ |
| 2713 | return 0; |
| 2714 | } |
| 2715 | |
| 2716 | /* first get the noise value. We will use it to report the link quality */ |
| 2717 | rvalue = mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r); |
| 2718 | noise = r.u; |
| 2719 | |
| 2720 | /* Ask the device for a list of known bss. We can report at most |
| 2721 | * IW_MAX_AP=64 to the range struct. But the device won't repport anything |
| 2722 | * if you change the value of IWMAX_BSS=24. |
| 2723 | */ |
| 2724 | rvalue |= mgt_get_request(priv, DOT11_OID_BSSLIST, 0, NULL, &r); |
| 2725 | bsslist = r.ptr; |
| 2726 | |
| 2727 | /* ok now, scan the list and translate its info */ |
| 2728 | for (i = 0; i < min(IW_MAX_AP, (int) bsslist->nr); i++) |
| 2729 | current_ev = prism54_translate_bss(ndev, current_ev, |
| 2730 | extra + IW_SCAN_MAX_DATA, |
| 2731 | &(bsslist->bsslist[i]), |
| 2732 | noise); |
| 2733 | kfree(bsslist); |
| 2734 | |
| 2735 | return rvalue; |
| 2736 | } |
| 2737 | |
| 2738 | static int |
| 2739 | prism54_hostapd(struct net_device *ndev, struct iw_point *p) |
| 2740 | { |
| 2741 | struct prism2_hostapd_param *param; |
| 2742 | int ret = 0; |
| 2743 | u32 uwrq; |
| 2744 | |
| 2745 | printk(KERN_DEBUG "prism54_hostapd - len=%d\n", p->length); |
| 2746 | if (p->length < sizeof(struct prism2_hostapd_param) || |
| 2747 | p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) |
| 2748 | return -EINVAL; |
| 2749 | |
| 2750 | param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL); |
| 2751 | if (param == NULL) |
| 2752 | return -ENOMEM; |
| 2753 | |
| 2754 | if (copy_from_user(param, p->pointer, p->length)) { |
| 2755 | kfree(param); |
| 2756 | return -EFAULT; |
| 2757 | } |
| 2758 | |
| 2759 | switch (param->cmd) { |
| 2760 | case PRISM2_SET_ENCRYPTION: |
| 2761 | printk(KERN_DEBUG "%s: Caught WPA supplicant set encryption request\n", |
| 2762 | ndev->name); |
| 2763 | ret = prism2_ioctl_set_encryption(ndev, param, p->length); |
| 2764 | break; |
| 2765 | case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT: |
| 2766 | printk(KERN_DEBUG "%s: Caught WPA supplicant set WPA IE request\n", |
| 2767 | ndev->name); |
| 2768 | ret = prism2_ioctl_set_generic_element(ndev, param, |
| 2769 | p->length); |
| 2770 | break; |
| 2771 | case PRISM2_HOSTAPD_MLME: |
| 2772 | printk(KERN_DEBUG "%s: Caught WPA supplicant MLME request\n", |
| 2773 | ndev->name); |
| 2774 | ret = prism2_ioctl_mlme(ndev, param); |
| 2775 | break; |
| 2776 | case PRISM2_HOSTAPD_SCAN_REQ: |
| 2777 | printk(KERN_DEBUG "%s: Caught WPA supplicant scan request\n", |
| 2778 | ndev->name); |
| 2779 | ret = prism2_ioctl_scan_req(ndev, param); |
| 2780 | break; |
| 2781 | case PRISM54_SET_WPA: |
| 2782 | printk(KERN_DEBUG "%s: Caught WPA supplicant wpa init request\n", |
| 2783 | ndev->name); |
| 2784 | uwrq = 1; |
| 2785 | ret = prism54_set_wpa(ndev, NULL, &uwrq, NULL); |
| 2786 | break; |
| 2787 | case PRISM54_DROP_UNENCRYPTED: |
| 2788 | printk(KERN_DEBUG "%s: Caught WPA drop unencrypted request\n", |
| 2789 | ndev->name); |
| 2790 | #if 0 |
| 2791 | uwrq = 0x01; |
| 2792 | mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &uwrq); |
| 2793 | down_write(&priv->mib_sem); |
| 2794 | mgt_commit(priv); |
| 2795 | up_write(&priv->mib_sem); |
| 2796 | #endif |
| 2797 | /* Not necessary, as set_wpa does it, should we just do it here though? */ |
| 2798 | ret = 0; |
| 2799 | break; |
| 2800 | default: |
| 2801 | printk(KERN_DEBUG "%s: Caught a WPA supplicant request that is not supported\n", |
| 2802 | ndev->name); |
| 2803 | ret = -EOPNOTSUPP; |
| 2804 | break; |
| 2805 | } |
| 2806 | |
| 2807 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) |
| 2808 | ret = -EFAULT; |
| 2809 | |
| 2810 | kfree(param); |
| 2811 | |
| 2812 | return ret; |
| 2813 | } |
| 2814 | |
| 2815 | static int |
| 2816 | prism54_set_wpa(struct net_device *ndev, struct iw_request_info *info, |
| 2817 | __u32 * uwrq, char *extra) |
| 2818 | { |
| 2819 | islpci_private *priv = netdev_priv(ndev); |
| 2820 | u32 mlme, authen, dot1x, filter, wep; |
| 2821 | |
| 2822 | if (islpci_get_state(priv) < PRV_STATE_INIT) |
| 2823 | return 0; |
| 2824 | |
| 2825 | wep = 1; /* For privacy invoked */ |
| 2826 | filter = 1; /* Filter out all unencrypted frames */ |
| 2827 | dot1x = 0x01; /* To enable eap filter */ |
| 2828 | mlme = DOT11_MLME_EXTENDED; |
| 2829 | authen = DOT11_AUTH_OS; /* Only WEP uses _SK and _BOTH */ |
| 2830 | |
| 2831 | down_write(&priv->mib_sem); |
| 2832 | priv->wpa = *uwrq; |
| 2833 | |
| 2834 | switch (priv->wpa) { |
| 2835 | default: |
| 2836 | case 0: /* Clears/disables WPA and friends */ |
| 2837 | wep = 0; |
| 2838 | filter = 0; /* Do not filter un-encrypted data */ |
| 2839 | dot1x = 0; |
| 2840 | mlme = DOT11_MLME_AUTO; |
| 2841 | printk("%s: Disabling WPA\n", ndev->name); |
| 2842 | break; |
| 2843 | case 2: |
| 2844 | case 1: /* WPA */ |
| 2845 | printk("%s: Enabling WPA\n", ndev->name); |
| 2846 | break; |
| 2847 | } |
| 2848 | up_write(&priv->mib_sem); |
| 2849 | |
| 2850 | mgt_set_request(priv, DOT11_OID_AUTHENABLE, 0, &authen); |
| 2851 | mgt_set_request(priv, DOT11_OID_PRIVACYINVOKED, 0, &wep); |
| 2852 | mgt_set_request(priv, DOT11_OID_EXUNENCRYPTED, 0, &filter); |
| 2853 | mgt_set_request(priv, DOT11_OID_DOT1XENABLE, 0, &dot1x); |
| 2854 | mgt_set_request(priv, DOT11_OID_MLMEAUTOLEVEL, 0, &mlme); |
| 2855 | |
| 2856 | return 0; |
| 2857 | } |
| 2858 | |
| 2859 | static int |
| 2860 | prism54_get_wpa(struct net_device *ndev, struct iw_request_info *info, |
| 2861 | __u32 * uwrq, char *extra) |
| 2862 | { |
| 2863 | islpci_private *priv = netdev_priv(ndev); |
| 2864 | *uwrq = priv->wpa; |
| 2865 | return 0; |
| 2866 | } |
| 2867 | |
| 2868 | static int |
| 2869 | prism54_set_prismhdr(struct net_device *ndev, struct iw_request_info *info, |
| 2870 | __u32 * uwrq, char *extra) |
| 2871 | { |
| 2872 | islpci_private *priv = netdev_priv(ndev); |
| 2873 | priv->monitor_type = |
| 2874 | (*uwrq ? ARPHRD_IEEE80211_PRISM : ARPHRD_IEEE80211); |
| 2875 | if (priv->iw_mode == IW_MODE_MONITOR) |
| 2876 | priv->ndev->type = priv->monitor_type; |
| 2877 | |
| 2878 | return 0; |
| 2879 | } |
| 2880 | |
| 2881 | static int |
| 2882 | prism54_get_prismhdr(struct net_device *ndev, struct iw_request_info *info, |
| 2883 | __u32 * uwrq, char *extra) |
| 2884 | { |
| 2885 | islpci_private *priv = netdev_priv(ndev); |
| 2886 | *uwrq = (priv->monitor_type == ARPHRD_IEEE80211_PRISM); |
| 2887 | return 0; |
| 2888 | } |
| 2889 | |
| 2890 | static int |
| 2891 | prism54_debug_oid(struct net_device *ndev, struct iw_request_info *info, |
| 2892 | __u32 * uwrq, char *extra) |
| 2893 | { |
| 2894 | islpci_private *priv = netdev_priv(ndev); |
| 2895 | |
| 2896 | priv->priv_oid = *uwrq; |
| 2897 | printk("%s: oid 0x%08X\n", ndev->name, *uwrq); |
| 2898 | |
| 2899 | return 0; |
| 2900 | } |
| 2901 | |
| 2902 | static int |
| 2903 | prism54_debug_get_oid(struct net_device *ndev, struct iw_request_info *info, |
| 2904 | struct iw_point *data, char *extra) |
| 2905 | { |
| 2906 | islpci_private *priv = netdev_priv(ndev); |
| 2907 | struct islpci_mgmtframe *response; |
| 2908 | int ret = -EIO; |
| 2909 | |
| 2910 | printk("%s: get_oid 0x%08X\n", ndev->name, priv->priv_oid); |
| 2911 | data->length = 0; |
| 2912 | |
| 2913 | if (islpci_get_state(priv) >= PRV_STATE_INIT) { |
| 2914 | ret = |
| 2915 | islpci_mgt_transaction(priv->ndev, PIMFOR_OP_GET, |
| 2916 | priv->priv_oid, extra, 256, |
| 2917 | &response); |
| 2918 | printk("%s: ret: %i\n", ndev->name, ret); |
| 2919 | if (ret || !response |
| 2920 | || response->header->operation == PIMFOR_OP_ERROR) { |
| 2921 | if (response) { |
| 2922 | islpci_mgt_release(response); |
| 2923 | } |
| 2924 | printk("%s: EIO\n", ndev->name); |
| 2925 | ret = -EIO; |
| 2926 | } |
| 2927 | if (!ret) { |
| 2928 | data->length = response->header->length; |
| 2929 | memcpy(extra, response->data, data->length); |
| 2930 | islpci_mgt_release(response); |
| 2931 | printk("%s: len: %i\n", ndev->name, data->length); |
| 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | return ret; |
| 2936 | } |
| 2937 | |
| 2938 | static int |
| 2939 | prism54_debug_set_oid(struct net_device *ndev, struct iw_request_info *info, |
| 2940 | struct iw_point *data, char *extra) |
| 2941 | { |
| 2942 | islpci_private *priv = netdev_priv(ndev); |
| 2943 | struct islpci_mgmtframe *response; |
| 2944 | int ret = 0, response_op = PIMFOR_OP_ERROR; |
| 2945 | |
| 2946 | printk("%s: set_oid 0x%08X\tlen: %d\n", ndev->name, priv->priv_oid, |
| 2947 | data->length); |
| 2948 | |
| 2949 | if (islpci_get_state(priv) >= PRV_STATE_INIT) { |
| 2950 | ret = |
| 2951 | islpci_mgt_transaction(priv->ndev, PIMFOR_OP_SET, |
| 2952 | priv->priv_oid, extra, data->length, |
| 2953 | &response); |
| 2954 | printk("%s: ret: %i\n", ndev->name, ret); |
| 2955 | if (ret || !response |
| 2956 | || response->header->operation == PIMFOR_OP_ERROR) { |
| 2957 | if (response) { |
| 2958 | islpci_mgt_release(response); |
| 2959 | } |
| 2960 | printk("%s: EIO\n", ndev->name); |
| 2961 | ret = -EIO; |
| 2962 | } |
| 2963 | if (!ret) { |
| 2964 | response_op = response->header->operation; |
| 2965 | printk("%s: response_op: %i\n", ndev->name, |
| 2966 | response_op); |
| 2967 | islpci_mgt_release(response); |
| 2968 | } |
| 2969 | } |
| 2970 | |
| 2971 | return (ret ? ret : -EINPROGRESS); |
| 2972 | } |
| 2973 | |
| 2974 | static int |
| 2975 | prism54_set_spy(struct net_device *ndev, |
| 2976 | struct iw_request_info *info, |
| 2977 | union iwreq_data *uwrq, char *extra) |
| 2978 | { |
| 2979 | islpci_private *priv = netdev_priv(ndev); |
| 2980 | u32 u, oid = OID_INL_CONFIG; |
| 2981 | |
| 2982 | down_write(&priv->mib_sem); |
| 2983 | mgt_get(priv, OID_INL_CONFIG, &u); |
| 2984 | |
| 2985 | if ((uwrq->data.length == 0) && (priv->spy_data.spy_number > 0)) |
| 2986 | /* disable spy */ |
| 2987 | u &= ~INL_CONFIG_RXANNEX; |
| 2988 | else if ((uwrq->data.length > 0) && (priv->spy_data.spy_number == 0)) |
| 2989 | /* enable spy */ |
| 2990 | u |= INL_CONFIG_RXANNEX; |
| 2991 | |
| 2992 | mgt_set(priv, OID_INL_CONFIG, &u); |
| 2993 | mgt_commit_list(priv, &oid, 1); |
| 2994 | up_write(&priv->mib_sem); |
| 2995 | |
| 2996 | return iw_handler_set_spy(ndev, info, uwrq, extra); |
| 2997 | } |
| 2998 | |
| 2999 | static const iw_handler prism54_handler[] = { |
| 3000 | (iw_handler) prism54_commit, /* SIOCSIWCOMMIT */ |
| 3001 | (iw_handler) prism54_get_name, /* SIOCGIWNAME */ |
| 3002 | (iw_handler) NULL, /* SIOCSIWNWID */ |
| 3003 | (iw_handler) NULL, /* SIOCGIWNWID */ |
| 3004 | (iw_handler) prism54_set_freq, /* SIOCSIWFREQ */ |
| 3005 | (iw_handler) prism54_get_freq, /* SIOCGIWFREQ */ |
| 3006 | (iw_handler) prism54_set_mode, /* SIOCSIWMODE */ |
| 3007 | (iw_handler) prism54_get_mode, /* SIOCGIWMODE */ |
| 3008 | (iw_handler) prism54_set_sens, /* SIOCSIWSENS */ |
| 3009 | (iw_handler) prism54_get_sens, /* SIOCGIWSENS */ |
| 3010 | (iw_handler) NULL, /* SIOCSIWRANGE */ |
| 3011 | (iw_handler) prism54_get_range, /* SIOCGIWRANGE */ |
| 3012 | (iw_handler) NULL, /* SIOCSIWPRIV */ |
| 3013 | (iw_handler) NULL, /* SIOCGIWPRIV */ |
| 3014 | (iw_handler) NULL, /* SIOCSIWSTATS */ |
| 3015 | (iw_handler) NULL, /* SIOCGIWSTATS */ |
| 3016 | prism54_set_spy, /* SIOCSIWSPY */ |
| 3017 | iw_handler_get_spy, /* SIOCGIWSPY */ |
| 3018 | iw_handler_set_thrspy, /* SIOCSIWTHRSPY */ |
| 3019 | iw_handler_get_thrspy, /* SIOCGIWTHRSPY */ |
| 3020 | (iw_handler) prism54_set_wap, /* SIOCSIWAP */ |
| 3021 | (iw_handler) prism54_get_wap, /* SIOCGIWAP */ |
| 3022 | (iw_handler) NULL, /* -- hole -- */ |
| 3023 | (iw_handler) NULL, /* SIOCGIWAPLIST depreciated */ |
| 3024 | (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */ |
| 3025 | (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */ |
| 3026 | (iw_handler) prism54_set_essid, /* SIOCSIWESSID */ |
| 3027 | (iw_handler) prism54_get_essid, /* SIOCGIWESSID */ |
| 3028 | (iw_handler) prism54_set_nick, /* SIOCSIWNICKN */ |
| 3029 | (iw_handler) prism54_get_nick, /* SIOCGIWNICKN */ |
| 3030 | (iw_handler) NULL, /* -- hole -- */ |
| 3031 | (iw_handler) NULL, /* -- hole -- */ |
| 3032 | (iw_handler) prism54_set_rate, /* SIOCSIWRATE */ |
| 3033 | (iw_handler) prism54_get_rate, /* SIOCGIWRATE */ |
| 3034 | (iw_handler) prism54_set_rts, /* SIOCSIWRTS */ |
| 3035 | (iw_handler) prism54_get_rts, /* SIOCGIWRTS */ |
| 3036 | (iw_handler) prism54_set_frag, /* SIOCSIWFRAG */ |
| 3037 | (iw_handler) prism54_get_frag, /* SIOCGIWFRAG */ |
| 3038 | (iw_handler) prism54_set_txpower, /* SIOCSIWTXPOW */ |
| 3039 | (iw_handler) prism54_get_txpower, /* SIOCGIWTXPOW */ |
| 3040 | (iw_handler) prism54_set_retry, /* SIOCSIWRETRY */ |
| 3041 | (iw_handler) prism54_get_retry, /* SIOCGIWRETRY */ |
| 3042 | (iw_handler) prism54_set_encode, /* SIOCSIWENCODE */ |
| 3043 | (iw_handler) prism54_get_encode, /* SIOCGIWENCODE */ |
| 3044 | (iw_handler) NULL, /* SIOCSIWPOWER */ |
| 3045 | (iw_handler) NULL, /* SIOCGIWPOWER */ |
Dan Williams | eab411f | 2006-07-17 21:21:47 -0400 | [diff] [blame] | 3046 | NULL, /* -- hole -- */ |
| 3047 | NULL, /* -- hole -- */ |
| 3048 | (iw_handler) prism54_set_genie, /* SIOCSIWGENIE */ |
| 3049 | (iw_handler) prism54_get_genie, /* SIOCGIWGENIE */ |
| 3050 | (iw_handler) prism54_set_auth, /* SIOCSIWAUTH */ |
| 3051 | (iw_handler) prism54_get_auth, /* SIOCGIWAUTH */ |
| 3052 | (iw_handler) prism54_set_encodeext, /* SIOCSIWENCODEEXT */ |
| 3053 | (iw_handler) prism54_get_encodeext, /* SIOCGIWENCODEEXT */ |
| 3054 | NULL, /* SIOCSIWPMKSA */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | }; |
| 3056 | |
| 3057 | /* The low order bit identify a SET (0) or a GET (1) ioctl. */ |
| 3058 | |
| 3059 | #define PRISM54_RESET SIOCIWFIRSTPRIV |
| 3060 | #define PRISM54_GET_POLICY SIOCIWFIRSTPRIV+1 |
| 3061 | #define PRISM54_SET_POLICY SIOCIWFIRSTPRIV+2 |
| 3062 | #define PRISM54_GET_MAC SIOCIWFIRSTPRIV+3 |
| 3063 | #define PRISM54_ADD_MAC SIOCIWFIRSTPRIV+4 |
| 3064 | |
| 3065 | #define PRISM54_DEL_MAC SIOCIWFIRSTPRIV+6 |
| 3066 | |
| 3067 | #define PRISM54_KICK_MAC SIOCIWFIRSTPRIV+8 |
| 3068 | |
| 3069 | #define PRISM54_KICK_ALL SIOCIWFIRSTPRIV+10 |
| 3070 | |
| 3071 | #define PRISM54_GET_WPA SIOCIWFIRSTPRIV+11 |
| 3072 | #define PRISM54_SET_WPA SIOCIWFIRSTPRIV+12 |
| 3073 | |
| 3074 | #define PRISM54_DBG_OID SIOCIWFIRSTPRIV+14 |
| 3075 | #define PRISM54_DBG_GET_OID SIOCIWFIRSTPRIV+15 |
| 3076 | #define PRISM54_DBG_SET_OID SIOCIWFIRSTPRIV+16 |
| 3077 | |
| 3078 | #define PRISM54_GET_OID SIOCIWFIRSTPRIV+17 |
| 3079 | #define PRISM54_SET_OID_U32 SIOCIWFIRSTPRIV+18 |
| 3080 | #define PRISM54_SET_OID_STR SIOCIWFIRSTPRIV+20 |
| 3081 | #define PRISM54_SET_OID_ADDR SIOCIWFIRSTPRIV+22 |
| 3082 | |
| 3083 | #define PRISM54_GET_PRISMHDR SIOCIWFIRSTPRIV+23 |
| 3084 | #define PRISM54_SET_PRISMHDR SIOCIWFIRSTPRIV+24 |
| 3085 | |
| 3086 | #define IWPRIV_SET_U32(n,x) { n, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x } |
| 3087 | #define IWPRIV_SET_SSID(n,x) { n, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x } |
| 3088 | #define IWPRIV_SET_ADDR(n,x) { n, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "s_"x } |
| 3089 | #define IWPRIV_GET(n,x) { n, 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, "g_"x } |
| 3090 | |
| 3091 | #define IWPRIV_U32(n,x) IWPRIV_SET_U32(n,x), IWPRIV_GET(n,x) |
| 3092 | #define IWPRIV_SSID(n,x) IWPRIV_SET_SSID(n,x), IWPRIV_GET(n,x) |
| 3093 | #define IWPRIV_ADDR(n,x) IWPRIV_SET_ADDR(n,x), IWPRIV_GET(n,x) |
| 3094 | |
| 3095 | /* Note : limited to 128 private ioctls (wireless tools 26) */ |
| 3096 | |
| 3097 | static const struct iw_priv_args prism54_private_args[] = { |
| 3098 | /*{ cmd, set_args, get_args, name } */ |
| 3099 | {PRISM54_RESET, 0, 0, "reset"}, |
| 3100 | {PRISM54_GET_PRISMHDR, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 3101 | "get_prismhdr"}, |
| 3102 | {PRISM54_SET_PRISMHDR, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, |
| 3103 | "set_prismhdr"}, |
| 3104 | {PRISM54_GET_POLICY, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 3105 | "getPolicy"}, |
| 3106 | {PRISM54_SET_POLICY, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, |
| 3107 | "setPolicy"}, |
| 3108 | {PRISM54_GET_MAC, 0, IW_PRIV_TYPE_ADDR | 64, "getMac"}, |
| 3109 | {PRISM54_ADD_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, |
| 3110 | "addMac"}, |
| 3111 | {PRISM54_DEL_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, |
| 3112 | "delMac"}, |
| 3113 | {PRISM54_KICK_MAC, IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, |
| 3114 | "kickMac"}, |
| 3115 | {PRISM54_KICK_ALL, 0, 0, "kickAll"}, |
| 3116 | {PRISM54_GET_WPA, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 3117 | "get_wpa"}, |
| 3118 | {PRISM54_SET_WPA, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, |
| 3119 | "set_wpa"}, |
| 3120 | {PRISM54_DBG_OID, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, |
| 3121 | "dbg_oid"}, |
| 3122 | {PRISM54_DBG_GET_OID, 0, IW_PRIV_TYPE_BYTE | 256, "dbg_get_oid"}, |
| 3123 | {PRISM54_DBG_SET_OID, IW_PRIV_TYPE_BYTE | 256, 0, "dbg_set_oid"}, |
| 3124 | /* --- sub-ioctls handlers --- */ |
| 3125 | {PRISM54_GET_OID, |
| 3126 | 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | PRIV_STR_SIZE, ""}, |
| 3127 | {PRISM54_SET_OID_U32, |
| 3128 | IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, ""}, |
| 3129 | {PRISM54_SET_OID_STR, |
| 3130 | IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 1, 0, ""}, |
| 3131 | {PRISM54_SET_OID_ADDR, |
| 3132 | IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, ""}, |
| 3133 | /* --- sub-ioctls definitions --- */ |
| 3134 | IWPRIV_ADDR(GEN_OID_MACADDRESS, "addr"), |
| 3135 | IWPRIV_GET(GEN_OID_LINKSTATE, "linkstate"), |
| 3136 | IWPRIV_U32(DOT11_OID_BSSTYPE, "bsstype"), |
| 3137 | IWPRIV_ADDR(DOT11_OID_BSSID, "bssid"), |
| 3138 | IWPRIV_U32(DOT11_OID_STATE, "state"), |
| 3139 | IWPRIV_U32(DOT11_OID_AID, "aid"), |
| 3140 | |
| 3141 | IWPRIV_SSID(DOT11_OID_SSIDOVERRIDE, "ssidoverride"), |
| 3142 | |
| 3143 | IWPRIV_U32(DOT11_OID_MEDIUMLIMIT, "medlimit"), |
| 3144 | IWPRIV_U32(DOT11_OID_BEACONPERIOD, "beacon"), |
| 3145 | IWPRIV_U32(DOT11_OID_DTIMPERIOD, "dtimperiod"), |
| 3146 | |
| 3147 | IWPRIV_U32(DOT11_OID_AUTHENABLE, "authenable"), |
| 3148 | IWPRIV_U32(DOT11_OID_PRIVACYINVOKED, "privinvok"), |
| 3149 | IWPRIV_U32(DOT11_OID_EXUNENCRYPTED, "exunencrypt"), |
| 3150 | |
| 3151 | IWPRIV_U32(DOT11_OID_REKEYTHRESHOLD, "rekeythresh"), |
| 3152 | |
| 3153 | IWPRIV_U32(DOT11_OID_MAXTXLIFETIME, "maxtxlife"), |
| 3154 | IWPRIV_U32(DOT11_OID_MAXRXLIFETIME, "maxrxlife"), |
| 3155 | IWPRIV_U32(DOT11_OID_ALOFT_FIXEDRATE, "fixedrate"), |
| 3156 | IWPRIV_U32(DOT11_OID_MAXFRAMEBURST, "frameburst"), |
| 3157 | IWPRIV_U32(DOT11_OID_PSM, "psm"), |
| 3158 | |
| 3159 | IWPRIV_U32(DOT11_OID_BRIDGELOCAL, "bridge"), |
| 3160 | IWPRIV_U32(DOT11_OID_CLIENTS, "clients"), |
| 3161 | IWPRIV_U32(DOT11_OID_CLIENTSASSOCIATED, "clientassoc"), |
| 3162 | IWPRIV_U32(DOT11_OID_DOT1XENABLE, "dot1xenable"), |
| 3163 | IWPRIV_U32(DOT11_OID_ANTENNARX, "rxant"), |
| 3164 | IWPRIV_U32(DOT11_OID_ANTENNATX, "txant"), |
| 3165 | IWPRIV_U32(DOT11_OID_ANTENNADIVERSITY, "antdivers"), |
| 3166 | IWPRIV_U32(DOT11_OID_EDTHRESHOLD, "edthresh"), |
| 3167 | IWPRIV_U32(DOT11_OID_PREAMBLESETTINGS, "preamble"), |
| 3168 | IWPRIV_GET(DOT11_OID_RATES, "rates"), |
| 3169 | IWPRIV_U32(DOT11_OID_OUTPUTPOWER, ".11outpower"), |
| 3170 | IWPRIV_GET(DOT11_OID_SUPPORTEDRATES, "supprates"), |
| 3171 | IWPRIV_GET(DOT11_OID_SUPPORTEDFREQUENCIES, "suppfreq"), |
| 3172 | |
| 3173 | IWPRIV_U32(DOT11_OID_NOISEFLOOR, "noisefloor"), |
| 3174 | IWPRIV_GET(DOT11_OID_FREQUENCYACTIVITY, "freqactivity"), |
| 3175 | IWPRIV_U32(DOT11_OID_NONERPPROTECTION, "nonerpprotec"), |
| 3176 | IWPRIV_U32(DOT11_OID_PROFILES, "profile"), |
| 3177 | IWPRIV_GET(DOT11_OID_EXTENDEDRATES, "extrates"), |
| 3178 | IWPRIV_U32(DOT11_OID_MLMEAUTOLEVEL, "mlmelevel"), |
| 3179 | |
| 3180 | IWPRIV_GET(DOT11_OID_BSSS, "bsss"), |
| 3181 | IWPRIV_GET(DOT11_OID_BSSLIST, "bsslist"), |
| 3182 | IWPRIV_U32(OID_INL_MODE, "mode"), |
| 3183 | IWPRIV_U32(OID_INL_CONFIG, "config"), |
| 3184 | IWPRIV_U32(OID_INL_DOT11D_CONFORMANCE, ".11dconform"), |
| 3185 | IWPRIV_GET(OID_INL_PHYCAPABILITIES, "phycapa"), |
| 3186 | IWPRIV_U32(OID_INL_OUTPUTPOWER, "outpower"), |
| 3187 | }; |
| 3188 | |
| 3189 | static const iw_handler prism54_private_handler[] = { |
| 3190 | (iw_handler) prism54_reset, |
| 3191 | (iw_handler) prism54_get_policy, |
| 3192 | (iw_handler) prism54_set_policy, |
| 3193 | (iw_handler) prism54_get_mac, |
| 3194 | (iw_handler) prism54_add_mac, |
| 3195 | (iw_handler) NULL, |
| 3196 | (iw_handler) prism54_del_mac, |
| 3197 | (iw_handler) NULL, |
| 3198 | (iw_handler) prism54_kick_mac, |
| 3199 | (iw_handler) NULL, |
| 3200 | (iw_handler) prism54_kick_all, |
| 3201 | (iw_handler) prism54_get_wpa, |
| 3202 | (iw_handler) prism54_set_wpa, |
| 3203 | (iw_handler) NULL, |
| 3204 | (iw_handler) prism54_debug_oid, |
| 3205 | (iw_handler) prism54_debug_get_oid, |
| 3206 | (iw_handler) prism54_debug_set_oid, |
| 3207 | (iw_handler) prism54_get_oid, |
| 3208 | (iw_handler) prism54_set_u32, |
| 3209 | (iw_handler) NULL, |
| 3210 | (iw_handler) prism54_set_raw, |
| 3211 | (iw_handler) NULL, |
| 3212 | (iw_handler) prism54_set_raw, |
| 3213 | (iw_handler) prism54_get_prismhdr, |
| 3214 | (iw_handler) prism54_set_prismhdr, |
| 3215 | }; |
| 3216 | |
| 3217 | const struct iw_handler_def prism54_handler_def = { |
| 3218 | .num_standard = sizeof (prism54_handler) / sizeof (iw_handler), |
| 3219 | .num_private = sizeof (prism54_private_handler) / sizeof (iw_handler), |
| 3220 | .num_private_args = |
| 3221 | sizeof (prism54_private_args) / sizeof (struct iw_priv_args), |
| 3222 | .standard = (iw_handler *) prism54_handler, |
| 3223 | .private = (iw_handler *) prism54_private_handler, |
| 3224 | .private_args = (struct iw_priv_args *) prism54_private_args, |
Jean Tourrilhes | 61bd496 | 2005-09-02 11:42:56 -0700 | [diff] [blame] | 3225 | .get_wireless_stats = prism54_get_wireless_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | }; |
| 3227 | |
| 3228 | /* For wpa_supplicant */ |
| 3229 | |
| 3230 | int |
| 3231 | prism54_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd) |
| 3232 | { |
| 3233 | struct iwreq *wrq = (struct iwreq *) rq; |
| 3234 | int ret = -1; |
| 3235 | switch (cmd) { |
| 3236 | case PRISM54_HOSTAPD: |
| 3237 | if (!capable(CAP_NET_ADMIN)) |
| 3238 | return -EPERM; |
| 3239 | ret = prism54_hostapd(ndev, &wrq->u.data); |
| 3240 | return ret; |
| 3241 | } |
| 3242 | return -EOPNOTSUPP; |
| 3243 | } |