summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2005-03-20 04:21:56 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2005-03-20 04:21:56 +0000
commit3a055a6eeeb7007a188f09910d2a947f3a0a4daa (patch)
treee7e03f4244d77d55ebf3f46a25639130a2414a8f /sys/dev/ic
parentde6b5a33f143a91a058e47a2024a2c45ebd708b8 (diff)
some fixes for wep and reset.
btw.: this is a commit using an ar5212 in 11b mode... ok deraadt@, krw@
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/ar5210.c83
-rw-r--r--sys/dev/ic/ar5210reg.h8
-rw-r--r--sys/dev/ic/ar5211.c82
-rw-r--r--sys/dev/ic/ar5211reg.h8
-rw-r--r--sys/dev/ic/ar5212.c100
-rw-r--r--sys/dev/ic/ar5212reg.h10
-rw-r--r--sys/dev/ic/ar5212var.h6
-rw-r--r--sys/dev/ic/ar5xxx.c11
-rw-r--r--sys/dev/ic/ar5xxx.h4
9 files changed, 135 insertions, 177 deletions
diff --git a/sys/dev/ic/ar5210.c b/sys/dev/ic/ar5210.c
index 6f468a57d4d..85f85b673d0 100644
--- a/sys/dev/ic/ar5210.c
+++ b/sys/dev/ic/ar5210.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5210.c,v 1.15 2005/03/18 14:36:39 reyk Exp $ */
+/* $OpenBSD: ar5210.c,v 1.16 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -1877,7 +1877,7 @@ u_int32_t
ar5k_ar5210_getKeyCacheSize(hal)
struct ath_hal *hal;
{
- return (AR5K_AR5210_KEYTABLE_SIZE);
+ return (AR5K_AR5210_KEYCACHE_SIZE);
}
HAL_BOOL
@@ -1890,7 +1890,7 @@ ar5k_ar5210_resetKeyCacheEntry(hal, entry)
AR5K_ASSERT_ENTRY(entry, AR5K_AR5210_KEYTABLE_SIZE);
for (i = 0; i < AR5K_AR5210_KEYCACHE_SIZE; i++)
- AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE(entry) + (i << 2), 0);
+ AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE_OFF(entry, i), 0);
return (AH_FALSE);
}
@@ -1900,17 +1900,14 @@ ar5k_ar5210_isKeyCacheEntryValid(hal, entry)
struct ath_hal *hal;
u_int16_t entry;
{
- int offset;
-
AR5K_ASSERT_ENTRY(entry, AR5K_AR5210_KEYTABLE_SIZE);
/*
* Check the validation flag at the end of the entry
*/
- offset = (AR5K_AR5210_KEYCACHE_SIZE - 1) << 2;
- if (AR5K_REG_READ(AR5K_AR5210_KEYTABLE(entry) + offset) &
+ if (AR5K_REG_READ(AR5K_AR5210_KEYTABLE_MAC1(entry)) &
AR5K_AR5210_KEYTABLE_VALID)
- return AH_TRUE;
+ return (AH_TRUE);
return (AH_FALSE);
}
@@ -1923,26 +1920,36 @@ ar5k_ar5210_setKeyCacheEntry(hal, entry, keyval, mac, xor_notused)
const u_int8_t *mac;
int xor_notused;
{
- int elements = AR5K_AR5210_KEYCACHE_SIZE - 2;
+ int elements = AR5K_AR5210_KEYCACHE_SIZE - 2, i;
u_int32_t key_v[elements];
- int i, offset = 0;
AR5K_ASSERT_ENTRY(entry, AR5K_AR5210_KEYTABLE_SIZE);
- /*
- * Store the key type in the last field
- */
+ bzero(&key_v, sizeof(key_v));
+
switch (keyval->wk_len) {
case 5:
- key_v[elements - 1] = AR5K_AR5210_KEYTABLE_TYPE_40;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 1);
+ key_v[5] = AR5K_AR5210_KEYTABLE_TYPE_40;
break;
case 13:
- key_v[elements - 1] = AR5K_AR5210_KEYTABLE_TYPE_104;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 2);
+ bcopy(keyval->wk_key + 6, &key_v[2], 4);
+ bcopy(keyval->wk_key + 10, &key_v[3], 2);
+ bcopy(keyval->wk_key + 12, &key_v[4], 1);
+ key_v[5] = AR5K_AR5210_KEYTABLE_TYPE_104;
break;
case 16:
- key_v[elements - 1] = AR5K_AR5210_KEYTABLE_TYPE_128;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 2);
+ bcopy(keyval->wk_key + 6, &key_v[2], 4);
+ bcopy(keyval->wk_key + 10, &key_v[3], 2);
+ bcopy(keyval->wk_key + 12, &key_v[4], 4);
+ key_v[5] = AR5K_AR5210_KEYTABLE_TYPE_128;
break;
default:
@@ -1950,29 +1957,8 @@ ar5k_ar5210_setKeyCacheEntry(hal, entry, keyval, mac, xor_notused)
return (AH_FALSE);
}
- /*
- * Write key cache entry
- */
- for (i = 0; i < elements; i++) {
- if (elements < 5) {
- if (i % 2) {
- key_v[i] = AR5K_LE_READ_2(keyval->wk_key +
- offset) & 0xffff;
- offset += 2;
- } else {
- key_v[i] = AR5K_LE_READ_4(keyval->wk_key +
- offset);
- offset += 4;
- }
-
- if (i == 4 && keyval->wk_len <= 13)
- key_v[i] &= 0xff;
- }
-
- /* Write value */
- AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE(entry) + (i << 2),
- key_v[i]);
- }
+ for (i = 0; i < elements; i++)
+ AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE_OFF(entry, i), key_v[i]);
return (ar5k_ar5210_setKeyCacheEntryMac(hal, entry, mac));
}
@@ -1984,27 +1970,22 @@ ar5k_ar5210_setKeyCacheEntryMac(hal, entry, mac)
const u_int8_t *mac;
{
u_int32_t low_id, high_id;
- int offset;
+ const u_int8_t *mac_v;
/*
* Invalid entry (key table overflow)
*/
AR5K_ASSERT_ENTRY(entry, AR5K_AR5210_KEYTABLE_SIZE);
- offset = AR5K_AR5210_KEYCACHE_SIZE - 2;
- low_id = high_id = 0;
-
/* MAC may be NULL if it's a broadcast key */
- if (mac != NULL) {
- bcopy(mac, &low_id, 4);
- bcopy(mac + 4, &high_id, 2);
- }
+ mac_v = mac == NULL ? etherbroadcastaddr : mac;
- high_id = 0x0000ffff & htole32(high_id);
+ bcopy(mac_v, &low_id, 4);
+ bcopy(mac_v + 4, &high_id, 2);
+ high_id |= AR5K_AR5210_KEYTABLE_VALID;
- AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE(entry) + (offset++ << 2),
- htole32(low_id));
- AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE(entry) + (offset << 2), high_id);
+ AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE_MAC0(entry), htole32(low_id));
+ AR5K_REG_WRITE(AR5K_AR5210_KEYTABLE_MAC1(entry), htole32(high_id));
return (AH_TRUE);
}
diff --git a/sys/dev/ic/ar5210reg.h b/sys/dev/ic/ar5210reg.h
index 2213f9ac6b8..4adf1011745 100644
--- a/sys/dev/ic/ar5210reg.h
+++ b/sys/dev/ic/ar5210reg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5210reg.h,v 1.7 2005/02/17 23:52:05 reyk Exp $ */
+/* $OpenBSD: ar5210reg.h,v 1.8 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -603,10 +603,14 @@ typedef enum {
* Key table (WEP) register
*/
#define AR5K_AR5210_KEYTABLE_0 0x9000
-#define AR5K_AR5210_KEYTABLE(n) (AR5K_AR5210_KEYTABLE_0 + ((n) * 32))
+#define AR5K_AR5210_KEYTABLE(n) (AR5K_AR5210_KEYTABLE_0 + ((n) << 5))
+#define AR5K_AR5210_KEYTABLE_OFF(_n, x) (AR5K_AR5210_KEYTABLE(_n) + (x << 2))
+#define AR5K_AR5210_KEYTABLE_TYPE(_n) AR5K_AR5210_KEYTABLE_OFF(_n, 5)
#define AR5K_AR5210_KEYTABLE_TYPE_40 0x00000000
#define AR5K_AR5210_KEYTABLE_TYPE_104 0x00000001
#define AR5K_AR5210_KEYTABLE_TYPE_128 0x00000003
+#define AR5K_AR5210_KEYTABLE_MAC0(_n) AR5K_AR5210_KEYTABLE_OFF(_n, 6)
+#define AR5K_AR5210_KEYTABLE_MAC1(_n) AR5K_AR5210_KEYTABLE_OFF(_n, 7)
#define AR5K_AR5210_KEYTABLE_VALID 0x00008000
#define AR5K_AR5210_KEYTABLE_SIZE 64
diff --git a/sys/dev/ic/ar5211.c b/sys/dev/ic/ar5211.c
index 7c90537554b..6d361e60226 100644
--- a/sys/dev/ic/ar5211.c
+++ b/sys/dev/ic/ar5211.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5211.c,v 1.5 2005/03/19 17:27:46 reyk Exp $ */
+/* $OpenBSD: ar5211.c,v 1.6 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -1946,7 +1946,7 @@ u_int32_t
ar5k_ar5211_getKeyCacheSize(hal)
struct ath_hal *hal;
{
- return (AR5K_AR5211_KEYTABLE_SIZE);
+ return (AR5K_AR5211_KEYCACHE_SIZE);
}
HAL_BOOL
@@ -1959,7 +1959,7 @@ ar5k_ar5211_resetKeyCacheEntry(hal, entry)
AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
for (i = 0; i < AR5K_AR5211_KEYCACHE_SIZE; i++)
- AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE(entry) + (i * 4), 0);
+ AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_OFF(entry, i), 0);
return (AH_FALSE);
}
@@ -1969,17 +1969,14 @@ ar5k_ar5211_isKeyCacheEntryValid(hal, entry)
struct ath_hal *hal;
u_int16_t entry;
{
- int offset;
-
AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
/*
* Check the validation flag at the end of the entry
*/
- offset = (AR5K_AR5211_KEYCACHE_SIZE - 1) * 4;
- if (AR5K_REG_READ(AR5K_AR5211_KEYTABLE(entry) + offset) &
+ if (AR5K_REG_READ(AR5K_AR5211_KEYTABLE_MAC1(entry)) &
AR5K_AR5211_KEYTABLE_VALID)
- return AH_TRUE;
+ return (AH_TRUE);
return (AH_FALSE);
}
@@ -1992,26 +1989,36 @@ ar5k_ar5211_setKeyCacheEntry(hal, entry, keyval, mac, xor_notused)
const u_int8_t *mac;
int xor_notused;
{
- int elements = AR5K_AR5211_KEYCACHE_SIZE - 2;
+ int elements = AR5K_AR5211_KEYCACHE_SIZE - 2, i;
u_int32_t key_v[elements];
- int i, offset = 0;
AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
- /*
- * Store the key type in the last field
- */
+ bzero(&key_v, sizeof(key_v));
+
switch (keyval->wk_len) {
case 5:
- key_v[elements - 1] = AR5K_AR5211_KEYTABLE_TYPE_40;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 1);
+ key_v[5] = AR5K_AR5211_KEYTABLE_TYPE_40;
break;
case 13:
- key_v[elements - 1] = AR5K_AR5211_KEYTABLE_TYPE_104;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 2);
+ bcopy(keyval->wk_key + 6, &key_v[2], 4);
+ bcopy(keyval->wk_key + 10, &key_v[3], 2);
+ bcopy(keyval->wk_key + 12, &key_v[4], 1);
+ key_v[5] = AR5K_AR5211_KEYTABLE_TYPE_104;
break;
case 16:
- key_v[elements - 1] = AR5K_AR5211_KEYTABLE_TYPE_128;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 2);
+ bcopy(keyval->wk_key + 6, &key_v[2], 4);
+ bcopy(keyval->wk_key + 10, &key_v[3], 2);
+ bcopy(keyval->wk_key + 12, &key_v[4], 4);
+ key_v[5] = AR5K_AR5211_KEYTABLE_TYPE_128;
break;
default:
@@ -2019,28 +2026,8 @@ ar5k_ar5211_setKeyCacheEntry(hal, entry, keyval, mac, xor_notused)
return (AH_FALSE);
}
- /*
- * Write key cache entry
- */
- for (i = 0; i < elements; i++) {
- if (elements < 5) {
- if (i % 2) {
- key_v[i] = AR5K_LE_READ_2(keyval->wk_key +
- offset) & 0xffff;
- offset += 2;
- } else {
- key_v[i] = AR5K_LE_READ_4(keyval->wk_key +
- offset);
- offset += 4;
- }
-
- if (i == 4 && keyval->wk_len <= 13)
- key_v[i] &= 0xff;
- }
-
- /* Write value */
- AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE(entry) + (i * 4), key_v[i]);
- }
+ for (i = 0; i < elements; i++)
+ AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_OFF(entry, i), key_v[i]);
return (ar5k_ar5211_setKeyCacheEntryMac(hal, entry, mac));
}
@@ -2052,27 +2039,22 @@ ar5k_ar5211_setKeyCacheEntryMac(hal, entry, mac)
const u_int8_t *mac;
{
u_int32_t low_id, high_id;
- int offset;
+ const u_int8_t *mac_v;
/*
* Invalid entry (key table overflow)
*/
AR5K_ASSERT_ENTRY(entry, AR5K_AR5211_KEYTABLE_SIZE);
- offset = AR5K_AR5211_KEYCACHE_SIZE - 2;
- low_id = high_id = 0;
-
/* MAC may be NULL if it's a broadcast key */
- if (mac != NULL) {
- bcopy(mac, &low_id, 4);
- bcopy(mac + 4, &high_id, 2);
- }
+ mac_v = mac == NULL ? etherbroadcastaddr : mac;
- high_id = 0x0000ffff & htole32(high_id);
+ bcopy(mac_v, &low_id, 4);
+ bcopy(mac_v + 4, &high_id, 2);
+ high_id |= AR5K_AR5211_KEYTABLE_VALID;
- AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE(entry) + (offset++ * 4),
- htole32(low_id));
- AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE(entry) + (offset * 4), high_id);
+ AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_MAC0(entry), htole32(low_id));
+ AR5K_REG_WRITE(AR5K_AR5211_KEYTABLE_MAC1(entry), htole32(high_id));
return (AH_TRUE);
}
diff --git a/sys/dev/ic/ar5211reg.h b/sys/dev/ic/ar5211reg.h
index 7ffe70b110f..05135bd5ea1 100644
--- a/sys/dev/ic/ar5211reg.h
+++ b/sys/dev/ic/ar5211reg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5211reg.h,v 1.3 2005/03/19 17:27:46 reyk Exp $ */
+/* $OpenBSD: ar5211reg.h,v 1.4 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -890,14 +890,18 @@ typedef enum {
*/
#define AR5K_AR5211_KEYTABLE_0 0x8800
#define AR5K_AR5211_KEYTABLE(n) (AR5K_AR5211_KEYTABLE_0 + ((n) * 32))
+#define AR5K_AR5211_KEYTABLE_OFF(_n, x) (AR5K_AR5211_KEYTABLE(_n) + (x << 2))
+#define AR5K_AR5211_KEYTABLE_TYPE(_n) AR5K_AR5211_KEYTABLE_OFF(_n, 5)
#define AR5K_AR5211_KEYTABLE_TYPE_40 0x00000000
#define AR5K_AR5211_KEYTABLE_TYPE_104 0x00000001
#define AR5K_AR5211_KEYTABLE_TYPE_128 0x00000003
#define AR5K_AR5211_KEYTABLE_TYPE_AES 0x00000005
#define AR5K_AR5211_KEYTABLE_TYPE_NULL 0x00000007
+#define AR5K_AR5211_KEYTABLE_MAC0(_n) AR5K_AR5211_KEYTABLE_OFF(_n, 6)
+#define AR5K_AR5211_KEYTABLE_MAC1(_n) AR5K_AR5211_KEYTABLE_OFF(_n, 7)
#define AR5K_AR5211_KEYTABLE_VALID 0x00008000
-#define AR5K_AR5211_KEYTABLE_SIZE 64
+#define AR5K_AR5211_KEYTABLE_SIZE 128
#define AR5K_AR5211_KEYCACHE_SIZE 8
/*
diff --git a/sys/dev/ic/ar5212.c b/sys/dev/ic/ar5212.c
index 496b4e5e1e2..76f781e64f4 100644
--- a/sys/dev/ic/ar5212.c
+++ b/sys/dev/ic/ar5212.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5212.c,v 1.9 2005/03/19 18:21:31 reyk Exp $ */
+/* $OpenBSD: ar5212.c,v 1.10 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -430,7 +430,7 @@ ar5k_ar5212_reset(hal, op_mode, channel, change_channel, status)
struct ar5k_eeprom_info *ee = &hal->ah_capabilities.cap_eeprom;
u_int8_t mac[IEEE80211_ADDR_LEN];
u_int32_t data, s_seq, s_ant, s_led[3];
- u_int i, phy, mode, freq, ee_mode, ant[2];
+ u_int i, phy, mode, freq, off, ee_mode, ant[2];
const HAL_RATE_TABLE *rt;
/*
@@ -506,19 +506,19 @@ ar5k_ar5212_reset(hal, op_mode, channel, change_channel, status)
*/
for (i = 0; i < AR5K_ELEMENTS(ar5212_mode); i++) {
if (ar5212_mode[i].mode_flags == AR5K_INI_FLAG_511X)
- phy = AR5K_INI_PHY_511X;
+ off = AR5K_INI_PHY_511X;
else if (ar5212_mode[i].mode_flags & AR5K_INI_FLAG_5111 &&
hal->ah_radio == AR5K_AR5111)
- phy = AR5K_INI_PHY_5111;
+ off = AR5K_INI_PHY_5111;
else if (ar5212_mode[i].mode_flags & AR5K_INI_FLAG_5112 &&
hal->ah_radio == AR5K_AR5112)
- phy = AR5K_INI_PHY_5112;
+ off = AR5K_INI_PHY_5112;
else
continue;
AR5K_REG_WAIT(i);
AR5K_REG_WRITE((u_int32_t)ar5212_mode[i].mode_register,
- ar5212_mode[i].mode_value[phy][mode]);
+ ar5212_mode[i].mode_value[off][mode]);
}
/*
@@ -630,7 +630,7 @@ ar5k_ar5212_reset(hal, op_mode, channel, change_channel, status)
if (hal->ah_ant_diversity == AH_FALSE) {
if (freq == AR5K_INI_RFGAIN_2GHZ)
ant[0] = HAL_ANT_FIXED_B;
- else if (freq == AR5K_INI_RFGAIN_5GHZ)
+ else
ant[1] = HAL_ANT_FIXED_A;
}
@@ -640,7 +640,7 @@ ar5k_ar5212_reset(hal, op_mode, channel, change_channel, status)
hal->ah_antenna[ee_mode][ant[1]]);
/* Commit values from EEPROM */
- if (hal->ah_radio == AR5K_AR5112)
+ if (hal->ah_radio == AR5K_AR5111)
AR5K_REG_WRITE_BITS(AR5K_AR5212_PHY_FC,
AR5K_AR5212_PHY_FC_TX_CLIP, ee->ee_tx_clip);
@@ -2225,7 +2225,7 @@ u_int32_t
ar5k_ar5212_getKeyCacheSize(hal)
struct ath_hal *hal;
{
- return (AR5K_AR5212_KEYTABLE_SIZE);
+ return (AR5K_AR5212_KEYCACHE_SIZE);
}
HAL_BOOL
@@ -2238,7 +2238,11 @@ ar5k_ar5212_resetKeyCacheEntry(hal, entry)
AR5K_ASSERT_ENTRY(entry, AR5K_AR5212_KEYTABLE_SIZE);
for (i = 0; i < AR5K_AR5212_KEYCACHE_SIZE; i++)
- AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE(entry) + (i * 4), 0);
+ AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE_OFF(entry, i), 0);
+
+ /* Set NULL encryption */
+ AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE_TYPE(entry),
+ AR5K_AR5212_KEYTABLE_TYPE_NULL);
return (AH_FALSE);
}
@@ -2248,17 +2252,14 @@ ar5k_ar5212_isKeyCacheEntryValid(hal, entry)
struct ath_hal *hal;
u_int16_t entry;
{
- int offset;
-
AR5K_ASSERT_ENTRY(entry, AR5K_AR5212_KEYTABLE_SIZE);
/*
* Check the validation flag at the end of the entry
*/
- offset = (AR5K_AR5212_KEYCACHE_SIZE - 1) * 4;
- if (AR5K_REG_READ(AR5K_AR5212_KEYTABLE(entry) + offset) &
+ if (AR5K_REG_READ(AR5K_AR5212_KEYTABLE_MAC1(entry)) &
AR5K_AR5212_KEYTABLE_VALID)
- return AH_TRUE;
+ return (AH_TRUE);
return (AH_FALSE);
}
@@ -2271,26 +2272,36 @@ ar5k_ar5212_setKeyCacheEntry(hal, entry, keyval, mac, xor_notused)
const u_int8_t *mac;
int xor_notused;
{
- int elements = AR5K_AR5212_KEYCACHE_SIZE - 2;
+ int elements = AR5K_AR5212_KEYCACHE_SIZE - 2, i;
u_int32_t key_v[elements];
- int i, offset = 0;
AR5K_ASSERT_ENTRY(entry, AR5K_AR5212_KEYTABLE_SIZE);
- /*
- * Store the key type in the last field
- */
+ bzero(&key_v, sizeof(key_v));
+
switch (keyval->wk_len) {
case 5:
- key_v[elements - 1] = AR5K_AR5212_KEYTABLE_TYPE_40;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 1);
+ key_v[5] = AR5K_AR5212_KEYTABLE_TYPE_40;
break;
case 13:
- key_v[elements - 1] = AR5K_AR5212_KEYTABLE_TYPE_104;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 2);
+ bcopy(keyval->wk_key + 6, &key_v[2], 4);
+ bcopy(keyval->wk_key + 10, &key_v[3], 2);
+ bcopy(keyval->wk_key + 12, &key_v[4], 1);
+ key_v[5] = AR5K_AR5212_KEYTABLE_TYPE_104;
break;
case 16:
- key_v[elements - 1] = AR5K_AR5212_KEYTABLE_TYPE_128;
+ bcopy(keyval->wk_key, &key_v[0], 4);
+ bcopy(keyval->wk_key + 4, &key_v[1], 2);
+ bcopy(keyval->wk_key + 6, &key_v[2], 4);
+ bcopy(keyval->wk_key + 10, &key_v[3], 2);
+ bcopy(keyval->wk_key + 12, &key_v[4], 4);
+ key_v[5] = AR5K_AR5212_KEYTABLE_TYPE_128;
break;
default:
@@ -2298,28 +2309,8 @@ ar5k_ar5212_setKeyCacheEntry(hal, entry, keyval, mac, xor_notused)
return (AH_FALSE);
}
- /*
- * Write key cache entry
- */
- for (i = 0; i < elements; i++) {
- if (elements < 5) {
- if (i % 2) {
- key_v[i] = AR5K_LE_READ_2(keyval->wk_key +
- offset) & 0xffff;
- offset += 2;
- } else {
- key_v[i] = AR5K_LE_READ_4(keyval->wk_key +
- offset);
- offset += 4;
- }
-
- if (i == 4 && keyval->wk_len <= 13)
- key_v[i] &= 0xff;
- }
-
- /* Write value */
- AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE(entry) + (i * 4), key_v[i]);
- }
+ for (i = 0; i < elements; i++)
+ AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE_OFF(entry, i), key_v[i]);
return (ar5k_ar5212_setKeyCacheEntryMac(hal, entry, mac));
}
@@ -2331,27 +2322,22 @@ ar5k_ar5212_setKeyCacheEntryMac(hal, entry, mac)
const u_int8_t *mac;
{
u_int32_t low_id, high_id;
- int offset;
+ const u_int8_t *mac_v;
/*
* Invalid entry (key table overflow)
*/
AR5K_ASSERT_ENTRY(entry, AR5K_AR5212_KEYTABLE_SIZE);
- offset = AR5K_AR5212_KEYCACHE_SIZE - 2;
- low_id = high_id = 0;
-
/* MAC may be NULL if it's a broadcast key */
- if (mac != NULL) {
- bcopy(mac, &low_id, 4);
- bcopy(mac + 4, &high_id, 2);
- }
+ mac_v = mac == NULL ? etherbroadcastaddr : mac;
- high_id = 0x0000ffff & htole32(high_id);
+ bcopy(mac_v, &low_id, 4);
+ bcopy(mac_v + 4, &high_id, 2);
+ high_id |= AR5K_AR5212_KEYTABLE_VALID;
- AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE(entry) + (offset++ * 4),
- htole32(low_id));
- AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE(entry) + (offset * 4), high_id);
+ AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE_MAC0(entry), htole32(low_id));
+ AR5K_REG_WRITE(AR5K_AR5212_KEYTABLE_MAC1(entry), htole32(high_id));
return (AH_TRUE);
}
diff --git a/sys/dev/ic/ar5212reg.h b/sys/dev/ic/ar5212reg.h
index 89cca021405..7f11d5de49d 100644
--- a/sys/dev/ic/ar5212reg.h
+++ b/sys/dev/ic/ar5212reg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5212reg.h,v 1.3 2005/03/18 20:46:32 reyk Exp $ */
+/* $OpenBSD: ar5212reg.h,v 1.4 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -1010,7 +1010,9 @@ typedef enum {
* Key table (WEP) register
*/
#define AR5K_AR5212_KEYTABLE_0 0x8800
-#define AR5K_AR5212_KEYTABLE(n) (AR5K_AR5212_KEYTABLE_0 + ((n) * 32))
+#define AR5K_AR5212_KEYTABLE(_n) (AR5K_AR5212_KEYTABLE_0 + ((_n) << 5))
+#define AR5K_AR5212_KEYTABLE_OFF(_n, x) (AR5K_AR5212_KEYTABLE(_n) + (x << 2))
+#define AR5K_AR5212_KEYTABLE_TYPE(_n) AR5K_AR5212_KEYTABLE_OFF(_n, 5)
#define AR5K_AR5212_KEYTABLE_TYPE_40 0x00000000
#define AR5K_AR5212_KEYTABLE_TYPE_104 0x00000001
#define AR5K_AR5212_KEYTABLE_TYPE_128 0x00000003
@@ -1019,9 +1021,11 @@ typedef enum {
#define AR5K_AR5212_KEYTABLE_TYPE_CCM 0x00000006
#define AR5K_AR5212_KEYTABLE_TYPE_NULL 0x00000007
#define AR5K_AR5212_KEYTABLE_ANTENNA 0x00000008
+#define AR5K_AR5212_KEYTABLE_MAC0(_n) AR5K_AR5212_KEYTABLE_OFF(_n, 6)
+#define AR5K_AR5212_KEYTABLE_MAC1(_n) AR5K_AR5212_KEYTABLE_OFF(_n, 7)
#define AR5K_AR5212_KEYTABLE_VALID 0x00008000
-#define AR5K_AR5212_KEYTABLE_SIZE 64
+#define AR5K_AR5212_KEYTABLE_SIZE 128
#define AR5K_AR5212_KEYCACHE_SIZE 8
/*
diff --git a/sys/dev/ic/ar5212var.h b/sys/dev/ic/ar5212var.h
index 366b569dab0..76c0d8033d7 100644
--- a/sys/dev/ic/ar5212var.h
+++ b/sys/dev/ic/ar5212var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5212var.h,v 1.3 2005/03/10 08:30:56 reyk Exp $ */
+/* $OpenBSD: ar5212var.h,v 1.4 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -233,7 +233,6 @@ struct ar5k_ar5212_ini {
{ AR5K_INI_FLAG_BOTH, 0x004c, 0x00000010 }, \
{ AR5K_INI_FLAG_BOTH, 0x0050, 0x00000000 }, \
{ AR5K_INI_FLAG_BOTH, 0x0054, 0x0000001f }, \
- { AR5K_INI_FLAG_BOTH, 0x0400, 0x0000000e }, \
{ AR5K_INI_FLAG_BOTH, 0x0800, 0x00000000 }, \
{ AR5K_INI_FLAG_BOTH, 0x0804, 0x00000000 }, \
{ AR5K_INI_FLAG_BOTH, 0x0808, 0x00000000 }, \
@@ -299,7 +298,6 @@ struct ar5k_ar5212_ini {
{ AR5K_INI_FLAG_BOTH, 0x8004, 0x00000000 }, \
{ AR5K_INI_FLAG_BOTH, 0x8008, 0x00000000 }, \
{ AR5K_INI_FLAG_BOTH, 0x800c, 0x00000000 }, \
- { AR5K_INI_FLAG_BOTH, 0x8014, 0x08400840 }, \
{ AR5K_INI_FLAG_BOTH, 0x8018, 0x00000000 }, \
{ AR5K_INI_FLAG_BOTH, 0x8020, 0x00000000 }, \
{ AR5K_INI_FLAG_BOTH, 0x8024, 0x00000000 }, \
@@ -695,7 +693,7 @@ struct ar5k_ar5212_ini_mode {
} }, \
{ 0x9860, AR5K_INI_FLAG_511X, { \
{ 0, }, \
- { 0x00009d10, 0x00009d10, 0x00009d18, 0x00009d18, 0x00009d10 } \
+ { 0x00009d10, 0x00009d10, 0x00009d10, 0x00009d10, 0x00009d10 } \
} }, \
{ 0x9864, AR5K_INI_FLAG_511X, { \
{ 0, }, \
diff --git a/sys/dev/ic/ar5xxx.c b/sys/dev/ic/ar5xxx.c
index d08a9534548..654732a95b4 100644
--- a/sys/dev/ic/ar5xxx.c
+++ b/sys/dev/ic/ar5xxx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5xxx.c,v 1.19 2005/03/19 17:27:46 reyk Exp $ */
+/* $OpenBSD: ar5xxx.c,v 1.20 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -459,8 +459,7 @@ ath_hal_init_channels(hal, channels, max_channels, channels_size, country, mode,
* and mode. 5GHz...
*/
for (i = 0; (hal->ah_capabilities.cap_range.range_5ghz_max > 0) &&
- (i < (sizeof(ar5k_5ghz_channels) /
- sizeof(ar5k_5ghz_channels[0]))) &&
+ (i < AR5K_ELEMENTS(ar5k_5ghz_channels)) &&
(c < max_channels); i++) {
/* Check if channel is supported by the chipset */
if (ar5k_check_channel(hal,
@@ -479,7 +478,8 @@ ath_hal_init_channels(hal, channels, max_channels, channels_size, country, mode,
} else if (ar5k_5ghz_channels[i].rc_mode &
IEEE80211_CHAN_OFDM) {
all_channels[c].c_channel_flags = CHANNEL_A;
- }
+ } else
+ continue;
/* Write channel and increment counter */
all_channels[c++].channel = ar5k_5ghz_channels[i].rc_channel;
@@ -489,8 +489,7 @@ ath_hal_init_channels(hal, channels, max_channels, channels_size, country, mode,
* ...and 2GHz.
*/
for (i = 0; (hal->ah_capabilities.cap_range.range_2ghz_max > 0) &&
- (i < (sizeof(ar5k_2ghz_channels) /
- sizeof(ar5k_2ghz_channels[0]))) &&
+ (i < AR5K_ELEMENTS(ar5k_2ghz_channels)) &&
(c < max_channels); i++) {
/* Check if channel is supported by the chipset */
if (ar5k_check_channel(hal,
diff --git a/sys/dev/ic/ar5xxx.h b/sys/dev/ic/ar5xxx.h
index e448bd15607..de4723bfef2 100644
--- a/sys/dev/ic/ar5xxx.h
+++ b/sys/dev/ic/ar5xxx.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5xxx.h,v 1.14 2005/03/19 17:27:46 reyk Exp $ */
+/* $OpenBSD: ar5xxx.h,v 1.15 2005/03/20 04:21:55 reyk Exp $ */
/*
* Copyright (c) 2004, 2005 Reyk Floeter <reyk@vantronix.net>
@@ -452,7 +452,7 @@ typedef struct {
#define CHANNEL_A (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
#define CHANNEL_B (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
-#define CHANNEL_G (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM) /* _DYN */
+#define CHANNEL_G (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
#define CHANNEL_PUREG (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
#define CHANNEL_T (CHANNEL_A | IEEE80211_CHAN_TURBO)
#define CHANNEL_TG (CHANNEL_PUREG | IEEE80211_CHAN_TURBO)