blob: 9c7752076b008e5591dfdd67c3866a989f665263 [file] [log] [blame]
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001/*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
7 *
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
9 *
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. *
14 * *
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. *
19 * *
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. *
24 * *
25 *************************************************************************
26
27 Module Name:
28 connect.c
29
30 Abstract:
31
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 John 2004-08-08 Major modification from RT2560
36*/
37#include "../rt_config.h"
38
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -080039u8 CipherSuiteWpaNoneTkip[] = {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -080040 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 */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -080047};
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070048
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -080049u8 CipherSuiteWpaNoneTkipLen =
50 (sizeof(CipherSuiteWpaNoneTkip) / sizeof(u8));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -080051
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -080052u8 CipherSuiteWpaNoneAes[] = {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -080053 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 */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -080060};
61
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -080062u8 CipherSuiteWpaNoneAesLen =
63 (sizeof(CipherSuiteWpaNoneAes) / sizeof(u8));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070064
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -080065/* The following MACRO is called after 1. starting an new IBSS, 2. succesfully JOIN an IBSS, */
66/* or 3. succesfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS */
67/* All settings successfuly negotiated furing MLME state machines become final settings */
68/* and are copied to pAd->StaActive */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070069#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \
70{ \
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020071 NdisZeroMemory((_pAd)->CommonCfg.Ssid, MAX_LEN_OF_SSID); \
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070072 (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \
73 NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \
74 COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \
75 (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \
76 (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \
77 (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \
78 (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \
79 (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \
80 (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \
81 (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \
82 (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \
83 (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \
84 NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\
85 (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \
86 NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -080087 NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(struct rt_edca_parm));\
88 NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(struct rt_qos_capability_parm));\
89 NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(struct rt_qbss_load_parm));\
Greg Kroah-Hartman91980992008-10-28 14:48:09 -070090 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \
91 (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \
92 (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\
93 COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\
94 (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\
95}
96
97/*
98 ==========================================================================
99 Description:
100
101 IRQL = PASSIVE_LEVEL
102
103 ==========================================================================
104*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800105void MlmeCntlInit(struct rt_rtmp_adapter *pAd,
106 struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[])
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700107{
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800108 /* Control state machine differs from other state machines, the interface */
109 /* follows the standard interface */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700110 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
111}
112
113/*
114 ==========================================================================
115 Description:
116
117 IRQL = DISPATCH_LEVEL
118
119 ==========================================================================
120*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800121void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd,
122 struct rt_state_machine *S,
123 struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700124{
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800125 switch (pAd->Mlme.CntlMachine.CurrState) {
126 case CNTL_IDLE:
127 CntlIdleProc(pAd, Elem);
128 break;
129 case CNTL_WAIT_DISASSOC:
130 CntlWaitDisassocProc(pAd, Elem);
131 break;
132 case CNTL_WAIT_JOIN:
133 CntlWaitJoinProc(pAd, Elem);
134 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700135
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800136 /* CNTL_WAIT_REASSOC is the only state in CNTL machine that does */
137 /* not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)". */
138 /* Therefore not protected by NDIS's "only one outstanding OID request" */
139 /* rule. Which means NDIS may SET OID in the middle of ROAMing attempts. */
140 /* Current approach is to block new SET request at RTMPSetInformation() */
141 /* when CntlMachine.CurrState is not CNTL_IDLE */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800142 case CNTL_WAIT_REASSOC:
143 CntlWaitReassocProc(pAd, Elem);
144 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700145
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800146 case CNTL_WAIT_START:
147 CntlWaitStartProc(pAd, Elem);
148 break;
149 case CNTL_WAIT_AUTH:
150 CntlWaitAuthProc(pAd, Elem);
151 break;
152 case CNTL_WAIT_AUTH2:
153 CntlWaitAuthProc2(pAd, Elem);
154 break;
155 case CNTL_WAIT_ASSOC:
156 CntlWaitAssocProc(pAd, Elem);
157 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700158
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800159 case CNTL_WAIT_OID_LIST_SCAN:
160 if (Elem->MsgType == MT2_SCAN_CONF) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800161 /* 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 */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800163 RTMPResumeMsduTransmission(pAd);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200164
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800165 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700166
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800167 /* */
168 /* Set LED status to previous status. */
169 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800170 if (pAd->bLedOnScanning) {
171 pAd->bLedOnScanning = FALSE;
172 RTMPSetLED(pAd, pAd->LedStatus);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700173 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800174 }
175 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700176
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800177 case CNTL_WAIT_OID_DISASSOC:
178 if (Elem->MsgType == MT2_DISASSOC_CONF) {
179 LinkDown(pAd, FALSE);
180 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
181 }
182 break;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200183#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800184 /* */
185 /* This state is for that we want to connect to an AP but */
186 /* it didn't find on BSS List table. So we need to scan the air first, */
187 /* after that we can try to connect to the desired AP if available. */
188 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800189 case CNTL_WAIT_SCAN_FOR_CONNECT:
190 if (Elem->MsgType == MT2_SCAN_CONF) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800191 /* Resume TxRing after SCANING complete. We hope the out-of-service time */
192 /* won't be too long to let upper layer time-out the waiting frames */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800193 RTMPResumeMsduTransmission(pAd);
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +0200194#ifdef CCX_SUPPORT
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800195 if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800196 /* Cisco scan request is finished, prepare beacon report */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800197 MlmeEnqueue(pAd, AIRONET_STATE_MACHINE,
198 MT2_AIRONET_SCAN_DONE, 0, NULL);
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +0200199 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800200#endif /* CCX_SUPPORT // */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800201 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
202
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800203 /* */
204 /* Check if we can connect to. */
205 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800206 BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800207 (char *) pAd->MlmeAux.
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800208 AutoReconnectSsid,
209 pAd->MlmeAux.AutoReconnectSsidLen);
210 if (pAd->MlmeAux.SsidBssTab.BssNr > 0) {
211 MlmeAutoReconnectLastSSID(pAd);
212 }
213 }
214 break;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800215#endif /* RTMP_MAC_USB // */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800216 default:
217 DBGPRINT_ERR(("!ERROR! CNTL - Illegal message type(=%ld)",
218 Elem->MsgType));
219 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700220 }
221}
222
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700223/*
224 ==========================================================================
225 Description:
226
227 IRQL = DISPATCH_LEVEL
228
229 ==========================================================================
230*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800231void CntlIdleProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700232{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800233 struct rt_mlme_disassoc_req DisassocReq;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700234
235 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF))
236 return;
237
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800238 switch (Elem->MsgType) {
239 case OID_802_11_SSID:
240 CntlOidSsidProc(pAd, Elem);
241 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700242
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800243 case OID_802_11_BSSID:
244 CntlOidRTBssidProc(pAd, Elem);
245 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700246
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800247 case OID_802_11_BSSID_LIST_SCAN:
248 CntlOidScanProc(pAd, Elem);
249 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700250
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800251 case OID_802_11_DISASSOCIATE:
252 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid,
253 REASON_DISASSOC_STA_LEAVING);
254 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800255 sizeof(struct rt_mlme_disassoc_req), &DisassocReq);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800256 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC;
Bartlomiej Zolnierkiewicze08bae52009-04-26 16:05:56 +0200257
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800258 if (pAd->StaCfg.WpaSupplicantUP !=
259 WPA_SUPPLICANT_ENABLE_WITH_WEB_UI) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800260 /* Set the AutoReconnectSsid to prevent it reconnect to old SSID */
261 /* Since calling this indicate user don't want to connect to that SSID anymore. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800262 pAd->MlmeAux.AutoReconnectSsidLen = 32;
263 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid,
264 pAd->MlmeAux.AutoReconnectSsidLen);
265 }
266 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700267
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800268 case MT2_MLME_ROAMING_REQ:
269 CntlMlmeRoamingProc(pAd, Elem);
270 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700271
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800272 case OID_802_11_MIC_FAILURE_REPORT_FRAME:
273 WpaMicFailureReportFrame(pAd, Elem);
274 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700275
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800276 default:
277 DBGPRINT(RT_DEBUG_TRACE,
278 ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n",
279 Elem->MsgType));
280 break;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700281 }
282}
283
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800284void CntlOidScanProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700285{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800286 struct rt_mlme_scan_req ScanReq;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800287 unsigned long BssIdx = BSS_NOT_FOUND;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800288 struct rt_bss_entry CurrBss;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200289
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800290 /* record current BSS if network is connected. */
291 /* 2003-2-13 do not include current IBSS if this is the only STA in this IBSS. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800292 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) {
293 BssIdx =
294 BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800295 (u8 *)pAd->CommonCfg.Ssid,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800296 pAd->CommonCfg.SsidLen,
297 pAd->CommonCfg.Channel);
298 if (BssIdx != BSS_NOT_FOUND) {
299 NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx],
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800300 sizeof(struct rt_bss_entry));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700301 }
302 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800303 /* clean up previous SCAN result, add current BSS back to table if any */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700304 BssTableInit(&pAd->ScanTab);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800305 if (BssIdx != BSS_NOT_FOUND) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800306 /* DDK Note: If the NIC is associated with a particular BSSID and SSID */
307 /* that are not contained in the list of BSSIDs generated by this scan, the */
308 /* BSSID description of the currently associated BSSID and SSID should be */
309 /* appended to the list of BSSIDs in the NIC's database. */
310 /* To ensure this, we append this BSS as the first entry in SCAN result */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800311 NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800312 sizeof(struct rt_bss_entry));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700313 pAd->ScanTab.BssNr = 1;
314 }
315
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800316 ScanParmFill(pAd, &ScanReq, (char *)Elem->Msg, Elem->MsgLen, BSS_ANY,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800317 SCAN_ACTIVE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700318 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800319 sizeof(struct rt_mlme_scan_req), &ScanReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700320 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
321}
322
323/*
324 ==========================================================================
325 Description:
326 Before calling this routine, user desired SSID should already been
327 recorded in CommonCfg.Ssid[]
328 IRQL = DISPATCH_LEVEL
329
330 ==========================================================================
331*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800332void CntlOidSsidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700333{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800334 struct rt_ndis_802_11_ssid * pOidSsid = (struct rt_ndis_802_11_ssid *) Elem->Msg;
335 struct rt_mlme_disassoc_req DisassocReq;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800336 unsigned long Now;
Adam McDanieled291e82009-02-23 08:01:07 -0700337
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800338 /* Step 1. record the desired user settings to MlmeAux */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700339 NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
340 NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength);
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800341 pAd->MlmeAux.SsidLen = (u8)pOidSsid->SsidLength;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700342 NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
343 pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
344
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200345 pAd->StaCfg.bAutoConnectByBssid = FALSE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700346
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800347 /* */
348 /* Update Reconnect Ssid, that user desired to connect. */
349 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700350 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800351 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid,
352 pAd->MlmeAux.SsidLen);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700353 pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen;
354
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800355 /* step 2. find all matching BSS in the lastest SCAN result (inBssTab) */
356 /* & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800357 BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800358 (char *)pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700359
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800360 DBGPRINT(RT_DEBUG_TRACE,
361 ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n",
362 pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr,
363 pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700364 NdisGetSystemUpTime(&Now);
365
366 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) &&
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800367 (pAd->CommonCfg.SsidLen ==
368 pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen)
369 && NdisEqualMemory(pAd->CommonCfg.Ssid,
370 pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid,
371 pAd->CommonCfg.SsidLen)
372 && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid,
373 pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800374 /* Case 1. already connected with an AP who has the desired SSID */
375 /* with highest RSSI */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700376
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800377 /* Add checking Mode "LEAP" for CCX 1.0 */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700378 if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) ||
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800379 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
380 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
381 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)
382 ) &&
383 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800384 /* case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo */
385 /* connection process */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800386 DBGPRINT(RT_DEBUG_TRACE,
387 ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
388 DisassocParmFill(pAd, &DisassocReq,
389 pAd->CommonCfg.Bssid,
390 REASON_DISASSOC_STA_LEAVING);
391 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
392 MT2_MLME_DISASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800393 sizeof(struct rt_mlme_disassoc_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800394 &DisassocReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700395 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800396 } else if (pAd->bConfigChanged == TRUE) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800397 /* case 1.2 Important Config has changed, we have to reconnect to the same AP */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800398 DBGPRINT(RT_DEBUG_TRACE,
399 ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n"));
400 DisassocParmFill(pAd, &DisassocReq,
401 pAd->CommonCfg.Bssid,
402 REASON_DISASSOC_STA_LEAVING);
403 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
404 MT2_MLME_DISASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800405 sizeof(struct rt_mlme_disassoc_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800406 &DisassocReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700407 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800408 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800409 /* case 1.3. already connected to the SSID with highest RSSI. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800410 DBGPRINT(RT_DEBUG_TRACE,
411 ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n"));
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800412 /* */
413 /* (HCT 12.1) 1c_wlan_mediaevents required */
414 /* media connect events are indicated when associating with the same AP */
415 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800416 if (INFRA_ON(pAd)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800417 /* */
418 /* Since MediaState already is NdisMediaStateConnected */
419 /* We just indicate the connect event again to meet the WHQL required. */
420 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800421 pAd->IndicateMediaState =
422 NdisMediaStateConnected;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700423 RTMP_IndicateMediaState(pAd);
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800424 pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information to link is up */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700425 }
426
427 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800428 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1,
429 &pAd->MlmeAux.Bssid[0], NULL,
430 0);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700431 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800432 } else if (INFRA_ON(pAd)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800433 /* */
434 /* For RT61 */
435 /* [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: ) */
436 /* RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect */
437 /* But media status is connected, so the SSID not report correctly. */
438 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800439 if (!SSID_EQUAL
440 (pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen,
441 pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800442 /* */
443 /* Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event. */
444 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700445 pAd->MlmeAux.CurrReqIsFromNdis = TRUE;
446 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800447 /* case 2. active INFRA association existent */
448 /* roaming is done within miniport driver, nothing to do with configuration */
449 /* utility. so upon a new SET(OID_802_11_SSID) is received, we just */
450 /* disassociate with the current associated AP, */
451 /* then perform a new association with this new SSID, no matter the */
452 /* new/old SSID are the same or not. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800453 DBGPRINT(RT_DEBUG_TRACE,
454 ("CntlOidSsidProc():CNTL - disassociate with current AP...\n"));
455 DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid,
456 REASON_DISASSOC_STA_LEAVING);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700457 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800458 sizeof(struct rt_mlme_disassoc_req), &DisassocReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700459 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800460 } else {
461 if (ADHOC_ON(pAd)) {
462 DBGPRINT(RT_DEBUG_TRACE,
463 ("CntlOidSsidProc():CNTL - drop current ADHOC\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700464 LinkDown(pAd, FALSE);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800465 OPSTATUS_CLEAR_FLAG(pAd,
466 fOP_STATUS_MEDIA_STATE_CONNECTED);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700467 pAd->IndicateMediaState = NdisMediaStateDisconnected;
468 RTMP_IndicateMediaState(pAd);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800469 pAd->ExtraInfo = GENERAL_LINK_DOWN;
470 DBGPRINT(RT_DEBUG_TRACE,
471 ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700472 }
473
474 if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) &&
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800475 (pAd->StaCfg.bAutoReconnect == TRUE) &&
476 (pAd->MlmeAux.BssType == BSS_INFRA) &&
477 (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen)
478 == TRUE)
479 ) {
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800480 struct rt_mlme_scan_req ScanReq;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700481
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800482 DBGPRINT(RT_DEBUG_TRACE,
483 ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n"));
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800484 ScanParmFill(pAd, &ScanReq, (char *)pAd->MlmeAux.Ssid,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800485 pAd->MlmeAux.SsidLen, BSS_ANY,
486 SCAN_ACTIVE);
487 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800488 sizeof(struct rt_mlme_scan_req), &ScanReq);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800489 pAd->Mlme.CntlMachine.CurrState =
490 CNTL_WAIT_OID_LIST_SCAN;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800491 /* Reset Missed scan number */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700492 pAd->StaCfg.LastScanTime = Now;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800493 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700494 pAd->MlmeAux.BssIdx = 0;
495 IterateOnBssTab(pAd);
496 }
497 }
498}
499
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700500/*
501 ==========================================================================
502 Description:
503
504 IRQL = DISPATCH_LEVEL
505
506 ==========================================================================
507*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800508void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700509{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800510 unsigned long BssIdx;
511 u8 *pOidBssid = (u8 *)Elem->Msg;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800512 struct rt_mlme_disassoc_req DisassocReq;
513 struct rt_mlme_join_req JoinReq;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700514
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800515 /* record user desired settings */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700516 COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid);
517 pAd->MlmeAux.BssType = pAd->StaCfg.BssType;
518
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800519 /* find the desired BSS in the latest SCAN result table */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700520 BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800521 if (BssIdx == BSS_NOT_FOUND) {
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800522 struct rt_mlme_scan_req ScanReq;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200523
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800524 DBGPRINT(RT_DEBUG_TRACE,
525 ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n"));
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800526 /*pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200527
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800528 DBGPRINT(RT_DEBUG_TRACE,
529 ("CNTL - BSSID not found. start a new scan\n"));
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800530 ScanParmFill(pAd, &ScanReq, (char *)pAd->MlmeAux.Ssid,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800531 pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE);
532 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800533 sizeof(struct rt_mlme_scan_req), &ScanReq);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200534 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800535 /* Reset Missed scan number */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200536 NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700537 return;
538 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800539 /* */
540 /* Update Reconnect Ssid, that user desired to connect. */
541 /* */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200542 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800543 pAd->MlmeAux.AutoReconnectSsidLen =
544 pAd->ScanTab.BssEntry[BssIdx].SsidLen;
545 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid,
546 pAd->ScanTab.BssEntry[BssIdx].Ssid,
547 pAd->ScanTab.BssEntry[BssIdx].SsidLen);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200548
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800549 /* copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why? */
550 /* Because we need this entry to become the JOIN target in later on SYNC state machine */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700551 pAd->MlmeAux.BssIdx = 0;
552 pAd->MlmeAux.SsidBssTab.BssNr = 1;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800553 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0],
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800554 &pAd->ScanTab.BssEntry[BssIdx], sizeof(struct rt_bss_entry));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700555
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800556 /* Add SSID into MlmeAux for site surey joining hidden SSID */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200557 pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800558 NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid,
559 pAd->MlmeAux.SsidLen);
Bartlomiej Zolnierkiewicz2684d162009-04-26 16:05:51 +0200560
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700561 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800562 if (INFRA_ON(pAd)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800563 /* disassoc from current AP first */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800564 DBGPRINT(RT_DEBUG_TRACE,
565 ("CNTL - disassociate with current AP ...\n"));
566 DisassocParmFill(pAd, &DisassocReq,
567 pAd->CommonCfg.Bssid,
568 REASON_DISASSOC_STA_LEAVING);
569 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
570 MT2_MLME_DISASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800571 sizeof(struct rt_mlme_disassoc_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800572 &DisassocReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700573
574 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800575 } else {
576 if (ADHOC_ON(pAd)) {
577 DBGPRINT(RT_DEBUG_TRACE,
578 ("CNTL - drop current ADHOC\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700579 LinkDown(pAd, FALSE);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800580 OPSTATUS_CLEAR_FLAG(pAd,
581 fOP_STATUS_MEDIA_STATE_CONNECTED);
582 pAd->IndicateMediaState =
583 NdisMediaStateDisconnected;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700584 RTMP_IndicateMediaState(pAd);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800585 pAd->ExtraInfo = GENERAL_LINK_DOWN;
586 DBGPRINT(RT_DEBUG_TRACE,
587 ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700588 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800589 /* Change the wepstatus to original wepstatus */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800590 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
591 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700592 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
593
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800594 /* Check cipher suite, AP must have more secured cipher than station setting */
595 /* Set the Pairwise and Group cipher to match the intended AP setting */
596 /* We can only connect to AP with less secured cipher setting */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800597 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA)
598 || (pAd->StaCfg.AuthMode ==
599 Ndis802_11AuthModeWPAPSK)) {
600 pAd->StaCfg.GroupCipher =
601 pAd->ScanTab.BssEntry[BssIdx].WPA.
602 GroupCipher;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700603
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800604 if (pAd->StaCfg.WepStatus ==
605 pAd->ScanTab.BssEntry[BssIdx].WPA.
606 PairCipher)
607 pAd->StaCfg.PairCipher =
608 pAd->ScanTab.BssEntry[BssIdx].WPA.
609 PairCipher;
610 else if (pAd->ScanTab.BssEntry[BssIdx].WPA.
611 PairCipherAux != Ndis802_11WEPDisabled)
612 pAd->StaCfg.PairCipher =
613 pAd->ScanTab.BssEntry[BssIdx].WPA.
614 PairCipherAux;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800615 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800616 pAd->StaCfg.PairCipher =
617 Ndis802_11Encryption2Enabled;
618 } else
619 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
620 || (pAd->StaCfg.AuthMode ==
621 Ndis802_11AuthModeWPA2PSK)) {
622 pAd->StaCfg.GroupCipher =
623 pAd->ScanTab.BssEntry[BssIdx].WPA2.
624 GroupCipher;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700625
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800626 if (pAd->StaCfg.WepStatus ==
627 pAd->ScanTab.BssEntry[BssIdx].WPA2.
628 PairCipher)
629 pAd->StaCfg.PairCipher =
630 pAd->ScanTab.BssEntry[BssIdx].WPA2.
631 PairCipher;
632 else if (pAd->ScanTab.BssEntry[BssIdx].WPA2.
633 PairCipherAux != Ndis802_11WEPDisabled)
634 pAd->StaCfg.PairCipher =
635 pAd->ScanTab.BssEntry[BssIdx].WPA2.
636 PairCipherAux;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800637 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800638 pAd->StaCfg.PairCipher =
639 Ndis802_11Encryption2Enabled;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700640
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800641 /* RSN capability */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800642 pAd->StaCfg.RsnCapability =
643 pAd->ScanTab.BssEntry[BssIdx].WPA2.
644 RsnCapability;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700645 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800646 /* Set Mix cipher flag */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800647 pAd->StaCfg.bMixCipher =
648 (pAd->StaCfg.PairCipher ==
649 pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200650 /*if (pAd->StaCfg.bMixCipher == TRUE)
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800651 {
652 // If mix cipher, re-build RSNIE
653 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
654 } */
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800655 /* No active association, join the BSS immediately */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800656 DBGPRINT(RT_DEBUG_TRACE,
657 ("CNTL - joining %02x:%02x:%02x:%02x:%02x:%02x ...\n",
658 pOidBssid[0], pOidBssid[1], pOidBssid[2],
659 pOidBssid[3], pOidBssid[4], pOidBssid[5]));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700660
661 JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800662 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800663 sizeof(struct rt_mlme_join_req), &JoinReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700664
665 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
666 }
667 }
668}
669
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800670/* Roaming is the only external request triggering CNTL state machine */
671/* despite of other "SET OID" operation. All "SET OID" related oerations */
672/* happen in sequence, because no other SET OID will be sent to this device */
673/* until the the previous SET operation is complete (successful o failed). */
674/* So, how do we quarantee this ROAMING request won't corrupt other "SET OID"? */
675/* or been corrupted by other "SET OID"? */
676/* */
677/* IRQL = DISPATCH_LEVEL */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800678void CntlMlmeRoamingProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700679{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800680 u8 BBPValue = 0;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200681
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800682 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Roaming in MlmeAux.RoamTab...\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700683
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200684 {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800685 /*Let BBP register at 20MHz to do (fast) roaming. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200686 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
687 BBPValue &= (~0x18);
688 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
689
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800690 NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab,
691 sizeof(pAd->MlmeAux.RoamTab));
692 pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700693
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800694 BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab);
695 pAd->MlmeAux.BssIdx = 0;
696 IterateOnBssTab(pAd);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200697 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700698}
699
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700700/*
701 ==========================================================================
702 Description:
703
704 IRQL = DISPATCH_LEVEL
705
706 ==========================================================================
707*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800708void CntlWaitDisassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700709{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800710 struct rt_mlme_start_req StartReq;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700711
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800712 if (Elem->MsgType == MT2_DISASSOC_CONF) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700713 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n"));
714
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800715 if (pAd->CommonCfg.bWirelessEvent) {
716 RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG,
717 pAd->MacTab.Content[BSSID_WCID].
718 Addr, BSS0, 0);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700719 }
720
721 LinkDown(pAd, FALSE);
722
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800723 /* case 1. no matching BSS, and user wants ADHOC, so we just start a new one */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800724 if ((pAd->MlmeAux.SsidBssTab.BssNr == 0)
725 && (pAd->StaCfg.BssType == BSS_ADHOC)) {
726 DBGPRINT(RT_DEBUG_TRACE,
727 ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n",
728 pAd->MlmeAux.Ssid));
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800729 StartParmFill(pAd, &StartReq, (char *)pAd->MlmeAux.Ssid,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800730 pAd->MlmeAux.SsidLen);
731 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800732 sizeof(struct rt_mlme_start_req), &StartReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700733 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
734 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800735 /* case 2. try each matched BSS */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800736 else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700737 pAd->MlmeAux.BssIdx = 0;
738
739 IterateOnBssTab(pAd);
740 }
741 }
742}
743
744/*
745 ==========================================================================
746 Description:
747
748 IRQL = DISPATCH_LEVEL
749
750 ==========================================================================
751*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800752void CntlWaitJoinProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700753{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800754 u16 Reason;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800755 struct rt_mlme_auth_req AuthReq;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700756
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800757 if (Elem->MsgType == MT2_JOIN_CONF) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800758 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800759 if (Reason == MLME_SUCCESS) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800760 /* 1. joined an IBSS, we are pretty much done here */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800761 if (pAd->MlmeAux.BssType == BSS_ADHOC) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800762 /* */
763 /* 5G bands rules of Japan: */
764 /* Ad hoc must be disabled in W53(ch52,56,60,64) channels. */
765 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800766 if ((pAd->CommonCfg.bIEEE80211H == 1) &&
767 RadarChannelCheck(pAd,
768 pAd->CommonCfg.Channel)
769 ) {
770 pAd->Mlme.CntlMachine.CurrState =
771 CNTL_IDLE;
772 DBGPRINT(RT_DEBUG_TRACE,
773 ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n",
774 pAd->CommonCfg.Channel));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700775 return;
776 }
777
778 LinkUp(pAd, BSS_ADHOC);
779 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800780 DBGPRINT(RT_DEBUG_TRACE,
781 ("CNTL - join the IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
782 pAd->CommonCfg.Bssid[0],
783 pAd->CommonCfg.Bssid[1],
784 pAd->CommonCfg.Bssid[2],
785 pAd->CommonCfg.Bssid[3],
786 pAd->CommonCfg.Bssid[4],
787 pAd->CommonCfg.Bssid[5]));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700788
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800789 pAd->IndicateMediaState =
790 NdisMediaStateConnected;
791 pAd->ExtraInfo = GENERAL_LINK_UP;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700792 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800793 /* 2. joined a new INFRA network, start from authentication */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800794 else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700795 {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800796 /* either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800797 if ((pAd->StaCfg.AuthMode ==
798 Ndis802_11AuthModeShared)
799 || (pAd->StaCfg.AuthMode ==
800 Ndis802_11AuthModeAutoSwitch)) {
801 AuthParmFill(pAd, &AuthReq,
802 pAd->MlmeAux.Bssid,
803 AUTH_MODE_KEY);
804 } else {
805 AuthParmFill(pAd, &AuthReq,
806 pAd->MlmeAux.Bssid,
807 AUTH_MODE_OPEN);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700808 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800809 MlmeEnqueue(pAd, AUTH_STATE_MACHINE,
810 MT2_MLME_AUTH_REQ,
811 sizeof
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800812 (struct rt_mlme_auth_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800813 &AuthReq);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200814 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700815
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800816 pAd->Mlme.CntlMachine.CurrState =
817 CNTL_WAIT_AUTH;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700818 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800819 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800820 /* 3. failed, try next BSS */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700821 pAd->MlmeAux.BssIdx++;
822 IterateOnBssTab(pAd);
823 }
824 }
825}
826
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700827/*
828 ==========================================================================
829 Description:
830
831 IRQL = DISPATCH_LEVEL
832
833 ==========================================================================
834*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800835void CntlWaitStartProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700836{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800837 u16 Result;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700838
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800839 if (Elem->MsgType == MT2_START_CONF) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800840 NdisMoveMemory(&Result, Elem->Msg, sizeof(u16));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800841 if (Result == MLME_SUCCESS) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800842 /* */
843 /* 5G bands rules of Japan: */
844 /* Ad hoc must be disabled in W53(ch52,56,60,64) channels. */
845 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800846 if ((pAd->CommonCfg.bIEEE80211H == 1) &&
847 RadarChannelCheck(pAd, pAd->CommonCfg.Channel)
848 ) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700849 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800850 DBGPRINT(RT_DEBUG_TRACE,
851 ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n",
852 pAd->CommonCfg.Channel));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700853 return;
854 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800855 NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo.
856 MCSSet[0], 16);
857 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700858 N_ChannelCheck(pAd);
859 SetCommonHT(pAd);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800860 NdisMoveMemory(&pAd->MlmeAux.AddHtInfo,
861 &pAd->CommonCfg.AddHTInfo,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800862 sizeof(struct rt_add_ht_info_ie));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800863 RTMPCheckHt(pAd, BSSID_WCID,
864 &pAd->CommonCfg.HtCapability,
865 &pAd->CommonCfg.AddHTInfo);
866 pAd->StaActive.SupportedPhyInfo.bHtEnable =
867 TRUE;
868 NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo.
869 MCSSet[0],
870 &pAd->CommonCfg.HtCapability.
871 MCSSet[0], 16);
872 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG
873 (pAd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700874
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800875 if ((pAd->CommonCfg.HtCapability.HtCapInfo.
876 ChannelWidth == BW_40)
877 && (pAd->CommonCfg.AddHTInfo.AddHtInfo.
878 ExtChanOffset == EXTCHA_ABOVE)) {
879 pAd->MlmeAux.CentralChannel =
880 pAd->CommonCfg.Channel + 2;
881 } else
882 if ((pAd->CommonCfg.HtCapability.HtCapInfo.
883 ChannelWidth == BW_40)
884 && (pAd->CommonCfg.AddHTInfo.AddHtInfo.
885 ExtChanOffset == EXTCHA_BELOW)) {
886 pAd->MlmeAux.CentralChannel =
887 pAd->CommonCfg.Channel - 2;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700888 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800889 } else {
890 pAd->StaActive.SupportedPhyInfo.bHtEnable =
891 FALSE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700892 }
893 LinkUp(pAd, BSS_ADHOC);
894 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800895 /* Before send beacon, driver need do radar detection */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800896 if ((pAd->CommonCfg.Channel > 14)
897 && (pAd->CommonCfg.bIEEE80211H == 1)
898 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) {
899 pAd->CommonCfg.RadarDetect.RDMode =
900 RD_SILENCE_MODE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700901 pAd->CommonCfg.RadarDetect.RDCount = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700902 }
903
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800904 DBGPRINT(RT_DEBUG_TRACE,
905 ("CNTL - start a new IBSS = %02x:%02x:%02x:%02x:%02x:%02x ...\n",
906 pAd->CommonCfg.Bssid[0],
907 pAd->CommonCfg.Bssid[1],
908 pAd->CommonCfg.Bssid[2],
909 pAd->CommonCfg.Bssid[3],
910 pAd->CommonCfg.Bssid[4],
911 pAd->CommonCfg.Bssid[5]));
912 } else {
913 DBGPRINT(RT_DEBUG_TRACE,
914 ("CNTL - Start IBSS fail. BUG!!!!!\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700915 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
916 }
917 }
918}
919
920/*
921 ==========================================================================
922 Description:
923
924 IRQL = DISPATCH_LEVEL
925
926 ==========================================================================
927*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800928void CntlWaitAuthProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700929{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800930 u16 Reason;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800931 struct rt_mlme_assoc_req AssocReq;
932 struct rt_mlme_auth_req AuthReq;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700933
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800934 if (Elem->MsgType == MT2_AUTH_CONF) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800935 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800936 if (Reason == MLME_SUCCESS) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700937 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800938 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid,
939 pAd->MlmeAux.CapabilityInfo,
940 ASSOC_TIMEOUT,
941 pAd->StaCfg.DefaultListenCount);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700942
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700943 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800944 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
945 MT2_MLME_ASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800946 sizeof(struct rt_mlme_assoc_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800947 &AssocReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700948
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800949 pAd->Mlme.CntlMachine.CurrState =
950 CNTL_WAIT_ASSOC;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700951 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800952 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800953 /* This fail may because of the AP already keep us in its MAC table without */
954 /* ageing-out. The previous authentication attempt must have let it remove us. */
955 /* so try Authentication again may help. For D-Link DWL-900AP+ compatibility. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800956 DBGPRINT(RT_DEBUG_TRACE,
957 ("CNTL - AUTH FAIL, try again...\n"));
Bartlomiej Zolnierkiewicz720613f2009-04-26 16:05:24 +0200958
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700959 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800960 if ((pAd->StaCfg.AuthMode ==
961 Ndis802_11AuthModeShared)
962 || (pAd->StaCfg.AuthMode ==
963 Ndis802_11AuthModeAutoSwitch)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -0800964 /* either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800965 AuthParmFill(pAd, &AuthReq,
966 pAd->MlmeAux.Bssid,
967 AUTH_MODE_KEY);
968 } else {
969 AuthParmFill(pAd, &AuthReq,
970 pAd->MlmeAux.Bssid,
971 AUTH_MODE_OPEN);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700972 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800973 MlmeEnqueue(pAd, AUTH_STATE_MACHINE,
974 MT2_MLME_AUTH_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800975 sizeof(struct rt_mlme_auth_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800976 &AuthReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700977
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200978 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700979 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2;
980 }
981 }
982}
983
984/*
985 ==========================================================================
986 Description:
987
988 IRQL = DISPATCH_LEVEL
989
990 ==========================================================================
991*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800992void CntlWaitAuthProc2(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700993{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800994 u16 Reason;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800995 struct rt_mlme_assoc_req AssocReq;
996 struct rt_mlme_auth_req AuthReq;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -0700997
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -0800998 if (Elem->MsgType == MT2_AUTH_CONF) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800999 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001000 if (Reason == MLME_SUCCESS) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001001 DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n"));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001002 AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid,
1003 pAd->MlmeAux.CapabilityInfo,
1004 ASSOC_TIMEOUT,
1005 pAd->StaCfg.DefaultListenCount);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001006 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001007 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE,
1008 MT2_MLME_ASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001009 sizeof(struct rt_mlme_assoc_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001010 &AssocReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001011
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001012 pAd->Mlme.CntlMachine.CurrState =
1013 CNTL_WAIT_ASSOC;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001014 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001015 } else {
1016 if ((pAd->StaCfg.AuthMode ==
1017 Ndis802_11AuthModeAutoSwitch)
1018 && (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared)) {
1019 DBGPRINT(RT_DEBUG_TRACE,
1020 ("CNTL - AUTH FAIL, try OPEN system...\n"));
1021 AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid,
1022 Ndis802_11AuthModeOpen);
1023 MlmeEnqueue(pAd, AUTH_STATE_MACHINE,
1024 MT2_MLME_AUTH_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001025 sizeof(struct rt_mlme_auth_req),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001026 &AuthReq);
1027
1028 pAd->Mlme.CntlMachine.CurrState =
1029 CNTL_WAIT_AUTH2;
1030 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001031 /* not success, try next BSS */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001032 DBGPRINT(RT_DEBUG_TRACE,
1033 ("CNTL - AUTH FAIL, give up; try next BSS\n"));
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001034 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; /*??????? */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001035 pAd->MlmeAux.BssIdx++;
1036 IterateOnBssTab(pAd);
1037 }
1038 }
1039 }
1040}
1041
1042/*
1043 ==========================================================================
1044 Description:
1045
1046 IRQL = DISPATCH_LEVEL
1047
1048 ==========================================================================
1049*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001050void CntlWaitAssocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001051{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001052 u16 Reason;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001053
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001054 if (Elem->MsgType == MT2_ASSOC_CONF) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001055 NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001056 if (Reason == MLME_SUCCESS) {
1057 if (pAd->CommonCfg.bWirelessEvent) {
1058 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG,
1059 pAd->MacTab.
1060 Content[BSSID_WCID].Addr,
1061 BSS0, 0);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001062 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001063
1064 LinkUp(pAd, BSS_INFRA);
1065 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001066 DBGPRINT(RT_DEBUG_TRACE,
1067 ("CNTL - Association successful on BSS #%ld\n",
1068 pAd->MlmeAux.BssIdx));
1069 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001070 /* not success, try next BSS */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001071 DBGPRINT(RT_DEBUG_TRACE,
1072 ("CNTL - Association fails on BSS #%ld\n",
1073 pAd->MlmeAux.BssIdx));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001074 pAd->MlmeAux.BssIdx++;
1075 IterateOnBssTab(pAd);
1076 }
1077 }
1078}
1079
1080/*
1081 ==========================================================================
1082 Description:
1083
1084 IRQL = DISPATCH_LEVEL
1085
1086 ==========================================================================
1087*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001088void CntlWaitReassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001089{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001090 u16 Result;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001091
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001092 if (Elem->MsgType == MT2_REASSOC_CONF) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001093 NdisMoveMemory(&Result, Elem->Msg, sizeof(u16));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001094 if (Result == MLME_SUCCESS) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001095 /* send wireless event - for association */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001096 if (pAd->CommonCfg.bWirelessEvent)
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001097 RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG,
1098 pAd->MacTab.
1099 Content[BSSID_WCID].Addr,
1100 BSS0, 0);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001101
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001102 /* */
1103 /* NDIS requires a new Link UP indication but no Link Down for RE-ASSOC */
1104 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001105 LinkUp(pAd, BSS_INFRA);
1106
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001107 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001108 DBGPRINT(RT_DEBUG_TRACE,
1109 ("CNTL - Re-assocition successful on BSS #%ld\n",
1110 pAd->MlmeAux.RoamIdx));
1111 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001112 /* reassoc failed, try to pick next BSS in the BSS Table */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001113 DBGPRINT(RT_DEBUG_TRACE,
1114 ("CNTL - Re-assocition fails on BSS #%ld\n",
1115 pAd->MlmeAux.RoamIdx));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001116 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001117 pAd->MlmeAux.RoamIdx++;
1118 IterateOnBssTab2(pAd);
1119 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001120 }
1121 }
1122}
1123
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001124void AdhocTurnOnQos(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02001125{
1126#define AC0_DEF_TXOP 0
1127#define AC1_DEF_TXOP 0
1128#define AC2_DEF_TXOP 94
1129#define AC3_DEF_TXOP 47
1130
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001131 /* Turn on QOs if use HT rate. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001132 if (pAd->CommonCfg.APEdcaParm.bValid == FALSE) {
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02001133 pAd->CommonCfg.APEdcaParm.bValid = TRUE;
1134 pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
1135 pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
1136 pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
1137 pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
1138
1139 pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
1140 pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
1141 pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
1142 pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
1143
1144 pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10;
1145 pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6;
1146 pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
1147 pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
1148
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001149 pAd->CommonCfg.APEdcaParm.Txop[0] = 0;
1150 pAd->CommonCfg.APEdcaParm.Txop[1] = 0;
1151 pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP;
1152 pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP;
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02001153 }
1154 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1155}
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02001156
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001157/*
1158 ==========================================================================
1159 Description:
1160
1161 IRQL = DISPATCH_LEVEL
1162
1163 ==========================================================================
1164*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001165void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001166{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001167 unsigned long Now;
1168 u32 Data;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001169 BOOLEAN Cancelled;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001170 u8 Value = 0, idx = 0, HashIdx = 0;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001171 struct rt_mac_table_entry *pEntry = NULL, *pCurrEntry = NULL;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001172
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001173 /* Init ChannelQuality to prevent DEAD_CQI at initial LinkUp */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001174 pAd->Mlme.ChannelQuality = 50;
1175
1176 pEntry = MacTableLookup(pAd, pAd->CommonCfg.Bssid);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001177 if (pEntry) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001178 MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr);
1179 pEntry = NULL;
Adam McDanieled291e82009-02-23 08:01:07 -07001180 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001181
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001182 pEntry = &pAd->MacTab.Content[BSSID_WCID];
1183
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001184 /* */
1185 /* ASSOC - DisassocTimeoutAction */
1186 /* CNTL - Dis-associate successful */
1187 /* !!! LINK DOWN !!! */
1188 /* [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: ) */
1189 /* */
1190 /* To prevent DisassocTimeoutAction to call Link down after we link up, */
1191 /* cancel the DisassocTimer no matter what it start or not. */
1192 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001193 RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001194
1195 COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
1196
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001197 COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd);
Bartlomiej Zolnierkiewicz16232672009-04-26 16:06:00 +02001198
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001199#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001200 /* Before power save before link up function, We will force use 1R. */
1201 /* So after link up, check Rx antenna # again. */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001202 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001203 if (pAd->Antenna.field.RxPath == 3) {
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001204 Value |= (0x10);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001205 } else if (pAd->Antenna.field.RxPath == 2) {
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001206 Value |= (0x8);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001207 } else if (pAd->Antenna.field.RxPath == 1) {
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001208 Value |= (0x0);
1209 }
1210 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
1211 pAd->StaCfg.BBPR3 = Value;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001212#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001213
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001214 if (BssType == BSS_ADHOC) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001215 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1216 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1217
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02001218 if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)
1219 AdhocTurnOnQos(pAd);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001220
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001221 DBGPRINT(RT_DEBUG_TRACE, ("!!!Adhoc LINK UP !!! \n"));
1222 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001223 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON);
1224 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1225
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001226 DBGPRINT(RT_DEBUG_TRACE, ("!!!Infra LINK UP !!! \n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001227 }
1228
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001229 /* 3*3 */
1230 /* reset Tx beamforming bit */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001231 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1232 Value &= (~0x01);
1233 Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF;
1234 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1235
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001236 /* Change to AP channel */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001237 if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel)
1238 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001239 /* Must using 40MHz. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001240 pAd->CommonCfg.BBPCurrentBW = BW_40;
1241 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
1242 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
1243
1244 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1245 Value &= (~0x18);
1246 Value |= 0x10;
1247 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1248
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001249 /* RX : control channel at lower */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001250 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1251 Value &= (~0x20);
1252 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001253#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001254 pAd->StaCfg.BBPR3 = Value;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001255#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001256
1257 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1258 Data &= 0xfffffffe;
1259 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1260
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001261 if (pAd->MACVersion == 0x28600100) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001262 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1263 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1264 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001265 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001266 }
1267
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001268 DBGPRINT(RT_DEBUG_TRACE,
1269 ("!!!40MHz Lower LINK UP !!! Control Channel at Below. Central = %d \n",
1270 pAd->CommonCfg.CentralChannel));
1271 } else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel)
1272 && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth ==
1273 BW_40)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001274 /* Must using 40MHz. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001275 pAd->CommonCfg.BBPCurrentBW = BW_40;
1276 AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001277 AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001278
1279 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1280 Value &= (~0x18);
1281 Value |= 0x10;
1282 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1283
1284 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1285 Data |= 0x1;
1286 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1287
1288 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001289 Value |= (0x20);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001290 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001291#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001292 pAd->StaCfg.BBPR3 = Value;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001293#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001294
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001295 if (pAd->MACVersion == 0x28600100) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001296 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A);
1297 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A);
1298 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001299 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001300 }
1301
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001302 DBGPRINT(RT_DEBUG_TRACE,
1303 ("!!! 40MHz Upper LINK UP !!! Control Channel at UpperCentral = %d \n",
1304 pAd->CommonCfg.CentralChannel));
1305 } else {
1306 pAd->CommonCfg.BBPCurrentBW = BW_20;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001307 pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
1308 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
1309 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
1310
1311 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value);
1312 Value &= (~0x18);
1313 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value);
1314
1315 RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data);
1316 Data &= 0xfffffffe;
1317 RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data);
1318
1319 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value);
1320 Value &= (~0x20);
1321 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value);
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001322#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001323 pAd->StaCfg.BBPR3 = Value;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001324#endif /* RTMP_MAC_PCI // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001325
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001326 if (pAd->MACVersion == 0x28600100) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001327 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16);
1328 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08);
1329 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001330 DBGPRINT(RT_DEBUG_TRACE, ("!!!rt2860C !!! \n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001331 }
1332
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001333 DBGPRINT(RT_DEBUG_TRACE, ("!!! 20MHz LINK UP !!! \n"));
1334 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001335
1336 RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001337
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001338 /* */
1339 /* Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission */
1340 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001341 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66,
1342 &pAd->BbpTuning.R66CurrentValue);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001343
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001344 DBGPRINT(RT_DEBUG_TRACE,
1345 ("!!! LINK UP !!! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n",
1346 BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid,
1347 pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001348
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001349 DBGPRINT(RT_DEBUG_TRACE,
1350 ("!!! LINK UP !!! (Density =%d, )\n",
1351 pAd->MacTab.Content[BSSID_WCID].MpduDensity));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001352
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001353 AsicSetBssid(pAd, pAd->CommonCfg.Bssid);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001354
1355 AsicSetSlotTime(pAd, TRUE);
1356 AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1357
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001358 /* Call this for RTS protectionfor legacy rate, we will always enable RTS threshold, but normally it will not hit */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001359 AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE,
1360 FALSE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001361
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001362 if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001363 /* Update HT protectionfor based on AP's operating mode. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001364 if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1) {
1365 AsicUpdateProtect(pAd,
1366 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1367 OperaionMode, ALLN_SETPROTECT, FALSE,
1368 TRUE);
1369 } else
1370 AsicUpdateProtect(pAd,
1371 pAd->MlmeAux.AddHtInfo.AddHtInfo2.
1372 OperaionMode, ALLN_SETPROTECT, FALSE,
1373 FALSE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001374 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001375
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001376 NdisZeroMemory(&pAd->DrsCounters, sizeof(struct rt_counter_drs));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001377
1378 NdisGetSystemUpTime(&Now);
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001379 pAd->StaCfg.LastBeaconRxTime = Now; /* last RX timestamp */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001380
1381 if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) &&
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001382 CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo)) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001383 MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
1384 }
1385
1386 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1387
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001388 if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001389 }
1390 pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE;
1391
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001392 if (BssType == BSS_ADHOC) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001393 MakeIbssBeacon(pAd);
1394 if ((pAd->CommonCfg.Channel > 14)
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001395 && (pAd->CommonCfg.bIEEE80211H == 1)
1396 && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001397 ; /*Do nothing */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001398 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001399 AsicEnableIbssSync(pAd);
1400 }
1401
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001402 /* In ad hoc mode, use MAC table from index 1. */
1403 /* 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. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001404 RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00);
1405 RTMP_IO_WRITE32(pAd, 0x1808, 0x00);
1406
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001407 /* If WEP is enabled, add key material and cipherAlg into Asic */
1408 /* Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000) */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001409
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001410 if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001411 u8 *Key;
1412 u8 CipherAlg;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001413
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001414 for (idx = 0; idx < SHARE_KEY_NUM; idx++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001415 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001416 Key = pAd->SharedKey[BSS0][idx].Key;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001417
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001418 if (pAd->SharedKey[BSS0][idx].KeyLen > 0) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001419 /* Set key material and cipherAlg to Asic */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001420 AsicAddSharedKeyEntry(pAd, BSS0, idx,
1421 CipherAlg, Key,
1422 NULL, NULL);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001423
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001424 if (idx == pAd->StaCfg.DefaultKeyId) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001425 /* Update WCID attribute table and IVEIV table for this group key table */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001426 RTMPAddWcidAttributeEntry(pAd,
1427 BSS0,
1428 idx,
1429 CipherAlg,
1430 NULL);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001431 }
1432 }
1433
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001434 }
1435 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001436 /* If WPANone is enabled, add key material and cipherAlg into Asic */
1437 /* Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000) */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001438 else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001439 pAd->StaCfg.DefaultKeyId = 0; /* always be zero */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001440
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001441 NdisZeroMemory(&pAd->SharedKey[BSS0][0],
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001442 sizeof(struct rt_cipher_key));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001443 pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
1444 NdisMoveMemory(pAd->SharedKey[BSS0][0].Key,
1445 pAd->StaCfg.PMK, LEN_TKIP_EK);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001446
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001447 if (pAd->StaCfg.PairCipher ==
1448 Ndis802_11Encryption2Enabled) {
1449 NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic,
1450 &pAd->StaCfg.PMK[16],
1451 LEN_TKIP_RXMICK);
1452 NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic,
1453 &pAd->StaCfg.PMK[16],
1454 LEN_TKIP_TXMICK);
1455 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001456 /* Decide its ChiperAlg */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001457 if (pAd->StaCfg.PairCipher ==
1458 Ndis802_11Encryption2Enabled)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001459 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001460 else if (pAd->StaCfg.PairCipher ==
1461 Ndis802_11Encryption3Enabled)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001462 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001463 else {
1464 DBGPRINT(RT_DEBUG_TRACE,
1465 ("Unknow Cipher (=%d), set Cipher to AES\n",
1466 pAd->StaCfg.PairCipher));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001467 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001468 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001469
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001470 /* Set key material and cipherAlg to Asic */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001471 AsicAddSharedKeyEntry(pAd,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001472 BSS0,
1473 0,
1474 pAd->SharedKey[BSS0][0].CipherAlg,
1475 pAd->SharedKey[BSS0][0].Key,
1476 pAd->SharedKey[BSS0][0].TxMic,
1477 pAd->SharedKey[BSS0][0].RxMic);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001478
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001479 /* Update WCID attribute table and IVEIV table for this group key table */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001480 RTMPAddWcidAttributeEntry(pAd, BSS0, 0,
1481 pAd->SharedKey[BSS0][0].
1482 CipherAlg, NULL);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001483
1484 }
1485
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001486 } else /* BSS_INFRA */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001487 {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001488 /* Check the new SSID with last SSID */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001489 while (Cancelled == TRUE) {
1490 if (pAd->CommonCfg.LastSsidLen ==
1491 pAd->CommonCfg.SsidLen) {
1492 if (RTMPCompareMemory
1493 (pAd->CommonCfg.LastSsid,
1494 pAd->CommonCfg.Ssid,
1495 pAd->CommonCfg.LastSsidLen) == 0) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001496 /* Link to the old one no linkdown is required. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001497 break;
1498 }
1499 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001500 /* Send link down event before set to link up */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001501 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1502 RTMP_IndicateMediaState(pAd);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001503 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1504 DBGPRINT(RT_DEBUG_TRACE,
1505 ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001506 break;
1507 }
1508
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001509 /* */
1510 /* On WPA mode, Remove All Keys if not connect to the last BSSID */
1511 /* Key will be set after 4-way handshake. */
1512 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001513 if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001514 unsigned long IV;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001515
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001516 /* Remove all WPA keys */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001517 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001518 RTMPWPARemoveAllKeys(pAd);
1519 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001520 pAd->StaCfg.PrivacyFilter =
1521 Ndis802_11PrivFilter8021xWEP;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001522
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001523 /* Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP */
1524 /* If IV related values are too large in GroupMsg2, AP would ignore this message. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001525 IV = 1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001526 IV |= (pAd->StaCfg.DefaultKeyId << 30);
1527 AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0);
1528 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001529 /* NOTE: */
1530 /* the decision of using "short slot time" or not may change dynamically due to */
1531 /* new STA association to the AP. so we have to decide that upon parsing BEACON, not here */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001532
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001533 /* NOTE: */
1534 /* the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically */
1535 /* due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001536
1537 ComposePsPoll(pAd);
1538 ComposeNullFrame(pAd);
1539
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001540 AsicEnableBssSync(pAd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001541
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001542 /* Add BSSID to WCID search table */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001543 AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid);
1544
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001545 /* If WEP is enabled, add paiewise and shared key */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001546 if (((pAd->StaCfg.WpaSupplicantUP) &&
1547 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
1548 (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) ||
1549 ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE) &&
1550 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled))) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001551 u8 *Key;
1552 u8 CipherAlg;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001553
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001554 for (idx = 0; idx < SHARE_KEY_NUM; idx++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001555 CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001556 Key = pAd->SharedKey[BSS0][idx].Key;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001557
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001558 if (pAd->SharedKey[BSS0][idx].KeyLen > 0) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001559 /* Set key material and cipherAlg to Asic */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001560 AsicAddSharedKeyEntry(pAd, BSS0, idx,
1561 CipherAlg, Key,
1562 NULL, NULL);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001563
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001564 if (idx == pAd->StaCfg.DefaultKeyId) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001565 /* Assign group key info */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001566 RTMPAddWcidAttributeEntry(pAd,
1567 BSS0,
1568 idx,
1569 CipherAlg,
1570 NULL);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001571
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001572 pEntry->Aid = BSSID_WCID;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001573 /* Assign pairwise key info */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001574 RTMPAddWcidAttributeEntry(pAd,
1575 BSS0,
1576 idx,
1577 CipherAlg,
1578 pEntry);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001579 }
1580 }
1581 }
1582 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001583 /* only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode */
1584 /* should wait until at least 2 active nodes in this BSSID. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001585 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1586
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001587 /* For GUI ++ */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001588 if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001589 pAd->IndicateMediaState = NdisMediaStateConnected;
1590 pAd->ExtraInfo = GENERAL_LINK_UP;
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02001591 RTMP_IndicateMediaState(pAd);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001592 } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1593 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001594 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001595 if (pAd->StaCfg.WpaSupplicantUP ==
1596 WPA_SUPPLICANT_DISABLE)
1597 RTMPSetTimer(&pAd->Mlme.LinkDownTimer,
1598 LINK_DOWN_TIMEOUT);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001599 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001600 /* -- */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001601
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001602 /* Add BSSID in my MAC Table. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001603 NdisAcquireSpinLock(&pAd->MacTabLock);
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001604 /* add this MAC entry into HASH table */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001605 if (pEntry) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001606 HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001607 if (pAd->MacTab.Hash[HashIdx] == NULL) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001608 pAd->MacTab.Hash[HashIdx] = pEntry;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001609 } else {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001610 pCurrEntry = pAd->MacTab.Hash[HashIdx];
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001611 while (pCurrEntry->pNext != NULL) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001612 pCurrEntry = pCurrEntry->pNext;
1613 }
1614 pCurrEntry->pNext = pEntry;
1615 }
1616 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001617 RTMPMoveMemory(pEntry->Addr, pAd->CommonCfg.Bssid,
1618 MAC_ADDR_LEN);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001619 pEntry->Aid = BSSID_WCID;
1620 pEntry->pAd = pAd;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001621 pEntry->ValidAsCLI = TRUE; /*Although this is bssid..still set ValidAsCl */
1622 pAd->MacTab.Size = 1; /* infra mode always set MACtab size =1. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001623 pEntry->Sst = SST_ASSOC;
1624 pEntry->AuthState = SST_ASSOC;
1625 pEntry->AuthMode = pAd->StaCfg.AuthMode;
1626 pEntry->WepStatus = pAd->StaCfg.WepStatus;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001627 if (pEntry->AuthMode < Ndis802_11AuthModeWPA) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001628 pEntry->WpaState = AS_NOTUSE;
1629 pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001630 } else {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001631 pEntry->WpaState = AS_PTKSTART;
1632 pEntry->PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
1633 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001634 NdisReleaseSpinLock(&pAd->MacTabLock);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001635
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001636 DBGPRINT(RT_DEBUG_TRACE,
1637 ("!!! LINK UP !!! ClientStatusFlags=%lx)\n",
1638 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001639
1640 MlmeUpdateTxRates(pAd, TRUE, BSS0);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001641 MlmeUpdateHtTxRates(pAd, BSS0);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001642 DBGPRINT(RT_DEBUG_TRACE,
1643 ("!!! LINK UP !! (StaActive.bHtEnable =%d, )\n",
1644 pAd->StaActive.SupportedPhyInfo.bHtEnable));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001645
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001646 if (pAd->CommonCfg.bAggregationCapable) {
1647 if ((pAd->CommonCfg.bPiggyBackCapable)
1648 && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3) {
1649 OPSTATUS_SET_FLAG(pAd,
1650 fOP_STATUS_PIGGYBACK_INUSED);
1651 OPSTATUS_SET_FLAG(pAd,
1652 fOP_STATUS_AGGREGATION_INUSED);
1653 CLIENT_STATUS_SET_FLAG(pEntry,
1654 fCLIENT_STATUS_AGGREGATION_CAPABLE);
1655 CLIENT_STATUS_SET_FLAG(pEntry,
1656 fCLIENT_STATUS_PIGGYBACK_CAPABLE);
1657 RTMPSetPiggyBack(pAd, TRUE);
1658 DBGPRINT(RT_DEBUG_TRACE,
1659 ("Turn on Piggy-Back\n"));
1660 } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) {
1661 OPSTATUS_SET_FLAG(pAd,
1662 fOP_STATUS_AGGREGATION_INUSED);
1663 CLIENT_STATUS_SET_FLAG(pEntry,
1664 fCLIENT_STATUS_AGGREGATION_CAPABLE);
1665 DBGPRINT(RT_DEBUG_TRACE,
1666 ("Ralink Aggregation\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001667 }
1668 }
1669
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001670 if (pAd->MlmeAux.APRalinkIe != 0x0) {
1671 if (CLIENT_STATUS_TEST_FLAG
1672 (pEntry, fCLIENT_STATUS_RDG_CAPABLE)) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001673 AsicEnableRDG(pAd);
1674 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001675 OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001676 CLIENT_STATUS_SET_FLAG(pEntry,
1677 fCLIENT_STATUS_RALINK_CHIPSET);
1678 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001679 OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001680 CLIENT_STATUS_CLEAR_FLAG(pEntry,
1681 fCLIENT_STATUS_RALINK_CHIPSET);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001682 }
1683 }
1684
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001685 DBGPRINT(RT_DEBUG_TRACE,
1686 ("NDIS_STATUS_MEDIA_CONNECT Event B!.BACapability = %x. ClientStatusFlags = %lx\n",
1687 pAd->CommonCfg.BACapability.word,
1688 pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001689
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001690 /* Set LED */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001691 RTMPSetLED(pAd, LED_LINK_UP);
1692
1693 pAd->Mlme.PeriodicRound = 0;
1694 pAd->Mlme.OneSecPeriodicRound = 0;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001695 pAd->bConfigChanged = FALSE; /* Reset config flag */
1696 pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information to link is up */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001697
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001698 /* Set asic auto fall back */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001699 {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001700 u8 *pTable;
1701 u8 TableSize = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001702
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001703 MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID],
1704 &pTable, &TableSize,
1705 &pAd->CommonCfg.TxRateIndex);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001706 AsicUpdateAutoFallBackTable(pAd, pTable);
1707 }
1708
1709 NdisAcquireSpinLock(&pAd->MacTabLock);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001710 pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1711 pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word;
1712 if (pAd->StaCfg.bAutoTxRateSwitch == FALSE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001713 pEntry->bAutoTxRateSwitch = FALSE;
Bartlomiej Zolnierkiewicz16232672009-04-26 16:06:00 +02001714
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001715 if (pEntry->HTPhyMode.field.MCS == 32)
1716 pEntry->HTPhyMode.field.ShortGI = GI_800;
1717
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001718 if ((pEntry->HTPhyMode.field.MCS > MCS_7)
1719 || (pEntry->HTPhyMode.field.MCS == 32))
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001720 pEntry->HTPhyMode.field.STBC = STBC_NONE;
Bartlomiej Zolnierkiewicz16232672009-04-26 16:06:00 +02001721
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001722 /* If the legacy mode is set, overwrite the transmit setting of this entry. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001723 if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM)
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001724 RTMPUpdateLegacyTxSetting((u8)pAd->StaCfg.
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001725 DesiredTransmitSetting.field.
1726 FixedTxMode, pEntry);
1727 } else
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001728 pEntry->bAutoTxRateSwitch = TRUE;
1729 NdisReleaseSpinLock(&pAd->MacTabLock);
1730
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001731 /* Let Link Status Page display first initial rate. */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001732 pAd->LastTxRate = (u16)(pEntry->HTPhyMode.word);
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001733 /* Select DAC according to HT or Legacy */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001734 if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001735 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1736 Value &= (~0x18);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001737 if (pAd->Antenna.field.TxPath == 2) {
1738 Value |= 0x10;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001739 }
1740 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001741 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001742 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value);
1743 Value &= (~0x18);
1744 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value);
1745 }
1746
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001747 if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) {
1748 } else if (pEntry->MaxRAmpduFactor == 0) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001749 /* If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0. */
1750 /* Because our Init value is 1 at MACRegTable. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001751 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff);
1752 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001753 /* Patch for Marvel AP to gain high throughput */
1754 /* Need to set as following, */
1755 /* 1. Set txop in register-EDCA_AC0_CFG as 0x60 */
1756 /* 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero */
1757 /* 3. PBF_MAX_PCNT as 0x1F3FBF9F */
1758 /* 4. kick per two packets when dequeue */
1759 /* */
1760 /* Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable */
1761 /* */
1762 /* if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001763 if (!((pAd->CommonCfg.RxStream == 1) && (pAd->CommonCfg.TxStream == 1))
1764 && (pAd->StaCfg.bForceTxBurst == FALSE)
1765 &&
1766 (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE)
1767 && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))
1768 || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)
1769 && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)))) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001770 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001771 Data &= 0xFFFFFF00;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001772 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1773
1774 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1775 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n"));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001776 } else if (pAd->CommonCfg.bEnableTxBurst) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001777 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001778 Data &= 0xFFFFFF00;
1779 Data |= 0x60;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001780 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1781 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE;
1782
1783 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F);
1784 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n"));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001785 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001786 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001787 Data &= 0xFFFFFF00;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001788 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data);
1789
1790 RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F);
1791 DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n"));
1792 }
1793
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001794 /* Re-check to turn on TX burst or not. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001795 if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE)
1796 && ((STA_WEP_ON(pAd)) || (STA_TKIP_ON(pAd)))) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001797 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001798 if (pAd->CommonCfg.bEnableTxBurst) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001799 u32 MACValue = 0;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001800 /* Force disable TXOP value in this case. The same action in MLMEUpdateProtect too. */
1801 /* I didn't change PBF_MAX_PCNT setting. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001802 RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001803 MACValue &= 0xFFFFFF00;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001804 RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue);
1805 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
1806 }
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001807 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001808 pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE;
1809 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001810
1811 pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE;
1812 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001813 DBGPRINT(RT_DEBUG_TRACE,
1814 ("!!!pAd->bNextDisableRxBA= %d \n",
1815 pAd->CommonCfg.IOTestParm.bNextDisableRxBA));
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001816 /* BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap */
1817 /* Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver. */
1818 /* Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001819
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001820 if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001821 if (pAd->StaCfg.WpaSupplicantUP &&
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001822 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
1823 (pAd->StaCfg.IEEE8021X == TRUE)) ;
1824 else {
1825 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
1826 pAd->StaCfg.PrivacyFilter =
1827 Ndis802_11PrivFilterAcceptAll;
1828 }
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001829 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001830
1831 NdisAcquireSpinLock(&pAd->MacTabLock);
1832 pEntry->PortSecured = pAd->StaCfg.PortSecured;
1833 NdisReleaseSpinLock(&pAd->MacTabLock);
1834
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001835 /* */
1836 /* Patch Atheros AP TX will breakdown issue. */
1837 /* AP Model: DLink DWL-8200AP */
1838 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001839 if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)
1840 && STA_TKIP_ON(pAd)) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001841 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001842 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001843 RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00);
1844 }
1845
1846 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001847
Adam McDanieled291e82009-02-23 08:01:07 -07001848 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001849}
1850
1851/*
1852 ==========================================================================
1853
1854 Routine Description:
1855 Disconnect current BSSID
1856
1857 Arguments:
1858 pAd - Pointer to our adapter
1859 IsReqFromAP - Request from AP
1860
1861 Return Value:
1862 None
1863
1864 IRQL = DISPATCH_LEVEL
1865
1866 Note:
1867 We need more information to know it's this requst from AP.
1868 If yes! we need to do extra handling, for example, remove the WPA key.
1869 Otherwise on 4-way handshaking will faied, since the WPA key didn't be
1870 remove while auto reconnect.
1871 Disconnect request from AP, it means we will start afresh 4-way handshaking
1872 on WPA mode.
1873
1874 ==========================================================================
1875*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001876void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001877{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08001878 u8 i, ByteValue = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001879
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001880 /* Do nothing if monitor mode is on */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001881 if (MONITOR_ON(pAd))
1882 return;
1883
Adam McDanieled291e82009-02-23 08:01:07 -07001884 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW);
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001885 /*Comment the codes, beasue the line 2291 call the same function. */
1886 /*RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); */
1887 /* Not allow go to sleep within linkdown function. */
Adam McDanieled291e82009-02-23 08:01:07 -07001888 RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
1889
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001890 if (pAd->CommonCfg.bWirelessEvent) {
1891 RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG,
1892 pAd->MacTab.Content[BSSID_WCID].Addr,
1893 BSS0, 0);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001894 }
1895
1896 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN !!!\n"));
1897 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED);
1898
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001899#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001900 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) {
1901 BOOLEAN Cancelled;
1902 pAd->Mlme.bPsPollTimerRunning = FALSE;
1903 RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled);
1904 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001905
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001906 pAd->bPCIclkOff = FALSE;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001907#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001908
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001909 if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)
1910 || RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND)
1911 || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF)) {
1912 AUTO_WAKEUP_STRUC AutoWakeupCfg;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001913 AsicForceWakeup(pAd, TRUE);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001914 AutoWakeupCfg.word = 0;
1915 RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word);
1916 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE);
1917 }
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001918#ifdef RTMP_MAC_PCI
1919 pAd->bPCIclkOff = FALSE;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001920#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewicze44fd1c2009-09-22 20:44:24 +02001921
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001922 if (ADHOC_ON(pAd)) /* Adhoc mode link down */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001923 {
1924 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 1!!!\n"));
1925
1926 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON);
1927 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1928 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1929 RTMP_IndicateMediaState(pAd);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001930 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1931 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid,
1932 pAd->CommonCfg.Channel);
1933 DBGPRINT(RT_DEBUG_TRACE,
1934 ("!!! MacTab.Size=%d !!!\n", pAd->MacTab.Size));
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001935 } else /* Infra structure mode */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001936 {
1937 DBGPRINT(RT_DEBUG_TRACE, ("!!! LINK DOWN 2!!!\n"));
1938
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001939 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON);
1940 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED);
1941
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001942 /* Saved last SSID for linkup comparison */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001943 pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001944 NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid,
1945 pAd->CommonCfg.LastSsidLen);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001946 COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001947 if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001948 pAd->IndicateMediaState = NdisMediaStateDisconnected;
1949 RTMP_IndicateMediaState(pAd);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001950 pAd->ExtraInfo = GENERAL_LINK_DOWN;
1951 DBGPRINT(RT_DEBUG_TRACE,
1952 ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n"));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001953 pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001954 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001955 /* */
1956 /* If disassociation request is from NDIS, then we don't need to delete BSSID from entry. */
1957 /* Otherwise lost beacon or receive De-Authentication from AP, */
1958 /* then we should delete BSSID from BssTable. */
1959 /* If we don't delete from entry, roaming will fail. */
1960 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001961 BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid,
1962 pAd->CommonCfg.Channel);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001963 }
1964
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001965 /* restore back to - */
1966 /* 1. long slot (20 us) or short slot (9 us) time */
1967 /* 2. turn on/off RTS/CTS and/or CTS-to-self protection */
1968 /* 3. short preamble */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001969 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED);
1970
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001971 }
1972
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001973 for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001974 if (pAd->MacTab.Content[i].ValidAsCLI == TRUE)
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001975 MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid,
1976 pAd->MacTab.Content[i].Addr);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001977 }
1978
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001979 AsicSetSlotTime(pAd, TRUE); /*FALSE); */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001980 AsicSetEdcaParm(pAd, NULL);
1981
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001982 /* Set LED */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001983 RTMPSetLED(pAd, LED_LINK_DOWN);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001984 pAd->LedIndicatorStrength = 0xF0;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001985 RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, firmware is not done it. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001986
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001987 AsicDisableSync(pAd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001988
1989 pAd->Mlme.PeriodicRound = 0;
1990 pAd->Mlme.OneSecPeriodicRound = 0;
1991
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08001992 if (pAd->StaCfg.BssType == BSS_INFRA) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08001993 /* Remove StaCfg Information after link down */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07001994 NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN);
1995 NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID);
1996 pAd->CommonCfg.SsidLen = 0;
1997 }
Bartlomiej Zolnierkiewicz16232672009-04-26 16:06:00 +02001998
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08001999 NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(struct rt_ht_capability_ie));
2000 NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(struct rt_add_ht_info_ie));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002001 pAd->MlmeAux.HtCapabilityLen = 0;
2002 pAd->MlmeAux.NewExtChannelOffset = 0xff;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002003
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002004 /* Reset WPA-PSK state. Only reset when supplicant enabled */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002005 if (pAd->StaCfg.WpaState != SS_NOTUSE) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002006 pAd->StaCfg.WpaState = SS_START;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002007 /* Clear Replay counter */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002008 NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002009
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002010 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002011 /* */
2012 /* if link down come from AP, we need to remove all WPA keys on WPA mode. */
2013 /* otherwise will cause 4-way handshaking failed, since the WPA key not empty. */
2014 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002015 if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002016 /* Remove all WPA keys */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002017 RTMPWPARemoveAllKeys(pAd);
2018 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002019 /* 802.1x port control */
Bartlomiej Zolnierkiewicze08bae52009-04-26 16:05:56 +02002020
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002021 /* Prevent clear PortSecured here with static WEP */
2022 /* NetworkManger set security policy first then set SSID to connect AP. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002023 if (pAd->StaCfg.WpaSupplicantUP &&
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002024 (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) &&
2025 (pAd->StaCfg.IEEE8021X == FALSE)) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002026 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002027 } else {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002028 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
2029 pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP;
2030 }
2031
2032 NdisAcquireSpinLock(&pAd->MacTabLock);
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002033 NdisZeroMemory(&pAd->MacTab, sizeof(struct rt_mac_table));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002034 pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured;
2035 NdisReleaseSpinLock(&pAd->MacTabLock);
2036
2037 pAd->StaCfg.MicErrCnt = 0;
2038
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002039 pAd->IndicateMediaState = NdisMediaStateDisconnected;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002040 /* Update extra information to link is up */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002041 pAd->ExtraInfo = GENERAL_LINK_DOWN;
2042
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002043 pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002044
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002045#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002046 pAd->bUsbTxBulkAggre = FALSE;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002047#endif /* RTMP_MAC_USB // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002048
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002049 /* Clean association information */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002050 NdisZeroMemory(&pAd->StaCfg.AssocInfo,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002051 sizeof(struct rt_ndis_802_11_association_information));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002052 pAd->StaCfg.AssocInfo.Length =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002053 sizeof(struct rt_ndis_802_11_association_information);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002054 pAd->StaCfg.ReqVarIELen = 0;
2055 pAd->StaCfg.ResVarIELen = 0;
2056
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002057 /* */
2058 /* Reset RSSI value after link down */
2059 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002060 pAd->StaCfg.RssiSample.AvgRssi0 = 0;
2061 pAd->StaCfg.RssiSample.AvgRssi0X8 = 0;
2062 pAd->StaCfg.RssiSample.AvgRssi1 = 0;
2063 pAd->StaCfg.RssiSample.AvgRssi1X8 = 0;
2064 pAd->StaCfg.RssiSample.AvgRssi2 = 0;
2065 pAd->StaCfg.RssiSample.AvgRssi2X8 = 0;
2066
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002067 /* Restore MlmeRate */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002068 pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate;
2069 pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate;
2070
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002071 /* */
2072 /* After Link down, reset piggy-back setting in ASIC. Disable RDG. */
2073 /* */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002074 if (pAd->CommonCfg.BBPCurrentBW == BW_40) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002075 pAd->CommonCfg.BBPCurrentBW = BW_20;
2076 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue);
2077 ByteValue &= (~0x18);
2078 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue);
2079 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002080 /* Reset DAC */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002081 RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue);
2082 ByteValue &= (~0x18);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002083 if (pAd->Antenna.field.TxPath == 2) {
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002084 ByteValue |= 0x10;
2085 }
2086 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue);
2087
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002088 RTMPSetPiggyBack(pAd, FALSE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002089 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED);
2090
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002091 pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002092
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002093 /* Restore all settings in the following. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002094 AsicUpdateProtect(pAd, 0,
2095 (ALLN_SETPROTECT | CCKSETPROTECT | OFDMSETPROTECT),
2096 TRUE, FALSE);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002097 AsicDisableRDG(pAd);
2098 pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE;
2099 pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE;
2100
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002101 RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff);
2102 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS);
2103
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002104/* Allow go to sleep after linkdown steps. */
Adam McDanieled291e82009-02-23 08:01:07 -07002105 RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP);
2106
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002107 RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, 0);
2108
2109#ifdef RT30xx
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002110 if ((IS_RT30xx(pAd) || IS_RT3090(pAd) || IS_RT3390(pAd))
2111 && (pAd->Antenna.field.RxPath > 1 || pAd->Antenna.field.TxPath > 1)) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002112 RTMP_ASIC_MMPS_DISABLE(pAd);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002113 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002114#endif /* RT30xx // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002115}
2116
2117/*
2118 ==========================================================================
2119 Description:
2120
2121 IRQL = DISPATCH_LEVEL
2122
2123 ==========================================================================
2124*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002125void IterateOnBssTab(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002126{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002127 struct rt_mlme_start_req StartReq;
2128 struct rt_mlme_join_req JoinReq;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002129 unsigned long BssIdx;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002130
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002131 /* Change the wepstatus to original wepstatus */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002132 pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus;
2133 pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002134 pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus;
2135
2136 BssIdx = pAd->MlmeAux.BssIdx;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002137 if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002138 /* Check cipher suite, AP must have more secured cipher than station setting */
2139 /* Set the Pairwise and Group cipher to match the intended AP setting */
2140 /* We can only connect to AP with less secured cipher setting */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002141 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA)
2142 || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) {
2143 pAd->StaCfg.GroupCipher =
2144 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.
2145 GroupCipher;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002146
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002147 if (pAd->StaCfg.WepStatus ==
2148 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.
2149 PairCipher)
2150 pAd->StaCfg.PairCipher =
2151 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2152 WPA.PairCipher;
2153 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.
2154 PairCipherAux != Ndis802_11WEPDisabled)
2155 pAd->StaCfg.PairCipher =
2156 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2157 WPA.PairCipherAux;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002158 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002159 pAd->StaCfg.PairCipher =
2160 Ndis802_11Encryption2Enabled;
2161 } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)
2162 || (pAd->StaCfg.AuthMode ==
2163 Ndis802_11AuthModeWPA2PSK)) {
2164 pAd->StaCfg.GroupCipher =
2165 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2166 GroupCipher;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002167
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002168 if (pAd->StaCfg.WepStatus ==
2169 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2170 PairCipher)
2171 pAd->StaCfg.PairCipher =
2172 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2173 WPA2.PairCipher;
2174 else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2175 PairCipherAux != Ndis802_11WEPDisabled)
2176 pAd->StaCfg.PairCipher =
2177 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].
2178 WPA2.PairCipherAux;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002179 else /* There is no PairCipher Aux, downgrade our capability to TKIP */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002180 pAd->StaCfg.PairCipher =
2181 Ndis802_11Encryption2Enabled;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002182
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002183 /* RSN capability */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002184 pAd->StaCfg.RsnCapability =
2185 pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.
2186 RsnCapability;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002187 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002188 /* Set Mix cipher flag */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002189 pAd->StaCfg.bMixCipher =
2190 (pAd->StaCfg.PairCipher ==
2191 pAd->StaCfg.GroupCipher) ? FALSE : TRUE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002192 /*if (pAd->StaCfg.bMixCipher == TRUE)
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002193 {
2194 // If mix cipher, re-build RSNIE
2195 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
2196 } */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002197
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002198 DBGPRINT(RT_DEBUG_TRACE,
2199 ("CNTL - iterate BSS %ld of %d\n", BssIdx,
2200 pAd->MlmeAux.SsidBssTab.BssNr));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002201 JoinParmFill(pAd, &JoinReq, BssIdx);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002202 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002203 sizeof(struct rt_mlme_join_req), &JoinReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002204 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002205 } else if (pAd->StaCfg.BssType == BSS_ADHOC) {
2206 DBGPRINT(RT_DEBUG_TRACE,
2207 ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",
2208 pAd->MlmeAux.Ssid));
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002209 StartParmFill(pAd, &StartReq, (char *)pAd->MlmeAux.Ssid,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002210 pAd->MlmeAux.SsidLen);
2211 MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002212 sizeof(struct rt_mlme_start_req), &StartReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002213 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002214 } else /* no more BSS */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002215 {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002216
2217 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002218 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2219 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2220 DBGPRINT(RT_DEBUG_TRACE,
2221 ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n",
2222 pAd->CommonCfg.Channel, pAd->ScanTab.BssNr));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002223 }
2224
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002225 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2226 }
2227}
2228
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002229/* for re-association only */
2230/* IRQL = DISPATCH_LEVEL */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002231void IterateOnBssTab2(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002232{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002233 struct rt_mlme_assoc_req ReassocReq;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002234 unsigned long BssIdx;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002235 struct rt_bss_entry *pBss;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002236
2237 BssIdx = pAd->MlmeAux.RoamIdx;
2238 pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];
2239
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002240 if (BssIdx < pAd->MlmeAux.RoamTab.BssNr) {
2241 DBGPRINT(RT_DEBUG_TRACE,
2242 ("CNTL - iterate BSS %ld of %d\n", BssIdx,
2243 pAd->MlmeAux.RoamTab.BssNr));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002244
2245 AsicSwitchChannel(pAd, pBss->Channel, FALSE);
2246 AsicLockChannel(pAd, pBss->Channel);
2247
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002248 /* reassociate message has the same structure as associate message */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002249 AssocParmFill(pAd, &ReassocReq, pBss->Bssid,
2250 pBss->CapabilityInfo, ASSOC_TIMEOUT,
2251 pAd->StaCfg.DefaultListenCount);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002252 MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002253 sizeof(struct rt_mlme_assoc_req), &ReassocReq);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002254
2255 pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002256 } else /* no more BSS */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002257 {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002258
2259 {
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002260 AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
2261 AsicLockChannel(pAd, pAd->CommonCfg.Channel);
2262 DBGPRINT(RT_DEBUG_TRACE,
2263 ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n",
2264 pAd->CommonCfg.Channel, pAd->ScanTab.BssNr));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002265 }
2266
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002267 pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
2268 }
2269}
2270
2271/*
2272 ==========================================================================
2273 Description:
2274
2275 IRQL = DISPATCH_LEVEL
2276
2277 ==========================================================================
2278*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002279void JoinParmFill(struct rt_rtmp_adapter *pAd,
2280 struct rt_mlme_join_req *JoinReq, unsigned long BssIdx)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002281{
2282 JoinReq->BssIdx = BssIdx;
2283}
2284
2285/*
2286 ==========================================================================
2287 Description:
2288
2289 IRQL = DISPATCH_LEVEL
2290
2291 ==========================================================================
2292*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002293void ScanParmFill(struct rt_rtmp_adapter *pAd,
2294 struct rt_mlme_scan_req *ScanReq,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002295 char Ssid[],
2296 u8 SsidLen, u8 BssType, u8 ScanType)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002297{
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002298 NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002299 ScanReq->SsidLen = SsidLen;
2300 NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);
2301 ScanReq->BssType = BssType;
2302 ScanReq->ScanType = ScanType;
2303}
2304
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002305/*
2306 ==========================================================================
2307 Description:
2308
2309 IRQL = DISPATCH_LEVEL
2310
2311 ==========================================================================
2312*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002313void StartParmFill(struct rt_rtmp_adapter *pAd,
2314 struct rt_mlme_start_req *StartReq,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002315 char Ssid[], u8 SsidLen)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002316{
2317 ASSERT(SsidLen <= MAX_LEN_OF_SSID);
2318 NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);
2319 StartReq->SsidLen = SsidLen;
2320}
2321
2322/*
2323 ==========================================================================
2324 Description:
2325
2326 IRQL = DISPATCH_LEVEL
2327
2328 ==========================================================================
2329*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002330void AuthParmFill(struct rt_rtmp_adapter *pAd,
2331 struct rt_mlme_auth_req *AuthReq,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002332 u8 *pAddr, u16 Alg)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002333{
2334 COPY_MAC_ADDR(AuthReq->Addr, pAddr);
2335 AuthReq->Alg = Alg;
2336 AuthReq->Timeout = AUTH_TIMEOUT;
2337}
2338
2339/*
2340 ==========================================================================
2341 Description:
2342
2343 IRQL = DISPATCH_LEVEL
2344
2345 ==========================================================================
2346 */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002347#ifdef RTMP_MAC_PCI
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002348void ComposePsPoll(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002349{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002350 NdisZeroMemory(&pAd->PsPollFrame, sizeof(struct rt_pspoll_frame));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002351 pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
2352 pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
2353 pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
2354 COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
2355 COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
2356}
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002357
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002358/* IRQL = DISPATCH_LEVEL */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002359void ComposeNullFrame(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002360{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002361 NdisZeroMemory(&pAd->NullFrame, sizeof(struct rt_header_802_11));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002362 pAd->NullFrame.FC.Type = BTYPE_DATA;
2363 pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
2364 pAd->NullFrame.FC.ToDs = 1;
2365 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
2366 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
2367 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
2368}
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002369#endif /* RTMP_MAC_PCI // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02002370#ifdef RTMP_MAC_USB
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002371void MlmeCntlConfirm(struct rt_rtmp_adapter *pAd, unsigned long MsgType, u16 Msg)
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002372{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002373 MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(u16),
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002374 &Msg);
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002375}
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002376
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002377void ComposePsPoll(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002378{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002379 struct rt_txinfo *pTxInfo;
2380 struct rt_txwi * pTxWI;
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002381
2382 DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n"));
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002383 NdisZeroMemory(&pAd->PsPollFrame, sizeof(struct rt_pspoll_frame));
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002384
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002385 pAd->PsPollFrame.FC.PwrMgmt = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002386 pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
2387 pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
2388 pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000;
2389 COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid);
2390 COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002391
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002392 RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field.
2393 WirelessPacket[0], 100);
2394 pTxInfo =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002395 (struct rt_txinfo *)& pAd->PsPollContext.TransferBuffer->field.
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002396 WirelessPacket[0];
2397 RTMPWriteTxInfo(pAd, pTxInfo,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002398 (u16)(sizeof(struct rt_pspoll_frame) + TXWI_SIZE), TRUE,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002399 EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2400 pTxWI =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002401 (struct rt_txwi *) & pAd->PsPollContext.TransferBuffer->field.
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002402 WirelessPacket[TXINFO_SIZE];
2403 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002404 BSSID_WCID, (sizeof(struct rt_pspoll_frame)), 0, 0,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002405 (u8)pAd->CommonCfg.MlmeTransmit.field.MCS,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002406 IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2407 RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field.
2408 WirelessPacket[TXWI_SIZE + TXINFO_SIZE],
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002409 &pAd->PsPollFrame, sizeof(struct rt_pspoll_frame));
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002410 /* Append 4 extra zero bytes. */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002411 pAd->PsPollContext.BulkOutSize =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002412 TXINFO_SIZE + TXWI_SIZE + sizeof(struct rt_pspoll_frame) + 4;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002413}
2414
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002415/* IRQL = DISPATCH_LEVEL */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002416void ComposeNullFrame(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002417{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002418 struct rt_txinfo *pTxInfo;
2419 struct rt_txwi * pTxWI;
Bartlomiej Zolnierkiewicz5f5d2df2009-04-26 16:06:29 +02002420
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002421 NdisZeroMemory(&pAd->NullFrame, sizeof(struct rt_header_802_11));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002422 pAd->NullFrame.FC.Type = BTYPE_DATA;
2423 pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
2424 pAd->NullFrame.FC.ToDs = 1;
2425 COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid);
2426 COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
2427 COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid);
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002428 RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field.
2429 WirelessPacket[0], 100);
2430 pTxInfo =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002431 (struct rt_txinfo *)& pAd->NullContext.TransferBuffer->field.
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002432 WirelessPacket[0];
2433 RTMPWriteTxInfo(pAd, pTxInfo,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002434 (u16)(sizeof(struct rt_header_802_11) + TXWI_SIZE), TRUE,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002435 EpToQueue[MGMTPIPEIDX], FALSE, FALSE);
2436 pTxWI =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002437 (struct rt_txwi *) & pAd->NullContext.TransferBuffer->field.
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002438 WirelessPacket[TXINFO_SIZE];
2439 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002440 BSSID_WCID, (sizeof(struct rt_header_802_11)), 0, 0,
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002441 (u8)pAd->CommonCfg.MlmeTransmit.field.MCS,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002442 IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit);
2443 RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field.
2444 WirelessPacket[TXWI_SIZE + TXINFO_SIZE], &pAd->NullFrame,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002445 sizeof(struct rt_header_802_11));
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002446 pAd->NullContext.BulkOutSize =
2447 TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002448}
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002449#endif /* RTMP_MAC_USB // */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002450
2451/*
2452 ==========================================================================
2453 Description:
2454 Pre-build a BEACON frame in the shared memory
2455
2456 IRQL = PASSIVE_LEVEL
2457 IRQL = DISPATCH_LEVEL
2458
2459 ==========================================================================
2460*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002461unsigned long MakeIbssBeacon(struct rt_rtmp_adapter *pAd)
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002462{
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002463 u8 DsLen = 1, IbssLen = 2;
2464 u8 LocalErpIe[3] = { IE_ERP, 1, 0x04 };
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002465 struct rt_header_802_11 BcnHdr;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002466 u16 CapabilityInfo;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002467 LARGE_INTEGER FakeTimestamp;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002468 unsigned long FrameLen = 0;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002469 struct rt_txwi * pTxWI = &pAd->BeaconTxWI;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002470 u8 *pBeaconFrame = pAd->BeaconBuf;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002471 BOOLEAN Privacy;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002472 u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES];
2473 u8 SupRateLen = 0;
2474 u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
2475 u8 ExtRateLen = 0;
2476 u8 RSNIe = IE_WPA;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002477
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002478 if ((pAd->CommonCfg.PhyMode == PHY_11B)
2479 && (pAd->CommonCfg.Channel <= 14)) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002480 SupRate[0] = 0x82; /* 1 mbps */
2481 SupRate[1] = 0x84; /* 2 mbps */
2482 SupRate[2] = 0x8b; /* 5.5 mbps */
2483 SupRate[3] = 0x96; /* 11 mbps */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002484 SupRateLen = 4;
2485 ExtRateLen = 0;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002486 } else if (pAd->CommonCfg.Channel > 14) {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002487 SupRate[0] = 0x8C; /* 6 mbps, in units of 0.5 Mbps, basic rate */
2488 SupRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */
2489 SupRate[2] = 0x98; /* 12 mbps, in units of 0.5 Mbps, basic rate */
2490 SupRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */
2491 SupRate[4] = 0xb0; /* 24 mbps, in units of 0.5 Mbps, basic rate */
2492 SupRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */
2493 SupRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */
2494 SupRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002495 SupRateLen = 8;
2496 ExtRateLen = 0;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002497
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002498 /* */
2499 /* Also Update MlmeRate & RtsRate for G only & A only */
2500 /* */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002501 pAd->CommonCfg.MlmeRate = RATE_6;
2502 pAd->CommonCfg.RtsRate = RATE_6;
2503 pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002504 pAd->CommonCfg.MlmeTransmit.field.MCS =
2505 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2506 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE =
2507 MODE_OFDM;
2508 pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS =
2509 OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate];
2510 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002511 SupRate[0] = 0x82; /* 1 mbps */
2512 SupRate[1] = 0x84; /* 2 mbps */
2513 SupRate[2] = 0x8b; /* 5.5 mbps */
2514 SupRate[3] = 0x96; /* 11 mbps */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002515 SupRateLen = 4;
2516
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002517 ExtRate[0] = 0x0C; /* 6 mbps, in units of 0.5 Mbps, */
2518 ExtRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */
2519 ExtRate[2] = 0x18; /* 12 mbps, in units of 0.5 Mbps, */
2520 ExtRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */
2521 ExtRate[4] = 0x30; /* 24 mbps, in units of 0.5 Mbps, */
2522 ExtRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */
2523 ExtRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */
2524 ExtRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002525 ExtRateLen = 8;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002526 }
2527
2528 pAd->StaActive.SupRateLen = SupRateLen;
2529 NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen);
2530 pAd->StaActive.ExtRateLen = ExtRateLen;
2531 NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen);
2532
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002533 /* compose IBSS beacon frame */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002534 MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR,
2535 pAd->CommonCfg.Bssid);
2536 Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled)
2537 || (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled)
2538 || (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled);
2539 CapabilityInfo =
2540 CAP_GENERATE(0, 1, Privacy,
2541 (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort),
2542 0, 0);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002543
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002544 MakeOutgoingFrame(pBeaconFrame, &FrameLen,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -08002545 sizeof(struct rt_header_802_11), &BcnHdr,
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002546 TIMESTAMP_LEN, &FakeTimestamp,
2547 2, &pAd->CommonCfg.BeaconPeriod,
2548 2, &CapabilityInfo,
2549 1, &SsidIe,
2550 1, &pAd->CommonCfg.SsidLen,
2551 pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid,
2552 1, &SupRateIe,
2553 1, &SupRateLen,
2554 SupRateLen, SupRate,
2555 1, &DsIe,
2556 1, &DsLen,
2557 1, &pAd->CommonCfg.Channel,
2558 1, &IbssIe,
2559 1, &IbssLen, 2, &pAd->StaActive.AtimWin, END_OF_ARGS);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002560
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002561 /* add ERP_IE and EXT_RAE IE of in 802.11g */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002562 if (ExtRateLen) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002563 unsigned long tmp;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002564
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002565 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2566 3, LocalErpIe,
2567 1, &ExtRateIe,
2568 1, &ExtRateLen,
2569 ExtRateLen, ExtRate, END_OF_ARGS);
2570 FrameLen += tmp;
2571 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002572 /* If adhoc secruity is set for WPA-None, append the cipher suite IE */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002573 if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002574 unsigned long tmp;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002575 RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus,
2576 BSS0);
2577
2578 MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
2579 1, &RSNIe,
2580 1, &pAd->StaCfg.RSNIE_Len,
2581 pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE,
2582 END_OF_ARGS);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002583 FrameLen += tmp;
2584 }
2585
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002586 if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -08002587 unsigned long TmpLen;
2588 u8 HtLen, HtLen1;
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002589
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002590 /* add HT Capability IE */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002591 HtLen = sizeof(pAd->CommonCfg.HtCapability);
2592 HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo);
Bartlomiej Zolnierkiewicz51f94a72009-04-26 16:05:39 +02002593
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002594 MakeOutgoingFrame(pBeaconFrame + FrameLen, &TmpLen,
2595 1, &HtCapIe,
2596 1, &HtLen,
2597 HtLen, &pAd->CommonCfg.HtCapability,
2598 1, &AddHtInfoIe,
2599 1, &HtLen1,
2600 HtLen1, &pAd->CommonCfg.AddHTInfo,
2601 END_OF_ARGS);
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002602
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002603 FrameLen += TmpLen;
2604 }
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002605 /*beacon use reserved WCID 0xff */
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002606 if (pAd->CommonCfg.Channel > 14) {
2607 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE,
2608 TRUE, 0, 0xff, FrameLen, PID_MGMT, PID_BEACON,
2609 RATE_1, IFS_HTTXOP, FALSE,
2610 &pAd->CommonCfg.MlmeTransmit);
2611 } else {
Bartlomiej Zolnierkiewicz82819582009-12-11 12:23:15 -08002612 /* Set to use 1Mbps for Adhoc beacon. */
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002613 HTTRANSMIT_SETTING Transmit;
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002614 Transmit.word = 0;
2615 RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE,
2616 TRUE, 0, 0xff, FrameLen, PID_MGMT, PID_BEACON,
2617 RATE_1, IFS_HTTXOP, FALSE, &Transmit);
2618 }
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002619
Bartlomiej Zolnierkiewicz0f65bec2009-12-11 12:23:14 -08002620 DBGPRINT(RT_DEBUG_TRACE,
2621 ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n",
2622 FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel,
2623 pAd->CommonCfg.PhyMode));
Greg Kroah-Hartman91980992008-10-28 14:48:09 -07002624 return FrameLen;
2625}