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

📄 sta_ioctl.c

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 C
📖 第 1 页 / 共 5 页
字号:
{	UCHAR ChannelNum = pAd->ChannelListNum;	UCHAR Channel = pAd->CommonCfg.Channel;	if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pAd->CommonCfg.RegTransmitSetting.field.BW  == BW_40))	{		if (Channel > 14)		{			if ((Channel == 36) || (Channel == 44) || (Channel == 52) || (Channel == 60) || (Channel == 100) || (Channel == 108) ||			    (Channel == 116) || (Channel == 124) || (Channel == 132) || (Channel == 149) || (Channel == 157))			{				pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;			}			else if ((Channel == 40) || (Channel == 48) || (Channel == 56) || (Channel == 64) || (Channel == 104) || (Channel == 112) ||					(Channel == 120) || (Channel == 128) || (Channel == 136) || (Channel == 153) || (Channel == 161))			{				pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;			}			else			{				pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;			}		}		else		{			switch (pAd->CommonCfg.CountryRegion  & 0x7f)			{				case REGION_0_BG_BAND:	// 1 -11				case REGION_1_BG_BAND:	// 1 - 13				case REGION_5_BG_BAND:	// 1 - 14					if (Channel <= 4)					{						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;					}					else if (Channel >= 8)					{						if ((ChannelNum - Channel) < 4)							pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;					}					break;				case REGION_2_BG_BAND:	// 10 - 11				case REGION_3_BG_BAND:	// 10 - 13				case REGION_4_BG_BAND:	// 14					pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;					break;				case REGION_6_BG_BAND:	// 3 - 9					if (Channel <= 5)						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;					else if (Channel == 6)						pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;					else if (Channel >= 7)						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;					break;				case REGION_7_BG_BAND:  // 5 - 13					if (Channel <= 8)						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;					else if (Channel >= 10)						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;					break;				default:	// Error. should never happen					break;			}		}	}}VOID RTMPAddKey(	IN	PRTMP_ADAPTER	    pAd, 	IN	PNDIS_802_11_KEY    pKey){	ULONG				KeyIdx;	MAC_TABLE_ENTRY  	*pEntry;		    DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n"));	if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)	{		if (pKey->KeyIndex & 0x80000000)		{		    if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)            {                NdisZeroMemory(pAd->StaCfg.PMK, 32);                NdisMoveMemory(pAd->StaCfg.PMK, pKey->KeyMaterial, pKey->KeyLength);                goto end;            }		    // Update PTK		    NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));              pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;            NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pKey->KeyMaterial, LEN_TKIP_EK);#ifdef WPA_SUPPLICANT_SUPPORT                        if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)            {                NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);                            NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);            }            else#endif // WPA_SUPPLICANT_SUPPORT //            {            	NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);                            NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);            }            // Decide its ChiperAlg        	if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)        		pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;        	else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)        		pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;        	else        		pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;             // Update these related information to MAC_TABLE_ENTRY        	pEntry = &pAd->MacTab.Content[BSSID_WCID];            NdisMoveMemory(pEntry->PairwiseKey.Key, pAd->SharedKey[BSS0][0].Key, LEN_TKIP_EK);                    	NdisMoveMemory(pEntry->PairwiseKey.RxMic, pAd->SharedKey[BSS0][0].RxMic, LEN_TKIP_RXMICK);        	NdisMoveMemory(pEntry->PairwiseKey.TxMic, pAd->SharedKey[BSS0][0].TxMic, LEN_TKIP_TXMICK);        	pEntry->PairwiseKey.CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg;        	// Update pairwise key information to ASIC Shared Key Table	           	AsicAddSharedKeyEntry(pAd,         						  BSS0,         						  0,         						  pAd->SharedKey[BSS0][0].CipherAlg,        						  pAd->SharedKey[BSS0][0].Key,        						  pAd->SharedKey[BSS0][0].TxMic,         						  pAd->SharedKey[BSS0][0].RxMic);        	// Update ASIC WCID attribute table and IVEIV table        	RTMPAddWcidAttributeEntry(pAd,         							  BSS0,         							  0,         							  pAd->SharedKey[BSS0][0].CipherAlg,         							  pEntry);            if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2)                // set 802.1x port control	            pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;		}        else        {            // Update GTK                        pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF);            NdisZeroMemory(&pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId], sizeof(CIPHER_KEY));              pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = LEN_TKIP_EK;            NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key, pKey->KeyMaterial, LEN_TKIP_EK);#ifdef WPA_SUPPLICANT_SUPPORT                        if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)            {                NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);                            NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);        	            }            else#endif // WPA_SUPPLICANT_SUPPORT //                            {            	NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic, pKey->KeyMaterial + LEN_TKIP_EK, LEN_TKIP_TXMICK);                            NdisMoveMemory(pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic, pKey->KeyMaterial + LEN_TKIP_EK + LEN_TKIP_TXMICK, LEN_TKIP_RXMICK);        	            }            // Update Shared Key CipherAlg    		pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_NONE;    		if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled)    			pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_TKIP;    		else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled)    			pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg = CIPHER_AES;            // Update group key information to ASIC Shared Key Table	           	AsicAddSharedKeyEntry(pAd,         						  BSS0,         						  pAd->StaCfg.DefaultKeyId,         						  pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,        						  pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].Key,        						  pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].TxMic,         						  pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].RxMic);        	// Update ASIC WCID attribute table and IVEIV table        	RTMPAddWcidAttributeEntry(pAd,         							  BSS0,         							  pAd->StaCfg.DefaultKeyId,         							  pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].CipherAlg,         							  NULL);            // set 802.1x port control	        pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;        }	}	else	// dynamic WEP from wpa_supplicant	{		UCHAR	CipherAlg;    	PUCHAR	Key;		if(pKey->KeyLength == 32)			goto end;				KeyIdx = pKey->KeyIndex & 0x0fffffff;		if (KeyIdx < 4)		{			// it is a default shared key, for Pairwise key setting			if (pKey->KeyIndex & 0x80000000)			{				pEntry = MacTableLookup(pAd, pKey->BSSID);				if (pEntry)				{					DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey: Set Pair-wise Key\n"));							// set key material and key length 					pEntry->PairwiseKey.KeyLen = (UCHAR)pKey->KeyLength;					NdisMoveMemory(pEntry->PairwiseKey.Key, &pKey->KeyMaterial, pKey->KeyLength);										// set Cipher type					if (pKey->KeyLength == 5)						pEntry->PairwiseKey.CipherAlg = CIPHER_WEP64;					else						pEntry->PairwiseKey.CipherAlg = CIPHER_WEP128;											// Add Pair-wise key to Asic					AsicAddPairwiseKeyEntry(						pAd, 						pEntry->Addr, 						(UCHAR)pEntry->Aid,                		&pEntry->PairwiseKey);					// update WCID attribute table and IVEIV table for this entry					RTMPAddWcidAttributeEntry(						pAd, 						BSS0, 						KeyIdx, // The value may be not zero						pEntry->PairwiseKey.CipherAlg, 						pEntry);				}				}			else	            {				// Default key for tx (shared key)				pAd->StaCfg.DefaultKeyId = (UCHAR) KeyIdx;                     				// set key material and key length				pAd->SharedKey[BSS0][KeyIdx].KeyLen = (UCHAR) pKey->KeyLength;				NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, &pKey->KeyMaterial, pKey->KeyLength);								// Set Ciper type				if (pKey->KeyLength == 5)					pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP64;				else					pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_WEP128;			    			CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg;    			Key = pAd->SharedKey[BSS0][KeyIdx].Key;				// Set Group key material to Asic    			AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, CipherAlg, Key, NULL, NULL);						// Update WCID attribute table and IVEIV table for this group key table  				RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, CipherAlg, NULL);															}		}	}end:    DBGPRINT(RT_DEBUG_INFO, ("<------ RTMPAddKey\n"));}char * rtstrchr(const char * s, int c){    for(; *s != (char) c; ++s)        if (*s == '\0')            return NULL;    return (char *) s;}/*This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function*/intrt_ioctl_giwname(struct net_device *dev,		   struct iw_request_info *info,		   char *name, char *extra){	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;	//check if the interface is down    	if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))    	{        	DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));                  	return -ENETDOWN;       	}	strncpy(name, "RT2860 Wireless", IFNAMSIZ);	return 0;}int rt_ioctl_siwfreq(struct net_device *dev,			struct iw_request_info *info,			struct iw_freq *freq, char *extra){	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;	int 	chan = -1;    //check if the interface is down    if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))    {        DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));        return -ENETDOWN;       }	if (freq->e > 1)		return -EINVAL;	if((freq->e == 0) && (freq->m <= 1000))		chan = freq->m;	// Setting by channel number 	else		MAP_KHZ_TO_CHANNEL_ID( (freq->m /100) , chan); // Setting by frequency - search the table , like 2.412G, 2.422G, 	pAdapter->CommonCfg.Channel = chan;	DBGPRINT(RT_DEBUG_ERROR, ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", SIOCSIWFREQ, pAdapter->CommonCfg.Channel));	return 0;}int rt_ioctl_giwfreq(struct net_device *dev,		   struct iw_request_info *info,		   struct iw_freq *freq, char *extra){	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;	ULONG	m;	DBGPRINT(RT_DEBUG_TRACE,("==>rt_ioctl_giwfreq  %d\n",pAdapter->CommonCfg.Channel));    //check if the interface is down    if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))    {        DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));        return -ENETDOWN;       }	    MAP_CHANNEL_ID_TO_KHZ(pAdapter->CommonCfg.Channel, m);	freq->m = m * 100;	freq->e = 1;	return 0;}int rt_ioctl_siwmode(struct net_device *dev,		   struct iw_request_info *info,		   __u32 *mode, char *extra){	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;    ULONG	Value = 0;	//check if the interface is down    if(!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE))    {    	DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n"));       	return -ENETDOWN;       }	switch (*mode)	{		case IW_MODE_ADHOC:			if (pAdapter->StaCfg.BssType != BSS_ADHOC)			{				                    // Config has changed				pAdapter->bConfigChanged = TRUE;                if (MONITOR_ON(pAdapter))                {                    RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, STANORMAL);                    RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value);					Value &= (~0x80);					RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value);                    OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED);                    pAdapter->StaCfg.bAutoReconnect = TRUE;                    LinkDown(pAdapter, FALSE);                }                if (INFRA_ON(pAdapter))				{					BOOLEAN Cancelled;					// Set the AutoReconnectSsid to prevent it reconnect to old SSID					// Since calling this indicate user don't want to connect to that SSID anymore.					pAdapter->MlmeAux.AutoReconnectSsidLen= 32;					NdisZeroMemory(pAdapter->MlmeAux.AutoReconnectSsid, pAdapter->MlmeAux.AutoReconnectSsidLen);												LinkDown(pAdapter, FALSE);					// First cancel linkdown timer					RTMPCancelTimer(&pAdapter->Mlme.LinkDownTimer, &Cancelled);					DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n"));				}			}			

⌨️ 快捷键说明

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