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

📄 sta_ioctl.c

📁 Linux下的RT系列无线网卡驱动,可以直接在x86平台上编译
💻 C
📖 第 1 页 / 共 5 页
字号:
         // ChannelQuality = W1*RSSI + W2*TxPRR + W3*RxPER	 (RSSI 0..100), (TxPER 100..0), (RxPER 100..0)    ChannelQuality = (RSSI_WEIGHTING * NorRssi + 					    TX_WEIGHTING * (100 - 0) + 				        RX_WEIGHTING* (100 - 0)) / 100;    if (ChannelQuality >= 100)        ChannelQuality = 100;            iq->qual = (__u8)ChannelQuality;        iq->level = (__u8)(rssi - pAdapter->BbpRssiToDbmDelta);    iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8)pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); 	// noise level (dBm)    iq->noise += 256 - 143;		    iq->updated = pAdapter->iw_stats.qual.updated;}int rt_ioctl_iwaplist(struct net_device *dev,			struct iw_request_info *info,			struct iw_point *data, char *extra){ 	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;	struct sockaddr addr[IW_MAX_AP];	struct iw_quality qual[IW_MAX_AP];	int i;   	//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;       	}	for (i = 0; i <IW_MAX_AP ; i++)	{		if (i >=  pAdapter->ScanTab.BssNr)			break;		addr[i].sa_family = ARPHRD_ETHER;			memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, MAC_ADDR_LEN);		set_quality(pAdapter, &qual[i], pAdapter->ScanTab.BssEntry[i].Rssi);		}	data->length = i;	memcpy(extra, &addr, i*sizeof(addr[0]));	data->flags = 1;		/* signal quality present (sort of) */	memcpy(extra + i*sizeof(addr[0]), &qual, i*sizeof(qual[i]));	return 0;}#ifdef SIOCGIWSCANint rt_ioctl_siwscan(struct net_device *dev,			struct iw_request_info *info,			struct iw_point *data, char *extra){	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;	ULONG								Now;	int Status = NDIS_STATUS_SUCCESS;	//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;   	}	//BOOLEAN 		StateMachineTouched = FALSE;	if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))		return 0;	do{		Now = jiffies;            if ((OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) &&				((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || 				(pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&					(pAdapter->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))            {                DBGPRINT(RT_DEBUG_TRACE, ("!!! Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n"));				Status = NDIS_STATUS_SUCCESS;				break;            }            if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)            {                MlmeRestartStateMachine(pAdapter);                DBGPRINT(RT_DEBUG_TRACE, ("!!! MLME busy, reset MLME state machine !!!\n"));            }            // tell CNTL state machine to call NdisMSetInformationComplete() after completing            // this request, because this request is initiated by NDIS.            pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE;            // Reset allowed scan retries            pAdapter->StaCfg.ScanCnt = 0;            pAdapter->StaCfg.LastScanTime = Now;            MlmeEnqueue(pAdapter,                     MLME_CNTL_STATE_MACHINE,                     OID_802_11_BSSID_LIST_SCAN,                     0,                     NULL);		Status = NDIS_STATUS_SUCCESS;		//StateMachineTouched = TRUE;		MlmeHandler(pAdapter);	}while(0);	return 0;}#define MAX_CUSTOM_LEN 64  int rt_ioctl_giwscan(struct net_device *dev,			struct iw_request_info *info,			struct iw_point *data, char *extra){	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;	int i=0;	char *current_ev = extra, *previous_ev = extra;	char *end_buf;	char *current_val;	struct iw_event iwe;   	//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 (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))    {		/*		 * Still scanning, indicate the caller should try again.		 */		return -EAGAIN;	}#if WIRELESS_EXT >= 17    end_buf = extra + data->length;#else    end_buf = extra + IW_SCAN_MAX_DATA;#endif    	for (i = 0; i < pAdapter->ScanTab.BssNr; i++) 	{		if (current_ev >= end_buf)        {      #if WIRELESS_EXT >= 17            return -E2BIG;#endif			break;        }				//MAC address		//================================		memset(&iwe, 0, sizeof(iwe));		iwe.cmd = SIOCGIWAP;		iwe.u.ap_addr.sa_family = ARPHRD_ETHER;				memcpy(iwe.u.ap_addr.sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN);        previous_ev = current_ev;			current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);        if (current_ev == previous_ev)            break;		//ESSID			//================================		memset(&iwe, 0, sizeof(iwe));		iwe.cmd = SIOCGIWESSID;		iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen;		iwe.u.data.flags = 1;         previous_ev = current_ev;		current_ev = iwe_stream_add_point(current_ev,end_buf, &iwe, pAdapter->ScanTab.BssEntry[i].Ssid);        if (current_ev == previous_ev)            break;				//Network Type 		//================================		memset(&iwe, 0, sizeof(iwe));		iwe.cmd = SIOCGIWMODE;		if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS)		{			iwe.u.mode = IW_MODE_ADHOC;		}		else if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11Infrastructure)		{			iwe.u.mode = IW_MODE_INFRA;		}		else		{			iwe.u.mode = IW_MODE_AUTO;		}		iwe.len = IW_EV_UINT_LEN;        previous_ev = current_ev;		current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,  IW_EV_UINT_LEN);        if (current_ev == previous_ev)            break;		//Channel and Frequency		//================================		memset(&iwe, 0, sizeof(iwe));		iwe.cmd = SIOCGIWFREQ;		if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter))			iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;		else			iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel;		iwe.u.freq.e = 0;		iwe.u.freq.i = 0;				previous_ev = current_ev;		current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);        if (current_ev == previous_ev)            break;        //Add quality statistics        //================================        memset(&iwe, 0, sizeof(iwe));    	iwe.cmd = IWEVQUAL;    	iwe.u.qual.level = 0;    	iwe.u.qual.noise = 0;        set_quality(pAdapter, &iwe.u.qual, pAdapter->ScanTab.BssEntry[i].Rssi);    	current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);        if (current_ev == previous_ev)            break;		//Encyption key		//================================		memset(&iwe, 0, sizeof(iwe));		iwe.cmd = SIOCGIWENCODE;		if (CAP_IS_PRIVACY_ON (pAdapter->ScanTab.BssEntry[i].CapabilityInfo ))			iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;		else			iwe.u.data.flags = IW_ENCODE_DISABLED;        previous_ev = current_ev;		        current_ev = iwe_stream_add_point(current_ev, end_buf,&iwe, (char *)pAdapter->SharedKey[BSS0][(iwe.u.data.flags & IW_ENCODE_INDEX)-1].Key);        if (current_ev == previous_ev)            break;		//Bit Rate		//================================		if (pAdapter->ScanTab.BssEntry[i].SupRateLen)        {            UCHAR tmpRate = pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter->ScanTab.BssEntry[i].SupRateLen-1];            memset(&iwe, 0, sizeof(iwe));    		iwe.cmd = SIOCGIWRATE;    		current_val = current_ev + IW_EV_LCP_LEN;                        if (tmpRate == 0x82)                iwe.u.bitrate.value =  1 * 1000000;            else if (tmpRate == 0x84)                iwe.u.bitrate.value =  2 * 1000000;            else if (tmpRate == 0x8B)                iwe.u.bitrate.value =  5.5 * 1000000;            else if (tmpRate == 0x96)                iwe.u.bitrate.value =  11 * 1000000;            else    		    iwe.u.bitrate.value =  (tmpRate/2) * 1000000;                		iwe.u.bitrate.disabled = 0;    		current_val = iwe_stream_add_value(current_ev,    				current_val, end_buf, &iwe,    				IW_EV_PARAM_LEN);                        if((current_val-current_ev)>IW_EV_LCP_LEN)                current_ev = current_val;            else                break;        }            #ifdef WPA_SUPPLICANT_SUPPORT                    //WPA/WPA2 IE		//================================        if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0 &&            ((pAdapter->ScanTab.BssEntry[i].WpaIE.IELen*2) + 7) <= MAX_CUSTOM_LEN)        {            UCHAR   idx;            char custom[MAX_CUSTOM_LEN] = {0};                		NdisZeroMemory(&iwe, sizeof(iwe));    		iwe.cmd = IWEVCUSTOM;            if (pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0] == IE_WPA2)                sprintf(custom, "rsn_ie=");            else                sprintf(custom, "wpa_ie=");            for (idx=0; idx<pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; idx++)                sprintf(custom, "%s%02x", custom, pAdapter->ScanTab.BssEntry[i].WpaIE.IE[idx]);            iwe.u.data.length = (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen*2) + 7;            previous_ev = current_ev;    		current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,  custom);            if (current_ev == previous_ev)                break;        }#endif // WPA_SUPPLICANT_SUPPORT //        		//================================		memset(&iwe, 0, sizeof(iwe));	}	data->length = current_ev - extra; 	DBGPRINT(RT_DEBUG_ERROR ,("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n",i , pAdapter->ScanTab.BssNr, data->length));	return 0;}#endifint rt_ioctl_siwessid(struct net_device *dev,			 struct iw_request_info *info,			 struct iw_point *data, char *essid){	PRTMP_ADAPTER pAdapter = (PRTMP_ADAPTER) dev->priv;	NDIS_802_11_SSID					Ssid, *pSsid=NULL;	//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;       }	memset(&Ssid, 0x00, sizeof(NDIS_802_11_SSID));	if (data->flags)	{		if (data->length > (IW_ESSID_MAX_SIZE + 1)) //includes null character.		{			return -E2BIG;		}        memcpy(Ssid.Ssid, essid, data->length);        if (Ssid.Ssid[data->length - 1] == '\0')        {            if (data->length > 0)		        Ssid.SsidLength = data->length - 1;	//minus null character.        }		else            Ssid.SsidLength = data->length;        if (Ssid.SsidLength > IW_ESSID_MAX_SIZE)		{		    DBGPRINT(RT_DEBUG_TRACE ,("The length of SSID exceeds 32 !\n"));			return -E2BIG;		}	}	else    // ANY ssid	{	    Ssid.SsidLength = 0; 		memcpy(pSsid->Ssid, "", 0);		pAdapter->StaCfg.BssType = BSS_INFRA;       	pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen;       	pAdapter->StaCfg.WepStatus  = Ndis802_11EncryptionDisabled;		        }	pSsid = &Ssid;    if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE)    {        MlmeRestartStateMachine(pAdapter);        DBGPRINT(RT_DEBUG_TRACE ,("!!! MLME busy, reset MLME state machine !!!\n"));    }    // tell CNTL state machine to call NdisMSetInformationComplete() after completing	// this request, because this request is initiated by NDIS.	// To prevent some kernel thread is very low priority ...so essid copy immediately for later wpapsk counting.	if ((pAdapter->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) && (pAdapter->StaCfg.AuthMode != Ndis802_11AuthModeWPANone))		NdisMoveMemory(pAdapter->MlmeAux.Ssid, Ssid.Ssid, Ssid.SsidLength);    	pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE; 	DBGPRINT(RT_DEBUG_TRACE ,("===>rt_ioctl_siwessid:: (Ssid.SsidLength = %d, %s)\n",Ssid.SsidLength, Ssid.Ssid));		MlmeEnqueue(pAdapter, 				MLME_CNTL_STATE_MACHINE, 				OID_802_11_SSID,				sizeof(NDIS_802_11_SSID),				(VOID *)pSsid);        MlmeHandler(pAdapter);	return 0;}int rt_ioctl_giwessid(struct net_device *dev,			 struct iw_request_info *info,			 struct iw_point *data, char *essid){	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;   	}

⌨️ 快捷键说明

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