Index: tools/regression/net80211/ccmp/test_ccmp.c =================================================================== --- tools/regression/net80211/ccmp/test_ccmp.c +++ tools/regression/net80211/ccmp/test_ccmp.c @@ -53,6 +53,7 @@ #include #include +#include #include #include @@ -591,12 +592,12 @@ } static int -runtest(struct ieee80211com *ic, struct ciphertest *t) +runtest(struct ieee80211vap *vap, struct ciphertest *t) { struct ieee80211_key key; struct mbuf *m = NULL; const struct ieee80211_cipher *cip; - u_int8_t mac[IEEE80211_ADDR_LEN]; + int hdrlen; printf("%s: ", t->name); @@ -606,7 +607,7 @@ 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, + if (!ieee80211_crypto_newkey(vap, t->cipher, IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, &key)) { printf("FAIL: ieee80211_crypto_newkey failed\n"); goto bad; @@ -614,9 +615,9 @@ memcpy(key.wk_key, t->key, t->key_len); key.wk_keylen = t->key_len; - key.wk_keyrsc = 0; + memset(key.wk_keyrsc, 0, sizeof(key.wk_keyrsc)); key.wk_keytsc = t->pn-1; /* PN-1 since we do encap */ - if (!ieee80211_crypto_setkey(ic, &key, mac)) { + if (!ieee80211_crypto_setkey(vap, &key)) { printf("FAIL: ieee80211_crypto_setkey failed\n"); goto bad; } @@ -630,6 +631,7 @@ memcpy(mtod(m, void *), t->plaintext, t->plaintext_len); m->m_len = t->plaintext_len; m->m_pkthdr.len = m->m_len; + hdrlen = ieee80211_anyhdrsize(mtod(m, void *)); /* * Encrypt frame w/ MIC. @@ -660,7 +662,7 @@ /* * Decrypt frame; strip MIC. */ - if (!cip->ic_decap(&key, m)) { + if (!cip->ic_decap(&key, m, hdrlen)) { printf("FAIL: ccmp decap failed\n"); printtest(t); cmpfail(mtod(m, const void *), m->m_len, @@ -680,17 +682,17 @@ printf("FAIL: decap botch; data does not compare\n"); printtest(t); cmpfail(mtod(m, const void *), m->m_pkthdr.len, - t->plaintext, t_plaintext_len); + t->plaintext, t->plaintext_len); 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; } @@ -704,26 +706,38 @@ static int init_crypto_ccmp_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 = ⁣ + 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(ccmptests); i++) + for (i = 0; i < nitems(ccmptests); i++) if (tests & (1< #include +#include #include #include @@ -179,14 +180,14 @@ } static int -runtest(struct ieee80211com *ic, struct ciphertest *t) +runtest(struct ieee80211vap *vap, struct ciphertest *t) { struct tkip_ctx *ctx; struct ieee80211_key key; struct mbuf *m = NULL; const struct ieee80211_cipher *cip; - u_int8_t mac[IEEE80211_ADDR_LEN]; u_int len; + int hdrlen; printf("%s: ", t->name); @@ -196,7 +197,7 @@ 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, IEEE80211_CIPHER_TKIP, + if (!ieee80211_crypto_newkey(vap, t->cipher, IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, &key)) { printf("FAIL: ieee80211_crypto_newkey failed\n"); goto bad; @@ -204,9 +205,9 @@ memcpy(key.wk_key, t->key, t->key_len); key.wk_keylen = 128/NBBY; - key.wk_keyrsc = 0; + memset(key.wk_keyrsc, 0, sizeof(key.wk_keyrsc)); key.wk_keytsc = t->pn; - if (!ieee80211_crypto_setkey(ic, &key, mac)) { + if (!ieee80211_crypto_setkey(vap, &key)) { printf("FAIL: ieee80211_crypto_setkey failed\n"); goto bad; } @@ -221,11 +222,12 @@ memcpy(mtod(m, void *), t->plaintext, len); m->m_len = len; m->m_pkthdr.len = m->m_len; + hdrlen = ieee80211_anyhdrsize(mtod(m, void *)); /* * Add MIC. */ - if (!ieee80211_crypto_enmic(ic, &key, m)) { + if (!ieee80211_crypto_enmic(vap, &key, m, 1)) { printf("FAIL: tkip enmic failed\n"); goto bad; } @@ -281,7 +283,7 @@ /* * Decrypt frame. */ - if (!cip->ic_decap(&key, m)) { + if (!cip->ic_decap(&key, m, hdrlen)) { printf("tkip decap failed\n"); /* * Check reason for failure: phase1, phase2, frame data (ICV). @@ -319,17 +321,19 @@ /* * De-MIC decrypted frame. */ - if (!ieee80211_crypto_demic(ic, &key, m)) { + if (!ieee80211_crypto_demic(vap, &key, m, 1)) { printf("FAIL: tkip demic failed\n"); goto bad; } /* XXX check frame length and contents... */ + m_freem(m); + 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; } @@ -343,26 +347,38 @@ static int init_crypto_tkip_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 = ⁣ + 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(tkiptests); i++) + for (i = 0; i < nitems(tkiptests); i++) if (tests & (1< #include +#include #include #include @@ -178,18 +179,19 @@ } 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 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); @@ -199,7 +201,7 @@ 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, + if (!ieee80211_crypto_newkey(vap, t->cipher, IEEE80211_KEY_XMIT | IEEE80211_KEY_RECV, &key)) { printf("FAIL: ieee80211_crypto_newkey failed\n"); goto bad; @@ -207,11 +209,10 @@ memcpy(key.wk_key, t->key, t->key_len); key.wk_keylen = t->key_len; - if (!ieee80211_crypto_setkey(ic, &key, mac)) { + if (!ieee80211_crypto_setkey(vap, &key)) { printf("FAIL: ieee80211_crypto_setkey failed\n"); goto bad; } - cip = key.wk_cipher; /* * Craft frame from plaintext data. @@ -221,11 +222,12 @@ 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); @@ -250,6 +252,8 @@ * Encrypt frame. */ 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)) { printf("FAIL: wep encap failed\n"); @@ -271,13 +275,13 @@ 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 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 = ⁣ + 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<