xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/mvl88w8977/mlan/esa/supplicant.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /** @file supplicant.c
2  *
3  *  @brief This file defines the API for supplicant
4  *
5  * Copyright (C) 2014-2017, Marvell International Ltd.
6  *
7  * This software file (the "File") is distributed by Marvell International
8  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
9  * (the "License").  You may use, redistribute and/or modify this File in
10  * accordance with the terms and conditions of the License, a copy of which
11  * is available by writing to the Free Software Foundation, Inc.,
12  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
13  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14  *
15  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
17  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
18  * this warranty disclaimer.
19  */
20 
21 /******************************************************
22 Change log:
23     03/07/2014: Initial version
24 ******************************************************/
25 
26 #include "wltypes.h"
27 #include "keyMgmtSta.h"
28 #include "keyCommonDef.h"
29 #include "keyMgmtSta.h"
30 #include "pmkCache.h"
31 
32 t_u8
EAPoLKeyPkt_Validation(mlan_buffer * pmbuf)33 EAPoLKeyPkt_Validation(mlan_buffer *pmbuf)
34 {
35 	t_u32 recvd_pkt_len, eapol_pkt_len;
36 	EAPOL_KeyMsg_t *pKeyMsg = NULL;
37 
38 	pKeyMsg =
39 		(EAPOL_KeyMsg_t *)(pmbuf->pbuf + pmbuf->data_offset +
40 				   sizeof(ether_hdr_t));
41 	/* Received eapol pkt length: DataLen - 802.3 header */
42 	recvd_pkt_len = pmbuf->data_len - sizeof(ether_hdr_t);
43 	/* 8021.X header + EAPOL key pkt header */
44 	eapol_pkt_len = sizeof(EAPOL_KeyMsg_t) - sizeof(pKeyMsg->key_data);
45 
46 	if (recvd_pkt_len < eapol_pkt_len) {
47 		PRINTM(MERROR,
48 		       "Invalid EAPOL Key Msg, received length: %u, least length: %u\n",
49 		       recvd_pkt_len, eapol_pkt_len);
50 		return 1;
51 	}
52 	/* Todo: other validation check */
53 
54 	return 0;
55 }
56 
57 static __inline void
ProcessEAPoLKeyPkt(phostsa_private priv,mlan_buffer * pmbuf,IEEEtypes_MacAddr_t * sa,IEEEtypes_MacAddr_t * da)58 ProcessEAPoLKeyPkt(phostsa_private priv, mlan_buffer *pmbuf,
59 		   IEEEtypes_MacAddr_t *sa, IEEEtypes_MacAddr_t *da)
60 {
61 	hostsa_mlan_fns *pm_fns = &priv->mlan_fns;
62 	t_u8 bss_role = pm_fns->Hostsa_get_bss_role(pm_fns->pmlan_private);
63 
64 	PRINTM(MMSG, "ProcessEAPoLKeyPk bss_type=%x bss_role=%x\n",
65 	       pm_fns->bss_type, bss_role);
66 
67 #ifdef MIB_STATS
68 	INC_MIB_STAT(connPtr, eapolRxForESUPPCnt);
69 #endif
70 
71 	if (EAPoLKeyPkt_Validation(pmbuf) != 0)
72 		return;
73 
74 	switch (bss_role) {
75 #ifdef BTAMP
76 	case CONNECTION_TYPE_BTAMP:
77 		ProcessKeyMgmtDataAmp(bufDesc);
78 		break;
79 #endif
80 
81 	case MLAN_BSS_ROLE_STA:
82 		/*key data */
83 		ProcessKeyMgmtDataSta(priv, pmbuf, sa, da);
84 		break;
85 
86 	default:
87 #ifdef AUTHENTICATOR
88 		if (WIFI_DIRECT_MODE_GO == connPtr->DeviceMode) {
89 			ProcessKeyMgmtDataAp(bufDesc);
90 		}
91 #endif
92 
93 		break;
94 	}
95 }
96 
97 t_u8
ProcessEAPoLPkt(void * priv,mlan_buffer * pmbuf)98 ProcessEAPoLPkt(void *priv, mlan_buffer *pmbuf)
99 {
100 	phostsa_private psapriv = (phostsa_private)priv;
101 	ether_hdr_t *pEthHdr =
102 		(ether_hdr_t *)(pmbuf->pbuf + pmbuf->data_offset);
103 	EAP_PacketMsg_t *pEapPkt = NULL;
104 	UINT8 fPacketProcessed = 0;
105 
106 	pEapPkt = (EAP_PacketMsg_t *)((t_u8 *)pEthHdr + sizeof(ether_hdr_t));
107 	switch (pEapPkt->hdr_8021x.pckt_type) {
108 	case IEEE_8021X_PACKET_TYPE_EAPOL_KEY:
109 		ProcessEAPoLKeyPkt(psapriv, pmbuf,
110 				   (IEEEtypes_MacAddr_t *)pEthHdr->sa,
111 				   (IEEEtypes_MacAddr_t *)pEthHdr->da);
112 		fPacketProcessed = 1;
113 		break;
114 
115 #if 0
116 	case IEEE_8021X_PACKET_TYPE_EAP_PACKET:
117 		{
118 			if (WIFI_DIRECT_MODE_CLIENT == connPtr->DeviceMode
119 			    || WIFI_DIRECT_MODE_DEVICE == connPtr->DeviceMode) {
120 				if (pEapPkt->code ==
121 				    IEEE_8021X_CODE_TYPE_REQUEST) {
122 					assocAgent_eapRequestRx(sa);
123 				}
124 			}
125 		}
126 		break;
127 #endif
128 	default:
129 		break;
130 	}
131 //    CLEAN_FLUSH_CACHED_SQMEM((UINT32)(pEapPkt), bufDesc->DataLen);
132 	return fPacketProcessed;
133 }
134 
135 Status_e
supplicantRestoreDefaults(void * priv)136 supplicantRestoreDefaults(void *priv)
137 {
138 	pmkCacheInit(priv);
139 	return SUCCESS;
140 }
141 
142 /* This can also be removed*/
143 //#pragma arm section code = ".init"
144 void
supplicantFuncInit(void * priv)145 supplicantFuncInit(void *priv)
146 {
147 	supplicantRestoreDefaults(priv);
148 }
149 
150 //#pragma arm section code
151 //#endif /* PSK_SUPPLICANT */
152