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

📄 isl_ioctl.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* *  Copyright (C) 2002 Intersil Americas Inc. *            (C) 2003,2004 Aurelien Alleaume <slts@free.fr> *            (C) 2003 Herbert Valerio Riedel <hvr@gnu.org> *            (C) 2003 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu> * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * */#include <linux/module.h>#include <linux/kernel.h>#include <linux/if_arp.h>#include <linux/pci.h>#include <asm/uaccess.h>#include "prismcompat.h"#include "isl_ioctl.h"#include "islpci_mgt.h"#include "isl_oid.h"		/* additional types and defs for isl38xx fw */#include "oid_mgt.h"#include <net/iw_handler.h>	/* New driver API */#define KEY_SIZE_WEP104 13	/* 104/128-bit WEP keys */#define KEY_SIZE_WEP40  5	/* 40/64-bit WEP keys *//* KEY_SIZE_TKIP should match isl_oid.h, struct obj_key.key[] size */#define KEY_SIZE_TKIP   32	/* TKIP keys */static void prism54_wpa_bss_ie_add(islpci_private *priv, u8 *bssid,				u8 *wpa_ie, size_t wpa_ie_len);static size_t prism54_wpa_bss_ie_get(islpci_private *priv, u8 *bssid, u8 *wpa_ie);static int prism54_set_wpa(struct net_device *, struct iw_request_info *,				__u32 *, char *);/* In 500 kbps */static const unsigned char scan_rate_list[] = { 2, 4, 11, 22,						12, 18, 24, 36,						48, 72, 96, 108 };/** * prism54_mib_mode_helper - MIB change mode helper function * @mib: the &struct islpci_mib object to modify * @iw_mode: new mode (%IW_MODE_*) * *  This is a helper function, hence it does not lock. Make sure *  caller deals with locking *if* necessary. This function sets the *  mode-dependent mib values and does the mapping of the Linux *  Wireless API modes to Device firmware modes. It also checks for *  correct valid Linux wireless modes. */static intprism54_mib_mode_helper(islpci_private *priv, u32 iw_mode){	u32 config = INL_CONFIG_MANUALRUN;	u32 mode, bsstype;	/* For now, just catch early the Repeater and Secondary modes here */	if (iw_mode == IW_MODE_REPEAT || iw_mode == IW_MODE_SECOND) {		printk(KERN_DEBUG		       "%s(): Sorry, Repeater mode and Secondary mode "		       "are not yet supported by this driver.\n", __FUNCTION__);		return -EINVAL;	}	priv->iw_mode = iw_mode;	switch (iw_mode) {	case IW_MODE_AUTO:		mode = INL_MODE_CLIENT;		bsstype = DOT11_BSSTYPE_ANY;		break;	case IW_MODE_ADHOC:		mode = INL_MODE_CLIENT;		bsstype = DOT11_BSSTYPE_IBSS;		break;	case IW_MODE_INFRA:		mode = INL_MODE_CLIENT;		bsstype = DOT11_BSSTYPE_INFRA;		break;	case IW_MODE_MASTER:		mode = INL_MODE_AP;		bsstype = DOT11_BSSTYPE_INFRA;		break;	case IW_MODE_MONITOR:		mode = INL_MODE_PROMISCUOUS;		bsstype = DOT11_BSSTYPE_ANY;		config |= INL_CONFIG_RXANNEX;		break;	default:		return -EINVAL;	}	if (init_wds)		config |= INL_CONFIG_WDS;	mgt_set(priv, DOT11_OID_BSSTYPE, &bsstype);	mgt_set(priv, OID_INL_CONFIG, &config);	mgt_set(priv, OID_INL_MODE, &mode);	return 0;}/** * prism54_mib_init - fill MIB cache with defaults * *  this function initializes the struct given as @mib with defaults, *  of which many are retrieved from the global module parameter *  variables. */voidprism54_mib_init(islpci_private *priv){	u32 channel, authen, wep, filter, dot1x, mlme, conformance, power, mode;	struct obj_buffer psm_buffer = {		.size = PSM_BUFFER_SIZE,		.addr = priv->device_psm_buffer	};	channel = CARD_DEFAULT_CHANNEL;	authen = CARD_DEFAULT_AUTHEN;	wep = CARD_DEFAULT_WEP;	filter = CARD_DEFAULT_FILTER; /* (0) Do not filter un-encrypted data */	dot1x = CARD_DEFAULT_DOT1X;	mlme = CARD_DEFAULT_MLME_MODE;	conformance = CARD_DEFAULT_CONFORMANCE;	power = 127;	mode = CARD_DEFAULT_IW_MODE;	mgt_set(priv, DOT11_OID_CHANNEL, &channel);	mgt_set(priv, DOT11_OID_AUTHENABLE, &authen);	mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &wep);	mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer);	mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &filter);	mgt_set(priv, DOT11_OID_DOT1XENABLE, &dot1x);	mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlme);	mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &conformance);	mgt_set(priv, OID_INL_OUTPUTPOWER, &power);	/* This sets all of the mode-dependent values */	prism54_mib_mode_helper(priv, mode);}/* this will be executed outside of atomic context thanks to * schedule_work(), thus we can as well use sleeping semaphore * locking */voidprism54_update_stats(struct work_struct *work){	islpci_private *priv = container_of(work, islpci_private, stats_work);	char *data;	int j;	struct obj_bss bss, *bss2;	union oid_res_t r;	if (down_interruptible(&priv->stats_sem))		return;/* Noise floor. * I'm not sure if the unit is dBm. * Note : If we are not connected, this value seems to be irrelevant. */	mgt_get_request(priv, DOT11_OID_NOISEFLOOR, 0, NULL, &r);	priv->local_iwstatistics.qual.noise = r.u;/* Get the rssi of the link. To do this we need to retrieve a bss. */	/* First get the MAC address of the AP we are associated with. */	mgt_get_request(priv, DOT11_OID_BSSID, 0, NULL, &r);	data = r.ptr;	/* copy this MAC to the bss */	memcpy(bss.address, data, 6);	kfree(data);	/* now ask for the corresponding bss */	j = mgt_get_request(priv, DOT11_OID_BSSFIND, 0, (void *) &bss, &r);	bss2 = r.ptr;	/* report the rssi and use it to calculate	 *  link quality through a signal-noise	 *  ratio */	priv->local_iwstatistics.qual.level = bss2->rssi;	priv->local_iwstatistics.qual.qual =	    bss2->rssi - priv->iwstatistics.qual.noise;	kfree(bss2);	/* report that the stats are new */	priv->local_iwstatistics.qual.updated = 0x7;/* Rx : unable to decrypt the MPDU */	mgt_get_request(priv, DOT11_OID_PRIVRXFAILED, 0, NULL, &r);	priv->local_iwstatistics.discard.code = r.u;/* Tx : Max MAC retries num reached */	mgt_get_request(priv, DOT11_OID_MPDUTXFAILED, 0, NULL, &r);	priv->local_iwstatistics.discard.retries = r.u;	up(&priv->stats_sem);	return;}struct iw_statistics *prism54_get_wireless_stats(struct net_device *ndev){	islpci_private *priv = netdev_priv(ndev);	/* If the stats are being updated return old data */	if (down_trylock(&priv->stats_sem) == 0) {		memcpy(&priv->iwstatistics, &priv->local_iwstatistics,		       sizeof (struct iw_statistics));		/* They won't be marked updated for the next time */		priv->local_iwstatistics.qual.updated = 0;		up(&priv->stats_sem);	} else		priv->iwstatistics.qual.updated = 0;	/* Update our wireless stats, but do not schedule to often	 * (max 1 HZ) */	if ((priv->stats_timestamp == 0) ||	    time_after(jiffies, priv->stats_timestamp + 1 * HZ)) {		schedule_work(&priv->stats_work);		priv->stats_timestamp = jiffies;	}	return &priv->iwstatistics;}static intprism54_commit(struct net_device *ndev, struct iw_request_info *info,	       char *cwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	/* simply re-set the last set SSID, this should commit most stuff */	/* Commit in Monitor mode is not necessary, also setting essid	 * in Monitor mode does not make sense and isn't allowed for this	 * device's firmware */	if (priv->iw_mode != IW_MODE_MONITOR)		return mgt_set_request(priv, DOT11_OID_SSID, 0, NULL);	return 0;}static intprism54_get_name(struct net_device *ndev, struct iw_request_info *info,		 char *cwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	char *capabilities;	union oid_res_t r;	int rvalue;	if (islpci_get_state(priv) < PRV_STATE_INIT) {		strncpy(cwrq, "NOT READY!", IFNAMSIZ);		return 0;	}	rvalue = mgt_get_request(priv, OID_INL_PHYCAPABILITIES, 0, NULL, &r);	switch (r.u) {	case INL_PHYCAP_5000MHZ:		capabilities = "IEEE 802.11a/b/g";		break;	case INL_PHYCAP_FAA:		capabilities = "IEEE 802.11b/g - FAA Support";		break;	case INL_PHYCAP_2400MHZ:	default:		capabilities = "IEEE 802.11b/g";	/* Default */		break;	}	strncpy(cwrq, capabilities, IFNAMSIZ);	return rvalue;}static intprism54_set_freq(struct net_device *ndev, struct iw_request_info *info,		 struct iw_freq *fwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	int rvalue;	u32 c;	if (fwrq->m < 1000)		/* we have a channel number */		c = fwrq->m;	else		c = (fwrq->e == 1) ? channel_of_freq(fwrq->m / 100000) : 0;	rvalue = c ? mgt_set_request(priv, DOT11_OID_CHANNEL, 0, &c) : -EINVAL;	/* Call commit handler */	return (rvalue ? rvalue : -EINPROGRESS);}static intprism54_get_freq(struct net_device *ndev, struct iw_request_info *info,		 struct iw_freq *fwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	union oid_res_t r;	int rvalue;	rvalue = mgt_get_request(priv, DOT11_OID_CHANNEL, 0, NULL, &r);	fwrq->i = r.u;	rvalue |= mgt_get_request(priv, DOT11_OID_FREQUENCY, 0, NULL, &r);	fwrq->m = r.u;	fwrq->e = 3;	return rvalue;}static intprism54_set_mode(struct net_device *ndev, struct iw_request_info *info,		 __u32 * uwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	u32 mlmeautolevel = CARD_DEFAULT_MLME_MODE;	/* Let's see if the user passed a valid Linux Wireless mode */	if (*uwrq > IW_MODE_MONITOR || *uwrq < IW_MODE_AUTO) {		printk(KERN_DEBUG		       "%s: %s() You passed a non-valid init_mode.\n",		       priv->ndev->name, __FUNCTION__);		return -EINVAL;	}	down_write(&priv->mib_sem);	if (prism54_mib_mode_helper(priv, *uwrq)) {		up_write(&priv->mib_sem);		return -EOPNOTSUPP;	}	/* the ACL code needs an intermediate mlmeautolevel. The wpa stuff an	 * extended one.	 */	if ((*uwrq == IW_MODE_MASTER) && (priv->acl.policy != MAC_POLICY_OPEN))		mlmeautolevel = DOT11_MLME_INTERMEDIATE;	if (priv->wpa)		mlmeautolevel = DOT11_MLME_EXTENDED;	mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &mlmeautolevel);	if (mgt_commit(priv)) {		up_write(&priv->mib_sem);		return -EIO;	}	priv->ndev->type = (priv->iw_mode == IW_MODE_MONITOR)	    ? priv->monitor_type : ARPHRD_ETHER;	up_write(&priv->mib_sem);	return 0;}/* Use mib cache */static intprism54_get_mode(struct net_device *ndev, struct iw_request_info *info,		 __u32 * uwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	BUG_ON((priv->iw_mode < IW_MODE_AUTO) || (priv->iw_mode >						  IW_MODE_MONITOR));	*uwrq = priv->iw_mode;	return 0;}/* we use DOT11_OID_EDTHRESHOLD. From what I guess the card will not try to * emit data if (sensitivity > rssi - noise) (in dBm). * prism54_set_sens does not seem to work. */static intprism54_set_sens(struct net_device *ndev, struct iw_request_info *info,		 struct iw_param *vwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	u32 sens;	/* by default  the card sets this to 20. */	sens = vwrq->disabled ? 20 : vwrq->value;	return mgt_set_request(priv, DOT11_OID_EDTHRESHOLD, 0, &sens);}static intprism54_get_sens(struct net_device *ndev, struct iw_request_info *info,		 struct iw_param *vwrq, char *extra){	islpci_private *priv = netdev_priv(ndev);	union oid_res_t r;	int rvalue;	rvalue = mgt_get_request(priv, DOT11_OID_EDTHRESHOLD, 0, NULL, &r);	vwrq->value = r.u;	vwrq->disabled = (vwrq->value == 0);	vwrq->fixed = 1;	return rvalue;}static intprism54_get_range(struct net_device *ndev, struct iw_request_info *info,		  struct iw_point *dwrq, char *extra){	struct iw_range *range = (struct iw_range *) extra;	islpci_private *priv = netdev_priv(ndev);	u8 *data;	int i, m, rvalue;	struct obj_frequencies *freq;	union oid_res_t r;	memset(range, 0, sizeof (struct iw_range));	dwrq->length = sizeof (struct iw_range);	/* set the wireless extension version number */	range->we_version_source = SUPPORTED_WIRELESS_EXT;	range->we_version_compiled = WIRELESS_EXT;	/* Now the encoding capabilities */	range->num_encoding_sizes = 3;	/* 64(40) bits WEP */	range->encoding_size[0] = 5;	/* 128(104) bits WEP */	range->encoding_size[1] = 13;	/* 256 bits for WPA-PSK */	range->encoding_size[2] = 32;	/* 4 keys are allowed */	range->max_encoding_tokens = 4;	/* we don't know the quality range... */	range->max_qual.level = 0;	range->max_qual.noise = 0;	range->max_qual.qual = 0;	/* these value describe an average quality. Needs more tweaking... */	range->avg_qual.level = -80;	/* -80 dBm */	range->avg_qual.noise = 0;	/* don't know what to put here */	range->avg_qual.qual = 0;	range->sensitivity = 200;	/* retry limit capabilities */	range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;	range->retry_flags = IW_RETRY_LIMIT;	range->r_time_flags = IW_RETRY_LIFETIME;	/* I don't know the range. Put stupid things here */	range->min_retry = 1;	range->max_retry = 65535;	range->min_r_time = 1024;	range->max_r_time = 65535 * 1024;	/* txpower is supported in dBm's */	range->txpower_capa = IW_TXPOW_DBM;	/* Event capability (kernel + driver) */	range->event_capa[0] = (IW_EVENT_CAPA_K_0 |	IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |	IW_EVENT_CAPA_MASK(SIOCGIWAP));	range->event_capa[1] = IW_EVENT_CAPA_K_1;	range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVCUSTOM);	range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |		IW_ENC_CAPA_CIPHER_TKIP;	if (islpci_get_state(priv) < PRV_STATE_INIT)		return 0;	/* Request the device for the supported frequencies	 * not really relevant since some devices will report the 5 GHz band	 * frequencies even if they don't support them.	 */	rvalue =	    mgt_get_request(priv, DOT11_OID_SUPPORTEDFREQUENCIES, 0, NULL, &r);	freq = r.ptr;	range->num_channels = freq->nr;	range->num_frequency = freq->nr;	m = min(IW_MAX_FREQUENCIES, (int) freq->nr);	for (i = 0; i < m; i++) {		range->freq[i].m = freq->mhz[i];		range->freq[i].e = 6;		range->freq[i].i = channel_of_freq(freq->mhz[i]);	}	kfree(freq);	rvalue |= mgt_get_request(priv, DOT11_OID_SUPPORTEDRATES, 0, NULL, &r);	data = r.ptr;	/* We got an array of char. It is NULL terminated. */	i = 0;	while ((i < IW_MAX_BITRATES) && (*data != 0)) {		/*       the result must be in bps. The card gives us 500Kbps */		range->bitrate[i] = *data * 500000;		i++;		data++;	}	range->num_bitrates = i;	kfree(r.ptr);

⌨️ 快捷键说明

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