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 */
379 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
383 } while ((k > 0) && xmitting);
388 err = HERMES_WRITE_RECORD(hw, USER_BAP,
389 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
392 return ret ? ret : err;
395 int orinoco_clear_tkip_key(struct orinoco_private *priv, int key_idx)
397 hermes_t *hw = &priv->hw;
400 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
401 err = hermes_write_wordrec(hw, USER_BAP,
402 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
405 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
406 priv->ndev->name, err, key_idx);
410 int __orinoco_hw_set_multicast_list(struct orinoco_private *priv,
411 struct dev_addr_list *mc_list,
412 int mc_count, int promisc)
414 hermes_t *hw = &priv->hw;
417 if (promisc != priv->promiscuous) {
418 err = hermes_write_wordrec(hw, USER_BAP,
419 HERMES_RID_CNFPROMISCUOUSMODE,
422 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
423 priv->ndev->name, err);
425 priv->promiscuous = promisc;
428 /* If we're not in promiscuous mode, then we need to set the
429 * group address if either we want to multicast, or if we were
430 * multicasting and want to stop */
431 if (!promisc && (mc_count || priv->mc_count)) {
432 struct dev_mc_list *p = mc_list;
433 struct hermes_multicast mclist;
436 for (i = 0; i < mc_count; i++) {
437 /* paranoia: is list shorter than mc_count? */
439 /* paranoia: bad address size in list? */
440 BUG_ON(p->dmi_addrlen != ETH_ALEN);
442 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
447 printk(KERN_WARNING "%s: Multicast list is "
448 "longer than mc_count\n", priv->ndev->name);
450 err = hermes_write_ltv(hw, USER_BAP,
451 HERMES_RID_CNFGROUPADDRESSES,
452 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
455 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
456 priv->ndev->name, err);
458 priv->mc_count = mc_count;
463 /* Return : < 0 -> error code ; >= 0 -> length */
464 int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
465 char buf[IW_ESSID_MAX_SIZE+1])
467 hermes_t *hw = &priv->hw;
469 struct hermes_idstring essidbuf;
470 char *p = (char *)(&essidbuf.val);
474 if (orinoco_lock(priv, &flags) != 0)
477 if (strlen(priv->desired_essid) > 0) {
478 /* We read the desired SSID from the hardware rather
479 than from priv->desired_essid, just in case the
480 firmware is allowed to change it on us. I'm not
482 /* My guess is that the OWNSSID should always be whatever
483 * we set to the card, whereas CURRENT_SSID is the one that
484 * may change... - Jean II */
489 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
490 HERMES_RID_CNFDESIREDSSID;
492 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
499 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
500 sizeof(essidbuf), NULL, &essidbuf);
505 len = le16_to_cpu(essidbuf.len);
506 BUG_ON(len > IW_ESSID_MAX_SIZE);
508 memset(buf, 0, IW_ESSID_MAX_SIZE);
513 orinoco_unlock(priv, &flags);
518 int orinoco_hw_get_freq(struct orinoco_private *priv)
520 hermes_t *hw = &priv->hw;
526 if (orinoco_lock(priv, &flags) != 0)
529 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
534 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
540 if ((channel < 1) || (channel > NUM_CHANNELS)) {
541 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
542 priv->ndev->name, channel);
547 freq = ieee80211_dsss_chan_to_freq(channel);
550 orinoco_unlock(priv, &flags);
554 return err ? err : freq;
557 int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
558 int *numrates, s32 *rates, int max)
560 hermes_t *hw = &priv->hw;
561 struct hermes_idstring list;
562 unsigned char *p = (unsigned char *)&list.val;
568 if (orinoco_lock(priv, &flags) != 0)
571 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
572 sizeof(list), NULL, &list);
573 orinoco_unlock(priv, &flags);
578 num = le16_to_cpu(list.len);
582 for (i = 0; i < num; i++)
583 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */