blob: 5b126542692247bb907f5e7c4bbbee58141f6ee8 [file] [log] [blame]
David Kilroy712a4342009-02-04 23:05:55 +00001/* Encapsulate basic setting changes and retrieval on Hermes hardware
2 *
3 * See copyright notice in main.c
4 */
5#include <linux/kernel.h>
David Kilroya3f47b92009-06-18 23:21:21 +01006#include <linux/device.h>
David Kilroy712a4342009-02-04 23:05:55 +00007#include <linux/if_arp.h>
8#include <linux/ieee80211.h>
9#include <linux/wireless.h>
David Kilroy5217c572009-06-18 23:21:32 +010010#include <net/cfg80211.h>
David Kilroy712a4342009-02-04 23:05:55 +000011#include "hermes.h"
12#include "hermes_rid.h"
13#include "orinoco.h"
14
15#include "hw.h"
16
David Kilroya2d1a422009-06-18 23:21:18 +010017#define SYMBOL_MAX_VER_LEN (14)
18
David Kilroy42a51b92009-06-18 23:21:20 +010019/* Symbol firmware has a bug allocating buffers larger than this */
20#define TX_NICBUF_SIZE_BUG 1585
21
David Kilroy712a4342009-02-04 23:05:55 +000022/********************************************************************/
23/* Data tables */
24/********************************************************************/
25
26/* This tables gives the actual meanings of the bitrate IDs returned
27 * by the firmware. */
28static 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 Kilroya2d1a422009-06-18 23:21:18 +010045/* Firmware version encoding */
46struct comp_id {
47 u16 id, variant, major, minor;
48} __attribute__ ((packed));
49
50static 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 Kilroya3f47b92009-06-18 23:21:21 +010060/* 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 Kilroya2d1a422009-06-18 23:21:18 +010064int determine_fw_capabilities(struct orinoco_private *priv)
65{
David Kilroya3f47b92009-06-18 23:21:21 +010066 struct device *dev = priv->dev;
David Kilroya2d1a422009-06-18 23:21:18 +010067 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 Kilroya3f47b92009-06-18 23:21:21 +010076 dev_err(dev, "Cannot read hardware identity: error %d\n",
77 err);
David Kilroya2d1a422009-06-18 23:21:18 +010078 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 Kilroya3f47b92009-06-18 23:21:21 +010085 dev_info(dev, "Hardware identity %04x:%04x:%04x:%04x\n",
86 nic_id.id, nic_id.variant, nic_id.major, nic_id.minor);
David Kilroya2d1a422009-06-18 23:21:18 +010087
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 Kilroya3f47b92009-06-18 23:21:21 +010093 dev_err(dev, "Cannot read station identity: error %d\n",
94 err);
David Kilroya2d1a422009-06-18 23:21:18 +010095 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 Kilroya3f47b92009-06-18 23:21:21 +0100102 dev_info(dev, "Station identity %04x:%04x:%04x:%04x\n",
103 sta_id.id, sta_id.variant, sta_id.major, sta_id.minor);
David Kilroya2d1a422009-06-18 23:21:18 +0100104
105 switch (sta_id.id) {
106 case 0x15:
David Kilroya3f47b92009-06-18 23:21:21 +0100107 dev_err(dev, "Primary firmware is active\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100108 return -ENODEV;
109 case 0x14b:
David Kilroya3f47b92009-06-18 23:21:21 +0100110 dev_err(dev, "Tertiary firmware is active\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100111 return -ENODEV;
112 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
113 case 0x21: /* Symbol Spectrum24 Trilogy */
114 break;
115 default:
David Kilroya3f47b92009-06-18 23:21:21 +0100116 dev_notice(dev, "Unknown station ID, please report\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100117 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 Kilroya3f47b92009-06-18 23:21:21 +0100170 dev_warn(dev, "Error %d reading Symbol firmware info. "
171 "Wildly guessing capabilities...\n", err);
David Kilroya2d1a422009-06-18 23:21:18 +0100172 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 Kilroya3f47b92009-06-18 23:21:21 +0100242 dev_notice(dev, "Intersil firmware earlier than v0.8.x"
243 " - several features not supported\n");
David Kilroya2d1a422009-06-18 23:21:18 +0100244 priv->ibss_port = 1;
245 }
246 break;
247 }
David Kilroya3f47b92009-06-18 23:21:21 +0100248 dev_info(dev, "Firmware determined as %s\n", priv->fw_name);
David Kilroya2d1a422009-06-18 23:21:18 +0100249
250 return 0;
251}
252
David Kilroye9e3d012009-06-18 23:21:19 +0100253/* Read settings from EEPROM into our private structure.
David Kilroya3f47b92009-06-18 23:21:21 +0100254 * MAC address gets dropped into callers buffer
255 * Can be called before netdev registration.
256 */
David Kilroye9e3d012009-06-18 23:21:19 +0100257int orinoco_hw_read_card_settings(struct orinoco_private *priv, u8 *dev_addr)
258{
David Kilroya3f47b92009-06-18 23:21:21 +0100259 struct device *dev = priv->dev;
David Kilroye9e3d012009-06-18 23:21:19 +0100260 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 Kilroya3f47b92009-06-18 23:21:21 +0100270 dev_warn(dev, "Failed to read MAC address!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100271 goto out;
272 }
273
David Kilroya3f47b92009-06-18 23:21:21 +0100274 dev_dbg(dev, "MAC address %pM\n", dev_addr);
David Kilroye9e3d012009-06-18 23:21:19 +0100275
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 Kilroya3f47b92009-06-18 23:21:21 +0100280 dev_err(dev, "failed to read station name\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100281 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 Kilroya3f47b92009-06-18 23:21:21 +0100290 dev_dbg(dev, "Station name \"%s\"\n", priv->nick);
David Kilroye9e3d012009-06-18 23:21:19 +0100291
292 /* Get allowed channels */
293 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
294 &priv->channel_mask);
295 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100296 dev_err(dev, "Failed to read channel list!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100297 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 Kilroya3f47b92009-06-18 23:21:21 +0100310 dev_err(dev, "Failed to read RTS threshold!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100311 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 Kilroya3f47b92009-06-18 23:21:21 +0100324 dev_err(dev, "Failed to read fragmentation settings!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100325 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 Kilroya3f47b92009-06-18 23:21:21 +0100336 dev_err(dev, "Failed to read power management "
337 "period!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100338 goto out;
339 }
340 err = hermes_read_wordrec(hw, USER_BAP,
341 HERMES_RID_CNFPMHOLDOVERDURATION,
342 &priv->pm_timeout);
343 if (err) {
David Kilroya3f47b92009-06-18 23:21:21 +0100344 dev_err(dev, "Failed to read power management "
345 "timeout!\n");
David Kilroye9e3d012009-06-18 23:21:19 +0100346 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
357out:
358 return err;
359}
360
David Kilroya3f47b92009-06-18 23:21:21 +0100361/* Can be called before netdev registration */
David Kilroy42a51b92009-06-18 23:21:20 +0100362int orinoco_hw_allocate_fid(struct orinoco_private *priv)
363{
David Kilroya3f47b92009-06-18 23:21:21 +0100364 struct device *dev = priv->dev;
David Kilroy42a51b92009-06-18 23:21:20 +0100365 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 Kilroya3f47b92009-06-18 23:21:21 +0100374 dev_warn(dev, "Firmware ALLOC bug detected "
375 "(old Symbol firmware?). Work around %s\n",
376 err ? "failed!" : "ok.");
David Kilroy42a51b92009-06-18 23:21:20 +0100377 }
378
379 return err;
380}
381
David Kilroy712a4342009-02-04 23:05:55 +0000382int 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
401void 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
David Kilroy721aa2f2009-06-18 23:21:31 +0100409int orinoco_hw_program_rids(struct orinoco_private *priv)
410{
411 struct net_device *dev = priv->ndev;
David Kilroy5217c572009-06-18 23:21:32 +0100412 struct wireless_dev *wdev = netdev_priv(dev);
David Kilroy721aa2f2009-06-18 23:21:31 +0100413 hermes_t *hw = &priv->hw;
414 int err;
415 struct hermes_idstring idbuf;
416
417 /* Set the MAC address */
418 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
419 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
420 if (err) {
421 printk(KERN_ERR "%s: Error %d setting MAC address\n",
422 dev->name, err);
423 return err;
424 }
425
426 /* Set up the link mode */
427 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
428 priv->port_type);
429 if (err) {
430 printk(KERN_ERR "%s: Error %d setting port type\n",
431 dev->name, err);
432 return err;
433 }
434 /* Set the channel/frequency */
David Kilroy5217c572009-06-18 23:21:32 +0100435 if (priv->channel != 0 && priv->iw_mode != NL80211_IFTYPE_STATION) {
David Kilroy721aa2f2009-06-18 23:21:31 +0100436 err = hermes_write_wordrec(hw, USER_BAP,
437 HERMES_RID_CNFOWNCHANNEL,
438 priv->channel);
439 if (err) {
440 printk(KERN_ERR "%s: Error %d setting channel %d\n",
441 dev->name, err, priv->channel);
442 return err;
443 }
444 }
445
446 if (priv->has_ibss) {
447 u16 createibss;
448
449 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
450 printk(KERN_WARNING "%s: This firmware requires an "
451 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
452 /* With wvlan_cs, in this case, we would crash.
453 * hopefully, this driver will behave better...
454 * Jean II */
455 createibss = 0;
456 } else {
457 createibss = priv->createibss;
458 }
459
460 err = hermes_write_wordrec(hw, USER_BAP,
461 HERMES_RID_CNFCREATEIBSS,
462 createibss);
463 if (err) {
464 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
465 dev->name, err);
466 return err;
467 }
468 }
469
470 /* Set the desired BSSID */
471 err = __orinoco_hw_set_wap(priv);
472 if (err) {
473 printk(KERN_ERR "%s: Error %d setting AP address\n",
474 dev->name, err);
475 return err;
476 }
477
478 /* Set the desired ESSID */
479 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
480 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
481 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
482 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
483 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
484 &idbuf);
485 if (err) {
486 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
487 dev->name, err);
488 return err;
489 }
490 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
491 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
492 &idbuf);
493 if (err) {
494 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
495 dev->name, err);
496 return err;
497 }
498
499 /* Set the station name */
500 idbuf.len = cpu_to_le16(strlen(priv->nick));
501 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
502 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
503 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
504 &idbuf);
505 if (err) {
506 printk(KERN_ERR "%s: Error %d setting nickname\n",
507 dev->name, err);
508 return err;
509 }
510
511 /* Set AP density */
512 if (priv->has_sensitivity) {
513 err = hermes_write_wordrec(hw, USER_BAP,
514 HERMES_RID_CNFSYSTEMSCALE,
515 priv->ap_density);
516 if (err) {
517 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
518 "Disabling sensitivity control\n",
519 dev->name, err);
520
521 priv->has_sensitivity = 0;
522 }
523 }
524
525 /* Set RTS threshold */
526 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
527 priv->rts_thresh);
528 if (err) {
529 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
530 dev->name, err);
531 return err;
532 }
533
534 /* Set fragmentation threshold or MWO robustness */
535 if (priv->has_mwo)
536 err = hermes_write_wordrec(hw, USER_BAP,
537 HERMES_RID_CNFMWOROBUST_AGERE,
538 priv->mwo_robust);
539 else
540 err = hermes_write_wordrec(hw, USER_BAP,
541 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
542 priv->frag_thresh);
543 if (err) {
544 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
545 dev->name, err);
546 return err;
547 }
548
549 /* Set bitrate */
550 err = __orinoco_hw_set_bitrate(priv);
551 if (err) {
552 printk(KERN_ERR "%s: Error %d setting bitrate\n",
553 dev->name, err);
554 return err;
555 }
556
557 /* Set power management */
558 if (priv->has_pm) {
559 err = hermes_write_wordrec(hw, USER_BAP,
560 HERMES_RID_CNFPMENABLED,
561 priv->pm_on);
562 if (err) {
563 printk(KERN_ERR "%s: Error %d setting up PM\n",
564 dev->name, err);
565 return err;
566 }
567
568 err = hermes_write_wordrec(hw, USER_BAP,
569 HERMES_RID_CNFMULTICASTRECEIVE,
570 priv->pm_mcast);
571 if (err) {
572 printk(KERN_ERR "%s: Error %d setting up PM\n",
573 dev->name, err);
574 return err;
575 }
576 err = hermes_write_wordrec(hw, USER_BAP,
577 HERMES_RID_CNFMAXSLEEPDURATION,
578 priv->pm_period);
579 if (err) {
580 printk(KERN_ERR "%s: Error %d setting up PM\n",
581 dev->name, err);
582 return err;
583 }
584 err = hermes_write_wordrec(hw, USER_BAP,
585 HERMES_RID_CNFPMHOLDOVERDURATION,
586 priv->pm_timeout);
587 if (err) {
588 printk(KERN_ERR "%s: Error %d setting up PM\n",
589 dev->name, err);
590 return err;
591 }
592 }
593
594 /* Set preamble - only for Symbol so far... */
595 if (priv->has_preamble) {
596 err = hermes_write_wordrec(hw, USER_BAP,
597 HERMES_RID_CNFPREAMBLE_SYMBOL,
598 priv->preamble);
599 if (err) {
600 printk(KERN_ERR "%s: Error %d setting preamble\n",
601 dev->name, err);
602 return err;
603 }
604 }
605
606 /* Set up encryption */
607 if (priv->has_wep || priv->has_wpa) {
608 err = __orinoco_hw_setup_enc(priv);
609 if (err) {
610 printk(KERN_ERR "%s: Error %d activating encryption\n",
611 dev->name, err);
612 return err;
613 }
614 }
615
David Kilroy5217c572009-06-18 23:21:32 +0100616 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
David Kilroy721aa2f2009-06-18 23:21:31 +0100617 /* Enable monitor mode */
618 dev->type = ARPHRD_IEEE80211;
619 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
620 HERMES_TEST_MONITOR, 0, NULL);
621 } else {
622 /* Disable monitor mode */
623 dev->type = ARPHRD_ETHER;
624 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
625 HERMES_TEST_STOP, 0, NULL);
626 }
627 if (err)
628 return err;
629
630 /* Reset promiscuity / multicast*/
631 priv->promiscuous = 0;
632 priv->mc_count = 0;
633
David Kilroy5217c572009-06-18 23:21:32 +0100634 /* Record mode change */
635 wdev->iftype = priv->iw_mode;
636
David Kilroy721aa2f2009-06-18 23:21:31 +0100637 return 0;
638}
639
David Kilroy712a4342009-02-04 23:05:55 +0000640/* Get tsc from the firmware */
641int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc)
642{
643 hermes_t *hw = &priv->hw;
644 int err = 0;
David Kilroy5c9f41e2009-08-05 21:23:28 +0100645 u8 tsc_arr[4][ORINOCO_SEQ_LEN];
David Kilroy712a4342009-02-04 23:05:55 +0000646
647 if ((key < 0) || (key > 4))
648 return -EINVAL;
649
650 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
651 sizeof(tsc_arr), NULL, &tsc_arr);
652 if (!err)
653 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
654
655 return err;
656}
657
658int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
659{
660 hermes_t *hw = &priv->hw;
661 int ratemode = priv->bitratemode;
662 int err = 0;
663
664 if (ratemode >= BITRATE_TABLE_SIZE) {
665 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
666 priv->ndev->name, ratemode);
667 return -EINVAL;
668 }
669
670 switch (priv->firmware_type) {
671 case FIRMWARE_TYPE_AGERE:
672 err = hermes_write_wordrec(hw, USER_BAP,
673 HERMES_RID_CNFTXRATECONTROL,
674 bitrate_table[ratemode].agere_txratectrl);
675 break;
676 case FIRMWARE_TYPE_INTERSIL:
677 case FIRMWARE_TYPE_SYMBOL:
678 err = hermes_write_wordrec(hw, USER_BAP,
679 HERMES_RID_CNFTXRATECONTROL,
680 bitrate_table[ratemode].intersil_txratectrl);
681 break;
682 default:
683 BUG();
684 }
685
686 return err;
687}
688
689int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate)
690{
691 hermes_t *hw = &priv->hw;
692 int i;
693 int err = 0;
694 u16 val;
695
696 err = hermes_read_wordrec(hw, USER_BAP,
697 HERMES_RID_CURRENTTXRATE, &val);
698 if (err)
699 return err;
700
701 switch (priv->firmware_type) {
702 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
703 /* Note : in Lucent firmware, the return value of
704 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
705 * and therefore is totally different from the
706 * encoding of HERMES_RID_CNFTXRATECONTROL.
707 * Don't forget that 6Mb/s is really 5.5Mb/s */
708 if (val == 6)
709 *bitrate = 5500000;
710 else
711 *bitrate = val * 1000000;
712 break;
713 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
714 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
715 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
716 if (bitrate_table[i].intersil_txratectrl == val)
717 break;
718
719 if (i >= BITRATE_TABLE_SIZE)
720 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
721 priv->ndev->name, val);
722
723 *bitrate = bitrate_table[i].bitrate * 100000;
724 break;
725 default:
726 BUG();
727 }
728
729 return err;
730}
731
732/* Set fixed AP address */
733int __orinoco_hw_set_wap(struct orinoco_private *priv)
734{
735 int roaming_flag;
736 int err = 0;
737 hermes_t *hw = &priv->hw;
738
739 switch (priv->firmware_type) {
740 case FIRMWARE_TYPE_AGERE:
741 /* not supported */
742 break;
743 case FIRMWARE_TYPE_INTERSIL:
744 if (priv->bssid_fixed)
745 roaming_flag = 2;
746 else
747 roaming_flag = 1;
748
749 err = hermes_write_wordrec(hw, USER_BAP,
750 HERMES_RID_CNFROAMINGMODE,
751 roaming_flag);
752 break;
753 case FIRMWARE_TYPE_SYMBOL:
754 err = HERMES_WRITE_RECORD(hw, USER_BAP,
755 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
756 &priv->desired_bssid);
757 break;
758 }
759 return err;
760}
761
762/* Change the WEP keys and/or the current keys. Can be called
763 * either from __orinoco_hw_setup_enc() or directly from
764 * orinoco_ioctl_setiwencode(). In the later case the association
765 * with the AP is not broken (if the firmware can handle it),
766 * which is needed for 802.1x implementations. */
767int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
768{
769 hermes_t *hw = &priv->hw;
770 int err = 0;
771
772 switch (priv->firmware_type) {
773 case FIRMWARE_TYPE_AGERE:
774 err = HERMES_WRITE_RECORD(hw, USER_BAP,
775 HERMES_RID_CNFWEPKEYS_AGERE,
776 &priv->keys);
777 if (err)
778 return err;
779 err = hermes_write_wordrec(hw, USER_BAP,
780 HERMES_RID_CNFTXKEY_AGERE,
781 priv->tx_key);
782 if (err)
783 return err;
784 break;
785 case FIRMWARE_TYPE_INTERSIL:
786 case FIRMWARE_TYPE_SYMBOL:
787 {
788 int keylen;
789 int i;
790
791 /* Force uniform key length to work around
792 * firmware bugs */
793 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
794
795 if (keylen > LARGE_KEY_SIZE) {
796 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
797 priv->ndev->name, priv->tx_key, keylen);
798 return -E2BIG;
799 }
800
801 /* Write all 4 keys */
802 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
803 err = hermes_write_ltv(hw, USER_BAP,
804 HERMES_RID_CNFDEFAULTKEY0 + i,
805 HERMES_BYTES_TO_RECLEN(keylen),
806 priv->keys[i].data);
807 if (err)
808 return err;
809 }
810
811 /* Write the index of the key used in transmission */
812 err = hermes_write_wordrec(hw, USER_BAP,
813 HERMES_RID_CNFWEPDEFAULTKEYID,
814 priv->tx_key);
815 if (err)
816 return err;
817 }
818 break;
819 }
820
821 return 0;
822}
823
824int __orinoco_hw_setup_enc(struct orinoco_private *priv)
825{
826 hermes_t *hw = &priv->hw;
827 int err = 0;
828 int master_wep_flag;
829 int auth_flag;
830 int enc_flag;
831
832 /* Setup WEP keys for WEP and WPA */
833 if (priv->encode_alg)
834 __orinoco_hw_setup_wepkeys(priv);
835
836 if (priv->wep_restrict)
837 auth_flag = HERMES_AUTH_SHARED_KEY;
838 else
839 auth_flag = HERMES_AUTH_OPEN;
840
841 if (priv->wpa_enabled)
842 enc_flag = 2;
David Kilroy5c9f41e2009-08-05 21:23:28 +0100843 else if (priv->encode_alg == ORINOCO_ALG_WEP)
David Kilroy712a4342009-02-04 23:05:55 +0000844 enc_flag = 1;
845 else
846 enc_flag = 0;
847
848 switch (priv->firmware_type) {
849 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
David Kilroy5c9f41e2009-08-05 21:23:28 +0100850 if (priv->encode_alg == ORINOCO_ALG_WEP) {
David Kilroy712a4342009-02-04 23:05:55 +0000851 /* Enable the shared-key authentication. */
852 err = hermes_write_wordrec(hw, USER_BAP,
853 HERMES_RID_CNFAUTHENTICATION_AGERE,
854 auth_flag);
855 }
856 err = hermes_write_wordrec(hw, USER_BAP,
857 HERMES_RID_CNFWEPENABLED_AGERE,
858 enc_flag);
859 if (err)
860 return err;
861
862 if (priv->has_wpa) {
863 /* Set WPA key management */
864 err = hermes_write_wordrec(hw, USER_BAP,
865 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
866 priv->key_mgmt);
867 if (err)
868 return err;
869 }
870
871 break;
872
873 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
874 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
David Kilroy5c9f41e2009-08-05 21:23:28 +0100875 if (priv->encode_alg == ORINOCO_ALG_WEP) {
David Kilroy712a4342009-02-04 23:05:55 +0000876 if (priv->wep_restrict ||
877 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
878 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
879 HERMES_WEP_EXCL_UNENCRYPTED;
880 else
881 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
882
883 err = hermes_write_wordrec(hw, USER_BAP,
884 HERMES_RID_CNFAUTHENTICATION,
885 auth_flag);
886 if (err)
887 return err;
888 } else
889 master_wep_flag = 0;
890
David Kilroy5217c572009-06-18 23:21:32 +0100891 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
David Kilroy712a4342009-02-04 23:05:55 +0000892 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
893
894 /* Master WEP setting : on/off */
895 err = hermes_write_wordrec(hw, USER_BAP,
896 HERMES_RID_CNFWEPFLAGS_INTERSIL,
897 master_wep_flag);
898 if (err)
899 return err;
900
901 break;
902 }
903
904 return 0;
905}
906
907/* key must be 32 bytes, including the tx and rx MIC keys.
David Kilroy16e15842009-08-05 21:23:29 +0100908 * rsc must be NULL or up to 8 bytes
909 * tsc must be NULL or up to 8 bytes
David Kilroy712a4342009-02-04 23:05:55 +0000910 */
David Kilroy98e5f402009-06-18 23:21:25 +0100911int __orinoco_hw_set_tkip_key(struct orinoco_private *priv, int key_idx,
David Kilroy16e15842009-08-05 21:23:29 +0100912 int set_tx, u8 *key, u8 *rsc, size_t rsc_len,
913 u8 *tsc, size_t tsc_len)
David Kilroy712a4342009-02-04 23:05:55 +0000914{
915 struct {
916 __le16 idx;
David Kilroy5c9f41e2009-08-05 21:23:28 +0100917 u8 rsc[ORINOCO_SEQ_LEN];
David Kilroy712a4342009-02-04 23:05:55 +0000918 u8 key[TKIP_KEYLEN];
919 u8 tx_mic[MIC_KEYLEN];
920 u8 rx_mic[MIC_KEYLEN];
David Kilroy5c9f41e2009-08-05 21:23:28 +0100921 u8 tsc[ORINOCO_SEQ_LEN];
David Kilroy712a4342009-02-04 23:05:55 +0000922 } __attribute__ ((packed)) buf;
David Kilroy98e5f402009-06-18 23:21:25 +0100923 hermes_t *hw = &priv->hw;
David Kilroy712a4342009-02-04 23:05:55 +0000924 int ret;
925 int err;
926 int k;
927 u16 xmitting;
928
929 key_idx &= 0x3;
930
931 if (set_tx)
932 key_idx |= 0x8000;
933
934 buf.idx = cpu_to_le16(key_idx);
935 memcpy(buf.key, key,
936 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
937
David Kilroy16e15842009-08-05 21:23:29 +0100938 if (rsc_len > sizeof(buf.rsc))
939 rsc_len = sizeof(buf.rsc);
David Kilroy712a4342009-02-04 23:05:55 +0000940
David Kilroy16e15842009-08-05 21:23:29 +0100941 if (tsc_len > sizeof(buf.tsc))
942 tsc_len = sizeof(buf.tsc);
943
944 memset(buf.rsc, 0, sizeof(buf.rsc));
945 memset(buf.tsc, 0, sizeof(buf.tsc));
946
947 if (rsc != NULL)
948 memcpy(buf.rsc, rsc, rsc_len);
949
950 if (tsc != NULL)
951 memcpy(buf.tsc, tsc, tsc_len);
952 else
David Kilroy712a4342009-02-04 23:05:55 +0000953 buf.tsc[4] = 0x10;
David Kilroy712a4342009-02-04 23:05:55 +0000954
955 /* Wait upto 100ms for tx queue to empty */
Pavel Roskin91fe9ca2009-04-09 21:41:05 -0400956 for (k = 100; k > 0; k--) {
David Kilroy712a4342009-02-04 23:05:55 +0000957 udelay(1000);
958 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
959 &xmitting);
Pavel Roskin91fe9ca2009-04-09 21:41:05 -0400960 if (ret || !xmitting)
David Kilroy712a4342009-02-04 23:05:55 +0000961 break;
Pavel Roskin91fe9ca2009-04-09 21:41:05 -0400962 }
David Kilroy712a4342009-02-04 23:05:55 +0000963
964 if (k == 0)
965 ret = -ETIMEDOUT;
966
967 err = HERMES_WRITE_RECORD(hw, USER_BAP,
968 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
969 &buf);
970
971 return ret ? ret : err;
972}
973
974int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx)
975{
976 hermes_t *hw = &priv->hw;
977 int err;
978
979 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
980 err = hermes_write_wordrec(hw, USER_BAP,
981 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
982 key_idx);
983 if (err)
984 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
985 priv->ndev->name, err, key_idx);
986 return err;
987}
988
989int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
990 struct dev_addr_list *mc_list,
991 int mc_count, int promisc)
992{
993 hermes_t *hw = &priv->hw;
994 int err = 0;
995
996 if (promisc != priv->promiscuous) {
997 err = hermes_write_wordrec(hw, USER_BAP,
998 HERMES_RID_CNFPROMISCUOUSMODE,
999 promisc);
1000 if (err) {
1001 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1002 priv->ndev->name, err);
1003 } else
1004 priv->promiscuous = promisc;
1005 }
1006
1007 /* If we're not in promiscuous mode, then we need to set the
1008 * group address if either we want to multicast, or if we were
1009 * multicasting and want to stop */
1010 if (!promisc && (mc_count || priv->mc_count)) {
1011 struct dev_mc_list *p = mc_list;
1012 struct hermes_multicast mclist;
1013 int i;
1014
1015 for (i = 0; i < mc_count; i++) {
1016 /* paranoia: is list shorter than mc_count? */
1017 BUG_ON(!p);
1018 /* paranoia: bad address size in list? */
1019 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1020
1021 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1022 p = p->next;
1023 }
1024
1025 if (p)
1026 printk(KERN_WARNING "%s: Multicast list is "
1027 "longer than mc_count\n", priv->ndev->name);
1028
1029 err = hermes_write_ltv(hw, USER_BAP,
1030 HERMES_RID_CNFGROUPADDRESSES,
1031 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
1032 &mclist);
1033 if (err)
1034 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1035 priv->ndev->name, err);
1036 else
1037 priv->mc_count = mc_count;
1038 }
1039 return err;
1040}
1041
1042/* Return : < 0 -> error code ; >= 0 -> length */
1043int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
1044 char buf[IW_ESSID_MAX_SIZE+1])
1045{
1046 hermes_t *hw = &priv->hw;
1047 int err = 0;
1048 struct hermes_idstring essidbuf;
1049 char *p = (char *)(&essidbuf.val);
1050 int len;
1051 unsigned long flags;
1052
1053 if (orinoco_lock(priv, &flags) != 0)
1054 return -EBUSY;
1055
1056 if (strlen(priv->desired_essid) > 0) {
1057 /* We read the desired SSID from the hardware rather
1058 than from priv->desired_essid, just in case the
1059 firmware is allowed to change it on us. I'm not
1060 sure about this */
1061 /* My guess is that the OWNSSID should always be whatever
1062 * we set to the card, whereas CURRENT_SSID is the one that
1063 * may change... - Jean II */
1064 u16 rid;
1065
1066 *active = 1;
1067
1068 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
1069 HERMES_RID_CNFDESIREDSSID;
1070
1071 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
1072 NULL, &essidbuf);
1073 if (err)
1074 goto fail_unlock;
1075 } else {
1076 *active = 0;
1077
1078 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
1079 sizeof(essidbuf), NULL, &essidbuf);
1080 if (err)
1081 goto fail_unlock;
1082 }
1083
1084 len = le16_to_cpu(essidbuf.len);
1085 BUG_ON(len > IW_ESSID_MAX_SIZE);
1086
1087 memset(buf, 0, IW_ESSID_MAX_SIZE);
1088 memcpy(buf, p, len);
1089 err = len;
1090
1091 fail_unlock:
1092 orinoco_unlock(priv, &flags);
1093
1094 return err;
1095}
1096
1097int orinoco_hw_get_freq(struct orinoco_private *priv)
1098{
1099 hermes_t *hw = &priv->hw;
1100 int err = 0;
1101 u16 channel;
1102 int freq = 0;
1103 unsigned long flags;
1104
1105 if (orinoco_lock(priv, &flags) != 0)
1106 return -EBUSY;
1107
1108 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
1109 &channel);
1110 if (err)
1111 goto out;
1112
1113 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
1114 if (channel == 0) {
1115 err = -EBUSY;
1116 goto out;
1117 }
1118
1119 if ((channel < 1) || (channel > NUM_CHANNELS)) {
1120 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
1121 priv->ndev->name, channel);
1122 err = -EBUSY;
1123 goto out;
1124
1125 }
1126 freq = ieee80211_dsss_chan_to_freq(channel);
1127
1128 out:
1129 orinoco_unlock(priv, &flags);
1130
1131 if (err > 0)
1132 err = -EBUSY;
1133 return err ? err : freq;
1134}
1135
1136int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
1137 int *numrates, s32 *rates, int max)
1138{
1139 hermes_t *hw = &priv->hw;
1140 struct hermes_idstring list;
1141 unsigned char *p = (unsigned char *)&list.val;
1142 int err = 0;
1143 int num;
1144 int i;
1145 unsigned long flags;
1146
1147 if (orinoco_lock(priv, &flags) != 0)
1148 return -EBUSY;
1149
1150 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
1151 sizeof(list), NULL, &list);
1152 orinoco_unlock(priv, &flags);
1153
1154 if (err)
1155 return err;
1156
1157 num = le16_to_cpu(list.len);
1158 *numrates = num;
1159 num = min(num, max);
1160
1161 for (i = 0; i < num; i++)
1162 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
1163
1164 return 0;
1165}
David Kilroyc63cdbe2009-06-18 23:21:33 +01001166
1167int orinoco_hw_trigger_scan(struct orinoco_private *priv,
1168 const struct cfg80211_ssid *ssid)
1169{
1170 struct net_device *dev = priv->ndev;
1171 hermes_t *hw = &priv->hw;
1172 unsigned long flags;
1173 int err = 0;
1174
1175 if (orinoco_lock(priv, &flags) != 0)
1176 return -EBUSY;
1177
1178 /* Scanning with port 0 disabled would fail */
1179 if (!netif_running(dev)) {
1180 err = -ENETDOWN;
1181 goto out;
1182 }
1183
1184 /* In monitor mode, the scan results are always empty.
1185 * Probe responses are passed to the driver as received
1186 * frames and could be processed in software. */
1187 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
1188 err = -EOPNOTSUPP;
1189 goto out;
1190 }
1191
1192 if (priv->has_hostscan) {
1193 switch (priv->firmware_type) {
1194 case FIRMWARE_TYPE_SYMBOL:
1195 err = hermes_write_wordrec(hw, USER_BAP,
1196 HERMES_RID_CNFHOSTSCAN_SYMBOL,
1197 HERMES_HOSTSCAN_SYMBOL_ONCE |
1198 HERMES_HOSTSCAN_SYMBOL_BCAST);
1199 break;
1200 case FIRMWARE_TYPE_INTERSIL: {
1201 __le16 req[3];
1202
1203 req[0] = cpu_to_le16(0x3fff); /* All channels */
1204 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
1205 req[2] = 0; /* Any ESSID */
1206 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1207 HERMES_RID_CNFHOSTSCAN, &req);
1208 break;
1209 }
1210 case FIRMWARE_TYPE_AGERE:
1211 if (ssid->ssid_len > 0) {
1212 struct hermes_idstring idbuf;
1213 size_t len = ssid->ssid_len;
1214
1215 idbuf.len = cpu_to_le16(len);
1216 memcpy(idbuf.val, ssid->ssid, len);
1217
1218 err = hermes_write_ltv(hw, USER_BAP,
1219 HERMES_RID_CNFSCANSSID_AGERE,
1220 HERMES_BYTES_TO_RECLEN(len + 2),
1221 &idbuf);
1222 } else
1223 err = hermes_write_wordrec(hw, USER_BAP,
1224 HERMES_RID_CNFSCANSSID_AGERE,
1225 0); /* Any ESSID */
1226 if (err)
1227 break;
1228
1229 if (priv->has_ext_scan) {
1230 err = hermes_write_wordrec(hw, USER_BAP,
1231 HERMES_RID_CNFSCANCHANNELS2GHZ,
1232 0x7FFF);
1233 if (err)
1234 goto out;
1235
1236 err = hermes_inquire(hw,
1237 HERMES_INQ_CHANNELINFO);
1238 } else
1239 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1240
1241 break;
1242 }
1243 } else
1244 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1245
1246 out:
1247 orinoco_unlock(priv, &flags);
1248
1249 return err;
1250}
David Kilroy07542d02009-08-05 21:23:30 +01001251
1252/* Disassociate from node with BSSID addr */
1253int orinoco_hw_disassociate(struct orinoco_private *priv,
1254 u8 *addr, u16 reason_code)
1255{
1256 hermes_t *hw = &priv->hw;
1257 int err;
1258
1259 struct {
1260 u8 addr[ETH_ALEN];
1261 __le16 reason_code;
1262 } __attribute__ ((packed)) buf;
1263
1264 /* Currently only supported by WPA enabled Agere fw */
1265 if (!priv->has_wpa)
1266 return -EOPNOTSUPP;
1267
1268 memcpy(buf.addr, addr, ETH_ALEN);
1269 buf.reason_code = cpu_to_le16(reason_code);
1270 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1271 HERMES_RID_CNFDISASSOCIATE,
1272 &buf);
1273 return err;
1274}
David Kilroy2b260352009-08-05 21:23:31 +01001275
1276int orinoco_hw_get_current_bssid(struct orinoco_private *priv,
1277 u8 *addr)
1278{
1279 hermes_t *hw = &priv->hw;
1280 int err;
1281
1282 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1283 ETH_ALEN, NULL, addr);
1284
1285 return err;
1286}