1 /* Encapsulate basic setting changes and retrieval on Hermes hardware
3 * See copyright notice in main.c
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>
12 #include "hermes_rid.h"
17 #define SYMBOL_MAX_VER_LEN (14)
19 /* Symbol firmware has a bug allocating buffers larger than this */
20 #define TX_NICBUF_SIZE_BUG 1585
22 /********************************************************************/
24 /********************************************************************/
26 /* This tables gives the actual meanings of the bitrate IDs returned
29 int bitrate
; /* in 100s of kilobits */
32 u16 intersil_txratectrl
;
34 {110, 1, 3, 15}, /* Entry 0 is the default */
43 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
45 /* Firmware version encoding */
47 u16 id
, variant
, major
, minor
;
48 } __attribute__ ((packed
));
50 static inline fwtype_t
determine_firmware_type(struct comp_id
*nic_id
)
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
;
57 return FIRMWARE_TYPE_INTERSIL
;
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
64 * If non-NULL stores a firmware description in fw_name.
65 * If non-NULL stores a HW version in hw_ver
67 * These are output via generic cfg80211 ethtool support.
69 int determine_fw_capabilities(struct orinoco_private
*priv
,
70 char *fw_name
, size_t fw_name_len
,
73 struct device
*dev
= priv
->dev
;
74 hermes_t
*hw
= &priv
->hw
;
76 struct comp_id nic_id
, sta_id
;
78 char tmp
[SYMBOL_MAX_VER_LEN
+1] __attribute__((aligned(2)));
80 /* Get the hardware version */
81 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_NICID
, &nic_id
);
83 dev_err(dev
, "Cannot read hardware identity: error %d\n",
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
);
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));
101 priv
->firmware_type
= determine_firmware_type(&nic_id
);
103 /* Get the firmware version */
104 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_STAID
, &sta_id
);
106 dev_err(dev
, "Cannot read station identity: error %d\n",
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
);
120 dev_err(dev
, "Primary firmware is active\n");
123 dev_err(dev
, "Tertiary firmware is active\n");
125 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
126 case 0x21: /* Symbol Spectrum24 Trilogy */
129 dev_notice(dev
, "Unknown station ID, please report\n");
133 /* Default capabilities */
134 priv
->has_sensitivity
= 1;
136 priv
->has_preamble
= 0;
140 priv
->has_big_wep
= 0;
141 priv
->has_alt_txcntl
= 0;
142 priv
->has_ext_scan
= 0;
144 priv
->do_fw_download
= 0;
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 */
152 snprintf(fw_name
, fw_name_len
, "Lucent/Agere %d.%02d",
153 sta_id
.major
, sta_id
.minor
);
155 firmver
= ((unsigned long)sta_id
.major
<< 16) | sta_id
.minor
;
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 ? */
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 */
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
);
184 dev_warn(dev
, "Error %d reading Symbol firmware info. "
185 "Wildly guessing capabilities...\n", err
);
189 /* The firmware revision is a string, the format is
190 * something like : "V2.20-01".
191 * Quick and dirty parsing... - Jean II
193 firmver
= ((tmp
[1] - '0') << 16)
194 | ((tmp
[3] - '0') << 12)
195 | ((tmp
[4] - '0') << 8)
196 | ((tmp
[6] - '0') << 4)
199 tmp
[SYMBOL_MAX_VER_LEN
] = '\0';
203 snprintf(fw_name
, fw_name_len
, "Symbol %s", tmp
);
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) ||
211 priv
->has_preamble
= (firmver
>= 0x20000);
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.
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
223 * For now we can identify a spectrum_cs based card
224 * because it has a firmware reset function.
226 priv
->do_fw_download
= (priv
->stop_fw
!= NULL
);
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 */
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:* */
242 snprintf(fw_name
, fw_name_len
, "Intersil %d.%d.%d",
243 sta_id
.major
, sta_id
.minor
, sta_id
.variant
);
245 firmver
= ((unsigned long)sta_id
.major
<< 16) |
246 ((unsigned long)sta_id
.minor
<< 8) | sta_id
.variant
;
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);
253 if (firmver
>= 0x000800)
256 dev_notice(dev
, "Intersil firmware earlier than v0.8.x"
257 " - several features not supported\n");
263 dev_info(dev
, "Firmware determined as %s\n", fw_name
);
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");
275 /* Read settings from EEPROM into our private structure.
276 * MAC address gets dropped into callers buffer
277 * Can be called before netdev registration.
279 int orinoco_hw_read_card_settings(struct orinoco_private
*priv
, u8
*dev_addr
)
281 struct device
*dev
= priv
->dev
;
282 struct hermes_idstring nickbuf
;
283 hermes_t
*hw
= &priv
->hw
;
288 /* Get the MAC address */
289 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
290 ETH_ALEN
, NULL
, dev_addr
);
292 dev_warn(dev
, "Failed to read MAC address!\n");
296 dev_dbg(dev
, "MAC address %pM\n", dev_addr
);
298 /* Get the station name */
299 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
300 sizeof(nickbuf
), &reclen
, &nickbuf
);
302 dev_err(dev
, "failed to read station name\n");
306 len
= min(IW_ESSID_MAX_SIZE
, (int)le16_to_cpu(nickbuf
.len
));
308 len
= min(IW_ESSID_MAX_SIZE
, 2 * reclen
);
309 memcpy(priv
->nick
, &nickbuf
.val
, len
);
310 priv
->nick
[len
] = '\0';
312 dev_dbg(dev
, "Station name \"%s\"\n", priv
->nick
);
314 /* Get allowed channels */
315 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CHANNELLIST
,
316 &priv
->channel_mask
);
318 dev_err(dev
, "Failed to read channel list!\n");
322 /* Get initial AP density */
323 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFSYSTEMSCALE
,
325 if (err
|| priv
->ap_density
< 1 || priv
->ap_density
> 3)
326 priv
->has_sensitivity
= 0;
328 /* Get initial RTS threshold */
329 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
332 dev_err(dev
, "Failed to read RTS threshold!\n");
336 /* Get initial fragmentation settings */
338 err
= hermes_read_wordrec(hw
, USER_BAP
,
339 HERMES_RID_CNFMWOROBUST_AGERE
,
342 err
= hermes_read_wordrec(hw
, USER_BAP
,
343 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
346 dev_err(dev
, "Failed to read fragmentation settings!\n");
350 /* Power management setup */
354 err
= hermes_read_wordrec(hw
, USER_BAP
,
355 HERMES_RID_CNFMAXSLEEPDURATION
,
358 dev_err(dev
, "Failed to read power management "
362 err
= hermes_read_wordrec(hw
, USER_BAP
,
363 HERMES_RID_CNFPMHOLDOVERDURATION
,
366 dev_err(dev
, "Failed to read power management "
373 if (priv
->has_preamble
) {
374 err
= hermes_read_wordrec(hw
, USER_BAP
,
375 HERMES_RID_CNFPREAMBLE_SYMBOL
,
383 /* Can be called before netdev registration */
384 int orinoco_hw_allocate_fid(struct orinoco_private
*priv
)
386 struct device
*dev
= priv
->dev
;
387 struct hermes
*hw
= &priv
->hw
;
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
);
396 dev_warn(dev
, "Firmware ALLOC bug detected "
397 "(old Symbol firmware?). Work around %s\n",
398 err
? "failed!" : "ok.");
404 int orinoco_get_bitratemode(int bitrate
, int automatic
)
409 if ((bitrate
!= 10) && (bitrate
!= 20) &&
410 (bitrate
!= 55) && (bitrate
!= 110))
413 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++) {
414 if ((bitrate_table
[i
].bitrate
== bitrate
) &&
415 (bitrate_table
[i
].automatic
== automatic
)) {
423 void orinoco_get_ratemode_cfg(int ratemode
, int *bitrate
, int *automatic
)
425 BUG_ON((ratemode
< 0) || (ratemode
>= BITRATE_TABLE_SIZE
));
427 *bitrate
= bitrate_table
[ratemode
].bitrate
* 100000;
428 *automatic
= bitrate_table
[ratemode
].automatic
;
431 int orinoco_hw_program_rids(struct orinoco_private
*priv
)
433 struct net_device
*dev
= priv
->ndev
;
434 struct wireless_dev
*wdev
= netdev_priv(dev
);
435 hermes_t
*hw
= &priv
->hw
;
437 struct hermes_idstring idbuf
;
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
);
443 printk(KERN_ERR
"%s: Error %d setting MAC address\n",
448 /* Set up the link mode */
449 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPORTTYPE
,
452 printk(KERN_ERR
"%s: Error %d setting port type\n",
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
,
462 printk(KERN_ERR
"%s: Error %d setting channel %d\n",
463 dev
->name
, err
, priv
->channel
);
468 if (priv
->has_ibss
) {
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...
479 createibss
= priv
->createibss
;
482 err
= hermes_write_wordrec(hw
, USER_BAP
,
483 HERMES_RID_CNFCREATEIBSS
,
486 printk(KERN_ERR
"%s: Error %d setting CREATEIBSS\n",
492 /* Set the desired BSSID */
493 err
= __orinoco_hw_set_wap(priv
);
495 printk(KERN_ERR
"%s: Error %d setting AP address\n",
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),
508 printk(KERN_ERR
"%s: Error %d setting OWNSSID\n",
512 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFDESIREDSSID
,
513 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
516 printk(KERN_ERR
"%s: Error %d setting DESIREDSSID\n",
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),
528 printk(KERN_ERR
"%s: Error %d setting nickname\n",
534 if (priv
->has_sensitivity
) {
535 err
= hermes_write_wordrec(hw
, USER_BAP
,
536 HERMES_RID_CNFSYSTEMSCALE
,
539 printk(KERN_WARNING
"%s: Error %d setting SYSTEMSCALE. "
540 "Disabling sensitivity control\n",
543 priv
->has_sensitivity
= 0;
547 /* Set RTS threshold */
548 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
551 printk(KERN_ERR
"%s: Error %d setting RTS threshold\n",
556 /* Set fragmentation threshold or MWO robustness */
558 err
= hermes_write_wordrec(hw
, USER_BAP
,
559 HERMES_RID_CNFMWOROBUST_AGERE
,
562 err
= hermes_write_wordrec(hw
, USER_BAP
,
563 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
566 printk(KERN_ERR
"%s: Error %d setting fragmentation\n",
572 err
= __orinoco_hw_set_bitrate(priv
);
574 printk(KERN_ERR
"%s: Error %d setting bitrate\n",
579 /* Set power management */
581 err
= hermes_write_wordrec(hw
, USER_BAP
,
582 HERMES_RID_CNFPMENABLED
,
585 printk(KERN_ERR
"%s: Error %d setting up PM\n",
590 err
= hermes_write_wordrec(hw
, USER_BAP
,
591 HERMES_RID_CNFMULTICASTRECEIVE
,
594 printk(KERN_ERR
"%s: Error %d setting up PM\n",
598 err
= hermes_write_wordrec(hw
, USER_BAP
,
599 HERMES_RID_CNFMAXSLEEPDURATION
,
602 printk(KERN_ERR
"%s: Error %d setting up PM\n",
606 err
= hermes_write_wordrec(hw
, USER_BAP
,
607 HERMES_RID_CNFPMHOLDOVERDURATION
,
610 printk(KERN_ERR
"%s: Error %d setting up PM\n",
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
,
622 printk(KERN_ERR
"%s: Error %d setting preamble\n",
628 /* Set up encryption */
629 if (priv
->has_wep
|| priv
->has_wpa
) {
630 err
= __orinoco_hw_setup_enc(priv
);
632 printk(KERN_ERR
"%s: Error %d activating encryption\n",
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
);
644 /* Disable monitor mode */
645 dev
->type
= ARPHRD_ETHER
;
646 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
647 HERMES_TEST_STOP
, 0, NULL
);
652 /* Reset promiscuity / multicast*/
653 priv
->promiscuous
= 0;
656 /* Record mode change */
657 wdev
->iftype
= priv
->iw_mode
;
662 /* Get tsc from the firmware */
663 int orinoco_hw_get_tkip_iv(struct orinoco_private
*priv
, int key
, u8
*tsc
)
665 hermes_t
*hw
= &priv
->hw
;
667 u8 tsc_arr
[4][ORINOCO_SEQ_LEN
];
669 if ((key
< 0) || (key
>= 4))
672 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENT_TKIP_IV
,
673 sizeof(tsc_arr
), NULL
, &tsc_arr
);
675 memcpy(tsc
, &tsc_arr
[key
][0], sizeof(tsc_arr
[0]));
680 int __orinoco_hw_set_bitrate(struct orinoco_private
*priv
)
682 hermes_t
*hw
= &priv
->hw
;
683 int ratemode
= priv
->bitratemode
;
686 if (ratemode
>= BITRATE_TABLE_SIZE
) {
687 printk(KERN_ERR
"%s: BUG: Invalid bitrate mode %d\n",
688 priv
->ndev
->name
, ratemode
);
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
);
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
);
711 int orinoco_hw_get_act_bitrate(struct orinoco_private
*priv
, int *bitrate
)
713 hermes_t
*hw
= &priv
->hw
;
718 err
= hermes_read_wordrec(hw
, USER_BAP
,
719 HERMES_RID_CURRENTTXRATE
, &val
);
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 */
733 *bitrate
= val
* 1000000;
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
)
741 if (i
>= BITRATE_TABLE_SIZE
)
742 printk(KERN_INFO
"%s: Unable to determine current bitrate (0x%04hx)\n",
743 priv
->ndev
->name
, val
);
745 *bitrate
= bitrate_table
[i
].bitrate
* 100000;
754 /* Set fixed AP address */
755 int __orinoco_hw_set_wap(struct orinoco_private
*priv
)
759 hermes_t
*hw
= &priv
->hw
;
761 switch (priv
->firmware_type
) {
762 case FIRMWARE_TYPE_AGERE
:
765 case FIRMWARE_TYPE_INTERSIL
:
766 if (priv
->bssid_fixed
)
771 err
= hermes_write_wordrec(hw
, USER_BAP
,
772 HERMES_RID_CNFROAMINGMODE
,
775 case FIRMWARE_TYPE_SYMBOL
:
776 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
777 HERMES_RID_CNFMANDATORYBSSID_SYMBOL
,
778 &priv
->desired_bssid
);
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
)
791 hermes_t
*hw
= &priv
->hw
;
795 switch (priv
->firmware_type
) {
796 case FIRMWARE_TYPE_AGERE
:
798 struct orinoco_key keys
[ORINOCO_MAX_KEYS
];
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
);
808 keys
[i
].len
= cpu_to_le16(SMALL_KEY_SIZE
);
810 keys
[i
].len
= cpu_to_le16(0);
813 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
814 HERMES_RID_CNFWEPKEYS_AGERE
,
818 err
= hermes_write_wordrec(hw
, USER_BAP
,
819 HERMES_RID_CNFTXKEY_AGERE
,
825 case FIRMWARE_TYPE_INTERSIL
:
826 case FIRMWARE_TYPE_SYMBOL
:
830 /* Force uniform key length to work around
832 keylen
= priv
->keys
[priv
->tx_key
].key_len
;
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
);
838 } else if (keylen
> SMALL_KEY_SIZE
)
839 keylen
= LARGE_KEY_SIZE
;
841 keylen
= SMALL_KEY_SIZE
;
845 /* Write all 4 keys */
846 for (i
= 0; i
< ORINOCO_MAX_KEYS
; i
++) {
847 u8 key
[LARGE_KEY_SIZE
] = { 0 };
849 memcpy(key
, priv
->keys
[i
].key
,
850 priv
->keys
[i
].key_len
);
852 err
= hermes_write_ltv(hw
, USER_BAP
,
853 HERMES_RID_CNFDEFAULTKEY0
+ i
,
854 HERMES_BYTES_TO_RECLEN(keylen
),
860 /* Write the index of the key used in transmission */
861 err
= hermes_write_wordrec(hw
, USER_BAP
,
862 HERMES_RID_CNFWEPDEFAULTKEYID
,
873 int __orinoco_hw_setup_enc(struct orinoco_private
*priv
)
875 hermes_t
*hw
= &priv
->hw
;
882 if (priv
->encode_alg
== ORINOCO_ALG_WEP
)
883 __orinoco_hw_setup_wepkeys(priv
);
885 if (priv
->wep_restrict
)
886 auth_flag
= HERMES_AUTH_SHARED_KEY
;
888 auth_flag
= HERMES_AUTH_OPEN
;
890 if (priv
->wpa_enabled
)
892 else if (priv
->encode_alg
== ORINOCO_ALG_WEP
)
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
,
905 err
= hermes_write_wordrec(hw
, USER_BAP
,
906 HERMES_RID_CNFWEPENABLED_AGERE
,
912 /* Set WPA key management */
913 err
= hermes_write_wordrec(hw
, USER_BAP
,
914 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE
,
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
;
930 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
;
932 err
= hermes_write_wordrec(hw
, USER_BAP
,
933 HERMES_RID_CNFAUTHENTICATION
,
940 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
)
941 master_wep_flag
|= HERMES_WEP_HOST_DECRYPT
;
943 /* Master WEP setting : on/off */
944 err
= hermes_write_wordrec(hw
, USER_BAP
,
945 HERMES_RID_CNFWEPFLAGS_INTERSIL
,
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
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
)
966 u8 rsc
[ORINOCO_SEQ_LEN
];
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
;
983 buf
.idx
= cpu_to_le16(key_idx
);
985 sizeof(buf
.key
) + sizeof(buf
.tx_mic
) + sizeof(buf
.rx_mic
));
987 if (rsc_len
> sizeof(buf
.rsc
))
988 rsc_len
= sizeof(buf
.rsc
);
990 if (tsc_len
> sizeof(buf
.tsc
))
991 tsc_len
= sizeof(buf
.tsc
);
993 memset(buf
.rsc
, 0, sizeof(buf
.rsc
));
994 memset(buf
.tsc
, 0, sizeof(buf
.tsc
));
997 memcpy(buf
.rsc
, rsc
, rsc_len
);
1000 memcpy(buf
.tsc
, tsc
, tsc_len
);
1004 /* Wait upto 100ms for tx queue to empty */
1005 for (k
= 100; k
> 0; k
--) {
1007 ret
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_TXQUEUEEMPTY
,
1009 if (ret
|| !xmitting
)
1016 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
1017 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE
,
1020 return ret
? ret
: err
;
1023 int orinoco_clear_tkip_key(struct orinoco_private
*priv
, int key_idx
)
1025 hermes_t
*hw
= &priv
->hw
;
1028 err
= hermes_write_wordrec(hw
, USER_BAP
,
1029 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE
,
1032 printk(KERN_WARNING
"%s: Error %d clearing TKIP key %d\n",
1033 priv
->ndev
->name
, err
, key_idx
);
1037 int __orinoco_hw_set_multicast_list(struct orinoco_private
*priv
,
1038 struct net_device
*dev
,
1039 int mc_count
, int promisc
)
1041 hermes_t
*hw
= &priv
->hw
;
1044 if (promisc
!= priv
->promiscuous
) {
1045 err
= hermes_write_wordrec(hw
, USER_BAP
,
1046 HERMES_RID_CNFPROMISCUOUSMODE
,
1049 printk(KERN_ERR
"%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1050 priv
->ndev
->name
, err
);
1052 priv
->promiscuous
= promisc
;
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
;
1063 netdev_for_each_mc_addr(p
, dev
) {
1066 memcpy(mclist
.addr
[i
++], p
->dmi_addr
, ETH_ALEN
);
1069 err
= hermes_write_ltv(hw
, USER_BAP
,
1070 HERMES_RID_CNFGROUPADDRESSES
,
1071 HERMES_BYTES_TO_RECLEN(mc_count
* ETH_ALEN
),
1074 printk(KERN_ERR
"%s: Error %d setting multicast list.\n",
1075 priv
->ndev
->name
, err
);
1077 priv
->mc_count
= mc_count
;
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])
1086 hermes_t
*hw
= &priv
->hw
;
1088 struct hermes_idstring essidbuf
;
1089 char *p
= (char *)(&essidbuf
.val
);
1091 unsigned long flags
;
1093 if (orinoco_lock(priv
, &flags
) != 0)
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
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 */
1108 rid
= (priv
->port_type
== 3) ? HERMES_RID_CNFOWNSSID
:
1109 HERMES_RID_CNFDESIREDSSID
;
1111 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, sizeof(essidbuf
),
1118 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTSSID
,
1119 sizeof(essidbuf
), NULL
, &essidbuf
);
1124 len
= le16_to_cpu(essidbuf
.len
);
1125 BUG_ON(len
> IW_ESSID_MAX_SIZE
);
1127 memset(buf
, 0, IW_ESSID_MAX_SIZE
);
1128 memcpy(buf
, p
, len
);
1132 orinoco_unlock(priv
, &flags
);
1137 int orinoco_hw_get_freq(struct orinoco_private
*priv
)
1139 hermes_t
*hw
= &priv
->hw
;
1143 unsigned long flags
;
1145 if (orinoco_lock(priv
, &flags
) != 0)
1148 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CURRENTCHANNEL
,
1153 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
1159 if ((channel
< 1) || (channel
> NUM_CHANNELS
)) {
1160 printk(KERN_WARNING
"%s: Channel out of range (%d)!\n",
1161 priv
->ndev
->name
, channel
);
1166 freq
= ieee80211_dsss_chan_to_freq(channel
);
1169 orinoco_unlock(priv
, &flags
);
1173 return err
? err
: freq
;
1176 int orinoco_hw_get_bitratelist(struct orinoco_private
*priv
,
1177 int *numrates
, s32
*rates
, int max
)
1179 hermes_t
*hw
= &priv
->hw
;
1180 struct hermes_idstring list
;
1181 unsigned char *p
= (unsigned char *)&list
.val
;
1185 unsigned long flags
;
1187 if (orinoco_lock(priv
, &flags
) != 0)
1190 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_SUPPORTEDDATARATES
,
1191 sizeof(list
), NULL
, &list
);
1192 orinoco_unlock(priv
, &flags
);
1197 num
= le16_to_cpu(list
.len
);
1199 num
= min(num
, max
);
1201 for (i
= 0; i
< num
; i
++)
1202 rates
[i
] = (p
[i
] & 0x7f) * 500000; /* convert to bps */
1207 int orinoco_hw_trigger_scan(struct orinoco_private
*priv
,
1208 const struct cfg80211_ssid
*ssid
)
1210 struct net_device
*dev
= priv
->ndev
;
1211 hermes_t
*hw
= &priv
->hw
;
1212 unsigned long flags
;
1215 if (orinoco_lock(priv
, &flags
) != 0)
1218 /* Scanning with port 0 disabled would fail */
1219 if (!netif_running(dev
)) {
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
) {
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
);
1240 case FIRMWARE_TYPE_INTERSIL
: {
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
);
1250 case FIRMWARE_TYPE_AGERE
:
1251 if (ssid
->ssid_len
> 0) {
1252 struct hermes_idstring idbuf
;
1253 size_t len
= ssid
->ssid_len
;
1255 idbuf
.len
= cpu_to_le16(len
);
1256 memcpy(idbuf
.val
, ssid
->ssid
, len
);
1258 err
= hermes_write_ltv(hw
, USER_BAP
,
1259 HERMES_RID_CNFSCANSSID_AGERE
,
1260 HERMES_BYTES_TO_RECLEN(len
+ 2),
1263 err
= hermes_write_wordrec(hw
, USER_BAP
,
1264 HERMES_RID_CNFSCANSSID_AGERE
,
1269 if (priv
->has_ext_scan
) {
1270 err
= hermes_write_wordrec(hw
, USER_BAP
,
1271 HERMES_RID_CNFSCANCHANNELS2GHZ
,
1276 err
= hermes_inquire(hw
,
1277 HERMES_INQ_CHANNELINFO
);
1279 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
1284 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
1287 orinoco_unlock(priv
, &flags
);
1292 /* Disassociate from node with BSSID addr */
1293 int orinoco_hw_disassociate(struct orinoco_private
*priv
,
1294 u8
*addr
, u16 reason_code
)
1296 hermes_t
*hw
= &priv
->hw
;
1302 } __attribute__ ((packed
)) buf
;
1304 /* Currently only supported by WPA enabled Agere fw */
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
,
1316 int orinoco_hw_get_current_bssid(struct orinoco_private
*priv
,
1319 hermes_t
*hw
= &priv
->hw
;
1322 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTBSSID
,
1323 ETH_ALEN
, NULL
, addr
);