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

📄 wext.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	if (dwrq->length > MAX_WPA_IE_LEN ||	    (dwrq->length && extra == NULL)) {		ret = -EINVAL;		goto out;	}	if (dwrq->length) {		memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);		assoc_req->wpa_ie_len = dwrq->length;	} else {		memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));		assoc_req->wpa_ie_len = 0;	}out:	if (ret == 0) {		set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);		wlan_postpone_association_work(priv);	} else {		wlan_cancel_association_work(priv);	}	mutex_unlock(&adapter->lock);	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);	return ret;}static int wlan_get_genie(struct net_device *dev,			  struct iw_request_info *info,			  struct iw_point *dwrq,			  char *extra){	int ret = 0;	wlan_private *priv = dev->priv;	wlan_adapter *adapter = priv->adapter;	lbs_deb_enter(LBS_DEB_WEXT);	if (adapter->wpa_ie_len == 0) {		dwrq->length = 0;		goto out;	}	if (dwrq->length < adapter->wpa_ie_len) {		ret = -E2BIG;		goto out;	}	dwrq->length = adapter->wpa_ie_len;	memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);out:	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);	return ret;}static int wlan_set_auth(struct net_device *dev,			 struct iw_request_info *info,			 struct iw_param *dwrq,			 char *extra){	wlan_private *priv = dev->priv;	wlan_adapter *adapter = priv->adapter;	struct assoc_request * assoc_req;	int ret = 0;	int updated = 0;	lbs_deb_enter(LBS_DEB_WEXT);	mutex_lock(&adapter->lock);	assoc_req = wlan_get_association_request(adapter);	if (!assoc_req) {		ret = -ENOMEM;		goto out;	}	switch (dwrq->flags & IW_AUTH_INDEX) {	case IW_AUTH_TKIP_COUNTERMEASURES:	case IW_AUTH_CIPHER_PAIRWISE:	case IW_AUTH_CIPHER_GROUP:	case IW_AUTH_KEY_MGMT:	case IW_AUTH_DROP_UNENCRYPTED:		/*		 * libertas does not use these parameters		 */		break;	case IW_AUTH_WPA_VERSION:		if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {			assoc_req->secinfo.WPAenabled = 0;			assoc_req->secinfo.WPA2enabled = 0;			disable_wpa (assoc_req);		}		if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {			assoc_req->secinfo.WPAenabled = 1;			assoc_req->secinfo.wep_enabled = 0;			assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;		}		if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {			assoc_req->secinfo.WPA2enabled = 1;			assoc_req->secinfo.wep_enabled = 0;			assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;		}		updated = 1;		break;	case IW_AUTH_80211_AUTH_ALG:		if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {			assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;		} else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {			assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;		} else if (dwrq->value & IW_AUTH_ALG_LEAP) {			assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;		} else {			ret = -EINVAL;		}		updated = 1;		break;	case IW_AUTH_WPA_ENABLED:		if (dwrq->value) {			if (!assoc_req->secinfo.WPAenabled &&			    !assoc_req->secinfo.WPA2enabled) {				assoc_req->secinfo.WPAenabled = 1;				assoc_req->secinfo.WPA2enabled = 1;				assoc_req->secinfo.wep_enabled = 0;				assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;			}		} else {			assoc_req->secinfo.WPAenabled = 0;			assoc_req->secinfo.WPA2enabled = 0;			disable_wpa (assoc_req);		}		updated = 1;		break;	default:		ret = -EOPNOTSUPP;		break;	}out:	if (ret == 0) {		if (updated)			set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);		wlan_postpone_association_work(priv);	} else if (ret != -EOPNOTSUPP) {		wlan_cancel_association_work(priv);	}	mutex_unlock(&adapter->lock);	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);	return ret;}static int wlan_get_auth(struct net_device *dev,			 struct iw_request_info *info,			 struct iw_param *dwrq,			 char *extra){	int ret = 0;	wlan_private *priv = dev->priv;	wlan_adapter *adapter = priv->adapter;	lbs_deb_enter(LBS_DEB_WEXT);	switch (dwrq->flags & IW_AUTH_INDEX) {	case IW_AUTH_WPA_VERSION:		dwrq->value = 0;		if (adapter->secinfo.WPAenabled)			dwrq->value |= IW_AUTH_WPA_VERSION_WPA;		if (adapter->secinfo.WPA2enabled)			dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;		if (!dwrq->value)			dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;		break;	case IW_AUTH_80211_AUTH_ALG:		dwrq->value = adapter->secinfo.auth_mode;		break;	case IW_AUTH_WPA_ENABLED:		if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)			dwrq->value = 1;		break;	default:		ret = -EOPNOTSUPP;	}	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);	return ret;}static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,		   struct iw_param *vwrq, char *extra){	int ret = 0;	wlan_private *priv = dev->priv;	wlan_adapter *adapter = priv->adapter;	u16 dbm;	lbs_deb_enter(LBS_DEB_WEXT);	if (vwrq->disabled) {		wlan_radio_ioctl(priv, RADIO_OFF);		return 0;	}	adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;	wlan_radio_ioctl(priv, RADIO_ON);	/* Userspace check in iwrange if it should use dBm or mW,	 * therefore this should never happen... Jean II */	if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {		return -EOPNOTSUPP;	} else		dbm = (u16) vwrq->value;	/* auto tx power control */	if (vwrq->fixed == 0)		dbm = 0xffff;	lbs_deb_wext("txpower set %d dbm\n", dbm);	ret = libertas_prepare_and_send_command(priv,				    CMD_802_11_RF_TX_POWER,				    CMD_ACT_TX_POWER_OPT_SET_LOW,				    CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);	return ret;}static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,		   struct iw_point *dwrq, char *extra){	wlan_private *priv = dev->priv;	wlan_adapter *adapter = priv->adapter;	lbs_deb_enter(LBS_DEB_WEXT);	/*	 * Note : if dwrq->flags != 0, we should get the relevant SSID from	 * the SSID list...	 */	/*	 * Get the current SSID	 */	if (adapter->connect_status == LIBERTAS_CONNECTED) {		memcpy(extra, adapter->curbssparams.ssid,		       adapter->curbssparams.ssid_len);		extra[adapter->curbssparams.ssid_len] = '\0';	} else {		memset(extra, 0, 32);		extra[adapter->curbssparams.ssid_len] = '\0';	}	/*	 * If none, we may want to get the one that was set	 */	dwrq->length = adapter->curbssparams.ssid_len;	dwrq->flags = 1;	/* active */	lbs_deb_leave(LBS_DEB_WEXT);	return 0;}static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,		   struct iw_point *dwrq, char *extra){	wlan_private *priv = dev->priv;	wlan_adapter *adapter = priv->adapter;	int ret = 0;	u8 ssid[IW_ESSID_MAX_SIZE];	u8 ssid_len = 0;	struct assoc_request * assoc_req;	int in_ssid_len = dwrq->length;	lbs_deb_enter(LBS_DEB_WEXT);	/* Check the size of the string */	if (in_ssid_len > IW_ESSID_MAX_SIZE) {		ret = -E2BIG;		goto out;	}	memset(&ssid, 0, sizeof(ssid));	if (!dwrq->flags || !in_ssid_len) {		/* "any" SSID requested; leave SSID blank */	} else {		/* Specific SSID requested */		memcpy(&ssid, extra, in_ssid_len);		ssid_len = in_ssid_len;	}	if (!ssid_len) {		lbs_deb_wext("requested any SSID\n");	} else {		lbs_deb_wext("requested SSID '%s'\n",		             escape_essid(ssid, ssid_len));	}out:	mutex_lock(&adapter->lock);	if (ret == 0) {		/* Get or create the current association request */		assoc_req = wlan_get_association_request(adapter);		if (!assoc_req) {			ret = -ENOMEM;		} else {			/* Copy the SSID to the association request */			memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);			assoc_req->ssid_len = ssid_len;			set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);			wlan_postpone_association_work(priv);		}	}	/* Cancel the association request if there was an error */	if (ret != 0) {		wlan_cancel_association_work(priv);	}	mutex_unlock(&adapter->lock);	lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);	return ret;}/** *  @brief Connect to the AP or Ad-hoc Network with specific bssid * *  @param dev          A pointer to net_device structure *  @param info         A pointer to iw_request_info structure *  @param awrq         A pointer to iw_param structure *  @param extra        A pointer to extra data buf *  @return             0 --success, otherwise fail */static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,		 struct sockaddr *awrq, char *extra){	wlan_private *priv = dev->priv;	wlan_adapter *adapter = priv->adapter;	struct assoc_request * assoc_req;	int ret = 0;	DECLARE_MAC_BUF(mac);	lbs_deb_enter(LBS_DEB_WEXT);	if (awrq->sa_family != ARPHRD_ETHER)		return -EINVAL;	lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));	mutex_lock(&adapter->lock);	/* Get or create the current association request */	assoc_req = wlan_get_association_request(adapter);	if (!assoc_req) {		wlan_cancel_association_work(priv);		ret = -ENOMEM;	} else {		/* Copy the BSSID to the association request */		memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);		set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);		wlan_postpone_association_work(priv);	}	mutex_unlock(&adapter->lock);	return ret;}void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen){	char fwver[32];	mutex_lock(&adapter->lock);	if (adapter->fwreleasenumber[3] == 0)		sprintf(fwver, "%u.%u.%u",			adapter->fwreleasenumber[2],			adapter->fwreleasenumber[1],			adapter->fwreleasenumber[0]);	else		sprintf(fwver, "%u.%u.%u.p%u",			adapter->fwreleasenumber[2],			adapter->fwreleasenumber[1],			adapter->fwreleasenumber[0],			adapter->fwreleasenumber[3]);	mutex_unlock(&adapter->lock);	snprintf(fwversion, maxlen, fwver);}/* * iwconfig settable callbacks */static const iw_handler wlan_handler[] = {	(iw_handler) NULL,	/* SIOCSIWCOMMIT */	(iw_handler) wlan_get_name,	/* SIOCGIWNAME */	(iw_handler) NULL,	/* SIOCSIWNWID */	(iw_handler) NULL,	/* SIOCGIWNWID */	(iw_handler) wlan_set_freq,	/* SIOCSIWFREQ */	(iw_handler) wlan_get_freq,	/* SIOCGIWFREQ */	(iw_handler) wlan_set_mode,	/* SIOCSIWMODE */	(iw_handler) wlan_get_mode,	/* SIOCGIWMODE */	(iw_handler) NULL,	/* SIOCSIWSENS */	(iw_handler) NULL,	/* SIOCGIWSENS */	(iw_handler) NULL,	/* SIOCSIWRANGE */	(iw_handler) wlan_get_range,	/* SIOCGIWRANGE */	(iw_handler) NULL,	/* SIOCSIWPRIV */	(iw_handler) NULL,	/* SIOCGIWPRIV */	(iw_handler) NULL,	/* SIOCSIWSTATS */	(iw_handler) NULL,	/* SIOCGIWSTATS */	iw_handler_set_spy,	/* SIOCSIWSPY */	iw_handler_get_spy,	/* SIOCGIWSPY */	iw_handler_set_thrspy,	/* SIOCSIWTHRSPY */	iw_handler_get_thrspy,	/* SIOCGIWTHRSPY */	(iw_handler) wlan_set_wap,	/* SIOCSIWAP */	(iw_handler) wlan_get_wap,	/* SIOCGIWAP */	(iw_handler) NULL,	/* SIOCSIWMLME */	(iw_handler) NULL,	/* SIOCGIWAPLIST - deprecated */	(iw_handler) libertas_set_scan,	/* SIOCSIWSCAN */	(iw_handler) libertas_get_scan,	/* SIOCGIWSCAN */	(iw_handler) wlan_set_essid,	/* SIOCSIWESSID */	(iw_handler) wlan_get_essid,	/* SIOCGIWESSID */	(iw_handler) wlan_set_nick,	/* SIOCSIWNICKN */	(iw_handler) wlan_get_nick,	/* SIOCGIWNICKN */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) wlan_set_rate,	/* SIOCSIWRATE */	(iw_handler) wlan_get_rate,	/* SIOCGIWRATE */	(iw_handler) wlan_set_rts,	/* SIOCSIWRTS */	(iw_handler) wlan_get_rts,	/* SIOCGIWRTS */	(iw_handler) wlan_set_frag,	/* SIOCSIWFRAG */	(iw_handler) wlan_get_frag,	/* SIOCGIWFRAG */	(iw_handler) wlan_set_txpow,	/* SIOCSIWTXPOW */	(iw_handler) wlan_get_txpow,	/* SIOCGIWTXPOW */	(iw_handler) wlan_set_retry,	/* SIOCSIWRETRY */	(iw_handler) wlan_get_retry,	/* SIOCGIWRETRY */	(iw_handler) wlan_set_encode,	/* SIOCSIWENCODE */	(iw_handler) wlan_get_encode,	/* SIOCGIWENCODE */	(iw_handler) wlan_set_power,	/* SIOCSIWPOWER */	(iw_handler) wlan_get_power,	/* SIOCGIWPOWER */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) wlan_set_genie,	/* SIOCSIWGENIE */	(iw_handler) wlan_get_genie,	/* SIOCGIWGENIE */	(iw_handler) wlan_set_auth,	/* SIOCSIWAUTH */	(iw_handler) wlan_get_auth,	/* SIOCGIWAUTH */	(iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */	(iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */	(iw_handler) NULL,		/* SIOCSIWPMKSA */};static const iw_handler mesh_wlan_handler[] = {	(iw_handler) NULL,	/* SIOCSIWCOMMIT */	(iw_handler) wlan_get_name,	/* SIOCGIWNAME */	(iw_handler) NULL,	/* SIOCSIWNWID */	(iw_handler) NULL,	/* SIOCGIWNWID */	(iw_handler) wlan_set_freq,	/* SIOCSIWFREQ */	(iw_handler) wlan_get_freq,	/* SIOCGIWFREQ */	(iw_handler) NULL,		/* SIOCSIWMODE */	(iw_handler) mesh_wlan_get_mode,	/* SIOCGIWMODE */	(iw_handler) NULL,	/* SIOCSIWSENS */	(iw_handler) NULL,	/* SIOCGIWSENS */	(iw_handler) NULL,	/* SIOCSIWRANGE */	(iw_handler) wlan_get_range,	/* SIOCGIWRANGE */	(iw_handler) NULL,	/* SIOCSIWPRIV */	(iw_handler) NULL,	/* SIOCGIWPRIV */	(iw_handler) NULL,	/* SIOCSIWSTATS */	(iw_handler) NULL,	/* SIOCGIWSTATS */	iw_handler_set_spy,	/* SIOCSIWSPY */	iw_handler_get_spy,	/* SIOCGIWSPY */	iw_handler_set_thrspy,	/* SIOCSIWTHRSPY */	iw_handler_get_thrspy,	/* SIOCGIWTHRSPY */	(iw_handler) NULL,	/* SIOCSIWAP */	(iw_handler) NULL,	/* SIOCGIWAP */	(iw_handler) NULL,	/* SIOCSIWMLME */	(iw_handler) NULL,	/* SIOCGIWAPLIST - deprecated */	(iw_handler) libertas_set_scan,	/* SIOCSIWSCAN */	(iw_handler) libertas_get_scan,	/* SIOCGIWSCAN */	(iw_handler) NULL,		/* SIOCSIWESSID */	(iw_handler) NULL,		/* SIOCGIWESSID */	(iw_handler) NULL,		/* SIOCSIWNICKN */	(iw_handler) mesh_get_nick,	/* SIOCGIWNICKN */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) wlan_set_rate,	/* SIOCSIWRATE */	(iw_handler) wlan_get_rate,	/* SIOCGIWRATE */	(iw_handler) wlan_set_rts,	/* SIOCSIWRTS */	(iw_handler) wlan_get_rts,	/* SIOCGIWRTS */	(iw_handler) wlan_set_frag,	/* SIOCSIWFRAG */	(iw_handler) wlan_get_frag,	/* SIOCGIWFRAG */	(iw_handler) wlan_set_txpow,	/* SIOCSIWTXPOW */	(iw_handler) wlan_get_txpow,	/* SIOCGIWTXPOW */	(iw_handler) wlan_set_retry,	/* SIOCSIWRETRY */	(iw_handler) wlan_get_retry,	/* SIOCGIWRETRY */	(iw_handler) wlan_set_encode,	/* SIOCSIWENCODE */	(iw_handler) wlan_get_encode,	/* SIOCGIWENCODE */	(iw_handler) wlan_set_power,	/* SIOCSIWPOWER */	(iw_handler) wlan_get_power,	/* SIOCGIWPOWER */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) NULL,	/* -- hole -- */	(iw_handler) wlan_set_genie,	/* SIOCSIWGENIE */	(iw_handler) wlan_get_genie,	/* SIOCGIWGENIE */	(iw_handler) wlan_set_auth,	/* SIOCSIWAUTH */	(iw_handler) wlan_get_auth,	/* SIOCGIWAUTH */	(iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */	(iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */	(iw_handler) NULL,		/* SIOCSIWPMKSA */};struct iw_handler_def libertas_handler_def = {	.num_standard	= ARRAY_SIZE(wlan_handler),	.standard	= (iw_handler *) wlan_handler,	.get_wireless_stats = wlan_get_wireless_stats,};struct iw_handler_def mesh_handler_def = {	.num_standard	= ARRAY_SIZE(mesh_wlan_handler),	.standard	= (iw_handler *) mesh_wlan_handler,	.get_wireless_stats = wlan_get_wireless_stats,};

⌨️ 快捷键说明

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