David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1 | /* Wireless extensions support. |
| 2 | * |
| 3 | * See copyright notice in main.c |
| 4 | */ |
| 5 | #include <linux/kernel.h> |
| 6 | #include <linux/if_arp.h> |
| 7 | #include <linux/wireless.h> |
| 8 | #include <linux/ieee80211.h> |
| 9 | #include <net/iw_handler.h> |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 10 | #include <net/cfg80211.h> |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 11 | |
| 12 | #include "hermes.h" |
| 13 | #include "hermes_rid.h" |
| 14 | #include "orinoco.h" |
| 15 | |
| 16 | #include "hw.h" |
| 17 | #include "mic.h" |
| 18 | #include "scan.h" |
| 19 | #include "main.h" |
| 20 | |
| 21 | #include "wext.h" |
| 22 | |
| 23 | #define MAX_RID_LEN 1024 |
| 24 | |
| 25 | static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev) |
| 26 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 27 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 28 | hermes_t *hw = &priv->hw; |
| 29 | struct iw_statistics *wstats = &priv->wstats; |
| 30 | int err; |
| 31 | unsigned long flags; |
| 32 | |
| 33 | if (!netif_device_present(dev)) { |
| 34 | printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n", |
| 35 | dev->name); |
| 36 | return NULL; /* FIXME: Can we do better than this? */ |
| 37 | } |
| 38 | |
| 39 | /* If busy, return the old stats. Returning NULL may cause |
| 40 | * the interface to disappear from /proc/net/wireless */ |
| 41 | if (orinoco_lock(priv, &flags) != 0) |
| 42 | return wstats; |
| 43 | |
| 44 | /* We can't really wait for the tallies inquiry command to |
| 45 | * complete, so we just use the previous results and trigger |
| 46 | * a new tallies inquiry command for next time - Jean II */ |
| 47 | /* FIXME: Really we should wait for the inquiry to come back - |
| 48 | * as it is the stats we give don't make a whole lot of sense. |
| 49 | * Unfortunately, it's not clear how to do that within the |
| 50 | * wireless extensions framework: I think we're in user |
| 51 | * context, but a lock seems to be held by the time we get in |
| 52 | * here so we're not safe to sleep here. */ |
| 53 | hermes_inquire(hw, HERMES_INQ_TALLIES); |
| 54 | |
David Kilroy | 5217c57 | 2009-06-18 23:21:32 +0100 | [diff] [blame] | 55 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) { |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 56 | memset(&wstats->qual, 0, sizeof(wstats->qual)); |
| 57 | /* If a spy address is defined, we report stats of the |
| 58 | * first spy address - Jean II */ |
| 59 | if (SPY_NUMBER(priv)) { |
| 60 | wstats->qual.qual = priv->spy_data.spy_stat[0].qual; |
| 61 | wstats->qual.level = priv->spy_data.spy_stat[0].level; |
| 62 | wstats->qual.noise = priv->spy_data.spy_stat[0].noise; |
| 63 | wstats->qual.updated = |
| 64 | priv->spy_data.spy_stat[0].updated; |
| 65 | } |
| 66 | } else { |
| 67 | struct { |
| 68 | __le16 qual, signal, noise, unused; |
| 69 | } __attribute__ ((packed)) cq; |
| 70 | |
| 71 | err = HERMES_READ_RECORD(hw, USER_BAP, |
| 72 | HERMES_RID_COMMSQUALITY, &cq); |
| 73 | |
| 74 | if (!err) { |
| 75 | wstats->qual.qual = (int)le16_to_cpu(cq.qual); |
| 76 | wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95; |
| 77 | wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95; |
| 78 | wstats->qual.updated = |
| 79 | IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | orinoco_unlock(priv, &flags); |
| 84 | return wstats; |
| 85 | } |
| 86 | |
| 87 | /********************************************************************/ |
| 88 | /* Wireless extensions */ |
| 89 | /********************************************************************/ |
| 90 | |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 91 | static int orinoco_ioctl_setwap(struct net_device *dev, |
| 92 | struct iw_request_info *info, |
| 93 | struct sockaddr *ap_addr, |
| 94 | char *extra) |
| 95 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 96 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 97 | int err = -EINPROGRESS; /* Call commit handler */ |
| 98 | unsigned long flags; |
| 99 | static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
| 100 | static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 101 | |
| 102 | if (orinoco_lock(priv, &flags) != 0) |
| 103 | return -EBUSY; |
| 104 | |
| 105 | /* Enable automatic roaming - no sanity checks are needed */ |
| 106 | if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 || |
| 107 | memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) { |
| 108 | priv->bssid_fixed = 0; |
| 109 | memset(priv->desired_bssid, 0, ETH_ALEN); |
| 110 | |
| 111 | /* "off" means keep existing connection */ |
| 112 | if (ap_addr->sa_data[0] == 0) { |
| 113 | __orinoco_hw_set_wap(priv); |
| 114 | err = 0; |
| 115 | } |
| 116 | goto out; |
| 117 | } |
| 118 | |
| 119 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) { |
| 120 | printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't " |
| 121 | "support manual roaming\n", |
| 122 | dev->name); |
| 123 | err = -EOPNOTSUPP; |
| 124 | goto out; |
| 125 | } |
| 126 | |
David Kilroy | 5217c57 | 2009-06-18 23:21:32 +0100 | [diff] [blame] | 127 | if (priv->iw_mode != NL80211_IFTYPE_STATION) { |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 128 | printk(KERN_WARNING "%s: Manual roaming supported only in " |
| 129 | "managed mode\n", dev->name); |
| 130 | err = -EOPNOTSUPP; |
| 131 | goto out; |
| 132 | } |
| 133 | |
| 134 | /* Intersil firmware hangs without Desired ESSID */ |
| 135 | if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL && |
| 136 | strlen(priv->desired_essid) == 0) { |
| 137 | printk(KERN_WARNING "%s: Desired ESSID must be set for " |
| 138 | "manual roaming\n", dev->name); |
| 139 | err = -EOPNOTSUPP; |
| 140 | goto out; |
| 141 | } |
| 142 | |
| 143 | /* Finally, enable manual roaming */ |
| 144 | priv->bssid_fixed = 1; |
| 145 | memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN); |
| 146 | |
| 147 | out: |
| 148 | orinoco_unlock(priv, &flags); |
| 149 | return err; |
| 150 | } |
| 151 | |
| 152 | static int orinoco_ioctl_getwap(struct net_device *dev, |
| 153 | struct iw_request_info *info, |
| 154 | struct sockaddr *ap_addr, |
| 155 | char *extra) |
| 156 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 157 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 158 | |
| 159 | hermes_t *hw = &priv->hw; |
| 160 | int err = 0; |
| 161 | unsigned long flags; |
| 162 | |
| 163 | if (orinoco_lock(priv, &flags) != 0) |
| 164 | return -EBUSY; |
| 165 | |
| 166 | ap_addr->sa_family = ARPHRD_ETHER; |
| 167 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID, |
| 168 | ETH_ALEN, NULL, ap_addr->sa_data); |
| 169 | |
| 170 | orinoco_unlock(priv, &flags); |
| 171 | |
| 172 | return err; |
| 173 | } |
| 174 | |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 175 | static int orinoco_ioctl_getiwrange(struct net_device *dev, |
| 176 | struct iw_request_info *info, |
| 177 | struct iw_point *rrq, |
| 178 | char *extra) |
| 179 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 180 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 181 | int err = 0; |
| 182 | struct iw_range *range = (struct iw_range *) extra; |
| 183 | int numrates; |
| 184 | int i, k; |
| 185 | |
| 186 | rrq->length = sizeof(struct iw_range); |
| 187 | memset(range, 0, sizeof(struct iw_range)); |
| 188 | |
| 189 | range->we_version_compiled = WIRELESS_EXT; |
| 190 | range->we_version_source = 22; |
| 191 | |
| 192 | /* Set available channels/frequencies */ |
| 193 | range->num_channels = NUM_CHANNELS; |
| 194 | k = 0; |
| 195 | for (i = 0; i < NUM_CHANNELS; i++) { |
| 196 | if (priv->channel_mask & (1 << i)) { |
| 197 | range->freq[k].i = i + 1; |
| 198 | range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) * |
| 199 | 100000); |
| 200 | range->freq[k].e = 1; |
| 201 | k++; |
| 202 | } |
| 203 | |
| 204 | if (k >= IW_MAX_FREQUENCIES) |
| 205 | break; |
| 206 | } |
| 207 | range->num_frequency = k; |
| 208 | range->sensitivity = 3; |
| 209 | |
| 210 | if (priv->has_wep) { |
| 211 | range->max_encoding_tokens = ORINOCO_MAX_KEYS; |
| 212 | range->encoding_size[0] = SMALL_KEY_SIZE; |
| 213 | range->num_encoding_sizes = 1; |
| 214 | |
| 215 | if (priv->has_big_wep) { |
| 216 | range->encoding_size[1] = LARGE_KEY_SIZE; |
| 217 | range->num_encoding_sizes = 2; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | if (priv->has_wpa) |
| 222 | range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP; |
| 223 | |
David Kilroy | 5217c57 | 2009-06-18 23:21:32 +0100 | [diff] [blame] | 224 | if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) && (!SPY_NUMBER(priv))) { |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 225 | /* Quality stats meaningless in ad-hoc mode */ |
| 226 | } else { |
| 227 | range->max_qual.qual = 0x8b - 0x2f; |
| 228 | range->max_qual.level = 0x2f - 0x95 - 1; |
| 229 | range->max_qual.noise = 0x2f - 0x95 - 1; |
| 230 | /* Need to get better values */ |
| 231 | range->avg_qual.qual = 0x24; |
| 232 | range->avg_qual.level = 0xC2; |
| 233 | range->avg_qual.noise = 0x9E; |
| 234 | } |
| 235 | |
| 236 | err = orinoco_hw_get_bitratelist(priv, &numrates, |
| 237 | range->bitrate, IW_MAX_BITRATES); |
| 238 | if (err) |
| 239 | return err; |
| 240 | range->num_bitrates = numrates; |
| 241 | |
| 242 | /* Set an indication of the max TCP throughput in bit/s that we can |
| 243 | * expect using this interface. May be use for QoS stuff... |
| 244 | * Jean II */ |
| 245 | if (numrates > 2) |
| 246 | range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */ |
| 247 | else |
| 248 | range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */ |
| 249 | |
| 250 | range->min_rts = 0; |
| 251 | range->max_rts = 2347; |
| 252 | range->min_frag = 256; |
| 253 | range->max_frag = 2346; |
| 254 | |
| 255 | range->min_pmp = 0; |
| 256 | range->max_pmp = 65535000; |
| 257 | range->min_pmt = 0; |
| 258 | range->max_pmt = 65535 * 1000; /* ??? */ |
| 259 | range->pmp_flags = IW_POWER_PERIOD; |
| 260 | range->pmt_flags = IW_POWER_TIMEOUT; |
| 261 | range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT | |
| 262 | IW_POWER_UNICAST_R); |
| 263 | |
| 264 | range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME; |
| 265 | range->retry_flags = IW_RETRY_LIMIT; |
| 266 | range->r_time_flags = IW_RETRY_LIFETIME; |
| 267 | range->min_retry = 0; |
| 268 | range->max_retry = 65535; /* ??? */ |
| 269 | range->min_r_time = 0; |
| 270 | range->max_r_time = 65535 * 1000; /* ??? */ |
| 271 | |
| 272 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) |
| 273 | range->scan_capa = IW_SCAN_CAPA_ESSID; |
| 274 | else |
| 275 | range->scan_capa = IW_SCAN_CAPA_NONE; |
| 276 | |
| 277 | /* Event capability (kernel) */ |
| 278 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); |
| 279 | /* Event capability (driver) */ |
| 280 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY); |
| 281 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); |
| 282 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); |
| 283 | IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP); |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | static int orinoco_ioctl_setiwencode(struct net_device *dev, |
| 289 | struct iw_request_info *info, |
| 290 | struct iw_point *erq, |
| 291 | char *keybuf) |
| 292 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 293 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 294 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; |
| 295 | int setindex = priv->tx_key; |
| 296 | int encode_alg = priv->encode_alg; |
| 297 | int restricted = priv->wep_restrict; |
| 298 | u16 xlen = 0; |
| 299 | int err = -EINPROGRESS; /* Call commit handler */ |
| 300 | unsigned long flags; |
| 301 | |
| 302 | if (!priv->has_wep) |
| 303 | return -EOPNOTSUPP; |
| 304 | |
| 305 | if (erq->pointer) { |
| 306 | /* We actually have a key to set - check its length */ |
| 307 | if (erq->length > LARGE_KEY_SIZE) |
| 308 | return -E2BIG; |
| 309 | |
| 310 | if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep) |
| 311 | return -E2BIG; |
| 312 | } |
| 313 | |
| 314 | if (orinoco_lock(priv, &flags) != 0) |
| 315 | return -EBUSY; |
| 316 | |
| 317 | /* Clear any TKIP key we have */ |
| 318 | if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP)) |
| 319 | (void) orinoco_clear_tkip_key(priv, setindex); |
| 320 | |
| 321 | if (erq->length > 0) { |
| 322 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) |
| 323 | index = priv->tx_key; |
| 324 | |
| 325 | /* Adjust key length to a supported value */ |
| 326 | if (erq->length > SMALL_KEY_SIZE) |
| 327 | xlen = LARGE_KEY_SIZE; |
| 328 | else if (erq->length > 0) |
| 329 | xlen = SMALL_KEY_SIZE; |
| 330 | else |
| 331 | xlen = 0; |
| 332 | |
| 333 | /* Switch on WEP if off */ |
| 334 | if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) { |
| 335 | setindex = index; |
| 336 | encode_alg = IW_ENCODE_ALG_WEP; |
| 337 | } |
| 338 | } else { |
| 339 | /* Important note : if the user do "iwconfig eth0 enc off", |
| 340 | * we will arrive there with an index of -1. This is valid |
| 341 | * but need to be taken care off... Jean II */ |
| 342 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) { |
| 343 | if ((index != -1) || (erq->flags == 0)) { |
| 344 | err = -EINVAL; |
| 345 | goto out; |
| 346 | } |
| 347 | } else { |
| 348 | /* Set the index : Check that the key is valid */ |
| 349 | if (priv->keys[index].len == 0) { |
| 350 | err = -EINVAL; |
| 351 | goto out; |
| 352 | } |
| 353 | setindex = index; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | if (erq->flags & IW_ENCODE_DISABLED) |
| 358 | encode_alg = IW_ENCODE_ALG_NONE; |
| 359 | if (erq->flags & IW_ENCODE_OPEN) |
| 360 | restricted = 0; |
| 361 | if (erq->flags & IW_ENCODE_RESTRICTED) |
| 362 | restricted = 1; |
| 363 | |
| 364 | if (erq->pointer && erq->length > 0) { |
| 365 | priv->keys[index].len = cpu_to_le16(xlen); |
| 366 | memset(priv->keys[index].data, 0, |
| 367 | sizeof(priv->keys[index].data)); |
| 368 | memcpy(priv->keys[index].data, keybuf, erq->length); |
| 369 | } |
| 370 | priv->tx_key = setindex; |
| 371 | |
| 372 | /* Try fast key change if connected and only keys are changed */ |
| 373 | if ((priv->encode_alg == encode_alg) && |
| 374 | (priv->wep_restrict == restricted) && |
| 375 | netif_carrier_ok(dev)) { |
| 376 | err = __orinoco_hw_setup_wepkeys(priv); |
| 377 | /* No need to commit if successful */ |
| 378 | goto out; |
| 379 | } |
| 380 | |
| 381 | priv->encode_alg = encode_alg; |
| 382 | priv->wep_restrict = restricted; |
| 383 | |
| 384 | out: |
| 385 | orinoco_unlock(priv, &flags); |
| 386 | |
| 387 | return err; |
| 388 | } |
| 389 | |
| 390 | static int orinoco_ioctl_getiwencode(struct net_device *dev, |
| 391 | struct iw_request_info *info, |
| 392 | struct iw_point *erq, |
| 393 | char *keybuf) |
| 394 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 395 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 396 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; |
| 397 | u16 xlen = 0; |
| 398 | unsigned long flags; |
| 399 | |
| 400 | if (!priv->has_wep) |
| 401 | return -EOPNOTSUPP; |
| 402 | |
| 403 | if (orinoco_lock(priv, &flags) != 0) |
| 404 | return -EBUSY; |
| 405 | |
| 406 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) |
| 407 | index = priv->tx_key; |
| 408 | |
| 409 | erq->flags = 0; |
| 410 | if (!priv->encode_alg) |
| 411 | erq->flags |= IW_ENCODE_DISABLED; |
| 412 | erq->flags |= index + 1; |
| 413 | |
| 414 | if (priv->wep_restrict) |
| 415 | erq->flags |= IW_ENCODE_RESTRICTED; |
| 416 | else |
| 417 | erq->flags |= IW_ENCODE_OPEN; |
| 418 | |
| 419 | xlen = le16_to_cpu(priv->keys[index].len); |
| 420 | |
| 421 | erq->length = xlen; |
| 422 | |
| 423 | memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE); |
| 424 | |
| 425 | orinoco_unlock(priv, &flags); |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static int orinoco_ioctl_setessid(struct net_device *dev, |
| 430 | struct iw_request_info *info, |
| 431 | struct iw_point *erq, |
| 432 | char *essidbuf) |
| 433 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 434 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 435 | unsigned long flags; |
| 436 | |
| 437 | /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it |
| 438 | * anyway... - Jean II */ |
| 439 | |
| 440 | /* Hum... Should not use Wireless Extension constant (may change), |
| 441 | * should use our own... - Jean II */ |
| 442 | if (erq->length > IW_ESSID_MAX_SIZE) |
| 443 | return -E2BIG; |
| 444 | |
| 445 | if (orinoco_lock(priv, &flags) != 0) |
| 446 | return -EBUSY; |
| 447 | |
| 448 | /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */ |
| 449 | memset(priv->desired_essid, 0, sizeof(priv->desired_essid)); |
| 450 | |
| 451 | /* If not ANY, get the new ESSID */ |
| 452 | if (erq->flags) |
| 453 | memcpy(priv->desired_essid, essidbuf, erq->length); |
| 454 | |
| 455 | orinoco_unlock(priv, &flags); |
| 456 | |
| 457 | return -EINPROGRESS; /* Call commit handler */ |
| 458 | } |
| 459 | |
| 460 | static int orinoco_ioctl_getessid(struct net_device *dev, |
| 461 | struct iw_request_info *info, |
| 462 | struct iw_point *erq, |
| 463 | char *essidbuf) |
| 464 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 465 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 466 | int active; |
| 467 | int err = 0; |
| 468 | unsigned long flags; |
| 469 | |
| 470 | if (netif_running(dev)) { |
| 471 | err = orinoco_hw_get_essid(priv, &active, essidbuf); |
| 472 | if (err < 0) |
| 473 | return err; |
| 474 | erq->length = err; |
| 475 | } else { |
| 476 | if (orinoco_lock(priv, &flags) != 0) |
| 477 | return -EBUSY; |
| 478 | memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE); |
| 479 | erq->length = strlen(priv->desired_essid); |
| 480 | orinoco_unlock(priv, &flags); |
| 481 | } |
| 482 | |
| 483 | erq->flags = 1; |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static int orinoco_ioctl_setnick(struct net_device *dev, |
| 489 | struct iw_request_info *info, |
| 490 | struct iw_point *nrq, |
| 491 | char *nickbuf) |
| 492 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 493 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 494 | unsigned long flags; |
| 495 | |
| 496 | if (nrq->length > IW_ESSID_MAX_SIZE) |
| 497 | return -E2BIG; |
| 498 | |
| 499 | if (orinoco_lock(priv, &flags) != 0) |
| 500 | return -EBUSY; |
| 501 | |
| 502 | memset(priv->nick, 0, sizeof(priv->nick)); |
| 503 | memcpy(priv->nick, nickbuf, nrq->length); |
| 504 | |
| 505 | orinoco_unlock(priv, &flags); |
| 506 | |
| 507 | return -EINPROGRESS; /* Call commit handler */ |
| 508 | } |
| 509 | |
| 510 | static int orinoco_ioctl_getnick(struct net_device *dev, |
| 511 | struct iw_request_info *info, |
| 512 | struct iw_point *nrq, |
| 513 | char *nickbuf) |
| 514 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 515 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 516 | unsigned long flags; |
| 517 | |
| 518 | if (orinoco_lock(priv, &flags) != 0) |
| 519 | return -EBUSY; |
| 520 | |
| 521 | memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE); |
| 522 | orinoco_unlock(priv, &flags); |
| 523 | |
| 524 | nrq->length = strlen(priv->nick); |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | static int orinoco_ioctl_setfreq(struct net_device *dev, |
| 530 | struct iw_request_info *info, |
| 531 | struct iw_freq *frq, |
| 532 | char *extra) |
| 533 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 534 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 535 | int chan = -1; |
| 536 | unsigned long flags; |
| 537 | int err = -EINPROGRESS; /* Call commit handler */ |
| 538 | |
| 539 | /* In infrastructure mode the AP sets the channel */ |
David Kilroy | 5217c57 | 2009-06-18 23:21:32 +0100 | [diff] [blame] | 540 | if (priv->iw_mode == NL80211_IFTYPE_STATION) |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 541 | return -EBUSY; |
| 542 | |
| 543 | if ((frq->e == 0) && (frq->m <= 1000)) { |
| 544 | /* Setting by channel number */ |
| 545 | chan = frq->m; |
| 546 | } else { |
| 547 | /* Setting by frequency */ |
| 548 | int denom = 1; |
| 549 | int i; |
| 550 | |
| 551 | /* Calculate denominator to rescale to MHz */ |
| 552 | for (i = 0; i < (6 - frq->e); i++) |
| 553 | denom *= 10; |
| 554 | |
| 555 | chan = ieee80211_freq_to_dsss_chan(frq->m / denom); |
| 556 | } |
| 557 | |
| 558 | if ((chan < 1) || (chan > NUM_CHANNELS) || |
| 559 | !(priv->channel_mask & (1 << (chan-1)))) |
| 560 | return -EINVAL; |
| 561 | |
| 562 | if (orinoco_lock(priv, &flags) != 0) |
| 563 | return -EBUSY; |
| 564 | |
| 565 | priv->channel = chan; |
David Kilroy | 5217c57 | 2009-06-18 23:21:32 +0100 | [diff] [blame] | 566 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) { |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 567 | /* Fast channel change - no commit if successful */ |
| 568 | hermes_t *hw = &priv->hw; |
| 569 | err = hermes_docmd_wait(hw, HERMES_CMD_TEST | |
| 570 | HERMES_TEST_SET_CHANNEL, |
| 571 | chan, NULL); |
| 572 | } |
| 573 | orinoco_unlock(priv, &flags); |
| 574 | |
| 575 | return err; |
| 576 | } |
| 577 | |
| 578 | static int orinoco_ioctl_getfreq(struct net_device *dev, |
| 579 | struct iw_request_info *info, |
| 580 | struct iw_freq *frq, |
| 581 | char *extra) |
| 582 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 583 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 584 | int tmp; |
| 585 | |
| 586 | /* Locking done in there */ |
| 587 | tmp = orinoco_hw_get_freq(priv); |
| 588 | if (tmp < 0) |
| 589 | return tmp; |
| 590 | |
| 591 | frq->m = tmp * 100000; |
| 592 | frq->e = 1; |
| 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
| 597 | static int orinoco_ioctl_getsens(struct net_device *dev, |
| 598 | struct iw_request_info *info, |
| 599 | struct iw_param *srq, |
| 600 | char *extra) |
| 601 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 602 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 603 | hermes_t *hw = &priv->hw; |
| 604 | u16 val; |
| 605 | int err; |
| 606 | unsigned long flags; |
| 607 | |
| 608 | if (!priv->has_sensitivity) |
| 609 | return -EOPNOTSUPP; |
| 610 | |
| 611 | if (orinoco_lock(priv, &flags) != 0) |
| 612 | return -EBUSY; |
| 613 | err = hermes_read_wordrec(hw, USER_BAP, |
| 614 | HERMES_RID_CNFSYSTEMSCALE, &val); |
| 615 | orinoco_unlock(priv, &flags); |
| 616 | |
| 617 | if (err) |
| 618 | return err; |
| 619 | |
| 620 | srq->value = val; |
| 621 | srq->fixed = 0; /* auto */ |
| 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | static int orinoco_ioctl_setsens(struct net_device *dev, |
| 627 | struct iw_request_info *info, |
| 628 | struct iw_param *srq, |
| 629 | char *extra) |
| 630 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 631 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 632 | int val = srq->value; |
| 633 | unsigned long flags; |
| 634 | |
| 635 | if (!priv->has_sensitivity) |
| 636 | return -EOPNOTSUPP; |
| 637 | |
| 638 | if ((val < 1) || (val > 3)) |
| 639 | return -EINVAL; |
| 640 | |
| 641 | if (orinoco_lock(priv, &flags) != 0) |
| 642 | return -EBUSY; |
| 643 | priv->ap_density = val; |
| 644 | orinoco_unlock(priv, &flags); |
| 645 | |
| 646 | return -EINPROGRESS; /* Call commit handler */ |
| 647 | } |
| 648 | |
| 649 | static int orinoco_ioctl_setrts(struct net_device *dev, |
| 650 | struct iw_request_info *info, |
| 651 | struct iw_param *rrq, |
| 652 | char *extra) |
| 653 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 654 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 655 | int val = rrq->value; |
| 656 | unsigned long flags; |
| 657 | |
| 658 | if (rrq->disabled) |
| 659 | val = 2347; |
| 660 | |
| 661 | if ((val < 0) || (val > 2347)) |
| 662 | return -EINVAL; |
| 663 | |
| 664 | if (orinoco_lock(priv, &flags) != 0) |
| 665 | return -EBUSY; |
| 666 | |
| 667 | priv->rts_thresh = val; |
| 668 | orinoco_unlock(priv, &flags); |
| 669 | |
| 670 | return -EINPROGRESS; /* Call commit handler */ |
| 671 | } |
| 672 | |
| 673 | static int orinoco_ioctl_getrts(struct net_device *dev, |
| 674 | struct iw_request_info *info, |
| 675 | struct iw_param *rrq, |
| 676 | char *extra) |
| 677 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 678 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 679 | |
| 680 | rrq->value = priv->rts_thresh; |
| 681 | rrq->disabled = (rrq->value == 2347); |
| 682 | rrq->fixed = 1; |
| 683 | |
| 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | static int orinoco_ioctl_setfrag(struct net_device *dev, |
| 688 | struct iw_request_info *info, |
| 689 | struct iw_param *frq, |
| 690 | char *extra) |
| 691 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 692 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 693 | int err = -EINPROGRESS; /* Call commit handler */ |
| 694 | unsigned long flags; |
| 695 | |
| 696 | if (orinoco_lock(priv, &flags) != 0) |
| 697 | return -EBUSY; |
| 698 | |
| 699 | if (priv->has_mwo) { |
| 700 | if (frq->disabled) |
| 701 | priv->mwo_robust = 0; |
| 702 | else { |
| 703 | if (frq->fixed) |
| 704 | printk(KERN_WARNING "%s: Fixed fragmentation " |
| 705 | "is not supported on this firmware. " |
| 706 | "Using MWO robust instead.\n", |
| 707 | dev->name); |
| 708 | priv->mwo_robust = 1; |
| 709 | } |
| 710 | } else { |
| 711 | if (frq->disabled) |
| 712 | priv->frag_thresh = 2346; |
| 713 | else { |
| 714 | if ((frq->value < 256) || (frq->value > 2346)) |
| 715 | err = -EINVAL; |
| 716 | else |
| 717 | /* must be even */ |
| 718 | priv->frag_thresh = frq->value & ~0x1; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | orinoco_unlock(priv, &flags); |
| 723 | |
| 724 | return err; |
| 725 | } |
| 726 | |
| 727 | static int orinoco_ioctl_getfrag(struct net_device *dev, |
| 728 | struct iw_request_info *info, |
| 729 | struct iw_param *frq, |
| 730 | char *extra) |
| 731 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 732 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 733 | hermes_t *hw = &priv->hw; |
| 734 | int err; |
| 735 | u16 val; |
| 736 | unsigned long flags; |
| 737 | |
| 738 | if (orinoco_lock(priv, &flags) != 0) |
| 739 | return -EBUSY; |
| 740 | |
| 741 | if (priv->has_mwo) { |
| 742 | err = hermes_read_wordrec(hw, USER_BAP, |
| 743 | HERMES_RID_CNFMWOROBUST_AGERE, |
| 744 | &val); |
| 745 | if (err) |
| 746 | val = 0; |
| 747 | |
| 748 | frq->value = val ? 2347 : 0; |
| 749 | frq->disabled = !val; |
| 750 | frq->fixed = 0; |
| 751 | } else { |
| 752 | err = hermes_read_wordrec(hw, USER_BAP, |
| 753 | HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, |
| 754 | &val); |
| 755 | if (err) |
| 756 | val = 0; |
| 757 | |
| 758 | frq->value = val; |
| 759 | frq->disabled = (val >= 2346); |
| 760 | frq->fixed = 1; |
| 761 | } |
| 762 | |
| 763 | orinoco_unlock(priv, &flags); |
| 764 | |
| 765 | return err; |
| 766 | } |
| 767 | |
| 768 | static int orinoco_ioctl_setrate(struct net_device *dev, |
| 769 | struct iw_request_info *info, |
| 770 | struct iw_param *rrq, |
| 771 | char *extra) |
| 772 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 773 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 774 | int ratemode; |
| 775 | int bitrate; /* 100s of kilobits */ |
| 776 | unsigned long flags; |
| 777 | |
| 778 | /* As the user space doesn't know our highest rate, it uses -1 |
| 779 | * to ask us to set the highest rate. Test it using "iwconfig |
| 780 | * ethX rate auto" - Jean II */ |
| 781 | if (rrq->value == -1) |
| 782 | bitrate = 110; |
| 783 | else { |
| 784 | if (rrq->value % 100000) |
| 785 | return -EINVAL; |
| 786 | bitrate = rrq->value / 100000; |
| 787 | } |
| 788 | |
| 789 | ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed); |
| 790 | |
| 791 | if (ratemode == -1) |
| 792 | return -EINVAL; |
| 793 | |
| 794 | if (orinoco_lock(priv, &flags) != 0) |
| 795 | return -EBUSY; |
| 796 | priv->bitratemode = ratemode; |
| 797 | orinoco_unlock(priv, &flags); |
| 798 | |
| 799 | return -EINPROGRESS; |
| 800 | } |
| 801 | |
| 802 | static int orinoco_ioctl_getrate(struct net_device *dev, |
| 803 | struct iw_request_info *info, |
| 804 | struct iw_param *rrq, |
| 805 | char *extra) |
| 806 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 807 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 808 | int err = 0; |
| 809 | int bitrate, automatic; |
| 810 | unsigned long flags; |
| 811 | |
| 812 | if (orinoco_lock(priv, &flags) != 0) |
| 813 | return -EBUSY; |
| 814 | |
| 815 | orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic); |
| 816 | |
| 817 | /* If the interface is running we try to find more about the |
| 818 | current mode */ |
| 819 | if (netif_running(dev)) |
| 820 | err = orinoco_hw_get_act_bitrate(priv, &bitrate); |
| 821 | |
| 822 | orinoco_unlock(priv, &flags); |
| 823 | |
| 824 | rrq->value = bitrate; |
| 825 | rrq->fixed = !automatic; |
| 826 | rrq->disabled = 0; |
| 827 | |
| 828 | return err; |
| 829 | } |
| 830 | |
| 831 | static int orinoco_ioctl_setpower(struct net_device *dev, |
| 832 | struct iw_request_info *info, |
| 833 | struct iw_param *prq, |
| 834 | char *extra) |
| 835 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 836 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 837 | int err = -EINPROGRESS; /* Call commit handler */ |
| 838 | unsigned long flags; |
| 839 | |
| 840 | if (orinoco_lock(priv, &flags) != 0) |
| 841 | return -EBUSY; |
| 842 | |
| 843 | if (prq->disabled) { |
| 844 | priv->pm_on = 0; |
| 845 | } else { |
| 846 | switch (prq->flags & IW_POWER_MODE) { |
| 847 | case IW_POWER_UNICAST_R: |
| 848 | priv->pm_mcast = 0; |
| 849 | priv->pm_on = 1; |
| 850 | break; |
| 851 | case IW_POWER_ALL_R: |
| 852 | priv->pm_mcast = 1; |
| 853 | priv->pm_on = 1; |
| 854 | break; |
| 855 | case IW_POWER_ON: |
| 856 | /* No flags : but we may have a value - Jean II */ |
| 857 | break; |
| 858 | default: |
| 859 | err = -EINVAL; |
| 860 | goto out; |
| 861 | } |
| 862 | |
| 863 | if (prq->flags & IW_POWER_TIMEOUT) { |
| 864 | priv->pm_on = 1; |
| 865 | priv->pm_timeout = prq->value / 1000; |
| 866 | } |
| 867 | if (prq->flags & IW_POWER_PERIOD) { |
| 868 | priv->pm_on = 1; |
| 869 | priv->pm_period = prq->value / 1000; |
| 870 | } |
| 871 | /* It's valid to not have a value if we are just toggling |
| 872 | * the flags... Jean II */ |
| 873 | if (!priv->pm_on) { |
| 874 | err = -EINVAL; |
| 875 | goto out; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | out: |
| 880 | orinoco_unlock(priv, &flags); |
| 881 | |
| 882 | return err; |
| 883 | } |
| 884 | |
| 885 | static int orinoco_ioctl_getpower(struct net_device *dev, |
| 886 | struct iw_request_info *info, |
| 887 | struct iw_param *prq, |
| 888 | char *extra) |
| 889 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 890 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 891 | hermes_t *hw = &priv->hw; |
| 892 | int err = 0; |
| 893 | u16 enable, period, timeout, mcast; |
| 894 | unsigned long flags; |
| 895 | |
| 896 | if (orinoco_lock(priv, &flags) != 0) |
| 897 | return -EBUSY; |
| 898 | |
| 899 | err = hermes_read_wordrec(hw, USER_BAP, |
| 900 | HERMES_RID_CNFPMENABLED, &enable); |
| 901 | if (err) |
| 902 | goto out; |
| 903 | |
| 904 | err = hermes_read_wordrec(hw, USER_BAP, |
| 905 | HERMES_RID_CNFMAXSLEEPDURATION, &period); |
| 906 | if (err) |
| 907 | goto out; |
| 908 | |
| 909 | err = hermes_read_wordrec(hw, USER_BAP, |
| 910 | HERMES_RID_CNFPMHOLDOVERDURATION, &timeout); |
| 911 | if (err) |
| 912 | goto out; |
| 913 | |
| 914 | err = hermes_read_wordrec(hw, USER_BAP, |
| 915 | HERMES_RID_CNFMULTICASTRECEIVE, &mcast); |
| 916 | if (err) |
| 917 | goto out; |
| 918 | |
| 919 | prq->disabled = !enable; |
| 920 | /* Note : by default, display the period */ |
| 921 | if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { |
| 922 | prq->flags = IW_POWER_TIMEOUT; |
| 923 | prq->value = timeout * 1000; |
| 924 | } else { |
| 925 | prq->flags = IW_POWER_PERIOD; |
| 926 | prq->value = period * 1000; |
| 927 | } |
| 928 | if (mcast) |
| 929 | prq->flags |= IW_POWER_ALL_R; |
| 930 | else |
| 931 | prq->flags |= IW_POWER_UNICAST_R; |
| 932 | |
| 933 | out: |
| 934 | orinoco_unlock(priv, &flags); |
| 935 | |
| 936 | return err; |
| 937 | } |
| 938 | |
| 939 | static int orinoco_ioctl_set_encodeext(struct net_device *dev, |
| 940 | struct iw_request_info *info, |
| 941 | union iwreq_data *wrqu, |
| 942 | char *extra) |
| 943 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 944 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 945 | struct iw_point *encoding = &wrqu->encoding; |
| 946 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 947 | int idx, alg = ext->alg, set_key = 1; |
| 948 | unsigned long flags; |
| 949 | int err = -EINVAL; |
| 950 | u16 key_len; |
| 951 | |
| 952 | if (orinoco_lock(priv, &flags) != 0) |
| 953 | return -EBUSY; |
| 954 | |
| 955 | /* Determine and validate the key index */ |
| 956 | idx = encoding->flags & IW_ENCODE_INDEX; |
| 957 | if (idx) { |
| 958 | if ((idx < 1) || (idx > 4)) |
| 959 | goto out; |
| 960 | idx--; |
| 961 | } else |
| 962 | idx = priv->tx_key; |
| 963 | |
| 964 | if (encoding->flags & IW_ENCODE_DISABLED) |
| 965 | alg = IW_ENCODE_ALG_NONE; |
| 966 | |
| 967 | if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) { |
| 968 | /* Clear any TKIP TX key we had */ |
| 969 | (void) orinoco_clear_tkip_key(priv, priv->tx_key); |
| 970 | } |
| 971 | |
| 972 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { |
| 973 | priv->tx_key = idx; |
| 974 | set_key = ((alg == IW_ENCODE_ALG_TKIP) || |
| 975 | (ext->key_len > 0)) ? 1 : 0; |
| 976 | } |
| 977 | |
| 978 | if (set_key) { |
| 979 | /* Set the requested key first */ |
| 980 | switch (alg) { |
| 981 | case IW_ENCODE_ALG_NONE: |
| 982 | priv->encode_alg = alg; |
| 983 | priv->keys[idx].len = 0; |
| 984 | break; |
| 985 | |
| 986 | case IW_ENCODE_ALG_WEP: |
| 987 | if (ext->key_len > SMALL_KEY_SIZE) |
| 988 | key_len = LARGE_KEY_SIZE; |
| 989 | else if (ext->key_len > 0) |
| 990 | key_len = SMALL_KEY_SIZE; |
| 991 | else |
| 992 | goto out; |
| 993 | |
| 994 | priv->encode_alg = alg; |
| 995 | priv->keys[idx].len = cpu_to_le16(key_len); |
| 996 | |
| 997 | key_len = min(ext->key_len, key_len); |
| 998 | |
| 999 | memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE); |
| 1000 | memcpy(priv->keys[idx].data, ext->key, key_len); |
| 1001 | break; |
| 1002 | |
| 1003 | case IW_ENCODE_ALG_TKIP: |
| 1004 | { |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1005 | u8 *tkip_iv = NULL; |
| 1006 | |
| 1007 | if (!priv->has_wpa || |
| 1008 | (ext->key_len > sizeof(priv->tkip_key[0]))) |
| 1009 | goto out; |
| 1010 | |
| 1011 | priv->encode_alg = alg; |
| 1012 | memset(&priv->tkip_key[idx], 0, |
| 1013 | sizeof(priv->tkip_key[idx])); |
| 1014 | memcpy(&priv->tkip_key[idx], ext->key, ext->key_len); |
| 1015 | |
| 1016 | if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) |
| 1017 | tkip_iv = &ext->rx_seq[0]; |
| 1018 | |
David Kilroy | 98e5f40 | 2009-06-18 23:21:25 +0100 | [diff] [blame] | 1019 | err = __orinoco_hw_set_tkip_key(priv, idx, |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1020 | ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY, |
| 1021 | (u8 *) &priv->tkip_key[idx], |
| 1022 | tkip_iv, NULL); |
| 1023 | if (err) |
| 1024 | printk(KERN_ERR "%s: Error %d setting TKIP key" |
| 1025 | "\n", dev->name, err); |
| 1026 | |
| 1027 | goto out; |
| 1028 | } |
| 1029 | default: |
| 1030 | goto out; |
| 1031 | } |
| 1032 | } |
| 1033 | err = -EINPROGRESS; |
| 1034 | out: |
| 1035 | orinoco_unlock(priv, &flags); |
| 1036 | |
| 1037 | return err; |
| 1038 | } |
| 1039 | |
| 1040 | static int orinoco_ioctl_get_encodeext(struct net_device *dev, |
| 1041 | struct iw_request_info *info, |
| 1042 | union iwreq_data *wrqu, |
| 1043 | char *extra) |
| 1044 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1045 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1046 | struct iw_point *encoding = &wrqu->encoding; |
| 1047 | struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; |
| 1048 | int idx, max_key_len; |
| 1049 | unsigned long flags; |
| 1050 | int err; |
| 1051 | |
| 1052 | if (orinoco_lock(priv, &flags) != 0) |
| 1053 | return -EBUSY; |
| 1054 | |
| 1055 | err = -EINVAL; |
| 1056 | max_key_len = encoding->length - sizeof(*ext); |
| 1057 | if (max_key_len < 0) |
| 1058 | goto out; |
| 1059 | |
| 1060 | idx = encoding->flags & IW_ENCODE_INDEX; |
| 1061 | if (idx) { |
| 1062 | if ((idx < 1) || (idx > 4)) |
| 1063 | goto out; |
| 1064 | idx--; |
| 1065 | } else |
| 1066 | idx = priv->tx_key; |
| 1067 | |
| 1068 | encoding->flags = idx + 1; |
| 1069 | memset(ext, 0, sizeof(*ext)); |
| 1070 | |
| 1071 | ext->alg = priv->encode_alg; |
| 1072 | switch (priv->encode_alg) { |
| 1073 | case IW_ENCODE_ALG_NONE: |
| 1074 | ext->key_len = 0; |
| 1075 | encoding->flags |= IW_ENCODE_DISABLED; |
| 1076 | break; |
| 1077 | case IW_ENCODE_ALG_WEP: |
| 1078 | ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len), |
| 1079 | max_key_len); |
| 1080 | memcpy(ext->key, priv->keys[idx].data, ext->key_len); |
| 1081 | encoding->flags |= IW_ENCODE_ENABLED; |
| 1082 | break; |
| 1083 | case IW_ENCODE_ALG_TKIP: |
| 1084 | ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key), |
| 1085 | max_key_len); |
| 1086 | memcpy(ext->key, &priv->tkip_key[idx], ext->key_len); |
| 1087 | encoding->flags |= IW_ENCODE_ENABLED; |
| 1088 | break; |
| 1089 | } |
| 1090 | |
| 1091 | err = 0; |
| 1092 | out: |
| 1093 | orinoco_unlock(priv, &flags); |
| 1094 | |
| 1095 | return err; |
| 1096 | } |
| 1097 | |
| 1098 | static int orinoco_ioctl_set_auth(struct net_device *dev, |
| 1099 | struct iw_request_info *info, |
| 1100 | union iwreq_data *wrqu, char *extra) |
| 1101 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1102 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1103 | hermes_t *hw = &priv->hw; |
| 1104 | struct iw_param *param = &wrqu->param; |
| 1105 | unsigned long flags; |
| 1106 | int ret = -EINPROGRESS; |
| 1107 | |
| 1108 | if (orinoco_lock(priv, &flags) != 0) |
| 1109 | return -EBUSY; |
| 1110 | |
| 1111 | switch (param->flags & IW_AUTH_INDEX) { |
| 1112 | case IW_AUTH_WPA_VERSION: |
| 1113 | case IW_AUTH_CIPHER_PAIRWISE: |
| 1114 | case IW_AUTH_CIPHER_GROUP: |
| 1115 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: |
| 1116 | case IW_AUTH_PRIVACY_INVOKED: |
| 1117 | case IW_AUTH_DROP_UNENCRYPTED: |
| 1118 | /* |
| 1119 | * orinoco does not use these parameters |
| 1120 | */ |
| 1121 | break; |
| 1122 | |
| 1123 | case IW_AUTH_KEY_MGMT: |
| 1124 | /* wl_lkm implies value 2 == PSK for Hermes I |
| 1125 | * which ties in with WEXT |
| 1126 | * no other hints tho :( |
| 1127 | */ |
| 1128 | priv->key_mgmt = param->value; |
| 1129 | break; |
| 1130 | |
| 1131 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 1132 | /* When countermeasures are enabled, shut down the |
| 1133 | * card; when disabled, re-enable the card. This must |
| 1134 | * take effect immediately. |
| 1135 | * |
| 1136 | * TODO: Make sure that the EAPOL message is getting |
| 1137 | * out before card disabled |
| 1138 | */ |
| 1139 | if (param->value) { |
| 1140 | priv->tkip_cm_active = 1; |
| 1141 | ret = hermes_enable_port(hw, 0); |
| 1142 | } else { |
| 1143 | priv->tkip_cm_active = 0; |
| 1144 | ret = hermes_disable_port(hw, 0); |
| 1145 | } |
| 1146 | break; |
| 1147 | |
| 1148 | case IW_AUTH_80211_AUTH_ALG: |
| 1149 | if (param->value & IW_AUTH_ALG_SHARED_KEY) |
| 1150 | priv->wep_restrict = 1; |
| 1151 | else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) |
| 1152 | priv->wep_restrict = 0; |
| 1153 | else |
| 1154 | ret = -EINVAL; |
| 1155 | break; |
| 1156 | |
| 1157 | case IW_AUTH_WPA_ENABLED: |
| 1158 | if (priv->has_wpa) { |
| 1159 | priv->wpa_enabled = param->value ? 1 : 0; |
| 1160 | } else { |
| 1161 | if (param->value) |
| 1162 | ret = -EOPNOTSUPP; |
| 1163 | /* else silently accept disable of WPA */ |
| 1164 | priv->wpa_enabled = 0; |
| 1165 | } |
| 1166 | break; |
| 1167 | |
| 1168 | default: |
| 1169 | ret = -EOPNOTSUPP; |
| 1170 | } |
| 1171 | |
| 1172 | orinoco_unlock(priv, &flags); |
| 1173 | return ret; |
| 1174 | } |
| 1175 | |
| 1176 | static int orinoco_ioctl_get_auth(struct net_device *dev, |
| 1177 | struct iw_request_info *info, |
| 1178 | union iwreq_data *wrqu, char *extra) |
| 1179 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1180 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1181 | struct iw_param *param = &wrqu->param; |
| 1182 | unsigned long flags; |
| 1183 | int ret = 0; |
| 1184 | |
| 1185 | if (orinoco_lock(priv, &flags) != 0) |
| 1186 | return -EBUSY; |
| 1187 | |
| 1188 | switch (param->flags & IW_AUTH_INDEX) { |
| 1189 | case IW_AUTH_KEY_MGMT: |
| 1190 | param->value = priv->key_mgmt; |
| 1191 | break; |
| 1192 | |
| 1193 | case IW_AUTH_TKIP_COUNTERMEASURES: |
| 1194 | param->value = priv->tkip_cm_active; |
| 1195 | break; |
| 1196 | |
| 1197 | case IW_AUTH_80211_AUTH_ALG: |
| 1198 | if (priv->wep_restrict) |
| 1199 | param->value = IW_AUTH_ALG_SHARED_KEY; |
| 1200 | else |
| 1201 | param->value = IW_AUTH_ALG_OPEN_SYSTEM; |
| 1202 | break; |
| 1203 | |
| 1204 | case IW_AUTH_WPA_ENABLED: |
| 1205 | param->value = priv->wpa_enabled; |
| 1206 | break; |
| 1207 | |
| 1208 | default: |
| 1209 | ret = -EOPNOTSUPP; |
| 1210 | } |
| 1211 | |
| 1212 | orinoco_unlock(priv, &flags); |
| 1213 | return ret; |
| 1214 | } |
| 1215 | |
| 1216 | static int orinoco_ioctl_set_genie(struct net_device *dev, |
| 1217 | struct iw_request_info *info, |
| 1218 | union iwreq_data *wrqu, char *extra) |
| 1219 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1220 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1221 | u8 *buf; |
| 1222 | unsigned long flags; |
| 1223 | |
| 1224 | /* cut off at IEEE80211_MAX_DATA_LEN */ |
| 1225 | if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) || |
| 1226 | (wrqu->data.length && (extra == NULL))) |
| 1227 | return -EINVAL; |
| 1228 | |
| 1229 | if (wrqu->data.length) { |
| 1230 | buf = kmalloc(wrqu->data.length, GFP_KERNEL); |
| 1231 | if (buf == NULL) |
| 1232 | return -ENOMEM; |
| 1233 | |
| 1234 | memcpy(buf, extra, wrqu->data.length); |
| 1235 | } else |
| 1236 | buf = NULL; |
| 1237 | |
| 1238 | if (orinoco_lock(priv, &flags) != 0) { |
| 1239 | kfree(buf); |
| 1240 | return -EBUSY; |
| 1241 | } |
| 1242 | |
| 1243 | kfree(priv->wpa_ie); |
| 1244 | priv->wpa_ie = buf; |
| 1245 | priv->wpa_ie_len = wrqu->data.length; |
| 1246 | |
| 1247 | if (priv->wpa_ie) { |
| 1248 | /* Looks like wl_lkm wants to check the auth alg, and |
| 1249 | * somehow pass it to the firmware. |
| 1250 | * Instead it just calls the key mgmt rid |
| 1251 | * - we do this in set auth. |
| 1252 | */ |
| 1253 | } |
| 1254 | |
| 1255 | orinoco_unlock(priv, &flags); |
| 1256 | return 0; |
| 1257 | } |
| 1258 | |
| 1259 | static int orinoco_ioctl_get_genie(struct net_device *dev, |
| 1260 | struct iw_request_info *info, |
| 1261 | union iwreq_data *wrqu, char *extra) |
| 1262 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1263 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1264 | unsigned long flags; |
| 1265 | int err = 0; |
| 1266 | |
| 1267 | if (orinoco_lock(priv, &flags) != 0) |
| 1268 | return -EBUSY; |
| 1269 | |
| 1270 | if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) { |
| 1271 | wrqu->data.length = 0; |
| 1272 | goto out; |
| 1273 | } |
| 1274 | |
| 1275 | if (wrqu->data.length < priv->wpa_ie_len) { |
| 1276 | err = -E2BIG; |
| 1277 | goto out; |
| 1278 | } |
| 1279 | |
| 1280 | wrqu->data.length = priv->wpa_ie_len; |
| 1281 | memcpy(extra, priv->wpa_ie, priv->wpa_ie_len); |
| 1282 | |
| 1283 | out: |
| 1284 | orinoco_unlock(priv, &flags); |
| 1285 | return err; |
| 1286 | } |
| 1287 | |
| 1288 | static int orinoco_ioctl_set_mlme(struct net_device *dev, |
| 1289 | struct iw_request_info *info, |
| 1290 | union iwreq_data *wrqu, char *extra) |
| 1291 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1292 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1293 | hermes_t *hw = &priv->hw; |
| 1294 | struct iw_mlme *mlme = (struct iw_mlme *)extra; |
| 1295 | unsigned long flags; |
| 1296 | int ret = 0; |
| 1297 | |
| 1298 | if (orinoco_lock(priv, &flags) != 0) |
| 1299 | return -EBUSY; |
| 1300 | |
| 1301 | switch (mlme->cmd) { |
| 1302 | case IW_MLME_DEAUTH: |
| 1303 | /* silently ignore */ |
| 1304 | break; |
| 1305 | |
| 1306 | case IW_MLME_DISASSOC: |
| 1307 | { |
| 1308 | struct { |
| 1309 | u8 addr[ETH_ALEN]; |
| 1310 | __le16 reason_code; |
| 1311 | } __attribute__ ((packed)) buf; |
| 1312 | |
| 1313 | memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN); |
| 1314 | buf.reason_code = cpu_to_le16(mlme->reason_code); |
| 1315 | ret = HERMES_WRITE_RECORD(hw, USER_BAP, |
| 1316 | HERMES_RID_CNFDISASSOCIATE, |
| 1317 | &buf); |
| 1318 | break; |
| 1319 | } |
| 1320 | default: |
| 1321 | ret = -EOPNOTSUPP; |
| 1322 | } |
| 1323 | |
| 1324 | orinoco_unlock(priv, &flags); |
| 1325 | return ret; |
| 1326 | } |
| 1327 | |
| 1328 | static int orinoco_ioctl_getretry(struct net_device *dev, |
| 1329 | struct iw_request_info *info, |
| 1330 | struct iw_param *rrq, |
| 1331 | char *extra) |
| 1332 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1333 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1334 | hermes_t *hw = &priv->hw; |
| 1335 | int err = 0; |
| 1336 | u16 short_limit, long_limit, lifetime; |
| 1337 | unsigned long flags; |
| 1338 | |
| 1339 | if (orinoco_lock(priv, &flags) != 0) |
| 1340 | return -EBUSY; |
| 1341 | |
| 1342 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT, |
| 1343 | &short_limit); |
| 1344 | if (err) |
| 1345 | goto out; |
| 1346 | |
| 1347 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT, |
| 1348 | &long_limit); |
| 1349 | if (err) |
| 1350 | goto out; |
| 1351 | |
| 1352 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME, |
| 1353 | &lifetime); |
| 1354 | if (err) |
| 1355 | goto out; |
| 1356 | |
| 1357 | rrq->disabled = 0; /* Can't be disabled */ |
| 1358 | |
| 1359 | /* Note : by default, display the retry number */ |
| 1360 | if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { |
| 1361 | rrq->flags = IW_RETRY_LIFETIME; |
| 1362 | rrq->value = lifetime * 1000; /* ??? */ |
| 1363 | } else { |
| 1364 | /* By default, display the min number */ |
| 1365 | if ((rrq->flags & IW_RETRY_LONG)) { |
| 1366 | rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; |
| 1367 | rrq->value = long_limit; |
| 1368 | } else { |
| 1369 | rrq->flags = IW_RETRY_LIMIT; |
| 1370 | rrq->value = short_limit; |
| 1371 | if (short_limit != long_limit) |
| 1372 | rrq->flags |= IW_RETRY_SHORT; |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | out: |
| 1377 | orinoco_unlock(priv, &flags); |
| 1378 | |
| 1379 | return err; |
| 1380 | } |
| 1381 | |
| 1382 | static int orinoco_ioctl_reset(struct net_device *dev, |
| 1383 | struct iw_request_info *info, |
| 1384 | void *wrqu, |
| 1385 | char *extra) |
| 1386 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1387 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1388 | |
| 1389 | if (!capable(CAP_NET_ADMIN)) |
| 1390 | return -EPERM; |
| 1391 | |
| 1392 | if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) { |
| 1393 | printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name); |
| 1394 | |
| 1395 | /* Firmware reset */ |
| 1396 | orinoco_reset(&priv->reset_work); |
| 1397 | } else { |
| 1398 | printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name); |
| 1399 | |
| 1400 | schedule_work(&priv->reset_work); |
| 1401 | } |
| 1402 | |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | static int orinoco_ioctl_setibssport(struct net_device *dev, |
| 1407 | struct iw_request_info *info, |
| 1408 | void *wrqu, |
| 1409 | char *extra) |
| 1410 | |
| 1411 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1412 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1413 | int val = *((int *) extra); |
| 1414 | unsigned long flags; |
| 1415 | |
| 1416 | if (orinoco_lock(priv, &flags) != 0) |
| 1417 | return -EBUSY; |
| 1418 | |
| 1419 | priv->ibss_port = val ; |
| 1420 | |
| 1421 | /* Actually update the mode we are using */ |
| 1422 | set_port_type(priv); |
| 1423 | |
| 1424 | orinoco_unlock(priv, &flags); |
| 1425 | return -EINPROGRESS; /* Call commit handler */ |
| 1426 | } |
| 1427 | |
| 1428 | static int orinoco_ioctl_getibssport(struct net_device *dev, |
| 1429 | struct iw_request_info *info, |
| 1430 | void *wrqu, |
| 1431 | char *extra) |
| 1432 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1433 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1434 | int *val = (int *) extra; |
| 1435 | |
| 1436 | *val = priv->ibss_port; |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
| 1440 | static int orinoco_ioctl_setport3(struct net_device *dev, |
| 1441 | struct iw_request_info *info, |
| 1442 | void *wrqu, |
| 1443 | char *extra) |
| 1444 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1445 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1446 | int val = *((int *) extra); |
| 1447 | int err = 0; |
| 1448 | unsigned long flags; |
| 1449 | |
| 1450 | if (orinoco_lock(priv, &flags) != 0) |
| 1451 | return -EBUSY; |
| 1452 | |
| 1453 | switch (val) { |
| 1454 | case 0: /* Try to do IEEE ad-hoc mode */ |
| 1455 | if (!priv->has_ibss) { |
| 1456 | err = -EINVAL; |
| 1457 | break; |
| 1458 | } |
| 1459 | priv->prefer_port3 = 0; |
| 1460 | |
| 1461 | break; |
| 1462 | |
| 1463 | case 1: /* Try to do Lucent proprietary ad-hoc mode */ |
| 1464 | if (!priv->has_port3) { |
| 1465 | err = -EINVAL; |
| 1466 | break; |
| 1467 | } |
| 1468 | priv->prefer_port3 = 1; |
| 1469 | break; |
| 1470 | |
| 1471 | default: |
| 1472 | err = -EINVAL; |
| 1473 | } |
| 1474 | |
| 1475 | if (!err) { |
| 1476 | /* Actually update the mode we are using */ |
| 1477 | set_port_type(priv); |
| 1478 | err = -EINPROGRESS; |
| 1479 | } |
| 1480 | |
| 1481 | orinoco_unlock(priv, &flags); |
| 1482 | |
| 1483 | return err; |
| 1484 | } |
| 1485 | |
| 1486 | static int orinoco_ioctl_getport3(struct net_device *dev, |
| 1487 | struct iw_request_info *info, |
| 1488 | void *wrqu, |
| 1489 | char *extra) |
| 1490 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1491 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1492 | int *val = (int *) extra; |
| 1493 | |
| 1494 | *val = priv->prefer_port3; |
| 1495 | return 0; |
| 1496 | } |
| 1497 | |
| 1498 | static int orinoco_ioctl_setpreamble(struct net_device *dev, |
| 1499 | struct iw_request_info *info, |
| 1500 | void *wrqu, |
| 1501 | char *extra) |
| 1502 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1503 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1504 | unsigned long flags; |
| 1505 | int val; |
| 1506 | |
| 1507 | if (!priv->has_preamble) |
| 1508 | return -EOPNOTSUPP; |
| 1509 | |
| 1510 | /* 802.11b has recently defined some short preamble. |
| 1511 | * Basically, the Phy header has been reduced in size. |
| 1512 | * This increase performance, especially at high rates |
| 1513 | * (the preamble is transmitted at 1Mb/s), unfortunately |
| 1514 | * this give compatibility troubles... - Jean II */ |
| 1515 | val = *((int *) extra); |
| 1516 | |
| 1517 | if (orinoco_lock(priv, &flags) != 0) |
| 1518 | return -EBUSY; |
| 1519 | |
| 1520 | if (val) |
| 1521 | priv->preamble = 1; |
| 1522 | else |
| 1523 | priv->preamble = 0; |
| 1524 | |
| 1525 | orinoco_unlock(priv, &flags); |
| 1526 | |
| 1527 | return -EINPROGRESS; /* Call commit handler */ |
| 1528 | } |
| 1529 | |
| 1530 | static int orinoco_ioctl_getpreamble(struct net_device *dev, |
| 1531 | struct iw_request_info *info, |
| 1532 | void *wrqu, |
| 1533 | char *extra) |
| 1534 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1535 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1536 | int *val = (int *) extra; |
| 1537 | |
| 1538 | if (!priv->has_preamble) |
| 1539 | return -EOPNOTSUPP; |
| 1540 | |
| 1541 | *val = priv->preamble; |
| 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | /* ioctl interface to hermes_read_ltv() |
| 1546 | * To use with iwpriv, pass the RID as the token argument, e.g. |
| 1547 | * iwpriv get_rid [0xfc00] |
| 1548 | * At least Wireless Tools 25 is required to use iwpriv. |
| 1549 | * For Wireless Tools 25 and 26 append "dummy" are the end. */ |
| 1550 | static int orinoco_ioctl_getrid(struct net_device *dev, |
| 1551 | struct iw_request_info *info, |
| 1552 | struct iw_point *data, |
| 1553 | char *extra) |
| 1554 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1555 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1556 | hermes_t *hw = &priv->hw; |
| 1557 | int rid = data->flags; |
| 1558 | u16 length; |
| 1559 | int err; |
| 1560 | unsigned long flags; |
| 1561 | |
| 1562 | /* It's a "get" function, but we don't want users to access the |
| 1563 | * WEP key and other raw firmware data */ |
| 1564 | if (!capable(CAP_NET_ADMIN)) |
| 1565 | return -EPERM; |
| 1566 | |
| 1567 | if (rid < 0xfc00 || rid > 0xffff) |
| 1568 | return -EINVAL; |
| 1569 | |
| 1570 | if (orinoco_lock(priv, &flags) != 0) |
| 1571 | return -EBUSY; |
| 1572 | |
| 1573 | err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length, |
| 1574 | extra); |
| 1575 | if (err) |
| 1576 | goto out; |
| 1577 | |
| 1578 | data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length), |
| 1579 | MAX_RID_LEN); |
| 1580 | |
| 1581 | out: |
| 1582 | orinoco_unlock(priv, &flags); |
| 1583 | return err; |
| 1584 | } |
| 1585 | |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1586 | |
| 1587 | /* Commit handler, called after set operations */ |
| 1588 | static int orinoco_ioctl_commit(struct net_device *dev, |
| 1589 | struct iw_request_info *info, |
| 1590 | void *wrqu, |
| 1591 | char *extra) |
| 1592 | { |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1593 | struct orinoco_private *priv = ndev_priv(dev); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1594 | unsigned long flags; |
| 1595 | int err = 0; |
| 1596 | |
| 1597 | if (!priv->open) |
| 1598 | return 0; |
| 1599 | |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1600 | if (orinoco_lock(priv, &flags) != 0) |
| 1601 | return err; |
| 1602 | |
David Kilroy | 721aa2f | 2009-06-18 23:21:31 +0100 | [diff] [blame] | 1603 | err = orinoco_commit(priv); |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1604 | |
| 1605 | orinoco_unlock(priv, &flags); |
| 1606 | return err; |
| 1607 | } |
| 1608 | |
| 1609 | static const struct iw_priv_args orinoco_privtab[] = { |
| 1610 | { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" }, |
| 1611 | { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" }, |
| 1612 | { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1613 | 0, "set_port3" }, |
| 1614 | { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1615 | "get_port3" }, |
| 1616 | { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1617 | 0, "set_preamble" }, |
| 1618 | { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1619 | "get_preamble" }, |
| 1620 | { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1621 | 0, "set_ibssport" }, |
| 1622 | { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, |
| 1623 | "get_ibssport" }, |
| 1624 | { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN, |
| 1625 | "get_rid" }, |
| 1626 | }; |
| 1627 | |
| 1628 | |
| 1629 | /* |
| 1630 | * Structures to export the Wireless Handlers |
| 1631 | */ |
| 1632 | |
| 1633 | #define STD_IW_HANDLER(id, func) \ |
| 1634 | [IW_IOCTL_IDX(id)] = (iw_handler) func |
| 1635 | static const iw_handler orinoco_handler[] = { |
| 1636 | STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit), |
David Kilroy | ea60a6a | 2009-06-18 23:21:26 +0100 | [diff] [blame] | 1637 | STD_IW_HANDLER(SIOCGIWNAME, cfg80211_wext_giwname), |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1638 | STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq), |
| 1639 | STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq), |
David Kilroy | 5217c57 | 2009-06-18 23:21:32 +0100 | [diff] [blame] | 1640 | STD_IW_HANDLER(SIOCSIWMODE, cfg80211_wext_siwmode), |
| 1641 | STD_IW_HANDLER(SIOCGIWMODE, cfg80211_wext_giwmode), |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1642 | STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens), |
| 1643 | STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens), |
| 1644 | STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange), |
| 1645 | STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy), |
| 1646 | STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy), |
| 1647 | STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy), |
| 1648 | STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy), |
| 1649 | STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap), |
| 1650 | STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap), |
David Kilroy | c63cdbe | 2009-06-18 23:21:33 +0100 | [diff] [blame^] | 1651 | STD_IW_HANDLER(SIOCSIWSCAN, cfg80211_wext_siwscan), |
| 1652 | STD_IW_HANDLER(SIOCGIWSCAN, cfg80211_wext_giwscan), |
David Kilroy | cb1576a | 2009-02-04 23:05:56 +0000 | [diff] [blame] | 1653 | STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid), |
| 1654 | STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid), |
| 1655 | STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick), |
| 1656 | STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick), |
| 1657 | STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate), |
| 1658 | STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate), |
| 1659 | STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts), |
| 1660 | STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts), |
| 1661 | STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag), |
| 1662 | STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag), |
| 1663 | STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry), |
| 1664 | STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode), |
| 1665 | STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode), |
| 1666 | STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower), |
| 1667 | STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower), |
| 1668 | STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie), |
| 1669 | STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie), |
| 1670 | STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme), |
| 1671 | STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth), |
| 1672 | STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth), |
| 1673 | STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext), |
| 1674 | STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext), |
| 1675 | }; |
| 1676 | |
| 1677 | |
| 1678 | /* |
| 1679 | Added typecasting since we no longer use iwreq_data -- Moustafa |
| 1680 | */ |
| 1681 | static const iw_handler orinoco_private_handler[] = { |
| 1682 | [0] = (iw_handler) orinoco_ioctl_reset, |
| 1683 | [1] = (iw_handler) orinoco_ioctl_reset, |
| 1684 | [2] = (iw_handler) orinoco_ioctl_setport3, |
| 1685 | [3] = (iw_handler) orinoco_ioctl_getport3, |
| 1686 | [4] = (iw_handler) orinoco_ioctl_setpreamble, |
| 1687 | [5] = (iw_handler) orinoco_ioctl_getpreamble, |
| 1688 | [6] = (iw_handler) orinoco_ioctl_setibssport, |
| 1689 | [7] = (iw_handler) orinoco_ioctl_getibssport, |
| 1690 | [9] = (iw_handler) orinoco_ioctl_getrid, |
| 1691 | }; |
| 1692 | |
| 1693 | const struct iw_handler_def orinoco_handler_def = { |
| 1694 | .num_standard = ARRAY_SIZE(orinoco_handler), |
| 1695 | .num_private = ARRAY_SIZE(orinoco_private_handler), |
| 1696 | .num_private_args = ARRAY_SIZE(orinoco_privtab), |
| 1697 | .standard = orinoco_handler, |
| 1698 | .private = orinoco_private_handler, |
| 1699 | .private_args = orinoco_privtab, |
| 1700 | .get_wireless_stats = orinoco_get_wireless_stats, |
| 1701 | }; |