linux/drivers/staging/ks7010/ks_wlan_net.c
<<
>>
Prefs
   1/*
   2 *   Driver for KeyStream 11b/g wireless LAN
   3 *
   4 *   Copyright (C) 2005-2008 KeyStream Corp.
   5 *   Copyright (C) 2009 Renesas Technology Corp.
   6 *
   7 *   This program is free software; you can redistribute it and/or modify
   8 *   it under the terms of the GNU General Public License version 2 as
   9 *   published by the Free Software Foundation.
  10 */
  11
  12#include <linux/version.h>
  13#include <linux/module.h>
  14#include <linux/kernel.h>
  15#include <linux/compiler.h>
  16#include <linux/init.h>
  17#include <linux/ioport.h>
  18#include <linux/netdevice.h>
  19#include <linux/etherdevice.h>
  20#include <linux/if_arp.h>
  21#include <linux/rtnetlink.h>
  22#include <linux/delay.h>
  23#include <linux/completion.h>
  24#include <linux/mii.h>
  25#include <linux/pci.h>
  26#include <linux/ctype.h>
  27#include <linux/timer.h>
  28#include <asm/atomic.h>
  29#include <linux/io.h>
  30#include <asm/uaccess.h>
  31
  32static int wep_on_off;
  33#define WEP_OFF         0
  34#define WEP_ON_64BIT    1
  35#define WEP_ON_128BIT   2
  36
  37#include "ks_wlan.h"
  38#include "ks_hostif.h"
  39#include "ks_wlan_ioctl.h"
  40
  41/* Include Wireless Extension definition and check version */
  42#include <linux/wireless.h>
  43#define WIRELESS_SPY    /* enable iwspy support */
  44#include <net/iw_handler.h>     /* New driver API */
  45
  46/* Frequency list (map channels to frequencies) */
  47static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
  48        2447, 2452, 2457, 2462, 2467, 2472, 2484
  49};
  50
  51/* A few details needed for WEP (Wireless Equivalent Privacy) */
  52#define MAX_KEY_SIZE 13 /* 128 (?) bits */
  53#define MIN_KEY_SIZE  5 /* 40 bits RC4 - WEP */
  54typedef struct wep_key_t {
  55        u16 len;
  56        u8 key[16];     /* 40-bit and 104-bit keys */
  57} wep_key_t;
  58
  59/* Backward compatibility */
  60#ifndef IW_ENCODE_NOKEY
  61#define IW_ENCODE_NOKEY 0x0800  /* Key is write only, so not present */
  62#define IW_ENCODE_MODE  (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
  63#endif /* IW_ENCODE_NOKEY */
  64
  65/* List of Wireless Handlers (new API) */
  66static const struct iw_handler_def ks_wlan_handler_def;
  67
  68#define KSC_OPNOTSUPP   /* Operation Not Support */
  69
  70/*
  71 *      function prototypes
  72 */
  73extern int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p,
  74                         unsigned long size,
  75                         void (*complete_handler) (void *arg1, void *arg2),
  76                         void *arg1, void *arg2);
  77static int ks_wlan_open(struct net_device *dev);
  78static void ks_wlan_tx_timeout(struct net_device *dev);
  79static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
  80static int ks_wlan_close(struct net_device *dev);
  81static void ks_wlan_set_multicast_list(struct net_device *dev);
  82static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
  83static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
  84static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
  85                                int cmd);
  86
  87static atomic_t update_phyinfo;
  88static struct timer_list update_phyinfo_timer;
  89static
  90int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
  91{
  92        struct iw_statistics *wstats = &priv->wstats;
  93
  94        DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
  95
  96        if (priv->dev_state < DEVICE_STATE_READY) {
  97                return -1;      /* not finished initialize */
  98        }
  99        if (atomic_read(&update_phyinfo))
 100                return 1;
 101
 102        /* The status */
 103        wstats->status = priv->reg.operation_mode;      /* Operation mode */
 104
 105        /* Signal quality and co. But where is the noise level ??? */
 106        hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
 107
 108        /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
 109        if (!wait_for_completion_interruptible_timeout
 110            (&priv->confirm_wait, HZ / 2)) {
 111                DPRINTK(1, "wait time out!!\n");
 112        }
 113
 114        atomic_inc(&update_phyinfo);
 115        update_phyinfo_timer.expires = jiffies + HZ;    /* 1sec */
 116        add_timer(&update_phyinfo_timer);
 117
 118        return 0;
 119}
 120
 121static
 122void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
 123{
 124        DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
 125        atomic_set(&update_phyinfo, 0);
 126}
 127
 128int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
 129                            unsigned int commit_flag)
 130{
 131        DPRINTK(2, "\n");
 132
 133        hostif_sme_enqueue(priv, SME_STOP_REQUEST);
 134
 135        if (commit_flag & SME_RTS)
 136                hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
 137        if (commit_flag & SME_FRAG)
 138                hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
 139
 140        if (commit_flag & SME_WEP_INDEX)
 141                hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
 142        if (commit_flag & SME_WEP_VAL1)
 143                hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
 144        if (commit_flag & SME_WEP_VAL2)
 145                hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
 146        if (commit_flag & SME_WEP_VAL3)
 147                hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
 148        if (commit_flag & SME_WEP_VAL4)
 149                hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
 150        if (commit_flag & SME_WEP_FLAG)
 151                hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
 152
 153        if (commit_flag & SME_RSN) {
 154                hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
 155                hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
 156        }
 157        if (commit_flag & SME_RSN_MULTICAST)
 158                hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
 159        if (commit_flag & SME_RSN_UNICAST)
 160                hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
 161        if (commit_flag & SME_RSN_AUTH)
 162                hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
 163
 164        hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
 165
 166        hostif_sme_enqueue(priv, SME_START_REQUEST);
 167
 168        return 0;
 169}
 170
 171/*
 172 * Initial Wireless Extension code for Ks_Wlannet driver by :
 173 *      Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
 174 * Conversion to new driver API by :
 175 *      Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
 176 * Javier also did a good amount of work here, adding some new extensions
 177 * and fixing my code. Let's just say that without him this code just
 178 * would not work at all... - Jean II
 179 */
 180
 181/*------------------------------------------------------------------*/
 182/* Wireless Handler : get protocol name */
 183static int ks_wlan_get_name(struct net_device *dev,
 184                            struct iw_request_info *info, char *cwrq,
 185                            char *extra)
 186{
 187        struct ks_wlan_private *priv =
 188            (struct ks_wlan_private *)netdev_priv(dev);
 189
 190        if (priv->sleep_mode == SLP_SLEEP) {
 191                return -EPERM;
 192        }
 193        /* for SLEEP MODE */
 194        if (priv->dev_state < DEVICE_STATE_READY) {
 195                strcpy(cwrq, "NOT READY!");
 196        } else if (priv->reg.phy_type == D_11B_ONLY_MODE) {
 197                strcpy(cwrq, "IEEE 802.11b");
 198        } else if (priv->reg.phy_type == D_11G_ONLY_MODE) {
 199                strcpy(cwrq, "IEEE 802.11g");
 200        } else {
 201                strcpy(cwrq, "IEEE 802.11b/g");
 202        }
 203
 204        return 0;
 205}
 206
 207/*------------------------------------------------------------------*/
 208/* Wireless Handler : set frequency */
 209static int ks_wlan_set_freq(struct net_device *dev,
 210                            struct iw_request_info *info, struct iw_freq *fwrq,
 211                            char *extra)
 212{
 213        struct ks_wlan_private *priv =
 214            (struct ks_wlan_private *)netdev_priv(dev);
 215        int rc = -EINPROGRESS;  /* Call commit handler */
 216
 217        if (priv->sleep_mode == SLP_SLEEP) {
 218                return -EPERM;
 219        }
 220
 221        /* for SLEEP MODE */
 222        /* If setting by frequency, convert to a channel */
 223        if ((fwrq->e == 1) &&
 224            (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
 225                int f = fwrq->m / 100000;
 226                int c = 0;
 227                while ((c < 14) && (f != frequency_list[c]))
 228                        c++;
 229                /* Hack to fall through... */
 230                fwrq->e = 0;
 231                fwrq->m = c + 1;
 232        }
 233        /* Setting by channel number */
 234        if ((fwrq->m > 1000) || (fwrq->e > 0))
 235                rc = -EOPNOTSUPP;
 236        else {
 237                int channel = fwrq->m;
 238                /* We should do a better check than that,
 239                 * based on the card capability !!! */
 240                if ((channel < 1) || (channel > 14)) {
 241                        printk(KERN_DEBUG
 242                               "%s: New channel value of %d is invalid!\n",
 243                               dev->name, fwrq->m);
 244                        rc = -EINVAL;
 245                } else {
 246                        /* Yes ! We can set it !!! */
 247                        priv->reg.channel = (u8) (channel);
 248                        priv->need_commit |= SME_MODE_SET;
 249                }
 250        }
 251
 252        return rc;
 253}
 254
 255/*------------------------------------------------------------------*/
 256/* Wireless Handler : get frequency */
 257static int ks_wlan_get_freq(struct net_device *dev,
 258                            struct iw_request_info *info, struct iw_freq *fwrq,
 259                            char *extra)
 260{
 261        struct ks_wlan_private *priv =
 262            (struct ks_wlan_private *)netdev_priv(dev);
 263        int f;
 264
 265        if (priv->sleep_mode == SLP_SLEEP) {
 266                return -EPERM;
 267        }
 268        /* for SLEEP MODE */
 269        if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
 270                f = (int)priv->current_ap.channel;
 271        } else
 272                f = (int)priv->reg.channel;
 273        fwrq->m = frequency_list[f - 1] * 100000;
 274        fwrq->e = 1;
 275
 276        return 0;
 277}
 278
 279/*------------------------------------------------------------------*/
 280/* Wireless Handler : set ESSID */
 281static int ks_wlan_set_essid(struct net_device *dev,
 282                             struct iw_request_info *info,
 283                             struct iw_point *dwrq, char *extra)
 284{
 285        struct ks_wlan_private *priv =
 286            (struct ks_wlan_private *)netdev_priv(dev);
 287        size_t len;
 288
 289        DPRINTK(2, " %d\n", dwrq->flags);
 290
 291        if (priv->sleep_mode == SLP_SLEEP) {
 292                return -EPERM;
 293        }
 294
 295        /* for SLEEP MODE */
 296        /* Check if we asked for `any' */
 297        if (dwrq->flags == 0) {
 298                /* Just send an empty SSID list */
 299                memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
 300                priv->reg.ssid.size = 0;
 301        } else {
 302#if 1
 303                len = dwrq->length;
 304                /* iwconfig uses nul termination in SSID.. */
 305                if (len > 0 && extra[len - 1] == '\0')
 306                        len--;
 307
 308                /* Check the size of the string */
 309                if (len > IW_ESSID_MAX_SIZE) {
 310                        return -EINVAL;
 311                }
 312#else
 313                /* Check the size of the string */
 314                if (dwrq->length > IW_ESSID_MAX_SIZE + 1) {
 315                        return -E2BIG;
 316                }
 317#endif
 318
 319                /* Set the SSID */
 320                memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
 321
 322#if 1
 323                memcpy(priv->reg.ssid.body, extra, len);
 324                priv->reg.ssid.size = len;
 325#else
 326                memcpy(priv->reg.ssid.body, extra, dwrq->length);
 327                priv->reg.ssid.size = dwrq->length;
 328#endif
 329        }
 330        /* Write it to the card */
 331        priv->need_commit |= SME_MODE_SET;
 332
 333//      return  -EINPROGRESS;   /* Call commit handler */
 334        ks_wlan_setup_parameter(priv, priv->need_commit);
 335        priv->need_commit = 0;
 336        return 0;
 337}
 338
 339/*------------------------------------------------------------------*/
 340/* Wireless Handler : get ESSID */
 341static int ks_wlan_get_essid(struct net_device *dev,
 342                             struct iw_request_info *info,
 343                             struct iw_point *dwrq, char *extra)
 344{
 345        struct ks_wlan_private *priv =
 346            (struct ks_wlan_private *)netdev_priv(dev);
 347
 348        if (priv->sleep_mode == SLP_SLEEP) {
 349                return -EPERM;
 350        }
 351
 352        /* for SLEEP MODE */
 353        /* Note : if dwrq->flags != 0, we should
 354         * get the relevant SSID from the SSID list... */
 355        if (priv->reg.ssid.size) {
 356                /* Get the current SSID */
 357                memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
 358#if 0
 359                extra[priv->reg.ssid.size] = '\0';
 360#endif
 361                /* If none, we may want to get the one that was set */
 362
 363                /* Push it out ! */
 364#if 1
 365                dwrq->length = priv->reg.ssid.size;
 366#else
 367                dwrq->length = priv->reg.ssid.size + 1;
 368#endif
 369                dwrq->flags = 1;        /* active */
 370        } else {
 371#if 1
 372                dwrq->length = 0;
 373#else
 374                extra[0] = '\0';
 375                dwrq->length = 1;
 376#endif
 377                dwrq->flags = 0;        /* ANY */
 378        }
 379
 380        return 0;
 381}
 382
 383/*------------------------------------------------------------------*/
 384/* Wireless Handler : set AP address */
 385static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
 386                           struct sockaddr *ap_addr, char *extra)
 387{
 388        struct ks_wlan_private *priv =
 389            (struct ks_wlan_private *)netdev_priv(dev);
 390
 391        DPRINTK(2, "\n");
 392
 393        if (priv->sleep_mode == SLP_SLEEP) {
 394                return -EPERM;
 395        }
 396        /* for SLEEP MODE */
 397        if (priv->reg.operation_mode == MODE_ADHOC ||
 398            priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
 399                memcpy(priv->reg.bssid, (u8 *) & ap_addr->sa_data, ETH_ALEN);
 400
 401                if (is_valid_ether_addr((u8 *) priv->reg.bssid)) {
 402                        priv->need_commit |= SME_MODE_SET;
 403                }
 404        } else {
 405                memset(priv->reg.bssid, 0x0, ETH_ALEN);
 406                return -EOPNOTSUPP;
 407        }
 408
 409        DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
 410                priv->reg.bssid[0], priv->reg.bssid[1], priv->reg.bssid[2],
 411                priv->reg.bssid[3], priv->reg.bssid[4], priv->reg.bssid[5]);
 412
 413        /* Write it to the card */
 414        if (priv->need_commit) {
 415                priv->need_commit |= SME_MODE_SET;
 416                return -EINPROGRESS;    /* Call commit handler */
 417        }
 418        return 0;
 419}
 420
 421/*------------------------------------------------------------------*/
 422/* Wireless Handler : get AP address */
 423static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
 424                           struct sockaddr *awrq, char *extra)
 425{
 426        struct ks_wlan_private *priv =
 427            (struct ks_wlan_private *)netdev_priv(dev);
 428
 429        if (priv->sleep_mode == SLP_SLEEP) {
 430                return -EPERM;
 431        }
 432        /* for SLEEP MODE */
 433        if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
 434                memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
 435        } else {
 436                memset(awrq->sa_data, 0, ETH_ALEN);
 437        }
 438
 439        awrq->sa_family = ARPHRD_ETHER;
 440
 441        return 0;
 442}
 443
 444/*------------------------------------------------------------------*/
 445/* Wireless Handler : set Nickname */
 446static int ks_wlan_set_nick(struct net_device *dev,
 447                            struct iw_request_info *info, struct iw_point *dwrq,
 448                            char *extra)
 449{
 450        struct ks_wlan_private *priv =
 451            (struct ks_wlan_private *)netdev_priv(dev);
 452
 453        if (priv->sleep_mode == SLP_SLEEP) {
 454                return -EPERM;
 455        }
 456
 457        /* for SLEEP MODE */
 458        /* Check the size of the string */
 459        if (dwrq->length > 16 + 1) {
 460                return -E2BIG;
 461        }
 462        memset(priv->nick, 0, sizeof(priv->nick));
 463        memcpy(priv->nick, extra, dwrq->length);
 464
 465        return -EINPROGRESS;    /* Call commit handler */
 466}
 467
 468/*------------------------------------------------------------------*/
 469/* Wireless Handler : get Nickname */
 470static int ks_wlan_get_nick(struct net_device *dev,
 471                            struct iw_request_info *info, struct iw_point *dwrq,
 472                            char *extra)
 473{
 474        struct ks_wlan_private *priv =
 475            (struct ks_wlan_private *)netdev_priv(dev);
 476
 477        if (priv->sleep_mode == SLP_SLEEP) {
 478                return -EPERM;
 479        }
 480        /* for SLEEP MODE */
 481        strncpy(extra, priv->nick, 16);
 482        extra[16] = '\0';
 483        dwrq->length = strlen(extra) + 1;
 484
 485        return 0;
 486}
 487
 488/*------------------------------------------------------------------*/
 489/* Wireless Handler : set Bit-Rate */
 490static int ks_wlan_set_rate(struct net_device *dev,
 491                            struct iw_request_info *info, struct iw_param *vwrq,
 492                            char *extra)
 493{
 494        struct ks_wlan_private *priv =
 495            (struct ks_wlan_private *)netdev_priv(dev);
 496        int i = 0;
 497
 498        if (priv->sleep_mode == SLP_SLEEP) {
 499                return -EPERM;
 500        }
 501        /* for SLEEP MODE */
 502        if (priv->reg.phy_type == D_11B_ONLY_MODE) {
 503                if (vwrq->fixed == 1) {
 504                        switch (vwrq->value) {
 505                        case 11000000:
 506                        case 5500000:
 507                                priv->reg.rate_set.body[0] =
 508                                    (uint8_t) (vwrq->value / 500000);
 509                                break;
 510                        case 2000000:
 511                        case 1000000:
 512                                priv->reg.rate_set.body[0] =
 513                                    ((uint8_t) (vwrq->value / 500000)) |
 514                                    BASIC_RATE;
 515                                break;
 516                        default:
 517                                return -EINVAL;
 518                        }
 519                        priv->reg.tx_rate = TX_RATE_FIXED;
 520                        priv->reg.rate_set.size = 1;
 521                } else {        /* vwrq->fixed == 0 */
 522                        if (vwrq->value > 0) {
 523                                switch (vwrq->value) {
 524                                case 11000000:
 525                                        priv->reg.rate_set.body[3] =
 526                                            TX_RATE_11M;
 527                                        i++;
 528                                case 5500000:
 529                                        priv->reg.rate_set.body[2] = TX_RATE_5M;
 530                                        i++;
 531                                case 2000000:
 532                                        priv->reg.rate_set.body[1] =
 533                                            TX_RATE_2M | BASIC_RATE;
 534                                        i++;
 535                                case 1000000:
 536                                        priv->reg.rate_set.body[0] =
 537                                            TX_RATE_1M | BASIC_RATE;
 538                                        i++;
 539                                        break;
 540                                default:
 541                                        return -EINVAL;
 542                                }
 543                                priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
 544                                priv->reg.rate_set.size = i;
 545                        } else {
 546                                priv->reg.rate_set.body[3] = TX_RATE_11M;
 547                                priv->reg.rate_set.body[2] = TX_RATE_5M;
 548                                priv->reg.rate_set.body[1] =
 549                                    TX_RATE_2M | BASIC_RATE;
 550                                priv->reg.rate_set.body[0] =
 551                                    TX_RATE_1M | BASIC_RATE;
 552                                priv->reg.tx_rate = TX_RATE_FULL_AUTO;
 553                                priv->reg.rate_set.size = 4;
 554                        }
 555                }
 556        } else {        /* D_11B_ONLY_MODE or  D_11BG_COMPATIBLE_MODE */
 557                if (vwrq->fixed == 1) {
 558                        switch (vwrq->value) {
 559                        case 54000000:
 560                        case 48000000:
 561                        case 36000000:
 562                        case 18000000:
 563                        case 9000000:
 564                                priv->reg.rate_set.body[0] =
 565                                    (uint8_t) (vwrq->value / 500000);
 566                                break;
 567                        case 24000000:
 568                        case 12000000:
 569                        case 11000000:
 570                        case 6000000:
 571                        case 5500000:
 572                        case 2000000:
 573                        case 1000000:
 574                                priv->reg.rate_set.body[0] =
 575                                    ((uint8_t) (vwrq->value / 500000)) |
 576                                    BASIC_RATE;
 577                                break;
 578                        default:
 579                                return -EINVAL;
 580                        }
 581                        priv->reg.tx_rate = TX_RATE_FIXED;
 582                        priv->reg.rate_set.size = 1;
 583                } else {        /* vwrq->fixed == 0 */
 584                        if (vwrq->value > 0) {
 585                                switch (vwrq->value) {
 586                                case 54000000:
 587                                        priv->reg.rate_set.body[11] =
 588                                            TX_RATE_54M;
 589                                        i++;
 590                                case 48000000:
 591                                        priv->reg.rate_set.body[10] =
 592                                            TX_RATE_48M;
 593                                        i++;
 594                                case 36000000:
 595                                        priv->reg.rate_set.body[9] =
 596                                            TX_RATE_36M;
 597                                        i++;
 598                                case 24000000:
 599                                case 18000000:
 600                                case 12000000:
 601                                case 11000000:
 602                                case 9000000:
 603                                case 6000000:
 604                                        if (vwrq->value == 24000000) {
 605                                                priv->reg.rate_set.body[8] =
 606                                                    TX_RATE_18M;
 607                                                i++;
 608                                                priv->reg.rate_set.body[7] =
 609                                                    TX_RATE_9M;
 610                                                i++;
 611                                                priv->reg.rate_set.body[6] =
 612                                                    TX_RATE_24M | BASIC_RATE;
 613                                                i++;
 614                                                priv->reg.rate_set.body[5] =
 615                                                    TX_RATE_12M | BASIC_RATE;
 616                                                i++;
 617                                                priv->reg.rate_set.body[4] =
 618                                                    TX_RATE_6M | BASIC_RATE;
 619                                                i++;
 620                                                priv->reg.rate_set.body[3] =
 621                                                    TX_RATE_11M | BASIC_RATE;
 622                                                i++;
 623                                        } else if (vwrq->value == 18000000) {
 624                                                priv->reg.rate_set.body[7] =
 625                                                    TX_RATE_18M;
 626                                                i++;
 627                                                priv->reg.rate_set.body[6] =
 628                                                    TX_RATE_9M;
 629                                                i++;
 630                                                priv->reg.rate_set.body[5] =
 631                                                    TX_RATE_12M | BASIC_RATE;
 632                                                i++;
 633                                                priv->reg.rate_set.body[4] =
 634                                                    TX_RATE_6M | BASIC_RATE;
 635                                                i++;
 636                                                priv->reg.rate_set.body[3] =
 637                                                    TX_RATE_11M | BASIC_RATE;
 638                                                i++;
 639                                        } else if (vwrq->value == 12000000) {
 640                                                priv->reg.rate_set.body[6] =
 641                                                    TX_RATE_9M;
 642                                                i++;
 643                                                priv->reg.rate_set.body[5] =
 644                                                    TX_RATE_12M | BASIC_RATE;
 645                                                i++;
 646                                                priv->reg.rate_set.body[4] =
 647                                                    TX_RATE_6M | BASIC_RATE;
 648                                                i++;
 649                                                priv->reg.rate_set.body[3] =
 650                                                    TX_RATE_11M | BASIC_RATE;
 651                                                i++;
 652                                        } else if (vwrq->value == 11000000) {
 653                                                priv->reg.rate_set.body[5] =
 654                                                    TX_RATE_9M;
 655                                                i++;
 656                                                priv->reg.rate_set.body[4] =
 657                                                    TX_RATE_6M | BASIC_RATE;
 658                                                i++;
 659                                                priv->reg.rate_set.body[3] =
 660                                                    TX_RATE_11M | BASIC_RATE;
 661                                                i++;
 662                                        } else if (vwrq->value == 9000000) {
 663                                                priv->reg.rate_set.body[4] =
 664                                                    TX_RATE_9M;
 665                                                i++;
 666                                                priv->reg.rate_set.body[3] =
 667                                                    TX_RATE_6M | BASIC_RATE;
 668                                                i++;
 669                                        } else {        /* vwrq->value == 6000000 */
 670                                                priv->reg.rate_set.body[3] =
 671                                                    TX_RATE_6M | BASIC_RATE;
 672                                                i++;
 673                                        }
 674                                case 5500000:
 675                                        priv->reg.rate_set.body[2] =
 676                                            TX_RATE_5M | BASIC_RATE;
 677                                        i++;
 678                                case 2000000:
 679                                        priv->reg.rate_set.body[1] =
 680                                            TX_RATE_2M | BASIC_RATE;
 681                                        i++;
 682                                case 1000000:
 683                                        priv->reg.rate_set.body[0] =
 684                                            TX_RATE_1M | BASIC_RATE;
 685                                        i++;
 686                                        break;
 687                                default:
 688                                        return -EINVAL;
 689                                }
 690                                priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
 691                                priv->reg.rate_set.size = i;
 692                        } else {
 693                                priv->reg.rate_set.body[11] = TX_RATE_54M;
 694                                priv->reg.rate_set.body[10] = TX_RATE_48M;
 695                                priv->reg.rate_set.body[9] = TX_RATE_36M;
 696                                priv->reg.rate_set.body[8] = TX_RATE_18M;
 697                                priv->reg.rate_set.body[7] = TX_RATE_9M;
 698                                priv->reg.rate_set.body[6] =
 699                                    TX_RATE_24M | BASIC_RATE;
 700                                priv->reg.rate_set.body[5] =
 701                                    TX_RATE_12M | BASIC_RATE;
 702                                priv->reg.rate_set.body[4] =
 703                                    TX_RATE_6M | BASIC_RATE;
 704                                priv->reg.rate_set.body[3] =
 705                                    TX_RATE_11M | BASIC_RATE;
 706                                priv->reg.rate_set.body[2] =
 707                                    TX_RATE_5M | BASIC_RATE;
 708                                priv->reg.rate_set.body[1] =
 709                                    TX_RATE_2M | BASIC_RATE;
 710                                priv->reg.rate_set.body[0] =
 711                                    TX_RATE_1M | BASIC_RATE;
 712                                priv->reg.tx_rate = TX_RATE_FULL_AUTO;
 713                                priv->reg.rate_set.size = 12;
 714                        }
 715                }
 716        }
 717
 718        priv->need_commit |= SME_MODE_SET;
 719
 720        return -EINPROGRESS;    /* Call commit handler */
 721}
 722
 723/*------------------------------------------------------------------*/
 724/* Wireless Handler : get Bit-Rate */
 725static int ks_wlan_get_rate(struct net_device *dev,
 726                            struct iw_request_info *info, struct iw_param *vwrq,
 727                            char *extra)
 728{
 729        struct ks_wlan_private *priv =
 730            (struct ks_wlan_private *)netdev_priv(dev);
 731
 732        DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
 733                in_interrupt(), atomic_read(&update_phyinfo));
 734
 735        if (priv->sleep_mode == SLP_SLEEP) {
 736                return -EPERM;
 737        }
 738        /* for SLEEP MODE */
 739        if (!atomic_read(&update_phyinfo)) {
 740                ks_wlan_update_phy_information(priv);
 741        }
 742        vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
 743        if (priv->reg.tx_rate == TX_RATE_FIXED)
 744                vwrq->fixed = 1;
 745        else
 746                vwrq->fixed = 0;
 747
 748        return 0;
 749}
 750
 751/*------------------------------------------------------------------*/
 752/* Wireless Handler : set RTS threshold */
 753static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
 754                           struct iw_param *vwrq, char *extra)
 755{
 756        struct ks_wlan_private *priv =
 757            (struct ks_wlan_private *)netdev_priv(dev);
 758        int rthr = vwrq->value;
 759
 760        if (priv->sleep_mode == SLP_SLEEP) {
 761                return -EPERM;
 762        }
 763        /* for SLEEP MODE */
 764        if (vwrq->disabled)
 765                rthr = 2347;
 766        if ((rthr < 0) || (rthr > 2347)) {
 767                return -EINVAL;
 768        }
 769        priv->reg.rts = rthr;
 770        priv->need_commit |= SME_RTS;
 771
 772        return -EINPROGRESS;    /* Call commit handler */
 773}
 774
 775/*------------------------------------------------------------------*/
 776/* Wireless Handler : get RTS threshold */
 777static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
 778                           struct iw_param *vwrq, char *extra)
 779{
 780        struct ks_wlan_private *priv =
 781            (struct ks_wlan_private *)netdev_priv(dev);
 782
 783        if (priv->sleep_mode == SLP_SLEEP) {
 784                return -EPERM;
 785        }
 786        /* for SLEEP MODE */
 787        vwrq->value = priv->reg.rts;
 788        vwrq->disabled = (vwrq->value >= 2347);
 789        vwrq->fixed = 1;
 790
 791        return 0;
 792}
 793
 794/*------------------------------------------------------------------*/
 795/* Wireless Handler : set Fragmentation threshold */
 796static int ks_wlan_set_frag(struct net_device *dev,
 797                            struct iw_request_info *info, struct iw_param *vwrq,
 798                            char *extra)
 799{
 800        struct ks_wlan_private *priv =
 801            (struct ks_wlan_private *)netdev_priv(dev);
 802        int fthr = vwrq->value;
 803
 804        if (priv->sleep_mode == SLP_SLEEP) {
 805                return -EPERM;
 806        }
 807        /* for SLEEP MODE */
 808        if (vwrq->disabled)
 809                fthr = 2346;
 810        if ((fthr < 256) || (fthr > 2346)) {
 811                return -EINVAL;
 812        }
 813        fthr &= ~0x1;   /* Get an even value - is it really needed ??? */
 814        priv->reg.fragment = fthr;
 815        priv->need_commit |= SME_FRAG;
 816
 817        return -EINPROGRESS;    /* Call commit handler */
 818}
 819
 820/*------------------------------------------------------------------*/
 821/* Wireless Handler : get Fragmentation threshold */
 822static int ks_wlan_get_frag(struct net_device *dev,
 823                            struct iw_request_info *info, struct iw_param *vwrq,
 824                            char *extra)
 825{
 826        struct ks_wlan_private *priv =
 827            (struct ks_wlan_private *)netdev_priv(dev);
 828
 829        if (priv->sleep_mode == SLP_SLEEP) {
 830                return -EPERM;
 831        }
 832        /* for SLEEP MODE */
 833        vwrq->value = priv->reg.fragment;
 834        vwrq->disabled = (vwrq->value >= 2346);
 835        vwrq->fixed = 1;
 836
 837        return 0;
 838}
 839
 840/*------------------------------------------------------------------*/
 841/* Wireless Handler : set Mode of Operation */
 842static int ks_wlan_set_mode(struct net_device *dev,
 843                            struct iw_request_info *info, __u32 * uwrq,
 844                            char *extra)
 845{
 846        struct ks_wlan_private *priv =
 847            (struct ks_wlan_private *)netdev_priv(dev);
 848
 849        DPRINTK(2, "mode=%d\n", *uwrq);
 850
 851        if (priv->sleep_mode == SLP_SLEEP) {
 852                return -EPERM;
 853        }
 854        /* for SLEEP MODE */
 855        switch (*uwrq) {
 856        case IW_MODE_ADHOC:
 857                priv->reg.operation_mode = MODE_ADHOC;
 858                priv->need_commit |= SME_MODE_SET;
 859                break;
 860        case IW_MODE_INFRA:
 861                priv->reg.operation_mode = MODE_INFRASTRUCTURE;
 862                priv->need_commit |= SME_MODE_SET;
 863                break;
 864        case IW_MODE_AUTO:
 865        case IW_MODE_MASTER:
 866        case IW_MODE_REPEAT:
 867        case IW_MODE_SECOND:
 868        case IW_MODE_MONITOR:
 869        default:
 870                return -EINVAL;
 871        }
 872
 873        return -EINPROGRESS;    /* Call commit handler */
 874}
 875
 876/*------------------------------------------------------------------*/
 877/* Wireless Handler : get Mode of Operation */
 878static int ks_wlan_get_mode(struct net_device *dev,
 879                            struct iw_request_info *info, __u32 * uwrq,
 880                            char *extra)
 881{
 882        struct ks_wlan_private *priv =
 883            (struct ks_wlan_private *)netdev_priv(dev);
 884
 885        if (priv->sleep_mode == SLP_SLEEP) {
 886                return -EPERM;
 887        }
 888
 889        /* for SLEEP MODE */
 890        /* If not managed, assume it's ad-hoc */
 891        switch (priv->reg.operation_mode) {
 892        case MODE_INFRASTRUCTURE:
 893                *uwrq = IW_MODE_INFRA;
 894                break;
 895        case MODE_ADHOC:
 896                *uwrq = IW_MODE_ADHOC;
 897                break;
 898        default:
 899                *uwrq = IW_MODE_ADHOC;
 900        }
 901
 902        return 0;
 903}
 904
 905/*------------------------------------------------------------------*/
 906/* Wireless Handler : set Encryption Key */
 907static int ks_wlan_set_encode(struct net_device *dev,
 908                              struct iw_request_info *info,
 909                              struct iw_point *dwrq, char *extra)
 910{
 911        struct ks_wlan_private *priv =
 912            (struct ks_wlan_private *)netdev_priv(dev);
 913
 914        wep_key_t key;
 915        int index = (dwrq->flags & IW_ENCODE_INDEX);
 916        int current_index = priv->reg.wep_index;
 917        int i;
 918
 919        DPRINTK(2, "flags=%04X\n", dwrq->flags);
 920
 921        if (priv->sleep_mode == SLP_SLEEP) {
 922                return -EPERM;
 923        }
 924
 925        /* for SLEEP MODE */
 926        /* index check */
 927        if ((index < 0) || (index > 4))
 928                return -EINVAL;
 929        else if (index == 0)
 930                index = current_index;
 931        else
 932                index--;
 933
 934        /* Is WEP supported ? */
 935        /* Basic checking: do we have a key to set ? */
 936        if (dwrq->length > 0) {
 937                if (dwrq->length > MAX_KEY_SIZE) {      /* Check the size of the key */
 938                        return -EINVAL;
 939                }
 940                if (dwrq->length > MIN_KEY_SIZE) {      /* Set the length */
 941                        key.len = MAX_KEY_SIZE;
 942                        priv->reg.privacy_invoked = 0x01;
 943                        priv->need_commit |= SME_WEP_FLAG;
 944                        wep_on_off = WEP_ON_128BIT;
 945                } else {
 946                        if (dwrq->length > 0) {
 947                                key.len = MIN_KEY_SIZE;
 948                                priv->reg.privacy_invoked = 0x01;
 949                                priv->need_commit |= SME_WEP_FLAG;
 950                                wep_on_off = WEP_ON_64BIT;
 951                        } else {        /* Disable the key */
 952                                key.len = 0;
 953                        }
 954                }
 955                /* Check if the key is not marked as invalid */
 956                if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
 957                        /* Cleanup */
 958                        memset(key.key, 0, MAX_KEY_SIZE);
 959                        /* Copy the key in the driver */
 960                        if (copy_from_user
 961                            (key.key, dwrq->pointer, dwrq->length)) {
 962                                key.len = 0;
 963                                return -EFAULT;
 964                        }
 965                        /* Send the key to the card */
 966                        priv->reg.wep_key[index].size = key.len;
 967                        for (i = 0; i < (priv->reg.wep_key[index].size); i++) {
 968                                priv->reg.wep_key[index].val[i] = key.key[i];
 969                        }
 970                        priv->need_commit |= (SME_WEP_VAL1 << index);
 971                        priv->reg.wep_index = index;
 972                        priv->need_commit |= SME_WEP_INDEX;
 973                }
 974        } else {
 975                if (dwrq->flags & IW_ENCODE_DISABLED) {
 976                        priv->reg.wep_key[0].size = 0;
 977                        priv->reg.wep_key[1].size = 0;
 978                        priv->reg.wep_key[2].size = 0;
 979                        priv->reg.wep_key[3].size = 0;
 980                        priv->reg.privacy_invoked = 0x00;
 981                        if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
 982                                priv->need_commit |= SME_MODE_SET;
 983                        }
 984                        priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
 985                        wep_on_off = WEP_OFF;
 986                        priv->need_commit |= SME_WEP_FLAG;
 987                } else {
 988                        /* Do we want to just set the transmit key index ? */
 989                        if ((index >= 0) && (index < 4)) {
 990                                /* set_wep_key(priv, index, 0, 0, 1);   xxx */
 991                                if (priv->reg.wep_key[index].size) {
 992                                        priv->reg.wep_index = index;
 993                                        priv->need_commit |= SME_WEP_INDEX;
 994                                } else
 995                                        return -EINVAL;
 996                        }
 997                }
 998        }
 999
1000        /* Commit the changes if needed */
1001        if (dwrq->flags & IW_ENCODE_MODE)
1002                priv->need_commit |= SME_WEP_FLAG;
1003
1004        if (dwrq->flags & IW_ENCODE_OPEN) {
1005                if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
1006                        priv->need_commit |= SME_MODE_SET;
1007                }
1008                priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1009        } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1010                if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) {
1011                        priv->need_commit |= SME_MODE_SET;
1012                }
1013                priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1014        }
1015//      return -EINPROGRESS;            /* Call commit handler */
1016        if (priv->need_commit) {
1017                ks_wlan_setup_parameter(priv, priv->need_commit);
1018                priv->need_commit = 0;
1019        }
1020        return 0;
1021}
1022
1023/*------------------------------------------------------------------*/
1024/* Wireless Handler : get Encryption Key */
1025static int ks_wlan_get_encode(struct net_device *dev,
1026                              struct iw_request_info *info,
1027                              struct iw_point *dwrq, char *extra)
1028{
1029        struct ks_wlan_private *priv =
1030            (struct ks_wlan_private *)netdev_priv(dev);
1031        char zeros[16];
1032        int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1033
1034        if (priv->sleep_mode == SLP_SLEEP) {
1035                return -EPERM;
1036        }
1037        /* for SLEEP MODE */
1038        dwrq->flags = IW_ENCODE_DISABLED;
1039
1040        /* Check encryption mode */
1041        switch (priv->reg.authenticate_type) {
1042        case AUTH_TYPE_OPEN_SYSTEM:
1043                dwrq->flags = IW_ENCODE_OPEN;
1044                break;
1045        case AUTH_TYPE_SHARED_KEY:
1046                dwrq->flags = IW_ENCODE_RESTRICTED;
1047                break;
1048        }
1049
1050        memset(zeros, 0, sizeof(zeros));
1051
1052        /* Which key do we want ? -1 -> tx index */
1053        if ((index < 0) || (index >= 4))
1054                index = priv->reg.wep_index;
1055        if (priv->reg.privacy_invoked) {
1056                dwrq->flags &= ~IW_ENCODE_DISABLED;
1057                /* dwrq->flags |= IW_ENCODE_NOKEY; */
1058        }
1059        dwrq->flags |= index + 1;
1060        DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
1061        /* Copy the key to the user buffer */
1062        if ((index >= 0) && (index < 4))
1063                dwrq->length = priv->reg.wep_key[index].size;
1064        if (dwrq->length > 16) {
1065                dwrq->length = 0;
1066        }
1067#if 1   /* IW_ENCODE_NOKEY; */
1068        if (dwrq->length) {
1069                if ((index >= 0) && (index < 4))
1070                        memcpy(extra, priv->reg.wep_key[index].val,
1071                               dwrq->length);
1072        } else
1073                memcpy(extra, zeros, dwrq->length);
1074#endif
1075        return 0;
1076}
1077
1078#ifndef KSC_OPNOTSUPP
1079/*------------------------------------------------------------------*/
1080/* Wireless Handler : set Tx-Power */
1081static int ks_wlan_set_txpow(struct net_device *dev,
1082                             struct iw_request_info *info,
1083                             struct iw_param *vwrq, char *extra)
1084{
1085        return -EOPNOTSUPP;     /* Not Support */
1086}
1087
1088/*------------------------------------------------------------------*/
1089/* Wireless Handler : get Tx-Power */
1090static int ks_wlan_get_txpow(struct net_device *dev,
1091                             struct iw_request_info *info,
1092                             struct iw_param *vwrq, char *extra)
1093{
1094        if (priv->sleep_mode == SLP_SLEEP) {
1095                return -EPERM;
1096        }
1097
1098        /* for SLEEP MODE */
1099        /* Not Support */
1100        vwrq->value = 0;
1101        vwrq->disabled = (vwrq->value == 0);
1102        vwrq->fixed = 1;
1103        return 0;
1104}
1105
1106/*------------------------------------------------------------------*/
1107/* Wireless Handler : set Retry limits */
1108static int ks_wlan_set_retry(struct net_device *dev,
1109                             struct iw_request_info *info,
1110                             struct iw_param *vwrq, char *extra)
1111{
1112        return -EOPNOTSUPP;     /* Not Support */
1113}
1114
1115/*------------------------------------------------------------------*/
1116/* Wireless Handler : get Retry limits */
1117static int ks_wlan_get_retry(struct net_device *dev,
1118                             struct iw_request_info *info,
1119                             struct iw_param *vwrq, char *extra)
1120{
1121        if (priv->sleep_mode == SLP_SLEEP) {
1122                return -EPERM;
1123        }
1124
1125        /* for SLEEP MODE */
1126        /* Not Support */
1127        vwrq->value = 0;
1128        vwrq->disabled = (vwrq->value == 0);
1129        vwrq->fixed = 1;
1130        return 0;
1131}
1132#endif /* KSC_OPNOTSUPP */
1133
1134/*------------------------------------------------------------------*/
1135/* Wireless Handler : get range info */
1136static int ks_wlan_get_range(struct net_device *dev,
1137                             struct iw_request_info *info,
1138                             struct iw_point *dwrq, char *extra)
1139{
1140        struct ks_wlan_private *priv =
1141            (struct ks_wlan_private *)netdev_priv(dev);
1142        struct iw_range *range = (struct iw_range *)extra;
1143        int i, k;
1144
1145        DPRINTK(2, "\n");
1146
1147        if (priv->sleep_mode == SLP_SLEEP) {
1148                return -EPERM;
1149        }
1150        /* for SLEEP MODE */
1151        dwrq->length = sizeof(struct iw_range);
1152        memset(range, 0, sizeof(*range));
1153        range->min_nwid = 0x0000;
1154        range->max_nwid = 0x0000;
1155        range->num_channels = 14;
1156        /* Should be based on cap_rid.country to give only
1157         * what the current card support */
1158        k = 0;
1159        for (i = 0; i < 13; i++) {      /* channel 1 -- 13 */
1160                range->freq[k].i = i + 1;       /* List index */
1161                range->freq[k].m = frequency_list[i] * 100000;
1162                range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1163        }
1164        range->num_frequency = k;
1165        if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) {    /* channel 14 */
1166                range->freq[13].i = 14; /* List index */
1167                range->freq[13].m = frequency_list[13] * 100000;
1168                range->freq[13].e = 1;  /* Values in table in MHz -> * 10^5 * 10 */
1169                range->num_frequency = 14;
1170        }
1171
1172        /* Hum... Should put the right values there */
1173        range->max_qual.qual = 100;
1174        range->max_qual.level = 256 - 128;      /* 0 dBm? */
1175        range->max_qual.noise = 256 - 128;
1176        range->sensitivity = 1;
1177
1178        if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1179                range->bitrate[0] = 1e6;
1180                range->bitrate[1] = 2e6;
1181                range->bitrate[2] = 5.5e6;
1182                range->bitrate[3] = 11e6;
1183                range->num_bitrates = 4;
1184        } else {        /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1185                range->bitrate[0] = 1e6;
1186                range->bitrate[1] = 2e6;
1187                range->bitrate[2] = 5.5e6;
1188                range->bitrate[3] = 11e6;
1189
1190                range->bitrate[4] = 6e6;
1191                range->bitrate[5] = 9e6;
1192                range->bitrate[6] = 12e6;
1193                if (IW_MAX_BITRATES < 9) {
1194                        range->bitrate[7] = 54e6;
1195                        range->num_bitrates = 8;
1196                } else {
1197                        range->bitrate[7] = 18e6;
1198                        range->bitrate[8] = 24e6;
1199                        range->bitrate[9] = 36e6;
1200                        range->bitrate[10] = 48e6;
1201                        range->bitrate[11] = 54e6;
1202
1203                        range->num_bitrates = 12;
1204                }
1205        }
1206
1207        /* Set an indication of the max TCP throughput
1208         * in bit/s that we can expect using this interface.
1209         * May be use for QoS stuff... Jean II */
1210        if (i > 2)
1211                range->throughput = 5000 * 1000;
1212        else
1213                range->throughput = 1500 * 1000;
1214
1215        range->min_rts = 0;
1216        range->max_rts = 2347;
1217        range->min_frag = 256;
1218        range->max_frag = 2346;
1219
1220        range->encoding_size[0] = 5;    /* WEP: RC4 40 bits */
1221        range->encoding_size[1] = 13;   /* WEP: RC4 ~128 bits */
1222        range->num_encoding_sizes = 2;
1223        range->max_encoding_tokens = 4;
1224
1225        /* power management not support */
1226        range->pmp_flags = IW_POWER_ON;
1227        range->pmt_flags = IW_POWER_ON;
1228        range->pm_capa = 0;
1229
1230        /* Transmit Power - values are in dBm( or mW) */
1231        range->txpower[0] = -256;
1232        range->num_txpower = 1;
1233        range->txpower_capa = IW_TXPOW_DBM;
1234        /* range->txpower_capa = IW_TXPOW_MWATT; */
1235
1236        range->we_version_source = 21;
1237        range->we_version_compiled = WIRELESS_EXT;
1238
1239        range->retry_capa = IW_RETRY_ON;
1240        range->retry_flags = IW_RETRY_ON;
1241        range->r_time_flags = IW_RETRY_ON;
1242
1243        /* Experimental measurements - boundary 11/5.5 Mb/s */
1244        /* Note : with or without the (local->rssi), results
1245         * are somewhat different. - Jean II */
1246        range->avg_qual.qual = 50;
1247        range->avg_qual.level = 186;    /* -70 dBm */
1248        range->avg_qual.noise = 0;
1249
1250        /* Event capability (kernel + driver) */
1251        range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1252                                IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1253                                IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1254        range->event_capa[1] = IW_EVENT_CAPA_K_1;
1255        range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1256                                IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1257
1258        /* encode extension (WPA) capability */
1259        range->enc_capa = (IW_ENC_CAPA_WPA |
1260                           IW_ENC_CAPA_WPA2 |
1261                           IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1262        return 0;
1263}
1264
1265/*------------------------------------------------------------------*/
1266/* Wireless Handler : set Power Management */
1267static int ks_wlan_set_power(struct net_device *dev,
1268                             struct iw_request_info *info,
1269                             struct iw_param *vwrq, char *extra)
1270{
1271        struct ks_wlan_private *priv =
1272            (struct ks_wlan_private *)netdev_priv(dev);
1273        short enabled;
1274
1275        if (priv->sleep_mode == SLP_SLEEP) {
1276                return -EPERM;
1277        }
1278        /* for SLEEP MODE */
1279        enabled = vwrq->disabled ? 0 : 1;
1280        if (enabled == 0) {     /* 0 */
1281                priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1282        } else if (enabled) {   /* 1 */
1283                if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1284                        priv->reg.powermgt = POWMGT_SAVE1_MODE;
1285                else
1286                        return -EINVAL;
1287        } else if (enabled) {   /* 2 */
1288                if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1289                        priv->reg.powermgt = POWMGT_SAVE2_MODE;
1290                else
1291                        return -EINVAL;
1292        } else
1293                return -EINVAL;
1294
1295        hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1296
1297        return 0;
1298}
1299
1300/*------------------------------------------------------------------*/
1301/* Wireless Handler : get Power Management */
1302static int ks_wlan_get_power(struct net_device *dev,
1303                             struct iw_request_info *info,
1304                             struct iw_param *vwrq, char *extra)
1305{
1306        struct ks_wlan_private *priv =
1307            (struct ks_wlan_private *)netdev_priv(dev);
1308
1309        if (priv->sleep_mode == SLP_SLEEP) {
1310                return -EPERM;
1311        }
1312        /* for SLEEP MODE */
1313        if (priv->reg.powermgt > 0)
1314                vwrq->disabled = 0;
1315        else
1316                vwrq->disabled = 1;
1317
1318        return 0;
1319}
1320
1321/*------------------------------------------------------------------*/
1322/* Wireless Handler : get wirless statistics */
1323static int ks_wlan_get_iwstats(struct net_device *dev,
1324                               struct iw_request_info *info,
1325                               struct iw_quality *vwrq, char *extra)
1326{
1327        struct ks_wlan_private *priv =
1328            (struct ks_wlan_private *)netdev_priv(dev);
1329
1330        if (priv->sleep_mode == SLP_SLEEP) {
1331                return -EPERM;
1332        }
1333        /* for SLEEP MODE */
1334        vwrq->qual = 0; /* not supported */
1335        vwrq->level = priv->wstats.qual.level;
1336        vwrq->noise = 0;        /* not supported */
1337        vwrq->updated = 0;
1338
1339        return 0;
1340}
1341
1342#ifndef KSC_OPNOTSUPP
1343/*------------------------------------------------------------------*/
1344/* Wireless Handler : set Sensitivity */
1345static int ks_wlan_set_sens(struct net_device *dev,
1346                            struct iw_request_info *info, struct iw_param *vwrq,
1347                            char *extra)
1348{
1349        return -EOPNOTSUPP;     /* Not Support */
1350}
1351
1352/*------------------------------------------------------------------*/
1353/* Wireless Handler : get Sensitivity */
1354static int ks_wlan_get_sens(struct net_device *dev,
1355                            struct iw_request_info *info, struct iw_param *vwrq,
1356                            char *extra)
1357{
1358        /* Not Support */
1359        vwrq->value = 0;
1360        vwrq->disabled = (vwrq->value == 0);
1361        vwrq->fixed = 1;
1362        return 0;
1363}
1364#endif /* KSC_OPNOTSUPP */
1365
1366/*------------------------------------------------------------------*/
1367/* Wireless Handler : get AP List */
1368/* Note : this is deprecated in favor of IWSCAN */
1369static int ks_wlan_get_aplist(struct net_device *dev,
1370                              struct iw_request_info *info,
1371                              struct iw_point *dwrq, char *extra)
1372{
1373        struct ks_wlan_private *priv =
1374            (struct ks_wlan_private *)netdev_priv(dev);
1375        struct sockaddr *address = (struct sockaddr *)extra;
1376        struct iw_quality qual[LOCAL_APLIST_MAX];
1377
1378        int i;
1379
1380        if (priv->sleep_mode == SLP_SLEEP) {
1381                return -EPERM;
1382        }
1383        /* for SLEEP MODE */
1384        for (i = 0; i < priv->aplist.size; i++) {
1385                memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1386                       ETH_ALEN);
1387                address[i].sa_family = ARPHRD_ETHER;
1388                qual[i].level = 256 - priv->aplist.ap[i].rssi;
1389                qual[i].qual = priv->aplist.ap[i].sq;
1390                qual[i].noise = 0;      /* invalid noise value */
1391                qual[i].updated = 7;
1392        }
1393        if (i) {
1394                dwrq->flags = 1;        /* Should be define'd */
1395                memcpy(extra + sizeof(struct sockaddr) * i,
1396                       &qual, sizeof(struct iw_quality) * i);
1397        }
1398        dwrq->length = i;
1399
1400        return 0;
1401}
1402
1403/*------------------------------------------------------------------*/
1404/* Wireless Handler : Initiate Scan */
1405static int ks_wlan_set_scan(struct net_device *dev,
1406                            struct iw_request_info *info,
1407                            union iwreq_data *wrqu, char *extra)
1408{
1409        struct ks_wlan_private *priv =
1410            (struct ks_wlan_private *)netdev_priv(dev);
1411        struct iw_scan_req *req = NULL;
1412        DPRINTK(2, "\n");
1413
1414        if (priv->sleep_mode == SLP_SLEEP) {
1415                return -EPERM;
1416        }
1417
1418        /* for SLEEP MODE */
1419        /* specified SSID SCAN */
1420        if (wrqu->data.length == sizeof(struct iw_scan_req)
1421            && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1422                req = (struct iw_scan_req *)extra;
1423                priv->scan_ssid_len = req->essid_len;
1424                memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1425        } else {
1426                priv->scan_ssid_len = 0;
1427        }
1428
1429        priv->sme_i.sme_flag |= SME_AP_SCAN;
1430        hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1431
1432        /* At this point, just return to the user. */
1433
1434        return 0;
1435}
1436
1437/*------------------------------------------------------------------*/
1438/*
1439 * Translate scan data returned from the card to a card independent
1440 * format that the Wireless Tools will understand - Jean II
1441 */
1442static inline char *ks_wlan_translate_scan(struct net_device *dev,
1443                                           struct iw_request_info *info,
1444                                           char *current_ev, char *end_buf,
1445                                           struct local_ap_t *ap)
1446{
1447        /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1448        struct iw_event iwe;    /* Temporary buffer */
1449        u16 capabilities;
1450        char *current_val;      /* For rates */
1451        int i;
1452        static const char rsn_leader[] = "rsn_ie=";
1453        static const char wpa_leader[] = "wpa_ie=";
1454        char buf0[RSN_IE_BODY_MAX * 2 + 30];
1455        char buf1[RSN_IE_BODY_MAX * 2 + 30];
1456        char *pbuf;
1457        /* First entry *MUST* be the AP MAC address */
1458        iwe.cmd = SIOCGIWAP;
1459        iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1460        memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1461        current_ev =
1462            iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1463                                 IW_EV_ADDR_LEN);
1464
1465        /* Other entries will be displayed in the order we give them */
1466
1467        /* Add the ESSID */
1468        iwe.u.data.length = ap->ssid.size;
1469        if (iwe.u.data.length > 32)
1470                iwe.u.data.length = 32;
1471        iwe.cmd = SIOCGIWESSID;
1472        iwe.u.data.flags = 1;
1473        current_ev =
1474            iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1475                                 &(ap->ssid.body[0]));
1476
1477        /* Add mode */
1478        iwe.cmd = SIOCGIWMODE;
1479        capabilities = le16_to_cpu(ap->capability);
1480        if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1481                if (capabilities & BSS_CAP_ESS)
1482                        iwe.u.mode = IW_MODE_INFRA;
1483                else
1484                        iwe.u.mode = IW_MODE_ADHOC;
1485                current_ev =
1486                    iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1487                                         IW_EV_UINT_LEN);
1488        }
1489
1490        /* Add frequency */
1491        iwe.cmd = SIOCGIWFREQ;
1492        iwe.u.freq.m = ap->channel;
1493        iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1494        iwe.u.freq.e = 1;
1495        current_ev =
1496            iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1497                                 IW_EV_FREQ_LEN);
1498
1499        /* Add quality statistics */
1500        iwe.cmd = IWEVQUAL;
1501        iwe.u.qual.level = 256 - ap->rssi;
1502        iwe.u.qual.qual = ap->sq;
1503        iwe.u.qual.noise = 0;   /* invalid noise value */
1504        current_ev =
1505            iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1506                                 IW_EV_QUAL_LEN);
1507
1508        /* Add encryption capability */
1509        iwe.cmd = SIOCGIWENCODE;
1510        if (capabilities & BSS_CAP_PRIVACY)
1511                iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1512        else
1513                iwe.u.data.flags = IW_ENCODE_DISABLED;
1514        iwe.u.data.length = 0;
1515        current_ev =
1516            iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1517                                 &(ap->ssid.body[0]));
1518
1519        /* Rate : stuffing multiple values in a single event require a bit
1520         * more of magic - Jean II */
1521        current_val = current_ev + IW_EV_LCP_LEN;
1522
1523        iwe.cmd = SIOCGIWRATE;
1524        /* Those two flags are ignored... */
1525        iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1526
1527        /* Max 16 values */
1528        for (i = 0; i < 16; i++) {
1529                /* NULL terminated */
1530                if (i >= ap->rate_set.size)
1531                        break;
1532                /* Bit rate given in 500 kb/s units (+ 0x80) */
1533                iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1534                /* Add new value to event */
1535                current_val =
1536                    iwe_stream_add_value(info, current_ev, current_val, end_buf,
1537                                         &iwe, IW_EV_PARAM_LEN);
1538        }
1539        /* Check if we added any event */
1540        if ((current_val - current_ev) > IW_EV_LCP_LEN)
1541                current_ev = current_val;
1542
1543#define GENERIC_INFO_ELEM_ID 0xdd
1544#define RSN_INFO_ELEM_ID 0x30
1545        if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1546                pbuf = &buf0[0];
1547                memset(&iwe, 0, sizeof(iwe));
1548                iwe.cmd = IWEVCUSTOM;
1549                memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1550                iwe.u.data.length += sizeof(rsn_leader) - 1;
1551                pbuf += sizeof(rsn_leader) - 1;
1552
1553                pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1554                pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1555                iwe.u.data.length += 4;
1556
1557                for (i = 0; i < ap->rsn_ie.size; i++)
1558                        pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1559                iwe.u.data.length += (ap->rsn_ie.size) * 2;
1560
1561                DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1562
1563                current_ev =
1564                    iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1565                                         &buf0[0]);
1566        }
1567        if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1568                pbuf = &buf1[0];
1569                memset(&iwe, 0, sizeof(iwe));
1570                iwe.cmd = IWEVCUSTOM;
1571                memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1572                iwe.u.data.length += sizeof(wpa_leader) - 1;
1573                pbuf += sizeof(wpa_leader) - 1;
1574
1575                pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1576                pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1577                iwe.u.data.length += 4;
1578
1579                for (i = 0; i < ap->wpa_ie.size; i++)
1580                        pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1581                iwe.u.data.length += (ap->wpa_ie.size) * 2;
1582
1583                DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1584                DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1585
1586                current_ev =
1587                    iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1588                                         &buf1[0]);
1589        }
1590
1591        /* The other data in the scan result are not really
1592         * interesting, so for now drop it - Jean II */
1593        return current_ev;
1594}
1595
1596/*------------------------------------------------------------------*/
1597/* Wireless Handler : Read Scan Results */
1598static int ks_wlan_get_scan(struct net_device *dev,
1599                            struct iw_request_info *info, struct iw_point *dwrq,
1600                            char *extra)
1601{
1602        struct ks_wlan_private *priv =
1603            (struct ks_wlan_private *)netdev_priv(dev);
1604        int i;
1605        char *current_ev = extra;
1606        DPRINTK(2, "\n");
1607
1608        if (priv->sleep_mode == SLP_SLEEP) {
1609                return -EPERM;
1610        }
1611        /* for SLEEP MODE */
1612        if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1613                DPRINTK(2, "flag AP_SCAN\n");
1614                return -EAGAIN;
1615        }
1616
1617        if (priv->aplist.size == 0) {
1618                /* Client error, no scan results...
1619                 * The caller need to restart the scan. */
1620                DPRINTK(2, "aplist 0\n");
1621                return -ENODATA;
1622        }
1623#if 0
1624        /* current connect ap */
1625        if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1626                if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1627                        dwrq->length = 0;
1628                        return -E2BIG;
1629                }
1630                current_ev = ks_wlan_translate_scan(dev, current_ev,
1631//                                                  extra + IW_SCAN_MAX_DATA,
1632                                                    extra + dwrq->length,
1633                                                    &(priv->current_ap));
1634        }
1635#endif
1636        /* Read and parse all entries */
1637        for (i = 0; i < priv->aplist.size; i++) {
1638                if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1639                        dwrq->length = 0;
1640                        return -E2BIG;
1641                }
1642                /* Translate to WE format this entry */
1643                current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1644//                                                  extra + IW_SCAN_MAX_DATA,
1645                                                    extra + dwrq->length,
1646                                                    &(priv->aplist.ap[i]));
1647        }
1648        /* Length of data */
1649        dwrq->length = (current_ev - extra);
1650        dwrq->flags = 0;
1651
1652        return 0;
1653}
1654
1655/*------------------------------------------------------------------*/
1656/* Commit handler : called after a bunch of SET operations */
1657static int ks_wlan_config_commit(struct net_device *dev,
1658                                 struct iw_request_info *info, void *zwrq,
1659                                 char *extra)
1660{
1661        struct ks_wlan_private *priv =
1662            (struct ks_wlan_private *)netdev_priv(dev);
1663
1664        if (!priv->need_commit)
1665                return 0;
1666
1667        ks_wlan_setup_parameter(priv, priv->need_commit);
1668        priv->need_commit = 0;
1669        return 0;
1670}
1671
1672/*------------------------------------------------------------------*/
1673/* Wireless handler : set association ie params */
1674static int ks_wlan_set_genie(struct net_device *dev,
1675                             struct iw_request_info *info,
1676                             struct iw_point *dwrq, char *extra)
1677{
1678        struct ks_wlan_private *priv =
1679            (struct ks_wlan_private *)netdev_priv(dev);
1680
1681        DPRINTK(2, "\n");
1682
1683        if (priv->sleep_mode == SLP_SLEEP) {
1684                return -EPERM;
1685        }
1686        /* for SLEEP MODE */
1687        return 0;
1688//      return -EOPNOTSUPP;
1689}
1690
1691/*------------------------------------------------------------------*/
1692/* Wireless handler : set authentication mode params */
1693static int ks_wlan_set_auth_mode(struct net_device *dev,
1694                                 struct iw_request_info *info,
1695                                 struct iw_param *vwrq, char *extra)
1696{
1697        struct ks_wlan_private *priv =
1698            (struct ks_wlan_private *)netdev_priv(dev);
1699        int index = (vwrq->flags & IW_AUTH_INDEX);
1700        int value = vwrq->value;
1701
1702        DPRINTK(2, "index=%d:value=%08X\n", index, value);
1703
1704        if (priv->sleep_mode == SLP_SLEEP) {
1705                return -EPERM;
1706        }
1707        /* for SLEEP MODE */
1708        switch (index) {
1709        case IW_AUTH_WPA_VERSION:       /* 0 */
1710                switch (value) {
1711                case IW_AUTH_WPA_VERSION_DISABLED:
1712                        priv->wpa.version = value;
1713                        if (priv->wpa.rsn_enabled) {
1714                                priv->wpa.rsn_enabled = 0;
1715                        }
1716                        priv->need_commit |= SME_RSN;
1717                        break;
1718                case IW_AUTH_WPA_VERSION_WPA:
1719                case IW_AUTH_WPA_VERSION_WPA2:
1720                        priv->wpa.version = value;
1721                        if (!(priv->wpa.rsn_enabled)) {
1722                                priv->wpa.rsn_enabled = 1;
1723                        }
1724                        priv->need_commit |= SME_RSN;
1725                        break;
1726                default:
1727                        return -EOPNOTSUPP;
1728                }
1729                break;
1730        case IW_AUTH_CIPHER_PAIRWISE:   /* 1 */
1731                switch (value) {
1732                case IW_AUTH_CIPHER_NONE:
1733                        if (priv->reg.privacy_invoked) {
1734                                priv->reg.privacy_invoked = 0x00;
1735                                priv->need_commit |= SME_WEP_FLAG;
1736                        }
1737                        break;
1738                case IW_AUTH_CIPHER_WEP40:
1739                case IW_AUTH_CIPHER_TKIP:
1740                case IW_AUTH_CIPHER_CCMP:
1741                case IW_AUTH_CIPHER_WEP104:
1742                        if (!priv->reg.privacy_invoked) {
1743                                priv->reg.privacy_invoked = 0x01;
1744                                priv->need_commit |= SME_WEP_FLAG;
1745                        }
1746                        priv->wpa.pairwise_suite = value;
1747                        priv->need_commit |= SME_RSN_UNICAST;
1748                        break;
1749                default:
1750                        return -EOPNOTSUPP;
1751                }
1752                break;
1753        case IW_AUTH_CIPHER_GROUP:      /* 2 */
1754                switch (value) {
1755                case IW_AUTH_CIPHER_NONE:
1756                        if (priv->reg.privacy_invoked) {
1757                                priv->reg.privacy_invoked = 0x00;
1758                                priv->need_commit |= SME_WEP_FLAG;
1759                        }
1760                        break;
1761                case IW_AUTH_CIPHER_WEP40:
1762                case IW_AUTH_CIPHER_TKIP:
1763                case IW_AUTH_CIPHER_CCMP:
1764                case IW_AUTH_CIPHER_WEP104:
1765                        if (!priv->reg.privacy_invoked) {
1766                                priv->reg.privacy_invoked = 0x01;
1767                                priv->need_commit |= SME_WEP_FLAG;
1768                        }
1769                        priv->wpa.group_suite = value;
1770                        priv->need_commit |= SME_RSN_MULTICAST;
1771                        break;
1772                default:
1773                        return -EOPNOTSUPP;
1774                }
1775                break;
1776        case IW_AUTH_KEY_MGMT:  /* 3 */
1777                switch (value) {
1778                case IW_AUTH_KEY_MGMT_802_1X:
1779                case IW_AUTH_KEY_MGMT_PSK:
1780                case 0: /* NONE or 802_1X_NO_WPA */
1781                case 4: /* WPA_NONE */
1782                        priv->wpa.key_mgmt_suite = value;
1783                        priv->need_commit |= SME_RSN_AUTH;
1784                        break;
1785                default:
1786                        return -EOPNOTSUPP;
1787                }
1788                break;
1789        case IW_AUTH_80211_AUTH_ALG:    /* 6 */
1790                switch (value) {
1791                case IW_AUTH_ALG_OPEN_SYSTEM:
1792                        priv->wpa.auth_alg = value;
1793                        priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1794                        break;
1795                case IW_AUTH_ALG_SHARED_KEY:
1796                        priv->wpa.auth_alg = value;
1797                        priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1798                        break;
1799                case IW_AUTH_ALG_LEAP:
1800                default:
1801                        return -EOPNOTSUPP;
1802                }
1803                priv->need_commit |= SME_MODE_SET;
1804                break;
1805        case IW_AUTH_WPA_ENABLED:       /* 7 */
1806                priv->wpa.wpa_enabled = value;
1807                break;
1808        case IW_AUTH_PRIVACY_INVOKED:   /* 10 */
1809                if ((value && !priv->reg.privacy_invoked) ||
1810                    (!value && priv->reg.privacy_invoked)) {
1811                        priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1812                        priv->need_commit |= SME_WEP_FLAG;
1813                }
1814                break;
1815        case IW_AUTH_RX_UNENCRYPTED_EAPOL:      /* 4 */
1816        case IW_AUTH_TKIP_COUNTERMEASURES:      /* 5 */
1817        case IW_AUTH_DROP_UNENCRYPTED:  /* 8 */
1818        case IW_AUTH_ROAMING_CONTROL:   /* 9 */
1819        default:
1820                break;
1821        }
1822
1823        /* return -EINPROGRESS; */
1824        if (priv->need_commit) {
1825                ks_wlan_setup_parameter(priv, priv->need_commit);
1826                priv->need_commit = 0;
1827        }
1828        return 0;
1829}
1830
1831/*------------------------------------------------------------------*/
1832/* Wireless handler : get authentication mode params */
1833static int ks_wlan_get_auth_mode(struct net_device *dev,
1834                                 struct iw_request_info *info,
1835                                 struct iw_param *vwrq, char *extra)
1836{
1837        struct ks_wlan_private *priv =
1838            (struct ks_wlan_private *)netdev_priv(dev);
1839        int index = (vwrq->flags & IW_AUTH_INDEX);
1840        DPRINTK(2, "index=%d\n", index);
1841
1842        if (priv->sleep_mode == SLP_SLEEP) {
1843                return -EPERM;
1844        }
1845
1846        /* for SLEEP MODE */
1847        /*  WPA (not used ?? wpa_supplicant) */
1848        switch (index) {
1849        case IW_AUTH_WPA_VERSION:
1850                vwrq->value = priv->wpa.version;
1851                break;
1852        case IW_AUTH_CIPHER_PAIRWISE:
1853                vwrq->value = priv->wpa.pairwise_suite;
1854                break;
1855        case IW_AUTH_CIPHER_GROUP:
1856                vwrq->value = priv->wpa.group_suite;
1857                break;
1858        case IW_AUTH_KEY_MGMT:
1859                vwrq->value = priv->wpa.key_mgmt_suite;
1860                break;
1861        case IW_AUTH_80211_AUTH_ALG:
1862                vwrq->value = priv->wpa.auth_alg;
1863                break;
1864        case IW_AUTH_WPA_ENABLED:
1865                vwrq->value = priv->wpa.rsn_enabled;
1866                break;
1867        case IW_AUTH_RX_UNENCRYPTED_EAPOL:      /* OK??? */
1868        case IW_AUTH_TKIP_COUNTERMEASURES:
1869        case IW_AUTH_DROP_UNENCRYPTED:
1870        default:
1871                /* return -EOPNOTSUPP; */
1872                break;
1873        }
1874        return 0;
1875}
1876
1877/*------------------------------------------------------------------*/
1878/* Wireless Handler : set encoding token & mode (WPA)*/
1879static int ks_wlan_set_encode_ext(struct net_device *dev,
1880                                  struct iw_request_info *info,
1881                                  struct iw_point *dwrq, char *extra)
1882{
1883        struct ks_wlan_private *priv =
1884            (struct ks_wlan_private *)netdev_priv(dev);
1885        struct iw_encode_ext *enc;
1886        int index = dwrq->flags & IW_ENCODE_INDEX;
1887        unsigned int commit = 0;
1888
1889        enc = (struct iw_encode_ext *)extra;
1890
1891        DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1892                enc->ext_flags);
1893
1894        if (priv->sleep_mode == SLP_SLEEP) {
1895                return -EPERM;
1896        }
1897        /* for SLEEP MODE */
1898        if (index < 1 || index > 4)
1899                return -EINVAL;
1900        else
1901                index--;
1902
1903        if (dwrq->flags & IW_ENCODE_DISABLED) {
1904                priv->wpa.key[index].key_len = 0;
1905        }
1906
1907        if (enc) {
1908                priv->wpa.key[index].ext_flags = enc->ext_flags;
1909                if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1910                        priv->wpa.txkey = index;
1911                        commit |= SME_WEP_INDEX;
1912                } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1913                        memcpy(&priv->wpa.key[index].rx_seq[0],
1914                               enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1915                }
1916
1917                memcpy(&priv->wpa.key[index].addr.sa_data[0],
1918                       &enc->addr.sa_data[0], ETH_ALEN);
1919
1920                switch (enc->alg) {
1921                case IW_ENCODE_ALG_NONE:
1922                        if (priv->reg.privacy_invoked) {
1923                                priv->reg.privacy_invoked = 0x00;
1924                                commit |= SME_WEP_FLAG;
1925                        }
1926                        priv->wpa.key[index].key_len = 0;
1927
1928                        break;
1929                case IW_ENCODE_ALG_WEP:
1930                case IW_ENCODE_ALG_CCMP:
1931                        if (!priv->reg.privacy_invoked) {
1932                                priv->reg.privacy_invoked = 0x01;
1933                                commit |= SME_WEP_FLAG;
1934                        }
1935                        if (enc->key_len) {
1936                                memcpy(&priv->wpa.key[index].key_val[0],
1937                                       &enc->key[0], enc->key_len);
1938                                priv->wpa.key[index].key_len = enc->key_len;
1939                                commit |= (SME_WEP_VAL1 << index);
1940                        }
1941                        break;
1942                case IW_ENCODE_ALG_TKIP:
1943                        if (!priv->reg.privacy_invoked) {
1944                                priv->reg.privacy_invoked = 0x01;
1945                                commit |= SME_WEP_FLAG;
1946                        }
1947                        if (enc->key_len == 32) {
1948                                memcpy(&priv->wpa.key[index].key_val[0],
1949                                       &enc->key[0], enc->key_len - 16);
1950                                priv->wpa.key[index].key_len =
1951                                    enc->key_len - 16;
1952                                if (priv->wpa.key_mgmt_suite == 4) {    /* WPA_NONE */
1953                                        memcpy(&priv->wpa.key[index].
1954                                               tx_mic_key[0], &enc->key[16], 8);
1955                                        memcpy(&priv->wpa.key[index].
1956                                               rx_mic_key[0], &enc->key[16], 8);
1957                                } else {
1958                                        memcpy(&priv->wpa.key[index].
1959                                               tx_mic_key[0], &enc->key[16], 8);
1960                                        memcpy(&priv->wpa.key[index].
1961                                               rx_mic_key[0], &enc->key[24], 8);
1962                                }
1963                                commit |= (SME_WEP_VAL1 << index);
1964                        }
1965                        break;
1966                default:
1967                        return -EINVAL;
1968                }
1969                priv->wpa.key[index].alg = enc->alg;
1970        } else
1971                return -EINVAL;
1972
1973        if (commit) {
1974                if (commit & SME_WEP_INDEX)
1975                        hostif_sme_enqueue(priv, SME_SET_TXKEY);
1976                if (commit & SME_WEP_VAL_MASK)
1977                        hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1978                if (commit & SME_WEP_FLAG)
1979                        hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1980        }
1981
1982        return 0;
1983}
1984
1985/*------------------------------------------------------------------*/
1986/* Wireless Handler : get encoding token & mode (WPA)*/
1987static int ks_wlan_get_encode_ext(struct net_device *dev,
1988                                  struct iw_request_info *info,
1989                                  struct iw_point *dwrq, char *extra)
1990{
1991        struct ks_wlan_private *priv =
1992            (struct ks_wlan_private *)netdev_priv(dev);
1993
1994        if (priv->sleep_mode == SLP_SLEEP) {
1995                return -EPERM;
1996        }
1997
1998        /* for SLEEP MODE */
1999        /*  WPA (not used ?? wpa_supplicant)
2000           struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2001           struct iw_encode_ext *enc;
2002           enc = (struct iw_encode_ext *)extra;
2003           int index = dwrq->flags & IW_ENCODE_INDEX;
2004           WPA (not used ?? wpa_supplicant) */
2005        return 0;
2006}
2007
2008/*------------------------------------------------------------------*/
2009/* Wireless Handler : PMKSA cache operation (WPA2) */
2010static int ks_wlan_set_pmksa(struct net_device *dev,
2011                             struct iw_request_info *info,
2012                             struct iw_point *dwrq, char *extra)
2013{
2014        struct ks_wlan_private *priv =
2015            (struct ks_wlan_private *)netdev_priv(dev);
2016        struct iw_pmksa *pmksa;
2017        int i;
2018        struct pmk_t *pmk;
2019        struct list_head *ptr;
2020
2021        DPRINTK(2, "\n");
2022
2023        if (priv->sleep_mode == SLP_SLEEP) {
2024                return -EPERM;
2025        }
2026        /* for SLEEP MODE */
2027        if (!extra) {
2028                return -EINVAL;
2029        }
2030        pmksa = (struct iw_pmksa *)extra;
2031        DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2032
2033        switch (pmksa->cmd) {
2034        case IW_PMKSA_ADD:
2035                if (list_empty(&priv->pmklist.head)) {  /* new list */
2036                        for (i = 0; i < PMK_LIST_MAX; i++) {
2037                                pmk = &priv->pmklist.pmk[i];
2038                                if (!memcmp
2039                                    ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2040                                     ETH_ALEN))
2041                                        break;
2042                        }
2043                        memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2044                        memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2045                        list_add(&pmk->list, &priv->pmklist.head);
2046                        priv->pmklist.size++;
2047                } else {        /* search cache data */
2048                        list_for_each(ptr, &priv->pmklist.head) {
2049                                pmk = list_entry(ptr, struct pmk_t, list);
2050                                if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {      /* match address! list move to head. */
2051                                        memcpy(pmk->pmkid, pmksa->pmkid,
2052                                               IW_PMKID_LEN);
2053                                        list_move(&pmk->list,
2054                                                  &priv->pmklist.head);
2055                                        break;
2056                                }
2057                        }
2058                        if (ptr == &priv->pmklist.head) {       /* not find address. */
2059                                if (PMK_LIST_MAX > priv->pmklist.size) {        /* new cache data */
2060                                        for (i = 0; i < PMK_LIST_MAX; i++) {
2061                                                pmk = &priv->pmklist.pmk[i];
2062                                                if (!memcmp
2063                                                    ("\x00\x00\x00\x00\x00\x00",
2064                                                     pmk->bssid, ETH_ALEN))
2065                                                        break;
2066                                        }
2067                                        memcpy(pmk->bssid, pmksa->bssid.sa_data,
2068                                               ETH_ALEN);
2069                                        memcpy(pmk->pmkid, pmksa->pmkid,
2070                                               IW_PMKID_LEN);
2071                                        list_add(&pmk->list,
2072                                                 &priv->pmklist.head);
2073                                        priv->pmklist.size++;
2074                                } else {        /* overwrite old cache data */
2075                                        pmk =
2076                                            list_entry(priv->pmklist.head.prev,
2077                                                       struct pmk_t, list);
2078                                        memcpy(pmk->bssid, pmksa->bssid.sa_data,
2079                                               ETH_ALEN);
2080                                        memcpy(pmk->pmkid, pmksa->pmkid,
2081                                               IW_PMKID_LEN);
2082                                        list_move(&pmk->list,
2083                                                  &priv->pmklist.head);
2084                                }
2085                        }
2086                }
2087                break;
2088        case IW_PMKSA_REMOVE:
2089                if (list_empty(&priv->pmklist.head)) {  /* list empty */
2090                        return -EINVAL;
2091                } else {        /* search cache data */
2092                        list_for_each(ptr, &priv->pmklist.head) {
2093                                pmk = list_entry(ptr, struct pmk_t, list);
2094                                if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) {      /* match address! list del. */
2095                                        memset(pmk->bssid, 0, ETH_ALEN);
2096                                        memset(pmk->pmkid, 0, IW_PMKID_LEN);
2097                                        list_del_init(&pmk->list);
2098                                        break;
2099                                }
2100                        }
2101                        if (ptr == &priv->pmklist.head) {       /* not find address. */
2102                                return 0;
2103                        }
2104                }
2105                break;
2106        case IW_PMKSA_FLUSH:
2107                memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2108                INIT_LIST_HEAD(&priv->pmklist.head);
2109                for (i = 0; i < PMK_LIST_MAX; i++)
2110                        INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2111                break;
2112        default:
2113                return -EINVAL;
2114        }
2115
2116        hostif_sme_enqueue(priv, SME_SET_PMKSA);
2117        return 0;
2118}
2119
2120static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2121{
2122
2123        struct ks_wlan_private *priv =
2124            (struct ks_wlan_private *)netdev_priv(dev);
2125        struct iw_statistics *wstats = &priv->wstats;
2126
2127        if (!atomic_read(&update_phyinfo)) {
2128                if (priv->dev_state < DEVICE_STATE_READY)
2129                        return NULL;    /* not finished initialize */
2130                else
2131                        return wstats;
2132        }
2133
2134        /* Packets discarded in the wireless adapter due to wireless
2135         * specific problems */
2136        wstats->discard.nwid = 0;       /* Rx invalid nwid      */
2137        wstats->discard.code = 0;       /* Rx invalid crypt     */
2138        wstats->discard.fragment = 0;   /* Rx invalid frag      */
2139        wstats->discard.retries = 0;    /* Tx excessive retries */
2140        wstats->discard.misc = 0;       /* Invalid misc         */
2141        wstats->miss.beacon = 0;        /* Missed beacon        */
2142
2143        return wstats;
2144}
2145
2146/*------------------------------------------------------------------*/
2147/* Private handler : set stop request */
2148static int ks_wlan_set_stop_request(struct net_device *dev,
2149                                    struct iw_request_info *info, __u32 * uwrq,
2150                                    char *extra)
2151{
2152        struct ks_wlan_private *priv =
2153            (struct ks_wlan_private *)netdev_priv(dev);
2154        DPRINTK(2, "\n");
2155
2156        if (priv->sleep_mode == SLP_SLEEP) {
2157                return -EPERM;
2158        }
2159        /* for SLEEP MODE */
2160        if (!(*uwrq))
2161                return -EINVAL;
2162
2163        hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2164        return 0;
2165}
2166
2167/*------------------------------------------------------------------*/
2168/* Wireless Handler : set MLME */
2169#include <linux/ieee80211.h>
2170static int ks_wlan_set_mlme(struct net_device *dev,
2171                            struct iw_request_info *info, struct iw_point *dwrq,
2172                            char *extra)
2173{
2174        struct ks_wlan_private *priv =
2175            (struct ks_wlan_private *)netdev_priv(dev);
2176        struct iw_mlme *mlme = (struct iw_mlme *)extra;
2177        __u32 mode;
2178
2179        DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2180
2181        if (priv->sleep_mode == SLP_SLEEP) {
2182                return -EPERM;
2183        }
2184        /* for SLEEP MODE */
2185        switch (mlme->cmd) {
2186        case IW_MLME_DEAUTH:
2187                if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2188                        return 0;
2189                }
2190        case IW_MLME_DISASSOC:
2191                mode = 1;
2192                return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2193        default:
2194                return -EOPNOTSUPP;     /* Not Support */
2195        }
2196}
2197
2198/*------------------------------------------------------------------*/
2199/* Private handler : get firemware version */
2200static int ks_wlan_get_firmware_version(struct net_device *dev,
2201                                        struct iw_request_info *info,
2202                                        struct iw_point *dwrq, char *extra)
2203{
2204        struct ks_wlan_private *priv =
2205            (struct ks_wlan_private *)netdev_priv(dev);
2206        strcpy(extra, &(priv->firmware_version[0]));
2207        dwrq->length = priv->version_size + 1;
2208        return 0;
2209}
2210
2211#if 0
2212/*------------------------------------------------------------------*/
2213/* Private handler : set force disconnect status */
2214static int ks_wlan_set_detach(struct net_device *dev,
2215                              struct iw_request_info *info, __u32 * uwrq,
2216                              char *extra)
2217{
2218        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2219
2220        if (priv->sleep_mode == SLP_SLEEP) {
2221                return -EPERM;
2222        }
2223        /* for SLEEP MODE */
2224        if (*uwrq == CONNECT_STATUS) {  /* 0 */
2225                priv->connect_status &= ~FORCE_DISCONNECT;
2226                if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2227                    CONNECT_STATUS)
2228                        netif_carrier_on(dev);
2229        } else if (*uwrq == DISCONNECT_STATUS) {        /* 1 */
2230                priv->connect_status |= FORCE_DISCONNECT;
2231                netif_carrier_off(dev);
2232        } else
2233                return -EINVAL;
2234        return 0;
2235}
2236
2237/*------------------------------------------------------------------*/
2238/* Private handler : get force disconnect status */
2239static int ks_wlan_get_detach(struct net_device *dev,
2240                              struct iw_request_info *info, __u32 * uwrq,
2241                              char *extra)
2242{
2243        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2244
2245        if (priv->sleep_mode == SLP_SLEEP) {
2246                return -EPERM;
2247        }
2248        /* for SLEEP MODE */
2249        *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2250        return 0;
2251}
2252
2253/*------------------------------------------------------------------*/
2254/* Private handler : get connect status */
2255static int ks_wlan_get_connect(struct net_device *dev,
2256                               struct iw_request_info *info, __u32 * uwrq,
2257                               char *extra)
2258{
2259        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2260
2261        if (priv->sleep_mode == SLP_SLEEP) {
2262                return -EPERM;
2263        }
2264        /* for SLEEP MODE */
2265        *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2266        return 0;
2267}
2268#endif
2269
2270/*------------------------------------------------------------------*/
2271/* Private handler : set preamble */
2272static int ks_wlan_set_preamble(struct net_device *dev,
2273                                struct iw_request_info *info, __u32 * uwrq,
2274                                char *extra)
2275{
2276        struct ks_wlan_private *priv =
2277            (struct ks_wlan_private *)netdev_priv(dev);
2278
2279        if (priv->sleep_mode == SLP_SLEEP) {
2280                return -EPERM;
2281        }
2282        /* for SLEEP MODE */
2283        if (*uwrq == LONG_PREAMBLE) {   /* 0 */
2284                priv->reg.preamble = LONG_PREAMBLE;
2285        } else if (*uwrq == SHORT_PREAMBLE) {   /* 1 */
2286                priv->reg.preamble = SHORT_PREAMBLE;
2287        } else
2288                return -EINVAL;
2289
2290        priv->need_commit |= SME_MODE_SET;
2291        return -EINPROGRESS;    /* Call commit handler */
2292
2293}
2294
2295/*------------------------------------------------------------------*/
2296/* Private handler : get preamble */
2297static int ks_wlan_get_preamble(struct net_device *dev,
2298                                struct iw_request_info *info, __u32 * uwrq,
2299                                char *extra)
2300{
2301        struct ks_wlan_private *priv =
2302            (struct ks_wlan_private *)netdev_priv(dev);
2303
2304        if (priv->sleep_mode == SLP_SLEEP) {
2305                return -EPERM;
2306        }
2307        /* for SLEEP MODE */
2308        *uwrq = priv->reg.preamble;
2309        return 0;
2310}
2311
2312/*------------------------------------------------------------------*/
2313/* Private handler : set power save mode */
2314static int ks_wlan_set_powermgt(struct net_device *dev,
2315                                struct iw_request_info *info, __u32 * uwrq,
2316                                char *extra)
2317{
2318        struct ks_wlan_private *priv =
2319            (struct ks_wlan_private *)netdev_priv(dev);
2320
2321        if (priv->sleep_mode == SLP_SLEEP) {
2322                return -EPERM;
2323        }
2324        /* for SLEEP MODE */
2325        if (*uwrq == POWMGT_ACTIVE_MODE) {      /* 0 */
2326                priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2327        } else if (*uwrq == POWMGT_SAVE1_MODE) {        /* 1 */
2328                if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2329                        priv->reg.powermgt = POWMGT_SAVE1_MODE;
2330                else
2331                        return -EINVAL;
2332        } else if (*uwrq == POWMGT_SAVE2_MODE) {        /* 2 */
2333                if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2334                        priv->reg.powermgt = POWMGT_SAVE2_MODE;
2335                else
2336                        return -EINVAL;
2337        } else
2338                return -EINVAL;
2339
2340        hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2341
2342        return 0;
2343}
2344
2345/*------------------------------------------------------------------*/
2346/* Private handler : get power save made */
2347static int ks_wlan_get_powermgt(struct net_device *dev,
2348                                struct iw_request_info *info, __u32 * uwrq,
2349                                char *extra)
2350{
2351        struct ks_wlan_private *priv =
2352            (struct ks_wlan_private *)netdev_priv(dev);
2353
2354        if (priv->sleep_mode == SLP_SLEEP) {
2355                return -EPERM;
2356        }
2357        /* for SLEEP MODE */
2358        *uwrq = priv->reg.powermgt;
2359        return 0;
2360}
2361
2362/*------------------------------------------------------------------*/
2363/* Private handler : set scan type */
2364static int ks_wlan_set_scan_type(struct net_device *dev,
2365                                 struct iw_request_info *info, __u32 * uwrq,
2366                                 char *extra)
2367{
2368        struct ks_wlan_private *priv =
2369            (struct ks_wlan_private *)netdev_priv(dev);
2370
2371        if (priv->sleep_mode == SLP_SLEEP) {
2372                return -EPERM;
2373        }
2374        /* for SLEEP MODE */
2375        if (*uwrq == ACTIVE_SCAN) {     /* 0 */
2376                priv->reg.scan_type = ACTIVE_SCAN;
2377        } else if (*uwrq == PASSIVE_SCAN) {     /* 1 */
2378                priv->reg.scan_type = PASSIVE_SCAN;
2379        } else
2380                return -EINVAL;
2381
2382        return 0;
2383}
2384
2385/*------------------------------------------------------------------*/
2386/* Private handler : get scan type */
2387static int ks_wlan_get_scan_type(struct net_device *dev,
2388                                 struct iw_request_info *info, __u32 * uwrq,
2389                                 char *extra)
2390{
2391        struct ks_wlan_private *priv =
2392            (struct ks_wlan_private *)netdev_priv(dev);
2393
2394        if (priv->sleep_mode == SLP_SLEEP) {
2395                return -EPERM;
2396        }
2397        /* for SLEEP MODE */
2398        *uwrq = priv->reg.scan_type;
2399        return 0;
2400}
2401
2402#if 0
2403/*------------------------------------------------------------------*/
2404/* Private handler : write raw data to device */
2405static int ks_wlan_data_write(struct net_device *dev,
2406                              struct iw_request_info *info,
2407                              struct iw_point *dwrq, char *extra)
2408{
2409        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2410        unsigned char *wbuff = NULL;
2411
2412        if (priv->sleep_mode == SLP_SLEEP) {
2413                return -EPERM;
2414        }
2415        /* for SLEEP MODE */
2416        wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2417        if (!wbuff)
2418                return -EFAULT;
2419        memcpy(wbuff, extra, dwrq->length);
2420
2421        /* write to device */
2422        ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2423
2424        return 0;
2425}
2426
2427/*------------------------------------------------------------------*/
2428/* Private handler : read raw data form device */
2429static int ks_wlan_data_read(struct net_device *dev,
2430                             struct iw_request_info *info,
2431                             struct iw_point *dwrq, char *extra)
2432{
2433        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2434        unsigned short read_length;
2435
2436        if (priv->sleep_mode == SLP_SLEEP) {
2437                return -EPERM;
2438        }
2439        /* for SLEEP MODE */
2440        if (!atomic_read(&priv->event_count)) {
2441                if (priv->dev_state < DEVICE_STATE_BOOT) {      /* Remove device */
2442                        read_length = 4;
2443                        memset(extra, 0xff, read_length);
2444                        dwrq->length = read_length;
2445                        return 0;
2446                }
2447                read_length = 0;
2448                memset(extra, 0, 1);
2449                dwrq->length = 0;
2450                return 0;
2451        }
2452
2453        if (atomic_read(&priv->event_count) > 0)
2454                atomic_dec(&priv->event_count);
2455
2456        spin_lock(&priv->dev_read_lock);        /* request spin lock */
2457
2458        /* Copy length max size 0x07ff */
2459        if (priv->dev_size[priv->dev_count] > 2047)
2460                read_length = 2047;
2461        else
2462                read_length = priv->dev_size[priv->dev_count];
2463
2464        /* Copy data */
2465        memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2466
2467        spin_unlock(&priv->dev_read_lock);      /* release spin lock */
2468
2469        /* Initialize */
2470        priv->dev_data[priv->dev_count] = 0;
2471        priv->dev_size[priv->dev_count] = 0;
2472
2473        priv->dev_count++;
2474        if (priv->dev_count == DEVICE_STOCK_COUNT)
2475                priv->dev_count = 0;
2476
2477        /* Set read size */
2478        dwrq->length = read_length;
2479
2480        return 0;
2481}
2482#endif
2483
2484#if 0
2485/*------------------------------------------------------------------*/
2486/* Private handler : get wep string */
2487#define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2488static int ks_wlan_get_wep_ascii(struct net_device *dev,
2489                                 struct iw_request_info *info,
2490                                 struct iw_point *dwrq, char *extra)
2491{
2492        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2493        int i, j, len = 0;
2494        char tmp[WEP_ASCII_BUFF_SIZE];
2495
2496        if (priv->sleep_mode == SLP_SLEEP) {
2497                return -EPERM;
2498        }
2499        /* for SLEEP MODE */
2500        strcpy(tmp, " WEP keys ASCII \n");
2501        len += strlen(" WEP keys ASCII \n");
2502
2503        for (i = 0; i < 4; i++) {
2504                strcpy(tmp + len, "\t[");
2505                len += strlen("\t[");
2506                tmp[len] = '1' + i;
2507                len++;
2508                strcpy(tmp + len, "] ");
2509                len += strlen("] ");
2510                if (priv->reg.wep_key[i].size) {
2511                        strcpy(tmp + len,
2512                               (priv->reg.wep_key[i].size <
2513                                6 ? "(40bits) [" : "(104bits) ["));
2514                        len +=
2515                            strlen((priv->reg.wep_key[i].size <
2516                                    6 ? "(40bits) [" : "(104bits) ["));
2517                        for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2518                                tmp[len] =
2519                                    (isprint(priv->reg.wep_key[i].val[j]) ?
2520                                     priv->reg.wep_key[i].val[j] : ' ');
2521
2522                        strcpy(tmp + len, "]\n");
2523                        len += strlen("]\n");
2524                } else {
2525                        strcpy(tmp + len, "off\n");
2526                        len += strlen("off\n");
2527                }
2528        }
2529
2530        memcpy(extra, tmp, len);
2531        dwrq->length = len + 1;
2532        return 0;
2533}
2534#endif
2535
2536/*------------------------------------------------------------------*/
2537/* Private handler : set beacon lost count */
2538static int ks_wlan_set_beacon_lost(struct net_device *dev,
2539                                   struct iw_request_info *info, __u32 * uwrq,
2540                                   char *extra)
2541{
2542        struct ks_wlan_private *priv =
2543            (struct ks_wlan_private *)netdev_priv(dev);
2544
2545        if (priv->sleep_mode == SLP_SLEEP) {
2546                return -EPERM;
2547        }
2548        /* for SLEEP MODE */
2549        if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2550                priv->reg.beacon_lost_count = *uwrq;
2551        } else
2552                return -EINVAL;
2553
2554        if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2555                priv->need_commit |= SME_MODE_SET;
2556                return -EINPROGRESS;    /* Call commit handler */
2557        } else
2558                return 0;
2559}
2560
2561/*------------------------------------------------------------------*/
2562/* Private handler : get beacon lost count */
2563static int ks_wlan_get_beacon_lost(struct net_device *dev,
2564                                   struct iw_request_info *info, __u32 * uwrq,
2565                                   char *extra)
2566{
2567        struct ks_wlan_private *priv =
2568            (struct ks_wlan_private *)netdev_priv(dev);
2569
2570        if (priv->sleep_mode == SLP_SLEEP) {
2571                return -EPERM;
2572        }
2573        /* for SLEEP MODE */
2574        *uwrq = priv->reg.beacon_lost_count;
2575        return 0;
2576}
2577
2578/*------------------------------------------------------------------*/
2579/* Private handler : set phy type */
2580static int ks_wlan_set_phy_type(struct net_device *dev,
2581                                struct iw_request_info *info, __u32 * uwrq,
2582                                char *extra)
2583{
2584        struct ks_wlan_private *priv =
2585            (struct ks_wlan_private *)netdev_priv(dev);
2586
2587        if (priv->sleep_mode == SLP_SLEEP) {
2588                return -EPERM;
2589        }
2590        /* for SLEEP MODE */
2591        if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2592                priv->reg.phy_type = D_11B_ONLY_MODE;
2593        } else if (*uwrq == D_11G_ONLY_MODE) {  /* 1 */
2594                priv->reg.phy_type = D_11G_ONLY_MODE;
2595        } else if (*uwrq == D_11BG_COMPATIBLE_MODE) {   /* 2 */
2596                priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2597        } else
2598                return -EINVAL;
2599
2600        priv->need_commit |= SME_MODE_SET;
2601        return -EINPROGRESS;    /* Call commit handler */
2602}
2603
2604/*------------------------------------------------------------------*/
2605/* Private handler : get phy type */
2606static int ks_wlan_get_phy_type(struct net_device *dev,
2607                                struct iw_request_info *info, __u32 * uwrq,
2608                                char *extra)
2609{
2610        struct ks_wlan_private *priv =
2611            (struct ks_wlan_private *)netdev_priv(dev);
2612
2613        if (priv->sleep_mode == SLP_SLEEP) {
2614                return -EPERM;
2615        }
2616        /* for SLEEP MODE */
2617        *uwrq = priv->reg.phy_type;
2618        return 0;
2619}
2620
2621/*------------------------------------------------------------------*/
2622/* Private handler : set cts mode */
2623static int ks_wlan_set_cts_mode(struct net_device *dev,
2624                                struct iw_request_info *info, __u32 * uwrq,
2625                                char *extra)
2626{
2627        struct ks_wlan_private *priv =
2628            (struct ks_wlan_private *)netdev_priv(dev);
2629
2630        if (priv->sleep_mode == SLP_SLEEP) {
2631                return -EPERM;
2632        }
2633        /* for SLEEP MODE */
2634        if (*uwrq == CTS_MODE_FALSE) {  /* 0 */
2635                priv->reg.cts_mode = CTS_MODE_FALSE;
2636        } else if (*uwrq == CTS_MODE_TRUE) {    /* 1 */
2637                if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2638                    priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2639                        priv->reg.cts_mode = CTS_MODE_TRUE;
2640                else
2641                        priv->reg.cts_mode = CTS_MODE_FALSE;
2642        } else
2643                return -EINVAL;
2644
2645        priv->need_commit |= SME_MODE_SET;
2646        return -EINPROGRESS;    /* Call commit handler */
2647}
2648
2649/*------------------------------------------------------------------*/
2650/* Private handler : get cts mode */
2651static int ks_wlan_get_cts_mode(struct net_device *dev,
2652                                struct iw_request_info *info, __u32 * uwrq,
2653                                char *extra)
2654{
2655        struct ks_wlan_private *priv =
2656            (struct ks_wlan_private *)netdev_priv(dev);
2657
2658        if (priv->sleep_mode == SLP_SLEEP) {
2659                return -EPERM;
2660        }
2661        /* for SLEEP MODE */
2662        *uwrq = priv->reg.cts_mode;
2663        return 0;
2664}
2665
2666/*------------------------------------------------------------------*/
2667/* Private handler : set sleep mode */
2668static int ks_wlan_set_sleep_mode(struct net_device *dev,
2669                                  struct iw_request_info *info,
2670                                  __u32 * uwrq, char *extra)
2671{
2672        struct ks_wlan_private *priv =
2673            (struct ks_wlan_private *)netdev_priv(dev);
2674
2675        DPRINTK(2, "\n");
2676
2677        if (*uwrq == SLP_SLEEP) {
2678                priv->sleep_mode = *uwrq;
2679                printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2680
2681                hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2682                hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2683
2684        } else if (*uwrq == SLP_ACTIVE) {
2685                priv->sleep_mode = *uwrq;
2686                printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2687                hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2688        } else {
2689                printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2690                return -EINVAL;
2691        }
2692
2693        return 0;
2694}
2695
2696/*------------------------------------------------------------------*/
2697/* Private handler : get sleep mode */
2698static int ks_wlan_get_sleep_mode(struct net_device *dev,
2699                                  struct iw_request_info *info,
2700                                  __u32 * uwrq, char *extra)
2701{
2702        struct ks_wlan_private *priv =
2703            (struct ks_wlan_private *)netdev_priv(dev);
2704
2705        DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2706        *uwrq = priv->sleep_mode;
2707
2708        return 0;
2709}
2710
2711#if 0
2712/*------------------------------------------------------------------*/
2713/* Private handler : set phy information timer */
2714static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2715                                             struct iw_request_info *info,
2716                                             __u32 * uwrq, char *extra)
2717{
2718        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2719
2720        if (priv->sleep_mode == SLP_SLEEP) {
2721                return -EPERM;
2722        }
2723        /* for SLEEP MODE */
2724        if (*uwrq >= 0 && *uwrq <= 0xFFFF)      /* 0-65535 */
2725                priv->reg.phy_info_timer = (uint16_t) * uwrq;
2726        else
2727                return -EINVAL;
2728
2729        hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2730
2731        return 0;
2732}
2733
2734/*------------------------------------------------------------------*/
2735/* Private handler : get phy information timer */
2736static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2737                                             struct iw_request_info *info,
2738                                             __u32 * uwrq, char *extra)
2739{
2740        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2741
2742        if (priv->sleep_mode == SLP_SLEEP) {
2743                return -EPERM;
2744        }
2745        /* for SLEEP MODE */
2746        *uwrq = priv->reg.phy_info_timer;
2747        return 0;
2748}
2749#endif
2750
2751#ifdef WPS
2752/*------------------------------------------------------------------*/
2753/* Private handler : set WPS enable */
2754static int ks_wlan_set_wps_enable(struct net_device *dev,
2755                                  struct iw_request_info *info, __u32 * uwrq,
2756                                  char *extra)
2757{
2758        struct ks_wlan_private *priv =
2759            (struct ks_wlan_private *)netdev_priv(dev);
2760        DPRINTK(2, "\n");
2761
2762        if (priv->sleep_mode == SLP_SLEEP) {
2763                return -EPERM;
2764        }
2765        /* for SLEEP MODE */
2766        if (*uwrq == 0 || *uwrq == 1)
2767                priv->wps.wps_enabled = *uwrq;
2768        else
2769                return -EINVAL;
2770
2771        hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2772
2773        return 0;
2774}
2775
2776/*------------------------------------------------------------------*/
2777/* Private handler : get WPS enable */
2778static int ks_wlan_get_wps_enable(struct net_device *dev,
2779                                  struct iw_request_info *info, __u32 * uwrq,
2780                                  char *extra)
2781{
2782        struct ks_wlan_private *priv =
2783            (struct ks_wlan_private *)netdev_priv(dev);
2784        DPRINTK(2, "\n");
2785
2786        if (priv->sleep_mode == SLP_SLEEP) {
2787                return -EPERM;
2788        }
2789        /* for SLEEP MODE */
2790        *uwrq = priv->wps.wps_enabled;
2791        printk("return=%d\n", *uwrq);
2792
2793        return 0;
2794}
2795
2796/*------------------------------------------------------------------*/
2797/* Private handler : set WPS probe req */
2798static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2799                                     struct iw_request_info *info,
2800                                     struct iw_point *dwrq, char *extra)
2801{
2802        uint8_t *p = extra;
2803        unsigned char len;
2804        struct ks_wlan_private *priv =
2805            (struct ks_wlan_private *)netdev_priv(dev);
2806
2807        DPRINTK(2, "\n");
2808
2809        if (priv->sleep_mode == SLP_SLEEP) {
2810                return -EPERM;
2811        }
2812        /* for SLEEP MODE */
2813        DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2814
2815        /* length check */
2816        if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2817                return -EINVAL;
2818        }
2819
2820        priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2821        len = p[1] + 2; /* IE header + IE */
2822
2823        memcpy(priv->wps.ie, &len, sizeof(len));
2824        p = memcpy(priv->wps.ie + 1, p, len);
2825
2826        DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2827                priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2828                p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2829                p[priv->wps.ielen - 1]);
2830
2831        hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2832
2833        return 0;
2834}
2835
2836#if 0
2837/*------------------------------------------------------------------*/
2838/* Private handler : get WPS probe req */
2839static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2840                                     struct iw_request_info *info,
2841                                     __u32 * uwrq, char *extra)
2842{
2843        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2844        DPRINTK(2, "\n");
2845
2846        if (priv->sleep_mode == SLP_SLEEP) {
2847                return -EPERM;
2848        }
2849        /* for SLEEP MODE */
2850        return 0;
2851}
2852#endif
2853#endif /* WPS */
2854
2855/*------------------------------------------------------------------*/
2856/* Private handler : set tx gain control value */
2857static int ks_wlan_set_tx_gain(struct net_device *dev,
2858                               struct iw_request_info *info, __u32 * uwrq,
2859                               char *extra)
2860{
2861        struct ks_wlan_private *priv =
2862            (struct ks_wlan_private *)netdev_priv(dev);
2863
2864        if (priv->sleep_mode == SLP_SLEEP) {
2865                return -EPERM;
2866        }
2867        /* for SLEEP MODE */
2868        if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2869                priv->gain.TxGain = (uint8_t) * uwrq;
2870        else
2871                return -EINVAL;
2872
2873        if (priv->gain.TxGain < 0xFF)
2874                priv->gain.TxMode = 1;
2875        else
2876                priv->gain.TxMode = 0;
2877
2878        hostif_sme_enqueue(priv, SME_SET_GAIN);
2879        return 0;
2880}
2881
2882/*------------------------------------------------------------------*/
2883/* Private handler : get tx gain control value */
2884static int ks_wlan_get_tx_gain(struct net_device *dev,
2885                               struct iw_request_info *info, __u32 * uwrq,
2886                               char *extra)
2887{
2888        struct ks_wlan_private *priv =
2889            (struct ks_wlan_private *)netdev_priv(dev);
2890
2891        if (priv->sleep_mode == SLP_SLEEP) {
2892                return -EPERM;
2893        }
2894        /* for SLEEP MODE */
2895        *uwrq = priv->gain.TxGain;
2896        hostif_sme_enqueue(priv, SME_GET_GAIN);
2897        return 0;
2898}
2899
2900/*------------------------------------------------------------------*/
2901/* Private handler : set rx gain control value */
2902static int ks_wlan_set_rx_gain(struct net_device *dev,
2903                               struct iw_request_info *info, __u32 * uwrq,
2904                               char *extra)
2905{
2906        struct ks_wlan_private *priv =
2907            (struct ks_wlan_private *)netdev_priv(dev);
2908
2909        if (priv->sleep_mode == SLP_SLEEP) {
2910                return -EPERM;
2911        }
2912        /* for SLEEP MODE */
2913        if (*uwrq >= 0 && *uwrq <= 0xFF)        /* 0-255 */
2914                priv->gain.RxGain = (uint8_t) * uwrq;
2915        else
2916                return -EINVAL;
2917
2918        if (priv->gain.RxGain < 0xFF)
2919                priv->gain.RxMode = 1;
2920        else
2921                priv->gain.RxMode = 0;
2922
2923        hostif_sme_enqueue(priv, SME_SET_GAIN);
2924        return 0;
2925}
2926
2927/*------------------------------------------------------------------*/
2928/* Private handler : get rx gain control value */
2929static int ks_wlan_get_rx_gain(struct net_device *dev,
2930                               struct iw_request_info *info, __u32 * uwrq,
2931                               char *extra)
2932{
2933        struct ks_wlan_private *priv =
2934            (struct ks_wlan_private *)netdev_priv(dev);
2935
2936        if (priv->sleep_mode == SLP_SLEEP) {
2937                return -EPERM;
2938        }
2939        /* for SLEEP MODE */
2940        *uwrq = priv->gain.RxGain;
2941        hostif_sme_enqueue(priv, SME_GET_GAIN);
2942        return 0;
2943}
2944
2945#if 0
2946/*------------------------------------------------------------------*/
2947/* Private handler : set region value */
2948static int ks_wlan_set_region(struct net_device *dev,
2949                              struct iw_request_info *info, __u32 * uwrq,
2950                              char *extra)
2951{
2952        struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2953
2954        if (priv->sleep_mode == SLP_SLEEP) {
2955                return -EPERM;
2956        }
2957        /* for SLEEP MODE */
2958        if (*uwrq >= 0x9 && *uwrq <= 0xF)       /* 0x9-0xf */
2959                priv->region = (uint8_t) * uwrq;
2960        else
2961                return -EINVAL;
2962
2963        hostif_sme_enqueue(priv, SME_SET_REGION);
2964        return 0;
2965}
2966#endif
2967
2968/*------------------------------------------------------------------*/
2969/* Private handler : get eeprom checksum result */
2970static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2971                                    struct iw_request_info *info, __u32 * uwrq,
2972                                    char *extra)
2973{
2974        struct ks_wlan_private *priv =
2975            (struct ks_wlan_private *)netdev_priv(dev);
2976
2977        *uwrq = priv->eeprom_checksum;
2978        return 0;
2979}
2980
2981static void print_hif_event(int event)
2982{
2983
2984        switch (event) {
2985        case HIF_DATA_REQ:
2986                printk("HIF_DATA_REQ\n");
2987                break;
2988        case HIF_DATA_IND:
2989                printk("HIF_DATA_IND\n");
2990                break;
2991        case HIF_MIB_GET_REQ:
2992                printk("HIF_MIB_GET_REQ\n");
2993                break;
2994        case HIF_MIB_GET_CONF:
2995                printk("HIF_MIB_GET_CONF\n");
2996                break;
2997        case HIF_MIB_SET_REQ:
2998                printk("HIF_MIB_SET_REQ\n");
2999                break;
3000        case HIF_MIB_SET_CONF:
3001                printk("HIF_MIB_SET_CONF\n");
3002                break;
3003        case HIF_POWERMGT_REQ:
3004                printk("HIF_POWERMGT_REQ\n");
3005                break;
3006        case HIF_POWERMGT_CONF:
3007                printk("HIF_POWERMGT_CONF\n");
3008                break;
3009        case HIF_START_REQ:
3010                printk("HIF_START_REQ\n");
3011                break;
3012        case HIF_START_CONF:
3013                printk("HIF_START_CONF\n");
3014                break;
3015        case HIF_CONNECT_IND:
3016                printk("HIF_CONNECT_IND\n");
3017                break;
3018        case HIF_STOP_REQ:
3019                printk("HIF_STOP_REQ\n");
3020                break;
3021        case HIF_STOP_CONF:
3022                printk("HIF_STOP_CONF\n");
3023                break;
3024        case HIF_PS_ADH_SET_REQ:
3025                printk("HIF_PS_ADH_SET_REQ\n");
3026                break;
3027        case HIF_PS_ADH_SET_CONF:
3028                printk("HIF_PS_ADH_SET_CONF\n");
3029                break;
3030        case HIF_INFRA_SET_REQ:
3031                printk("HIF_INFRA_SET_REQ\n");
3032                break;
3033        case HIF_INFRA_SET_CONF:
3034                printk("HIF_INFRA_SET_CONF\n");
3035                break;
3036        case HIF_ADH_SET_REQ:
3037                printk("HIF_ADH_SET_REQ\n");
3038                break;
3039        case HIF_ADH_SET_CONF:
3040                printk("HIF_ADH_SET_CONF\n");
3041                break;
3042        case HIF_AP_SET_REQ:
3043                printk("HIF_AP_SET_REQ\n");
3044                break;
3045        case HIF_AP_SET_CONF:
3046                printk("HIF_AP_SET_CONF\n");
3047                break;
3048        case HIF_ASSOC_INFO_IND:
3049                printk("HIF_ASSOC_INFO_IND\n");
3050                break;
3051        case HIF_MIC_FAILURE_REQ:
3052                printk("HIF_MIC_FAILURE_REQ\n");
3053                break;
3054        case HIF_MIC_FAILURE_CONF:
3055                printk("HIF_MIC_FAILURE_CONF\n");
3056                break;
3057        case HIF_SCAN_REQ:
3058                printk("HIF_SCAN_REQ\n");
3059                break;
3060        case HIF_SCAN_CONF:
3061                printk("HIF_SCAN_CONF\n");
3062                break;
3063        case HIF_PHY_INFO_REQ:
3064                printk("HIF_PHY_INFO_REQ\n");
3065                break;
3066        case HIF_PHY_INFO_CONF:
3067                printk("HIF_PHY_INFO_CONF\n");
3068                break;
3069        case HIF_SLEEP_REQ:
3070                printk("HIF_SLEEP_REQ\n");
3071                break;
3072        case HIF_SLEEP_CONF:
3073                printk("HIF_SLEEP_CONF\n");
3074                break;
3075        case HIF_PHY_INFO_IND:
3076                printk("HIF_PHY_INFO_IND\n");
3077                break;
3078        case HIF_SCAN_IND:
3079                printk("HIF_SCAN_IND\n");
3080                break;
3081        case HIF_INFRA_SET2_REQ:
3082                printk("HIF_INFRA_SET2_REQ\n");
3083                break;
3084        case HIF_INFRA_SET2_CONF:
3085                printk("HIF_INFRA_SET2_CONF\n");
3086                break;
3087        case HIF_ADH_SET2_REQ:
3088                printk("HIF_ADH_SET2_REQ\n");
3089                break;
3090        case HIF_ADH_SET2_CONF:
3091                printk("HIF_ADH_SET2_CONF\n");
3092        }
3093}
3094
3095/*------------------------------------------------------------------*/
3096/* Private handler : get host command history */
3097static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3098                         __u32 * uwrq, char *extra)
3099{
3100        int i, event;
3101        struct ks_wlan_private *priv =
3102            (struct ks_wlan_private *)netdev_priv(dev);
3103
3104        for (i = 63; i >= 0; i--) {
3105                event =
3106                    priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3107                                     SME_EVENT_BUFF_SIZE];
3108                print_hif_event(event);
3109        }
3110        return 0;
3111}
3112
3113/* Structures to export the Wireless Handlers */
3114
3115static const struct iw_priv_args ks_wlan_private_args[] = {
3116/*{ cmd, set_args, get_args, name[16] } */
3117        {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3118         IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3119#ifdef WPS
3120        {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3121         IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3122        {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3123         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3124        {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3125         "SetWPSProbeReq"},
3126#endif /* WPS */
3127        {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3128         IW_PRIV_TYPE_NONE, "SetPreamble"},
3129        {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3130         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3131        {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3132         IW_PRIV_TYPE_NONE, "SetPowerSave"},
3133        {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3134         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3135        {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3136         IW_PRIV_TYPE_NONE, "SetScanType"},
3137        {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3138         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3139        {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3140         IW_PRIV_TYPE_NONE, "SetRxGain"},
3141        {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3142         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3143        {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3144         "hostt"},
3145        {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3146         IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3147        {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3148         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3149        {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3150         IW_PRIV_TYPE_NONE, "SetSleepMode"},
3151        {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3152         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3153        {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3154         IW_PRIV_TYPE_NONE, "SetTxGain"},
3155        {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3156         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3157        {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3158         IW_PRIV_TYPE_NONE, "SetPhyType"},
3159        {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3160         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3161        {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3162         IW_PRIV_TYPE_NONE, "SetCtsMode"},
3163        {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3164         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3165        {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3166         IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3167};
3168
3169static const iw_handler ks_wlan_handler[] = {
3170        (iw_handler) ks_wlan_config_commit,     /* SIOCSIWCOMMIT */
3171        (iw_handler) ks_wlan_get_name,  /* SIOCGIWNAME */
3172        (iw_handler) NULL,      /* SIOCSIWNWID */
3173        (iw_handler) NULL,      /* SIOCGIWNWID */
3174        (iw_handler) ks_wlan_set_freq,  /* SIOCSIWFREQ */
3175        (iw_handler) ks_wlan_get_freq,  /* SIOCGIWFREQ */
3176        (iw_handler) ks_wlan_set_mode,  /* SIOCSIWMODE */
3177        (iw_handler) ks_wlan_get_mode,  /* SIOCGIWMODE */
3178#ifndef KSC_OPNOTSUPP
3179        (iw_handler) ks_wlan_set_sens,  /* SIOCSIWSENS */
3180        (iw_handler) ks_wlan_get_sens,  /* SIOCGIWSENS */
3181#else /* KSC_OPNOTSUPP */
3182        (iw_handler) NULL,      /* SIOCSIWSENS */
3183        (iw_handler) NULL,      /* SIOCGIWSENS */
3184#endif /* KSC_OPNOTSUPP */
3185        (iw_handler) NULL,      /* SIOCSIWRANGE */
3186        (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3187        (iw_handler) NULL,      /* SIOCSIWPRIV */
3188        (iw_handler) NULL,      /* SIOCGIWPRIV */
3189        (iw_handler) NULL,      /* SIOCSIWSTATS */
3190        (iw_handler) ks_wlan_get_iwstats,       /* SIOCGIWSTATS */
3191        (iw_handler) NULL,      /* SIOCSIWSPY */
3192        (iw_handler) NULL,      /* SIOCGIWSPY */
3193        (iw_handler) NULL,      /* SIOCSIWTHRSPY */
3194        (iw_handler) NULL,      /* SIOCGIWTHRSPY */
3195        (iw_handler) ks_wlan_set_wap,   /* SIOCSIWAP */
3196        (iw_handler) ks_wlan_get_wap,   /* SIOCGIWAP */
3197//      (iw_handler) NULL,                      /* SIOCSIWMLME */
3198        (iw_handler) ks_wlan_set_mlme,  /* SIOCSIWMLME */
3199        (iw_handler) ks_wlan_get_aplist,        /* SIOCGIWAPLIST */
3200        (iw_handler) ks_wlan_set_scan,  /* SIOCSIWSCAN */
3201        (iw_handler) ks_wlan_get_scan,  /* SIOCGIWSCAN */
3202        (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3203        (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3204        (iw_handler) ks_wlan_set_nick,  /* SIOCSIWNICKN */
3205        (iw_handler) ks_wlan_get_nick,  /* SIOCGIWNICKN */
3206        (iw_handler) NULL,      /* -- hole -- */
3207        (iw_handler) NULL,      /* -- hole -- */
3208        (iw_handler) ks_wlan_set_rate,  /* SIOCSIWRATE */
3209        (iw_handler) ks_wlan_get_rate,  /* SIOCGIWRATE */
3210        (iw_handler) ks_wlan_set_rts,   /* SIOCSIWRTS */
3211        (iw_handler) ks_wlan_get_rts,   /* SIOCGIWRTS */
3212        (iw_handler) ks_wlan_set_frag,  /* SIOCSIWFRAG */
3213        (iw_handler) ks_wlan_get_frag,  /* SIOCGIWFRAG */
3214#ifndef KSC_OPNOTSUPP
3215        (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3216        (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3217        (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3218        (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3219#else /* KSC_OPNOTSUPP */
3220        (iw_handler) NULL,      /* SIOCSIWTXPOW */
3221        (iw_handler) NULL,      /* SIOCGIWTXPOW */
3222        (iw_handler) NULL,      /* SIOCSIWRETRY */
3223        (iw_handler) NULL,      /* SIOCGIWRETRY */
3224#endif /* KSC_OPNOTSUPP */
3225        (iw_handler) ks_wlan_set_encode,        /* SIOCSIWENCODE */
3226        (iw_handler) ks_wlan_get_encode,        /* SIOCGIWENCODE */
3227        (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3228        (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3229        (iw_handler) NULL,      /* -- hole -- */
3230        (iw_handler) NULL,      /* -- hole -- */
3231//      (iw_handler) NULL,                      /* SIOCSIWGENIE */
3232        (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3233        (iw_handler) NULL,      /* SIOCGIWGENIE */
3234        (iw_handler) ks_wlan_set_auth_mode,     /* SIOCSIWAUTH */
3235        (iw_handler) ks_wlan_get_auth_mode,     /* SIOCGIWAUTH */
3236        (iw_handler) ks_wlan_set_encode_ext,    /* SIOCSIWENCODEEXT */
3237        (iw_handler) ks_wlan_get_encode_ext,    /* SIOCGIWENCODEEXT */
3238        (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3239        (iw_handler) NULL,      /* -- hole -- */
3240};
3241
3242/* private_handler */
3243static const iw_handler ks_wlan_private_handler[] = {
3244        (iw_handler) NULL,      /*  0 */
3245        (iw_handler) NULL,      /*  1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3246        (iw_handler) NULL,      /*  2 */
3247        (iw_handler) ks_wlan_get_firmware_version,      /*  3 KS_WLAN_GET_FIRM_VERSION */
3248#ifdef WPS
3249        (iw_handler) ks_wlan_set_wps_enable,    /*  4 KS_WLAN_SET_WPS_ENABLE  */
3250        (iw_handler) ks_wlan_get_wps_enable,    /*  5 KS_WLAN_GET_WPS_ENABLE  */
3251        (iw_handler) ks_wlan_set_wps_probe_req, /*  6 KS_WLAN_SET_WPS_PROBE_REQ */
3252#else
3253        (iw_handler) NULL,      /*  4 */
3254        (iw_handler) NULL,      /*  5 */
3255        (iw_handler) NULL,      /*  6 */
3256#endif /* WPS */
3257
3258        (iw_handler) ks_wlan_get_eeprom_cksum,  /*  7 KS_WLAN_GET_CONNECT */
3259        (iw_handler) ks_wlan_set_preamble,      /*  8 KS_WLAN_SET_PREAMBLE */
3260        (iw_handler) ks_wlan_get_preamble,      /*  9 KS_WLAN_GET_PREAMBLE */
3261        (iw_handler) ks_wlan_set_powermgt,      /* 10 KS_WLAN_SET_POWER_SAVE */
3262        (iw_handler) ks_wlan_get_powermgt,      /* 11 KS_WLAN_GET_POWER_SAVE */
3263        (iw_handler) ks_wlan_set_scan_type,     /* 12 KS_WLAN_SET_SCAN_TYPE */
3264        (iw_handler) ks_wlan_get_scan_type,     /* 13 KS_WLAN_GET_SCAN_TYPE */
3265        (iw_handler) ks_wlan_set_rx_gain,       /* 14 KS_WLAN_SET_RX_GAIN */
3266        (iw_handler) ks_wlan_get_rx_gain,       /* 15 KS_WLAN_GET_RX_GAIN */
3267        (iw_handler) ks_wlan_hostt,     /* 16 KS_WLAN_HOSTT */
3268        (iw_handler) NULL,      /* 17 */
3269        (iw_handler) ks_wlan_set_beacon_lost,   /* 18 KS_WLAN_SET_BECAN_LOST */
3270        (iw_handler) ks_wlan_get_beacon_lost,   /* 19 KS_WLAN_GET_BECAN_LOST */
3271        (iw_handler) ks_wlan_set_tx_gain,       /* 20 KS_WLAN_SET_TX_GAIN */
3272        (iw_handler) ks_wlan_get_tx_gain,       /* 21 KS_WLAN_GET_TX_GAIN */
3273        (iw_handler) ks_wlan_set_phy_type,      /* 22 KS_WLAN_SET_PHY_TYPE */
3274        (iw_handler) ks_wlan_get_phy_type,      /* 23 KS_WLAN_GET_PHY_TYPE */
3275        (iw_handler) ks_wlan_set_cts_mode,      /* 24 KS_WLAN_SET_CTS_MODE */
3276        (iw_handler) ks_wlan_get_cts_mode,      /* 25 KS_WLAN_GET_CTS_MODE */
3277        (iw_handler) NULL,      /* 26 */
3278        (iw_handler) NULL,      /* 27 */
3279        (iw_handler) ks_wlan_set_sleep_mode,    /* 28 KS_WLAN_SET_SLEEP_MODE */
3280        (iw_handler) ks_wlan_get_sleep_mode,    /* 29 KS_WLAN_GET_SLEEP_MODE */
3281        (iw_handler) NULL,      /* 30 */
3282        (iw_handler) NULL,      /* 31 */
3283};
3284
3285static const struct iw_handler_def ks_wlan_handler_def = {
3286        .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3287        .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3288        .num_private_args =
3289            sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3290        .standard = (iw_handler *) ks_wlan_handler,
3291        .private = (iw_handler *) ks_wlan_private_handler,
3292        .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3293        .get_wireless_stats = ks_get_wireless_stats,
3294};
3295
3296static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3297                                int cmd)
3298{
3299        int rc = 0;
3300        struct iwreq *wrq = (struct iwreq *)rq;
3301        switch (cmd) {
3302        case SIOCIWFIRSTPRIV + 20:      /* KS_WLAN_SET_STOP_REQ */
3303                rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3304                break;
3305                // All other calls are currently unsupported
3306        default:
3307                rc = -EOPNOTSUPP;
3308        }
3309
3310        DPRINTK(5, "return=%d\n", rc);
3311        return rc;
3312}
3313
3314static
3315struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3316{
3317        struct ks_wlan_private *priv = netdev_priv(dev);
3318
3319        if (priv->dev_state < DEVICE_STATE_READY) {
3320                return NULL;    /* not finished initialize */
3321        }
3322
3323        return &priv->nstats;
3324}
3325
3326static
3327int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3328{
3329        struct ks_wlan_private *priv = netdev_priv(dev);
3330        struct sockaddr *mac_addr = (struct sockaddr *)addr;
3331        if (netif_running(dev))
3332                return -EBUSY;
3333        memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3334        memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3335
3336        priv->mac_address_valid = 0;
3337        hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3338        printk(KERN_INFO
3339               "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3340               priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3341               priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3342        return 0;
3343}
3344
3345static
3346void ks_wlan_tx_timeout(struct net_device *dev)
3347{
3348        struct ks_wlan_private *priv = netdev_priv(dev);
3349
3350        DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3351                priv->tx_dev.qtail);
3352        if (!netif_queue_stopped(dev)) {
3353                netif_stop_queue(dev);
3354        }
3355        priv->nstats.tx_errors++;
3356        netif_wake_queue(dev);
3357
3358        return;
3359}
3360
3361static
3362int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3363{
3364        struct ks_wlan_private *priv = netdev_priv(dev);
3365        int rc = 0;
3366
3367        DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3368
3369        if (skb == NULL) {
3370                printk(KERN_ERR "ks_wlan:  skb == NULL!!!\n");
3371                return 0;
3372        }
3373        if (priv->dev_state < DEVICE_STATE_READY) {
3374                dev_kfree_skb(skb);
3375                return 0;       /* not finished initialize */
3376        }
3377
3378        if (netif_running(dev))
3379                netif_stop_queue(dev);
3380
3381        rc = hostif_data_request(priv, skb);
3382        netif_trans_update(dev);
3383
3384        DPRINTK(4, "rc=%d\n", rc);
3385        if (rc) {
3386                rc = 0;
3387        }
3388
3389        return rc;
3390}
3391
3392void send_packet_complete(void *arg1, void *arg2)
3393{
3394        struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3395        struct sk_buff *packet = (struct sk_buff *)arg2;
3396
3397        DPRINTK(3, "\n");
3398
3399        priv->nstats.tx_bytes += packet->len;
3400        priv->nstats.tx_packets++;
3401
3402        if (netif_queue_stopped(priv->net_dev))
3403                netif_wake_queue(priv->net_dev);
3404
3405        if (packet) {
3406                dev_kfree_skb(packet);
3407                packet = NULL;
3408        }
3409
3410}
3411
3412/* Set or clear the multicast filter for this adaptor.
3413   This routine is not state sensitive and need not be SMP locked. */
3414static
3415void ks_wlan_set_multicast_list(struct net_device *dev)
3416{
3417        struct ks_wlan_private *priv = netdev_priv(dev);
3418
3419        DPRINTK(4, "\n");
3420        if (priv->dev_state < DEVICE_STATE_READY) {
3421                return; /* not finished initialize */
3422        }
3423        hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3424
3425        return;
3426}
3427
3428static
3429int ks_wlan_open(struct net_device *dev)
3430{
3431        struct ks_wlan_private *priv = netdev_priv(dev);
3432
3433        priv->cur_rx = 0;
3434
3435        if (!priv->mac_address_valid) {
3436                printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3437                return -EBUSY;
3438        } else
3439                netif_start_queue(dev);
3440
3441        return 0;
3442}
3443
3444static
3445int ks_wlan_close(struct net_device *dev)
3446{
3447
3448        netif_stop_queue(dev);
3449
3450        DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3451                dev->name, 0x00);
3452
3453        return 0;
3454}
3455
3456/* Operational parameters that usually are not changed. */
3457/* Time in jiffies before concluding the transmitter is hung. */
3458#define TX_TIMEOUT  (3*HZ)
3459static const unsigned char dummy_addr[] =
3460    { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3461
3462static const struct net_device_ops ks_wlan_netdev_ops = {
3463        .ndo_start_xmit = ks_wlan_start_xmit,
3464        .ndo_open = ks_wlan_open,
3465        .ndo_stop = ks_wlan_close,
3466        .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3467        .ndo_set_mac_address = ks_wlan_set_mac_address,
3468        .ndo_get_stats = ks_wlan_get_stats,
3469        .ndo_tx_timeout = ks_wlan_tx_timeout,
3470        .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3471};
3472
3473int ks_wlan_net_start(struct net_device *dev)
3474{
3475        struct ks_wlan_private *priv;
3476        /* int rc; */
3477
3478        priv = netdev_priv(dev);
3479        priv->mac_address_valid = 0;
3480        priv->need_commit = 0;
3481
3482        priv->device_open_status = 1;
3483
3484        /* phy information update timer */
3485        atomic_set(&update_phyinfo, 0);
3486        init_timer(&update_phyinfo_timer);
3487        update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3488        update_phyinfo_timer.data = (unsigned long)priv;
3489
3490        /* dummy address set */
3491        memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3492        dev->dev_addr[0] = priv->eth_addr[0];
3493        dev->dev_addr[1] = priv->eth_addr[1];
3494        dev->dev_addr[2] = priv->eth_addr[2];
3495        dev->dev_addr[3] = priv->eth_addr[3];
3496        dev->dev_addr[4] = priv->eth_addr[4];
3497        dev->dev_addr[5] = priv->eth_addr[5];
3498        dev->dev_addr[6] = 0x00;
3499        dev->dev_addr[7] = 0x00;
3500
3501        /* The ks_wlan-specific entries in the device structure. */
3502        dev->netdev_ops = &ks_wlan_netdev_ops;
3503        dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3504        dev->watchdog_timeo = TX_TIMEOUT;
3505
3506        netif_carrier_off(dev);
3507
3508        return 0;
3509}
3510
3511int ks_wlan_net_stop(struct net_device *dev)
3512{
3513        struct ks_wlan_private *priv = netdev_priv(dev);
3514
3515        int ret = 0;
3516        priv->device_open_status = 0;
3517        del_timer_sync(&update_phyinfo_timer);
3518
3519        if (netif_running(dev))
3520                netif_stop_queue(dev);
3521
3522        return ret;
3523}
3524
3525int ks_wlan_reset(struct net_device *dev)
3526{
3527        return 0;
3528}
3529