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