aboutsummaryrefslogtreecommitdiffstats
path: root/src/drivers/driver_bsd.c
diff options
context:
space:
mode:
authorZhu Yi <yi.zhu@atheros.com>2011-06-23 12:47:21 (GMT)
committerJouni Malinen <j@w1.fi>2011-06-23 12:47:21 (GMT)
commitc3b0a1c8ad694af367026d5236b725e9594677b8 (patch)
treebd6f539a0005c8a9389268e58a604f579005d03a /src/drivers/driver_bsd.c
parent29fbc52251e37d2981033978693050c62d801138 (diff)
downloadhostap-c3b0a1c8ad694af367026d5236b725e9594677b8.zip
hostap-c3b0a1c8ad694af367026d5236b725e9594677b8.tar.gz
hostap-c3b0a1c8ad694af367026d5236b725e9594677b8.tar.bz2
bsd: Fix set_key() sequence number endian issue
In set_key handler, the seq[8] is in little endian order defined by WPA. BSD kernel uses a u_int64_t value ik_keyrsc to represent it internally. The kernel expects the native endian order for the value. Thus, we need to detect the endian order and swap bytes when necessary.
Diffstat (limited to 'src/drivers/driver_bsd.c')
-rw-r--r--src/drivers/driver_bsd.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/drivers/driver_bsd.c b/src/drivers/driver_bsd.c
index 1b52865..4596a51 100644
--- a/src/drivers/driver_bsd.c
+++ b/src/drivers/driver_bsd.c
@@ -345,8 +345,20 @@ bsd_set_key(const char *ifname, void *priv, enum wpa_alg alg,
if (wk.ik_keyix != IEEE80211_KEYIX_NONE && set_tx)
wk.ik_flags |= IEEE80211_KEY_DEFAULT;
wk.ik_keylen = key_len;
- if (seq)
+ if (seq) {
+#ifdef WORDS_BIGENDIAN
+ /*
+ * wk.ik_keyrsc is in host byte order (big endian), need to
+ * swap it to match with the byte order used in WPA.
+ */
+ int i;
+ u8 *keyrsc = (u8 *) &wk.ik_keyrsc;
+ for (i = 0; i < seq_len; i++)
+ keyrsc[WPA_KEY_RSC_LEN - i - 1] = seq[i];
+#else /* WORDS_BIGENDIAN */
os_memcpy(&wk.ik_keyrsc, seq, seq_len);
+#endif /* WORDS_BIGENDIAN */
+ }
os_memcpy(wk.ik_keydata, key, key_len);
return set80211var(priv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));