cmm_info.c

来自「ralink最新rt3070 usb wifi 无线网卡驱动程序」· C语言 代码 · 共 2,146 行 · 第 1/5 页

C
2,146
字号
				else#endif // QOS_DLS_SUPPORT //				Wcid = BSSID_WCID;			}			else				Wcid = MCAST_WCID;		}#endif // CONFIG_STA_SUPPORT //	}	// Update WCID attribute table	offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);#ifdef CONFIG_STA_SUPPORT	IF_DEV_CONFIG_OPMODE_ON_STA(pAd)	{		if (pEntry && pEntry->ValidAsMesh)			WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;#ifdef QOS_DLS_SUPPORT		else if ((pEntry) && (pEntry->ValidAsDls) &&					((CipherAlg == CIPHER_TKIP) || 				 	(CipherAlg == CIPHER_TKIP_NO_MIC) || 					(CipherAlg == CIPHER_AES) || 				 	(CipherAlg == CIPHER_NONE))) 			WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;#endif // QOS_DLS_SUPPORT //		else			WCIDAttri = (CipherAlg<<1) | SHAREDKEYTABLE;	}#endif // CONFIG_STA_SUPPORT //			RTMP_IO_WRITE32(pAd, offset, WCIDAttri);			// Update IV/EIV table	offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE);	// WPA mode	if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) || (CipherAlg == CIPHER_AES))	{			// Eiv bit on. keyid always is 0 for pairwise key 					IVEIV = (KeyIdx <<6) | 0x20;		}	 	else	{		// WEP KeyIdx is default tx key. 		IVEIV = (KeyIdx << 6);		}	// For key index and ext IV bit, so only need to update the position(offset+3).#ifdef RT2870	RTUSBMultiWrite_OneByte(pAd, offset+3, &IVEIV);#endif // RT2870 //		DBGPRINT(RT_DEBUG_TRACE,("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",Wcid, KeyIdx, CipherName[CipherAlg]));	DBGPRINT(RT_DEBUG_TRACE,("	WCIDAttri = 0x%x \n",  WCIDAttri));	}/*     ==========================================================================    Description:        Parse encryption typeArguments:    pAdapter                    Pointer to our adapter    wrq                         Pointer to the ioctl argument    Return Value:        None    Note:    ==========================================================================*/CHAR *GetEncryptType(CHAR enc){    if(enc == Ndis802_11WEPDisabled)        return "NONE";    if(enc == Ndis802_11WEPEnabled)    	return "WEP";    if(enc == Ndis802_11Encryption2Enabled)    	return "TKIP";    if(enc == Ndis802_11Encryption3Enabled)    	return "AES";	if(enc == Ndis802_11Encryption4Enabled)    	return "TKIPAES";    else    	return "UNKNOW";}CHAR *GetAuthMode(CHAR auth){    if(auth == Ndis802_11AuthModeOpen)    	return "OPEN";    if(auth == Ndis802_11AuthModeShared)    	return "SHARED";	if(auth == Ndis802_11AuthModeAutoSwitch)    	return "AUTOWEP";    if(auth == Ndis802_11AuthModeWPA)    	return "WPA";    if(auth == Ndis802_11AuthModeWPAPSK)    	return "WPAPSK";    if(auth == Ndis802_11AuthModeWPANone)    	return "WPANONE";    if(auth == Ndis802_11AuthModeWPA2)    	return "WPA2";    if(auth == Ndis802_11AuthModeWPA2PSK)    	return "WPA2PSK";	if(auth == Ndis802_11AuthModeWPA1WPA2)    	return "WPA1WPA2";	if(auth == Ndis802_11AuthModeWPA1PSKWPA2PSK)    	return "WPA1PSKWPA2PSK";	    	return "UNKNOW";}		#if 1 //#ifndef UCOS/*     ==========================================================================    Description:        Get site survey results	Arguments:	    pAdapter                    Pointer to our adapter	    wrq                         Pointer to the ioctl argument    Return Value:        None    Note:        Usage:        		1.) UI needs to wait 4 seconds after issue a site survey command        		2.) iwpriv ra0 get_site_survey        		3.) UI needs to prepare at least 4096bytes to get the results    ==========================================================================*/#define	LINE_LEN	(4+33+20+8+10+9+7+3)	// Channel+SSID+Bssid+WepStatus+AuthMode+Signal+WiressMode+NetworkType#ifdef CONFIG_STA_SUPPORT#endif // CONFIG_STA_SUPPORT //VOID RTMPIoctlGetSiteSurvey(	IN	PRTMP_ADAPTER	pAdapter, 	IN	struct iwreq	*wrq){	CHAR		*msg;	INT 		i=0;	 	INT			WaitCnt;	INT 		Status=0;	CHAR		Ssid[MAX_LEN_OF_SSID +1];    INT         Rssi = 0, max_len = LINE_LEN;	UINT        Rssi_Quality = 0;	NDIS_802_11_NETWORK_TYPE    wireless_mode;	os_alloc_mem(NULL, (PUCHAR *)&msg, sizeof(CHAR)*((MAX_LEN_OF_BSS_TABLE)*max_len));	if (msg == NULL)	{   		DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - msg memory alloc fail.\n"));		return;	}	memset(msg, 0 ,(MAX_LEN_OF_BSS_TABLE)*max_len );	memset(Ssid, 0 ,(MAX_LEN_OF_SSID +1));	sprintf(msg,"%s","\n");	sprintf(msg+strlen(msg),"%-4s%-33s%-20s%-8s%-10s%-9s%-7s%-3s\n",	    "Ch", "SSID", "BSSID", "Enc", "Auth", "Siganl(%)", "W-Mode", " NT");	#ifdef CONFIG_STA_SUPPORT#endif // CONFIG_STA_SUPPORT //	WaitCnt = 0;#ifdef CONFIG_STA_SUPPORT	pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;	while ((ScanRunning(pAdapter) == TRUE) && (WaitCnt++ < 200))		OS_WAIT(500);	#endif // CONFIG_STA_SUPPORT //	for(i=0; i<pAdapter->ScanTab.BssNr ;i++)	{		if( pAdapter->ScanTab.BssEntry[i].Channel==0)			break;		if((strlen(msg)+max_len ) >= IW_SCAN_MAX_DATA)			break;		//Channel		sprintf(msg+strlen(msg),"%-4d", pAdapter->ScanTab.BssEntry[i].Channel);		//SSID		memcpy(Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);		Ssid[pAdapter->ScanTab.BssEntry[i].SsidLen] = '\0';		sprintf(msg+strlen(msg),"%-33s", Ssid);      		//BSSID		sprintf(msg+strlen(msg),"%02x:%02x:%02x:%02x:%02x:%02x   ", 			pAdapter->ScanTab.BssEntry[i].Bssid[0], 			pAdapter->ScanTab.BssEntry[i].Bssid[1],			pAdapter->ScanTab.BssEntry[i].Bssid[2], 			pAdapter->ScanTab.BssEntry[i].Bssid[3], 			pAdapter->ScanTab.BssEntry[i].Bssid[4], 			pAdapter->ScanTab.BssEntry[i].Bssid[5]);		//Encryption Type		sprintf(msg+strlen(msg),"%-8s",GetEncryptType(pAdapter->ScanTab.BssEntry[i].WepStatus));		//Authentication Mode		if (pAdapter->ScanTab.BssEntry[i].WepStatus == Ndis802_11WEPEnabled)			sprintf(msg+strlen(msg),"%-10s", "UNKNOW");		else			sprintf(msg+strlen(msg),"%-10s",GetAuthMode(pAdapter->ScanTab.BssEntry[i].AuthMode));		// Rssi		Rssi = (INT)pAdapter->ScanTab.BssEntry[i].Rssi;		if (Rssi >= -50)			Rssi_Quality = 100;		else if (Rssi >= -80)    // between -50 ~ -80dbm			Rssi_Quality = (UINT)(24 + ((Rssi + 80) * 26)/10);		else if (Rssi >= -90)   // between -80 ~ -90dbm			Rssi_Quality = (UINT)(((Rssi + 90) * 26)/10);		else    // < -84 dbm			Rssi_Quality = 0;		sprintf(msg+strlen(msg),"%-9d", Rssi_Quality);		// Wireless Mode		wireless_mode = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);		if (wireless_mode == Ndis802_11FH ||			wireless_mode == Ndis802_11DS)			sprintf(msg+strlen(msg),"%-7s", "11b");		else if (wireless_mode == Ndis802_11OFDM5)			sprintf(msg+strlen(msg),"%-7s", "11a");		else if (wireless_mode == Ndis802_11OFDM5_N)			sprintf(msg+strlen(msg),"%-7s", "11a/n");		else if (wireless_mode == Ndis802_11OFDM24)			sprintf(msg+strlen(msg),"%-7s", "11b/g");		else if (wireless_mode == Ndis802_11OFDM24_N)			sprintf(msg+strlen(msg),"%-7s", "11b/g/n");		else			sprintf(msg+strlen(msg),"%-7s", "unknow");		//Network Type				if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_ADHOC)			sprintf(msg+strlen(msg),"%-3s", " Ad");		else			sprintf(msg+strlen(msg),"%-3s", " In");        sprintf(msg+strlen(msg),"\n");#ifdef CONFIG_STA_SUPPORT#endif // CONFIG_STA_SUPPORT //	}#ifdef CONFIG_STA_SUPPORT	pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;#endif // CONFIG_STA_SUPPORT //	wrq->u.data.length = strlen(msg);	Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);	DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - wrq->u.data.length = %d\n", wrq->u.data.length));	os_free_mem(NULL, (PUCHAR)msg);	}#define	MAC_LINE_LEN	(14+4+4+10+10+10+6+6)	// Addr+aid+psm+datatime+rxbyte+txbyte+current tx rate+last tx rateVOID RTMPIoctlGetMacTable(	IN PRTMP_ADAPTER pAd, 	IN struct iwreq *wrq){	INT i;	RT_802_11_MAC_TABLE MacTab;	char *msg;	MacTab.Num = 0;	for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)	{		if (pAd->MacTab.Content[i].ValidAsCLI && (pAd->MacTab.Content[i].Sst == SST_ASSOC))		{			COPY_MAC_ADDR(MacTab.Entry[MacTab.Num].Addr, &pAd->MacTab.Content[i].Addr);			MacTab.Entry[MacTab.Num].Aid = (UCHAR)pAd->MacTab.Content[i].Aid;			MacTab.Entry[MacTab.Num].Psm = pAd->MacTab.Content[i].PsMode;#ifdef DOT11_N_SUPPORT			MacTab.Entry[MacTab.Num].MimoPs = pAd->MacTab.Content[i].MmpsMode;#endif // DOT11_N_SUPPORT //			// Fill in RSSI per entry			MacTab.Entry[MacTab.Num].AvgRssi0 = pAd->MacTab.Content[i].RssiSample.AvgRssi0;			MacTab.Entry[MacTab.Num].AvgRssi1 = pAd->MacTab.Content[i].RssiSample.AvgRssi1;			MacTab.Entry[MacTab.Num].AvgRssi2 = pAd->MacTab.Content[i].RssiSample.AvgRssi2;			// the connected time per entry			MacTab.Entry[MacTab.Num].ConnectedTime = pAd->MacTab.Content[i].StaConnectTime;			MacTab.Entry[MacTab.Num].TxRate.field.MCS = pAd->MacTab.Content[i].HTPhyMode.field.MCS;			MacTab.Entry[MacTab.Num].TxRate.field.BW = pAd->MacTab.Content[i].HTPhyMode.field.BW;			MacTab.Entry[MacTab.Num].TxRate.field.ShortGI = pAd->MacTab.Content[i].HTPhyMode.field.ShortGI;			MacTab.Entry[MacTab.Num].TxRate.field.STBC = pAd->MacTab.Content[i].HTPhyMode.field.STBC;			MacTab.Entry[MacTab.Num].TxRate.field.rsv = pAd->MacTab.Content[i].HTPhyMode.field.rsv;			MacTab.Entry[MacTab.Num].TxRate.field.MODE = pAd->MacTab.Content[i].HTPhyMode.field.MODE;			MacTab.Entry[MacTab.Num].TxRate.word = pAd->MacTab.Content[i].HTPhyMode.word;												MacTab.Num += 1;		}	}	wrq->u.data.length = sizeof(RT_802_11_MAC_TABLE);	if (copy_to_user(wrq->u.data.pointer, &MacTab, wrq->u.data.length))	{		DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __FUNCTION__));	}	msg = (CHAR *) kmalloc(sizeof(CHAR)*(MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN), MEM_ALLOC_FLAG);	memset(msg, 0 ,MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN );	sprintf(msg,"%s","\n");	sprintf(msg+strlen(msg),"%-14s%-4s%-4s%-10s%-10s%-10s%-6s%-6s\n",		"MAC", "AID", "PSM", "LDT", "RxB", "TxB","CTxR", "LTxR");		for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)	{		PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];		if (pEntry->ValidAsCLI && (pEntry->Sst == SST_ASSOC))		{			if((strlen(msg)+MAC_LINE_LEN ) >= (MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN) )				break;				sprintf(msg+strlen(msg),"%02x%02x%02x%02x%02x%02x  ",				pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],				pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);			sprintf(msg+strlen(msg),"%-4d", (int)pEntry->Aid);			sprintf(msg+strlen(msg),"%-4d", (int)pEntry->PsMode);			sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.LastDataPacketTime*/); // ToDo			sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalRxByteCount*/); // ToDo			sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalTxByteCount*/); // ToDo			sprintf(msg+strlen(msg),"%-6d",RateIdToMbps[pAd->MacTab.Content[i].CurrTxRate]);			sprintf(msg+strlen(msg),"%-6d\n",0/*RateIdToMbps[pAd->MacTab.Content[i].LastTxRate]*/); // ToDo		}	} 	// for compatible with old API just do the printk to console	//wrq->u.data.length = strlen(msg);	//if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))	{		DBGPRINT(RT_DEBUG_TRACE, ("%s", msg));	}	kfree(msg);}#endif // UCOS //#ifdef DOT11_N_SUPPORTINT	Set_BASetup_Proc(	IN	PRTMP_ADAPTER	pAd, 	IN	PUCHAR			arg){    UCHAR mac[6], tid;	char *token, sepValue[] = ":", DASH = '-';	INT i;    MAC_TABLE_ENTRY *pEntry;/*	The BASetup inupt string format should be xx:xx:xx:xx:xx:xx-d, 		=>The six 2 digit hex-decimal number previous are the Mac address, 		=>The seventh decimal number is the tid value.*/	//printk("\n%s\n", arg);		if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.		return FALSE;	token = strchr(arg, DASH);	if ((token != NULL) && (strlen(token)>1))	{		tid = simple_strtol((token+1), 0, 10);		if (tid > 15)			return FALSE;				*token = '\0';		for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)		{			if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))				return FALSE;			AtoH(token, (PUCHAR)(&mac[i]), 1);		}		if(i != 6)			return FALSE;		printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x\n", mac[0], mac[1],				mac[2], mac[3], mac[4], mac[5], tid);	    pEntry = MacTableLookup(pAd, mac);    	if (pEntry) {        	printk("\nSetup BA Session: Tid = %d\n", tid);	        BAOriSessionSetUp(pAd, pEntry, tid, 0, 100, TRUE);    	}		return TRUE;	}	return FALSE;}INT	Set_BADecline_Proc(	IN	PRTMP_ADAPTER	pAd, 	IN	PUCHAR			arg){	ULONG bBADecline;	bBADecline = simple_strtol(arg, 0, 10);	if (bBADecline == 0)	{		pAd->CommonCfg.bBADecline = FALSE;	}	else if (bBADecline == 1)	{		pAd->CommonCfg.bBADecline = TRUE;	}	else 	{		return FALSE; //Invalid argument	}	DBGPRINT(RT_DEBUG_TRACE, ("Set_BADecline_Proc::(BADecline=%d)\n", pAd->CommonCfg.bBADecline));	return TRUE;}INT	Set_BAOriTearDown_Proc(	IN	PRTMP_ADAPTER	pAd, 	IN	PUCHAR			arg){    UCHAR mac[6], tid;	char *token, sepValue[] = ":", DASH = '-';	INT i;    MAC_TABLE_ENTRY *pEntry;    //printk("\n%s\n", arg);/*	The BAOriTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d, 		=>The six 2 digit hex-decimal number previous are the Mac address, 		=>The seventh decimal number is t

⌨️ 快捷键说明

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