瀏覽代碼

qcacmn: Integrate crypto service and sw files

Integrate crypto service and crypto sw files from hostapd

Change-Id: I1e461269a603beffd9d05e304817418e5d0e4f1c
Ashok Ponnaiah 8 年之前
父節點
當前提交
13e9f9bb19

+ 11 - 0
umac/cmn_services/crypto/inc/wlan_crypto_global_api.h

@@ -342,4 +342,15 @@ QDF_STATUS wlan_crypto_set_peer_wep_keys(struct wlan_objmgr_vdev *vdev,
 QDF_STATUS wlan_crypto_register_crypto_rx_ops(
 			struct wlan_lmac_if_crypto_rx_ops *crypto_rx_ops);
 
+/**
+ * wlan_crypto_get_crypto_rx_ops - get crypto_rx_ops from psoc
+ *
+ * @psoc: psoc
+ *
+ * This function gets called by umac to get the crypto_rx_ops
+ *
+ * Return: crypto_rx_ops
+ */
+struct wlan_lmac_if_crypto_rx_ops *wlan_crypto_get_crypto_rx_ops(
+			struct wlan_objmgr_psoc *psoc);
 #endif /* end of _WLAN_CRYPTO_GLOBAL_API_H_ */

+ 13 - 0
umac/cmn_services/crypto/inc/wlan_crypto_global_def.h

@@ -23,6 +23,8 @@
 #ifndef _WLAN_CRYPTO_GLOBAL_DEF_H_
 #define _WLAN_CRYPTO_GLOBAL_DEF_H_
 
+#include <wlan_cmn.h>
+
 #define WLAN_CRYPTO_TID_SIZE         (17)
 #define WLAN_CRYPTO_KEYBUF_SIZE      (32)
 #define WLAN_CRYPTO_MICBUF_SIZE      (16)
@@ -293,4 +295,15 @@ struct wlan_lmac_if_crypto_rx_ops {
 						uint8_t *mac_addr);
 };
 
+#define WLAN_CRYPTO_RX_OPS_ENCAP(crypto_rx_ops) \
+				(crypto_rx_ops->crypto_encap)
+#define WLAN_CRYPTO_RX_OPS_DECAP(crypto_rx_ops) \
+				(crypto_rx_ops->crypto_decap)
+#define WLAN_CRYPTO_RX_OPS_ENMIC(crypto_rx_ops) \
+				(crypto_rx_ops->crypto_enmic)
+#define WLAN_CRYPTO_RX_OPS_DEMIC(crypto_rx_ops) \
+				(crypto_rx_ops->crypto_demic)
+#define WLAN_CRYPTO_RX_OPS_SET_PEER_WEP_KEYS(crypto_rx_ops) \
+				(crypto_rx_ops->set_peer_wep_keys)
+
 #endif /* end of _WLAN_CRYPTO_GLOBAL_DEF_H_ */

+ 10 - 7
umac/cmn_services/crypto/src/wlan_crypto_aes_ccm.c

@@ -39,15 +39,18 @@ static void aes_ccm_auth_start(void *aes, size_t M, size_t L,
 	b[0] |= (((M - 2) / 2) /* M' */ << 3);
 	b[0] |= (L - 1) /* L' */;
 	qdf_mem_copy(&b[1], nonce, 15 - L);
-	WPA_PUT_BE16(&b[AES_BLOCK_SIZE - L], plain_len);
+	wlan_crypto_put_be16(&b[AES_BLOCK_SIZE - L], plain_len);
 
 	wpa_hexdump_key(MSG_EXCESSIVE, "CCM B_0", b, AES_BLOCK_SIZE);
 	wlan_crypto_aes_encrypt(aes, b, x); /* X_1 = E(K, B_0) */
 
-	if (!aad_len)
+	if (!aad_len) {
+		qdf_print("%s[%d] aad length should be non zero\n",
+						__func__, __LINE__);
 		return;
+	}
 
-	WPA_PUT_BE16(aad_buf, aad_len);
+	wlan_crypto_put_be16(aad_buf, aad_len);
 	qdf_mem_copy(aad_buf + 2, aad, aad_len);
 	qdf_mem_set(aad_buf + 2 + aad_len, 0, sizeof(aad_buf) - 2 - aad_len);
 
@@ -97,7 +100,7 @@ static void aes_ccm_encr(void *aes, size_t L, const uint8_t *in, size_t len,
 
 	/* crypt = msg XOR (S_1 | S_2 | ... | S_n) */
 	for (i = 1; i <= len / AES_BLOCK_SIZE; i++) {
-		WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], i);
+		wlan_crypto_put_be16(&a[AES_BLOCK_SIZE - 2], i);
 		/* S_i = E(K, A_i) */
 		wlan_crypto_aes_encrypt(aes, a, out);
 		xor_aes_block(out, in);
@@ -105,7 +108,7 @@ static void aes_ccm_encr(void *aes, size_t L, const uint8_t *in, size_t len,
 		in += AES_BLOCK_SIZE;
 	}
 	if (last) {
-		WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], i);
+		wlan_crypto_put_be16(&a[AES_BLOCK_SIZE - 2], i);
 		wlan_crypto_aes_encrypt(aes, a, out);
 		/* XOR zero-padded last block */
 		for (i = 0; i < last; i++)
@@ -121,7 +124,7 @@ static void aes_ccm_encr_auth(void *aes, size_t M, uint8_t *x, uint8_t *a,
 
 	wpa_hexdump_key(MSG_EXCESSIVE, "CCM T", x, M);
 	/* U = T XOR S_0; S_0 = E(K, A_0) */
-	WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], 0);
+	wlan_crypto_put_be16(&a[AES_BLOCK_SIZE - 2], 0);
 	wlan_crypto_aes_encrypt(aes, a, tmp);
 	for (i = 0; i < M; i++)
 		auth[i] = x[i] ^ tmp[i];
@@ -136,7 +139,7 @@ static void aes_ccm_decr_auth(void *aes, size_t M, uint8_t *a,
 
 	wpa_hexdump_key(MSG_EXCESSIVE, "CCM U", auth, M);
 	/* U = T XOR S_0; S_0 = E(K, A_0) */
-	WPA_PUT_BE16(&a[AES_BLOCK_SIZE - 2], 0);
+	wlan_crypto_put_be16(&a[AES_BLOCK_SIZE - 2], 0);
 	wlan_crypto_aes_encrypt(aes, a, tmp);
 	for (i = 0; i < M; i++)
 		t[i] = auth[i] ^ tmp[i];

+ 14 - 14
umac/cmn_services/crypto/src/wlan_crypto_aes_gcm.c

@@ -19,9 +19,9 @@
 static void inc32(uint8_t *block)
 {
 	uint32_t val;
-	val = WPA_GET_BE32(block + AES_BLOCK_SIZE - 4);
+	val = wlan_crypto_get_be32(block + AES_BLOCK_SIZE - 4);
 	val++;
-	WPA_PUT_BE32(block + AES_BLOCK_SIZE - 4, val);
+	wlan_crypto_put_be32(block + AES_BLOCK_SIZE - 4, val);
 }
 
 
@@ -40,27 +40,27 @@ static void shift_right_block(uint8_t *v)
 {
 	uint32_t val;
 
-	val = WPA_GET_BE32(v + 12);
+	val = wlan_crypto_get_be32(v + 12);
 	val >>= 1;
 	if (v[11] & 0x01)
 		val |= 0x80000000;
-	WPA_PUT_BE32(v + 12, val);
+	wlan_crypto_put_be32(v + 12, val);
 
-	val = WPA_GET_BE32(v + 8);
+	val = wlan_crypto_get_be32(v + 8);
 	val >>= 1;
 	if (v[7] & 0x01)
 		val |= 0x80000000;
-	WPA_PUT_BE32(v + 8, val);
+	wlan_crypto_put_be32(v + 8, val);
 
-	val = WPA_GET_BE32(v + 4);
+	val = wlan_crypto_get_be32(v + 4);
 	val >>= 1;
 	if (v[3] & 0x01)
 		val |= 0x80000000;
-	WPA_PUT_BE32(v + 4, val);
+	wlan_crypto_put_be32(v + 4, val);
 
-	val = WPA_GET_BE32(v);
+	val = wlan_crypto_get_be32(v);
 	val >>= 1;
-	WPA_PUT_BE32(v, val);
+	wlan_crypto_put_be32(v, val);
 }
 
 
@@ -208,8 +208,8 @@ static void aes_gcm_prepare_j0(const uint8_t *iv, size_t iv_len,
 		 */
 		ghash_start(J0);
 		ghash(H, iv, iv_len, J0);
-		WPA_PUT_BE64(len_buf, 0);
-		WPA_PUT_BE64(len_buf + 8, iv_len * 8);
+		wlan_crypto_put_be64(len_buf, 0);
+		wlan_crypto_put_be64(len_buf + 8, iv_len * 8);
 		ghash(H, len_buf, sizeof(len_buf), J0);
 	}
 }
@@ -242,8 +242,8 @@ static void aes_gcm_ghash(const uint8_t *H, const uint8_t *aad, size_t aad_len,
 	ghash_start(S);
 	ghash(H, aad, aad_len, S);
 	ghash(H, crypt, crypt_len, S);
-	WPA_PUT_BE64(len_buf, aad_len * 8);
-	WPA_PUT_BE64(len_buf + 8, crypt_len * 8);
+	wlan_crypto_put_be64(len_buf, aad_len * 8);
+	wlan_crypto_put_be64(len_buf + 8, crypt_len * 8);
 	ghash(H, len_buf, sizeof(len_buf), S);
 
 	wpa_hexdump_key(MSG_EXCESSIVE, "S = GHASH_H(...)", S, 16);

+ 22 - 16
umac/cmn_services/crypto/src/wlan_crypto_aes_i.h

@@ -12,6 +12,13 @@
 #ifndef WLAN_CRYPTO_AES_I_H
 #define WLAN_CRYPTO_AES_I_H
 
+#include <wlan_cmn.h>
+#include <wlan_objmgr_cmn.h>
+#include <wlan_objmgr_global_obj.h>
+#include <wlan_objmgr_psoc_obj.h>
+#include <wlan_objmgr_pdev_obj.h>
+#include <wlan_objmgr_vdev_obj.h>
+#include <wlan_objmgr_peer_obj.h>
 #include "wlan_crypto_global_def.h"
 
 
@@ -182,29 +189,24 @@ struct ieee80211_hdr_qos_addr4 {
 int wlan_crypto_rijndaelKeySetupEnc(uint32_t rk[], const uint8_t cipherKey[],
 					int keyBits);
 
-uint8_t *wlan_crypto_ccmp_encrypt(const uint8_t *tk, uint8_t *frame, size_t len,
-				size_t hdrlen, uint8_t *qos,
-				uint8_t *pn, int keyid,
-				size_t *encrypted_len);
+uint8_t *wlan_crypto_ccmp_encrypt(const uint8_t *key, uint8_t *frame,
+					size_t len, size_t hdrlen);
 
-uint8_t *wlan_crypto_ccmp_decrypt(const uint8_t *tk,
+uint8_t *wlan_crypto_ccmp_decrypt(const uint8_t *key,
 				const struct ieee80211_hdr *hdr,
-				const uint8_t *data, size_t data_len,
-				size_t *decrypted_len);
+				uint8_t *data, size_t data_len);
 
-uint8_t *wlan_crypto_tkip_encrypt(const uint8_t *tk, uint8_t *frame, size_t len,
-				size_t hdrlen, uint8_t *qos, uint8_t *pn,
-				int keyid, size_t *encrypted_len);
+uint8_t *wlan_crypto_tkip_encrypt(const uint8_t *key, uint8_t *frame,
+					size_t len, size_t hdrlen);
 
-uint8_t *wlan_crypto_tkip_decrypt(const uint8_t *tk,
+uint8_t *wlan_crypto_tkip_decrypt(const uint8_t *key,
 				const struct ieee80211_hdr *hdr,
-				const uint8_t *data, size_t data_len,
-				size_t *decrypted_len);
+				uint8_t *data, size_t data_len);
 
+uint8_t *wlan_crypto_wep_encrypt(const uint8_t *key, uint16_t key_len,
+				uint8_t *data, size_t data_len);
 uint8_t *wlan_crypto_wep_decrypt(const uint8_t *key, uint16_t key_len,
-				const struct ieee80211_hdr *hdr,
-				const uint8_t *data, size_t data_len,
-				size_t *decrypted_len);
+				uint8_t *data, size_t data_len);
 
 void wlan_crypto_wep_crypt(uint8_t *key, uint8_t *buf, size_t plen);
 
@@ -242,4 +244,8 @@ void wlan_crypto_aes_encrypt_deinit(void *ctx);
 void *wlan_crypto_aes_decrypt_init(const uint8_t *key, size_t len);
 void wlan_crypto_aes_decrypt(void *ctx, const uint8_t *crypt, uint8_t *plain);
 void wlan_crypto_aes_decrypt_deinit(void *ctx);
+int omac1_aes_128(const uint8_t *key, const uint8_t *data,
+				size_t data_len, uint8_t *mac);
+int omac1_aes_256(const uint8_t *key, const uint8_t *data,
+				size_t data_len, uint8_t *mac);
 #endif /* WLAN_CRYPTO_AES_I_H */

+ 14 - 38
umac/cmn_services/crypto/src/wlan_crypto_ccmp.c

@@ -32,26 +32,11 @@
 #include "wlan_crypto_def_i.h"
 #include "wlan_crypto_main_i.h"
 #include "wlan_crypto_obj_mgr_i.h"
-#include "wlan_crypto_ccmp_i.h"
 
 #define MAX_CCMP_PN_GAP_ERR_CHECK 0
 
 static QDF_STATUS ccmp_setkey(struct wlan_crypto_key *key)
 {
-
-	struct wlan_crypto_ccmp_ctx *ctx;
-
-	if (key->private == NULL) {
-		key->private = qdf_mem_malloc(
-					sizeof(struct wlan_crypto_ccmp_ctx));
-		if (key->private == NULL)
-			return QDF_STATUS_E_NOMEM;
-	}
-
-	ctx = key->private;
-	wlan_crypto_rijndael_set_key(&ctx->cc_aes, key->keyval,
-					(key->keylen*NBBY));
-
 	return QDF_STATUS_SUCCESS;
 }
 
@@ -60,12 +45,12 @@ static QDF_STATUS ccmp_encap(struct wlan_crypto_key *key,
 				uint8_t encapdone,
 				uint8_t hdrlen){
 	uint8_t *ivp;
-	struct ieee80211_frame *wh;
+	struct ieee80211_hdr *hdr;
 	struct wlan_crypto_cipher *cipher_table;
 
 	cipher_table = (struct wlan_crypto_cipher *)key->cipher_table;
 
-	wh = (struct ieee80211_frame *)qdf_nbuf_data(wbuf);
+	hdr = (struct ieee80211_hdr *)qdf_nbuf_data(wbuf);
 
 	/*
 	 * Copy down 802.11 header and add the IV, KeyID, and ExtIV.
@@ -77,8 +62,8 @@ static QDF_STATUS ccmp_encap(struct wlan_crypto_key *key,
 		ivp = (uint8_t *)qdf_nbuf_push_head(wbuf,
 							cipher_table->header);
 		qdf_mem_move(ivp, ivp + cipher_table->header, hdrlen);
-		/* recompute wh */
-		wh = (struct ieee80211_frame *) qdf_nbuf_data(wbuf);
+		/* recompute hdr */
+		hdr = (struct ieee80211_hdr *) qdf_nbuf_data(wbuf);
 	}
 
 	ivp += hdrlen;
@@ -99,8 +84,9 @@ static QDF_STATUS ccmp_encap(struct wlan_crypto_key *key,
 	 * Finally, do software encrypt if neeed.
 	 */
 	if (key->flags & WLAN_CRYPTO_KEY_SWENCRYPT) {
-		if (!wlan_crypto_ccmp_encrypt(key, wbuf, hdrlen,
-				IEEE80211_IS_MFP_FRAME(wh))) {
+		if (!wlan_crypto_ccmp_encrypt(key->keyval,
+						qdf_nbuf_data(wbuf),
+						qdf_nbuf_len(wbuf), hdrlen)) {
 			return 0;
 		}
 	}
@@ -114,7 +100,7 @@ static QDF_STATUS ccmp_decap(struct wlan_crypto_key *key,
 				qdf_nbuf_t wbuf,
 				uint8_t tid,
 				uint8_t hdrlen){
-	struct ieee80211_frame *wh;
+	struct ieee80211_hdr *hdr;
 	uint8_t *ivp, *origHdr;
 	uint64_t pn;
 	uint8_t  update_keyrsc = 1;
@@ -127,7 +113,7 @@ static QDF_STATUS ccmp_decap(struct wlan_crypto_key *key,
 	 * verify the former and validate the latter.
 	 */
 	origHdr = (uint8_t *)qdf_nbuf_data(wbuf);
-	wh = (struct ieee80211_frame *)origHdr;
+	hdr = (struct ieee80211_hdr *)origHdr;
 
 	ivp = origHdr + hdrlen;
 
@@ -136,20 +122,8 @@ static QDF_STATUS ccmp_decap(struct wlan_crypto_key *key,
 		return QDF_STATUS_E_INVAL;
 	}
 
-	tid = IEEE80211_NON_QOS_SEQ;
-
-	if (IEEE80211_QOS_HAS_SEQ(wh)) {
-		if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK)
-				== IEEE80211_FC1_DIR_DSTODS) {
-			tid = ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0]
-							& IEEE80211_QOS_TID;
-		} else {
-			tid = ((struct ieee80211_qosframe *)wh)->i_qos[0]
-							& IEEE80211_QOS_TID;
-		}
-	}
+	tid = wlan_get_tid(qdf_nbuf_data(wbuf));
 
-	/* NB: assume IEEEE80211_WEP_MINLEN covers the extended IV */
 	pn = READ_6(ivp[0], ivp[1], ivp[4], ivp[5], ivp[6], ivp[7]);
 
 	if (pn <= key->keyrsc[tid]) {
@@ -160,8 +134,10 @@ static QDF_STATUS ccmp_decap(struct wlan_crypto_key *key,
 	}
 
 	if ((key->flags & WLAN_CRYPTO_KEY_SWDECRYPT)) {
-		if (!wlan_crypto_ccmp_decrypt(key,
-				pn, wbuf, hdrlen, IEEE80211_IS_MFP_FRAME(wh))) {
+		if (!wlan_crypto_ccmp_decrypt(key->keyval,
+				(struct ieee80211_hdr *)origHdr,
+				(origHdr + hdrlen),
+				(qdf_nbuf_len(wbuf) - hdrlen))) {
 			return QDF_STATUS_CRYPTO_DECRYPT_FAILED;
 		}
 	}

+ 12 - 21
umac/cmn_services/crypto/src/wlan_crypto_ccmp_sw.c

@@ -46,13 +46,13 @@ static void ccmp_aad_nonce(const struct ieee80211_hdr *hdr, const uint8_t *data,
 
 	fc &= ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT | WLAN_FC_MOREDATA);
 	fc |= WLAN_FC_ISWEP;
-	WPA_PUT_LE16(aad, fc);
+	wlan_crypto_put_le16(aad, fc);
 	pos = aad + 2;
 	qdf_mem_copy(pos, hdr->addr1, 3 * WLAN_ALEN);
 	pos += 3 * WLAN_ALEN;
 	seq = qdf_le16_to_cpu(hdr->seq_ctrl);
 	seq &= ~0xfff0; /* Mask Seq#; do not modify Frag# */
-	WPA_PUT_LE16(pos, seq);
+	wlan_crypto_put_le16(pos, seq);
 	pos += 2;
 
 	qdf_mem_copy(pos, hdr + 1, addr4 * WLAN_ALEN + qos * 2);
@@ -79,8 +79,7 @@ static void ccmp_aad_nonce(const struct ieee80211_hdr *hdr, const uint8_t *data,
 
 uint8_t *wlan_crypto_ccmp_decrypt(const uint8_t *tk,
 					const struct ieee80211_hdr *hdr,
-					const uint8_t *data, size_t data_len,
-					size_t *decrypted_len){
+					uint8_t *data, size_t data_len){
 	uint8_t aad[30], nonce[13];
 	size_t aad_len;
 	size_t mlen;
@@ -116,8 +115,9 @@ uint8_t *wlan_crypto_ccmp_decrypt(const uint8_t *tk,
 	}
 	wpa_hexdump(MSG_EXCESSIVE, "CCMP decrypted", plain, mlen);
 
-	*decrypted_len = mlen;
-	return plain;
+	qdf_mem_copy(data, plain, data_len);
+	qdf_mem_free(plain);
+	return data;
 }
 
 
@@ -133,9 +133,7 @@ void ccmp_get_pn(uint8_t *pn, const uint8_t *data)
 
 
 uint8_t *wlan_crypto_ccmp_encrypt(const uint8_t *tk, uint8_t *frame,
-					size_t len, size_t hdrlen, uint8_t *qos,
-					uint8_t *pn, int keyid,
-					size_t *encrypted_len){
+					size_t len, size_t hdrlen){
 	uint8_t aad[30], nonce[13];
 	size_t aad_len, plen;
 	uint8_t *crypt, *pos;
@@ -152,17 +150,10 @@ uint8_t *wlan_crypto_ccmp_encrypt(const uint8_t *tk, uint8_t *frame,
 	}
 
 	qdf_mem_copy(crypt, frame, hdrlen);
+
 	hdr = (struct ieee80211_hdr *) crypt;
 	hdr->frame_control |= qdf_cpu_to_le16(WLAN_FC_ISWEP);
-	pos = crypt + hdrlen;
-	*pos++ = pn[5]; /* PN0 */
-	*pos++ = pn[4]; /* PN1 */
-	*pos++ = 0x00; /* Rsvd */
-	*pos++ = 0x20 | (keyid << 6);
-	*pos++ = pn[3]; /* PN2 */
-	*pos++ = pn[2]; /* PN3 */
-	*pos++ = pn[1]; /* PN4 */
-	*pos++ = pn[0]; /* PN5 */
+	pos = crypt + hdrlen + 8;
 
 	qdf_mem_set(aad, 0, sizeof(aad));
 	ccmp_aad_nonce(hdr, crypt + hdrlen, aad, &aad_len, nonce);
@@ -175,11 +166,11 @@ uint8_t *wlan_crypto_ccmp_encrypt(const uint8_t *tk, uint8_t *frame,
 		return NULL;
 	}
 
+	qdf_mem_copy(frame, crypt, len);
 	wpa_hexdump(MSG_EXCESSIVE, "CCMP encrypted", crypt + hdrlen + 8, plen);
+	qdf_mem_free(crypt);
 
-	*encrypted_len = hdrlen + 8 + plen + 8;
-
-	return crypt;
+	return frame;
 }
 
 

+ 12 - 11
umac/cmn_services/crypto/src/wlan_crypto_def_i.h

@@ -93,34 +93,34 @@
 
 /* Macros for handling unaligned memory accesses */
 
-static inline uint16_t WPA_GET_BE16(const uint8_t *a)
+static inline uint16_t wlan_crypto_get_be16(const uint8_t *a)
 {
 	return (a[0] << 8) | a[1];
 }
 
-static inline void WPA_PUT_BE16(uint8_t *a, uint16_t val)
+static inline void wlan_crypto_put_be16(uint8_t *a, uint16_t val)
 {
 	a[0] = val >> 8;
 	a[1] = val & 0xff;
 }
 
-static inline uint16_t WPA_GET_LE16(const uint8_t *a)
+static inline uint16_t wlan_crypto_get_le16(const uint8_t *a)
 {
 	return (a[1] << 8) | a[0];
 }
 
-static inline void WPA_PUT_LE16(uint8_t *a, uint16_t val)
+static inline void wlan_crypto_put_le16(uint8_t *a, uint16_t val)
 {
 	a[1] = val >> 8;
 	a[0] = val & 0xff;
 }
 
-static inline uint32_t WPA_GET_BE32(const uint8_t *a)
+static inline uint32_t wlan_crypto_get_be32(const uint8_t *a)
 {
 	return ((u32) a[0] << 24) | (a[1] << 16) | (a[2] << 8) | a[3];
 }
 
-static inline void WPA_PUT_BE32(uint8_t *a, uint32_t val)
+static inline void wlan_crypto_put_be32(uint8_t *a, uint32_t val)
 {
 	a[0] = (val >> 24) & 0xff;
 	a[1] = (val >> 16) & 0xff;
@@ -128,12 +128,12 @@ static inline void WPA_PUT_BE32(uint8_t *a, uint32_t val)
 	a[3] = val & 0xff;
 }
 
-static inline uint32_t WPA_GET_LE32(const uint8_t *a)
+static inline uint32_t wlan_crypto_get_le32(const uint8_t *a)
 {
 	return ((u32) a[3] << 24) | (a[2] << 16) | (a[1] << 8) | a[0];
 }
 
-static inline void WPA_PUT_LE32(uint8_t *a, uint32_t val)
+static inline void wlan_crypto_put_le32(uint8_t *a, uint32_t val)
 {
 	a[3] = (val >> 24) & 0xff;
 	a[2] = (val >> 16) & 0xff;
@@ -141,7 +141,7 @@ static inline void WPA_PUT_LE32(uint8_t *a, uint32_t val)
 	a[0] = val & 0xff;
 }
 
-static inline void WPA_PUT_BE64(u8 *a, u64 val)
+static inline void wlan_crypto_put_be64(u8 *a, u64 val)
 {
 	a[0] = val >> 56;
 	a[1] = val >> 48;
@@ -390,6 +390,7 @@ struct wlan_crypto_comp_priv {
 	struct wlan_crypto_params crypto_params;
 	struct wlan_crypto_key *key[4];
 	struct wlan_crypto_key *igtk_key;
+	uint32_t igtk_key_type;
 	uint8_t def_tx_keyid;
 };
 
@@ -432,7 +433,7 @@ static inline int ieee80211_hdrsize(const void *data)
 	}
 
 	if (((WLAN_FC_GET_STYPE(hdr->frame_control)
-			== WLAN_FC_STYPE_QOS_DATA)) {
+			== WLAN_FC_STYPE_QOS_DATA))) {
 		size += sizeof(uint16_t);
 		/* Qos frame with Order bit set indicates an HTC frame */
 		if (hdr->frame_control & WLAN_FC_ORDER)
@@ -446,7 +447,7 @@ static inline int wlan_get_tid(const void *data)
 	const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)data;
 
 	if (((WLAN_FC_GET_STYPE(hdr->frame_control)
-				== WLAN_FC_STYPE_QOS_DATA)) {
+				== WLAN_FC_STYPE_QOS_DATA))) {
 		if ((hdr->frame_control & (WLAN_FC_TODS | WLAN_FC_FROMDS))
 				== (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
 			return ((struct ieee80211_hdr_qos_addr4 *)data)->qos

+ 2 - 2
umac/cmn_services/crypto/src/wlan_crypto_gcmp_sw.c

@@ -41,13 +41,13 @@ static void gcmp_aad_nonce(const struct ieee80211_hdr *hdr, const uint8_t *data,
 	}
 
 	fc &= ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT | WLAN_FC_MOREDATA);
-	WPA_PUT_LE16(aad, fc);
+	wlan_crypto_put_le16(aad, fc);
 	pos = aad + 2;
 	qdf_mem_copy(pos, hdr->addr1, 3 * WLAN_ALEN);
 	pos += 3 * WLAN_ALEN;
 	seq = qdf_le16_to_cpu(hdr->seq_ctrl);
 	seq &= ~0xfff0; /* Mask Seq#; do not modify Frag# */
-	WPA_PUT_LE16(pos, seq);
+	wlan_crypto_put_le16(pos, seq);
 	pos += 2;
 
 	qdf_mem_copy(pos, hdr + 1, addr4 * WLAN_ALEN + qos * 2);

+ 168 - 93
umac/cmn_services/crypto/src/wlan_crypto_global_api.c

@@ -33,12 +33,10 @@
 #include "wlan_crypto_def_i.h"
 #include "wlan_crypto_param_handling_i.h"
 #include "wlan_crypto_obj_mgr_i.h"
-#include "wlan_crypto_pmf_i.h"
 
 
 const struct wlan_crypto_cipher *wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_MAX];
 
-
 /**
  * wlan_crypto_vdev_get_crypto_params - called by mlme to get crypto params
  *
@@ -84,6 +82,10 @@ static struct wlan_crypto_params *wlan_crypto_peer_get_comp_params(
 	return &((*crypto_priv)->crypto_params);
 }
 
+static QDF_STATUS wlan_crypto_set_igtk_key(struct wlan_crypto_key *key)
+{
+	return QDF_STATUS_SUCCESS;
+}
 /**
  * wlan_crypto_set_param - called by ucfg to set crypto param
  *
@@ -223,8 +225,9 @@ QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev,
 	uint8_t *macaddr = NULL;
 	bool isbcast;
 
-	if (!req_key || req_key->keylen > (sizeof(req_key->keydata))) {
-		qdf_print("%s[%d] req_key invalid\n", __func__, __LINE__);
+	if (!vdev || !req_key || req_key->keylen > (sizeof(req_key->keydata))) {
+		qdf_print("%s[%d] Invalid params vdev%p, req_key%p\n",
+				__func__, __LINE__, vdev, req_key);
 		return QDF_STATUS_E_INVAL;
 	}
 
@@ -268,7 +271,7 @@ QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev,
 	if (req_key->keyix == WLAN_CRYPTO_KEYIX_NONE) {
 		if (req_key->flags != (WLAN_CRYPTO_KEY_XMIT
 						| WLAN_CRYPTO_KEY_RECV)) {
-			req_key->flags = (WLAN_CRYPTO_KEY_XMIT
+			req_key->flags |= (WLAN_CRYPTO_KEY_XMIT
 						| WLAN_CRYPTO_KEY_RECV);
 		}
 	} else {
@@ -277,7 +280,7 @@ QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev,
 			return QDF_STATUS_E_INVAL;
 		}
 
-		req_key->flags = (WLAN_CRYPTO_KEY_XMIT
+		req_key->flags |= (WLAN_CRYPTO_KEY_XMIT
 					| WLAN_CRYPTO_KEY_RECV);
 		req_key->flags |= WLAN_CRYPTO_KEY_GROUP;
 	}
@@ -296,6 +299,7 @@ QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev,
 
 		if (IS_MGMT_CIPHER(req_key->type)) {
 			key = crypto_priv->igtk_key;
+			crypto_priv->igtk_key_type = req_key->type;
 		} else {
 			if (!HAS_MCAST_CIPHER(crypto_params, req_key->type)
 				&& (req_key->type != WLAN_CRYPTO_CIPHER_WEP)) {
@@ -362,6 +366,10 @@ QDF_STATUS wlan_crypto_setkey(struct wlan_objmgr_vdev *vdev,
 	else
 		key->keyix = req_key->keyix;
 
+	if (req_key->flags & WLAN_CRYPTO_KEY_DEFAULT) {
+		crypto_priv->def_tx_keyid = key->keyix;
+		key->flags |= WLAN_CRYPTO_KEY_DEFAULT;
+	}
 	if ((req_key->type == WLAN_CRYPTO_CIPHER_WAPI_SMS4)
 		|| (req_key->type == WLAN_CRYPTO_CIPHER_WAPI_GCM4)) {
 		uint8_t iv_AP[16] = {	0x5c, 0x36, 0x5c, 0x36,
@@ -469,6 +477,7 @@ QDF_STATUS wlan_crypto_getkey(struct wlan_objmgr_vdev *vdev,
 				uint8_t *mac_addr){
 	struct wlan_crypto_comp_priv *crypto_priv;
 	struct wlan_crypto_params *crypto_params;
+	struct wlan_crypto_cipher *cipher_table;
 	struct wlan_crypto_key *key;
 
 	if (qdf_is_macaddr_broadcast((struct qdf_mac_addr *)mac_addr)) {
@@ -477,11 +486,8 @@ QDF_STATUS wlan_crypto_getkey(struct wlan_objmgr_vdev *vdev,
 		if (crypto_priv == NULL) {
 			qdf_print("%s[%d] crypto_priv NULL\n",
 							__func__, __LINE__);
-		}
-			return QDF_STATUS_E_INVAL;
-
-		if (!HAS_MCAST_CIPHER(crypto_params, req_key->type))
 			return QDF_STATUS_E_INVAL;
+		}
 
 		key = crypto_priv->key[crypto_priv->def_tx_keyid];
 		if (!key)
@@ -509,9 +515,6 @@ QDF_STATUS wlan_crypto_getkey(struct wlan_objmgr_vdev *vdev,
 			return QDF_STATUS_E_INVAL;
 		}
 
-		if (!HAS_UCAST_CIPHER(crypto_params, req_key->type))
-			return QDF_STATUS_E_INVAL;
-
 		key = crypto_priv->key[crypto_priv->def_tx_keyid];
 		if (!key)
 			return QDF_STATUS_E_INVAL;
@@ -519,7 +522,7 @@ QDF_STATUS wlan_crypto_getkey(struct wlan_objmgr_vdev *vdev,
 
 	if (key->valid) {
 		qdf_mem_copy(req_key->keydata,
-				key->keyval, sizeof(key->keyval));
+				key->keyval, key->keylen);
 		qdf_mem_copy((uint8_t *)(&req_key->keytsc),
 				(uint8_t *)(&key->keytsc),
 				sizeof(req_key->keytsc));
@@ -527,6 +530,9 @@ QDF_STATUS wlan_crypto_getkey(struct wlan_objmgr_vdev *vdev,
 				(uint8_t *)(&key->keyrsc[0]),
 				sizeof(req_key->keyrsc));
 		req_key->keylen = key->keylen;
+		req_key->flags = key->flags;
+		cipher_table = (struct wlan_crypto_cipher *)key->cipher_table;
+		req_key->type = cipher_table->cipher;
 	}
 
 	return QDF_STATUS_SUCCESS;
@@ -551,6 +557,12 @@ QDF_STATUS wlan_crypto_delkey(struct wlan_objmgr_vdev *vdev,
 	struct wlan_crypto_key *key;
 	struct wlan_crypto_cipher *cipher_table;
 
+	if (!vdev || !macaddr || (key_idx >= WLAN_CRYPTO_MAXKEYIDX)) {
+		qdf_print("%s[%d] Invalid params vdev %p, macaddr %p keyidx %d",
+				__func__, __LINE__, vdev,
+				macaddr, key_idx);
+		return QDF_STATUS_E_INVAL;
+	}
 	if (qdf_is_macaddr_broadcast((struct qdf_mac_addr *)macaddr)) {
 		crypto_params = wlan_crypto_vdev_get_comp_params(vdev,
 								&crypto_priv);
@@ -683,6 +695,7 @@ QDF_STATUS wlan_crypto_default_key(struct wlan_objmgr_vdev *vdev,
 		WLAN_CRYPTO_TX_OPS_DEFAULTKEY(psoc)(vdev, key_idx,
 						macaddr);
 	}
+	crypto_priv->def_tx_keyid = key_idx;
 
 	return QDF_STATUS_SUCCESS;
 }
@@ -1031,12 +1044,18 @@ uint8_t *wlan_crypto_add_mmie(struct wlan_objmgr_vdev *vdev,
 				uint8_t *bfrm,
 				uint32_t len) {
 	struct wlan_crypto_key *key;
-	struct ieee80211_ath_mmie *mmie;
-	uint8_t *pn, aad[20], *efrm, nounce[12];
-	struct ieee80211_frame *wh;
-	uint32_t i, hdrlen;
+	struct wlan_crypto_mmie *mmie;
+	uint8_t *pn, *aad, *buf, *efrm, nounce[12];
+	struct ieee80211_hdr *hdr;
+	uint32_t i, hdrlen, mic_len, aad_len;
 	struct wlan_crypto_comp_priv *crypto_priv;
 	struct wlan_crypto_params *crypto_params;
+	int32_t ret;
+
+	if (!bfrm) {
+		qdf_print("%s[%d] frame is NULL\n", __func__, __LINE__);
+		return NULL;
+	}
 
 	crypto_params = wlan_crypto_vdev_get_comp_params(vdev,
 							&crypto_priv);
@@ -1046,20 +1065,19 @@ uint8_t *wlan_crypto_add_mmie(struct wlan_objmgr_vdev *vdev,
 	}
 
 	key = crypto_priv->igtk_key;
-	if (!key)
-		return NULL;
-
-	if (!key && !bfrm) {
-		/* Invalid Key or frame */
+	if (!key) {
+		qdf_print("%s[%d] No igtk key present\n", __func__, __LINE__);
 		return NULL;
 	}
+	mic_len = (crypto_priv->igtk_key_type
+			== WLAN_CRYPTO_CIPHER_AES_CMAC) ? 8 : 16;
 
 	efrm = bfrm + len;
-	len += sizeof(*mmie);
-	hdrlen = sizeof(*wh);
+	aad_len = 20;
+	hdrlen = sizeof(struct ieee80211_hdr);
 
-	mmie = (struct ieee80211_ath_mmie *) efrm;
-	mmie->element_id = IEEE80211_ELEMID_MMIE;
+	mmie = (struct wlan_crypto_mmie *) efrm;
+	mmie->element_id = WLAN_ELEMID_MMIE;
 	mmie->length = sizeof(*mmie) - 2;
 	mmie->key_id = qdf_cpu_to_le16(key->keyix);
 
@@ -1075,43 +1093,57 @@ uint8_t *wlan_crypto_add_mmie(struct wlan_objmgr_vdev *vdev,
 	/* Copy IPN */
 	qdf_mem_copy(mmie->sequence_number, pn, 6);
 
-	wh = (struct ieee80211_frame *) bfrm;
+	hdr = (struct ieee80211_hdr *) bfrm;
 
+	buf = qdf_mem_malloc(len - hdrlen);
+	if (!buf) {
+		qdf_print("%s[%d] malloc failed\n", __func__, __LINE__);
+		return NULL;
+	}
+	aad = buf;
 	/* generate BIP AAD: FC(masked) || A1 || A2 || A3 */
 
 	/* FC type/subtype */
-	aad[0] = wh->i_fc[0];
+	aad[0] = hdr->frame_control & 0xff;
 	/* Mask FC Retry, PwrMgt, MoreData flags to zero */
-	aad[1] = wh->i_fc[1] & ~(IEEE80211_FC1_RETRY | IEEE80211_FC1_PWR_MGT
-						| IEEE80211_FC1_MORE_DATA);
+	aad[1] = (hdr->frame_control & ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT
+						| WLAN_FC_MOREDATA)) >> 8;
 	/* A1 || A2 || A3 */
-	qdf_mem_copy(aad + 2, wh->i_addr1, WLAN_ALEN);
-	qdf_mem_copy(aad + 8, wh->i_addr2, WLAN_ALEN);
-	qdf_mem_copy(aad + 14, wh->i_addr3, WLAN_ALEN);
+	qdf_mem_copy(aad + 2, hdr->addr1, WLAN_ALEN);
+	qdf_mem_copy(aad + 8, hdr->addr2, WLAN_ALEN);
+	qdf_mem_copy(aad + 14, hdr->addr3, WLAN_ALEN);
+	qdf_mem_zero(mmie->mic, 16);
 	/*
 	 * MIC = AES-128-CMAC(IGTK, AAD || Management Frame Body || MMIE, 64)
 	 */
-
-	if ((HAS_MGMT_CIPHER(crypto_params, WLAN_CRYPTO_CIPHER_AES_CMAC))
-		|| HAS_MGMT_CIPHER(crypto_params,
-					WLAN_CRYPTO_CIPHER_AES_CMAC_256)) {
-		/* size of MIC is 16 for GMAC, size of mic for CMAC is 8 */
-		len -= 8;
+	qdf_mem_copy(buf + 20, bfrm + hdrlen, len - hdrlen);
+	if (crypto_priv->igtk_key_type == WLAN_CRYPTO_CIPHER_AES_CMAC) {
 		mmie->length -= 8;
-		wlan_crypto_cmac_calc_mic(key, aad, bfrm + hdrlen,
-						len - hdrlen, mmie->mic);
-	} else if ((HAS_MGMT_CIPHER(crypto_params, WLAN_CRYPTO_CIPHER_AES_GMAC))
-		|| HAS_MGMT_CIPHER(crypto_params,
-					WLAN_CRYPTO_CIPHER_AES_GMAC_256)) {
-		qdf_mem_copy(nounce, wh->i_addr2, WLAN_ALEN);
+		ret = omac1_aes_128(key->keyval, buf,
+					len + aad_len - hdrlen, mmie->mic);
+	} else if (crypto_priv->igtk_key_type
+				== WLAN_CRYPTO_CIPHER_AES_CMAC_256) {
+		ret = omac1_aes_256(key->keyval, buf,
+					len + aad_len - hdrlen, mmie->mic);
+	} else if ((crypto_priv->igtk_key_type == WLAN_CRYPTO_CIPHER_AES_GMAC)
+			|| (crypto_priv->igtk_key_type
+					== WLAN_CRYPTO_CIPHER_AES_GMAC_256)) {
+		qdf_mem_copy(nounce, hdr->addr2, WLAN_ALEN);
 		qdf_mem_copy(nounce + 6, pn, 6);
-		wlan_crypto_gmac_calc_mic(key, aad, bfrm + hdrlen, 20,
-							mmie->mic, nounce);
-	} else {
-		qdf_print("%s CMAC/GMAC Not valid rsn\n", __func__);
+		ret = wlan_crypto_aes_gmac(key->keyval, key->keylen, nounce,
+					sizeof(nounce), buf,
+					len + aad_len - hdrlen, mmie->mic);
+	}
+	qdf_mem_free(buf);
+	if (ret < 0) {
+		qdf_print("%s[%d] add mmie failed\n", __func__, __LINE__);
 		return NULL;
 	}
 
+	len += sizeof(struct wlan_crypto_mmie);
+	if (mic_len == 8)
+		len -= 8;
+	key->keytsc++;
 	return bfrm + len;
 }
 
@@ -1129,18 +1161,23 @@ uint8_t *wlan_crypto_add_mmie(struct wlan_objmgr_vdev *vdev,
 bool wlan_crypto_is_mmie_valid(struct wlan_objmgr_vdev *vdev,
 					uint8_t *frm,
 					uint8_t *efrm){
-	struct ieee80211_ath_mmie   *mmie = NULL;
-	uint8_t *ipn, aad[20], mic[16], nounce[12];
+	struct wlan_crypto_mmie   *mmie = NULL;
+	uint8_t *ipn, *aad, *buf, mic[16], nounce[12];
 	struct wlan_crypto_key *key;
-	struct ieee80211_frame *wh;
-	uint8_t mic_length;
+	struct ieee80211_hdr *hdr;
+	uint16_t mic_len, hdrlen, len;
 	struct wlan_crypto_comp_priv *crypto_priv;
 	struct wlan_crypto_params *crypto_params;
+	uint8_t aad_len = 20;
+	int32_t ret;
 
 	/* check if frame is illegal length */
-	if ((efrm < frm) || ((efrm - frm) < sizeof(*wh)))
+	if (!frm || !efrm || (efrm < frm)
+			|| ((efrm - frm) < sizeof(struct ieee80211_hdr))) {
+		qdf_print("%s[%d] Invalid params\n", __func__, __LINE__);
 		return false;
-
+	}
+	len = efrm - frm;
 	crypto_priv = (struct wlan_crypto_comp_priv *)
 				wlan_get_vdev_crypto_obj(vdev);
 	if (crypto_priv == NULL) {
@@ -1149,68 +1186,89 @@ bool wlan_crypto_is_mmie_valid(struct wlan_objmgr_vdev *vdev,
 	}
 
 	crypto_params = &(crypto_priv->crypto_params);
-		key = crypto_priv->igtk_key;
-	if (!key)
-		return false;
 
-	if ((HAS_MGMT_CIPHER(crypto_params, WLAN_CRYPTO_CIPHER_AES_CMAC))
-		|| HAS_MGMT_CIPHER(crypto_params,
-					WLAN_CRYPTO_CIPHER_AES_CMAC_256)) {
-		mmie = (struct ieee80211_ath_mmie *)(efrm - sizeof(*mmie) + 8);
-	} else if ((HAS_MGMT_CIPHER(crypto_params,
-						WLAN_CRYPTO_CIPHER_AES_GMAC))
-		|| HAS_MGMT_CIPHER(crypto_params,
-					WLAN_CRYPTO_CIPHER_AES_GMAC_256)) {
-		mmie = (struct ieee80211_ath_mmie *)(efrm - sizeof(*mmie));
+	key = crypto_priv->igtk_key;
+	if (!key) {
+		qdf_print("%s[%d] No igtk key present\n", __func__, __LINE__);
+		return false;
 	}
+
+	mic_len = (crypto_priv->igtk_key_type
+			== WLAN_CRYPTO_CIPHER_AES_CMAC) ? 8 : 16;
+	hdrlen = sizeof(struct ieee80211_hdr);
+
+	if (mic_len == 8)
+		mmie = (struct wlan_crypto_mmie *)(efrm - sizeof(*mmie) + 8);
+	else
+		mmie = (struct wlan_crypto_mmie *)(efrm - sizeof(*mmie));
+
+
 	/* check Elem ID*/
-	if ((mmie == NULL) || (mmie->element_id != IEEE80211_ELEMID_MMIE)) {
-		/* IE is not Mgmt MIC IE */
+	if ((mmie == NULL) || (mmie->element_id != WLAN_ELEMID_MMIE)) {
+		qdf_print("%s[%d] IE is not MMIE\n", __func__, __LINE__);
 		return false;
 	}
 
 	/* validate ipn */
 	ipn = mmie->sequence_number;
 	if (qdf_mem_cmp(ipn, key->keyrsc, 6) <= 0) {
-		/* replay error */
+		qdf_print("%s[%d] replay error\n", __func__, __LINE__);
 		return false;
 	}
 
+	buf = qdf_mem_malloc(len - hdrlen);
+	if (!buf) {
+		qdf_print("%s[%d] malloc failed\n", __func__, __LINE__);
+		return false;
+	}
+	aad = buf;
+
 	/* construct AAD */
-	wh = (struct ieee80211_frame *)frm;
+	hdr = (struct ieee80211_hdr *)frm;
 	/* generate BIP AAD: FC(masked) || A1 || A2 || A3 */
 
 	/* FC type/subtype */
-	aad[0] = wh->i_fc[0];
+	aad[0] = hdr->frame_control & 0xff;
 	/* Mask FC Retry, PwrMgt, MoreData flags to zero */
-	aad[1] = wh->i_fc[1] & ~(IEEE80211_FC1_RETRY | IEEE80211_FC1_PWR_MGT
-						| IEEE80211_FC1_MORE_DATA);
+	aad[1] = (hdr->frame_control & ~(WLAN_FC_RETRY | WLAN_FC_PWRMGT
+						| WLAN_FC_MOREDATA)) >> 8;
 	/* A1 || A2 || A3 */
-	qdf_mem_copy(aad + 2, wh->i_addr_all, 3 * WLAN_ALEN);
+	qdf_mem_copy(aad + 2, hdr->addr1, 3 * WLAN_ALEN);
 
 	/*
 	 * MIC = AES-128-CMAC(IGTK, AAD || Management Frame Body || MMIE, 64)
 	 */
-	if ((HAS_MGMT_CIPHER(crypto_params, WLAN_CRYPTO_CIPHER_AES_CMAC))
-		|| HAS_MGMT_CIPHER(crypto_params,
-					WLAN_CRYPTO_CIPHER_AES_CMAC_256)) {
-		mic_length = 8;
-		 wlan_crypto_cmac_calc_mic(key, aad, (uint8_t *)(wh+1),
-					(efrm - (uint8_t *)(wh+1)), mic);
-	} else if ((HAS_MGMT_CIPHER(crypto_params, WLAN_CRYPTO_CIPHER_AES_GMAC))
-		|| HAS_MGMT_CIPHER(crypto_params,
-					WLAN_CRYPTO_CIPHER_AES_GMAC_256)) {
-		mic_length = 16;
-		qdf_mem_copy(nounce, wh->i_addr2, WLAN_ALEN);
+	qdf_mem_copy(buf + 20, frm + hdrlen, len - hdrlen);
+	if (crypto_priv->igtk_key_type == WLAN_CRYPTO_CIPHER_AES_CMAC) {
+		mmie->length -= 8;
+		ret = omac1_aes_128(key->keyval, buf,
+					len + aad_len - hdrlen, mic);
+	} else if (crypto_priv->igtk_key_type
+				== WLAN_CRYPTO_CIPHER_AES_CMAC_256) {
+		ret = omac1_aes_256(key->keyval, buf,
+					len + aad_len - hdrlen, mic);
+	} else if ((crypto_priv->igtk_key_type == WLAN_CRYPTO_CIPHER_AES_GMAC)
+			|| (crypto_priv->igtk_key_type
+					== WLAN_CRYPTO_CIPHER_AES_GMAC_256)) {
+		qdf_mem_copy(nounce, hdr->addr2, WLAN_ALEN);
 		qdf_mem_copy(nounce + 6, ipn, 6);
-		wlan_crypto_gmac_calc_mic(key, aad,  (uint8_t *)(wh+1),
-							20, mic, nounce);
-	} else
+		ret = wlan_crypto_aes_gmac(key->keyval, key->keylen, nounce,
+					sizeof(nounce), buf,
+					len + aad_len - hdrlen, mic);
+	}
+
+	qdf_mem_free(buf);
+
+	if (ret < 0) {
+		qdf_print("%s[%d] genarate mmie failed\n", __func__, __LINE__);
 		return false;
+	}
 
-	if (qdf_mem_cmp(mic, mmie->mic, mic_length) != 0)
+	if (qdf_mem_cmp(mic, mmie->mic, mic_len) != 0) {
+		qdf_print("%s[%d] mmie mismatch\n", __func__, __LINE__);
 		/* MMIE MIC mismatch */
 		return false;
+	}
 
 	/* Update the receive sequence number */
 	qdf_mem_copy(key->keyrsc, ipn, 6);
@@ -1640,7 +1698,7 @@ uint8_t *wlan_crypto_build_wpaie(struct wlan_crypto_params *crypto_params,
 	uint8_t *selcnt;
 	uint32_t mcastcipher;
 
-	*frm++ = IEEE80211_ELEMID_VENDOR;
+	*frm++ = WLAN_ELEMID_VENDOR;
 	*frm++ = 0;
 	WLAN_CRYPTO_ADDSELECTOR(frm, WPA_TYPE_OUI);
 	WLAN_CRYPTO_ADDSHORT(frm, WPA_VERSION);
@@ -1722,7 +1780,7 @@ uint8_t *wlan_crypto_build_rsnie(struct wlan_crypto_params *crypto_params,
 	uint8_t *selcnt;
 	uint32_t mcastcipher;
 
-	*frm++ = IEEE80211_ELEMID_RSN;
+	*frm++ = WLAN_ELEMID_RSN;
 	*frm++ = 0;
 	WLAN_CRYPTO_ADDSHORT(frm, RSN_VERSION);
 
@@ -2053,3 +2111,20 @@ QDF_STATUS wlan_crypto_register_crypto_rx_ops(
 
 	return QDF_STATUS_SUCCESS;
 }
+
+/**
+ * wlan_crypto_get_crypto_rx_ops - get crypto_rx_ops from psoc
+ *
+ * @psoc: psoc
+ *
+ * This function gets called by umac to get the crypto_rx_ops
+ *
+ * Return: crypto_rx_ops
+ */
+struct wlan_lmac_if_crypto_rx_ops *wlan_crypto_get_crypto_rx_ops(
+					struct wlan_objmgr_psoc *psoc)
+{
+
+	return &(psoc->soc_cb.rx_ops.crypto_rx_ops);
+}
+EXPORT_SYMBOL(wlan_crypto_get_crypto_rx_ops);

+ 33 - 15
umac/cmn_services/crypto/src/wlan_crypto_obj_mgr.c

@@ -50,16 +50,6 @@ static QDF_STATUS wlan_crypto_register_all_ciphers(
 					struct wlan_crypto_params *crypto_param)
 {
 
-	wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_WEP]  = wep_register();
-	wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_TKIP] = tkip_register();
-	wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_AES_CCM]
-							= ccmp_register();
-	wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_AES_CCM_256]
-							= ccmp256_register();
-	wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_AES_GCM]
-						= gcmp_register();
-	wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_AES_GCM_256]
-							= gcmp256_register();
 	if (HAS_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_WEP)) {
 		wlan_crypto_cipher_ops[WLAN_CRYPTO_CIPHER_WEP]
 							= wep_register();
@@ -117,20 +107,22 @@ static QDF_STATUS wlan_crypto_vdev_obj_create_handler(
 
 	crypto_param = &(crypto_priv->crypto_params);
 	pdev = wlan_vdev_get_pdev(vdev);
-
 	wlan_pdev_obj_lock(pdev);
 	if (wlan_pdev_nif_fw_cap_get(pdev, WLAN_SOC_C_WEP))
 		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_WEP);
 	if (wlan_pdev_nif_fw_cap_get(pdev, WLAN_SOC_C_TKIP))
 		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_TKIP_MIC);
-	if (wlan_pdev_nif_fw_cap_get(pdev, WLAN_SOC_C_AES))
+	if (wlan_pdev_nif_fw_cap_get(pdev, WLAN_SOC_C_AES)) {
 		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_AES);
+		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_CCM256);
+		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_GCM);
+		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_GCM_256);
+	}
 	if (wlan_pdev_nif_fw_cap_get(pdev, WLAN_SOC_C_CKIP))
 		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_CKIP);
 	if (wlan_pdev_nif_fw_cap_get(pdev, WLAN_SOC_C_WAPI))
 		SET_CIPHER_CAP(crypto_param, WLAN_CRYPTO_CAP_WAPI_SMS4);
 	wlan_pdev_obj_unlock(pdev);
-
 	/* update the crypto cipher table based on the fw caps*/
 	/* update the fw_caps into ciphercaps then attach to objmgr*/
 	wlan_crypto_register_all_ciphers(crypto_param);
@@ -178,13 +170,22 @@ static void wlan_crypto_free_key(struct wlan_crypto_comp_priv *crypto_priv)
 {
 	uint8_t i;
 
+	if (!crypto_priv) {
+		qdf_print("%s[%d] crypto_priv NULL\n", __func__, __LINE__);
+		return;
+	}
+
 	for (i = 0; i < WLAN_CRYPTO_MAXKEYIDX; i++) {
-		if (crypto_priv->key[i])
+		if (crypto_priv->key[i]) {
 			qdf_mem_free(crypto_priv->key[i]);
+			crypto_priv->key[i] = NULL;
+		}
 	}
 
-	if (crypto_priv->igtk_key)
+	if (crypto_priv->igtk_key) {
 		qdf_mem_free(crypto_priv->igtk_key);
+		crypto_priv->igtk_key = NULL;
+	}
 
 }
 
@@ -193,9 +194,18 @@ static QDF_STATUS wlan_crypto_vdev_obj_destroy_handler(
 						void *arg){
 	struct wlan_crypto_comp_priv *crypto_priv;
 
+	if (!vdev) {
+		qdf_print("%s[%d] Vdev NULL\n", __func__, __LINE__);
+		return QDF_STATUS_E_INVAL;
+	}
+
 	crypto_priv = (struct wlan_crypto_comp_priv *)
 				wlan_get_vdev_crypto_obj(vdev);
 
+	if (!crypto_priv) {
+		qdf_print("%s[%d] crypto_priv NULL\n", __func__, __LINE__);
+		return QDF_STATUS_E_INVAL;
+	}
 	wlan_objmgr_vdev_component_obj_detach(vdev,
 						WLAN_UMAC_COMP_CRYPTO,
 						(void *)crypto_priv);
@@ -210,8 +220,16 @@ static QDF_STATUS wlan_crypto_peer_obj_destroy_handler(
 						void *arg){
 	struct wlan_crypto_comp_priv *crypto_priv;
 
+	if (!peer) {
+		qdf_print("%s[%d] Peer NULL\n", __func__, __LINE__);
+		return QDF_STATUS_E_INVAL;
+	}
 	crypto_priv = (struct wlan_crypto_comp_priv *)
 				wlan_get_peer_crypto_obj(peer);
+	if (!crypto_priv) {
+		qdf_print("%s[%d] crypto_priv NULL\n", __func__, __LINE__);
+		return QDF_STATUS_E_INVAL;
+	}
 
 	wlan_objmgr_peer_component_obj_detach(peer,
 						WLAN_UMAC_COMP_CRYPTO,

+ 20 - 35
umac/cmn_services/crypto/src/wlan_crypto_tkip.c

@@ -32,7 +32,6 @@
 #include "wlan_crypto_def_i.h"
 #include "wlan_crypto_main_i.h"
 #include "wlan_crypto_obj_mgr_i.h"
-#include "wlan_crypto_tkip_i.h"
 
 
 static QDF_STATUS tkip_enmic(struct wlan_crypto_key *key, qdf_nbuf_t wbuf,
@@ -43,7 +42,7 @@ static QDF_STATUS tkip_demic(struct wlan_crypto_key *key, qdf_nbuf_t wbuf,
 
 static QDF_STATUS tkip_setkey(struct wlan_crypto_key *key)
 {
-	struct wlan_crypto_tkip_ctx *ctx;
+/*	struct wlan_crypto_tkip_ctx *ctx;
 
 	if (key->private == NULL) {
 		key->private = qdf_mem_malloc(
@@ -53,7 +52,7 @@ static QDF_STATUS tkip_setkey(struct wlan_crypto_key *key)
 	}
 
 	ctx = key->private;
-
+*/
 	return QDF_STATUS_SUCCESS;
 }
 
@@ -62,13 +61,9 @@ static QDF_STATUS tkip_encap(struct wlan_crypto_key *key,
 				uint8_t encapdone,
 				uint8_t hdrlen){
 	uint8_t *ivp;
-	struct ieee80211_frame *wh;
-	qdf_nbuf_t wbuf0;
-	uint16_t pktlen;
 	struct wlan_crypto_cipher *cipher_table;
 
 	cipher_table = key->cipher_table;
-	wh = (struct ieee80211_frame *)qdf_nbuf_data(wbuf);
 
 	/*
 	 * Copy down 802.11 header and add the IV, KeyID, and ExtIV.
@@ -76,12 +71,10 @@ static QDF_STATUS tkip_encap(struct wlan_crypto_key *key,
 	if (encapdone) {
 		ivp = (uint8_t *)qdf_nbuf_data(wbuf);
 	} else {
-		ivp = (uint8_t *)qdf_nbuf_push_head(wbuf, cipher_table->header);
+		ivp = qdf_nbuf_push_head(wbuf, cipher_table->header);
 		qdf_mem_move(ivp, (ivp + cipher_table->header), hdrlen);
-		wh = (struct ieee80211_frame *) qdf_nbuf_data(wbuf);
 	}
 
-	ivp += hdrlen;
 	key->keytsc++;         /* XXX wrap at 48 bits */
 
 	ivp[0] = key->keytsc >> 8;            /* TSC1 */
@@ -93,24 +86,24 @@ static QDF_STATUS tkip_encap(struct wlan_crypto_key *key,
 	ivp[6] = key->keytsc >> 32;           /* PN4 */
 	ivp[7] = key->keytsc >> 40;           /* PN5 */
 
-	wbuf0 = wbuf;
+/*	wbuf0 = wbuf;
 	pktlen = qdf_nbuf_len(wbuf);
 	while (qdf_nbuf_queue_next(wbuf0) != NULL) {
 		wbuf = qdf_nbuf_queue_next(wbuf0);
 		pktlen += qdf_nbuf_len(wbuf0);
 	}
-
+*/
 	/*
 	 * Finally, do software encrypt if neeed.
 	 */
 	if (key->flags & WLAN_CRYPTO_KEY_SWENCRYPT) {
-		/*if not frag frame then do mic calculation */
-		if (tkip_enmic(key, wbuf, encapdone, hdrlen)
-						!= QDF_STATUS_SUCCESS) {
+		qdf_nbuf_realloc_tailroom(wbuf, cipher_table->miclen);
+		if (qdf_nbuf_realloc_tailroom(wbuf, cipher_table->miclen)
+			&& (!wlan_crypto_tkip_encrypt(key->keyval,
+				qdf_nbuf_data(wbuf), qdf_nbuf_len(wbuf),
+				hdrlen))){
 			return QDF_STATUS_CRYPTO_ENCRYPT_FAILED;
 		}
-		if (!wlan_crypto_tkip_encrypt(key, wbuf, hdrlen))
-			return QDF_STATUS_CRYPTO_ENCRYPT_FAILED;
 	}
 
 	return QDF_STATUS_SUCCESS;
@@ -120,7 +113,7 @@ static QDF_STATUS tkip_decap(struct wlan_crypto_key *key,
 				qdf_nbuf_t wbuf,
 				uint8_t tid,
 				uint8_t hdrlen){
-	struct ieee80211_frame *wh;
+	struct ieee80211_hdr *hdr;
 	uint8_t *ivp, *origHdr;
 	uint64_t pn;
 	struct wlan_crypto_cipher *cipher_table;
@@ -132,37 +125,29 @@ static QDF_STATUS tkip_decap(struct wlan_crypto_key *key,
 	 * verify the former and validate the latter.
 	 */
 	origHdr = (uint8_t *)qdf_nbuf_data(wbuf);
-	wh = (struct ieee80211_frame *)origHdr;
+	hdr = (struct ieee80211_hdr *)origHdr;
 
 	ivp = origHdr + hdrlen;
 
 	if ((ivp[WLAN_CRYPTO_IV_LEN] & WLAN_CRYPTO_EXT_IV_BIT) == 0)
 		return 0;
 
-	tid = 16; /* non QoS*/
-	if ((((wh)->i_fc[0] & (0x0c | 0x80)) == (0x00 | 0x80))) {
-		if ((wh->i_fc[1] & 0x03) == 0x03) {
-			tid = ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0]
-									& 0x0f;
-		} else {
-			tid = ((struct ieee80211_qosframe *)wh)->i_qos[0]
-									& 0x0f;
-		}
-	}
+	tid = wlan_get_tid(qdf_nbuf_data(wbuf));
 
-	/* NB: assume IEEEE80211_WEP_MINLEN covers the extended IV */
 	pn = READ_6(ivp[0], ivp[1], ivp[4], ivp[5], ivp[6], ivp[7]);
 
 	if (pn <= key->keyrsc[tid]) {
 		/* Replay violation.*/
-		return 0;
+		return QDF_STATUS_CRYPTO_DECRYPT_FAILED;
 	}
 
 	if ((key->flags & WLAN_CRYPTO_KEY_SWDECRYPT)) {
-		if (!wlan_crypto_tkip_decrypt(key, wbuf, hdrlen) == 0)
+		if (!wlan_crypto_tkip_decrypt(key->keyval,
+					(struct ieee80211_hdr *)origHdr,
+					(origHdr + hdrlen),
+					(qdf_nbuf_len(wbuf) - hdrlen)))
 			return QDF_STATUS_CRYPTO_DECRYPT_FAILED;
 	}
-	/* PN will be updated in tkip_demic*/
 
 	/*
 	 * Copy up 802.11 header and strip crypto bits.
@@ -170,8 +155,8 @@ static QDF_STATUS tkip_decap(struct wlan_crypto_key *key,
 	qdf_mem_move(origHdr + cipher_table->header, origHdr, hdrlen);
 
 	qdf_nbuf_pull_head(wbuf, cipher_table->header);
-	while (qdf_nbuf_queue_next(wbuf) != NULL)
-		wbuf = qdf_nbuf_queue_next(wbuf);
+	/*while (qdf_nbuf_queue_next(wbuf) != NULL)
+		wbuf = qdf_nbuf_queue_next(wbuf);*/
 	qdf_nbuf_trim_tail(wbuf, cipher_table->trailer);
 
 	return QDF_STATUS_SUCCESS;

+ 29 - 51
umac/cmn_services/crypto/src/wlan_crypto_tkip_sw.c

@@ -159,12 +159,12 @@ static void tkip_mixing_phase2(uint8_t *WEPSeed, const uint8_t *TK,
 	WEPSeed[1] = (Hi8(IV16) | 0x20) & 0x7F;
 	WEPSeed[2] = Lo8(IV16);
 	WEPSeed[3] = Lo8((PPK[5] ^ Mk16_le((uint16_t *) &TK[0])) >> 1);
-	WPA_PUT_LE16(&WEPSeed[4], PPK[0]);
-	WPA_PUT_LE16(&WEPSeed[6], PPK[1]);
-	WPA_PUT_LE16(&WEPSeed[8], PPK[2]);
-	WPA_PUT_LE16(&WEPSeed[10], PPK[3]);
-	WPA_PUT_LE16(&WEPSeed[12], PPK[4]);
-	WPA_PUT_LE16(&WEPSeed[14], PPK[5]);
+	wlan_crypto_put_le16(&WEPSeed[4], PPK[0]);
+	wlan_crypto_put_le16(&WEPSeed[6], PPK[1]);
+	wlan_crypto_put_le16(&WEPSeed[8], PPK[2]);
+	wlan_crypto_put_le16(&WEPSeed[10], PPK[3]);
+	wlan_crypto_put_le16(&WEPSeed[12], PPK[4]);
+	wlan_crypto_put_le16(&WEPSeed[14], PPK[5]);
 }
 
 
@@ -197,24 +197,24 @@ static void michael_mic(const uint8_t *key, const uint8_t *hdr,
 	uint32_t l, r;
 	int i, blocks, last;
 
-	l = WPA_GET_LE32(key);
-	r = WPA_GET_LE32(key + 4);
+	l = wlan_crypto_get_le32(key);
+	r = wlan_crypto_get_le32(key + 4);
 
 	/* Michael MIC pseudo header: DA, SA, 3 x 0, Priority */
-	l ^= WPA_GET_LE32(hdr);
+	l ^= wlan_crypto_get_le32(hdr);
 	michael_block(l, r);
-	l ^= WPA_GET_LE32(&hdr[4]);
+	l ^= wlan_crypto_get_le32(&hdr[4]);
 	michael_block(l, r);
-	l ^= WPA_GET_LE32(&hdr[8]);
+	l ^= wlan_crypto_get_le32(&hdr[8]);
 	michael_block(l, r);
-	l ^= WPA_GET_LE32(&hdr[12]);
+	l ^= wlan_crypto_get_le32(&hdr[12]);
 	michael_block(l, r);
 
 	/* 32-bit blocks of data */
 	blocks = data_len / 4;
 	last = data_len % 4;
 	for (i = 0; i < blocks; i++) {
-		l ^= WPA_GET_LE32(&data[4 * i]);
+		l ^= wlan_crypto_get_le32(&data[4 * i]);
 		michael_block(l, r);
 	}
 
@@ -238,8 +238,8 @@ static void michael_mic(const uint8_t *key, const uint8_t *hdr,
 	/* l ^= 0; */
 	michael_block(l, r);
 
-	WPA_PUT_LE32(mic, l);
-	WPA_PUT_LE32(mic + 4, r);
+	wlan_crypto_put_le32(mic, l);
+	wlan_crypto_put_le32(mic + 4, r);
 }
 
 
@@ -281,8 +281,7 @@ static void michael_mic_hdr(const struct ieee80211_hdr *hdr11, uint8_t *hdr)
 
 uint8_t *wlan_crypto_tkip_decrypt(const uint8_t *tk,
 					const struct ieee80211_hdr *hdr,
-					const uint8_t *data, size_t data_len,
-					size_t *decrypted_len){
+					uint8_t *data, size_t data_len){
 	uint16_t iv16;
 	uint32_t iv32;
 	uint16_t ttak[5];
@@ -299,7 +298,7 @@ uint8_t *wlan_crypto_tkip_decrypt(const uint8_t *tk,
 		return NULL;
 
 	iv16 = (data[0] << 8) | data[2];
-	iv32 = WPA_GET_LE32(&data[4]);
+	iv32 = wlan_crypto_get_le32(&data[4]);
 	wpa_printf(MSG_EXCESSIVE, "TKIP decrypt: iv32=%08x iv16=%04x",
 		   iv32, iv16);
 
@@ -309,16 +308,11 @@ uint8_t *wlan_crypto_tkip_decrypt(const uint8_t *tk,
 	wpa_hexdump(MSG_EXCESSIVE, "TKIP RC4KEY", rc4key, sizeof(rc4key));
 
 	plain_len = data_len - 8;
-	plain = qdf_mem_malloc(plain_len);
-	if (plain == NULL) {
-		qdf_print("%s[%d] mem alloc failed\n", __func__, __LINE__);
-		return NULL;
-	}
-	qdf_mem_copy(plain, data + 8, plain_len);
+	plain = data + 8;
 	wlan_crypto_wep_crypt(rc4key, plain, plain_len);
 
 	icv = wlan_crypto_crc32(plain, plain_len - 4);
-	rx_icv = WPA_GET_LE32(plain + plain_len - 4);
+	rx_icv = wlan_crypto_get_le32(plain + plain_len - 4);
 	if (icv != rx_icv) {
 		wpa_printf(MSG_INFO, "TKIP ICV mismatch in frame from " MACSTR,
 			   MAC2STR(hdr->addr2));
@@ -347,12 +341,10 @@ uint8_t *wlan_crypto_tkip_decrypt(const uint8_t *tk,
 		wpa_hexdump(MSG_DEBUG, "TKIP: Calculated MIC", mic, 8);
 		wpa_hexdump(MSG_DEBUG, "TKIP: Received MIC",
 			    plain + plain_len - 8, 8);
-		qdf_mem_free(plain);
 		return NULL;
 	}
 
-	*decrypted_len = plain_len - 8;
-	return plain;
+	return data;
 }
 
 
@@ -368,14 +360,13 @@ void tkip_get_pn(uint8_t *pn, const uint8_t *data)
 
 
 uint8_t *wlan_crypto_tkip_encrypt(const uint8_t *tk, uint8_t *frame,
-				size_t len, size_t hdrlen, uint8_t *qos,
-				uint8_t *pn, int keyid, size_t *encrypted_len){
+				size_t len, size_t hdrlen){
 	uint8_t michael_hdr[16];
 	uint8_t mic[8];
 	struct ieee80211_hdr *hdr;
 	uint16_t fc;
 	const uint8_t *mic_key;
-	uint8_t *crypt, *pos;
+	uint8_t *pos;
 	uint16_t iv16;
 	uint32_t iv32;
 	uint16_t ttak[5];
@@ -390,35 +381,22 @@ uint8_t *wlan_crypto_tkip_encrypt(const uint8_t *tk, uint8_t *frame,
 	mic_key = tk + ((fc & WLAN_FC_FROMDS) ? 16 : 24);
 	michael_mic(mic_key, michael_hdr, frame + hdrlen, len - hdrlen, mic);
 	wpa_hexdump(MSG_EXCESSIVE, "TKIP: MIC", mic, sizeof(mic));
+	pos = frame + hdrlen;
 
-	iv32 = WPA_GET_BE32(pn);
-	iv16 = WPA_GET_BE16(pn + 4);
+	iv32 = wlan_crypto_get_be32(pos);
+	iv16 = wlan_crypto_get_be16(pos + 4);
 	tkip_mixing_phase1(ttak, tk, hdr->addr2, iv32);
 	wpa_hexdump(MSG_EXCESSIVE, "TKIP TTAK", (uint8_t *) ttak, sizeof(ttak));
 	tkip_mixing_phase2(rc4key, tk, ttak, iv16);
 	wpa_hexdump(MSG_EXCESSIVE, "TKIP RC4KEY", rc4key, sizeof(rc4key));
 
-	crypt = qdf_mem_malloc(len + 8 + sizeof(mic) + 4);
-	if (crypt == NULL) {
-		qdf_print("%s[%d] mem alloc failed\n", __func__, __LINE__);
-		return NULL;
-	}
-	qdf_mem_copy(crypt, frame, hdrlen);
-	pos = crypt + hdrlen;
 	qdf_mem_copy(pos, rc4key, 3);
-	pos += 3;
-	*pos++ = keyid << 6 | BIT(5);
-	*pos++ = pn[3];
-	*pos++ = pn[2];
-	*pos++ = pn[1];
-	*pos++ = pn[0];
-
-	qdf_mem_copy(pos, frame + hdrlen, len - hdrlen);
+	pos += 8;
+
 	qdf_mem_copy(pos + len - hdrlen, mic, sizeof(mic));
-	WPA_PUT_LE32(pos + len - hdrlen + sizeof(mic),
+	wlan_crypto_put_le32(pos + len - hdrlen + sizeof(mic),
 		     wlan_crypto_crc32(pos, len - hdrlen + sizeof(mic)));
 	wlan_crypto_wep_crypt(rc4key, pos, len - hdrlen + sizeof(mic) + 4);
 
-	*encrypted_len = len + 8 + sizeof(mic) + 4;
-	return crypt;
+	return frame;
 }

+ 5 - 15
umac/cmn_services/crypto/src/wlan_crypto_wep.c

@@ -33,9 +33,6 @@
 #include "wlan_crypto_main_i.h"
 #include "wlan_crypto_obj_mgr_i.h"
 
-#include "wlan_crypto_rijndael.h"
-#include "wlan_crypto_tkip_i.h"
-
 
 static QDF_STATUS wep_setkey(struct wlan_crypto_key *key)
 {
@@ -48,11 +45,8 @@ static QDF_STATUS wep_encap(struct wlan_crypto_key *key,
 				uint8_t hdrlen)
 {
 	uint8_t *ivp;
-	struct ieee80211_frame *wh;
 	struct wlan_crypto_cipher *cipher_table;
-	uint16_t off, data_len;
 
-	wh = (struct ieee80211_frame *)qdf_nbuf_data(wbuf);
 	cipher_table = key->cipher_table;
 	/*
 	 * Copy down 802.11 header and add the IV, KeyID, and ExtIV.
@@ -64,8 +58,6 @@ static QDF_STATUS wep_encap(struct wlan_crypto_key *key,
 		ivp = (uint8_t *)qdf_nbuf_push_head(wbuf,
 						cipher_table->header);
 		memmove(ivp, ivp + cipher_table->header, hdrlen);
-		/* recompute wh */
-		wh = (struct ieee80211_frame *) qdf_nbuf_data(wbuf);
 	}
 
 	ivp += hdrlen;
@@ -84,10 +76,9 @@ static QDF_STATUS wep_encap(struct wlan_crypto_key *key,
 	/*
 	 * Finally, do software encrypt if neeed.
 	 */
-	off = hdrlen + cipher_table->header;
-	data_len = qdf_nbuf_len(wbuf) - off;
 	if ((key->flags & WLAN_CRYPTO_KEY_SWENCRYPT) &&
-		!wlan_crypto_wep_encrypt(key->keyval, wbuf, off, data_len)) {
+		!wlan_crypto_wep_encrypt(key->keyval, key->keylen,
+				qdf_nbuf_data(wbuf), qdf_nbuf_len(wbuf))) {
 		return QDF_STATUS_CRYPTO_ENCRYPT_FAILED;
 	}
 
@@ -98,12 +89,10 @@ static QDF_STATUS wep_decap(struct wlan_crypto_key *key,
 					uint8_t tid,
 					uint8_t hdrlen)
 {
-	struct ieee80211_frame *wh;
 	struct wlan_crypto_cipher *cipher_table;
 	uint8_t *origHdr = (uint8_t *)qdf_nbuf_data(wbuf);
 	uint16_t off, data_len;
 
-	wh = (struct ieee80211_frame *)origHdr;
 	cipher_table = key->cipher_table;
 
 	/*
@@ -115,8 +104,9 @@ static QDF_STATUS wep_decap(struct wlan_crypto_key *key,
 	off = hdrlen + cipher_table->header;
 	data_len = qdf_nbuf_len(wbuf) - off - cipher_table->trailer;
 	if ((key->flags & WLAN_CRYPTO_KEY_SWDECRYPT) &&
-		!wlan_crypto_wep_decrypt(key->keyval, wbuf, off, data_len)) {
-		return 0;
+		!wlan_crypto_wep_decrypt(key->keyval, key->keylen,
+				qdf_nbuf_data(wbuf), qdf_nbuf_len(wbuf))) {
+		return QDF_STATUS_CRYPTO_DECRYPT_FAILED;
 	}
 	/*
 	 * Copy up 802.11 header and strip crypto bits.

+ 31 - 31
umac/cmn_services/crypto/src/wlan_crypto_wep_sw.c

@@ -44,13 +44,11 @@ void wlan_crypto_wep_crypt(uint8_t *key, uint8_t *buf, size_t plen)
 }
 
 
-static int wlan_crypto_try_wep(const uint8_t *key, size_t key_len,
-				const uint8_t *data, size_t data_len,
-				uint8_t *plain){
-	uint32_t icv, rx_icv;
+void wlan_crypto_try_wep(const uint8_t *key, size_t key_len,
+				uint8_t *data, size_t data_len,
+				uint32_t *icv){
 	uint8_t k[16];
 	int i, j;
-	int32_t status = -1;
 
 	for (i = 0, j = 0; i < sizeof(k); i++) {
 		k[i] = key[j];
@@ -59,46 +57,48 @@ static int wlan_crypto_try_wep(const uint8_t *key, size_t key_len,
 			j = 0;
 	}
 
-	qdf_mem_copy(plain, data, data_len);
-	wlan_crypto_wep_crypt(k, plain, data_len);
-	icv = wlan_crypto_crc32(plain, data_len - 4);
-	rx_icv = WPA_GET_LE32(plain + data_len - 4);
-	if (icv != rx_icv)
-		return status;
-
-	return 0;
+	wlan_crypto_wep_crypt(k, data, data_len);
+	*icv = wlan_crypto_crc32(data, data_len - 4);
 }
 
-uint8_t *wlan_crypto_wep_decrypt(const uint8_t *key, uint16_t key_len,
-				const struct ieee80211_hdr *hdr,
-				const uint8_t *data, size_t data_len,
-				size_t *decrypted_len){
-
-	uint8_t *plain;
-	int found = 0;
+uint8_t *wlan_crypto_wep_encrypt(const uint8_t *key, uint16_t key_len,
+					uint8_t *data, size_t data_len){
 	uint8_t k[16];
+	uint32_t icv;
 
-	if (data_len < 4 + 4)
+	if (data_len < 4 + 4) {
+		qdf_print("%s[%d] invalid len\n", __func__, __LINE__);
 		return NULL;
-	plain = qdf_mem_malloc(data_len - 4);
+	}
+
+	qdf_mem_copy(k, data, 3);
+	qdf_mem_copy(k + 3, key, key_len);
+	wlan_crypto_try_wep(k, 3 + key_len, data + 4, data_len - 4, &icv);
 
-	if (plain == NULL) {
-		qdf_print("%s[%d] mem alloc failed\n", __func__, __LINE__);
+	return data;
+}
+
+uint8_t *wlan_crypto_wep_decrypt(const uint8_t *key, uint16_t key_len,
+					uint8_t *data, size_t data_len){
+	uint8_t k[16];
+	uint32_t icv, rx_icv;
+
+	if (data_len < 4 + 4) {
+		qdf_print("%s[%d] invalid len\n", __func__, __LINE__);
 		return NULL;
 	}
 
 	qdf_mem_copy(k, data, 3);
 	qdf_mem_copy(k + 3, key, key_len);
 
-	if (wlan_crypto_try_wep(k, 3 + key_len, data + 4,
-			data_len - 4, plain)  == 0)
-		found = 1;
+	rx_icv = wlan_crypto_get_le32(data + data_len - 4);
+
+	wlan_crypto_try_wep(k, 3 + key_len, data + 4, data_len - 4, &icv);
 
-	if (!found) {
-		qdf_mem_free(plain);
+	if (icv != rx_icv) {
+		qdf_print("%s[%d] iv mismatch\n", __func__, __LINE__);
 		return NULL;
 	}
 
-	*decrypted_len = data_len - 4 - 4;
-	return plain;
+	return data;
 }

+ 3 - 3
umac/global_umac_dispatcher/lmac_if/inc/wlan_lmac_if_def.h

@@ -28,7 +28,7 @@
 #include "wlan_atf_utils_defs.h"
 #endif
 
-#if WLAN_CRYPTO_SUPPORTED
+#if WLAN_CONV_CRYPTO_SUPPORTED
 #include "wlan_crypto_global_def.h"
 #endif
 
@@ -372,7 +372,7 @@ struct wlan_lmac_if_tx_ops {
 #ifdef WLAN_ATF_ENABLE
 	struct wlan_lmac_if_atf_tx_ops atf_tx_ops;
 #endif
-#if WLAN_CRYPTO_SUPPORTED
+#if WLAN_CONV_CRYPTO_SUPPORTED
 	struct wlan_lmac_if_crypto_tx_ops crypto_tx_ops;
 #endif
 #ifdef WIFI_POS_CONVERGED
@@ -596,7 +596,7 @@ struct wlan_lmac_if_rx_ops {
 #ifdef WLAN_ATF_ENABLE
 	struct wlan_lmac_if_atf_rx_ops atf_rx_ops;
 #endif
-#if WLAN_CRYPTO_SUPPORTED
+#if WLAN_CONV_CRYPTO_SUPPORTED
 	struct wlan_lmac_if_crypto_rx_ops crypto_rx_ops;
 #endif
 #ifdef WIFI_POS_CONVERGED

+ 2 - 2
umac/global_umac_dispatcher/lmac_if/src/wlan_lmac_if.c

@@ -32,7 +32,7 @@
 #include "target_if_nan.h"
 #endif /* WLAN_FEATURE_NAN_CONVERGENCE */
 
-#if WLAN_CRYPTO_SUPPORTED
+#if WLAN_CONV_CRYPTO_SUPPORTED
 #include "wlan_crypto_global_api.h"
 #endif
 /* Function pointer for OL/WMA specific UMAC tx_ops
@@ -162,7 +162,7 @@ wlan_lmac_if_umac_rx_ops_register(struct wlan_lmac_if_rx_ops *rx_ops)
 	rx_ops->scan.scan_ev_handler = tgt_scan_event_handler;
 	wlan_lmac_if_atf_rx_ops_register(rx_ops);
 
-#if WLAN_CRYPTO_SUPPORTED
+#if WLAN_CONV_CRYPTO_SUPPORTED
 	wlan_crypto_register_crypto_rx_ops(&rx_ops->crypto_rx_ops);
 #endif
 	/* wifi_pos rx ops */