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 Chang 2004-09-01 modified for rt2561/2661
36 Jan Lee 2006-08-01 modified for rt2860 for 802.11n
38 #include "../rt_config.h"
40 #define ADHOC_ENTRY_BEACON_LOST_TIME (2*OS_HZ) // 2 sec
43 ==========================================================================
45 The sync state machine,
47 Sm - pointer to the state machine
49 the state machine looks like the following
51 ==========================================================================
53 VOID SyncStateMachineInit(
56 OUT STATE_MACHINE_FUNC Trans[])
58 StateMachineInit(Sm, Trans, MAX_SYNC_STATE, MAX_SYNC_MSG, (STATE_MACHINE_FUNC)Drop, SYNC_IDLE, SYNC_MACHINE_BASE);
61 StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)MlmeScanReqAction);
62 StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)MlmeJoinReqAction);
63 StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)MlmeStartReqAction);
64 StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeacon);
65 StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_PROBE_REQ, (STATE_MACHINE_FUNC)PeerProbeReqAction);
68 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);
69 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);
70 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);
71 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtJoinAction);
72 StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_BEACON_TIMEOUT, (STATE_MACHINE_FUNC)BeaconTimeoutAtJoinAction);
75 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_SCAN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenScan);
76 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_JOIN_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenJoin);
77 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_START_REQ, (STATE_MACHINE_FUNC)InvalidStateWhenStart);
78 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_BEACON, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);
79 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_PROBE_RSP, (STATE_MACHINE_FUNC)PeerBeaconAtScanAction);
80 StateMachineSetAction(Sm, SCAN_LISTEN, MT2_SCAN_TIMEOUT, (STATE_MACHINE_FUNC)ScanTimeoutAction);
83 RTMPInitTimer(pAd, &pAd->MlmeAux.BeaconTimer, GET_TIMER_FUNCTION(BeaconTimeout), pAd, FALSE);
84 RTMPInitTimer(pAd, &pAd->MlmeAux.ScanTimer, GET_TIMER_FUNCTION(ScanTimeout), pAd, FALSE);
88 ==========================================================================
90 Beacon timeout handler, executed in timer thread
94 ==========================================================================
97 IN PVOID SystemSpecific1,
98 IN PVOID FunctionContext,
99 IN PVOID SystemSpecific2,
100 IN PVOID SystemSpecific3)
102 RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
104 DBGPRINT(RT_DEBUG_TRACE,("SYNC - BeaconTimeout\n"));
106 // Do nothing if the driver is starting halt state.
107 // This might happen when timer already been fired before cancel timer with mlmehalt
108 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
111 #ifdef DOT11_N_SUPPORT
112 if ((pAd->CommonCfg.BBPCurrentBW == BW_40)
116 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
117 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
118 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
121 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
122 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n",pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr));
124 #endif // DOT11_N_SUPPORT //
126 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_BEACON_TIMEOUT, 0, NULL);
127 RT28XX_MLME_HANDLER(pAd);
131 ==========================================================================
133 Scan timeout handler, executed in timer thread
135 IRQL = DISPATCH_LEVEL
137 ==========================================================================
140 IN PVOID SystemSpecific1,
141 IN PVOID FunctionContext,
142 IN PVOID SystemSpecific2,
143 IN PVOID SystemSpecific3)
145 RTMP_ADAPTER *pAd = (RTMP_ADAPTER *)FunctionContext;
148 // Do nothing if the driver is starting halt state.
149 // This might happen when timer already been fired before cancel timer with mlmehalt
150 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
153 if (MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_SCAN_TIMEOUT, 0, NULL))
155 RT28XX_MLME_HANDLER(pAd);
159 // To prevent SyncMachine.CurrState is SCAN_LISTEN forever.
160 pAd->MlmeAux.Channel = 0;
161 ScanNextChannel(pAd);
162 if (pAd->CommonCfg.bWirelessEvent)
164 RTMPSendWirelessEvent(pAd, IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
170 ==========================================================================
172 MLME SCAN req state machine procedure
173 ==========================================================================
175 VOID MlmeScanReqAction(
176 IN PRTMP_ADAPTER pAd,
177 IN MLME_QUEUE_ELEM *Elem)
179 UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, ScanType, BssType, BBPValue = 0;
180 BOOLEAN TimerCancelled;
183 PHEADER_802_11 pHdr80211;
184 PUCHAR pOutBuffer = NULL;
187 // Check the total scan tries for one single OID command
188 // If this is the CCX 2.0 Case, skip that!
189 if ( !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP))
191 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeScanReqAction before Startup\n"));
195 // Increase the scan retry counters.
196 pAd->StaCfg.ScanCnt++;
199 // first check the parameter sanity
200 if (MlmeScanReqSanity(pAd,
209 // Check for channel load and noise hist request
210 // Suspend MSDU only at scan request, not the last two mentioned
211 if ((ScanType == SCAN_CISCO_NOISE) || (ScanType == SCAN_CISCO_CHANNEL_LOAD))
213 if (pAd->StaCfg.CCXScanChannel != pAd->CommonCfg.Channel)
214 RTMPSuspendMsduTransmission(pAd); // Suspend MSDU transmission here
218 // Suspend MSDU transmission here
219 RTMPSuspendMsduTransmission(pAd);
223 // To prevent data lost.
224 // Send an NULL data with turned PSM bit on to current associated AP before SCAN progress.
225 // And should send an NULL data with turned PSM bit off to AP, when scan progress done
227 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && (INFRA_ON(pAd)))
229 NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);
230 if (NStatus == NDIS_STATUS_SUCCESS)
232 pHdr80211 = (PHEADER_802_11) pOutBuffer;
233 MgtMacHeaderInit(pAd, pHdr80211, SUBTYPE_NULL_FUNC, 1, pAd->CommonCfg.Bssid, pAd->CommonCfg.Bssid);
234 pHdr80211->Duration = 0;
235 pHdr80211->FC.Type = BTYPE_DATA;
236 pHdr80211->FC.PwrMgmt = PWR_SAVE;
238 // Send using priority queue
239 MiniportMMRequest(pAd, 0, pOutBuffer, sizeof(HEADER_802_11));
240 DBGPRINT(RT_DEBUG_TRACE, ("MlmeScanReqAction -- Send PSM Data frame for off channel RM\n"));
241 MlmeFreeMemory(pAd, pOutBuffer);
246 NdisGetSystemUpTime(&Now);
247 pAd->StaCfg.LastScanTime = Now;
248 // reset all the timers
249 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
250 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
252 // record desired BSS parameters
253 pAd->MlmeAux.BssType = BssType;
254 pAd->MlmeAux.ScanType = ScanType;
255 pAd->MlmeAux.SsidLen = SsidLen;
256 NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
257 NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
259 // start from the first channel
260 pAd->MlmeAux.Channel = FirstChannel(pAd);
262 // Change the scan channel when dealing with CCX beacon report
263 if ((ScanType == SCAN_CISCO_PASSIVE) || (ScanType == SCAN_CISCO_ACTIVE) ||
264 (ScanType == SCAN_CISCO_CHANNEL_LOAD) || (ScanType == SCAN_CISCO_NOISE))
265 pAd->MlmeAux.Channel = pAd->StaCfg.CCXScanChannel;
267 // Let BBP register at 20MHz to do scan
268 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
270 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
271 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
272 ScanNextChannel(pAd);
276 DBGPRINT_ERR(("SYNC - MlmeScanReqAction() sanity check fail\n"));
277 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
278 Status = MLME_INVALID_FORMAT;
279 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
284 ==========================================================================
286 MLME JOIN req state machine procedure
287 ==========================================================================
289 VOID MlmeJoinReqAction(
290 IN PRTMP_ADAPTER pAd,
291 IN MLME_QUEUE_ELEM *Elem)
295 BOOLEAN TimerCancelled;
296 HEADER_802_11 Hdr80211;
299 PUCHAR pOutBuffer = NULL;
300 PUCHAR pSupRate = NULL;
302 PUCHAR pExtRate = NULL;
304 UCHAR ASupRate[] = {0x8C, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6C};
305 UCHAR ASupRateLen = sizeof(ASupRate)/sizeof(UCHAR);
306 MLME_JOIN_REQ_STRUCT *pInfo = (MLME_JOIN_REQ_STRUCT *)(Elem->Msg);
308 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeJoinReqAction(BSS #%ld)\n", pInfo->BssIdx));
311 // reset all the timers
312 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
313 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
315 pBss = &pAd->MlmeAux.SsidBssTab.BssEntry[pInfo->BssIdx];
317 // record the desired SSID & BSSID we're waiting for
318 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pBss->Bssid);
320 // If AP's SSID is not hidden, it is OK for updating ssid to MlmeAux again.
321 if (pBss->Hidden == 0)
323 NdisMoveMemory(pAd->MlmeAux.Ssid, pBss->Ssid, pBss->SsidLen);
324 pAd->MlmeAux.SsidLen = pBss->SsidLen;
327 pAd->MlmeAux.BssType = pBss->BssType;
328 pAd->MlmeAux.Channel = pBss->Channel;
329 pAd->MlmeAux.CentralChannel = pBss->CentralChannel;
331 #ifdef EXT_BUILD_CHANNEL_LIST
332 // Country IE of the AP will be evaluated and will be used.
333 if ((pAd->StaCfg.IEEE80211dClientMode != Rt802_11_D_None) &&
334 (pBss->bHasCountryIE == TRUE))
336 NdisMoveMemory(&pAd->CommonCfg.CountryCode[0], &pBss->CountryString[0], 2);
337 if (pBss->CountryString[2] == 'I')
338 pAd->CommonCfg.Geography = IDOR;
339 else if (pBss->CountryString[2] == 'O')
340 pAd->CommonCfg.Geography = ODOR;
342 pAd->CommonCfg.Geography = BOTH;
343 BuildChannelListEx(pAd);
345 #endif // EXT_BUILD_CHANNEL_LIST //
347 // Let BBP register at 20MHz to do scan
348 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
350 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
351 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n"));
353 // switch channel and waiting for beacon timer
354 AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
355 AsicLockChannel(pAd, pAd->MlmeAux.Channel);
356 RTMPSetTimer(&pAd->MlmeAux.BeaconTimer, JOIN_TIMEOUT);
360 if (((pAd->CommonCfg.bIEEE80211H == 1) &&
361 (pAd->MlmeAux.Channel > 14) &&
362 RadarChannelCheck(pAd, pAd->MlmeAux.Channel))
363 #ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
364 || (pAd->CommonCfg.CarrierDetect.Enable == TRUE)
365 #endif // CARRIER_DETECTION_SUPPORT //
369 // We can't send any Probe request frame to meet 802.11h.
371 if (pBss->Hidden == 0)
376 // send probe request
378 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
379 if (NStatus == NDIS_STATUS_SUCCESS)
381 if (pAd->MlmeAux.Channel <= 14)
383 pSupRate = pAd->CommonCfg.SupRate;
384 SupRateLen = pAd->CommonCfg.SupRateLen;
385 pExtRate = pAd->CommonCfg.ExtRate;
386 ExtRateLen = pAd->CommonCfg.ExtRateLen;
391 // Overwrite Support Rate, CCK rate are not allowed
394 SupRateLen = ASupRateLen;
398 if (pAd->MlmeAux.BssType == BSS_INFRA)
399 MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, pAd->MlmeAux.Bssid, pAd->MlmeAux.Bssid);
401 MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
403 MakeOutgoingFrame(pOutBuffer, &FrameLen,
404 sizeof(HEADER_802_11), &Hdr80211,
406 1, &pAd->MlmeAux.SsidLen,
407 pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
410 SupRateLen, pSupRate,
416 MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
419 ExtRateLen, pExtRate,
425 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
426 MlmeFreeMemory(pAd, pOutBuffer);
430 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - Switch to ch %d, Wait BEACON from %02x:%02x:%02x:%02x:%02x:%02x\n",
431 pBss->Channel, pBss->Bssid[0], pBss->Bssid[1], pBss->Bssid[2], pBss->Bssid[3], pBss->Bssid[4], pBss->Bssid[5]));
433 pAd->Mlme.SyncMachine.CurrState = JOIN_WAIT_BEACON;
437 ==========================================================================
439 MLME START Request state machine procedure, starting an IBSS
440 ==========================================================================
442 VOID MlmeStartReqAction(
443 IN PRTMP_ADAPTER pAd,
444 IN MLME_QUEUE_ELEM *Elem)
446 UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen;
447 BOOLEAN TimerCancelled;
449 // New for WPA security suites
450 UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
451 NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
452 LARGE_INTEGER TimeStamp;
456 // Init Variable IE structure
457 pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
459 TimeStamp.u.LowPart = 0;
460 TimeStamp.u.HighPart = 0;
462 if (MlmeStartReqSanity(pAd, Elem->Msg, Elem->MsgLen, Ssid, &SsidLen))
464 // reset all the timers
465 RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled);
466 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
469 // Start a new IBSS. All IBSS parameters are decided now....
471 DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - Start a new IBSS. All IBSS parameters are decided now.... \n"));
472 pAd->MlmeAux.BssType = BSS_ADHOC;
473 NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
474 pAd->MlmeAux.SsidLen = SsidLen;
476 // generate a radom number as BSSID
477 MacAddrRandomBssid(pAd, pAd->MlmeAux.Bssid);
478 DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqAction - generate a radom number as BSSID \n"));
480 Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
481 (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
482 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
483 pAd->MlmeAux.CapabilityInfo = CAP_GENERATE(0,1,Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 1, 0);
484 pAd->MlmeAux.BeaconPeriod = pAd->CommonCfg.BeaconPeriod;
485 pAd->MlmeAux.AtimWin = pAd->StaCfg.AtimWin;
486 pAd->MlmeAux.Channel = pAd->CommonCfg.Channel;
488 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
489 pAd->MlmeAux.CentralChannel = pAd->CommonCfg.CentralChannel;
491 pAd->MlmeAux.SupRateLen= pAd->CommonCfg.SupRateLen;
492 NdisMoveMemory(pAd->MlmeAux.SupRate, pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
493 RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
494 pAd->MlmeAux.ExtRateLen = pAd->CommonCfg.ExtRateLen;
495 NdisMoveMemory(pAd->MlmeAux.ExtRate, pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
496 RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
497 #ifdef DOT11_N_SUPPORT
498 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
500 RTMPUpdateHTIE(&pAd->CommonCfg.DesiredHtPhy, &pAd->StaCfg.DesiredHtPhyInfo.MCSSet[0], &pAd->MlmeAux.HtCapability, &pAd->MlmeAux.AddHtInfo);
501 pAd->MlmeAux.HtCapabilityLen = sizeof(HT_CAPABILITY_IE);
502 // Not turn pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE here.
503 DBGPRINT(RT_DEBUG_TRACE, ("SYNC -pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE\n"));
506 #endif // DOT11_N_SUPPORT //
508 pAd->MlmeAux.HtCapabilityLen = 0;
509 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
511 // temporarily not support QOS in IBSS
512 NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));
513 NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));
514 NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));
516 AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE);
517 AsicLockChannel(pAd, pAd->MlmeAux.Channel);
519 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - MlmeStartReqAction(ch= %d,sup rates= %d, ext rates=%d)\n",
520 pAd->MlmeAux.Channel, pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));
522 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
523 Status = MLME_SUCCESS;
524 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
528 DBGPRINT_ERR(("SYNC - MlmeStartReqAction() sanity check fail.\n"));
529 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
530 Status = MLME_INVALID_FORMAT;
531 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
536 ==========================================================================
538 peer sends beacon back when scanning
539 ==========================================================================
541 VOID PeerBeaconAtScanAction(
542 IN PRTMP_ADAPTER pAd,
543 IN MLME_QUEUE_ELEM *Elem)
545 UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
546 UCHAR Ssid[MAX_LEN_OF_SSID], BssType, Channel, NewChannel,
547 SsidLen, DtimCount, DtimPeriod, BcastFlag, MessageToMe;
549 USHORT BeaconPeriod, AtimWin, CapabilityInfo;
550 PFRAME_802_11 pFrame;
551 LARGE_INTEGER TimeStamp;
553 UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
554 UCHAR SupRateLen, ExtRateLen;
557 UCHAR AironetCellPowerLimit;
559 QBSS_LOAD_PARM QbssLoad;
560 QOS_CAPABILITY_PARM QosCapability;
562 UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
563 NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
564 HT_CAPABILITY_IE HtCapability;
565 ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
566 UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
568 UCHAR NewExtChannelOffset = 0xff;
571 // NdisFillMemory(Ssid, MAX_LEN_OF_SSID, 0x00);
572 pFrame = (PFRAME_802_11) Elem->Msg;
573 // Init Variable IE structure
574 pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
576 #ifdef DOT11_N_SUPPORT
577 RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
578 RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
579 #endif // DOT11_N_SUPPORT //
581 if (PeerBeaconAndProbeRspSanity(pAd,
607 &AironetCellPowerLimit,
613 &PreNHtCapabilityLen,
617 &NewExtChannelOffset,
624 Idx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
625 if (Idx != BSS_NOT_FOUND)
626 Rssi = pAd->ScanTab.BssEntry[Idx].Rssi;
628 Rssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
631 #ifdef DOT11_N_SUPPORT
632 if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
633 HtCapabilityLen = SIZE_HT_CAP_IE;
634 #endif // DOT11_N_SUPPORT //
635 if ((pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) && (Channel == pAd->StaCfg.CCXScanChannel))
637 Idx = BssTableSetEntry(pAd, &pAd->StaCfg.CCXBssTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
638 &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen,ExtRate, ExtRateLen, &HtCapability,
639 &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,
640 &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
641 if (Idx != BSS_NOT_FOUND)
643 NdisMoveMemory(pAd->StaCfg.CCXBssTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);
644 NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
645 NdisMoveMemory(&pAd->StaCfg.CCXBssTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
646 if (pAd->StaCfg.CCXReqType == MSRN_TYPE_BEACON_REQ)
647 AironetAddBeaconReport(pAd, Idx, Elem);
652 Idx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
653 &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,
654 &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, Rssi, TimeStamp, CkipFlag,
655 &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
656 #ifdef DOT11_N_SUPPORT
658 if (pAd->ChannelList[pAd->CommonCfg.ChannelListIdx].bEffectedChannel == TRUE)
661 PeerBeaconAndProbeRspSanity2(pAd, Elem->Msg, Elem->MsgLen, &RegClass);
662 TriEventTableSetEntry(pAd, &pAd->CommonCfg.TriggerEventTab, Bssid, &HtCapability, HtCapabilityLen, RegClass, Channel);
664 #endif // DOT11N_DRAFT3 //
665 #endif // DOT11_N_SUPPORT //
666 if (Idx != BSS_NOT_FOUND)
668 NdisMoveMemory(pAd->ScanTab.BssEntry[Idx].PTSF, &Elem->Msg[24], 4);
669 NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
670 NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
674 // sanity check fail, ignored
678 ==========================================================================
680 When waiting joining the (I)BSS, beacon received from external
681 ==========================================================================
683 VOID PeerBeaconAtJoinAction(
684 IN PRTMP_ADAPTER pAd,
685 IN MLME_QUEUE_ELEM *Elem)
687 UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
688 UCHAR Ssid[MAX_LEN_OF_SSID], SsidLen, BssType, Channel, MessageToMe,
689 DtimCount, DtimPeriod, BcastFlag, NewChannel;
690 LARGE_INTEGER TimeStamp;
691 USHORT BeaconPeriod, AtimWin, CapabilityInfo;
693 BOOLEAN TimerCancelled;
695 UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
696 UCHAR SupRateLen, ExtRateLen;
699 UCHAR AironetCellPowerLimit;
701 QBSS_LOAD_PARM QbssLoad;
702 QOS_CAPABILITY_PARM QosCapability;
704 UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
705 NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
708 HT_CAPABILITY_IE HtCapability;
709 ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
710 UCHAR HtCapabilityLen = 0, PreNHtCapabilityLen = 0;
712 UCHAR NewExtChannelOffset = 0xff;
713 #ifdef DOT11_N_SUPPORT
714 UCHAR CentralChannel;
715 #endif // DOT11_N_SUPPORT //
717 // Init Variable IE structure
718 pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
720 RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
721 RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
724 if (PeerBeaconAndProbeRspSanity(pAd,
750 &AironetCellPowerLimit,
756 &PreNHtCapabilityLen,
760 &NewExtChannelOffset,
764 // Disqualify 11b only adhoc when we are in 11g only adhoc mode
765 if ((BssType == BSS_ADHOC) && (pAd->CommonCfg.PhyMode == PHY_11G) && ((SupRateLen+ExtRateLen)< 12))
768 // BEACON from desired BSS/IBSS found. We should be able to decide most
769 // BSS parameters here.
770 // Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATEION?
771 // Do we need to receover back all parameters belonging to previous BSS?
772 // A. Should be not. There's no back-door recover to previous AP. It still need
773 // a new JOIN-AUTH-ASSOC sequence.
774 if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid))
776 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - receive desired BEACON at JoinWaitBeacon... Channel = %d\n", Channel));
777 RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled);
779 // Update RSSI to prevent No signal display when cards first initialized
780 pAd->StaCfg.RssiSample.LastRssi0 = ConvertToRssi(pAd, Elem->Rssi0, RSSI_0);
781 pAd->StaCfg.RssiSample.LastRssi1 = ConvertToRssi(pAd, Elem->Rssi1, RSSI_1);
782 pAd->StaCfg.RssiSample.LastRssi2 = ConvertToRssi(pAd, Elem->Rssi2, RSSI_2);
783 pAd->StaCfg.RssiSample.AvgRssi0 = pAd->StaCfg.RssiSample.LastRssi0;
784 pAd->StaCfg.RssiSample.AvgRssi0X8 = pAd->StaCfg.RssiSample.AvgRssi0 << 3;
785 pAd->StaCfg.RssiSample.AvgRssi1 = pAd->StaCfg.RssiSample.LastRssi1;
786 pAd->StaCfg.RssiSample.AvgRssi1X8 = pAd->StaCfg.RssiSample.AvgRssi1 << 3;
787 pAd->StaCfg.RssiSample.AvgRssi2 = pAd->StaCfg.RssiSample.LastRssi2;
788 pAd->StaCfg.RssiSample.AvgRssi2X8 = pAd->StaCfg.RssiSample.AvgRssi2 << 3;
791 // We need to check if SSID only set to any, then we can record the current SSID.
792 // Otherwise will cause hidden SSID association failed.
794 if (pAd->MlmeAux.SsidLen == 0)
796 NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen);
797 pAd->MlmeAux.SsidLen = SsidLen;
801 Idx = BssSsidTableSearch(&pAd->ScanTab, Bssid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, Channel);
803 if (Idx != BSS_NOT_FOUND)
806 // Multiple SSID case, used correct CapabilityInfo
808 CapabilityInfo = pAd->ScanTab.BssEntry[Idx].CapabilityInfo;
811 NdisMoveMemory(pAd->MlmeAux.Bssid, Bssid, MAC_ADDR_LEN);
812 pAd->MlmeAux.CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO;
813 pAd->MlmeAux.BssType = BssType;
814 pAd->MlmeAux.BeaconPeriod = BeaconPeriod;
815 pAd->MlmeAux.Channel = Channel;
816 pAd->MlmeAux.AtimWin = AtimWin;
817 pAd->MlmeAux.CfpPeriod = Cf.CfpPeriod;
818 pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration;
819 pAd->MlmeAux.APRalinkIe = RalinkIe;
821 // Copy AP's supported rate to MlmeAux for creating assoication request
822 // Also filter out not supported rate
823 pAd->MlmeAux.SupRateLen = SupRateLen;
824 NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen);
825 RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen);
826 pAd->MlmeAux.ExtRateLen = ExtRateLen;
827 NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen);
828 RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen);
830 NdisZeroMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, 16);
831 #ifdef DOT11_N_SUPPORT
832 pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;
833 pAd->MlmeAux.HtCapabilityLen = HtCapabilityLen;
835 // filter out un-supported ht rates
836 if (((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0)) && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
838 RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
839 RTMPMoveMemory(&pAd->MlmeAux.AddHtInfo, &AddHtInfo, SIZE_ADD_HT_INFO_IE);
841 // StaActive.SupportedHtPhy.MCSSet stores Peer AP's 11n Rx capability
842 NdisMoveMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, HtCapability.MCSSet, 16);
843 pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset;
844 pAd->MlmeAux.HtCapabilityLen = SIZE_HT_CAP_IE;
845 pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;
846 if (PreNHtCapabilityLen > 0)
847 pAd->StaActive.SupportedPhyInfo.bPreNHt = TRUE;
848 RTMPCheckHt(pAd, BSSID_WCID, &HtCapability, &AddHtInfo);
849 // Copy AP Parameter to StaActive. This is also in LinkUp.
850 DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction! (MpduDensity=%d, MaxRAmpduFactor=%d, BW=%d)\n",
851 pAd->StaActive.SupportedHtPhy.MpduDensity, pAd->StaActive.SupportedHtPhy.MaxRAmpduFactor, HtCapability.HtCapInfo.ChannelWidth));
853 if (AddHtInfoLen > 0)
855 CentralChannel = AddHtInfo.ControlChan;
856 // Check again the Bandwidth capability of this AP.
857 if ((AddHtInfo.ControlChan > 2)&& (AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))
859 CentralChannel = AddHtInfo.ControlChan - 2;
861 else if ((AddHtInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE) && (HtCapability.HtCapInfo.ChannelWidth == BW_40))
863 CentralChannel = AddHtInfo.ControlChan + 2;
867 if (pAd->MlmeAux.CentralChannel != CentralChannel)
868 DBGPRINT(RT_DEBUG_ERROR, ("PeerBeaconAtJoinAction HT===>Beacon Central Channel = %d, Control Channel = %d. Mlmeaux CentralChannel = %d\n", CentralChannel, AddHtInfo.ControlChan, pAd->MlmeAux.CentralChannel));
870 DBGPRINT(RT_DEBUG_TRACE, ("PeerBeaconAtJoinAction HT===>Central Channel = %d, Control Channel = %d, .\n", CentralChannel, AddHtInfo.ControlChan));
876 #endif // DOT11_N_SUPPORT //
878 // To prevent error, let legacy AP must have same CentralChannel and Channel.
879 if ((HtCapabilityLen == 0) && (PreNHtCapabilityLen == 0))
880 pAd->MlmeAux.CentralChannel = pAd->MlmeAux.Channel;
882 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
883 RTMPZeroMemory(&pAd->MlmeAux.HtCapability, SIZE_HT_CAP_IE);
884 RTMPZeroMemory(&pAd->MlmeAux.AddHtInfo, SIZE_ADD_HT_INFO_IE);
887 RTMPUpdateMlmeRate(pAd);
889 // copy QOS related information
890 if ((pAd->CommonCfg.bWmmCapable)
891 #ifdef DOT11_N_SUPPORT
892 || (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
893 #endif // DOT11_N_SUPPORT //
896 NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, &EdcaParm, sizeof(EDCA_PARM));
897 NdisMoveMemory(&pAd->MlmeAux.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));
898 NdisMoveMemory(&pAd->MlmeAux.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));
902 NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));
903 NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));
904 NdisZeroMemory(&pAd->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));
907 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - after JOIN, SupRateLen=%d, ExtRateLen=%d\n",
908 pAd->MlmeAux.SupRateLen, pAd->MlmeAux.ExtRateLen));
912 pAd->StaCfg.CkipFlag = CkipFlag;
914 // Keep TimeStamp for Re-Association used.
915 if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
916 pAd->StaCfg.CCKMBeaconAtJoinTimeStamp = TimeStamp;
917 #endif // LEAP_SUPPORT //
919 if (AironetCellPowerLimit != 0xFF)
921 //We need to change our TxPower for CCX 2.0 AP Control of Client Transmit Power
922 ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);
924 else //Used the default TX Power Percentage.
925 pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
927 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
928 Status = MLME_SUCCESS;
929 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
931 // not to me BEACON, ignored
933 // sanity check fail, ignore this frame
937 ==========================================================================
939 receive BEACON from peer
941 IRQL = DISPATCH_LEVEL
943 ==========================================================================
946 IN PRTMP_ADAPTER pAd,
947 IN MLME_QUEUE_ELEM *Elem)
949 UCHAR Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN];
950 CHAR Ssid[MAX_LEN_OF_SSID];
952 UCHAR SsidLen, MessageToMe=0, BssType, Channel, NewChannel, index=0;
953 UCHAR DtimCount=0, DtimPeriod=0, BcastFlag=0;
954 USHORT CapabilityInfo, AtimWin, BeaconPeriod;
955 LARGE_INTEGER TimeStamp;
956 USHORT TbttNumToNextWakeUp;
958 UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
959 UCHAR SupRateLen, ExtRateLen;
962 UCHAR AironetCellPowerLimit;
964 QBSS_LOAD_PARM QbssLoad;
965 QOS_CAPABILITY_PARM QosCapability;
967 // New for WPA security suites
968 UCHAR VarIE[MAX_VIE_LEN]; // Total VIE length = MAX_VIE_LEN - -5
969 NDIS_802_11_VARIABLE_IEs *pVIE = NULL;
970 HT_CAPABILITY_IE HtCapability;
971 ADD_HT_INFO_IE AddHtInfo; // AP might use this additional ht info IE
972 UCHAR HtCapabilityLen, PreNHtCapabilityLen;
974 UCHAR NewExtChannelOffset = 0xff;
982 #endif // RALINK_ATE //
984 if (!(INFRA_ON(pAd) || ADHOC_ON(pAd)
988 // Init Variable IE structure
989 pVIE = (PNDIS_802_11_VARIABLE_IEs) VarIE;
991 RTMPZeroMemory(&HtCapability, sizeof(HtCapability));
992 RTMPZeroMemory(&AddHtInfo, sizeof(ADD_HT_INFO_IE));
994 if (PeerBeaconAndProbeRspSanity(pAd,
1020 &AironetCellPowerLimit,
1026 &PreNHtCapabilityLen,
1030 &NewExtChannelOffset,
1034 BOOLEAN is_my_bssid, is_my_ssid;
1037 CHAR RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), ConvertToRssi(pAd, Elem->Rssi2, RSSI_2));
1039 is_my_bssid = MAC_ADDR_EQUAL(Bssid, pAd->CommonCfg.Bssid)? TRUE : FALSE;
1040 is_my_ssid = SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen)? TRUE:FALSE;
1043 // ignore BEACON not for my SSID
1044 if ((! is_my_ssid) && (! is_my_bssid))
1047 // It means STA waits disassoc completely from this AP, ignores this beacon.
1048 if (pAd->Mlme.CntlMachine.CurrState == CNTL_WAIT_DISASSOC)
1051 #ifdef DOT11_N_SUPPORT
1052 // Copy Control channel for this BSSID.
1053 if (AddHtInfoLen != 0)
1054 Channel = AddHtInfo.ControlChan;
1056 if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0))
1057 HtCapabilityLen = SIZE_HT_CAP_IE;
1058 #endif // DOT11_N_SUPPORT //
1061 // Housekeeping "SsidBssTab" table for later-on ROAMing usage.
1063 Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
1064 if (Bssidx == BSS_NOT_FOUND)
1066 // discover new AP of this network, create BSS entry
1067 Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
1068 &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen,
1069 &HtCapability, &AddHtInfo,HtCapabilityLen,AddHtInfoLen,NewExtChannelOffset, Channel,
1070 RealRssi, TimeStamp, CkipFlag, &EdcaParm, &QosCapability,
1071 &QbssLoad, LenVIE, pVIE);
1072 if (Bssidx == BSS_NOT_FOUND) // return if BSS table full
1075 NdisMoveMemory(pAd->ScanTab.BssEntry[Bssidx].PTSF, &Elem->Msg[24], 4);
1076 NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[0], &Elem->TimeStamp.u.LowPart, 4);
1077 NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[4], &Elem->TimeStamp.u.LowPart, 4);
1083 if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) && (Channel != NewChannel))
1085 // Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection).
1086 // In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results.
1087 AsicSwitchChannel(pAd, 1, FALSE);
1088 AsicLockChannel(pAd, 1);
1089 LinkDown(pAd, FALSE);
1090 MlmeQueueInit(&pAd->Mlme.Queue);
1091 BssTableInit(&pAd->ScanTab);
1092 RTMPusecDelay(1000000); // use delay to prevent STA do reassoc
1094 // channel sanity check
1095 for (index = 0 ; index < pAd->ChannelListNum; index++)
1097 if (pAd->ChannelList[index].Channel == NewChannel)
1099 pAd->ScanTab.BssEntry[Bssidx].Channel = NewChannel;
1100 pAd->CommonCfg.Channel = NewChannel;
1101 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
1102 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
1103 DBGPRINT(RT_DEBUG_TRACE, ("PeerBeacon - STA receive channel switch announcement IE (New Channel =%d)\n", NewChannel));
1108 if (index >= pAd->ChannelListNum)
1110 DBGPRINT_ERR(("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum));
1114 // if the ssid matched & bssid unmatched, we should select the bssid with large value.
1115 // This might happened when two STA start at the same time
1116 if ((! is_my_bssid) && ADHOC_ON(pAd))
1120 // Add the safeguard against the mismatch of adhoc wep status
1121 if (pAd->StaCfg.WepStatus != pAd->ScanTab.BssEntry[Bssidx].WepStatus)
1123 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - Not matched wep status %d %d\n", pAd->StaCfg.WepStatus, pAd->ScanTab.BssEntry[Bssidx].WepStatus));
1124 DBGPRINT(RT_DEBUG_TRACE, ("bssid=%s\n", pAd->ScanTab.BssEntry[Bssidx].Bssid));
1128 // collapse into the ADHOC network which has bigger BSSID value.
1129 for (i = 0; i < 6; i++)
1131 if (Bssid[i] > pAd->CommonCfg.Bssid[i])
1133 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - merge to the IBSS with bigger BSSID=%02x:%02x:%02x:%02x:%02x:%02x\n",
1134 Bssid[0], Bssid[1], Bssid[2], Bssid[3], Bssid[4], Bssid[5]));
1135 AsicDisableSync(pAd);
1136 COPY_MAC_ADDR(pAd->CommonCfg.Bssid, Bssid);
1137 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
1138 MakeIbssBeacon(pAd); // re-build BEACON frame
1139 AsicEnableIbssSync(pAd); // copy BEACON frame to on-chip memory
1143 else if (Bssid[i] < pAd->CommonCfg.Bssid[i])
1149 NdisGetSystemUpTime(&Now);
1150 pBss = &pAd->ScanTab.BssEntry[Bssidx];
1151 pBss->Rssi = RealRssi; // lastest RSSI
1152 pBss->LastBeaconRxTime = Now; // last RX timestamp
1155 // BEACON from my BSSID - either IBSS or INFRA network
1161 pAd->StaCfg.DtimCount = DtimCount;
1162 pAd->StaCfg.DtimPeriod = DtimPeriod;
1163 pAd->StaCfg.LastBeaconRxTime = Now;
1166 RxWI.RSSI0 = Elem->Rssi0;
1167 RxWI.RSSI1 = Elem->Rssi1;
1168 RxWI.RSSI2 = Elem->Rssi2;
1170 Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, &RxWI);
1171 if (AironetCellPowerLimit != 0xFF)
1174 // We get the Cisco (ccx) "TxPower Limit" required
1175 // Changed to appropriate TxPower Limit for Ciso Compatible Extensions
1177 ChangeToCellPowerLimit(pAd, AironetCellPowerLimit);
1182 // AironetCellPowerLimit equal to 0xFF means the Cisco (ccx) "TxPower Limit" not exist.
1183 // Used the default TX Power Percentage, that set from UI.
1185 pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
1188 if (ADHOC_ON(pAd) && (CAP_IS_IBSS_ON(CapabilityInfo)))
1190 UCHAR MaxSupportedRateIn500Kbps = 0;
1192 MAC_TABLE_ENTRY *pEntry;
1194 // supported rates array may not be sorted. sort it and find the maximum rate
1195 for (idx=0; idx<SupRateLen; idx++)
1197 if (MaxSupportedRateIn500Kbps < (SupRate[idx] & 0x7f))
1198 MaxSupportedRateIn500Kbps = SupRate[idx] & 0x7f;
1201 for (idx=0; idx<ExtRateLen; idx++)
1203 if (MaxSupportedRateIn500Kbps < (ExtRate[idx] & 0x7f))
1204 MaxSupportedRateIn500Kbps = ExtRate[idx] & 0x7f;
1207 // look up the existing table
1208 pEntry = MacTableLookup(pAd, Addr2);
1210 // Ad-hoc mode is using MAC address as BA session. So we need to continuously find newly joined adhoc station by receiving beacon.
1211 // To prevent always check this, we use wcid == RESERVED_WCID to recognize it as newly joined adhoc station.
1212 if ((ADHOC_ON(pAd) && (Elem->Wcid == RESERVED_WCID)) ||
1213 (pEntry && ((pEntry->LastBeaconRxTime + ADHOC_ENTRY_BEACON_LOST_TIME) < Now)))
1216 // Another adhoc joining, add to our MAC table.
1217 pEntry = MacTableInsertEntry(pAd, Addr2, BSS0, FALSE);
1219 if (StaAddMacTableEntry(pAd, pEntry, MaxSupportedRateIn500Kbps, &HtCapability, HtCapabilityLen, CapabilityInfo) == FALSE)
1221 DBGPRINT(RT_DEBUG_TRACE, ("ADHOC - Add Entry failed.\n"));
1226 (Elem->Wcid == RESERVED_WCID))
1228 idx = pAd->StaCfg.DefaultKeyId;
1229 RT28XX_STA_SECURITY_INFO_ADD(pAd, BSS0, idx, pEntry);
1233 if (pEntry && pEntry->ValidAsCLI)
1234 pEntry->LastBeaconRxTime = Now;
1236 // At least another peer in this IBSS, declare MediaState as CONNECTED
1237 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
1239 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1241 pAd->IndicateMediaState = NdisMediaStateConnected;
1242 RTMP_IndicateMediaState(pAd);
1243 pAd->ExtraInfo = GENERAL_LINK_UP;
1244 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
1246 // 2003/03/12 - john
1247 // Make sure this entry in "ScanTab" table, thus complies to Microsoft's policy that
1248 // "site survey" result should always include the current connected network.
1250 Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel);
1251 if (Bssidx == BSS_NOT_FOUND)
1253 Bssidx = BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, SsidLen, BssType, BeaconPeriod,
1254 &CfParm, AtimWin, CapabilityInfo, SupRate, SupRateLen, ExtRate, ExtRateLen, &HtCapability,
1255 &AddHtInfo, HtCapabilityLen, AddHtInfoLen, NewExtChannelOffset, Channel, RealRssi, TimeStamp, 0,
1256 &EdcaParm, &QosCapability, &QbssLoad, LenVIE, pVIE);
1258 DBGPRINT(RT_DEBUG_TRACE, ("ADHOC fOP_STATUS_MEDIA_STATE_CONNECTED.\n"));
1264 BOOLEAN bUseShortSlot, bUseBGProtection;
1266 // decide to use/change to -
1267 // 1. long slot (20 us) or short slot (9 us) time
1268 // 2. turn on/off RTS/CTS and/or CTS-to-self protection
1269 // 3. short preamble
1271 //bUseShortSlot = pAd->CommonCfg.bUseShortSlotTime && CAP_IS_SHORT_SLOT(CapabilityInfo);
1272 bUseShortSlot = CAP_IS_SHORT_SLOT(CapabilityInfo);
1273 if (bUseShortSlot != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED))
1274 AsicSetSlotTime(pAd, bUseShortSlot);
1276 bUseBGProtection = (pAd->CommonCfg.UseBGProtection == 1) || // always use
1277 ((pAd->CommonCfg.UseBGProtection == 0) && ERP_IS_USE_PROTECTION(Erp));
1279 if (pAd->CommonCfg.Channel > 14) // always no BG protection in A-band. falsely happened when switching A/G band to a dual-band AP
1280 bUseBGProtection = FALSE;
1282 if (bUseBGProtection != OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED))
1284 if (bUseBGProtection)
1286 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
1287 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),FALSE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));
1291 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
1292 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, (OFDMSETPROTECT|CCKSETPROTECT|ALLN_SETPROTECT),TRUE,(pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1));
1295 DBGPRINT(RT_DEBUG_WARN, ("SYNC - AP changed B/G protection to %d\n", bUseBGProtection));
1298 #ifdef DOT11_N_SUPPORT
1299 // check Ht protection mode. and adhere to the Non-GF device indication by AP.
1300 if ((AddHtInfoLen != 0) &&
1301 ((AddHtInfo.AddHtInfo2.OperaionMode != pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode) ||
1302 (AddHtInfo.AddHtInfo2.NonGfPresent != pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent)))
1304 pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent = AddHtInfo.AddHtInfo2.NonGfPresent;
1305 pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode = AddHtInfo.AddHtInfo2.OperaionMode;
1306 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)
1308 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);
1311 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
1313 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP changed N OperaionMode to %d\n", pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode));
1315 #endif // DOT11_N_SUPPORT //
1317 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED) &&
1318 ERP_IS_USE_BARKER_PREAMBLE(Erp))
1320 MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
1321 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP forced to use LONG preamble\n"));
1324 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) &&
1325 (EdcaParm.bValid == TRUE) &&
1326 (EdcaParm.EdcaUpdateCount != pAd->CommonCfg.APEdcaParm.EdcaUpdateCount))
1328 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - AP change EDCA parameters(from %d to %d)\n",
1329 pAd->CommonCfg.APEdcaParm.EdcaUpdateCount,
1330 EdcaParm.EdcaUpdateCount));
1331 AsicSetEdcaParm(pAd, &EdcaParm);
1334 // copy QOS related information
1335 NdisMoveMemory(&pAd->CommonCfg.APQbssLoad, &QbssLoad, sizeof(QBSS_LOAD_PARM));
1336 NdisMoveMemory(&pAd->CommonCfg.APQosCapability, &QosCapability, sizeof(QOS_CAPABILITY_PARM));
1339 // only INFRASTRUCTURE mode support power-saving feature
1340 if ((INFRA_ON(pAd) && (pAd->StaCfg.Psm == PWR_SAVE)) || (pAd->CommonCfg.bAPSDForcePowerSave))
1343 // 1. AP has backlogged unicast-to-me frame, stay AWAKE, send PSPOLL
1344 // 2. AP has backlogged broadcast/multicast frame and we want those frames, stay AWAKE
1345 // 3. we have outgoing frames in TxRing or MgmtRing, better stay AWAKE
1346 // 4. Psm change to PWR_SAVE, but AP not been informed yet, we better stay AWAKE
1347 // 5. otherwise, put PHY back to sleep to save battery.
1350 if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable &&
1351 pAd->CommonCfg.bAPSDAC_BE && pAd->CommonCfg.bAPSDAC_BK && pAd->CommonCfg.bAPSDAC_VI && pAd->CommonCfg.bAPSDAC_VO)
1353 pAd->CommonCfg.bNeedSendTriggerFrame = TRUE;
1356 RT28XX_PS_POLL_ENQUEUE(pAd);
1358 else if (BcastFlag && (DtimCount == 0) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM))
1361 else if ((pAd->TxSwQueue[QID_AC_BK].Number != 0) ||
1362 (pAd->TxSwQueue[QID_AC_BE].Number != 0) ||
1363 (pAd->TxSwQueue[QID_AC_VI].Number != 0) ||
1364 (pAd->TxSwQueue[QID_AC_VO].Number != 0) ||
1365 (RTMPFreeTXDRequest(pAd, QID_AC_BK, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
1366 (RTMPFreeTXDRequest(pAd, QID_AC_BE, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
1367 (RTMPFreeTXDRequest(pAd, QID_AC_VI, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
1368 (RTMPFreeTXDRequest(pAd, QID_AC_VO, TX_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS) ||
1369 (RTMPFreeTXDRequest(pAd, QID_MGMT, MGMT_RING_SIZE - 1, &FreeNumber) != NDIS_STATUS_SUCCESS))
1371 // TODO: consider scheduled HCCA. might not be proper to use traditional DTIM-based power-saving scheme
1372 // can we cheat here (i.e. just check MGMT & AC_BE) for better performance?
1376 USHORT NextDtim = DtimCount;
1379 NextDtim = DtimPeriod;
1381 TbttNumToNextWakeUp = pAd->StaCfg.DefaultListenCount;
1382 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM) && (TbttNumToNextWakeUp > NextDtim))
1383 TbttNumToNextWakeUp = NextDtim;
1385 if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
1387 AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
1392 // not my BSSID, ignore it
1394 // sanity check fail, ignore this frame
1398 ==========================================================================
1400 Receive PROBE REQ from remote peer when operating in IBSS mode
1401 ==========================================================================
1403 VOID PeerProbeReqAction(
1404 IN PRTMP_ADAPTER pAd,
1405 IN MLME_QUEUE_ELEM *Elem)
1407 UCHAR Addr2[MAC_ADDR_LEN];
1408 CHAR Ssid[MAX_LEN_OF_SSID];
1410 #ifdef DOT11_N_SUPPORT
1411 UCHAR HtLen, AddHtLen, NewExtLen;
1412 #endif // DOT11_N_SUPPORT //
1413 HEADER_802_11 ProbeRspHdr;
1414 NDIS_STATUS NStatus;
1415 PUCHAR pOutBuffer = NULL;
1417 LARGE_INTEGER FakeTimestamp;
1418 UCHAR DsLen = 1, IbssLen = 2;
1419 UCHAR LocalErpIe[3] = {IE_ERP, 1, 0};
1421 USHORT CapabilityInfo;
1422 UCHAR RSNIe = IE_WPA;
1424 if (! ADHOC_ON(pAd))
1427 if (PeerProbeReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, Ssid, &SsidLen))
1429 if ((SsidLen == 0) || SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen))
1431 // allocate and send out ProbeRsp frame
1432 NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
1433 if (NStatus != NDIS_STATUS_SUCCESS)
1436 //pAd->StaCfg.AtimWin = 0; // ??????
1438 Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
1439 (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
1440 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
1441 CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);
1443 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1444 sizeof(HEADER_802_11), &ProbeRspHdr,
1445 TIMESTAMP_LEN, &FakeTimestamp,
1446 2, &pAd->CommonCfg.BeaconPeriod,
1449 1, &pAd->CommonCfg.SsidLen,
1450 pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
1452 1, &pAd->StaActive.SupRateLen,
1453 pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,
1456 1, &pAd->CommonCfg.Channel,
1459 2, &pAd->StaActive.AtimWin,
1462 if (pAd->StaActive.ExtRateLen)
1465 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1468 1, &pAd->StaActive.ExtRateLen,
1469 pAd->StaActive.ExtRateLen, &pAd->StaActive.ExtRate,
1474 // If adhoc secruity is set for WPA-None, append the cipher suite IE
1475 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1478 MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1480 1, &pAd->StaCfg.RSNIE_Len,
1481 pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
1485 #ifdef DOT11_N_SUPPORT
1486 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
1489 UCHAR BROADCOM[4] = {0x0, 0x90, 0x4c, 0x33};
1490 HtLen = sizeof(pAd->CommonCfg.HtCapability);
1491 AddHtLen = sizeof(pAd->CommonCfg.AddHTInfo);
1493 //New extension channel offset IE is included in Beacon, Probe Rsp or channel Switch Announcement Frame
1494 if (pAd->bBroadComHT == TRUE)
1496 MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
1499 pAd->MlmeAux.HtCapabilityLen, &pAd->MlmeAux.HtCapability,
1504 MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen,
1507 sizeof(HT_CAPABILITY_IE), &pAd->CommonCfg.HtCapability,
1510 sizeof(ADD_HT_INFO_IE), &pAd->CommonCfg.AddHTInfo,
1513 sizeof(NEW_EXT_CHAN_IE), &pAd->CommonCfg.NewExtChanOffset,
1518 #endif // DOT11_N_SUPPORT //
1519 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1520 MlmeFreeMemory(pAd, pOutBuffer);
1525 VOID BeaconTimeoutAtJoinAction(
1526 IN PRTMP_ADAPTER pAd,
1527 IN MLME_QUEUE_ELEM *Elem)
1530 DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeoutAtJoinAction\n"));
1531 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1532 Status = MLME_REJ_TIMEOUT;
1533 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
1537 ==========================================================================
1539 Scan timeout procedure. basically add channel index by 1 and rescan
1540 ==========================================================================
1542 VOID ScanTimeoutAction(
1543 IN PRTMP_ADAPTER pAd,
1544 IN MLME_QUEUE_ELEM *Elem)
1546 pAd->MlmeAux.Channel = NextChannel(pAd, pAd->MlmeAux.Channel);
1548 // Only one channel scanned for CISCO beacon request
1549 if ((pAd->MlmeAux.ScanType == SCAN_CISCO_ACTIVE) ||
1550 (pAd->MlmeAux.ScanType == SCAN_CISCO_PASSIVE) ||
1551 (pAd->MlmeAux.ScanType == SCAN_CISCO_NOISE) ||
1552 (pAd->MlmeAux.ScanType == SCAN_CISCO_CHANNEL_LOAD))
1553 pAd->MlmeAux.Channel = 0;
1555 // this routine will stop if pAd->MlmeAux.Channel == 0
1556 ScanNextChannel(pAd);
1560 ==========================================================================
1562 ==========================================================================
1564 VOID InvalidStateWhenScan(
1565 IN PRTMP_ADAPTER pAd,
1566 IN MLME_QUEUE_ELEM *Elem)
1569 DBGPRINT(RT_DEBUG_TRACE, ("AYNC - InvalidStateWhenScan(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
1570 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1571 Status = MLME_STATE_MACHINE_REJECT;
1572 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
1576 ==========================================================================
1578 ==========================================================================
1580 VOID InvalidStateWhenJoin(
1581 IN PRTMP_ADAPTER pAd,
1582 IN MLME_QUEUE_ELEM *Elem)
1585 DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenJoin(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
1586 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1587 Status = MLME_STATE_MACHINE_REJECT;
1588 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
1592 ==========================================================================
1594 ==========================================================================
1596 VOID InvalidStateWhenStart(
1597 IN PRTMP_ADAPTER pAd,
1598 IN MLME_QUEUE_ELEM *Elem)
1601 DBGPRINT(RT_DEBUG_TRACE, ("InvalidStateWhenStart(state=%ld). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState));
1602 pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
1603 Status = MLME_STATE_MACHINE_REJECT;
1604 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
1608 ==========================================================================
1611 IRQL = DISPATCH_LEVEL
1613 ==========================================================================
1616 IN PRTMP_ADAPTER pAd)
1623 #endif // RALINK_ATE //
1626 if (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeLegacy_PSP)
1627 pAd->PsPollFrame.FC.PwrMgmt = PWR_SAVE;
1628 MiniportMMRequest(pAd, 0, (PUCHAR)&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
1633 ==========================================================================
1635 ==========================================================================
1637 VOID EnqueueProbeRequest(
1638 IN PRTMP_ADAPTER pAd)
1643 HEADER_802_11 Hdr80211;
1645 DBGPRINT(RT_DEBUG_TRACE, ("force out a ProbeRequest ...\n"));
1647 NState = MlmeAllocateMemory(pAd, &pOutBuffer); //Get an unused nonpaged memory
1648 if (NState == NDIS_STATUS_SUCCESS)
1650 MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
1652 // this ProbeRequest explicitly specify SSID to reduce unwanted ProbeResponse
1653 MakeOutgoingFrame(pOutBuffer, &FrameLen,
1654 sizeof(HEADER_802_11), &Hdr80211,
1656 1, &pAd->CommonCfg.SsidLen,
1657 pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
1659 1, &pAd->StaActive.SupRateLen,
1660 pAd->StaActive.SupRateLen, pAd->StaActive.SupRate,
1662 MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
1663 MlmeFreeMemory(pAd, pOutBuffer);
1668 #ifdef DOT11_N_SUPPORT
1669 #ifdef DOT11N_DRAFT3
1670 VOID BuildEffectedChannelList(
1671 IN PRTMP_ADAPTER pAd)
1675 UCHAR UpperChannel = 0, LowerChannel = 0;
1677 RTMPZeroMemory(EChannel, 11);
1679 // Find upper channel and lower channel.
1680 if (pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
1682 UpperChannel = pAd->CommonCfg.Channel;
1683 LowerChannel = pAd->CommonCfg.CentralChannel;
1685 else if (pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
1687 UpperChannel = pAd->CommonCfg.CentralChannel;
1688 LowerChannel = pAd->CommonCfg.Channel;
1695 // Record channels that is below lower channel..
1696 if (LowerChannel > 1)
1698 EChannel[0] = LowerChannel - 1;
1700 if (LowerChannel > 2)
1702 EChannel[1] = LowerChannel - 2;
1704 if (LowerChannel > 3)
1706 EChannel[2] = LowerChannel - 3;
1711 // Record channels that is between lower channel and upper channel.
1712 for (k = LowerChannel;k < UpperChannel;k++)
1717 // Record channels that is above upper channel..
1718 if (LowerChannel < 11)
1720 EChannel[i] = UpperChannel + 1;
1722 if (LowerChannel < 10)
1724 EChannel[i] = LowerChannel + 2;
1726 if (LowerChannel < 9)
1728 EChannel[i] = LowerChannel + 3;
1734 for (j = 0;j < i;j++)
1736 for (k = 0;k < pAd->ChannelListNum;k++)
1738 if (pAd->ChannelList[k].Channel == EChannel[j])
1740 pAd->ChannelList[k].bEffectedChannel = TRUE;
1741 DBGPRINT(RT_DEBUG_TRACE,(" EffectedChannel( =%d)\n", EChannel[j]));
1747 #endif // DOT11N_DRAFT3 //
1748 #endif // DOT11_N_SUPPORT //
1750 BOOLEAN ScanRunning(
1751 IN PRTMP_ADAPTER pAd)
1753 return (pAd->Mlme.SyncMachine.CurrState == SCAN_LISTEN) ? TRUE : FALSE;