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