David Kilroy | 712a434 | 2009-02-04 23:05:55 +0000 | [diff] [blame] | 1 | /* Encapsulate basic setting changes and retrieval on Hermes hardware |
| 2 | * |
| 3 | * See copyright notice in main.c |
| 4 | */ |
| 5 | #include <linux/kernel.h> |
| 6 | #include <linux/if_arp.h> |
| 7 | #include <linux/ieee80211.h> |
| 8 | #include <linux/wireless.h> |
| 9 | |
| 10 | #include "hermes.h" |
| 11 | #include "hermes_rid.h" |
| 12 | #include "orinoco.h" |
| 13 | |
| 14 | #include "hw.h" |
| 15 | |
David Kilroy | a2d1a42 | 2009-06-18 23:21:18 +0100 | [diff] [blame^] | 16 | #define SYMBOL_MAX_VER_LEN (14) |
| 17 | |
David Kilroy | 712a434 | 2009-02-04 23:05:55 +0000 | [diff] [blame] | 18 | /********************************************************************/ |
| 19 | /* Data tables */ |
| 20 | /********************************************************************/ |
| 21 | |
| 22 | /* This tables gives the actual meanings of the bitrate IDs returned |
| 23 | * by the firmware. */ |
| 24 | static const struct { |
| 25 | int bitrate; /* in 100s of kilobits */ |
| 26 | int automatic; |
| 27 | u16 agere_txratectrl; |
| 28 | u16 intersil_txratectrl; |
| 29 | } bitrate_table[] = { |
| 30 | {110, 1, 3, 15}, /* Entry 0 is the default */ |
| 31 | {10, 0, 1, 1}, |
| 32 | {10, 1, 1, 1}, |
| 33 | {20, 0, 2, 2}, |
| 34 | {20, 1, 6, 3}, |
| 35 | {55, 0, 4, 4}, |
| 36 | {55, 1, 7, 7}, |
| 37 | {110, 0, 5, 8}, |
| 38 | }; |
| 39 | #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table) |
| 40 | |
David Kilroy | a2d1a42 | 2009-06-18 23:21:18 +0100 | [diff] [blame^] | 41 | /* Firmware version encoding */ |
| 42 | struct comp_id { |
| 43 | u16 id, variant, major, minor; |
| 44 | } __attribute__ ((packed)); |
| 45 | |
| 46 | static inline fwtype_t determine_firmware_type(struct comp_id *nic_id) |
| 47 | { |
| 48 | if (nic_id->id < 0x8000) |
| 49 | return FIRMWARE_TYPE_AGERE; |
| 50 | else if (nic_id->id == 0x8000 && nic_id->major == 0) |
| 51 | return FIRMWARE_TYPE_SYMBOL; |
| 52 | else |
| 53 | return FIRMWARE_TYPE_INTERSIL; |
| 54 | } |
| 55 | |
| 56 | /* Set priv->firmware type, determine firmware properties */ |
| 57 | int determine_fw_capabilities(struct orinoco_private *priv) |
| 58 | { |
| 59 | struct net_device *dev = priv->ndev; |
| 60 | hermes_t *hw = &priv->hw; |
| 61 | int err; |
| 62 | struct comp_id nic_id, sta_id; |
| 63 | unsigned int firmver; |
| 64 | char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2))); |
| 65 | |
| 66 | /* Get the hardware version */ |
| 67 | err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id); |
| 68 | if (err) { |
| 69 | printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n", |
| 70 | dev->name, err); |
| 71 | return err; |
| 72 | } |
| 73 | |
| 74 | le16_to_cpus(&nic_id.id); |
| 75 | le16_to_cpus(&nic_id.variant); |
| 76 | le16_to_cpus(&nic_id.major); |
| 77 | le16_to_cpus(&nic_id.minor); |
| 78 | printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n", |
| 79 | dev->name, nic_id.id, nic_id.variant, |
| 80 | nic_id.major, nic_id.minor); |
| 81 | |
| 82 | priv->firmware_type = determine_firmware_type(&nic_id); |
| 83 | |
| 84 | /* Get the firmware version */ |
| 85 | err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id); |
| 86 | if (err) { |
| 87 | printk(KERN_ERR "%s: Cannot read station identity: error %d\n", |
| 88 | dev->name, err); |
| 89 | return err; |
| 90 | } |
| 91 | |
| 92 | le16_to_cpus(&sta_id.id); |
| 93 | le16_to_cpus(&sta_id.variant); |
| 94 | le16_to_cpus(&sta_id.major); |
| 95 | le16_to_cpus(&sta_id.minor); |
| 96 | printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n", |
| 97 | dev->name, sta_id.id, sta_id.variant, |
| 98 | sta_id.major, sta_id.minor); |
| 99 | |
| 100 | switch (sta_id.id) { |
| 101 | case 0x15: |
| 102 | printk(KERN_ERR "%s: Primary firmware is active\n", |
| 103 | dev->name); |
| 104 | return -ENODEV; |
| 105 | case 0x14b: |
| 106 | printk(KERN_ERR "%s: Tertiary firmware is active\n", |
| 107 | dev->name); |
| 108 | return -ENODEV; |
| 109 | case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */ |
| 110 | case 0x21: /* Symbol Spectrum24 Trilogy */ |
| 111 | break; |
| 112 | default: |
| 113 | printk(KERN_NOTICE "%s: Unknown station ID, please report\n", |
| 114 | dev->name); |
| 115 | break; |
| 116 | } |
| 117 | |
| 118 | /* Default capabilities */ |
| 119 | priv->has_sensitivity = 1; |
| 120 | priv->has_mwo = 0; |
| 121 | priv->has_preamble = 0; |
| 122 | priv->has_port3 = 1; |
| 123 | priv->has_ibss = 1; |
| 124 | priv->has_wep = 0; |
| 125 | priv->has_big_wep = 0; |
| 126 | priv->has_alt_txcntl = 0; |
| 127 | priv->has_ext_scan = 0; |
| 128 | priv->has_wpa = 0; |
| 129 | priv->do_fw_download = 0; |
| 130 | |
| 131 | /* Determine capabilities from the firmware version */ |
| 132 | switch (priv->firmware_type) { |
| 133 | case FIRMWARE_TYPE_AGERE: |
| 134 | /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout, |
| 135 | ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */ |
| 136 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, |
| 137 | "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor); |
| 138 | |
| 139 | firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor; |
| 140 | |
| 141 | priv->has_ibss = (firmver >= 0x60006); |
| 142 | priv->has_wep = (firmver >= 0x40020); |
| 143 | priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell |
| 144 | Gold cards from the others? */ |
| 145 | priv->has_mwo = (firmver >= 0x60000); |
| 146 | priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */ |
| 147 | priv->ibss_port = 1; |
| 148 | priv->has_hostscan = (firmver >= 0x8000a); |
| 149 | priv->do_fw_download = 1; |
| 150 | priv->broken_monitor = (firmver >= 0x80000); |
| 151 | priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */ |
| 152 | priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */ |
| 153 | priv->has_wpa = (firmver >= 0x9002a); |
| 154 | /* Tested with Agere firmware : |
| 155 | * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II |
| 156 | * Tested CableTron firmware : 4.32 => Anton */ |
| 157 | break; |
| 158 | case FIRMWARE_TYPE_SYMBOL: |
| 159 | /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */ |
| 160 | /* Intel MAC : 00:02:B3:* */ |
| 161 | /* 3Com MAC : 00:50:DA:* */ |
| 162 | memset(tmp, 0, sizeof(tmp)); |
| 163 | /* Get the Symbol firmware version */ |
| 164 | err = hermes_read_ltv(hw, USER_BAP, |
| 165 | HERMES_RID_SECONDARYVERSION_SYMBOL, |
| 166 | SYMBOL_MAX_VER_LEN, NULL, &tmp); |
| 167 | if (err) { |
| 168 | printk(KERN_WARNING |
| 169 | "%s: Error %d reading Symbol firmware info. " |
| 170 | "Wildly guessing capabilities...\n", |
| 171 | dev->name, err); |
| 172 | firmver = 0; |
| 173 | tmp[0] = '\0'; |
| 174 | } else { |
| 175 | /* The firmware revision is a string, the format is |
| 176 | * something like : "V2.20-01". |
| 177 | * Quick and dirty parsing... - Jean II |
| 178 | */ |
| 179 | firmver = ((tmp[1] - '0') << 16) |
| 180 | | ((tmp[3] - '0') << 12) |
| 181 | | ((tmp[4] - '0') << 8) |
| 182 | | ((tmp[6] - '0') << 4) |
| 183 | | (tmp[7] - '0'); |
| 184 | |
| 185 | tmp[SYMBOL_MAX_VER_LEN] = '\0'; |
| 186 | } |
| 187 | |
| 188 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, |
| 189 | "Symbol %s", tmp); |
| 190 | |
| 191 | priv->has_ibss = (firmver >= 0x20000); |
| 192 | priv->has_wep = (firmver >= 0x15012); |
| 193 | priv->has_big_wep = (firmver >= 0x20000); |
| 194 | priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) || |
| 195 | (firmver >= 0x29000 && firmver < 0x30000) || |
| 196 | firmver >= 0x31000; |
| 197 | priv->has_preamble = (firmver >= 0x20000); |
| 198 | priv->ibss_port = 4; |
| 199 | |
| 200 | /* Symbol firmware is found on various cards, but |
| 201 | * there has been no attempt to check firmware |
| 202 | * download on non-spectrum_cs based cards. |
| 203 | * |
| 204 | * Given that the Agere firmware download works |
| 205 | * differently, we should avoid doing a firmware |
| 206 | * download with the Symbol algorithm on non-spectrum |
| 207 | * cards. |
| 208 | * |
| 209 | * For now we can identify a spectrum_cs based card |
| 210 | * because it has a firmware reset function. |
| 211 | */ |
| 212 | priv->do_fw_download = (priv->stop_fw != NULL); |
| 213 | |
| 214 | priv->broken_disableport = (firmver == 0x25013) || |
| 215 | (firmver >= 0x30000 && firmver <= 0x31000); |
| 216 | priv->has_hostscan = (firmver >= 0x31001) || |
| 217 | (firmver >= 0x29057 && firmver < 0x30000); |
| 218 | /* Tested with Intel firmware : 0x20015 => Jean II */ |
| 219 | /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */ |
| 220 | break; |
| 221 | case FIRMWARE_TYPE_INTERSIL: |
| 222 | /* D-Link, Linksys, Adtron, ZoomAir, and many others... |
| 223 | * Samsung, Compaq 100/200 and Proxim are slightly |
| 224 | * different and less well tested */ |
| 225 | /* D-Link MAC : 00:40:05:* */ |
| 226 | /* Addtron MAC : 00:90:D1:* */ |
| 227 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, |
| 228 | "Intersil %d.%d.%d", sta_id.major, sta_id.minor, |
| 229 | sta_id.variant); |
| 230 | |
| 231 | firmver = ((unsigned long)sta_id.major << 16) | |
| 232 | ((unsigned long)sta_id.minor << 8) | sta_id.variant; |
| 233 | |
| 234 | priv->has_ibss = (firmver >= 0x000700); /* FIXME */ |
| 235 | priv->has_big_wep = priv->has_wep = (firmver >= 0x000800); |
| 236 | priv->has_pm = (firmver >= 0x000700); |
| 237 | priv->has_hostscan = (firmver >= 0x010301); |
| 238 | |
| 239 | if (firmver >= 0x000800) |
| 240 | priv->ibss_port = 0; |
| 241 | else { |
| 242 | printk(KERN_NOTICE "%s: Intersil firmware earlier " |
| 243 | "than v0.8.x - several features not supported\n", |
| 244 | dev->name); |
| 245 | priv->ibss_port = 1; |
| 246 | } |
| 247 | break; |
| 248 | } |
| 249 | printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name, |
| 250 | priv->fw_name); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
David Kilroy | 712a434 | 2009-02-04 23:05:55 +0000 | [diff] [blame] | 255 | int orinoco_get_bitratemode(int bitrate, int automatic) |
| 256 | { |
| 257 | int ratemode = -1; |
| 258 | int i; |
| 259 | |
| 260 | if ((bitrate != 10) && (bitrate != 20) && |
| 261 | (bitrate != 55) && (bitrate != 110)) |
| 262 | return ratemode; |
| 263 | |
| 264 | for (i = 0; i < BITRATE_TABLE_SIZE; i++) { |
| 265 | if ((bitrate_table[i].bitrate == bitrate) && |
| 266 | (bitrate_table[i].automatic == automatic)) { |
| 267 | ratemode = i; |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | return ratemode; |
| 272 | } |
| 273 | |
| 274 | void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic) |
| 275 | { |
| 276 | BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE)); |
| 277 | |
| 278 | *bitrate = bitrate_table[ratemode].bitrate * 100000; |
| 279 | *automatic = bitrate_table[ratemode].automatic; |
| 280 | } |
| 281 | |
| 282 | /* Get tsc from the firmware */ |
| 283 | int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc) |
| 284 | { |
| 285 | hermes_t *hw = &priv->hw; |
| 286 | int err = 0; |
| 287 | u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE]; |
| 288 | |
| 289 | if ((key < 0) || (key > 4)) |
| 290 | return -EINVAL; |
| 291 | |
| 292 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV, |
| 293 | sizeof(tsc_arr), NULL, &tsc_arr); |
| 294 | if (!err) |
| 295 | memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0])); |
| 296 | |
| 297 | return err; |
| 298 | } |
| 299 | |
| 300 | int __orinoco_hw_set_bitrate(struct orinoco_private *priv) |
| 301 | { |
| 302 | hermes_t *hw = &priv->hw; |
| 303 | int ratemode = priv->bitratemode; |
| 304 | int err = 0; |
| 305 | |
| 306 | if (ratemode >= BITRATE_TABLE_SIZE) { |
| 307 | printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n", |
| 308 | priv->ndev->name, ratemode); |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | switch (priv->firmware_type) { |
| 313 | case FIRMWARE_TYPE_AGERE: |
| 314 | err = hermes_write_wordrec(hw, USER_BAP, |
| 315 | HERMES_RID_CNFTXRATECONTROL, |
| 316 | bitrate_table[ratemode].agere_txratectrl); |
| 317 | break; |
| 318 | case FIRMWARE_TYPE_INTERSIL: |
| 319 | case FIRMWARE_TYPE_SYMBOL: |
| 320 | err = hermes_write_wordrec(hw, USER_BAP, |
| 321 | HERMES_RID_CNFTXRATECONTROL, |
| 322 | bitrate_table[ratemode].intersil_txratectrl); |
| 323 | break; |
| 324 | default: |
| 325 | BUG(); |
| 326 | } |
| 327 | |
| 328 | return err; |
| 329 | } |
| 330 | |
| 331 | int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate) |
| 332 | { |
| 333 | hermes_t *hw = &priv->hw; |
| 334 | int i; |
| 335 | int err = 0; |
| 336 | u16 val; |
| 337 | |
| 338 | err = hermes_read_wordrec(hw, USER_BAP, |
| 339 | HERMES_RID_CURRENTTXRATE, &val); |
| 340 | if (err) |
| 341 | return err; |
| 342 | |
| 343 | switch (priv->firmware_type) { |
| 344 | case FIRMWARE_TYPE_AGERE: /* Lucent style rate */ |
| 345 | /* Note : in Lucent firmware, the return value of |
| 346 | * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s, |
| 347 | * and therefore is totally different from the |
| 348 | * encoding of HERMES_RID_CNFTXRATECONTROL. |
| 349 | * Don't forget that 6Mb/s is really 5.5Mb/s */ |
| 350 | if (val == 6) |
| 351 | *bitrate = 5500000; |
| 352 | else |
| 353 | *bitrate = val * 1000000; |
| 354 | break; |
| 355 | case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */ |
| 356 | case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */ |
| 357 | for (i = 0; i < BITRATE_TABLE_SIZE; i++) |
| 358 | if (bitrate_table[i].intersil_txratectrl == val) |
| 359 | break; |
| 360 | |
| 361 | if (i >= BITRATE_TABLE_SIZE) |
| 362 | printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n", |
| 363 | priv->ndev->name, val); |
| 364 | |
| 365 | *bitrate = bitrate_table[i].bitrate * 100000; |
| 366 | break; |
| 367 | default: |
| 368 | BUG(); |
| 369 | } |
| 370 | |
| 371 | return err; |
| 372 | } |
| 373 | |
| 374 | /* Set fixed AP address */ |
| 375 | int __orinoco_hw_set_wap(struct orinoco_private *priv) |
| 376 | { |
| 377 | int roaming_flag; |
| 378 | int err = 0; |
| 379 | hermes_t *hw = &priv->hw; |
| 380 | |
| 381 | switch (priv->firmware_type) { |
| 382 | case FIRMWARE_TYPE_AGERE: |
| 383 | /* not supported */ |
| 384 | break; |
| 385 | case FIRMWARE_TYPE_INTERSIL: |
| 386 | if (priv->bssid_fixed) |
| 387 | roaming_flag = 2; |
| 388 | else |
| 389 | roaming_flag = 1; |
| 390 | |
| 391 | err = hermes_write_wordrec(hw, USER_BAP, |
| 392 | HERMES_RID_CNFROAMINGMODE, |
| 393 | roaming_flag); |
| 394 | break; |
| 395 | case FIRMWARE_TYPE_SYMBOL: |
| 396 | err = HERMES_WRITE_RECORD(hw, USER_BAP, |
| 397 | HERMES_RID_CNFMANDATORYBSSID_SYMBOL, |
| 398 | &priv->desired_bssid); |
| 399 | break; |
| 400 | } |
| 401 | return err; |
| 402 | } |
| 403 | |
| 404 | /* Change the WEP keys and/or the current keys. Can be called |
| 405 | * either from __orinoco_hw_setup_enc() or directly from |
| 406 | * orinoco_ioctl_setiwencode(). In the later case the association |
| 407 | * with the AP is not broken (if the firmware can handle it), |
| 408 | * which is needed for 802.1x implementations. */ |
| 409 | int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv) |
| 410 | { |
| 411 | hermes_t *hw = &priv->hw; |
| 412 | int err = 0; |
| 413 | |
| 414 | switch (priv->firmware_type) { |
| 415 | case FIRMWARE_TYPE_AGERE: |
| 416 | err = HERMES_WRITE_RECORD(hw, USER_BAP, |
| 417 | HERMES_RID_CNFWEPKEYS_AGERE, |
| 418 | &priv->keys); |
| 419 | if (err) |
| 420 | return err; |
| 421 | err = hermes_write_wordrec(hw, USER_BAP, |
| 422 | HERMES_RID_CNFTXKEY_AGERE, |
| 423 | priv->tx_key); |
| 424 | if (err) |
| 425 | return err; |
| 426 | break; |
| 427 | case FIRMWARE_TYPE_INTERSIL: |
| 428 | case FIRMWARE_TYPE_SYMBOL: |
| 429 | { |
| 430 | int keylen; |
| 431 | int i; |
| 432 | |
| 433 | /* Force uniform key length to work around |
| 434 | * firmware bugs */ |
| 435 | keylen = le16_to_cpu(priv->keys[priv->tx_key].len); |
| 436 | |
| 437 | if (keylen > LARGE_KEY_SIZE) { |
| 438 | printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n", |
| 439 | priv->ndev->name, priv->tx_key, keylen); |
| 440 | return -E2BIG; |
| 441 | } |
| 442 | |
| 443 | /* Write all 4 keys */ |
| 444 | for (i = 0; i < ORINOCO_MAX_KEYS; i++) { |
| 445 | err = hermes_write_ltv(hw, USER_BAP, |
| 446 | HERMES_RID_CNFDEFAULTKEY0 + i, |
| 447 | HERMES_BYTES_TO_RECLEN(keylen), |
| 448 | priv->keys[i].data); |
| 449 | if (err) |
| 450 | return err; |
| 451 | } |
| 452 | |
| 453 | /* Write the index of the key used in transmission */ |
| 454 | err = hermes_write_wordrec(hw, USER_BAP, |
| 455 | HERMES_RID_CNFWEPDEFAULTKEYID, |
| 456 | priv->tx_key); |
| 457 | if (err) |
| 458 | return err; |
| 459 | } |
| 460 | break; |
| 461 | } |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | int __orinoco_hw_setup_enc(struct orinoco_private *priv) |
| 467 | { |
| 468 | hermes_t *hw = &priv->hw; |
| 469 | int err = 0; |
| 470 | int master_wep_flag; |
| 471 | int auth_flag; |
| 472 | int enc_flag; |
| 473 | |
| 474 | /* Setup WEP keys for WEP and WPA */ |
| 475 | if (priv->encode_alg) |
| 476 | __orinoco_hw_setup_wepkeys(priv); |
| 477 | |
| 478 | if (priv->wep_restrict) |
| 479 | auth_flag = HERMES_AUTH_SHARED_KEY; |
| 480 | else |
| 481 | auth_flag = HERMES_AUTH_OPEN; |
| 482 | |
| 483 | if (priv->wpa_enabled) |
| 484 | enc_flag = 2; |
| 485 | else if (priv->encode_alg == IW_ENCODE_ALG_WEP) |
| 486 | enc_flag = 1; |
| 487 | else |
| 488 | enc_flag = 0; |
| 489 | |
| 490 | switch (priv->firmware_type) { |
| 491 | case FIRMWARE_TYPE_AGERE: /* Agere style WEP */ |
| 492 | if (priv->encode_alg == IW_ENCODE_ALG_WEP) { |
| 493 | /* Enable the shared-key authentication. */ |
| 494 | err = hermes_write_wordrec(hw, USER_BAP, |
| 495 | HERMES_RID_CNFAUTHENTICATION_AGERE, |
| 496 | auth_flag); |
| 497 | } |
| 498 | err = hermes_write_wordrec(hw, USER_BAP, |
| 499 | HERMES_RID_CNFWEPENABLED_AGERE, |
| 500 | enc_flag); |
| 501 | if (err) |
| 502 | return err; |
| 503 | |
| 504 | if (priv->has_wpa) { |
| 505 | /* Set WPA key management */ |
| 506 | err = hermes_write_wordrec(hw, USER_BAP, |
| 507 | HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE, |
| 508 | priv->key_mgmt); |
| 509 | if (err) |
| 510 | return err; |
| 511 | } |
| 512 | |
| 513 | break; |
| 514 | |
| 515 | case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */ |
| 516 | case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */ |
| 517 | if (priv->encode_alg == IW_ENCODE_ALG_WEP) { |
| 518 | if (priv->wep_restrict || |
| 519 | (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)) |
| 520 | master_wep_flag = HERMES_WEP_PRIVACY_INVOKED | |
| 521 | HERMES_WEP_EXCL_UNENCRYPTED; |
| 522 | else |
| 523 | master_wep_flag = HERMES_WEP_PRIVACY_INVOKED; |
| 524 | |
| 525 | err = hermes_write_wordrec(hw, USER_BAP, |
| 526 | HERMES_RID_CNFAUTHENTICATION, |
| 527 | auth_flag); |
| 528 | if (err) |
| 529 | return err; |
| 530 | } else |
| 531 | master_wep_flag = 0; |
| 532 | |
| 533 | if (priv->iw_mode == IW_MODE_MONITOR) |
| 534 | master_wep_flag |= HERMES_WEP_HOST_DECRYPT; |
| 535 | |
| 536 | /* Master WEP setting : on/off */ |
| 537 | err = hermes_write_wordrec(hw, USER_BAP, |
| 538 | HERMES_RID_CNFWEPFLAGS_INTERSIL, |
| 539 | master_wep_flag); |
| 540 | if (err) |
| 541 | return err; |
| 542 | |
| 543 | break; |
| 544 | } |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | /* key must be 32 bytes, including the tx and rx MIC keys. |
| 550 | * rsc must be 8 bytes |
| 551 | * tsc must be 8 bytes or NULL |
| 552 | */ |
| 553 | int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx, |
| 554 | u8 *key, u8 *rsc, u8 *tsc) |
| 555 | { |
| 556 | struct { |
| 557 | __le16 idx; |
| 558 | u8 rsc[IW_ENCODE_SEQ_MAX_SIZE]; |
| 559 | u8 key[TKIP_KEYLEN]; |
| 560 | u8 tx_mic[MIC_KEYLEN]; |
| 561 | u8 rx_mic[MIC_KEYLEN]; |
| 562 | u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; |
| 563 | } __attribute__ ((packed)) buf; |
| 564 | int ret; |
| 565 | int err; |
| 566 | int k; |
| 567 | u16 xmitting; |
| 568 | |
| 569 | key_idx &= 0x3; |
| 570 | |
| 571 | if (set_tx) |
| 572 | key_idx |= 0x8000; |
| 573 | |
| 574 | buf.idx = cpu_to_le16(key_idx); |
| 575 | memcpy(buf.key, key, |
| 576 | sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic)); |
| 577 | |
| 578 | if (rsc == NULL) |
| 579 | memset(buf.rsc, 0, sizeof(buf.rsc)); |
| 580 | else |
| 581 | memcpy(buf.rsc, rsc, sizeof(buf.rsc)); |
| 582 | |
| 583 | if (tsc == NULL) { |
| 584 | memset(buf.tsc, 0, sizeof(buf.tsc)); |
| 585 | buf.tsc[4] = 0x10; |
| 586 | } else { |
| 587 | memcpy(buf.tsc, tsc, sizeof(buf.tsc)); |
| 588 | } |
| 589 | |
| 590 | /* Wait upto 100ms for tx queue to empty */ |
Pavel Roskin | 91fe9ca | 2009-04-09 21:41:05 -0400 | [diff] [blame] | 591 | for (k = 100; k > 0; k--) { |
David Kilroy | 712a434 | 2009-02-04 23:05:55 +0000 | [diff] [blame] | 592 | udelay(1000); |
| 593 | ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY, |
| 594 | &xmitting); |
Pavel Roskin | 91fe9ca | 2009-04-09 21:41:05 -0400 | [diff] [blame] | 595 | if (ret || !xmitting) |
David Kilroy | 712a434 | 2009-02-04 23:05:55 +0000 | [diff] [blame] | 596 | break; |
Pavel Roskin | 91fe9ca | 2009-04-09 21:41:05 -0400 | [diff] [blame] | 597 | } |
David Kilroy | 712a434 | 2009-02-04 23:05:55 +0000 | [diff] [blame] | 598 | |
| 599 | if (k == 0) |
| 600 | ret = -ETIMEDOUT; |
| 601 | |
| 602 | err = HERMES_WRITE_RECORD(hw, USER_BAP, |
| 603 | HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE, |
| 604 | &buf); |
| 605 | |
| 606 | return ret ? ret : err; |
| 607 | } |
| 608 | |
| 609 | int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx) |
| 610 | { |
| 611 | hermes_t *hw = &priv->hw; |
| 612 | int err; |
| 613 | |
| 614 | memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx])); |
| 615 | err = hermes_write_wordrec(hw, USER_BAP, |
| 616 | HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE, |
| 617 | key_idx); |
| 618 | if (err) |
| 619 | printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n", |
| 620 | priv->ndev->name, err, key_idx); |
| 621 | return err; |
| 622 | } |
| 623 | |
| 624 | int __orinoco_hw_set_multicast_list(struct orinoco_private *priv, |
| 625 | struct dev_addr_list *mc_list, |
| 626 | int mc_count, int promisc) |
| 627 | { |
| 628 | hermes_t *hw = &priv->hw; |
| 629 | int err = 0; |
| 630 | |
| 631 | if (promisc != priv->promiscuous) { |
| 632 | err = hermes_write_wordrec(hw, USER_BAP, |
| 633 | HERMES_RID_CNFPROMISCUOUSMODE, |
| 634 | promisc); |
| 635 | if (err) { |
| 636 | printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n", |
| 637 | priv->ndev->name, err); |
| 638 | } else |
| 639 | priv->promiscuous = promisc; |
| 640 | } |
| 641 | |
| 642 | /* If we're not in promiscuous mode, then we need to set the |
| 643 | * group address if either we want to multicast, or if we were |
| 644 | * multicasting and want to stop */ |
| 645 | if (!promisc && (mc_count || priv->mc_count)) { |
| 646 | struct dev_mc_list *p = mc_list; |
| 647 | struct hermes_multicast mclist; |
| 648 | int i; |
| 649 | |
| 650 | for (i = 0; i < mc_count; i++) { |
| 651 | /* paranoia: is list shorter than mc_count? */ |
| 652 | BUG_ON(!p); |
| 653 | /* paranoia: bad address size in list? */ |
| 654 | BUG_ON(p->dmi_addrlen != ETH_ALEN); |
| 655 | |
| 656 | memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN); |
| 657 | p = p->next; |
| 658 | } |
| 659 | |
| 660 | if (p) |
| 661 | printk(KERN_WARNING "%s: Multicast list is " |
| 662 | "longer than mc_count\n", priv->ndev->name); |
| 663 | |
| 664 | err = hermes_write_ltv(hw, USER_BAP, |
| 665 | HERMES_RID_CNFGROUPADDRESSES, |
| 666 | HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN), |
| 667 | &mclist); |
| 668 | if (err) |
| 669 | printk(KERN_ERR "%s: Error %d setting multicast list.\n", |
| 670 | priv->ndev->name, err); |
| 671 | else |
| 672 | priv->mc_count = mc_count; |
| 673 | } |
| 674 | return err; |
| 675 | } |
| 676 | |
| 677 | /* Return : < 0 -> error code ; >= 0 -> length */ |
| 678 | int orinoco_hw_get_essid(struct orinoco_private *priv, int *active, |
| 679 | char buf[IW_ESSID_MAX_SIZE+1]) |
| 680 | { |
| 681 | hermes_t *hw = &priv->hw; |
| 682 | int err = 0; |
| 683 | struct hermes_idstring essidbuf; |
| 684 | char *p = (char *)(&essidbuf.val); |
| 685 | int len; |
| 686 | unsigned long flags; |
| 687 | |
| 688 | if (orinoco_lock(priv, &flags) != 0) |
| 689 | return -EBUSY; |
| 690 | |
| 691 | if (strlen(priv->desired_essid) > 0) { |
| 692 | /* We read the desired SSID from the hardware rather |
| 693 | than from priv->desired_essid, just in case the |
| 694 | firmware is allowed to change it on us. I'm not |
| 695 | sure about this */ |
| 696 | /* My guess is that the OWNSSID should always be whatever |
| 697 | * we set to the card, whereas CURRENT_SSID is the one that |
| 698 | * may change... - Jean II */ |
| 699 | u16 rid; |
| 700 | |
| 701 | *active = 1; |
| 702 | |
| 703 | rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID : |
| 704 | HERMES_RID_CNFDESIREDSSID; |
| 705 | |
| 706 | err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf), |
| 707 | NULL, &essidbuf); |
| 708 | if (err) |
| 709 | goto fail_unlock; |
| 710 | } else { |
| 711 | *active = 0; |
| 712 | |
| 713 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID, |
| 714 | sizeof(essidbuf), NULL, &essidbuf); |
| 715 | if (err) |
| 716 | goto fail_unlock; |
| 717 | } |
| 718 | |
| 719 | len = le16_to_cpu(essidbuf.len); |
| 720 | BUG_ON(len > IW_ESSID_MAX_SIZE); |
| 721 | |
| 722 | memset(buf, 0, IW_ESSID_MAX_SIZE); |
| 723 | memcpy(buf, p, len); |
| 724 | err = len; |
| 725 | |
| 726 | fail_unlock: |
| 727 | orinoco_unlock(priv, &flags); |
| 728 | |
| 729 | return err; |
| 730 | } |
| 731 | |
| 732 | int orinoco_hw_get_freq(struct orinoco_private *priv) |
| 733 | { |
| 734 | hermes_t *hw = &priv->hw; |
| 735 | int err = 0; |
| 736 | u16 channel; |
| 737 | int freq = 0; |
| 738 | unsigned long flags; |
| 739 | |
| 740 | if (orinoco_lock(priv, &flags) != 0) |
| 741 | return -EBUSY; |
| 742 | |
| 743 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, |
| 744 | &channel); |
| 745 | if (err) |
| 746 | goto out; |
| 747 | |
| 748 | /* Intersil firmware 1.3.5 returns 0 when the interface is down */ |
| 749 | if (channel == 0) { |
| 750 | err = -EBUSY; |
| 751 | goto out; |
| 752 | } |
| 753 | |
| 754 | if ((channel < 1) || (channel > NUM_CHANNELS)) { |
| 755 | printk(KERN_WARNING "%s: Channel out of range (%d)!\n", |
| 756 | priv->ndev->name, channel); |
| 757 | err = -EBUSY; |
| 758 | goto out; |
| 759 | |
| 760 | } |
| 761 | freq = ieee80211_dsss_chan_to_freq(channel); |
| 762 | |
| 763 | out: |
| 764 | orinoco_unlock(priv, &flags); |
| 765 | |
| 766 | if (err > 0) |
| 767 | err = -EBUSY; |
| 768 | return err ? err : freq; |
| 769 | } |
| 770 | |
| 771 | int orinoco_hw_get_bitratelist(struct orinoco_private *priv, |
| 772 | int *numrates, s32 *rates, int max) |
| 773 | { |
| 774 | hermes_t *hw = &priv->hw; |
| 775 | struct hermes_idstring list; |
| 776 | unsigned char *p = (unsigned char *)&list.val; |
| 777 | int err = 0; |
| 778 | int num; |
| 779 | int i; |
| 780 | unsigned long flags; |
| 781 | |
| 782 | if (orinoco_lock(priv, &flags) != 0) |
| 783 | return -EBUSY; |
| 784 | |
| 785 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES, |
| 786 | sizeof(list), NULL, &list); |
| 787 | orinoco_unlock(priv, &flags); |
| 788 | |
| 789 | if (err) |
| 790 | return err; |
| 791 | |
| 792 | num = le16_to_cpu(list.len); |
| 793 | *numrates = num; |
| 794 | num = min(num, max); |
| 795 | |
| 796 | for (i = 0; i < num; i++) |
| 797 | rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */ |
| 798 | |
| 799 | return 0; |
| 800 | } |