linux/drivers/staging/vt6656/wcmd.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
   3 * All rights reserved.
   4 *
   5 * This program is free software; you can redistribute it and/or modify
   6 * it under the terms of the GNU General Public License as published by
   7 * the Free Software Foundation; either version 2 of the License, or
   8 * (at your option) any later version.
   9 *
  10 * This program is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13 * GNU General Public License for more details.
  14 *
  15 * You should have received a copy of the GNU General Public License along
  16 * with this program; if not, write to the Free Software Foundation, Inc.,
  17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18 *
  19 * File: wcmd.c
  20 *
  21 * Purpose: Handles the management command interface functions
  22 *
  23 * Author: Lyndon Chen
  24 *
  25 * Date: May 8, 2003
  26 *
  27 * Functions:
  28 *      s_vProbeChannel - Active scan channel
  29 *      s_MgrMakeProbeRequest - Make ProbeRequest packet
  30 *      CommandTimer - Timer function to handle command
  31 *      s_bCommandComplete - Command Complete function
  32 *      bScheduleCommand - Push Command and wait Command Scheduler to do
  33 *      vCommandTimer- Command call back functions
  34 *      vCommandTimerWait- Call back timer
  35 *      s_bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
  36 *
  37 * Revision History:
  38 *
  39 */
  40
  41#include "tmacro.h"
  42#include "device.h"
  43#include "mac.h"
  44#include "card.h"
  45#include "80211hdr.h"
  46#include "wcmd.h"
  47#include "wmgr.h"
  48#include "power.h"
  49#include "wctl.h"
  50#include "baseband.h"
  51#include "control.h"
  52#include "rxtx.h"
  53#include "rf.h"
  54#include "rndis.h"
  55#include "channel.h"
  56#include "iowpa.h"
  57
  58static int msglevel = MSG_LEVEL_INFO;
  59//static int msglevel = MSG_LEVEL_DEBUG;
  60
  61static void s_vProbeChannel(struct vnt_private *);
  62
  63static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *,
  64        struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
  65        PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
  66
  67static int s_bCommandComplete(struct vnt_private *);
  68
  69static int s_bClearBSSID_SCAN(struct vnt_private *);
  70
  71/*
  72 * Description:
  73 *      Stop AdHoc beacon during scan process
  74 *
  75 * Parameters:
  76 *  In:
  77 *      pDevice     - Pointer to the adapter
  78 *  Out:
  79 *      none
  80 *
  81 * Return Value: none
  82 *
  83 */
  84
  85static void vAdHocBeaconStop(struct vnt_private *pDevice)
  86{
  87        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
  88        int bStop;
  89
  90        /*
  91         * temporarily stop Beacon packet for AdHoc Server
  92         * if all of the following coditions are met:
  93         *  (1) STA is in AdHoc mode
  94         *  (2) VT3253 is programmed as automatic Beacon Transmitting
  95         *  (3) One of the following conditions is met
  96         *      (3.1) AdHoc channel is in B/G band and the
  97         *      current scan channel is in A band
  98         *      or
  99         *      (3.2) AdHoc channel is in A mode
 100         */
 101        bStop = false;
 102        if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
 103            (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
 104                if ((pMgmt->uIBSSChannel <=  CB_MAX_CHANNEL_24G) &&
 105                    (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
 106                        bStop = true;
 107                }
 108                if (pMgmt->uIBSSChannel >  CB_MAX_CHANNEL_24G)
 109                        bStop = true;
 110        }
 111
 112        if (bStop) {
 113                //PMESG(("STOP_BEACON: IBSSChannel = %u, ScanChannel = %u\n",
 114                //        pMgmt->uIBSSChannel, pMgmt->uScanChannel));
 115                MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
 116        }
 117
 118} /* vAdHocBeaconStop */
 119
 120/*
 121 * Description:
 122 *      Restart AdHoc beacon after scan process complete
 123 *
 124 * Parameters:
 125 *  In:
 126 *      pDevice     - Pointer to the adapter
 127 *  Out:
 128 *      none
 129 *
 130 * Return Value: none
 131 *
 132 */
 133static void vAdHocBeaconRestart(struct vnt_private *pDevice)
 134{
 135        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
 136
 137    /*
 138     * Restart Beacon packet for AdHoc Server
 139     * if all of the following coditions are met:
 140     *  (1) STA is in AdHoc mode
 141     *  (2) VT3253 is programmed as automatic Beacon Transmitting
 142     */
 143        if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
 144            (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
 145                //PMESG(("RESTART_BEACON\n"));
 146                MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
 147        }
 148
 149}
 150
 151/*+
 152 *
 153 * Routine Description:
 154 *   Prepare and send probe request management frames.
 155 *
 156 *
 157 * Return Value:
 158 *    none.
 159 *
 160-*/
 161
 162static void s_vProbeChannel(struct vnt_private *pDevice)
 163{
 164        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
 165        struct vnt_tx_mgmt *pTxPacket;
 166        u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
 167                        8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
 168                        /* 1M,   2M,   5M,   11M,  18M,  24M,  36M,  54M*/
 169        u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
 170                        4, 0x0C, 0x12, 0x18, 0x60};
 171                        /* 6M,   9M,   12M,  48M*/
 172        u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
 173                        8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
 174        u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
 175                        4, 0x02, 0x04, 0x0B, 0x16};
 176        u8 *pbyRate;
 177        int ii;
 178
 179        if (pDevice->byBBType == BB_TYPE_11A)
 180                pbyRate = &abyCurrSuppRatesA[0];
 181        else if (pDevice->byBBType == BB_TYPE_11B)
 182                pbyRate = &abyCurrSuppRatesB[0];
 183        else
 184                pbyRate = &abyCurrSuppRatesG[0];
 185
 186        // build an assocreq frame and send it
 187        pTxPacket = s_MgrMakeProbeRequest
 188                    (
 189                     pDevice,
 190                     pMgmt,
 191                     pMgmt->abyScanBSSID,
 192                     (PWLAN_IE_SSID)pMgmt->abyScanSSID,
 193                     (PWLAN_IE_SUPP_RATES)pbyRate,
 194                     (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
 195                     );
 196
 197        if (pTxPacket != NULL) {
 198                for (ii = 0; ii < 1; ii++) {
 199                        if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
 200                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail..\n");
 201                        } else {
 202                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending..\n");
 203                        }
 204                }
 205        }
 206
 207}
 208
 209/*+
 210 *
 211 * Routine Description:
 212 *  Constructs an probe request frame
 213 *
 214 *
 215 * Return Value:
 216 *    A ptr to Tx frame or NULL on allocation failure
 217 *
 218-*/
 219
 220static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice,
 221        struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
 222        PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
 223{
 224        struct vnt_tx_mgmt *pTxPacket = NULL;
 225        WLAN_FR_PROBEREQ sFrame;
 226
 227        pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
 228        memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
 229                + WLAN_PROBEREQ_FR_MAXLEN);
 230        pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
 231                + sizeof(struct vnt_tx_mgmt));
 232        sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
 233        sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
 234        vMgrEncodeProbeRequest(&sFrame);
 235        sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
 236                (
 237                 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
 238                 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
 239                 ));
 240        memcpy(sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
 241        memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
 242        memcpy(sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
 243        // Copy the SSID, pSSID->len=0 indicate broadcast SSID
 244        sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
 245        sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
 246        memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
 247        sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
 248        sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
 249        memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
 250        // Copy the extension rate set
 251        if (pDevice->byBBType == BB_TYPE_11G) {
 252                sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
 253                sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
 254                memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
 255        }
 256        pTxPacket->cbMPDULen = sFrame.len;
 257        pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
 258
 259        return pTxPacket;
 260}
 261
 262static void
 263vCommandTimerWait(struct vnt_private *pDevice, unsigned long MSecond)
 264{
 265        schedule_delayed_work(&pDevice->run_command_work,
 266                                                msecs_to_jiffies(MSecond));
 267}
 268
 269void vRunCommand(struct work_struct *work)
 270{
 271        struct vnt_private *pDevice =
 272                container_of(work, struct vnt_private, run_command_work.work);
 273        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
 274        PWLAN_IE_SSID pItemSSID;
 275        PWLAN_IE_SSID pItemSSIDCurr;
 276        CMD_STATUS Status;
 277        struct sk_buff  *skb;
 278        union iwreq_data wrqu;
 279        int ii;
 280        u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
 281        u8 byData;
 282
 283        if (pDevice->Flags & fMP_DISCONNECTED)
 284                return;
 285
 286        if (pDevice->bCmdRunning != true)
 287                return;
 288
 289        spin_lock_irq(&pDevice->lock);
 290
 291        switch (pDevice->eCommandState) {
 292
 293        case WLAN_CMD_SCAN_START:
 294
 295                pDevice->byReAssocCount = 0;
 296                if (pDevice->bRadioOff == true)
 297                        break;
 298
 299                if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
 300                        break;
 301
 302                pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
 303
 304                if (pMgmt->uScanChannel == 0)
 305                        pMgmt->uScanChannel = pDevice->byMinChannel;
 306                if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
 307                        pDevice->eCommandState = WLAN_CMD_SCAN_END;
 308                        break;
 309                } else {
 310                        if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
 311                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d\n", pMgmt->uScanChannel);
 312                                pMgmt->uScanChannel++;
 313                                break;
 314                        }
 315                        if (pMgmt->uScanChannel == pDevice->byMinChannel) {
 316                                // pMgmt->eScanType = WMAC_SCAN_ACTIVE;          //mike mark
 317                                pMgmt->abyScanBSSID[0] = 0xFF;
 318                                pMgmt->abyScanBSSID[1] = 0xFF;
 319                                pMgmt->abyScanBSSID[2] = 0xFF;
 320                                pMgmt->abyScanBSSID[3] = 0xFF;
 321                                pMgmt->abyScanBSSID[4] = 0xFF;
 322                                pMgmt->abyScanBSSID[5] = 0xFF;
 323                                pItemSSID->byElementID = WLAN_EID_SSID;
 324                                // clear bssid list
 325                                /* BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass); */
 326                                pMgmt->eScanState = WMAC_IS_SCANNING;
 327                                pDevice->byScanBBType = pDevice->byBBType;  //lucas
 328                                pDevice->bStopDataPkt = true;
 329                                // Turn off RCR_BSSID filter every time
 330                                MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
 331                                pDevice->byRxMode &= ~RCR_BSSID;
 332                        }
 333                        //lucas
 334                        vAdHocBeaconStop(pDevice);
 335                        if ((pDevice->byBBType != BB_TYPE_11A) &&
 336                            (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
 337                                pDevice->byBBType = BB_TYPE_11A;
 338                                CARDvSetBSSMode(pDevice);
 339                        } else if ((pDevice->byBBType == BB_TYPE_11A) &&
 340                                   (pMgmt->uScanChannel <= CB_MAX_CHANNEL_24G)) {
 341                                pDevice->byBBType = BB_TYPE_11G;
 342                                CARDvSetBSSMode(pDevice);
 343                        }
 344                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning....  channel: [%d]\n", pMgmt->uScanChannel);
 345                        // Set channel
 346                        CARDbSetMediaChannel(pDevice, pMgmt->uScanChannel);
 347                        // Set Baseband to be more sensitive.
 348
 349                        if (pDevice->bUpdateBBVGA) {
 350                                BBvSetShortSlotTime(pDevice);
 351                                BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
 352                                BBvUpdatePreEDThreshold(pDevice, true);
 353                        }
 354                        pMgmt->uScanChannel++;
 355
 356                        while (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
 357                                pMgmt->uScanChannel <= pDevice->byMaxChannel){
 358                                pMgmt->uScanChannel++;
 359                        }
 360
 361                        if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
 362                                // Set Baseband to be not sensitive and rescan
 363                                pDevice->eCommandState = WLAN_CMD_SCAN_END;
 364                        }
 365                        if ((pMgmt->b11hEnable == false) ||
 366                            (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
 367                                s_vProbeChannel(pDevice);
 368                                spin_unlock_irq(&pDevice->lock);
 369                                vCommandTimerWait((void *) pDevice, 100);
 370                                return;
 371                        } else {
 372                                spin_unlock_irq(&pDevice->lock);
 373                                vCommandTimerWait((void *) pDevice, WCMD_PASSIVE_SCAN_TIME);
 374                                return;
 375                        }
 376                }
 377
 378                break;
 379
 380        case WLAN_CMD_SCAN_END:
 381
 382                // Set Baseband's sensitivity back.
 383                if (pDevice->byBBType != pDevice->byScanBBType) {
 384                        pDevice->byBBType = pDevice->byScanBBType;
 385                        CARDvSetBSSMode(pDevice);
 386                }
 387
 388                if (pDevice->bUpdateBBVGA) {
 389                        BBvSetShortSlotTime(pDevice);
 390                        BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
 391                        BBvUpdatePreEDThreshold(pDevice, false);
 392                }
 393
 394                // Set channel back
 395                vAdHocBeaconRestart(pDevice);
 396                // Set channel back
 397                CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
 398                // Set Filter
 399                if (pMgmt->bCurrBSSIDFilterOn) {
 400                        MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
 401                        pDevice->byRxMode |= RCR_BSSID;
 402                }
 403                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
 404                pMgmt->uScanChannel = 0;
 405                pMgmt->eScanState = WMAC_NO_SCANNING;
 406                pDevice->bStopDataPkt = false;
 407
 408                /*send scan event to wpa_Supplicant*/
 409                PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
 410                memset(&wrqu, 0, sizeof(wrqu));
 411                wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
 412
 413                break;
 414
 415        case WLAN_CMD_DISASSOCIATE_START:
 416                pDevice->byReAssocCount = 0;
 417                if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
 418                    (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
 419                        break;
 420                } else {
 421                        pDevice->bwextstep0 = false;
 422                        pDevice->bwextstep1 = false;
 423                        pDevice->bwextstep2 = false;
 424                        pDevice->bwextstep3 = false;
 425                        pDevice->bWPASuppWextEnabled = false;
 426                        pDevice->fWPA_Authened = false;
 427
 428                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
 429                        // reason = 8 : disassoc because sta has left
 430                        vMgrDisassocBeginSta((void *) pDevice,
 431                                             pMgmt,
 432                                             pMgmt->abyCurrBSSID,
 433                                             (8),
 434                                             &Status);
 435                        pDevice->bLinkPass = false;
 436                        ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_SLOW);
 437                        // unlock command busy
 438                        pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
 439                        pItemSSID->len = 0;
 440                        memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
 441                        pMgmt->eCurrState = WMAC_STATE_IDLE;
 442                        pMgmt->sNodeDBTable[0].bActive = false;
 443//                      pDevice->bBeaconBufReady = false;
 444                }
 445                netif_stop_queue(pDevice->dev);
 446                if (pDevice->bNeedRadioOFF == true)
 447                        CARDbRadioPowerOff(pDevice);
 448
 449                break;
 450
 451        case WLAN_CMD_SSID_START:
 452
 453                pDevice->byReAssocCount = 0;
 454                if (pDevice->bRadioOff == true)
 455                        break;
 456
 457                memcpy(pMgmt->abyAdHocSSID, pMgmt->abyDesireSSID,
 458                       ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
 459
 460                pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
 461                pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
 462                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
 463                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
 464
 465                if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
 466                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
 467                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n", pItemSSID->len);
 468                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n", pItemSSIDCurr->len);
 469                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
 470                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
 471                }
 472
 473                if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
 474                    ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
 475                        if (pItemSSID->len == pItemSSIDCurr->len) {
 476                                if (!memcmp(pItemSSID->abySSID,
 477                                        pItemSSIDCurr->abySSID, pItemSSID->len))
 478                                        break;
 479                        }
 480                        netif_stop_queue(pDevice->dev);
 481                        pDevice->bLinkPass = false;
 482                        ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_SLOW);
 483                }
 484                // set initial state
 485                pMgmt->eCurrState = WMAC_STATE_IDLE;
 486                pMgmt->eCurrMode = WMAC_MODE_STANDBY;
 487                PSvDisablePowerSaving((void *) pDevice);
 488                BSSvClearNodeDBTable(pDevice, 0);
 489                vMgrJoinBSSBegin((void *) pDevice, &Status);
 490                // if Infra mode
 491                if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
 492                        // Call mgr to begin the deauthentication
 493                        // reason = (3) because sta has left ESS
 494                        if (pMgmt->eCurrState >= WMAC_STATE_AUTH) {
 495                                vMgrDeAuthenBeginSta((void *)pDevice,
 496                                                     pMgmt,
 497                                                     pMgmt->abyCurrBSSID,
 498                                                     (3),
 499                                                     &Status);
 500                        }
 501                        // Call mgr to begin the authentication
 502                        vMgrAuthenBeginSta((void *) pDevice, pMgmt, &Status);
 503                        if (Status == CMD_STATUS_SUCCESS) {
 504                                pDevice->byLinkWaitCount = 0;
 505                                pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
 506                                vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT);
 507                                spin_unlock_irq(&pDevice->lock);
 508                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
 509                                return;
 510                        }
 511                }
 512                // if Adhoc mode
 513                else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
 514                        if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
 515                                if (netif_queue_stopped(pDevice->dev))
 516                                        netif_wake_queue(pDevice->dev);
 517                                pDevice->bLinkPass = true;
 518                                ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_INTER);
 519                                pMgmt->sNodeDBTable[0].bActive = true;
 520                                pMgmt->sNodeDBTable[0].uInActiveCount = 0;
 521                        } else {
 522                                // start own IBSS
 523                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CreateOwn IBSS by CurrMode = IBSS_STA\n");
 524                                vMgrCreateOwnIBSS((void *) pDevice, &Status);
 525                                if (Status != CMD_STATUS_SUCCESS) {
 526                                        DBG_PRT(MSG_LEVEL_DEBUG,
 527                                                KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
 528                                }
 529                                BSSvAddMulticastNode(pDevice);
 530                        }
 531                        s_bClearBSSID_SCAN(pDevice);
 532                }
 533                // if SSID not found
 534                else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
 535                        if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
 536                            pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
 537                                // start own IBSS
 538                                DBG_PRT(MSG_LEVEL_DEBUG,
 539                                        KERN_INFO "CreateOwn IBSS by CurrMode = STANDBY\n");
 540                                vMgrCreateOwnIBSS((void *) pDevice, &Status);
 541                                if (Status != CMD_STATUS_SUCCESS) {
 542                                        DBG_PRT(MSG_LEVEL_DEBUG,
 543                                                KERN_INFO "WLAN_CMD_IBSS_CREATE fail!\n");
 544                                }
 545                                BSSvAddMulticastNode(pDevice);
 546                                s_bClearBSSID_SCAN(pDevice);
 547/*
 548                                pDevice->bLinkPass = true;
 549                                ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
 550                                if (netif_queue_stopped(pDevice->dev)){
 551                                        netif_wake_queue(pDevice->dev);
 552                                }
 553                                s_bClearBSSID_SCAN(pDevice);
 554*/
 555                        } else {
 556                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
 557                                // if(pDevice->bWPASuppWextEnabled == true)
 558                                {
 559                                        union iwreq_data  wrqu;
 560                                        memset(&wrqu, 0, sizeof(wrqu));
 561                                        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
 562                                        PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
 563                                        wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
 564                                }
 565                        }
 566                }
 567                break;
 568
 569        case WLAN_AUTHENTICATE_WAIT:
 570                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
 571                if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
 572                        pDevice->byLinkWaitCount = 0;
 573                        // Call mgr to begin the association
 574                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
 575                        vMgrAssocBeginSta((void *) pDevice, pMgmt, &Status);
 576                        if (Status == CMD_STATUS_SUCCESS) {
 577                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
 578                                pDevice->byLinkWaitCount = 0;
 579                                pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
 580                                vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT);
 581                                spin_unlock_irq(&pDevice->lock);
 582                                return;
 583                        }
 584                } else if (pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
 585                        printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
 586                } else if (pDevice->byLinkWaitCount <= 4) {
 587                        //mike add:wait another 2 sec if authenticated_frame delay!
 588                        pDevice->byLinkWaitCount++;
 589                        printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
 590                        spin_unlock_irq(&pDevice->lock);
 591                        vCommandTimerWait((void *) pDevice, AUTHENTICATE_TIMEOUT/2);
 592                        return;
 593                }
 594                pDevice->byLinkWaitCount = 0;
 595
 596                break;
 597
 598        case WLAN_ASSOCIATE_WAIT:
 599                if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
 600                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
 601                        if (pDevice->ePSMode != WMAC_POWER_CAM) {
 602                                PSvEnablePowerSaving((void *) pDevice,
 603                                                pMgmt->wListenInterval);
 604                        }
 605/*
 606                        if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
 607                                KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
 608                        }
 609*/
 610                        pDevice->byLinkWaitCount = 0;
 611                        pDevice->byReAssocCount = 0;
 612                        pDevice->bLinkPass = true;
 613                        ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_INTER);
 614                        s_bClearBSSID_SCAN(pDevice);
 615
 616                        if (netif_queue_stopped(pDevice->dev))
 617                                netif_wake_queue(pDevice->dev);
 618
 619                } else if (pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
 620                        printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
 621                } else if (pDevice->byLinkWaitCount <= 4) {
 622                        //mike add:wait another 2 sec if associated_frame delay!
 623                        pDevice->byLinkWaitCount++;
 624                        printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
 625                        spin_unlock_irq(&pDevice->lock);
 626                        vCommandTimerWait((void *) pDevice, ASSOCIATE_TIMEOUT/2);
 627                        return;
 628                }
 629
 630                break;
 631
 632        case WLAN_CMD_AP_MODE_START:
 633                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
 634
 635                if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
 636                        cancel_delayed_work_sync(&pDevice->second_callback_work);
 637                        pMgmt->eCurrState = WMAC_STATE_IDLE;
 638                        pMgmt->eCurrMode = WMAC_MODE_STANDBY;
 639                        pDevice->bLinkPass = false;
 640                        ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_SLOW);
 641                        if (pDevice->bEnableHostWEP == true)
 642                                BSSvClearNodeDBTable(pDevice, 1);
 643                        else
 644                                BSSvClearNodeDBTable(pDevice, 0);
 645                        pDevice->uAssocCount = 0;
 646                        pMgmt->eCurrState = WMAC_STATE_IDLE;
 647                        pDevice->bFixRate = false;
 648
 649                        vMgrCreateOwnIBSS((void *) pDevice, &Status);
 650                        if (Status != CMD_STATUS_SUCCESS) {
 651                                DBG_PRT(MSG_LEVEL_DEBUG,
 652                                        KERN_INFO "vMgrCreateOwnIBSS fail!\n");
 653                        }
 654                        // always turn off unicast bit
 655                        MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_UNICAST);
 656                        pDevice->byRxMode &= ~RCR_UNICAST;
 657                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode);
 658                        BSSvAddMulticastNode(pDevice);
 659                        if (netif_queue_stopped(pDevice->dev))
 660                                netif_wake_queue(pDevice->dev);
 661                        pDevice->bLinkPass = true;
 662                        ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_INTER);
 663                        schedule_delayed_work(&pDevice->second_callback_work, HZ);
 664                }
 665                break;
 666
 667        case WLAN_CMD_TX_PSPACKET_START:
 668                // DTIM Multicast tx
 669                if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
 670                        while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
 671                                if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
 672                                        pMgmt->abyPSTxMap[0] &= ~byMask[0];
 673                                        pDevice->bMoreData = false;
 674                                } else {
 675                                        pDevice->bMoreData = true;
 676                                }
 677
 678                                if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0)
 679                                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail\n");
 680
 681                                pMgmt->sNodeDBTable[0].wEnQueueCnt--;
 682                        }
 683                }
 684
 685                // PS nodes tx
 686                for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
 687                        if (pMgmt->sNodeDBTable[ii].bActive &&
 688                            pMgmt->sNodeDBTable[ii].bRxPSPoll) {
 689                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
 690                                                ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
 691                                while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
 692                                        if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
 693                                                // clear tx map
 694                                                pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
 695                                                                        ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
 696                                                pDevice->bMoreData = false;
 697                                        } else {
 698                                                pDevice->bMoreData = true;
 699                                        }
 700
 701                                        if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0)
 702                                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail\n");
 703
 704                                        pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
 705                                        // check if sta ps enable, wait next pspoll
 706                                        // if sta ps disable, send all pending buffers.
 707                                        if (pMgmt->sNodeDBTable[ii].bPSEnable)
 708                                                break;
 709                                }
 710                                if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
 711                                        // clear tx map
 712                                        pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
 713                                                        ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
 714                                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear\n", ii);
 715                                }
 716                                pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
 717                        }
 718                }
 719                break;
 720
 721        case WLAN_CMD_RADIO_START:
 722
 723                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
 724//              if (pDevice->bRadioCmd == true)
 725//                      CARDbRadioPowerOn(pDevice);
 726//              else
 727//                      CARDbRadioPowerOff(pDevice);
 728                {
 729                        int ntStatus = STATUS_SUCCESS;
 730                        u8            byTmp;
 731
 732                        ntStatus = CONTROLnsRequestIn(pDevice,
 733                                        MESSAGE_TYPE_READ,
 734                                        MAC_REG_GPIOCTL1,
 735                                        MESSAGE_REQUEST_MACREG,
 736                                        1,
 737                                        &byTmp);
 738
 739                        if (ntStatus != STATUS_SUCCESS)
 740                                break;
 741                        if ((byTmp & GPIO3_DATA) == 0) {
 742                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_OFF........................\n");
 743                                // Old commands are useless.
 744                                // empty command Q
 745                                pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
 746                                pDevice->uCmdDequeueIdx = 0;
 747                                pDevice->uCmdEnqueueIdx = 0;
 748                                //0415pDevice->bCmdRunning = false;
 749                                pDevice->bCmdClear = true;
 750                                pDevice->bStopTx0Pkt = false;
 751                                pDevice->bStopDataPkt = true;
 752
 753                                pDevice->byKeyIndex = 0;
 754                                pDevice->bTransmitKey = false;
 755                                spin_unlock_irq(&pDevice->lock);
 756                                KeyvInitTable(pDevice, &pDevice->sKey);
 757                                spin_lock_irq(&pDevice->lock);
 758                                pMgmt->byCSSPK = KEY_CTL_NONE;
 759                                pMgmt->byCSSGK = KEY_CTL_NONE;
 760
 761                                if (pDevice->bLinkPass == true) {
 762                                        // reason = 8 : disassoc because sta has left
 763                                        vMgrDisassocBeginSta((void *) pDevice,
 764                                                        pMgmt,
 765                                                        pMgmt->abyCurrBSSID,
 766                                                        (8),
 767                                                        &Status);
 768                                        pDevice->bLinkPass = false;
 769                                        // unlock command busy
 770                                        pMgmt->eCurrState = WMAC_STATE_IDLE;
 771                                        pMgmt->sNodeDBTable[0].bActive = false;
 772                                        // if(pDevice->bWPASuppWextEnabled == true)
 773                                        {
 774                                                union iwreq_data  wrqu;
 775                                                memset(&wrqu, 0, sizeof(wrqu));
 776                                                wrqu.ap_addr.sa_family = ARPHRD_ETHER;
 777                                                PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
 778                                                wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
 779                                        }
 780                                }
 781                                pDevice->bwextstep0 = false;
 782                                pDevice->bwextstep1 = false;
 783                                pDevice->bwextstep2 = false;
 784                                pDevice->bwextstep3 = false;
 785                                pDevice->bWPASuppWextEnabled = false;
 786                                //clear current SSID
 787                                pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
 788                                pItemSSID->len = 0;
 789                                memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
 790                                //clear desired SSID
 791                                pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
 792                                pItemSSID->len = 0;
 793                                memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
 794
 795                                netif_stop_queue(pDevice->dev);
 796                                CARDbRadioPowerOff(pDevice);
 797                                MACvRegBitsOn(pDevice, MAC_REG_GPIOCTL1, GPIO3_INTMD);
 798                                ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_OFF);
 799                                pDevice->bHWRadioOff = true;
 800                        } else {
 801                                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
 802                                pDevice->bHWRadioOff = false;
 803                                CARDbRadioPowerOn(pDevice);
 804                                MACvRegBitsOff(pDevice, MAC_REG_GPIOCTL1, GPIO3_INTMD);
 805                                ControlvMaskByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PAPEDELAY, LEDSTS_STS, LEDSTS_ON);
 806                        }
 807                }
 808
 809                break;
 810
 811        case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
 812
 813                pDevice->bStopDataPkt = true;
 814                pDevice->byBBVGACurrent = pDevice->byBBVGANew;
 815                BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
 816                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
 817                pDevice->bStopDataPkt = false;
 818                break;
 819
 820        case WLAN_CMD_TBTT_WAKEUP_START:
 821                PSbIsNextTBTTWakeUp(pDevice);
 822                break;
 823
 824        case WLAN_CMD_BECON_SEND_START:
 825                bMgrPrepareBeaconToSend(pDevice, pMgmt);
 826                break;
 827
 828        case WLAN_CMD_SETPOWER_START:
 829
 830                RFbSetPower(pDevice, pDevice->wCurrentRate, pMgmt->uCurrChannel);
 831
 832                break;
 833
 834        case WLAN_CMD_CHANGE_ANTENNA_START:
 835                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
 836                if (pDevice->dwRxAntennaSel == 0) {
 837                        pDevice->dwRxAntennaSel = 1;
 838                        if (pDevice->bTxRxAntInv == true)
 839                                BBvSetAntennaMode(pDevice, ANT_RXA);
 840                        else
 841                                BBvSetAntennaMode(pDevice, ANT_RXB);
 842                } else {
 843                        pDevice->dwRxAntennaSel = 0;
 844                        if (pDevice->bTxRxAntInv == true)
 845                                BBvSetAntennaMode(pDevice, ANT_RXB);
 846                        else
 847                                BBvSetAntennaMode(pDevice, ANT_RXA);
 848                }
 849                break;
 850
 851        case WLAN_CMD_REMOVE_ALLKEY_START:
 852                KeybRemoveAllKey(pDevice, &(pDevice->sKey), pDevice->abyBSSID);
 853                break;
 854
 855        case WLAN_CMD_MAC_DISPOWERSAVING_START:
 856                ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
 857                if ((byData & PSCTL_PS) != 0) {
 858                        // disable power saving hw function
 859                        CONTROLnsRequestOut(pDevice,
 860                                        MESSAGE_TYPE_DISABLE_PS,
 861                                        0,
 862                                        0,
 863                                        0,
 864                                        NULL
 865                                        );
 866                }
 867                break;
 868
 869        case WLAN_CMD_11H_CHSW_START:
 870                CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
 871                pDevice->bChannelSwitch = false;
 872                pMgmt->uCurrChannel = pDevice->byNewChannel;
 873                pDevice->bStopDataPkt = false;
 874                break;
 875
 876        case WLAN_CMD_CONFIGURE_FILTER_START:
 877                vnt_configure_filter(pDevice);
 878                break;
 879        default:
 880                break;
 881        } //switch
 882
 883        s_bCommandComplete(pDevice);
 884
 885        spin_unlock_irq(&pDevice->lock);
 886        return;
 887}
 888
 889static int s_bCommandComplete(struct vnt_private *pDevice)
 890{
 891        struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
 892        PWLAN_IE_SSID pSSID;
 893        int bRadioCmd = false;
 894        int bForceSCAN = true;
 895
 896        pDevice->eCommandState = WLAN_CMD_IDLE;
 897        if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
 898                //Command Queue Empty
 899                pDevice->bCmdRunning = false;
 900                return true;
 901        } else {
 902                pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
 903                pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
 904                bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
 905                bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
 906                ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
 907                pDevice->cbFreeCmdQueue++;
 908                pDevice->bCmdRunning = true;
 909                switch (pDevice->eCommand) {
 910                case WLAN_CMD_BSSID_SCAN:
 911                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
 912                        pDevice->eCommandState = WLAN_CMD_SCAN_START;
 913                        pMgmt->uScanChannel = 0;
 914                        if (pSSID->len != 0)
 915                                memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
 916                        else
 917                                memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
 918/*
 919                        if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
 920                                if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
 921                                    ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
 922                                        pDevice->eCommandState = WLAN_CMD_IDLE;
 923                                }
 924                        }
 925*/
 926                        break;
 927                case WLAN_CMD_SSID:
 928                        pDevice->eCommandState = WLAN_CMD_SSID_START;
 929                        if (pSSID->len > WLAN_SSID_MAXLEN)
 930                                pSSID->len = WLAN_SSID_MAXLEN;
 931                        if (pSSID->len != 0)
 932                                memcpy(pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
 933                        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
 934                        break;
 935                case WLAN_CMD_DISASSOCIATE:
 936                        pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
 937                        break;
 938                case WLAN_CMD_RX_PSPOLL:
 939                        pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
 940                        break;
 941                case WLAN_CMD_RUN_AP:
 942                        pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
 943                        break;
 944                case WLAN_CMD_RADIO:
 945                        pDevice->eCommandState = WLAN_CMD_RADIO_START;
 946                        pDevice->bRadioCmd = bRadioCmd;
 947                        break;
 948                case WLAN_CMD_CHANGE_BBSENSITIVITY:
 949                        pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
 950                        break;
 951
 952                case WLAN_CMD_TBTT_WAKEUP:
 953                        pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
 954                        break;
 955
 956                case WLAN_CMD_BECON_SEND:
 957                        pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
 958                        break;
 959
 960                case WLAN_CMD_SETPOWER:
 961                        pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
 962                        break;
 963
 964                case WLAN_CMD_CHANGE_ANTENNA:
 965                        pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
 966                        break;
 967
 968                case WLAN_CMD_REMOVE_ALLKEY:
 969                        pDevice->eCommandState = WLAN_CMD_REMOVE_ALLKEY_START;
 970                        break;
 971
 972                case WLAN_CMD_MAC_DISPOWERSAVING:
 973                        pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
 974                        break;
 975
 976                case WLAN_CMD_11H_CHSW:
 977                        pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
 978                        break;
 979
 980                case WLAN_CMD_CONFIGURE_FILTER:
 981                        pDevice->eCommandState =
 982                                                WLAN_CMD_CONFIGURE_FILTER_START;
 983                        break;
 984
 985                default:
 986                        break;
 987                }
 988                vCommandTimerWait(pDevice, 0);
 989        }
 990
 991        return true;
 992}
 993
 994int bScheduleCommand(struct vnt_private *pDevice,
 995                CMD_CODE eCommand, u8 *pbyItem0)
 996{
 997
 998        if (pDevice->cbFreeCmdQueue == 0)
 999                return false;
1000        pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1001        pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
1002        memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1003        if (pbyItem0 != NULL) {
1004                switch (eCommand) {
1005                case WLAN_CMD_BSSID_SCAN:
1006                        pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
1007                        memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1008                                pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1009                        break;
1010
1011                case WLAN_CMD_SSID:
1012                        memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1013                                pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1014                        break;
1015
1016                case WLAN_CMD_DISASSOCIATE:
1017                        pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
1018                        break;
1019/*
1020                case WLAN_CMD_DEAUTH:
1021                        pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((u16 *)pbyItem0);
1022                        break;
1023*/
1024
1025                case WLAN_CMD_RADIO:
1026                        pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
1027                        break;
1028
1029                default:
1030                        break;
1031                }
1032        }
1033
1034        ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1035        pDevice->cbFreeCmdQueue--;
1036
1037        if (pDevice->bCmdRunning == false)
1038                s_bCommandComplete(pDevice);
1039
1040        return true;
1041
1042}
1043
1044/*
1045 * Description:
1046 *      Clear BSSID_SCAN cmd in CMD Queue
1047 *
1048 * Parameters:
1049 *  In:
1050 *      hDeviceContext  - Pointer to the adapter
1051 *      eCommand        - Command
1052 *  Out:
1053 *      none
1054 *
1055 * Return Value: true if success; otherwise false
1056 *
1057 */
1058static int s_bClearBSSID_SCAN(struct vnt_private *pDevice)
1059{
1060        unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1061        unsigned int ii;
1062
1063        if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1064                for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii++) {
1065                        if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1066                                pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1067                        ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1068                        if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1069                                break;
1070                }
1071        }
1072        return true;
1073}
1074
1075//mike add:reset command timer
1076void vResetCommandTimer(struct vnt_private *pDevice)
1077{
1078        cancel_delayed_work_sync(&pDevice->run_command_work);
1079
1080        pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1081        pDevice->uCmdDequeueIdx = 0;
1082        pDevice->uCmdEnqueueIdx = 0;
1083        pDevice->eCommandState = WLAN_CMD_IDLE;
1084        pDevice->bCmdRunning = false;
1085        pDevice->bCmdClear = false;
1086}
1087