📄 atmel.c
字号:
* 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_128; priv->encryption_level = 2; } else { priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_64; 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_set_encodeext(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra){ struct atmel_private *priv = netdev_priv(dev); struct iw_point *encoding = &wrqu->encoding; struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; int idx, key_len, alg = ext->alg, set_key = 1; /* Determine and validate the key index */ idx = encoding->flags & IW_ENCODE_INDEX; if (idx) { if (idx < 1 || idx > WEP_KEYS) return -EINVAL; idx--; } else idx = priv->default_key; if (encoding->flags & IW_ENCODE_DISABLED) alg = IW_ENCODE_ALG_NONE; if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { priv->default_key = idx; set_key = ext->key_len > 0 ? 1 : 0; } if (set_key) { /* Set the requested key first */ switch (alg) { case IW_ENCODE_ALG_NONE: priv->wep_is_on = 0; priv->encryption_level = 0; priv->pairwise_cipher_suite = CIPHER_SUITE_NONE; break; case IW_ENCODE_ALG_WEP: if (ext->key_len > 5) { priv->wep_key_len[idx] = 13; priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_128; priv->encryption_level = 2; } else if (ext->key_len > 0) { priv->wep_key_len[idx] = 5; priv->pairwise_cipher_suite = CIPHER_SUITE_WEP_64; priv->encryption_level = 1; } else { return -EINVAL; } priv->wep_is_on = 1; memset(priv->wep_keys[idx], 0, 13); key_len = min ((int)ext->key_len, priv->wep_key_len[idx]); memcpy(priv->wep_keys[idx], ext->key, key_len); break; default: return -EINVAL; } } return -EINPROGRESS;}static int atmel_get_encodeext(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra){ struct atmel_private *priv = netdev_priv(dev); struct iw_point *encoding = &wrqu->encoding; struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; int idx, max_key_len; max_key_len = encoding->length - sizeof(*ext); if (max_key_len < 0) return -EINVAL; idx = encoding->flags & IW_ENCODE_INDEX; if (idx) { if (idx < 1 || idx > WEP_KEYS) return -EINVAL; idx--; } else idx = priv->default_key; encoding->flags = idx + 1; memset(ext, 0, sizeof(*ext)); if (!priv->wep_is_on) { ext->alg = IW_ENCODE_ALG_NONE; ext->key_len = 0; encoding->flags |= IW_ENCODE_DISABLED; } else { if (priv->encryption_level > 0) ext->alg = IW_ENCODE_ALG_WEP; else return -EINVAL; ext->key_len = priv->wep_key_len[idx]; memcpy(ext->key, priv->wep_keys[idx], ext->key_len); encoding->flags |= IW_ENCODE_ENABLED; } return 0;}static int atmel_set_auth(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra){ struct atmel_private *priv = netdev_priv(dev); struct iw_param *param = &wrqu->param; switch (param->flags & IW_AUTH_INDEX) { case IW_AUTH_WPA_VERSION: case IW_AUTH_CIPHER_PAIRWISE: case IW_AUTH_CIPHER_GROUP: case IW_AUTH_KEY_MGMT: case IW_AUTH_RX_UNENCRYPTED_EAPOL: case IW_AUTH_PRIVACY_INVOKED: /* * atmel does not use these parameters */ break; case IW_AUTH_DROP_UNENCRYPTED: priv->exclude_unencrypted = param->value ? 1 : 0; break; case IW_AUTH_80211_AUTH_ALG: { if (param->value & IW_AUTH_ALG_SHARED_KEY) { priv->exclude_unencrypted = 1; } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) { priv->exclude_unencrypted = 0; } else return -EINVAL; break; } case IW_AUTH_WPA_ENABLED: /* Silently accept disable of WPA */ if (param->value > 0) return -EOPNOTSUPP; break; default: return -EOPNOTSUPP; } return -EINPROGRESS;}static int atmel_get_auth(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra){ struct atmel_private *priv = netdev_priv(dev); struct iw_param *param = &wrqu->param; switch (param->flags & IW_AUTH_INDEX) { case IW_AUTH_DROP_UNENCRYPTED: param->value = priv->exclude_unencrypted; break; case IW_AUTH_80211_AUTH_ALG: if (priv->exclude_unencrypted == 1) param->value = IW_AUTH_ALG_SHARED_KEY; else param->value = IW_AUTH_ALG_OPEN_SYSTEM; break; case IW_AUTH_WPA_ENABLED: param->value = 0; break; default: return -EOPNOTSUPP; } 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_para
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -