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