summaryrefslogtreecommitdiffstats
path: root/drivers/staging/ks7010/ks_wlan_net.c
diff options
context:
space:
mode:
authorWolfram Sang <wsa+renesas@sang-engineering.com>2016-05-31 12:56:13 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-06-07 22:42:53 -0700
commit13a9930d15b424ab7d3b906af8ba7ff8c409edfe (patch)
treeca1490a09b5f633a1cec5014dd360ad5c934f336 /drivers/staging/ks7010/ks_wlan_net.c
parente3c9078af85dceaa6cda2a573c4bf0be7d978bc4 (diff)
staging: ks7010: add driver from Nanonote extra-repository
See the TODO for details where this driver came from. Only a few minor changes were made to make the driver suitable for staging: * updated Kconfig help text and dependencies * added TODO * removed two __DATE__ and __TIME__ printouts to allow reproducible builds * added to staging main Kconfig + Makefile Tested on a Renesas Salvator-X board with a Spectec SDW-823 card. I could connect to a WPA-protected network. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/ks7010/ks_wlan_net.c')
-rw-r--r--drivers/staging/ks7010/ks_wlan_net.c3157
1 files changed, 3157 insertions, 0 deletions
diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
new file mode 100644
index 000000000000..546a25609397
--- /dev/null
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -0,0 +1,3157 @@
+/*
+ * Driver for KeyStream 11b/g wireless LAN
+ *
+ * ks_wlan_net.c
+ * $Id: ks_wlan_net.c 1020 2009-09-28 05:48:31Z sekine $
+ *
+ * Copyright (C) 2005-2008 KeyStream Corp.
+ * Copyright (C) 2009 Renesas Technology Corp.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it undr the terms of the GNU General Public License version 2 as
+ * published by the Free Sotware Foundation.
+ */
+
+#include <linux/version.h>
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
+#include <linux/config.h>
+#endif
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/compiler.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/if_arp.h>
+#include <linux/rtnetlink.h>
+#include <linux/delay.h>
+#include <linux/completion.h>
+#include <linux/mii.h>
+#include <linux/pci.h>
+#include <linux/ctype.h>
+#include <linux/timer.h>
+#include <asm/atomic.h>
+#include <linux/io.h>
+#include <asm/uaccess.h>
+
+static int wep_on_off;
+#define WEP_OFF 0
+#define WEP_ON_64BIT 1
+#define WEP_ON_128BIT 2
+
+#include "ks_wlan.h"
+#include "ks_hostif.h"
+#include "ks_wlan_ioctl.h"
+#include "ks_debug.h"
+
+/* Include Wireless Extension definition and check version */
+#include <linux/wireless.h>
+#define WIRELESS_SPY /* enable iwspy support */
+#include <net/iw_handler.h> /* New driver API */
+
+#ifdef WIRELESS_EXT
+/* Frequency list (map channels to frequencies) */
+static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
+ 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
+
+/* A few details needed for WEP (Wireless Equivalent Privacy) */
+#define MAX_KEY_SIZE 13 /* 128 (?) bits */
+#define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
+typedef struct wep_key_t {
+ u16 len;
+ u8 key[16]; /* 40-bit and 104-bit keys */
+} wep_key_t;
+
+/* Backward compatibility */
+#ifndef IW_ENCODE_NOKEY
+#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
+#define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
+#endif /* IW_ENCODE_NOKEY */
+
+/* List of Wireless Handlers (new API) */
+static const struct iw_handler_def ks_wlan_handler_def;
+
+#define KSC_OPNOTSUPP /* Operation Not Support*/
+
+#endif /* WIRELESS_EXT */
+
+/*
+ * function prototypes
+ */
+extern int ks_wlan_hw_tx(ks_wlan_private *priv, void *p, unsigned long size,
+ void (*complete_handler)(void *arg1, void *arg2),
+ void *arg1,
+ void *arg2 );
+static int ks_wlan_open (struct net_device *dev);
+static void ks_wlan_tx_timeout (struct net_device *dev);
+static int ks_wlan_start_xmit (struct sk_buff *skb, struct net_device *dev);
+static int ks_wlan_close (struct net_device *dev);
+static void ks_wlan_set_multicast_list (struct net_device *dev);
+static struct net_device_stats *ks_wlan_get_stats (struct net_device *dev);
+static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
+static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
+
+static atomic_t update_phyinfo;
+static struct timer_list update_phyinfo_timer;
+static
+int ks_wlan_update_phy_information(ks_wlan_private *priv)
+{
+ struct iw_statistics *wstats = &priv->wstats;
+
+ DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
+
+ if (priv->dev_state < DEVICE_STATE_READY) {
+ return -1; /* not finished initialize */
+ }
+ if(atomic_read(&update_phyinfo))
+ return 1;
+
+ /* The status */
+ wstats->status = priv->reg.operation_mode; /* Operation mode */
+
+ /* Signal quality and co. But where is the noise level ??? */
+ hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
+
+ /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
+ if(!wait_for_completion_interruptible_timeout(&priv->confirm_wait,HZ/2)){
+ DPRINTK(1,"wait time out!!\n");
+ }
+
+ atomic_inc(&update_phyinfo);
+ update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
+ add_timer(&update_phyinfo_timer);
+
+ return 0;
+}
+
+static
+void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
+{
+ DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
+ atomic_set(&update_phyinfo,0);
+}
+
+int ks_wlan_setup_parameter(ks_wlan_private *priv, unsigned int commit_flag)
+{
+ DPRINTK(2,"\n");
+
+ hostif_sme_enqueue(priv, SME_STOP_REQUEST);
+
+ if(commit_flag & SME_RTS)
+ hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
+ if(commit_flag & SME_FRAG)
+ hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
+
+ if(commit_flag & SME_WEP_INDEX)
+ hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
+ if(commit_flag & SME_WEP_VAL1)
+ hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
+ if(commit_flag & SME_WEP_VAL2)
+ hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
+ if(commit_flag & SME_WEP_VAL3)
+ hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
+ if(commit_flag & SME_WEP_VAL4)
+ hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
+ if(commit_flag & SME_WEP_FLAG)
+ hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
+
+ if(commit_flag & SME_RSN){
+ hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
+ hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
+ }
+ if(commit_flag & SME_RSN_MULTICAST)
+ hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
+ if(commit_flag & SME_RSN_UNICAST)
+ hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
+ if(commit_flag & SME_RSN_AUTH)
+ hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
+
+ hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
+
+ hostif_sme_enqueue(priv, SME_START_REQUEST);
+
+ return 0;
+}
+
+#ifdef WIRELESS_EXT
+/*
+ * Initial Wireless Extension code for Ks_Wlannet driver by :
+ * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
+ * Conversion to new driver API by :
+ * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
+ * Javier also did a good amount of work here, adding some new extensions
+ * and fixing my code. Let's just say that without him this code just
+ * would not work at all... - Jean II
+ */
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get protocol name */
+static int ks_wlan_get_name(struct net_device *dev, struct iw_request_info *info,
+ char *cwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *) netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if (priv->dev_state < DEVICE_STATE_READY) {
+ strcpy(cwrq, "NOT READY!");
+ }
+ else if(priv->reg.phy_type == D_11B_ONLY_MODE){
+ strcpy(cwrq, "IEEE 802.11b");
+ }
+ else if(priv->reg.phy_type == D_11G_ONLY_MODE){
+ strcpy(cwrq, "IEEE 802.11g");
+ }
+ else {
+ strcpy(cwrq, "IEEE 802.11b/g");
+ }
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set frequency */
+static int ks_wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
+ struct iw_freq *fwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ int rc = -EINPROGRESS; /* Call commit handler */
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* If setting by frequency, convert to a channel */
+ if((fwrq->e == 1) &&
+ (fwrq->m >= (int) 2.412e8) &&
+ (fwrq->m <= (int) 2.487e8)) {
+ int f = fwrq->m / 100000;
+ int c = 0;
+ while((c < 14) && (f != frequency_list[c]))
+ c++;
+ /* Hack to fall through... */
+ fwrq->e = 0;
+ fwrq->m = c + 1;
+ }
+ /* Setting by channel number */
+ if((fwrq->m > 1000) || (fwrq->e > 0))
+ rc = -EOPNOTSUPP;
+ else {
+ int channel = fwrq->m;
+ /* We should do a better check than that,
+ * based on the card capability !!! */
+ if((channel < 1) || (channel > 14)) {
+ printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
+ rc = -EINVAL;
+ } else {
+ /* Yes ! We can set it !!! */
+ priv->reg.channel = (u8)(channel);
+ priv->need_commit |= SME_MODE_SET;
+ }
+ }
+
+ return rc;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get frequency */
+static int ks_wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
+ struct iw_freq *fwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ int f;
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
+ f = (int)priv->current_ap.channel;
+ }
+ else
+ f = (int)priv->reg.channel;
+ fwrq->m = frequency_list[f-1] * 100000;
+ fwrq->e = 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set ESSID */
+static int ks_wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
+ struct iw_point *dwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ size_t len;
+
+ DPRINTK(2," %d\n", dwrq->flags);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* Check if we asked for `any' */
+ if(dwrq->flags == 0) {
+ /* Just send an empty SSID list */
+ memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
+ priv->reg.ssid.size = 0;
+ } else {
+#if 1
+ len = dwrq->length;
+ /* iwconfig uses nul termination in SSID.. */
+ if (len > 0 && extra[len - 1] == '\0')
+ len--;
+
+ /* Check the size of the string */
+ if(len > IW_ESSID_MAX_SIZE) {
+ return -EINVAL;
+ }
+#else
+ /* Check the size of the string */
+ if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
+ return -E2BIG ;
+ }
+#endif
+
+ /* Set the SSID */
+ memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
+
+#if 1
+ memcpy(priv->reg.ssid.body, extra, len);
+ priv->reg.ssid.size = len;
+#else
+ memcpy(priv->reg.ssid.body, extra, dwrq->length);
+ priv->reg.ssid.size = dwrq->length;
+#endif
+ }
+ /* Write it to the card */
+ priv->need_commit |= SME_MODE_SET;
+
+// return -EINPROGRESS; /* Call commit handler */
+ ks_wlan_setup_parameter(priv, priv->need_commit);
+ priv->need_commit=0;
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get ESSID */
+static int ks_wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
+ struct iw_point *dwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* Note : if dwrq->flags != 0, we should
+ * get the relevant SSID from the SSID list... */
+
+ if(priv->reg.ssid.size){
+ /* Get the current SSID */
+ memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
+#if 0
+ extra[priv->reg.ssid.size] = '\0';
+#endif
+ /* If none, we may want to get the one that was set */
+
+ /* Push it out ! */
+#if 1
+ dwrq->length = priv->reg.ssid.size;
+#else
+ dwrq->length = priv->reg.ssid.size+1;
+#endif
+ dwrq->flags = 1; /* active */
+ }else{
+#if 1
+ dwrq->length = 0;
+#else
+ extra[0] = '\0';
+ dwrq->length = 1;
+#endif
+ dwrq->flags = 0; /* ANY */
+ }
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set AP address */
+static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
+ struct sockaddr *ap_addr, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ DPRINTK(2,"\n");
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if (priv->reg.operation_mode == MODE_ADHOC ||
+ priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
+ memcpy(priv->reg.bssid, (u8 *)&ap_addr->sa_data, ETH_ALEN);
+
+ if (is_valid_ether_addr((u8 *)priv->reg.bssid)) {
+ priv->need_commit |= SME_MODE_SET;
+ }
+ }
+ else {
+ memset(priv->reg.bssid, 0x0, ETH_ALEN);
+ return -EOPNOTSUPP;
+ }
+
+ DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
+ priv->reg.bssid[0],priv->reg.bssid[1],priv->reg.bssid[2],
+ priv->reg.bssid[3],priv->reg.bssid[4],priv->reg.bssid[5]);
+
+ /* Write it to the card */
+ if (priv->need_commit) {
+ priv->need_commit |= SME_MODE_SET;
+ return -EINPROGRESS; /* Call commit handler */
+ }
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get AP address */
+static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
+ struct sockaddr *awrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS){
+ memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
+ }
+ else{
+ memset(awrq->sa_data, 0, ETH_ALEN);
+ }
+
+ awrq->sa_family = ARPHRD_ETHER;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set Nickname */
+static int ks_wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
+ struct iw_point *dwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* Check the size of the string */
+ if(dwrq->length > 16 + 1) {
+ return -E2BIG;
+ }
+ memset(priv->nick, 0, sizeof(priv->nick));
+ memcpy(priv->nick, extra, dwrq->length);
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get Nickname */
+static int ks_wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
+ struct iw_point *dwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ strncpy(extra, priv->nick, 16);
+ extra[16] = '\0';
+ dwrq->length = strlen(extra) + 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set Bit-Rate */
+static int ks_wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ int i = 0;
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if(priv->reg.phy_type == D_11B_ONLY_MODE){
+ if(vwrq->fixed == 1) {
+ switch(vwrq->value){
+ case 11000000:
+ case 5500000:
+ priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
+ break;
+ case 2000000:
+ case 1000000:
+ priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
+ break;
+ default:
+ return -EINVAL;
+ }
+ priv->reg.tx_rate = TX_RATE_FIXED;
+ priv->reg.rate_set.size = 1;
+ }else{ /* vwrq->fixed == 0 */
+ if(vwrq->value > 0){
+ switch(vwrq->value){
+ case 11000000:
+ priv->reg.rate_set.body[3] = TX_RATE_11M; i++;
+ case 5500000:
+ priv->reg.rate_set.body[2] = TX_RATE_5M; i++;
+ case 2000000:
+ priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
+ case 1000000:
+ priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
+ break;
+ default:
+ return -EINVAL;
+ }
+ priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
+ priv->reg.rate_set.size = i;
+ }else{
+ priv->reg.rate_set.body[3] = TX_RATE_11M;
+ priv->reg.rate_set.body[2] = TX_RATE_5M;
+ priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
+ priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
+ priv->reg.tx_rate = TX_RATE_FULL_AUTO;
+ priv->reg.rate_set.size = 4;
+ }
+ }
+ }else{ /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
+ if(vwrq->fixed == 1) {
+ switch(vwrq->value){
+ case 54000000:
+ case 48000000:
+ case 36000000:
+ case 18000000:
+ case 9000000:
+ priv->reg.rate_set.body[0] = (uint8_t)(vwrq->value/500000);
+ break;
+ case 24000000:
+ case 12000000:
+ case 11000000:
+ case 6000000:
+ case 5500000:
+ case 2000000:
+ case 1000000:
+ priv->reg.rate_set.body[0] = ((uint8_t)(vwrq->value/500000))|BASIC_RATE;
+ break;
+ default:
+ return -EINVAL;
+ }
+ priv->reg.tx_rate = TX_RATE_FIXED;
+ priv->reg.rate_set.size = 1;
+ }else{ /* vwrq->fixed == 0 */
+ if(vwrq->value > 0){
+ switch(vwrq->value){
+ case 54000000:
+ priv->reg.rate_set.body[11] = TX_RATE_54M; i++;
+ case 48000000:
+ priv->reg.rate_set.body[10] = TX_RATE_48M; i++;
+ case 36000000:
+ priv->reg.rate_set.body[9] = TX_RATE_36M; i++;
+ case 24000000: case 18000000: case 12000000:
+ case 11000000: case 9000000: case 6000000:
+ if(vwrq->value == 24000000){
+ priv->reg.rate_set.body[8] = TX_RATE_18M; i++;
+ priv->reg.rate_set.body[7] = TX_RATE_9M; i++;
+ priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
+ }else if(vwrq->value == 18000000){
+ priv->reg.rate_set.body[7] = TX_RATE_18M; i++;
+ priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
+ priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
+ }else if(vwrq->value == 12000000){
+ priv->reg.rate_set.body[6] = TX_RATE_9M; i++;
+ priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
+ }else if(vwrq->value == 11000000){
+ priv->reg.rate_set.body[5] = TX_RATE_9M; i++;
+ priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE; i++;
+ priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE; i++;
+ }else if(vwrq->value == 9000000){
+ priv->reg.rate_set.body[4] = TX_RATE_9M; i++;
+ priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
+ }else{ /* vwrq->value == 6000000 */
+ priv->reg.rate_set.body[3] = TX_RATE_6M|BASIC_RATE; i++;
+ }
+ case 5500000:
+ priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE; i++;
+ case 2000000:
+ priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE; i++;
+ case 1000000:
+ priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE; i++;
+ break;
+ default:
+ return -EINVAL;
+ }
+ priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
+ priv->reg.rate_set.size = i;
+ }else{
+ priv->reg.rate_set.body[11] = TX_RATE_54M;
+ priv->reg.rate_set.body[10] = TX_RATE_48M;
+ priv->reg.rate_set.body[9] = TX_RATE_36M;
+ priv->reg.rate_set.body[8] = TX_RATE_18M;
+ priv->reg.rate_set.body[7] = TX_RATE_9M;
+ priv->reg.rate_set.body[6] = TX_RATE_24M|BASIC_RATE;
+ priv->reg.rate_set.body[5] = TX_RATE_12M|BASIC_RATE;
+ priv->reg.rate_set.body[4] = TX_RATE_6M|BASIC_RATE;
+ priv->reg.rate_set.body[3] = TX_RATE_11M|BASIC_RATE;
+ priv->reg.rate_set.body[2] = TX_RATE_5M|BASIC_RATE;
+ priv->reg.rate_set.body[1] = TX_RATE_2M|BASIC_RATE;
+ priv->reg.rate_set.body[0] = TX_RATE_1M|BASIC_RATE;
+ priv->reg.tx_rate = TX_RATE_FULL_AUTO;
+ priv->reg.rate_set.size = 12;
+ }
+ }
+ }
+
+ priv->need_commit |= SME_MODE_SET;
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get Bit-Rate */
+static int ks_wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
+ in_interrupt(),atomic_read(&update_phyinfo));
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if(!atomic_read(&update_phyinfo)){
+ ks_wlan_update_phy_information(priv);
+ }
+ vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
+ if(priv->reg.tx_rate == TX_RATE_FIXED)
+ vwrq->fixed = 1;
+ else
+ vwrq->fixed = 0;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set RTS threshold */
+static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ int rthr = vwrq->value;
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if(vwrq->disabled)
+ rthr = 2347;
+ if((rthr < 0) || (rthr > 2347)) {
+ return -EINVAL;
+ }
+ priv->reg.rts = rthr;
+ priv->need_commit |= SME_RTS;
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get RTS threshold */
+static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ vwrq->value = priv->reg.rts;
+ vwrq->disabled = (vwrq->value >= 2347);
+ vwrq->fixed = 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set Fragmentation threshold */
+static int ks_wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ int fthr = vwrq->value;
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ if(vwrq->disabled)
+ fthr = 2346;
+ if((fthr < 256) || (fthr > 2346)) {
+ return -EINVAL;
+ }
+ fthr &= ~0x1; /* Get an even value - is it really needed ??? */
+ priv->reg.fragment = fthr;
+ priv->need_commit |= SME_FRAG;
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get Fragmentation threshold */
+static int ks_wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ vwrq->value = priv->reg.fragment;
+ vwrq->disabled = (vwrq->value >= 2346);
+ vwrq->fixed = 1;
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set Mode of Operation */
+static int ks_wlan_set_mode(struct net_device *dev, struct iw_request_info *info,
+ __u32 *uwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ DPRINTK(2,"mode=%d\n",*uwrq);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ switch(*uwrq) {
+ case IW_MODE_ADHOC:
+ priv->reg.operation_mode = MODE_ADHOC;
+ priv->need_commit |= SME_MODE_SET;
+ break;
+ case IW_MODE_INFRA:
+ priv->reg.operation_mode = MODE_INFRASTRUCTURE;
+ priv->need_commit |= SME_MODE_SET;
+ break;
+ case IW_MODE_AUTO:
+ case IW_MODE_MASTER:
+ case IW_MODE_REPEAT:
+ case IW_MODE_SECOND:
+ case IW_MODE_MONITOR:
+ default:
+ return -EINVAL;
+ }
+
+ return -EINPROGRESS; /* Call commit handler */
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get Mode of Operation */
+static int ks_wlan_get_mode(struct net_device *dev, struct iw_request_info *info,
+ __u32 *uwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* If not managed, assume it's ad-hoc */
+ switch (priv->reg.operation_mode) {
+ case MODE_INFRASTRUCTURE:
+ *uwrq = IW_MODE_INFRA;
+ break;
+ case MODE_ADHOC:
+ *uwrq = IW_MODE_ADHOC;
+ break;
+ default:
+ *uwrq = IW_MODE_ADHOC;
+ }
+
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set Encryption Key */
+static int ks_wlan_set_encode(struct net_device *dev, struct iw_request_info *info,
+ struct iw_point *dwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+
+ wep_key_t key;
+ int index = (dwrq->flags & IW_ENCODE_INDEX);
+ int current_index = priv->reg.wep_index;
+ int i;
+
+ DPRINTK(2,"flags=%04X\n",dwrq->flags);
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* index check */
+ if((index<0) || (index>4))
+ return -EINVAL;
+ else if (index==0)
+ index = current_index;
+ else
+ index--;
+
+ /* Is WEP supported ? */
+ /* Basic checking: do we have a key to set ? */
+ if (dwrq->length > 0) {
+ if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
+ return -EINVAL;
+ }
+ if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
+ key.len = MAX_KEY_SIZE;
+ priv->reg.privacy_invoked = 0x01;
+ priv->need_commit |= SME_WEP_FLAG;
+ wep_on_off = WEP_ON_128BIT;
+ } else {
+ if (dwrq->length > 0) {
+ key.len = MIN_KEY_SIZE;
+ priv->reg.privacy_invoked = 0x01;
+ priv->need_commit |= SME_WEP_FLAG;
+ wep_on_off = WEP_ON_64BIT;
+ } else { /* Disable the key */
+ key.len = 0;
+ }
+ }
+ /* Check if the key is not marked as invalid */
+ if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
+ /* Cleanup */
+ memset(key.key, 0, MAX_KEY_SIZE);
+ /* Copy the key in the driver */
+ if(copy_from_user(key.key,dwrq->pointer,dwrq->length)) {
+ key.len = 0;
+ return -EFAULT;
+ }
+ /* Send the key to the card */
+ priv->reg.wep_key[index].size = key.len;
+ for (i=0; i<(priv->reg.wep_key[index].size); i++) {
+ priv->reg.wep_key[index].val[i] = key.key[i];
+ }
+ priv->need_commit |= (SME_WEP_VAL1<<index);
+ priv->reg.wep_index = index;
+ priv->need_commit |= SME_WEP_INDEX;
+ }
+ } else {
+ if(dwrq->flags & IW_ENCODE_DISABLED){
+ priv->reg.wep_key[0].size = 0;
+ priv->reg.wep_key[1].size = 0;
+ priv->reg.wep_key[2].size = 0;
+ priv->reg.wep_key[3].size = 0;
+ priv->reg.privacy_invoked = 0x00;
+ if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
+ priv->need_commit |= SME_MODE_SET;
+ }
+ priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
+ wep_on_off = WEP_OFF;
+ priv->need_commit |= SME_WEP_FLAG;
+ }else{
+ /* Do we want to just set the transmit key index ? */
+ if ((index>=0) && (index<4)) {
+ /* set_wep_key(priv, index, 0, 0, 1); xxx */
+ if(priv->reg.wep_key[index].size){
+ priv->reg.wep_index = index;
+ priv->need_commit |= SME_WEP_INDEX;
+ }
+ else
+ return -EINVAL;
+ }
+ }
+ }
+
+ /* Commit the changes if needed */
+ if(dwrq->flags & IW_ENCODE_MODE)
+ priv->need_commit |= SME_WEP_FLAG;
+
+ if(dwrq->flags & IW_ENCODE_OPEN) {
+ if(priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY){
+ priv->need_commit |= SME_MODE_SET;
+ }
+ priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
+ } else if(dwrq->flags & IW_ENCODE_RESTRICTED) {
+ if(priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM){
+ priv->need_commit |= SME_MODE_SET;
+ }
+ priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
+ }
+
+// return -EINPROGRESS; /* Call commit handler */
+ if(priv->need_commit){
+ ks_wlan_setup_parameter(priv, priv->need_commit);
+ priv->need_commit=0;
+ }
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get Encryption Key */
+static int ks_wlan_get_encode(struct net_device *dev, struct iw_request_info *info,
+ struct iw_point *dwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ char zeros[16];
+ int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ dwrq->flags = IW_ENCODE_DISABLED;
+
+ /* Check encryption mode */
+ switch(priv->reg.authenticate_type) {
+ case AUTH_TYPE_OPEN_SYSTEM:
+ dwrq->flags = IW_ENCODE_OPEN;
+ break;
+ case AUTH_TYPE_SHARED_KEY:
+ dwrq->flags = IW_ENCODE_RESTRICTED;
+ break;
+ }
+
+ memset(zeros,0, sizeof(zeros));
+
+ /* Which key do we want ? -1 -> tx index */
+ if((index < 0) || (index >= 4))
+ index = priv->reg.wep_index;
+ if (priv->reg.privacy_invoked){
+ dwrq->flags &= ~IW_ENCODE_DISABLED;
+ /* dwrq->flags |= IW_ENCODE_NOKEY; */
+ }
+ dwrq->flags |= index + 1;
+ DPRINTK(2,"encoding flag = 0x%04X\n",dwrq->flags);
+ /* Copy the key to the user buffer */
+ if((index >= 0) && (index < 4))
+ dwrq->length = priv->reg.wep_key[index].size;
+ if (dwrq->length > 16) {
+ dwrq->length=0;
+ }
+#if 1 /* IW_ENCODE_NOKEY; */
+ if (dwrq->length) {
+ if((index >= 0) && (index < 4))
+ memcpy(extra,priv->reg.wep_key[index].val,dwrq->length);
+ } else
+ memcpy(extra,zeros,dwrq->length);
+#endif
+ return 0;
+}
+
+#ifndef KSC_OPNOTSUPP
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set Tx-Power */
+static int ks_wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ return -EOPNOTSUPP; /* Not Support */
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get Tx-Power */
+static int ks_wlan_get_txpow(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* Not Support */
+ vwrq->value = 0;
+ vwrq->disabled = (vwrq->value == 0);
+ vwrq->fixed = 1;
+ return 0;
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : set Retry limits */
+static int ks_wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ return -EOPNOTSUPP; /* Not Support */
+}
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get Retry limits */
+static int ks_wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
+ struct iw_param *vwrq, char *extra)
+{
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ /* Not Support */
+ vwrq->value = 0;
+ vwrq->disabled = (vwrq->value == 0);
+ vwrq->fixed = 1;
+ return 0;
+}
+#endif /* KSC_OPNOTSUPP */
+
+/*------------------------------------------------------------------*/
+/* Wireless Handler : get range info */
+static int ks_wlan_get_range(struct net_device *dev, struct iw_request_info *info,
+ struct iw_point *dwrq, char *extra)
+{
+ ks_wlan_private *priv = (ks_wlan_private *)netdev_priv(dev);
+ struct iw_range *range = (struct iw_range *) extra;
+ int i,k;
+
+ DPRINTK(2,"\n");
+
+ if (priv->sleep_mode == SLP_SLEEP){ return -EPERM; } /* for SLEEP MODE */
+
+ dwrq->length = sizeof(struct iw_range);
+ memset(range, 0, sizeof(*range));
+ range->min_nwid = 0x0000;
+ range->max_nwid = 0x0000;
+ range->num_channels = 14;
+ /* Should be based on cap_rid.country to give only
+ * what the current card support */
+ k = 0;
+ for(i = 0; i < 13; i++) { /* channel 1 -- 13*/
+ range->freq[k].i = i + 1; /* List index */
+ range->freq[k].m = frequency_list[i] * 100000;
+ range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
+ }
+ range->num_frequency = k;
+ if(priv->reg.phy_type == D_11B_ONLY_MODE ||
+ priv->reg.phy_type == D_11BG_COMPATIBLE_MODE){ /* channel 14 */
+ range->freq[13].i = 14; /* List index */
+ range->freq[13].m = frequency_list[13] * 100000;
+ range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
+ range->num_frequency = 14;
+ }
+
+ /* Hum... Should put the right values there */
+ range->max_qual.qual = 100;
+ range->max_qual.level = 256 - 128; /* 0 dBm? */
+ range->max_qual.noise = 256 - 128;
+ range->sensitivity = 1;
+
+ if(priv->reg.phy_type == D_11B_ONLY_MODE){
+ range->bitrate[0] = 1e6;
+ range->bitrate[1] = 2e6;
+ range->bitrate[2] = 5.5e6;
+ range->bitrate[3] = 11e6;
+ range->num_bitrates = 4;
+ }
+ else{ /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
+ range->bitrate[0] = 1e6;
+ range->bitrate[1] = 2e6;
+ range->bitrate[2] = 5.5e6;
+ range->bitrate[3] = 11e6;
+
+ range->bitrate[4] = 6e6;
+ range->bitrate[5] = 9e6;
+ range->bitrate[6] = 12e6;
+ if(IW_MAX_BITRATES < 9){
+ range->bitrate[7] = 54e6;
+ range->num_bitrates = 8;
+ }else{
+ range->bitrate[7] = 18e6;
+ range->bitrate[8] = 24e6;
+ range->bitrate[9] = 36e6;
+ range->bitrate[10] = 48e6;
+ range->bitrate[11] = 54e6;
+
+ range->num_bitrates = 12;
+ }
+ }
+<