linux/drivers/staging/otus/ioctl.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2007-2008 Atheros Communications Inc.
   3 *
   4 * Permission to use, copy, modify, and/or distribute this software for any
   5 * purpose with or without fee is hereby granted, provided that the above
   6 * copyright notice and this permission notice appear in all copies.
   7 *
   8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15 */
  16/*                                                                      */
  17/*  Module Name : ioctl.c                                               */
  18/*                                                                      */
  19/*  Abstract                                                            */
  20/*      This module contains Linux wireless extension related functons. */
  21/*                                                                      */
  22/*  NOTES                                                               */
  23/*     Platform dependent.                                              */
  24/*                                                                      */
  25/************************************************************************/
  26#include <linux/module.h>
  27#include <linux/if_arp.h>
  28#include <linux/uaccess.h>
  29
  30#include "usbdrv.h"
  31
  32#define ZD_IOCTL_WPA                        (SIOCDEVPRIVATE + 1)
  33#define ZD_IOCTL_PARAM                      (SIOCDEVPRIVATE + 2)
  34#define ZD_IOCTL_GETWPAIE                   (SIOCDEVPRIVATE + 3)
  35#ifdef ZM_ENABLE_CENC
  36#define ZM_IOCTL_CENC               (SIOCDEVPRIVATE + 4)
  37#endif  /* ZM_ENABLE_CENC */
  38#define ZD_PARAM_ROAMING                    0x0001
  39#define ZD_PARAM_PRIVACY                    0x0002
  40#define ZD_PARAM_WPA                        0x0003
  41#define ZD_PARAM_COUNTERMEASURES        0x0004
  42#define ZD_PARAM_DROPUNENCRYPTED        0x0005
  43#define ZD_PARAM_AUTH_ALGS                  0x0006
  44#define ZD_PARAM_WPS_FILTER                 0x0007
  45
  46#ifdef ZM_ENABLE_CENC
  47#define P80211_PACKET_CENCFLAG          0x0001
  48#endif  /* ZM_ENABLE_CENC */
  49#define P80211_PACKET_SETKEY            0x0003
  50
  51#define ZD_CMD_SET_ENCRYPT_KEY          0x0001
  52#define ZD_CMD_SET_MLME                     0x0002
  53#define ZD_CMD_SCAN_REQ                     0x0003
  54#define ZD_CMD_SET_GENERIC_ELEMENT      0x0004
  55#define ZD_CMD_GET_TSC                      0x0005
  56
  57#define ZD_CRYPT_ALG_NAME_LEN           16
  58#define ZD_MAX_KEY_SIZE                     32
  59#define ZD_MAX_GENERIC_SIZE                 64
  60
  61#include <net/iw_handler.h>
  62
  63extern u16_t zfLnxGetVapId(zdev_t *dev);
  64
  65static const u32_t channel_frequency_11A[] =
  66{
  67        /* Even element for Channel Number, Odd for Frequency */
  68        36, 5180,
  69        40, 5200,
  70        44, 5220,
  71        48, 5240,
  72        52, 5260,
  73        56, 5280,
  74        60, 5300,
  75        64, 5320,
  76        100, 5500,
  77        104, 5520,
  78        108, 5540,
  79        112, 5560,
  80        116, 5580,
  81        120, 5600,
  82        124, 5620,
  83        128, 5640,
  84        132, 5660,
  85        136, 5680,
  86        140, 5700,
  87        /**/
  88        184, 4920,
  89        188, 4940,
  90        192, 4960,
  91        196, 4980,
  92        8, 5040,
  93        12, 5060,
  94        16, 5080,
  95        34, 5170,
  96        38, 5190,
  97        42, 5210,
  98        46, 5230,
  99        /**/
 100        149, 5745,
 101        153, 5765,
 102        157, 5785,
 103        161, 5805,
 104        165, 5825
 105        /**/
 106};
 107
 108int usbdrv_freq2chan(u32_t freq)
 109{
 110        /* 2.4G Hz */
 111        if (freq > 2400 && freq < 3000) {
 112                return ((freq-2412)/5) + 1;
 113        } else {
 114                u16_t ii;
 115                u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
 116
 117                for (ii = 1; ii < num_chan; ii += 2) {
 118                        if (channel_frequency_11A[ii] == freq)
 119                                return channel_frequency_11A[ii-1];
 120                }
 121        }
 122
 123        return 0;
 124}
 125
 126int usbdrv_chan2freq(int chan)
 127{
 128        int freq;
 129
 130        /* If channel number is out of range */
 131        if (chan > 165 || chan <= 0)
 132                return -1;
 133
 134        /* 2.4G band */
 135        if (chan >= 1 && chan <= 13) {
 136                freq = (2412 + (chan - 1) * 5);
 137                        return freq;
 138        } else if (chan >= 36 && chan <= 165) {
 139                u16_t ii;
 140                u16_t num_chan = sizeof(channel_frequency_11A)/sizeof(u32_t);
 141
 142                for (ii = 0; ii < num_chan; ii += 2) {
 143                        if (channel_frequency_11A[ii] == chan)
 144                                return channel_frequency_11A[ii+1];
 145                }
 146
 147        /* Can't find desired frequency */
 148        if (ii == num_chan)
 149                return -1;
 150        }
 151
 152        /* Can't find deisred frequency */
 153        return -1;
 154}
 155
 156int usbdrv_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
 157{
 158        #ifdef ZM_HOSTAPD_SUPPORT
 159        /* struct usbdrv_private *macp = dev->ml_priv; */
 160        char essidbuf[IW_ESSID_MAX_SIZE+1];
 161        int i;
 162
 163        if (!netif_running(dev))
 164                return -EINVAL;
 165
 166        memset(essidbuf, 0, sizeof(essidbuf));
 167
 168        printk(KERN_ERR "usbdrv_ioctl_setessid\n");
 169
 170        /* printk("ssidlen=%d\n", erq->length); //for any, it is 1. */
 171        if (erq->flags) {
 172                if (erq->length > (IW_ESSID_MAX_SIZE+1))
 173                        return -E2BIG;
 174
 175                if (copy_from_user(essidbuf, erq->pointer, erq->length))
 176                        return -EFAULT;
 177        }
 178
 179        /* zd_DisasocAll(2); */
 180        /* wait_ms(100); */
 181
 182        printk(KERN_ERR "essidbuf: ");
 183
 184        for (i = 0; i < erq->length; i++)
 185                printk(KERN_ERR "%02x ", essidbuf[i]);
 186
 187        printk(KERN_ERR "\n");
 188
 189        essidbuf[erq->length] = '\0';
 190        /* memcpy(macp->wd.ws.ssid, essidbuf, erq->length); */
 191        /* macp->wd.ws.ssidLen = strlen(essidbuf)+2; */
 192        /* macp->wd.ws.ssid[1] = strlen(essidbuf); Update ssid length */
 193
 194        zfiWlanSetSSID(dev, essidbuf, erq->length);
 195        #if 0
 196                printk(KERN_ERR "macp->wd.ws.ssid: ");
 197
 198                for (i = 0; i < macp->wd.ws.ssidLen; i++)
 199                        printk(KERN_ERR "%02x ", macp->wd.ws.ssid[i]);
 200
 201                printk(KERN_ERR "\n");
 202        #endif
 203
 204        zfiWlanDisable(dev, 0);
 205        zfiWlanEnable(dev);
 206
 207        #endif
 208
 209        return 0;
 210}
 211
 212int usbdrv_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
 213{
 214        /* struct usbdrv_private *macp = dev->ml_priv; */
 215        u8_t essidbuf[IW_ESSID_MAX_SIZE+1];
 216        u8_t len;
 217        u8_t i;
 218
 219
 220        /* len = macp->wd.ws.ssidLen; */
 221        /* memcpy(essidbuf, macp->wd.ws.ssid, macp->wd.ws.ssidLen); */
 222        zfiWlanQuerySSID(dev, essidbuf, &len);
 223
 224        essidbuf[len] = 0;
 225
 226        printk(KERN_ERR "ESSID: ");
 227
 228        for (i = 0; i < len; i++)
 229                printk(KERN_ERR "%c", essidbuf[i]);
 230
 231        printk(KERN_ERR "\n");
 232
 233        erq->flags = 1;
 234        erq->length = strlen(essidbuf) + 1;
 235
 236        if (erq->pointer) {
 237                if (copy_to_user(erq->pointer, essidbuf, erq->length))
 238                        return -EFAULT;
 239        }
 240
 241        return 0;
 242}
 243
 244int usbdrv_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
 245{
 246        return 0;
 247}
 248
 249/*
 250 * Encode a WPA or RSN information element as a custom
 251 * element using the hostap format.
 252 */
 253u32 encode_ie(void *buf, u32 bufsize, const u8 *ie, u32 ielen,
 254                const u8 *leader, u32 leader_len)
 255{
 256        u8 *p;
 257        u32 i;
 258
 259        if (bufsize < leader_len)
 260                return 0;
 261        p = buf;
 262        memcpy(p, leader, leader_len);
 263        bufsize -= leader_len;
 264        p += leader_len;
 265        for (i = 0; i < ielen && bufsize > 2; i++)
 266                p += sprintf(p, "%02x", ie[i]);
 267        return (i == ielen ? p - (u8 *)buf:0);
 268}
 269
 270/*
 271 * Translate scan data returned from the card to a card independent
 272 * format that the Wireless Tools will understand
 273 */
 274char *usbdrv_translate_scan(struct net_device *dev,
 275        struct iw_request_info *info, char *current_ev,
 276        char *end_buf, struct zsBssInfo *list)
 277{
 278        struct iw_event iwe;   /* Temporary buffer */
 279        u16_t capabilities;
 280        char *current_val;     /* For rates */
 281        char *last_ev;
 282        int i;
 283        char    buf[64*2 + 30];
 284
 285        last_ev = current_ev;
 286
 287        /* First entry *MUST* be the AP MAC address */
 288        iwe.cmd = SIOCGIWAP;
 289        iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
 290        memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
 291        current_ev = iwe_stream_add_event(info, current_ev,
 292                                        end_buf, &iwe, IW_EV_ADDR_LEN);
 293
 294        /* Ran out of buffer */
 295        if (last_ev == current_ev)
 296                return end_buf;
 297
 298        last_ev = current_ev;
 299
 300        /* Other entries will be displayed in the order we give them */
 301
 302        /* Add the ESSID */
 303        iwe.u.data.length = list->ssid[1];
 304        if (iwe.u.data.length > 32)
 305                iwe.u.data.length = 32;
 306        iwe.cmd = SIOCGIWESSID;
 307        iwe.u.data.flags = 1;
 308        current_ev = iwe_stream_add_point(info, current_ev,
 309                                        end_buf, &iwe, &list->ssid[2]);
 310
 311        /* Ran out of buffer */
 312        if (last_ev == current_ev)
 313                return end_buf;
 314
 315        last_ev = current_ev;
 316
 317        /* Add mode */
 318        iwe.cmd = SIOCGIWMODE;
 319        capabilities = (list->capability[1] << 8) + list->capability[0];
 320        if (capabilities & (0x01 | 0x02)) {
 321                if (capabilities & 0x01)
 322                        iwe.u.mode = IW_MODE_MASTER;
 323                else
 324                        iwe.u.mode = IW_MODE_ADHOC;
 325                        current_ev = iwe_stream_add_event(info, current_ev,
 326                                                end_buf, &iwe, IW_EV_UINT_LEN);
 327        }
 328
 329        /* Ran out of buffer */
 330        if (last_ev == current_ev)
 331                return end_buf;
 332
 333        last_ev = current_ev;
 334
 335        /* Add frequency */
 336        iwe.cmd = SIOCGIWFREQ;
 337        iwe.u.freq.m = list->channel;
 338        /* Channel frequency in KHz */
 339        if (iwe.u.freq.m > 14) {
 340                if ((184 <= iwe.u.freq.m) && (iwe.u.freq.m <= 196))
 341                        iwe.u.freq.m = 4000 + iwe.u.freq.m * 5;
 342                else
 343                        iwe.u.freq.m = 5000 + iwe.u.freq.m * 5;
 344        } else {
 345                if (iwe.u.freq.m == 14)
 346                        iwe.u.freq.m = 2484;
 347                else
 348                        iwe.u.freq.m = 2412 + (iwe.u.freq.m - 1) * 5;
 349        }
 350        iwe.u.freq.e = 6;
 351        current_ev = iwe_stream_add_event(info, current_ev,
 352                                        end_buf, &iwe, IW_EV_FREQ_LEN);
 353
 354        /* Ran out of buffer */
 355        if (last_ev == current_ev)
 356                return end_buf;
 357
 358        last_ev = current_ev;
 359
 360        /* Add quality statistics */
 361        iwe.cmd = IWEVQUAL;
 362        iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED
 363                                | IW_QUAL_NOISE_UPDATED;
 364        iwe.u.qual.level = list->signalStrength;
 365        iwe.u.qual.noise = 0;
 366        iwe.u.qual.qual = list->signalQuality;
 367        current_ev = iwe_stream_add_event(info, current_ev,
 368                                        end_buf, &iwe, IW_EV_QUAL_LEN);
 369
 370        /* Ran out of buffer */
 371        if (last_ev == current_ev)
 372                return end_buf;
 373
 374        last_ev = current_ev;
 375
 376        /* Add encryption capability */
 377
 378        iwe.cmd = SIOCGIWENCODE;
 379        if (capabilities & 0x10)
 380                iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
 381        else
 382                iwe.u.data.flags = IW_ENCODE_DISABLED;
 383
 384        iwe.u.data.length = 0;
 385        current_ev = iwe_stream_add_point(info, current_ev,
 386                                        end_buf, &iwe, list->ssid);
 387
 388        /* Ran out of buffer */
 389        if (last_ev == current_ev)
 390                return end_buf;
 391
 392        last_ev = current_ev;
 393
 394        /* Rate : stuffing multiple values in a single event require a bit
 395        * more of magic
 396        */
 397        current_val = current_ev + IW_EV_LCP_LEN;
 398
 399        iwe.cmd = SIOCGIWRATE;
 400        /* Those two flags are ignored... */
 401        iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
 402
 403        for (i = 0 ; i < list->supportedRates[1] ; i++) {
 404                /* Bit rate given in 500 kb/s units (+ 0x80) */
 405                iwe.u.bitrate.value = ((list->supportedRates[i+2] & 0x7f)
 406                                        * 500000);
 407                /* Add new value to event */
 408                current_val = iwe_stream_add_value(info, current_ev,
 409                                current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
 410
 411                /* Ran out of buffer */
 412                if (last_ev == current_val)
 413                        return end_buf;
 414
 415                last_ev = current_val;
 416        }
 417
 418        for (i = 0 ; i < list->extSupportedRates[1] ; i++) {
 419                /* Bit rate given in 500 kb/s units (+ 0x80) */
 420                iwe.u.bitrate.value = ((list->extSupportedRates[i+2] & 0x7f)
 421                                        * 500000);
 422                /* Add new value to event */
 423                current_val = iwe_stream_add_value(info, current_ev,
 424                                current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
 425
 426                /* Ran out of buffer */
 427                if (last_ev == current_val)
 428                        return end_buf;
 429
 430                last_ev = current_ev;
 431        }
 432
 433        /* Check if we added any event */
 434        if ((current_val - current_ev) > IW_EV_LCP_LEN)
 435                current_ev = current_val;
 436                #define IEEE80211_ELEMID_RSN 0x30
 437        memset(&iwe, 0, sizeof(iwe));
 438        iwe.cmd = IWEVCUSTOM;
 439        snprintf(buf, sizeof(buf), "bcn_int=%d", (list->beaconInterval[1] << 8)
 440                                                + list->beaconInterval[0]);
 441        iwe.u.data.length = strlen(buf);
 442        current_ev = iwe_stream_add_point(info, current_ev,
 443                                                end_buf, &iwe, buf);
 444
 445        /* Ran out of buffer */
 446        if (last_ev == current_ev)
 447                return end_buf;
 448
 449        last_ev = current_ev;
 450
 451        if (list->wpaIe[1] != 0) {
 452                static const char rsn_leader[] = "rsn_ie=";
 453                static const char wpa_leader[] = "wpa_ie=";
 454
 455                memset(&iwe, 0, sizeof(iwe));
 456                iwe.cmd = IWEVCUSTOM;
 457                if (list->wpaIe[0] == IEEE80211_ELEMID_RSN)
 458                        iwe.u.data.length = encode_ie(buf, sizeof(buf),
 459                                        list->wpaIe, list->wpaIe[1]+2,
 460                                        rsn_leader, sizeof(rsn_leader)-1);
 461                else
 462                        iwe.u.data.length = encode_ie(buf, sizeof(buf),
 463                                        list->wpaIe, list->wpaIe[1]+2,
 464                                        wpa_leader, sizeof(wpa_leader)-1);
 465
 466                if (iwe.u.data.length != 0)
 467                        current_ev = iwe_stream_add_point(info, current_ev,
 468                                                        end_buf, &iwe, buf);
 469
 470                /* Ran out of buffer */
 471                if (last_ev == current_ev)
 472                        return end_buf;
 473
 474                last_ev = current_ev;
 475        }
 476
 477        if (list->rsnIe[1] != 0) {
 478                static const char rsn_leader[] = "rsn_ie=";
 479                memset(&iwe, 0, sizeof(iwe));
 480                iwe.cmd = IWEVCUSTOM;
 481
 482                if (list->rsnIe[0] == IEEE80211_ELEMID_RSN) {
 483                        iwe.u.data.length = encode_ie(buf, sizeof(buf),
 484                        list->rsnIe, list->rsnIe[1]+2,
 485                        rsn_leader, sizeof(rsn_leader)-1);
 486                        if (iwe.u.data.length != 0)
 487                                current_ev = iwe_stream_add_point(info,
 488                                        current_ev, end_buf,  &iwe, buf);
 489
 490                        /* Ran out of buffer */
 491                        if (last_ev == current_ev)
 492                                return end_buf;
 493
 494                        last_ev = current_ev;
 495                }
 496        }
 497        /* The other data in the scan result are not really
 498        * interesting, so for now drop it
 499        */
 500        return current_ev;
 501}
 502
 503int usbdrvwext_giwname(struct net_device *dev,
 504                struct iw_request_info *info,
 505                union iwreq_data *wrq, char *extra)
 506{
 507        /* struct usbdrv_private *macp = dev->ml_priv; */
 508
 509        strcpy(wrq->name, "IEEE 802.11-MIMO");
 510
 511        return 0;
 512}
 513
 514int usbdrvwext_siwfreq(struct net_device *dev,
 515                struct iw_request_info *info,
 516                struct iw_freq *freq, char *extra)
 517{
 518        u32_t FreqKHz;
 519        struct usbdrv_private *macp = dev->ml_priv;
 520
 521        if (!netif_running(dev))
 522                return -EINVAL;
 523
 524        if (freq->e > 1)
 525                return -EINVAL;
 526
 527        if (freq->e == 1) {
 528                FreqKHz = (freq->m / 100000);
 529
 530                if (FreqKHz > 4000000) {
 531                        if (FreqKHz > 5825000)
 532                                FreqKHz = 5825000;
 533                        else if (FreqKHz < 4920000)
 534                                FreqKHz = 4920000;
 535                        else if (FreqKHz < 5000000)
 536                                FreqKHz = (((FreqKHz - 4000000) / 5000) * 5000)
 537                                                + 4000000;
 538                        else
 539                                FreqKHz = (((FreqKHz - 5000000) / 5000) * 5000)
 540                                                + 5000000;
 541                } else {
 542                        if (FreqKHz > 2484000)
 543                                FreqKHz = 2484000;
 544                        else if (FreqKHz < 2412000)
 545                                FreqKHz = 2412000;
 546                        else
 547                                FreqKHz = (((FreqKHz - 2412000) / 5000) * 5000)
 548                                                + 2412000;
 549                }
 550        } else {
 551                FreqKHz = usbdrv_chan2freq(freq->m);
 552
 553                if (FreqKHz != -1)
 554                        FreqKHz *= 1000;
 555                else
 556                        FreqKHz = 2412000;
 557        }
 558
 559        /* printk("freq->m: %d, freq->e: %d\n", freq->m, freq->e); */
 560        /* printk("FreqKHz: %d\n", FreqKHz); */
 561
 562        if (macp->DeviceOpened == 1) {
 563                zfiWlanSetFrequency(dev, FreqKHz, 0); /* Immediate */
 564                /* u8_t wpaieLen,wpaie[50]; */
 565                /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
 566                zfiWlanDisable(dev, 0);
 567                zfiWlanEnable(dev);
 568                /* if (wpaieLen > 2) */
 569                /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
 570        }
 571
 572        return 0;
 573}
 574
 575int usbdrvwext_giwfreq(struct net_device *dev,
 576                struct iw_request_info *info,
 577                struct iw_freq *freq, char *extra)
 578{
 579        struct usbdrv_private *macp = dev->ml_priv;
 580
 581        if (macp->DeviceOpened != 1)
 582                return 0;
 583
 584        freq->m = zfiWlanQueryFrequency(dev);
 585        freq->e = 3;
 586
 587        return 0;
 588}
 589
 590int usbdrvwext_siwmode(struct net_device *dev,
 591                struct iw_request_info *info,
 592                union iwreq_data *wrq, char *extra)
 593{
 594        struct usbdrv_private *macp = dev->ml_priv;
 595        u8_t WlanMode;
 596
 597        if (!netif_running(dev))
 598                return -EINVAL;
 599
 600        if (macp->DeviceOpened != 1)
 601                return 0;
 602
 603        switch (wrq->mode) {
 604        case IW_MODE_MASTER:
 605                WlanMode = ZM_MODE_AP;
 606                break;
 607        case IW_MODE_INFRA:
 608                WlanMode = ZM_MODE_INFRASTRUCTURE;
 609                break;
 610        case IW_MODE_ADHOC:
 611                WlanMode = ZM_MODE_IBSS;
 612                break;
 613        default:
 614                WlanMode = ZM_MODE_IBSS;
 615                break;
 616        }
 617
 618        zfiWlanSetWlanMode(dev, WlanMode);
 619        zfiWlanDisable(dev, 1);
 620        zfiWlanEnable(dev);
 621
 622        return 0;
 623}
 624
 625int usbdrvwext_giwmode(struct net_device *dev,
 626        struct iw_request_info *info,
 627        __u32 *mode, char *extra)
 628{
 629        unsigned long irqFlag;
 630        struct usbdrv_private *macp = dev->ml_priv;
 631
 632        if (!netif_running(dev))
 633                return -EINVAL;
 634
 635        if (macp->DeviceOpened != 1)
 636                return 0;
 637
 638        spin_lock_irqsave(&macp->cs_lock, irqFlag);
 639
 640        switch (zfiWlanQueryWlanMode(dev)) {
 641        case ZM_MODE_AP:
 642                *mode = IW_MODE_MASTER;
 643                break;
 644        case ZM_MODE_INFRASTRUCTURE:
 645                *mode = IW_MODE_INFRA;
 646                break;
 647        case ZM_MODE_IBSS:
 648                *mode = IW_MODE_ADHOC;
 649                break;
 650        default:
 651                *mode = IW_MODE_ADHOC;
 652                break;
 653        }
 654
 655        spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
 656
 657        return 0;
 658}
 659
 660int usbdrvwext_siwsens(struct net_device *dev,
 661                        struct iw_request_info *info,
 662                        struct iw_param *sens, char *extra)
 663{
 664        return 0;
 665}
 666
 667int usbdrvwext_giwsens(struct net_device *dev,
 668                        struct iw_request_info *info,
 669                        struct iw_param *sens, char *extra)
 670{
 671        sens->value = 0;
 672        sens->fixed = 1;
 673
 674        return 0;
 675}
 676
 677int usbdrvwext_giwrange(struct net_device *dev,
 678                struct iw_request_info *info,
 679                struct iw_point *data, char *extra)
 680{
 681        struct iw_range *range = (struct iw_range *) extra;
 682        int i, val;
 683        /* int num_band_a; */
 684        u16_t channels[60];
 685        u16_t channel_num;
 686
 687        if (!netif_running(dev))
 688                return -EINVAL;
 689
 690        range->txpower_capa = IW_TXPOW_DBM;
 691        /* XXX what about min/max_pmp, min/max_pmt, etc. */
 692
 693        range->we_version_compiled = WIRELESS_EXT;
 694        range->we_version_source = 13;
 695
 696        range->retry_capa = IW_RETRY_LIMIT;
 697        range->retry_flags = IW_RETRY_LIMIT;
 698        range->min_retry = 0;
 699        range->max_retry = 255;
 700
 701        channel_num = zfiWlanQueryAllowChannels(dev, channels);
 702
 703        /* Gurantee reported channel numbers is less
 704        * or equal to IW_MAX_FREQUENCIES
 705        */
 706        if (channel_num > IW_MAX_FREQUENCIES)
 707                channel_num = IW_MAX_FREQUENCIES;
 708
 709        val = 0;
 710
 711        for (i = 0; i < channel_num; i++) {
 712                range->freq[val].i = usbdrv_freq2chan(channels[i]);
 713                range->freq[val].m = channels[i];
 714                range->freq[val].e = 6;
 715                val++;
 716        }
 717
 718        range->num_channels = channel_num;
 719        range->num_frequency = channel_num;
 720
 721        #if 0
 722        range->num_channels = 14; /* Only 2.4G */
 723
 724        /* XXX need to filter against the regulatory domain &| active set */
 725        val = 0;
 726        /* B,G Bands */
 727        for (i = 1; i <= 14; i++) {
 728                range->freq[val].i = i;
 729                if (i == 14)
 730                        range->freq[val].m = 2484000;
 731                else
 732                        range->freq[val].m = (2412+(i-1)*5)*1000;
 733                range->freq[val].e = 3;
 734                val++;
 735        }
 736
 737        num_band_a = (IW_MAX_FREQUENCIES - val);
 738        /* A Bands */
 739        for (i = 0; i < num_band_a; i++) {
 740                range->freq[val].i = channel_frequency_11A[2 * i];
 741                range->freq[val].m = channel_frequency_11A[2 * i + 1] * 1000;
 742                range->freq[val].e = 3;
 743                val++;
 744        }
 745        /* MIMO Rate Not Defined Now
 746        * For 802.11a, there are too more frequency.
 747        * We can't return them all.
 748        */
 749        range->num_frequency = val;
 750        #endif
 751
 752        /* Max of /proc/net/wireless */
 753        range->max_qual.qual = 100;  /* ??  92; */
 754        range->max_qual.level = 154; /* ?? */
 755        range->max_qual.noise = 154; /* ?? */
 756        range->sensitivity = 3;      /* ?? */
 757
 758        /* XXX these need to be nsd-specific! */
 759        range->min_rts = 0;
 760        range->max_rts = 2347;
 761        range->min_frag = 256;
 762        range->max_frag = 2346;
 763        range->max_encoding_tokens = 4 /* NUM_WEPKEYS ?? */;
 764        range->num_encoding_sizes = 2; /* ?? */
 765
 766        range->encoding_size[0] = 5; /* ?? WEP Key Encoding Size */
 767        range->encoding_size[1] = 13; /* ?? */
 768
 769        /* XXX what about num_bitrates/throughput? */
 770        range->num_bitrates = 0; /* ?? */
 771
 772        /* estimated max throughput
 773        * XXX need to cap it if we're running at ~2Mbps..
 774        */
 775
 776        range->throughput = 300000000;
 777
 778        return 0;
 779}
 780
 781int usbdrvwext_siwap(struct net_device *dev, struct iw_request_info *info,
 782                struct sockaddr *MacAddr, char *extra)
 783{
 784        struct usbdrv_private *macp = dev->ml_priv;
 785
 786        if (!netif_running(dev))
 787                return -EINVAL;
 788
 789        if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
 790                /* AP Mode */
 791                zfiWlanSetMacAddress(dev, (u16_t *)&MacAddr->sa_data[0]);
 792        } else {
 793                /* STA Mode */
 794                zfiWlanSetBssid(dev, &MacAddr->sa_data[0]);
 795        }
 796
 797        if (macp->DeviceOpened == 1) {
 798                /* u8_t wpaieLen,wpaie[80]; */
 799                /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
 800                zfiWlanDisable(dev, 0);
 801                zfiWlanEnable(dev);
 802                /* if (wpaieLen > 2) */
 803                /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
 804        }
 805
 806        return 0;
 807}
 808
 809int usbdrvwext_giwap(struct net_device *dev,
 810                struct iw_request_info *info,
 811                struct sockaddr *MacAddr, char *extra)
 812{
 813        struct usbdrv_private *macp = dev->ml_priv;
 814
 815        if (macp->DeviceOpened != 1)
 816                return 0;
 817
 818        if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
 819                /* AP Mode */
 820                zfiWlanQueryMacAddress(dev, &MacAddr->sa_data[0]);
 821        } else {
 822                /* STA Mode */
 823                if (macp->adapterState == ZM_STATUS_MEDIA_CONNECT) {
 824                        zfiWlanQueryBssid(dev, &MacAddr->sa_data[0]);
 825                } else {
 826                        u8_t zero_addr[6] = { 0x00, 0x00, 0x00, 0x00,
 827                                                                0x00, 0x00 };
 828                        memcpy(&MacAddr->sa_data[0], zero_addr,
 829                                                        sizeof(zero_addr));
 830                }
 831        }
 832
 833        return 0;
 834}
 835
 836int usbdrvwext_iwaplist(struct net_device *dev,
 837                        struct iw_request_info *info,
 838                        struct iw_point *data, char *extra)
 839{
 840        /* Don't know how to do yet--CWYang(+) */
 841        return 0;
 842
 843}
 844
 845int usbdrvwext_siwscan(struct net_device *dev, struct iw_request_info *info,
 846        struct iw_point *data, char *extra)
 847{
 848        struct usbdrv_private *macp = dev->ml_priv;
 849
 850        if (macp->DeviceOpened != 1)
 851                return 0;
 852
 853        printk(KERN_WARNING "CWY - usbdrvwext_siwscan\n");
 854
 855        zfiWlanScan(dev);
 856
 857        return 0;
 858}
 859
 860int usbdrvwext_giwscan(struct net_device *dev,
 861                struct iw_request_info *info,
 862                struct iw_point *data, char *extra)
 863{
 864        struct usbdrv_private *macp = dev->ml_priv;
 865        /* struct zsWlanDev* wd = (struct zsWlanDev*) zmw_wlan_dev(dev); */
 866        char *current_ev = extra;
 867        char *end_buf;
 868        int i;
 869        /* struct zsBssList BssList; */
 870        struct zsBssListV1 *pBssList = kmalloc(sizeof(struct zsBssListV1),
 871                                                                GFP_KERNEL);
 872        /* BssList = wd->sta.pBssList; */
 873        /* zmw_get_wlan_dev(dev); */
 874
 875        if (macp->DeviceOpened != 1)
 876                return 0;
 877
 878        if (data->length == 0)
 879                end_buf = extra + IW_SCAN_MAX_DATA;
 880        else
 881                end_buf = extra + data->length;
 882
 883        printk(KERN_WARNING "giwscan - Report Scan Results\n");
 884        /* printk("giwscan - BssList Sreucture Len : %d\n", sizeof(BssList));
 885        * printk("giwscan - BssList Count : %d\n",
 886        * wd->sta.pBssList->bssCount);
 887        * printk("giwscan - UpdateBssList Count : %d\n",
 888        * wd->sta.pUpdateBssList->bssCount);
 889        */
 890        zfiWlanQueryBssListV1(dev, pBssList);
 891        /* zfiWlanQueryBssList(dev, &BssList); */
 892
 893        /* Read and parse all entries */
 894        printk(KERN_WARNING "giwscan - pBssList->bssCount : %d\n",
 895                                                pBssList->bssCount);
 896        /* printk("giwscan - BssList.bssCount : %d\n", BssList.bssCount); */
 897
 898        for (i = 0; i < pBssList->bssCount; i++) {
 899                /* Translate to WE format this entry
 900                * current_ev = usbdrv_translate_scan(dev, info, current_ev,
 901                * extra + IW_SCAN_MAX_DATA, &pBssList->bssInfo[i]);
 902                */
 903                current_ev = usbdrv_translate_scan(dev, info, current_ev,
 904                                        end_buf, &pBssList->bssInfo[i]);
 905
 906                if (current_ev == end_buf) {
 907                        kfree(pBssList);
 908                        data->length = current_ev - extra;
 909                        return -E2BIG;
 910                }
 911        }
 912
 913        /* Length of data */
 914        data->length = (current_ev - extra);
 915        data->flags = 0;   /* todo */
 916
 917        kfree(pBssList);
 918
 919        return 0;
 920}
 921
 922int usbdrvwext_siwessid(struct net_device *dev,
 923                struct iw_request_info *info,
 924                struct iw_point *essid, char *extra)
 925{
 926        char EssidBuf[IW_ESSID_MAX_SIZE + 1];
 927        struct usbdrv_private *macp = dev->ml_priv;
 928
 929        if (!netif_running(dev))
 930                return -EINVAL;
 931
 932        if (essid->flags == 1) {
 933                if (essid->length > (IW_ESSID_MAX_SIZE + 1))
 934                        return -E2BIG;
 935
 936                if (copy_from_user(&EssidBuf, essid->pointer, essid->length))
 937                        return -EFAULT;
 938
 939                EssidBuf[essid->length] = '\0';
 940                /* printk("siwessid - Set Essid : %s\n",EssidBuf); */
 941                /* printk("siwessid - Essid Len : %d\n",essid->length); */
 942                /* printk("siwessid - Essid Flag : %x\n",essid->flags); */
 943                if (macp->DeviceOpened == 1) {
 944                        zfiWlanSetSSID(dev, EssidBuf, strlen(EssidBuf));
 945                        zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev),
 946                                                FALSE);
 947                        zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev));
 948                        /* u8_t wpaieLen,wpaie[50]; */
 949                        /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
 950                        zfiWlanDisable(dev, 0);
 951                        zfiWlanEnable(dev);
 952                        /* if (wpaieLen > 2) */
 953                        /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
 954                }
 955        }
 956
 957        return 0;
 958}
 959
 960int usbdrvwext_giwessid(struct net_device *dev,
 961                struct iw_request_info *info,
 962                struct iw_point *essid, char *extra)
 963{
 964        struct usbdrv_private *macp = dev->ml_priv;
 965        u8_t EssidLen;
 966        char EssidBuf[IW_ESSID_MAX_SIZE + 1];
 967        int ssid_len;
 968
 969        if (!netif_running(dev))
 970                return -EINVAL;
 971
 972        if (macp->DeviceOpened != 1)
 973                return 0;
 974
 975        zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
 976
 977        /* Convert type from unsigned char to char */
 978        ssid_len = (int)EssidLen;
 979
 980        /* Make sure the essid length is not greater than IW_ESSID_MAX_SIZE */
 981        if (ssid_len > IW_ESSID_MAX_SIZE)
 982                ssid_len = IW_ESSID_MAX_SIZE;
 983
 984        EssidBuf[ssid_len] = '\0';
 985
 986        essid->flags = 1;
 987        essid->length = strlen(EssidBuf);
 988
 989        memcpy(extra, EssidBuf, essid->length);
 990        /* wireless.c in Kernel would handle copy_to_user -- line 679 */
 991        /* if (essid->pointer) {
 992        * if (copy_to_user(essid->pointer, EssidBuf, essid->length)) {
 993        * printk("giwessid - copy_to_user Fail\n");
 994        * return -EFAULT;
 995        * }
 996        * }
 997        */
 998
 999        return 0;
1000}
1001
1002int usbdrvwext_siwnickn(struct net_device *dev,
1003                        struct iw_request_info *info,
1004                        struct iw_point *data, char *nickname)
1005{
1006        /* Exist but junk--CWYang(+) */
1007        return 0;
1008}
1009
1010int usbdrvwext_giwnickn(struct net_device *dev,
1011                        struct iw_request_info *info,
1012                        struct iw_point *data, char *nickname)
1013{
1014        struct usbdrv_private *macp = dev->ml_priv;
1015        u8_t EssidLen;
1016        char EssidBuf[IW_ESSID_MAX_SIZE + 1];
1017
1018        if (macp->DeviceOpened != 1)
1019                return 0;
1020
1021        zfiWlanQuerySSID(dev, &EssidBuf[0], &EssidLen);
1022        EssidBuf[EssidLen] = 0;
1023
1024        data->flags = 1;
1025        data->length = strlen(EssidBuf);
1026
1027        memcpy(nickname, EssidBuf, data->length);
1028
1029        return 0;
1030}
1031
1032int usbdrvwext_siwrate(struct net_device *dev,
1033                struct iw_request_info *info,
1034                struct iw_param *frq, char *extra)
1035{
1036        struct usbdrv_private *macp = dev->ml_priv;
1037        /* Array to Define Rate Number that Send to Driver */
1038        u16_t zcIndextoRateBG[16] = {1000, 2000, 5500, 11000, 0, 0, 0, 0,
1039                        48000, 24000, 12000, 6000, 54000, 36000, 18000, 9000};
1040        u16_t zcRateToMCS[] = {0xff, 0, 1, 2, 3, 0xb, 0xf, 0xa, 0xe, 0x9, 0xd,
1041                                0x8, 0xc};
1042        u8_t i, RateIndex = 4;
1043        u16_t RateKbps;
1044
1045        /* printk("frq->disabled : 0x%x\n",frq->disabled); */
1046        /* printk("frq->value : 0x%x\n",frq->value); */
1047
1048        RateKbps = frq->value / 1000;
1049        /* printk("RateKbps : %d\n", RateKbps); */
1050        for (i = 0; i < 16; i++) {
1051                if (RateKbps == zcIndextoRateBG[i])
1052                        RateIndex = i;
1053        }
1054
1055        if (zcIndextoRateBG[RateIndex] == 0)
1056                RateIndex = 0xff;
1057        /* printk("RateIndex : %x\n", RateIndex); */
1058        for (i = 0; i < 13; i++)
1059                if (RateIndex == zcRateToMCS[i])
1060                        break;
1061        /* printk("Index : %x\n", i); */
1062        if (RateKbps == 65000) {
1063                RateIndex = 20;
1064                printk(KERN_WARNING "RateIndex : %d\n", RateIndex);
1065        }
1066
1067        if (macp->DeviceOpened == 1) {
1068                zfiWlanSetTxRate(dev, i);
1069                /* zfiWlanDisable(dev); */
1070                /* zfiWlanEnable(dev); */
1071        }
1072
1073        return 0;
1074}
1075
1076int usbdrvwext_giwrate(struct net_device *dev,
1077                struct iw_request_info *info,
1078                struct iw_param *frq, char *extra)
1079{
1080        struct usbdrv_private *macp = dev->ml_priv;
1081
1082        if (!netif_running(dev))
1083                return -EINVAL;
1084
1085        if (macp->DeviceOpened != 1)
1086                return 0;
1087
1088        frq->fixed = 0;
1089        frq->disabled = 0;
1090        frq->value = zfiWlanQueryRxRate(dev) * 1000;
1091
1092        return 0;
1093}
1094
1095int usbdrvwext_siwrts(struct net_device *dev,
1096                struct iw_request_info *info,
1097                struct iw_param *rts, char *extra)
1098{
1099        struct usbdrv_private *macp = dev->ml_priv;
1100        int val = rts->value;
1101
1102        if (macp->DeviceOpened != 1)
1103                return 0;
1104
1105        if (rts->disabled)
1106                val = 2347;
1107
1108        if ((val < 0) || (val > 2347))
1109                return -EINVAL;
1110
1111        zfiWlanSetRtsThreshold(dev, val);
1112
1113        return 0;
1114}
1115
1116int usbdrvwext_giwrts(struct net_device *dev,
1117                struct iw_request_info *info,
1118                struct iw_param *rts, char *extra)
1119{
1120        struct usbdrv_private *macp = dev->ml_priv;
1121
1122        if (!netif_running(dev))
1123                return -EINVAL;
1124
1125        if (macp->DeviceOpened != 1)
1126                return 0;
1127
1128        rts->value = zfiWlanQueryRtsThreshold(dev);
1129        rts->disabled = (rts->value >= 2347);
1130        rts->fixed = 1;
1131
1132        return 0;
1133}
1134
1135int usbdrvwext_siwfrag(struct net_device *dev,
1136                struct iw_request_info *info,
1137                struct iw_param *frag, char *extra)
1138{
1139        struct usbdrv_private *macp = dev->ml_priv;
1140        u16_t fragThreshold;
1141
1142        if (macp->DeviceOpened != 1)
1143                return 0;
1144
1145        if (frag->disabled)
1146                fragThreshold = 0;
1147        else
1148                fragThreshold = frag->value;
1149
1150        zfiWlanSetFragThreshold(dev, fragThreshold);
1151
1152        return 0;
1153}
1154
1155int usbdrvwext_giwfrag(struct net_device *dev,
1156                struct iw_request_info *info,
1157                struct iw_param *frag, char *extra)
1158{
1159        struct usbdrv_private *macp = dev->ml_priv;
1160        u16 val;
1161        unsigned long irqFlag;
1162
1163        if (!netif_running(dev))
1164                return -EINVAL;
1165
1166        if (macp->DeviceOpened != 1)
1167                return 0;
1168
1169        spin_lock_irqsave(&macp->cs_lock, irqFlag);
1170
1171        val = zfiWlanQueryFragThreshold(dev);
1172
1173        frag->value = val;
1174
1175        frag->disabled = (val >= 2346);
1176        frag->fixed = 1;
1177
1178        spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1179
1180        return 0;
1181}
1182
1183int usbdrvwext_siwtxpow(struct net_device *dev,
1184                        struct iw_request_info *info,
1185                        struct iw_param *rrq, char *extra)
1186{
1187        /* Not support yet--CWYng(+) */
1188        return 0;
1189}
1190
1191int usbdrvwext_giwtxpow(struct net_device *dev,
1192                        struct iw_request_info *info,
1193                        struct iw_param *rrq, char *extra)
1194{
1195        /* Not support yet--CWYng(+) */
1196        return 0;
1197}
1198
1199int usbdrvwext_siwretry(struct net_device *dev,
1200                        struct iw_request_info *info,
1201                        struct iw_param *rrq, char *extra)
1202{
1203        /* Do nothing--CWYang(+) */
1204        return 0;
1205}
1206
1207int usbdrvwext_giwretry(struct net_device *dev,
1208                        struct iw_request_info *info,
1209                        struct iw_param *rrq, char *extra)
1210{
1211        /* Do nothing--CWYang(+) */
1212        return 0;
1213}
1214
1215int usbdrvwext_siwencode(struct net_device *dev,
1216                struct iw_request_info *info,
1217                struct iw_point *erq, char *key)
1218{
1219        struct zsKeyInfo keyInfo;
1220        int i;
1221        int WepState = ZM_ENCRYPTION_WEP_DISABLED;
1222        struct usbdrv_private *macp = dev->ml_priv;
1223
1224        if (!netif_running(dev))
1225                return -EINVAL;
1226
1227        if ((erq->flags & IW_ENCODE_DISABLED) == 0) {
1228                keyInfo.key = key;
1229                keyInfo.keyLength = erq->length;
1230                keyInfo.keyIndex = (erq->flags & IW_ENCODE_INDEX) - 1;
1231                if (keyInfo.keyIndex >= 4)
1232                        keyInfo.keyIndex = 0;
1233                keyInfo.flag = ZM_KEY_FLAG_DEFAULT_KEY;
1234
1235                zfiWlanSetKey(dev, keyInfo);
1236                WepState = ZM_ENCRYPTION_WEP_ENABLED;
1237        } else {
1238                for (i = 1; i < 4; i++)
1239                        zfiWlanRemoveKey(dev, 0, i);
1240                WepState = ZM_ENCRYPTION_WEP_DISABLED;
1241                /* zfiWlanSetEncryMode(dev, ZM_NO_WEP); */
1242        }
1243
1244        if (macp->DeviceOpened == 1) {
1245                zfiWlanSetWepStatus(dev, WepState);
1246                zfiWlanSetFrequency(dev, zfiWlanQueryFrequency(dev), FALSE);
1247                /* zfiWlanSetEncryMode(dev, zfiWlanQueryEncryMode(dev)); */
1248                /* u8_t wpaieLen,wpaie[50]; */
1249                /* zfiWlanQueryWpaIe(dev, wpaie, &wpaieLen); */
1250                zfiWlanDisable(dev, 0);
1251                zfiWlanEnable(dev);
1252                /* if (wpaieLen > 2) */
1253                /* zfiWlanSetWpaIe(dev, wpaie, wpaieLen); */
1254        }
1255
1256        return 0;
1257}
1258
1259int usbdrvwext_giwencode(struct net_device *dev,
1260                struct iw_request_info *info,
1261                struct iw_point *erq, char *key)
1262{
1263        struct usbdrv_private *macp = dev->ml_priv;
1264        u8_t EncryptionMode;
1265        u8_t keyLen = 0;
1266
1267        if (macp->DeviceOpened != 1)
1268                return 0;
1269
1270        EncryptionMode = zfiWlanQueryEncryMode(dev);
1271
1272        if (EncryptionMode)
1273                erq->flags = IW_ENCODE_ENABLED;
1274        else
1275                erq->flags = IW_ENCODE_DISABLED;
1276
1277        /* We can't return the key, so set the proper flag and return zero */
1278        erq->flags |= IW_ENCODE_NOKEY;
1279        memset(key, 0, 16);
1280
1281        /* Copy the key to the user buffer */
1282        switch (EncryptionMode) {
1283        case ZM_WEP64:
1284                keyLen = 5;
1285                break;
1286        case ZM_WEP128:
1287                keyLen = 13;
1288                break;
1289        case ZM_WEP256:
1290                keyLen = 29;
1291                break;
1292        case ZM_AES:
1293                keyLen = 16;
1294                break;
1295        case ZM_TKIP:
1296                keyLen = 32;
1297                break;
1298        #ifdef ZM_ENABLE_CENC
1299        case ZM_CENC:
1300                /* ZM_ENABLE_CENC */
1301                keyLen = 32;
1302                break;
1303        #endif
1304        case ZM_NO_WEP:
1305                keyLen = 0;
1306                break;
1307        default:
1308                keyLen = 0;
1309                printk(KERN_ERR "Unknown EncryMode\n");
1310                break;
1311        }
1312        erq->length = keyLen;
1313
1314        return 0;
1315}
1316
1317int usbdrvwext_siwpower(struct net_device *dev,
1318                struct iw_request_info *info,
1319                struct iw_param *frq, char *extra)
1320{
1321        struct usbdrv_private *macp = dev->ml_priv;
1322        u8_t PSMode;
1323
1324        if (macp->DeviceOpened != 1)
1325                return 0;
1326
1327        if (frq->disabled)
1328                PSMode = ZM_STA_PS_NONE;
1329        else
1330                PSMode = ZM_STA_PS_MAX;
1331
1332        zfiWlanSetPowerSaveMode(dev, PSMode);
1333
1334        return 0;
1335}
1336
1337int usbdrvwext_giwpower(struct net_device *dev,
1338                struct iw_request_info *info,
1339                struct iw_param *frq, char *extra)
1340{
1341        unsigned long irqFlag;
1342        struct usbdrv_private *macp = dev->ml_priv;
1343
1344        if (macp->DeviceOpened != 1)
1345                return 0;
1346
1347        spin_lock_irqsave(&macp->cs_lock, irqFlag);
1348
1349        if (zfiWlanQueryPowerSaveMode(dev) == ZM_STA_PS_NONE)
1350                frq->disabled = 1;
1351        else
1352                frq->disabled = 0;
1353
1354        spin_unlock_irqrestore(&macp->cs_lock, irqFlag);
1355
1356        return 0;
1357}
1358
1359/*int usbdrvwext_setparam(struct net_device *dev, struct iw_request_info *info,
1360*                        void *w, char *extra)
1361*{
1362*       struct ieee80211vap *vap = dev->ml_priv;
1363*       struct ieee80211com *ic = vap->iv_ic;
1364*       struct ieee80211_rsnparms *rsn = &vap->iv_bss->ni_rsn;
1365*       int *i = (int *) extra;
1366*       int param = i[0];               // parameter id is 1st
1367*       int value = i[1];               // NB: most values are TYPE_INT
1368*       int retv = 0;
1369*       int j, caps;
1370*       const struct ieee80211_authenticator *auth;
1371*       const struct ieee80211_aclator *acl;
1372*
1373*       switch (param) {
1374*       case IEEE80211_PARAM_AUTHMODE:
1375*               switch (value) {
1376*               case IEEE80211_AUTH_WPA:        // WPA
1377*               case IEEE80211_AUTH_8021X:      // 802.1x
1378*               case IEEE80211_AUTH_OPEN:       // open
1379*               case IEEE80211_AUTH_SHARED:     // shared-key
1380*               case IEEE80211_AUTH_AUTO:       // auto
1381*                       auth = ieee80211_authenticator_get(value);
1382*                       if (auth == NULL)
1383*                               return -EINVAL;
1384*                       break;
1385*               default:
1386*                       return -EINVAL;
1387*               }
1388*               switch (value) {
1389*               case IEEE80211_AUTH_WPA:        // WPA w/ 802.1x
1390*                       vap->iv_flags |= IEEE80211_F_PRIVACY;
1391*                       value = IEEE80211_AUTH_8021X;
1392*                       break;
1393*               case IEEE80211_AUTH_OPEN:       // open
1394*               vap->iv_flags &= ~(IEEE80211_F_WPA | IEEE80211_F_PRIVACY);
1395*                       break;
1396*               case IEEE80211_AUTH_SHARED:     // shared-key
1397*               case IEEE80211_AUTH_AUTO:       // auto
1398*               case IEEE80211_AUTH_8021X:      // 802.1x
1399*                       vap->iv_flags &= ~IEEE80211_F_WPA;
1400*                       // both require a key so mark the PRIVACY capability
1401*                       vap->iv_flags |= IEEE80211_F_PRIVACY;
1402*                       break;
1403*               }
1404*               // NB: authenticator attach/detach happens on state change
1405*               vap->iv_bss->ni_authmode = value;
1406*               // XXX mixed/mode/usage?
1407*               vap->iv_auth = auth;
1408*               retv = ENETRESET;
1409*               break;
1410*       case IEEE80211_PARAM_PROTMODE:
1411*               if (value > IEEE80211_PROT_RTSCTS)
1412*                       return -EINVAL;
1413*               ic->ic_protmode = value;
1414*               // NB: if not operating in 11g this can wait
1415*               if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1416*                   IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1417*                       retv = ENETRESET;
1418*               break;
1419*       case IEEE80211_PARAM_MCASTCIPHER:
1420*               if ((vap->iv_caps & cipher2cap(value)) == 0 &&
1421*                   !ieee80211_crypto_available(value))
1422*                       return -EINVAL;
1423*               rsn->rsn_mcastcipher = value;
1424*               if (vap->iv_flags & IEEE80211_F_WPA)
1425*                       retv = ENETRESET;
1426*               break;
1427*       case IEEE80211_PARAM_MCASTKEYLEN:
1428*               if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1429*                       return -EINVAL;
1430*               // XXX no way to verify driver capability
1431*               rsn->rsn_mcastkeylen = value;
1432*               if (vap->iv_flags & IEEE80211_F_WPA)
1433*                       retv = ENETRESET;
1434*               break;
1435*       case IEEE80211_PARAM_UCASTCIPHERS:
1436*
1437*                // Convert cipher set to equivalent capabilities.
1438*                // NB: this logic intentionally ignores unknown and
1439*                // unsupported ciphers so folks can specify 0xff or
1440*                // similar and get all available ciphers.
1441*
1442*               caps = 0;
1443*               for (j = 1; j < 32; j++)        // NB: skip WEP
1444*                       if ((value & (1<<j)) &&
1445*                           ((vap->iv_caps & cipher2cap(j)) ||
1446*                            ieee80211_crypto_available(j)))
1447*                               caps |= 1<<j;
1448*               if (caps == 0)                  // nothing available
1449*                       return -EINVAL;
1450*               // XXX verify ciphers ok for unicast use?
1451*               // XXX disallow if running as it'll have no effect
1452*               rsn->rsn_ucastcipherset = caps;
1453*               if (vap->iv_flags & IEEE80211_F_WPA)
1454*                       retv = ENETRESET;
1455*               break;
1456*       case IEEE80211_PARAM_UCASTCIPHER:
1457*               if ((rsn->rsn_ucastcipherset & cipher2cap(value)) == 0)
1458*                       return -EINVAL;
1459*               rsn->rsn_ucastcipher = value;
1460*               break;
1461*       case IEEE80211_PARAM_UCASTKEYLEN:
1462*               if (!(0 < value && value < IEEE80211_KEYBUF_SIZE))
1463*                       return -EINVAL;
1464*               // XXX no way to verify driver capability
1465*               rsn->rsn_ucastkeylen = value;
1466*               break;
1467*       case IEEE80211_PARAM_KEYMGTALGS:
1468*               // XXX check
1469*               rsn->rsn_keymgmtset = value;
1470*               if (vap->iv_flags & IEEE80211_F_WPA)
1471*                       retv = ENETRESET;
1472*               break;
1473*       case IEEE80211_PARAM_RSNCAPS:
1474*               // XXX check
1475*               rsn->rsn_caps = value;
1476*               if (vap->iv_flags & IEEE80211_F_WPA)
1477*                       retv = ENETRESET;
1478*               break;
1479*       case IEEE80211_PARAM_WPA:
1480*               if (value > 3)
1481*                       return -EINVAL;
1482*               // XXX verify ciphers available
1483*               vap->iv_flags &= ~IEEE80211_F_WPA;
1484*               switch (value) {
1485*               case 1:
1486*                       vap->iv_flags |= IEEE80211_F_WPA1;
1487*                       break;
1488*               case 2:
1489*                       vap->iv_flags |= IEEE80211_F_WPA2;
1490*                       break;
1491*               case 3:
1492*                       vap->iv_flags |= IEEE80211_F_WPA1 | IEEE80211_F_WPA2;
1493*                       break;
1494*               }
1495*               retv = ENETRESET;               // XXX?
1496*               break;
1497*       case IEEE80211_PARAM_ROAMING:
1498*               if (!(IEEE80211_ROAMING_DEVICE <= value &&
1499*                   value <= IEEE80211_ROAMING_MANUAL))
1500*                       return -EINVAL;
1501*               ic->ic_roaming = value;
1502*               break;
1503*       case IEEE80211_PARAM_PRIVACY:
1504*               if (value) {
1505*                       // XXX check for key state?
1506*                       vap->iv_flags |= IEEE80211_F_PRIVACY;
1507*               } else
1508*                       vap->iv_flags &= ~IEEE80211_F_PRIVACY;
1509*               break;
1510*       case IEEE80211_PARAM_DROPUNENCRYPTED:
1511*               if (value)
1512*                       vap->iv_flags |= IEEE80211_F_DROPUNENC;
1513*               else
1514*                       vap->iv_flags &= ~IEEE80211_F_DROPUNENC;
1515*               break;
1516*       case IEEE80211_PARAM_COUNTERMEASURES:
1517*               if (value) {
1518*                       if ((vap->iv_flags & IEEE80211_F_WPA) == 0)
1519*                               return -EINVAL;
1520*                       vap->iv_flags |= IEEE80211_F_COUNTERM;
1521*               } else
1522*                       vap->iv_flags &= ~IEEE80211_F_COUNTERM;
1523*               break;
1524*       case IEEE80211_PARAM_DRIVER_CAPS:
1525*               vap->iv_caps = value;           // NB: for testing
1526*               break;
1527*       case IEEE80211_PARAM_MACCMD:
1528*               acl = vap->iv_acl;
1529*               switch (value) {
1530*               case IEEE80211_MACCMD_POLICY_OPEN:
1531*               case IEEE80211_MACCMD_POLICY_ALLOW:
1532*               case IEEE80211_MACCMD_POLICY_DENY:
1533*                       if (acl == NULL) {
1534*                               acl = ieee80211_aclator_get("mac");
1535*                               if (acl == NULL || !acl->iac_attach(vap))
1536*                                       return -EINVAL;
1537*                               vap->iv_acl = acl;
1538*                       }
1539*                       acl->iac_setpolicy(vap, value);
1540*                       break;
1541*               case IEEE80211_MACCMD_FLUSH:
1542*                       if (acl != NULL)
1543*                               acl->iac_flush(vap);
1544*                       // NB: silently ignore when not in use
1545*                       break;
1546*               case IEEE80211_MACCMD_DETACH:
1547*                       if (acl != NULL) {
1548*                               vap->iv_acl = NULL;
1549*                               acl->iac_detach(vap);
1550*                       }
1551*                       break;
1552*               }
1553*               break;
1554*       case IEEE80211_PARAM_WMM:
1555*               if (ic->ic_caps & IEEE80211_C_WME){
1556*                       if (value) {
1557*                               vap->iv_flags |= IEEE80211_F_WME;
1558*                                *//* XXX needed by ic_reset *//*
1559*                               vap->iv_ic->ic_flags |= IEEE80211_F_WME;
1560*                       }
1561*                       else {
1562*                               *//* XXX needed by ic_reset *//*
1563*                               vap->iv_flags &= ~IEEE80211_F_WME;
1564*                               vap->iv_ic->ic_flags &= ~IEEE80211_F_WME;
1565*                       }
1566*                       retv = ENETRESET;       // Renegotiate for capabilities
1567*               }
1568*               break;
1569*       case IEEE80211_PARAM_HIDESSID:
1570*               if (value)
1571*                       vap->iv_flags |= IEEE80211_F_HIDESSID;
1572*               else
1573*                       vap->iv_flags &= ~IEEE80211_F_HIDESSID;
1574*               retv = ENETRESET;
1575*               break;
1576*       case IEEE80211_PARAM_APBRIDGE:
1577*               if (value == 0)
1578*                       vap->iv_flags |= IEEE80211_F_NOBRIDGE;
1579*               else
1580*                       vap->iv_flags &= ~IEEE80211_F_NOBRIDGE;
1581*               break;
1582*       case IEEE80211_PARAM_INACT:
1583*               vap->iv_inact_run = value / IEEE80211_INACT_WAIT;
1584*               break;
1585*       case IEEE80211_PARAM_INACT_AUTH:
1586*               vap->iv_inact_auth = value / IEEE80211_INACT_WAIT;
1587*               break;
1588*       case IEEE80211_PARAM_INACT_INIT:
1589*               vap->iv_inact_init = value / IEEE80211_INACT_WAIT;
1590*               break;
1591*       case IEEE80211_PARAM_ABOLT:
1592*               caps = 0;
1593*
1594*                // Map abolt settings to capability bits;
1595*                // this also strips unknown/unwanted bits.
1596*
1597*               if (value & IEEE80211_ABOLT_TURBO_PRIME)
1598*                       caps |= IEEE80211_ATHC_TURBOP;
1599*               if (value & IEEE80211_ABOLT_COMPRESSION)
1600*                       caps |= IEEE80211_ATHC_COMP;
1601*               if (value & IEEE80211_ABOLT_FAST_FRAME)
1602*                       caps |= IEEE80211_ATHC_FF;
1603*               if (value & IEEE80211_ABOLT_XR)
1604*                       caps |= IEEE80211_ATHC_XR;
1605*               if (value & IEEE80211_ABOLT_AR)
1606*                       caps |= IEEE80211_ATHC_AR;
1607*               if (value & IEEE80211_ABOLT_BURST)
1608*                       caps |= IEEE80211_ATHC_BURST;
1609*        if (value & IEEE80211_ABOLT_WME_ELE)
1610*            caps |= IEEE80211_ATHC_WME;
1611*               // verify requested capabilities are supported
1612*               if ((caps & ic->ic_ath_cap) != caps)
1613*                       return -EINVAL;
1614*               if (vap->iv_ath_cap != caps) {
1615*                       if ((vap->iv_ath_cap ^ caps) & IEEE80211_ATHC_TURBOP) {
1616*                               if (ieee80211_set_turbo(dev,
1617*                                               caps & IEEE80211_ATHC_TURBOP))
1618*                                       return -EINVAL;
1619*                               ieee80211_scan_flush(ic);
1620*                       }
1621*                       vap->iv_ath_cap = caps;
1622*                       ic->ic_athcapsetup(vap->iv_ic, vap->iv_ath_cap);
1623*                       retv = ENETRESET;
1624*               }
1625*               break;
1626*       case IEEE80211_PARAM_DTIM_PERIOD:
1627*               if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1628*                   vap->iv_opmode != IEEE80211_M_IBSS)
1629*                       return -EINVAL;
1630*               if (IEEE80211_DTIM_MIN <= value &&
1631*                   value <= IEEE80211_DTIM_MAX) {
1632*                       vap->iv_dtim_period = value;
1633*                       retv = ENETRESET;               // requires restart
1634*               } else
1635*                       retv = EINVAL;
1636*               break;
1637*       case IEEE80211_PARAM_BEACON_INTERVAL:
1638*               if (vap->iv_opmode != IEEE80211_M_HOSTAP &&
1639*                   vap->iv_opmode != IEEE80211_M_IBSS)
1640*                       return -EINVAL;
1641*               if (IEEE80211_BINTVAL_MIN <= value &&
1642*                   value <= IEEE80211_BINTVAL_MAX) {
1643*                       ic->ic_lintval = value;         // XXX multi-bss
1644*                       retv = ENETRESET;               // requires restart
1645*               } else
1646*                       retv = EINVAL;
1647*               break;
1648*       case IEEE80211_PARAM_DOTH:
1649*               if (value) {
1650*                       ic->ic_flags |= IEEE80211_F_DOTH;
1651*               }
1652*               else
1653*                       ic->ic_flags &= ~IEEE80211_F_DOTH;
1654*               retv = ENETRESET;       // XXX: need something this drastic?
1655*               break;
1656*       case IEEE80211_PARAM_PWRTARGET:
1657*               ic->ic_curchanmaxpwr = value;
1658*               break;
1659*       case IEEE80211_PARAM_GENREASSOC:
1660*               IEEE80211_SEND_MGMT(vap->iv_bss,
1661*                                       IEEE80211_FC0_SUBTYPE_REASSOC_REQ, 0);
1662*               break;
1663*       case IEEE80211_PARAM_COMPRESSION:
1664*               retv = ieee80211_setathcap(vap, IEEE80211_ATHC_COMP, value);
1665*               break;
1666*    case IEEE80211_PARAM_WMM_AGGRMODE:
1667*        retv = ieee80211_setathcap(vap, IEEE80211_ATHC_WME, value);
1668*        break;
1669*       case IEEE80211_PARAM_FF:
1670*               retv = ieee80211_setathcap(vap, IEEE80211_ATHC_FF, value);
1671*               break;
1672*       case IEEE80211_PARAM_TURBO:
1673*               retv = ieee80211_setathcap(vap, IEEE80211_ATHC_TURBOP, value);
1674*               if (retv == ENETRESET) {
1675*                       if(ieee80211_set_turbo(dev,value))
1676*                                       return -EINVAL;
1677*                       ieee80211_scan_flush(ic);
1678*               }
1679*               break;
1680*       case IEEE80211_PARAM_XR:
1681*               retv = ieee80211_setathcap(vap, IEEE80211_ATHC_XR, value);
1682*               break;
1683*       case IEEE80211_PARAM_BURST:
1684*               retv = ieee80211_setathcap(vap, IEEE80211_ATHC_BURST, value);
1685*               break;
1686*       case IEEE80211_PARAM_AR:
1687*               retv = ieee80211_setathcap(vap, IEEE80211_ATHC_AR, value);
1688*               break;
1689*       case IEEE80211_PARAM_PUREG:
1690*               if (value)
1691*                       vap->iv_flags |= IEEE80211_F_PUREG;
1692*               else
1693*                       vap->iv_flags &= ~IEEE80211_F_PUREG;
1694*               // NB: reset only if we're operating on an 11g channel
1695*               if (ic->ic_bsschan != IEEE80211_CHAN_ANYC &&
1696*                   IEEE80211_IS_CHAN_ANYG(ic->ic_bsschan))
1697*                       retv = ENETRESET;
1698*               break;
1699*       case IEEE80211_PARAM_WDS:
1700*               if (value)
1701*                       vap->iv_flags_ext |= IEEE80211_FEXT_WDS;
1702*               else
1703*                       vap->iv_flags_ext &= ~IEEE80211_FEXT_WDS;
1704*               break;
1705*       case IEEE80211_PARAM_BGSCAN:
1706*               if (value) {
1707*                       if ((vap->iv_caps & IEEE80211_C_BGSCAN) == 0)
1708*                               return -EINVAL;
1709*                       vap->iv_flags |= IEEE80211_F_BGSCAN;
1710*               } else {
1711*                       // XXX racey?
1712*                       vap->iv_flags &= ~IEEE80211_F_BGSCAN;
1713*                       ieee80211_cancel_scan(vap);     // anything current
1714*               }
1715*               break;
1716*       case IEEE80211_PARAM_BGSCAN_IDLE:
1717*               if (value >= IEEE80211_BGSCAN_IDLE_MIN)
1718*                       vap->iv_bgscanidle = value*HZ/1000;
1719*               else
1720*                       retv = EINVAL;
1721*               break;
1722*       case IEEE80211_PARAM_BGSCAN_INTERVAL:
1723*               if (value >= IEEE80211_BGSCAN_INTVAL_MIN)
1724*                       vap->iv_bgscanintvl = value*HZ;
1725*               else
1726*                       retv = EINVAL;
1727*               break;
1728*       case IEEE80211_PARAM_MCAST_RATE:
1729*               // units are in KILObits per second
1730*               if (value >= 256 && value <= 54000)
1731*                       vap->iv_mcast_rate = value;
1732*               else
1733*                       retv = EINVAL;
1734*               break;
1735*       case IEEE80211_PARAM_COVERAGE_CLASS:
1736*               if (value >= 0 && value <= IEEE80211_COVERAGE_CLASS_MAX) {
1737*                       ic->ic_coverageclass = value;
1738*                       if (IS_UP_AUTO(vap))
1739*                               ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
1740*                       retv = 0;
1741*               }
1742*               else
1743*                       retv = EINVAL;
1744*               break;
1745*       case IEEE80211_PARAM_COUNTRY_IE:
1746*               if (value)
1747*                       ic->ic_flags_ext |= IEEE80211_FEXT_COUNTRYIE;
1748*               else
1749*                       ic->ic_flags_ext &= ~IEEE80211_FEXT_COUNTRYIE;
1750*               retv = ENETRESET;
1751*               break;
1752*       case IEEE80211_PARAM_REGCLASS:
1753*               if (value)
1754*                       ic->ic_flags_ext |= IEEE80211_FEXT_REGCLASS;
1755*               else
1756*                       ic->ic_flags_ext &= ~IEEE80211_FEXT_REGCLASS;
1757*               retv = ENETRESET;
1758*               break;
1759*       case IEEE80211_PARAM_SCANVALID:
1760*               vap->iv_scanvalid = value*HZ;
1761*               break;
1762*       case IEEE80211_PARAM_ROAM_RSSI_11A:
1763*               vap->iv_roam.rssi11a = value;
1764*               break;
1765*       case IEEE80211_PARAM_ROAM_RSSI_11B:
1766*               vap->iv_roam.rssi11bOnly = value;
1767*               break;
1768*       case IEEE80211_PARAM_ROAM_RSSI_11G:
1769*               vap->iv_roam.rssi11b = value;
1770*               break;
1771*       case IEEE80211_PARAM_ROAM_RATE_11A:
1772*               vap->iv_roam.rate11a = value;
1773*               break;
1774*       case IEEE80211_PARAM_ROAM_RATE_11B:
1775*               vap->iv_roam.rate11bOnly = value;
1776*               break;
1777*       case IEEE80211_PARAM_ROAM_RATE_11G:
1778*               vap->iv_roam.rate11b = value;
1779*               break;
1780*       case IEEE80211_PARAM_UAPSDINFO:
1781*               if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1782*                       if (ic->ic_caps & IEEE80211_C_UAPSD) {
1783*                               if (value)
1784*                                       IEEE80211_VAP_UAPSD_ENABLE(vap);
1785*                               else
1786*                                       IEEE80211_VAP_UAPSD_DISABLE(vap);
1787*                               retv = ENETRESET;
1788*                       }
1789*               }
1790*               else if (vap->iv_opmode == IEEE80211_M_STA) {
1791*                       vap->iv_uapsdinfo = value;
1792*                       IEEE80211_VAP_UAPSD_ENABLE(vap);
1793*                       retv = ENETRESET;
1794*               }
1795*               break;
1796*       case IEEE80211_PARAM_SLEEP:
1797*               // XXX: Forced sleep for testing. Does not actually place the
1798*               //      HW in sleep mode yet. this only makes sense for STAs.
1799*
1800*               if (value) {
1801*                       // goto sleep
1802*                       IEEE80211_VAP_GOTOSLEEP(vap);
1803*               }
1804*               else {
1805*                       // wakeup
1806*                       IEEE80211_VAP_WAKEUP(vap);
1807*               }
1808*               ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1809*               break;
1810*       case IEEE80211_PARAM_QOSNULL:
1811*               // Force a QoS Null for testing.
1812*               ieee80211_send_qosnulldata(vap->iv_bss, value);
1813*               break;
1814*       case IEEE80211_PARAM_PSPOLL:
1815*               // Force a PS-POLL for testing.
1816*               ieee80211_send_pspoll(vap->iv_bss);
1817*               break;
1818*       case IEEE80211_PARAM_EOSPDROP:
1819*               if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
1820*                       if (value) IEEE80211_VAP_EOSPDROP_ENABLE(vap);
1821*                       else IEEE80211_VAP_EOSPDROP_DISABLE(vap);
1822*               }
1823*               break;
1824*       case IEEE80211_PARAM_MARKDFS:
1825*               if (value)
1826*                       ic->ic_flags_ext |= IEEE80211_FEXT_MARKDFS;
1827*               else
1828*                       ic->ic_flags_ext &= ~IEEE80211_FEXT_MARKDFS;
1829*               break;
1830*       case IEEE80211_PARAM_CHANBW:
1831*               switch (value) {
1832*                       case 0:
1833*                               ic->ic_chanbwflag = 0;
1834*                               break;
1835*                       case 1:
1836*                               ic->ic_chanbwflag = IEEE80211_CHAN_HALF;
1837*                               break;
1838*                       case 2:
1839*                               ic->ic_chanbwflag = IEEE80211_CHAN_QUARTER;
1840*                               break;
1841*                       default:
1842*                               retv = EINVAL;
1843*                               break;
1844*               }
1845*               break;
1846*       case IEEE80211_PARAM_SHORTPREAMBLE:
1847*               if (value) {
1848*                       ic->ic_caps |= IEEE80211_C_SHPREAMBLE;
1849*               } else {
1850*                       ic->ic_caps &= ~IEEE80211_C_SHPREAMBLE;
1851*               }
1852*               retv = ENETRESET;
1853*               break;
1854*       default:
1855*               retv = EOPNOTSUPP;
1856*               break;
1857*       }
1858*       // XXX should any of these cause a rescan?
1859*       if (retv == ENETRESET)
1860*               retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0;
1861*       return -retv;
1862*}
1863*/
1864
1865int usbdrvwext_setmode(struct net_device *dev, struct iw_request_info *info,
1866                        void *w, char *extra)
1867{
1868        return 0;
1869}
1870
1871int usbdrvwext_getmode(struct net_device *dev, struct iw_request_info *info,
1872                        void *w, char *extra)
1873{
1874        /* struct usbdrv_private *macp = dev->ml_priv; */
1875        struct iw_point *wri = (struct iw_point *)extra;
1876        char mode[8];
1877
1878        strcpy(mode, "11g");
1879        return copy_to_user(wri->pointer, mode, 6) ? -EFAULT : 0;
1880}
1881
1882int zfLnxPrivateIoctl(struct net_device *dev, struct zdap_ioctl* zdreq)
1883{
1884        /* void* regp = macp->regp; */
1885        u16_t cmd;
1886        /* u32_t temp; */
1887        u32_t *p;
1888        u32_t i;
1889
1890        cmd = zdreq->cmd;
1891        switch (cmd) {
1892        case ZM_IOCTL_REG_READ:
1893                zfiDbgReadReg(dev, zdreq->addr);
1894                break;
1895        case ZM_IOCTL_REG_WRITE:
1896                zfiDbgWriteReg(dev, zdreq->addr, zdreq->value);
1897                break;
1898        case ZM_IOCTL_MEM_READ:
1899                p = (u32_t *) bus_to_virt(zdreq->addr);
1900                printk(KERN_WARNING
1901                                "usbdrv: read memory addr: 0x%08x value:"
1902                                " 0x%08x\n", zdreq->addr, *p);
1903                break;
1904        case ZM_IOCTL_MEM_WRITE:
1905                p = (u32_t *) bus_to_virt(zdreq->addr);
1906                *p = zdreq->value;
1907                printk(KERN_WARNING
1908                        "usbdrv : write value : 0x%08x to memory addr :"
1909                        " 0x%08x\n", zdreq->value, zdreq->addr);
1910                break;
1911        case ZM_IOCTL_TALLY:
1912                zfiWlanShowTally(dev);
1913                if (zdreq->addr)
1914                        zfiWlanResetTally(dev);
1915                break;
1916        case ZM_IOCTL_TEST:
1917                printk(KERN_WARNING
1918                                "ZM_IOCTL_TEST:len=%d\n", zdreq->addr);
1919                /* zfiWlanReadReg(dev, 0x10f400); */
1920                /* zfiWlanReadReg(dev, 0x10f404); */
1921                printk(KERN_WARNING "IOCTL TEST\n");
1922                #if 1
1923                /* print packet */
1924                for (i = 0; i < zdreq->addr; i++) {
1925                        if ((i&0x7) == 0)
1926                                printk(KERN_WARNING "\n");
1927                        printk(KERN_WARNING "%02X ",
1928                                        (unsigned char)zdreq->data[i]);
1929                }
1930                printk(KERN_WARNING "\n");
1931                #endif
1932
1933                /* For Test?? 1 to 0 by CWYang(-) */
1934                #if 0
1935                        struct sk_buff *s;
1936
1937                        /* Allocate a skb */
1938                        s = alloc_skb(2000, GFP_ATOMIC);
1939
1940                        /* Copy data to skb */
1941                        for (i = 0; i < zdreq->addr; i++)
1942                                s->data[i] = zdreq->data[i];
1943                        s->len = zdreq->addr;
1944
1945                        /* Call zfIdlRecv() */
1946                        zfiRecv80211(dev, s, NULL);
1947                #endif
1948                break;
1949        /************************* ZDCONFIG ***************************/
1950        case ZM_IOCTL_FRAG:
1951                zfiWlanSetFragThreshold(dev, zdreq->addr);
1952                break;
1953        case ZM_IOCTL_RTS:
1954                zfiWlanSetRtsThreshold(dev, zdreq->addr);
1955                break;
1956        case ZM_IOCTL_SCAN:
1957                zfiWlanScan(dev);
1958                break;
1959        case ZM_IOCTL_KEY: {
1960                u8_t key[29];
1961                struct zsKeyInfo keyInfo;
1962                u32_t i;
1963
1964                for (i = 0; i < 29; i++)
1965                        key[i] = 0;
1966
1967                for (i = 0; i < zdreq->addr; i++)
1968                        key[i] = zdreq->data[i];
1969
1970                printk(KERN_WARNING
1971                        "key len=%d, key=%02x%02x%02x%02x%02x...\n",
1972                        zdreq->addr, key[0], key[1], key[2], key[3], key[4]);
1973
1974                keyInfo.keyLength = zdreq->addr;
1975                keyInfo.keyIndex = 0;
1976                keyInfo.flag = 0;
1977                keyInfo.key = key;
1978                zfiWlanSetKey(dev, keyInfo);
1979        }
1980                break;
1981        case ZM_IOCTL_RATE:
1982                zfiWlanSetTxRate(dev, zdreq->addr);
1983                break;
1984        case ZM_IOCTL_ENCRYPTION_MODE:
1985                zfiWlanSetEncryMode(dev, zdreq->addr);
1986
1987                zfiWlanDisable(dev, 0);
1988                zfiWlanEnable(dev);
1989                break;
1990                /* CWYang(+) */
1991        case ZM_IOCTL_SIGNAL_STRENGTH: {
1992                u8_t buffer[2];
1993                zfiWlanQuerySignalInfo(dev, &buffer[0]);
1994                printk(KERN_WARNING
1995                        "Current Signal Strength : %02d\n", buffer[0]);
1996        }
1997                break;
1998                /* CWYang(+) */
1999        case ZM_IOCTL_SIGNAL_QUALITY: {
2000                u8_t buffer[2];
2001                zfiWlanQuerySignalInfo(dev, &buffer[0]);
2002                printk(KERN_WARNING
2003                        "Current Signal Quality : %02d\n", buffer[1]);
2004        }
2005                break;
2006        case ZM_IOCTL_SET_PIBSS_MODE:
2007                if (zdreq->addr == 1)
2008                        zfiWlanSetWlanMode(dev, ZM_MODE_PSEUDO);
2009                else
2010                        zfiWlanSetWlanMode(dev, ZM_MODE_INFRASTRUCTURE);
2011
2012                zfiWlanDisable(dev, 0);
2013                zfiWlanEnable(dev);
2014                break;
2015        /********************* ZDCONFIG ***********************/
2016        default:
2017                printk(KERN_ERR "usbdrv: error command = %x\n", cmd);
2018                break;
2019        }
2020
2021        return 0;
2022}
2023
2024int usbdrv_wpa_ioctl(struct net_device *dev, struct athr_wlan_param *zdparm)
2025{
2026        int ret = 0;
2027        u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2028        u8_t mac_addr[80];
2029        struct zsKeyInfo keyInfo;
2030        struct usbdrv_private *macp = dev->ml_priv;
2031        u16_t vapId = 0;
2032        int ii;
2033
2034        /* zmw_get_wlan_dev(dev); */
2035
2036        switch (zdparm->cmd) {
2037        case ZD_CMD_SET_ENCRYPT_KEY:
2038                /* Set up key information */
2039                keyInfo.keyLength = zdparm->u.crypt.key_len;
2040                keyInfo.keyIndex = zdparm->u.crypt.idx;
2041                if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2042                        /* AP Mode */
2043                        keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR;
2044                } else
2045                        keyInfo.flag = 0;
2046                keyInfo.key = zdparm->u.crypt.key;
2047                keyInfo.initIv = zdparm->u.crypt.seq;
2048                keyInfo.macAddr = (u16_t *)zdparm->sta_addr;
2049
2050                /* Identify the MAC address information */
2051                if (memcmp(zdparm->sta_addr, bc_addr, sizeof(bc_addr)) == 0)
2052                        keyInfo.flag |= ZM_KEY_FLAG_GK;
2053                else
2054                        keyInfo.flag |= ZM_KEY_FLAG_PK;
2055
2056                if (!strcmp(zdparm->u.crypt.alg, "NONE")) {
2057                        /* u8_t zero_mac[]={0,0,0,0,0,0}; */
2058
2059                        /* Set key length to zero */
2060                        keyInfo.keyLength = 0;
2061
2062                        /* del group key */
2063                        if (zdparm->sta_addr[0] & 1) {
2064                                /* if (macp->cardSetting.WPAIeLen==0)
2065                                * { 802.1x dynamic WEP
2066                                *    mDynKeyMode = 0;
2067                                *    mKeyFormat[0] = 0;
2068                                *    mPrivacyInvoked[0]=FALSE;
2069                                *    mCap[0] &= ~CAP_PRIVACY;
2070                                *    macp->cardSetting.EncryOnOff[0]=0;
2071                                * }
2072                                * mWpaBcKeyLen = mGkInstalled = 0;
2073                                */
2074                        } else {
2075                                /* if (memcmp(zero_mac,zdparm->sta_addr, 6)==0)
2076                                * {
2077                                *     mDynKeyMode=0;
2078                                *    mKeyFormat[0]=0;
2079                                *    pSetting->DynKeyMode=0;
2080                                *    pSetting->EncryMode[0]=0;
2081                                *    mDynKeyMode=0;
2082                                * }
2083                                */
2084                        }
2085
2086                        printk(KERN_ERR "Set Encryption Type NONE\n");
2087                        return ret;
2088                } else if (!strcmp(zdparm->u.crypt.alg, "TKIP")) {
2089                        zfiWlanSetEncryMode(dev, ZM_TKIP);
2090                        /* //Linux Supplicant will inverse Tx/Rx key
2091                        * //So we inverse it back, CWYang(+)
2092                        * zfMemoryCopy(&temp[0], &keyInfo.key[16], 8);
2093                        * zfMemoryCopy(&keyInfo.key[16], keyInfo.key[24], 8);
2094                        * zfMemoryCopy(&keyInfo.key[24], &temp[0], 8);
2095                        * u8_t temp;
2096                        * int k;
2097                        * for (k = 0; k < 8; k++)
2098                        * {
2099                        *     temp = keyInfo.key[16 + k];
2100                        *     keyInfo.key[16 + k] = keyInfo.key[24 + k];
2101                        *     keyInfo.key[24 + k] = temp;
2102                        * }
2103                        * CamEncryType = ZM_TKIP;
2104                        * if (idx == 0)
2105                        * {   // Pairwise key
2106                        *     mKeyFormat[0] = CamEncryType;
2107                        *     mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_TKIP;
2108                        * }
2109                        */
2110                } else if (!strcmp(zdparm->u.crypt.alg, "CCMP")) {
2111                        zfiWlanSetEncryMode(dev, ZM_AES);
2112                        /* CamEncryType = ZM_AES;
2113                        * if (idx == 0)
2114                        * {  // Pairwise key
2115                        *    mKeyFormat[0] = CamEncryType;
2116                        *    mDynKeyMode = pSetting->DynKeyMode = DYN_KEY_AES;
2117                        * }
2118                        */
2119                } else if (!strcmp(zdparm->u.crypt.alg, "WEP")) {
2120                        if (keyInfo.keyLength == 5) {
2121                                /* WEP 64 */
2122                                zfiWlanSetEncryMode(dev, ZM_WEP64);
2123                                /* CamEncryType = ZM_WEP64; */
2124                                /* tmpDynKeyMode=DYN_KEY_WEP64; */
2125                        } else if (keyInfo.keyLength == 13) {
2126                                /* keylen=13, WEP 128 */
2127                                zfiWlanSetEncryMode(dev, ZM_WEP128);
2128                                /* CamEncryType = ZM_WEP128; */
2129                                /* tmpDynKeyMode=DYN_KEY_WEP128; */
2130                        } else {
2131                                zfiWlanSetEncryMode(dev, ZM_WEP256);
2132                        }
2133
2134        /* For Dynamic WEP key (Non-WPA Radius), the key ID range: 0-3
2135        * In WPA/RSN mode, the key ID range: 1-3, usually, a broadcast key.
2136        * For WEP key setting: we set mDynKeyMode and mKeyFormat in following
2137        * case:
2138        *   1. For 802.1x dynamically generated WEP key method.
2139        *   2. For WPA/RSN mode, but key id == 0.
2140        *       (But this is an impossible case)
2141        * So, only check case 1.
2142        * if (macp->cardSetting.WPAIeLen==0)
2143        * {
2144        *    mKeyFormat[0] = CamEncryType;
2145        *    mDynKeyMode = pSetting->DynKeyMode = tmpDynKeyMode;
2146        *    mPrivacyInvoked[0]=TRUE;
2147        *    mCap[0] |= CAP_PRIVACY;
2148        *    macp->cardSetting.EncryOnOff[0]=1;
2149        * }
2150        */
2151                }
2152
2153                /* DUMP key context */
2154                /* #ifdef WPA_DEBUG */
2155                if (keyInfo.keyLength > 0) {
2156                        printk(KERN_WARNING
2157                                                "Otus: Key Context:\n");
2158                        for (ii = 0; ii < keyInfo.keyLength; ) {
2159                                printk(KERN_WARNING
2160                                                "0x%02x ", keyInfo.key[ii]);
2161                                if ((++ii % 16) == 0)
2162                                        printk(KERN_WARNING "\n");
2163                        }
2164                        printk(KERN_WARNING "\n");
2165                }
2166                /* #endif */
2167
2168                /* Set encrypt mode */
2169                /* zfiWlanSetEncryMode(dev, CamEncryType); */
2170                vapId = zfLnxGetVapId(dev);
2171                if (vapId == 0xffff)
2172                        keyInfo.vapId = 0;
2173                else
2174                        keyInfo.vapId = vapId + 1;
2175                keyInfo.vapAddr[0] = keyInfo.macAddr[0];
2176                keyInfo.vapAddr[1] = keyInfo.macAddr[1];
2177                keyInfo.vapAddr[2] = keyInfo.macAddr[2];
2178
2179                zfiWlanSetKey(dev, keyInfo);
2180
2181                /* zfiWlanDisable(dev); */
2182                /* zfiWlanEnable(dev); */
2183                break;
2184        case ZD_CMD_SET_MLME:
2185                printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SET_MLME\n");
2186
2187                /* Translate STA's address */
2188                sprintf(mac_addr, "%02x:%02x:%02x:%02x:%02x:%02x",
2189                        zdparm->sta_addr[0], zdparm->sta_addr[1],
2190                        zdparm->sta_addr[2], zdparm->sta_addr[3],
2191                        zdparm->sta_addr[4], zdparm->sta_addr[5]);
2192
2193                switch (zdparm->u.mlme.cmd) {
2194                case MLME_STA_DEAUTH:
2195                        printk(KERN_WARNING
2196                                " -------Call zfiWlanDeauth, reason:%d\n",
2197                                zdparm->u.mlme.reason_code);
2198                        if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2199                                zdparm->u.mlme.reason_code) != 0)
2200                                printk(KERN_ERR "Can't deauthencate STA: %s\n",
2201                                        mac_addr);
2202                        else
2203                                printk(KERN_ERR "Deauthenticate STA: %s"
2204                                        "with reason code: %d\n",
2205                                        mac_addr, zdparm->u.mlme.reason_code);
2206                        break;
2207                case MLME_STA_DISASSOC:
2208                        printk(KERN_WARNING
2209                                " -------Call zfiWlanDeauth, reason:%d\n",
2210                                zdparm->u.mlme.reason_code);
2211                        if (zfiWlanDeauth(dev, (u16_t *) zdparm->sta_addr,
2212                                zdparm->u.mlme.reason_code) != 0)
2213                                printk(KERN_ERR "Can't disassociate STA: %s\n",
2214                                        mac_addr);
2215                        else
2216                                printk(KERN_ERR "Disassociate STA: %s"
2217                                        "with reason code: %d\n",
2218                                        mac_addr, zdparm->u.mlme.reason_code);
2219                        break;
2220                default:
2221                        printk(KERN_ERR "MLME command: 0x%04x not support\n",
2222                                zdparm->u.mlme.cmd);
2223                        break;
2224                }
2225
2226                break;
2227        case ZD_CMD_SCAN_REQ:
2228                printk(KERN_ERR "usbdrv_wpa_ioctl: ZD_CMD_SCAN_REQ\n");
2229                break;
2230        case ZD_CMD_SET_GENERIC_ELEMENT:
2231                printk(KERN_ERR "usbdrv_wpa_ioctl:"
2232                                        " ZD_CMD_SET_GENERIC_ELEMENT\n");
2233
2234                /* Copy the WPA IE
2235                * zm_msg1_mm(ZM_LV_0, "CWY - wpaie Length : ",
2236                * zdparm->u.generic_elem.len);
2237                */
2238                printk(KERN_ERR "wpaie Length : % d\n",
2239                                                zdparm->u.generic_elem.len);
2240                if (zfiWlanQueryWlanMode(dev) == ZM_MODE_AP) {
2241                        /* AP Mode */
2242                        zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2243                                        zdparm->u.generic_elem.len);
2244                } else {
2245                        macp->supLen = zdparm->u.generic_elem.len;
2246                        memcpy(macp->supIe, zdparm->u.generic_elem.data,
2247                                zdparm->u.generic_elem.len);
2248                }
2249                zfiWlanSetWpaSupport(dev, 1);
2250                /* zfiWlanSetWpaIe(dev, zdparm->u.generic_elem.data,
2251                * zdparm->u.generic_elem.len);
2252                */
2253                u8_t len = zdparm->u.generic_elem.len;
2254                u8_t *wpaie = (u8_t *)zdparm->u.generic_elem.data;
2255
2256                printk(KERN_ERR "wd->ap.wpaLen : % d\n", len);
2257
2258                /* DUMP WPA IE */
2259                for(ii = 0; ii < len;) {
2260                        printk(KERN_ERR "0x%02x ", wpaie[ii]);
2261
2262                        if((++ii % 16) == 0)
2263                                printk(KERN_ERR "\n");
2264                }
2265                printk(KERN_ERR "\n");
2266
2267                /* #ifdef ZM_HOSTAPD_SUPPORT
2268                * if (wd->wlanMode == ZM_MODE_AP)
2269                * {// Update Beacon FIFO in the next TBTT.
2270                *     memcpy(&mWPAIe, pSetting->WPAIe, pSetting->WPAIeLen);
2271                *     printk(KERN_ERR "Copy WPA IE into mWPAIe\n");
2272                * }
2273                * #endif
2274                */
2275                break;
2276
2277        /* #ifdef ZM_HOSTAPD_SUPPORT */
2278        case ZD_CMD_GET_TSC:
2279                printk(KERN_ERR "usbdrv_wpa_ioctl : ZD_CMD_GET_TSC\n");
2280                break;
2281        /* #endif */
2282
2283        default:
2284                printk(KERN_ERR "usbdrv_wpa_ioctl default : 0x%04x\n",
2285                        zdparm->cmd);
2286                ret = -EINVAL;
2287                break;
2288        }
2289
2290        return ret;
2291}
2292
2293#ifdef ZM_ENABLE_CENC
2294int usbdrv_cenc_ioctl(struct net_device *dev, struct zydas_cenc_param *zdparm)
2295{
2296        /* struct usbdrv_private *macp = dev->ml_priv; */
2297        struct zsKeyInfo keyInfo;
2298        u16_t apId;
2299        u8_t bc_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2300        int ret = 0;
2301        int ii;
2302
2303        /* Get the AP Id */
2304        apId = zfLnxGetVapId(dev);
2305
2306        if (apId == 0xffff) {
2307                apId = 0;
2308        } else {
2309                apId = apId + 1;
2310        }
2311
2312        switch (zdparm->cmd) {
2313        case ZM_CMD_CENC_SETCENC:
2314                printk(KERN_ERR "ZM_CMD_CENC_SETCENC\n");
2315                printk(KERN_ERR "length : % d\n", zdparm->len);
2316                printk(KERN_ERR "policy : % d\n", zdparm->u.info.cenc_policy);
2317                break;
2318        case ZM_CMD_CENC_SETKEY:
2319                /* ret = wai_ioctl_setkey(vap, ioctl_msg); */
2320                printk(KERN_ERR "ZM_CMD_CENC_SETKEY\n");
2321
2322                printk(KERN_ERR "MAC address = ");
2323                for (ii = 0; ii < 6; ii++) {
2324                        printk(KERN_ERR "0x%02x ",
2325                                zdparm->u.crypt.sta_addr[ii]);
2326                }
2327                printk(KERN_ERR "\n");
2328
2329                printk(KERN_ERR "Key Index : % d\n", zdparm->u.crypt.keyid);
2330                printk(KERN_ERR "Encryption key = ");
2331                for (ii = 0; ii < 16; ii++) {
2332                        printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2333                }
2334                printk(KERN_ERR "\n");
2335
2336                printk(KERN_ERR "MIC key = ");
2337                for(ii = 16; ii < ZM_CENC_KEY_SIZE; ii++) {
2338                        printk(KERN_ERR "0x%02x ", zdparm->u.crypt.key[ii]);
2339                }
2340                printk(KERN_ERR "\n");
2341
2342                /* Set up key information */
2343                keyInfo.keyLength = ZM_CENC_KEY_SIZE;
2344                keyInfo.keyIndex = zdparm->u.crypt.keyid;
2345                keyInfo.flag = ZM_KEY_FLAG_AUTHENTICATOR | ZM_KEY_FLAG_CENC;
2346                keyInfo.key = zdparm->u.crypt.key;
2347                keyInfo.macAddr = (u16_t *)zdparm->u.crypt.sta_addr;
2348
2349                /* Identify the MAC address information */
2350                if (memcmp(zdparm->u.crypt.sta_addr, bc_addr,
2351                                sizeof(bc_addr)) == 0) {
2352                        keyInfo.flag |= ZM_KEY_FLAG_GK;
2353                        keyInfo.vapId = apId;
2354                        memcpy(keyInfo.vapAddr, dev->dev_addr, ETH_ALEN);
2355                } else {
2356                        keyInfo.flag |= ZM_KEY_FLAG_PK;
2357                }
2358
2359                zfiWlanSetKey(dev, keyInfo);
2360
2361                break;
2362        case ZM_CMD_CENC_REKEY:
2363                /* ret = wai_ioctl_rekey(vap, ioctl_msg); */
2364                printk(KERN_ERR "ZM_CMD_CENC_REKEY\n");
2365                break;
2366        default:
2367                ret = -EOPNOTSUPP;
2368                break;
2369        }
2370
2371        /* if (retv == ENETRESET) */
2372        /* retv = IS_UP_AUTO(vap) ? ieee80211_open(vap->iv_dev) : 0; */
2373
2374        return ret;
2375}
2376#endif /* ZM_ENABLE_CENC */
2377
2378int usbdrv_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
2379{
2380        /* struct usbdrv_private *macp; */
2381        /* void *regp; */
2382        struct zdap_ioctl zdreq;
2383        struct iwreq *wrq = (struct iwreq *)ifr;
2384        struct athr_wlan_param zdparm;
2385        struct usbdrv_private *macp = dev->ml_priv;
2386
2387        int err = 0, val = 0;
2388        int changed = 0;
2389
2390        /* regp = macp->regp; */
2391
2392        if (!netif_running(dev))
2393                return -EINVAL;
2394
2395        switch (cmd) {
2396        case SIOCGIWNAME:
2397                strcpy(wrq->u.name, "IEEE 802.11-DS");
2398                break;
2399        case SIOCGIWAP:
2400                err = usbdrvwext_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2401                break;
2402        case SIOCSIWAP:
2403                err = usbdrvwext_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2404                break;
2405        case SIOCGIWMODE:
2406                err = usbdrvwext_giwmode(dev, NULL, &wrq->u.mode, NULL);
2407                break;
2408        case SIOCSIWESSID:
2409                printk(KERN_ERR "CWY - usbdrvwext_siwessid\n");
2410                /* err = usbdrv_ioctl_setessid(dev, &wrq->u.essid); */
2411                err = usbdrvwext_siwessid(dev, NULL, &wrq->u.essid, NULL);
2412
2413                if (!err)
2414                        changed = 1;
2415                break;
2416        case SIOCGIWESSID:
2417                err = usbdrvwext_giwessid(dev, NULL, &wrq->u.essid, NULL);
2418                break;
2419        case SIOCSIWRTS:
2420                err = usbdrv_ioctl_setrts(dev, &wrq->u.rts);
2421                if (! err)
2422                        changed = 1;
2423                break;
2424        /* set_auth */
2425        case SIOCIWFIRSTPRIV + 0x2: {
2426                /* printk("CWY - SIOCIWFIRSTPRIV + 0x2(set_auth)\n"); */
2427                if (!capable(CAP_NET_ADMIN)) {
2428                        err = -EPERM;
2429                        break;
2430                }
2431                val = *((int *) wrq->u.name);
2432                if ((val < 0) || (val > 2)) {
2433                        err = -EINVAL;
2434                        break;
2435                } else {
2436                        zfiWlanSetAuthenticationMode(dev, val);
2437
2438                        if (macp->DeviceOpened == 1) {
2439                                zfiWlanDisable(dev, 0);
2440                                zfiWlanEnable(dev);
2441                        }
2442
2443                        err = 0;
2444                        changed = 1;
2445                }
2446        }
2447                break;
2448        /* get_auth */
2449        case SIOCIWFIRSTPRIV + 0x3: {
2450                int AuthMode = ZM_AUTH_MODE_OPEN;
2451
2452                /* printk("CWY - SIOCIWFIRSTPRIV + 0x3(get_auth)\n"); */
2453
2454                if (wrq->u.data.pointer) {
2455                        wrq->u.data.flags = 1;
2456
2457                        AuthMode = zfiWlanQueryAuthenticationMode(dev, 0);
2458                        if (AuthMode == ZM_AUTH_MODE_OPEN) {
2459                                wrq->u.data.length = 12;
2460
2461                                if (copy_to_user(wrq->u.data.pointer,
2462                                        "open system", 12)) {
2463                                                return -EFAULT;
2464                                }
2465                        } else if (AuthMode == ZM_AUTH_MODE_SHARED_KEY) {
2466                                wrq->u.data.length = 11;
2467
2468                                if (copy_to_user(wrq->u.data.pointer,
2469                                        "shared key", 11)) {
2470                                                        return -EFAULT;
2471                                }
2472                        } else if (AuthMode == ZM_AUTH_MODE_AUTO) {
2473                                wrq->u.data.length = 10;
2474
2475                                if (copy_to_user(wrq->u.data.pointer,
2476                                        "auto mode", 10)) {
2477                                                        return -EFAULT;
2478                                }
2479                        } else {
2480                                return -EFAULT;
2481                        }
2482                }
2483        }
2484                break;
2485        /* debug command */
2486        case ZDAPIOCTL:
2487                if (copy_from_user(&zdreq, ifr->ifr_data, sizeof(zdreq))) {
2488                        printk(KERN_ERR "usbdrv : copy_from_user error\n");
2489                        return -EFAULT;
2490                }
2491
2492                /* printk(KERN_WARNING
2493                * "usbdrv : cmd = % 2x, reg = 0x%04lx,
2494                *value = 0x%08lx\n",
2495                * zdreq.cmd, zdreq.addr, zdreq.value);
2496                */
2497                zfLnxPrivateIoctl(dev, &zdreq);
2498
2499                err = 0;
2500                break;
2501        case ZD_IOCTL_WPA:
2502                if (copy_from_user(&zdparm, ifr->ifr_data,
2503                        sizeof(struct athr_wlan_param))) {
2504                        printk(KERN_ERR "usbdrv : copy_from_user error\n");
2505                        return -EFAULT;
2506                }
2507
2508                usbdrv_wpa_ioctl(dev, &zdparm);
2509                err = 0;
2510                break;
2511        case ZD_IOCTL_PARAM: {
2512                int *p;
2513                int op;
2514                int arg;
2515
2516                /* Point to the name field and retrieve the
2517                * op and arg elements.
2518                */
2519                p = (int *)wrq->u.name;
2520                op = *p++;
2521                arg = *p;
2522
2523                if (op == ZD_PARAM_ROAMING) {
2524                        printk(KERN_ERR
2525                        "*************ZD_PARAM_ROAMING : % d\n", arg);
2526                        /* macp->cardSetting.ap_scan=(U8)arg; */
2527                }
2528                if (op == ZD_PARAM_PRIVACY) {
2529                        printk(KERN_ERR "ZD_IOCTL_PRIVACY : ");
2530
2531                        /* Turn on the privacy invoke flag */
2532                        if (arg) {
2533                                /* mCap[0] |= CAP_PRIVACY; */
2534                                /* macp->cardSetting.EncryOnOff[0] = 1; */
2535                                printk(KERN_ERR "enable\n");
2536
2537                        } else {
2538                                /* mCap[0] &= ~CAP_PRIVACY; */
2539                                /* macp->cardSetting.EncryOnOff[0] = 0; */
2540                                printk(KERN_ERR "disable\n");
2541                        }
2542                        /* changed=1; */
2543                }
2544                if (op == ZD_PARAM_WPA) {
2545
2546                printk(KERN_ERR "ZD_PARAM_WPA : ");
2547
2548                if (arg) {
2549                        printk(KERN_ERR "enable\n");
2550
2551                        if (zfiWlanQueryWlanMode(dev) != ZM_MODE_AP) {
2552                                printk(KERN_ERR "Station Mode\n");
2553                                /* zfiWlanQueryWpaIe(dev, (u8_t *)
2554                                        &wpaIe, &wpalen); */
2555                                /* printk("wpaIe : % 2x, % 2x, % 2x\n",
2556                                        wpaIe[21], wpaIe[22], wpaIe[23]); */
2557                                /* printk("rsnIe : % 2x, % 2x, % 2x\n",
2558                                        wpaIe[17], wpaIe[18], wpaIe[19]); */
2559                                if ((macp->supIe[21] == 0x50) &&
2560                                        (macp->supIe[22] == 0xf2) &&
2561                                        (macp->supIe[23] == 0x2)) {
2562                                        printk(KERN_ERR
2563                                "wd->sta.authMode = ZM_AUTH_MODE_WPAPSK\n");
2564                                /* wd->sta.authMode = ZM_AUTH_MODE_WPAPSK; */
2565                                /* wd->ws.authMode = ZM_AUTH_MODE_WPAPSK; */
2566                                zfiWlanSetAuthenticationMode(dev,
2567                                                        ZM_AUTH_MODE_WPAPSK);
2568                                } else if ((macp->supIe[21] == 0x50) &&
2569                                        (macp->supIe[22] == 0xf2) &&
2570                                        (macp->supIe[23] == 0x1)) {
2571                                        printk(KERN_ERR
2572                                "wd->sta.authMode = ZM_AUTH_MODE_WPA\n");
2573                                /* wd->sta.authMode = ZM_AUTH_MODE_WPA; */
2574                                /* wd->ws.authMode = ZM_AUTH_MODE_WPA; */
2575                                zfiWlanSetAuthenticationMode(dev,
2576                                                        ZM_AUTH_MODE_WPA);
2577                                        } else if ((macp->supIe[17] == 0xf) &&
2578                                                (macp->supIe[18] == 0xac) &&
2579                                                (macp->supIe[19] == 0x2))
2580                                        {
2581                                                printk(KERN_ERR
2582                                "wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK\n");
2583                                /* wd->sta.authMode = ZM_AUTH_MODE_WPA2PSK; */
2584                                /* wd->ws.authMode = ZM_AUTH_MODE_WPA2PSK; */
2585                                zfiWlanSetAuthenticationMode(dev,
2586                                ZM_AUTH_MODE_WPA2PSK);
2587                        } else if ((macp->supIe[17] == 0xf) &&
2588                                (macp->supIe[18] == 0xac) &&
2589                                (macp->supIe[19] == 0x1))
2590                                {
2591                                        printk(KERN_ERR
2592                                "wd->sta.authMode = ZM_AUTH_MODE_WPA2\n");
2593                                /* wd->sta.authMode = ZM_AUTH_MODE_WPA2; */
2594                                /* wd->ws.authMode = ZM_AUTH_MODE_WPA2; */
2595                                zfiWlanSetAuthenticationMode(dev,
2596                                                        ZM_AUTH_MODE_WPA2);
2597                        }
2598                        /* WPA or WPAPSK */
2599                        if ((macp->supIe[21] == 0x50) ||
2600                                (macp->supIe[22] == 0xf2)) {
2601                                if (macp->supIe[11] == 0x2) {
2602                                        printk(KERN_ERR
2603                                "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2604                                /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2605                                /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2606                                zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2607                        } else {
2608                                printk(KERN_ERR
2609                                "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2610                                /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2611                                /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2612                                zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2613                                }
2614                        }
2615                        //WPA2 or WPA2PSK
2616                        if ((macp->supIe[17] == 0xf) ||
2617                                (macp->supIe[18] == 0xac)) {
2618                                if (macp->supIe[13] == 0x2) {
2619                                        printk(KERN_ERR
2620                                "wd->sta.wepStatus = ZM_ENCRYPTION_TKIP\n");
2621                                /* wd->sta.wepStatus = ZM_ENCRYPTION_TKIP; */
2622                                /* wd->ws.wepStatus = ZM_ENCRYPTION_TKIP; */
2623                                zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_TKIP);
2624                                } else {
2625                                        printk(KERN_ERR
2626                                "wd->sta.wepStatus = ZM_ENCRYPTION_AES\n");
2627                                /* wd->sta.wepStatus = ZM_ENCRYPTION_AES; */
2628                                /* wd->ws.wepStatus = ZM_ENCRYPTION_AES; */
2629                                zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_AES);
2630                                        }
2631                                }
2632                        }
2633                        zfiWlanSetWpaSupport(dev, 1);
2634                } else {
2635                        /* Reset the WPA related variables */
2636                        printk(KERN_ERR "disable\n");
2637
2638                        zfiWlanSetWpaSupport(dev, 0);
2639                        zfiWlanSetAuthenticationMode(dev, ZM_AUTH_MODE_OPEN);
2640                        zfiWlanSetWepStatus(dev, ZM_ENCRYPTION_WEP_DISABLED);
2641
2642                        /* Now we only set the length in the WPA IE
2643                        * field to zero.
2644                        *macp->cardSetting.WPAIe[1] = 0;
2645                        */
2646                        }
2647                }
2648
2649                if (op == ZD_PARAM_COUNTERMEASURES) {
2650                        printk(KERN_ERR
2651                                "****************ZD_PARAM_COUNTERMEASURES : ");
2652
2653                        if(arg) {
2654                                /*    mCounterMeasureState=1; */
2655                                printk(KERN_ERR "enable\n");
2656                        } else {
2657                                /*    mCounterMeasureState=0; */
2658                                printk(KERN_ERR "disable\n");
2659                        }
2660                }
2661                if (op == ZD_PARAM_DROPUNENCRYPTED) {
2662                        printk(KERN_ERR "ZD_PARAM_DROPUNENCRYPTED : ");
2663
2664                        if(arg) {
2665                                printk(KERN_ERR "enable\n");
2666                        } else {
2667                                printk(KERN_ERR "disable\n");
2668                        }
2669                }
2670                if (op == ZD_PARAM_AUTH_ALGS) {
2671                        printk(KERN_ERR "ZD_PARAM_AUTH_ALGS : ");
2672
2673                        if (arg == 0) {
2674                                printk(KERN_ERR "OPEN_SYSTEM\n");
2675                        } else {
2676                                printk(KERN_ERR "SHARED_KEY\n");
2677                        }
2678                }
2679                if (op == ZD_PARAM_WPS_FILTER) {
2680                        printk(KERN_ERR "ZD_PARAM_WPS_FILTER : ");
2681
2682                        if (arg) {
2683                                /*    mCounterMeasureState=1; */
2684                                macp->forwardMgmt = 1;
2685                                printk(KERN_ERR "enable\n");
2686                        } else {
2687                                /*    mCounterMeasureState=0; */
2688                                macp->forwardMgmt = 0;
2689                                printk(KERN_ERR "disable\n");
2690                        }
2691                }
2692        }
2693                err = 0;
2694                break;
2695        case ZD_IOCTL_GETWPAIE: {
2696                struct ieee80211req_wpaie req_wpaie;
2697                u16_t apId, i, j;
2698
2699                /* Get the AP Id */
2700                apId = zfLnxGetVapId(dev);
2701
2702                if (apId == 0xffff) {
2703                        apId = 0;
2704                } else {
2705                        apId = apId + 1;
2706                }
2707
2708                if (copy_from_user(&req_wpaie, ifr->ifr_data,
2709                                        sizeof(struct ieee80211req_wpaie))) {
2710                        printk(KERN_ERR "usbdrv : copy_from_user error\n");
2711                        return -EFAULT;
2712                }
2713
2714                for (i = 0; i < ZM_OAL_MAX_STA_SUPPORT; i++) {
2715                        for (j = 0; j < IEEE80211_ADDR_LEN; j++) {
2716                                if (macp->stawpaie[i].wpa_macaddr[j] !=
2717                                                req_wpaie.wpa_macaddr[j])
2718                                break;
2719                        }
2720                        if (j == 6)
2721                        break;
2722                }
2723
2724                if (i < ZM_OAL_MAX_STA_SUPPORT) {
2725                /* printk("ZD_IOCTL_GETWPAIE - sta index = % d\n", i); */
2726                memcpy(req_wpaie.wpa_ie, macp->stawpaie[i].wpa_ie,
2727                                                        IEEE80211_MAX_IE_SIZE);
2728                }
2729
2730                if (copy_to_user(wrq->u.data.pointer, &req_wpaie,
2731                                sizeof(struct ieee80211req_wpaie))) {
2732                        return -EFAULT;
2733                }
2734        }
2735
2736                err = 0;
2737                break;
2738        #ifdef ZM_ENABLE_CENC
2739        case ZM_IOCTL_CENC:
2740                if (copy_from_user(&macp->zd_wpa_req, ifr->ifr_data,
2741                        sizeof(struct athr_wlan_param))) {
2742                        printk(KERN_ERR "usbdrv : copy_from_user error\n");
2743                        return -EFAULT;
2744                }
2745
2746                usbdrv_cenc_ioctl(dev,
2747                                (struct zydas_cenc_param *)&macp->zd_wpa_req);
2748                err = 0;
2749                break;
2750        #endif /* ZM_ENABLE_CENC */
2751        default:
2752                err = -EOPNOTSUPP;
2753                break;
2754        }
2755
2756        return err;
2757}
2758