isl_ioctl.c
来自「优龙2410linux2.6.8内核源代码」· C语言 代码 · 共 2,269 行 · 第 1/5 页
C
2,269 行
/* * * 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/version.h>#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 */static int init_mode = CARD_DEFAULT_IW_MODE;static int init_channel = CARD_DEFAULT_CHANNEL;static int init_wep = CARD_DEFAULT_WEP;static int init_filter = CARD_DEFAULT_FILTER;static int init_authen = CARD_DEFAULT_AUTHEN;static int init_dot1x = CARD_DEFAULT_DOT1X;static int init_conformance = CARD_DEFAULT_CONFORMANCE;static int init_mlme = CARD_DEFAULT_MLME_MODE;module_param(init_mode, int, 0);MODULE_PARM_DESC(init_mode, "Set card mode:\n0: Auto\n1: Ad-Hoc\n2: Managed Client (Default)\n3: Master / Access Point\n4: Repeater (Not supported yet)\n5: Secondary (Not supported yet)\n6: Monitor");module_param(init_channel, int, 0);MODULE_PARM_DESC(init_channel, "Check `iwpriv ethx channel` for available channels");module_param(init_wep, int, 0);module_param(init_filter, int, 0);module_param(init_authen, int, 0);MODULE_PARM_DESC(init_authen, "Authentication method. Can be of seven types:\n0 0x0000: None\n1 0x0001: DOT11_AUTH_OS (Default)\n2 0x0002: DOT11_AUTH_SK\n3 0x0003: DOT11_AUTH_BOTH");module_param(init_dot1x, int, 0);MODULE_PARM_DESC(init_dot1x, "\n0: None/not set (Default)\n1: DOT11_DOT1X_AUTHENABLED\n2: DOT11_DOT1X_KEYTXENABLED");module_param(init_mlme, int, 0);MODULE_PARM_DESC(init_mlme, "Sets the MAC layer management entity (MLME) mode of operation,\n0: DOT11_MLME_AUTO (Default)\n1: DOT11_MLME_INTERMEDIATE\n2: DOT11_MLME_EXTENDED");/** * 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. */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 t; struct obj_buffer psm_buffer = { .size = PSM_BUFFER_SIZE, .addr = priv->device_psm_buffer }; mgt_set(priv, DOT11_OID_CHANNEL, &init_channel); mgt_set(priv, DOT11_OID_AUTHENABLE, &init_authen); mgt_set(priv, DOT11_OID_PRIVACYINVOKED, &init_wep); mgt_set(priv, DOT11_OID_PSMBUFFER, &psm_buffer); mgt_set(priv, DOT11_OID_EXUNENCRYPTED, &init_filter); mgt_set(priv, DOT11_OID_DOT1XENABLE, &init_dot1x); mgt_set(priv, DOT11_OID_MLMEAUTOLEVEL, &init_mlme); mgt_set(priv, OID_INL_DOT11D_CONFORMANCE, &init_conformance); t = 127; mgt_set(priv, OID_INL_OUTPUTPOWER, &t); /* Important: we are setting a default wireless mode and we are * forcing a valid one, so prism54_mib_mode_helper should just set * mib values depending on what the wireless mode given is. No need * for it save old values */ if (init_mode > IW_MODE_MONITOR || init_mode < IW_MODE_AUTO) { printk(KERN_DEBUG "%s(): You passed a non-valid init_mode. " "Using default mode\n", __FUNCTION__); init_mode = CARD_DEFAULT_IW_MODE; } /* This sets all of the mode-dependent values */ prism54_mib_mode_helper(priv, init_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(islpci_private *priv){ 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->m = r.u; fwrq->e = 0; 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); mgt_commit(priv); 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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?