summaryrefslogtreecommitdiffstats
path: root/tools/regression/net80211/wep
diff options
context:
space:
mode:
authoravos <avos@FreeBSD.org>2015-10-22 17:08:12 +0000
committeravos <avos@FreeBSD.org>2015-10-22 17:08:12 +0000
commit640ff9e50a5d983146a4e77b35f1c1431a763c17 (patch)
tree0e02b161e64b53448b42eb12d2c0f11fc93956d5 /tools/regression/net80211/wep
parente7b0d632512d9d47cda7fb808874b6759c396f53 (diff)
downloadFreeBSD-src-640ff9e50a5d983146a4e77b35f1c1431a763c17.zip
FreeBSD-src-640ff9e50a5d983146a4e77b35f1c1431a763c17.tar.gz
Unbreak regression testing tools for net80211 crypto cipher modules
Approved by: adrian (mentor) Differential Revision: https://reviews.freebsd.org/D3441
Diffstat (limited to 'tools/regression/net80211/wep')
-rw-r--r--tools/regression/net80211/wep/test_wep.c69
1 files changed, 43 insertions, 26 deletions
diff --git a/tools/regression/net80211/wep/test_wep.c b/tools/regression/net80211/wep/test_wep.c
index ba6cd46..c156863 100644
--- a/tools/regression/net80211/wep/test_wep.c
+++ b/tools/regression/net80211/wep/test_wep.c
@@ -53,6 +53,7 @@
#include <sys/socket.h>
#include <net/if.h>
+#include <net/if_var.h>
#include <net/if_media.h>
#include <net80211/ieee80211_var.h>
@@ -178,54 +179,55 @@ cmpfail(const void *gen, size_t genlen, const void *ref, size_t reflen)
}
struct wep_ctx_hw { /* for use with h/w support */
- struct ieee80211com *wc_ic; /* for diagnostics */
- u_int32_t wc_iv; /* initial vector for crypto */
+ struct ieee80211vap *wc_vap; /* for diagnostics+statistics */
+ struct ieee80211com *wc_ic;
+ uint32_t wc_iv; /* initial vector for crypto */
};
static int
-runtest(struct ieee80211com *ic, struct ciphertest *t)
+runtest(struct ieee80211vap *vap, struct ciphertest *t)
{
- struct ieee80211_key key;
+ struct ieee80211_key *key = &vap->iv_nw_keys[t->keyix];
struct mbuf *m = NULL;
const struct ieee80211_cipher *cip;
- u_int8_t mac[IEEE80211_ADDR_LEN];
struct wep_ctx_hw *ctx;
+ int hdrlen;
printf("%s: ", t->name);
/*
* Setup key.
*/
- memset(&key, 0, sizeof(key));
- key.wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
- key.wk_cipher = &ieee80211_cipher_none;
- if (!ieee80211_crypto_newkey(ic, t->cipher,
- IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, &key)) {
+ memset(key, 0, sizeof(*key));
+ key->wk_flags = IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV;
+ key->wk_cipher = &ieee80211_cipher_none;
+ if (!ieee80211_crypto_newkey(vap, t->cipher,
+ IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, key)) {
printf("FAIL: ieee80211_crypto_newkey failed\n");
goto bad;
}
- memcpy(key.wk_key, t->key, t->key_len);
- key.wk_keylen = t->key_len;
- if (!ieee80211_crypto_setkey(ic, &key, mac)) {
+ memcpy(key->wk_key, t->key, t->key_len);
+ key->wk_keylen = t->key_len;
+ if (!ieee80211_crypto_setkey(vap, key)) {
printf("FAIL: ieee80211_crypto_setkey failed\n");
goto bad;
}
- cip = key.wk_cipher;
/*
* Craft frame from plaintext data.
*/
- cip = key.wk_cipher;
+ cip = key->wk_cipher;
m = m_getcl(M_NOWAIT, MT_HEADER, M_PKTHDR);
memcpy(mtod(m, void *), t->encrypted, t->encrypted_len);
m->m_len = t->encrypted_len;
m->m_pkthdr.len = m->m_len;
+ hdrlen = ieee80211_anyhdrsize(mtod(m, void *));
/*
* Decrypt frame.
*/
- if (!cip->ic_decap(&key, m)) {
+ if (!cip->ic_decap(key, m, hdrlen)) {
printf("FAIL: wep decap failed\n");
cmpfail(mtod(m, const void *), m->m_pkthdr.len,
t->plaintext, t->plaintext_len);
@@ -249,9 +251,11 @@ runtest(struct ieee80211com *ic, struct ciphertest *t)
/*
* Encrypt frame.
*/
- ctx = (struct wep_ctx_hw *) key.wk_private;
+ ctx = (struct wep_ctx_hw *) key->wk_private;
+ ctx->wc_vap = vap;
+ ctx->wc_ic = vap->iv_ic;
memcpy(&ctx->wc_iv, t->iv, sizeof(t->iv)); /* for encap/encrypt */
- if (!cip->ic_encap(&key, m, t->keyix<<6)) {
+ if (!cip->ic_encap(key, m)) {
printf("FAIL: wep encap failed\n");
goto bad;
}
@@ -271,13 +275,13 @@ runtest(struct ieee80211com *ic, struct ciphertest *t)
goto bad;
}
m_freem(m);
- ieee80211_crypto_delkey(ic, &key);
+ ieee80211_crypto_delkey(vap, key);
printf("PASS\n");
return 1;
bad:
if (m != NULL)
m_freem(m);
- ieee80211_crypto_delkey(ic, &key);
+ ieee80211_crypto_delkey(vap, key);
return 0;
}
@@ -291,25 +295,38 @@ static int debug = 0;
static int
init_crypto_wep_test(void)
{
-#define N(a) (sizeof(a)/sizeof(a[0]))
struct ieee80211com ic;
+ struct ieee80211vap vap;
+ struct ifnet ifp;
int i, pass, total;
memset(&ic, 0, sizeof(ic));
- if (debug)
- ic.ic_debug = IEEE80211_MSG_CRYPTO;
+ memset(&vap, 0, sizeof(vap));
+ memset(&ifp, 0, sizeof(ifp));
+
ieee80211_crypto_attach(&ic);
+
+ /* some minimal initialization */
+ strncpy(ifp.if_xname, "test_ccmp", sizeof(ifp.if_xname));
+ vap.iv_ic = &ic;
+ vap.iv_ifp = &ifp;
+ if (debug)
+ vap.iv_debug = IEEE80211_MSG_CRYPTO;
+ ieee80211_crypto_vattach(&vap);
+
pass = 0;
total = 0;
- for (i = 0; i < N(weptests); i++)
+ for (i = 0; i < nitems(weptests); i++)
if (tests & (1<<i)) {
total++;
- pass += runtest(&ic, &weptests[i]);
+ pass += runtest(&vap, &weptests[i]);
}
printf("%u of %u 802.11i WEP test vectors passed\n", pass, total);
+
+ ieee80211_crypto_vdetach(&vap);
ieee80211_crypto_detach(&ic);
+
return (pass == total ? 0 : -1);
-#undef N
}
static int
OpenPOWER on IntegriCloud