📄 atmel.c
字号:
dwrq->length = priv->SSID_size + 1; } dwrq->flags = !priv->connect_to_any_BSS; /* active */ return 0;}static int atmel_get_wap(struct net_device *dev, struct iw_request_info *info, struct sockaddr *awrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); memcpy(awrq->sa_data, priv->CurrentBSSID, 6); awrq->sa_family = ARPHRD_ETHER; return 0;}static int atmel_set_encode(struct net_device *dev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); /* Basic checking: do we have a key to set ? * Note : with the new API, it's impossible to get a NULL pointer. * Therefore, we need to check a key size == 0 instead. * New version of iwconfig properly set the IW_ENCODE_NOKEY flag * when no key is present (only change flags), but older versions * don't do it. - Jean II */ if (dwrq->length > 0) { int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; int current_index = priv->default_key; /* Check the size of the key */ if (dwrq->length > 13) { return -EINVAL; } /* Check the index (none -> use current) */ if (index < 0 || index >= 4) index = current_index; else priv->default_key = index; /* Set the length */ if (dwrq->length > 5) priv->wep_key_len[index] = 13; else if (dwrq->length > 0) priv->wep_key_len[index] = 5; else /* Disable the key */ priv->wep_key_len[index] = 0; /* Check if the key is not marked as invalid */ if(!(dwrq->flags & IW_ENCODE_NOKEY)) { /* Cleanup */ memset(priv->wep_keys[index], 0, 13); /* Copy the key in the driver */ memcpy(priv->wep_keys[index], extra, dwrq->length); } /* WE specify that if a valid key is set, encryption * should be enabled (user may turn it off later) * This is also how "iwconfig ethX key on" works */ if (index == current_index && priv->wep_key_len[index] > 0) { priv->wep_is_on = 1; priv->exclude_unencrypted = 1; if (priv->wep_key_len[index] > 5) { priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_64; priv->encryption_level = 2; } else { priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_128; priv->encryption_level = 1; } } } else { /* Do we want to just set the transmit key index ? */ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; if ( index>=0 && index < 4 ) { priv->default_key = index; } else /* Don't complain if only change the mode */ if(!dwrq->flags & IW_ENCODE_MODE) { return -EINVAL; } } /* Read the flags */ if(dwrq->flags & IW_ENCODE_DISABLED) { priv->wep_is_on = 0; priv->encryption_level = 0; priv->pairwise_cipher_suite = CIPHER_SUITE_NONE; } else { priv->wep_is_on = 1; if (priv->wep_key_len[priv->default_key] > 5) { priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_128; priv->encryption_level = 2; } else { priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_64; priv->encryption_level = 1; } } if(dwrq->flags & IW_ENCODE_RESTRICTED) priv->exclude_unencrypted = 1; if(dwrq->flags & IW_ENCODE_OPEN) priv->exclude_unencrypted = 0; return -EINPROGRESS; /* Call commit handler */}static int atmel_get_encode(struct net_device *dev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; if (!priv->wep_is_on) dwrq->flags = IW_ENCODE_DISABLED; else if (priv->exclude_unencrypted) dwrq->flags = IW_ENCODE_RESTRICTED; else dwrq->flags = IW_ENCODE_OPEN; /* Which key do we want ? -1 -> tx index */ if (index < 0 || index >= 4) index = priv->default_key; dwrq->flags |= index + 1; /* Copy the key to the user buffer */ dwrq->length = priv->wep_key_len[index]; if (dwrq->length > 16) { dwrq->length=0; } else { memset(extra, 0, 16); memcpy(extra, priv->wep_keys[index], dwrq->length); } return 0;}static int atmel_get_name(struct net_device *dev, struct iw_request_info *info, char *cwrq, char *extra){ strcpy(cwrq, "IEEE 802.11-DS"); return 0;}static int atmel_set_rate(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); if (vwrq->fixed == 0) { priv->tx_rate = 3; priv->auto_tx_rate = 1; } else { priv->auto_tx_rate = 0; /* Which type of value ? */ if((vwrq->value < 4) && (vwrq->value >= 0)) { /* Setting by rate index */ priv->tx_rate = vwrq->value; } else { /* Setting by frequency value */ switch (vwrq->value) { case 1000000: priv->tx_rate = 0; break; case 2000000: priv->tx_rate = 1; break; case 5500000: priv->tx_rate = 2; break; case 11000000: priv->tx_rate = 3; break; default: return -EINVAL; } } } return -EINPROGRESS;}static int atmel_set_mode(struct net_device *dev, struct iw_request_info *info, __u32 *uwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); if (*uwrq != IW_MODE_ADHOC && *uwrq != IW_MODE_INFRA) return -EINVAL; priv->operating_mode = *uwrq; return -EINPROGRESS; }static int atmel_get_mode(struct net_device *dev, struct iw_request_info *info, __u32 *uwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); *uwrq = priv->operating_mode; return 0;}static int atmel_get_rate(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); if (priv->auto_tx_rate) { vwrq->fixed = 0; vwrq->value = 11000000; } else { vwrq->fixed = 1; switch(priv->tx_rate) { case 0: vwrq->value = 1000000; break; case 1: vwrq->value = 2000000; break; case 2: vwrq->value = 5500000; break; case 3: vwrq->value = 11000000; break; } } return 0;}static int atmel_set_power(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); priv->power_mode = vwrq->disabled ? 0 : 1; return -EINPROGRESS;}static int atmel_get_power(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); vwrq->disabled = priv->power_mode ? 0 : 1; vwrq->flags = IW_POWER_ON; return 0;}static int atmel_set_retry(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); if(!vwrq->disabled && (vwrq->flags & IW_RETRY_LIMIT)) { if(vwrq->flags & IW_RETRY_MAX) priv->long_retry = vwrq->value; else if (vwrq->flags & IW_RETRY_MIN) priv->short_retry = vwrq->value; else { /* No modifier : set both */ priv->long_retry = vwrq->value; priv->short_retry = vwrq->value; } return -EINPROGRESS; } return -EINVAL;}static int atmel_get_retry(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); vwrq->disabled = 0; /* Can't be disabled */ /* Note : by default, display the min retry number */ if((vwrq->flags & IW_RETRY_MAX)) { vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; vwrq->value = priv->long_retry; } else { vwrq->flags = IW_RETRY_LIMIT; vwrq->value = priv->short_retry; if(priv->long_retry != priv->short_retry) vwrq->flags |= IW_RETRY_MIN; } return 0;}static int atmel_set_rts(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); int rthr = vwrq->value; if(vwrq->disabled) rthr = 2347; if((rthr < 0) || (rthr > 2347)) { return -EINVAL; } priv->rts_threshold = rthr; return -EINPROGRESS; /* Call commit handler */}static int atmel_get_rts(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); vwrq->value = priv->rts_threshold; vwrq->disabled = (vwrq->value >= 2347); vwrq->fixed = 1; return 0;}static int atmel_set_frag(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); int fthr = vwrq->value; if(vwrq->disabled) fthr = 2346; if((fthr < 256) || (fthr > 2346)) { return -EINVAL; } fthr &= ~0x1; /* Get an even value - is it really needed ??? */ priv->frag_threshold = fthr; return -EINPROGRESS; /* Call commit handler */}static int atmel_get_frag(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); vwrq->value = priv->frag_threshold; vwrq->disabled = (vwrq->value >= 2346); vwrq->fixed = 1; return 0;}static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484 };static int atmel_set_freq(struct net_device *dev, struct iw_request_info *info, struct iw_freq *fwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); int rc = -EINPROGRESS; /* Call commit handler */ /* If setting by frequency, convert to a channel */ if((fwrq->e == 1) && (fwrq->m >= (int) 241200000) && (fwrq->m <= (int) 248700000)) { int f = fwrq->m / 100000; int c = 0; while((c < 14) && (f != frequency_list[c])) c++; /* Hack to fall through... */ fwrq->e = 0; fwrq->m = c + 1; } /* Setting by channel number */ if((fwrq->m > 1000) || (fwrq->e > 0)) rc = -EOPNOTSUPP; else { int channel = fwrq->m; if (atmel_validate_channel(priv, channel) == 0) { priv->channel = channel; } else { rc = -EINVAL; } } return rc;}static int atmel_get_freq(struct net_device *dev, struct iw_request_info *info, struct iw_freq *fwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); fwrq->m = priv->channel; fwrq->e = 0; return 0;}static int atmel_set_scan(struct net_device *dev, struct iw_request_info *info, struct iw_param *vwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); unsigned long flags; /* Note : you may have realise
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -