Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux...
[linux-2.6-block.git] / drivers / staging / vt6656 / wmgr.c
CommitLineData
92b96797
FB
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wmgr.c
21 *
22 * Purpose: Handles the 802.11 management functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: May 8, 2002
27 *
28 * Functions:
29 * nsMgrObjectInitial - Initialize Management Objet data structure
a0a1f61a 30 * vMgrObjectReset - Reset Management Object data structure
92b96797
FB
31 * vMgrAssocBeginSta - Start associate function
32 * vMgrReAssocBeginSta - Start reassociate function
33 * vMgrDisassocBeginSta - Start disassociate function
34 * s_vMgrRxAssocRequest - Handle Rcv associate_request
35 * s_vMgrRxAssocResponse - Handle Rcv associate_response
36 * vMrgAuthenBeginSta - Start authentication function
37 * vMgrDeAuthenDeginSta - Start deauthentication function
38 * s_vMgrRxAuthentication - Handle Rcv authentication
39 * s_vMgrRxAuthenSequence_1 - Handle Rcv authentication sequence 1
40 * s_vMgrRxAuthenSequence_2 - Handle Rcv authentication sequence 2
41 * s_vMgrRxAuthenSequence_3 - Handle Rcv authentication sequence 3
42 * s_vMgrRxAuthenSequence_4 - Handle Rcv authentication sequence 4
43 * s_vMgrRxDisassociation - Handle Rcv disassociation
44 * s_vMgrRxBeacon - Handle Rcv Beacon
45 * vMgrCreateOwnIBSS - Create ad_hoc IBSS or AP BSS
46 * vMgrJoinBSSBegin - Join BSS function
47 * s_vMgrSynchBSS - Synch & adopt BSS parameters
48 * s_MgrMakeBeacon - Create Baecon frame
49 * s_MgrMakeProbeResponse - Create Probe Response frame
50 * s_MgrMakeAssocRequest - Create Associate Request frame
51 * s_MgrMakeReAssocRequest - Create ReAssociate Request frame
52 * s_vMgrRxProbeResponse - Handle Rcv probe_response
53 * s_vMrgRxProbeRequest - Handle Rcv probe_request
54 * bMgrPrepareBeaconToSend - Prepare Beacon frame
55 * s_vMgrLogStatus - Log 802.11 Status
56 * vMgrRxManagePacket - Rcv management frame dispatch function
93184690 57 * s_vMgrFormatTIM- Assembler TIM field of beacon
92b96797
FB
58 * vMgrTimerInit- Initial 1-sec and command call back funtions
59 *
60 * Revision History:
61 *
62 */
63
92b96797 64#include "tmacro.h"
92b96797 65#include "desc.h"
92b96797 66#include "device.h"
92b96797 67#include "card.h"
92b96797 68#include "80211hdr.h"
92b96797 69#include "80211mgr.h"
92b96797 70#include "wmgr.h"
92b96797 71#include "wcmd.h"
92b96797 72#include "mac.h"
92b96797 73#include "bssdb.h"
92b96797 74#include "power.h"
92b96797 75#include "datarate.h"
92b96797 76#include "baseband.h"
92b96797 77#include "rxtx.h"
92b96797 78#include "wpa.h"
92b96797 79#include "rf.h"
92b96797 80#include "iowpa.h"
92b96797 81#include "control.h"
92b96797 82#include "rndis.h"
9d26d60f 83
e7ed40fb 84static int msglevel = MSG_LEVEL_INFO;
92b96797
FB
85//static int msglevel =MSG_LEVEL_DEBUG;
86
78f41c91 87static int ChannelExceedZoneType(struct vnt_private *, u8 byCurrChannel);
92b96797 88
78f41c91
MP
89/* Association/diassociation functions */
90static struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *,
91 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
92 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
93 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
92b96797 94
78f41c91
MP
95static void s_vMgrRxAssocRequest(struct vnt_private *,
96 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
97 u32 uNodeIndex);
92b96797 98
78f41c91
MP
99static struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *,
100 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
101 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
102 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
92b96797 103
78f41c91
MP
104static void s_vMgrRxAssocResponse(struct vnt_private *,
105 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
106 int bReAssocType);
92b96797 107
78f41c91
MP
108static void s_vMgrRxDisassociation(struct vnt_private *,
109 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
92b96797 110
78f41c91
MP
111/* Authentication/deauthen functions */
112static void s_vMgrRxAuthenSequence_1(struct vnt_private *,
113 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
92b96797 114
78f41c91
MP
115static void s_vMgrRxAuthenSequence_2(struct vnt_private *,
116 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
92b96797 117
78f41c91
MP
118static void s_vMgrRxAuthenSequence_3(struct vnt_private *,
119 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
92b96797 120
78f41c91
MP
121static void s_vMgrRxAuthenSequence_4(struct vnt_private *,
122 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
92b96797 123
78f41c91
MP
124static void s_vMgrRxAuthentication(struct vnt_private *,
125 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
92b96797 126
78f41c91
MP
127static void s_vMgrRxDeauthentication(struct vnt_private *,
128 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
92b96797 129
78f41c91
MP
130/* Scan functions
131* probe request/response functions */
92b96797 132
78f41c91
MP
133static void s_vMgrRxProbeRequest(struct vnt_private *,
134 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
92b96797 135
78f41c91
MP
136static void s_vMgrRxProbeResponse(struct vnt_private *,
137 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
92b96797 138
78f41c91
MP
139/* beacon functions */
140static void s_vMgrRxBeacon(struct vnt_private *pDevice,
141 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
142 int bInScan);
92b96797 143
78f41c91 144static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM);
92b96797 145
78f41c91
MP
146static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
147 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
148 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
149 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
150 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
92b96797 151
78f41c91
MP
152/* Association response */
153static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *,
154 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
155 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
156 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
92b96797 157
78f41c91
MP
158/* ReAssociation response */
159static struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *,
160 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
161 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
162 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
92b96797 163
78f41c91
MP
164/* Probe response */
165static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *,
166 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
167 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
168 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
169 PWLAN_IE_SUPP_RATES pCurrSuppRates,
170 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType);
92b96797 171
78f41c91
MP
172/* received status */
173static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus);
92b96797 174
78f41c91
MP
175static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode,
176 PKnownBSS pCurr, PCMD_STATUS pStatus);
92b96797 177
dfdcc425 178static bool
92b96797 179s_bCipherMatch (
592ccfeb
AM
180 PKnownBSS pBSSNode,
181 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
b902fbfe
AM
182 u8 * pbyCCSPK,
183 u8 * pbyCCSGK
92b96797
FB
184 );
185
78f41c91 186static void Encyption_Rebuild(struct vnt_private *, PKnownBSS pCurr);
92b96797 187
92b96797
FB
188/*+
189 *
190 * Routine Description:
191 * Allocates and initializes the Management object.
192 *
193 * Return Value:
194 * Ndis_staus.
195 *
196-*/
197
78f41c91 198void vMgrObjectInit(struct vnt_private *pDevice)
92b96797 199{
78f41c91
MP
200 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
201 int ii;
92b96797 202
92b96797
FB
203 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
204 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
205 pMgmt->uCurrChannel = pDevice->uChannel;
33d33e42
AM
206 for (ii = 0; ii < WLAN_BSSID_LEN; ii++)
207 pMgmt->abyDesireBSSID[ii] = 0xFF;
208
92b96797
FB
209 pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
210 //memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
211 pMgmt->byCSSPK = KEY_CTL_NONE;
212 pMgmt->byCSSGK = KEY_CTL_NONE;
213 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
e269fc2d 214 BSSvClearBSSList((void *) pDevice, false);
92b96797 215
92b96797
FB
216 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
217 pDevice->uCmdDequeueIdx = 0;
218 pDevice->uCmdEnqueueIdx = 0;
219 pDevice->eCommandState = WLAN_CMD_IDLE;
e269fc2d
AM
220 pDevice->bCmdRunning = false;
221 pDevice->bCmdClear = false;
92b96797
FB
222
223 return;
224}
225
92b96797
FB
226/*+
227 *
228 * Routine Description:
229 * Start the station association procedure. Namely, send an
230 * association request frame to the AP.
231 *
232 * Return Value:
233 * None.
234 *
235-*/
236
78f41c91
MP
237void vMgrAssocBeginSta(struct vnt_private *pDevice,
238 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
92b96797 239{
78f41c91 240 struct vnt_tx_mgmt *pTxPacket;
92b96797 241
92b96797
FB
242 pMgmt->wCurrCapInfo = 0;
243 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
244 if (pDevice->bEncryptionEnable) {
245 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
246 }
247 // always allow receive short preamble
248 //if (pDevice->byPreambleType == 1) {
249 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
250 //}
251 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
252 if (pMgmt->wListenInterval == 0)
253 pMgmt->wListenInterval = 1; // at least one.
254
255 // ERP Phy (802.11g) should support short preamble.
256 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
257 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
4e9b5e2b 258 if (pDevice->bShortSlotTime == true)
92b96797
FB
259 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
260
261 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
262 if (pDevice->byPreambleType == 1) {
263 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
264 }
265 }
4e9b5e2b 266 if (pMgmt->b11hEnable == true)
92b96797
FB
267 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
268
269 // build an assocreq frame and send it
270 pTxPacket = s_MgrMakeAssocRequest
271 (
272 pDevice,
273 pMgmt,
274 pMgmt->abyCurrBSSID,
275 pMgmt->wCurrCapInfo,
276 pMgmt->wListenInterval,
277 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
278 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
279 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
280 );
281
282 if (pTxPacket != NULL ){
283 // send the frame
284 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
285 if (*pStatus == CMD_STATUS_PENDING) {
286 pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
287 *pStatus = CMD_STATUS_SUCCESS;
288 }
289 }
290 else
291 *pStatus = CMD_STATUS_RESOURCES;
292
293 return ;
294}
295
92b96797
FB
296/*+
297 *
298 * Routine Description:
299 * Start the station re-association procedure.
300 *
301 * Return Value:
302 * None.
303 *
304-*/
305
78f41c91
MP
306void vMgrReAssocBeginSta(struct vnt_private *pDevice,
307 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
92b96797 308{
78f41c91 309 struct vnt_tx_mgmt *pTxPacket;
92b96797
FB
310
311 pMgmt->wCurrCapInfo = 0;
312 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
313 if (pDevice->bEncryptionEnable) {
314 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
315 }
316
317 //if (pDevice->byPreambleType == 1) {
318 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
319 //}
320 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
321
322 if (pMgmt->wListenInterval == 0)
323 pMgmt->wListenInterval = 1; // at least one.
324
92b96797
FB
325 // ERP Phy (802.11g) should support short preamble.
326 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
327 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
4e9b5e2b 328 if (pDevice->bShortSlotTime == true)
92b96797
FB
329 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
330
331 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
332 if (pDevice->byPreambleType == 1) {
333 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
334 }
335 }
4e9b5e2b 336 if (pMgmt->b11hEnable == true)
92b96797
FB
337 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
338
92b96797
FB
339 pTxPacket = s_MgrMakeReAssocRequest
340 (
341 pDevice,
342 pMgmt,
343 pMgmt->abyCurrBSSID,
344 pMgmt->wCurrCapInfo,
345 pMgmt->wListenInterval,
346 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
347 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
348 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
349 );
350
351 if (pTxPacket != NULL ){
352 // send the frame
353 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
354 if (*pStatus != CMD_STATUS_PENDING) {
355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
356 }
357 else {
358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
359 }
360 }
361
92b96797
FB
362 return ;
363}
364
365/*+
366 *
367 * Routine Description:
368 * Send an dis-association request frame to the AP.
369 *
370 * Return Value:
371 * None.
372 *
373-*/
374
78f41c91
MP
375void vMgrDisassocBeginSta(struct vnt_private *pDevice,
376 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
377 PCMD_STATUS pStatus)
92b96797 378{
78f41c91
MP
379 struct vnt_tx_mgmt *pTxPacket = NULL;
380 WLAN_FR_DISASSOC sFrame;
92b96797 381
78f41c91
MP
382 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
383 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
384 + WLAN_DISASSOC_FR_MAXLEN);
385 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
386 + sizeof(struct vnt_tx_mgmt));
92b96797
FB
387
388 // Setup the sFrame structure
b902fbfe 389 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
390 sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
391
392 // format fixed field frame structure
393 vMgrEncodeDisassociation(&sFrame);
394
395 // Setup the header
396 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
397 (
398 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
399 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
400 ));
401
402 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
403 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
404 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
405
406 // Set reason code
407 *(sFrame.pwReason) = cpu_to_le16(wReason);
408 pTxPacket->cbMPDULen = sFrame.len;
409 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
410
411 // send the frame
412 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
413 if (*pStatus == CMD_STATUS_PENDING) {
414 pMgmt->eCurrState = WMAC_STATE_IDLE;
415 *pStatus = CMD_STATUS_SUCCESS;
9fc86028 416 }
92b96797
FB
417
418 return;
419}
420
92b96797
FB
421/*+
422 *
423 * Routine Description:(AP function)
424 * Handle incoming station association request frames.
425 *
426 * Return Value:
427 * None.
428 *
429-*/
430
78f41c91
MP
431static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
432 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
433 u32 uNodeIndex)
92b96797 434{
78f41c91
MP
435 WLAN_FR_ASSOCREQ sFrame;
436 CMD_STATUS Status;
437 struct vnt_tx_mgmt *pTxPacket;
438 u16 wAssocStatus = 0;
439 u16 wAssocAID = 0;
440 u32 uRateLen = WLAN_RATES_MAXLEN;
441 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
442 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
92b96797 443
92b96797
FB
444 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
445 return;
446 // node index not found
447 if (!uNodeIndex)
448 return;
449
450 //check if node is authenticated
451 //decode the frame
452 memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
453 memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
454 memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
455 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 456 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
457
458 vMgrDecodeAssocRequest(&sFrame);
459
460 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
461 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
462 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
463 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
464 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
4e9b5e2b 465 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
92b96797
FB
466 // Todo: check sta basic rate, if ap can't support, set status code
467 if (pDevice->byBBType == BB_TYPE_11B) {
468 uRateLen = WLAN_RATES_MAXLEN_11B;
469 }
470 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
471 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
472 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
473 uRateLen);
474 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
475 if (pDevice->byBBType == BB_TYPE_11G) {
476 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
477 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
478 uRateLen);
479 } else {
480 abyCurrExtSuppRates[1] = 0;
481 }
482
8611a29a 483 RATEvParseMaxRate((void *)pDevice,
92b96797
FB
484 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
485 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
e269fc2d 486 false, // do not change our basic rate
92b96797
FB
487 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
488 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
489 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
490 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
491 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
492 );
493
494 // set max tx rate
495 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
496 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
497 // Todo: check sta preamble, if ap can't support, set status code
498 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
499 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
500 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
501 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
3eaca0d2 502 pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
92b96797 503 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
3eaca0d2 504 wAssocAID = (u16)uNodeIndex;
92b96797
FB
505 // check if ERP support
506 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
4e9b5e2b 507 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
92b96797
FB
508
509 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
510 // B only STA join
4e9b5e2b
AM
511 pDevice->bProtectMode = true;
512 pDevice->bNonERPPresent = true;
92b96797 513 }
e269fc2d 514 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
4e9b5e2b 515 pDevice->bBarkerPreambleMd = true;
92b96797
FB
516 }
517
518 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
519 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
520 sFrame.pHdr->sA3.abyAddr2[0],
521 sFrame.pHdr->sA3.abyAddr2[1],
522 sFrame.pHdr->sA3.abyAddr2[2],
523 sFrame.pHdr->sA3.abyAddr2[3],
524 sFrame.pHdr->sA3.abyAddr2[4],
525 sFrame.pHdr->sA3.abyAddr2[5]
526 ) ;
527 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
528 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
529 }
530
92b96797
FB
531 // assoc response reply..
532 pTxPacket = s_MgrMakeAssocResponse
533 (
534 pDevice,
535 pMgmt,
536 pMgmt->wCurrCapInfo,
537 wAssocStatus,
538 wAssocAID,
539 sFrame.pHdr->sA3.abyAddr2,
540 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
541 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
542 );
543 if (pTxPacket != NULL ){
544
545 if (pDevice->bEnableHostapd) {
546 return;
547 }
548 /* send the frame */
549 Status = csMgmt_xmit(pDevice, pTxPacket);
550 if (Status != CMD_STATUS_PENDING) {
551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
552 }
553 else {
554 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
555 }
556
557 }
558
559 return;
560}
561
92b96797
FB
562/*+
563 *
564 * Description:(AP function)
565 * Handle incoming station re-association request frames.
566 *
567 * Parameters:
568 * In:
569 * pMgmt - Management Object structure
570 * pRxPacket - Received Packet
571 * Out:
572 * none
573 *
574 * Return Value: None.
575 *
576-*/
577
78f41c91
MP
578static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
579 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
580 u32 uNodeIndex)
92b96797 581{
78f41c91
MP
582 WLAN_FR_REASSOCREQ sFrame;
583 CMD_STATUS Status;
584 struct vnt_tx_mgmt *pTxPacket;
585 u16 wAssocStatus = 0;
586 u16 wAssocAID = 0;
587 u32 uRateLen = WLAN_RATES_MAXLEN;
588 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
589 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
92b96797
FB
590
591 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
592 return;
593 // node index not found
594 if (!uNodeIndex)
595 return;
596 //check if node is authenticated
597 //decode the frame
598 memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
599 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 600 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
601 vMgrDecodeReassocRequest(&sFrame);
602
603 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
604 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
605 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
606 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
607 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
4e9b5e2b 608 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
92b96797
FB
609 // Todo: check sta basic rate, if ap can't support, set status code
610
611 if (pDevice->byBBType == BB_TYPE_11B) {
612 uRateLen = WLAN_RATES_MAXLEN_11B;
613 }
614
615 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
616 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
617 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
618 uRateLen);
619 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
620 if (pDevice->byBBType == BB_TYPE_11G) {
621 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
622 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
623 uRateLen);
624 } else {
625 abyCurrExtSuppRates[1] = 0;
626 }
627
8611a29a 628 RATEvParseMaxRate((void *)pDevice,
92b96797
FB
629 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
630 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
e269fc2d 631 false, // do not change our basic rate
92b96797
FB
632 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
633 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
634 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
635 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
636 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
637 );
638
639 // set max tx rate
640 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
641 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
642 // Todo: check sta preamble, if ap can't support, set status code
643 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
644 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
645 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
646 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
3eaca0d2 647 pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
92b96797 648 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
3eaca0d2 649 wAssocAID = (u16)uNodeIndex;
92b96797
FB
650
651 // if suppurt ERP
652 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
4e9b5e2b 653 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
92b96797
FB
654
655 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
656 // B only STA join
4e9b5e2b
AM
657 pDevice->bProtectMode = true;
658 pDevice->bNonERPPresent = true;
92b96797 659 }
e269fc2d 660 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
4e9b5e2b 661 pDevice->bBarkerPreambleMd = true;
92b96797
FB
662 }
663
664 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
665 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
666 sFrame.pHdr->sA3.abyAddr2[0],
667 sFrame.pHdr->sA3.abyAddr2[1],
668 sFrame.pHdr->sA3.abyAddr2[2],
669 sFrame.pHdr->sA3.abyAddr2[3],
670 sFrame.pHdr->sA3.abyAddr2[4],
671 sFrame.pHdr->sA3.abyAddr2[5]
672 ) ;
673 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
674 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
675
676 }
677
92b96797
FB
678 // assoc response reply..
679 pTxPacket = s_MgrMakeReAssocResponse
680 (
681 pDevice,
682 pMgmt,
683 pMgmt->wCurrCapInfo,
684 wAssocStatus,
685 wAssocAID,
686 sFrame.pHdr->sA3.abyAddr2,
687 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
688 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
689 );
690
691 if (pTxPacket != NULL ){
692 /* send the frame */
693 if (pDevice->bEnableHostapd) {
694 return;
695 }
696 Status = csMgmt_xmit(pDevice, pTxPacket);
697 if (Status != CMD_STATUS_PENDING) {
698 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
699 }
700 else {
701 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
702 }
703 }
704 return;
705}
706
92b96797
FB
707/*+
708 *
709 * Routine Description:
710 * Handle incoming association response frames.
711 *
712 * Return Value:
713 * None.
714 *
715-*/
716
78f41c91
MP
717static void s_vMgrRxAssocResponse(struct vnt_private *pDevice,
718 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
719 int bReAssocType)
92b96797 720{
78f41c91
MP
721 WLAN_FR_ASSOCRESP sFrame;
722 PWLAN_IE_SSID pItemSSID;
723 u8 *pbyIEs;
92b96797 724
92b96797
FB
725 if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
726 pMgmt->eCurrState == WMAC_STATE_ASSOC) {
727
728 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 729 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
730 // decode the frame
731 vMgrDecodeAssocResponse(&sFrame);
6e1b4e24
AM
732 if ((sFrame.pwCapInfo == NULL)
733 || (sFrame.pwStatus == NULL)
734 || (sFrame.pwAid == NULL)
735 || (sFrame.pSuppRates == NULL)) {
6e1b4e24 736 return;
9fc86028 737 }
92b96797
FB
738
739 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
740 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
741 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
742 pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
743
744 pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
745 pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
746 pbyIEs = pMgmt->sAssocInfo.abyIEs;
747 pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
748 memcpy(pbyIEs, (sFrame.pBuf + 24 +6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
749
750 // save values and set current BSS state
751 if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
752 // set AID
753 pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
754 if ( (pMgmt->wCurrAID >> 14) != (BIT0 | BIT1) )
755 {
756 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
9fc86028 757 }
92b96797
FB
758 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14|BIT15));
759 pMgmt->eCurrState = WMAC_STATE_ASSOC;
0cbd8d98
AM
760 BSSvUpdateAPNode((void *) pDevice,
761 sFrame.pwCapInfo,
762 sFrame.pSuppRates,
763 sFrame.pExtSuppRates);
92b96797
FB
764 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
765 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
4e9b5e2b 766 pDevice->bLinkPass = true;
92b96797 767 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
465711b3 768
4e9b5e2b 769 //if(pDevice->bWPASuppWextEnabled == true)
92b96797 770 {
b902fbfe 771 u8 buf[512];
92b96797
FB
772 size_t len;
773 union iwreq_data wrqu;
774 int we_event;
775
776 memset(buf, 0, 512);
777
778 len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
779 if(len) {
780 memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
781 memset(&wrqu, 0, sizeof (wrqu));
782 wrqu.data.length = len;
783 we_event = IWEVASSOCREQIE;
784 PRINT_K("wireless_send_event--->IWEVASSOCREQIE\n");
785 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
786 }
787
788 memset(buf, 0, 512);
789 len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
790
791 if(len) {
792 memcpy(buf, pbyIEs, len);
793 memset(&wrqu, 0, sizeof (wrqu));
794 wrqu.data.length = len;
795 we_event = IWEVASSOCRESPIE;
796 PRINT_K("wireless_send_event--->IWEVASSOCRESPIE\n");
797 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
798 }
799
800 memset(&wrqu, 0, sizeof (wrqu));
801 memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
802 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
803 PRINT_K("wireless_send_event--->SIOCGIWAP(associated)\n");
804 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
805
806 }
465711b3 807
92b96797
FB
808 }
809 else {
810 if (bReAssocType) {
811 pMgmt->eCurrState = WMAC_STATE_IDLE;
812 }
813 else {
814 // jump back to the auth state and indicate the error
815 pMgmt->eCurrState = WMAC_STATE_AUTH;
816 }
817 s_vMgrLogStatus(pMgmt,cpu_to_le16((*(sFrame.pwStatus))));
818 }
819
820 }
821
92b96797 822//need clear flags related to Networkmanager
e269fc2d
AM
823 pDevice->bwextstep0 = false;
824 pDevice->bwextstep1 = false;
825 pDevice->bwextstep2 = false;
826 pDevice->bwextstep3 = false;
827 pDevice->bWPASuppWextEnabled = false;
92b96797 828
94488a7e
MP
829 if (pMgmt->eCurrState == WMAC_STATE_ASSOC)
830 schedule_delayed_work(&pDevice->run_command_work, 0);
92b96797
FB
831
832 return;
833}
834
92b96797
FB
835/*+
836 *
837 * Routine Description:
838 * Start the station authentication procedure. Namely, send an
839 * authentication frame to the AP.
840 *
841 * Return Value:
842 * None.
843 *
844-*/
845
78f41c91
MP
846void vMgrAuthenBeginSta(struct vnt_private *pDevice,
847 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
92b96797 848{
78f41c91
MP
849 WLAN_FR_AUTHEN sFrame;
850 struct vnt_tx_mgmt *pTxPacket =
851 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
852
853 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
854 + WLAN_AUTHEN_FR_MAXLEN);
855 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
856 + sizeof(struct vnt_tx_mgmt));
b902fbfe 857 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
858 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
859 vMgrEncodeAuthen(&sFrame);
860 /* insert values */
861 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
862 (
863 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
864 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
865 ));
866 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
867 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
868 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
869 if (pMgmt->bShareKeyAlgorithm)
870 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
871 else
872 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
873
874 *(sFrame.pwAuthSequence) = cpu_to_le16(1);
875 /* Adjust the length fields */
876 pTxPacket->cbMPDULen = sFrame.len;
877 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
878
879 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
880 if (*pStatus == CMD_STATUS_PENDING){
881 pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
882 *pStatus = CMD_STATUS_SUCCESS;
883 }
884
885 return ;
886}
887
92b96797
FB
888/*+
889 *
890 * Routine Description:
891 * Start the station(AP) deauthentication procedure. Namely, send an
892 * deauthentication frame to the AP or Sta.
893 *
894 * Return Value:
895 * None.
896 *
897-*/
898
78f41c91
MP
899void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
900 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
901 PCMD_STATUS pStatus)
92b96797 902{
78f41c91
MP
903 WLAN_FR_DEAUTHEN sFrame;
904 struct vnt_tx_mgmt *pTxPacket =
905 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
906
907 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
908 + WLAN_DEAUTHEN_FR_MAXLEN);
909 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
910 + sizeof(struct vnt_tx_mgmt));
b902fbfe 911 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
912 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
913 vMgrEncodeDeauthen(&sFrame);
914 /* insert values */
915 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
916 (
917 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
918 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
919 ));
920
921 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
922 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
923 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
924
925 *(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
926 /* Adjust the length fields */
927 pTxPacket->cbMPDULen = sFrame.len;
928 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
929
930 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
931 if (*pStatus == CMD_STATUS_PENDING){
932 *pStatus = CMD_STATUS_SUCCESS;
933 }
934
92b96797
FB
935 return ;
936}
937
92b96797
FB
938/*+
939 *
940 * Routine Description:
941 * Handle incoming authentication frames.
942 *
943 * Return Value:
944 * None.
945 *
946-*/
947
78f41c91
MP
948static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
949 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
92b96797 950{
78f41c91 951 WLAN_FR_AUTHEN sFrame;
92b96797
FB
952
953 // we better be an AP or a STA in AUTHPENDING otherwise ignore
954 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
955 pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
956 return;
957 }
958
959 // decode the frame
960 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 961 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
962 vMgrDecodeAuthen(&sFrame);
963 switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
964 case 1:
965 //AP funciton
966 s_vMgrRxAuthenSequence_1(pDevice,pMgmt, &sFrame);
967 break;
968 case 2:
969 s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
970 break;
971 case 3:
972 //AP funciton
973 s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
974 break;
975 case 4:
976 s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
977 break;
978 default:
979 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
980 cpu_to_le16((*(sFrame.pwAuthSequence))));
981 break;
982 }
983 return;
984}
985
92b96797
FB
986/*+
987 *
988 * Routine Description:
989 * Handles incoming authen frames with sequence 1. Currently
990 * assumes we're an AP. So far, no one appears to use authentication
991 * in Ad-Hoc mode.
992 *
993 * Return Value:
994 * None.
995 *
996-*/
997
78f41c91
MP
998static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
999 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
92b96797 1000{
78f41c91
MP
1001 struct vnt_tx_mgmt *pTxPacket = NULL;
1002 u32 uNodeIndex;
1003 WLAN_FR_AUTHEN sFrame;
1004 PSKeyItem pTransmitKey;
1005
1006 /* Insert a Node entry */
1007 if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2,
1008 &uNodeIndex)) {
1009 BSSvCreateOneNode(pDevice, &uNodeIndex);
1010 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr,
1011 pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1012 }
92b96797
FB
1013
1014 if (pMgmt->bShareKeyAlgorithm) {
1015 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
1016 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
1017 }
1018 else {
1019 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1020 }
1021
1022 // send auth reply
78f41c91
MP
1023 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1024 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1025 + WLAN_AUTHEN_FR_MAXLEN);
1026 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1027 + sizeof(struct vnt_tx_mgmt));
b902fbfe 1028 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
1029 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1030 // format buffer structure
1031 vMgrEncodeAuthen(&sFrame);
1032 // insert values
1033 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1034 (
1035 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1036 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1037 WLAN_SET_FC_ISWEP(0)
1038 ));
1039 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1040 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1041 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1042 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1043 *(sFrame.pwAuthSequence) = cpu_to_le16(2);
1044
1045 if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
1046 if (pMgmt->bShareKeyAlgorithm)
1047 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1048 else
1049 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1050 }
1051 else {
1052 if (pMgmt->bShareKeyAlgorithm)
1053 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1054 else
1055 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1056 }
1057
1058 if (pMgmt->bShareKeyAlgorithm &&
1059 (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
1060
1061 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1062 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1063 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1064 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1065 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
1066 // get group key
4e9b5e2b 1067 if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
92b96797
FB
1068 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
1069 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
1070 }
1071 memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
1072 }
1073
1074 /* Adjust the length fields */
1075 pTxPacket->cbMPDULen = sFrame.len;
1076 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1077 // send the frame
1078 if (pDevice->bEnableHostapd) {
1079 return;
1080 }
1081 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
1082 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1083 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
1084 }
1085 return;
1086}
1087
92b96797
FB
1088/*+
1089 *
1090 * Routine Description:
1091 * Handles incoming auth frames with sequence number 2. Currently
1092 * assumes we're a station.
1093 *
1094 *
1095 * Return Value:
1096 * None.
1097 *
1098-*/
1099
78f41c91
MP
1100static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
1101 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
92b96797 1102{
78f41c91
MP
1103 WLAN_FR_AUTHEN sFrame;
1104 struct vnt_tx_mgmt *pTxPacket = NULL;
92b96797 1105
92b96797
FB
1106 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
1107 {
1108 case WLAN_AUTH_ALG_OPENSYSTEM:
1109 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1110 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
1111 pMgmt->eCurrState = WMAC_STATE_AUTH;
94488a7e 1112 schedule_delayed_work(&pDevice->run_command_work, 0);
92b96797
FB
1113 }
1114 else {
1115 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
1116 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1117 pMgmt->eCurrState = WMAC_STATE_IDLE;
1118 }
0cbd8d98
AM
1119 if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT) {
1120 /* spin_unlock_irq(&pDevice->lock);
1121 vCommandTimerWait((void *) pDevice, 0);
1122 spin_lock_irq(&pDevice->lock); */
92b96797 1123 }
92b96797
FB
1124 break;
1125
1126 case WLAN_AUTH_ALG_SHAREDKEY:
1127
1128 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
78f41c91
MP
1129 pTxPacket = (struct vnt_tx_mgmt *)
1130 pMgmt->pbyMgmtPacketPool;
1131 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1132 + WLAN_AUTHEN_FR_MAXLEN);
1133 pTxPacket->p80211Header
1134 = (PUWLAN_80211HDR)((u8 *)pTxPacket
1135 + sizeof(struct vnt_tx_mgmt));
b902fbfe 1136 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
1137 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1138 // format buffer structure
1139 vMgrEncodeAuthen(&sFrame);
1140 // insert values
1141 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1142 (
1143 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1144 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1145 WLAN_SET_FC_ISWEP(1)
1146 ));
1147 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1148 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1149 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1150 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1151 *(sFrame.pwAuthSequence) = cpu_to_le16(3);
1152 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1153 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1154 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1155 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1156 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1157 memcpy( sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
1158 // Adjust the length fields
1159 pTxPacket->cbMPDULen = sFrame.len;
1160 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1161 // send the frame
1162 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1163 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
1164 }
1165 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
1166 }
1167 else {
1168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
1169 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
0cbd8d98
AM
1170 /* spin_unlock_irq(&pDevice->lock);
1171 vCommandTimerWait((void *) pDevice, 0);
1172 spin_lock_irq(&pDevice->lock); */
92b96797
FB
1173 }
1174 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1175 }
1176 break;
1177 default:
1178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
1179 break;
1180 }
1181 return;
1182}
1183
92b96797
FB
1184/*+
1185 *
1186 * Routine Description:
1187 * Handles incoming authen frames with sequence 3. Currently
1188 * assumes we're an AP. This function assumes the frame has
1189 * already been successfully decrypted.
1190 *
1191 *
1192 * Return Value:
1193 * None.
1194 *
1195-*/
1196
78f41c91
MP
1197static void s_vMgrRxAuthenSequence_3(struct vnt_private *pDevice,
1198 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
92b96797 1199{
78f41c91
MP
1200 struct vnt_tx_mgmt *pTxPacket = NULL;
1201 u32 uStatusCode = 0 ;
1202 u32 uNodeIndex = 0;
1203 WLAN_FR_AUTHEN sFrame;
92b96797
FB
1204
1205 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
1206 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1207 goto reply;
1208 }
1209 if (BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1210 if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
1211 uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
1212 goto reply;
1213 }
1214 if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
1215 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1216 goto reply;
1217 }
1218 }
1219 else {
1220 uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
1221 goto reply;
1222 }
1223
1224 if (uNodeIndex) {
1225 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1226 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
1227 }
1228 uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
1229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
1230
1231reply:
1232 // send auth reply
78f41c91
MP
1233 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1234 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1235 + WLAN_AUTHEN_FR_MAXLEN);
1236 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1237 + sizeof(struct vnt_tx_mgmt));
b902fbfe 1238 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
1239 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1240 // format buffer structure
1241 vMgrEncodeAuthen(&sFrame);
1242 /* insert values */
1243 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1244 (
1245 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1246 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1247 WLAN_SET_FC_ISWEP(0)
1248 ));
1249 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1250 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1251 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1252 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1253 *(sFrame.pwAuthSequence) = cpu_to_le16(4);
1254 *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
1255
1256 /* Adjust the length fields */
1257 pTxPacket->cbMPDULen = sFrame.len;
1258 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1259 // send the frame
1260 if (pDevice->bEnableHostapd) {
1261 return;
1262 }
1263 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1264 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
1265 }
1266 return;
1267
1268}
1269
92b96797
FB
1270/*+
1271 *
1272 * Routine Description:
1273 * Handles incoming authen frames with sequence 4
1274 *
1275 *
1276 * Return Value:
1277 * None.
1278 *
1279-*/
78f41c91
MP
1280static void s_vMgrRxAuthenSequence_4(struct vnt_private *pDevice,
1281 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
92b96797
FB
1282{
1283
1284 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1285 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
1286 pMgmt->eCurrState = WMAC_STATE_AUTH;
94488a7e 1287 schedule_delayed_work(&pDevice->run_command_work, 0);
92b96797
FB
1288 }
1289 else{
1290 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
1291 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))) );
1292 pMgmt->eCurrState = WMAC_STATE_IDLE;
1293 }
1294
1295 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
0cbd8d98
AM
1296 /* spin_unlock_irq(&pDevice->lock);
1297 vCommandTimerWait((void *) pDevice, 0);
1298 spin_lock_irq(&pDevice->lock); */
92b96797 1299 }
92b96797
FB
1300}
1301
1302/*+
1303 *
1304 * Routine Description:
1305 * Handles incoming disassociation frames
1306 *
1307 *
1308 * Return Value:
1309 * None.
1310 *
1311-*/
1312
78f41c91
MP
1313static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
1314 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
92b96797 1315{
78f41c91
MP
1316 WLAN_FR_DISASSOC sFrame;
1317 u32 uNodeIndex = 0;
1318 CMD_STATUS CmdStatus;
92b96797
FB
1319
1320 if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1321 // if is acting an AP..
1322 // a STA is leaving this BSS..
1323 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 1324 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
1325 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1326 BSSvRemoveOneNode(pDevice, uNodeIndex);
1327 }
1328 else {
1329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
1330 }
1331 }
1332 else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
1333 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 1334 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
1335 vMgrDecodeDisassociation(&sFrame);
1336 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
1337
e269fc2d 1338 pDevice->fWPA_Authened = false;
92b96797
FB
1339
1340 //TODO: do something let upper layer know or
1341 //try to send associate packet again because of inactivity timeout
1342 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
e269fc2d
AM
1343 pDevice->bLinkPass = false;
1344 pMgmt->sNodeDBTable[0].bActive = false;
92b96797
FB
1345 pDevice->byReAssocCount = 0;
1346 pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state!
1347 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
78f41c91 1348 vMgrReAssocBeginSta(pDevice, pMgmt, &CmdStatus);
92b96797
FB
1349 if(CmdStatus == CMD_STATUS_PENDING) {
1350 pDevice->byReAssocCount ++;
1351 return; //mike add: you'll retry for many times, so it cann't be regarded as disconnected!
1352 }
9fc86028 1353 }
92b96797 1354
4e9b5e2b 1355 // if(pDevice->bWPASuppWextEnabled == true)
92b96797
FB
1356 {
1357 union iwreq_data wrqu;
1358 memset(&wrqu, 0, sizeof (wrqu));
1359 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1360 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1361 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1362 }
92b96797
FB
1363 }
1364 /* else, ignore it */
1365
1366 return;
1367}
1368
92b96797
FB
1369/*+
1370 *
1371 * Routine Description:
1372 * Handles incoming deauthentication frames
1373 *
1374 *
1375 * Return Value:
1376 * None.
1377 *
1378-*/
1379
78f41c91
MP
1380static void s_vMgrRxDeauthentication(struct vnt_private *pDevice,
1381 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
92b96797 1382{
78f41c91
MP
1383 WLAN_FR_DEAUTHEN sFrame;
1384 u32 uNodeIndex = 0;
92b96797 1385
92b96797
FB
1386 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1387 //Todo:
1388 // if is acting an AP..
1389 // a STA is leaving this BSS..
1390 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 1391 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
1392 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1393 BSSvRemoveOneNode(pDevice, uNodeIndex);
1394 }
1395 else {
1396 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
1397 }
1398 }
1399 else {
1400 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
1401 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 1402 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797 1403 vMgrDecodeDeauthen(&sFrame);
e269fc2d 1404 pDevice->fWPA_Authened = false;
92b96797
FB
1405 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
1406 // TODO: update BSS list for specific BSSID if pre-authentication case
8329419a
JP
1407 if (ether_addr_equal(sFrame.pHdr->sA3.abyAddr3,
1408 pMgmt->abyCurrBSSID)) {
92b96797 1409 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
e269fc2d 1410 pMgmt->sNodeDBTable[0].bActive = false;
92b96797
FB
1411 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1412 pMgmt->eCurrState = WMAC_STATE_IDLE;
1413 netif_stop_queue(pDevice->dev);
e269fc2d 1414 pDevice->bLinkPass = false;
92b96797
FB
1415 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1416 }
9fc86028 1417 }
92b96797 1418
4e9b5e2b 1419 // if(pDevice->bWPASuppWextEnabled == true)
92b96797
FB
1420 {
1421 union iwreq_data wrqu;
1422 memset(&wrqu, 0, sizeof (wrqu));
1423 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1424 PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
1425 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1426 }
92b96797
FB
1427
1428 }
1429 /* else, ignore it. TODO: IBSS authentication service
1430 would be implemented here */
1431 };
1432 return;
1433}
1434
92b96797
FB
1435/*+
1436 *
1437 * Routine Description:
1438 * check if current channel is match ZoneType.
1439 *for USA:1~11;
1440 * Japan:1~13;
1441 * Europe:1~13
1442 * Return Value:
1443 * True:exceed;
1444 * False:normal case
1445-*/
78f41c91 1446static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel)
92b96797 1447{
e269fc2d 1448 int exceed = false;
92b96797
FB
1449
1450 switch(pDevice->byZoneType) {
1451 case 0x00: //USA:1~11
1452 if((byCurrChannel<1) ||(byCurrChannel>11))
4e9b5e2b 1453 exceed = true;
92b96797
FB
1454 break;
1455 case 0x01: //Japan:1~13
1456 case 0x02: //Europe:1~13
1457 if((byCurrChannel<1) ||(byCurrChannel>13))
4e9b5e2b 1458 exceed = true;
92b96797
FB
1459 break;
1460 default: //reserve for other zonetype
1461 break;
1462 }
1463
1464 return exceed;
1465}
1466
1467/*+
1468 *
1469 * Routine Description:
1470 * Handles and analysis incoming beacon frames.
1471 *
1472 *
1473 * Return Value:
1474 * None.
1475 *
1476-*/
1477
78f41c91
MP
1478static void s_vMgrRxBeacon(struct vnt_private *pDevice,
1479 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
1480 int bInScan)
92b96797 1481{
78f41c91
MP
1482 PKnownBSS pBSSList;
1483 WLAN_FR_BEACON sFrame;
7c65fa2a 1484 u64 qwTSFOffset;
e269fc2d
AM
1485 int bIsBSSIDEqual = false;
1486 int bIsSSIDEqual = false;
1487 int bTSFLargeDiff = false;
1488 int bTSFOffsetPostive = false;
1489 int bUpdateTSF = false;
1490 int bIsAPBeacon = false;
1491 int bIsChannelEqual = false;
78f41c91
MP
1492 u32 uLocateByteIndex;
1493 u8 byTIMBitOn = 0;
1494 u16 wAIDNumber = 0;
1495 u32 uNodeIndex;
7c65fa2a
MP
1496 u64 qwTimestamp, qwLocalTSF;
1497 u64 qwCurrTSF;
78f41c91
MP
1498 u16 wStartIndex = 0;
1499 u16 wAIDIndex = 0;
1500 u8 byCurrChannel = pRxPacket->byRxChannel;
1501 ERPObject sERP;
1502 u32 uRateLen = WLAN_RATES_MAXLEN;
e269fc2d 1503 int bChannelHit = false;
78f41c91 1504 u8 byOldPreambleType;
92b96797 1505
92b96797
FB
1506 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
1507 return;
1508
1509 memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
1510 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 1511 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
1512
1513 // decode the beacon frame
1514 vMgrDecodeBeacon(&sFrame);
1515
6e1b4e24
AM
1516 if ((sFrame.pwBeaconInterval == NULL)
1517 || (sFrame.pwCapInfo == NULL)
1518 || (sFrame.pSSID == NULL)
1519 || (sFrame.pSuppRates == NULL)) {
92b96797 1520
6e1b4e24
AM
1521 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
1522 return;
9fc86028 1523 }
92b96797
FB
1524
1525 if( byCurrChannel > CB_MAX_CHANNEL_24G )
1526 {
1527 if (sFrame.pDSParms != NULL) {
1528 if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
4e9b5e2b 1529 bChannelHit = true;
92b96797
FB
1530 byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
1531 } else {
4e9b5e2b 1532 bChannelHit = true;
92b96797
FB
1533 }
1534
1535 } else {
1536 if (sFrame.pDSParms != NULL) {
1537 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
4e9b5e2b 1538 bChannelHit = true;
92b96797
FB
1539 byCurrChannel = sFrame.pDSParms->byCurrChannel;
1540 } else {
4e9b5e2b 1541 bChannelHit = true;
92b96797
FB
1542 }
1543 }
1544
4e9b5e2b 1545if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
92b96797
FB
1546 return;
1547
1548 if (sFrame.pERP != NULL) {
1549 sERP.byERP = sFrame.pERP->byContext;
4e9b5e2b 1550 sERP.bERPExist = true;
92b96797
FB
1551
1552 } else {
e269fc2d 1553 sERP.bERPExist = false;
92b96797
FB
1554 sERP.byERP = 0;
1555 }
1556
0cbd8d98
AM
1557 pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
1558 sFrame.pHdr->sA3.abyAddr3,
1559 sFrame.pSSID);
92b96797
FB
1560 if (pBSSList == NULL) {
1561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon/insert: RxChannel = : %d\n", byCurrChannel);
0cbd8d98 1562 BSSbInsertToBSSList((void *) pDevice,
92b96797
FB
1563 sFrame.pHdr->sA3.abyAddr3,
1564 *sFrame.pqwTimestamp,
1565 *sFrame.pwBeaconInterval,
1566 *sFrame.pwCapInfo,
1567 byCurrChannel,
1568 sFrame.pSSID,
1569 sFrame.pSuppRates,
1570 sFrame.pExtSuppRates,
1571 &sERP,
1572 sFrame.pRSN,
1573 sFrame.pRSNWPA,
1574 sFrame.pIE_Country,
1575 sFrame.pIE_Quiet,
1576 sFrame.len - WLAN_HDR_ADDR3_LEN,
1577 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
0cbd8d98 1578 (void *) pRxPacket);
92b96797
FB
1579 }
1580 else {
1581// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"update bcn: RxChannel = : %d\n", byCurrChannel);
0cbd8d98 1582 BSSbUpdateToBSSList((void *) pDevice,
92b96797
FB
1583 *sFrame.pqwTimestamp,
1584 *sFrame.pwBeaconInterval,
1585 *sFrame.pwCapInfo,
1586 byCurrChannel,
1587 bChannelHit,
1588 sFrame.pSSID,
1589 sFrame.pSuppRates,
1590 sFrame.pExtSuppRates,
1591 &sERP,
1592 sFrame.pRSN,
1593 sFrame.pRSNWPA,
1594 sFrame.pIE_Country,
1595 sFrame.pIE_Quiet,
1596 pBSSList,
1597 sFrame.len - WLAN_HDR_ADDR3_LEN,
1598 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
0cbd8d98 1599 (void *) pRxPacket);
92b96797
FB
1600
1601 }
1602
1603 if (bInScan) {
1604 return;
1605 }
1606
b902fbfe 1607 if(byCurrChannel == (u8)pMgmt->uCurrChannel)
4e9b5e2b 1608 bIsChannelEqual = true;
92b96797
FB
1609
1610 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1611
1612 // if rx beacon without ERP field
1613 if (sERP.bERPExist) {
1614 if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)){
1615 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1616 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1617 }
1618 }
1619 else {
1620 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1621 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1622 }
1623
1624 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1625 if(!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
1626 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1627 if(!sERP.bERPExist)
1628 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1629 }
1630 }
1631
1632 // check if BSSID the same
1633 if (memcmp(sFrame.pHdr->sA3.abyAddr3,
1634 pMgmt->abyCurrBSSID,
1635 WLAN_BSSID_LEN) == 0) {
1636
4e9b5e2b 1637 bIsBSSIDEqual = true;
92b96797
FB
1638 pDevice->uCurrRSSI = pRxPacket->uRSSI;
1639 pDevice->byCurrSQ = pRxPacket->bySQ;
1640 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
1641 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1642 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
1643 }
1644 }
1645 // check if SSID the same
1646 if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
1647 if (memcmp(sFrame.pSSID->abySSID,
1648 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
1649 sFrame.pSSID->len
1650 ) == 0) {
4e9b5e2b 1651 bIsSSIDEqual = true;
9fc86028 1652 }
92b96797
FB
1653 }
1654
4e9b5e2b
AM
1655 if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) &&
1656 (bIsBSSIDEqual == true) &&
1657 (bIsSSIDEqual == true) &&
92b96797
FB
1658 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1659 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1660 // add state check to prevent reconnect fail since we'll receive Beacon
1661
4e9b5e2b 1662 bIsAPBeacon = true;
92b96797
FB
1663 if (pBSSList != NULL) {
1664
1665 // Sync ERP field
4e9b5e2b 1666 if ((pBSSList->sERP.bERPExist == true) && (pDevice->byBBType == BB_TYPE_11G)) {
92b96797
FB
1667 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
1668 pDevice->bProtectMode = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
1669 if (pDevice->bProtectMode) {
1670 MACvEnableProtectMD(pDevice);
1671 } else {
1672 MACvDisableProtectMD(pDevice);
1673 }
1674 vUpdateIFS(pDevice);
1675 }
1676 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
1677 pDevice->bNonERPPresent = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
1678 }
1679 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
1680 pDevice->bBarkerPreambleMd = (pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
1681 //BarkerPreambleMd has higher priority than shortPreamble bit in Cap
1682 if (pDevice->bBarkerPreambleMd) {
1683 MACvEnableBarkerPreambleMd(pDevice);
1684 } else {
1685 MACvDisableBarkerPreambleMd(pDevice);
1686 }
1687 }
1688 }
1689 // Sync Short Slot Time
1690 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo) != pDevice->bShortSlotTime) {
dfdcc425 1691 bool bShortSlotTime;
92b96797
FB
1692
1693 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo);
1694 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
1695 //Kyle check if it is OK to set G.
1696 if (pDevice->byBBType == BB_TYPE_11A) {
4e9b5e2b 1697 bShortSlotTime = true;
92b96797
FB
1698 }
1699 else if (pDevice->byBBType == BB_TYPE_11B) {
e269fc2d 1700 bShortSlotTime = false;
92b96797
FB
1701 }
1702 if (bShortSlotTime != pDevice->bShortSlotTime) {
1703 pDevice->bShortSlotTime = bShortSlotTime;
1704 BBvSetShortSlotTime(pDevice);
1705 vUpdateIFS(pDevice);
1706 }
1707 }
1708
1709 //
93184690 1710 // Preamble may change dynamically
92b96797
FB
1711 //
1712 byOldPreambleType = pDevice->byPreambleType;
1713 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pBSSList->wCapInfo)) {
1714 pDevice->byPreambleType = pDevice->byShortPreamble;
1715 }
1716 else {
1717 pDevice->byPreambleType = 0;
1718 }
1719 if (pDevice->byPreambleType != byOldPreambleType)
b902fbfe 1720 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
92b96797 1721 //
93184690 1722 // Basic Rate Set may change dynamically
92b96797
FB
1723 //
1724 if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
1725 uRateLen = WLAN_RATES_MAXLEN_11B;
1726 }
1727 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
1728 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1729 uRateLen);
1730 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
1731 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1732 uRateLen);
8611a29a 1733 RATEvParseMaxRate((void *)pDevice,
92b96797
FB
1734 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1735 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
4e9b5e2b 1736 true,
92b96797
FB
1737 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
1738 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
1739 &(pMgmt->sNodeDBTable[0].wSuppRate),
1740 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
1741 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
1742 );
1743
1744 }
1745 }
1746
1747// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon 2 \n");
1748 // check if CF field exisit
1749 if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
1750 if (sFrame.pCFParms->wCFPDurRemaining > 0) {
1751 // TODO: deal with CFP period to set NAV
9fc86028
JP
1752 }
1753 }
92b96797 1754
7c65fa2a
MP
1755 qwTimestamp = cpu_to_le64(*sFrame.pqwTimestamp);
1756 qwLocalTSF = pRxPacket->qwLocalTSF;
92b96797
FB
1757
1758 // check if beacon TSF larger or small than our local TSF
7c65fa2a 1759 if (qwTimestamp >= qwLocalTSF)
4e9b5e2b 1760 bTSFOffsetPostive = true;
7c65fa2a 1761 else
e269fc2d 1762 bTSFOffsetPostive = false;
92b96797
FB
1763
1764 if (bTSFOffsetPostive) {
1765 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
1766 }
1767 else {
1768 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
1769 }
1770
7c65fa2a 1771 if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
4e9b5e2b 1772 bTSFLargeDiff = true;
92b96797 1773
92b96797 1774 // if infra mode
4e9b5e2b 1775 if (bIsAPBeacon == true) {
92b96797
FB
1776
1777 // Infra mode: Local TSF always follow AP's TSF if Difference huge.
1778 if (bTSFLargeDiff)
4e9b5e2b 1779 bUpdateTSF = true;
92b96797 1780
4e9b5e2b 1781 if ((pDevice->bEnablePSMode == true) && (sFrame.pTIM)) {
92b96797 1782
6e1b4e24 1783 /* deal with DTIM, analysis TIM */
4e9b5e2b 1784 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ;
92b96797
FB
1785 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
1786 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
1787 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
1788
1789 // check if AID in TIM field bit on
1790 // wStartIndex = N1
1791 wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
1792 // AIDIndex = N2
1793 wAIDIndex = (wAIDNumber >> 3);
1794 if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
1795 uLocateByteIndex = wAIDIndex - wStartIndex;
1796 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
1797 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
1798 byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
4e9b5e2b 1799 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
92b96797
FB
1800 }
1801 else {
e269fc2d 1802 pMgmt->bInTIM = false;
92b96797
FB
1803 };
1804 }
1805 else {
e269fc2d 1806 pMgmt->bInTIM = false;
92b96797
FB
1807 };
1808
1809 if (pMgmt->bInTIM ||
1810 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
4e9b5e2b 1811 pMgmt->bInTIMWake = true;
78f41c91
MP
1812 /* send out ps-poll packet */
1813 if (pMgmt->bInTIM)
1814 PSvSendPSPOLL(pDevice);
92b96797
FB
1815
1816 }
1817 else {
e269fc2d 1818 pMgmt->bInTIMWake = false;
92b96797 1819 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
e269fc2d 1820 if (pDevice->bPWBitOn == false) {
92b96797
FB
1821 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
1822 if (PSbSendNullPacket(pDevice))
4e9b5e2b 1823 pDevice->bPWBitOn = true;
92b96797 1824 }
e269fc2d 1825 if(PSbConsiderPowerDown(pDevice, false, false)) {
92b96797 1826 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
9fc86028 1827 }
92b96797
FB
1828 }
1829
1830 }
1831
1832 }
1833 // if adhoc mode
1834 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
1835 if (bIsBSSIDEqual) {
1836 // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
1837 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
1838 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1839
1840 // adhoc mode:TSF updated only when beacon larger then local TSF
1841 if (bTSFLargeDiff && bTSFOffsetPostive &&
1842 (pMgmt->eCurrState == WMAC_STATE_JOINTED))
4e9b5e2b 1843 bUpdateTSF = true;
92b96797
FB
1844
1845 // During dpc, already in spinlocked.
1846 if (BSSbIsSTAInNodeDB(pDevice, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
1847
a0a1f61a 1848 // Update the STA, (Technically the Beacons of all the IBSS nodes
92b96797
FB
1849 // should be identical, but that's not happening in practice.
1850 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1851 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1852 WLAN_RATES_MAXLEN_11B);
8611a29a 1853 RATEvParseMaxRate((void *)pDevice,
92b96797
FB
1854 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1855 NULL,
4e9b5e2b 1856 true,
92b96797
FB
1857 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
1858 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
1859 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
1860 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
1861 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
1862 );
1863 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
1864 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
1865 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
1866 }
1867 else {
78f41c91
MP
1868 /* Todo, initial Node content */
1869 BSSvCreateOneNode(pDevice, &uNodeIndex);
92b96797
FB
1870
1871 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1872 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1873 WLAN_RATES_MAXLEN_11B);
8611a29a 1874 RATEvParseMaxRate((void *)pDevice,
92b96797
FB
1875 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1876 NULL,
4e9b5e2b 1877 true,
92b96797
FB
1878 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
1879 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
1880 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
1881 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
1882 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
1883 );
1884
1885 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1886 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
1887 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
1888/*
1889 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
1890 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
4e9b5e2b 1891 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
92b96797
FB
1892*/
1893 }
1894
1895 // if other stations jointed, indicate connect to upper layer..
1896 if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
1897 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
1898 pMgmt->eCurrState = WMAC_STATE_JOINTED;
4e9b5e2b 1899 pDevice->bLinkPass = true;
92b96797
FB
1900 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
1901 if (netif_queue_stopped(pDevice->dev)){
1902 netif_wake_queue(pDevice->dev);
1903 }
4e9b5e2b 1904 pMgmt->sNodeDBTable[0].bActive = true;
92b96797
FB
1905 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1906
9fc86028 1907 }
92b96797
FB
1908 }
1909 else if (bIsSSIDEqual) {
1910
1911 // See other adhoc sta with the same SSID but BSSID is different.
1912 // adpot this vars only when TSF larger then us.
1913 if (bTSFLargeDiff && bTSFOffsetPostive) {
1914 // we don't support ATIM under adhoc mode
1915 // if ( sFrame.pIBSSParms->wATIMWindow == 0) {
1916 // adpot this vars
1917 // TODO: check sFrame cap if privacy on, and support rate syn
1918 memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
1919 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1920 pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
1921 pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
1922 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
1923 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1924 WLAN_RATES_MAXLEN_11B);
1925 // set HW beacon interval and re-synchronizing....
1926 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
1927
1928 MACvWriteBeaconInterval(pDevice, pMgmt->wCurrBeaconPeriod);
1929 CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
1930 CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
1931
1932 // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
1933 MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
1934
1935 byOldPreambleType = pDevice->byPreambleType;
1936 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo)) {
1937 pDevice->byPreambleType = pDevice->byShortPreamble;
1938 }
1939 else {
1940 pDevice->byPreambleType = 0;
1941 }
1942 if (pDevice->byPreambleType != byOldPreambleType)
b902fbfe 1943 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
92b96797 1944
92b96797
FB
1945 // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
1946 // set highest basic rate
1947 // s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
1948 // Prepare beacon frame
0cbd8d98 1949 bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
92b96797 1950 // }
9fc86028 1951 }
92b96797 1952 }
9fc86028 1953 }
92b96797
FB
1954 // endian issue ???
1955 // Update TSF
1956 if (bUpdateTSF) {
1957 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
1958 CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp , pRxPacket->qwLocalTSF);
1959 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
1960 CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
1961 }
1962
1963 return;
1964}
1965
92b96797
FB
1966/*+
1967 *
1968 * Routine Description:
1969 * Instructs the hw to create a bss using the supplied
1970 * attributes. Note that this implementation only supports Ad-Hoc
1971 * BSS creation.
1972 *
1973 *
1974 * Return Value:
1975 * CMD_STATUS
1976 *
1977-*/
0cbd8d98 1978
78f41c91 1979void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
92b96797 1980{
78f41c91
MP
1981 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1982 u16 wMaxBasicRate;
1983 u16 wMaxSuppRate;
1984 u8 byTopCCKBasicRate;
1985 u8 byTopOFDMBasicRate;
7c65fa2a 1986 u64 qwCurrTSF = 0;
78f41c91
MP
1987 int ii;
1988 u8 abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C,
1989 0x12, 0x18, 0x60};
1990 u8 abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
1991 u8 abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
1992 u16 wSuppRate;
92b96797 1993
92b96797
FB
1994 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
1995
1996 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
1997 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
1998 (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
1999 (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
2000 // encryption mode error
2001 *pStatus = CMD_STATUS_FAILURE;
2002 return;
2003 }
2004 }
2005
2006 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2007 pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
2008
2009 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2010 pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
2011 } else {
2012 if (pDevice->byBBType == BB_TYPE_11G)
2013 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2014 if (pDevice->byBBType == BB_TYPE_11B)
2015 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2016 if (pDevice->byBBType == BB_TYPE_11A)
2017 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2018 }
2019
2020 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
2021 pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
2022 pMgmt->abyCurrExtSuppRates[1] = 0;
2023 for (ii = 0; ii < 4; ii++)
2024 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2025 } else {
2026 pMgmt->abyCurrSuppRates[1] = 8;
2027 pMgmt->abyCurrExtSuppRates[1] = 0;
2028 for (ii = 0; ii < 8; ii++)
2029 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2030 }
2031
92b96797
FB
2032 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2033 pMgmt->abyCurrSuppRates[1] = 8;
2034 pMgmt->abyCurrExtSuppRates[1] = 4;
2035 for (ii = 0; ii < 4; ii++)
2036 pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
2037 for (ii = 4; ii < 8; ii++)
2038 pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
2039 for (ii = 0; ii < 4; ii++)
2040 pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
2041 }
2042
92b96797
FB
2043 // Disable Protect Mode
2044 pDevice->bProtectMode = 0;
2045 MACvDisableProtectMD(pDevice);
2046
2047 pDevice->bBarkerPreambleMd = 0;
2048 MACvDisableBarkerPreambleMd(pDevice);
2049
2050 // Kyle Test 2003.11.04
2051
2052 // set HW beacon interval
2053 if (pMgmt->wIBSSBeaconPeriod == 0)
2054 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
2055 MACvWriteBeaconInterval(pDevice, pMgmt->wIBSSBeaconPeriod);
2056
2057 CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
2058 // clear TSF counter
2059 CARDbClearCurrentTSF(pDevice);
2060
2061 // enable TSF counter
2062 MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTREN);
2063 // set Next TBTT
2064 CARDvSetFirstNextTBTT(pDevice, pMgmt->wIBSSBeaconPeriod);
2065
2066 pMgmt->uIBSSChannel = pDevice->uChannel;
2067
2068 if (pMgmt->uIBSSChannel == 0)
2069 pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
2070
2071 // set channel and clear NAV
2072 CARDbSetMediaChannel(pDevice, pMgmt->uIBSSChannel);
2073 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2074
2075 pDevice->byPreambleType = pDevice->byShortPreamble;
2076
2077 // set basic rate
2078
8611a29a
AM
2079 RATEvParseMaxRate((void *)pDevice,
2080 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4e9b5e2b 2081 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
92b96797
FB
2082 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2083 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2084
92b96797 2085 if (pDevice->byBBType == BB_TYPE_11A) {
4e9b5e2b 2086 pDevice->bShortSlotTime = true;
92b96797 2087 } else {
e269fc2d 2088 pDevice->bShortSlotTime = false;
92b96797
FB
2089 }
2090 BBvSetShortSlotTime(pDevice);
2091 // vUpdateIFS() use pDevice->bShortSlotTime as parameter so it must be called
2092 // after setting ShortSlotTime.
2093 // CARDvSetBSSMode call vUpdateIFS()
2094 CARDvSetBSSMode(pDevice);
2095
2096 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2097 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_AP);
2098 pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
2099 }
2100
2101 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2102 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2103 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2104 }
2105
2106 // Adopt pre-configured IBSS vars to current vars
2107 pMgmt->eCurrState = WMAC_STATE_STARTED;
2108 pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
2109 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2110 pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
2111 pDevice->uCurrRSSI = 0;
2112 pDevice->byCurrSQ = 0;
2113
92b96797
FB
2114 memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
2115 ((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
92b96797
FB
2116
2117 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2118 memcpy(pMgmt->abyCurrSSID,
2119 pMgmt->abyDesireSSID,
2120 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
2121 );
2122
2123 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2124 // AP mode BSSID = MAC addr
2125 memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
d6a32aa1
AS
2126 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"AP beacon created BSSID:"
2127 "%pM\n", pMgmt->abyCurrBSSID);
92b96797
FB
2128 }
2129
2130 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2131
2132 // BSSID selected must be randomized as spec 11.1.3
7c65fa2a
MP
2133 pMgmt->abyCurrBSSID[5] = (u8)(qwCurrTSF & 0x000000ff);
2134 pMgmt->abyCurrBSSID[4] = (u8)((qwCurrTSF & 0x0000ff00) >> 8);
2135 pMgmt->abyCurrBSSID[3] = (u8)((qwCurrTSF & 0x00ff0000) >> 16);
2136 pMgmt->abyCurrBSSID[2] = (u8)((qwCurrTSF & 0x00000ff0) >> 4);
2137 pMgmt->abyCurrBSSID[1] = (u8)((qwCurrTSF & 0x000ff000) >> 12);
2138 pMgmt->abyCurrBSSID[0] = (u8)((qwCurrTSF & 0x0ff00000) >> 20);
92b96797
FB
2139 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
2140 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
2141 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
2142 pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
2143 pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
2144 pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
2145 pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
2146 pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
2147
d6a32aa1
AS
2148 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:"
2149 "%pM\n", pMgmt->abyCurrBSSID);
92b96797
FB
2150 }
2151
2152 // set BSSID filter
2153 MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
2154 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
2155
2156 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2157 pDevice->byRxMode |= RCR_BSSID;
4e9b5e2b 2158 pMgmt->bCurrBSSIDFilterOn = true;
92b96797
FB
2159
2160 // Set Capability Info
2161 pMgmt->wCurrCapInfo = 0;
2162
2163 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2164 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
2165 pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
2166 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
a0ad2776 2167 pDevice->op_mode = NL80211_IFTYPE_AP;
92b96797
FB
2168 }
2169
2170 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2171 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
a0ad2776 2172 pDevice->op_mode = NL80211_IFTYPE_ADHOC;
92b96797
FB
2173 }
2174
2175 if (pDevice->bEncryptionEnable) {
2176 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
2177 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2178 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2179 pMgmt->byCSSPK = KEY_CTL_CCMP;
2180 pMgmt->byCSSGK = KEY_CTL_CCMP;
2181 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2182 pMgmt->byCSSPK = KEY_CTL_TKIP;
2183 pMgmt->byCSSGK = KEY_CTL_TKIP;
2184 } else {
2185 pMgmt->byCSSPK = KEY_CTL_NONE;
2186 pMgmt->byCSSGK = KEY_CTL_WEP;
2187 }
2188 } else {
2189 pMgmt->byCSSPK = KEY_CTL_WEP;
2190 pMgmt->byCSSGK = KEY_CTL_WEP;
2191 }
9fc86028 2192 }
92b96797
FB
2193
2194 pMgmt->byERPContext = 0;
2195
2196 if (pDevice->byPreambleType == 1) {
2197 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
2198 } else {
2199 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
2200 }
2201
2202 pMgmt->eCurrState = WMAC_STATE_STARTED;
2203 // Prepare beacon to send
0cbd8d98
AM
2204 if (bMgrPrepareBeaconToSend((void *) pDevice, pMgmt))
2205 *pStatus = CMD_STATUS_SUCCESS;
92b96797 2206
0cbd8d98
AM
2207 return;
2208}
92b96797
FB
2209
2210/*+
2211 *
2212 * Routine Description:
2213 * Instructs wmac to join a bss using the supplied attributes.
2214 * The arguments may the BSSID or SSID and the rest of the
2215 * attributes are obtained from the scan result of known bss list.
2216 *
2217 *
2218 * Return Value:
2219 * None.
2220 *
2221-*/
2222
78f41c91 2223void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
92b96797 2224{
78f41c91
MP
2225 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2226 PKnownBSS pCurr = NULL;
2227 int ii, uu;
2228 PWLAN_IE_SUPP_RATES pItemRates = NULL;
2229 PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
2230 PWLAN_IE_SSID pItemSSID;
2231 u32 uRateLen = WLAN_RATES_MAXLEN;
2232 u16 wMaxBasicRate = RATE_1M;
2233 u16 wMaxSuppRate = RATE_1M;
2234 u16 wSuppRate;
2235 u8 byTopCCKBasicRate = RATE_1M;
2236 u8 byTopOFDMBasicRate = RATE_1M;
e269fc2d 2237 u8 bShortSlotTime = false;
92b96797 2238
92b96797 2239 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
4e9b5e2b 2240 if (pMgmt->sBSSList[ii].bActive == true)
92b96797
FB
2241 break;
2242 }
2243
2244 if (ii == MAX_BSS_NUM) {
2245 *pStatus = CMD_STATUS_RESOURCES;
2246 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
2247 return;
9fc86028 2248 }
92b96797
FB
2249
2250 // memset(pMgmt->abyDesireBSSID, 0, WLAN_BSSID_LEN);
2251 // Search known BSS list for prefer BSSID or SSID
2252
2253 pCurr = BSSpSearchBSSList(pDevice,
2254 pMgmt->abyDesireBSSID,
2255 pMgmt->abyDesireSSID,
2256 pDevice->eConfigPHYMode
2257 );
2258
2259 if (pCurr == NULL){
2260 *pStatus = CMD_STATUS_RESOURCES;
2261 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
2262 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
2263 return;
9fc86028 2264 }
92b96797
FB
2265
2266 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
2267
2268 if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))){
2269
bd2bc4c7
AM
2270 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
2271 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
2272 /*
92b96797 2273 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
e269fc2d 2274 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
92b96797
FB
2275 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2276 // encryption mode error
2277 pMgmt->eCurrState = WMAC_STATE_IDLE;
2278 return;
2279 }
2280 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
e269fc2d 2281 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
92b96797
FB
2282 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2283 // encryption mode error
2284 pMgmt->eCurrState = WMAC_STATE_IDLE;
2285 return;
2286 }
2287 }
2288*/
2289 }
2290
4e9b5e2b 2291 //if(pDevice->bWPASuppWextEnabled == true)
92b96797 2292 Encyption_Rebuild(pDevice, pCurr);
92b96797
FB
2293
2294 // Infrastructure BSS
2295 s_vMgrSynchBSS(pDevice,
2296 WMAC_MODE_ESS_STA,
2297 pCurr,
2298 pStatus
2299 );
2300
2301 if (*pStatus == CMD_STATUS_SUCCESS){
2302
2303 // Adopt this BSS state vars in Mgmt Object
2304 pMgmt->uCurrChannel = pCurr->uChannel;
2305
2306 memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2307 memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2308
2309 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2310 uRateLen = WLAN_RATES_MAXLEN_11B;
2311 }
2312
2313 pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
2314 pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
2315
2316 // Parse Support Rate IE
2317 pItemRates->byElementID = WLAN_EID_SUPP_RATES;
2318 pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2319 pItemRates,
2320 uRateLen);
2321
2322 // Parse Extension Support Rate IE
2323 pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
2324 pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
2325 pItemExtRates,
2326 uRateLen);
2327 // Stuffing Rate IE
2328 if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
cc856e61
AM
2329 for (ii = 0; ii < (unsigned int) (8 - pItemRates->len); ) {
2330 pItemRates->abyRates[pItemRates->len + ii] =
2331 pItemExtRates->abyRates[ii];
2332 ii++;
92b96797
FB
2333 if (pItemExtRates->len <= ii)
2334 break;
2335 }
b902fbfe 2336 pItemRates->len += (u8)ii;
92b96797 2337 if (pItemExtRates->len - ii > 0) {
b902fbfe 2338 pItemExtRates->len -= (u8)ii;
92b96797
FB
2339 for (uu = 0; uu < pItemExtRates->len; uu ++) {
2340 pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
2341 }
2342 } else {
2343 pItemExtRates->len = 0;
2344 }
2345 }
2346
4e9b5e2b 2347 RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
92b96797
FB
2348 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2349 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2350 vUpdateIFS(pDevice);
2351 // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
2352 // TODO: deal with if wCapInfo the PS-Pollable is on.
2353 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2354 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2355 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2356 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2357
2358 pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
2359
2360 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2361 // Adopt BSS state in Adapter Device Object
a0ad2776 2362 pDevice->op_mode = NL80211_IFTYPE_STATION;
92b96797
FB
2363 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2364
2365 // Add current BSS to Candidate list
a0a1f61a 2366 // This should only work for WPA2 BSS, and WPA2 BSS check must be done before.
92b96797 2367 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
dfdcc425 2368 bool bResult = bAdd_PMKID_Candidate((void *) pDevice,
0cbd8d98
AM
2369 pMgmt->abyCurrBSSID,
2370 &pCurr->sRSNCapObj);
92b96797 2371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
e269fc2d 2372 if (bResult == false) {
0cbd8d98
AM
2373 vFlush_PMKID_Candidate((void *) pDevice);
2374 DBG_PRT(MSG_LEVEL_DEBUG,
2375 KERN_INFO "vFlush_PMKID_Candidate: 4\n");
2376 bAdd_PMKID_Candidate((void *) pDevice,
2377 pMgmt->abyCurrBSSID,
2378 &pCurr->sRSNCapObj);
92b96797
FB
2379 }
2380 }
2381
2382 // Preamble type auto-switch: if AP can receive short-preamble cap,
2383 // we can turn on too.
2384 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
2385 pDevice->byPreambleType = pDevice->byShortPreamble;
2386 }
2387 else {
2388 pDevice->byPreambleType = 0;
2389 }
2390 // Change PreambleType must set RSPINF again
b902fbfe 2391 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
92b96797
FB
2392
2393 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
2394
2395 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11G) {
2396
2397 if ((pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
2398 pDevice->bProtectMode = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
2399 if (pDevice->bProtectMode) {
2400 MACvEnableProtectMD(pDevice);
2401 } else {
2402 MACvDisableProtectMD(pDevice);
2403 }
2404 vUpdateIFS(pDevice);
2405 }
2406 if ((pCurr->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
2407 pDevice->bNonERPPresent = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
2408 }
2409 if ((pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
2410 pDevice->bBarkerPreambleMd = (pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
2411 //BarkerPreambleMd has higher priority than shortPreamble bit in Cap
2412 if (pDevice->bBarkerPreambleMd) {
2413 MACvEnableBarkerPreambleMd(pDevice);
2414 } else {
2415 MACvDisableBarkerPreambleMd(pDevice);
2416 }
2417 }
2418 }
2419 //DBG_PRN_WLAN05(("wCapInfo: %X\n", pCurr->wCapInfo));
2420 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo) != pDevice->bShortSlotTime) {
2421 if (pDevice->byBBType == BB_TYPE_11A) {
4e9b5e2b 2422 bShortSlotTime = true;
92b96797
FB
2423 }
2424 else if (pDevice->byBBType == BB_TYPE_11B) {
e269fc2d 2425 bShortSlotTime = false;
92b96797
FB
2426 }
2427 else {
2428 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo);
2429 }
2430 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
2431 if (bShortSlotTime != pDevice->bShortSlotTime) {
2432 pDevice->bShortSlotTime = bShortSlotTime;
2433 BBvSetShortSlotTime(pDevice);
2434 vUpdateIFS(pDevice);
2435 }
2436 }
2437
2438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End of Join AP -- A/B/G Action\n");
2439 }
2440 else {
2441 pMgmt->eCurrState = WMAC_STATE_IDLE;
2442 };
2443
92b96797
FB
2444 }
2445 else {
2446 // ad-hoc mode BSS
2447 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2448
2449 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2450/*
e269fc2d 2451 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
92b96797
FB
2452 // encryption mode error
2453 pMgmt->eCurrState = WMAC_STATE_IDLE;
2454 return;
2455 }
2456*/
2457 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2458/*
e269fc2d 2459 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
92b96797
FB
2460 // encryption mode error
2461 pMgmt->eCurrState = WMAC_STATE_IDLE;
2462 return;
2463 }
2464*/
2465 } else {
2466 // encryption mode error
2467 pMgmt->eCurrState = WMAC_STATE_IDLE;
2468 return;
2469 }
2470 }
2471
2472 s_vMgrSynchBSS(pDevice,
2473 WMAC_MODE_IBSS_STA,
2474 pCurr,
2475 pStatus
2476 );
2477
2478 if (*pStatus == CMD_STATUS_SUCCESS){
2479 // Adopt this BSS state vars in Mgmt Object
2480 // TODO: check if CapInfo privacy on, but we don't..
2481 pMgmt->uCurrChannel = pCurr->uChannel;
2482
92b96797
FB
2483 // Parse Support Rate IE
2484 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2485 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2486 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2487 WLAN_RATES_MAXLEN_11B);
2488 // set basic rate
8611a29a
AM
2489 RATEvParseMaxRate((void *)pDevice,
2490 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4e9b5e2b 2491 NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
92b96797
FB
2492 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2493 vUpdateIFS(pDevice);
2494 pMgmt->wCurrCapInfo = pCurr->wCapInfo;
2495 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2496 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2497 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2498 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2499// pMgmt->wCurrATIMWindow = pCurr->wATIMWindow;
2500 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2501 pMgmt->eCurrState = WMAC_STATE_STARTED;
2502 // Adopt BSS state in Adapter Device Object
a0ad2776 2503 pDevice->op_mode = NL80211_IFTYPE_ADHOC;
4e9b5e2b 2504 pDevice->bLinkPass = true;
92b96797
FB
2505 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
2506 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2507
d6a32aa1
AS
2508 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join IBSS ok:%pM\n",
2509 pMgmt->abyCurrBSSID);
92b96797
FB
2510 // Preamble type auto-switch: if AP can receive short-preamble cap,
2511 // and if registry setting is short preamble we can turn on too.
2512
2513 if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
2514 pDevice->byPreambleType = pDevice->byShortPreamble;
2515 }
2516 else {
2517 pDevice->byPreambleType = 0;
2518 }
2519 // Change PreambleType must set RSPINF again
b902fbfe 2520 CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
92b96797
FB
2521
2522 // Prepare beacon
0cbd8d98 2523 bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
92b96797
FB
2524 }
2525 else {
2526 pMgmt->eCurrState = WMAC_STATE_IDLE;
2527 };
2528 };
2529 return;
2530}
2531
92b96797
FB
2532/*+
2533 *
2534 * Routine Description:
2535 * Set HW to synchronize a specific BSS from known BSS list.
2536 *
2537 *
2538 * Return Value:
2539 * PCM_STATUS
2540 *
2541-*/
78f41c91
MP
2542static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode,
2543 PKnownBSS pCurr, PCMD_STATUS pStatus)
92b96797 2544{
78f41c91
MP
2545 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2546 u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
2547 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
2548 /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
2549 u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
2550 4, 0x0C, 0x12, 0x18, 0x60};
2551 /* 6M, 9M, 12M, 48M*/
2552 u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
2553 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2554 u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
2555 4, 0x02, 0x04, 0x0B, 0x16};
92b96797
FB
2556
2557 *pStatus = CMD_STATUS_FAILURE;
2558
2559 if (s_bCipherMatch(pCurr,
2560 pDevice->eEncryptionStatus,
2561 &(pMgmt->byCSSPK),
e269fc2d 2562 &(pMgmt->byCSSGK)) == false) {
92b96797
FB
2563 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "s_bCipherMatch Fail .......\n");
2564 return;
2565 }
2566
2567 pMgmt->pCurrBSS = pCurr;
2568
2569 // if previous mode is IBSS.
2570 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2571 MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
2572 }
2573
2574 // Init the BSS informations
4e9b5e2b 2575 pDevice->bCCK = true;
e269fc2d 2576 pDevice->bProtectMode = false;
92b96797 2577 MACvDisableProtectMD(pDevice);
e269fc2d 2578 pDevice->bBarkerPreambleMd = false;
92b96797 2579 MACvDisableBarkerPreambleMd(pDevice);
e269fc2d 2580 pDevice->bNonERPPresent = false;
92b96797
FB
2581 pDevice->byPreambleType = 0;
2582 pDevice->wBasicRate = 0;
2583 // Set Basic Rate
8611a29a 2584 CARDbAddBasicRate((void *)pDevice, RATE_1M);
92b96797
FB
2585
2586 // calculate TSF offset
2587 // TSF Offset = Received Timestamp TSF - Marked Local's TSF
2588 CARDvAdjustTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
2589
2590 // set HW beacon interval
2591 MACvWriteBeaconInterval(pDevice, pCurr->wBeaconInterval);
2592
2593 // set Next TBTT
2594 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
2595 CARDvSetFirstNextTBTT(pDevice, pCurr->wBeaconInterval);
2596
2597 // set BSSID
2598 MACvWriteBSSIDAddress(pDevice, pCurr->abyBSSID);
2599
3e362598 2600 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, 6);
92b96797 2601
d6a32aa1
AS
2602 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:set CurrBSSID address = "
2603 "%pM\n", pMgmt->abyCurrBSSID);
92b96797
FB
2604
2605 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
2606 if ((pDevice->eConfigPHYMode == PHY_TYPE_11A) ||
2607 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2608 pDevice->byBBType = BB_TYPE_11A;
2609 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
4e9b5e2b 2610 pDevice->bShortSlotTime = true;
92b96797
FB
2611 BBvSetShortSlotTime(pDevice);
2612 CARDvSetBSSMode(pDevice);
2613 } else {
2614 return;
2615 }
2616 } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2617 if ((pDevice->eConfigPHYMode == PHY_TYPE_11B) ||
2618 (pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
2619 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2620 pDevice->byBBType = BB_TYPE_11B;
2621 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
e269fc2d 2622 pDevice->bShortSlotTime = false;
92b96797
FB
2623 BBvSetShortSlotTime(pDevice);
2624 CARDvSetBSSMode(pDevice);
2625 } else {
2626 return;
2627 }
2628 } else {
2629 if ((pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
2630 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2631 pDevice->byBBType = BB_TYPE_11G;
2632 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
4e9b5e2b 2633 pDevice->bShortSlotTime = true;
92b96797
FB
2634 BBvSetShortSlotTime(pDevice);
2635 CARDvSetBSSMode(pDevice);
2636 } else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) {
2637 pDevice->byBBType = BB_TYPE_11B;
e269fc2d 2638 pDevice->bShortSlotTime = false;
92b96797
FB
2639 BBvSetShortSlotTime(pDevice);
2640 CARDvSetBSSMode(pDevice);
2641 } else {
2642 return;
2643 }
2644 }
2645
2646 if (uBSSMode == WMAC_MODE_ESS_STA) {
2647 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2648 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2649 pDevice->byRxMode |= RCR_BSSID;
4e9b5e2b 2650 pMgmt->bCurrBSSIDFilterOn = true;
92b96797
FB
2651 }
2652
2653 // set channel and clear NAV
2654 CARDbSetMediaChannel(pDevice, pCurr->uChannel);
2655 pMgmt->uCurrChannel = pCurr->uChannel;
2656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Channel [%d]\n", pCurr->uChannel);
2657
2658 if ((pDevice->bUpdateBBVGA) &&
2659 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
2660 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
2661 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
2662 BBvSetShortSlotTime(pDevice);
2663 }
2664 //
2665 // Notes:
2666 // 1. In Ad-hoc mode : check if received others beacon as jointed indication,
2667 // otherwise we will start own IBSS.
2668 // 2. In Infra mode : Supposed we already synchronized with AP right now.
2669
2670 if (uBSSMode == WMAC_MODE_IBSS_STA) {
2671 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2672 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2673 pDevice->byRxMode |= RCR_BSSID;
4e9b5e2b 2674 pMgmt->bCurrBSSIDFilterOn = true;
9fc86028 2675 }
92b96797
FB
2676
2677 if (pDevice->byBBType == BB_TYPE_11A) {
3e362598 2678 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
92b96797
FB
2679 pMgmt->abyCurrExtSuppRates[1] = 0;
2680 } else if (pDevice->byBBType == BB_TYPE_11B) {
3e362598 2681 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
92b96797
FB
2682 pMgmt->abyCurrExtSuppRates[1] = 0;
2683 } else {
3e362598
JL
2684 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
2685 memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
92b96797
FB
2686 }
2687 pMgmt->byERPContext = pCurr->sERP.byERP;
2688
2689 *pStatus = CMD_STATUS_SUCCESS;
2690
2691 return;
2692};
2693
78f41c91 2694static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr)
92b96797 2695 {
78f41c91 2696 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
92b96797 2697
78f41c91
MP
2698 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
2699 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
4e9b5e2b 2700 if (pCurr->bWPAValid == true) { /*WPA-PSK */
92b96797
FB
2701 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
2702 if(pCurr->abyPKType[0] == WPA_TKIP) {
2703 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2704 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
2705 }
2706 else if(pCurr->abyPKType[0] == WPA_AESCCMP) {
2707 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2708 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
2709 }
2710 }
4e9b5e2b 2711 else if(pCurr->bWPA2Valid == true) { //WPA2-PSK
92b96797
FB
2712 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
2713 if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
2714 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2715 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
2716 }
2717 else if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
2718 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2719 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
2720 }
2721 }
2722 }
2723 // }
2724 return;
2725 }
2726
92b96797
FB
2727/*+
2728 *
2729 * Routine Description:
2730 * Format TIM field
2731 *
2732 *
2733 * Return Value:
8611a29a 2734 * void
92b96797
FB
2735 *
2736-*/
2737
78f41c91 2738static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM)
92b96797 2739{
78f41c91
MP
2740 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2741 u8 byMap;
2742 int ii, jj;
e269fc2d
AM
2743 int bStartFound = false;
2744 int bMulticast = false;
78f41c91
MP
2745 u16 wStartIndex = 0;
2746 u16 wEndIndex = 0;
92b96797 2747
92b96797
FB
2748 // Find size of partial virtual bitmap
2749 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
2750 byMap = pMgmt->abyPSTxMap[ii];
2751 if (!ii) {
2752 // Mask out the broadcast bit which is indicated separately.
2753 bMulticast = (byMap & byMask[0]) != 0;
2754 if(bMulticast) {
4e9b5e2b 2755 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
92b96797
FB
2756 }
2757 byMap = 0;
2758 }
2759 if (byMap) {
2760 if (!bStartFound) {
4e9b5e2b 2761 bStartFound = true;
3eaca0d2 2762 wStartIndex = (u16)ii;
92b96797 2763 }
3eaca0d2 2764 wEndIndex = (u16)ii;
92b96797 2765 }
273f4bef 2766 }
92b96797 2767
92b96797
FB
2768 // Round start index down to nearest even number
2769 wStartIndex &= ~BIT0;
2770
2771 // Round end index up to nearest even number
2772 wEndIndex = ((wEndIndex + 1) & ~BIT0);
2773
2774 // Size of element payload
2775
2776 pTIM->len = 3 + (wEndIndex - wStartIndex) + 1;
2777
2778 // Fill in the Fixed parts of the TIM
2779 pTIM->byDTIMCount = pMgmt->byDTIMCount;
2780 pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
2781 pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
2782 (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
2783
2784 // Append variable part of TIM
2785
2786 for (ii = wStartIndex, jj =0 ; ii <= wEndIndex; ii++, jj++) {
2787 pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
2788 }
2789
2790 // Aid = 0 don't used.
2791 pTIM->byVirtBitMap[0] &= ~BIT0;
2792}
2793
92b96797
FB
2794/*+
2795 *
2796 * Routine Description:
2797 * Constructs an Beacon frame( Ad-hoc mode)
2798 *
2799 *
2800 * Return Value:
a0a1f61a 2801 * PTR to frame; or NULL on allocation failure
92b96797
FB
2802 *
2803-*/
2804
78f41c91
MP
2805static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
2806 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
2807 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
2808 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
2809 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
92b96797 2810{
78f41c91
MP
2811 struct vnt_tx_mgmt *pTxPacket = NULL;
2812 WLAN_FR_BEACON sFrame;
2813 u8 abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
92b96797 2814
78f41c91
MP
2815 /* prepare beacon frame */
2816 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
2817 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
2818 + WLAN_BEACON_FR_MAXLEN);
2819 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
2820 + sizeof(struct vnt_tx_mgmt));
92b96797 2821 // Setup the sFrame structure.
b902fbfe 2822 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
2823 sFrame.len = WLAN_BEACON_FR_MAXLEN;
2824 vMgrEncodeBeacon(&sFrame);
2825 // Setup the header
2826 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
2827 (
2828 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
2829 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
2830 ));
2831
2832 if (pDevice->bEnablePSMode) {
3eaca0d2 2833 sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((u16)WLAN_SET_FC_PWRMGT(1));
92b96797
FB
2834 }
2835
2836 memcpy( sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
2837 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2838 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
2839 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
2840 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
2841 // Copy SSID
2842 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
2843 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
2844 memcpy(sFrame.pSSID,
2845 pCurrSSID,
2846 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
2847 );
2848 // Copy the rate set
2849 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
2850 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
2851 memcpy(sFrame.pSuppRates,
2852 pCurrSuppRates,
2853 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
2854 );
2855 // DS parameter
2856 if (pDevice->byBBType != BB_TYPE_11A) {
2857 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
2858 sFrame.len += (1) + WLAN_IEHDR_LEN;
2859 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
2860 sFrame.pDSParms->len = 1;
b902fbfe 2861 sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
92b96797
FB
2862 }
2863 // TIM field
2864 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2865 sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
2866 sFrame.pTIM->byElementID = WLAN_EID_TIM;
2867 s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
2868 sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
2869 }
2870
2871 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2872
2873 // IBSS parameter
2874 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
2875 sFrame.len += (2) + WLAN_IEHDR_LEN;
2876 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
2877 sFrame.pIBSSParms->len = 2;
2878 sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
2879 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2880 /* RSN parameter */
2881 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
2882 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
2883 sFrame.pRSNWPA->len = 12;
2884 sFrame.pRSNWPA->abyOUI[0] = 0x00;
2885 sFrame.pRSNWPA->abyOUI[1] = 0x50;
2886 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
2887 sFrame.pRSNWPA->abyOUI[3] = 0x01;
2888 sFrame.pRSNWPA->wVersion = 1;
2889 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
2890 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
2891 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
2892 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
2893 sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
2894 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
2895 sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
2896 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
2897 sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
2898 else
2899 sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
2900
2901 // Pairwise Key Cipher Suite
2902 sFrame.pRSNWPA->wPKCount = 0;
2903 // Auth Key Management Suite
3eaca0d2 2904 *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
92b96797
FB
2905 sFrame.pRSNWPA->len +=2;
2906
2907 // RSN Capabilites
3eaca0d2 2908 *((u16 *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
92b96797
FB
2909 sFrame.pRSNWPA->len +=2;
2910 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
2911 }
2912 }
2913
92b96797
FB
2914 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2915 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
2916 sFrame.len += 1 + WLAN_IEHDR_LEN;
2917 sFrame.pERP->byElementID = WLAN_EID_ERP;
2918 sFrame.pERP->len = 1;
2919 sFrame.pERP->byContext = 0;
4e9b5e2b 2920 if (pDevice->bProtectMode == true)
92b96797 2921 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
4e9b5e2b 2922 if (pDevice->bNonERPPresent == true)
92b96797 2923 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
4e9b5e2b 2924 if (pDevice->bBarkerPreambleMd == true)
92b96797
FB
2925 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
2926 }
2927 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
2928 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
2929 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3e362598 2930 memcpy(sFrame.pExtSuppRates,
92b96797
FB
2931 pCurrExtSuppRates,
2932 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2933 );
2934 }
2935 // hostapd wpa/wpa2 IE
4e9b5e2b 2936 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
92b96797
FB
2937 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2938 if (pMgmt->wWPAIELen != 0) {
2939 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
2940 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
2941 sFrame.len += pMgmt->wWPAIELen;
2942 }
2943 }
2944 }
2945
2946 /* Adjust the length fields */
2947 pTxPacket->cbMPDULen = sFrame.len;
2948 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
2949
2950 return pTxPacket;
2951}
2952
92b96797
FB
2953/*+
2954 *
2955 * Routine Description:
2956 * Constructs an Prob-response frame
2957 *
2958 *
2959 * Return Value:
a0a1f61a 2960 * PTR to frame; or NULL on allocation failure
92b96797
FB
2961 *
2962-*/
2963
3b138851 2964static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
78f41c91
MP
2965 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
2966 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
2967 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
2968 PWLAN_IE_SUPP_RATES pCurrSuppRates,
2969 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType)
92b96797 2970{
78f41c91
MP
2971 struct vnt_tx_mgmt *pTxPacket = NULL;
2972 WLAN_FR_PROBERESP sFrame;
92b96797 2973
78f41c91
MP
2974 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
2975 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
2976 + WLAN_PROBERESP_FR_MAXLEN);
2977 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
2978 + sizeof(struct vnt_tx_mgmt));
92b96797 2979 // Setup the sFrame structure.
b902fbfe 2980 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
2981 sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
2982 vMgrEncodeProbeResponse(&sFrame);
2983 // Setup the header
2984 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
2985 (
2986 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
2987 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
2988 ));
2989 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
2990 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2991 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
2992 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
2993 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
2994
2995 if (byPHYType == BB_TYPE_11B) {
3eaca0d2 2996 *sFrame.pwCapInfo &= cpu_to_le16((u16)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
92b96797
FB
2997 }
2998
2999 // Copy SSID
3000 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3001 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3002 memcpy(sFrame.pSSID,
3003 pCurrSSID,
3004 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3005 );
3006 // Copy the rate set
3007 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3008
3009 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3010 memcpy(sFrame.pSuppRates,
3011 pCurrSuppRates,
3012 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3013 );
3014
3015 // DS parameter
3016 if (pDevice->byBBType != BB_TYPE_11A) {
3017 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3018 sFrame.len += (1) + WLAN_IEHDR_LEN;
3019 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3020 sFrame.pDSParms->len = 1;
b902fbfe 3021 sFrame.pDSParms->byCurrChannel = (u8)uCurrChannel;
92b96797
FB
3022 }
3023
3024 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3025 // IBSS parameter
3026 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3027 sFrame.len += (2) + WLAN_IEHDR_LEN;
3028 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3029 sFrame.pIBSSParms->len = 2;
3030 sFrame.pIBSSParms->wATIMWindow = 0;
3031 }
3032 if (pDevice->byBBType == BB_TYPE_11G) {
3033 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3034 sFrame.len += 1 + WLAN_IEHDR_LEN;
3035 sFrame.pERP->byElementID = WLAN_EID_ERP;
3036 sFrame.pERP->len = 1;
3037 sFrame.pERP->byContext = 0;
4e9b5e2b 3038 if (pDevice->bProtectMode == true)
92b96797 3039 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
4e9b5e2b 3040 if (pDevice->bNonERPPresent == true)
92b96797 3041 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
4e9b5e2b 3042 if (pDevice->bBarkerPreambleMd == true)
92b96797
FB
3043 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3044 }
3045
3046 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3047 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3048 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3e362598 3049 memcpy(sFrame.pExtSuppRates,
92b96797
FB
3050 pCurrExtSuppRates,
3051 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3052 );
3053 }
3054
3055 // hostapd wpa/wpa2 IE
4e9b5e2b 3056 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
92b96797
FB
3057 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3058 if (pMgmt->wWPAIELen != 0) {
3059 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3060 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3061 sFrame.len += pMgmt->wWPAIELen;
3062 }
3063 }
3064 }
3065
3066 // Adjust the length fields
3067 pTxPacket->cbMPDULen = sFrame.len;
3068 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3069
3070 return pTxPacket;
3071}
3072
92b96797
FB
3073/*+
3074 *
3075 * Routine Description:
3076 * Constructs an association request frame
3077 *
3078 *
3079 * Return Value:
a0ae9e3c 3080 * A ptr to frame or NULL on allocation failure
92b96797
FB
3081 *
3082-*/
3083
3b138851 3084static struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
78f41c91
MP
3085 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3086 u16 wListenInterval,
3087 PWLAN_IE_SSID pCurrSSID,
3088 PWLAN_IE_SUPP_RATES pCurrRates,
3089 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
92b96797 3090{
78f41c91
MP
3091 struct vnt_tx_mgmt *pTxPacket = NULL;
3092 WLAN_FR_ASSOCREQ sFrame;
3093 u8 *pbyIEs;
3094 u8 *pbyRSN;
92b96797 3095
78f41c91
MP
3096 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3097 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3098 + WLAN_ASSOCREQ_FR_MAXLEN);
3099 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3100 + sizeof(struct vnt_tx_mgmt));
92b96797 3101 // Setup the sFrame structure.
b902fbfe 3102 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
3103 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
3104 // format fixed field frame structure
3105 vMgrEncodeAssocRequest(&sFrame);
3106 // Setup the header
3107 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3108 (
3109 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3110 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
3111 ));
3112 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3113 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3114 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3115
a0a1f61a 3116 // Set the capability and listen interval
92b96797
FB
3117 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3118 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3119
3120 // sFrame.len point to end of fixed field
3121 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3122 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3123 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3124
3125 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3126 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3127 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3e362598 3128 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
92b96797
FB
3129 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3130
3131 // Copy the rate set
3132 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3133 if ((pDevice->byBBType == BB_TYPE_11B) && (pCurrRates->len > 4))
3134 sFrame.len += 4 + WLAN_IEHDR_LEN;
3135 else
3136 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3137 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3138
3139 // Copy the extension rate set
3140 if ((pDevice->byBBType == BB_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3141 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3142 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3143 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3144 }
3145
3146 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3e362598 3147 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
92b96797
FB
3148 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3149
92b96797
FB
3150 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3151 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3152 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3153 (pMgmt->pCurrBSS != NULL)) {
3154 /* WPA IE */
3155 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3156 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3157 sFrame.pRSNWPA->len = 16;
3158 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3159 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3160 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3161 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3162 sFrame.pRSNWPA->wVersion = 1;
3163 //Group Key Cipher Suite
3164 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3165 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3166 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3167 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3168 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3169 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3170 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3171 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3172 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3173 } else {
3174 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3175 }
3176 // Pairwise Key Cipher Suite
3177 sFrame.pRSNWPA->wPKCount = 1;
3178 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3179 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3180 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3181 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3182 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3183 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3184 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3185 } else {
3186 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3187 }
3188 // Auth Key Management Suite
b902fbfe 3189 pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
92b96797
FB
3190 *pbyRSN++=0x01;
3191 *pbyRSN++=0x00;
3192 *pbyRSN++=0x00;
3193
3194 *pbyRSN++=0x50;
3195 *pbyRSN++=0xf2;
3196 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3197 *pbyRSN++=WPA_AUTH_PSK;
3198 }
3199 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3200 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3201 }
3202 else {
3203 *pbyRSN++=WPA_NONE;
3204 }
3205
3206 sFrame.pRSNWPA->len +=6;
3207
3208 // RSN Capabilites
3209
3210 *pbyRSN++=0x00;
3211 *pbyRSN++=0x00;
3212 sFrame.pRSNWPA->len +=2;
3213
3214 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3215 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3216 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3e362598 3217 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
92b96797
FB
3218 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3219
3220 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3221 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3222 (pMgmt->pCurrBSS != NULL)) {
cc856e61 3223 unsigned int ii;
3eaca0d2 3224 u16 * pwPMKID;
92b96797
FB
3225
3226 // WPA IE
3227 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3228 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3229 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3230 sFrame.pRSN->wVersion = 1;
3231 //Group Key Cipher Suite
3232 sFrame.pRSN->abyRSN[0] = 0x00;
3233 sFrame.pRSN->abyRSN[1] = 0x0F;
3234 sFrame.pRSN->abyRSN[2] = 0xAC;
3235 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3236 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3237 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3238 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3239 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3240 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3241 } else {
3242 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3243 }
3244
3245 // Pairwise Key Cipher Suite
3246 sFrame.pRSN->abyRSN[4] = 1;
3247 sFrame.pRSN->abyRSN[5] = 0;
3248 sFrame.pRSN->abyRSN[6] = 0x00;
3249 sFrame.pRSN->abyRSN[7] = 0x0F;
3250 sFrame.pRSN->abyRSN[8] = 0xAC;
3251 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3252 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3253 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3254 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3255 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3256 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3257 } else {
3258 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3259 }
3260 sFrame.pRSN->len += 6;
3261
3262 // Auth Key Management Suite
3263 sFrame.pRSN->abyRSN[10] = 1;
3264 sFrame.pRSN->abyRSN[11] = 0;
3265 sFrame.pRSN->abyRSN[12] = 0x00;
3266 sFrame.pRSN->abyRSN[13] = 0x0F;
3267 sFrame.pRSN->abyRSN[14] = 0xAC;
3268 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3269 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3270 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3271 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3272 } else {
3273 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3274 }
3275 sFrame.pRSN->len +=6;
3276
3277 // RSN Capabilites
4e9b5e2b 3278 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
3e362598 3279 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
92b96797
FB
3280 } else {
3281 sFrame.pRSN->abyRSN[16] = 0;
3282 sFrame.pRSN->abyRSN[17] = 0;
3283 }
3284 sFrame.pRSN->len +=2;
3285
4e9b5e2b 3286 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
92b96797
FB
3287 // RSN PMKID
3288 pbyRSN = &sFrame.pRSN->abyRSN[18];
3eaca0d2 3289 pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
92b96797
FB
3290 *pwPMKID = 0; // Initialize PMKID count
3291 pbyRSN += 2; // Point to PMKID list
9a0e756c
AM
3292 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3293 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0],
3294 pMgmt->abyCurrBSSID,
3295 ETH_ALEN)) {
3296 (*pwPMKID)++;
3297 memcpy(pbyRSN,
3298 pDevice->gsPMKID.BSSIDInfo[ii].PMKID,
3299 16);
3300 pbyRSN += 16;
3301 }
3302 }
92b96797
FB
3303 if (*pwPMKID != 0) {
3304 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3305 }
3306 }
3307
3308 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3309 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3310 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3e362598 3311 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
92b96797
FB
3312 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3313 }
3314
92b96797
FB
3315 // Adjust the length fields
3316 pTxPacket->cbMPDULen = sFrame.len;
3317 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3318 return pTxPacket;
3319}
3320
92b96797
FB
3321/*+
3322 *
3323 * Routine Description:
3324 * Constructs an re-association request frame
3325 *
3326 *
3327 * Return Value:
a0a1f61a 3328 * A ptr to frame or NULL on allocation failure
92b96797
FB
3329 *
3330-*/
3331
3b138851 3332static struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
78f41c91
MP
3333 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3334 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
3335 PWLAN_IE_SUPP_RATES pCurrRates,
3336 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
92b96797 3337{
78f41c91
MP
3338 struct vnt_tx_mgmt *pTxPacket = NULL;
3339 WLAN_FR_REASSOCREQ sFrame;
3340 u8 *pbyIEs;
3341 u8 *pbyRSN;
92b96797 3342
78f41c91
MP
3343 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3344 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3345 + WLAN_REASSOCREQ_FR_MAXLEN);
3346 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3347 + sizeof(struct vnt_tx_mgmt));
92b96797 3348 /* Setup the sFrame structure. */
b902fbfe 3349 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
3350 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
3351
3352 // format fixed field frame structure
3353 vMgrEncodeReassocRequest(&sFrame);
3354
3355 /* Setup the header */
3356 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3357 (
3358 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3359 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
3360 ));
3361 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3362 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3363 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3364
a0a1f61a 3365 /* Set the capability and listen interval */
92b96797
FB
3366 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3367 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3368
3369 memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3370 /* Copy the SSID */
3371 /* sFrame.len point to end of fixed field */
3372 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3373 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3374 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3375
3376 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3377 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3378 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3e362598 3379 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
92b96797
FB
3380 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3381
3382 /* Copy the rate set */
3383 /* sFrame.len point to end of SSID */
3384 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3385 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3386 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3387
3388 // Copy the extension rate set
3389 if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3390 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3391 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3392 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3393 }
3394
3395 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3e362598 3396 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
92b96797
FB
3397 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3398
3399 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3400 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3401 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3402 (pMgmt->pCurrBSS != NULL)) {
3403 /* WPA IE */
3404 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3405 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3406 sFrame.pRSNWPA->len = 16;
3407 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3408 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3409 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3410 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3411 sFrame.pRSNWPA->wVersion = 1;
3412 //Group Key Cipher Suite
3413 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3414 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3415 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3416 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3417 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3418 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3419 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3420 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3421 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3422 } else {
3423 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3424 }
3425 // Pairwise Key Cipher Suite
3426 sFrame.pRSNWPA->wPKCount = 1;
3427 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3428 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3429 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3430 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3431 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3432 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3433 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3434 } else {
3435 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3436 }
3437 // Auth Key Management Suite
b902fbfe 3438 pbyRSN = (u8 *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
92b96797
FB
3439 *pbyRSN++=0x01;
3440 *pbyRSN++=0x00;
3441 *pbyRSN++=0x00;
3442
3443 *pbyRSN++=0x50;
3444 *pbyRSN++=0xf2;
3445 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3446 *pbyRSN++=WPA_AUTH_PSK;
3447 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3448 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3449 } else {
3450 *pbyRSN++=WPA_NONE;
3451 }
3452
3453 sFrame.pRSNWPA->len +=6;
3454
3455 // RSN Capabilites
3456 *pbyRSN++=0x00;
3457 *pbyRSN++=0x00;
3458 sFrame.pRSNWPA->len +=2;
3459
3460 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3461 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3462 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3e362598 3463 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
92b96797
FB
3464 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3465
3466 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3467 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3468 (pMgmt->pCurrBSS != NULL)) {
cc856e61 3469 unsigned int ii;
3eaca0d2 3470 u16 * pwPMKID;
92b96797
FB
3471
3472 /* WPA IE */
3473 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3474 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3475 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3476 sFrame.pRSN->wVersion = 1;
3477 //Group Key Cipher Suite
3478 sFrame.pRSN->abyRSN[0] = 0x00;
3479 sFrame.pRSN->abyRSN[1] = 0x0F;
3480 sFrame.pRSN->abyRSN[2] = 0xAC;
3481 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3482 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3483 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3484 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3485 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3486 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3487 } else {
3488 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3489 }
3490
3491 // Pairwise Key Cipher Suite
3492 sFrame.pRSN->abyRSN[4] = 1;
3493 sFrame.pRSN->abyRSN[5] = 0;
3494 sFrame.pRSN->abyRSN[6] = 0x00;
3495 sFrame.pRSN->abyRSN[7] = 0x0F;
3496 sFrame.pRSN->abyRSN[8] = 0xAC;
3497 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3498 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3499 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3500 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3501 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3502 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3503 } else {
3504 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3505 }
3506 sFrame.pRSN->len += 6;
3507
3508 // Auth Key Management Suite
3509 sFrame.pRSN->abyRSN[10] = 1;
3510 sFrame.pRSN->abyRSN[11] = 0;
3511 sFrame.pRSN->abyRSN[12] = 0x00;
3512 sFrame.pRSN->abyRSN[13] = 0x0F;
3513 sFrame.pRSN->abyRSN[14] = 0xAC;
3514 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3515 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3516 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3517 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3518 } else {
3519 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3520 }
3521 sFrame.pRSN->len +=6;
3522
3523 // RSN Capabilites
4e9b5e2b 3524 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
3e362598 3525 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
92b96797
FB
3526 } else {
3527 sFrame.pRSN->abyRSN[16] = 0;
3528 sFrame.pRSN->abyRSN[17] = 0;
3529 }
3530 sFrame.pRSN->len +=2;
3531
4e9b5e2b 3532 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
92b96797
FB
3533 // RSN PMKID
3534 pbyRSN = &sFrame.pRSN->abyRSN[18];
3eaca0d2 3535 pwPMKID = (u16 *)pbyRSN; // Point to PMKID count
92b96797
FB
3536 *pwPMKID = 0; // Initialize PMKID count
3537 pbyRSN += 2; // Point to PMKID list
3538 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
9a0e756c
AM
3539 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0],
3540 pMgmt->abyCurrBSSID,
3541 ETH_ALEN)) {
3542 (*pwPMKID)++;
3543 memcpy(pbyRSN,
3544 pDevice->gsPMKID.BSSIDInfo[ii].PMKID,
3545 16);
3546 pbyRSN += 16;
92b96797
FB
3547 }
3548 }
3549 if (*pwPMKID != 0) {
3550 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3551 }
3552 }
3553
3554 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3555 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3556 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3e362598 3557 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
92b96797
FB
3558 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3559 }
3560
92b96797
FB
3561 /* Adjust the length fields */
3562 pTxPacket->cbMPDULen = sFrame.len;
3563 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3564
3565 return pTxPacket;
3566}
3567
92b96797
FB
3568/*+
3569 *
3570 * Routine Description:
3571 * Constructs an assoc-response frame
3572 *
3573 *
3574 * Return Value:
a0a1f61a 3575 * PTR to frame; or NULL on allocation failure
92b96797
FB
3576 *
3577-*/
3578
3b138851 3579static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
78f41c91
MP
3580 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
3581 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3582 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
92b96797 3583{
78f41c91
MP
3584 struct vnt_tx_mgmt *pTxPacket = NULL;
3585 WLAN_FR_ASSOCRESP sFrame;
92b96797 3586
78f41c91
MP
3587 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3588 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3589 + WLAN_ASSOCREQ_FR_MAXLEN);
3590 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3591 + sizeof(struct vnt_tx_mgmt));
92b96797 3592 // Setup the sFrame structure
b902fbfe 3593 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
3594 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3595 vMgrEncodeAssocResponse(&sFrame);
3596 // Setup the header
3597 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3598 (
3599 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3600 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
3601 ));
3602 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3603 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3604 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3605
3606 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3607 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
3eaca0d2 3608 *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
92b96797
FB
3609
3610 // Copy the rate set
3611 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3612 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3613 memcpy(sFrame.pSuppRates,
3614 pCurrSuppRates,
3615 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3616 );
3617
3618 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3619 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3620 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3e362598 3621 memcpy(sFrame.pExtSuppRates,
92b96797
FB
3622 pCurrExtSuppRates,
3623 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3624 );
3625 }
3626
3627 // Adjust the length fields
3628 pTxPacket->cbMPDULen = sFrame.len;
3629 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3630
3631 return pTxPacket;
3632}
3633
92b96797
FB
3634/*+
3635 *
3636 * Routine Description:
3637 * Constructs an reassoc-response frame
3638 *
3639 *
3640 * Return Value:
a0a1f61a 3641 * PTR to frame; or NULL on allocation failure
92b96797
FB
3642 *
3643-*/
3644
3b138851 3645static struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
78f41c91
MP
3646 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
3647 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3648 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
92b96797 3649{
78f41c91
MP
3650 struct vnt_tx_mgmt *pTxPacket = NULL;
3651 WLAN_FR_REASSOCRESP sFrame;
92b96797 3652
78f41c91
MP
3653 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3654 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3655 + WLAN_ASSOCREQ_FR_MAXLEN);
3656 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3657 + sizeof(struct vnt_tx_mgmt));
92b96797 3658 // Setup the sFrame structure
b902fbfe 3659 sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
92b96797
FB
3660 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3661 vMgrEncodeReassocResponse(&sFrame);
3662 // Setup the header
3663 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3664 (
3665 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3666 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
3667 ));
3668 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3669 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3670 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3671
3672 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3673 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
3eaca0d2 3674 *sFrame.pwAid = cpu_to_le16((u16)(wAssocAID | BIT14 | BIT15));
92b96797
FB
3675
3676 // Copy the rate set
3677 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3678 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3679 memcpy(sFrame.pSuppRates,
3680 pCurrSuppRates,
3681 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3682 );
3683
3684 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3685 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3686 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3e362598 3687 memcpy(sFrame.pExtSuppRates,
92b96797
FB
3688 pCurrExtSuppRates,
3689 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3690 );
3691 }
3692
3693 // Adjust the length fields
3694 pTxPacket->cbMPDULen = sFrame.len;
3695 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3696
3697 return pTxPacket;
3698}
3699
92b96797
FB
3700/*+
3701 *
3702 * Routine Description:
3703 * Handles probe response management frames.
3704 *
3705 *
3706 * Return Value:
3707 * none.
3708 *
3709-*/
3710
78f41c91
MP
3711static void s_vMgrRxProbeResponse(struct vnt_private *pDevice,
3712 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
92b96797 3713{
78f41c91
MP
3714 PKnownBSS pBSSList = NULL;
3715 WLAN_FR_PROBERESP sFrame;
3716 u8 byCurrChannel = pRxPacket->byRxChannel;
3717 ERPObject sERP;
4e9b5e2b 3718 int bChannelHit = true;
92b96797 3719
92b96797
FB
3720 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
3721 // decode the frame
3722 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 3723 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
3724 vMgrDecodeProbeResponse(&sFrame);
3725
6e1b4e24
AM
3726 if ((sFrame.pqwTimestamp == NULL)
3727 || (sFrame.pwBeaconInterval == NULL)
3728 || (sFrame.pwCapInfo == NULL)
3729 || (sFrame.pSSID == NULL)
3730 || (sFrame.pSuppRates == NULL)) {
3731
3732 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp:Fail addr:[%p]\n",
3733 pRxPacket->p80211Header);
6e1b4e24 3734 return;
9fc86028 3735 }
92b96797
FB
3736
3737 if(sFrame.pSSID->len == 0)
3738 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
3739
92b96797
FB
3740 //{{ RobertYu:20050201, 11a byCurrChannel != sFrame.pDSParms->byCurrChannel mapping
3741 if( byCurrChannel > CB_MAX_CHANNEL_24G )
3742 {
6e1b4e24
AM
3743 if (sFrame.pDSParms) {
3744 if (byCurrChannel ==
3745 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
4e9b5e2b 3746 bChannelHit = true;
6e1b4e24
AM
3747 byCurrChannel =
3748 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
92b96797 3749 } else {
4e9b5e2b 3750 bChannelHit = true;
92b96797 3751 }
92b96797 3752 } else {
6e1b4e24
AM
3753 if (sFrame.pDSParms) {
3754 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
4e9b5e2b 3755 bChannelHit = true;
6e1b4e24
AM
3756 byCurrChannel = sFrame.pDSParms->byCurrChannel;
3757 } else {
4e9b5e2b 3758 bChannelHit = true;
6e1b4e24 3759 }
92b96797
FB
3760 }
3761 //RobertYu:20050201
3762
4e9b5e2b 3763if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
92b96797
FB
3764 return;
3765
6e1b4e24 3766 if (sFrame.pERP) {
92b96797 3767 sERP.byERP = sFrame.pERP->byContext;
4e9b5e2b 3768 sERP.bERPExist = true;
92b96797 3769 } else {
e269fc2d 3770 sERP.bERPExist = false;
92b96797
FB
3771 sERP.byERP = 0;
3772 }
3773
92b96797 3774 // update or insert the bss
0cbd8d98
AM
3775 pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
3776 sFrame.pHdr->sA3.abyAddr3,
3777 sFrame.pSSID);
92b96797 3778 if (pBSSList) {
0cbd8d98
AM
3779 BSSbUpdateToBSSList((void *) pDevice,
3780 *sFrame.pqwTimestamp,
3781 *sFrame.pwBeaconInterval,
3782 *sFrame.pwCapInfo,
3783 byCurrChannel,
3784 bChannelHit,
3785 sFrame.pSSID,
3786 sFrame.pSuppRates,
3787 sFrame.pExtSuppRates,
3788 &sERP,
3789 sFrame.pRSN,
3790 sFrame.pRSNWPA,
3791 sFrame.pIE_Country,
3792 sFrame.pIE_Quiet,
3793 pBSSList,
3794 sFrame.len - WLAN_HDR_ADDR3_LEN,
3795 /* payload of probresponse */
3796 sFrame.pHdr->sA4.abyAddr4,
3797 (void *) pRxPacket);
3798 } else {
92b96797 3799 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Probe resp/insert: RxChannel = : %d\n", byCurrChannel);
0cbd8d98 3800 BSSbInsertToBSSList((void *) pDevice,
92b96797
FB
3801 sFrame.pHdr->sA3.abyAddr3,
3802 *sFrame.pqwTimestamp,
3803 *sFrame.pwBeaconInterval,
3804 *sFrame.pwCapInfo,
3805 byCurrChannel,
3806 sFrame.pSSID,
3807 sFrame.pSuppRates,
3808 sFrame.pExtSuppRates,
3809 &sERP,
3810 sFrame.pRSN,
3811 sFrame.pRSNWPA,
3812 sFrame.pIE_Country,
3813 sFrame.pIE_Quiet,
3814 sFrame.len - WLAN_HDR_ADDR3_LEN,
0cbd8d98
AM
3815 sFrame.pHdr->sA4.abyAddr4, /* payload of beacon */
3816 (void *) pRxPacket);
92b96797
FB
3817 }
3818 return;
3819
3820}
3821
3822/*+
3823 *
3824 * Routine Description:(AP)or(Ad-hoc STA)
3825 * Handles probe request management frames.
3826 *
3827 *
3828 * Return Value:
3829 * none.
3830 *
3831-*/
3832
78f41c91
MP
3833static void s_vMgrRxProbeRequest(struct vnt_private *pDevice,
3834 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
92b96797 3835{
78f41c91
MP
3836 WLAN_FR_PROBEREQ sFrame;
3837 CMD_STATUS Status;
3838 struct vnt_tx_mgmt *pTxPacket;
3839 u8 byPHYType = BB_TYPE_11B;
92b96797
FB
3840
3841 // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
3842 // STA have to response this request.
3843 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
3844 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
3845
3846 memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
3847 // decode the frame
3848 sFrame.len = pRxPacket->cbMPDULen;
b902fbfe 3849 sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
92b96797
FB
3850 vMgrDecodeProbeRequest(&sFrame);
3851/*
d6a32aa1
AS
3852 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%pM\n",
3853 sFrame.pHdr->sA3.abyAddr2);
92b96797
FB
3854*/
3855 if (sFrame.pSSID->len != 0) {
3856 if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
3857 return;
3858 if (memcmp(sFrame.pSSID->abySSID,
3859 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
3860 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
3861 return;
3862 }
3863 }
3864
3865 if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL)) {
3866 byPHYType = BB_TYPE_11G;
3867 }
3868
3869 // Probe response reply..
3870 pTxPacket = s_MgrMakeProbeResponse
3871 (
3872 pDevice,
3873 pMgmt,
3874 pMgmt->wCurrCapInfo,
3875 pMgmt->wCurrBeaconPeriod,
3876 pMgmt->uCurrChannel,
3877 0,
3878 sFrame.pHdr->sA3.abyAddr2,
3879 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
b902fbfe 3880 (u8 *)pMgmt->abyCurrBSSID,
92b96797
FB
3881 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
3882 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
3883 byPHYType
3884 );
3885 if (pTxPacket != NULL ){
3886 /* send the frame */
3887 Status = csMgmt_xmit(pDevice, pTxPacket);
3888 if (Status != CMD_STATUS_PENDING) {
3889 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx failed\n");
3890 }
3891 else {
3892// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx sending..\n");
3893 }
3894 }
3895 }
3896
3897 return;
3898}
3899
92b96797
FB
3900/*+
3901 *
3902 * Routine Description:
3903 *
3904 * Entry point for the reception and handling of 802.11 management
3905 * frames. Makes a determination of the frame type and then calls
3906 * the appropriate function.
3907 *
3908 *
3909 * Return Value:
3910 * none.
3911 *
3912-*/
3913
78f41c91
MP
3914void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt,
3915 struct vnt_rx_mgmt *pRxPacket)
92b96797 3916{
e269fc2d 3917 int bInScan = false;
78f41c91
MP
3918 u32 uNodeIndex = 0;
3919 NODE_STATE eNodeState = 0;
3920 CMD_STATUS Status;
92b96797 3921
92b96797
FB
3922 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
3923 if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
3924 eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
3925 }
3926
3927 switch( WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) ){
3928
3929 case WLAN_FSTYPE_ASSOCREQ:
3930 // Frame Clase = 2
3931 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocreq\n");
3932 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
3933 (eNodeState < NODE_AUTH)) {
3934 // send deauth notification
3935 // reason = (6) class 2 received from nonauth sta
3936 vMgrDeAuthenBeginSta(pDevice,
3937 pMgmt,
3938 pRxPacket->p80211Header->sA3.abyAddr2,
3939 (6),
3940 &Status
3941 );
3942 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 1\n");
3943 }
3944 else {
3945 s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
3946 }
3947 break;
3948
3949 case WLAN_FSTYPE_ASSOCRESP:
3950 // Frame Clase = 2
3951 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
e269fc2d 3952 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
92b96797
FB
3953 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
3954 break;
3955
3956 case WLAN_FSTYPE_REASSOCREQ:
3957 // Frame Clase = 2
3958 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocreq\n");
3959 // Todo: reassoc
3960 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
3961 (eNodeState < NODE_AUTH)) {
3962 // send deauth notification
3963 // reason = (6) class 2 received from nonauth sta
3964 vMgrDeAuthenBeginSta(pDevice,
3965 pMgmt,
3966 pRxPacket->p80211Header->sA3.abyAddr2,
3967 (6),
3968 &Status
3969 );
3970 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 2\n");
3971
3972 }
3973 s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
3974 break;
3975
3976 case WLAN_FSTYPE_REASSOCRESP:
3977 // Frame Clase = 2
3978 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
4e9b5e2b 3979 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
92b96797
FB
3980 break;
3981
3982 case WLAN_FSTYPE_PROBEREQ:
3983 // Frame Clase = 0
3984 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx probereq\n");
3985 s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
3986 break;
3987
3988 case WLAN_FSTYPE_PROBERESP:
3989 // Frame Clase = 0
3990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx proberesp\n");
3991
3992 s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
3993 break;
3994
3995 case WLAN_FSTYPE_BEACON:
3996 // Frame Clase = 0
3997 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
3998 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
4e9b5e2b 3999 bInScan = true;
9fc86028 4000 }
92b96797
FB
4001 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
4002 break;
4003
4004 case WLAN_FSTYPE_ATIM:
4005 // Frame Clase = 1
4006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx atim\n");
4007 break;
4008
4009 case WLAN_FSTYPE_DISASSOC:
4010 // Frame Clase = 2
4011 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx disassoc\n");
4012 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
4013 (eNodeState < NODE_AUTH)) {
4014 // send deauth notification
4015 // reason = (6) class 2 received from nonauth sta
4016 vMgrDeAuthenBeginSta(pDevice,
4017 pMgmt,
4018 pRxPacket->p80211Header->sA3.abyAddr2,
4019 (6),
4020 &Status
4021 );
4022 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 3\n");
4023 }
4024 s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
4025 break;
4026
4027 case WLAN_FSTYPE_AUTHEN:
4028 // Frame Clase = 1
4029 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx authen\n");
4030 s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
4031 break;
4032
4033 case WLAN_FSTYPE_DEAUTHEN:
4034 // Frame Clase = 1
4035 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx deauthen\n");
4036 s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
4037 break;
4038
4039 default:
4040 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx unknown mgmt\n");
4041 }
4042
4043 return;
4044}
4045
92b96797
FB
4046/*+
4047 *
4048 * Routine Description:
4049 *
4050 *
4051 * Prepare beacon to send
4052 *
4053 * Return Value:
4e9b5e2b 4054 * true if success; false if failed.
92b96797
FB
4055 *
4056-*/
78f41c91
MP
4057int bMgrPrepareBeaconToSend(struct vnt_private *pDevice,
4058 struct vnt_manager *pMgmt)
92b96797 4059{
78f41c91 4060 struct vnt_tx_mgmt *pTxPacket;
92b96797 4061
e269fc2d 4062// pDevice->bBeaconBufReady = false;
92b96797
FB
4063 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){
4064 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
4065 }
4066 else {
4067 pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
4068 }
4069 pTxPacket = s_MgrMakeBeacon
4070 (
4071 pDevice,
4072 pMgmt,
4073 pMgmt->wCurrCapInfo,
4074 pMgmt->wCurrBeaconPeriod,
4075 pMgmt->uCurrChannel,
4076 pMgmt->wCurrATIMWindow, //0,
4077 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
b902fbfe 4078 (u8 *)pMgmt->abyCurrBSSID,
92b96797
FB
4079 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4080 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
4081 );
4082
4083 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
4084 (pMgmt->abyCurrBSSID[0] == 0))
e269fc2d 4085 return false;
92b96797
FB
4086
4087 csBeacon_xmit(pDevice, pTxPacket);
4088 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
4089
4e9b5e2b 4090 return true;
92b96797
FB
4091}
4092
92b96797
FB
4093/*+
4094 *
4095 * Routine Description:
4096 *
4097 * Log a warning message based on the contents of the Status
4098 * Code field of an 802.11 management frame. Defines are
4099 * derived from 802.11-1997 SPEC.
4100 *
4101 * Return Value:
4102 * none.
4103 *
4104-*/
78f41c91 4105static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus)
92b96797
FB
4106{
4107 switch( wStatus ){
4108 case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
4109 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Unspecified error.\n");
4110 break;
4111 case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
4112 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Can't support all requested capabilities.\n");
4113 break;
4114 case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
4115 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Reassoc denied, can't confirm original Association.\n");
4116 break;
4117 case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
4118 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, undefine in spec\n");
4119 break;
4120 case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
4121 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Peer doesn't support authen algorithm.\n");
4122 break;
4123 case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
4124 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen frame received out of sequence.\n");
4125 break;
4126 case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
4127 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, challenge failure.\n");
4128 break;
4129 case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
4130 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, timeout waiting for next frame.\n");
4131 break;
4132 case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
4133 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, AP too busy.\n");
4134 break;
4135 case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
4136 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we haven't enough basic rates.\n");
4137 break;
4138 case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
4139 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support short preamble.\n");
4140 break;
4141 case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
4142 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support PBCC.\n");
4143 break;
4144 case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
4145 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support channel agility.\n");
4146 break;
4147 default:
4148 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Unknown status code %d.\n", wStatus);
4149 break;
4150 }
4151}
4152
92b96797
FB
4153/*
4154 *
4155 * Description:
4156 * Add BSSID in PMKID Candidate list.
4157 *
4158 * Parameters:
4159 * In:
4160 * hDeviceContext - device structure point
4161 * pbyBSSID - BSSID address for adding
4162 * wRSNCap - BSS's RSN capability
4163 * Out:
4164 * none
4165 *
4166 * Return Value: none.
4167 *
4168-*/
0cbd8d98 4169
78f41c91
MP
4170int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID,
4171 PSRSNCapObject psRSNCapObj)
92b96797 4172{
78f41c91
MP
4173 PPMKID_CANDIDATE pCandidateList;
4174 int ii = 0;
92b96797
FB
4175
4176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4177
4178 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
e269fc2d 4179 return false;
92b96797
FB
4180
4181 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
e269fc2d 4182 return false;
92b96797 4183
92b96797
FB
4184 // Update Old Candidate
4185 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
9a0e756c
AM
4186 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
4187 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
4e9b5e2b 4188 if ((psRSNCapObj->bRSNCapExist == true)
9a0e756c
AM
4189 && (psRSNCapObj->wRSNCap & BIT0)) {
4190 pCandidateList->Flags |=
4191 NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4192 } else {
4193 pCandidateList->Flags &=
4194 ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4195 }
4e9b5e2b 4196 return true;
92b96797
FB
4197 }
4198 }
4199
4200 // New Candidate
4201 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
4e9b5e2b 4202 if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
92b96797
FB
4203 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4204 } else {
4205 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4206 }
9a0e756c 4207 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
92b96797
FB
4208 pDevice->gsPMKIDCandidate.NumCandidates++;
4209 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4e9b5e2b 4210 return true;
92b96797
FB
4211}
4212
4213/*
4214 *
4215 * Description:
4216 * Flush PMKID Candidate list.
4217 *
4218 * Parameters:
4219 * In:
4220 * hDeviceContext - device structure point
4221 * Out:
4222 * none
4223 *
4224 * Return Value: none.
4225 *
4226-*/
0cbd8d98 4227
78f41c91 4228void vFlush_PMKID_Candidate(struct vnt_private *pDevice)
92b96797 4229{
78f41c91
MP
4230 if (pDevice == NULL)
4231 return;
92b96797 4232
78f41c91 4233 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
92b96797 4234
78f41c91 4235 return;
92b96797
FB
4236}
4237
dfdcc425 4238static bool
92b96797 4239s_bCipherMatch (
592ccfeb
AM
4240 PKnownBSS pBSSNode,
4241 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
b902fbfe
AM
4242 u8 * pbyCCSPK,
4243 u8 * pbyCCSGK
92b96797
FB
4244 )
4245{
b902fbfe
AM
4246 u8 byMulticastCipher = KEY_CTL_INVALID;
4247 u8 byCipherMask = 0x00;
92b96797
FB
4248 int i;
4249
4250 if (pBSSNode == NULL)
e269fc2d 4251 return false;
92b96797
FB
4252
4253 // check cap. of BSS
4254 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4255 (EncStatus == Ndis802_11Encryption1Enabled)) {
4256 // default is WEP only
4257 byMulticastCipher = KEY_CTL_WEP;
4258 }
4259
4260 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4e9b5e2b 4261 (pBSSNode->bWPA2Valid == true) &&
465711b3 4262
bd2bc4c7
AM
4263 ((EncStatus == Ndis802_11Encryption3Enabled) ||
4264 (EncStatus == Ndis802_11Encryption2Enabled))) {
92b96797
FB
4265 //WPA2
4266 // check Group Key Cipher
4267 if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
4268 (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
4269 byMulticastCipher = KEY_CTL_WEP;
4270 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
4271 byMulticastCipher = KEY_CTL_TKIP;
4272 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
4273 byMulticastCipher = KEY_CTL_CCMP;
4274 } else {
4275 byMulticastCipher = KEY_CTL_INVALID;
4276 }
4277
33d33e42
AM
4278 /* check Pairwise Key Cipher */
4279 for (i = 0; i < pBSSNode->wCSSPKCount; i++) {
4280 if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
4281 (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
4282 /* this should not happen as defined 802.11i */
4283 byCipherMask |= 0x01;
4284 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
4285 byCipherMask |= 0x02;
4286 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
4287 byCipherMask |= 0x04;
4288 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
4289 /* use group key only ignore all others */
4290 byCipherMask = 0;
4291 i = pBSSNode->wCSSPKCount;
4292 }
92b96797
FB
4293 }
4294
4295 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4e9b5e2b 4296 (pBSSNode->bWPAValid == true) &&
92b96797
FB
4297 ((EncStatus == Ndis802_11Encryption2Enabled) || (EncStatus == Ndis802_11Encryption3Enabled))) {
4298 //WPA
4299 // check Group Key Cipher
4300 if ((pBSSNode->byGKType == WPA_WEP40) ||
4301 (pBSSNode->byGKType == WPA_WEP104)) {
4302 byMulticastCipher = KEY_CTL_WEP;
4303 } else if (pBSSNode->byGKType == WPA_TKIP) {
4304 byMulticastCipher = KEY_CTL_TKIP;
4305 } else if (pBSSNode->byGKType == WPA_AESCCMP) {
4306 byMulticastCipher = KEY_CTL_CCMP;
4307 } else {
4308 byMulticastCipher = KEY_CTL_INVALID;
4309 }
4310
33d33e42
AM
4311 /* check Pairwise Key Cipher */
4312 for (i = 0; i < pBSSNode->wPKCount; i++) {
4313 if (pBSSNode->abyPKType[i] == WPA_TKIP) {
4314 byCipherMask |= 0x02;
4315 } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
4316 byCipherMask |= 0x04;
4317 } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
4318 /* use group key only ignore all others */
4319 byCipherMask = 0;
4320 i = pBSSNode->wPKCount;
4321 }
92b96797
FB
4322 }
4323 }
4324
4325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%d, %d, %d, %d, EncStatus:%d\n",
4326 byMulticastCipher, byCipherMask, pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
4327
4328 // mask our cap. with BSS
4329 if (EncStatus == Ndis802_11Encryption1Enabled) {
4330
4331 // For supporting Cisco migration mode, don't care pairwise key cipher
4332 //if ((byMulticastCipher == KEY_CTL_WEP) &&
4333 // (byCipherMask == 0)) {
4334 if ((byMulticastCipher == KEY_CTL_WEP) &&
4335 (byCipherMask == 0)) {
4336 *pbyCCSGK = KEY_CTL_WEP;
4337 *pbyCCSPK = KEY_CTL_NONE;
4e9b5e2b 4338 return true;
92b96797 4339 } else {
e269fc2d 4340 return false;
92b96797
FB
4341 }
4342
4343 } else if (EncStatus == Ndis802_11Encryption2Enabled) {
4344 if ((byMulticastCipher == KEY_CTL_TKIP) &&
4345 (byCipherMask == 0)) {
4346 *pbyCCSGK = KEY_CTL_TKIP;
4347 *pbyCCSPK = KEY_CTL_NONE;
4e9b5e2b 4348 return true;
92b96797
FB
4349 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4350 ((byCipherMask & 0x02) != 0)) {
4351 *pbyCCSGK = KEY_CTL_WEP;
4352 *pbyCCSPK = KEY_CTL_TKIP;
4e9b5e2b 4353 return true;
92b96797
FB
4354 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4355 ((byCipherMask & 0x02) != 0)) {
4356 *pbyCCSGK = KEY_CTL_TKIP;
4357 *pbyCCSPK = KEY_CTL_TKIP;
4e9b5e2b 4358 return true;
92b96797 4359 } else {
e269fc2d 4360 return false;
92b96797
FB
4361 }
4362 } else if (EncStatus == Ndis802_11Encryption3Enabled) {
4363 if ((byMulticastCipher == KEY_CTL_CCMP) &&
4364 (byCipherMask == 0)) {
4365 // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
e269fc2d 4366 return false;
92b96797
FB
4367 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4368 ((byCipherMask & 0x04) != 0)) {
4369 *pbyCCSGK = KEY_CTL_WEP;
4370 *pbyCCSPK = KEY_CTL_CCMP;
4e9b5e2b 4371 return true;
92b96797
FB
4372 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4373 ((byCipherMask & 0x04) != 0)) {
4374 *pbyCCSGK = KEY_CTL_TKIP;
4375 *pbyCCSPK = KEY_CTL_CCMP;
4e9b5e2b 4376 return true;
92b96797
FB
4377 } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
4378 ((byCipherMask & 0x04) != 0)) {
4379 *pbyCCSGK = KEY_CTL_CCMP;
4380 *pbyCCSPK = KEY_CTL_CCMP;
4e9b5e2b 4381 return true;
92b96797 4382 } else {
e269fc2d 4383 return false;
92b96797
FB
4384 }
4385 }
4e9b5e2b 4386 return true;
92b96797
FB
4387}
4388