📄 connect.c
字号:
/* *************************************************************************** * Ralink Tech Inc. * 4F, No. 2 Technology 5th Rd. * Science-based Industrial Park * Hsin-chu, Taiwan, R.O.C. * * (c) Copyright 2002-2006, Ralink Technology, Inc. * * All rights reserved. Ralink's source code is an unpublished work and the * use of a copyright notice does not imply otherwise. This source code * contains confidential trade secret material of Ralink Tech. Any attemp * or participation in deciphering, decoding, reverse engineering or in any * way altering the source code is stricitly prohibited, unless the prior * written consent of Ralink Technology, Inc. is obtained. *************************************************************************** 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->ActiveCfg#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \{ \ _pAd->PortCfg.SsidLen = _pAd->MlmeAux.SsidLen; \ NdisMoveMemory(_pAd->PortCfg.Ssid, _pAd->MlmeAux.Ssid, _pAd->MlmeAux.SsidLen); \ COPY_MAC_ADDR(_pAd->PortCfg.Bssid, _pAd->MlmeAux.Bssid); \ _pAd->PortCfg.Channel = _pAd->MlmeAux.Channel; \ _pAd->ActiveCfg.Aid = _pAd->MlmeAux.Aid; \ _pAd->ActiveCfg.AtimWin = _pAd->MlmeAux.AtimWin; \ _pAd->ActiveCfg.CapabilityInfo = _pAd->MlmeAux.CapabilityInfo; \ _pAd->PortCfg.BeaconPeriod = _pAd->MlmeAux.BeaconPeriod; \ _pAd->ActiveCfg.CfpMaxDuration = _pAd->MlmeAux.CfpMaxDuration; \ _pAd->ActiveCfg.CfpPeriod = _pAd->MlmeAux.CfpPeriod; \ _pAd->ActiveCfg.SupRateLen = _pAd->MlmeAux.SupRateLen; \ NdisMoveMemory(_pAd->ActiveCfg.SupRate, _pAd->MlmeAux.SupRate, _pAd->MlmeAux.SupRateLen); \ _pAd->ActiveCfg.ExtRateLen = _pAd->MlmeAux.ExtRateLen; \ NdisMoveMemory(_pAd->ActiveCfg.ExtRate, _pAd->MlmeAux.ExtRate, _pAd->MlmeAux.ExtRateLen); \ NdisMoveMemory(&_pAd->PortCfg.APEdcaParm, &_pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM)); \ NdisMoveMemory(&_pAd->PortCfg.APQosCapability, &_pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM)); \ NdisMoveMemory(&_pAd->PortCfg.APQbssLoad, &_pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM)); \}/* ========================================================================== Description: ==========================================================================*/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: ==========================================================================*/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 RTUSBResumeMsduTransmission(pAd); pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT if (pAd->PortCfg.bNativeWpa == TRUE) // add by johnli { union iwreq_data wrqu; wrqu.data.length = 0; wrqu.data.flags = 0; wireless_send_event(pAd->net_dev, SIOCGIWSCAN, &wrqu, NULL); }#endif } break; case CNTL_WAIT_OID_DISASSOC: if (Elem->MsgType == MT2_DISASSOC_CONF) { LinkDown(pAd, FALSE); pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; } break; default: DBGPRINT_ERR("!ERROR! CNTL - Illegal message type(=%d)", Elem->MsgType); break; }}/* ========================================================================== Description: ==========================================================================*/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)) { if (pAd->MlmeAux.CurrReqIsFromNdis) pAd->MlmeAux.CurrReqIsFromNdis = FALSE; 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: DisassocParmFill(pAd, &DisassocReq, pAd->PortCfg.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; // 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; //BensonLiu 07-11-22 add for countermeasure case OID_802_11_MIC_FAILURE_REPORT_FRAME: WpaMicFailureReportFrame(pAd, Elem); break; //BensonLiu 07-11-22 end for countermeasure // added by wy case MT2_DISASSOC_CONF: if(INFRA_ON(pAd) || ADHOC_ON(pAd)) LinkDown(pAd, FALSE); break; default: DBGPRINT(RT_DEBUG_TRACE, "CNTL - Illegal message in CntlIdleProc(MsgType=%d)\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; DBGPRINT(RT_DEBUG_INFO, "CNTL - SCAN starts\n"); // 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->PortCfg.Bssid, pAd->PortCfg.Ssid, pAd->PortCfg.SsidLen, pAd->PortCfg.Channel); if (BssIdx != BSS_NOT_FOUND) { NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY)); // 2003-2-20 reset this RSSI to a low value but not zero. In normal case, the coming SCAN // should return a correct RSSI to overwrite this. If no BEEACON received after SCAN, // at least we still report a "greater than 0" RSSI since we claim it's CONNECTED. //CurrBss.Rssi = pAd->BbpRssiToDbmDelta - 85; // assume -85 dB } } // 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; } //2008/01/08:KH modified the scan type form passiv scan to active scan 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 PortCfg.Ssid[] ==========================================================================*/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; ULONG Now; // Step 1. record the desired user settings to MlmeAux //NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);//--> BensonLiu 2007-11-28 modify NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID+1);//<-- BensonLiu 2007-11-28 modify NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength); pAd->MlmeAux.SsidLen = (UCHAR)pOidSsid->SsidLength; NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN); pAd->MlmeAux.BssType = pAd->PortCfg.BssType; // // Update Reconnect Ssid, that user desired to connect. // NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID+1);//BensonLiu 2007-11-28 modify NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen); pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen; // step 2. find all matching BSS in the lastest SCAN result (inBssTab) // & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen); DBGPRINT(RT_DEBUG_TRACE, "CNTL - %d BSS match the desire SSID - %s\n",pAd->MlmeAux.SsidBssTab.BssNr, pAd->MlmeAux.Ssid); Now = jiffies; if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (pAd->PortCfg.SsidLen == pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen) && NdisEqualMemory(pAd->PortCfg.Ssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid, pAd->PortCfg.SsidLen) && MAC_ADDR_EQUAL(pAd->PortCfg.Bssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid)) { // Case 1. already connected with an AP who has the desired SSID // with highest RSSI if (((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)#ifdef RALINK_WPA_SUPPLICANT_SUPPORT || (pAd->PortCfg.IEEE8021X == TRUE) #endif ) && (pAd->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) { // case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo // connection process DBGPRINT(RT_DEBUG_TRACE, "CNTL - disassociate with current AP...\n"); DisassocParmFill(pAd, &DisassocReq, pAd->PortCfg.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_DISASSOC; } else if (pAd->bConfigChanged == TRUE) { // case 1.2 Important Config has changed, we have to reconnect to the same AP DBGPRINT(RT_DEBUG_TRACE, "CNTL - disassociate with current AP Because config changed...\n"); DisassocParmFill(pAd, &DisassocReq, pAd->PortCfg.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_DISASSOC; } else { // case 1.3. already connected to the SSID with highest RSSI. DBGPRINT(RT_DEBUG_TRACE, "CNTL - already with this BSSID. ignore this SET_SSID request\n"); pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT#if 0 // 2007-04-11, Even we already connect to the same ESSID, we still need to send disassoc it // and re-connect it, or the wpa_supplicant may confused about current status. DBGPRINT(RT_DEBUG_TRACE, "CNTL - disassociate with current AP...\n"); DisassocParmFill(pAd, &DisassocReq, pAd->PortCfg.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_DISASSOC;#else if (pAd->PortCfg.bNativeWpa == TRUE) // add by johnli wext_notify_event_assoc(pAd, SIOCGIWAP, TRUE);#endif#endif } } else if (INFRA_ON(pAd)) { if (!SSID_EQUAL(pAd->PortCfg.Ssid, pAd->PortCfg.SsidLen, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen)) { // // Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event. // pAd->MlmeAux.CurrReqIsFromNdis = TRUE; } // case 2. active INFRA association existent // roaming is done within miniport driver, nothing to do with configuration // utility. so upon a new SET(OID_802_11_SSID) is received, we just // disassociate with the current associated AP, // then perform a new association with this new SSID, no matter the // new/old SSID are the same or not. DBGPRINT(RT_DEBUG_TRACE, "CNTL - disassociate with current AP...\n"); DisassocParmFill(pAd, &DisassocReq, pAd->PortCfg.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_DISASSOC; } else { if (ADHOC_ON(pAd)) { DBGPRINT(RT_DEBUG_TRACE, "CNTL - drop current ADHOC\n"); LinkDown(pAd, FALSE); OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED); DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"); } if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) && (pAd->PortCfg.bAutoReconnect == TRUE) && (pAd->MlmeAux.BssType == BSS_INFRA) && (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) == TRUE))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -