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