📄 connect.c
字号:
/*
***************************************************************************
* Ralink Tech Inc.
* 4F, No. 2 Technology 5th Rd.
* Science-based Industrial Park
* Hsin-chu, Taiwan, R.O.C.
*
* (c) Copyright 2002-2004, 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
-------- ---------- ----------------------------------------------
Name Date Modification logs
Jan Lee 2005-06-01 Release
*/
#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, 0x00, // 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, 0x00, // unicast
0x01, 0x00, // number of authentication method
0x00, 0x50, 0xf2, 0x00 // authentication
};
UCHAR CipherSuiteWpaNoneAesLen = (sizeof(CipherSuiteWpaNoneAes) / sizeof(UCHAR));
/*
==========================================================================
Description:
==========================================================================
*/
VOID MlmeCntlInit(
IN PRT2570ADAPTER 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 PRT2570ADAPTER 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);
if (pAd->Mlme.CntlAux.CurrReqIsFromNdis)
{
NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_SUCCESS);
}
pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
}
//
// Following line will potentially cause infinite loop
//
//if (pAd->MediaState == NdisMediaStateDisconnected)
// MlmeAutoReconnectLastSSID(pAd);
break;
case CNTL_WAIT_OID_DISASSOC:
if (Elem->MsgType == MT2_DISASSOC_CONF)
{
DBGPRINT_RAW(RT_DEBUG_TRACE, "LinkDown(MlmeCntlMachinePerformAction)\n");
LinkDown(pAd);
if (pAd->Mlme.CntlAux.CurrReqIsFromNdis)
{
NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_SUCCESS);
}
pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
}
break;
default:
DBGPRINT(RT_DEBUG_ERROR, "CNTL - Illegal message type(=%d)", Elem->MsgType);
break;
}
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID CntlIdleProc(
IN PRT2570ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
MLME_DISASSOC_REQ_STRUCT DisassocReq;
if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
{
if (pAd->Mlme.CntlAux.CurrReqIsFromNdis)
{
NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_FAILURE);
pAd->Mlme.CntlAux.CurrReqIsFromNdis = FALSE;
}
return;
}
switch(Elem->MsgType)
{
case OID_802_11_SSID:
CntlOidSsidProc(pAd, Elem);
break;
case RT_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 control aux SSID to prevent it reconnect to old SSID
// Since calling this indicate user don't want to connect to that SSID anymore.
pAd->Mlme.CntlAux.SsidLen = 32;
NdisZeroMemory(pAd->Mlme.CntlAux.Ssid, pAd->Mlme.CntlAux.SsidLen);
break;
case MT2_MLME_ROAMING_REQ:
CntlMlmeRoamingProc(pAd, Elem);
break;
default:
DBGPRINT(RT_DEBUG_TRACE, "CNTL - Illegal message in CntlIdleProc(MsgType=%d)\n",Elem->MsgType);
break;
}
}
VOID CntlOidScanProc(
IN PRT2570ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
MLME_SCAN_REQ_STRUCT ScanReq;
CHAR BroadSsid[MAX_LEN_OF_SSID];
ULONG BssIdx = BSS_NOT_FOUND;
BSS_ENTRY CurrBss;
ULONG Now;
// 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 (pAd->MediaState == NdisMediaStateConnected) // if (INFRA_ON(pAd) || ADHOC_ON(pAd))
{
BssIdx = BssTableSearch(&pAd->PortCfg.BssTab, &pAd->PortCfg.Bssid);
if (BssIdx != BSS_NOT_FOUND)
{
NdisMoveMemory(&CurrBss, &pAd->PortCfg.BssTab.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 = 18; // about -82 dB
}
}
// clean up previous SCAN result, add current BSS back to table if any
BssTableInit(&pAd->PortCfg.BssTab);
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->PortCfg.BssTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY));
pAd->PortCfg.BssTab.BssNr = 1;
}
BroadSsid[0] = '\0';
ScanParmFill(pAd, &ScanReq, BroadSsid, 0, BSS_ANY, SCAN_PASSIVE);
MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
Now = jiffies;
pAd->PortCfg.LastScanTime = Now;
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID CntlOidSsidProc(
IN PRT2570ADAPTER pAd,
IN MLME_QUEUE_ELEM * Elem)
{
NDIS_802_11_SSID *OidSsid = (NDIS_802_11_SSID *)Elem->Msg;
MLME_DISASSOC_REQ_STRUCT DisassocReq;
ULONG Now;
// Step 0.
// record the desired SSID and all matching BSSes into CntlAux.SsidBssTab for
// later-on iteration. Sort by RSSI order
if (OidSsid->Ssid[0] == 0)
{
DBGPRINT_RAW(RT_DEBUG_TRACE, "empty string SSID\n");
pAd->Mlme.CntlAux.SsidLen = 0;
}
else
pAd->Mlme.CntlAux.SsidLen = (UCHAR)OidSsid->SsidLength;
NdisMoveMemory(pAd->Mlme.CntlAux.Ssid, OidSsid->Ssid, pAd->Mlme.CntlAux.SsidLen);
BssTableSsidSort(pAd, &pAd->Mlme.CntlAux.SsidBssTab, pAd->Mlme.CntlAux.Ssid, pAd->Mlme.CntlAux.SsidLen);
pAd->Mlme.CntlAux.BssIdx = 0;
DBGPRINT(RT_DEBUG_TRACE,"CNTL - %d BSS match the desire SSID %s\n",pAd->Mlme.CntlAux.SsidBssTab.BssNr, pAd->Mlme.CntlAux.Ssid);
Now = jiffies;
if ((pAd->MediaState == NdisMediaStateConnected) &&
MAC_ADDR_EQUAL(&pAd->PortCfg.Bssid, &pAd->Mlme.CntlAux.SsidBssTab.BssEntry[0].Bssid))
{
if (((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) &&
(pAd->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
{
// 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)
{
// Config has changed, we have to reconnect 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
{
// We only check if same to the BSSID with highest RSSI.
// If roaming of same SSID required, we still do the reconnection.
// same BSSID, go back to idle state directly
DBGPRINT(RT_DEBUG_TRACE, "CNTL - already with this BSSID. ignore this SET_SSID request\n");
if (pAd->Mlme.CntlAux.CurrReqIsFromNdis)
{
NdisMSetInformationComplete(pAd->AdapterHandle, NDIS_STATUS_SUCCESS);
}
pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
}
}
else if (INFRA_ON(pAd))
{
// case 1. active 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 (or previous) associated AP, if any,
// then perform a new association with this new SSID, no matter the
// new/old SSID are the same or npt.
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"));
DBGPRINT_RAW(RT_DEBUG_TRACE, "LinkDown(CntlOidSsidProc)\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");
}
if ((pAd->Mlme.CntlAux.SsidBssTab.BssNr == 0) &&
(pAd->PortCfg.AutoReconnect == TRUE) &&
(pAd->PortCfg.BssType == BSS_INFRA) &&
(MlmeValidateSSID(pAd) == TRUE))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -