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)
126 CntlIdleProc(pAd, Elem);
128 case CNTL_WAIT_DISASSOC:
129 CntlWaitDisassocProc(pAd, Elem);
132 CntlWaitJoinProc(pAd, Elem);
135 // CNTL_WAIT_REASSOC is the only state in CNTL machine that does
136 // not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)".
137 // Therefore not protected by NDIS's "only one outstanding OID request"
138 // rule. Which means NDIS may SET OID in the middle of ROAMing attempts.
139 // Current approach is to block new SET request at RTMPSetInformation()
140 // when CntlMachine.CurrState is not CNTL_IDLE
141 case CNTL_WAIT_REASSOC:
142 CntlWaitReassocProc(pAd, Elem);
145 case CNTL_WAIT_START:
146 CntlWaitStartProc(pAd, Elem);
149 CntlWaitAuthProc(pAd, Elem);
151 case CNTL_WAIT_AUTH2:
152 CntlWaitAuthProc2(pAd, Elem);
154 case CNTL_WAIT_ASSOC:
155 CntlWaitAssocProc(pAd, Elem);
158 case CNTL_WAIT_OID_LIST_SCAN:
159 if(Elem->MsgType == MT2_SCAN_CONF)
161 // Resume TxRing after SCANING complete. We hope the out-of-service time
162 // won't be too long to let upper layer time-out the waiting frames
163 RTMPResumeMsduTransmission(pAd);
164 if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
166 // Cisco scan request is finished, prepare beacon report
167 MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
169 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
172 // Set LED status to previous status.
174 if (pAd->bLedOnScanning)
176 pAd->bLedOnScanning = FALSE;
177 RTMPSetLED(pAd, pAd->LedStatus);
180 // AP sent a 2040Coexistence mgmt frame, then station perform a scan, and then send back the respone.
181 if (pAd->CommonCfg.BSSCoexist2040.field.InfoReq == 1)
183 Update2040CoexistFrameAndNotify(pAd, BSSID_WCID, TRUE);
185 #endif // DOT11N_DRAFT3 //
189 case CNTL_WAIT_OID_DISASSOC:
190 if (Elem->MsgType == MT2_DISASSOC_CONF)
192 LinkDown(pAd, FALSE);
193 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
198 // This state is for that we want to connect to an AP but
199 // it didn't find on BSS List table. So we need to scan the air first,
200 // after that we can try to connect to the desired AP if available.
202 case CNTL_WAIT_SCAN_FOR_CONNECT:
203 if(Elem->MsgType == MT2_SCAN_CONF)
205 // Resume TxRing after SCANING complete. We hope the out-of-service time
206 // won't be too long to let upper layer time-out the waiting frames
207 RTMPResumeMsduTransmission(pAd);
209 if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED)
211 // Cisco scan request is finished, prepare beacon report
212 MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, MT2_AIRONET_SCAN_DONE, 0, NULL);
214 #endif // CCX_SUPPORT //
215 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
218 // Check if we can connect to.
220 BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
221 if (pAd->MlmeAux.SsidBssTab.BssNr > 0)
223 MlmeAutoReconnectLastSSID(pAd);
229 DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType));
236 ==========================================================================
239 IRQL = DISPATCH_LEVEL
241 ==========================================================================
244 IN PRTMP_ADAPTER pAd,
245 IN MLME_QUEUE_ELEM *Elem)
247 MLME_DISASSOC_REQ_STRUCT DisassocReq;
249 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
252 switch(Elem->MsgType)
254 case OID_802_11_SSID:
255 CntlOidSsidProc(pAd, Elem);
258 case OID_802_11_BSSID:
259 CntlOidRTBssidProc(pAd,Elem);
262 case OID_802_11_BSSID_LIST_SCAN:
263 CntlOidScanProc(pAd,Elem);
266 case OID_802_11_DISASSOCIATE:
267 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
268 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
269 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
270 #ifdef WPA_SUPPLICANT_SUPPORT
271 if (pAd->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_ENABLE_WITH_WEB_UI)
272 #endif // WPA_SUPPLICANT_SUPPORT //
274 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
275 // Since calling this indicate user don't want to connect to that SSID anymore.
276 pAd->MlmeAux.AutoReconnectSsidLen= 32;
277 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.AutoReconnectSsidLen);
281 case MT2_MLME_ROAMING_REQ:
282 CntlMlmeRoamingProc(pAd, Elem);
285 case OID_802_11_MIC_FAILURE_REPORT_FRAME:
286 WpaMicFailureReportFrame(pAd, Elem);
290 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem->MsgType));
295 VOID CntlOidScanProc(
296 IN PRTMP_ADAPTER pAd,
297 IN MLME_QUEUE_ELEM *Elem)
299 MLME_SCAN_REQ_STRUCT ScanReq;
300 ULONG BssIdx = BSS_NOT_FOUND;
303 // record current BSS if network is connected.
304 // 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.
305 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
307 BssIdx = BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->CommonCfg.Channel);
308 if (BssIdx != BSS_NOT_FOUND)
310 NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
314 // clean up previous SCAN result, add current BSS back to table if any
315 BssTableInit(&pAd->ScanTab);
316 if (BssIdx != BSS_NOT_FOUND)
318 // DDK Note: If the NIC is associated with a particular BSSID and SSID
319 // that are not contained in the list of BSSIDs generated by this scan, the
320 // BSSID description of the currently associated BSSID and SSID should be
321 // appended to the list of BSSIDs in the NIC's database.
322 // To ensure this, we append this BSS as the first entry in SCAN result
323 NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, sizeof(BSS_ENTRY));
324 pAd->ScanTab.BssNr = 1;
327 ScanParmFill(pAd, &ScanReq, "", 0, BSS_ANY, SCAN_ACTIVE);
328 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
329 sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
330 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
334 ==========================================================================
336 Before calling this routine, user desired SSID should already been
337 recorded in CommonCfg.Ssid[]
338 IRQL = DISPATCH_LEVEL
340 ==========================================================================
342 VOID CntlOidSsidProc(
343 IN PRTMP_ADAPTER pAd,
344 IN MLME_QUEUE_ELEM * Elem)
346 PNDIS_802_11_SSID pOidSsid = (NDIS_802_11_SSID *)Elem->Msg;
347 MLME_DISASSOC_REQ_STRUCT DisassocReq;
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.LeapAuthMode == CISCO_AuthModeLEAP)
388 #endif // LEAP_SUPPORT //
390 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED))
392 // case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo
393 // connection process
394 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
395 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
396 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
397 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
398 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
400 else if (pAd->bConfigChanged == TRUE)
402 // case 1.2 Important Config has changed, we have to reconnect to the same AP
403 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));
404 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
405 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
406 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
407 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
411 // case 1.3. already connected to the SSID with highest RSSI.
412 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));
414 // (HCT 12.1) 1c_wlan_mediaevents required
415 // media connect events are indicated when associating with the same AP
420 // Since MediaState already is NdisMediaStateConnected
421 // We just indicate the connect event again to meet the WHQL required.
423 pAd->IndicateMediaState = NdisMediaStateConnected;
424 RTMP_IndicateMediaState(pAd);
425 pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
428 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
429 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
431 union iwreq_data wrqu;
433 memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
434 memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
435 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
438 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
441 else if (INFRA_ON(pAd))
445 // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
446 // RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect
447 // But media status is connected, so the SSID not report correctly.
449 if (!SSID_EQUAL(pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen))
452 // Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event.
454 pAd->MlmeAux.CurrReqIsFromNdis = TRUE;
456 // case 2. active INFRA association existent
457 // roaming is done within miniport driver, nothing to do with configuration
458 // utility. so upon a new SET(OID_802_11_SSID) is received, we just
459 // disassociate with the current associated AP,
460 // then perform a new association with this new SSID, no matter the
461 // new/old SSID are the same or not.
462 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
463 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
464 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
465 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
466 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
472 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));
473 LinkDown(pAd, FALSE);
474 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
475 pAd->IndicateMediaState = NdisMediaStateDisconnected;
476 RTMP_IndicateMediaState(pAd);
477 pAd->ExtraInfo = GENERAL_LINK_DOWN;
478 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
481 if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) &&
482 (pAd->StaCfg.bAutoReconnect == TRUE) &&
483 (pAd->MlmeAux.BssType == BSS_INFRA) &&
484 (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) == TRUE)
487 MLME_SCAN_REQ_STRUCT ScanReq;
489 DBGPRINT(RT_DEBUG_TRACE, ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));
490 ScanParmFill(pAd, &ScanReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);
491 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, sizeof(MLME_SCAN_REQ_STRUCT), &ScanReq);
492 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
493 // Reset Missed scan number
494 pAd->StaCfg.LastScanTime = Now;
498 pAd->MlmeAux.BssIdx = 0;
499 IterateOnBssTab(pAd);
506 ==========================================================================
509 IRQL = DISPATCH_LEVEL
511 ==========================================================================
513 VOID CntlOidRTBssidProc(
514 IN PRTMP_ADAPTER pAd,
515 IN MLME_QUEUE_ELEM * Elem)
518 PUCHAR pOidBssid = (PUCHAR)Elem->Msg;
519 MLME_DISASSOC_REQ_STRUCT DisassocReq;
520 MLME_JOIN_REQ_STRUCT JoinReq;
522 // record user desired settings
523 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);
524 pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
527 // Update Reconnect Ssid, that user desired to connect.
529 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
530 pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
531 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
533 // find the desired BSS in the latest SCAN result table
534 BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);
535 if (BssIdx == BSS_NOT_FOUND)
537 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));
538 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
542 // copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why?
543 // Because we need this entry to become the JOIN target in later on SYNC state machine
544 pAd->MlmeAux.BssIdx = 0;
545 pAd->MlmeAux.SsidBssTab.BssNr = 1;
546 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], &pAd->ScanTab.BssEntry[BssIdx], sizeof(BSS_ENTRY));
548 //pAd->MlmeAux.AutoReconnectSsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
549 //NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->ScanTab.BssEntry[BssIdx].SsidLen);
551 // Add SSID into MlmeAux for site surey joining hidden SSID
552 //pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
553 //NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid, pAd->MlmeAux.SsidLen);
555 // 2002-11-26 skip the following checking. i.e. if user wants to re-connect to same AP
556 // we just follow normal procedure. The reason of user doing this may because he/she changed
557 // AP to another channel, but we still received BEACON from it thus don't claim Link Down.
558 // Since user knows he's changed AP channel, he'll re-connect again. By skipping the following
559 // checking, we'll disassociate then re-do normal association with this AP at the new channel.
560 // 2003-1-6 Re-enable this feature based on microsoft requirement which prefer not to re-do
561 // connection when setting the same BSSID.
562 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
563 MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, pOidBssid))
565 // already connected to the same BSSID, go back to idle state directly
566 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - already in this BSSID. ignore this SET_BSSID request\n"));
567 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
568 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
570 union iwreq_data wrqu;
572 memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
573 memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
574 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
577 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
583 // disassoc from current AP first
584 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - disassociate with current AP ...\n"));
585 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_DISASSOC_STA_LEAVING);
586 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
587 sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq);
589 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
595 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - drop current ADHOC\n"));
596 LinkDown(pAd, FALSE);
597 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
598 pAd->IndicateMediaState = NdisMediaStateDisconnected;
599 RTMP_IndicateMediaState(pAd);
600 pAd->ExtraInfo = GENERAL_LINK_DOWN;
601 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
604 // Change the wepstatus to original wepstatus
605 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
606 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
607 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
609 // Check cipher suite, AP must have more secured cipher than station setting
610 // Set the Pairwise and Group cipher to match the intended AP setting
611 // We can only connect to AP with less secured cipher setting
612 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
614 pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.GroupCipher;
616 if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher)
617 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipher;
618 else if (pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
619 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA.PairCipherAux;
620 else // There is no PairCipher Aux, downgrade our capability to TKIP
621 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
623 else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
625 pAd->StaCfg.GroupCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.GroupCipher;
627 if (pAd->StaCfg.WepStatus == pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher)
628 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipher;
629 else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
630 pAd->StaCfg.PairCipher = pAd->ScanTab.BssEntry[BssIdx].WPA2.PairCipherAux;
631 else // There is no PairCipher Aux, downgrade our capability to TKIP
632 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
635 pAd->StaCfg.RsnCapability = pAd->ScanTab.BssEntry[BssIdx].WPA2.RsnCapability;
638 // Set Mix cipher flag
639 pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
640 if (pAd->StaCfg.bMixCipher == TRUE)
642 // If mix cipher, re-build RSNIE
643 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
645 // No active association, join the BSS immediately
646 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",
647 pOidBssid[0],pOidBssid[1],pOidBssid[2],pOidBssid[3],pOidBssid[4],pOidBssid[5]));
649 JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);
650 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq);
652 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
657 // Roaming is the only external request triggering CNTL state machine
658 // despite of other "SET OID" operation. All "SET OID" related oerations
659 // happen in sequence, because no other SET OID will be sent to this device
660 // until the the previous SET operation is complete (successful o failed).
661 // So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?
662 // or been corrupted by other "SET OID"?
664 // IRQL = DISPATCH_LEVEL
665 VOID CntlMlmeRoamingProc(
666 IN PRTMP_ADAPTER pAd,
667 IN MLME_QUEUE_ELEM *Elem)
670 // AP in different channel may show lower RSSI than actual value??
671 // should we add a weighting factor to compensate it?
672 DBGPRINT(RT_DEBUG_TRACE,("CNTL - Roaming in MlmeAux.RoamTab...\n"));
674 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, sizeof(pAd->MlmeAux.RoamTab));
675 pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;
677 BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);
678 pAd->MlmeAux.BssIdx = 0;
679 IterateOnBssTab(pAd);
683 ==========================================================================
686 IRQL = DISPATCH_LEVEL
688 ==========================================================================
690 VOID CntlWaitDisassocProc(
691 IN PRTMP_ADAPTER pAd,
692 IN MLME_QUEUE_ELEM *Elem)
694 MLME_START_REQ_STRUCT StartReq;
696 if (Elem->MsgType == MT2_DISASSOC_CONF)
698 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n"));
700 if (pAd->CommonCfg.bWirelessEvent)
702 RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
705 LinkDown(pAd, FALSE);
707 // case 1. no matching BSS, and user wants ADHOC, so we just start a new one
708 if ((pAd->MlmeAux.SsidBssTab.BssNr==0) && (pAd->StaCfg.BssType == BSS_ADHOC))
710 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
711 StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
712 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
713 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
715 // case 2. try each matched BSS
718 pAd->MlmeAux.BssIdx = 0;
720 IterateOnBssTab(pAd);
726 ==========================================================================
729 IRQL = DISPATCH_LEVEL
731 ==========================================================================
733 VOID CntlWaitJoinProc(
734 IN PRTMP_ADAPTER pAd,
735 IN MLME_QUEUE_ELEM *Elem)
738 MLME_AUTH_REQ_STRUCT AuthReq;
740 if (Elem->MsgType == MT2_JOIN_CONF)
742 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
743 if (Reason == MLME_SUCCESS)
745 // 1. joined an IBSS, we are pretty much done here
746 if (pAd->MlmeAux.BssType == BSS_ADHOC)
749 // 5G bands rules of Japan:
750 // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
752 if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
753 RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
756 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
757 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
761 LinkUp(pAd, BSS_ADHOC);
762 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
763 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
764 pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
765 pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
767 pAd->IndicateMediaState = NdisMediaStateConnected;
768 pAd->ExtraInfo = GENERAL_LINK_UP;
770 // 2. joined a new INFRA network, start from authentication
774 // Add AuthMode "LEAP" for CCX 1.X
775 if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
777 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
780 #endif // LEAP_SUPPORT //
782 // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
783 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
784 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
786 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
790 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
793 MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
794 sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
796 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH;
801 // 3. failed, try next BSS
802 pAd->MlmeAux.BssIdx++;
803 IterateOnBssTab(pAd);
810 ==========================================================================
813 IRQL = DISPATCH_LEVEL
815 ==========================================================================
817 VOID CntlWaitStartProc(
818 IN PRTMP_ADAPTER pAd,
819 IN MLME_QUEUE_ELEM *Elem)
823 if (Elem->MsgType == MT2_START_CONF)
825 NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
826 if (Result == MLME_SUCCESS)
829 // 5G bands rules of Japan:
830 // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
832 if ( (pAd->CommonCfg.bIEEE80211H == 1) &&
833 RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
836 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
837 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd->CommonCfg.Channel));
840 #ifdef DOT11_N_SUPPORT
841 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
845 NdisMoveMemory(&pAd->MlmeAux.AddHtInfo, &pAd->CommonCfg.AddHTInfo, sizeof(ADD_HT_INFO_IE));
846 RTMPCheckHt(pAd, BSSID_WCID, &pAd->CommonCfg.HtCapability, &pAd->CommonCfg.AddHTInfo);
847 pAd->StaActive.SupportedPhyInfo.bHtEnable = TRUE;
848 NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], 16);
849 NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo.MCSSet[0], &pAd->CommonCfg.HtCapability.MCSSet[0], 16);
850 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
852 if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
853 (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_ABOVE))
855 pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel + 2;
857 else if ((pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth == BW_40) &&
858 (pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset == EXTCHA_BELOW))
860 pAd->MlmeAux.CentralChannel = pAd->CommonCfg.Channel - 2;
864 #endif // DOT11_N_SUPPORT //
866 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
868 LinkUp(pAd, BSS_ADHOC);
869 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
870 // Before send beacon, driver need do radar detection
871 if ((pAd->CommonCfg.Channel > 14 )
872 && (pAd->CommonCfg.bIEEE80211H == 1)
873 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
875 pAd->CommonCfg.RadarDetect.RDMode = RD_SILENCE_MODE;
876 pAd->CommonCfg.RadarDetect.RDCount = 0;
879 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
880 pAd->CommonCfg.Bssid[0],pAd->CommonCfg.Bssid[1],pAd->CommonCfg.Bssid[2],
881 pAd->CommonCfg.Bssid[3],pAd->CommonCfg.Bssid[4],pAd->CommonCfg.Bssid[5]));
885 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Start IBSS fail. BUG!!!!!\n"));
886 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
892 ==========================================================================
895 IRQL = DISPATCH_LEVEL
897 ==========================================================================
899 VOID CntlWaitAuthProc(
900 IN PRTMP_ADAPTER pAd,
901 IN MLME_QUEUE_ELEM *Elem)
904 MLME_ASSOC_REQ_STRUCT AssocReq;
905 MLME_AUTH_REQ_STRUCT AuthReq;
907 if (Elem->MsgType == MT2_AUTH_CONF)
909 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
910 if (Reason == MLME_SUCCESS)
912 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
913 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
914 ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
918 // Cisco Leap CCKM supported Re-association.
920 if (LEAP_CCKM_ON(pAd) && (pAd->StaCfg.CCKMLinkUpFlag == TRUE))
922 //if CCKM is turn on , that's mean Fast Reauthentication
923 //Use CCKM Reassociation instead of normal association for Fast Roaming.
924 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
925 sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
927 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
930 #endif // LEAP_SUPPORT //
932 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
933 sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
935 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
940 // This fail may because of the AP already keep us in its MAC table without
941 // ageing-out. The previous authentication attempt must have let it remove us.
942 // so try Authentication again may help. For D-Link DWL-900AP+ compatibility.
943 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try again...\n"));
945 //Add AuthMode "LEAP" for CCX 1.X
946 if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
948 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, CISCO_AuthModeLEAP);
951 #endif // LEAP_SUPPORT //
953 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeShared) ||
954 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch))
956 // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
957 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeShared);
961 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
964 MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
965 sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
967 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
973 ==========================================================================
976 IRQL = DISPATCH_LEVEL
978 ==========================================================================
980 VOID CntlWaitAuthProc2(
981 IN PRTMP_ADAPTER pAd,
982 IN MLME_QUEUE_ELEM *Elem)
985 MLME_ASSOC_REQ_STRUCT AssocReq;
986 MLME_AUTH_REQ_STRUCT AuthReq;
988 if (Elem->MsgType == MT2_AUTH_CONF)
990 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
991 if (Reason == MLME_SUCCESS)
993 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
994 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, pAd->MlmeAux.CapabilityInfo,
995 ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
996 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_ASSOC_REQ,
997 sizeof(MLME_ASSOC_REQ_STRUCT), &AssocReq);
999 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_ASSOC;
1004 // Process LEAP first, since it use different control variable
1005 // We don't want to affect other poven operation
1006 if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
1008 // LEAP Auth not success, try next BSS
1009 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - *LEAP* AUTH FAIL, give up; try next BSS\n"));
1010 DBGPRINT(RT_DEBUG_TRACE, ("Total match BSSID [=%d]\n", pAd->MlmeAux.SsidBssTab.BssNr));
1011 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1012 pAd->MlmeAux.BssIdx++;
1013 IterateOnBssTab(pAd);
1016 #endif // LEAP_SUPPORT //
1017 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeAutoSwitch) &&
1018 (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared))
1020 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, try OPEN system...\n"));
1021 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, Ndis802_11AuthModeOpen);
1022 MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_MLME_AUTH_REQ,
1023 sizeof(MLME_AUTH_REQ_STRUCT), &AuthReq);
1025 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
1029 // not success, try next BSS
1030 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH FAIL, give up; try next BSS\n"));
1031 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; //???????
1032 pAd->MlmeAux.BssIdx++;
1033 IterateOnBssTab(pAd);
1040 ==========================================================================
1043 IRQL = DISPATCH_LEVEL
1045 ==========================================================================
1047 VOID CntlWaitAssocProc(
1048 IN PRTMP_ADAPTER pAd,
1049 IN MLME_QUEUE_ELEM *Elem)
1053 if (Elem->MsgType == MT2_ASSOC_CONF)
1055 NdisMoveMemory(&Reason, Elem->Msg, sizeof(USHORT));
1056 if (Reason == MLME_SUCCESS)
1058 LinkUp(pAd, BSS_INFRA);
1059 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1060 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association successful on BSS #%ld\n",pAd->MlmeAux.BssIdx));
1062 if (pAd->CommonCfg.bWirelessEvent)
1064 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
1069 // not success, try next BSS
1070 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Association fails on BSS #%ld\n",pAd->MlmeAux.BssIdx));
1071 pAd->MlmeAux.BssIdx++;
1072 IterateOnBssTab(pAd);
1078 ==========================================================================
1081 IRQL = DISPATCH_LEVEL
1083 ==========================================================================
1085 VOID CntlWaitReassocProc(
1086 IN PRTMP_ADAPTER pAd,
1087 IN MLME_QUEUE_ELEM *Elem)
1091 if (Elem->MsgType == MT2_REASSOC_CONF)
1093 NdisMoveMemory(&Result, Elem->Msg, sizeof(USHORT));
1094 if (Result == MLME_SUCCESS)
1097 // NDIS requires a new Link UP indication but no Link Down for RE-ASSOC
1099 LinkUp(pAd, BSS_INFRA);
1101 // send wireless event - for association
1102 if (pAd->CommonCfg.bWirelessEvent)
1103 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
1107 if (LEAP_CCKM_ON(pAd))
1109 STA_PORT_SECURED(pAd);
1110 pAd->StaCfg.WpaState = SS_FINISH;
1112 #endif // LEAP_SUPPORT //
1113 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
1114 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition successful on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
1118 // reassoc failed, try to pick next BSS in the BSS Table
1119 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Re-assocition fails on BSS #%ld\n", pAd->MlmeAux.RoamIdx));
1120 pAd->MlmeAux.RoamIdx++;
1121 IterateOnBssTab2(pAd);
1127 VOID AdhocTurnOnQos(
1128 IN PRTMP_ADAPTER pAd)
1130 #define AC0_DEF_TXOP 0
1131 #define AC1_DEF_TXOP 0
1132 #define AC2_DEF_TXOP 94
1133 #define AC3_DEF_TXOP 47
1135 // Turn on QOs if use HT rate.
1136 if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
1138 pAd->CommonCfg.APEdcaParm.bValid = TRUE;
1139 pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
1140 pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
1141 pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
1142 pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
1144 pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
1145 pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
1146 pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
1147 pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
1149 pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10;
1150 pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6;
1151 pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
1152 pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
1154 pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
1155 pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
1156 pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP;
1157 pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP;
1159 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1163 ==========================================================================
1166 IRQL = DISPATCH_LEVEL
1168 ==========================================================================
1171 IN PRTMP_ADAPTER pAd,
1177 UCHAR Value = 0, idx;
1178 MAC_TABLE_ENTRY *pEntry = NULL, *pCurrEntry;
1180 pEntry = &pAd->MacTab.Content[BSSID_WCID];
1183 // ASSOC - DisassocTimeoutAction
1184 // CNTL - Dis-associate successful
1185 // !!! LINK DOWN !!!
1186 // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
1188 // To prevent DisassocTimeoutAction to call Link down after we link up,
1189 // cancel the DisassocTimer no matter what it start or not.
1191 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
1193 COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
1195 #ifdef DOT11_N_SUPPORT
1196 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
1197 #endif // DOT11_N_SUPPORT //
1198 // It's quite difficult to tell if a newly added KEY is WEP or CKIP until a new BSS
1199 // is formed (either ASSOC/RE-ASSOC done or IBSS started. LinkUP should be a safe place
1200 // to examine if cipher algorithm switching is required.
1201 //rt2860b. Don't know why need this
1202 SwitchBetweenWepAndCkip(pAd);
1205 if (BssType == BSS_ADHOC)
1207 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1208 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1210 #ifdef DOT11_N_SUPPORT
1211 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
1212 AdhocTurnOnQos(pAd);
1213 #endif // DOT11_N_SUPPORT //
1215 DBGPRINT(RT_DEBUG_TRACE, ("!!!Adhoc LINK UP !!! \n" ));
1219 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);
1220 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1222 DBGPRINT(RT_DEBUG_TRACE, ("!!!Infra LINK UP !!! \n" ));
1226 // reset Tx beamforming bit
1227 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1229 Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF;
1230 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1232 #ifdef DOT11_N_SUPPORT
1233 // Change to AP channel
1234 if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
1236 // Must using 40MHz.
1237 pAd->CommonCfg.BBPCurrentBW = BW_40;
1238 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1239 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1241 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1244 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1246 // RX : control channel at lower
1247 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1249 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1251 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1253 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1255 if (pAd->MACVersion == 0x28600100)
1257 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1258 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1259 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
1260 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
1263 DBGPRINT(RT_DEBUG_TRACE, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd->CommonCfg.CentralChannel ));
1265 else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40))
1267 // Must using 40MHz.
1268 pAd->CommonCfg.BBPCurrentBW = BW_40;
1269 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1270 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1272 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1275 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1277 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1279 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1281 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1283 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1285 if (pAd->MACVersion == 0x28600100)
1287 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1288 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1289 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
1290 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
1293 DBGPRINT(RT_DEBUG_TRACE, ("!!! 40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd->CommonCfg.CentralChannel ));
1296 #endif // DOT11_N_SUPPORT //
1298 pAd->CommonCfg.BBPCurrentBW = BW_20;
1299 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
1300 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
1301 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
1303 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1305 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1307 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1309 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1311 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1313 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1315 if (pAd->MACVersion == 0x28600100)
1317 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
1318 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
1319 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
1320 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n" ));
1323 DBGPRINT(RT_DEBUG_TRACE, ("!!! 20MHz LINK UP !!! \n" ));
1326 RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
1328 // Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission
1330 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &pAd->BbpTuning.R66CurrentValue);
1332 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",
1333 BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid, pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
1335 #ifdef DOT11_N_SUPPORT
1336 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! (Density =%d, )\n", pAd->MacTab.Content[BSSID_WCID].MpduDensity));
1337 #endif // DOT11_N_SUPPORT //
1339 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
1341 AsicSetSlotTime(pAd, TRUE);
1342 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1344 // Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit
1345 AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE, FALSE);
1347 #ifdef DOT11_N_SUPPORT
1348 if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE))
1350 // Update HT protectionfor based on AP's operating mode.
1351 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1)
1353 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, TRUE);
1356 AsicUpdateProtect(pAd, pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode, ALLN_SETPROTECT, FALSE, FALSE);
1358 #endif // DOT11_N_SUPPORT //
1360 NdisZeroMemory(&pAd->DrsCounters, sizeof(COUNTER_DRS));
1362 NdisGetSystemUpTime(&Now);
1363 pAd->StaCfg.LastBeaconRxTime = Now; // last RX timestamp
1365 if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) &&
1366 CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo))
1368 MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
1371 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1373 if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE)
1376 pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
1378 if (BssType == BSS_ADHOC)
1380 MakeIbssBeacon(pAd);
1381 if ((pAd->CommonCfg.Channel > 14)
1382 && (pAd->CommonCfg.bIEEE80211H == 1)
1383 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel))
1389 AsicEnableIbssSync(pAd);
1392 // In ad hoc mode, use MAC table from index 1.
1393 // 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.
1394 RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00);
1395 RTMP_IO_WRITE32(pAd, 0x1808, 0x00);
1397 // If WEP is enabled, add key material and cipherAlg into Asic
1398 // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
1400 if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
1405 for (idx=0; idx < SHARE_KEY_NUM; idx++)
1407 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
1408 Key = pAd->SharedKey[BSS0][idx].Key;
1410 if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
1412 // Set key material and cipherAlg to Asic
1413 AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
1415 if (idx == pAd->StaCfg.DefaultKeyId)
1417 // Update WCID attribute table and IVEIV table for this group key table
1418 RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
1425 // If WPANone is enabled, add key material and cipherAlg into Asic
1426 // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
1427 else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1429 pAd->StaCfg.DefaultKeyId = 0; // always be zero
1431 NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
1432 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
1433 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
1435 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
1437 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
1438 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
1441 // Decide its ChiperAlg
1442 if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
1443 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
1444 else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
1445 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1448 DBGPRINT(RT_DEBUG_TRACE, ("Unknow Cipher (=%d), set Cipher to AES\n", pAd->StaCfg.PairCipher));
1449 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1452 // Set key material and cipherAlg to Asic
1453 AsicAddSharedKeyEntry(pAd,
1456 pAd->SharedKey[BSS0][0].CipherAlg,
1457 pAd->SharedKey[BSS0][0].Key,
1458 pAd->SharedKey[BSS0][0].TxMic,
1459 pAd->SharedKey[BSS0][0].RxMic);
1461 // Update WCID attribute table and IVEIV table for this group key table
1462 RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pAd->SharedKey[BSS0][0].CipherAlg, NULL);
1469 // Check the new SSID with last SSID
1470 while (Cancelled == TRUE)
1472 if (pAd->CommonCfg.LastSsidLen == pAd->CommonCfg.SsidLen)
1474 if (RTMPCompareMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen) == 0)
1476 // Link to the old one no linkdown is required.
1480 // Send link down event before set to link up
1481 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1482 RTMP_IndicateMediaState(pAd);
1483 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1484 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));
1489 // On WPA mode, Remove All Keys if not connect to the last BSSID
1490 // Key will be set after 4-way handshake.
1492 if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
1496 // Remove all WPA keys
1497 RTMPWPARemoveAllKeys(pAd);
1498 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1499 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
1501 // Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP
1502 // If IV related values are too large in GroupMsg2, AP would ignore this message.
1504 IV |= (pAd->StaCfg.DefaultKeyId << 30);
1505 AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);
1508 // the decision of using "short slot time" or not may change dynamically due to
1509 // new STA association to the AP. so we have to decide that upon parsing BEACON, not here
1512 // the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically
1513 // due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here
1516 ComposeNullFrame(pAd);
1518 AsicEnableBssSync(pAd);
1520 // Add BSSID to WCID search table
1521 AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);
1523 NdisAcquireSpinLock(&pAd->MacTabLock);
1524 // add this BSSID entry into HASH table
1528 //pEntry = &pAd->MacTab.Content[BSSID_WCID];
1529 HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid);
1530 if (pAd->MacTab.Hash[HashIdx] == NULL)
1532 pAd->MacTab.Hash[HashIdx] = pEntry;
1536 pCurrEntry = pAd->MacTab.Hash[HashIdx];
1537 while (pCurrEntry->pNext != NULL)
1538 pCurrEntry = pCurrEntry->pNext;
1539 pCurrEntry->pNext = pEntry;
1542 NdisReleaseSpinLock(&pAd->MacTabLock);
1545 // If WEP is enabled, add paiewise and shared key
1546 #ifdef WPA_SUPPLICANT_SUPPORT
1547 if (((pAd->StaCfg.WpaSupplicantUP)&&
1548 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)&&
1549 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
1550 ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE)&&
1551 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)))
1553 if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled)
1554 #endif // WPA_SUPPLICANT_SUPPORT //
1559 for (idx=0; idx < SHARE_KEY_NUM; idx++)
1561 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
1562 Key = pAd->SharedKey[BSS0][idx].Key;
1564 if (pAd->SharedKey[BSS0][idx].KeyLen > 0)
1566 // Set key material and cipherAlg to Asic
1567 AsicAddSharedKeyEntry(pAd, BSS0, idx, CipherAlg, Key, NULL, NULL);
1569 if (idx == pAd->StaCfg.DefaultKeyId)
1571 // Assign group key info
1572 RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, NULL);
1574 // Assign pairwise key info
1575 RTMPAddWcidAttributeEntry(pAd, BSS0, idx, CipherAlg, pEntry);
1581 // only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode
1582 // should wait until at least 2 active nodes in this BSSID.
1583 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1586 if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
1588 pAd->IndicateMediaState = NdisMediaStateConnected;
1589 pAd->ExtraInfo = GENERAL_LINK_UP;
1590 RTMP_IndicateMediaState(pAd);
1594 // Add BSSID in my MAC Table.
1595 NdisAcquireSpinLock(&pAd->MacTabLock);
1596 RTMPMoveMemory(pAd->MacTab.Content[BSSID_WCID].Addr, pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
1597 pAd->MacTab.Content[BSSID_WCID].Aid = BSSID_WCID;
1598 pAd->MacTab.Content[BSSID_WCID].pAd = pAd;
1599 pAd->MacTab.Content[BSSID_WCID].ValidAsCLI = TRUE; //Although this is bssid..still set ValidAsCl
1600 pAd->MacTab.Size = 1; // infra mode always set MACtab size =1.
1601 pAd->MacTab.Content[BSSID_WCID].Sst = SST_ASSOC;
1602 pAd->MacTab.Content[BSSID_WCID].AuthState = SST_ASSOC;
1603 pAd->MacTab.Content[BSSID_WCID].WepStatus = pAd->StaCfg.WepStatus;
1604 NdisReleaseSpinLock(&pAd->MacTabLock);
1606 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !!! ClientStatusFlags=%lx)\n",
1607 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
1609 MlmeUpdateTxRates(pAd, TRUE, BSS0);
1610 #ifdef DOT11_N_SUPPORT
1611 MlmeUpdateHtTxRates(pAd, BSS0);
1612 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n", pAd->StaActive.SupportedPhyInfo.bHtEnable));
1613 #endif // DOT11_N_SUPPORT //
1616 // Report Adjacent AP report.
1619 CCXAdjacentAPReport(pAd);
1620 #endif // LEAP_SUPPORT //
1622 if (pAd->CommonCfg.bAggregationCapable)
1624 if ((pAd->CommonCfg.bPiggyBackCapable) && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)
1627 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
1628 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1629 RTMPSetPiggyBack(pAd, TRUE);
1630 DBGPRINT(RT_DEBUG_TRACE, ("Turn on Piggy-Back\n"));
1632 else if (pAd->MlmeAux.APRalinkIe & 0x00000001)
1634 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1638 if (pAd->MlmeAux.APRalinkIe != 0x0)
1640 #ifdef DOT11_N_SUPPORT
1641 if (CLIENT_STATUS_TEST_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RDG_CAPABLE))
1645 #endif // DOT11_N_SUPPORT //
1646 OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
1647 CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
1651 OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
1652 CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab.Content[BSSID_WCID], fCLIENT_STATUS_RALINK_CHIPSET);
1656 #ifdef DOT11_N_SUPPORT
1657 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));
1658 #endif // DOT11_N_SUPPORT //
1661 RTMPSetLED(pAd, LED_LINK_UP);
1663 pAd->Mlme.PeriodicRound = 0;
1664 pAd->Mlme.OneSecPeriodicRound = 0;
1665 pAd->bConfigChanged = FALSE; // Reset config flag
1666 pAd->ExtraInfo = GENERAL_LINK_UP; // Update extra information to link is up
1668 // Set asic auto fall back
1671 UCHAR TableSize = 0;
1673 MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID], &pTable, &TableSize, &pAd->CommonCfg.TxRateIndex);
1674 AsicUpdateAutoFallBackTable(pAd, pTable);
1677 NdisAcquireSpinLock(&pAd->MacTabLock);
1678 pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1679 pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1680 if (pAd->StaCfg.bAutoTxRateSwitch == FALSE)
1682 pEntry->bAutoTxRateSwitch = FALSE;
1683 #ifdef DOT11_N_SUPPORT
1684 if (pEntry->HTPhyMode.field.MCS == 32)
1685 pEntry->HTPhyMode.field.ShortGI = GI_800;
1687 if ((pEntry->HTPhyMode.field.MCS > MCS_7) || (pEntry->HTPhyMode.field.MCS == 32))
1688 pEntry->HTPhyMode.field.STBC = STBC_NONE;
1689 #endif // DOT11_N_SUPPORT //
1690 // If the legacy mode is set, overwrite the transmit setting of this entry.
1691 if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM)
1692 RTMPUpdateLegacyTxSetting((UCHAR)pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode, pEntry);
1695 pEntry->bAutoTxRateSwitch = TRUE;
1696 NdisReleaseSpinLock(&pAd->MacTabLock);
1698 // Let Link Status Page display first initial rate.
1699 pAd->LastTxRate = (USHORT)(pEntry->HTPhyMode.word);
1700 // Select DAC according to HT or Legacy
1701 if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00)
1703 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1705 if (pAd->Antenna.field.TxPath == 2)
1709 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
1713 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1715 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
1718 #ifdef DOT11_N_SUPPORT
1719 if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
1722 else if (pEntry->MaxRAmpduFactor == 0)
1724 // If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0.
1725 // Because our Init value is 1 at MACRegTable.
1726 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff);
1728 #endif // DOT11_N_SUPPORT //
1730 // Patch for Marvel AP to gain high throughput
1731 // Need to set as following,
1732 // 1. Set txop in register-EDCA_AC0_CFG as 0x60
1733 // 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero
1734 // 3. PBF_MAX_PCNT as 0x1F3FBF9F
1735 // 4. kick per two packets when dequeue
1737 // Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable
1739 // if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is.
1740 #ifdef DOT11_N_SUPPORT
1741 if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)))
1742 || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)))
1744 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1746 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1748 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1749 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n"));
1752 #endif // DOT11_N_SUPPORT //
1753 if (pAd->CommonCfg.bEnableTxBurst)
1755 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1758 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1759 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE;
1761 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F);
1762 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n"));
1766 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
1768 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1770 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1771 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n"));
1774 #ifdef DOT11_N_SUPPORT
1775 // Re-check to turn on TX burst or not.
1776 if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE) && ((STA_WEP_ON(pAd))||(STA_TKIP_ON(pAd))))
1778 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE;
1779 if (pAd->CommonCfg.bEnableTxBurst)
1781 UINT32 MACValue = 0;
1782 // Force disable TXOP value in this case. The same action in MLMEUpdateProtect too.
1783 // I didn't change PBF_MAX_PCNT setting.
1784 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue);
1785 MACValue &= 0xFFFFFF00;
1786 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue);
1787 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
1792 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE;
1794 #endif // DOT11_N_SUPPORT //
1796 pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE;
1797 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
1798 DBGPRINT(RT_DEBUG_TRACE, ("!!!pAd->bNextDisableRxBA= %d \n", pAd->CommonCfg.IOTestParm.bNextDisableRxBA));
1799 // BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap
1800 // Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver.
1801 // Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same.
1803 if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled)
1805 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1806 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
1809 NdisAcquireSpinLock(&pAd->MacTabLock);
1810 pEntry->PortSecured = pAd->StaCfg.PortSecured;
1811 NdisReleaseSpinLock(&pAd->MacTabLock);
1814 // Patch Atheros AP TX will breakdown issue.
1815 // AP Model: DLink DWL-8200AP
1817 if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && STA_TKIP_ON(pAd))
1819 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01);
1823 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00);
1826 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
1829 #ifdef DOT11_N_SUPPORT
1830 #ifdef DOT11N_DRAFT3
1831 if ((pAd->CommonCfg.BACapability.field.b2040CoexistScanSup) && (pAd->CommonCfg.Channel <= 11))
1833 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SCAN_2040);
1834 BuildEffectedChannelList(pAd);
1836 #endif // DOT11N_DRAFT3 //
1837 #endif // DOT11_N_SUPPORT //
1841 ==========================================================================
1843 Routine Description:
1844 Disconnect current BSSID
1847 pAd - Pointer to our adapter
1848 IsReqFromAP - Request from AP
1853 IRQL = DISPATCH_LEVEL
1856 We need more information to know it's this requst from AP.
1857 If yes! we need to do extra handling, for example, remove the WPA key.
1858 Otherwise on 4-way handshaking will faied, since the WPA key didn't be
1859 remove while auto reconnect.
1860 Disconnect request from AP, it means we will start afresh 4-way handshaking
1863 ==========================================================================
1866 IN PRTMP_ADAPTER pAd,
1867 IN BOOLEAN IsReqFromAP)
1869 UCHAR i, ByteValue = 0;
1871 // Do nothing if monitor mode is on
1872 if (MONITOR_ON(pAd))
1875 if (pAd->CommonCfg.bWirelessEvent)
1877 RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
1880 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN !!!\n"));
1881 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1883 if (ADHOC_ON(pAd)) // Adhoc mode link down
1885 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 1!!!\n"));
1887 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1888 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1889 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1890 RTMP_IndicateMediaState(pAd);
1891 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1892 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
1893 DBGPRINT(RT_DEBUG_TRACE, ("!!! MacTab.Size=%d !!!\n", pAd->MacTab.Size));
1895 else // Infra structure mode
1897 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 2!!!\n"));
1899 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1900 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1902 // Saved last SSID for linkup comparison
1903 pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen;
1904 NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, pAd->CommonCfg.LastSsidLen);
1905 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
1906 if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE)
1908 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1909 RTMP_IndicateMediaState(pAd);
1910 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1911 DBGPRINT(RT_DEBUG_TRACE, ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));
1912 pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
1917 // If disassociation request is from NDIS, then we don't need to delete BSSID from entry.
1918 // Otherwise lost beacon or receive De-Authentication from AP,
1919 // then we should delete BSSID from BssTable.
1920 // If we don't delete from entry, roaming will fail.
1922 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, pAd->CommonCfg.Channel);
1925 // restore back to -
1926 // 1. long slot (20 us) or short slot (9 us) time
1927 // 2. turn on/off RTS/CTS and/or CTS-to-self protection
1928 // 3. short preamble
1929 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
1931 if (pAd->StaCfg.CCXAdjacentAPReportFlag == TRUE)
1934 // Record current AP's information.
1935 // for later used reporting Adjacent AP report.
1937 pAd->StaCfg.CCXAdjacentAPChannel = pAd->CommonCfg.Channel;
1938 pAd->StaCfg.CCXAdjacentAPSsidLen = pAd->CommonCfg.SsidLen;
1939 NdisMoveMemory(pAd->StaCfg.CCXAdjacentAPSsid, pAd->CommonCfg.Ssid, pAd->StaCfg.CCXAdjacentAPSsidLen);
1940 COPY_MAC_ADDR(pAd->StaCfg.CCXAdjacentAPBssid, pAd->CommonCfg.Bssid);
1943 #ifdef EXT_BUILD_CHANNEL_LIST
1944 // Country IE of the AP will be evaluated and will be used.
1945 if (pAd->StaCfg.IEEE80211dClientMode != Rt802_11_D_None)
1947 NdisMoveMemory(&pAd->CommonCfg.CountryCode[0], &pAd->StaCfg.StaOriCountryCode[0], 2);
1948 pAd->CommonCfg.Geography = pAd->StaCfg.StaOriGeography;
1949 BuildChannelListEx(pAd);
1951 #endif // EXT_BUILD_CHANNEL_LIST //
1955 for (i=1; i<MAX_LEN_OF_MAC_TABLE; i++)
1957 if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
1958 MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid, pAd->MacTab.Content[i].Addr);
1961 pAd->StaCfg.CCXQosECWMin = 4;
1962 pAd->StaCfg.CCXQosECWMax = 10;
1964 AsicSetSlotTime(pAd, TRUE); //FALSE);
1965 AsicSetEdcaParm(pAd, NULL);
1968 RTMPSetLED(pAd, LED_LINK_DOWN);
1969 pAd->LedIndicatorStregth = 0xF0;
1970 RTMPSetSignalLED(pAd, -100); // Force signal strength Led to be turned off, firmware is not done it.
1972 AsicDisableSync(pAd);
1974 pAd->Mlme.PeriodicRound = 0;
1975 pAd->Mlme.OneSecPeriodicRound = 0;
1977 if (pAd->StaCfg.BssType == BSS_INFRA)
1979 // Remove StaCfg Information after link down
1980 NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
1981 NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID);
1982 pAd->CommonCfg.SsidLen = 0;
1984 #ifdef DOT11_N_SUPPORT
1985 NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(HT_CAPABILITY_IE));
1986 NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(ADD_HT_INFO_IE));
1987 pAd->MlmeAux.HtCapabilityLen = 0;
1988 pAd->MlmeAux.NewExtChannelOffset = 0xff;
1989 #endif // DOT11_N_SUPPORT //
1991 // Reset WPA-PSK state. Only reset when supplicant enabled
1992 if (pAd->StaCfg.WpaState != SS_NOTUSE)
1994 pAd->StaCfg.WpaState = SS_START;
1995 // Clear Replay counter
1996 NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
2001 // if link down come from AP, we need to remove all WPA keys on WPA mode.
2002 // otherwise will cause 4-way handshaking failed, since the WPA key not empty.
2004 if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA))
2006 // Remove all WPA keys
2007 RTMPWPARemoveAllKeys(pAd);
2010 // 802.1x port control
2011 #ifdef WPA_SUPPLICANT_SUPPORT
2012 // Prevent clear PortSecured here with static WEP
2013 // NetworkManger set security policy first then set SSID to connect AP.
2014 if (pAd->StaCfg.WpaSupplicantUP &&
2015 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
2016 (pAd->StaCfg.IEEE8021X == FALSE))
2018 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
2021 #endif // WPA_SUPPLICANT_SUPPORT //
2023 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2024 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
2027 NdisAcquireSpinLock(&pAd->MacTabLock);
2028 pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured;
2029 NdisReleaseSpinLock(&pAd->MacTabLock);
2031 pAd->StaCfg.MicErrCnt = 0;
2033 // Turn off Ckip control flag
2034 pAd->StaCfg.bCkipOn = FALSE;
2035 pAd->StaCfg.CCXEnable = FALSE;
2037 pAd->IndicateMediaState = NdisMediaStateDisconnected;
2038 // Update extra information to link is up
2039 pAd->ExtraInfo = GENERAL_LINK_DOWN;
2041 //pAd->StaCfg.AdhocBOnlyJoined = FALSE;
2042 //pAd->StaCfg.AdhocBGJoined = FALSE;
2043 //pAd->StaCfg.Adhoc20NJoined = FALSE;
2044 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
2046 // Reset the Current AP's IP address
2047 NdisZeroMemory(pAd->StaCfg.AironetIPAddress, 4);
2049 pAd->bUsbTxBulkAggre = FALSE;
2052 // Clean association information
2053 NdisZeroMemory(&pAd->StaCfg.AssocInfo, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION));
2054 pAd->StaCfg.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
2055 pAd->StaCfg.ReqVarIELen = 0;
2056 pAd->StaCfg.ResVarIELen = 0;
2059 // Reset RSSI value after link down
2061 pAd->StaCfg.RssiSample.AvgRssi0 = 0;
2062 pAd->StaCfg.RssiSample.AvgRssi0X8 = 0;
2063 pAd->StaCfg.RssiSample.AvgRssi1 = 0;
2064 pAd->StaCfg.RssiSample.AvgRssi1X8 = 0;
2065 pAd->StaCfg.RssiSample.AvgRssi2 = 0;
2066 pAd->StaCfg.RssiSample.AvgRssi2X8 = 0;
2069 pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate;
2070 pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate;
2072 #ifdef DOT11_N_SUPPORT
2074 // After Link down, reset piggy-back setting in ASIC. Disable RDG.
2076 if (pAd->CommonCfg.BBPCurrentBW == BW_40)
2078 pAd->CommonCfg.BBPCurrentBW = BW_20;
2079 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue);
2080 ByteValue &= (~0x18);
2081 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue);
2083 #endif // DOT11_N_SUPPORT //
2085 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue);
2086 ByteValue &= (~0x18);
2087 if (pAd->Antenna.field.TxPath == 2)
2091 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue);
2093 RTMPSetPiggyBack(pAd,FALSE);
2094 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
2096 #ifdef DOT11_N_SUPPORT
2097 pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word;
2098 #endif // DOT11_N_SUPPORT //
2100 // Restore all settings in the following.
2101 AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT|CCKSETPROTECT|OFDMSETPROTECT), TRUE, FALSE);
2102 AsicDisableRDG(pAd);
2103 pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;
2104 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
2106 #ifdef DOT11_N_SUPPORT
2107 #ifdef DOT11N_DRAFT3
2108 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SCAN_2040);
2109 pAd->CommonCfg.BSSCoexist2040.word = 0;
2111 for (i = 0; i < (pAd->ChannelListNum - 1); i++)
2113 pAd->ChannelList[i].bEffectedChannel = FALSE;
2115 #endif // DOT11N_DRAFT3 //
2116 #endif // DOT11_N_SUPPORT //
2118 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);
2119 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
2121 #ifdef WPA_SUPPLICANT_SUPPORT
2122 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
2123 if (pAd->StaCfg.WpaSupplicantUP) {
2124 union iwreq_data wrqu;
2125 //send disassociate event to wpa_supplicant
2126 memset(&wrqu, 0, sizeof(wrqu));
2127 wrqu.data.flags = RT_DISASSOC_EVENT_FLAG;
2128 wireless_send_event(pAd->net_dev, IWEVCUSTOM, &wrqu, NULL);
2130 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2131 #endif // WPA_SUPPLICANT_SUPPORT //
2133 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
2135 union iwreq_data wrqu;
2136 memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
2137 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
2139 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2143 ==========================================================================
2146 IRQL = DISPATCH_LEVEL
2148 ==========================================================================
2150 VOID IterateOnBssTab(
2151 IN PRTMP_ADAPTER pAd)
2153 MLME_START_REQ_STRUCT StartReq;
2154 MLME_JOIN_REQ_STRUCT JoinReq;
2157 // Change the wepstatus to original wepstatus
2158 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
2159 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
2160 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
2162 BssIdx = pAd->MlmeAux.BssIdx;
2163 if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr)
2165 // Check cipher suite, AP must have more secured cipher than station setting
2166 // Set the Pairwise and Group cipher to match the intended AP setting
2167 // We can only connect to AP with less secured cipher setting
2168 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
2170 pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.GroupCipher;
2172 if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher)
2173 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher;
2174 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
2175 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux;
2176 else // There is no PairCipher Aux, downgrade our capability to TKIP
2177 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2179 else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
2181 pAd->StaCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.GroupCipher;
2183 if (pAd->StaCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher)
2184 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher;
2185 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
2186 pAd->StaCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux;
2187 else // There is no PairCipher Aux, downgrade our capability to TKIP
2188 pAd->StaCfg.PairCipher = Ndis802_11Encryption2Enabled;
2191 pAd->StaCfg.RsnCapability = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.RsnCapability;
2194 // Set Mix cipher flag
2195 pAd->StaCfg.bMixCipher = (pAd->StaCfg.PairCipher == pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
2196 if (pAd->StaCfg.bMixCipher == TRUE)
2198 // If mix cipher, re-build RSNIE
2199 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
2202 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.SsidBssTab.BssNr));
2203 JoinParmFill(pAd, &JoinReq, BssIdx);
2204 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT),
2206 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
2208 else if (pAd->StaCfg.BssType == BSS_ADHOC)
2210 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid));
2211 StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
2212 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
2213 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
2217 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All roaming failed, stay @ ch #%d\n", pAd->CommonCfg.Channel));
2218 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2219 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2220 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2224 // for re-association only
2225 // IRQL = DISPATCH_LEVEL
2226 VOID IterateOnBssTab2(
2227 IN PRTMP_ADAPTER pAd)
2229 MLME_REASSOC_REQ_STRUCT ReassocReq;
2233 BssIdx = pAd->MlmeAux.RoamIdx;
2234 pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];
2236 if (BssIdx < pAd->MlmeAux.RoamTab.BssNr)
2238 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - iterate BSS %ld of %d\n", BssIdx, pAd->MlmeAux.RoamTab.BssNr));
2240 AsicSwitchChannel(pAd, pBss->Channel, FALSE);
2241 AsicLockChannel(pAd, pBss->Channel);
2243 // reassociate message has the same structure as associate message
2244 AssocParmFill(pAd, &ReassocReq, pBss->Bssid, pBss->CapabilityInfo,
2245 ASSOC_TIMEOUT, pAd->StaCfg.DefaultListenCount);
2246 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
2247 sizeof(MLME_REASSOC_REQ_STRUCT), &ReassocReq);
2249 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
2253 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - All fast roaming failed, back to ch #%d\n",pAd->CommonCfg.Channel));
2254 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2255 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2256 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2261 ==========================================================================
2264 IRQL = DISPATCH_LEVEL
2266 ==========================================================================
2269 IN PRTMP_ADAPTER pAd,
2270 IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,
2273 JoinReq->BssIdx = BssIdx;
2277 ==========================================================================
2280 IRQL = DISPATCH_LEVEL
2282 ==========================================================================
2285 IN PRTMP_ADAPTER pAd,
2286 IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,
2292 NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID);
2293 ScanReq->SsidLen = SsidLen;
2294 NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);
2295 ScanReq->BssType = BssType;
2296 ScanReq->ScanType = ScanType;
2300 ==========================================================================
2303 IRQL = DISPATCH_LEVEL
2305 ==========================================================================
2308 IN PRTMP_ADAPTER pAd,
2309 IN OUT MLME_START_REQ_STRUCT *StartReq,
2313 ASSERT(SsidLen <= MAX_LEN_OF_SSID);
2314 NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);
2315 StartReq->SsidLen = SsidLen;
2319 ==========================================================================
2322 IRQL = DISPATCH_LEVEL
2324 ==========================================================================
2327 IN PRTMP_ADAPTER pAd,
2328 IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,
2332 COPY_MAC_ADDR(AuthReq->Addr, pAddr);
2334 AuthReq->Timeout = AUTH_TIMEOUT;
2338 ==========================================================================
2341 IRQL = DISPATCH_LEVEL
2343 ==========================================================================
2349 VOID MlmeCntlConfirm(
2350 IN PRTMP_ADAPTER pAd,
2354 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(USHORT), &Msg);
2358 IN PRTMP_ADAPTER pAd)
2360 PTXINFO_STRUC pTxInfo;
2363 DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n"));
2364 NdisZeroMemory(&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
2366 pAd->PsPollFrame.FC.PwrMgmt = 0;
2367 pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
2368 pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
2369 pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
2370 COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
2371 COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
2373 RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0], 100);
2374 pTxInfo = (PTXINFO_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[0];
2375 RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(PSPOLL_FRAME)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2376 pTxWI = (PTXWI_STRUC)&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
2377 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(PSPOLL_FRAME)),
2378 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2379 RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
2380 // Append 4 extra zero bytes.
2381 pAd->PsPollContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(PSPOLL_FRAME) + 4;
2384 // IRQL = DISPATCH_LEVEL
2385 VOID ComposeNullFrame(
2386 IN PRTMP_ADAPTER pAd)
2388 PTXINFO_STRUC pTxInfo;
2391 NdisZeroMemory(&pAd->NullFrame, sizeof(HEADER_802_11));
2392 pAd->NullFrame.FC.Type = BTYPE_DATA;
2393 pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
2394 pAd->NullFrame.FC.ToDs = 1;
2395 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
2396 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
2397 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
2398 RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[0], 100);
2399 pTxInfo = (PTXINFO_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[0];
2400 RTMPWriteTxInfo(pAd, pTxInfo, (USHORT)(sizeof(HEADER_802_11)+TXWI_SIZE), TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2401 pTxWI = (PTXWI_STRUC)&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXINFO_SIZE];
2402 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, BSSID_WCID, (sizeof(HEADER_802_11)),
2403 0, 0, (UCHAR)pAd->CommonCfg.MlmeTransmit.field.MCS, IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2404 RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.WirelessPacket[TXWI_SIZE+TXINFO_SIZE], &pAd->NullFrame, sizeof(HEADER_802_11));
2405 pAd->NullContext.BulkOutSize = TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
2411 ==========================================================================
2413 Pre-build a BEACON frame in the shared memory
2415 IRQL = PASSIVE_LEVEL
2416 IRQL = DISPATCH_LEVEL
2418 ==========================================================================
2420 ULONG MakeIbssBeacon(
2421 IN PRTMP_ADAPTER pAd)
2423 UCHAR DsLen = 1, IbssLen = 2;
2424 UCHAR LocalErpIe[3] = {IE_ERP, 1, 0x04};
2425 HEADER_802_11 BcnHdr;
2426 USHORT CapabilityInfo;
2427 LARGE_INTEGER FakeTimestamp;
2429 PTXWI_STRUC pTxWI = &pAd->BeaconTxWI;
2430 CHAR *pBeaconFrame = pAd->BeaconBuf;
2432 UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
2433 UCHAR SupRateLen = 0;
2434 UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
2435 UCHAR ExtRateLen = 0;
2436 UCHAR RSNIe = IE_WPA;
2438 if ((pAd->CommonCfg.PhyMode == PHY_11B) && (pAd->CommonCfg.Channel <= 14))
2440 SupRate[0] = 0x82; // 1 mbps
2441 SupRate[1] = 0x84; // 2 mbps
2442 SupRate[2] = 0x8b; // 5.5 mbps
2443 SupRate[3] = 0x96; // 11 mbps
2447 else if (pAd->CommonCfg.Channel > 14)
2449 SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2450 SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2451 SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2452 SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2453 SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2454 SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2455 SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2456 SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2461 // Also Update MlmeRate & RtsRate for G only & A only
2463 pAd->CommonCfg.MlmeRate = RATE_6;
2464 pAd->CommonCfg.RtsRate = RATE_6;
2465 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
2466 pAd->CommonCfg.MlmeTransmit.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2467 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = MODE_OFDM;
2468 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2472 SupRate[0] = 0x82; // 1 mbps
2473 SupRate[1] = 0x84; // 2 mbps
2474 SupRate[2] = 0x8b; // 5.5 mbps
2475 SupRate[3] = 0x96; // 11 mbps
2478 ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps,
2479 ExtRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2480 ExtRate[2] = 0x18; // 12 mbps, in units of 0.5 Mbps,
2481 ExtRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2482 ExtRate[4] = 0x30; // 24 mbps, in units of 0.5 Mbps,
2483 ExtRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2484 ExtRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2485 ExtRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2489 pAd->StaActive.SupRateLen = SupRateLen;
2490 NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen);
2491 pAd->StaActive.ExtRateLen = ExtRateLen;
2492 NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen);
2494 // compose IBSS beacon frame
2495 MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR, pAd->CommonCfg.Bssid);
2496 Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
2497 (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
2498 (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
2499 CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), 0, 0);
2501 MakeOutgoingFrame(pBeaconFrame, &FrameLen,
2502 sizeof(HEADER_802_11), &BcnHdr,
2503 TIMESTAMP_LEN, &FakeTimestamp,
2504 2, &pAd->CommonCfg.BeaconPeriod,
2507 1, &pAd->CommonCfg.SsidLen,
2508 pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
2511 SupRateLen, SupRate,
2514 1, &pAd->CommonCfg.Channel,
2517 2, &pAd->StaActive.AtimWin,
2520 // add ERP_IE and EXT_RAE IE of in 802.11g
2525 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2529 ExtRateLen, ExtRate,
2534 // If adhoc secruity is set for WPA-None, append the cipher suite IE
2535 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
2538 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, BSS0);
2540 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2542 1, &pAd->StaCfg.RSNIE_Len,
2543 pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
2548 #ifdef DOT11_N_SUPPORT
2549 if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED))
2552 UCHAR HtLen, HtLen1;
2554 #ifdef RT_BIG_ENDIAN
2555 HT_CAPABILITY_IE HtCapabilityTmp;
2556 ADD_HT_INFO_IE addHTInfoTmp;
2557 USHORT b2lTmp, b2lTmp2;
2560 // add HT Capability IE
2561 HtLen = sizeof(pAd->CommonCfg.HtCapability);
2562 HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);
2563 #ifndef RT_BIG_ENDIAN
2564 MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,
2567 HtLen, &pAd->CommonCfg.HtCapability,
2570 HtLen1, &pAd->CommonCfg.AddHTInfo,
2573 NdisMoveMemory(&HtCapabilityTmp, &pAd->CommonCfg.HtCapability, HtLen);
2574 *(USHORT *)(&HtCapabilityTmp.HtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.HtCapInfo));
2575 *(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo) = SWAP16(*(USHORT *)(&HtCapabilityTmp.ExtHtCapInfo));
2577 NdisMoveMemory(&addHTInfoTmp, &pAd->CommonCfg.AddHTInfo, HtLen1);
2578 *(USHORT *)(&addHTInfoTmp.AddHtInfo2) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo2));
2579 *(USHORT *)(&addHTInfoTmp.AddHtInfo3) = SWAP16(*(USHORT *)(&addHTInfoTmp.AddHtInfo3));
2581 MakeOutgoingFrame(pBeaconFrame+FrameLen, &TmpLen,
2584 HtLen, &HtCapabilityTmp,
2587 HtLen1, &addHTInfoTmp,
2592 #endif // DOT11_N_SUPPORT //
2594 //beacon use reserved WCID 0xff
2595 if (pAd->CommonCfg.Channel > 14)
2597 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
2598 PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit);
2602 // Set to use 1Mbps for Adhoc beacon.
2603 HTTRANSMIT_SETTING Transmit;
2605 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, 0, 0xff, FrameLen,
2606 PID_MGMT, PID_BEACON, RATE_1, IFS_HTTXOP, FALSE, &Transmit);
2609 #ifdef RT_BIG_ENDIAN
2610 RTMPFrameEndianChange(pAd, pBeaconFrame, DIR_WRITE, FALSE);
2611 RTMPWIEndianChange((PUCHAR)pTxWI, TYPE_TXWI);
2614 DBGPRINT(RT_DEBUG_TRACE, ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
2615 FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel, pAd->CommonCfg.PhyMode));