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
38 #include "../rt_config.h"
41 UCHAR CipherSuiteWpaNoneTkip
[] = {
42 0x00, 0x50, 0xf2, 0x01, // oui
43 0x01, 0x00, // Version
44 0x00, 0x50, 0xf2, 0x02, // Multicast
45 0x01, 0x00, // Number of unicast
46 0x00, 0x50, 0xf2, 0x02, // unicast
47 0x01, 0x00, // number of authentication method
48 0x00, 0x50, 0xf2, 0x00 // authentication
50 UCHAR CipherSuiteWpaNoneTkipLen
= (sizeof(CipherSuiteWpaNoneTkip
) / sizeof(UCHAR
));
52 UCHAR CipherSuiteWpaNoneAes
[] = {
53 0x00, 0x50, 0xf2, 0x01, // oui
54 0x01, 0x00, // Version
55 0x00, 0x50, 0xf2, 0x04, // Multicast
56 0x01, 0x00, // Number of unicast
57 0x00, 0x50, 0xf2, 0x04, // unicast
58 0x01, 0x00, // number of authentication method
59 0x00, 0x50, 0xf2, 0x00 // authentication
61 UCHAR CipherSuiteWpaNoneAesLen
= (sizeof(CipherSuiteWpaNoneAes
) / sizeof(UCHAR
));
63 // The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS,
64 // or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS
65 // All settings successfuly negotiated furing MLME state machines become final settings
66 // and are copied to pAd->StaActive
67 #define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
69 NdisZeroMemory((_pAd)->CommonCfg.Ssid, MAX_LEN_OF_SSID); \
70 (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \
71 NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \
72 COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \
73 (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \
74 (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \
75 (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \
76 (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \
77 (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \
78 (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \
79 (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \
80 (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \
81 (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \
82 NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\
83 (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \
84 NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\
85 NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(EDCA_PARM));\
86 NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(QOS_CAPABILITY_PARM));\
87 NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(QBSS_LOAD_PARM));\
88 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \
89 (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \
90 (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\
91 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\
92 (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\
96 ==========================================================================
101 ==========================================================================
104 IN PRTMP_ADAPTER pAd
,
106 OUT STATE_MACHINE_FUNC Trans
[])
108 // Control state machine differs from other state machines, the interface
109 // follows the standard interface
110 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
114 ==========================================================================
117 IRQL = DISPATCH_LEVEL
119 ==========================================================================
121 VOID
MlmeCntlMachinePerformAction(
122 IN PRTMP_ADAPTER pAd
,
124 IN MLME_QUEUE_ELEM
*Elem
)
126 switch(pAd
->Mlme
.CntlMachine
.CurrState
)
129 CntlIdleProc(pAd
, Elem
);
131 case CNTL_WAIT_DISASSOC
:
132 CntlWaitDisassocProc(pAd
, Elem
);
135 CntlWaitJoinProc(pAd
, Elem
);
138 // CNTL_WAIT_REASSOC is the only state in CNTL machine that does
139 // not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)".
140 // Therefore not protected by NDIS's "only one outstanding OID request"
141 // rule. Which means NDIS may SET OID in the middle of ROAMing attempts.
142 // Current approach is to block new SET request at RTMPSetInformation()
143 // when CntlMachine.CurrState is not CNTL_IDLE
144 case CNTL_WAIT_REASSOC
:
145 CntlWaitReassocProc(pAd
, Elem
);
148 case CNTL_WAIT_START
:
149 CntlWaitStartProc(pAd
, Elem
);
152 CntlWaitAuthProc(pAd
, Elem
);
154 case CNTL_WAIT_AUTH2
:
155 CntlWaitAuthProc2(pAd
, Elem
);
157 case CNTL_WAIT_ASSOC
:
158 CntlWaitAssocProc(pAd
, Elem
);
161 case CNTL_WAIT_OID_LIST_SCAN
:
162 if(Elem
->MsgType
== MT2_SCAN_CONF
)
164 // Resume TxRing after SCANING complete. We hope the out-of-service time
165 // won't be too long to let upper layer time-out the waiting frames
166 RTMPResumeMsduTransmission(pAd
);
168 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
171 // Set LED status to previous status.
173 if (pAd
->bLedOnScanning
)
175 pAd
->bLedOnScanning
= FALSE
;
176 RTMPSetLED(pAd
, pAd
->LedStatus
);
179 // AP sent a 2040Coexistence mgmt frame, then station perform a scan, and then send back the respone.
180 if (pAd
->CommonCfg
.BSSCoexist2040
.field
.InfoReq
== 1)
182 Update2040CoexistFrameAndNotify(pAd
, BSSID_WCID
, TRUE
);
184 #endif // DOT11N_DRAFT3 //
188 case CNTL_WAIT_OID_DISASSOC
:
189 if (Elem
->MsgType
== MT2_DISASSOC_CONF
)
191 LinkDown(pAd
, FALSE
);
192 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
196 DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)", Elem
->MsgType
));
203 ==========================================================================
206 IRQL = DISPATCH_LEVEL
208 ==========================================================================
211 IN PRTMP_ADAPTER pAd
,
212 IN MLME_QUEUE_ELEM
*Elem
)
214 MLME_DISASSOC_REQ_STRUCT DisassocReq
;
216 if (RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_RADIO_OFF
))
219 switch(Elem
->MsgType
)
221 case OID_802_11_SSID
:
222 CntlOidSsidProc(pAd
, Elem
);
225 case OID_802_11_BSSID
:
226 CntlOidRTBssidProc(pAd
,Elem
);
229 case OID_802_11_BSSID_LIST_SCAN
:
230 CntlOidScanProc(pAd
,Elem
);
233 case OID_802_11_DISASSOCIATE
:
234 DisassocParmFill(pAd
, &DisassocReq
, pAd
->CommonCfg
.Bssid
, REASON_DISASSOC_STA_LEAVING
);
235 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_DISASSOC_REQ
, sizeof(MLME_DISASSOC_REQ_STRUCT
), &DisassocReq
);
236 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_OID_DISASSOC
;
237 #ifdef WPA_SUPPLICANT_SUPPORT
238 if (pAd
->StaCfg
.WpaSupplicantUP
!= WPA_SUPPLICANT_ENABLE_WITH_WEB_UI
)
239 #endif // WPA_SUPPLICANT_SUPPORT //
241 // Set the AutoReconnectSsid to prevent it reconnect to old SSID
242 // Since calling this indicate user don't want to connect to that SSID anymore.
243 pAd
->MlmeAux
.AutoReconnectSsidLen
= 32;
244 NdisZeroMemory(pAd
->MlmeAux
.AutoReconnectSsid
, pAd
->MlmeAux
.AutoReconnectSsidLen
);
248 case MT2_MLME_ROAMING_REQ
:
249 CntlMlmeRoamingProc(pAd
, Elem
);
252 case OID_802_11_MIC_FAILURE_REPORT_FRAME
:
253 WpaMicFailureReportFrame(pAd
, Elem
);
256 #ifdef QOS_DLS_SUPPORT
257 case RT_OID_802_11_SET_DLS_PARAM
:
258 CntlOidDLSSetupProc(pAd
, Elem
);
260 #endif // QOS_DLS_SUPPORT //
263 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",Elem
->MsgType
));
268 VOID
CntlOidScanProc(
269 IN PRTMP_ADAPTER pAd
,
270 IN MLME_QUEUE_ELEM
*Elem
)
272 MLME_SCAN_REQ_STRUCT ScanReq
;
273 ULONG BssIdx
= BSS_NOT_FOUND
;
277 /* Disable scanning when ATE is running. */
280 #endif // RALINK_ATE //
283 // record current BSS if network is connected.
284 // 2003-2-13 do not include current IBSS if this is the only STA in this IBSS.
285 if (OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
))
287 BssIdx
= BssSsidTableSearch(&pAd
->ScanTab
, pAd
->CommonCfg
.Bssid
, (PUCHAR
)pAd
->CommonCfg
.Ssid
, pAd
->CommonCfg
.SsidLen
, pAd
->CommonCfg
.Channel
);
288 if (BssIdx
!= BSS_NOT_FOUND
)
290 NdisMoveMemory(&CurrBss
, &pAd
->ScanTab
.BssEntry
[BssIdx
], sizeof(BSS_ENTRY
));
294 // clean up previous SCAN result, add current BSS back to table if any
295 BssTableInit(&pAd
->ScanTab
);
296 if (BssIdx
!= BSS_NOT_FOUND
)
298 // DDK Note: If the NIC is associated with a particular BSSID and SSID
299 // that are not contained in the list of BSSIDs generated by this scan, the
300 // BSSID description of the currently associated BSSID and SSID should be
301 // appended to the list of BSSIDs in the NIC's database.
302 // To ensure this, we append this BSS as the first entry in SCAN result
303 NdisMoveMemory(&pAd
->ScanTab
.BssEntry
[0], &CurrBss
, sizeof(BSS_ENTRY
));
304 pAd
->ScanTab
.BssNr
= 1;
307 ScanParmFill(pAd
, &ScanReq
, (PSTRING
) Elem
->Msg
, Elem
->MsgLen
, BSS_ANY
, SCAN_ACTIVE
);
308 MlmeEnqueue(pAd
, SYNC_STATE_MACHINE
, MT2_MLME_SCAN_REQ
,
309 sizeof(MLME_SCAN_REQ_STRUCT
), &ScanReq
);
310 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_OID_LIST_SCAN
;
314 ==========================================================================
316 Before calling this routine, user desired SSID should already been
317 recorded in CommonCfg.Ssid[]
318 IRQL = DISPATCH_LEVEL
320 ==========================================================================
322 VOID
CntlOidSsidProc(
323 IN PRTMP_ADAPTER pAd
,
324 IN MLME_QUEUE_ELEM
* Elem
)
326 PNDIS_802_11_SSID pOidSsid
= (NDIS_802_11_SSID
*)Elem
->Msg
;
327 MLME_DISASSOC_REQ_STRUCT DisassocReq
;
331 // Step 1. record the desired user settings to MlmeAux
332 NdisZeroMemory(pAd
->MlmeAux
.Ssid
, MAX_LEN_OF_SSID
);
333 NdisMoveMemory(pAd
->MlmeAux
.Ssid
, pOidSsid
->Ssid
, pOidSsid
->SsidLength
);
334 pAd
->MlmeAux
.SsidLen
= (UCHAR
)pOidSsid
->SsidLength
;
335 NdisZeroMemory(pAd
->MlmeAux
.Bssid
, MAC_ADDR_LEN
);
336 pAd
->MlmeAux
.BssType
= pAd
->StaCfg
.BssType
;
338 pAd
->StaCfg
.bAutoConnectByBssid
= FALSE
;
341 // Update Reconnect Ssid, that user desired to connect.
343 NdisZeroMemory(pAd
->MlmeAux
.AutoReconnectSsid
, MAX_LEN_OF_SSID
);
344 NdisMoveMemory(pAd
->MlmeAux
.AutoReconnectSsid
, pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
);
345 pAd
->MlmeAux
.AutoReconnectSsidLen
= pAd
->MlmeAux
.SsidLen
;
347 // step 2. find all matching BSS in the lastest SCAN result (inBssTab)
348 // & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order
349 BssTableSsidSort(pAd
, &pAd
->MlmeAux
.SsidBssTab
, (PCHAR
)pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
);
351 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",
352 pAd
->MlmeAux
.SsidBssTab
.BssNr
, pAd
->ScanTab
.BssNr
, pAd
->MlmeAux
.SsidLen
, pAd
->MlmeAux
.Ssid
));
353 NdisGetSystemUpTime(&Now
);
355 if (OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
) &&
356 (pAd
->CommonCfg
.SsidLen
== pAd
->MlmeAux
.SsidBssTab
.BssEntry
[0].SsidLen
) &&
357 NdisEqualMemory(pAd
->CommonCfg
.Ssid
, pAd
->MlmeAux
.SsidBssTab
.BssEntry
[0].Ssid
, pAd
->CommonCfg
.SsidLen
) &&
358 MAC_ADDR_EQUAL(pAd
->CommonCfg
.Bssid
, pAd
->MlmeAux
.SsidBssTab
.BssEntry
[0].Bssid
))
360 // Case 1. already connected with an AP who has the desired SSID
363 // Add checking Mode "LEAP" for CCX 1.0
364 if (((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA
) ||
365 (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPAPSK
) ||
366 (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA2
) ||
367 (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA2PSK
)
369 (pAd
->StaCfg
.PortSecured
== WPA_802_1X_PORT_NOT_SECURED
))
371 // case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo
372 // connection process
373 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
374 DisassocParmFill(pAd
, &DisassocReq
, pAd
->CommonCfg
.Bssid
, REASON_DISASSOC_STA_LEAVING
);
375 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_DISASSOC_REQ
,
376 sizeof(MLME_DISASSOC_REQ_STRUCT
), &DisassocReq
);
377 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_DISASSOC
;
379 else if (pAd
->bConfigChanged
== TRUE
)
381 // case 1.2 Important Config has changed, we have to reconnect to the same AP
382 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));
383 DisassocParmFill(pAd
, &DisassocReq
, pAd
->CommonCfg
.Bssid
, REASON_DISASSOC_STA_LEAVING
);
384 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_DISASSOC_REQ
,
385 sizeof(MLME_DISASSOC_REQ_STRUCT
), &DisassocReq
);
386 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_DISASSOC
;
390 // case 1.3. already connected to the SSID with highest RSSI.
391 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));
393 // (HCT 12.1) 1c_wlan_mediaevents required
394 // media connect events are indicated when associating with the same AP
399 // Since MediaState already is NdisMediaStateConnected
400 // We just indicate the connect event again to meet the WHQL required.
402 pAd
->IndicateMediaState
= NdisMediaStateConnected
;
403 RTMP_IndicateMediaState(pAd
);
404 pAd
->ExtraInfo
= GENERAL_LINK_UP
; // Update extra information to link is up
407 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
408 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
409 RtmpOSWrielessEventSend(pAd
, SIOCGIWAP
, -1, &pAd
->MlmeAux
.Bssid
[0], NULL
, 0);
410 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
413 else if (INFRA_ON(pAd
))
417 // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
418 // RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect
419 // But media status is connected, so the SSID not report correctly.
421 if (!SSID_EQUAL(pAd
->CommonCfg
.Ssid
, pAd
->CommonCfg
.SsidLen
, pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
))
424 // Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event.
426 pAd
->MlmeAux
.CurrReqIsFromNdis
= TRUE
;
428 // case 2. active INFRA association existent
429 // roaming is done within miniport driver, nothing to do with configuration
430 // utility. so upon a new SET(OID_802_11_SSID) is received, we just
431 // disassociate with the current associated AP,
432 // then perform a new association with this new SSID, no matter the
433 // new/old SSID are the same or not.
434 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
435 DisassocParmFill(pAd
, &DisassocReq
, pAd
->CommonCfg
.Bssid
, REASON_DISASSOC_STA_LEAVING
);
436 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_DISASSOC_REQ
,
437 sizeof(MLME_DISASSOC_REQ_STRUCT
), &DisassocReq
);
438 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_DISASSOC
;
444 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));
445 LinkDown(pAd
, FALSE
);
446 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
);
447 pAd
->IndicateMediaState
= NdisMediaStateDisconnected
;
448 RTMP_IndicateMediaState(pAd
);
449 pAd
->ExtraInfo
= GENERAL_LINK_DOWN
;
450 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
453 if ((pAd
->MlmeAux
.SsidBssTab
.BssNr
== 0) &&
454 (pAd
->StaCfg
.bAutoReconnect
== TRUE
) &&
455 (pAd
->MlmeAux
.BssType
== BSS_INFRA
) &&
456 (MlmeValidateSSID(pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
) == TRUE
)
459 MLME_SCAN_REQ_STRUCT ScanReq
;
461 DBGPRINT(RT_DEBUG_TRACE
, ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));
462 ScanParmFill(pAd
, &ScanReq
, (PSTRING
) pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
, BSS_ANY
, SCAN_ACTIVE
);
463 MlmeEnqueue(pAd
, SYNC_STATE_MACHINE
, MT2_MLME_SCAN_REQ
, sizeof(MLME_SCAN_REQ_STRUCT
), &ScanReq
);
464 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_OID_LIST_SCAN
;
465 // Reset Missed scan number
466 pAd
->StaCfg
.LastScanTime
= Now
;
471 pAd
->MlmeAux
.BssIdx
= 0;
472 IterateOnBssTab(pAd
);
479 ==========================================================================
482 IRQL = DISPATCH_LEVEL
484 ==========================================================================
486 VOID
CntlOidRTBssidProc(
487 IN PRTMP_ADAPTER pAd
,
488 IN MLME_QUEUE_ELEM
* Elem
)
491 PUCHAR pOidBssid
= (PUCHAR
)Elem
->Msg
;
492 MLME_DISASSOC_REQ_STRUCT DisassocReq
;
493 MLME_JOIN_REQ_STRUCT JoinReq
;
496 /* No need to perform this routine when ATE is running. */
499 #endif // RALINK_ATE //
501 // record user desired settings
502 COPY_MAC_ADDR(pAd
->MlmeAux
.Bssid
, pOidBssid
);
503 pAd
->MlmeAux
.BssType
= pAd
->StaCfg
.BssType
;
505 // find the desired BSS in the latest SCAN result table
506 BssIdx
= BssTableSearch(&pAd
->ScanTab
, pOidBssid
, pAd
->MlmeAux
.Channel
);
507 if (BssIdx
== BSS_NOT_FOUND
)
509 MLME_SCAN_REQ_STRUCT ScanReq
;
511 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));
512 //pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
514 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - BSSID not found. start a new scan\n"));
515 ScanParmFill(pAd
, &ScanReq
, (PSTRING
) pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
, BSS_ANY
, SCAN_ACTIVE
);
516 MlmeEnqueue(pAd
, SYNC_STATE_MACHINE
, MT2_MLME_SCAN_REQ
, sizeof(MLME_SCAN_REQ_STRUCT
), &ScanReq
);
517 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_OID_LIST_SCAN
;
518 // Reset Missed scan number
519 NdisGetSystemUpTime(&pAd
->StaCfg
.LastScanTime
);
524 // Update Reconnect Ssid, that user desired to connect.
526 NdisZeroMemory(pAd
->MlmeAux
.AutoReconnectSsid
, MAX_LEN_OF_SSID
);
527 pAd
->MlmeAux
.AutoReconnectSsidLen
= pAd
->ScanTab
.BssEntry
[BssIdx
].SsidLen
;
528 NdisMoveMemory(pAd
->MlmeAux
.AutoReconnectSsid
, pAd
->ScanTab
.BssEntry
[BssIdx
].Ssid
, pAd
->ScanTab
.BssEntry
[BssIdx
].SsidLen
);
530 // copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why?
531 // Because we need this entry to become the JOIN target in later on SYNC state machine
532 pAd
->MlmeAux
.BssIdx
= 0;
533 pAd
->MlmeAux
.SsidBssTab
.BssNr
= 1;
534 NdisMoveMemory(&pAd
->MlmeAux
.SsidBssTab
.BssEntry
[0], &pAd
->ScanTab
.BssEntry
[BssIdx
], sizeof(BSS_ENTRY
));
536 // Add SSID into MlmeAux for site surey joining hidden SSID
537 pAd
->MlmeAux
.SsidLen
= pAd
->ScanTab
.BssEntry
[BssIdx
].SsidLen
;
538 NdisMoveMemory(pAd
->MlmeAux
.Ssid
, pAd
->ScanTab
.BssEntry
[BssIdx
].Ssid
, pAd
->MlmeAux
.SsidLen
);
543 // disassoc from current AP first
544 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - disassociate with current AP ...\n"));
545 DisassocParmFill(pAd
, &DisassocReq
, pAd
->CommonCfg
.Bssid
, REASON_DISASSOC_STA_LEAVING
);
546 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_DISASSOC_REQ
,
547 sizeof(MLME_DISASSOC_REQ_STRUCT
), &DisassocReq
);
549 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_DISASSOC
;
555 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - drop current ADHOC\n"));
556 LinkDown(pAd
, FALSE
);
557 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
);
558 pAd
->IndicateMediaState
= NdisMediaStateDisconnected
;
559 RTMP_IndicateMediaState(pAd
);
560 pAd
->ExtraInfo
= GENERAL_LINK_DOWN
;
561 DBGPRINT(RT_DEBUG_TRACE
, ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
564 // Change the wepstatus to original wepstatus
565 pAd
->StaCfg
.WepStatus
= pAd
->StaCfg
.OrigWepStatus
;
566 pAd
->StaCfg
.PairCipher
= pAd
->StaCfg
.OrigWepStatus
;
567 pAd
->StaCfg
.GroupCipher
= pAd
->StaCfg
.OrigWepStatus
;
569 // Check cipher suite, AP must have more secured cipher than station setting
570 // Set the Pairwise and Group cipher to match the intended AP setting
571 // We can only connect to AP with less secured cipher setting
572 if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA
) || (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPAPSK
))
574 pAd
->StaCfg
.GroupCipher
= pAd
->ScanTab
.BssEntry
[BssIdx
].WPA
.GroupCipher
;
576 if (pAd
->StaCfg
.WepStatus
== pAd
->ScanTab
.BssEntry
[BssIdx
].WPA
.PairCipher
)
577 pAd
->StaCfg
.PairCipher
= pAd
->ScanTab
.BssEntry
[BssIdx
].WPA
.PairCipher
;
578 else if (pAd
->ScanTab
.BssEntry
[BssIdx
].WPA
.PairCipherAux
!= Ndis802_11WEPDisabled
)
579 pAd
->StaCfg
.PairCipher
= pAd
->ScanTab
.BssEntry
[BssIdx
].WPA
.PairCipherAux
;
580 else // There is no PairCipher Aux, downgrade our capability to TKIP
581 pAd
->StaCfg
.PairCipher
= Ndis802_11Encryption2Enabled
;
583 else if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA2
) || (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA2PSK
))
585 pAd
->StaCfg
.GroupCipher
= pAd
->ScanTab
.BssEntry
[BssIdx
].WPA2
.GroupCipher
;
587 if (pAd
->StaCfg
.WepStatus
== pAd
->ScanTab
.BssEntry
[BssIdx
].WPA2
.PairCipher
)
588 pAd
->StaCfg
.PairCipher
= pAd
->ScanTab
.BssEntry
[BssIdx
].WPA2
.PairCipher
;
589 else if (pAd
->ScanTab
.BssEntry
[BssIdx
].WPA2
.PairCipherAux
!= Ndis802_11WEPDisabled
)
590 pAd
->StaCfg
.PairCipher
= pAd
->ScanTab
.BssEntry
[BssIdx
].WPA2
.PairCipherAux
;
591 else // There is no PairCipher Aux, downgrade our capability to TKIP
592 pAd
->StaCfg
.PairCipher
= Ndis802_11Encryption2Enabled
;
595 pAd
->StaCfg
.RsnCapability
= pAd
->ScanTab
.BssEntry
[BssIdx
].WPA2
.RsnCapability
;
598 // Set Mix cipher flag
599 pAd
->StaCfg
.bMixCipher
= (pAd
->StaCfg
.PairCipher
== pAd
->StaCfg
.GroupCipher
) ? FALSE
: TRUE
;
600 /*if (pAd->StaCfg.bMixCipher == TRUE)
602 // If mix cipher, re-build RSNIE
603 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
605 // No active association, join the BSS immediately
606 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",
607 pOidBssid
[0],pOidBssid
[1],pOidBssid
[2],pOidBssid
[3],pOidBssid
[4],pOidBssid
[5]));
609 JoinParmFill(pAd
, &JoinReq
, pAd
->MlmeAux
.BssIdx
);
610 MlmeEnqueue(pAd
, SYNC_STATE_MACHINE
, MT2_MLME_JOIN_REQ
, sizeof(MLME_JOIN_REQ_STRUCT
), &JoinReq
);
612 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_JOIN
;
617 // Roaming is the only external request triggering CNTL state machine
618 // despite of other "SET OID" operation. All "SET OID" related oerations
619 // happen in sequence, because no other SET OID will be sent to this device
620 // until the the previous SET operation is complete (successful o failed).
621 // So, how do we quarantee this ROAMING request won't corrupt other "SET OID"?
622 // or been corrupted by other "SET OID"?
624 // IRQL = DISPATCH_LEVEL
625 VOID
CntlMlmeRoamingProc(
626 IN PRTMP_ADAPTER pAd
,
627 IN MLME_QUEUE_ELEM
*Elem
)
631 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - Roaming in MlmeAux.RoamTab...\n"));
634 //Let BBP register at 20MHz to do (fast) roaming.
635 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &BBPValue
);
637 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, BBPValue
);
639 NdisMoveMemory(&pAd
->MlmeAux
.SsidBssTab
, &pAd
->MlmeAux
.RoamTab
, sizeof(pAd
->MlmeAux
.RoamTab
));
640 pAd
->MlmeAux
.SsidBssTab
.BssNr
= pAd
->MlmeAux
.RoamTab
.BssNr
;
642 BssTableSortByRssi(&pAd
->MlmeAux
.SsidBssTab
);
643 pAd
->MlmeAux
.BssIdx
= 0;
644 IterateOnBssTab(pAd
);
648 #ifdef QOS_DLS_SUPPORT
650 ==========================================================================
653 IRQL = DISPATCH_LEVEL
655 ==========================================================================
657 VOID
CntlOidDLSSetupProc(
658 IN PRTMP_ADAPTER pAd
,
659 IN MLME_QUEUE_ELEM
*Elem
)
661 PRT_802_11_DLS pDLS
= (PRT_802_11_DLS
)Elem
->Msg
;
662 MLME_DLS_REQ_STRUCT MlmeDlsReq
;
664 USHORT reason
= REASON_UNSPECIFY
;
666 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - (OID set %02x:%02x:%02x:%02x:%02x:%02x with Valid=%d, Status=%d, TimeOut=%d, CountDownTimer=%d)\n",
667 pDLS
->MacAddr
[0], pDLS
->MacAddr
[1], pDLS
->MacAddr
[2], pDLS
->MacAddr
[3], pDLS
->MacAddr
[4], pDLS
->MacAddr
[5],
668 pDLS
->Valid
, pDLS
->Status
, pDLS
->TimeOut
, pDLS
->CountDownTimer
));
670 if (!pAd
->CommonCfg
.bDLSCapable
)
673 // DLS will not be supported when Adhoc mode
676 for (i
= 0; i
< MAX_NUM_OF_DLS_ENTRY
; i
++)
678 if (pDLS
->Valid
&& pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
) &&
679 (pDLS
->TimeOut
== pAd
->StaCfg
.DLSEntry
[i
].TimeOut
) && MAC_ADDR_EQUAL(pDLS
->MacAddr
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
))
681 // 1. Same setting, just drop it
682 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - setting unchanged\n"));
685 else if (!pDLS
->Valid
&& pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
) &&
686 MAC_ADDR_EQUAL(pDLS
->MacAddr
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
))
688 // 2. Disable DLS link case, just tear down DLS link
689 reason
= REASON_QOS_UNWANTED_MECHANISM
;
690 pAd
->StaCfg
.DLSEntry
[i
].Valid
= FALSE
;
691 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
692 DlsParmFill(pAd
, &MlmeDlsReq
, &pAd
->StaCfg
.DLSEntry
[i
], reason
);
693 MlmeEnqueue(pAd
, DLS_STATE_MACHINE
, MT2_MLME_DLS_TEAR_DOWN
, sizeof(MLME_DLS_REQ_STRUCT
), &MlmeDlsReq
);
694 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - start tear down procedure\n"));
697 else if ((i
< MAX_NUM_OF_DLS_ENTRY
) && pDLS
->Valid
&& !pAd
->StaCfg
.DLSEntry
[i
].Valid
)
699 // 3. Enable case, start DLS setup procedure
700 NdisMoveMemory(&pAd
->StaCfg
.DLSEntry
[i
], pDLS
, sizeof(RT_802_11_DLS_UI
));
702 //Update countdown timer
703 pAd
->StaCfg
.DLSEntry
[i
].CountDownTimer
= pAd
->StaCfg
.DLSEntry
[i
].TimeOut
;
704 DlsParmFill(pAd
, &MlmeDlsReq
, &pAd
->StaCfg
.DLSEntry
[i
], reason
);
705 MlmeEnqueue(pAd
, DLS_STATE_MACHINE
, MT2_MLME_DLS_REQ
, sizeof(MLME_DLS_REQ_STRUCT
), &MlmeDlsReq
);
706 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - DLS setup case\n"));
709 else if ((i
< MAX_NUM_OF_DLS_ENTRY
) && pDLS
->Valid
&& pAd
->StaCfg
.DLSEntry
[i
].Valid
&&
710 (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
) && !MAC_ADDR_EQUAL(pDLS
->MacAddr
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
))
712 // 4. update mac case, tear down old DLS and setup new DLS
713 reason
= REASON_QOS_UNWANTED_MECHANISM
;
714 pAd
->StaCfg
.DLSEntry
[i
].Valid
= FALSE
;
715 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
716 DlsParmFill(pAd
, &MlmeDlsReq
, &pAd
->StaCfg
.DLSEntry
[i
], reason
);
717 MlmeEnqueue(pAd
, DLS_STATE_MACHINE
, MT2_MLME_DLS_TEAR_DOWN
, sizeof(MLME_DLS_REQ_STRUCT
), &MlmeDlsReq
);
718 NdisMoveMemory(&pAd
->StaCfg
.DLSEntry
[i
], pDLS
, sizeof(RT_802_11_DLS_UI
));
719 DlsParmFill(pAd
, &MlmeDlsReq
, &pAd
->StaCfg
.DLSEntry
[i
], reason
);
720 MlmeEnqueue(pAd
, DLS_STATE_MACHINE
, MT2_MLME_DLS_REQ
, sizeof(MLME_DLS_REQ_STRUCT
), &MlmeDlsReq
);
721 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - DLS tear down and restart case\n"));
724 else if (pDLS
->Valid
&& pAd
->StaCfg
.DLSEntry
[i
].Valid
&&
725 MAC_ADDR_EQUAL(pDLS
->MacAddr
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
) && (pAd
->StaCfg
.DLSEntry
[i
].TimeOut
!= pDLS
->TimeOut
))
727 // 5. update timeout case, start DLS setup procedure (no tear down)
728 pAd
->StaCfg
.DLSEntry
[i
].TimeOut
= pDLS
->TimeOut
;
729 //Update countdown timer
730 pAd
->StaCfg
.DLSEntry
[i
].CountDownTimer
= pAd
->StaCfg
.DLSEntry
[i
].TimeOut
;
731 DlsParmFill(pAd
, &MlmeDlsReq
, &pAd
->StaCfg
.DLSEntry
[i
], reason
);
732 MlmeEnqueue(pAd
, DLS_STATE_MACHINE
, MT2_MLME_DLS_REQ
, sizeof(MLME_DLS_REQ_STRUCT
), &MlmeDlsReq
);
733 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - DLS update timeout case\n"));
736 else if (pDLS
->Valid
&& pAd
->StaCfg
.DLSEntry
[i
].Valid
&&
737 (pAd
->StaCfg
.DLSEntry
[i
].Status
!= DLS_FINISH
) && MAC_ADDR_EQUAL(pDLS
->MacAddr
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
))
739 // 6. re-setup case, start DLS setup procedure (no tear down)
740 DlsParmFill(pAd
, &MlmeDlsReq
, &pAd
->StaCfg
.DLSEntry
[i
], reason
);
741 MlmeEnqueue(pAd
, DLS_STATE_MACHINE
, MT2_MLME_DLS_REQ
, sizeof(MLME_DLS_REQ_STRUCT
), &MlmeDlsReq
);
742 DBGPRINT(RT_DEBUG_TRACE
,("CNTL - DLS retry setup procedure\n"));
747 DBGPRINT(RT_DEBUG_WARN
,("CNTL - DLS not changed in entry - %d - Valid=%d, Status=%d, TimeOut=%d\n",
748 i
, pAd
->StaCfg
.DLSEntry
[i
].Valid
, pAd
->StaCfg
.DLSEntry
[i
].Status
, pAd
->StaCfg
.DLSEntry
[i
].TimeOut
));
753 #endif // QOS_DLS_SUPPORT //
756 ==========================================================================
759 IRQL = DISPATCH_LEVEL
761 ==========================================================================
763 VOID
CntlWaitDisassocProc(
764 IN PRTMP_ADAPTER pAd
,
765 IN MLME_QUEUE_ELEM
*Elem
)
767 MLME_START_REQ_STRUCT StartReq
;
769 if (Elem
->MsgType
== MT2_DISASSOC_CONF
)
771 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Dis-associate successful\n"));
773 if (pAd
->CommonCfg
.bWirelessEvent
)
775 RTMPSendWirelessEvent(pAd
, IW_DISASSOC_EVENT_FLAG
, pAd
->MacTab
.Content
[BSSID_WCID
].Addr
, BSS0
, 0);
778 LinkDown(pAd
, FALSE
);
780 // case 1. no matching BSS, and user wants ADHOC, so we just start a new one
781 if ((pAd
->MlmeAux
.SsidBssTab
.BssNr
==0) && (pAd
->StaCfg
.BssType
== BSS_ADHOC
))
783 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",pAd
->MlmeAux
.Ssid
));
784 StartParmFill(pAd
, &StartReq
, (PCHAR
)pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
);
785 MlmeEnqueue(pAd
, SYNC_STATE_MACHINE
, MT2_MLME_START_REQ
, sizeof(MLME_START_REQ_STRUCT
), &StartReq
);
786 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_START
;
788 // case 2. try each matched BSS
791 pAd
->MlmeAux
.BssIdx
= 0;
793 IterateOnBssTab(pAd
);
799 ==========================================================================
802 IRQL = DISPATCH_LEVEL
804 ==========================================================================
806 VOID
CntlWaitJoinProc(
807 IN PRTMP_ADAPTER pAd
,
808 IN MLME_QUEUE_ELEM
*Elem
)
811 MLME_AUTH_REQ_STRUCT AuthReq
;
813 if (Elem
->MsgType
== MT2_JOIN_CONF
)
815 NdisMoveMemory(&Reason
, Elem
->Msg
, sizeof(USHORT
));
816 if (Reason
== MLME_SUCCESS
)
818 // 1. joined an IBSS, we are pretty much done here
819 if (pAd
->MlmeAux
.BssType
== BSS_ADHOC
)
822 // 5G bands rules of Japan:
823 // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
825 if ( (pAd
->CommonCfg
.bIEEE80211H
== 1) &&
826 RadarChannelCheck(pAd
, pAd
->CommonCfg
.Channel
)
829 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
830 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd
->CommonCfg
.Channel
));
834 LinkUp(pAd
, BSS_ADHOC
);
835 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
836 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
837 pAd
->CommonCfg
.Bssid
[0],pAd
->CommonCfg
.Bssid
[1],pAd
->CommonCfg
.Bssid
[2],
838 pAd
->CommonCfg
.Bssid
[3],pAd
->CommonCfg
.Bssid
[4],pAd
->CommonCfg
.Bssid
[5]));
840 pAd
->IndicateMediaState
= NdisMediaStateConnected
;
841 pAd
->ExtraInfo
= GENERAL_LINK_UP
;
843 // 2. joined a new INFRA network, start from authentication
847 // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
848 if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeShared
) ||
849 (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeAutoSwitch
))
851 AuthParmFill(pAd
, &AuthReq
, pAd
->MlmeAux
.Bssid
, AUTH_MODE_KEY
);
855 AuthParmFill(pAd
, &AuthReq
, pAd
->MlmeAux
.Bssid
, AUTH_MODE_OPEN
);
857 MlmeEnqueue(pAd
, AUTH_STATE_MACHINE
, MT2_MLME_AUTH_REQ
,
858 sizeof(MLME_AUTH_REQ_STRUCT
), &AuthReq
);
861 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_AUTH
;
866 // 3. failed, try next BSS
867 pAd
->MlmeAux
.BssIdx
++;
868 IterateOnBssTab(pAd
);
875 ==========================================================================
878 IRQL = DISPATCH_LEVEL
880 ==========================================================================
882 VOID
CntlWaitStartProc(
883 IN PRTMP_ADAPTER pAd
,
884 IN MLME_QUEUE_ELEM
*Elem
)
888 if (Elem
->MsgType
== MT2_START_CONF
)
890 NdisMoveMemory(&Result
, Elem
->Msg
, sizeof(USHORT
));
891 if (Result
== MLME_SUCCESS
)
894 // 5G bands rules of Japan:
895 // Ad hoc must be disabled in W53(ch52,56,60,64) channels.
897 if ( (pAd
->CommonCfg
.bIEEE80211H
== 1) &&
898 RadarChannelCheck(pAd
, pAd
->CommonCfg
.Channel
)
901 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
902 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n", pAd
->CommonCfg
.Channel
));
905 #ifdef DOT11_N_SUPPORT
906 NdisZeroMemory(&pAd
->StaActive
.SupportedPhyInfo
.MCSSet
[0], 16);
907 if (pAd
->CommonCfg
.PhyMode
>= PHY_11ABGN_MIXED
)
911 NdisMoveMemory(&pAd
->MlmeAux
.AddHtInfo
, &pAd
->CommonCfg
.AddHTInfo
, sizeof(ADD_HT_INFO_IE
));
912 RTMPCheckHt(pAd
, BSSID_WCID
, &pAd
->CommonCfg
.HtCapability
, &pAd
->CommonCfg
.AddHTInfo
);
913 pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
= TRUE
;
914 NdisMoveMemory(&pAd
->StaActive
.SupportedPhyInfo
.MCSSet
[0], &pAd
->CommonCfg
.HtCapability
.MCSSet
[0], 16);
915 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd
);
917 if ((pAd
->CommonCfg
.HtCapability
.HtCapInfo
.ChannelWidth
== BW_40
) &&
918 (pAd
->CommonCfg
.AddHTInfo
.AddHtInfo
.ExtChanOffset
== EXTCHA_ABOVE
))
920 pAd
->MlmeAux
.CentralChannel
= pAd
->CommonCfg
.Channel
+ 2;
922 else if ((pAd
->CommonCfg
.HtCapability
.HtCapInfo
.ChannelWidth
== BW_40
) &&
923 (pAd
->CommonCfg
.AddHTInfo
.AddHtInfo
.ExtChanOffset
== EXTCHA_BELOW
))
925 pAd
->MlmeAux
.CentralChannel
= pAd
->CommonCfg
.Channel
- 2;
929 #endif // DOT11_N_SUPPORT //
931 pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
= FALSE
;
933 LinkUp(pAd
, BSS_ADHOC
);
934 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
935 // Before send beacon, driver need do radar detection
936 if ((pAd
->CommonCfg
.Channel
> 14 )
937 && (pAd
->CommonCfg
.bIEEE80211H
== 1)
938 && RadarChannelCheck(pAd
, pAd
->CommonCfg
.Channel
))
940 pAd
->CommonCfg
.RadarDetect
.RDMode
= RD_SILENCE_MODE
;
941 pAd
->CommonCfg
.RadarDetect
.RDCount
= 0;
943 BbpRadarDetectionStart(pAd
);
944 #endif // DFS_SUPPORT //
947 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
948 pAd
->CommonCfg
.Bssid
[0],pAd
->CommonCfg
.Bssid
[1],pAd
->CommonCfg
.Bssid
[2],
949 pAd
->CommonCfg
.Bssid
[3],pAd
->CommonCfg
.Bssid
[4],pAd
->CommonCfg
.Bssid
[5]));
953 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Start IBSS fail. BUG!!!!!\n"));
954 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
960 ==========================================================================
963 IRQL = DISPATCH_LEVEL
965 ==========================================================================
967 VOID
CntlWaitAuthProc(
968 IN PRTMP_ADAPTER pAd
,
969 IN MLME_QUEUE_ELEM
*Elem
)
972 MLME_ASSOC_REQ_STRUCT AssocReq
;
973 MLME_AUTH_REQ_STRUCT AuthReq
;
975 if (Elem
->MsgType
== MT2_AUTH_CONF
)
977 NdisMoveMemory(&Reason
, Elem
->Msg
, sizeof(USHORT
));
978 if (Reason
== MLME_SUCCESS
)
980 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - AUTH OK\n"));
981 AssocParmFill(pAd
, &AssocReq
, pAd
->MlmeAux
.Bssid
, pAd
->MlmeAux
.CapabilityInfo
,
982 ASSOC_TIMEOUT
, pAd
->StaCfg
.DefaultListenCount
);
985 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_ASSOC_REQ
,
986 sizeof(MLME_ASSOC_REQ_STRUCT
), &AssocReq
);
988 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_ASSOC
;
993 // This fail may because of the AP already keep us in its MAC table without
994 // ageing-out. The previous authentication attempt must have let it remove us.
995 // so try Authentication again may help. For D-Link DWL-900AP+ compatibility.
996 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - AUTH FAIL, try again...\n"));
998 if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeShared
) ||
999 (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeAutoSwitch
))
1001 // either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first
1002 AuthParmFill(pAd
, &AuthReq
, pAd
->MlmeAux
.Bssid
, AUTH_MODE_KEY
);
1006 AuthParmFill(pAd
, &AuthReq
, pAd
->MlmeAux
.Bssid
, AUTH_MODE_OPEN
);
1008 MlmeEnqueue(pAd
, AUTH_STATE_MACHINE
, MT2_MLME_AUTH_REQ
,
1009 sizeof(MLME_AUTH_REQ_STRUCT
), &AuthReq
);
1012 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_AUTH2
;
1018 ==========================================================================
1021 IRQL = DISPATCH_LEVEL
1023 ==========================================================================
1025 VOID
CntlWaitAuthProc2(
1026 IN PRTMP_ADAPTER pAd
,
1027 IN MLME_QUEUE_ELEM
*Elem
)
1030 MLME_ASSOC_REQ_STRUCT AssocReq
;
1031 MLME_AUTH_REQ_STRUCT AuthReq
;
1033 if (Elem
->MsgType
== MT2_AUTH_CONF
)
1035 NdisMoveMemory(&Reason
, Elem
->Msg
, sizeof(USHORT
));
1036 if (Reason
== MLME_SUCCESS
)
1038 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - AUTH OK\n"));
1039 AssocParmFill(pAd
, &AssocReq
, pAd
->MlmeAux
.Bssid
, pAd
->MlmeAux
.CapabilityInfo
,
1040 ASSOC_TIMEOUT
, pAd
->StaCfg
.DefaultListenCount
);
1042 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_ASSOC_REQ
,
1043 sizeof(MLME_ASSOC_REQ_STRUCT
), &AssocReq
);
1045 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_ASSOC
;
1050 if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeAutoSwitch
) &&
1051 (pAd
->MlmeAux
.Alg
== Ndis802_11AuthModeShared
))
1053 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - AUTH FAIL, try OPEN system...\n"));
1054 AuthParmFill(pAd
, &AuthReq
, pAd
->MlmeAux
.Bssid
, Ndis802_11AuthModeOpen
);
1055 MlmeEnqueue(pAd
, AUTH_STATE_MACHINE
, MT2_MLME_AUTH_REQ
,
1056 sizeof(MLME_AUTH_REQ_STRUCT
), &AuthReq
);
1058 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_AUTH2
;
1062 // not success, try next BSS
1063 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - AUTH FAIL, give up; try next BSS\n"));
1064 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
; //???????
1065 pAd
->MlmeAux
.BssIdx
++;
1066 IterateOnBssTab(pAd
);
1073 ==========================================================================
1076 IRQL = DISPATCH_LEVEL
1078 ==========================================================================
1080 VOID
CntlWaitAssocProc(
1081 IN PRTMP_ADAPTER pAd
,
1082 IN MLME_QUEUE_ELEM
*Elem
)
1086 if (Elem
->MsgType
== MT2_ASSOC_CONF
)
1088 NdisMoveMemory(&Reason
, Elem
->Msg
, sizeof(USHORT
));
1089 if (Reason
== MLME_SUCCESS
)
1091 if (pAd
->CommonCfg
.bWirelessEvent
)
1093 RTMPSendWirelessEvent(pAd
, IW_ASSOC_EVENT_FLAG
, pAd
->MacTab
.Content
[BSSID_WCID
].Addr
, BSS0
, 0);
1096 LinkUp(pAd
, BSS_INFRA
);
1097 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
1098 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Association successful on BSS #%ld\n",pAd
->MlmeAux
.BssIdx
));
1102 // not success, try next BSS
1103 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Association fails on BSS #%ld\n",pAd
->MlmeAux
.BssIdx
));
1104 pAd
->MlmeAux
.BssIdx
++;
1105 IterateOnBssTab(pAd
);
1111 ==========================================================================
1114 IRQL = DISPATCH_LEVEL
1116 ==========================================================================
1118 VOID
CntlWaitReassocProc(
1119 IN PRTMP_ADAPTER pAd
,
1120 IN MLME_QUEUE_ELEM
*Elem
)
1124 if (Elem
->MsgType
== MT2_REASSOC_CONF
)
1126 NdisMoveMemory(&Result
, Elem
->Msg
, sizeof(USHORT
));
1127 if (Result
== MLME_SUCCESS
)
1129 // send wireless event - for association
1130 if (pAd
->CommonCfg
.bWirelessEvent
)
1131 RTMPSendWirelessEvent(pAd
, IW_ASSOC_EVENT_FLAG
, pAd
->MacTab
.Content
[BSSID_WCID
].Addr
, BSS0
, 0);
1134 // NDIS requires a new Link UP indication but no Link Down for RE-ASSOC
1136 LinkUp(pAd
, BSS_INFRA
);
1138 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
1139 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Re-assocition successful on BSS #%ld\n", pAd
->MlmeAux
.RoamIdx
));
1143 // reassoc failed, try to pick next BSS in the BSS Table
1144 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - Re-assocition fails on BSS #%ld\n", pAd
->MlmeAux
.RoamIdx
));
1146 pAd
->MlmeAux
.RoamIdx
++;
1147 IterateOnBssTab2(pAd
);
1154 VOID
AdhocTurnOnQos(
1155 IN PRTMP_ADAPTER pAd
)
1157 #define AC0_DEF_TXOP 0
1158 #define AC1_DEF_TXOP 0
1159 #define AC2_DEF_TXOP 94
1160 #define AC3_DEF_TXOP 47
1162 // Turn on QOs if use HT rate.
1163 if (pAd
->CommonCfg
.APEdcaParm
.bValid
== FALSE
)
1165 pAd
->CommonCfg
.APEdcaParm
.bValid
= TRUE
;
1166 pAd
->CommonCfg
.APEdcaParm
.Aifsn
[0] = 3;
1167 pAd
->CommonCfg
.APEdcaParm
.Aifsn
[1] = 7;
1168 pAd
->CommonCfg
.APEdcaParm
.Aifsn
[2] = 1;
1169 pAd
->CommonCfg
.APEdcaParm
.Aifsn
[3] = 1;
1171 pAd
->CommonCfg
.APEdcaParm
.Cwmin
[0] = 4;
1172 pAd
->CommonCfg
.APEdcaParm
.Cwmin
[1] = 4;
1173 pAd
->CommonCfg
.APEdcaParm
.Cwmin
[2] = 3;
1174 pAd
->CommonCfg
.APEdcaParm
.Cwmin
[3] = 2;
1176 pAd
->CommonCfg
.APEdcaParm
.Cwmax
[0] = 10;
1177 pAd
->CommonCfg
.APEdcaParm
.Cwmax
[1] = 6;
1178 pAd
->CommonCfg
.APEdcaParm
.Cwmax
[2] = 4;
1179 pAd
->CommonCfg
.APEdcaParm
.Cwmax
[3] = 3;
1181 pAd
->CommonCfg
.APEdcaParm
.Txop
[0] = 0;
1182 pAd
->CommonCfg
.APEdcaParm
.Txop
[1] = 0;
1183 pAd
->CommonCfg
.APEdcaParm
.Txop
[2] = AC2_DEF_TXOP
;
1184 pAd
->CommonCfg
.APEdcaParm
.Txop
[3] = AC3_DEF_TXOP
;
1186 AsicSetEdcaParm(pAd
, &pAd
->CommonCfg
.APEdcaParm
);
1190 ==========================================================================
1193 IRQL = DISPATCH_LEVEL
1195 ==========================================================================
1198 IN PRTMP_ADAPTER pAd
,
1204 UCHAR Value
= 0, idx
= 0, HashIdx
= 0;
1205 MAC_TABLE_ENTRY
*pEntry
= NULL
, *pCurrEntry
= NULL
;
1207 // Init ChannelQuality to prevent DEAD_CQI at initial LinkUp
1208 pAd
->Mlme
.ChannelQuality
= 50;
1210 pEntry
= MacTableLookup(pAd
, pAd
->CommonCfg
.Bssid
);
1213 MacTableDeleteEntry(pAd
, pEntry
->Aid
, pEntry
->Addr
);
1218 pEntry
= &pAd
->MacTab
.Content
[BSSID_WCID
];
1221 // ASSOC - DisassocTimeoutAction
1222 // CNTL - Dis-associate successful
1223 // !!! LINK DOWN !!!
1224 // [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: )
1226 // To prevent DisassocTimeoutAction to call Link down after we link up,
1227 // cancel the DisassocTimer no matter what it start or not.
1229 RTMPCancelTimer(&pAd
->MlmeAux
.DisassocTimer
, &Cancelled
);
1231 COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd
);
1233 #ifdef DOT11_N_SUPPORT
1234 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd
);
1235 #endif // DOT11_N_SUPPORT //
1238 // Before power save before link up function, We will force use 1R.
1239 // So after link up, check Rx antenna # again.
1240 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &Value
);
1241 if(pAd
->Antenna
.field
.RxPath
== 3)
1245 else if(pAd
->Antenna
.field
.RxPath
== 2)
1249 else if(pAd
->Antenna
.field
.RxPath
== 1)
1253 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, Value
);
1254 pAd
->StaCfg
.BBPR3
= Value
;
1255 #endif // RTMP_MAC_PCI //
1257 if (BssType
== BSS_ADHOC
)
1259 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_ADHOC_ON
);
1260 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_INFRA_ON
);
1262 #ifdef CARRIER_DETECTION_SUPPORT // Roger sync Carrier
1263 // No carrier detection when adhoc
1264 // CarrierDetectionStop(pAd);
1265 pAd
->CommonCfg
.CarrierDetect
.CD_State
= CD_NORMAL
;
1266 #endif // CARRIER_DETECTION_SUPPORT //
1268 #ifdef DOT11_N_SUPPORT
1269 if (pAd
->CommonCfg
.PhyMode
>= PHY_11ABGN_MIXED
)
1270 AdhocTurnOnQos(pAd
);
1271 #endif // DOT11_N_SUPPORT //
1273 DBGPRINT(RT_DEBUG_TRACE
, ("!!!Adhoc LINK UP !!! \n" ));
1277 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_INFRA_ON
);
1278 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_ADHOC_ON
);
1280 DBGPRINT(RT_DEBUG_TRACE
, ("!!!Infra LINK UP !!! \n" ));
1284 // reset Tx beamforming bit
1285 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &Value
);
1287 Value
|= pAd
->CommonCfg
.RegTransmitSetting
.field
.TxBF
;
1288 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, Value
);
1290 #ifdef DOT11_N_SUPPORT
1291 // Change to AP channel
1292 if ((pAd
->CommonCfg
.CentralChannel
> pAd
->CommonCfg
.Channel
) && (pAd
->MlmeAux
.HtCapability
.HtCapInfo
.ChannelWidth
== BW_40
))
1294 // Must using 40MHz.
1295 pAd
->CommonCfg
.BBPCurrentBW
= BW_40
;
1296 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.CentralChannel
, FALSE
);
1297 AsicLockChannel(pAd
, pAd
->CommonCfg
.CentralChannel
);
1299 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &Value
);
1302 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, Value
);
1304 // RX : control channel at lower
1305 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &Value
);
1307 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, Value
);
1309 pAd
->StaCfg
.BBPR3
= Value
;
1310 #endif // RTMP_MAC_PCI //
1312 RTMP_IO_READ32(pAd
, TX_BAND_CFG
, &Data
);
1314 RTMP_IO_WRITE32(pAd
, TX_BAND_CFG
, Data
);
1316 if (pAd
->MACVersion
== 0x28600100)
1318 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x1A);
1319 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R70
, 0x0A);
1320 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x16);
1321 DBGPRINT(RT_DEBUG_TRACE
, ("!!!rt2860C !!! \n" ));
1324 DBGPRINT(RT_DEBUG_TRACE
, ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n", pAd
->CommonCfg
.CentralChannel
));
1326 else if ((pAd
->CommonCfg
.CentralChannel
< pAd
->CommonCfg
.Channel
) && (pAd
->MlmeAux
.HtCapability
.HtCapInfo
.ChannelWidth
== BW_40
))
1328 // Must using 40MHz.
1329 pAd
->CommonCfg
.BBPCurrentBW
= BW_40
;
1330 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.CentralChannel
, FALSE
);
1331 AsicLockChannel(pAd
, pAd
->CommonCfg
.CentralChannel
);
1333 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &Value
);
1336 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, Value
);
1338 RTMP_IO_READ32(pAd
, TX_BAND_CFG
, &Data
);
1340 RTMP_IO_WRITE32(pAd
, TX_BAND_CFG
, Data
);
1342 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &Value
);
1344 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, Value
);
1346 pAd
->StaCfg
.BBPR3
= Value
;
1347 #endif // RTMP_MAC_PCI //
1349 if (pAd
->MACVersion
== 0x28600100)
1351 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x1A);
1352 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R70
, 0x0A);
1353 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x16);
1354 DBGPRINT(RT_DEBUG_TRACE
, ("!!!rt2860C !!! \n" ));
1357 DBGPRINT(RT_DEBUG_TRACE
, ("!!! 40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n", pAd
->CommonCfg
.CentralChannel
));
1360 #endif // DOT11_N_SUPPORT //
1362 pAd
->CommonCfg
.BBPCurrentBW
= BW_20
;
1363 pAd
->CommonCfg
.CentralChannel
= pAd
->CommonCfg
.Channel
;
1364 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.Channel
, FALSE
);
1365 AsicLockChannel(pAd
, pAd
->CommonCfg
.Channel
);
1367 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &Value
);
1369 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, Value
);
1371 RTMP_IO_READ32(pAd
, TX_BAND_CFG
, &Data
);
1373 RTMP_IO_WRITE32(pAd
, TX_BAND_CFG
, Data
);
1375 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R3
, &Value
);
1377 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R3
, Value
);
1379 pAd
->StaCfg
.BBPR3
= Value
;
1380 #endif // RTMP_MAC_PCI //
1382 if (pAd
->MACVersion
== 0x28600100)
1384 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R69
, 0x16);
1385 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R70
, 0x08);
1386 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R73
, 0x11);
1387 DBGPRINT(RT_DEBUG_TRACE
, ("!!!rt2860C !!! \n" ));
1390 DBGPRINT(RT_DEBUG_TRACE
, ("!!! 20MHz LINK UP !!! \n" ));
1393 RTMPSetAGCInitValue(pAd
, pAd
->CommonCfg
.BBPCurrentBW
);
1395 // Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission
1397 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R66
, &pAd
->BbpTuning
.R66CurrentValue
);
1399 DBGPRINT(RT_DEBUG_TRACE
, ("!!! LINK UP !!! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",
1400 BssType
, pAd
->StaActive
.Aid
, pAd
->CommonCfg
.Ssid
, pAd
->CommonCfg
.Channel
, pAd
->CommonCfg
.CentralChannel
));
1402 #ifdef DOT11_N_SUPPORT
1403 DBGPRINT(RT_DEBUG_TRACE
, ("!!! LINK UP !!! (Density =%d, )\n", pAd
->MacTab
.Content
[BSSID_WCID
].MpduDensity
));
1404 #endif // DOT11_N_SUPPORT //
1406 AsicSetBssid(pAd
, pAd
->CommonCfg
.Bssid
);
1408 AsicSetSlotTime(pAd
, TRUE
);
1409 AsicSetEdcaParm(pAd
, &pAd
->CommonCfg
.APEdcaParm
);
1412 // Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit
1413 AsicUpdateProtect(pAd
, 0, (OFDMSETPROTECT
| CCKSETPROTECT
), TRUE
, FALSE
);
1415 #ifdef DOT11_N_SUPPORT
1416 if ((pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
== TRUE
))
1418 // Update HT protectionfor based on AP's operating mode.
1419 if (pAd
->MlmeAux
.AddHtInfo
.AddHtInfo2
.NonGfPresent
== 1)
1421 AsicUpdateProtect(pAd
, pAd
->MlmeAux
.AddHtInfo
.AddHtInfo2
.OperaionMode
, ALLN_SETPROTECT
, FALSE
, TRUE
);
1424 AsicUpdateProtect(pAd
, pAd
->MlmeAux
.AddHtInfo
.AddHtInfo2
.OperaionMode
, ALLN_SETPROTECT
, FALSE
, FALSE
);
1426 #endif // DOT11_N_SUPPORT //
1428 NdisZeroMemory(&pAd
->DrsCounters
, sizeof(COUNTER_DRS
));
1430 NdisGetSystemUpTime(&Now
);
1431 pAd
->StaCfg
.LastBeaconRxTime
= Now
; // last RX timestamp
1433 if ((pAd
->CommonCfg
.TxPreamble
!= Rt802_11PreambleLong
) &&
1434 CAP_IS_SHORT_PREAMBLE_ON(pAd
->StaActive
.CapabilityInfo
))
1436 MlmeSetTxPreamble(pAd
, Rt802_11PreambleShort
);
1439 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_AGGREGATION_INUSED
);
1441 if (pAd
->CommonCfg
.RadarDetect
.RDMode
== RD_SILENCE_MODE
)
1444 RadarDetectionStop(pAd
);
1445 #endif // DFS_SUPPORT //
1447 pAd
->CommonCfg
.RadarDetect
.RDMode
= RD_NORMAL_MODE
;
1449 if (BssType
== BSS_ADHOC
)
1451 MakeIbssBeacon(pAd
);
1452 if ((pAd
->CommonCfg
.Channel
> 14)
1453 && (pAd
->CommonCfg
.bIEEE80211H
== 1)
1454 && RadarChannelCheck(pAd
, pAd
->CommonCfg
.Channel
))
1460 AsicEnableIbssSync(pAd
);
1463 // In ad hoc mode, use MAC table from index 1.
1464 // 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.
1465 RTMP_IO_WRITE32(pAd
, MAC_WCID_BASE
, 0x00);
1466 RTMP_IO_WRITE32(pAd
, 0x1808, 0x00);
1468 // If WEP is enabled, add key material and cipherAlg into Asic
1469 // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
1471 if (pAd
->StaCfg
.WepStatus
== Ndis802_11WEPEnabled
)
1476 for (idx
=0; idx
< SHARE_KEY_NUM
; idx
++)
1478 CipherAlg
= pAd
->SharedKey
[BSS0
][idx
].CipherAlg
;
1479 Key
= pAd
->SharedKey
[BSS0
][idx
].Key
;
1481 if (pAd
->SharedKey
[BSS0
][idx
].KeyLen
> 0)
1483 // Set key material and cipherAlg to Asic
1484 AsicAddSharedKeyEntry(pAd
, BSS0
, idx
, CipherAlg
, Key
, NULL
, NULL
);
1486 if (idx
== pAd
->StaCfg
.DefaultKeyId
)
1488 // Update WCID attribute table and IVEIV table for this group key table
1489 RTMPAddWcidAttributeEntry(pAd
, BSS0
, idx
, CipherAlg
, NULL
);
1496 // If WPANone is enabled, add key material and cipherAlg into Asic
1497 // Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000)
1498 else if (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPANone
)
1500 pAd
->StaCfg
.DefaultKeyId
= 0; // always be zero
1502 NdisZeroMemory(&pAd
->SharedKey
[BSS0
][0], sizeof(CIPHER_KEY
));
1503 pAd
->SharedKey
[BSS0
][0].KeyLen
= LEN_TKIP_EK
;
1504 NdisMoveMemory(pAd
->SharedKey
[BSS0
][0].Key
, pAd
->StaCfg
.PMK
, LEN_TKIP_EK
);
1506 if (pAd
->StaCfg
.PairCipher
== Ndis802_11Encryption2Enabled
)
1508 NdisMoveMemory(pAd
->SharedKey
[BSS0
][0].RxMic
, &pAd
->StaCfg
.PMK
[16], LEN_TKIP_RXMICK
);
1509 NdisMoveMemory(pAd
->SharedKey
[BSS0
][0].TxMic
, &pAd
->StaCfg
.PMK
[16], LEN_TKIP_TXMICK
);
1512 // Decide its ChiperAlg
1513 if (pAd
->StaCfg
.PairCipher
== Ndis802_11Encryption2Enabled
)
1514 pAd
->SharedKey
[BSS0
][0].CipherAlg
= CIPHER_TKIP
;
1515 else if (pAd
->StaCfg
.PairCipher
== Ndis802_11Encryption3Enabled
)
1516 pAd
->SharedKey
[BSS0
][0].CipherAlg
= CIPHER_AES
;
1519 DBGPRINT(RT_DEBUG_TRACE
, ("Unknow Cipher (=%d), set Cipher to AES\n", pAd
->StaCfg
.PairCipher
));
1520 pAd
->SharedKey
[BSS0
][0].CipherAlg
= CIPHER_AES
;
1523 // Set key material and cipherAlg to Asic
1524 AsicAddSharedKeyEntry(pAd
,
1527 pAd
->SharedKey
[BSS0
][0].CipherAlg
,
1528 pAd
->SharedKey
[BSS0
][0].Key
,
1529 pAd
->SharedKey
[BSS0
][0].TxMic
,
1530 pAd
->SharedKey
[BSS0
][0].RxMic
);
1532 // Update WCID attribute table and IVEIV table for this group key table
1533 RTMPAddWcidAttributeEntry(pAd
, BSS0
, 0, pAd
->SharedKey
[BSS0
][0].CipherAlg
, NULL
);
1540 // Check the new SSID with last SSID
1541 while (Cancelled
== TRUE
)
1543 if (pAd
->CommonCfg
.LastSsidLen
== pAd
->CommonCfg
.SsidLen
)
1545 if (RTMPCompareMemory(pAd
->CommonCfg
.LastSsid
, pAd
->CommonCfg
.Ssid
, pAd
->CommonCfg
.LastSsidLen
) == 0)
1547 // Link to the old one no linkdown is required.
1551 // Send link down event before set to link up
1552 pAd
->IndicateMediaState
= NdisMediaStateDisconnected
;
1553 RTMP_IndicateMediaState(pAd
);
1554 pAd
->ExtraInfo
= GENERAL_LINK_DOWN
;
1555 DBGPRINT(RT_DEBUG_TRACE
, ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));
1560 // On WPA mode, Remove All Keys if not connect to the last BSSID
1561 // Key will be set after 4-way handshake.
1563 if (pAd
->StaCfg
.AuthMode
>= Ndis802_11AuthModeWPA
)
1567 // Remove all WPA keys
1568 RTMP_CLEAR_PSFLAG(pAd
, fRTMP_PS_CAN_GO_SLEEP
);
1569 RTMPWPARemoveAllKeys(pAd
);
1570 pAd
->StaCfg
.PortSecured
= WPA_802_1X_PORT_NOT_SECURED
;
1571 pAd
->StaCfg
.PrivacyFilter
= Ndis802_11PrivFilter8021xWEP
;
1573 // Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP
1574 // If IV related values are too large in GroupMsg2, AP would ignore this message.
1576 IV
|= (pAd
->StaCfg
.DefaultKeyId
<< 30);
1577 AsicUpdateWCIDIVEIV(pAd
, BSSID_WCID
, IV
, 0);
1578 //RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1582 // the decision of using "short slot time" or not may change dynamically due to
1583 // new STA association to the AP. so we have to decide that upon parsing BEACON, not here
1586 // the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically
1587 // due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here
1590 ComposeNullFrame(pAd
);
1592 AsicEnableBssSync(pAd
);
1594 // Add BSSID to WCID search table
1595 AsicUpdateRxWCIDTable(pAd
, BSSID_WCID
, pAd
->CommonCfg
.Bssid
);
1597 // If WEP is enabled, add paiewise and shared key
1598 #ifdef WPA_SUPPLICANT_SUPPORT
1599 if (((pAd
->StaCfg
.WpaSupplicantUP
)&&
1600 (pAd
->StaCfg
.WepStatus
== Ndis802_11WEPEnabled
)&&
1601 (pAd
->StaCfg
.PortSecured
== WPA_802_1X_PORT_SECURED
)) ||
1602 ((pAd
->StaCfg
.WpaSupplicantUP
== WPA_SUPPLICANT_DISABLE
)&&
1603 (pAd
->StaCfg
.WepStatus
== Ndis802_11WEPEnabled
)))
1605 if (pAd
->StaCfg
.WepStatus
== Ndis802_11WEPEnabled
)
1606 #endif // WPA_SUPPLICANT_SUPPORT //
1611 for (idx
=0; idx
< SHARE_KEY_NUM
; idx
++)
1613 CipherAlg
= pAd
->SharedKey
[BSS0
][idx
].CipherAlg
;
1614 Key
= pAd
->SharedKey
[BSS0
][idx
].Key
;
1616 if (pAd
->SharedKey
[BSS0
][idx
].KeyLen
> 0)
1618 // Set key material and cipherAlg to Asic
1619 AsicAddSharedKeyEntry(pAd
, BSS0
, idx
, CipherAlg
, Key
, NULL
, NULL
);
1621 if (idx
== pAd
->StaCfg
.DefaultKeyId
)
1623 // Assign group key info
1624 RTMPAddWcidAttributeEntry(pAd
, BSS0
, idx
, CipherAlg
, NULL
);
1626 pEntry
->Aid
= BSSID_WCID
;
1627 // Assign pairwise key info
1628 RTMPAddWcidAttributeEntry(pAd
, BSS0
, idx
, CipherAlg
, pEntry
);
1634 // only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode
1635 // should wait until at least 2 active nodes in this BSSID.
1636 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
);
1639 if (pAd
->StaCfg
.AuthMode
< Ndis802_11AuthModeWPA
)
1641 pAd
->IndicateMediaState
= NdisMediaStateConnected
;
1642 pAd
->ExtraInfo
= GENERAL_LINK_UP
;
1643 RTMP_IndicateMediaState(pAd
);
1645 else if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPAPSK
) ||
1646 (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA2PSK
))
1648 #ifdef WPA_SUPPLICANT_SUPPORT
1649 if (pAd
->StaCfg
.WpaSupplicantUP
== WPA_SUPPLICANT_DISABLE
)
1650 #endif // WPA_SUPPLICANT_SUPPORT //
1651 RTMPSetTimer(&pAd
->Mlme
.LinkDownTimer
, LINK_DOWN_TIMEOUT
);
1655 // Add BSSID in my MAC Table.
1656 NdisAcquireSpinLock(&pAd
->MacTabLock
);
1657 // add this MAC entry into HASH table
1660 HashIdx
= MAC_ADDR_HASH_INDEX(pAd
->CommonCfg
.Bssid
);
1661 if (pAd
->MacTab
.Hash
[HashIdx
] == NULL
)
1663 pAd
->MacTab
.Hash
[HashIdx
] = pEntry
;
1667 pCurrEntry
= pAd
->MacTab
.Hash
[HashIdx
];
1668 while (pCurrEntry
->pNext
!= NULL
)
1670 pCurrEntry
= pCurrEntry
->pNext
;
1672 pCurrEntry
->pNext
= pEntry
;
1675 RTMPMoveMemory(pEntry
->Addr
, pAd
->CommonCfg
.Bssid
, MAC_ADDR_LEN
);
1676 pEntry
->Aid
= BSSID_WCID
;
1678 pEntry
->ValidAsCLI
= TRUE
; //Although this is bssid..still set ValidAsCl
1679 pAd
->MacTab
.Size
= 1; // infra mode always set MACtab size =1.
1680 pEntry
->Sst
= SST_ASSOC
;
1681 pEntry
->AuthState
= SST_ASSOC
;
1682 pEntry
->AuthMode
= pAd
->StaCfg
.AuthMode
;
1683 pEntry
->WepStatus
= pAd
->StaCfg
.WepStatus
;
1684 if (pEntry
->AuthMode
< Ndis802_11AuthModeWPA
)
1686 pEntry
->WpaState
= AS_NOTUSE
;
1687 pEntry
->PrivacyFilter
= Ndis802_11PrivFilterAcceptAll
;
1691 pEntry
->WpaState
= AS_PTKSTART
;
1692 pEntry
->PrivacyFilter
= Ndis802_11PrivFilter8021xWEP
;
1694 NdisReleaseSpinLock(&pAd
->MacTabLock
);
1696 DBGPRINT(RT_DEBUG_TRACE
, ("!!! LINK UP !!! ClientStatusFlags=%lx)\n",
1697 pAd
->MacTab
.Content
[BSSID_WCID
].ClientStatusFlags
));
1700 MlmeUpdateTxRates(pAd
, TRUE
, BSS0
);
1701 #ifdef DOT11_N_SUPPORT
1702 MlmeUpdateHtTxRates(pAd
, BSS0
);
1703 DBGPRINT(RT_DEBUG_TRACE
, ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n", pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
));
1704 #endif // DOT11_N_SUPPORT //
1707 if (pAd
->CommonCfg
.bAggregationCapable
)
1709 if ((pAd
->CommonCfg
.bPiggyBackCapable
) && (pAd
->MlmeAux
.APRalinkIe
& 0x00000003) == 3)
1712 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_PIGGYBACK_INUSED
);
1713 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_AGGREGATION_INUSED
);
1714 CLIENT_STATUS_SET_FLAG(pEntry
, fCLIENT_STATUS_AGGREGATION_CAPABLE
);
1715 CLIENT_STATUS_SET_FLAG(pEntry
, fCLIENT_STATUS_PIGGYBACK_CAPABLE
);
1716 RTMPSetPiggyBack(pAd
, TRUE
);
1717 DBGPRINT(RT_DEBUG_TRACE
, ("Turn on Piggy-Back\n"));
1719 else if (pAd
->MlmeAux
.APRalinkIe
& 0x00000001)
1721 CLIENT_STATUS_SET_FLAG(pEntry
, fCLIENT_STATUS_AGGREGATION_CAPABLE
);
1722 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_AGGREGATION_INUSED
);
1726 if (pAd
->MlmeAux
.APRalinkIe
!= 0x0)
1728 #ifdef DOT11_N_SUPPORT
1729 if (CLIENT_STATUS_TEST_FLAG(&pAd
->MacTab
.Content
[BSSID_WCID
], fCLIENT_STATUS_RDG_CAPABLE
))
1733 #endif // DOT11_N_SUPPORT //
1734 OPSTATUS_SET_FLAG(pAd
, fCLIENT_STATUS_RALINK_CHIPSET
);
1735 CLIENT_STATUS_SET_FLAG(&pAd
->MacTab
.Content
[BSSID_WCID
], fCLIENT_STATUS_RALINK_CHIPSET
);
1739 OPSTATUS_CLEAR_FLAG(pAd
, fCLIENT_STATUS_RALINK_CHIPSET
);
1740 CLIENT_STATUS_CLEAR_FLAG(&pAd
->MacTab
.Content
[BSSID_WCID
], fCLIENT_STATUS_RALINK_CHIPSET
);
1745 #ifdef DOT11_N_SUPPORT
1746 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
));
1747 #endif // DOT11_N_SUPPORT //
1750 RTMPSetLED(pAd
, LED_LINK_UP
);
1752 pAd
->Mlme
.PeriodicRound
= 0;
1753 pAd
->Mlme
.OneSecPeriodicRound
= 0;
1754 pAd
->bConfigChanged
= FALSE
; // Reset config flag
1755 pAd
->ExtraInfo
= GENERAL_LINK_UP
; // Update extra information to link is up
1757 // Set asic auto fall back
1760 UCHAR TableSize
= 0;
1762 MlmeSelectTxRateTable(pAd
, &pAd
->MacTab
.Content
[BSSID_WCID
], &pTable
, &TableSize
, &pAd
->CommonCfg
.TxRateIndex
);
1763 AsicUpdateAutoFallBackTable(pAd
, pTable
);
1766 NdisAcquireSpinLock(&pAd
->MacTabLock
);
1767 pEntry
->HTPhyMode
.word
= pAd
->StaCfg
.HTPhyMode
.word
;
1768 pEntry
->MaxHTPhyMode
.word
= pAd
->StaCfg
.HTPhyMode
.word
;
1769 if (pAd
->StaCfg
.bAutoTxRateSwitch
== FALSE
)
1771 pEntry
->bAutoTxRateSwitch
= FALSE
;
1772 #ifdef DOT11_N_SUPPORT
1773 if (pEntry
->HTPhyMode
.field
.MCS
== 32)
1774 pEntry
->HTPhyMode
.field
.ShortGI
= GI_800
;
1776 if ((pEntry
->HTPhyMode
.field
.MCS
> MCS_7
) || (pEntry
->HTPhyMode
.field
.MCS
== 32))
1777 pEntry
->HTPhyMode
.field
.STBC
= STBC_NONE
;
1778 #endif // DOT11_N_SUPPORT //
1779 // If the legacy mode is set, overwrite the transmit setting of this entry.
1780 if (pEntry
->HTPhyMode
.field
.MODE
<= MODE_OFDM
)
1781 RTMPUpdateLegacyTxSetting((UCHAR
)pAd
->StaCfg
.DesiredTransmitSetting
.field
.FixedTxMode
, pEntry
);
1784 pEntry
->bAutoTxRateSwitch
= TRUE
;
1785 NdisReleaseSpinLock(&pAd
->MacTabLock
);
1787 // Let Link Status Page display first initial rate.
1788 pAd
->LastTxRate
= (USHORT
)(pEntry
->HTPhyMode
.word
);
1789 // Select DAC according to HT or Legacy
1790 if (pAd
->StaActive
.SupportedPhyInfo
.MCSSet
[0] != 0x00)
1792 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R1
, &Value
);
1794 if (pAd
->Antenna
.field
.TxPath
== 2)
1798 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R1
, Value
);
1802 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R1
, &Value
);
1804 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R1
, Value
);
1807 #ifdef DOT11_N_SUPPORT
1808 if (pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
== FALSE
)
1811 else if (pEntry
->MaxRAmpduFactor
== 0)
1813 // If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0.
1814 // Because our Init value is 1 at MACRegTable.
1815 RTMP_IO_WRITE32(pAd
, MAX_LEN_CFG
, 0x0fff);
1817 #endif // DOT11_N_SUPPORT //
1819 // Patch for Marvel AP to gain high throughput
1820 // Need to set as following,
1821 // 1. Set txop in register-EDCA_AC0_CFG as 0x60
1822 // 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero
1823 // 3. PBF_MAX_PCNT as 0x1F3FBF9F
1824 // 4. kick per two packets when dequeue
1826 // Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable
1828 // if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is.
1829 #ifdef DOT11_N_SUPPORT
1830 if (!((pAd
->CommonCfg
.RxStream
== 1)&&(pAd
->CommonCfg
.TxStream
== 1)) &&
1831 (pAd
->StaCfg
.bForceTxBurst
== FALSE
) &&
1832 (((pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
== FALSE
) && OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_WMM_INUSED
))
1833 || ((pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
== TRUE
) && (pAd
->CommonCfg
.BACapability
.field
.Policy
== BA_NOTUSE
))))
1835 RTMP_IO_READ32(pAd
, EDCA_AC0_CFG
, &Data
);
1837 RTMP_IO_WRITE32(pAd
, EDCA_AC0_CFG
, Data
);
1839 RTMP_IO_WRITE32(pAd
, PBF_MAX_PCNT
, 0x1F3F7F9F);
1840 DBGPRINT(RT_DEBUG_TRACE
, ("Txburst 1\n"));
1843 #endif // DOT11_N_SUPPORT //
1844 if (pAd
->CommonCfg
.bEnableTxBurst
)
1846 RTMP_IO_READ32(pAd
, EDCA_AC0_CFG
, &Data
);
1849 RTMP_IO_WRITE32(pAd
, EDCA_AC0_CFG
, Data
);
1850 pAd
->CommonCfg
.IOTestParm
.bNowAtherosBurstOn
= TRUE
;
1852 RTMP_IO_WRITE32(pAd
, PBF_MAX_PCNT
, 0x1F3FBF9F);
1853 DBGPRINT(RT_DEBUG_TRACE
, ("Txburst 2\n"));
1857 RTMP_IO_READ32(pAd
, EDCA_AC0_CFG
, &Data
);
1859 RTMP_IO_WRITE32(pAd
, EDCA_AC0_CFG
, Data
);
1861 RTMP_IO_WRITE32(pAd
, PBF_MAX_PCNT
, 0x1F3F7F9F);
1862 DBGPRINT(RT_DEBUG_TRACE
, ("Txburst 3\n"));
1865 #ifdef DOT11_N_SUPPORT
1866 // Re-check to turn on TX burst or not.
1867 if ((pAd
->CommonCfg
.IOTestParm
.bLastAtheros
== TRUE
) && ((STA_WEP_ON(pAd
))||(STA_TKIP_ON(pAd
))))
1869 pAd
->CommonCfg
.IOTestParm
.bNextDisableRxBA
= TRUE
;
1870 if (pAd
->CommonCfg
.bEnableTxBurst
)
1872 UINT32 MACValue
= 0;
1873 // Force disable TXOP value in this case. The same action in MLMEUpdateProtect too.
1874 // I didn't change PBF_MAX_PCNT setting.
1875 RTMP_IO_READ32(pAd
, EDCA_AC0_CFG
, &MACValue
);
1876 MACValue
&= 0xFFFFFF00;
1877 RTMP_IO_WRITE32(pAd
, EDCA_AC0_CFG
, MACValue
);
1878 pAd
->CommonCfg
.IOTestParm
.bNowAtherosBurstOn
= FALSE
;
1883 pAd
->CommonCfg
.IOTestParm
.bNextDisableRxBA
= FALSE
;
1885 #endif // DOT11_N_SUPPORT //
1887 pAd
->CommonCfg
.IOTestParm
.bLastAtheros
= FALSE
;
1888 COPY_MAC_ADDR(pAd
->CommonCfg
.LastBssid
, pAd
->CommonCfg
.Bssid
);
1889 DBGPRINT(RT_DEBUG_TRACE
, ("!!!pAd->bNextDisableRxBA= %d \n", pAd
->CommonCfg
.IOTestParm
.bNextDisableRxBA
));
1890 // BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap
1891 // Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver.
1892 // Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same.
1894 if (pAd
->StaCfg
.WepStatus
<= Ndis802_11WEPDisabled
)
1896 #ifdef WPA_SUPPLICANT_SUPPORT
1897 if (pAd
->StaCfg
.WpaSupplicantUP
&&
1898 (pAd
->StaCfg
.WepStatus
== Ndis802_11WEPEnabled
) &&
1899 (pAd
->StaCfg
.IEEE8021X
== TRUE
))
1902 #endif // WPA_SUPPLICANT_SUPPORT //
1904 pAd
->StaCfg
.PortSecured
= WPA_802_1X_PORT_SECURED
;
1905 pAd
->StaCfg
.PrivacyFilter
= Ndis802_11PrivFilterAcceptAll
;
1909 NdisAcquireSpinLock(&pAd
->MacTabLock
);
1910 pEntry
->PortSecured
= pAd
->StaCfg
.PortSecured
;
1911 NdisReleaseSpinLock(&pAd
->MacTabLock
);
1914 // Patch Atheros AP TX will breakdown issue.
1915 // AP Model: DLink DWL-8200AP
1917 if (INFRA_ON(pAd
) && OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_WMM_INUSED
) && STA_TKIP_ON(pAd
))
1919 RTMP_IO_WRITE32(pAd
, RX_PARSER_CFG
, 0x01);
1923 RTMP_IO_WRITE32(pAd
, RX_PARSER_CFG
, 0x00);
1926 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS
);
1927 RTMP_CLEAR_PSFLAG(pAd
, fRTMP_PS_GO_TO_SLEEP_NOW
);
1929 #ifdef DOT11_N_SUPPORT
1930 #ifdef DOT11N_DRAFT3
1931 if ((pAd
->CommonCfg
.BACapability
.field
.b2040CoexistScanSup
) && (pAd
->CommonCfg
.Channel
<= 11))
1933 OPSTATUS_SET_FLAG(pAd
, fOP_STATUS_SCAN_2040
);
1934 BuildEffectedChannelList(pAd
);
1936 #endif // DOT11N_DRAFT3 //
1937 #endif // DOT11_N_SUPPORT //
1941 ==========================================================================
1943 Routine Description:
1944 Disconnect current BSSID
1947 pAd - Pointer to our adapter
1948 IsReqFromAP - Request from AP
1953 IRQL = DISPATCH_LEVEL
1956 We need more information to know it's this requst from AP.
1957 If yes! we need to do extra handling, for example, remove the WPA key.
1958 Otherwise on 4-way handshaking will faied, since the WPA key didn't be
1959 remove while auto reconnect.
1960 Disconnect request from AP, it means we will start afresh 4-way handshaking
1963 ==========================================================================
1966 IN PRTMP_ADAPTER pAd
,
1967 IN BOOLEAN IsReqFromAP
)
1969 UCHAR i
, ByteValue
= 0;
1973 // Do nothing if monitor mode is on
1974 if (MONITOR_ON(pAd
))
1978 // Nothing to do in ATE mode.
1981 #endif // RALINK_ATE //
1982 RTMP_CLEAR_PSFLAG(pAd
, fRTMP_PS_GO_TO_SLEEP_NOW
);
1983 //Comment the codes, beasue the line 2291 call the same function.
1984 //RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1985 // Not allow go to sleep within linkdown function.
1986 RTMP_CLEAR_PSFLAG(pAd
, fRTMP_PS_CAN_GO_SLEEP
);
1988 if (pAd
->CommonCfg
.bWirelessEvent
)
1990 RTMPSendWirelessEvent(pAd
, IW_STA_LINKDOWN_EVENT_FLAG
, pAd
->MacTab
.Content
[BSSID_WCID
].Addr
, BSS0
, 0);
1993 DBGPRINT(RT_DEBUG_TRACE
, ("!!! LINK DOWN !!!\n"));
1994 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_AGGREGATION_INUSED
);
1997 if (OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_PCIE_DEVICE
))
2000 pAd
->Mlme
.bPsPollTimerRunning
= FALSE
;
2001 RTMPCancelTimer(&pAd
->Mlme
.PsPollTimer
, &Cancelled
);
2004 pAd
->bPCIclkOff
= FALSE
;
2005 #endif // RTMP_MAC_PCI //
2007 if (OPSTATUS_TEST_FLAG(pAd
, fOP_STATUS_DOZE
)
2008 || RTMP_TEST_PSFLAG(pAd
, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND
)
2009 || RTMP_TEST_FLAG(pAd
, fRTMP_ADAPTER_IDLE_RADIO_OFF
))
2011 AUTO_WAKEUP_STRUC AutoWakeupCfg
;
2012 AsicForceWakeup(pAd
, TRUE
);
2013 AutoWakeupCfg
.word
= 0;
2014 RTMP_IO_WRITE32(pAd
, AUTO_WAKEUP_CFG
, AutoWakeupCfg
.word
);
2015 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_DOZE
);
2018 pAd
->bPCIclkOff
= FALSE
;
2019 #endif // RTMP_MAC_PCI //
2020 if (ADHOC_ON(pAd
)) // Adhoc mode link down
2022 DBGPRINT(RT_DEBUG_TRACE
, ("!!! LINK DOWN 1!!!\n"));
2024 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_ADHOC_ON
);
2025 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
);
2026 pAd
->IndicateMediaState
= NdisMediaStateDisconnected
;
2027 RTMP_IndicateMediaState(pAd
);
2028 pAd
->ExtraInfo
= GENERAL_LINK_DOWN
;
2029 BssTableDeleteEntry(&pAd
->ScanTab
, pAd
->CommonCfg
.Bssid
, pAd
->CommonCfg
.Channel
);
2030 DBGPRINT(RT_DEBUG_TRACE
, ("!!! MacTab.Size=%d !!!\n", pAd
->MacTab
.Size
));
2032 else // Infra structure mode
2034 DBGPRINT(RT_DEBUG_TRACE
, ("!!! LINK DOWN 2!!!\n"));
2036 #ifdef QOS_DLS_SUPPORT
2037 // DLS tear down frame must be sent before link down
2038 // send DLS-TEAR_DOWN message
2039 if (pAd
->CommonCfg
.bDLSCapable
)
2041 // tear down local dls table entry
2042 for (i
=0; i
<MAX_NUM_OF_INIT_DLS_ENTRY
; i
++)
2044 if (pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
))
2046 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
2047 RTMPSendDLSTearDownFrame(pAd
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
);
2051 // tear down peer dls table entry
2052 for (i
=MAX_NUM_OF_INIT_DLS_ENTRY
; i
<MAX_NUM_OF_DLS_ENTRY
; i
++)
2054 if (pAd
->StaCfg
.DLSEntry
[i
].Valid
&& (pAd
->StaCfg
.DLSEntry
[i
].Status
== DLS_FINISH
))
2056 pAd
->StaCfg
.DLSEntry
[i
].Status
= DLS_NONE
;
2057 RTMPSendDLSTearDownFrame(pAd
, pAd
->StaCfg
.DLSEntry
[i
].MacAddr
);
2061 #endif // QOS_DLS_SUPPORT //
2063 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_INFRA_ON
);
2064 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_MEDIA_STATE_CONNECTED
);
2066 // Saved last SSID for linkup comparison
2067 pAd
->CommonCfg
.LastSsidLen
= pAd
->CommonCfg
.SsidLen
;
2068 NdisMoveMemory(pAd
->CommonCfg
.LastSsid
, pAd
->CommonCfg
.Ssid
, pAd
->CommonCfg
.LastSsidLen
);
2069 COPY_MAC_ADDR(pAd
->CommonCfg
.LastBssid
, pAd
->CommonCfg
.Bssid
);
2070 if (pAd
->MlmeAux
.CurrReqIsFromNdis
== TRUE
)
2072 pAd
->IndicateMediaState
= NdisMediaStateDisconnected
;
2073 RTMP_IndicateMediaState(pAd
);
2074 pAd
->ExtraInfo
= GENERAL_LINK_DOWN
;
2075 DBGPRINT(RT_DEBUG_TRACE
, ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));
2076 pAd
->MlmeAux
.CurrReqIsFromNdis
= FALSE
;
2081 // If disassociation request is from NDIS, then we don't need to delete BSSID from entry.
2082 // Otherwise lost beacon or receive De-Authentication from AP,
2083 // then we should delete BSSID from BssTable.
2084 // If we don't delete from entry, roaming will fail.
2086 BssTableDeleteEntry(&pAd
->ScanTab
, pAd
->CommonCfg
.Bssid
, pAd
->CommonCfg
.Channel
);
2089 // restore back to -
2090 // 1. long slot (20 us) or short slot (9 us) time
2091 // 2. turn on/off RTS/CTS and/or CTS-to-self protection
2092 // 3. short preamble
2093 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_BG_PROTECTION_INUSED
);
2095 #ifdef EXT_BUILD_CHANNEL_LIST
2096 // Country IE of the AP will be evaluated and will be used.
2097 if (pAd
->StaCfg
.IEEE80211dClientMode
!= Rt802_11_D_None
)
2099 NdisMoveMemory(&pAd
->CommonCfg
.CountryCode
[0], &pAd
->StaCfg
.StaOriCountryCode
[0], 2);
2100 pAd
->CommonCfg
.Geography
= pAd
->StaCfg
.StaOriGeography
;
2101 BuildChannelListEx(pAd
);
2103 #endif // EXT_BUILD_CHANNEL_LIST //
2108 for (i
=1; i
<MAX_LEN_OF_MAC_TABLE
; i
++)
2110 if (pAd
->MacTab
.Content
[i
].ValidAsCLI
== TRUE
)
2111 MacTableDeleteEntry(pAd
, pAd
->MacTab
.Content
[i
].Aid
, pAd
->MacTab
.Content
[i
].Addr
);
2114 AsicSetSlotTime(pAd
, TRUE
); //FALSE);
2115 AsicSetEdcaParm(pAd
, NULL
);
2118 RTMPSetLED(pAd
, LED_LINK_DOWN
);
2119 pAd
->LedIndicatorStrength
= 0xF0;
2120 RTMPSetSignalLED(pAd
, -100); // Force signal strength Led to be turned off, firmware is not done it.
2122 AsicDisableSync(pAd
);
2124 pAd
->Mlme
.PeriodicRound
= 0;
2125 pAd
->Mlme
.OneSecPeriodicRound
= 0;
2127 if (pAd
->StaCfg
.BssType
== BSS_INFRA
)
2129 // Remove StaCfg Information after link down
2130 NdisZeroMemory(pAd
->CommonCfg
.Bssid
, MAC_ADDR_LEN
);
2131 NdisZeroMemory(pAd
->CommonCfg
.Ssid
, MAX_LEN_OF_SSID
);
2132 pAd
->CommonCfg
.SsidLen
= 0;
2134 #ifdef DOT11_N_SUPPORT
2135 NdisZeroMemory(&pAd
->MlmeAux
.HtCapability
, sizeof(HT_CAPABILITY_IE
));
2136 NdisZeroMemory(&pAd
->MlmeAux
.AddHtInfo
, sizeof(ADD_HT_INFO_IE
));
2137 pAd
->MlmeAux
.HtCapabilityLen
= 0;
2138 pAd
->MlmeAux
.NewExtChannelOffset
= 0xff;
2139 #endif // DOT11_N_SUPPORT //
2141 // Reset WPA-PSK state. Only reset when supplicant enabled
2142 if (pAd
->StaCfg
.WpaState
!= SS_NOTUSE
)
2144 pAd
->StaCfg
.WpaState
= SS_START
;
2145 // Clear Replay counter
2146 NdisZeroMemory(pAd
->StaCfg
.ReplayCounter
, 8);
2148 #ifdef QOS_DLS_SUPPORT
2149 if (pAd
->CommonCfg
.bDLSCapable
)
2150 NdisZeroMemory(pAd
->StaCfg
.DlsReplayCounter
, 8);
2151 #endif // QOS_DLS_SUPPORT //
2155 // if link down come from AP, we need to remove all WPA keys on WPA mode.
2156 // otherwise will cause 4-way handshaking failed, since the WPA key not empty.
2158 if ((IsReqFromAP
) && (pAd
->StaCfg
.AuthMode
>= Ndis802_11AuthModeWPA
))
2160 // Remove all WPA keys
2161 RTMPWPARemoveAllKeys(pAd
);
2164 // 802.1x port control
2165 #ifdef WPA_SUPPLICANT_SUPPORT
2166 // Prevent clear PortSecured here with static WEP
2167 // NetworkManger set security policy first then set SSID to connect AP.
2168 if (pAd
->StaCfg
.WpaSupplicantUP
&&
2169 (pAd
->StaCfg
.WepStatus
== Ndis802_11WEPEnabled
) &&
2170 (pAd
->StaCfg
.IEEE8021X
== FALSE
))
2172 pAd
->StaCfg
.PortSecured
= WPA_802_1X_PORT_SECURED
;
2175 #endif // WPA_SUPPLICANT_SUPPORT //
2177 pAd
->StaCfg
.PortSecured
= WPA_802_1X_PORT_NOT_SECURED
;
2178 pAd
->StaCfg
.PrivacyFilter
= Ndis802_11PrivFilter8021xWEP
;
2181 NdisAcquireSpinLock(&pAd
->MacTabLock
);
2182 NdisZeroMemory(&pAd
->MacTab
, sizeof(MAC_TABLE
));
2183 pAd
->MacTab
.Content
[BSSID_WCID
].PortSecured
= pAd
->StaCfg
.PortSecured
;
2184 NdisReleaseSpinLock(&pAd
->MacTabLock
);
2186 pAd
->StaCfg
.MicErrCnt
= 0;
2188 pAd
->IndicateMediaState
= NdisMediaStateDisconnected
;
2189 // Update extra information to link is up
2190 pAd
->ExtraInfo
= GENERAL_LINK_DOWN
;
2192 pAd
->StaActive
.SupportedPhyInfo
.bHtEnable
= FALSE
;
2195 // Clean association information
2196 NdisZeroMemory(&pAd
->StaCfg
.AssocInfo
, sizeof(NDIS_802_11_ASSOCIATION_INFORMATION
));
2197 pAd
->StaCfg
.AssocInfo
.Length
= sizeof(NDIS_802_11_ASSOCIATION_INFORMATION
);
2198 pAd
->StaCfg
.ReqVarIELen
= 0;
2199 pAd
->StaCfg
.ResVarIELen
= 0;
2202 // Reset RSSI value after link down
2204 pAd
->StaCfg
.RssiSample
.AvgRssi0
= 0;
2205 pAd
->StaCfg
.RssiSample
.AvgRssi0X8
= 0;
2206 pAd
->StaCfg
.RssiSample
.AvgRssi1
= 0;
2207 pAd
->StaCfg
.RssiSample
.AvgRssi1X8
= 0;
2208 pAd
->StaCfg
.RssiSample
.AvgRssi2
= 0;
2209 pAd
->StaCfg
.RssiSample
.AvgRssi2X8
= 0;
2212 pAd
->CommonCfg
.MlmeRate
= pAd
->CommonCfg
.BasicMlmeRate
;
2213 pAd
->CommonCfg
.RtsRate
= pAd
->CommonCfg
.BasicMlmeRate
;
2215 #ifdef DOT11_N_SUPPORT
2217 // After Link down, reset piggy-back setting in ASIC. Disable RDG.
2219 if (pAd
->CommonCfg
.BBPCurrentBW
== BW_40
)
2221 pAd
->CommonCfg
.BBPCurrentBW
= BW_20
;
2222 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R4
, &ByteValue
);
2223 ByteValue
&= (~0x18);
2224 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R4
, ByteValue
);
2226 #endif // DOT11_N_SUPPORT //
2228 RTMP_BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R1
, &ByteValue
);
2229 ByteValue
&= (~0x18);
2230 if (pAd
->Antenna
.field
.TxPath
== 2)
2234 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, BBP_R1
, ByteValue
);
2236 RTMPSetPiggyBack(pAd
,FALSE
);
2237 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_PIGGYBACK_INUSED
);
2239 #ifdef DOT11_N_SUPPORT
2240 pAd
->CommonCfg
.BACapability
.word
= pAd
->CommonCfg
.REGBACapability
.word
;
2241 #endif // DOT11_N_SUPPORT //
2243 // Restore all settings in the following.
2244 AsicUpdateProtect(pAd
, 0, (ALLN_SETPROTECT
|CCKSETPROTECT
|OFDMSETPROTECT
), TRUE
, FALSE
);
2245 AsicDisableRDG(pAd
);
2246 pAd
->CommonCfg
.IOTestParm
.bCurrentAtheros
= FALSE
;
2247 pAd
->CommonCfg
.IOTestParm
.bNowAtherosBurstOn
= FALSE
;
2249 #ifdef DOT11_N_SUPPORT
2250 #ifdef DOT11N_DRAFT3
2251 OPSTATUS_CLEAR_FLAG(pAd
, fOP_STATUS_SCAN_2040
);
2252 pAd
->CommonCfg
.BSSCoexist2040
.word
= 0;
2254 for (i
= 0; i
< (pAd
->ChannelListNum
- 1); i
++)
2256 pAd
->ChannelList
[i
].bEffectedChannel
= FALSE
;
2258 #endif // DOT11N_DRAFT3 //
2259 #endif // DOT11_N_SUPPORT //
2261 RTMP_IO_WRITE32(pAd
, MAX_LEN_CFG
, 0x1fff);
2262 RTMP_CLEAR_FLAG(pAd
, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS
);
2263 // Allow go to sleep after linkdown steps.
2264 RTMP_SET_PSFLAG(pAd
, fRTMP_PS_CAN_GO_SLEEP
);
2265 #ifdef WPA_SUPPLICANT_SUPPORT
2266 #ifndef NATIVE_WPA_SUPPLICANT_SUPPORT
2267 if (pAd
->StaCfg
.WpaSupplicantUP
) {
2268 //send disassociate event to wpa_supplicant
2269 RtmpOSWrielessEventSend(pAd
, IWEVCUSTOM
, RT_DISASSOC_EVENT_FLAG
, NULL
, NULL
, 0);
2271 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2272 #endif // WPA_SUPPLICANT_SUPPORT //
2274 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
2275 RtmpOSWrielessEventSend(pAd
, SIOCGIWAP
, -1, NULL
, NULL
, 0);
2276 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
2279 if ((IS_RT30xx(pAd
) || IS_RT3090(pAd
)||IS_RT3390(pAd
))
2280 &&(pAd
->Antenna
.field
.RxPath
>1||pAd
->Antenna
.field
.TxPath
>1))
2282 RTMP_ASIC_MMPS_DISABLE(pAd
);
2289 ==========================================================================
2292 IRQL = DISPATCH_LEVEL
2294 ==========================================================================
2296 VOID
IterateOnBssTab(
2297 IN PRTMP_ADAPTER pAd
)
2299 MLME_START_REQ_STRUCT StartReq
;
2300 MLME_JOIN_REQ_STRUCT JoinReq
;
2303 // Change the wepstatus to original wepstatus
2304 pAd
->StaCfg
.WepStatus
= pAd
->StaCfg
.OrigWepStatus
;
2305 pAd
->StaCfg
.PairCipher
= pAd
->StaCfg
.OrigWepStatus
;
2306 pAd
->StaCfg
.GroupCipher
= pAd
->StaCfg
.OrigWepStatus
;
2308 BssIdx
= pAd
->MlmeAux
.BssIdx
;
2309 if (BssIdx
< pAd
->MlmeAux
.SsidBssTab
.BssNr
)
2311 // Check cipher suite, AP must have more secured cipher than station setting
2312 // Set the Pairwise and Group cipher to match the intended AP setting
2313 // We can only connect to AP with less secured cipher setting
2314 if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA
) || (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPAPSK
))
2316 pAd
->StaCfg
.GroupCipher
= pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA
.GroupCipher
;
2318 if (pAd
->StaCfg
.WepStatus
== pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA
.PairCipher
)
2319 pAd
->StaCfg
.PairCipher
= pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA
.PairCipher
;
2320 else if (pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA
.PairCipherAux
!= Ndis802_11WEPDisabled
)
2321 pAd
->StaCfg
.PairCipher
= pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA
.PairCipherAux
;
2322 else // There is no PairCipher Aux, downgrade our capability to TKIP
2323 pAd
->StaCfg
.PairCipher
= Ndis802_11Encryption2Enabled
;
2325 else if ((pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA2
) || (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPA2PSK
))
2327 pAd
->StaCfg
.GroupCipher
= pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA2
.GroupCipher
;
2329 if (pAd
->StaCfg
.WepStatus
== pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA2
.PairCipher
)
2330 pAd
->StaCfg
.PairCipher
= pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA2
.PairCipher
;
2331 else if (pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA2
.PairCipherAux
!= Ndis802_11WEPDisabled
)
2332 pAd
->StaCfg
.PairCipher
= pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA2
.PairCipherAux
;
2333 else // There is no PairCipher Aux, downgrade our capability to TKIP
2334 pAd
->StaCfg
.PairCipher
= Ndis802_11Encryption2Enabled
;
2337 pAd
->StaCfg
.RsnCapability
= pAd
->MlmeAux
.SsidBssTab
.BssEntry
[BssIdx
].WPA2
.RsnCapability
;
2340 // Set Mix cipher flag
2341 pAd
->StaCfg
.bMixCipher
= (pAd
->StaCfg
.PairCipher
== pAd
->StaCfg
.GroupCipher
) ? FALSE
: TRUE
;
2342 /*if (pAd->StaCfg.bMixCipher == TRUE)
2344 // If mix cipher, re-build RSNIE
2345 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
2348 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - iterate BSS %ld of %d\n", BssIdx
, pAd
->MlmeAux
.SsidBssTab
.BssNr
));
2349 JoinParmFill(pAd
, &JoinReq
, BssIdx
);
2350 MlmeEnqueue(pAd
, SYNC_STATE_MACHINE
, MT2_MLME_JOIN_REQ
, sizeof(MLME_JOIN_REQ_STRUCT
),
2352 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_JOIN
;
2354 else if (pAd
->StaCfg
.BssType
== BSS_ADHOC
)
2356 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",pAd
->MlmeAux
.Ssid
));
2357 StartParmFill(pAd
, &StartReq
, (PCHAR
)pAd
->MlmeAux
.Ssid
, pAd
->MlmeAux
.SsidLen
);
2358 MlmeEnqueue(pAd
, SYNC_STATE_MACHINE
, MT2_MLME_START_REQ
, sizeof(MLME_START_REQ_STRUCT
), &StartReq
);
2359 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_START
;
2364 #ifdef DOT11_N_SUPPORT
2365 #endif // DOT11_N_SUPPORT //
2367 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.Channel
, FALSE
);
2368 AsicLockChannel(pAd
, pAd
->CommonCfg
.Channel
);
2369 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n",pAd
->CommonCfg
.Channel
, pAd
->ScanTab
.BssNr
));
2372 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
2376 // for re-association only
2377 // IRQL = DISPATCH_LEVEL
2378 VOID
IterateOnBssTab2(
2379 IN PRTMP_ADAPTER pAd
)
2381 MLME_REASSOC_REQ_STRUCT ReassocReq
;
2385 BssIdx
= pAd
->MlmeAux
.RoamIdx
;
2386 pBss
= &pAd
->MlmeAux
.RoamTab
.BssEntry
[BssIdx
];
2388 if (BssIdx
< pAd
->MlmeAux
.RoamTab
.BssNr
)
2390 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - iterate BSS %ld of %d\n", BssIdx
, pAd
->MlmeAux
.RoamTab
.BssNr
));
2392 AsicSwitchChannel(pAd
, pBss
->Channel
, FALSE
);
2393 AsicLockChannel(pAd
, pBss
->Channel
);
2395 // reassociate message has the same structure as associate message
2396 AssocParmFill(pAd
, &ReassocReq
, pBss
->Bssid
, pBss
->CapabilityInfo
,
2397 ASSOC_TIMEOUT
, pAd
->StaCfg
.DefaultListenCount
);
2398 MlmeEnqueue(pAd
, ASSOC_STATE_MACHINE
, MT2_MLME_REASSOC_REQ
,
2399 sizeof(MLME_REASSOC_REQ_STRUCT
), &ReassocReq
);
2401 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_WAIT_REASSOC
;
2406 #ifdef DOT11_N_SUPPORT
2407 #endif // DOT11_N_SUPPORT //
2409 AsicSwitchChannel(pAd
, pAd
->CommonCfg
.Channel
, FALSE
);
2410 AsicLockChannel(pAd
, pAd
->CommonCfg
.Channel
);
2411 DBGPRINT(RT_DEBUG_TRACE
, ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n",pAd
->CommonCfg
.Channel
, pAd
->ScanTab
.BssNr
));
2414 pAd
->Mlme
.CntlMachine
.CurrState
= CNTL_IDLE
;
2419 ==========================================================================
2422 IRQL = DISPATCH_LEVEL
2424 ==========================================================================
2427 IN PRTMP_ADAPTER pAd
,
2428 IN OUT MLME_JOIN_REQ_STRUCT
*JoinReq
,
2431 JoinReq
->BssIdx
= BssIdx
;
2435 ==========================================================================
2438 IRQL = DISPATCH_LEVEL
2440 ==========================================================================
2443 IN PRTMP_ADAPTER pAd
,
2444 IN OUT MLME_SCAN_REQ_STRUCT
*ScanReq
,
2450 NdisZeroMemory(ScanReq
->Ssid
, MAX_LEN_OF_SSID
);
2451 ScanReq
->SsidLen
= SsidLen
;
2452 NdisMoveMemory(ScanReq
->Ssid
, Ssid
, SsidLen
);
2453 ScanReq
->BssType
= BssType
;
2454 ScanReq
->ScanType
= ScanType
;
2457 #ifdef QOS_DLS_SUPPORT
2459 ==========================================================================
2462 IRQL = DISPATCH_LEVEL
2464 ==========================================================================
2467 IN PRTMP_ADAPTER pAd
,
2468 IN OUT MLME_DLS_REQ_STRUCT
*pDlsReq
,
2469 IN PRT_802_11_DLS pDls
,
2472 pDlsReq
->pDLS
= pDls
;
2473 pDlsReq
->Reason
= reason
;
2475 #endif // QOS_DLS_SUPPORT //
2478 ==========================================================================
2481 IRQL = DISPATCH_LEVEL
2483 ==========================================================================
2486 IN PRTMP_ADAPTER pAd
,
2487 IN OUT MLME_START_REQ_STRUCT
*StartReq
,
2491 ASSERT(SsidLen
<= MAX_LEN_OF_SSID
);
2492 NdisMoveMemory(StartReq
->Ssid
, Ssid
, SsidLen
);
2493 StartReq
->SsidLen
= SsidLen
;
2497 ==========================================================================
2500 IRQL = DISPATCH_LEVEL
2502 ==========================================================================
2505 IN PRTMP_ADAPTER pAd
,
2506 IN OUT MLME_AUTH_REQ_STRUCT
*AuthReq
,
2510 COPY_MAC_ADDR(AuthReq
->Addr
, pAddr
);
2512 AuthReq
->Timeout
= AUTH_TIMEOUT
;
2516 ==========================================================================
2519 IRQL = DISPATCH_LEVEL
2521 ==========================================================================
2525 IN PRTMP_ADAPTER pAd
)
2527 NdisZeroMemory(&pAd
->PsPollFrame
, sizeof(PSPOLL_FRAME
));
2528 pAd
->PsPollFrame
.FC
.Type
= BTYPE_CNTL
;
2529 pAd
->PsPollFrame
.FC
.SubType
= SUBTYPE_PS_POLL
;
2530 pAd
->PsPollFrame
.Aid
= pAd
->StaActive
.Aid
| 0xC000;
2531 COPY_MAC_ADDR(pAd
->PsPollFrame
.Bssid
, pAd
->CommonCfg
.Bssid
);
2532 COPY_MAC_ADDR(pAd
->PsPollFrame
.Ta
, pAd
->CurrentAddress
);
2535 // IRQL = DISPATCH_LEVEL
2536 VOID
ComposeNullFrame(
2537 IN PRTMP_ADAPTER pAd
)
2539 NdisZeroMemory(&pAd
->NullFrame
, sizeof(HEADER_802_11
));
2540 pAd
->NullFrame
.FC
.Type
= BTYPE_DATA
;
2541 pAd
->NullFrame
.FC
.SubType
= SUBTYPE_NULL_FUNC
;
2542 pAd
->NullFrame
.FC
.ToDs
= 1;
2543 COPY_MAC_ADDR(pAd
->NullFrame
.Addr1
, pAd
->CommonCfg
.Bssid
);
2544 COPY_MAC_ADDR(pAd
->NullFrame
.Addr2
, pAd
->CurrentAddress
);
2545 COPY_MAC_ADDR(pAd
->NullFrame
.Addr3
, pAd
->CommonCfg
.Bssid
);
2547 #endif // RTMP_MAC_PCI //
2553 ==========================================================================
2555 Pre-build a BEACON frame in the shared memory
2557 IRQL = PASSIVE_LEVEL
2558 IRQL = DISPATCH_LEVEL
2560 ==========================================================================
2562 ULONG
MakeIbssBeacon(
2563 IN PRTMP_ADAPTER pAd
)
2565 UCHAR DsLen
= 1, IbssLen
= 2;
2566 UCHAR LocalErpIe
[3] = {IE_ERP
, 1, 0x04};
2567 HEADER_802_11 BcnHdr
;
2568 USHORT CapabilityInfo
;
2569 LARGE_INTEGER FakeTimestamp
;
2571 PTXWI_STRUC pTxWI
= &pAd
->BeaconTxWI
;
2572 UCHAR
*pBeaconFrame
= pAd
->BeaconBuf
;
2574 UCHAR SupRate
[MAX_LEN_OF_SUPPORTED_RATES
];
2575 UCHAR SupRateLen
= 0;
2576 UCHAR ExtRate
[MAX_LEN_OF_SUPPORTED_RATES
];
2577 UCHAR ExtRateLen
= 0;
2578 UCHAR RSNIe
= IE_WPA
;
2580 if ((pAd
->CommonCfg
.PhyMode
== PHY_11B
) && (pAd
->CommonCfg
.Channel
<= 14))
2582 SupRate
[0] = 0x82; // 1 mbps
2583 SupRate
[1] = 0x84; // 2 mbps
2584 SupRate
[2] = 0x8b; // 5.5 mbps
2585 SupRate
[3] = 0x96; // 11 mbps
2589 else if (pAd
->CommonCfg
.Channel
> 14)
2591 SupRate
[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
2592 SupRate
[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2593 SupRate
[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
2594 SupRate
[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2595 SupRate
[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
2596 SupRate
[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2597 SupRate
[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2598 SupRate
[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2603 // Also Update MlmeRate & RtsRate for G only & A only
2605 pAd
->CommonCfg
.MlmeRate
= RATE_6
;
2606 pAd
->CommonCfg
.RtsRate
= RATE_6
;
2607 pAd
->CommonCfg
.MlmeTransmit
.field
.MODE
= MODE_OFDM
;
2608 pAd
->CommonCfg
.MlmeTransmit
.field
.MCS
= OfdmRateToRxwiMCS
[pAd
->CommonCfg
.MlmeRate
];
2609 pAd
->MacTab
.Content
[BSS0Mcast_WCID
].HTPhyMode
.field
.MODE
= MODE_OFDM
;
2610 pAd
->MacTab
.Content
[BSS0Mcast_WCID
].HTPhyMode
.field
.MCS
= OfdmRateToRxwiMCS
[pAd
->CommonCfg
.MlmeRate
];
2614 SupRate
[0] = 0x82; // 1 mbps
2615 SupRate
[1] = 0x84; // 2 mbps
2616 SupRate
[2] = 0x8b; // 5.5 mbps
2617 SupRate
[3] = 0x96; // 11 mbps
2620 ExtRate
[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps,
2621 ExtRate
[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
2622 ExtRate
[2] = 0x18; // 12 mbps, in units of 0.5 Mbps,
2623 ExtRate
[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
2624 ExtRate
[4] = 0x30; // 24 mbps, in units of 0.5 Mbps,
2625 ExtRate
[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
2626 ExtRate
[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
2627 ExtRate
[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
2631 pAd
->StaActive
.SupRateLen
= SupRateLen
;
2632 NdisMoveMemory(pAd
->StaActive
.SupRate
, SupRate
, SupRateLen
);
2633 pAd
->StaActive
.ExtRateLen
= ExtRateLen
;
2634 NdisMoveMemory(pAd
->StaActive
.ExtRate
, ExtRate
, ExtRateLen
);
2636 // compose IBSS beacon frame
2637 MgtMacHeaderInit(pAd
, &BcnHdr
, SUBTYPE_BEACON
, 0, BROADCAST_ADDR
, pAd
->CommonCfg
.Bssid
);
2638 Privacy
= (pAd
->StaCfg
.WepStatus
== Ndis802_11Encryption1Enabled
) ||
2639 (pAd
->StaCfg
.WepStatus
== Ndis802_11Encryption2Enabled
) ||
2640 (pAd
->StaCfg
.WepStatus
== Ndis802_11Encryption3Enabled
);
2641 CapabilityInfo
= CAP_GENERATE(0, 1, Privacy
, (pAd
->CommonCfg
.TxPreamble
== Rt802_11PreambleShort
), 0, 0);
2643 MakeOutgoingFrame(pBeaconFrame
, &FrameLen
,
2644 sizeof(HEADER_802_11
), &BcnHdr
,
2645 TIMESTAMP_LEN
, &FakeTimestamp
,
2646 2, &pAd
->CommonCfg
.BeaconPeriod
,
2649 1, &pAd
->CommonCfg
.SsidLen
,
2650 pAd
->CommonCfg
.SsidLen
, pAd
->CommonCfg
.Ssid
,
2653 SupRateLen
, SupRate
,
2656 1, &pAd
->CommonCfg
.Channel
,
2659 2, &pAd
->StaActive
.AtimWin
,
2662 // add ERP_IE and EXT_RAE IE of in 802.11g
2667 MakeOutgoingFrame(pBeaconFrame
+ FrameLen
, &tmp
,
2671 ExtRateLen
, ExtRate
,
2676 // If adhoc secruity is set for WPA-None, append the cipher suite IE
2677 if (pAd
->StaCfg
.AuthMode
== Ndis802_11AuthModeWPANone
)
2680 RTMPMakeRSNIE(pAd
, pAd
->StaCfg
.AuthMode
, pAd
->StaCfg
.WepStatus
, BSS0
);
2682 MakeOutgoingFrame(pBeaconFrame
+ FrameLen
, &tmp
,
2684 1, &pAd
->StaCfg
.RSNIE_Len
,
2685 pAd
->StaCfg
.RSNIE_Len
, pAd
->StaCfg
.RSN_IE
,
2690 #ifdef DOT11_N_SUPPORT
2691 if ((pAd
->CommonCfg
.PhyMode
>= PHY_11ABGN_MIXED
))
2694 UCHAR HtLen
, HtLen1
;
2696 #ifdef RT_BIG_ENDIAN
2697 HT_CAPABILITY_IE HtCapabilityTmp
;
2698 ADD_HT_INFO_IE addHTInfoTmp
;
2699 USHORT b2lTmp
, b2lTmp2
;
2702 // add HT Capability IE
2703 HtLen
= sizeof(pAd
->CommonCfg
.HtCapability
);
2704 HtLen1
= sizeof(pAd
->CommonCfg
.AddHTInfo
);
2705 #ifndef RT_BIG_ENDIAN
2706 MakeOutgoingFrame(pBeaconFrame
+FrameLen
, &TmpLen
,
2709 HtLen
, &pAd
->CommonCfg
.HtCapability
,
2712 HtLen1
, &pAd
->CommonCfg
.AddHTInfo
,
2715 NdisMoveMemory(&HtCapabilityTmp
, &pAd
->CommonCfg
.HtCapability
, HtLen
);
2716 *(USHORT
*)(&HtCapabilityTmp
.HtCapInfo
) = SWAP16(*(USHORT
*)(&HtCapabilityTmp
.HtCapInfo
));
2717 *(USHORT
*)(&HtCapabilityTmp
.ExtHtCapInfo
) = SWAP16(*(USHORT
*)(&HtCapabilityTmp
.ExtHtCapInfo
));
2719 NdisMoveMemory(&addHTInfoTmp
, &pAd
->CommonCfg
.AddHTInfo
, HtLen1
);
2720 *(USHORT
*)(&addHTInfoTmp
.AddHtInfo2
) = SWAP16(*(USHORT
*)(&addHTInfoTmp
.AddHtInfo2
));
2721 *(USHORT
*)(&addHTInfoTmp
.AddHtInfo3
) = SWAP16(*(USHORT
*)(&addHTInfoTmp
.AddHtInfo3
));
2723 MakeOutgoingFrame(pBeaconFrame
+FrameLen
, &TmpLen
,
2726 HtLen
, &HtCapabilityTmp
,
2729 HtLen1
, &addHTInfoTmp
,
2734 #endif // DOT11_N_SUPPORT //
2736 //beacon use reserved WCID 0xff
2737 if (pAd
->CommonCfg
.Channel
> 14)
2739 RTMPWriteTxWI(pAd
, pTxWI
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, TRUE
, 0, 0xff, FrameLen
,
2740 PID_MGMT
, PID_BEACON
, RATE_1
, IFS_HTTXOP
, FALSE
, &pAd
->CommonCfg
.MlmeTransmit
);
2744 // Set to use 1Mbps for Adhoc beacon.
2745 HTTRANSMIT_SETTING Transmit
;
2747 RTMPWriteTxWI(pAd
, pTxWI
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
, TRUE
, 0, 0xff, FrameLen
,
2748 PID_MGMT
, PID_BEACON
, RATE_1
, IFS_HTTXOP
, FALSE
, &Transmit
);
2751 #ifdef RT_BIG_ENDIAN
2752 RTMPFrameEndianChange(pAd
, pBeaconFrame
, DIR_WRITE
, FALSE
);
2753 RTMPWIEndianChange((PUCHAR
)pTxWI
, TYPE_TXWI
);
2756 DBGPRINT(RT_DEBUG_TRACE
, ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
2757 FrameLen
, SupRateLen
, ExtRateLen
, pAd
->CommonCfg
.Channel
, pAd
->CommonCfg
.PhyMode
));