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