883b8f86862692e7e876ae0aaca3c92694522187
[deliverable/linux.git] / drivers / net / wireless / orinoco / hw.c
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/device.h>
7 #include <linux/if_arp.h>
8 #include <linux/ieee80211.h>
9 #include <linux/wireless.h>
10 #include <net/cfg80211.h>
11 #include "hermes.h"
12 #include "hermes_rid.h"
13 #include "orinoco.h"
14
15 #include "hw.h"
16
17 #define SYMBOL_MAX_VER_LEN (14)
18
19 /* Symbol firmware has a bug allocating buffers larger than this */
20 #define TX_NICBUF_SIZE_BUG 1585
21
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
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
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 *
64 * If non-NULL stores a firmware description in fw_name.
65 * If non-NULL stores a HW version in hw_ver
66 *
67 * These are output via generic cfg80211 ethtool support.
68 */
69 int determine_fw_capabilities(struct orinoco_private *priv,
70 char *fw_name, size_t fw_name_len,
71 u32 *hw_ver)
72 {
73 struct device *dev = priv->dev;
74 hermes_t *hw = &priv->hw;
75 int err;
76 struct comp_id nic_id, sta_id;
77 unsigned int firmver;
78 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
79
80 /* Get the hardware version */
81 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
82 if (err) {
83 dev_err(dev, "Cannot read hardware identity: error %d\n",
84 err);
85 return err;
86 }
87
88 le16_to_cpus(&nic_id.id);
89 le16_to_cpus(&nic_id.variant);
90 le16_to_cpus(&nic_id.major);
91 le16_to_cpus(&nic_id.minor);
92 dev_info(dev, "Hardware identity %04x:%04x:%04x:%04x\n",
93 nic_id.id, nic_id.variant, nic_id.major, nic_id.minor);
94
95 if (hw_ver)
96 *hw_ver = (((nic_id.id & 0xff) << 24) |
97 ((nic_id.variant & 0xff) << 16) |
98 ((nic_id.major & 0xff) << 8) |
99 (nic_id.minor & 0xff));
100
101 priv->firmware_type = determine_firmware_type(&nic_id);
102
103 /* Get the firmware version */
104 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
105 if (err) {
106 dev_err(dev, "Cannot read station identity: error %d\n",
107 err);
108 return err;
109 }
110
111 le16_to_cpus(&sta_id.id);
112 le16_to_cpus(&sta_id.variant);
113 le16_to_cpus(&sta_id.major);
114 le16_to_cpus(&sta_id.minor);
115 dev_info(dev, "Station identity %04x:%04x:%04x:%04x\n",
116 sta_id.id, sta_id.variant, sta_id.major, sta_id.minor);
117
118 switch (sta_id.id) {
119 case 0x15:
120 dev_err(dev, "Primary firmware is active\n");
121 return -ENODEV;
122 case 0x14b:
123 dev_err(dev, "Tertiary firmware is active\n");
124 return -ENODEV;
125 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
126 case 0x21: /* Symbol Spectrum24 Trilogy */
127 break;
128 default:
129 dev_notice(dev, "Unknown station ID, please report\n");
130 break;
131 }
132
133 /* Default capabilities */
134 priv->has_sensitivity = 1;
135 priv->has_mwo = 0;
136 priv->has_preamble = 0;
137 priv->has_port3 = 1;
138 priv->has_ibss = 1;
139 priv->has_wep = 0;
140 priv->has_big_wep = 0;
141 priv->has_alt_txcntl = 0;
142 priv->has_ext_scan = 0;
143 priv->has_wpa = 0;
144 priv->do_fw_download = 0;
145
146 /* Determine capabilities from the firmware version */
147 switch (priv->firmware_type) {
148 case FIRMWARE_TYPE_AGERE:
149 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
150 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
151 if (fw_name)
152 snprintf(fw_name, fw_name_len, "Lucent/Agere %d.%02d",
153 sta_id.major, sta_id.minor);
154
155 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
156
157 priv->has_ibss = (firmver >= 0x60006);
158 priv->has_wep = (firmver >= 0x40020);
159 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
160 Gold cards from the others? */
161 priv->has_mwo = (firmver >= 0x60000);
162 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
163 priv->ibss_port = 1;
164 priv->has_hostscan = (firmver >= 0x8000a);
165 priv->do_fw_download = 1;
166 priv->broken_monitor = (firmver >= 0x80000);
167 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
168 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
169 priv->has_wpa = (firmver >= 0x9002a);
170 /* Tested with Agere firmware :
171 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
172 * Tested CableTron firmware : 4.32 => Anton */
173 break;
174 case FIRMWARE_TYPE_SYMBOL:
175 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
176 /* Intel MAC : 00:02:B3:* */
177 /* 3Com MAC : 00:50:DA:* */
178 memset(tmp, 0, sizeof(tmp));
179 /* Get the Symbol firmware version */
180 err = hermes_read_ltv(hw, USER_BAP,
181 HERMES_RID_SECONDARYVERSION_SYMBOL,
182 SYMBOL_MAX_VER_LEN, NULL, &tmp);
183 if (err) {
184 dev_warn(dev, "Error %d reading Symbol firmware info. "
185 "Wildly guessing capabilities...\n", err);
186 firmver = 0;
187 tmp[0] = '\0';
188 } else {
189 /* The firmware revision is a string, the format is
190 * something like : "V2.20-01".
191 * Quick and dirty parsing... - Jean II
192 */
193 firmver = ((tmp[1] - '0') << 16)
194 | ((tmp[3] - '0') << 12)
195 | ((tmp[4] - '0') << 8)
196 | ((tmp[6] - '0') << 4)
197 | (tmp[7] - '0');
198
199 tmp[SYMBOL_MAX_VER_LEN] = '\0';
200 }
201
202 if (fw_name)
203 snprintf(fw_name, fw_name_len, "Symbol %s", tmp);
204
205 priv->has_ibss = (firmver >= 0x20000);
206 priv->has_wep = (firmver >= 0x15012);
207 priv->has_big_wep = (firmver >= 0x20000);
208 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
209 (firmver >= 0x29000 && firmver < 0x30000) ||
210 firmver >= 0x31000;
211 priv->has_preamble = (firmver >= 0x20000);
212 priv->ibss_port = 4;
213
214 /* Symbol firmware is found on various cards, but
215 * there has been no attempt to check firmware
216 * download on non-spectrum_cs based cards.
217 *
218 * Given that the Agere firmware download works
219 * differently, we should avoid doing a firmware
220 * download with the Symbol algorithm on non-spectrum
221 * cards.
222 *
223 * For now we can identify a spectrum_cs based card
224 * because it has a firmware reset function.
225 */
226 priv->do_fw_download = (priv->stop_fw != NULL);
227
228 priv->broken_disableport = (firmver == 0x25013) ||
229 (firmver >= 0x30000 && firmver <= 0x31000);
230 priv->has_hostscan = (firmver >= 0x31001) ||
231 (firmver >= 0x29057 && firmver < 0x30000);
232 /* Tested with Intel firmware : 0x20015 => Jean II */
233 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
234 break;
235 case FIRMWARE_TYPE_INTERSIL:
236 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
237 * Samsung, Compaq 100/200 and Proxim are slightly
238 * different and less well tested */
239 /* D-Link MAC : 00:40:05:* */
240 /* Addtron MAC : 00:90:D1:* */
241 if (fw_name)
242 snprintf(fw_name, fw_name_len, "Intersil %d.%d.%d",
243 sta_id.major, sta_id.minor, sta_id.variant);
244
245 firmver = ((unsigned long)sta_id.major << 16) |
246 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
247
248 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
249 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
250 priv->has_pm = (firmver >= 0x000700);
251 priv->has_hostscan = (firmver >= 0x010301);
252
253 if (firmver >= 0x000800)
254 priv->ibss_port = 0;
255 else {
256 dev_notice(dev, "Intersil firmware earlier than v0.8.x"
257 " - several features not supported\n");
258 priv->ibss_port = 1;
259 }
260 break;
261 }
262 if (fw_name)
263 dev_info(dev, "Firmware determined as %s\n", fw_name);
264
265 #ifndef CONFIG_HERMES_PRISM
266 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
267 dev_err(dev, "Support for Prism chipset is not enabled\n");
268 return -ENODEV;
269 }
270 #endif
271
272 return 0;
273 }
274
275 /* Read settings from EEPROM into our private structure.
276 * MAC address gets dropped into callers buffer
277 * Can be called before netdev registration.
278 */
279 int orinoco_hw_read_card_settings(struct orinoco_private *priv, u8 *dev_addr)
280 {
281 struct device *dev = priv->dev;
282 struct hermes_idstring nickbuf;
283 hermes_t *hw = &priv->hw;
284 int len;
285 int err;
286 u16 reclen;
287
288 /* Get the MAC address */
289 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
290 ETH_ALEN, NULL, dev_addr);
291 if (err) {
292 dev_warn(dev, "Failed to read MAC address!\n");
293 goto out;
294 }
295
296 dev_dbg(dev, "MAC address %pM\n", dev_addr);
297
298 /* Get the station name */
299 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
300 sizeof(nickbuf), &reclen, &nickbuf);
301 if (err) {
302 dev_err(dev, "failed to read station name\n");
303 goto out;
304 }
305 if (nickbuf.len)
306 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
307 else
308 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
309 memcpy(priv->nick, &nickbuf.val, len);
310 priv->nick[len] = '\0';
311
312 dev_dbg(dev, "Station name \"%s\"\n", priv->nick);
313
314 /* Get allowed channels */
315 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
316 &priv->channel_mask);
317 if (err) {
318 dev_err(dev, "Failed to read channel list!\n");
319 goto out;
320 }
321
322 /* Get initial AP density */
323 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
324 &priv->ap_density);
325 if (err || priv->ap_density < 1 || priv->ap_density > 3)
326 priv->has_sensitivity = 0;
327
328 /* Get initial RTS threshold */
329 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
330 &priv->rts_thresh);
331 if (err) {
332 dev_err(dev, "Failed to read RTS threshold!\n");
333 goto out;
334 }
335
336 /* Get initial fragmentation settings */
337 if (priv->has_mwo)
338 err = hermes_read_wordrec(hw, USER_BAP,
339 HERMES_RID_CNFMWOROBUST_AGERE,
340 &priv->mwo_robust);
341 else
342 err = hermes_read_wordrec(hw, USER_BAP,
343 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
344 &priv->frag_thresh);
345 if (err) {
346 dev_err(dev, "Failed to read fragmentation settings!\n");
347 goto out;
348 }
349
350 /* Power management setup */
351 if (priv->has_pm) {
352 priv->pm_on = 0;
353 priv->pm_mcast = 1;
354 err = hermes_read_wordrec(hw, USER_BAP,
355 HERMES_RID_CNFMAXSLEEPDURATION,
356 &priv->pm_period);
357 if (err) {
358 dev_err(dev, "Failed to read power management "
359 "period!\n");
360 goto out;
361 }
362 err = hermes_read_wordrec(hw, USER_BAP,
363 HERMES_RID_CNFPMHOLDOVERDURATION,
364 &priv->pm_timeout);
365 if (err) {
366 dev_err(dev, "Failed to read power management "
367 "timeout!\n");
368 goto out;
369 }
370 }
371
372 /* Preamble setup */
373 if (priv->has_preamble) {
374 err = hermes_read_wordrec(hw, USER_BAP,
375 HERMES_RID_CNFPREAMBLE_SYMBOL,
376 &priv->preamble);
377 }
378
379 out:
380 return err;
381 }
382
383 /* Can be called before netdev registration */
384 int orinoco_hw_allocate_fid(struct orinoco_private *priv)
385 {
386 struct device *dev = priv->dev;
387 struct hermes *hw = &priv->hw;
388 int err;
389
390 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
391 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
392 /* Try workaround for old Symbol firmware bug */
393 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
394 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
395
396 dev_warn(dev, "Firmware ALLOC bug detected "
397 "(old Symbol firmware?). Work around %s\n",
398 err ? "failed!" : "ok.");
399 }
400
401 return err;
402 }
403
404 int orinoco_get_bitratemode(int bitrate, int automatic)
405 {
406 int ratemode = -1;
407 int i;
408
409 if ((bitrate != 10) && (bitrate != 20) &&
410 (bitrate != 55) && (bitrate != 110))
411 return ratemode;
412
413 for (i = 0; i < BITRATE_TABLE_SIZE; i++) {
414 if ((bitrate_table[i].bitrate == bitrate) &&
415 (bitrate_table[i].automatic == automatic)) {
416 ratemode = i;
417 break;
418 }
419 }
420 return ratemode;
421 }
422
423 void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
424 {
425 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
426
427 *bitrate = bitrate_table[ratemode].bitrate * 100000;
428 *automatic = bitrate_table[ratemode].automatic;
429 }
430
431 int orinoco_hw_program_rids(struct orinoco_private *priv)
432 {
433 struct net_device *dev = priv->ndev;
434 struct wireless_dev *wdev = netdev_priv(dev);
435 hermes_t *hw = &priv->hw;
436 int err;
437 struct hermes_idstring idbuf;
438
439 /* Set the MAC address */
440 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
441 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
442 if (err) {
443 printk(KERN_ERR "%s: Error %d setting MAC address\n",
444 dev->name, err);
445 return err;
446 }
447
448 /* Set up the link mode */
449 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
450 priv->port_type);
451 if (err) {
452 printk(KERN_ERR "%s: Error %d setting port type\n",
453 dev->name, err);
454 return err;
455 }
456 /* Set the channel/frequency */
457 if (priv->channel != 0 && priv->iw_mode != NL80211_IFTYPE_STATION) {
458 err = hermes_write_wordrec(hw, USER_BAP,
459 HERMES_RID_CNFOWNCHANNEL,
460 priv->channel);
461 if (err) {
462 printk(KERN_ERR "%s: Error %d setting channel %d\n",
463 dev->name, err, priv->channel);
464 return err;
465 }
466 }
467
468 if (priv->has_ibss) {
469 u16 createibss;
470
471 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
472 printk(KERN_WARNING "%s: This firmware requires an "
473 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
474 /* With wvlan_cs, in this case, we would crash.
475 * hopefully, this driver will behave better...
476 * Jean II */
477 createibss = 0;
478 } else {
479 createibss = priv->createibss;
480 }
481
482 err = hermes_write_wordrec(hw, USER_BAP,
483 HERMES_RID_CNFCREATEIBSS,
484 createibss);
485 if (err) {
486 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
487 dev->name, err);
488 return err;
489 }
490 }
491
492 /* Set the desired BSSID */
493 err = __orinoco_hw_set_wap(priv);
494 if (err) {
495 printk(KERN_ERR "%s: Error %d setting AP address\n",
496 dev->name, err);
497 return err;
498 }
499
500 /* Set the desired ESSID */
501 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
502 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
503 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
504 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
505 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
506 &idbuf);
507 if (err) {
508 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
509 dev->name, err);
510 return err;
511 }
512 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
513 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
514 &idbuf);
515 if (err) {
516 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
517 dev->name, err);
518 return err;
519 }
520
521 /* Set the station name */
522 idbuf.len = cpu_to_le16(strlen(priv->nick));
523 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
524 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
525 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
526 &idbuf);
527 if (err) {
528 printk(KERN_ERR "%s: Error %d setting nickname\n",
529 dev->name, err);
530 return err;
531 }
532
533 /* Set AP density */
534 if (priv->has_sensitivity) {
535 err = hermes_write_wordrec(hw, USER_BAP,
536 HERMES_RID_CNFSYSTEMSCALE,
537 priv->ap_density);
538 if (err) {
539 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
540 "Disabling sensitivity control\n",
541 dev->name, err);
542
543 priv->has_sensitivity = 0;
544 }
545 }
546
547 /* Set RTS threshold */
548 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
549 priv->rts_thresh);
550 if (err) {
551 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
552 dev->name, err);
553 return err;
554 }
555
556 /* Set fragmentation threshold or MWO robustness */
557 if (priv->has_mwo)
558 err = hermes_write_wordrec(hw, USER_BAP,
559 HERMES_RID_CNFMWOROBUST_AGERE,
560 priv->mwo_robust);
561 else
562 err = hermes_write_wordrec(hw, USER_BAP,
563 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
564 priv->frag_thresh);
565 if (err) {
566 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
567 dev->name, err);
568 return err;
569 }
570
571 /* Set bitrate */
572 err = __orinoco_hw_set_bitrate(priv);
573 if (err) {
574 printk(KERN_ERR "%s: Error %d setting bitrate\n",
575 dev->name, err);
576 return err;
577 }
578
579 /* Set power management */
580 if (priv->has_pm) {
581 err = hermes_write_wordrec(hw, USER_BAP,
582 HERMES_RID_CNFPMENABLED,
583 priv->pm_on);
584 if (err) {
585 printk(KERN_ERR "%s: Error %d setting up PM\n",
586 dev->name, err);
587 return err;
588 }
589
590 err = hermes_write_wordrec(hw, USER_BAP,
591 HERMES_RID_CNFMULTICASTRECEIVE,
592 priv->pm_mcast);
593 if (err) {
594 printk(KERN_ERR "%s: Error %d setting up PM\n",
595 dev->name, err);
596 return err;
597 }
598 err = hermes_write_wordrec(hw, USER_BAP,
599 HERMES_RID_CNFMAXSLEEPDURATION,
600 priv->pm_period);
601 if (err) {
602 printk(KERN_ERR "%s: Error %d setting up PM\n",
603 dev->name, err);
604 return err;
605 }
606 err = hermes_write_wordrec(hw, USER_BAP,
607 HERMES_RID_CNFPMHOLDOVERDURATION,
608 priv->pm_timeout);
609 if (err) {
610 printk(KERN_ERR "%s: Error %d setting up PM\n",
611 dev->name, err);
612 return err;
613 }
614 }
615
616 /* Set preamble - only for Symbol so far... */
617 if (priv->has_preamble) {
618 err = hermes_write_wordrec(hw, USER_BAP,
619 HERMES_RID_CNFPREAMBLE_SYMBOL,
620 priv->preamble);
621 if (err) {
622 printk(KERN_ERR "%s: Error %d setting preamble\n",
623 dev->name, err);
624 return err;
625 }
626 }
627
628 /* Set up encryption */
629 if (priv->has_wep || priv->has_wpa) {
630 err = __orinoco_hw_setup_enc(priv);
631 if (err) {
632 printk(KERN_ERR "%s: Error %d activating encryption\n",
633 dev->name, err);
634 return err;
635 }
636 }
637
638 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
639 /* Enable monitor mode */
640 dev->type = ARPHRD_IEEE80211;
641 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
642 HERMES_TEST_MONITOR, 0, NULL);
643 } else {
644 /* Disable monitor mode */
645 dev->type = ARPHRD_ETHER;
646 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
647 HERMES_TEST_STOP, 0, NULL);
648 }
649 if (err)
650 return err;
651
652 /* Reset promiscuity / multicast*/
653 priv->promiscuous = 0;
654 priv->mc_count = 0;
655
656 /* Record mode change */
657 wdev->iftype = priv->iw_mode;
658
659 return 0;
660 }
661
662 /* Get tsc from the firmware */
663 int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc)
664 {
665 hermes_t *hw = &priv->hw;
666 int err = 0;
667 u8 tsc_arr[4][ORINOCO_SEQ_LEN];
668
669 if ((key < 0) || (key >= 4))
670 return -EINVAL;
671
672 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
673 sizeof(tsc_arr), NULL, &tsc_arr);
674 if (!err)
675 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
676
677 return err;
678 }
679
680 int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
681 {
682 hermes_t *hw = &priv->hw;
683 int ratemode = priv->bitratemode;
684 int err = 0;
685
686 if (ratemode >= BITRATE_TABLE_SIZE) {
687 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
688 priv->ndev->name, ratemode);
689 return -EINVAL;
690 }
691
692 switch (priv->firmware_type) {
693 case FIRMWARE_TYPE_AGERE:
694 err = hermes_write_wordrec(hw, USER_BAP,
695 HERMES_RID_CNFTXRATECONTROL,
696 bitrate_table[ratemode].agere_txratectrl);
697 break;
698 case FIRMWARE_TYPE_INTERSIL:
699 case FIRMWARE_TYPE_SYMBOL:
700 err = hermes_write_wordrec(hw, USER_BAP,
701 HERMES_RID_CNFTXRATECONTROL,
702 bitrate_table[ratemode].intersil_txratectrl);
703 break;
704 default:
705 BUG();
706 }
707
708 return err;
709 }
710
711 int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate)
712 {
713 hermes_t *hw = &priv->hw;
714 int i;
715 int err = 0;
716 u16 val;
717
718 err = hermes_read_wordrec(hw, USER_BAP,
719 HERMES_RID_CURRENTTXRATE, &val);
720 if (err)
721 return err;
722
723 switch (priv->firmware_type) {
724 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
725 /* Note : in Lucent firmware, the return value of
726 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
727 * and therefore is totally different from the
728 * encoding of HERMES_RID_CNFTXRATECONTROL.
729 * Don't forget that 6Mb/s is really 5.5Mb/s */
730 if (val == 6)
731 *bitrate = 5500000;
732 else
733 *bitrate = val * 1000000;
734 break;
735 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
736 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
737 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
738 if (bitrate_table[i].intersil_txratectrl == val)
739 break;
740
741 if (i >= BITRATE_TABLE_SIZE)
742 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
743 priv->ndev->name, val);
744
745 *bitrate = bitrate_table[i].bitrate * 100000;
746 break;
747 default:
748 BUG();
749 }
750
751 return err;
752 }
753
754 /* Set fixed AP address */
755 int __orinoco_hw_set_wap(struct orinoco_private *priv)
756 {
757 int roaming_flag;
758 int err = 0;
759 hermes_t *hw = &priv->hw;
760
761 switch (priv->firmware_type) {
762 case FIRMWARE_TYPE_AGERE:
763 /* not supported */
764 break;
765 case FIRMWARE_TYPE_INTERSIL:
766 if (priv->bssid_fixed)
767 roaming_flag = 2;
768 else
769 roaming_flag = 1;
770
771 err = hermes_write_wordrec(hw, USER_BAP,
772 HERMES_RID_CNFROAMINGMODE,
773 roaming_flag);
774 break;
775 case FIRMWARE_TYPE_SYMBOL:
776 err = HERMES_WRITE_RECORD(hw, USER_BAP,
777 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
778 &priv->desired_bssid);
779 break;
780 }
781 return err;
782 }
783
784 /* Change the WEP keys and/or the current keys. Can be called
785 * either from __orinoco_hw_setup_enc() or directly from
786 * orinoco_ioctl_setiwencode(). In the later case the association
787 * with the AP is not broken (if the firmware can handle it),
788 * which is needed for 802.1x implementations. */
789 int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
790 {
791 hermes_t *hw = &priv->hw;
792 int err = 0;
793 int i;
794
795 switch (priv->firmware_type) {
796 case FIRMWARE_TYPE_AGERE:
797 {
798 struct orinoco_key keys[ORINOCO_MAX_KEYS];
799
800 memset(&keys, 0, sizeof(keys));
801 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
802 int len = min(priv->keys[i].key_len,
803 ORINOCO_MAX_KEY_SIZE);
804 memcpy(&keys[i].data, priv->keys[i].key, len);
805 if (len > SMALL_KEY_SIZE)
806 keys[i].len = cpu_to_le16(LARGE_KEY_SIZE);
807 else if (len > 0)
808 keys[i].len = cpu_to_le16(SMALL_KEY_SIZE);
809 else
810 keys[i].len = cpu_to_le16(0);
811 }
812
813 err = HERMES_WRITE_RECORD(hw, USER_BAP,
814 HERMES_RID_CNFWEPKEYS_AGERE,
815 &keys);
816 if (err)
817 return err;
818 err = hermes_write_wordrec(hw, USER_BAP,
819 HERMES_RID_CNFTXKEY_AGERE,
820 priv->tx_key);
821 if (err)
822 return err;
823 break;
824 }
825 case FIRMWARE_TYPE_INTERSIL:
826 case FIRMWARE_TYPE_SYMBOL:
827 {
828 int keylen;
829
830 /* Force uniform key length to work around
831 * firmware bugs */
832 keylen = priv->keys[priv->tx_key].key_len;
833
834 if (keylen > LARGE_KEY_SIZE) {
835 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
836 priv->ndev->name, priv->tx_key, keylen);
837 return -E2BIG;
838 } else if (keylen > SMALL_KEY_SIZE)
839 keylen = LARGE_KEY_SIZE;
840 else if (keylen > 0)
841 keylen = SMALL_KEY_SIZE;
842 else
843 keylen = 0;
844
845 /* Write all 4 keys */
846 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
847 u8 key[LARGE_KEY_SIZE] = { 0 };
848
849 memcpy(key, priv->keys[i].key,
850 priv->keys[i].key_len);
851
852 err = hermes_write_ltv(hw, USER_BAP,
853 HERMES_RID_CNFDEFAULTKEY0 + i,
854 HERMES_BYTES_TO_RECLEN(keylen),
855 key);
856 if (err)
857 return err;
858 }
859
860 /* Write the index of the key used in transmission */
861 err = hermes_write_wordrec(hw, USER_BAP,
862 HERMES_RID_CNFWEPDEFAULTKEYID,
863 priv->tx_key);
864 if (err)
865 return err;
866 }
867 break;
868 }
869
870 return 0;
871 }
872
873 int __orinoco_hw_setup_enc(struct orinoco_private *priv)
874 {
875 hermes_t *hw = &priv->hw;
876 int err = 0;
877 int master_wep_flag;
878 int auth_flag;
879 int enc_flag;
880
881 /* Setup WEP keys */
882 if (priv->encode_alg == ORINOCO_ALG_WEP)
883 __orinoco_hw_setup_wepkeys(priv);
884
885 if (priv->wep_restrict)
886 auth_flag = HERMES_AUTH_SHARED_KEY;
887 else
888 auth_flag = HERMES_AUTH_OPEN;
889
890 if (priv->wpa_enabled)
891 enc_flag = 2;
892 else if (priv->encode_alg == ORINOCO_ALG_WEP)
893 enc_flag = 1;
894 else
895 enc_flag = 0;
896
897 switch (priv->firmware_type) {
898 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
899 if (priv->encode_alg == ORINOCO_ALG_WEP) {
900 /* Enable the shared-key authentication. */
901 err = hermes_write_wordrec(hw, USER_BAP,
902 HERMES_RID_CNFAUTHENTICATION_AGERE,
903 auth_flag);
904 }
905 err = hermes_write_wordrec(hw, USER_BAP,
906 HERMES_RID_CNFWEPENABLED_AGERE,
907 enc_flag);
908 if (err)
909 return err;
910
911 if (priv->has_wpa) {
912 /* Set WPA key management */
913 err = hermes_write_wordrec(hw, USER_BAP,
914 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
915 priv->key_mgmt);
916 if (err)
917 return err;
918 }
919
920 break;
921
922 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
923 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
924 if (priv->encode_alg == ORINOCO_ALG_WEP) {
925 if (priv->wep_restrict ||
926 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
927 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
928 HERMES_WEP_EXCL_UNENCRYPTED;
929 else
930 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
931
932 err = hermes_write_wordrec(hw, USER_BAP,
933 HERMES_RID_CNFAUTHENTICATION,
934 auth_flag);
935 if (err)
936 return err;
937 } else
938 master_wep_flag = 0;
939
940 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
941 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
942
943 /* Master WEP setting : on/off */
944 err = hermes_write_wordrec(hw, USER_BAP,
945 HERMES_RID_CNFWEPFLAGS_INTERSIL,
946 master_wep_flag);
947 if (err)
948 return err;
949
950 break;
951 }
952
953 return 0;
954 }
955
956 /* key must be 32 bytes, including the tx and rx MIC keys.
957 * rsc must be NULL or up to 8 bytes
958 * tsc must be NULL or up to 8 bytes
959 */
960 int __orinoco_hw_set_tkip_key(struct orinoco_private *priv, int key_idx,
961 int set_tx, u8 *key, u8 *rsc, size_t rsc_len,
962 u8 *tsc, size_t tsc_len)
963 {
964 struct {
965 __le16 idx;
966 u8 rsc[ORINOCO_SEQ_LEN];
967 u8 key[TKIP_KEYLEN];
968 u8 tx_mic[MIC_KEYLEN];
969 u8 rx_mic[MIC_KEYLEN];
970 u8 tsc[ORINOCO_SEQ_LEN];
971 } __attribute__ ((packed)) buf;
972 hermes_t *hw = &priv->hw;
973 int ret;
974 int err;
975 int k;
976 u16 xmitting;
977
978 key_idx &= 0x3;
979
980 if (set_tx)
981 key_idx |= 0x8000;
982
983 buf.idx = cpu_to_le16(key_idx);
984 memcpy(buf.key, key,
985 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
986
987 if (rsc_len > sizeof(buf.rsc))
988 rsc_len = sizeof(buf.rsc);
989
990 if (tsc_len > sizeof(buf.tsc))
991 tsc_len = sizeof(buf.tsc);
992
993 memset(buf.rsc, 0, sizeof(buf.rsc));
994 memset(buf.tsc, 0, sizeof(buf.tsc));
995
996 if (rsc != NULL)
997 memcpy(buf.rsc, rsc, rsc_len);
998
999 if (tsc != NULL)
1000 memcpy(buf.tsc, tsc, tsc_len);
1001 else
1002 buf.tsc[4] = 0x10;
1003
1004 /* Wait upto 100ms for tx queue to empty */
1005 for (k = 100; k > 0; k--) {
1006 udelay(1000);
1007 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
1008 &xmitting);
1009 if (ret || !xmitting)
1010 break;
1011 }
1012
1013 if (k == 0)
1014 ret = -ETIMEDOUT;
1015
1016 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1017 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
1018 &buf);
1019
1020 return ret ? ret : err;
1021 }
1022
1023 int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx)
1024 {
1025 hermes_t *hw = &priv->hw;
1026 int err;
1027
1028 err = hermes_write_wordrec(hw, USER_BAP,
1029 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
1030 key_idx);
1031 if (err)
1032 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
1033 priv->ndev->name, err, key_idx);
1034 return err;
1035 }
1036
1037 int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
1038 struct net_device *dev,
1039 int mc_count, int promisc)
1040 {
1041 hermes_t *hw = &priv->hw;
1042 int err = 0;
1043
1044 if (promisc != priv->promiscuous) {
1045 err = hermes_write_wordrec(hw, USER_BAP,
1046 HERMES_RID_CNFPROMISCUOUSMODE,
1047 promisc);
1048 if (err) {
1049 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1050 priv->ndev->name, err);
1051 } else
1052 priv->promiscuous = promisc;
1053 }
1054
1055 /* If we're not in promiscuous mode, then we need to set the
1056 * group address if either we want to multicast, or if we were
1057 * multicasting and want to stop */
1058 if (!promisc && (mc_count || priv->mc_count)) {
1059 struct dev_mc_list *p;
1060 struct hermes_multicast mclist;
1061 int i = 0;
1062
1063 netdev_for_each_mc_addr(p, dev) {
1064 if (i == mc_count)
1065 break;
1066 memcpy(mclist.addr[i++], p->dmi_addr, ETH_ALEN);
1067 }
1068
1069 err = hermes_write_ltv(hw, USER_BAP,
1070 HERMES_RID_CNFGROUPADDRESSES,
1071 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
1072 &mclist);
1073 if (err)
1074 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1075 priv->ndev->name, err);
1076 else
1077 priv->mc_count = mc_count;
1078 }
1079 return err;
1080 }
1081
1082 /* Return : < 0 -> error code ; >= 0 -> length */
1083 int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
1084 char buf[IW_ESSID_MAX_SIZE+1])
1085 {
1086 hermes_t *hw = &priv->hw;
1087 int err = 0;
1088 struct hermes_idstring essidbuf;
1089 char *p = (char *)(&essidbuf.val);
1090 int len;
1091 unsigned long flags;
1092
1093 if (orinoco_lock(priv, &flags) != 0)
1094 return -EBUSY;
1095
1096 if (strlen(priv->desired_essid) > 0) {
1097 /* We read the desired SSID from the hardware rather
1098 than from priv->desired_essid, just in case the
1099 firmware is allowed to change it on us. I'm not
1100 sure about this */
1101 /* My guess is that the OWNSSID should always be whatever
1102 * we set to the card, whereas CURRENT_SSID is the one that
1103 * may change... - Jean II */
1104 u16 rid;
1105
1106 *active = 1;
1107
1108 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
1109 HERMES_RID_CNFDESIREDSSID;
1110
1111 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
1112 NULL, &essidbuf);
1113 if (err)
1114 goto fail_unlock;
1115 } else {
1116 *active = 0;
1117
1118 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
1119 sizeof(essidbuf), NULL, &essidbuf);
1120 if (err)
1121 goto fail_unlock;
1122 }
1123
1124 len = le16_to_cpu(essidbuf.len);
1125 BUG_ON(len > IW_ESSID_MAX_SIZE);
1126
1127 memset(buf, 0, IW_ESSID_MAX_SIZE);
1128 memcpy(buf, p, len);
1129 err = len;
1130
1131 fail_unlock:
1132 orinoco_unlock(priv, &flags);
1133
1134 return err;
1135 }
1136
1137 int orinoco_hw_get_freq(struct orinoco_private *priv)
1138 {
1139 hermes_t *hw = &priv->hw;
1140 int err = 0;
1141 u16 channel;
1142 int freq = 0;
1143 unsigned long flags;
1144
1145 if (orinoco_lock(priv, &flags) != 0)
1146 return -EBUSY;
1147
1148 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
1149 &channel);
1150 if (err)
1151 goto out;
1152
1153 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
1154 if (channel == 0) {
1155 err = -EBUSY;
1156 goto out;
1157 }
1158
1159 if ((channel < 1) || (channel > NUM_CHANNELS)) {
1160 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
1161 priv->ndev->name, channel);
1162 err = -EBUSY;
1163 goto out;
1164
1165 }
1166 freq = ieee80211_dsss_chan_to_freq(channel);
1167
1168 out:
1169 orinoco_unlock(priv, &flags);
1170
1171 if (err > 0)
1172 err = -EBUSY;
1173 return err ? err : freq;
1174 }
1175
1176 int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
1177 int *numrates, s32 *rates, int max)
1178 {
1179 hermes_t *hw = &priv->hw;
1180 struct hermes_idstring list;
1181 unsigned char *p = (unsigned char *)&list.val;
1182 int err = 0;
1183 int num;
1184 int i;
1185 unsigned long flags;
1186
1187 if (orinoco_lock(priv, &flags) != 0)
1188 return -EBUSY;
1189
1190 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
1191 sizeof(list), NULL, &list);
1192 orinoco_unlock(priv, &flags);
1193
1194 if (err)
1195 return err;
1196
1197 num = le16_to_cpu(list.len);
1198 *numrates = num;
1199 num = min(num, max);
1200
1201 for (i = 0; i < num; i++)
1202 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
1203
1204 return 0;
1205 }
1206
1207 int orinoco_hw_trigger_scan(struct orinoco_private *priv,
1208 const struct cfg80211_ssid *ssid)
1209 {
1210 struct net_device *dev = priv->ndev;
1211 hermes_t *hw = &priv->hw;
1212 unsigned long flags;
1213 int err = 0;
1214
1215 if (orinoco_lock(priv, &flags) != 0)
1216 return -EBUSY;
1217
1218 /* Scanning with port 0 disabled would fail */
1219 if (!netif_running(dev)) {
1220 err = -ENETDOWN;
1221 goto out;
1222 }
1223
1224 /* In monitor mode, the scan results are always empty.
1225 * Probe responses are passed to the driver as received
1226 * frames and could be processed in software. */
1227 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
1228 err = -EOPNOTSUPP;
1229 goto out;
1230 }
1231
1232 if (priv->has_hostscan) {
1233 switch (priv->firmware_type) {
1234 case FIRMWARE_TYPE_SYMBOL:
1235 err = hermes_write_wordrec(hw, USER_BAP,
1236 HERMES_RID_CNFHOSTSCAN_SYMBOL,
1237 HERMES_HOSTSCAN_SYMBOL_ONCE |
1238 HERMES_HOSTSCAN_SYMBOL_BCAST);
1239 break;
1240 case FIRMWARE_TYPE_INTERSIL: {
1241 __le16 req[3];
1242
1243 req[0] = cpu_to_le16(0x3fff); /* All channels */
1244 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
1245 req[2] = 0; /* Any ESSID */
1246 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1247 HERMES_RID_CNFHOSTSCAN, &req);
1248 break;
1249 }
1250 case FIRMWARE_TYPE_AGERE:
1251 if (ssid->ssid_len > 0) {
1252 struct hermes_idstring idbuf;
1253 size_t len = ssid->ssid_len;
1254
1255 idbuf.len = cpu_to_le16(len);
1256 memcpy(idbuf.val, ssid->ssid, len);
1257
1258 err = hermes_write_ltv(hw, USER_BAP,
1259 HERMES_RID_CNFSCANSSID_AGERE,
1260 HERMES_BYTES_TO_RECLEN(len + 2),
1261 &idbuf);
1262 } else
1263 err = hermes_write_wordrec(hw, USER_BAP,
1264 HERMES_RID_CNFSCANSSID_AGERE,
1265 0); /* Any ESSID */
1266 if (err)
1267 break;
1268
1269 if (priv->has_ext_scan) {
1270 err = hermes_write_wordrec(hw, USER_BAP,
1271 HERMES_RID_CNFSCANCHANNELS2GHZ,
1272 0x7FFF);
1273 if (err)
1274 goto out;
1275
1276 err = hermes_inquire(hw,
1277 HERMES_INQ_CHANNELINFO);
1278 } else
1279 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1280
1281 break;
1282 }
1283 } else
1284 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1285
1286 out:
1287 orinoco_unlock(priv, &flags);
1288
1289 return err;
1290 }
1291
1292 /* Disassociate from node with BSSID addr */
1293 int orinoco_hw_disassociate(struct orinoco_private *priv,
1294 u8 *addr, u16 reason_code)
1295 {
1296 hermes_t *hw = &priv->hw;
1297 int err;
1298
1299 struct {
1300 u8 addr[ETH_ALEN];
1301 __le16 reason_code;
1302 } __attribute__ ((packed)) buf;
1303
1304 /* Currently only supported by WPA enabled Agere fw */
1305 if (!priv->has_wpa)
1306 return -EOPNOTSUPP;
1307
1308 memcpy(buf.addr, addr, ETH_ALEN);
1309 buf.reason_code = cpu_to_le16(reason_code);
1310 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1311 HERMES_RID_CNFDISASSOCIATE,
1312 &buf);
1313 return err;
1314 }
1315
1316 int orinoco_hw_get_current_bssid(struct orinoco_private *priv,
1317 u8 *addr)
1318 {
1319 hermes_t *hw = &priv->hw;
1320 int err;
1321
1322 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1323 ETH_ALEN, NULL, addr);
1324
1325 return err;
1326 }
This page took 0.0827 seconds and 5 git commands to generate.