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