wt_ioctl.c
来自「mini-PCI driver for LHWT chipsets」· C语言 代码 · 共 1,783 行 · 第 1/3 页
C
1,783 行
{ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; if (awrq->sa_family != ARPHRD_ETHER) return -EINVAL; /* prepare the structure for the set object */ memcpy(&priv->MacParameter.mBssid, awrq->sa_data, 6); FN_EXIT(0,0); return 0; /* Call commit handler */}/* get AP address*/static intwt4_get_wap(struct net_device *ndev, struct iw_request_info *info, struct sockaddr *awrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; memcpy(awrq->sa_data, &priv->MacParameter.mBssid, 6); awrq->sa_family = ARPHRD_ETHER; FN_EXIT(0,0); return 0;}static intwt4_set_scan(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; ON_OID_802_11_BSSID_LIST_SCAN( priv ); FN_EXIT(0,0); return 0;}unsigned char wtwlan_get_level_from_dbm( IN PWT_ADAPTER priv, int level_dbm ){ unsigned char signal_level; FN_ENTER; signal_level = (unsigned char)(level_dbm&0xff); FN_EXIT(0,0); return ( signal_level ); }static intwtwlan_get_bss_max_rate( IN PWT_ADAPTER priv, PWTWLAN_BSSID_DESC bss ){ /* Add basic and extended rates */ int i; int max_rate = dot11rate1M; FN_ENTER; for( i = 0; i < bss->ie_rates.length; i++ ) { if( ( bss->ie_rates.sup_rates[i] & 0x7f ) > max_rate ) max_rate = ( bss->ie_rates.sup_rates[i] & 0x7f ); } for( i = 0; i < bss->ie_extendrates.len; i++ ) { if( ( bss->ie_extendrates.extrates[i] & 0x7f ) > max_rate ) max_rate = ( bss->ie_extendrates.extrates[i] & 0x7f ); } FN_EXIT(0,0); return max_rate; }static char *wt4_translate_bss(struct net_device *ndev, char *current_ev, char *end_buf, PWTWLAN_BSSID_DESC bss, char noise){ struct iw_event iwe; /* Temporary buffer */ WT_ADAPTER *priv = netdev_priv(ndev); int max_rate; FN_ENTER; /* The first entry must be the MAC address */ iwe.cmd = SIOCGIWAP; iwe.u.ap_addr.sa_family = ARPHRD_ETHER; memcpy(iwe.u.ap_addr.sa_data, bss->ndisbssidex.MacAddress, ETH_ALEN ); current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN); /* The following entries will be displayed in the same order we give them */ /* The ESSID. */ iwe.cmd = SIOCGIWESSID; iwe.u.data.flags = 1; if( bss->ndisbssidex.Ssid.SsidLength == 0 ) { iwe.u.data.length = sizeof("<hidden>"); current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "<hidden>"); } else { iwe.u.data.length = min( bss->ndisbssidex.Ssid.SsidLength, (ULONG)32 ); current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ndisbssidex.Ssid.Ssid); } /* Add name*/ iwe.cmd = SIOCGIWNAME; if( bss->ndisbssidex.NetworkTypeInUse == Ndis802_11OFDM5 ) { snprintf(iwe.u.name, IFNAMSIZ, "WT4abg %s", "a mode"); } else if( bss->ndisbssidex.NetworkTypeInUse == Ndis802_11OFDM24 ) { snprintf(iwe.u.name, IFNAMSIZ, "WT4abg %s", "g mode"); } else { snprintf(iwe.u.name, IFNAMSIZ, "WT4abg %s", "b mode"); } current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_CHAR_LEN); /* Mode */ iwe.cmd = SIOCGIWMODE; if ( bss->ie_fixed.Capabilities & (cIbss | cEss)) { if (bss->ie_fixed.Capabilities & cEss) iwe.u.mode = IW_MODE_INFRA; //IW_MODE_MASTER ? else iwe.u.mode = IW_MODE_ADHOC; current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN); } /* Encryption capability */ iwe.cmd = SIOCGIWENCODE; if (bss->ie_fixed.Capabilities & cPrivacy ) iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; else iwe.u.data.flags = IW_ENCODE_DISABLED; iwe.u.data.length = 0; current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, NULL); /* Add frequency. (short) bss->channel is the frequency in MHz */ iwe.cmd = SIOCGIWFREQ; iwe.u.freq.m = bss->ie_ds.curr_channel; iwe.u.freq.e = 0; iwe.u.freq.i = 0; current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN); /* Add quality statistics */ iwe.cmd = IWEVQUAL; iwe.u.qual.level = wtwlan_get_level_from_dbm( priv, bss->ndisbssidex.Rssi ); #if 0 if( bss->ndisbssidex.Rssi <= 0 ) { iwe.u.qual.level = wtwlan_get_level_from_dbm( priv, bss->ndisbssidex.Rssi ); } else { //check later wt __u8 level_local = 0; if( bss->ndisbssidex.Rssi > 100 ) level_local = (level_local *100) / 0xff ; if( level_local < noise ) level_local = noise; iwe.u.qual.level = level_local; }#endif iwe.u.qual.noise = noise; /* do a simple SNR for quality */ iwe.u.qual.qual = iwe.u.qual.level - noise; current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN); /* rates */ iwe.cmd = SIOCGIWRATE; iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; max_rate = wtwlan_get_bss_max_rate( priv, bss ); iwe.u.bitrate.value = max_rate * 500000; current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_PARAM_LEN); /*Add wpa_ie later*/ FN_EXIT(0,0); return current_ev;}u32 wtwlan_get_noice( IN PWT_ADAPTER priv ){ FN_ENTER; FN_EXIT(0,0); return 10;}intwt4_get_scan(struct net_device *ndev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); int i, rvalue = 0; u32 noise = 0; char *current_ev = extra; FN_ENTER; // sem should use later in scan db if( priv->MlmeParameter.bScanOngoing ) { dwrq->length = 0; return -EAGAIN; } if( priv->Ndis80211Parameter.pWlanScanDb->NumberOfItems == 0) { dwrq->length = 0; return -ENODATA; } /* first get the noise value. We will use it to report the link quality */ noise = wtwlan_get_noice(priv); /* ok now, scan the list and translate its info */ //printk(LEVEL" Scan db size is %d \r\n",priv->Ndis80211Parameter.pWlanScanDb->NumberOfItems); for (i = 0; i < priv->Ndis80211Parameter.pWlanScanDb->NumberOfItems ; i++) { current_ev = wt4_translate_bss(ndev, current_ev, extra + dwrq->length, &(priv->Ndis80211Parameter.pWlanScanDb->wlandesc[i]), noise);#if WIRELESS_EXT > 16 /* Check if there is space for one more entry */ if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) { /* Ask user space to try again with a bigger buffer */ rvalue = -E2BIG; break; }#endif /* WIRELESS_EXT > 16 */ } dwrq->length = (current_ev - extra); dwrq->flags = 0; /* todo */ FN_EXIT(0,0); return rvalue;}static intwt4_set_essid(struct net_device *ndev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); NDIS_802_11_SSID reqssid; int length = 0; FN_ENTER; //dbg_info_str(extra) //spin_lock(&priv->SsidSetLock); if (dwrq->flags && dwrq->length) { if (dwrq->length > min(33, IW_ESSID_MAX_SIZE + 1)) return -E2BIG; } else { // donot support 'any' here, check later return -EINVAL; } memset( &reqssid, 0, sizeof( NDIS_802_11_SSID ) ); length = dwrq->length - 1; reqssid.SsidLength = length; memcpy(reqssid.Ssid, extra, dwrq->length); SSIDSetProc( priv, (PVOID)(&reqssid) ); //spin_unlock(&priv->SsidSetLock); FN_EXIT(0,0); return 0;}static intwt4_get_essid(struct net_device *ndev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev);// union oid_res_t r; /* if link return essid else 'any'*/ /* Adapter->MacParameter.CurrentState or mdisable */ FN_ENTER; //spin_lock(&priv->SsidGetLock); if( ( priv->MacParameter.CurrentState == ASOC_PASS ) || ( priv->MacParameter.CurrentState == IBSS_ACTIVE ) || ( priv->MacParameter.CurrentState == IBSS_IDLE ) ) { dwrq->flags = 1; /* set ESSID to ON for Wireless Extensions */ /* if it is to big, trunk it */ dwrq->length = min(IW_ESSID_MAX_SIZE, (int)(priv->NdisCurNet.WlanDesc.ndisbssidex.Ssid.SsidLength + 1)); } else { dwrq->flags = 0; dwrq->length = 0; } memcpy(extra, priv->NdisCurNet.WlanDesc.ndisbssidex.Ssid.Ssid, dwrq->length); extra[priv->NdisCurNet.WlanDesc.ndisbssidex.Ssid.SsidLength] = '\0'; //spin_unlock(&priv->SsidGetLock); FN_EXIT(0,0); return 0;}/* Provides no functionality, just completes the ioctl. In essence this is a * just a cosmetic ioctl. */static intwt4_set_nick(struct net_device *ndev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; //printk("<0>*******Function %s Line %d******** \n\r",__FUNCTION__,__LINE__); //return; if (dwrq->length > IW_ESSID_MAX_SIZE) return -E2BIG; //dbg_info_str(extra) // down_write(&priv->mib_sem); memset(priv->nickname, 0, sizeof (priv->nickname)); memcpy(priv->nickname, extra, dwrq->length);// up_write(&priv->mib_sem); FN_EXIT(0,0); return 0;}static intwt4_get_nick(struct net_device *ndev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; //printk("<0>*******Function %s Line %d******** \n\r",__FUNCTION__,__LINE__); dwrq->length = 0;// down_read(&priv->mib_sem); dwrq->length = strlen(priv->nickname) + 1; memcpy(extra, priv->nickname, dwrq->length);// up_read(&priv->mib_sem); //dbg_info_str(extra) FN_EXIT(0,0); return 0;}/* Set the allowed Bitrates */static intwt4_set_rate(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; /*rate valide check, check later*/ priv->Ndis80211Parameter.TxRate = vwrq->value;printk("TxRate = %02x\n",priv->Ndis80211Parameter.TxRate); FN_EXIT(0,0); return 0;}/* Get the current bit rate */static intwt4_get_rate(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; vwrq->value=priv->Ndis80211Parameter.TxRate *500000 ; FN_EXIT(0,0); return 0;}static intwt4_set_rts(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; FN_EXIT(0,0); /*rts threshold valid check, check later*/ priv->Ndis80211Parameter.RTS_THRESHOLD =vwrq->value ; return 0 ;}static intwt4_get_rts(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; FN_EXIT(0,0); vwrq->value= priv->Ndis80211Parameter.RTS_THRESHOLD; return 0;}static intwt4_set_frag(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; /*frag threshold valid check, check later*/ priv->Ndis80211Parameter.FRAGMENTATION_THRESHOLD = vwrq->value; FN_EXIT(0,0); return 0;}static intwt4_get_frag(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; vwrq->value=priv->Ndis80211Parameter.FRAGMENTATION_THRESHOLD ; FN_EXIT(0,0); return 0;}/* Here we have (min,max) = max retries for (small frames, big frames). Where * big frame <=> bigger than the rts threshold * small frame <=> smaller than the rts threshold * This is not really the behavior expected by the wireless tool but it seems * to be a common behavior in other drivers. */static intwt4_set_retry(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; /*retry valid check, check later*/ if (vwrq->disabled) priv->Ndis80211Parameter.RetryNum=0; else priv->Ndis80211Parameter.RetryNum=vwrq->value; FN_EXIT(0,0); return 0;}static intwt4_get_retry(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; vwrq->value=priv->Ndis80211Parameter.RetryNum ; if(vwrq->value==0) { vwrq->disabled=1; } else { vwrq->disabled=0; vwrq->fixed=(unsigned char)IW_RETRY_TYPE; } FN_EXIT(0,0); return 0;}static intwt4_set_encode(struct net_device *ndev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){// WT_ADAPTER *priv = netdev_priv(ndev);// int rvalue = 0, force = 0; /* with the new API, it's impossible to get a NULL pointer. * New version of iwconfig set the IW_ENCODE_NOKEY flag * when no key is given, but older versions don't. */ FN_ENTER; FN_EXIT(0,0); return 0;}static intwt4_get_encode(struct net_device *ndev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){#if 0 WT_ADAPTER *priv = netdev_priv(ndev); struct obj_key *key; u32 devindex, index = (dwrq->flags & IW_ENCODE_INDEX) - 1; u32 authen = 0, invoke = 0, exunencrypt = 0; union oid_res_t r;#endif int rvalue = 0; //printk("command arrive"); FN_ENTER; FN_EXIT(0,0); dwrq->length=0x0; dwrq->flags=0x8001; *extra=0x0; return rvalue;}static intwt4_get_txpower(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *priv = netdev_priv(ndev); FN_ENTER; vwrq->value =WtWlanGetTxPower(priv); //priv->Ndis80211Parameter.TxPower ; vwrq->fixed = 1; vwrq->disabled = 0; FN_EXIT(0,0); return 0;}static intwt4_set_txpower(struct net_device *ndev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ WT_ADAPTER *Adapter = netdev_priv(ndev); FN_ENTER; /*using dbm to 0-oxff swap, check later,using fix now*/ Adapter->Ndis80211Parameter.TxPower =vwrq->value; //set ackpower. added by hk 2006.9.15 WRITE_WT4( 0x174, vwrq->value, 1); FN_EXIT(0,0); return 0 ;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?