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