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/if_arp.h>
7 #include <linux/ieee80211.h>
8 #include <linux/wireless.h>
11 #include "hermes_rid.h"
16 /********************************************************************/
18 /********************************************************************/
20 /* This tables gives the actual meanings of the bitrate IDs returned
23 int bitrate; /* in 100s of kilobits */
26 u16 intersil_txratectrl;
28 {110, 1, 3, 15}, /* Entry 0 is the default */
37 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
39 int orinoco_get_bitratemode(int bitrate, int automatic)
44 if ((bitrate != 10) && (bitrate != 20) &&
45 (bitrate != 55) && (bitrate != 110))
48 for (i = 0; i < BITRATE_TABLE_SIZE; i++) {
49 if ((bitrate_table[i].bitrate == bitrate) &&
50 (bitrate_table[i].automatic == automatic)) {
58 void orinoco_get_ratemode_cfg(int ratemode, int *bitrate, int *automatic)
60 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
62 *bitrate = bitrate_table[ratemode].bitrate * 100000;
63 *automatic = bitrate_table[ratemode].automatic;
66 /* Get tsc from the firmware */
67 int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key, u8 *tsc)
69 hermes_t *hw = &priv->hw;
71 u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
73 if ((key < 0) || (key > 4))
76 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
77 sizeof(tsc_arr), NULL, &tsc_arr);
79 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
84 int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
86 hermes_t *hw = &priv->hw;
87 int ratemode = priv->bitratemode;
90 if (ratemode >= BITRATE_TABLE_SIZE) {
91 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
92 priv->ndev->name, ratemode);
96 switch (priv->firmware_type) {
97 case FIRMWARE_TYPE_AGERE:
98 err = hermes_write_wordrec(hw, USER_BAP,
99 HERMES_RID_CNFTXRATECONTROL,
100 bitrate_table[ratemode].agere_txratectrl);
102 case FIRMWARE_TYPE_INTERSIL:
103 case FIRMWARE_TYPE_SYMBOL:
104 err = hermes_write_wordrec(hw, USER_BAP,
105 HERMES_RID_CNFTXRATECONTROL,
106 bitrate_table[ratemode].intersil_txratectrl);
115 int orinoco_hw_get_act_bitrate(struct orinoco_private *priv, int *bitrate)
117 hermes_t *hw = &priv->hw;
122 err = hermes_read_wordrec(hw, USER_BAP,
123 HERMES_RID_CURRENTTXRATE, &val);
127 switch (priv->firmware_type) {
128 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
129 /* Note : in Lucent firmware, the return value of
130 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
131 * and therefore is totally different from the
132 * encoding of HERMES_RID_CNFTXRATECONTROL.
133 * Don't forget that 6Mb/s is really 5.5Mb/s */
137 *bitrate = val * 1000000;
139 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
140 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
141 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
142 if (bitrate_table[i].intersil_txratectrl == val)
145 if (i >= BITRATE_TABLE_SIZE)
146 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
147 priv->ndev->name, val);
149 *bitrate = bitrate_table[i].bitrate * 100000;
158 /* Set fixed AP address */
159 int __orinoco_hw_set_wap(struct orinoco_private *priv)
163 hermes_t *hw = &priv->hw;
165 switch (priv->firmware_type) {
166 case FIRMWARE_TYPE_AGERE:
169 case FIRMWARE_TYPE_INTERSIL:
170 if (priv->bssid_fixed)
175 err = hermes_write_wordrec(hw, USER_BAP,
176 HERMES_RID_CNFROAMINGMODE,
179 case FIRMWARE_TYPE_SYMBOL:
180 err = HERMES_WRITE_RECORD(hw, USER_BAP,
181 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
182 &priv->desired_bssid);
188 /* Change the WEP keys and/or the current keys. Can be called
189 * either from __orinoco_hw_setup_enc() or directly from
190 * orinoco_ioctl_setiwencode(). In the later case the association
191 * with the AP is not broken (if the firmware can handle it),
192 * which is needed for 802.1x implementations. */
193 int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
195 hermes_t *hw = &priv->hw;
198 switch (priv->firmware_type) {
199 case FIRMWARE_TYPE_AGERE:
200 err = HERMES_WRITE_RECORD(hw, USER_BAP,
201 HERMES_RID_CNFWEPKEYS_AGERE,
205 err = hermes_write_wordrec(hw, USER_BAP,
206 HERMES_RID_CNFTXKEY_AGERE,
211 case FIRMWARE_TYPE_INTERSIL:
212 case FIRMWARE_TYPE_SYMBOL:
217 /* Force uniform key length to work around
219 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
221 if (keylen > LARGE_KEY_SIZE) {
222 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
223 priv->ndev->name, priv->tx_key, keylen);
227 /* Write all 4 keys */
228 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
229 err = hermes_write_ltv(hw, USER_BAP,
230 HERMES_RID_CNFDEFAULTKEY0 + i,
231 HERMES_BYTES_TO_RECLEN(keylen),
237 /* Write the index of the key used in transmission */
238 err = hermes_write_wordrec(hw, USER_BAP,
239 HERMES_RID_CNFWEPDEFAULTKEYID,
250 int __orinoco_hw_setup_enc(struct orinoco_private *priv)
252 hermes_t *hw = &priv->hw;
258 /* Setup WEP keys for WEP and WPA */
259 if (priv->encode_alg)
260 __orinoco_hw_setup_wepkeys(priv);
262 if (priv->wep_restrict)
263 auth_flag = HERMES_AUTH_SHARED_KEY;
265 auth_flag = HERMES_AUTH_OPEN;
267 if (priv->wpa_enabled)
269 else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
274 switch (priv->firmware_type) {
275 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
276 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
277 /* Enable the shared-key authentication. */
278 err = hermes_write_wordrec(hw, USER_BAP,
279 HERMES_RID_CNFAUTHENTICATION_AGERE,
282 err = hermes_write_wordrec(hw, USER_BAP,
283 HERMES_RID_CNFWEPENABLED_AGERE,
289 /* Set WPA key management */
290 err = hermes_write_wordrec(hw, USER_BAP,
291 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
299 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
300 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
301 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
302 if (priv->wep_restrict ||
303 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
304 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
305 HERMES_WEP_EXCL_UNENCRYPTED;
307 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
309 err = hermes_write_wordrec(hw, USER_BAP,
310 HERMES_RID_CNFAUTHENTICATION,
317 if (priv->iw_mode == IW_MODE_MONITOR)
318 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
320 /* Master WEP setting : on/off */
321 err = hermes_write_wordrec(hw, USER_BAP,
322 HERMES_RID_CNFWEPFLAGS_INTERSIL,
333 /* key must be 32 bytes, including the tx and rx MIC keys.
334 * rsc must be 8 bytes
335 * tsc must be 8 bytes or NULL
337 int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
338 u8 *key, u8 *rsc, u8 *tsc)
342 u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
344 u8 tx_mic[MIC_KEYLEN];
345 u8 rx_mic[MIC_KEYLEN];
346 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
347 } __attribute__ ((packed)) buf;
358 buf.idx = cpu_to_le16(key_idx);
360 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
363 memset(buf.rsc, 0, sizeof(buf.rsc));
365 memcpy(buf.rsc, rsc, sizeof(buf.rsc));
368 memset(buf.tsc, 0, sizeof(buf.tsc));
371 memcpy(buf.tsc, tsc, sizeof(buf.tsc));
374 /* Wait upto 100ms for tx queue to empty */
375 for (k = 100; k > 0; k--) {
377 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
379 if (ret || !xmitting)
386 err = HERMES_WRITE_RECORD(hw, USER_BAP,
387 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
390 return ret ? ret : err;
393 int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx)
395 hermes_t *hw = &priv->hw;
398 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
399 err = hermes_write_wordrec(hw, USER_BAP,
400 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
403 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
404 priv->ndev->name, err, key_idx);
408 int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
409 struct dev_addr_list *mc_list,
410 int mc_count, int promisc)
412 hermes_t *hw = &priv->hw;
415 if (promisc != priv->promiscuous) {
416 err = hermes_write_wordrec(hw, USER_BAP,
417 HERMES_RID_CNFPROMISCUOUSMODE,
420 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
421 priv->ndev->name, err);
423 priv->promiscuous = promisc;
426 /* If we're not in promiscuous mode, then we need to set the
427 * group address if either we want to multicast, or if we were
428 * multicasting and want to stop */
429 if (!promisc && (mc_count || priv->mc_count)) {
430 struct dev_mc_list *p = mc_list;
431 struct hermes_multicast mclist;
434 for (i = 0; i < mc_count; i++) {
435 /* paranoia: is list shorter than mc_count? */
437 /* paranoia: bad address size in list? */
438 BUG_ON(p->dmi_addrlen != ETH_ALEN);
440 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
445 printk(KERN_WARNING "%s: Multicast list is "
446 "longer than mc_count\n", priv->ndev->name);
448 err = hermes_write_ltv(hw, USER_BAP,
449 HERMES_RID_CNFGROUPADDRESSES,
450 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
453 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
454 priv->ndev->name, err);
456 priv->mc_count = mc_count;
461 /* Return : < 0 -> error code ; >= 0 -> length */
462 int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
463 char buf[IW_ESSID_MAX_SIZE+1])
465 hermes_t *hw = &priv->hw;
467 struct hermes_idstring essidbuf;
468 char *p = (char *)(&essidbuf.val);
472 if (orinoco_lock(priv, &flags) != 0)
475 if (strlen(priv->desired_essid) > 0) {
476 /* We read the desired SSID from the hardware rather
477 than from priv->desired_essid, just in case the
478 firmware is allowed to change it on us. I'm not
480 /* My guess is that the OWNSSID should always be whatever
481 * we set to the card, whereas CURRENT_SSID is the one that
482 * may change... - Jean II */
487 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
488 HERMES_RID_CNFDESIREDSSID;
490 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
497 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
498 sizeof(essidbuf), NULL, &essidbuf);
503 len = le16_to_cpu(essidbuf.len);
504 BUG_ON(len > IW_ESSID_MAX_SIZE);
506 memset(buf, 0, IW_ESSID_MAX_SIZE);
511 orinoco_unlock(priv, &flags);
516 int orinoco_hw_get_freq(struct orinoco_private *priv)
518 hermes_t *hw = &priv->hw;
524 if (orinoco_lock(priv, &flags) != 0)
527 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
532 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
538 if ((channel < 1) || (channel > NUM_CHANNELS)) {
539 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
540 priv->ndev->name, channel);
545 freq = ieee80211_dsss_chan_to_freq(channel);
548 orinoco_unlock(priv, &flags);
552 return err ? err : freq;
555 int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
556 int *numrates, s32 *rates, int max)
558 hermes_t *hw = &priv->hw;
559 struct hermes_idstring list;
560 unsigned char *p = (unsigned char *)&list.val;
566 if (orinoco_lock(priv, &flags) != 0)
569 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
570 sizeof(list), NULL, &list);
571 orinoco_unlock(priv, &flags);
576 num = le16_to_cpu(list.len);
580 for (i = 0; i < num; i++)
581 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */