📄 assoc.c
字号:
/*************************************************************************** * RT2x00 SourceForge Project - http://rt2x00.sourceforge.net * * * * 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. * * * * Licensed under the GNU GPL * * Original code supplied under license from RaLink Inc, 2004. * ***************************************************************************//*************************************************************************** * Module Name: assoc.c * * Abstract: * * Revision History: * Who When What * -------- ---------- ------------------------------- * Name Date Modification logs * Jan Lee 2005-06-01 Release ***************************************************************************/#include "rt_config.h"UCHAR CipherWpaTemplate[] = { 0xdd, // WPA IE 0x16, // Length 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, 0x01 // authentication };UCHAR CipherWpa2Template[] = { 0x30, // RSN IE 0x14, // Length 0x01, 0x00, // Version 0x00, 0x0f, 0xac, 0x02, // group cipher, TKIP 0x01, 0x00, // number of pairwise 0x00, 0x0f, 0xac, 0x02, // unicast 0x01, 0x00, // number of authentication method 0x00, 0x0f, 0xac, 0x02, // authentication 0x00, 0x00, // RSN capability };/* ========================================================================== Description: association state machine init, including state transition and timer init Parameters: S - pointer to the association state machine Note: The state machine looks like the following ASSOC_IDLE ASSOC_WAIT_RSP REASSOC_WAIT_RSP DISASSOC_WAIT_RSP MT2_MLME_ASSOC_REQ mlme_assoc_req_action invalid_state_when_assoc invalid_state_when_assoc invalid_state_when_assoc MT2_MLME_REASSOC_REQ mlme_reassoc_req_action invalid_state_when_reassoc invalid_state_when_reassoc invalid_state_when_reassoc MT2_MLME_DISASSOC_REQ mlme_disassoc_req_action mlme_disassoc_req_action mlme_disassoc_req_action mlme_disassoc_req_action MT2_PEER_DISASSOC_REQ peer_disassoc_action peer_disassoc_action peer_disassoc_action peer_disassoc_action MT2_PEER_ASSOC_REQ drop drop drop drop MT2_PEER_ASSOC_RSP drop peer_assoc_rsp_action drop drop MT2_PEER_REASSOC_REQ drop drop drop drop MT2_PEER_REASSOC_RSP drop drop peer_reassoc_rsp_action drop MT2_CLS3ERR cls3err_action cls3err_action cls3err_action cls3err_action MT2_ASSOC_TIMEOUT timer_nop assoc_timeout_action timer_nop timer_nop MT2_REASSOC_TIMEOUT timer_nop timer_nop reassoc_timeout_action timer_nop MT2_DISASSOC_TIMEOUT timer_nop timer_nop timer_nop disassoc_timeout_action IRQL = PASSIVE_LEVEL ========================================================================== */VOID AssocStateMachineInit( IN PRT2570ADAPTER pAd, IN STATE_MACHINE *S, OUT STATE_MACHINE_FUNC Trans[]) { StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG, (STATE_MACHINE_FUNC)Drop, ASSOC_IDLE, ASSOC_MACHINE_BASE); // first column StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)MlmeAssocReqAction); StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)MlmeReassocReqAction); StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)MlmeDisassocReqAction); StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction); //StateMachineSetAction(S, ASSOC_IDLE, MT2_CLS3ERR, Cls3errAction); // second column StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc); StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc); StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate); StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction); StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, (STATE_MACHINE_FUNC)PeerAssocRspAction); //StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_CLS3ERR, Cls3errAction); StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT, (STATE_MACHINE_FUNC)AssocTimeoutAction); // third column StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc); StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc); StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate); StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction); StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, (STATE_MACHINE_FUNC)PeerReassocRspAction); // StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_CLS3ERR, Cls3errAction); StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT, (STATE_MACHINE_FUNC)ReassocTimeoutAction); // fourth column StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenAssoc); StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenReassoc); StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenDisassociate); StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, (STATE_MACHINE_FUNC)PeerDisassocAction); //StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_CLS3ERR, Cls3errAction); StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT, (STATE_MACHINE_FUNC)DisassocTimeoutAction); // initialize the timer RTMPInitTimer(pAd, &pAd->Mlme.AssocAux.AssocTimer, AssocTimeout); RTMPInitTimer(pAd, &pAd->Mlme.AssocAux.ReassocTimer, ReassocTimeout); RTMPInitTimer(pAd, &pAd->Mlme.AssocAux.DisassocTimer, DisassocTimeout);}/* ========================================================================== Description: Association timeout procedure. After association timeout, this function will be called and it will put a message into the MLME queue Parameters: Standard timer parameters IRQL = DISPATCH_LEVEL ========================================================================== */VOID AssocTimeout(unsigned long data){ PRT2570ADAPTER pAd = (PRT2570ADAPTER)data; DBGPRINT(RT_DEBUG_TRACE, "ASSOC - enqueue MT2_ASSOC_TIMEOUT \n"); // Do nothing if the driver is starting halt state. // This might happen when timer already been fired before cancel timer with mlmehalt if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) return; MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL); //KeSetEvent(&pAd->MLMEEvent, 0, FALSE); RTUSBUp(pAd, (&(pAd->mlme_semaphore)));}/* ========================================================================== Description: Reassociation timeout procedure. After reassociation timeout, this function will be called and put a message into the MLME queue Parameters: Standard timer parameters IRQL = DISPATCH_LEVEL ========================================================================== */VOID ReassocTimeout(unsigned long data){ PRT2570ADAPTER pAd = (PRT2570ADAPTER)data; DBGPRINT(RT_DEBUG_TRACE,"ASSOC - enqueue MT2_REASSOC_TIMEOUT \n"); // Do nothing if the driver is starting halt state. // This might happen when timer already been fired before cancel timer with mlmehalt if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) return; MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL); //KeSetEvent(&pAd->MLMEEvent, 0, FALSE); RTUSBUp(pAd, (&(pAd->mlme_semaphore)));}/* ========================================================================== Description: Disassociation timeout procedure. After disassociation timeout, this function will be called and put a message into the MLME queue Parameters: Standard timer parameters IRQL = DISPATCH_LEVEL ========================================================================== */VOID DisassocTimeout(unsigned long data){ PRT2570ADAPTER pAd = (PRT2570ADAPTER)data; DBGPRINT(RT_DEBUG_TRACE,"ASSOC - enqueue MT2_DISASSOC_TIMEOUT \n"); // Do nothing if the driver is starting halt state. // This might happen when timer already been fired before cancel timer with mlmehalt if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) return; MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL); //KeSetEvent(&pAd->MLMEEvent, 0, FALSE); RTUSBUp(pAd, (&(pAd->mlme_semaphore)));}/* ========================================================================== Description: mlme assoc req handling procedure Parameters: Adapter - Adapter pointer Elem - MLME Queue Element Pre: the station has been authenticated and the following information is stored in the config -# SSID -# supported rates and their length -# listen interval (Adapter->PortCfg.default_listen_count) -# Transmit power (Adapter->PortCfg.tx_power) Post : -# An association request frame is generated and sent to the air -# Association timer starts -# Association state -> ASSOC_WAIT_RSP IRQL = DISPATCH_LEVEL ========================================================================== */VOID MlmeAssocReqAction( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { MACADDR ApAddr; MACHDR AssocHdr; UCHAR SsidIe = IE_SSID, RateIe = IE_SUPP_RATES, ExtRateIe = IE_EXT_SUPP_RATES; UCHAR CipherTmp[64]; UCHAR CipherTmpLen; USHORT ListenIntv; ULONG Timeout; USHORT CapabilityInfo; UCHAR *OutBuffer = NULL; NDIS_STATUS NStatus; ULONG FrameLen = 0; ULONG tmp, idx; BOOLEAN FoundPMK = FALSE; UCHAR VarIesOffset; // Block all authentication request durning WPA block period if (pAd->PortCfg.bBlockAssoc == TRUE) { DBGPRINT(RT_DEBUG_TRACE, "ASSOC - Block Assoc request durning WPA block period!\n"); pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; MlmeCntlConfirm(pAd, MT2_ASSOC_CONF, MLME_STATE_MACHINE_REJECT); } // check sanity first else if (MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, &ApAddr, &CapabilityInfo, &Timeout, &ListenIntv)) { RTMPCancelTimer(&pAd->Mlme.AssocAux.AssocTimer); COPY_MAC_ADDR(&pAd->Mlme.AssocAux.Addr, &ApAddr); // Mask out unnecessary capability information CapabilityInfo &= SUPPORTED_CAPABILITY_INFO; // pAd->PortCfg.SupportedCapabilityInfo; pAd->Mlme.AssocAux.CapabilityInfo = CapabilityInfo; pAd->Mlme.AssocAux.ListenIntv = ListenIntv; NStatus = MlmeAllocateMemory(pAd, (PVOID)&OutBuffer); //Get an unused nonpaged memory if (NStatus != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_TRACE,"ASSOC - MlmeAssocReqAction() allocate memory failed \n"); pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; MlmeCntlConfirm(pAd, MT2_ASSOC_CONF, MLME_FAIL_NO_RESOURCE); return; } // Add by James 03/06/27 pAd->PortCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION); // Association don't need to report MAC address pAd->PortCfg.AssocInfo.AvailableRequestFixedIEs = NDIS_802_11_AI_REQFI_CAPABILITIES | NDIS_802_11_AI_REQFI_LISTENINTERVAL; pAd->PortCfg.AssocInfo.RequestFixedIEs.Capabilities = CapabilityInfo; pAd->PortCfg.AssocInfo.RequestFixedIEs.ListenInterval = ListenIntv; // Only reassociate need this // memcpy(pAd->PortCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, &AssocHdr, sizeof(NDIS_802_11_MAC_ADDRESS)); pAd->PortCfg.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION); // First add SSID VarIesOffset = 0; memcpy(pAd->PortCfg.ReqVarIEs + VarIesOffset, &SsidIe, 1); VarIesOffset += 1; memcpy(pAd->PortCfg.ReqVarIEs + VarIesOffset, &pAd->PortCfg.SsidLen, 1); VarIesOffset += 1; memcpy(pAd->PortCfg.ReqVarIEs + VarIesOffset, pAd->PortCfg.Ssid, pAd->PortCfg.SsidLen); VarIesOffset += pAd->PortCfg.SsidLen; // Second add Supported rates memcpy(pAd->PortCfg.ReqVarIEs + VarIesOffset, &RateIe, 1); VarIesOffset += 1; memcpy(pAd->PortCfg.ReqVarIEs + VarIesOffset, &pAd->PortCfg.SupportedRatesLen, 1); VarIesOffset += 1; memcpy(pAd->PortCfg.ReqVarIEs + VarIesOffset, pAd->PortCfg.SupportedRates, pAd->PortCfg.SupportedRatesLen);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -