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