Staging: rt2860: remove WPA_SUPPLICANT_SUPPORT ifdefs
[pandora-kernel.git] / drivers / staging / rt2860 / sta / connect.c
index 36f28f8..7cede82 100644 (file)
@@ -178,13 +178,6 @@ VOID MlmeCntlMachinePerformAction(
                                        pAd->bLedOnScanning = FALSE;
                                        RTMPSetLED(pAd, pAd->LedStatus);
                                }
-#ifdef DOT11N_DRAFT3
-                               // AP sent a 2040Coexistence mgmt frame, then station perform a scan, and then send back the respone.
-                               if (pAd->CommonCfg.BSSCoexist2040.field.InfoReq == 1)
-                               {
-                                       Update2040CoexistFrameAndNotify(pAd, BSSID_WCID, TRUE);
-                               }
-#endif // DOT11N_DRAFT3 //
                        }
                        break;
 
@@ -234,19 +227,11 @@ VOID CntlIdleProc(
                        break;
 
                case OID_802_11_DISASSOCIATE:
-#ifdef RALINK_ATE
-                       if(ATE_ON(pAd))
-                       {
-                               DBGPRINT(RT_DEBUG_TRACE, ("The driver is in ATE mode now\n"));
-                               break;
-                       }
-#endif // RALINK_ATE //
                        DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
                        MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
                        pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
-#ifdef WPA_SUPPLICANT_SUPPORT
+
             if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_ENABLE_WITH_WEB_UI)
-#endif // WPA_SUPPLICANT_SUPPORT //
             {
                        // Set the AutoReconnectSsid to prevent it reconnect to old SSID
                        // Since calling this indicate user don't want to connect to that SSID anymore.
@@ -263,12 +248,6 @@ VOID CntlIdleProc(
             WpaMicFailureReportFrame(pAd, Elem);
             break;
 
-#ifdef QOS_DLS_SUPPORT
-               case RT_OID_802_11_SET_DLS_PARAM:
-                       CntlOidDLSSetupProc(pAd, Elem);
-                       break;
-#endif // QOS_DLS_SUPPORT //
-
                default:
                        DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem->MsgType));
                        break;
@@ -283,13 +262,6 @@ VOID CntlOidScanProc(
        ULONG                      BssIdx = BSS_NOT_FOUND;
        BSS_ENTRY                  CurrBss;
 
-#ifdef RALINK_ATE
-/* Disable scanning when ATE is running. */
-       if (ATE_ON(pAd))
-               return;
-#endif // RALINK_ATE //
-
-
        // record current BSS if network is connected.
        // 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.
        if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
@@ -337,6 +309,10 @@ VOID CntlOidSsidProc(
        MLME_DISASSOC_REQ_STRUCT   DisassocReq;
        ULONG                                      Now;
 
+       // BBP and RF are not accessible in PS mode, we has to wake them up first
+       if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
+               AsicForceWakeup(pAd, RTMP_HALT);
+
        // Step 1. record the desired user settings to MlmeAux
        NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
        NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);
@@ -373,9 +349,6 @@ VOID CntlOidSsidProc(
                         (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
                         (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
                         (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
-#ifdef LEAP_SUPPORT
-                        || (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
-#endif // LEAP_SUPPORT //
                         ) &&
                        (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
                {
@@ -416,7 +389,7 @@ VOID CntlOidSsidProc(
                        }
 
                        pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
-#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
+
             {
                 union iwreq_data    wrqu;
 
@@ -425,7 +398,6 @@ VOID CntlOidSsidProc(
                 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
 
             }
-#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
                }
        }
        else if (INFRA_ON(pAd))
@@ -509,12 +481,6 @@ VOID CntlOidRTBssidProc(
        MLME_DISASSOC_REQ_STRUCT    DisassocReq;
        MLME_JOIN_REQ_STRUCT        JoinReq;
 
-#ifdef RALINK_ATE
-/* No need to perform this routine when ATE is running. */
-       if (ATE_ON(pAd))
-               return;
-#endif // RALINK_ATE //
-
        // record user desired settings
        COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);
        pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
@@ -554,7 +520,7 @@ VOID CntlOidRTBssidProc(
                // already connected to the same BSSID, go back to idle state directly
                DBGPRINT(RT_DEBUG_TRACE, ("CNTL - already in this BSSID. ignore this SET_BSSID request\n"));
                pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
-#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
+
             {
                 union iwreq_data    wrqu;
 
@@ -563,7 +529,6 @@ VOID CntlOidRTBssidProc(
                 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
 
             }
-#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
        }
        else
        {
@@ -668,113 +633,6 @@ VOID CntlMlmeRoamingProc(
        IterateOnBssTab(pAd);
 }
 
-#ifdef QOS_DLS_SUPPORT
-/*
-       ==========================================================================
-       Description:
-
-       IRQL = DISPATCH_LEVEL
-
-       ==========================================================================
-*/
-VOID CntlOidDLSSetupProc(
-       IN PRTMP_ADAPTER pAd,
-       IN MLME_QUEUE_ELEM *Elem)
-{
-       PRT_802_11_DLS          pDLS = (PRT_802_11_DLS)Elem->Msg;
-       MLME_DLS_REQ_STRUCT     MlmeDlsReq;
-       INT                                     i;
-       USHORT                          reason = REASON_UNSPECIFY;
-
-       DBGPRINT(RT_DEBUG_TRACE,("CNTL - (OID set %02x:%02x:%02x:%02x:%02x:%02x with Valid=%d, Status=%d, TimeOut=%d, CountDownTimer=%d)\n",
-               pDLS->MacAddr[0], pDLS->MacAddr[1], pDLS->MacAddr[2], pDLS->MacAddr[3], pDLS->MacAddr[4], pDLS->MacAddr[5],
-               pDLS->Valid, pDLS->Status, pDLS->TimeOut, pDLS->CountDownTimer));
-
-       if (!pAd->CommonCfg.bDLSCapable)
-               return;
-
-       // DLS will not be supported when Adhoc mode
-       if (INFRA_ON(pAd))
-       {
-               for (i = 0; i < MAX_NUM_OF_DLS_ENTRY; i++)
-               {
-                       if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
-                               (pDLS->TimeOut == pAd->StaCfg.DLSEntry[i].TimeOut) && MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
-                       {
-                               // 1. Same setting, just drop it
-                               DBGPRINT(RT_DEBUG_TRACE,("CNTL - setting unchanged\n"));
-                               break;
-                       }
-                       else if (!pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) &&
-                               MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
-                       {
-                               // 2. Disable DLS link case, just tear down DLS link
-                               reason = REASON_QOS_UNWANTED_MECHANISM;
-                               pAd->StaCfg.DLSEntry[i].Valid   = FALSE;
-                               pAd->StaCfg.DLSEntry[i].Status  = DLS_NONE;
-                               DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
-                               MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
-                               DBGPRINT(RT_DEBUG_TRACE,("CNTL - start tear down procedure\n"));
-                               break;
-                       }
-                       else if ((i < MAX_NUM_OF_DLS_ENTRY) && pDLS->Valid && !pAd->StaCfg.DLSEntry[i].Valid)
-                       {
-                               // 3. Enable case, start DLS setup procedure
-                               NdisMoveMemory(&pAd->StaCfg.DLSEntry[i], pDLS, sizeof(RT_802_11_DLS_UI));
-
-                               //Update countdown timer
-                               pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
-                               DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
-                               MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
-                               DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS setup case\n"));
-                               break;
-                       }
-                       else if ((i < MAX_NUM_OF_DLS_ENTRY) && pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
-                               (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH) && !MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
-                       {
-                               // 4. update mac case, tear down old DLS and setup new DLS
-                               reason = REASON_QOS_UNWANTED_MECHANISM;
-                               pAd->StaCfg.DLSEntry[i].Valid   = FALSE;
-                               pAd->StaCfg.DLSEntry[i].Status  = DLS_NONE;
-                               DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
-                               MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_TEAR_DOWN, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
-                               NdisMoveMemory(&pAd->StaCfg.DLSEntry[i], pDLS, sizeof(RT_802_11_DLS_UI));
-                               DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
-                               MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
-                               DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS tear down and restart case\n"));
-                               break;
-                       }
-                       else if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
-                               MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr) && (pAd->StaCfg.DLSEntry[i].TimeOut != pDLS->TimeOut))
-                       {
-                               // 5. update timeout case, start DLS setup procedure (no tear down)
-                               pAd->StaCfg.DLSEntry[i].TimeOut = pDLS->TimeOut;
-                               //Update countdown timer
-                               pAd->StaCfg.DLSEntry[i].CountDownTimer = pAd->StaCfg.DLSEntry[i].TimeOut;
-                               DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
-                               MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
-                               DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS update timeout case\n"));
-                               break;
-                       }
-                       else if (pDLS->Valid && pAd->StaCfg.DLSEntry[i].Valid &&
-                               (pAd->StaCfg.DLSEntry[i].Status != DLS_FINISH) && MAC_ADDR_EQUAL(pDLS->MacAddr, pAd->StaCfg.DLSEntry[i].MacAddr))
-                       {
-                               // 6. re-setup case, start DLS setup procedure (no tear down)
-                               DlsParmFill(pAd, &MlmeDlsReq, &pAd->StaCfg.DLSEntry[i], reason);
-                               MlmeEnqueue(pAd, DLS_STATE_MACHINE, MT2_MLME_DLS_REQ, sizeof(MLME_DLS_REQ_STRUCT), &MlmeDlsReq);
-                               DBGPRINT(RT_DEBUG_TRACE,("CNTL - DLS retry setup procedure\n"));
-                               break;
-                       }
-                       else
-                       {
-                               DBGPRINT(RT_DEBUG_WARN,("CNTL - DLS not changed in entry - %d - Valid=%d, Status=%d, TimeOut=%d\n",
-                                       i, pAd->StaCfg.DLSEntry[i].Valid, pAd->StaCfg.DLSEntry[i].Status, pAd->StaCfg.DLSEntry[i].TimeOut));
-                       }
-               }
-       }
-}
-#endif // QOS_DLS_SUPPORT //
-
 /*
        ==========================================================================
        Description:
@@ -866,14 +724,6 @@ VOID CntlWaitJoinProc(
                        // 2. joined a new INFRA network, start from authentication
                        else
                        {
-#ifdef LEAP_SUPPORT
-                               // Add AuthMode "LEAP" for CCX 1.X
-                               if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
-                               {
-                                       AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
-                               }
-                               else
-#endif // LEAP_SUPPORT //
                                {
                                        // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
                                        if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
@@ -970,9 +820,6 @@ VOID CntlWaitStartProc(
                        {
                                pAd->CommonCfg.RadarDetect.RDMode = RD_SILENCE_MODE;
                                pAd->CommonCfg.RadarDetect.RDCount = 0;
-#ifdef DFS_SUPPORT
-                               BbpRadarDetectionStart(pAd);
-#endif // DFS_SUPPORT //
                        }
 
                        DBGPRINT(RT_DEBUG_TRACE, ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
@@ -1012,21 +859,6 @@ VOID CntlWaitAuthProc(
                        AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
                                                  ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
 
-#ifdef LEAP_SUPPORT
-                       //
-                       // Cisco Leap CCKM supported Re-association.
-                       //
-                       if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
-                       {
-                               //if CCKM is turn on , that's mean Fast Reauthentication
-                               //Use CCKM Reassociation instead of normal association for Fast Roaming.
-                               MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
-                                                       sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
-
-                               pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
-                       }
-                       else
-#endif // LEAP_SUPPORT //
                        {
                                MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
                                                        sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
@@ -1040,14 +872,7 @@ VOID CntlWaitAuthProc(
                        // ageing-out. The previous authentication attempt must have let it remove us.
                        // so try Authentication again may help. For D-Link DWL-900AP+ compatibility.
                        DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try again...\n"));
-#ifdef LEAP_SUPPORT
-                       //Add AuthMode "LEAP" for CCX 1.X
-                       if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
-                       {
-                               AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
-                       }
-                       else
-#endif // LEAP_SUPPORT //
+
                        {
                                if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
                                        (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
@@ -1099,20 +924,6 @@ VOID CntlWaitAuthProc2(
                }
                else
                {
-#ifdef LEAP_SUPPORT
-                       // Process LEAP first, since it use different control variable
-                       // We don't want to affect other poven operation
-                       if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
-                       {
-                               // LEAP Auth not success, try next BSS
-                               DBGPRINT(RT_DEBUG_TRACE, ("CNTL - *LEAP* AUTH FAIL, give up; try next BSS\n"));
-                               DBGPRINT(RT_DEBUG_TRACE, ("Total match BSSID [=%d]\n", pAd->MlmeAux.SsidBssTab.BssNr));
-                               pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
-                               pAd->MlmeAux.BssIdx++;
-                               IterateOnBssTab(pAd);
-                       }
-                       else
-#endif // LEAP_SUPPORT //
                        if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) &&
                                 (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared))
                        {
@@ -1201,14 +1012,6 @@ VOID CntlWaitReassocProc(
                        if (pAd->CommonCfg.bWirelessEvent)
                                RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
 
-
-#ifdef LEAP_SUPPORT
-                       if (LEAP_CCKM_ON(pAd))
-                       {
-                               STA_PORT_SECURED(pAd);
-                               pAd->StaCfg.WpaState = SS_FINISH;
-                       }
-#endif // LEAP_SUPPORT //
                        pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
                        DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition successful on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
                }
@@ -1240,6 +1043,13 @@ VOID LinkUp(
        UCHAR   Value = 0, idx;
        MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;
 
+       if (RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
+       {
+               RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_HALT);
+               RTMPusecDelay(6000);
+               pAd->bPCIclkOff = FALSE;
+       }
+
        pEntry = &pAd->MacTab.Content[BSSID_WCID];
 
        //
@@ -1264,7 +1074,6 @@ VOID LinkUp(
        //rt2860b. Don't know why need this
        SwitchBetweenWepAndCkip(pAd);
 
-#ifdef RT2860
        // Before power save before link up function, We will force use 1R.
        // So after link up, check Rx antenna # again.
        RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
@@ -1282,19 +1091,12 @@ VOID LinkUp(
        }
        RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
        pAd->StaCfg.BBPR3 = Value;
-#endif // RT2860 //
 
        if (BssType == BSS_ADHOC)
        {
                OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);
                OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
 
-#ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
-               // No carrier detection when adhoc
-               // CarrierDetectionStop(pAd);
-               pAd->CommonCfg.CarrierDetect.CD_State = CD_NORMAL;
-#endif // CARRIER_DETECTION_SUPPORT //
-
                DBGPRINT(RT_DEBUG_TRACE, ("!!!Adhoc LINK UP !!! \n" ));
        }
        else
@@ -1330,9 +1132,7 @@ VOID LinkUp(
                RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
                Value &= (~0x20);
                RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
-#ifdef RT2860
         pAd->StaCfg.BBPR3 = Value;
-#endif // RT2860 //
 
                RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
                Data &= 0xfffffffe;
@@ -1367,9 +1167,7 @@ VOID LinkUp(
                RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
            Value |= (0x20);
                RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
-#ifdef RT2860
         pAd->StaCfg.BBPR3 = Value;
-#endif // RT2860 //
 
                if (pAd->MACVersion == 0x28600100)
                {
@@ -1400,9 +1198,7 @@ VOID LinkUp(
                RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
                Value &= (~0x20);
                RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
-#ifdef RT2860
         pAd->StaCfg.BBPR3 = Value;
-#endif // RT2860 //
 
                if (pAd->MACVersion == 0x28600100)
                {
@@ -1464,9 +1260,6 @@ VOID LinkUp(
 
        if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE)
        {
-#ifdef DFS_SUPPORT
-               RadarDetectionStop(pAd);
-#endif // DFS_SUPPORT //
        }
        pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
 
@@ -1598,6 +1391,8 @@ VOID LinkUp(
                        IV = 0;
                        IV |= (pAd->StaCfg.DefaultKeyId << 30);
                        AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);
+
+                       RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
                }
                // NOTE:
                // the decision of using "short slot time" or not may change dynamically due to
@@ -1638,15 +1433,11 @@ VOID LinkUp(
 
 
                // If WEP is enabled, add paiewise and shared key
-#ifdef WPA_SUPPLICANT_SUPPORT
         if (((pAd->StaCfg.WpaSupplicantUP)&&
              (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)&&
              (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
             ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)&&
               (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)))
-#else
-               if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
-#endif // WPA_SUPPLICANT_SUPPORT //
                {
                        PUCHAR  Key;
                        UCHAR   CipherAlg;
@@ -1707,13 +1498,6 @@ VOID LinkUp(
                DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n", pAd->StaActive.SupportedPhyInfo.bHtEnable));
 #endif // DOT11_N_SUPPORT //
 
-               //
-               // Report Adjacent AP report.
-               //
-#ifdef LEAP_SUPPORT
-               CCXAdjacentAPReport(pAd);
-#endif // LEAP_SUPPORT //
-
                if (pAd->CommonCfg.bAggregationCapable)
                {
                        if ((pAd->CommonCfg.bPiggyBackCapable) && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)
@@ -1919,16 +1703,7 @@ VOID LinkUp(
        }
 
        RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
-
-#ifdef DOT11_N_SUPPORT
-#ifdef DOT11N_DRAFT3
-       if ((pAd->CommonCfg.BACapability.field.b2040CoexistScanSup) && (pAd->CommonCfg.Channel <= 11))
-       {
-               OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SCAN_2040);
-               BuildEffectedChannelList(pAd);
-       }
-#endif // DOT11N_DRAFT3 //
-#endif // DOT11_N_SUPPORT //
+       RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
 }
 
 /*
@@ -1961,16 +1736,17 @@ VOID LinkDown(
        IN  BOOLEAN      IsReqFromAP)
 {
        UCHAR                       i, ByteValue = 0;
+       BOOLEAN         Cancelled;
 
        // Do nothing if monitor mode is on
        if (MONITOR_ON(pAd))
                return;
 
-#ifdef RALINK_ATE
-       // Nothing to do in ATE mode.
-       if (ATE_ON(pAd))
-               return;
-#endif // RALINK_ATE //
+       RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
+       RTMPCancelTimer(&pAd->Mlme.PsPollTimer,         &Cancelled);
+
+       // Not allow go to sleep within linkdown function.
+       RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
 
     if (pAd->CommonCfg.bWirelessEvent)
        {
@@ -1980,7 +1756,6 @@ VOID LinkDown(
        DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN !!!\n"));
        OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
 
-#ifdef RT2860
     if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE))
     {
            BOOLEAN Cancelled;
@@ -1988,17 +1763,15 @@ VOID LinkDown(
         RTMPCancelTimer(&pAd->Mlme.PsPollTimer,        &Cancelled);
     }
 
-    if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
+    if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) ||
+               RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND) ||
+               RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))
     {
-        AUTO_WAKEUP_STRUC AutoWakeupCfg;
-               AsicForceWakeup(pAd, TRUE);
-        AutoWakeupCfg.word = 0;
-           RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
+               AsicForceWakeup(pAd, RTMP_HALT);
         OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
     }
 
     pAd->bPCIclkOff = FALSE;
-#endif // RT2860 //
        if (ADHOC_ON(pAd))              // Adhoc mode link down
        {
                DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 1!!!\n"));
@@ -2015,33 +1788,6 @@ VOID LinkDown(
        {
                DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 2!!!\n"));
 
-#ifdef QOS_DLS_SUPPORT
-               // DLS tear down frame must be sent before link down
-               // send DLS-TEAR_DOWN message
-               if (pAd->CommonCfg.bDLSCapable)
-               {
-                       // tear down local dls table entry
-                       for (i=0; i<MAX_NUM_OF_INIT_DLS_ENTRY; i++)
-                       {
-                               if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status == DLS_FINISH))
-                               {
-                                       pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
-                                       RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
-                               }
-                       }
-
-                       // tear down peer dls table entry
-                       for (i=MAX_NUM_OF_INIT_DLS_ENTRY; i<MAX_NUM_OF_DLS_ENTRY; i++)
-                       {
-                               if (pAd->StaCfg.DLSEntry[i].Valid && (pAd->StaCfg.DLSEntry[i].Status ==  DLS_FINISH))
-                               {
-                                       pAd->StaCfg.DLSEntry[i].Status = DLS_NONE;
-                                       RTMPSendDLSTearDownFrame(pAd, pAd->StaCfg.DLSEntry[i].MacAddr);
-                               }
-                       }
-               }
-#endif // QOS_DLS_SUPPORT //
-
                OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
                OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
 
@@ -2085,17 +1831,6 @@ VOID LinkDown(
                        NdisMoveMemory(pAd->StaCfg.CCXAdjacentAPSsid, pAd->CommonCfg.Ssid, pAd->StaCfg.CCXAdjacentAPSsidLen);
                        COPY_MAC_ADDR(pAd->StaCfg.CCXAdjacentAPBssid, pAd->CommonCfg.Bssid);
                }
-
-#ifdef EXT_BUILD_CHANNEL_LIST
-               // Country IE of the AP will be evaluated and will be used.
-               if (pAd->StaCfg.IEEE80211dClientMode != Rt802_11_D_None)
-               {
-                       NdisMoveMemory(&pAd->CommonCfg.CountryCode[0], &pAd->StaCfg.StaOriCountryCode[0], 2);
-                       pAd->CommonCfg.Geography = pAd->StaCfg.StaOriGeography;
-                       BuildChannelListEx(pAd);
-               }
-#endif // EXT_BUILD_CHANNEL_LIST //
-
        }
 
        for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
@@ -2140,11 +1875,6 @@ VOID LinkDown(
                pAd->StaCfg.WpaState = SS_START;
                // Clear Replay counter
                NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
-
-#ifdef QOS_DLS_SUPPORT
-               if (pAd->CommonCfg.bDLSCapable)
-                       NdisZeroMemory(pAd->StaCfg.DlsReplayCounter, 8);
-#endif // QOS_DLS_SUPPORT //
        }
 
 
@@ -2159,7 +1889,7 @@ VOID LinkDown(
        }
 
        // 802.1x port control
-#ifdef WPA_SUPPLICANT_SUPPORT
+
        // Prevent clear PortSecured here with static WEP
        // NetworkManger set security policy first then set SSID to connect AP.
        if (pAd->StaCfg.WpaSupplicantUP &&
@@ -2169,7 +1899,6 @@ VOID LinkDown(
                pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
        }
        else
-#endif // WPA_SUPPLICANT_SUPPORT //
        {
                pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
                pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
@@ -2251,40 +1980,17 @@ VOID LinkDown(
        pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;
        pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
 
-#ifdef DOT11_N_SUPPORT
-#ifdef DOT11N_DRAFT3
-       OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SCAN_2040);
-       pAd->CommonCfg.BSSCoexist2040.word = 0;
-       TriEventInit(pAd);
-       for (i = 0; i < (pAd->ChannelListNum - 1); i++)
-       {
-               pAd->ChannelList[i].bEffectedChannel = FALSE;
-       }
-#endif // DOT11N_DRAFT3 //
-#endif // DOT11_N_SUPPORT //
-
        RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);
        RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
 
-#ifdef WPA_SUPPLICANT_SUPPORT
-#ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
-       if (pAd->StaCfg.WpaSupplicantUP) {
-               union iwreq_data    wrqu;
-               //send disassociate event to wpa_supplicant
-               memset(&wrqu, 0, sizeof(wrqu));
-               wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
-               wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
-       }
-#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
-#endif // WPA_SUPPLICANT_SUPPORT //
+       // Allow go to sleep after linkdown steps.
+       RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
 
-#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
        {
                union iwreq_data    wrqu;
                memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
                wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
        }
-#endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
 }
 
 /*
@@ -2444,26 +2150,6 @@ VOID ScanParmFill(
        ScanReq->ScanType = ScanType;
 }
 
-#ifdef QOS_DLS_SUPPORT
-/*
-       ==========================================================================
-       Description:
-
-       IRQL = DISPATCH_LEVEL
-
-       ==========================================================================
-*/
-VOID DlsParmFill(
-       IN PRTMP_ADAPTER pAd,
-       IN OUT MLME_DLS_REQ_STRUCT *pDlsReq,
-       IN PRT_802_11_DLS pDls,
-       IN USHORT reason)
-{
-       pDlsReq->pDLS = pDls;
-       pDlsReq->Reason = reason;
-}
-#endif // QOS_DLS_SUPPORT //
-
 /*
        ==========================================================================
        Description:
@@ -2510,7 +2196,6 @@ VOID AuthParmFill(
 
        ==========================================================================
  */
-#ifdef RT2860
 VOID ComposePsPoll(
        IN PRTMP_ADAPTER pAd)
 {
@@ -2534,7 +2219,6 @@ VOID ComposeNullFrame(
        COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
        COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
 }
-#endif // RT2860 //
 
 
 
@@ -2683,16 +2367,10 @@ ULONG MakeIbssBeacon(
                ULONG TmpLen;
                UCHAR HtLen, HtLen1;
 
-#ifdef RT_BIG_ENDIAN
-               HT_CAPABILITY_IE HtCapabilityTmp;
-               ADD_HT_INFO_IE  addHTInfoTmp;
-               USHORT  b2lTmp, b2lTmp2;
-#endif
-
                // add HT Capability IE
                HtLen = sizeof(pAd->CommonCfg.HtCapability);
                HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);
-#ifndef RT_BIG_ENDIAN
+
                MakeOutgoingFrame(pBeaconFrame+FrameLen,        &TmpLen,
                                                  1,                                            &HtCapIe,
                                                  1,                                            &HtLen,
@@ -2701,24 +2379,7 @@ ULONG MakeIbssBeacon(
                                                  1,                                            &HtLen1,
                                                  HtLen1,                                       &pAd->CommonCfg.AddHTInfo,
                                                  END_OF_ARGS);
-#else
-               NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
-               *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
-               *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
 
-               NdisMoveMemory(&addHTInfoTmp, &pAd->CommonCfg.AddHTInfo, HtLen1);
-               *(USHORT *)(&addHTInfoTmp.AddHtInfo2) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo2));
-               *(USHORT *)(&addHTInfoTmp.AddHtInfo3) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo3));
-
-               MakeOutgoingFrame(pBeaconFrame+FrameLen,        &TmpLen,
-                                                 1,                                            &HtCapIe,
-                                                 1,                                            &HtLen,
-                                                 HtLen,                                        &HtCapabilityTmp,
-                                                 1,                                            &AddHtInfoIe,
-                                                 1,                                            &HtLen1,
-                                                 HtLen1,                                       &addHTInfoTmp,
-                                                 END_OF_ARGS);
-#endif
                FrameLen += TmpLen;
        }
 #endif // DOT11_N_SUPPORT //
@@ -2738,11 +2399,6 @@ ULONG MakeIbssBeacon(
                PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &Transmit);
     }
 
-#ifdef RT_BIG_ENDIAN
-       RTMPFrameEndianChange(pAd, pBeaconFrame, DIR_WRITE, FALSE);
-       RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
-#endif
-
     DBGPRINT(RT_DEBUG_TRACE, ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
                                        FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel, pAd->CommonCfg.PhyMode));
        return FrameLen;