📄 sta_assoc.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:
sta_assoc.c
Abstract:
Revision History:
Who When What
-------- ---------- ----------------------------------------------
Fonchi 2006-6-23 modified for rt61-APClinent
*/
#include "rt_config.h"
#include <net/iw_handler.h>
/*
==========================================================================
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
==========================================================================
*/
VOID StaAssocStateMachineInit(
IN PRTMP_ADAPTER pAd,
IN STA_STATE_MACHINE *S,
OUT STA_STATE_MACHINE_FUNC Trans[])
{
UCHAR i;
StaStateMachineInit(S, (STA_STATE_MACHINE_FUNC*)Trans, STA_MAX_ASSOC_STATE, STA_MAX_ASSOC_MSG, (STA_STATE_MACHINE_FUNC)StaDrop, STA_ASSOC_IDLE, STA_ASSOC_MACHINE_BASE);
// first column
StaStateMachineSetAction(S, STA_ASSOC_IDLE, STA_MT2_MLME_ASSOC_REQ, (STA_STATE_MACHINE_FUNC)StaMlmeAssocReqAction);
StaStateMachineSetAction(S, STA_ASSOC_IDLE, STA_MT2_MLME_DISASSOC_REQ, (STA_STATE_MACHINE_FUNC)StaMlmeDisassocReqAction);
StaStateMachineSetAction(S, STA_ASSOC_IDLE, STA_MT2_PEER_DISASSOC_REQ, (STA_STATE_MACHINE_FUNC)StaPeerDisassocAction);
// second column
StaStateMachineSetAction(S, STA_ASSOC_WAIT_RSP, STA_MT2_MLME_ASSOC_REQ, (STA_STATE_MACHINE_FUNC)StaInvalidStateWhenAssoc);
StaStateMachineSetAction(S, STA_ASSOC_WAIT_RSP, STA_MT2_MLME_DISASSOC_REQ, (STA_STATE_MACHINE_FUNC)StaInvalidStateWhenDisassociate);
StaStateMachineSetAction(S, STA_ASSOC_WAIT_RSP, STA_MT2_PEER_DISASSOC_REQ, (STA_STATE_MACHINE_FUNC)StaPeerDisassocAction);
StaStateMachineSetAction(S, STA_ASSOC_WAIT_RSP, STA_MT2_PEER_ASSOC_RSP, (STA_STATE_MACHINE_FUNC)StaPeerAssocRspAction);
StaStateMachineSetAction(S, STA_ASSOC_WAIT_RSP, STA_MT2_ASSOC_TIMEOUT, (STA_STATE_MACHINE_FUNC)StaAssocTimeoutAction);
// timer init
RTMPInitTimer(pAd, &pAd->MlmeAux.ApCliAssocTimer, (PVOID)&StaAssocTimeout);
for (i=0; i < MAX_APCLI_ENTRY; i++)
pAd->ApCliTab.ApCliEntry[i].AssocCurrState = STA_ASSOC_IDLE;
return;
}
/*
==========================================================================
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
==========================================================================
*/
VOID StaAssocTimeout(
IN unsigned long data)
{
RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)data;
DBGPRINT(RT_DEBUG_TRACE,"STA_ASSOC - enqueue STA_MT2_ASSOC_TIMEOUT \n");
StaMlmeEnqueue(pAd, STA_ASSOC_STATE_MACHINE, STA_MT2_ASSOC_TIMEOUT, 0, NULL, 0);
MlmeHandler(pAd);
return;
}
/*
==========================================================================
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
==========================================================================
*/
VOID StaMlmeAssocReqAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem,
OUT PULONG pCurrState,
IN USHORT ifIndex)
{
UCHAR ApAddr[6];
HEADER_802_11 AssocHdr;
UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, STA_QOS_CAPABILITY};
USHORT ListenIntv;
ULONG Timeout;
USHORT CapabilityInfo;
PUCHAR pOutBuffer = NULL;
ULONG FrameLen = 0;
ULONG tmp;
UCHAR SsidIe = IE_SSID;
UCHAR SupRateIe = IE_SUPP_RATES;
UCHAR ExtRateIe = IE_EXT_SUPP_RATES;
STA_CTRL_MSG_STRUCT StaCtrlMsg;
// Block all authentication request durning WPA block period
if (pAd->ApCliTab.ApCliEntry[ifIndex].bBlockAssoc == TRUE)
{
DBGPRINT(RT_DEBUG_TRACE, "STA ASSOC - Block Auth request durning WPA block period!\n");
pAd->Mlme.AuthMachine.CurrState = STA_ASSOC_IDLE;
StaCtrlMsg.Status = MLME_STATE_MACHINE_REJECT;
StaMlmeEnqueue(pAd, STA_CTRL_STATE_MACHINE, STA_CTRL_ASSOC_RSP,
sizeof(STA_CTRL_MSG_STRUCT), &StaCtrlMsg, ifIndex);
}
else if(MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))
{
RTMPCancelTimer(&pAd->MlmeAux.ApCliAssocTimer);
// allocate and send out AssocRsp frame
pOutBuffer = kmalloc(MAX_LEN_OF_MLME_BUFFER, MEM_ALLOC_FLAG);
if(pOutBuffer == NULL)
{
DBGPRINT(RT_DEBUG_TRACE,"STA_ASSOC - StaMlmeAssocReqAction() allocate memory failed \n");
*pCurrState = STA_ASSOC_IDLE;
StaCtrlMsg.Status = MLME_FAIL_NO_RESOURCE;
StaMlmeEnqueue(pAd, STA_CTRL_STATE_MACHINE, STA_CTRL_ASSOC_RSP,
sizeof(STA_CTRL_MSG_STRUCT), &StaCtrlMsg, ifIndex);
return;
}
DBGPRINT(RT_DEBUG_TRACE, "STA_ASSOC - Send ASSOC request...\n");
ApCliMgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr, ApAddr, ifIndex);
// Build basic frame first
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof(HEADER_802_11), &AssocHdr,
2, &CapabilityInfo,
2, &ListenIntv,
1, &SsidIe,
1, &pAd->MlmeAux.SsidLen,
pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
1, &SupRateIe,
1, &pAd->MlmeAux.SupRateLen,
pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
END_OF_ARGS);
if(pAd->MlmeAux.ExtRateLen != 0)
{
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &ExtRateIe,
1, &pAd->MlmeAux.ExtRateLen,
pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
END_OF_ARGS);
FrameLen += tmp;
}
if(pAd->MlmeAux.APEdcaParm.bValid)
{
WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f);
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
9, &WmeIe[0],
END_OF_ARGS);
FrameLen += tmp;
}
#ifdef APCLI_SUPPORT
// Append RSN_IE when WPAPSK OR WPA2PSK,
if ((pAd->PortCfg.MBSSID[MAIN_MBSSID].AuthMode == Ndis802_11AuthModeWPAPSK) ||
(pAd->PortCfg.MBSSID[MAIN_MBSSID].AuthMode == Ndis802_11AuthModeWPA2PSK))
{
UCHAR RSNIe = IE_WPA;
if (pAd->PortCfg.MBSSID[MAIN_MBSSID].AuthMode == Ndis802_11AuthModeWPA2PSK)
RSNIe = IE_WPA2;
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &RSNIe,
1, &pAd->PortCfg.MBSSID[MAIN_MBSSID].RSNIE_Len[0],
pAd->PortCfg.MBSSID[MAIN_MBSSID].RSNIE_Len[0], pAd->PortCfg.MBSSID[MAIN_MBSSID].RSN_IE[0],
END_OF_ARGS);
FrameLen += tmp;
}
#endif
#ifdef AGGREGATION_SUPPORT
// add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION
// Case I: (Aggregation)
// 1. user enable aggregation, AND
// 2. AP annouces it's AGGREGATION-capable in BEACON
if(pAd->PortCfg.bAggregationCapable)
{
if(pAd->MlmeAux.APRalinkIe & 0x00000001)
{
ULONG TmpLen;
UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};
MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
9, RalinkIe,
END_OF_ARGS);
FrameLen += TmpLen;
}
}
#endif /* AGGREGATION_SUPPORT */
MiniportMMRequest(pAd, pOutBuffer, FrameLen);
kfree( pOutBuffer);
RTMPAddTimer(&pAd->MlmeAux.ApCliAssocTimer, Timeout);
*pCurrState = STA_ASSOC_WAIT_RSP;
} else
{
DBGPRINT(RT_DEBUG_TRACE,"STA_ASSOC - StaMlmeAssocReqAction() sanity check failed. BUG!!!!!! \n");
*pCurrState = STA_ASSOC_IDLE;
StaCtrlMsg.Status = MLME_INVALID_FORMAT;
StaMlmeEnqueue(pAd, STA_CTRL_STATE_MACHINE, STA_CTRL_ASSOC_RSP,
sizeof(STA_CTRL_MSG_STRUCT), &StaCtrlMsg, ifIndex);
}
return;
}
/*
==========================================================================
Description:
Upper layer issues disassoc request
Parameters:
Elem -
==========================================================================
*/
VOID StaMlmeDisassocReqAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem,
OUT PULONG pCurrState,
IN USHORT ifIndex)
{
PMLME_DISASSOC_REQ_STRUCT pDisassocReq;
HEADER_802_11 DisassocHdr;
PCHAR pOutBuffer = NULL;
ULONG FrameLen = 0;
#if defined(WPA_SUPPLICANT_SUPPORT) && (WPA_SUPPLICANT_SUPPORT == 1)
union iwreq_data wrqu;
#endif
STA_CTRL_MSG_STRUCT StaCtrlMsg;
// skip sanity check
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -