📄 atmel.c
字号:
static int atmel_set_essid(struct net_device *dev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); /* Check if we asked for `any' */ if(dwrq->flags == 0) { priv->connect_to_any_BSS = 1; } else { int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; priv->connect_to_any_BSS = 0; /* Check the size of the string */ if (dwrq->length > MAX_SSID_LENGTH + 1) return -E2BIG; if (index != 0) return -EINVAL; memcpy(priv->new_SSID, extra, dwrq->length - 1); priv->new_SSID_size = dwrq->length - 1; } return -EINPROGRESS;}static int atmel_get_essid(struct net_device *dev, struct iw_request_info *info, struct iw_point *dwrq, char *extra){ struct atmel_private *priv = netdev_priv(dev); /* Get the current SSID */ if (priv->new_SSID_size != 0) { memcpy(extra, priv->new_SSID, priv->new_SSID_size); extra[priv->new_SSID_size] = '\0'; dwrq->length = priv->new_SSID_size; } else { memcpy(extra, priv->SSID, priv->SSID_size); extra[priv->SSID_size] = '\0'; dwrq->length = priv->SSID_size; } 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_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 -EINPROGRE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -