2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
34 -------- ---------- ----------------------------------------------
35 John 2004-9-3 porting from RT2500
37 #include "../rt_config.h"
39 u8 CipherWpaTemplate[] = {
42 0x00, 0x50, 0xf2, 0x01, /* oui */
43 0x01, 0x00, /* Version */
44 0x00, 0x50, 0xf2, 0x02, /* Multicast */
45 0x01, 0x00, /* Number of unicast */
46 0x00, 0x50, 0xf2, 0x02, /* unicast */
47 0x01, 0x00, /* number of authentication method */
48 0x00, 0x50, 0xf2, 0x01 /* authentication */
51 u8 CipherWpa2Template[] = {
54 0x01, 0x00, /* Version */
55 0x00, 0x0f, 0xac, 0x02, /* group cipher, TKIP */
56 0x01, 0x00, /* number of pairwise */
57 0x00, 0x0f, 0xac, 0x02, /* unicast */
58 0x01, 0x00, /* number of authentication method */
59 0x00, 0x0f, 0xac, 0x02, /* authentication */
60 0x00, 0x00, /* RSN capability */
63 u8 Ccx2IeInfo[] = { 0x00, 0x40, 0x96, 0x03, 0x02 };
66 ==========================================================================
68 association state machine init, including state transition and timer init
70 S - pointer to the association state machine
74 ==========================================================================
76 void AssocStateMachineInit(struct rt_rtmp_adapter *pAd,
77 struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[])
79 StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG,
80 (STATE_MACHINE_FUNC) Drop, ASSOC_IDLE,
84 StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ,
85 (STATE_MACHINE_FUNC) MlmeAssocReqAction);
86 StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ,
87 (STATE_MACHINE_FUNC) MlmeReassocReqAction);
88 StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ,
89 (STATE_MACHINE_FUNC) MlmeDisassocReqAction);
90 StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ,
91 (STATE_MACHINE_FUNC) PeerDisassocAction);
94 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ,
95 (STATE_MACHINE_FUNC) InvalidStateWhenAssoc);
96 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ,
97 (STATE_MACHINE_FUNC) InvalidStateWhenReassoc);
98 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ,
100 InvalidStateWhenDisassociate);
101 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ,
102 (STATE_MACHINE_FUNC) PeerDisassocAction);
103 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP,
104 (STATE_MACHINE_FUNC) PeerAssocRspAction);
106 /* Patch 3Com AP MOde:3CRWE454G72 */
107 /* We send Assoc request frame to this AP, it always send Reassoc Rsp not Associate Rsp. */
109 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP,
110 (STATE_MACHINE_FUNC) PeerAssocRspAction);
111 StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT,
112 (STATE_MACHINE_FUNC) AssocTimeoutAction);
115 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ,
116 (STATE_MACHINE_FUNC) InvalidStateWhenAssoc);
117 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ,
118 (STATE_MACHINE_FUNC) InvalidStateWhenReassoc);
119 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ,
121 InvalidStateWhenDisassociate);
122 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ,
123 (STATE_MACHINE_FUNC) PeerDisassocAction);
124 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP,
125 (STATE_MACHINE_FUNC) PeerReassocRspAction);
127 /* Patch, AP doesn't send Reassociate Rsp frame to Station. */
129 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP,
130 (STATE_MACHINE_FUNC) PeerReassocRspAction);
131 StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT,
132 (STATE_MACHINE_FUNC) ReassocTimeoutAction);
135 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ,
136 (STATE_MACHINE_FUNC) InvalidStateWhenAssoc);
137 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ,
138 (STATE_MACHINE_FUNC) InvalidStateWhenReassoc);
139 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ,
141 InvalidStateWhenDisassociate);
142 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ,
143 (STATE_MACHINE_FUNC) PeerDisassocAction);
144 StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT,
145 (STATE_MACHINE_FUNC) DisassocTimeoutAction);
147 /* initialize the timer */
148 RTMPInitTimer(pAd, &pAd->MlmeAux.AssocTimer,
149 GET_TIMER_FUNCTION(AssocTimeout), pAd, FALSE);
150 RTMPInitTimer(pAd, &pAd->MlmeAux.ReassocTimer,
151 GET_TIMER_FUNCTION(ReassocTimeout), pAd, FALSE);
152 RTMPInitTimer(pAd, &pAd->MlmeAux.DisassocTimer,
153 GET_TIMER_FUNCTION(DisassocTimeout), pAd, FALSE);
157 ==========================================================================
159 Association timeout procedure. After association timeout, this function
160 will be called and it will put a message into the MLME queue
162 Standard timer parameters
164 IRQL = DISPATCH_LEVEL
166 ==========================================================================
168 void AssocTimeout(void *SystemSpecific1,
169 void *FunctionContext,
170 void *SystemSpecific2, void *SystemSpecific3)
172 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
174 /* Do nothing if the driver is starting halt state. */
175 /* This might happen when timer already been fired before cancel timer with mlmehalt */
177 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
180 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL);
181 RTMP_MLME_HANDLER(pAd);
185 ==========================================================================
187 Reassociation timeout procedure. After reassociation timeout, this
188 function will be called and put a message into the MLME queue
190 Standard timer parameters
192 IRQL = DISPATCH_LEVEL
194 ==========================================================================
196 void ReassocTimeout(void *SystemSpecific1,
197 void *FunctionContext,
198 void *SystemSpecific2, void *SystemSpecific3)
200 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
202 /* Do nothing if the driver is starting halt state. */
203 /* This might happen when timer already been fired before cancel timer with mlmehalt */
205 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
208 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL);
209 RTMP_MLME_HANDLER(pAd);
213 ==========================================================================
215 Disassociation timeout procedure. After disassociation timeout, this
216 function will be called and put a message into the MLME queue
218 Standard timer parameters
220 IRQL = DISPATCH_LEVEL
222 ==========================================================================
224 void DisassocTimeout(void *SystemSpecific1,
225 void *FunctionContext,
226 void *SystemSpecific2, void *SystemSpecific3)
228 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext;
230 /* Do nothing if the driver is starting halt state. */
231 /* This might happen when timer already been fired before cancel timer with mlmehalt */
233 (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
236 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL);
237 RTMP_MLME_HANDLER(pAd);
241 ==========================================================================
243 mlme assoc req handling procedure
245 Adapter - Adapter pointer
246 Elem - MLME Queue Element
248 the station has been authenticated and the following information is stored in the config
250 -# supported rates and their length
251 -# listen interval (Adapter->StaCfg.default_listen_count)
252 -# Transmit power (Adapter->StaCfg.tx_power)
254 -# An association request frame is generated and sent to the air
255 -# Association timer starts
256 -# Association state -> ASSOC_WAIT_RSP
258 IRQL = DISPATCH_LEVEL
260 ==========================================================================
262 void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
265 struct rt_header_802_11 AssocHdr;
267 { IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01,
270 unsigned long Timeout;
272 BOOLEAN TimerCancelled;
273 u8 *pOutBuffer = NULL;
275 unsigned long FrameLen = 0;
280 /* Block all authentication request durning WPA block period */
281 if (pAd->StaCfg.bBlockAssoc == TRUE) {
282 DBGPRINT(RT_DEBUG_TRACE,
283 ("ASSOC - Block Assoc request durning WPA block period!\n"));
284 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
285 Status = MLME_STATE_MACHINE_REJECT;
286 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2,
289 /* check sanity first */
290 else if (MlmeAssocReqSanity
291 (pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo,
292 &Timeout, &ListenIntv)) {
293 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled);
294 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
296 /* Get an unused nonpaged memory */
297 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
298 if (NStatus != NDIS_STATUS_SUCCESS) {
299 DBGPRINT(RT_DEBUG_TRACE,
300 ("ASSOC - MlmeAssocReqAction() allocate memory failed \n"));
301 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
302 Status = MLME_FAIL_NO_RESOURCE;
303 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
304 MT2_ASSOC_CONF, 2, &Status);
307 /* Add by James 03/06/27 */
308 pAd->StaCfg.AssocInfo.Length =
309 sizeof(struct rt_ndis_802_11_association_information);
310 /* Association don't need to report MAC address */
311 pAd->StaCfg.AssocInfo.AvailableRequestFixedIEs =
312 NDIS_802_11_AI_REQFI_CAPABILITIES |
313 NDIS_802_11_AI_REQFI_LISTENINTERVAL;
314 pAd->StaCfg.AssocInfo.RequestFixedIEs.Capabilities =
316 pAd->StaCfg.AssocInfo.RequestFixedIEs.ListenInterval =
318 /* Only reassociate need this */
319 /*COPY_MAC_ADDR(pAd->StaCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, ApAddr); */
320 pAd->StaCfg.AssocInfo.OffsetRequestIEs =
321 sizeof(struct rt_ndis_802_11_association_information);
323 NdisZeroMemory(pAd->StaCfg.ReqVarIEs, MAX_VIE_LEN);
326 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SsidIe,
329 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
330 &pAd->MlmeAux.SsidLen, 1);
332 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
333 pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
334 VarIesOffset += pAd->MlmeAux.SsidLen;
336 /* Second add Supported rates */
337 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SupRateIe,
340 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
341 &pAd->MlmeAux.SupRateLen, 1);
343 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
344 pAd->MlmeAux.SupRate, pAd->MlmeAux.SupRateLen);
345 VarIesOffset += pAd->MlmeAux.SupRateLen;
346 /* End Add by James */
348 if ((pAd->CommonCfg.Channel > 14) &&
349 (pAd->CommonCfg.bIEEE80211H == TRUE))
350 CapabilityInfo |= 0x0100;
352 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send ASSOC request...\n"));
353 MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr,
356 /* Build basic frame first */
357 MakeOutgoingFrame(pOutBuffer, &FrameLen,
358 sizeof(struct rt_header_802_11), &AssocHdr,
362 1, &pAd->MlmeAux.SsidLen,
363 pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
365 1, &pAd->MlmeAux.SupRateLen,
366 pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
369 if (pAd->MlmeAux.ExtRateLen != 0) {
370 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
372 1, &pAd->MlmeAux.ExtRateLen,
373 pAd->MlmeAux.ExtRateLen,
374 pAd->MlmeAux.ExtRate, END_OF_ARGS);
378 if ((pAd->MlmeAux.HtCapabilityLen > 0)
379 && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
380 unsigned long TmpLen;
382 u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 };
383 if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE) {
384 HtLen = SIZE_HT_CAP_IE + 4;
385 MakeOutgoingFrame(pOutBuffer + FrameLen,
386 &TmpLen, 1, &WpaIe, 1, &HtLen,
388 pAd->MlmeAux.HtCapabilityLen,
389 &pAd->MlmeAux.HtCapability,
392 MakeOutgoingFrame(pOutBuffer + FrameLen,
393 &TmpLen, 1, &HtCapIe, 1,
394 &pAd->MlmeAux.HtCapabilityLen,
395 pAd->MlmeAux.HtCapabilityLen,
396 &pAd->MlmeAux.HtCapability,
401 /* add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION */
402 /* Case I: (Aggregation + Piggy-Back) */
403 /* 1. user enable aggregation, AND */
404 /* 2. Mac support piggy-back */
405 /* 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON */
406 /* Case II: (Aggregation) */
407 /* 1. user enable aggregation, AND */
408 /* 2. AP annouces it's AGGREGATION-capable in BEACON */
409 if (pAd->CommonCfg.bAggregationCapable) {
410 if ((pAd->CommonCfg.bPiggyBackCapable)
411 && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)) {
412 unsigned long TmpLen;
414 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
415 0x03, 0x00, 0x00, 0x00 };
416 MakeOutgoingFrame(pOutBuffer + FrameLen,
417 &TmpLen, 9, RalinkIe,
420 } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) {
421 unsigned long TmpLen;
423 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
424 0x01, 0x00, 0x00, 0x00 };
425 MakeOutgoingFrame(pOutBuffer + FrameLen,
426 &TmpLen, 9, RalinkIe,
431 unsigned long TmpLen;
433 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x06,
435 MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen, 9,
436 RalinkIe, END_OF_ARGS);
440 if (pAd->MlmeAux.APEdcaParm.bValid) {
441 if (pAd->CommonCfg.bAPSDCapable
442 && pAd->MlmeAux.APEdcaParm.bAPSDCapable) {
443 struct rt_qbss_sta_info_parm QosInfo;
445 NdisZeroMemory(&QosInfo,
446 sizeof(struct rt_qbss_sta_info_parm));
447 QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
448 QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
449 QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
450 QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
451 QosInfo.MaxSPLength =
452 pAd->CommonCfg.MaxSPLength;
453 WmeIe[8] |= *(u8 *)& QosInfo;
455 /* The Parameter Set Count is set to ¡§0¡¨ in the association request frames */
456 /* WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f); */
459 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
460 9, &WmeIe[0], END_OF_ARGS);
464 /* Let WPA(#221) Element ID on the end of this association frame. */
465 /* Otherwise some AP will fail on parsing Element ID and set status fail on Assoc Rsp. */
466 /* For example: Put Vendor Specific IE on the front of WPA IE. */
467 /* This happens on AP (Model No:Linksys WRK54G) */
469 if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
470 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) ||
471 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
472 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
477 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
478 || (pAd->StaCfg.AuthMode ==
479 Ndis802_11AuthModeWPA2)) {
483 if ((pAd->StaCfg.WpaSupplicantUP !=
484 WPA_SUPPLICANT_ENABLE)
485 && (pAd->StaCfg.bRSN_IE_FromWpaSupplicant == FALSE))
486 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode,
487 pAd->StaCfg.WepStatus, BSS0);
489 /* Check for WPA PMK cache list */
490 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) {
492 BOOLEAN FoundPMK = FALSE;
493 /* Search chched PMKID, append it if existed */
494 for (idx = 0; idx < PMKID_NO; idx++) {
497 &pAd->StaCfg.SavedPMK[idx].BSSID,
505 *(u16 *)& pAd->StaCfg.RSN_IE[pAd->
509 NdisMoveMemory(&pAd->StaCfg.
513 SavedPMK[idx].PMKID, 16);
514 pAd->StaCfg.RSNIE_Len += 18;
518 if ((pAd->StaCfg.WpaSupplicantUP ==
519 WPA_SUPPLICANT_ENABLE)
520 && (pAd->StaCfg.bRSN_IE_FromWpaSupplicant ==
522 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
523 pAd->StaCfg.RSNIE_Len,
527 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
529 1, &pAd->StaCfg.RSNIE_Len,
530 pAd->StaCfg.RSNIE_Len,
537 if ((pAd->StaCfg.WpaSupplicantUP !=
538 WPA_SUPPLICANT_ENABLE)
539 || (pAd->StaCfg.bRSN_IE_FromWpaSupplicant ==
541 /* Append Variable IE */
542 NdisMoveMemory(pAd->StaCfg.ReqVarIEs +
543 VarIesOffset, &RSNIe, 1);
545 NdisMoveMemory(pAd->StaCfg.ReqVarIEs +
547 &pAd->StaCfg.RSNIE_Len, 1);
550 NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset,
552 pAd->StaCfg.RSNIE_Len);
553 VarIesOffset += pAd->StaCfg.RSNIE_Len;
555 /* Set Variable IEs Length */
556 pAd->StaCfg.ReqVarIELen = VarIesOffset;
559 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
560 MlmeFreeMemory(pAd, pOutBuffer);
562 RTMPSetTimer(&pAd->MlmeAux.AssocTimer, Timeout);
563 pAd->Mlme.AssocMachine.CurrState = ASSOC_WAIT_RSP;
565 DBGPRINT(RT_DEBUG_TRACE,
566 ("ASSOC - MlmeAssocReqAction() sanity check failed. BUG!\n"));
567 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
568 Status = MLME_INVALID_FORMAT;
569 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2,
576 ==========================================================================
578 mlme reassoc req handling procedure
582 -# SSID (Adapter->StaCfg.ssid[])
583 -# BSSID (AP address, Adapter->StaCfg.bssid)
584 -# Supported rates (Adapter->StaCfg.supported_rates[])
585 -# Supported rates length (Adapter->StaCfg.supported_rates_len)
586 -# Tx power (Adapter->StaCfg.tx_power)
588 IRQL = DISPATCH_LEVEL
590 ==========================================================================
592 void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
595 struct rt_header_802_11 ReassocHdr;
597 { IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01,
599 u16 CapabilityInfo, ListenIntv;
600 unsigned long Timeout;
601 unsigned long FrameLen = 0;
602 BOOLEAN TimerCancelled;
605 u8 *pOutBuffer = NULL;
608 /* Block all authentication request durning WPA block period */
609 if (pAd->StaCfg.bBlockAssoc == TRUE) {
610 DBGPRINT(RT_DEBUG_TRACE,
611 ("ASSOC - Block ReAssoc request durning WPA block period!\n"));
612 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
613 Status = MLME_STATE_MACHINE_REJECT;
614 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2,
617 /* the parameters are the same as the association */
618 else if (MlmeAssocReqSanity
619 (pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo,
620 &Timeout, &ListenIntv)) {
621 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled);
623 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
624 if (NStatus != NDIS_STATUS_SUCCESS) {
625 DBGPRINT(RT_DEBUG_TRACE,
626 ("ASSOC - MlmeReassocReqAction() allocate memory failed \n"));
627 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
628 Status = MLME_FAIL_NO_RESOURCE;
629 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
630 MT2_REASSOC_CONF, 2, &Status);
634 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
636 /* make frame, use bssid as the AP address?? */
637 DBGPRINT(RT_DEBUG_TRACE,
638 ("ASSOC - Send RE-ASSOC request...\n"));
639 MgtMacHeaderInit(pAd, &ReassocHdr, SUBTYPE_REASSOC_REQ, 0,
641 MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11),
642 &ReassocHdr, 2, &CapabilityInfo, 2,
643 &ListenIntv, MAC_ADDR_LEN, ApAddr, 1, &SsidIe,
644 1, &pAd->MlmeAux.SsidLen,
645 pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid, 1,
646 &SupRateIe, 1, &pAd->MlmeAux.SupRateLen,
647 pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
650 if (pAd->MlmeAux.ExtRateLen != 0) {
651 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
653 1, &pAd->MlmeAux.ExtRateLen,
654 pAd->MlmeAux.ExtRateLen,
655 pAd->MlmeAux.ExtRate, END_OF_ARGS);
659 if (pAd->MlmeAux.APEdcaParm.bValid) {
660 if (pAd->CommonCfg.bAPSDCapable
661 && pAd->MlmeAux.APEdcaParm.bAPSDCapable) {
662 struct rt_qbss_sta_info_parm QosInfo;
664 NdisZeroMemory(&QosInfo,
665 sizeof(struct rt_qbss_sta_info_parm));
666 QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE;
667 QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK;
668 QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI;
669 QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO;
670 QosInfo.MaxSPLength =
671 pAd->CommonCfg.MaxSPLength;
672 WmeIe[8] |= *(u8 *)& QosInfo;
675 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
676 9, &WmeIe[0], END_OF_ARGS);
680 if ((pAd->MlmeAux.HtCapabilityLen > 0)
681 && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
682 unsigned long TmpLen;
684 u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 };
685 if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE) {
686 HtLen = SIZE_HT_CAP_IE + 4;
687 MakeOutgoingFrame(pOutBuffer + FrameLen,
688 &TmpLen, 1, &WpaIe, 1, &HtLen,
690 pAd->MlmeAux.HtCapabilityLen,
691 &pAd->MlmeAux.HtCapability,
694 MakeOutgoingFrame(pOutBuffer + FrameLen,
695 &TmpLen, 1, &HtCapIe, 1,
696 &pAd->MlmeAux.HtCapabilityLen,
697 pAd->MlmeAux.HtCapabilityLen,
698 &pAd->MlmeAux.HtCapability,
703 /* add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION */
704 /* Case I: (Aggregation + Piggy-Back) */
705 /* 1. user enable aggregation, AND */
706 /* 2. Mac support piggy-back */
707 /* 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON */
708 /* Case II: (Aggregation) */
709 /* 1. user enable aggregation, AND */
710 /* 2. AP annouces it's AGGREGATION-capable in BEACON */
711 if (pAd->CommonCfg.bAggregationCapable) {
712 if ((pAd->CommonCfg.bPiggyBackCapable)
713 && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)) {
714 unsigned long TmpLen;
716 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
717 0x03, 0x00, 0x00, 0x00 };
718 MakeOutgoingFrame(pOutBuffer + FrameLen,
719 &TmpLen, 9, RalinkIe,
722 } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) {
723 unsigned long TmpLen;
725 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43,
726 0x01, 0x00, 0x00, 0x00 };
727 MakeOutgoingFrame(pOutBuffer + FrameLen,
728 &TmpLen, 9, RalinkIe,
733 unsigned long TmpLen;
735 { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x04,
737 MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen, 9,
738 RalinkIe, END_OF_ARGS);
742 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
743 MlmeFreeMemory(pAd, pOutBuffer);
745 RTMPSetTimer(&pAd->MlmeAux.ReassocTimer, Timeout); /* in mSec */
746 pAd->Mlme.AssocMachine.CurrState = REASSOC_WAIT_RSP;
748 DBGPRINT(RT_DEBUG_TRACE,
749 ("ASSOC - MlmeReassocReqAction() sanity check failed. BUG!\n"));
750 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
751 Status = MLME_INVALID_FORMAT;
752 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2,
758 ==========================================================================
760 Upper layer issues disassoc request
766 ==========================================================================
768 void MlmeDisassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
770 struct rt_mlme_disassoc_req *pDisassocReq;
771 struct rt_header_802_11 DisassocHdr;
772 struct rt_header_802_11 * pDisassocHdr;
773 u8 *pOutBuffer = NULL;
774 unsigned long FrameLen = 0;
776 BOOLEAN TimerCancelled;
777 unsigned long Timeout = 500;
780 /* skip sanity check */
781 pDisassocReq = (struct rt_mlme_disassoc_req *)(Elem->Msg);
783 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
784 if (NStatus != NDIS_STATUS_SUCCESS) {
785 DBGPRINT(RT_DEBUG_TRACE,
786 ("ASSOC - MlmeDisassocReqAction() allocate memory failed\n"));
787 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
788 Status = MLME_FAIL_NO_RESOURCE;
789 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2,
794 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &TimerCancelled);
796 DBGPRINT(RT_DEBUG_TRACE,
797 ("ASSOC - Send DISASSOC request[BSSID::%pM (Reason=%d)\n",
798 pDisassocReq->Addr, pDisassocReq->Reason));
799 MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pDisassocReq->Addr, pDisassocReq->Addr); /* patch peap ttls switching issue */
800 MakeOutgoingFrame(pOutBuffer, &FrameLen,
801 sizeof(struct rt_header_802_11), &DisassocHdr,
802 2, &pDisassocReq->Reason, END_OF_ARGS);
803 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
805 /* To patch Instance and Buffalo(N) AP */
806 /* Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine */
807 /* Therefore, we send both of them. */
808 pDisassocHdr = (struct rt_header_802_11 *) pOutBuffer;
809 pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
810 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
812 MlmeFreeMemory(pAd, pOutBuffer);
814 pAd->StaCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING;
815 COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pDisassocReq->Addr);
817 RTMPSetTimer(&pAd->MlmeAux.DisassocTimer, Timeout); /* in mSec */
818 pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP;
820 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, 0);
825 ==========================================================================
827 peer sends assoc rsp back
829 Elme - MLME message containing the received frame
831 IRQL = DISPATCH_LEVEL
833 ==========================================================================
835 void PeerAssocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
837 u16 CapabilityInfo, Status, Aid;
838 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
839 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
840 u8 Addr2[MAC_ADDR_LEN];
841 BOOLEAN TimerCancelled;
843 struct rt_edca_parm EdcaParm;
844 struct rt_ht_capability_ie HtCapability;
845 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
846 u8 HtCapabilityLen = 0;
848 u8 NewExtChannelOffset = 0xff;
850 if (PeerAssocRspSanity
851 (pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status,
852 &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen, &HtCapability,
853 &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen, &NewExtChannelOffset,
854 &EdcaParm, &CkipFlag)) {
855 /* The frame is for me ? */
856 if (MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) {
857 DBGPRINT(RT_DEBUG_TRACE,
858 ("PeerAssocRspAction():ASSOC - receive ASSOC_RSP to me (status=%d)\n",
860 DBGPRINT(RT_DEBUG_TRACE,
861 ("PeerAssocRspAction():MacTable [%d].AMsduSize = %d. ClientStatusFlags = 0x%lx \n",
863 pAd->MacTab.Content[BSSID_WCID].AMsduSize,
864 pAd->MacTab.Content[BSSID_WCID].
866 RTMPCancelTimer(&pAd->MlmeAux.AssocTimer,
869 if (Status == MLME_SUCCESS) {
870 u8 MaxSupportedRateIn500Kbps = 0;
873 /* supported rates array may not be sorted. sort it and find the maximum rate */
874 for (idx = 0; idx < SupRateLen; idx++) {
875 if (MaxSupportedRateIn500Kbps <
876 (SupRate[idx] & 0x7f))
877 MaxSupportedRateIn500Kbps =
881 for (idx = 0; idx < ExtRateLen; idx++) {
882 if (MaxSupportedRateIn500Kbps <
883 (ExtRate[idx] & 0x7f))
884 MaxSupportedRateIn500Kbps =
887 /* go to procedure listed on page 376 */
888 AssocPostProc(pAd, Addr2, CapabilityInfo, Aid,
889 SupRate, SupRateLen, ExtRate,
890 ExtRateLen, &EdcaParm,
891 &HtCapability, HtCapabilityLen,
894 StaAddMacTableEntry(pAd,
897 MaxSupportedRateIn500Kbps,
899 HtCapabilityLen, &AddHtInfo,
903 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
904 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
905 MT2_ASSOC_CONF, 2, &Status);
908 DBGPRINT(RT_DEBUG_TRACE,
909 ("ASSOC - PeerAssocRspAction() sanity check fail\n"));
914 ==========================================================================
916 peer sends reassoc rsp
918 Elem - MLME message cntaining the received frame
920 IRQL = DISPATCH_LEVEL
922 ==========================================================================
924 void PeerReassocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
929 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
930 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
931 u8 Addr2[MAC_ADDR_LEN];
933 BOOLEAN TimerCancelled;
934 struct rt_edca_parm EdcaParm;
935 struct rt_ht_capability_ie HtCapability;
936 struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */
939 u8 NewExtChannelOffset = 0xff;
941 if (PeerAssocRspSanity
942 (pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status,
943 &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen, &HtCapability,
944 &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen, &NewExtChannelOffset,
945 &EdcaParm, &CkipFlag)) {
946 if (MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) /* The frame is for me ? */
948 DBGPRINT(RT_DEBUG_TRACE,
949 ("ASSOC - receive REASSOC_RSP to me (status=%d)\n",
951 RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer,
954 if (Status == MLME_SUCCESS) {
955 /* go to procedure listed on page 376 */
956 AssocPostProc(pAd, Addr2, CapabilityInfo, Aid,
957 SupRate, SupRateLen, ExtRate,
958 ExtRateLen, &EdcaParm,
959 &HtCapability, HtCapabilityLen,
963 wext_notify_event_assoc(pAd);
964 RtmpOSWrielessEventSend(pAd, SIOCGIWAP,
972 /* CkipFlag is no use for reassociate */
973 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
974 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE,
975 MT2_REASSOC_CONF, 2, &Status);
978 DBGPRINT(RT_DEBUG_TRACE,
979 ("ASSOC - PeerReassocRspAction() sanity check fail\n"));
985 ==========================================================================
987 procedures on IEEE 802.11/1999 p.376
990 IRQL = DISPATCH_LEVEL
992 ==========================================================================
994 void AssocPostProc(struct rt_rtmp_adapter *pAd, u8 *pAddr2, u16 CapabilityInfo, u16 Aid, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_edca_parm *pEdcaParm, struct rt_ht_capability_ie * pHtCapability, u8 HtCapabilityLen, struct rt_add_ht_info_ie * pAddHtInfo) /* AP might use this additional ht info IE */
998 pAd->MlmeAux.BssType = BSS_INFRA;
999 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pAddr2);
1000 pAd->MlmeAux.Aid = Aid;
1001 pAd->MlmeAux.CapabilityInfo =
1002 CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
1004 /* Some HT AP might lost WMM IE. We add WMM ourselves. beacuase HT requires QoS on. */
1005 if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE)) {
1006 pEdcaParm->bValid = TRUE;
1007 pEdcaParm->Aifsn[0] = 3;
1008 pEdcaParm->Aifsn[1] = 7;
1009 pEdcaParm->Aifsn[2] = 2;
1010 pEdcaParm->Aifsn[3] = 2;
1012 pEdcaParm->Cwmin[0] = 4;
1013 pEdcaParm->Cwmin[1] = 4;
1014 pEdcaParm->Cwmin[2] = 3;
1015 pEdcaParm->Cwmin[3] = 2;
1017 pEdcaParm->Cwmax[0] = 10;
1018 pEdcaParm->Cwmax[1] = 10;
1019 pEdcaParm->Cwmax[2] = 4;
1020 pEdcaParm->Cwmax[3] = 3;
1022 pEdcaParm->Txop[0] = 0;
1023 pEdcaParm->Txop[1] = 0;
1024 pEdcaParm->Txop[2] = 96;
1025 pEdcaParm->Txop[3] = 48;
1029 NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, pEdcaParm, sizeof(struct rt_edca_parm));
1031 /* filter out un-supported rates */
1032 pAd->MlmeAux.SupRateLen = SupRateLen;
1033 NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);
1034 RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
1036 /* filter out un-supported rates */
1037 pAd->MlmeAux.ExtRateLen = ExtRateLen;
1038 NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);
1039 RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
1041 if (HtCapabilityLen > 0) {
1042 RTMPCheckHt(pAd, BSSID_WCID, pHtCapability, pAddHtInfo);
1044 DBGPRINT(RT_DEBUG_TRACE,
1045 ("AssocPostProc===> AP.AMsduSize = %d. ClientStatusFlags = 0x%lx \n",
1046 pAd->MacTab.Content[BSSID_WCID].AMsduSize,
1047 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
1049 DBGPRINT(RT_DEBUG_TRACE,
1050 ("AssocPostProc===> (Mmps=%d, AmsduSize=%d, )\n",
1051 pAd->MacTab.Content[BSSID_WCID].MmpsMode,
1052 pAd->MacTab.Content[BSSID_WCID].AMsduSize));
1054 /* Set New WPA information */
1055 Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel);
1056 if (Idx == BSS_NOT_FOUND) {
1057 DBGPRINT_ERR(("ASSOC - Can't find BSS after receiving Assoc response\n"));
1060 pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0;
1061 NdisZeroMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE,
1064 /* Store appropriate RSN_IE for WPA SM negotiation later */
1065 if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)
1066 && (pAd->ScanTab.BssEntry[Idx].VarIELen != 0)) {
1069 struct rt_eid * pEid;
1071 pVIE = pAd->ScanTab.BssEntry[Idx].VarIEs;
1072 len = pAd->ScanTab.BssEntry[Idx].VarIELen;
1073 /*KH need to check again */
1074 /* Don't allow to go to sleep mode if authmode is WPA-related. */
1075 /*This can make Authentication process more smoothly. */
1076 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1079 pEid = (struct rt_eid *) pVIE;
1080 /* For WPA/WPAPSK */
1081 if ((pEid->Eid == IE_WPA)
1083 (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))
1084 && (pAd->StaCfg.AuthMode ==
1085 Ndis802_11AuthModeWPA
1086 || pAd->StaCfg.AuthMode ==
1087 Ndis802_11AuthModeWPAPSK)) {
1088 NdisMoveMemory(pAd->MacTab.
1089 Content[BSSID_WCID].
1092 pAd->MacTab.Content[BSSID_WCID].
1093 RSNIE_Len = (pEid->Len + 2);
1094 DBGPRINT(RT_DEBUG_TRACE,
1095 ("AssocPostProc===> Store RSN_IE for WPA SM negotiation \n"));
1097 /* For WPA2/WPA2PSK */
1098 else if ((pEid->Eid == IE_RSN)
1101 (pEid->Octet + 2, RSN_OUI, 3))
1102 && (pAd->StaCfg.AuthMode ==
1103 Ndis802_11AuthModeWPA2
1104 || pAd->StaCfg.AuthMode ==
1105 Ndis802_11AuthModeWPA2PSK)) {
1106 NdisMoveMemory(pAd->MacTab.
1107 Content[BSSID_WCID].
1110 pAd->MacTab.Content[BSSID_WCID].
1111 RSNIE_Len = (pEid->Len + 2);
1112 DBGPRINT(RT_DEBUG_TRACE,
1113 ("AssocPostProc===> Store RSN_IE for WPA2 SM negotiation \n"));
1116 pVIE += (pEid->Len + 2);
1117 len -= (pEid->Len + 2);
1122 if (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == 0) {
1123 DBGPRINT(RT_DEBUG_TRACE,
1124 ("AssocPostProc===> no RSN_IE \n"));
1127 pAd->MacTab.Content[BSSID_WCID].RSN_IE,
1128 pAd->MacTab.Content[BSSID_WCID].RSNIE_Len);
1134 ==========================================================================
1136 left part of IEEE 802.11/1999 p.374
1138 Elem - MLME message containing the received frame
1140 IRQL = DISPATCH_LEVEL
1142 ==========================================================================
1144 void PeerDisassocAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1146 u8 Addr2[MAC_ADDR_LEN];
1149 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction()\n"));
1150 if (PeerDisassocSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason)) {
1151 DBGPRINT(RT_DEBUG_TRACE,
1152 ("ASSOC - PeerDisassocAction() Reason = %d\n",
1155 && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, Addr2)) {
1157 if (pAd->CommonCfg.bWirelessEvent) {
1158 RTMPSendWirelessEvent(pAd,
1159 IW_DISASSOC_EVENT_FLAG,
1161 Content[BSSID_WCID].Addr,
1165 LinkDown(pAd, TRUE);
1166 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1168 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL,
1172 DBGPRINT(RT_DEBUG_TRACE,
1173 ("ASSOC - PeerDisassocAction() sanity check fail\n"));
1179 ==========================================================================
1181 what the state machine will do after assoc timeout
1185 IRQL = DISPATCH_LEVEL
1187 ==========================================================================
1189 void AssocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1192 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - AssocTimeoutAction\n"));
1193 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1194 Status = MLME_REJ_TIMEOUT;
1195 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
1199 ==========================================================================
1201 what the state machine will do after reassoc timeout
1203 IRQL = DISPATCH_LEVEL
1205 ==========================================================================
1207 void ReassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1210 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - ReassocTimeoutAction\n"));
1211 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1212 Status = MLME_REJ_TIMEOUT;
1213 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
1217 ==========================================================================
1219 what the state machine will do after disassoc timeout
1221 IRQL = DISPATCH_LEVEL
1223 ==========================================================================
1225 void DisassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1228 DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - DisassocTimeoutAction\n"));
1229 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1230 Status = MLME_SUCCESS;
1231 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2,
1235 void InvalidStateWhenAssoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1238 DBGPRINT(RT_DEBUG_TRACE,
1239 ("ASSOC - InvalidStateWhenAssoc(state=%ld), reset ASSOC state machine\n",
1240 pAd->Mlme.AssocMachine.CurrState));
1241 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1242 Status = MLME_STATE_MACHINE_REJECT;
1243 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status);
1246 void InvalidStateWhenReassoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
1249 DBGPRINT(RT_DEBUG_TRACE,
1250 ("ASSOC - InvalidStateWhenReassoc(state=%ld), reset ASSOC state machine\n",
1251 pAd->Mlme.AssocMachine.CurrState));
1252 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1253 Status = MLME_STATE_MACHINE_REJECT;
1254 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status);
1257 void InvalidStateWhenDisassociate(struct rt_rtmp_adapter *pAd,
1258 struct rt_mlme_queue_elem *Elem)
1261 DBGPRINT(RT_DEBUG_TRACE,
1262 ("ASSOC - InvalidStateWhenDisassoc(state=%ld), reset ASSOC state machine\n",
1263 pAd->Mlme.AssocMachine.CurrState));
1264 pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
1265 Status = MLME_STATE_MACHINE_REJECT;
1266 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2,
1271 ==========================================================================
1273 right part of IEEE 802.11/1999 page 374
1275 This event should never cause ASSOC state machine perform state
1276 transition, and has no relationship with CNTL machine. So we separate
1277 this routine as a service outside of ASSOC state transition table.
1279 IRQL = DISPATCH_LEVEL
1281 ==========================================================================
1283 void Cls3errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr)
1285 struct rt_header_802_11 DisassocHdr;
1286 struct rt_header_802_11 * pDisassocHdr;
1287 u8 *pOutBuffer = NULL;
1288 unsigned long FrameLen = 0;
1290 u16 Reason = REASON_CLS3ERR;
1292 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */
1293 if (NStatus != NDIS_STATUS_SUCCESS)
1296 DBGPRINT(RT_DEBUG_TRACE,
1297 ("ASSOC - Class 3 Error, Send DISASSOC frame\n"));
1298 MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pAddr, pAd->CommonCfg.Bssid); /* patch peap ttls switching issue */
1299 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1300 sizeof(struct rt_header_802_11), &DisassocHdr,
1301 2, &Reason, END_OF_ARGS);
1302 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1304 /* To patch Instance and Buffalo(N) AP */
1305 /* Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine */
1306 /* Therefore, we send both of them. */
1307 pDisassocHdr = (struct rt_header_802_11 *) pOutBuffer;
1308 pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH;
1309 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1311 MlmeFreeMemory(pAd, pOutBuffer);
1313 pAd->StaCfg.DisassocReason = REASON_CLS3ERR;
1314 COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pAddr);
1317 int wext_notify_event_assoc(struct rt_rtmp_adapter *pAd)
1319 char custom[IW_CUSTOM_MAX] = { 0 };
1321 if (pAd->StaCfg.ReqVarIELen <= IW_CUSTOM_MAX) {
1322 NdisMoveMemory(custom, pAd->StaCfg.ReqVarIEs,
1323 pAd->StaCfg.ReqVarIELen);
1324 RtmpOSWrielessEventSend(pAd, IWEVASSOCREQIE, -1, NULL, custom,
1325 pAd->StaCfg.ReqVarIELen);
1327 DBGPRINT(RT_DEBUG_TRACE,
1328 ("pAd->StaCfg.ReqVarIELen > MAX_CUSTOM_LEN\n"));
1334 BOOLEAN StaAddMacTableEntry(struct rt_rtmp_adapter *pAd,
1335 struct rt_mac_table_entry *pEntry,
1336 u8 MaxSupportedRateIn500Kbps,
1337 struct rt_ht_capability_ie * pHtCapability,
1339 struct rt_add_ht_info_ie * pAddHtInfo,
1340 u8 AddHtInfoLen, u16 CapabilityInfo)
1342 u8 MaxSupportedRate = RATE_11;
1345 CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE);
1347 switch (MaxSupportedRateIn500Kbps) {
1349 MaxSupportedRate = RATE_54;
1352 MaxSupportedRate = RATE_48;
1355 MaxSupportedRate = RATE_36;
1358 MaxSupportedRate = RATE_24;
1361 MaxSupportedRate = RATE_18;
1364 MaxSupportedRate = RATE_12;
1367 MaxSupportedRate = RATE_9;
1370 MaxSupportedRate = RATE_6;
1373 MaxSupportedRate = RATE_11;
1376 MaxSupportedRate = RATE_5_5;
1379 MaxSupportedRate = RATE_2;
1382 MaxSupportedRate = RATE_1;
1385 MaxSupportedRate = RATE_11;
1389 if ((pAd->CommonCfg.PhyMode == PHY_11G)
1390 && (MaxSupportedRate < RATE_FIRST_OFDM_RATE))
1394 if (((pAd->CommonCfg.PhyMode == PHY_11N_2_4G)
1395 || (pAd->CommonCfg.PhyMode == PHY_11N_5G))
1396 && (HtCapabilityLen == 0))
1402 NdisAcquireSpinLock(&pAd->MacTabLock);
1404 pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
1405 if ((MaxSupportedRate < RATE_FIRST_OFDM_RATE) ||
1406 (pAd->CommonCfg.PhyMode == PHY_11B)) {
1407 pEntry->RateLen = 4;
1408 if (MaxSupportedRate >= RATE_FIRST_OFDM_RATE)
1409 MaxSupportedRate = RATE_11;
1411 pEntry->RateLen = 12;
1413 pEntry->MaxHTPhyMode.word = 0;
1414 pEntry->MinHTPhyMode.word = 0;
1415 pEntry->HTPhyMode.word = 0;
1416 pEntry->MaxSupportedRate = MaxSupportedRate;
1417 if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE) {
1418 pEntry->MaxHTPhyMode.field.MODE = MODE_CCK;
1419 pEntry->MaxHTPhyMode.field.MCS =
1420 pEntry->MaxSupportedRate;
1421 pEntry->MinHTPhyMode.field.MODE = MODE_CCK;
1422 pEntry->MinHTPhyMode.field.MCS =
1423 pEntry->MaxSupportedRate;
1424 pEntry->HTPhyMode.field.MODE = MODE_CCK;
1425 pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate;
1427 pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM;
1428 pEntry->MaxHTPhyMode.field.MCS =
1429 OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
1430 pEntry->MinHTPhyMode.field.MODE = MODE_OFDM;
1431 pEntry->MinHTPhyMode.field.MCS =
1432 OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
1433 pEntry->HTPhyMode.field.MODE = MODE_OFDM;
1434 pEntry->HTPhyMode.field.MCS =
1435 OfdmRateToRxwiMCS[pEntry->MaxSupportedRate];
1437 pEntry->CapabilityInfo = CapabilityInfo;
1438 CLIENT_STATUS_CLEAR_FLAG(pEntry,
1439 fCLIENT_STATUS_AGGREGATION_CAPABLE);
1440 CLIENT_STATUS_CLEAR_FLAG(pEntry,
1441 fCLIENT_STATUS_PIGGYBACK_CAPABLE);
1444 NdisZeroMemory(&pEntry->HTCapability, sizeof(pEntry->HTCapability));
1445 /* If this Entry supports 802.11n, upgrade to HT rate. */
1446 if ((HtCapabilityLen != 0)
1447 && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
1448 u8 j, bitmask; /*k,bitmask; */
1452 CLIENT_STATUS_SET_FLAG(pEntry,
1453 fCLIENT_STATUS_WMM_CAPABLE);
1454 if ((pHtCapability->HtCapInfo.GF)
1455 && (pAd->CommonCfg.DesiredHtPhy.GF)) {
1456 pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD;
1458 pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
1459 pAd->MacTab.fAnyStationNonGF = TRUE;
1460 pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1;
1463 if ((pHtCapability->HtCapInfo.ChannelWidth) &&
1464 (pAd->CommonCfg.DesiredHtPhy.ChannelWidth) &&
1465 ((pAd->StaCfg.BssType == BSS_INFRA)
1466 || ((pAd->StaCfg.BssType == BSS_ADHOC)
1467 && (pAddHtInfo->AddHtInfo.ExtChanOffset ==
1468 pAd->CommonCfg.AddHTInfo.AddHtInfo.
1470 pEntry->MaxHTPhyMode.field.BW = BW_40;
1471 pEntry->MaxHTPhyMode.field.ShortGI =
1472 ((pAd->CommonCfg.DesiredHtPhy.
1473 ShortGIfor40) & (pHtCapability->HtCapInfo.
1476 pEntry->MaxHTPhyMode.field.BW = BW_20;
1477 pEntry->MaxHTPhyMode.field.ShortGI =
1478 ((pAd->CommonCfg.DesiredHtPhy.
1479 ShortGIfor20) & (pHtCapability->HtCapInfo.
1481 pAd->MacTab.fAnyStation20Only = TRUE;
1485 if (pAd->MACVersion >= RALINK_2883_VERSION
1486 && pAd->MACVersion < RALINK_3070_VERSION)
1487 pEntry->MaxHTPhyMode.field.TxBF =
1488 pAd->CommonCfg.RegTransmitSetting.field.TxBF;
1490 /* find max fixed rate */
1491 for (i = 23; i >= 0; i--) /* 3*3 */
1494 bitmask = (1 << (i - (j * 8)));
1495 if ((pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j] & bitmask)
1496 && (pHtCapability->MCSSet[j] & bitmask)) {
1497 pEntry->MaxHTPhyMode.field.MCS = i;
1504 if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) {
1505 if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32) {
1506 /* Fix MCS as HT Duplicated Mode */
1507 pEntry->MaxHTPhyMode.field.BW = 1;
1508 pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX;
1509 pEntry->MaxHTPhyMode.field.STBC = 0;
1510 pEntry->MaxHTPhyMode.field.ShortGI = 0;
1511 pEntry->MaxHTPhyMode.field.MCS = 32;
1512 } else if (pEntry->MaxHTPhyMode.field.MCS >
1513 pAd->StaCfg.HTPhyMode.field.MCS) {
1514 /* STA supports fixed MCS */
1515 pEntry->MaxHTPhyMode.field.MCS =
1516 pAd->StaCfg.HTPhyMode.field.MCS;
1520 pEntry->MaxHTPhyMode.field.STBC =
1521 (pHtCapability->HtCapInfo.
1522 RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC));
1523 pEntry->MpduDensity = pHtCapability->HtCapParm.MpduDensity;
1524 pEntry->MaxRAmpduFactor =
1525 pHtCapability->HtCapParm.MaxRAmpduFactor;
1526 pEntry->MmpsMode = (u8)pHtCapability->HtCapInfo.MimoPs;
1527 pEntry->AMsduSize = (u8)pHtCapability->HtCapInfo.AMsduSize;
1528 pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
1530 if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable
1531 && (pAd->CommonCfg.REGBACapability.field.AutoBA == FALSE))
1532 CLIENT_STATUS_SET_FLAG(pEntry,
1533 fCLIENT_STATUS_AMSDU_INUSED);
1534 if (pHtCapability->HtCapInfo.ShortGIfor20)
1535 CLIENT_STATUS_SET_FLAG(pEntry,
1536 fCLIENT_STATUS_SGI20_CAPABLE);
1537 if (pHtCapability->HtCapInfo.ShortGIfor40)
1538 CLIENT_STATUS_SET_FLAG(pEntry,
1539 fCLIENT_STATUS_SGI40_CAPABLE);
1540 if (pHtCapability->HtCapInfo.TxSTBC)
1541 CLIENT_STATUS_SET_FLAG(pEntry,
1542 fCLIENT_STATUS_TxSTBC_CAPABLE);
1543 if (pHtCapability->HtCapInfo.RxSTBC)
1544 CLIENT_STATUS_SET_FLAG(pEntry,
1545 fCLIENT_STATUS_RxSTBC_CAPABLE);
1546 if (pHtCapability->ExtHtCapInfo.PlusHTC)
1547 CLIENT_STATUS_SET_FLAG(pEntry,
1548 fCLIENT_STATUS_HTC_CAPABLE);
1549 if (pAd->CommonCfg.bRdg
1550 && pHtCapability->ExtHtCapInfo.RDGSupport)
1551 CLIENT_STATUS_SET_FLAG(pEntry,
1552 fCLIENT_STATUS_RDG_CAPABLE);
1553 if (pHtCapability->ExtHtCapInfo.MCSFeedback == 0x03)
1554 CLIENT_STATUS_SET_FLAG(pEntry,
1555 fCLIENT_STATUS_MCSFEEDBACK_CAPABLE);
1556 NdisMoveMemory(&pEntry->HTCapability, pHtCapability,
1559 pAd->MacTab.fAnyStationIsLegacy = TRUE;
1562 pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word;
1563 pEntry->CurrTxRate = pEntry->MaxSupportedRate;
1565 /* Set asic auto fall back */
1566 if (pAd->StaCfg.bAutoTxRateSwitch == TRUE) {
1570 MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize,
1571 &pEntry->CurrTxRateIndex);
1572 pEntry->bAutoTxRateSwitch = TRUE;
1574 pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE;
1575 pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS;
1576 pEntry->bAutoTxRateSwitch = FALSE;
1578 /* If the legacy mode is set, overwrite the transmit setting of this entry. */
1579 RTMPUpdateLegacyTxSetting((u8)pAd->StaCfg.
1580 DesiredTransmitSetting.field.
1581 FixedTxMode, pEntry);
1584 pEntry->PortSecured = WPA_802_1X_PORT_SECURED;
1585 pEntry->Sst = SST_ASSOC;
1586 pEntry->AuthState = AS_AUTH_OPEN;
1587 pEntry->AuthMode = pAd->StaCfg.AuthMode;
1588 pEntry->WepStatus = pAd->StaCfg.WepStatus;
1590 NdisReleaseSpinLock(&pAd->MacTabLock);
1593 union iwreq_data wrqu;
1594 wext_notify_event_assoc(pAd);
1596 memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
1597 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);