📄 connect.c
字号:
pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; } else { // case 1.3. already connected to the SSID with highest RSSI. DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n")); // // (HCT 12.1) 1c_wlan_mediaevents required // media connect events are indicated when associating with the same AP // if (INFRA_ON(pAd)) { // // Since MediaState already is NdisMediaStateConnected // We just indicate the connect event again to meet the WHQL required. // pAd->IndicateMediaState = NdisMediaStateConnected; RTMP_IndicateMediaState(); } pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;#ifdef NATIVE_WPA_SUPPLICANT_SUPPORT { union iwreq_data wrqu; memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN); memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN); wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL); }#endif // NATIVE_WPA_SUPPLICANT_SUPPORT // } } else if (INFRA_ON(pAd)) { // // For RT61 // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: ) // RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect // But media status is connected, so the SSID not report correctly. // if (!SSID_EQUAL(pAd->CommonCfg.Ssid, pAd->CommonCfg.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, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n")); 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_DISASSOC; } else { if (ADHOC_ON(pAd)) { DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - drop current ADHOC\n")); LinkDown(pAd, FALSE); OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED); pAd->IndicateMediaState = NdisMediaStateDisconnected; RTMP_IndicateMediaState(); DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n")); } if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) && (pAd->StaCfg.bAutoReconnect == TRUE) && (pAd->MlmeAux.BssType == BSS_INFRA) && (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) == TRUE)) { MLME_SCAN_REQ_STRUCT ScanReq; DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n")); ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.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->StaCfg.LastScanTime = Now; } else { pAd->MlmeAux.BssIdx = 0; IterateOnBssTab(pAd); } } }/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ==========================================================================*/VOID CntlOidRTBssidProc( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM * Elem) { ULONG BssIdx; PUCHAR pOidBssid = (PUCHAR)Elem->Msg; MLME_DISASSOC_REQ_STRUCT DisassocReq; MLME_JOIN_REQ_STRUCT JoinReq; // record user desired settings COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid); pAd->MlmeAux.BssType = pAd->StaCfg.BssType; // find the desired BSS in the latest SCAN result table BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel); if (BssIdx == BSS_NOT_FOUND) { DBGPRINT(RT_DEBUG_TRACE, ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n")); pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; return; } // copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why? // Because we need this entry to become the JOIN target in later on SYNC state machine pAd->MlmeAux.BssIdx = 0; pAd->MlmeAux.SsidBssTab.BssNr = 1; NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY)); // // Update Reconnect Ssid, that user desired to connect. // NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID); pAd->MlmeAux.AutoReconnectSsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen; NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->ScanTab.BssEntry[BssIdx].SsidLen); // Add SSID into MlmeAux for site surey joining hidden SSID pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen; NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->MlmeAux.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 changed 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 (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pOidBssid)) { // 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; memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN); memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN); wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL); }#endif // NATIVE_WPA_SUPPLICANT_SUPPORT // } else { if (INFRA_ON(pAd)) { // disassoc from current AP first DBGPRINT(RT_DEBUG_TRACE, ("CNTL - disassociate with current AP ...\n")); 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_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); pAd->IndicateMediaState = NdisMediaStateDisconnected; RTMP_IndicateMediaState(); DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n")); } // Change the wepstatus to original wepstatus pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus; pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus; pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus; // Check cipher suite, AP must have more secured cipher than station setting // Set the Pairwise and Group cipher to match the intended AP setting // We can only connect to AP with less secured cipher setting if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) { pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.GroupCipher; if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher) pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher; else if (pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled) pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux; else // There is no PairCipher Aux, downgrade our capability to TKIP pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled; } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) { pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.GroupCipher; if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher) pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher; else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled) pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux; else // There is no PairCipher Aux, downgrade our capability to TKIP pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled; // RSN capability pAd->StaCfg.RsnCapability = pAd->ScanTab.BssEntry[BssIdx].WPA2.RsnCapability; } // Set Mix cipher flag if (pAd->StaCfg.PairCipher != pAd->StaCfg.GroupCipher) { pAd->StaCfg.bMixCipher = TRUE; // If mix cipher, re-build RSNIE RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0); } // No active association, join the BSS immediately DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n", pOidBssid[0],pOidBssid[1],pOidBssid[2],pOidBssid[3],pOidBssid[4],pOidBssid[5])); JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.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"?//// IRQL = DISPATCH_LEVELVOID CntlMlmeRoamingProc( IN PRTMP_ADAPTER 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 MlmeAux.RoamTab...\n")); NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, sizeof(pAd->MlmeAux.RoamTab)); pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr; BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab); pAd->MlmeAux.BssIdx = 0; IterateOnBssTab(pAd);}/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ==========================================================================*/VOID CntlWaitDisassocProc( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { MLME_START_REQ_STRUCT StartReq; if (Elem->MsgType == MT2_DISASSOC_CONF) { DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n")); LinkDown(pAd, FALSE); // case 1. no matching BSS, and user wants ADHOC, so we just start a new one if ((pAd->MlmeAux.SsidBssTab.BssNr==0) && (pAd->StaCfg.BssType == BSS_ADHOC)) { DBGPRINT(RT_DEBUG_TRACE, ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid)); StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.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 { pAd->MlmeAux.BssIdx = 0; IterateOnBssTab(pAd); } }}/* ========================================================================== Description: IRQL = DISPATCH_LEVEL ==========================================================================*/VOID CntlWaitJoinProc( IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { USHORT Reason; MLME_AUTH_REQ_STRUCT AuthReq; if (Elem->MsgType == MT2_JOIN_CONF) { NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT)); if (Reason == MLME_SUCCESS) { // 1. joined an IBSS, we are pretty much done here if (pAd->MlmeAux.BssType == BSS_ADHOC) { // // 5G bands rules of Japan: // Ad hoc must be disabled in W53(ch52,56,60,64) channels. // if ( (pAd->CommonCfg.bIEEE80211H == 1) && ((pAd->CommonCfg.Channel==52) || (pAd->CommonCfg.Channel==56) || (pAd->CommonCfg.Channel==60) || (pAd->CommonCfg.Channel==64)) ) { pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel)); return; } LinkUp(pAd, BSS_ADHOC); pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; DBGPRINT(RT_DEBUG_TRACE, ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n", pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2], pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5])); } // 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) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch)) { AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -