📄 connect.c
字号:
ScanParmFill(pAd, &ScanReq, pAd->Mlme.CntlAux.Ssid, pAd->Mlme.CntlAux.SsidLen, 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; // Reset Missed scan number// pAd->PortCfg.IgnoredScanNumber = 0; pAd->PortCfg.LastScanTime = Now; } else { IterateOnBssTab(pAd); } } }/* ========================================================================== Description: ==========================================================================*/VOID CntlOidRTBssidProc( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM * Elem) { ULONG BssIdx; MACADDR *pOidBssid = (MACADDR *)Elem->Msg; MLME_DISASSOC_REQ_STRUCT DisassocReq; MLME_JOIN_REQ_STRUCT JoinReq; COPY_MAC_ADDR(&pAd->Mlme.CntlAux.Bssid, pOidBssid); BssIdx = BssTableSearch(&pAd->PortCfg.BssTab, pOidBssid); if (BssIdx == BSS_NOT_FOUND) { DBGPRINT(RT_DEBUG_TRACE, "CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"); if (pAd->Mlme.CntlAux.CurrReqIsFromNdis) { //NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_NOT_ACCEPTED); } pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; return; } // copy the matched BSS entry from PortCfg.BssTab to CntlAux.SsidBssTab pAd->Mlme.CntlAux.BssIdx = 0; pAd->Mlme.CntlAux.SsidBssTab.BssNr = 1; memcpy(&pAd->Mlme.CntlAux.SsidBssTab.BssEntry[0], &pAd->PortCfg.BssTab.BssEntry[BssIdx], sizeof(BSS_ENTRY)); // Add SSID into Mlme.CntlAux for site surey joining hidden SSID pAd->Mlme.CntlAux.SsidLen = pAd->Mlme.CntlAux.SsidBssTab.BssEntry[0].SsidLen; memcpy(pAd->Mlme.CntlAux.Ssid, pAd->Mlme.CntlAux.SsidBssTab.BssEntry[0].Ssid, pAd->Mlme.CntlAux.SsidLen); // 2002-11-26 skip the following checking. i.e. if user wants to re-connect to same AP // we just follow normal procedure. The reason of user doing this may because he/she changed // AP to another channel, but we still received BEACON from it thus don't claim Link Down. // Since user knows he's chnged AP channel, he'll re-connect again. By skipping the following // checking, we'll disassociate then re-do normal association with this AP at the new channel. // 2003-1-6 Re-enable this feature based on microsoft requirement which prefer not to re-do // connection when setting the same BSSID. if ( (pAd->MediaState == NdisMediaStateConnected) && //(INFRA_ON(pAd) || ADHOC_ON(pAd)) && MAC_ADDR_EQUAL(&pAd->PortCfg.Bssid, pOidBssid)) { // same BSSID, go back to idle state directly DBGPRINT(RT_DEBUG_TRACE, "CNTL - already in this BSSID. ignore this SET_BSSID request\n"); if (pAd->Mlme.CntlAux.CurrReqIsFromNdis) { NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_SUCCESS); } pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; } else { if (INFRA_ON(pAd)) { // disassoc from current AP first 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_RAW(RT_DEBUG_TRACE, "LinkDown(CntlOidRTBssidProc)\n"); LinkDown(pAd); pAd->MediaState = NdisMediaStateDisconnected; NdisMIndicateStatus(pAd->AdapterHandle, NDIS_STATUS_MEDIA_DISCONNECT, (PVOID)NULL, 0); NdisMIndicateStatusComplete(pAd->AdapterHandle); DBGPRINT(RT_DEBUG_TRACE, "NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"); } // No active association, join the BSS immediately DBGPRINT(RT_DEBUG_TRACE, "CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n", pOidBssid->Octet[0],pOidBssid->Octet[1],pOidBssid->Octet[2], pOidBssid->Octet[3],pOidBssid->Octet[4],pOidBssid->Octet[5]); JoinParmFill(pAd, &JoinReq, pAd->Mlme.CntlAux.BssIdx); MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN; } } }// Roaming is the only external request triggering CNTL state machine// despite of other "SET OID" operation. All "SET OID" related oerations // happen in sequence, because no other SET OID will be sent to this device// until the the previous SET operation is complete (successful o failed).// So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?// or been corrupted by other "SET OID"?VOID CntlMlmeRoamingProc( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { // TODO: // AP in different channel may show lower RSSI than actual value?? // should we add a weighting factor to compensate it? DBGPRINT(RT_DEBUG_TRACE,"CNTL - Roaming in CntlAux.RoamTab...\n"); BssTableSortByRssi(&pAd->Mlme.CntlAux.RoamTab); pAd->Mlme.CntlAux.RoamIdx=0; IterateOnBssTab2(pAd); }/* ========================================================================== Description: ==========================================================================*/VOID CntlWaitDisassocProc( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { MLME_START_REQ_STRUCT StartReq; if (Elem->MsgType == MT2_DISASSOC_CONF) { DBGPRINT_RAW(RT_DEBUG_TRACE, "LinkDown(CntlWaitDisassocProc)\n"); LinkDown(pAd); // case 1. no matching BSS, and user wants ADHOC, so we just start a new one if ((pAd->Mlme.CntlAux.SsidBssTab.BssNr==0) && (pAd->PortCfg.BssType == BSS_INDEP)) { DBGPRINT(RT_DEBUG_TRACE, "CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->Mlme.CntlAux.Ssid); StartParmFill(pAd, &StartReq, pAd->Mlme.CntlAux.Ssid, pAd->Mlme.CntlAux.SsidLen); MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START; } // case 2. try each matched BSS else { IterateOnBssTab(pAd); } }} /* ========================================================================== Description: ==========================================================================*/VOID CntlWaitJoinProc( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { USHORT Reason; MLME_AUTH_REQ_STRUCT AuthReq; if (Elem->MsgType == MT2_JOIN_CONF) { memcpy(&Reason, Elem->Msg, sizeof(USHORT)); if (Reason == MLME_SUCCESS) { // 1. joined an IBSS, we are pretty much done here if (pAd->PortCfg.BssType == BSS_INDEP) { LinkUp(pAd, BSS_INDEP); if (pAd->Mlme.CntlAux.CurrReqIsFromNdis) { NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_SUCCESS); } pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_JOIN_IN_PROGRESS);//steven:for test } // 2. joined a new INFRA network, start from authentication else {// RTUSBWriteMACRegister(pAd, TXRX_CSR2, 0x67e);//steven:for test // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeShared) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeAutoSwitch)) { AuthParmFill(pAd, &AuthReq, &pAd->PortCfg.Bssid, Ndis802_11AuthModeShared); } else { AuthParmFill(pAd, &AuthReq, &pAd->PortCfg.Bssid, Ndis802_11AuthModeOpen); } MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ, sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH; } } else { // 3. failed, try next BSS pAd->Mlme.CntlAux.BssIdx++; IterateOnBssTab(pAd); } } } /* ========================================================================== Description: ==========================================================================*/VOID CntlWaitStartProc( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { USHORT Result; if (Elem->MsgType == MT2_START_CONF) { memcpy(&Result, Elem->Msg, sizeof(USHORT)); if (Result == MLME_SUCCESS) { DBGPRINT(RT_DEBUG_TRACE, "CNTL - We have started a new ADHOC network\n"); DBGPRINT(RT_DEBUG_TRACE, "CNTL - BSSID %02x:%02x:%02x:%02x:%02x:%02x ...\n", pAd->PortCfg.Bssid.Octet[0], pAd->PortCfg.Bssid.Octet[1], pAd->PortCfg.Bssid.Octet[2], pAd->PortCfg.Bssid.Octet[3], pAd->PortCfg.Bssid.Octet[4], pAd->PortCfg.Bssid.Octet[5]); LinkUp(pAd, BSS_INDEP); if (pAd->Mlme.CntlAux.CurrReqIsFromNdis) { NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_SUCCESS); } pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_JOIN_IN_PROGRESS);//steven:for test } else { DBGPRINT(RT_DEBUG_TRACE, "CNTL - Start FAIL. BUG!!!!!\n"); if (pAd->Mlme.CntlAux.CurrReqIsFromNdis) { NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_FAILURE); } pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_JOIN_IN_PROGRESS);//steven:for test } }}/* ========================================================================== Description: ==========================================================================*/VOID CntlWaitAuthProc( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { USHORT Reason; MLME_ASSOC_REQ_STRUCT AssocReq; MLME_AUTH_REQ_STRUCT AuthReq; if (Elem->MsgType == MT2_AUTH_CONF) { memcpy(&Reason, Elem->Msg, sizeof(USHORT)); if (Reason == MLME_SUCCESS) { AssocParmFill(pAd, &AssocReq, &pAd->PortCfg.Bssid, pAd->PortCfg.CapabilityInfo, ASSOC_TIMEOUT, pAd->PortCfg.DefaultListenCount); MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ, sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC; } else { // This fail may because of the AP already keep us in its MAC table without // 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"); if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeShared) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeAutoSwitch)) { // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first AuthParmFill(pAd, &AuthReq, &pAd->PortCfg.Bssid, Ndis802_11AuthModeShared); } else { AuthParmFill(pAd, &AuthReq, &pAd->PortCfg.Bssid, Ndis802_11AuthModeOpen); } MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ, sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2; } } } /* ========================================================================== Description: ==========================================================================*/VOID CntlWaitAuthProc2( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { USHORT Reason; MLME_ASSOC_REQ_STRUCT AssocReq; MLME_AUTH_REQ_STRUCT AuthReq; if (Elem->MsgType == MT2_AUTH_CONF) { memcpy(&Reason, Elem->Msg, sizeof(USHORT)); if (Reason == MLME_SUCCESS) { AssocParmFill(pAd, &AssocReq, &pAd->PortCfg.Bssid, pAd->PortCfg.CapabilityInfo, ASSOC_TIMEOUT, pAd->PortCfg.DefaultListenCount); MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ, sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC; } else { if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) && (pAd->Mlme.AuthAux.Alg == Ndis802_11AuthModeShared)) { DBGPRINT(RT_DEBUG_TRACE, "CNTL - AUTH FAIL, try OPEN system...\n"); AuthParmFill(pAd, &AuthReq, &pAd->PortCfg.Bssid, Ndis802_11AuthModeOpen); MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ, sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2; } else { // not success, try next BSS DBGPRINT(RT_DEBUG_TRACE, "CNTL - AUTH FAIL, give up; try next BSS\n"); pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; //??????? pAd->Mlme.CntlAux.BssIdx++;// RTUSBWriteMACRegister(pAd, TXRX_CSR2, 0x7e);//steven:for test IterateOnBssTab(pAd); } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -