?? connect.c
字號(hào):
/* ************************************************************************* * Ralink Tech Inc. * 5F., No.36, Taiyuan St., Jhubei City, * Hsinchu County 302, * Taiwan, R.O.C. * * (c) Copyright 2002-2007, Ralink Technology, Inc. * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * ************************************************************************* Module Name: connect.c Abstract: Revision History: Who When What -------- ---------- ---------------------------------------------- John 2004-08-08 Major modification from RT2560*/#include "rt_config.h"UCHAR CipherSuiteWpaNoneTkip[] = { 0x00, 0x50, 0xf2, 0x01, // oui 0x01, 0x00, // Version 0x00, 0x50, 0xf2, 0x02, // Multicast 0x01, 0x00, // Number of unicast 0x00, 0x50, 0xf2, 0x02, // unicast 0x01, 0x00, // number of authentication method 0x00, 0x50, 0xf2, 0x00 // authentication };UCHAR CipherSuiteWpaNoneTkipLen = (sizeof(CipherSuiteWpaNoneTkip) / sizeof(UCHAR));UCHAR CipherSuiteWpaNoneAes[] = { 0x00, 0x50, 0xf2, 0x01, // oui 0x01, 0x00, // Version 0x00, 0x50, 0xf2, 0x04, // Multicast 0x01, 0x00, // Number of unicast 0x00, 0x50, 0xf2, 0x04, // unicast 0x01, 0x00, // number of authentication method 0x00, 0x50, 0xf2, 0x00 // authentication };UCHAR CipherSuiteWpaNoneAesLen = (sizeof(CipherSuiteWpaNoneAes) / sizeof(UCHAR));// The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS,// or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS// All settings successfuly negotiated furing MLME state machines become final settings// and are copied to pAd->StaActive#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \{ \ (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \ NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \ COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \ (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \ (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \ (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \ (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \ (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \ (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \ (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \ (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \ (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \ NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\ (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \ NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\ NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));\ NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));\ NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));\ COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \ (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \ (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\ COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\ (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\}/* ========================================================================== Description: IRQL = PASSIVE_LEVEL ==========================================================================*/VOID MlmeCntlInit( IN PRTMP_ADAPTER pAd, IN STATE_MACHINE *S, OUT STATE_MACHINE_FUNC Trans[]) { // Control state machine differs from other state machines, the interface // follows the standard interface pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;}/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ==========================================================================*/VOID MlmeCntlMachinePerformAction( IN PRTMP_ADAPTER pAd, IN STATE_MACHINE *S, IN MLME_QUEUE_ELEM *Elem) { switch(pAd->Mlme.CntlMachine.CurrState) { case CNTL_IDLE: { CntlIdleProc(pAd, Elem); } break; case CNTL_WAIT_DISASSOC: CntlWaitDisassocProc(pAd, Elem); break; case CNTL_WAIT_JOIN: CntlWaitJoinProc(pAd, Elem); break; // CNTL_WAIT_REASSOC is the only state in CNTL machine that does // not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)". // Therefore not protected by NDIS's "only one outstanding OID request" // rule. Which means NDIS may SET OID in the middle of ROAMing attempts. // Current approach is to block new SET request at RTMPSetInformation() // when CntlMachine.CurrState is not CNTL_IDLE case CNTL_WAIT_REASSOC: CntlWaitReassocProc(pAd, Elem); break; case CNTL_WAIT_START: CntlWaitStartProc(pAd, Elem); break; case CNTL_WAIT_AUTH: CntlWaitAuthProc(pAd, Elem); break; case CNTL_WAIT_AUTH2: CntlWaitAuthProc2(pAd, Elem); break; case CNTL_WAIT_ASSOC: CntlWaitAssocProc(pAd, Elem); break; case CNTL_WAIT_OID_LIST_SCAN: if(Elem->MsgType == MT2_SCAN_CONF) { // Resume TxRing after SCANING complete. We hope the out-of-service time // won't be too long to let upper layer time-out the waiting frames RTMPResumeMsduTransmission(pAd); if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) { // Cisco scan request is finished, prepare beacon report MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL); } pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; // // Set LED status to previous status. // if (pAd->bLedOnScanning) { 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; case CNTL_WAIT_OID_DISASSOC: if (Elem->MsgType == MT2_DISASSOC_CONF) { LinkDown(pAd, FALSE); pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; } break;#ifdef RT2870 // // This state is for that we want to connect to an AP but // it didn't find on BSS List table. So we need to scan the air first, // after that we can try to connect to the desired AP if available. // case CNTL_WAIT_SCAN_FOR_CONNECT: if(Elem->MsgType == MT2_SCAN_CONF) { // Resume TxRing after SCANING complete. We hope the out-of-service time // won't be too long to let upper layer time-out the waiting frames RTMPResumeMsduTransmission(pAd);#ifdef CCX_SUPPORT if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) { // Cisco scan request is finished, prepare beacon report MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL); }#endif // CCX_SUPPORT // pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; // // Check if we can connect to. // BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen); if (pAd->MlmeAux.SsidBssTab.BssNr > 0) { MlmeAutoReconnectLastSSID(pAd); } } break;#endif // RT2870 // default: DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType)); break; }}/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ==========================================================================*/VOID CntlIdleProc( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { MLME_DISASSOC_REQ_STRUCT DisassocReq; if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) return; switch(Elem->MsgType) { case OID_802_11_SSID: CntlOidSsidProc(pAd, Elem); break; case OID_802_11_BSSID: CntlOidRTBssidProc(pAd,Elem); break; case OID_802_11_BSSID_LIST_SCAN: CntlOidScanProc(pAd,Elem); 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. pAd->MlmeAux.AutoReconnectSsidLen= 32; NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen); } break; case MT2_MLME_ROAMING_REQ: CntlMlmeRoamingProc(pAd, Elem); break; case OID_802_11_MIC_FAILURE_REPORT_FRAME: 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; }}VOID CntlOidScanProc( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem){ MLME_SCAN_REQ_STRUCT ScanReq; 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)) { BssIdx = BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->CommonCfg.Channel); if (BssIdx != BSS_NOT_FOUND) { NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY)); } } // clean up previous SCAN result, add current BSS back to table if any BssTableInit(&pAd->ScanTab); if (BssIdx != BSS_NOT_FOUND) { // DDK Note: If the NIC is associated with a particular BSSID and SSID // that are not contained in the list of BSSIDs generated by this scan, the // BSSID description of the currently associated BSSID and SSID should be // appended to the list of BSSIDs in the NIC's database. // To ensure this, we append this BSS as the first entry in SCAN result NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY)); pAd->ScanTab.BssNr = 1; } ScanParmFill(pAd, &ScanReq, "", 0, BSS_ANY, SCAN_ACTIVE); MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;}/* ========================================================================== Description: Before calling this routine, user desired SSID should already been recorded in CommonCfg.Ssid[] IRQL = DISPATCH_LEVEL ==========================================================================*/VOID CntlOidSsidProc( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM * Elem) { PNDIS_802_11_SSID pOidSsid = (NDIS_802_11_SSID *)Elem->Msg; MLME_DISASSOC_REQ_STRUCT DisassocReq;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -