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

📄 iwctl.c

📁 VIA VT6655 x86下的Linux Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:


/*
 * Wireless Handler : get capability range
 */

int iwctl_giwrange(struct net_device *dev,
             struct iw_request_info *info,
             struct iw_point *wrq,
             char *extra)
{
	struct iw_range *range = (struct iw_range *) extra;    
	int		i,k;
    BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};    
    
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");	
	if (wrq->pointer) {
		wrq->length = sizeof(struct iw_range);
		memset(range, 0, sizeof(struct iw_range));
		range->min_nwid = 0x0000;
		range->max_nwid = 0x0000;
		range->num_channels = 14;
		// Should be based on cap_rid.country to give only
		//  what the current card support 
		k = 0;
		for(i = 0; i < 14; i++) {
			range->freq[k].i = i + 1; // List index 
			range->freq[k].m = frequency_list[i] * 100000;
			range->freq[k++].e = 1;	// Values in table in MHz -> * 10^5 * 10 
		}
		range->num_frequency = k;
		// Hum... Should put the right values there 
		range->max_qual.qual = 255;
		range->max_qual.level = 0;	
		range->max_qual.noise = 0;
		range->sensitivity = 255;

		for(i = 0 ; i < 13 ; i++) {
			range->bitrate[i] = abySupportedRates[i] * 500000;
			if(range->bitrate[i] == 0)
				break;
		}
		range->num_bitrates = i;

		// Set an indication of the max TCP throughput
		// in bit/s that we can expect using this interface.
		//  May be use for QoS stuff... Jean II 
		if(i > 2)
			range->throughput = 5 * 1000 * 1000;
		else
			range->throughput = 1.5 * 1000 * 1000;

		range->min_rts = 0;
		range->max_rts = 2312;
		range->min_frag = 256;
		range->max_frag = 2312;
		
		
	    // the encoding capabilities 
	    range->num_encoding_sizes = 3;
	    // 64(40) bits WEP 
	    range->encoding_size[0] = 5;
	    // 128(104) bits WEP 
	    range->encoding_size[1] = 13;
	    // 256 bits for WPA-PSK 
	    range->encoding_size[2] = 32;
	    // 4 keys are allowed 
	    range->max_encoding_tokens = 4;		

#if WIRELESS_EXT > 17
	    range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
		    IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
#endif 

#if WIRELESS_EXT > 9
		range->min_pmp = 0;
		range->max_pmp = 1000000;// 1 secs 
		range->min_pmt = 0;
		range->max_pmt = 1000000;// 1 secs	
		range->pmp_flags = IW_POWER_PERIOD;
		range->pmt_flags = IW_POWER_TIMEOUT;
		range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;

		// Transmit Power - values are in mW 

        range->txpower[0] = 100;
		range->num_txpower = 1;
		range->txpower_capa = IW_TXPOW_MWATT;
#endif // WIRELESS_EXT > 9 
#if WIRELESS_EXT > 10
		range->we_version_source = SUPPORTED_WIRELESS_EXT;
		range->we_version_compiled = WIRELESS_EXT;
		range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
		range->retry_flags = IW_RETRY_LIMIT;
		range->r_time_flags = IW_RETRY_LIFETIME;
		range->min_retry = 1;
		range->max_retry = 65535;
		range->min_r_time = 1024;
		range->max_r_time = 65535 * 1024;
#endif // WIRELESS_EXT > 10 
#if WIRELESS_EXT > 11
		// Experimental measurements - boundary 11/5.5 Mb/s 
		// Note : with or without the (local->rssi), results
		//  are somewhat different. - Jean II 
		range->avg_qual.qual = 6;
		range->avg_qual.level = 176;	// -80 dBm 
		range->avg_qual.noise = 0;
#endif // WIRELESS_EXT > 11 
	}    
    
    
	return 0;
}


/*
 * Wireless Handler : set ap mac address
 */

int iwctl_siwap(struct net_device *dev,
             struct iw_request_info *info,
			 struct sockaddr *wrq,             
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)dev->priv;    
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj); 	
    int rc = 0;
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");

	if (wrq->sa_family != ARPHRD_ETHER)
		rc = -EINVAL;
	else {
		memset(pMgmt->abyDesireBSSID, 0xFF, 6);
		memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
        if (pDevice->flags & DEVICE_FLAGS_OPENED) {
		    pDevice->bCommit = TRUE;
   		}			
	}    
	return rc;
}

/*
 * Wireless Handler : get ap mac address
 */

int iwctl_giwap(struct net_device *dev,
             struct iw_request_info *info,
			 struct sockaddr *wrq,                          
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)dev->priv;    
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj); 	
        
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
    
    memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
    
    if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode == WMAC_MODE_ESS_STA))
        memset(wrq->sa_data, 0, 6);
	    
    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
        memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
    }    

	wrq->sa_family = ARPHRD_ETHER;
	
	return 0;
    
}


/*
 * Wireless Handler : get ap list
 */

int iwctl_giwaplist(struct net_device *dev,
             struct iw_request_info *info,
             struct iw_point *wrq,
             char *extra)
{
	int ii,jj, rc = 0;
	struct sockaddr sock[IW_MAX_AP];
	struct iw_quality qual[IW_MAX_AP];    
	PSDevice	        pDevice = (PSDevice)dev->priv;    
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj); 	  	
	
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");	
	// Only super-user can see AP list
	
	if (!capable(CAP_NET_ADMIN)) {
		rc = -EPERM;
		return rc;
	}

	if (wrq->pointer) {

		PKnownBSS pBSS = &(pMgmt->sBSSList[0]);			

		for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
		    pBSS = &(pMgmt->sBSSList[ii]);
            if (!pBSS->bActive)
                continue;
            if ( jj >= IW_MAX_AP)
                break;   			    
			memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
			sock[jj].sa_family = ARPHRD_ETHER;
			qual[jj].level = pBSS->uRSSI;
			qual[jj].qual = qual[jj].noise = 0;
			qual[jj].updated = 2;
			jj++;
		}

		wrq->flags = 1; // Should be define'd 
		wrq->length = jj;		
		memcpy(extra, sock, sizeof(struct sockaddr)*jj);
		memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
	}	    
    
	return rc;
}


/*
 * Wireless Handler : set essid
 */

int iwctl_siwessid(struct net_device *dev,
             struct iw_request_info *info,
             struct iw_point *wrq,
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)dev->priv;
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj); 		
    PWLAN_IE_SSID       pItemSSID;
    
    
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");	

	// Check if we asked for `any' 
	if(wrq->flags == 0) {
		// Just send an empty SSID list 
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
	    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid to 'any' \n");
	} else {
		// Set the SSID 
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
        pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
        pItemSSID->byElementID = WLAN_EID_SSID;
		memcpy(pItemSSID->abySSID, extra, wrq->length);
	    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
		pItemSSID->len = wrq->length - 1;
	}
    if (pDevice->flags & DEVICE_FLAGS_OPENED) {
	    pDevice->bCommit = TRUE;
	}			

    
	return 0;
}


/*
 * Wireless Handler : get essid
 */

int iwctl_giwessid(struct net_device *dev,
             struct iw_request_info *info,
             struct iw_point *wrq,             
             char *extra)
{

	PSDevice	        pDevice = (PSDevice)dev->priv;
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj); 	
	PWLAN_IE_SSID       pItemSSID;
	
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");		

	// Note : if wrq->u.data.flags != 0, we should
	// get the relevant SSID from the SSID list...

	// Get the current SSID 
    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
	//pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;			
	memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
	extra[pItemSSID->len] = '\0';
	wrq->length = pItemSSID->len + 1;
	wrq->flags = 1; // active 

    
	return 0;
}

/*
 * Wireless Handler : set data rate
 */

int iwctl_siwrate(struct net_device *dev,
             struct iw_request_info *info,
			 struct iw_param *wrq,
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)dev->priv;
    int rc = 0;    
	u8	brate = 0;
	int	i;
	BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};	
   
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");		
    if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
        rc = -EINVAL;
        return rc;
    }    

	// First : get a valid bit rate value 

	// Which type of value 
	if((wrq->value < 13) &&
	   (wrq->value >= 0)) {
		// Setting by rate index 
		// Find value in the magic rate table
		brate = wrq->value;
	} else {
		// Setting by frequency value
		u8	normvalue = (u8) (wrq->value/500000);

		// Check if rate is valid 
		for(i = 0 ; i < 13 ; i++) {
			if(normvalue == abySupportedRates[i]) {
				brate = i;
				break;
			}
		}
	}
	// -1 designed the max rate (mostly auto mode) 
	if(wrq->value == -1) {
		// Get the highest available rate 
		for(i = 0 ; i < 13 ; i++) {
			if(abySupportedRates[i] == 0)
				break;
		}
		if(i != 0)
			brate = i - 1;
			
	}
	// Check that it is valid 
	// brate is index of abySupportedRates[] 
	if(brate > 13 ) {
		rc = -EINVAL;
		return rc;
	}		

	// Now, check if we want a fixed or auto value 
	if(wrq->fixed != 0) {
		// Fixed mode 
		// One rate, fixed 
		pDevice->bFixRate = TRUE;
        if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
            pDevice->uConnectionRate = 3;
        }
        else {
            pDevice->uConnectionRate = brate;
            DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
        }    
        
	}
	else {
        pDevice->bFixRate = FALSE;
        pDevice->uConnectionRate = 13;    
    }

	return rc;
}

/*
 * Wireless Handler : get data rate
 */

int iwctl_giwrate(struct net_device *dev,
             struct iw_request_info *info,
             struct iw_param *wrq,
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)dev->priv;    
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
    {
        BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
	    int brate = 0;
		if (pDevice->uConnectionRate < 13) {
	        brate = abySupportedRates[pDevice->uConnectionRate];
	    }else {
            if (pDevice->byBBType == BB_TYPE_11B)
	            brate = 0x16;
            if (pDevice->byBBType == BB_TYPE_11G)
	            brate = 0x6C;		            
            if (pDevice->byBBType == BB_TYPE_11A)		            
	            brate = 0x6C;		            		            
	    }
	    
	    if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
            if (pDevice->byBBType == BB_TYPE_11B)
	            brate = 0x16;
            if (pDevice->byBBType == BB_TYPE_11G)
	            brate = 0x6C;		            
            if (pDevice->byBBType == BB_TYPE_11A)
	            brate = 0x6C;
	    }        
//    		if (pDevice->uConnectionRate == 13)
//                brate = abySupportedRates[pDevice->wCurrentRate];
	    wrq->value = brate * 500000;
	    // If more than one rate, set auto 
	    if (pDevice->bFixRate == TRUE)
	        wrq->fixed = TRUE;
    }    
    
    
	return 0;
}



/*
 * Wireless Handler : set rts threshold
 */

int iwctl_siwrts(struct net_device *dev,
             struct iw_request_info *info,
			 struct iw_param *wrq,
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)dev->priv;
	int rc = 0;
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");	

	{
	    int rthr = wrq->value;
	    if(wrq->disabled)
			rthr = 2312;
	    if((rthr < 0) || (rthr > 2312)) {
			rc = -EINVAL;
    	}else {
		    pDevice->wRTSThreshold = rthr;
	    }
    }    
    
	return 0;
}

/*
 * Wireless Handler : get rts
 */

int iwctl_giwrts(struct net_device *dev,
             struct iw_request_info *info,
			 struct iw_param *wrq,
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)dev->priv;
	    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");		
	wrq->value = pDevice->wRTSThreshold;
	wrq->disabled = (wrq->value >= 2312);
	wrq->fixed = 1;    
	
	return 0;
}

/*
 * Wireless Handler : set fragment threshold
 */

int iwctl_siwfrag(struct net_device *dev,
             struct iw_request_info *info,
			 struct iw_param *wrq,
             char *extra)
{
    PSDevice	        pDevice = (PSDevice)dev->priv;
    int rc = 0;
    int fthr = wrq->value;    
    
    
    DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");


    if (wrq->disabled)
		fthr = 2312;
    if((fthr < 256) || (fthr > 2312)) {
		rc = -EINVAL;
    }else {
		 fthr &= ~0x1;	// Get an even value 
	     pDevice->wFragmentationThreshold = (u16)fthr;
    }
    
	return rc;
}

/*
 * Wireless Handler : get fragment threshold
 */

int iwctl_giwfrag(struct net_device *dev,
             struct iw_request_info *info,
			 struct iw_param *wrq,
             char *extra)
{

⌨️ 快捷键说明

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