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-08-08 Major modification from RT2560
37 #include "../rt_config.h"
39 UCHAR CipherSuiteWpaNoneTkip[] = {
40 0x00, 0x50, 0xf2, 0x01, // oui
41 0x01, 0x00, // Version
42 0x00, 0x50, 0xf2, 0x02, // Multicast
43 0x01, 0x00, // Number of unicast
44 0x00, 0x50, 0xf2, 0x02, // unicast
45 0x01, 0x00, // number of authentication method
46 0x00, 0x50, 0xf2, 0x00 // authentication
48 UCHAR CipherSuiteWpaNoneTkipLen = (sizeof(CipherSuiteWpaNoneTkip) / sizeof(UCHAR));
50 UCHAR CipherSuiteWpaNoneAes[] = {
51 0x00, 0x50, 0xf2, 0x01, // oui
52 0x01, 0x00, // Version
53 0x00, 0x50, 0xf2, 0x04, // Multicast
54 0x01, 0x00, // Number of unicast
55 0x00, 0x50, 0xf2, 0x04, // unicast
56 0x01, 0x00, // number of authentication method
57 0x00, 0x50, 0xf2, 0x00 // authentication
59 UCHAR CipherSuiteWpaNoneAesLen = (sizeof(CipherSuiteWpaNoneAes) / sizeof(UCHAR));
61 // The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS,
62 // or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS
63 // All settings successfuly negotiated furing MLME state machines become final settings
64 // and are copied to pAd->StaActive
65 #define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
67 (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \
68 NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \
69 COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \
70 (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \
71 (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \
72 (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \
73 (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \
74 (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \
75 (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \
76 (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \
77 (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \
78 (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \
79 NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\
80 (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \
81 NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\
82 NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));\
83 NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));\
84 NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));\
85 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \
86 (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \
87 (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\
88 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\
89 (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\
93 ==========================================================================
98 ==========================================================================
101 IN PRTMP_ADAPTER pAd,
103 OUT STATE_MACHINE_FUNC Trans[])
105 // Control state machine differs from other state machines, the interface
106 // follows the standard interface
107 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
111 ==========================================================================
114 IRQL = DISPATCH_LEVEL
116 ==========================================================================
118 VOID MlmeCntlMachinePerformAction(
119 IN PRTMP_ADAPTER pAd,
121 IN MLME_QUEUE_ELEM *Elem)
123 switch(pAd->Mlme.CntlMachine.CurrState)
127 CntlIdleProc(pAd, Elem);
130 case CNTL_WAIT_DISASSOC:
131 CntlWaitDisassocProc(pAd, Elem);
134 CntlWaitJoinProc(pAd, Elem);
137 // CNTL_WAIT_REASSOC is the only state in CNTL machine that does
138 // not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)".
139 // Therefore not protected by NDIS's "only one outstanding OID request"
140 // rule. Which means NDIS may SET OID in the middle of ROAMing attempts.
141 // Current approach is to block new SET request at RTMPSetInformation()
142 // when CntlMachine.CurrState is not CNTL_IDLE
143 case CNTL_WAIT_REASSOC:
144 CntlWaitReassocProc(pAd, Elem);
147 case CNTL_WAIT_START:
148 CntlWaitStartProc(pAd, Elem);
151 CntlWaitAuthProc(pAd, Elem);
153 case CNTL_WAIT_AUTH2:
154 CntlWaitAuthProc2(pAd, Elem);
156 case CNTL_WAIT_ASSOC:
157 CntlWaitAssocProc(pAd, Elem);
160 case CNTL_WAIT_OID_LIST_SCAN:
161 if(Elem->MsgType == MT2_SCAN_CONF)
163 // Resume TxRing after SCANING complete. We hope the out-of-service time
164 // won't be too long to let upper layer time-out the waiting frames
165 RTMPResumeMsduTransmission(pAd);
166 if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
168 // Cisco scan request is finished, prepare beacon report
169 MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
171 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
174 // Set LED status to previous status.
176 if (pAd->bLedOnScanning)
178 pAd->bLedOnScanning = FALSE;
179 RTMPSetLED(pAd, pAd->LedStatus);
184 case CNTL_WAIT_OID_DISASSOC:
185 if (Elem->MsgType == MT2_DISASSOC_CONF)
187 LinkDown(pAd, FALSE);
188 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
193 // This state is for that we want to connect to an AP but
194 // it didn't find on BSS List table. So we need to scan the air first,
195 // after that we can try to connect to the desired AP if available.
197 case CNTL_WAIT_SCAN_FOR_CONNECT:
198 if(Elem->MsgType == MT2_SCAN_CONF)
200 // Resume TxRing after SCANING complete. We hope the out-of-service time
201 // won't be too long to let upper layer time-out the waiting frames
202 RTMPResumeMsduTransmission(pAd);
204 if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
206 // Cisco scan request is finished, prepare beacon report
207 MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
209 #endif // CCX_SUPPORT //
210 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
213 // Check if we can connect to.
215 BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
216 if (pAd->MlmeAux.SsidBssTab.BssNr > 0)
218 MlmeAutoReconnectLastSSID(pAd);
224 DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType));
231 ==========================================================================
234 IRQL = DISPATCH_LEVEL
236 ==========================================================================
239 IN PRTMP_ADAPTER pAd,
240 IN MLME_QUEUE_ELEM *Elem)
242 MLME_DISASSOC_REQ_STRUCT DisassocReq;
244 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
247 switch(Elem->MsgType)
249 case OID_802_11_SSID:
250 CntlOidSsidProc(pAd, Elem);
253 case OID_802_11_BSSID:
254 CntlOidRTBssidProc(pAd,Elem);
257 case OID_802_11_BSSID_LIST_SCAN:
258 CntlOidScanProc(pAd,Elem);
261 case OID_802_11_DISASSOCIATE:
262 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
263 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
264 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
266 if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_ENABLE_WITH_WEB_UI)
268 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
269 // Since calling this indicate user don't want to connect to that SSID anymore.
270 pAd->MlmeAux.AutoReconnectSsidLen= 32;
271 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
275 case MT2_MLME_ROAMING_REQ:
276 CntlMlmeRoamingProc(pAd, Elem);
279 case OID_802_11_MIC_FAILURE_REPORT_FRAME:
280 WpaMicFailureReportFrame(pAd, Elem);
284 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem->MsgType));
289 VOID CntlOidScanProc(
290 IN PRTMP_ADAPTER pAd,
291 IN MLME_QUEUE_ELEM *Elem)
293 MLME_SCAN_REQ_STRUCT ScanReq;
294 ULONG BssIdx = BSS_NOT_FOUND;
297 // record current BSS if network is connected.
298 // 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.
299 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
301 BssIdx = BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->CommonCfg.Channel);
302 if (BssIdx != BSS_NOT_FOUND)
304 NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
308 // clean up previous SCAN result, add current BSS back to table if any
309 BssTableInit(&pAd->ScanTab);
310 if (BssIdx != BSS_NOT_FOUND)
312 // DDK Note: If the NIC is associated with a particular BSSID and SSID
313 // that are not contained in the list of BSSIDs generated by this scan, the
314 // BSSID description of the currently associated BSSID and SSID should be
315 // appended to the list of BSSIDs in the NIC's database.
316 // To ensure this, we append this BSS as the first entry in SCAN result
317 NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY));
318 pAd->ScanTab.BssNr = 1;
321 ScanParmFill(pAd, &ScanReq, "", 0, BSS_ANY, SCAN_ACTIVE);
322 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
323 sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
324 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
328 ==========================================================================
330 Before calling this routine, user desired SSID should already been
331 recorded in CommonCfg.Ssid[]
332 IRQL = DISPATCH_LEVEL
334 ==========================================================================
336 VOID CntlOidSsidProc(
337 IN PRTMP_ADAPTER pAd,
338 IN MLME_QUEUE_ELEM * Elem)
340 PNDIS_802_11_SSID pOidSsid = (NDIS_802_11_SSID *)Elem->Msg;
341 MLME_DISASSOC_REQ_STRUCT DisassocReq;
345 // BBP and RF are not accessible in PS mode, we has to wake them up first
346 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))
347 AsicForceWakeup(pAd, RTMP_HALT);
350 // Step 1. record the desired user settings to MlmeAux
351 NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
352 NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);
353 pAd->MlmeAux.SsidLen = (UCHAR)pOidSsid->SsidLength;
354 NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
355 pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
359 // Update Reconnect Ssid, that user desired to connect.
361 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
362 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
363 pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
365 // step 2. find all matching BSS in the lastest SCAN result (inBssTab)
366 // & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order
367 BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
369 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",
370 pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr, pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid));
371 NdisGetSystemUpTime(&Now);
373 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
374 (pAd->CommonCfg.SsidLen == pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen) &&
375 NdisEqualMemory(pAd->CommonCfg.Ssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid, pAd->CommonCfg.SsidLen) &&
376 MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid))
378 // Case 1. already connected with an AP who has the desired SSID
381 // Add checking Mode "LEAP" for CCX 1.0
382 if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
383 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
384 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
385 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
387 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
389 // case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo
390 // connection process
391 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
392 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
393 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
394 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
395 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
397 else if (pAd->bConfigChanged == TRUE)
399 // case 1.2 Important Config has changed, we have to reconnect to the same AP
400 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));
401 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
402 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
403 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
404 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
408 // case 1.3. already connected to the SSID with highest RSSI.
409 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));
411 // (HCT 12.1) 1c_wlan_mediaevents required
412 // media connect events are indicated when associating with the same AP
417 // Since MediaState already is NdisMediaStateConnected
418 // We just indicate the connect event again to meet the WHQL required.
420 pAd->IndicateMediaState = NdisMediaStateConnected;
421 RTMP_IndicateMediaState(pAd);
422 pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
425 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
428 union iwreq_data wrqu;
430 memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
431 memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
432 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
437 else if (INFRA_ON(pAd))
441 // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
442 // RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect
443 // But media status is connected, so the SSID not report correctly.
445 if (!SSID_EQUAL(pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen))
448 // Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event.
450 pAd->MlmeAux.CurrReqIsFromNdis = TRUE;
452 // case 2. active INFRA association existent
453 // roaming is done within miniport driver, nothing to do with configuration
454 // utility. so upon a new SET(OID_802_11_SSID) is received, we just
455 // disassociate with the current associated AP,
456 // then perform a new association with this new SSID, no matter the
457 // new/old SSID are the same or not.
458 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
459 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
460 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
461 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
462 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
468 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));
469 LinkDown(pAd, FALSE);
470 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
471 pAd->IndicateMediaState = NdisMediaStateDisconnected;
472 RTMP_IndicateMediaState(pAd);
473 pAd->ExtraInfo = GENERAL_LINK_DOWN;
474 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
477 if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) &&
478 (pAd->StaCfg.bAutoReconnect == TRUE) &&
479 (pAd->MlmeAux.BssType == BSS_INFRA) &&
480 (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) == TRUE)
483 MLME_SCAN_REQ_STRUCT ScanReq;
485 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));
486 ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);
487 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
488 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
489 // Reset Missed scan number
490 pAd->StaCfg.LastScanTime = Now;
494 pAd->MlmeAux.BssIdx = 0;
495 IterateOnBssTab(pAd);
502 ==========================================================================
505 IRQL = DISPATCH_LEVEL
507 ==========================================================================
509 VOID CntlOidRTBssidProc(
510 IN PRTMP_ADAPTER pAd,
511 IN MLME_QUEUE_ELEM * Elem)
514 PUCHAR pOidBssid = (PUCHAR)Elem->Msg;
515 MLME_DISASSOC_REQ_STRUCT DisassocReq;
516 MLME_JOIN_REQ_STRUCT JoinReq;
518 // record user desired settings
519 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);
520 pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
523 // Update Reconnect Ssid, that user desired to connect.
525 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
526 pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
527 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
529 // find the desired BSS in the latest SCAN result table
530 BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);
531 if (BssIdx == BSS_NOT_FOUND)
533 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));
534 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
538 // copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why?
539 // Because we need this entry to become the JOIN target in later on SYNC state machine
540 pAd->MlmeAux.BssIdx = 0;
541 pAd->MlmeAux.SsidBssTab.BssNr = 1;
542 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
544 // 2002-11-26 skip the following checking. i.e. if user wants to re-connect to same AP
545 // we just follow normal procedure. The reason of user doing this may because he/she changed
546 // AP to another channel, but we still received BEACON from it thus don't claim Link Down.
547 // Since user knows he's changed AP channel, he'll re-connect again. By skipping the following
548 // checking, we'll disassociate then re-do normal association with this AP at the new channel.
549 // 2003-1-6 Re-enable this feature based on microsoft requirement which prefer not to re-do
550 // connection when setting the same BSSID.
551 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
552 MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pOidBssid))
554 // already connected to the same BSSID, go back to idle state directly
555 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - already in this BSSID. ignore this SET_BSSID request\n"));
556 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
559 union iwreq_data wrqu;
561 memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
562 memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
563 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
571 // disassoc from current AP first
572 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - disassociate with current AP ...\n"));
573 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
574 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
575 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
577 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
583 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - drop current ADHOC\n"));
584 LinkDown(pAd, FALSE);
585 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
586 pAd->IndicateMediaState = NdisMediaStateDisconnected;
587 RTMP_IndicateMediaState(pAd);
588 pAd->ExtraInfo = GENERAL_LINK_DOWN;
589 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
592 // Change the wepstatus to original wepstatus
593 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
594 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
595 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
597 // Check cipher suite, AP must have more secured cipher than station setting
598 // Set the Pairwise and Group cipher to match the intended AP setting
599 // We can only connect to AP with less secured cipher setting
600 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
602 pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.GroupCipher;
604 if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher)
605 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher;
606 else if (pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
607 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux;
608 else // There is no PairCipher Aux, downgrade our capability to TKIP
609 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
611 else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
613 pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.GroupCipher;
615 if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher)
616 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher;
617 else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
618 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux;
619 else // There is no PairCipher Aux, downgrade our capability to TKIP
620 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
623 pAd->StaCfg.RsnCapability = pAd->ScanTab.BssEntry[BssIdx].WPA2.RsnCapability;
626 // Set Mix cipher flag
627 pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
628 if (pAd->StaCfg.bMixCipher == TRUE)
630 // If mix cipher, re-build RSNIE
631 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
633 // No active association, join the BSS immediately
634 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",
635 pOidBssid[0],pOidBssid[1],pOidBssid[2],pOidBssid[3],pOidBssid[4],pOidBssid[5]));
637 JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);
638 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq);
640 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
645 // Roaming is the only external request triggering CNTL state machine
646 // despite of other "SET OID" operation. All "SET OID" related oerations
647 // happen in sequence, because no other SET OID will be sent to this device
648 // until the the previous SET operation is complete (successful o failed).
649 // So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?
650 // or been corrupted by other "SET OID"?
652 // IRQL = DISPATCH_LEVEL
653 VOID CntlMlmeRoamingProc(
654 IN PRTMP_ADAPTER pAd,
655 IN MLME_QUEUE_ELEM *Elem)
658 // AP in different channel may show lower RSSI than actual value??
659 // should we add a weighting factor to compensate it?
660 DBGPRINT(RT_DEBUG_TRACE,("CNTL - Roaming in MlmeAux.RoamTab...\n"));
662 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, sizeof(pAd->MlmeAux.RoamTab));
663 pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;
665 BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);
666 pAd->MlmeAux.BssIdx = 0;
667 IterateOnBssTab(pAd);
671 ==========================================================================
674 IRQL = DISPATCH_LEVEL
676 ==========================================================================
678 VOID CntlWaitDisassocProc(
679 IN PRTMP_ADAPTER pAd,
680 IN MLME_QUEUE_ELEM *Elem)
682 MLME_START_REQ_STRUCT StartReq;
684 if (Elem->MsgType == MT2_DISASSOC_CONF)
686 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n"));
688 if (pAd->CommonCfg.bWirelessEvent)
690 RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
693 LinkDown(pAd, FALSE);
695 // case 1. no matching BSS, and user wants ADHOC, so we just start a new one
696 if ((pAd->MlmeAux.SsidBssTab.BssNr==0) && (pAd->StaCfg.BssType == BSS_ADHOC))
698 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
699 StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
700 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
701 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
703 // case 2. try each matched BSS
706 pAd->MlmeAux.BssIdx = 0;
708 IterateOnBssTab(pAd);
714 ==========================================================================
717 IRQL = DISPATCH_LEVEL
719 ==========================================================================
721 VOID CntlWaitJoinProc(
722 IN PRTMP_ADAPTER pAd,
723 IN MLME_QUEUE_ELEM *Elem)
726 MLME_AUTH_REQ_STRUCT AuthReq;
728 if (Elem->MsgType == MT2_JOIN_CONF)
730 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
731 if (Reason == MLME_SUCCESS)
733 // 1. joined an IBSS, we are pretty much done here
734 if (pAd->MlmeAux.BssType == BSS_ADHOC)
737 // 5G bands rules of Japan:
738 // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
740 if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
741 RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
744 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
745 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
749 LinkUp(pAd, BSS_ADHOC);
750 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
751 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
752 pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
753 pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
755 pAd->IndicateMediaState = NdisMediaStateConnected;
756 pAd->ExtraInfo = GENERAL_LINK_UP;
758 // 2. joined a new INFRA network, start from authentication
762 // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
763 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
764 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
766 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
770 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
773 MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
774 sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
776 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH;
781 // 3. failed, try next BSS
782 pAd->MlmeAux.BssIdx++;
783 IterateOnBssTab(pAd);
790 ==========================================================================
793 IRQL = DISPATCH_LEVEL
795 ==========================================================================
797 VOID CntlWaitStartProc(
798 IN PRTMP_ADAPTER pAd,
799 IN MLME_QUEUE_ELEM *Elem)
803 if (Elem->MsgType == MT2_START_CONF)
805 NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
806 if (Result == MLME_SUCCESS)
809 // 5G bands rules of Japan:
810 // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
812 if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
813 RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
816 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
817 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
821 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
825 NdisMoveMemory(&pAd->MlmeAux.AddHtInfo, &pAd->CommonCfg.AddHTInfo, sizeof(ADD_HT_INFO_IE));
826 RTMPCheckHt(pAd, BSSID_WCID, &pAd->CommonCfg.HtCapability, &pAd->CommonCfg.AddHTInfo);
827 pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;
828 NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], 16);
829 NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], &pAd->CommonCfg.HtCapability.MCSSet[0], 16);
830 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
832 if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
833 (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))
835 pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel + 2;
837 else if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
838 (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))
840 pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel - 2;
845 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
847 LinkUp(pAd, BSS_ADHOC);
848 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
849 // Before send beacon, driver need do radar detection
850 if ((pAd->CommonCfg.Channel > 14 )
851 && (pAd->CommonCfg.bIEEE80211H == 1)
852 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
854 pAd->CommonCfg.RadarDetect.RDMode = RD_SILENCE_MODE;
855 pAd->CommonCfg.RadarDetect.RDCount = 0;
858 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
859 pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
860 pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
864 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Start IBSS fail. BUG!!!!!\n"));
865 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
871 ==========================================================================
874 IRQL = DISPATCH_LEVEL
876 ==========================================================================
878 VOID CntlWaitAuthProc(
879 IN PRTMP_ADAPTER pAd,
880 IN MLME_QUEUE_ELEM *Elem)
883 MLME_ASSOC_REQ_STRUCT AssocReq;
884 MLME_AUTH_REQ_STRUCT AuthReq;
886 if (Elem->MsgType == MT2_AUTH_CONF)
888 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
889 if (Reason == MLME_SUCCESS)
891 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
892 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
893 ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
896 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
897 sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
899 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
904 // This fail may because of the AP already keep us in its MAC table without
905 // ageing-out. The previous authentication attempt must have let it remove us.
906 // so try Authentication again may help. For D-Link DWL-900AP+ compatibility.
907 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try again...\n"));
910 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
911 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
913 // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
914 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
918 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
921 MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
922 sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
924 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
930 ==========================================================================
933 IRQL = DISPATCH_LEVEL
935 ==========================================================================
937 VOID CntlWaitAuthProc2(
938 IN PRTMP_ADAPTER pAd,
939 IN MLME_QUEUE_ELEM *Elem)
942 MLME_ASSOC_REQ_STRUCT AssocReq;
943 MLME_AUTH_REQ_STRUCT AuthReq;
945 if (Elem->MsgType == MT2_AUTH_CONF)
947 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
948 if (Reason == MLME_SUCCESS)
950 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
951 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
952 ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
953 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
954 sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
956 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
960 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) &&
961 (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared))
963 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try OPEN system...\n"));
964 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
965 MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
966 sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
968 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
972 // not success, try next BSS
973 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, give up; try next BSS\n"));
974 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; //???????
975 pAd->MlmeAux.BssIdx++;
976 IterateOnBssTab(pAd);
983 ==========================================================================
986 IRQL = DISPATCH_LEVEL
988 ==========================================================================
990 VOID CntlWaitAssocProc(
991 IN PRTMP_ADAPTER pAd,
992 IN MLME_QUEUE_ELEM *Elem)
996 if (Elem->MsgType == MT2_ASSOC_CONF)
998 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
999 if (Reason == MLME_SUCCESS)
1001 LinkUp(pAd, BSS_INFRA);
1002 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1003 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association successful on BSS #%ld\n",pAd->MlmeAux.BssIdx));
1005 if (pAd->CommonCfg.bWirelessEvent)
1007 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
1012 // not success, try next BSS
1013 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association fails on BSS #%ld\n",pAd->MlmeAux.BssIdx));
1014 pAd->MlmeAux.BssIdx++;
1015 IterateOnBssTab(pAd);
1021 ==========================================================================
1024 IRQL = DISPATCH_LEVEL
1026 ==========================================================================
1028 VOID CntlWaitReassocProc(
1029 IN PRTMP_ADAPTER pAd,
1030 IN MLME_QUEUE_ELEM *Elem)
1034 if (Elem->MsgType == MT2_REASSOC_CONF)
1036 NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
1037 if (Result == MLME_SUCCESS)
1040 // NDIS requires a new Link UP indication but no Link Down for RE-ASSOC
1042 LinkUp(pAd, BSS_INFRA);
1044 // send wireless event - for association
1045 if (pAd->CommonCfg.bWirelessEvent)
1046 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
1048 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1049 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition successful on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
1053 // reassoc failed, try to pick next BSS in the BSS Table
1054 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition fails on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
1055 pAd->MlmeAux.RoamIdx++;
1056 IterateOnBssTab2(pAd);
1063 VOID AdhocTurnOnQos(
1064 IN PRTMP_ADAPTER pAd)
1066 #define AC0_DEF_TXOP 0
1067 #define AC1_DEF_TXOP 0
1068 #define AC2_DEF_TXOP 94
1069 #define AC3_DEF_TXOP 47
1071 // Turn on QOs if use HT rate.
1072 if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
1074 pAd->CommonCfg.APEdcaParm.bValid = TRUE;
1075 pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
1076 pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
1077 pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
1078 pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
1080 pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
1081 pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
1082 pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
1083 pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
1085 pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10;
1086 pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6;
1087 pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
1088 pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
1090 pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
1091 pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
1092 pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP;
1093 pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP;
1095 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1100 ==========================================================================
1103 IRQL = DISPATCH_LEVEL
1105 ==========================================================================
1108 IN PRTMP_ADAPTER pAd,
1114 UCHAR Value = 0, idx;
1115 MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;
1118 if (RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND))
1120 RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_HALT);
1121 RTMPusecDelay(6000);
1122 pAd->bPCIclkOff = FALSE;
1126 pEntry = &pAd->MacTab.Content[BSSID_WCID];
1129 // ASSOC - DisassocTimeoutAction
1130 // CNTL - Dis-associate successful
1131 // !!! LINK DOWN !!!
1132 // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
1134 // To prevent DisassocTimeoutAction to call Link down after we link up,
1135 // cancel the DisassocTimer no matter what it start or not.
1137 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
1139 COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
1141 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
1143 // It's quite difficult to tell if a newly added KEY is WEP or CKIP until a new BSS
1144 // is formed (either ASSOC/RE-ASSOC done or IBSS started. LinkUP should be a safe place
1145 // to examine if cipher algorithm switching is required.
1146 //rt2860b. Don't know why need this
1147 SwitchBetweenWepAndCkip(pAd);
1150 // Before power save before link up function, We will force use 1R.
1151 // So after link up, check Rx antenna # again.
1152 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1153 if(pAd->Antenna.field.RxPath == 3)
1157 else if(pAd->Antenna.field.RxPath == 2)
1161 else if(pAd->Antenna.field.RxPath == 1)
1165 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1166 pAd->StaCfg.BBPR3 = Value;
1169 if (BssType == BSS_ADHOC)
1171 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1172 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1175 if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
1176 (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))
1178 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;
1180 else if ((pAd->CommonCfg.Channel > 2) &&
1181 (pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
1182 (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))
1184 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;
1188 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
1189 AdhocTurnOnQos(pAd);
1192 DBGPRINT(RT_DEBUG_TRACE, ("!!!Adhoc LINK UP !!! \n" ));
1196 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);
1197 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1199 DBGPRINT(RT_DEBUG_TRACE, ("!!!Infra LINK UP !!! \n" ));
1203 // reset Tx beamforming bit
1204 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1206 Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF;
1207 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1209 // Change to AP channel
1210 if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
1212 // Must using 40MHz.
1213 pAd->CommonCfg.BBPCurrentBW = BW_40;
1214 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1215 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1217 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1220 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1222 // RX : control channel at lower
1223 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1225 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1227 pAd->StaCfg.BBPR3 = Value;
1230 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1232 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1234 if (pAd->MACVersion == 0x28600100)
1236 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1237 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1238 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
1239 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
1242 DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd->CommonCfg.CentralChannel ));
1244 else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
1246 // Must using 40MHz.
1247 pAd->CommonCfg.BBPCurrentBW = BW_40;
1248 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1249 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1251 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1254 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1256 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1258 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1260 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1262 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1264 pAd->StaCfg.BBPR3 = Value;
1267 if (pAd->MACVersion == 0x28600100)
1269 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1270 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1271 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
1272 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
1275 DBGPRINT(RT_DEBUG_TRACE, ("!!! 40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd->CommonCfg.CentralChannel ));
1279 pAd->CommonCfg.BBPCurrentBW = BW_20;
1280 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
1281 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
1282 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
1284 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1286 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1288 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1290 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1292 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1294 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1296 pAd->StaCfg.BBPR3 = Value;
1299 if (pAd->MACVersion == 0x28600100)
1301 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
1302 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
1303 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
1304 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
1307 DBGPRINT(RT_DEBUG_TRACE, ("!!! 20MHz LINK UP !!! \n" ));
1310 RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
1312 // Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission
1314 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue);
1316 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",
1317 BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid, pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
1319 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (Density =%d, )\n", pAd->MacTab.Content[BSSID_WCID].MpduDensity));
1321 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
1323 AsicSetSlotTime(pAd, TRUE);
1324 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1326 // Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit
1327 AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE, FALSE);
1329 if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE))
1331 // Update HT protectionfor based on AP's operating mode.
1332 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)
1334 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);
1337 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
1340 NdisZeroMemory(&pAd->DrsCounters, sizeof(COUNTER_DRS));
1342 NdisGetSystemUpTime(&Now);
1343 pAd->StaCfg.LastBeaconRxTime = Now; // last RX timestamp
1345 if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) &&
1346 CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo))
1348 MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
1351 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1353 if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE)
1356 pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
1358 if (BssType == BSS_ADHOC)
1360 MakeIbssBeacon(pAd);
1361 if ((pAd->CommonCfg.Channel > 14)
1362 && (pAd->CommonCfg.bIEEE80211H == 1)
1363 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
1369 AsicEnableIbssSync(pAd);
1372 // In ad hoc mode, use MAC table from index 1.
1373 // p.s ASIC use all 0xff as termination of WCID table search.To prevent it's 0xff-ff-ff-ff-ff-ff, Write 0 here.
1374 RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00);
1375 RTMP_IO_WRITE32(pAd, 0x1808, 0x00);
1377 // If WEP is enabled, add key material and cipherAlg into Asic
1378 // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
1380 if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
1385 for (idx=0; idx < SHARE_KEY_NUM; idx++)
1387 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
1388 Key = pAd->SharedKey[BSS0][idx].Key;
1390 if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
1392 // Set key material and cipherAlg to Asic
1393 AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
1395 if (idx == pAd->StaCfg.DefaultKeyId)
1397 // Update WCID attribute table and IVEIV table for this group key table
1398 RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
1405 // If WPANone is enabled, add key material and cipherAlg into Asic
1406 // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
1407 else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1409 pAd->StaCfg.DefaultKeyId = 0; // always be zero
1411 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
1412 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
1413 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
1415 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
1417 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
1418 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
1421 // Decide its ChiperAlg
1422 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
1423 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
1424 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
1425 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1428 DBGPRINT(RT_DEBUG_TRACE, ("Unknow Cipher (=%d), set Cipher to AES\n", pAd->StaCfg.PairCipher));
1429 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1432 // Set key material and cipherAlg to Asic
1433 AsicAddSharedKeyEntry(pAd,
1436 pAd->SharedKey[BSS0][0].CipherAlg,
1437 pAd->SharedKey[BSS0][0].Key,
1438 pAd->SharedKey[BSS0][0].TxMic,
1439 pAd->SharedKey[BSS0][0].RxMic);
1441 // Update WCID attribute table and IVEIV table for this group key table
1442 RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pAd->SharedKey[BSS0][0].CipherAlg, NULL);
1449 // Check the new SSID with last SSID
1450 while (Cancelled == TRUE)
1452 if (pAd->CommonCfg.LastSsidLen == pAd->CommonCfg.SsidLen)
1454 if (RTMPCompareMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen) == 0)
1456 // Link to the old one no linkdown is required.
1460 // Send link down event before set to link up
1461 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1462 RTMP_IndicateMediaState(pAd);
1463 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1464 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));
1469 // On WPA mode, Remove All Keys if not connect to the last BSSID
1470 // Key will be set after 4-way handshake.
1472 if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
1476 // Remove all WPA keys
1477 RTMPWPARemoveAllKeys(pAd);
1478 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1479 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
1481 // Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP
1482 // If IV related values are too large in GroupMsg2, AP would ignore this message.
1484 IV |= (pAd->StaCfg.DefaultKeyId << 30);
1485 AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);
1488 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1492 // the decision of using "short slot time" or not may change dynamically due to
1493 // new STA association to the AP. so we have to decide that upon parsing BEACON, not here
1496 // the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically
1497 // due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here
1500 ComposeNullFrame(pAd);
1502 AsicEnableBssSync(pAd);
1504 // Add BSSID to WCID search table
1505 AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);
1507 NdisAcquireSpinLock(&pAd->MacTabLock);
1508 // add this BSSID entry into HASH table
1512 //pEntry = &pAd->MacTab.Content[BSSID_WCID];
1513 HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid);
1514 if (pAd->MacTab.Hash[HashIdx] == NULL)
1516 pAd->MacTab.Hash[HashIdx] = pEntry;
1520 pCurrEntry = pAd->MacTab.Hash[HashIdx];
1521 while (pCurrEntry->pNext != NULL)
1522 pCurrEntry = pCurrEntry->pNext;
1523 pCurrEntry->pNext = pEntry;
1526 NdisReleaseSpinLock(&pAd->MacTabLock);
1529 // If WEP is enabled, add paiewise and shared key
1530 if (((pAd->StaCfg.WpaSupplicantUP)&&
1531 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)&&
1532 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
1533 ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)&&
1534 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)))
1539 for (idx=0; idx < SHARE_KEY_NUM; idx++)
1541 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
1542 Key = pAd->SharedKey[BSS0][idx].Key;
1544 if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
1546 // Set key material and cipherAlg to Asic
1547 AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
1549 if (idx == pAd->StaCfg.DefaultKeyId)
1551 // Assign group key info
1552 RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
1554 // Assign pairwise key info
1555 RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, pEntry);
1561 // only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode
1562 // should wait until at least 2 active nodes in this BSSID.
1563 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1566 if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
1568 pAd->IndicateMediaState = NdisMediaStateConnected;
1569 pAd->ExtraInfo = GENERAL_LINK_UP;
1571 RTMP_IndicateMediaState(pAd);
1576 RTMP_IndicateMediaState(pAd);
1579 // Add BSSID in my MAC Table.
1580 NdisAcquireSpinLock(&pAd->MacTabLock);
1581 RTMPMoveMemory(pAd->MacTab.Content[BSSID_WCID].Addr, pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
1582 pAd->MacTab.Content[BSSID_WCID].Aid = BSSID_WCID;
1583 pAd->MacTab.Content[BSSID_WCID].pAd = pAd;
1584 pAd->MacTab.Content[BSSID_WCID].ValidAsCLI = TRUE; //Although this is bssid..still set ValidAsCl
1585 pAd->MacTab.Size = 1; // infra mode always set MACtab size =1.
1586 pAd->MacTab.Content[BSSID_WCID].Sst = SST_ASSOC;
1587 pAd->MacTab.Content[BSSID_WCID].AuthState = SST_ASSOC;
1589 pAd->MacTab.Content[BSSID_WCID].AuthMode = pAd->StaCfg.AuthMode;
1591 pAd->MacTab.Content[BSSID_WCID].WepStatus = pAd->StaCfg.WepStatus;
1592 NdisReleaseSpinLock(&pAd->MacTabLock);
1594 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! ClientStatusFlags=%lx)\n",
1595 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
1597 MlmeUpdateTxRates(pAd, TRUE, BSS0);
1598 MlmeUpdateHtTxRates(pAd, BSS0);
1599 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n", pAd->StaActive.SupportedPhyInfo.bHtEnable));
1601 if (pAd->CommonCfg.bAggregationCapable)
1603 if ((pAd->CommonCfg.bPiggyBackCapable) && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)
1606 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
1607 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1608 RTMPSetPiggyBack(pAd, TRUE);
1609 DBGPRINT(RT_DEBUG_TRACE, ("Turn on Piggy-Back\n"));
1611 else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
1613 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1617 if (pAd->MlmeAux.APRalinkIe != 0x0)
1619 if (CLIENT_STATUS_TEST_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RDG_CAPABLE))
1624 OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
1625 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
1629 OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
1630 CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
1634 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_CONNECT Event B!.BACapability = %x. ClientStatusFlags = %lx\n", pAd->CommonCfg.BACapability.word, pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
1637 RTMPSetLED(pAd, LED_LINK_UP);
1639 pAd->Mlme.PeriodicRound = 0;
1640 pAd->Mlme.OneSecPeriodicRound = 0;
1641 pAd->bConfigChanged = FALSE; // Reset config flag
1642 pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
1644 // Set asic auto fall back
1647 UCHAR TableSize = 0;
1649 MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID], &pTable, &TableSize, &pAd->CommonCfg.TxRateIndex);
1650 AsicUpdateAutoFallBackTable(pAd, pTable);
1653 NdisAcquireSpinLock(&pAd->MacTabLock);
1654 pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1655 pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1656 if (pAd->StaCfg.bAutoTxRateSwitch == FALSE)
1658 pEntry->bAutoTxRateSwitch = FALSE;
1660 if (pEntry->HTPhyMode.field.MCS == 32)
1661 pEntry->HTPhyMode.field.ShortGI = GI_800;
1663 if ((pEntry->HTPhyMode.field.MCS > MCS_7) || (pEntry->HTPhyMode.field.MCS == 32))
1664 pEntry->HTPhyMode.field.STBC = STBC_NONE;
1666 // If the legacy mode is set, overwrite the transmit setting of this entry.
1667 if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM)
1668 RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
1671 pEntry->bAutoTxRateSwitch = TRUE;
1672 NdisReleaseSpinLock(&pAd->MacTabLock);
1674 // Let Link Status Page display first initial rate.
1675 pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word);
1676 // Select DAC according to HT or Legacy
1677 if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00)
1679 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1681 if (pAd->Antenna.field.TxPath == 2)
1685 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
1689 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1691 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
1694 if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
1697 else if (pEntry->MaxRAmpduFactor == 0)
1699 // If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0.
1700 // Because our Init value is 1 at MACRegTable.
1701 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff);
1704 // Patch for Marvel AP to gain high throughput
1705 // Need to set as following,
1706 // 1. Set txop in register-EDCA_AC0_CFG as 0x60
1707 // 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero
1708 // 3. PBF_MAX_PCNT as 0x1F3FBF9F
1709 // 4. kick per two packets when dequeue
1711 // Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable
1713 // if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is.
1715 if (!((pAd->CommonCfg.RxStream == 1)&&(pAd->CommonCfg.TxStream == 1)) &&
1716 (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))
1717 || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE))))
1720 if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)))
1721 || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)))
1724 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1726 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1728 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1729 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n"));
1732 if (pAd->CommonCfg.bEnableTxBurst)
1734 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1737 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1738 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE;
1740 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F);
1741 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n"));
1745 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1747 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1749 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1750 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n"));
1753 // Re-check to turn on TX burst or not.
1754 if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE) && ((STA_WEP_ON(pAd))||(STA_TKIP_ON(pAd))))
1756 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE;
1757 if (pAd->CommonCfg.bEnableTxBurst)
1759 UINT32 MACValue = 0;
1760 // Force disable TXOP value in this case. The same action in MLMEUpdateProtect too.
1761 // I didn't change PBF_MAX_PCNT setting.
1762 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue);
1763 MACValue &= 0xFFFFFF00;
1764 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue);
1765 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
1770 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE;
1773 pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE;
1774 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
1775 DBGPRINT(RT_DEBUG_TRACE, ("!!!pAd->bNextDisableRxBA= %d \n", pAd->CommonCfg.IOTestParm.bNextDisableRxBA));
1776 // BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap
1777 // Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver.
1778 // Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same.
1780 if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled)
1782 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1783 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
1786 NdisAcquireSpinLock(&pAd->MacTabLock);
1787 pEntry->PortSecured = pAd->StaCfg.PortSecured;
1788 NdisReleaseSpinLock(&pAd->MacTabLock);
1791 // Patch Atheros AP TX will breakdown issue.
1792 // AP Model: DLink DWL-8200AP
1794 if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && STA_TKIP_ON(pAd))
1796 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01);
1800 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00);
1803 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
1805 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
1810 ==========================================================================
1812 Routine Description:
1813 Disconnect current BSSID
1816 pAd - Pointer to our adapter
1817 IsReqFromAP - Request from AP
1822 IRQL = DISPATCH_LEVEL
1825 We need more information to know it's this requst from AP.
1826 If yes! we need to do extra handling, for example, remove the WPA key.
1827 Otherwise on 4-way handshaking will faied, since the WPA key didn't be
1828 remove while auto reconnect.
1829 Disconnect request from AP, it means we will start afresh 4-way handshaking
1832 ==========================================================================
1835 IN PRTMP_ADAPTER pAd,
1836 IN BOOLEAN IsReqFromAP)
1838 UCHAR i, ByteValue = 0;
1843 // Do nothing if monitor mode is on
1844 if (MONITOR_ON(pAd))
1848 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
1849 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1851 // Not allow go to sleep within linkdown function.
1852 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1855 if (pAd->CommonCfg.bWirelessEvent)
1857 RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
1860 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN !!!\n"));
1861 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1864 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE))
1867 pAd->Mlme.bPsPollTimerRunning = FALSE;
1868 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1871 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) ||
1872 RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND) ||
1873 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))
1875 AsicForceWakeup(pAd, RTMP_HALT);
1876 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
1879 pAd->bPCIclkOff = FALSE;
1881 if (ADHOC_ON(pAd)) // Adhoc mode link down
1883 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 1!!!\n"));
1885 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1886 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1887 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1888 RTMP_IndicateMediaState(pAd);
1889 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1890 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
1891 DBGPRINT(RT_DEBUG_TRACE, ("!!! MacTab.Size=%d !!!\n", pAd->MacTab.Size));
1893 else // Infra structure mode
1895 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 2!!!\n"));
1897 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1898 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1900 // Saved last SSID for linkup comparison
1901 pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen;
1902 NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen);
1903 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
1904 if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE)
1906 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1907 RTMP_IndicateMediaState(pAd);
1908 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1909 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));
1910 pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
1915 // If disassociation request is from NDIS, then we don't need to delete BSSID from entry.
1916 // Otherwise lost beacon or receive De-Authentication from AP,
1917 // then we should delete BSSID from BssTable.
1918 // If we don't delete from entry, roaming will fail.
1920 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
1923 // restore back to -
1924 // 1. long slot (20 us) or short slot (9 us) time
1925 // 2. turn on/off RTS/CTS and/or CTS-to-self protection
1926 // 3. short preamble
1927 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
1929 if (pAd->StaCfg.CCXAdjacentAPReportFlag == TRUE)
1932 // Record current AP's information.
1933 // for later used reporting Adjacent AP report.
1935 pAd->StaCfg.CCXAdjacentAPChannel = pAd->CommonCfg.Channel;
1936 pAd->StaCfg.CCXAdjacentAPSsidLen = pAd->CommonCfg.SsidLen;
1937 NdisMoveMemory(pAd->StaCfg.CCXAdjacentAPSsid, pAd->CommonCfg.Ssid, pAd->StaCfg.CCXAdjacentAPSsidLen);
1938 COPY_MAC_ADDR(pAd->StaCfg.CCXAdjacentAPBssid, pAd->CommonCfg.Bssid);
1942 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
1944 if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
1945 MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid, pAd->MacTab.Content[i].Addr);
1948 pAd->StaCfg.CCXQosECWMin = 4;
1949 pAd->StaCfg.CCXQosECWMax = 10;
1951 AsicSetSlotTime(pAd, TRUE); //FALSE);
1952 AsicSetEdcaParm(pAd, NULL);
1955 RTMPSetLED(pAd, LED_LINK_DOWN);
1956 pAd->LedIndicatorStregth = 0xF0;
1957 RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it.
1959 AsicDisableSync(pAd);
1961 pAd->Mlme.PeriodicRound = 0;
1962 pAd->Mlme.OneSecPeriodicRound = 0;
1964 if (pAd->StaCfg.BssType == BSS_INFRA)
1966 // Remove StaCfg Information after link down
1967 NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
1968 NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID);
1969 pAd->CommonCfg.SsidLen = 0;
1972 NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(HT_CAPABILITY_IE));
1973 NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(ADD_HT_INFO_IE));
1974 pAd->MlmeAux.HtCapabilityLen = 0;
1975 pAd->MlmeAux.NewExtChannelOffset = 0xff;
1977 // Reset WPA-PSK state. Only reset when supplicant enabled
1978 if (pAd->StaCfg.WpaState != SS_NOTUSE)
1980 pAd->StaCfg.WpaState = SS_START;
1981 // Clear Replay counter
1982 NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
1987 // if link down come from AP, we need to remove all WPA keys on WPA mode.
1988 // otherwise will cause 4-way handshaking failed, since the WPA key not empty.
1990 if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
1992 // Remove all WPA keys
1993 RTMPWPARemoveAllKeys(pAd);
1996 // 802.1x port control
1998 // Prevent clear PortSecured here with static WEP
1999 // NetworkManger set security policy first then set SSID to connect AP.
2000 if (pAd->StaCfg.WpaSupplicantUP &&
2001 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
2002 (pAd->StaCfg.IEEE8021X == FALSE))
2004 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2008 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2009 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
2012 NdisAcquireSpinLock(&pAd->MacTabLock);
2013 pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured;
2014 NdisReleaseSpinLock(&pAd->MacTabLock);
2016 pAd->StaCfg.MicErrCnt = 0;
2018 // Turn off Ckip control flag
2019 pAd->StaCfg.bCkipOn = FALSE;
2020 pAd->StaCfg.CCXEnable = FALSE;
2022 pAd->IndicateMediaState = NdisMediaStateDisconnected;
2023 // Update extra information to link is up
2024 pAd->ExtraInfo = GENERAL_LINK_DOWN;
2027 pAd->StaCfg.AdhocBOnlyJoined = FALSE;
2028 pAd->StaCfg.AdhocBGJoined = FALSE;
2029 pAd->StaCfg.Adhoc20NJoined = FALSE;
2031 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
2033 // Reset the Current AP's IP address
2034 NdisZeroMemory(pAd->StaCfg.AironetIPAddress, 4);
2036 pAd->bUsbTxBulkAggre = FALSE;
2039 // Clean association information
2040 NdisZeroMemory(&pAd->StaCfg.AssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
2041 pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
2042 pAd->StaCfg.ReqVarIELen = 0;
2043 pAd->StaCfg.ResVarIELen = 0;
2046 // Reset RSSI value after link down
2048 pAd->StaCfg.RssiSample.AvgRssi0 = 0;
2049 pAd->StaCfg.RssiSample.AvgRssi0X8 = 0;
2050 pAd->StaCfg.RssiSample.AvgRssi1 = 0;
2051 pAd->StaCfg.RssiSample.AvgRssi1X8 = 0;
2052 pAd->StaCfg.RssiSample.AvgRssi2 = 0;
2053 pAd->StaCfg.RssiSample.AvgRssi2X8 = 0;
2056 pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate;
2057 pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate;
2060 // After Link down, reset piggy-back setting in ASIC. Disable RDG.
2062 if (pAd->CommonCfg.BBPCurrentBW == BW_40)
2064 pAd->CommonCfg.BBPCurrentBW = BW_20;
2065 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue);
2066 ByteValue &= (~0x18);
2067 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue);
2071 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue);
2072 ByteValue &= (~0x18);
2073 if (pAd->Antenna.field.TxPath == 2)
2077 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue);
2079 RTMPSetPiggyBack(pAd,FALSE);
2080 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
2082 pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word;
2084 // Restore all settings in the following.
2085 AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT|CCKSETPROTECT|OFDMSETPROTECT), TRUE, FALSE);
2086 AsicDisableRDG(pAd);
2087 pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;
2088 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
2090 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);
2091 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
2094 // Allow go to sleep after linkdown steps.
2095 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
2099 union iwreq_data wrqu;
2100 memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
2101 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
2108 // disable MMPS BBP control register
2109 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &ByteValue);
2110 ByteValue &= ~(0x04); //bit 2
2111 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, ByteValue);
2113 // disable MMPS MAC control register
2114 RTMP_IO_READ32(pAd, 0x1210, &macdata);
2115 macdata &= ~(0x09); //bit 0, 3
2116 RTMP_IO_WRITE32(pAd, 0x1210, macdata);
2122 ==========================================================================
2125 IRQL = DISPATCH_LEVEL
2127 ==========================================================================
2129 VOID IterateOnBssTab(
2130 IN PRTMP_ADAPTER pAd)
2132 MLME_START_REQ_STRUCT StartReq;
2133 MLME_JOIN_REQ_STRUCT JoinReq;
2136 // Change the wepstatus to original wepstatus
2137 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
2138 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
2139 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
2141 BssIdx = pAd->MlmeAux.BssIdx;
2142 if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr)
2144 // Check cipher suite, AP must have more secured cipher than station setting
2145 // Set the Pairwise and Group cipher to match the intended AP setting
2146 // We can only connect to AP with less secured cipher setting
2147 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
2149 pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.GroupCipher;
2151 if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher)
2152 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher;
2153 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
2154 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux;
2155 else // There is no PairCipher Aux, downgrade our capability to TKIP
2156 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2158 else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
2160 pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.GroupCipher;
2162 if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher)
2163 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher;
2164 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
2165 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux;
2166 else // There is no PairCipher Aux, downgrade our capability to TKIP
2167 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2170 pAd->StaCfg.RsnCapability = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.RsnCapability;
2173 // Set Mix cipher flag
2174 pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
2175 if (pAd->StaCfg.bMixCipher == TRUE)
2177 // If mix cipher, re-build RSNIE
2178 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
2181 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.SsidBssTab.BssNr));
2182 JoinParmFill(pAd, &JoinReq, BssIdx);
2183 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT),
2185 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
2187 else if (pAd->StaCfg.BssType == BSS_ADHOC)
2189 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
2190 StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
2191 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
2192 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
2196 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All roaming failed, stay @ ch #%d\n", pAd->CommonCfg.Channel));
2197 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2198 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2199 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2203 // for re-association only
2204 // IRQL = DISPATCH_LEVEL
2205 VOID IterateOnBssTab2(
2206 IN PRTMP_ADAPTER pAd)
2208 MLME_REASSOC_REQ_STRUCT ReassocReq;
2212 BssIdx = pAd->MlmeAux.RoamIdx;
2213 pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];
2215 if (BssIdx < pAd->MlmeAux.RoamTab.BssNr)
2217 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.RoamTab.BssNr));
2219 AsicSwitchChannel(pAd, pBss->Channel, FALSE);
2220 AsicLockChannel(pAd, pBss->Channel);
2222 // reassociate message has the same structure as associate message
2223 AssocParmFill(pAd, &ReassocReq, pBss->Bssid, pBss->CapabilityInfo,
2224 ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
2225 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
2226 sizeof(MLME_REASSOC_REQ_STRUCT), &ReassocReq);
2228 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
2232 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All fast roaming failed, back to ch #%d\n",pAd->CommonCfg.Channel));
2233 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2234 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2235 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2240 ==========================================================================
2243 IRQL = DISPATCH_LEVEL
2245 ==========================================================================
2248 IN PRTMP_ADAPTER pAd,
2249 IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,
2252 JoinReq->BssIdx = BssIdx;
2256 ==========================================================================
2259 IRQL = DISPATCH_LEVEL
2261 ==========================================================================
2264 IN PRTMP_ADAPTER pAd,
2265 IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,
2271 NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID);
2272 ScanReq->SsidLen = SsidLen;
2273 NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);
2274 ScanReq->BssType = BssType;
2275 ScanReq->ScanType = ScanType;
2279 ==========================================================================
2282 IRQL = DISPATCH_LEVEL
2284 ==========================================================================
2287 IN PRTMP_ADAPTER pAd,
2288 IN OUT MLME_START_REQ_STRUCT *StartReq,
2292 ASSERT(SsidLen <= MAX_LEN_OF_SSID);
2293 NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);
2294 StartReq->SsidLen = SsidLen;
2298 ==========================================================================
2301 IRQL = DISPATCH_LEVEL
2303 ==========================================================================
2306 IN PRTMP_ADAPTER pAd,
2307 IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,
2311 COPY_MAC_ADDR(AuthReq->Addr, pAddr);
2313 AuthReq->Timeout = AUTH_TIMEOUT;
2317 ==========================================================================
2320 IRQL = DISPATCH_LEVEL
2322 ==========================================================================
2328 VOID MlmeCntlConfirm(
2329 IN PRTMP_ADAPTER pAd,
2333 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(USHORT), &Msg);
2338 IN PRTMP_ADAPTER pAd)
2341 PTXINFO_STRUC pTxInfo;
2344 DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n"));
2346 NdisZeroMemory(&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
2349 pAd->PsPollFrame.FC.PwrMgmt = 0;
2351 pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
2352 pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
2353 pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
2354 COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
2355 COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
2358 RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0], 100);
2359 pTxInfo = (PTXINFO_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0];
2360 RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(PSPOLL_FRAME)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2361 pTxWI = (PTXWI_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
2362 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(PSPOLL_FRAME)),
2363 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2364 RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
2365 // Append 4 extra zero bytes.
2366 pAd->PsPollContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(PSPOLL_FRAME) + 4;
2370 // IRQL = DISPATCH_LEVEL
2371 VOID ComposeNullFrame(
2372 IN PRTMP_ADAPTER pAd)
2375 PTXINFO_STRUC pTxInfo;
2379 NdisZeroMemory(&pAd->NullFrame, sizeof(HEADER_802_11));
2380 pAd->NullFrame.FC.Type = BTYPE_DATA;
2381 pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
2382 pAd->NullFrame.FC.ToDs = 1;
2383 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
2384 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
2385 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
2387 RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], 100);
2388 pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
2389 RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(HEADER_802_11)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2390 pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
2391 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(HEADER_802_11)),
2392 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2393 RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
2394 pAd->NullContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
2402 ==========================================================================
2404 Pre-build a BEACON frame in the shared memory
2406 IRQL = PASSIVE_LEVEL
2407 IRQL = DISPATCH_LEVEL
2409 ==========================================================================
2411 ULONG MakeIbssBeacon(
2412 IN PRTMP_ADAPTER pAd)
2414 UCHAR DsLen = 1, IbssLen = 2;
2415 UCHAR LocalErpIe[3] = {IE_ERP, 1, 0x04};
2416 HEADER_802_11 BcnHdr;
2417 USHORT CapabilityInfo;
2418 LARGE_INTEGER FakeTimestamp;
2420 PTXWI_STRUC pTxWI = &pAd->BeaconTxWI;
2421 CHAR *pBeaconFrame = pAd->BeaconBuf;
2423 UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
2424 UCHAR SupRateLen = 0;
2425 UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
2426 UCHAR ExtRateLen = 0;
2427 UCHAR RSNIe = IE_WPA;
2429 if ((pAd->CommonCfg.PhyMode == PHY_11B) && (pAd->CommonCfg.Channel <= 14))
2431 SupRate[0] = 0x82; // 1 mbps
2432 SupRate[1] = 0x84; // 2 mbps
2433 SupRate[2] = 0x8b; // 5.5 mbps
2434 SupRate[3] = 0x96; // 11 mbps
2438 else if (pAd->CommonCfg.Channel > 14)
2440 SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2441 SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2442 SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2443 SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2444 SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2445 SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2446 SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2447 SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2452 // Also Update MlmeRate & RtsRate for G only & A only
2454 pAd->CommonCfg.MlmeRate = RATE_6;
2455 pAd->CommonCfg.RtsRate = RATE_6;
2456 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
2457 pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2458 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM;
2459 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2463 SupRate[0] = 0x82; // 1 mbps
2464 SupRate[1] = 0x84; // 2 mbps
2465 SupRate[2] = 0x8b; // 5.5 mbps
2466 SupRate[3] = 0x96; // 11 mbps
2469 ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps,
2470 ExtRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2471 ExtRate[2] = 0x18; // 12 mbps, in units of 0.5 Mbps,
2472 ExtRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2473 ExtRate[4] = 0x30; // 24 mbps, in units of 0.5 Mbps,
2474 ExtRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2475 ExtRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2476 ExtRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2480 pAd->StaActive.SupRateLen = SupRateLen;
2481 NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen);
2482 pAd->StaActive.ExtRateLen = ExtRateLen;
2483 NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen);
2485 // compose IBSS beacon frame
2486 MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR, pAd->CommonCfg.Bssid);
2487 Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
2488 (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2489 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
2490 CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);
2492 MakeOutgoingFrame(pBeaconFrame, &FrameLen,
2493 sizeof(HEADER_802_11), &BcnHdr,
2494 TIMESTAMP_LEN, &FakeTimestamp,
2495 2, &pAd->CommonCfg.BeaconPeriod,
2498 1, &pAd->CommonCfg.SsidLen,
2499 pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
2502 SupRateLen, SupRate,
2505 1, &pAd->CommonCfg.Channel,
2508 2, &pAd->StaActive.AtimWin,
2511 // add ERP_IE and EXT_RAE IE of in 802.11g
2516 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2520 ExtRateLen, ExtRate,
2525 // If adhoc secruity is set for WPA-None, append the cipher suite IE
2526 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
2529 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);
2531 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2533 1, &pAd->StaCfg.RSNIE_Len,
2534 pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
2539 if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
2542 UCHAR HtLen, HtLen1;
2544 // add HT Capability IE
2545 HtLen = sizeof(pAd->CommonCfg.HtCapability);
2546 HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);
2548 MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,
2551 HtLen, &pAd->CommonCfg.HtCapability,
2554 HtLen1, &pAd->CommonCfg.AddHTInfo,
2560 //beacon use reserved WCID 0xff
2561 if (pAd->CommonCfg.Channel > 14)
2563 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
2564 PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);
2568 // Set to use 1Mbps for Adhoc beacon.
2569 HTTRANSMIT_SETTING Transmit;
2571 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
2572 PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &Transmit);
2575 DBGPRINT(RT_DEBUG_TRACE, ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
2576 FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel, pAd->CommonCfg.PhyMode));