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