⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmm_wpa.c

📁 ralink 2870 usb无线网卡 最新驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
    DBGPRINT(RT_DEBUG_TRACE, ("===> WPAStart4WayHS\n"));	if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS))	{		DBGPRINT(RT_DEBUG_ERROR, ("[ERROR]WPAStart4WayHS : The interface is closed...\n"));		return;			}	if (pBssid == NULL)	{		DBGPRINT(RT_DEBUG_ERROR, ("[ERROR]WPAStart4WayHS : No corresponding Authenticator.\n"));				return;    }	// Check the status    if ((pEntry->WpaState > AS_PTKSTART) || (pEntry->WpaState < AS_INITPMK))    {        DBGPRINT(RT_DEBUG_ERROR, ("[ERROR]WPAStart4WayHS : Not expect calling\n"));        return;    }        	// Increment replay counter by 1	ADD_ONE_To_64BIT_VAR(pEntry->R_Counter);		// Randomly generate ANonce			GenRandom(pAd, (UCHAR *)pBssid, pEntry->ANonce);		// Construct EAPoL message - Pairwise Msg 1	// EAPOL-Key(0,0,1,0,P,0,0,ANonce,0,DataKD_M1)			NdisZeroMemory(&EAPOLPKT, sizeof(EAPOL_PACKET));	ConstructEapolMsg(pEntry,					  group_cipher,					  EAPOL_PAIR_MSG_1,					  0,					// Default key index					  pEntry->ANonce,					  NULL,					// TxRSC					  NULL,					// GTK					  NULL,					// RSNIE					  0,					// RSNIE length						  &EAPOLPKT);			// Make outgoing frame    MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL);                RTMPToWirelessSta(pAd, pEntry, Header802_3, 					  LENGTH_802_3, (PUCHAR)&EAPOLPKT, 					  CONV_ARRARY_TO_UINT16(EAPOLPKT.Body_Len) + 4, 					  (pEntry->PortSecured == WPA_802_1X_PORT_SECURED) ? FALSE : TRUE);	// Trigger Retry Timer    RTMPModTimer(&pEntry->RetryTimer, TimeInterval);			// Update State    pEntry->WpaState = AS_PTKSTART;	DBGPRINT(RT_DEBUG_TRACE, ("<=== WPAStart4WayHS: send Msg1 of 4-way \n"));        }/*	========================================================================		Routine Description:		Process Pairwise key Msg-1 of 4-way handshaking and send Msg-2 	Arguments:		pAd			Pointer	to our adapter		Elem		Message body			Return Value:		None			Note:			========================================================================*/VOID PeerPairMsg1Action(	IN PRTMP_ADAPTER    pAd,     IN MAC_TABLE_ENTRY  *pEntry,    IN MLME_QUEUE_ELEM  *Elem) {	UCHAR				PTK[80];	UCHAR               Header802_3[14];	PEAPOL_PACKET		pMsg1;	UINT            	MsgLen;		EAPOL_PACKET		EAPOLPKT;	PUINT8				pCurrentAddr = NULL;	PUINT8				pmk_ptr = NULL;	UCHAR				group_cipher = Ndis802_11WEPDisabled;	PUINT8				rsnie_ptr = NULL;	UCHAR				rsnie_len = 0;	   	DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg1Action \n"));	if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli)))		return;    if (Elem->MsgLen < (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H + sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE - 2))        return;	#ifdef CONFIG_STA_SUPPORT	IF_DEV_CONFIG_OPMODE_ON_STA(pAd)	{						pCurrentAddr = pAd->CurrentAddress;		pmk_ptr = pAd->StaCfg.PMK;		group_cipher = pAd->StaCfg.GroupCipher;		rsnie_ptr = pAd->StaCfg.RSN_IE;		rsnie_len = pAd->StaCfg.RSNIE_Len;	}	#endif // CONFIG_STA_SUPPORT //	// Store the received frame	pMsg1 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];	MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;		// Sanity Check peer Pairwise message 1 - Replay Counter	if (PeerWpaMessageSanity(pAd, pMsg1, MsgLen, EAPOL_PAIR_MSG_1, pEntry) == FALSE)		return;		// Store Replay counter, it will use to verify message 3 and construct message 2	NdisMoveMemory(pEntry->R_Counter, pMsg1->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);			// Store ANonce	NdisMoveMemory(pEntry->ANonce, pMsg1->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);			// Generate random SNonce	GenRandom(pAd, (UCHAR *)pCurrentAddr, pEntry->SNonce);	{	    // Calculate PTK(ANonce, SNonce)	    WpaDerivePTK(pAd,	    			pmk_ptr,			     	pEntry->ANonce,				 	pEntry->Addr, 				 	pEntry->SNonce,				 	pCurrentAddr, 				    PTK, 				    LEN_PTK);		// Save key to PTK entry		NdisMoveMemory(pEntry->PTK, PTK, LEN_PTK);	}		    			// Update WpaState	pEntry->WpaState = AS_PTKINIT_NEGOTIATING;	// Construct EAPoL message - Pairwise Msg 2	//  EAPOL-Key(0,1,0,0,P,0,0,SNonce,MIC,DataKD_M2)	NdisZeroMemory(&EAPOLPKT, sizeof(EAPOL_PACKET));	ConstructEapolMsg(pEntry,					  group_cipher,					  EAPOL_PAIR_MSG_2,  					  0,				// DefaultKeyIdx					  pEntry->SNonce,					  NULL,				// TxRsc					  NULL,				// GTK					  (UCHAR *)rsnie_ptr,					  rsnie_len,					  &EAPOLPKT);	// Make outgoing frame	MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pCurrentAddr, EAPOL);			RTMPToWirelessSta(pAd, pEntry, 					  Header802_3, sizeof(Header802_3), (PUCHAR)&EAPOLPKT, 					  CONV_ARRARY_TO_UINT16(EAPOLPKT.Body_Len) + 4, TRUE);			DBGPRINT(RT_DEBUG_TRACE, ("<=== PeerPairMsg1Action: send Msg2 of 4-way \n"));}	/*    ==========================================================================    Description:        When receiving the second packet of 4-way pairwisekey handshake.    Return:    ==========================================================================*/VOID PeerPairMsg2Action(    IN PRTMP_ADAPTER    pAd,     IN MAC_TABLE_ENTRY  *pEntry,    IN MLME_QUEUE_ELEM  *Elem) {   	UCHAR				PTK[80];    BOOLEAN             Cancelled;    PHEADER_802_11      pHeader;	EAPOL_PACKET        EAPOLPKT;		PEAPOL_PACKET       pMsg2;	UINT            	MsgLen;    UCHAR               Header802_3[LENGTH_802_3];	UCHAR 				TxTsc[6];		PUINT8				pBssid = NULL;	PUINT8				pmk_ptr = NULL;	PUINT8				gtk_ptr = NULL;	UCHAR				default_key = 0;	UCHAR				group_cipher = Ndis802_11WEPDisabled;	PUINT8				rsnie_ptr = NULL;	UCHAR				rsnie_len = 0;    DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg2Action \n"));    if ((!pEntry) || (!pEntry->ValidAsCLI))        return;            if (Elem->MsgLen < (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H + sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE - 2))        return;    // check Entry in valid State    if (pEntry->WpaState < AS_PTKSTART)        return;	    // pointer to 802.11 header	pHeader = (PHEADER_802_11)Elem->Msg;	// skip 802.11_header(24-byte) and LLC_header(8) 	pMsg2 = (PEAPOL_PACKET)&Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];       	MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;	// Store SNonce	NdisMoveMemory(pEntry->SNonce, pMsg2->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE);	{		// Derive PTK		WpaDerivePTK(pAd, 					(UCHAR *)pmk_ptr,  					pEntry->ANonce, 		// ANONCE					(UCHAR *)pBssid, 					pEntry->SNonce, 		// SNONCE					pEntry->Addr, 					PTK, 					LEN_PTK); 		    	NdisMoveMemory(pEntry->PTK, PTK, LEN_PTK);	}	// Sanity Check peer Pairwise message 2 - Replay Counter, MIC, RSNIE	if (PeerWpaMessageSanity(pAd, pMsg2, MsgLen, EAPOL_PAIR_MSG_2, pEntry) == FALSE)		return;    do    {        // delete retry timer		RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled);		// Change state        pEntry->WpaState = AS_PTKINIT_NEGOTIATING;		// Increment replay counter by 1		ADD_ONE_To_64BIT_VAR(pEntry->R_Counter);		// Construct EAPoL message - Pairwise Msg 3		NdisZeroMemory(&EAPOLPKT, sizeof(EAPOL_PACKET));		ConstructEapolMsg(pEntry,						  group_cipher,						  EAPOL_PAIR_MSG_3,						  default_key,						  pEntry->ANonce,						  TxTsc,						  (UCHAR *)gtk_ptr,						  (UCHAR *)rsnie_ptr,						  rsnie_len,						  &EAPOLPKT);                    // Make outgoing frame        MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL);                    RTMPToWirelessSta(pAd, pEntry, Header802_3, LENGTH_802_3, 						  (PUCHAR)&EAPOLPKT, 						  CONV_ARRARY_TO_UINT16(EAPOLPKT.Body_Len) + 4, 						  (pEntry->PortSecured == WPA_802_1X_PORT_SECURED) ? FALSE : TRUE);        pEntry->ReTryCounter = PEER_MSG3_RETRY_TIMER_CTR;		RTMPSetTimer(&pEntry->RetryTimer, PEER_MSG3_RETRY_EXEC_INTV);        		// Update State        pEntry->WpaState = AS_PTKINIT_NEGOTIATING;    }while(FALSE);	DBGPRINT(RT_DEBUG_TRACE, ("<=== PeerPairMsg2Action: send Msg3 of 4-way \n"));}/*	========================================================================		Routine Description:		Process Pairwise key Msg 3 of 4-way handshaking and send Msg 4 	Arguments:		pAd	Pointer	to our adapter		Elem		Message body			Return Value:		None			Note:			========================================================================*/VOID PeerPairMsg3Action(    IN PRTMP_ADAPTER    pAd,     IN MAC_TABLE_ENTRY  *pEntry,    IN MLME_QUEUE_ELEM  *Elem) {	PHEADER_802_11		pHeader;	UCHAR               Header802_3[14];	EAPOL_PACKET		EAPOLPKT;	PEAPOL_PACKET		pMsg3;	UINT            	MsgLen;					PUINT8				pCurrentAddr = NULL;	UCHAR				group_cipher = Ndis802_11WEPDisabled;	   	DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg3Action \n"));		if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli)))		return;    if (Elem->MsgLen < (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H + sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE - 2))		return;#ifdef CONFIG_STA_SUPPORT	IF_DEV_CONFIG_OPMODE_ON_STA(pAd)	{						pCurrentAddr = pAd->CurrentAddress;		group_cipher = pAd->StaCfg.GroupCipher;	}	#endif // CONFIG_STA_SUPPORT //			// Record 802.11 header & the received EAPOL packet Msg3	pHeader	= (PHEADER_802_11) Elem->Msg;	pMsg3 = (PEAPOL_PACKET) &Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H];	MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H;	// Sanity Check peer Pairwise message 3 - Replay Counter, MIC, RSNIE	if (PeerWpaMessageSanity(pAd, pMsg3, MsgLen, EAPOL_PAIR_MSG_3, pEntry) == FALSE)		return;		// Save Replay counter, it will use construct message 4	NdisMoveMemory(pEntry->R_Counter, pMsg3->KeyDesc.ReplayCounter, LEN_KEY_DESC_REPLAY);	// Double check ANonce	if (!NdisEqualMemory(pEntry->ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE))	{		return;	}	// Construct EAPoL message - Pairwise Msg 4	NdisZeroMemory(&EAPOLPKT, sizeof(EAPOL_PACKET));	ConstructEapolMsg(pEntry,					  group_cipher,					  EAPOL_PAIR_MSG_4,  					  0,					// group key index not used in message 4					  NULL,					// Nonce not used in message 4					  NULL,					// TxRSC not used in message 4					  NULL,					// GTK not used in message 4					  NULL,					// RSN IE not used in message 4					  0,					  &EAPOLPKT);	// Update WpaState	pEntry->WpaState = AS_PTKINITDONE;	 		// Update pairwise key		#ifdef CONFIG_STA_SUPPORT	IF_DEV_CONFIG_OPMODE_ON_STA(pAd)	{		PCIPHER_KEY pSharedKey;		pSharedKey = &pAd->SharedKey[BSS0][0];		NdisMoveMemory(pAd->StaCfg.PTK, pEntry->PTK, LEN_PTK);				// Prepare pair-wise key information into shared key table		NdisZeroMemory(pSharedKey, sizeof(CIPHER_KEY));  		pSharedKey->KeyLen = LEN_TKIP_EK;	    NdisMoveMemory(pSharedKey->Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);		NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);		NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);            		// Decide its ChiperAlg		if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)			pSharedKey->CipherAlg = CIPHER_TKIP;		else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)			pSharedKey->CipherAlg = CIPHER_AES;		else			pSharedKey->CipherAlg = CIPHER_NONE;		// Update these related information to MAC_TABLE_ENTRY		pEntry = &pAd->MacTab.Content[BSSID_WCID];		NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK);		NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK);		NdisMoveMemory(pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK);            		pEntry->PairwiseKey.CipherAlg = pSharedKey->CipherAlg;				// Update pairwise key information to ASIC Shared Key Table	   		AsicAddSharedKeyEntry(pAd, 							  BSS0, 							  0, 							  pSharedKey->CipherAlg,							  pSharedKey->Key,							  pSharedKey->TxMic, 							  pSharedKey->RxMic);		// Update ASIC WCID attribute table and IVEIV table		RTMPAddWcidAttributeEntry(pAd, 								  BSS0, 								  0, 								  pSharedKey->CipherAlg, 								  pEntry);	}#endif // CONFIG_STA_SUPPORT //	// open 802.1x port control and privacy filter	if (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK || 		pEntry->AuthMode == Ndis802_11AuthModeWPA2)	{		pEntry->PortSecured = WPA_802_1X_PORT_SECURED;		pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;	#ifdef CONFIG_STA_SUPPORT		STA_PORT_SECURED(pAd);	    // Indicate Connected for GUI	    pAd->IndicateMediaState = NdisMediaStateConnected;#endif // CONFIG_STA_SUPPORT //		DBGPRINT(RT_DEBUG_TRACE, ("PeerPairMsg3Action: AuthMode(%s) PairwiseCipher(%s) GroupCipher(%s) \n",									GetAuthMode(pEntry->AuthMode),									GetEncryptType(pEntry->WepStatus),									GetEncryptType(group_cipher)));	}	else	{		}	// Init 802.3 header and send out

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -